1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc extern "C" { void f(bool); } 4*f4a2713aSLionel Sambuc 5*f4a2713aSLionel Sambuc namespace std { 6*f4a2713aSLionel Sambuc using ::f; 7*f4a2713aSLionel Sambuc inline void f() { return f(true); } 8*f4a2713aSLionel Sambuc } 9*f4a2713aSLionel Sambuc 10*f4a2713aSLionel Sambuc namespace M { 11*f4a2713aSLionel Sambuc void f(float); 12*f4a2713aSLionel Sambuc } 13*f4a2713aSLionel Sambuc 14*f4a2713aSLionel Sambuc namespace N { 15*f4a2713aSLionel Sambuc using M::f; 16*f4a2713aSLionel Sambuc void f(int) { } // expected-note{{previous}} 17*f4a2713aSLionel Sambuc 18*f4a2713aSLionel Sambuc void f(int) { } // expected-error{{redefinition}} 19*f4a2713aSLionel Sambuc } 20*f4a2713aSLionel Sambuc 21*f4a2713aSLionel Sambuc namespace N { 22*f4a2713aSLionel Sambuc void f(double); 23*f4a2713aSLionel Sambuc void f(long); 24*f4a2713aSLionel Sambuc } 25*f4a2713aSLionel Sambuc 26*f4a2713aSLionel Sambuc struct X0 { 27*f4a2713aSLionel Sambuc void operator()(int); 28*f4a2713aSLionel Sambuc void operator()(long); 29*f4a2713aSLionel Sambuc }; 30*f4a2713aSLionel Sambuc 31*f4a2713aSLionel Sambuc struct X1 : X0 { 32*f4a2713aSLionel Sambuc // FIXME: give this operator() a 'float' parameter to test overloading 33*f4a2713aSLionel Sambuc // behavior. It currently fails. 34*f4a2713aSLionel Sambuc void operator()(); 35*f4a2713aSLionel Sambuc using X0::operator(); 36*f4a2713aSLionel Sambuc 37*f4a2713aSLionel Sambuc void test() { 38*f4a2713aSLionel Sambuc (*this)(1); 39*f4a2713aSLionel Sambuc } 40*f4a2713aSLionel Sambuc }; 41*f4a2713aSLionel Sambuc 42*f4a2713aSLionel Sambuc struct A { void f(); }; 43*f4a2713aSLionel Sambuc struct B : A { }; 44*f4a2713aSLionel Sambuc class C : B { using B::f; }; 45*f4a2713aSLionel Sambuc 46*f4a2713aSLionel Sambuc // PR5751: Resolve overloaded functions through using decls. 47*f4a2713aSLionel Sambuc namespace O { 48*f4a2713aSLionel Sambuc void f(int i); 49*f4a2713aSLionel Sambuc void f(double d); 50*f4a2713aSLionel Sambuc } 51*f4a2713aSLionel Sambuc namespace P { 52*f4a2713aSLionel Sambuc void f(); 53*f4a2713aSLionel Sambuc void g(void (*ptr)(int)); 54*f4a2713aSLionel Sambuc using O::f; 55*f4a2713aSLionel Sambuc void test() { 56*f4a2713aSLionel Sambuc f(); 57*f4a2713aSLionel Sambuc f(1); 58*f4a2713aSLionel Sambuc void (*f_ptr1)(double) = f; 59*f4a2713aSLionel Sambuc void (*f_ptr2)() = f; 60*f4a2713aSLionel Sambuc g(f); 61*f4a2713aSLionel Sambuc } 62*f4a2713aSLionel Sambuc } 63*f4a2713aSLionel Sambuc 64*f4a2713aSLionel Sambuc // Make sure that ADL can find names brought in by using decls. 65*f4a2713aSLionel Sambuc namespace test0 { 66*f4a2713aSLionel Sambuc namespace ns { 67*f4a2713aSLionel Sambuc class Foo {}; 68*f4a2713aSLionel Sambuc 69*f4a2713aSLionel Sambuc namespace inner { 70*f4a2713aSLionel Sambuc void foo(char *); // expected-note {{no known conversion}} 71*f4a2713aSLionel Sambuc } 72*f4a2713aSLionel Sambuc 73*f4a2713aSLionel Sambuc using inner::foo; 74*f4a2713aSLionel Sambuc } 75*f4a2713aSLionel Sambuc 76*f4a2713aSLionel Sambuc void test(ns::Foo *p) { 77*f4a2713aSLionel Sambuc foo(*p); // expected-error {{no matching function for call to 'foo'}} 78*f4a2713aSLionel Sambuc } 79*f4a2713aSLionel Sambuc } 80*f4a2713aSLionel Sambuc 81*f4a2713aSLionel Sambuc // Redeclarations! 82*f4a2713aSLionel Sambuc namespace test1 { 83*f4a2713aSLionel Sambuc namespace ns0 { struct Foo {}; } 84*f4a2713aSLionel Sambuc namespace A { void foo(ns0::Foo *p, int y, int z); } 85*f4a2713aSLionel Sambuc namespace ns2 { using A::foo; } 86*f4a2713aSLionel Sambuc namespace ns1 { struct Bar : ns0::Foo {}; } 87*f4a2713aSLionel Sambuc namespace A { void foo(ns0::Foo *p, int y, int z = 0); } // expected-note {{candidate}} 88*f4a2713aSLionel Sambuc namespace ns1 { using A::foo; } 89*f4a2713aSLionel Sambuc namespace ns2 { struct Baz : ns1::Bar {}; } 90*f4a2713aSLionel Sambuc namespace A { void foo(ns0::Foo *p, int y = 0, int z); } 91*f4a2713aSLionel Sambuc 92*f4a2713aSLionel Sambuc void test(ns2::Baz *p) { 93*f4a2713aSLionel Sambuc foo(p, 0, 0); // okay! 94*f4a2713aSLionel Sambuc foo(p, 0); // should be fine! 95*f4a2713aSLionel Sambuc foo(p); // expected-error {{no matching function}} 96*f4a2713aSLionel Sambuc } 97*f4a2713aSLionel Sambuc } 98*f4a2713aSLionel Sambuc 99*f4a2713aSLionel Sambuc namespace test2 { 100*f4a2713aSLionel Sambuc namespace ns { int foo; } 101*f4a2713aSLionel Sambuc template <class T> using ns::foo; // expected-error {{cannot template a using declaration}} 102*f4a2713aSLionel Sambuc 103*f4a2713aSLionel Sambuc // PR8022 104*f4a2713aSLionel Sambuc struct A { 105*f4a2713aSLionel Sambuc template <typename T> void f(T); 106*f4a2713aSLionel Sambuc }; 107*f4a2713aSLionel Sambuc class B : A { 108*f4a2713aSLionel Sambuc template <typename T> using A::f<T>; // expected-error {{cannot template a using declaration}} 109*f4a2713aSLionel Sambuc }; 110*f4a2713aSLionel Sambuc } 111*f4a2713aSLionel Sambuc 112*f4a2713aSLionel Sambuc // PR8756 113*f4a2713aSLionel Sambuc namespace foo 114*f4a2713aSLionel Sambuc { 115*f4a2713aSLionel Sambuc class Class1; // expected-note{{forward declaration}} 116*f4a2713aSLionel Sambuc class Class2 117*f4a2713aSLionel Sambuc { 118*f4a2713aSLionel Sambuc using ::foo::Class1::Function; // expected-error{{incomplete type 'foo::Class1' named in nested name specifier}} 119*f4a2713aSLionel Sambuc }; 120*f4a2713aSLionel Sambuc } 121*f4a2713aSLionel Sambuc 122*f4a2713aSLionel Sambuc // Don't suggest non-typenames for positions requiring typenames. 123*f4a2713aSLionel Sambuc namespace using_suggestion_tyname_val { 124*f4a2713aSLionel Sambuc namespace N { void FFF() {} } 125*f4a2713aSLionel Sambuc using typename N::FFG; // expected-error {{no member named 'FFG' in namespace 'using_suggestion_tyname_val::N'}} 126*f4a2713aSLionel Sambuc } 127*f4a2713aSLionel Sambuc 128*f4a2713aSLionel Sambuc namespace using_suggestion_member_tyname_val { 129*f4a2713aSLionel Sambuc class CCC { public: void AAA() { } }; 130*f4a2713aSLionel Sambuc class DDD : public CCC { public: using typename CCC::AAB; }; // expected-error {{no member named 'AAB' in 'using_suggestion_member_tyname_val::CCC'}} 131*f4a2713aSLionel Sambuc } 132*f4a2713aSLionel Sambuc 133*f4a2713aSLionel Sambuc namespace using_suggestion_tyname_val_dropped_specifier { 134*f4a2713aSLionel Sambuc void FFF() {} 135*f4a2713aSLionel Sambuc namespace N { } 136*f4a2713aSLionel Sambuc using typename N::FFG; // expected-error {{no member named 'FFG' in namespace 'using_suggestion_tyname_val_dropped_specifier::N'}} 137*f4a2713aSLionel Sambuc } 138*f4a2713aSLionel Sambuc 139*f4a2713aSLionel Sambuc // Currently hints aren't provided to drop out the incorrect M::. 140*f4a2713aSLionel Sambuc namespace using_suggestion_ty_dropped_nested_specifier { 141*f4a2713aSLionel Sambuc namespace N { 142*f4a2713aSLionel Sambuc class AAA {}; // expected-note {{'N::AAA' declared here}} 143*f4a2713aSLionel Sambuc namespace M { } 144*f4a2713aSLionel Sambuc } 145*f4a2713aSLionel Sambuc using N::M::AAA; // expected-error {{no member named 'AAA' in namespace 'using_suggestion_ty_dropped_nested_specifier::N::M'; did you mean 'N::AAA'?}} 146*f4a2713aSLionel Sambuc } 147*f4a2713aSLionel Sambuc 148*f4a2713aSLionel Sambuc namespace using_suggestion_tyname_ty_dropped_nested_specifier { 149*f4a2713aSLionel Sambuc namespace N { 150*f4a2713aSLionel Sambuc class AAA {}; // expected-note {{'N::AAA' declared here}} 151*f4a2713aSLionel Sambuc namespace M { } 152*f4a2713aSLionel Sambuc } 153*f4a2713aSLionel Sambuc using typename N::M::AAA; // expected-error {{no member named 'AAA' in namespace 'using_suggestion_tyname_ty_dropped_nested_specifier::N::M'; did you mean 'N::AAA'?}} 154*f4a2713aSLionel Sambuc } 155*f4a2713aSLionel Sambuc 156*f4a2713aSLionel Sambuc namespace using_suggestion_val_dropped_nested_specifier { 157*f4a2713aSLionel Sambuc namespace N { 158*f4a2713aSLionel Sambuc void FFF() {} // expected-note {{'N::FFF' declared here}} 159*f4a2713aSLionel Sambuc namespace M { } 160*f4a2713aSLionel Sambuc } 161*f4a2713aSLionel Sambuc using N::M::FFF; // expected-error {{no member named 'FFF' in namespace 'using_suggestion_val_dropped_nested_specifier::N::M'; did you mean 'N::FFF'?}} 162*f4a2713aSLionel Sambuc } 163