1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc namespace A { 4*f4a2713aSLionel Sambuc short i; // expected-note 2{{candidate found by name lookup is 'A::i'}} 5*f4a2713aSLionel Sambuc namespace B { 6*f4a2713aSLionel Sambuc long i; // expected-note{{candidate found by name lookup is 'A::B::i'}} f()7*f4a2713aSLionel Sambuc void f() {} // expected-note{{candidate function}} 8*f4a2713aSLionel Sambuc int k; 9*f4a2713aSLionel Sambuc namespace E {} // \ 10*f4a2713aSLionel Sambuc expected-note{{candidate found by name lookup is 'A::B::E'}} 11*f4a2713aSLionel Sambuc } 12*f4a2713aSLionel Sambuc 13*f4a2713aSLionel Sambuc namespace E {} // expected-note{{candidate found by name lookup is 'A::E'}} 14*f4a2713aSLionel Sambuc 15*f4a2713aSLionel Sambuc namespace C { 16*f4a2713aSLionel Sambuc using namespace B; 17*f4a2713aSLionel Sambuc namespace E {} // \ 18*f4a2713aSLionel Sambuc expected-note{{candidate found by name lookup is 'A::C::E'}} 19*f4a2713aSLionel Sambuc } 20*f4a2713aSLionel Sambuc f()21*f4a2713aSLionel Sambuc void f() {} // expected-note{{candidate function}} 22*f4a2713aSLionel Sambuc 23*f4a2713aSLionel Sambuc class K1 { 24*f4a2713aSLionel Sambuc void foo(); 25*f4a2713aSLionel Sambuc }; 26*f4a2713aSLionel Sambuc local_i()27*f4a2713aSLionel Sambuc void local_i() { 28*f4a2713aSLionel Sambuc char i; 29*f4a2713aSLionel Sambuc using namespace A; 30*f4a2713aSLionel Sambuc using namespace B; 31*f4a2713aSLionel Sambuc int a[sizeof(i) == sizeof(char)? 1 : -1]; // okay 32*f4a2713aSLionel Sambuc } 33*f4a2713aSLionel Sambuc namespace B { 34*f4a2713aSLionel Sambuc int j; 35*f4a2713aSLionel Sambuc } 36*f4a2713aSLionel Sambuc ambig_i()37*f4a2713aSLionel Sambuc void ambig_i() { 38*f4a2713aSLionel Sambuc using namespace A; 39*f4a2713aSLionel Sambuc using namespace A::B; 40*f4a2713aSLionel Sambuc (void) i; // expected-error{{reference to 'i' is ambiguous}} 41*f4a2713aSLionel Sambuc f(); // expected-error{{call to 'f' is ambiguous}} 42*f4a2713aSLionel Sambuc (void) j; // okay 43*f4a2713aSLionel Sambuc using namespace C; 44*f4a2713aSLionel Sambuc (void) k; // okay 45*f4a2713aSLionel Sambuc using namespace E; // expected-error{{reference to 'E' is ambiguous}} 46*f4a2713aSLionel Sambuc } 47*f4a2713aSLionel Sambuc 48*f4a2713aSLionel Sambuc struct K2 {}; // expected-note 2{{candidate found by name lookup is 'A::K2'}} 49*f4a2713aSLionel Sambuc } 50*f4a2713aSLionel Sambuc 51*f4a2713aSLionel Sambuc struct K2 {}; // expected-note 2{{candidate found by name lookup is 'K2'}} 52*f4a2713aSLionel Sambuc 53*f4a2713aSLionel Sambuc using namespace A; 54*f4a2713aSLionel Sambuc foo()55*f4a2713aSLionel Sambucvoid K1::foo() {} // okay 56*f4a2713aSLionel Sambuc 57*f4a2713aSLionel Sambuc struct K2 *k2; // expected-error{{reference to 'K2' is ambiguous}} 58*f4a2713aSLionel Sambuc 59*f4a2713aSLionel Sambuc K2 *k3; // expected-error{{reference to 'K2' is ambiguous}} 60*f4a2713aSLionel Sambuc 61*f4a2713aSLionel Sambuc class X { // expected-note{{candidate found by name lookup is 'X'}} 62*f4a2713aSLionel Sambuc // FIXME: produce a suitable error message for this 63*f4a2713aSLionel Sambuc using namespace A; // expected-error{{not allowed}} 64*f4a2713aSLionel Sambuc }; 65*f4a2713aSLionel Sambuc 66*f4a2713aSLionel Sambuc namespace N { 67*f4a2713aSLionel Sambuc struct K2; 68*f4a2713aSLionel Sambuc struct K2 { }; 69*f4a2713aSLionel Sambuc } 70*f4a2713aSLionel Sambuc 71*f4a2713aSLionel Sambuc namespace Ni { 72*f4a2713aSLionel Sambuc int i(); // expected-note{{candidate found by name lookup is 'Ni::i'}} 73*f4a2713aSLionel Sambuc } 74*f4a2713aSLionel Sambuc 75*f4a2713aSLionel Sambuc namespace NiTest { 76*f4a2713aSLionel Sambuc using namespace A; 77*f4a2713aSLionel Sambuc using namespace Ni; 78*f4a2713aSLionel Sambuc test()79*f4a2713aSLionel Sambuc int test() { 80*f4a2713aSLionel Sambuc return i; // expected-error{{reference to 'i' is ambiguous}} 81*f4a2713aSLionel Sambuc } 82*f4a2713aSLionel Sambuc } 83*f4a2713aSLionel Sambuc 84*f4a2713aSLionel Sambuc namespace OneTag { 85*f4a2713aSLionel Sambuc struct X; // expected-note{{candidate found by name lookup is 'OneTag::X'}} 86*f4a2713aSLionel Sambuc } 87*f4a2713aSLionel Sambuc 88*f4a2713aSLionel Sambuc namespace OneFunction { 89*f4a2713aSLionel Sambuc void X(); // expected-note{{candidate found by name lookup is 'OneFunction::X'}} 90*f4a2713aSLionel Sambuc } 91*f4a2713aSLionel Sambuc 92*f4a2713aSLionel Sambuc namespace TwoTag { 93*f4a2713aSLionel Sambuc struct X; // expected-note{{candidate found by name lookup is 'TwoTag::X'}} 94*f4a2713aSLionel Sambuc } 95*f4a2713aSLionel Sambuc 96*f4a2713aSLionel Sambuc namespace FuncHidesTagAmbiguity { 97*f4a2713aSLionel Sambuc using namespace OneTag; 98*f4a2713aSLionel Sambuc using namespace OneFunction; 99*f4a2713aSLionel Sambuc using namespace TwoTag; 100*f4a2713aSLionel Sambuc test()101*f4a2713aSLionel Sambuc void test() { 102*f4a2713aSLionel Sambuc (void)X(); // expected-error{{reference to 'X' is ambiguous}} 103*f4a2713aSLionel Sambuc } 104*f4a2713aSLionel Sambuc } 105*f4a2713aSLionel Sambuc 106*f4a2713aSLionel Sambuc // PR5479 107*f4a2713aSLionel Sambuc namespace Aliased { 108*f4a2713aSLionel Sambuc void inAliased(); 109*f4a2713aSLionel Sambuc } 110*f4a2713aSLionel Sambuc namespace Alias = Aliased; 111*f4a2713aSLionel Sambuc using namespace Alias; testAlias()112*f4a2713aSLionel Sambucvoid testAlias() { 113*f4a2713aSLionel Sambuc inAliased(); 114*f4a2713aSLionel Sambuc } 115*f4a2713aSLionel Sambuc 116*f4a2713aSLionel Sambuc namespace N { void f2(int); } 117*f4a2713aSLionel Sambuc 118*f4a2713aSLionel Sambuc extern "C++" { 119*f4a2713aSLionel Sambuc using namespace N; f3()120*f4a2713aSLionel Sambuc void f3() { f2(1); } 121*f4a2713aSLionel Sambuc } 122*f4a2713aSLionel Sambuc f4()123*f4a2713aSLionel Sambucvoid f4() { f2(1); } 124*f4a2713aSLionel Sambuc 125*f4a2713aSLionel Sambuc // PR7517 126*f4a2713aSLionel Sambuc using namespace std; // expected-warning{{using directive refers to implicitly-defined namespace 'std'}} 127*f4a2713aSLionel Sambuc using namespace ::std; // expected-warning{{using directive refers to implicitly-defined namespace 'std'}} 128*f4a2713aSLionel Sambuc 129*f4a2713aSLionel Sambuc namespace test1 { 130*f4a2713aSLionel Sambuc namespace ns { typedef int test1; } 131*f4a2713aSLionel Sambuc template <class T> using namespace ns; // expected-error {{cannot template a using directive}} 132*f4a2713aSLionel Sambuc 133*f4a2713aSLionel Sambuc // Test that we recovered okay. 134*f4a2713aSLionel Sambuc test1 x; 135*f4a2713aSLionel Sambuc } 136