13573b2c84372d9484296fa658f5276f6c09acb92Daniel Dunbar// RUN: %clang_cc1 -fsyntax-only -verify %s 27a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor 37a7be65a7801addae8205fd68323cecd70df1635Douglas Gregornamespace A { 4d7cb037d4b143f66083a4bca56b8b9e51606f9f0Douglas Gregor short i; // expected-note 2{{candidate found by name lookup is 'A::i'}} 57a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor namespace B { 67a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor long i; // expected-note{{candidate found by name lookup is 'A::B::i'}} 77a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor void f() {} // expected-note{{candidate function}} 87a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor int k; 97a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor namespace E {} // \ 107a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor expected-note{{candidate found by name lookup is 'A::B::E'}} 117a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor } 127a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor 137a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor namespace E {} // expected-note{{candidate found by name lookup is 'A::E'}} 147a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor 157a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor namespace C { 167a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor using namespace B; 177a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor namespace E {} // \ 187a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor expected-note{{candidate found by name lookup is 'A::C::E'}} 197a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor } 207a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor 217a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor void f() {} // expected-note{{candidate function}} 227a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor 237a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor class K1 { 247a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor void foo(); 257a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor }; 267a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor 277a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor void local_i() { 287a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor char i; 297a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor using namespace A; 307a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor using namespace B; 317a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor int a[sizeof(i) == sizeof(char)? 1 : -1]; // okay 327a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor } 337a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor namespace B { 347a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor int j; 357a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor } 367a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor 377a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor void ambig_i() { 387a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor using namespace A; 397a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor using namespace A::B; 407a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor (void) i; // expected-error{{reference to 'i' is ambiguous}} 417a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor f(); // expected-error{{call to 'f' is ambiguous}} 427a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor (void) j; // okay 437a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor using namespace C; 447a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor (void) k; // okay 457a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor using namespace E; // expected-error{{reference to 'E' is ambiguous}} 467a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor } 477a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor 484f5fdef63912c84b365d00f916c542a252ff450bJohn McCall struct K2 {}; // expected-note 2{{candidate found by name lookup is 'A::K2'}} 497a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor} 507a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor 514f5fdef63912c84b365d00f916c542a252ff450bJohn McCallstruct K2 {}; // expected-note 2{{candidate found by name lookup is 'K2'}} 527a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor 537a7be65a7801addae8205fd68323cecd70df1635Douglas Gregorusing namespace A; 547a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor 557a7be65a7801addae8205fd68323cecd70df1635Douglas Gregorvoid K1::foo() {} // okay 567a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor 571c23b3ff07ff44e67f0bbc0cc55e2268da57912fJohn McCallstruct K2 *k2; // expected-error{{reference to 'K2' is ambiguous}} 587a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor 594f5fdef63912c84b365d00f916c542a252ff450bJohn McCallK2 *k3; // expected-error{{reference to 'K2' is ambiguous}} 607a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor 61b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregorclass X { // expected-note{{candidate found by name lookup is 'X'}} 627a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor // FIXME: produce a suitable error message for this 63683a1144296b0d866dea5b8bee2c2948ad0b6312Douglas Gregor using namespace A; // expected-error{{not allowed}} 647a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor}; 657a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor 667a7be65a7801addae8205fd68323cecd70df1635Douglas Gregornamespace N { 67362c8955c74cd6f9e24026403624afbe7fcdf029Douglas Gregor struct K2; 68362c8955c74cd6f9e24026403624afbe7fcdf029Douglas Gregor struct K2 { }; 697a7be65a7801addae8205fd68323cecd70df1635Douglas Gregor} 70b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor 71b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregornamespace Ni { 72b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor int i(); // expected-note{{candidate found by name lookup is 'Ni::i'}} 73b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor} 74b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor 75b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregornamespace NiTest { 76b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor using namespace A; 77b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor using namespace Ni; 78b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor 79b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor int test() { 80b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor return i; // expected-error{{reference to 'i' is ambiguous}} 81b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor } 82b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor} 83b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor 84b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregornamespace OneTag { 85b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor struct X; // expected-note{{candidate found by name lookup is 'OneTag::X'}} 86b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor} 87b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor 88b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregornamespace OneFunction { 89b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor void X(); // expected-note{{candidate found by name lookup is 'OneFunction::X'}} 90b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor} 91b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor 92b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregornamespace TwoTag { 93449808bbe9054c6be74400418b6b93901753a827Douglas Gregor struct X; // expected-note{{candidate found by name lookup is 'TwoTag::X'}} 94b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor} 95b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor 96b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregornamespace FuncHidesTagAmbiguity { 97b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor using namespace OneTag; 98b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor using namespace OneFunction; 99b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor using namespace TwoTag; 100b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor 101b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor void test() { 102449808bbe9054c6be74400418b6b93901753a827Douglas Gregor (void)X(); // expected-error{{reference to 'X' is ambiguous}} 103b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor } 104b96b92d2b8965ff7078ad9a2823d27f1411fb559Douglas Gregor} 105b4a0a8293aff2c6160e11edb51d8715a670248c6Sebastian Redl 106b4a0a8293aff2c6160e11edb51d8715a670248c6Sebastian Redl// PR5479 107b4a0a8293aff2c6160e11edb51d8715a670248c6Sebastian Redlnamespace Aliased { 108b4a0a8293aff2c6160e11edb51d8715a670248c6Sebastian Redl void inAliased(); 109b4a0a8293aff2c6160e11edb51d8715a670248c6Sebastian Redl} 110b4a0a8293aff2c6160e11edb51d8715a670248c6Sebastian Redlnamespace Alias = Aliased; 111b4a0a8293aff2c6160e11edb51d8715a670248c6Sebastian Redlusing namespace Alias; 112b4a0a8293aff2c6160e11edb51d8715a670248c6Sebastian Redlvoid testAlias() { 113b4a0a8293aff2c6160e11edb51d8715a670248c6Sebastian Redl inAliased(); 114b4a0a8293aff2c6160e11edb51d8715a670248c6Sebastian Redl} 1152539385eb3e538c81831f6ed136091f68e989574Douglas Gregor 1162539385eb3e538c81831f6ed136091f68e989574Douglas Gregornamespace N { void f2(int); } 1172539385eb3e538c81831f6ed136091f68e989574Douglas Gregor 1182539385eb3e538c81831f6ed136091f68e989574Douglas Gregorextern "C++" { 1192539385eb3e538c81831f6ed136091f68e989574Douglas Gregor using namespace N; 1202539385eb3e538c81831f6ed136091f68e989574Douglas Gregor void f3() { f2(1); } 1212539385eb3e538c81831f6ed136091f68e989574Douglas Gregor} 1222539385eb3e538c81831f6ed136091f68e989574Douglas Gregor 1232539385eb3e538c81831f6ed136091f68e989574Douglas Gregorvoid f4() { f2(1); } 1246c80d32157032a7f66dc587e74ae36ac11d7f5b4Douglas Gregor 1256c80d32157032a7f66dc587e74ae36ac11d7f5b4Douglas Gregor// PR7517 1266c80d32157032a7f66dc587e74ae36ac11d7f5b4Douglas Gregorusing namespace std; // expected-warning{{using directive refers to implicitly-defined namespace 'std'}} 1276c80d32157032a7f66dc587e74ae36ac11d7f5b4Douglas Gregorusing namespace ::std; // expected-warning{{using directive refers to implicitly-defined namespace 'std'}} 1286c80d32157032a7f66dc587e74ae36ac11d7f5b4Douglas Gregor 129a84a8537fe56300cc3b9a9edb2244518c587cab0John McCallnamespace test1 { 130a84a8537fe56300cc3b9a9edb2244518c587cab0John McCall namespace ns { typedef int test1; } 131a84a8537fe56300cc3b9a9edb2244518c587cab0John McCall template <class T> using namespace ns; // expected-error {{cannot template a using directive}} 132a84a8537fe56300cc3b9a9edb2244518c587cab0John McCall 133a84a8537fe56300cc3b9a9edb2244518c587cab0John McCall // Test that we recovered okay. 134a84a8537fe56300cc3b9a9edb2244518c587cab0John McCall test1 x; 135a84a8537fe56300cc3b9a9edb2244518c587cab0John McCall} 136