17002f4c03c2d0544f4e8bea8d3a5636519081e35John McCall// RUN: %clang_cc1 -fsyntax-only -verify %s
248270a36749b7f10677a514a03bbd2cf90697d58John McCall
348270a36749b7f10677a514a03bbd2cf90697d58John McCall// We have to avoid ADL for this test.
448270a36749b7f10677a514a03bbd2cf90697d58John McCall
548270a36749b7f10677a514a03bbd2cf90697d58John McCalltemplate <unsigned N> class test {};
648270a36749b7f10677a514a03bbd2cf90697d58John McCall
7cc5306ac8a39cdd5e7f83e597cba911e97c4a595Fariborz Jahanianclass foo {};	// expected-note {{candidate}}
848270a36749b7f10677a514a03bbd2cf90697d58John McCalltest<0> foo(foo); // expected-note {{candidate}}
948270a36749b7f10677a514a03bbd2cf90697d58John McCall
107ba107a1863ddfa1664555854f0d7bdb3c491c92John McCallnamespace Test0 {
1148270a36749b7f10677a514a03bbd2cf90697d58John McCall  class foo { int x; };
1248270a36749b7f10677a514a03bbd2cf90697d58John McCall  test<1> foo(class foo);
1348270a36749b7f10677a514a03bbd2cf90697d58John McCall
147ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall  namespace A {
15a41a8c5972c2632247ae7913cf6ce65d45f7e702Douglas Gregor    test<2> foo(class ::foo); // expected-note {{candidate}} \
16a41a8c5972c2632247ae7913cf6ce65d45f7e702Douglas Gregor    // expected-note{{passing argument to parameter here}}
1748270a36749b7f10677a514a03bbd2cf90697d58John McCall
1848270a36749b7f10677a514a03bbd2cf90697d58John McCall    void test0() {
1948270a36749b7f10677a514a03bbd2cf90697d58John McCall      using ::foo;
2048270a36749b7f10677a514a03bbd2cf90697d58John McCall
2148270a36749b7f10677a514a03bbd2cf90697d58John McCall      class foo a;
2248270a36749b7f10677a514a03bbd2cf90697d58John McCall      test<0> _ = (foo)(a);
2348270a36749b7f10677a514a03bbd2cf90697d58John McCall    }
2448270a36749b7f10677a514a03bbd2cf90697d58John McCall
2548270a36749b7f10677a514a03bbd2cf90697d58John McCall    void test1() {
267ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall      using Test0::foo;
2748270a36749b7f10677a514a03bbd2cf90697d58John McCall
2848270a36749b7f10677a514a03bbd2cf90697d58John McCall      class foo a;
2948270a36749b7f10677a514a03bbd2cf90697d58John McCall      test<1> _ = (foo)(a);
3048270a36749b7f10677a514a03bbd2cf90697d58John McCall    };
3148270a36749b7f10677a514a03bbd2cf90697d58John McCall
3248270a36749b7f10677a514a03bbd2cf90697d58John McCall    void test2() {
3348270a36749b7f10677a514a03bbd2cf90697d58John McCall      class ::foo a;
3448270a36749b7f10677a514a03bbd2cf90697d58John McCall
3548270a36749b7f10677a514a03bbd2cf90697d58John McCall      // Argument-dependent lookup is ambiguous between B:: and ::.
3648270a36749b7f10677a514a03bbd2cf90697d58John McCall      test<0> _0 = foo(a); // expected-error {{call to 'foo' is ambiguous}}
3748270a36749b7f10677a514a03bbd2cf90697d58John McCall
3848270a36749b7f10677a514a03bbd2cf90697d58John McCall      // But basic unqualified lookup is not.
3948270a36749b7f10677a514a03bbd2cf90697d58John McCall      test<2> _1 = (foo)(a);
4048270a36749b7f10677a514a03bbd2cf90697d58John McCall
417ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall      class Test0::foo b;
422fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu      test<2> _2 = (foo)(b); // expected-error {{no viable conversion from 'class Test0::foo' to 'class ::foo'}}
4348270a36749b7f10677a514a03bbd2cf90697d58John McCall    }
4448270a36749b7f10677a514a03bbd2cf90697d58John McCall  }
4548270a36749b7f10677a514a03bbd2cf90697d58John McCall}
467ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall
477ba107a1863ddfa1664555854f0d7bdb3c491c92John McCallnamespace Test1 {
487ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall  namespace A {
497ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall    class a {};
507ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall  }
517ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall
527ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall  namespace B {
537ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall    typedef class {} b;
547ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall  }
557ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall
567ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall  namespace C {
577ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall    int c(); // expected-note {{target of using declaration}}
587ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall  }
597ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall
607ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall  namespace D {
617ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall    using typename A::a;
627ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall    using typename B::b;
637ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall    using typename C::c; // expected-error {{'typename' keyword used on a non-type}}
647ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall
657ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall    a _1 = A::a();
667ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall    b _2 = B::b();
677ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall  }
687ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall}
6932daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall
7032daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCallnamespace test2 {
7132daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall  class A {
7232daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall  protected:
7332daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall    operator int();
7432daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall    operator bool();
7532daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall  };
7632daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall
7732daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall  class B : private A {
7832daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall  protected:
792fe9b7fb07dff15dd15dd8755a9a9e6de0fe46fcRichard Trieu    using A::operator int; // expected-note {{declared protected here}}
8032daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall  public:
8132daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall    using A::operator bool;
8232daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall  };
8332daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall
8432daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall  int test() {
8532daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall    bool b = B();
8632daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall    return B(); // expected-error {{'operator int' is a protected member of 'test2::B'}}
8732daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall  }
8832daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall}
8932daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall
9032daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCallnamespace test3 {
9132daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall  class A {
92d880f52be3e4a8ccad92ac31932eeae5e0870a93Douglas Gregor  public:
9332daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall    ~A();
9432daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall  };
9532daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall
9632daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall  class B {
9732daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall    friend class C;
9832daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall  private:
9932daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall    operator A*();
10032daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall  };
10132daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall
10232daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall  class C : public B {
10332daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall  public:
10432daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall    using B::operator A*;
10532daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall  };
10632daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall
10732daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall  void test() {
10832daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall    delete C();
10932daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall  }
11032daa4223ccb2c0afe5fbe151c6eb1ab64816957John McCall}
111