1*8fbe78f6SDaniel Dunbar // RUN: %clang_cc1 -fsyntax-only -verify %s 29757d036SJohn McCall 39757d036SJohn McCall // (this actually occurs before paragraph 1) 49757d036SJohn McCall namespace test0 { 59757d036SJohn McCall namespace A {} 69757d036SJohn McCall class B { 79757d036SJohn McCall using namespace A; // expected-error {{'using namespace' is not allowed in classes}} 89757d036SJohn McCall }; 99757d036SJohn McCall } 109757d036SJohn McCall 119757d036SJohn McCall 129757d036SJohn McCall struct opaque0 {}; 139757d036SJohn McCall struct opaque1 {}; 149757d036SJohn McCall 159757d036SJohn McCall // Test that names appear as if in deepest common ancestor. 169757d036SJohn McCall namespace test1 { 179757d036SJohn McCall namespace A { 189757d036SJohn McCall namespace B { 199757d036SJohn McCall opaque0 foo(); // expected-note {{candidate}} 209757d036SJohn McCall } 219757d036SJohn McCall } 229757d036SJohn McCall 239757d036SJohn McCall namespace C { 249757d036SJohn McCall opaque1 foo(); // expected-note {{candidate}} 259757d036SJohn McCall test()269757d036SJohn McCall opaque1 test() { 279757d036SJohn McCall using namespace A::B; 289757d036SJohn McCall return foo(); // C::foo 299757d036SJohn McCall } 309757d036SJohn McCall } 319757d036SJohn McCall test()329757d036SJohn McCall opaque1 test() { 339757d036SJohn McCall using namespace A::B; 349757d036SJohn McCall using namespace C; 359757d036SJohn McCall return foo(); // expected-error {{call to 'foo' is ambiguous}} 369757d036SJohn McCall } 379757d036SJohn McCall } 389757d036SJohn McCall 399757d036SJohn McCall // Same thing, but with the directives in namespaces. 409757d036SJohn McCall namespace test2 { 419757d036SJohn McCall namespace A { 429757d036SJohn McCall namespace B { 439757d036SJohn McCall opaque0 foo(); // expected-note {{candidate}} 449757d036SJohn McCall } 459757d036SJohn McCall } 469757d036SJohn McCall 479757d036SJohn McCall namespace C { 489757d036SJohn McCall opaque1 foo(); // expected-note {{candidate}} 499757d036SJohn McCall 509757d036SJohn McCall namespace test { 519757d036SJohn McCall using namespace A::B; 529757d036SJohn McCall test()539757d036SJohn McCall opaque1 test() { 549757d036SJohn McCall return foo(); // C::foo 559757d036SJohn McCall } 569757d036SJohn McCall } 579757d036SJohn McCall } 589757d036SJohn McCall 599757d036SJohn McCall namespace test { 609757d036SJohn McCall using namespace A::B; 619757d036SJohn McCall using namespace C; 629757d036SJohn McCall test()639757d036SJohn McCall opaque1 test() { 649757d036SJohn McCall return foo(); // expected-error {{call to 'foo' is ambiguous}} 659757d036SJohn McCall } 669757d036SJohn McCall } 679757d036SJohn McCall } 689757d036SJohn McCall 699757d036SJohn McCall // Transitivity. 709757d036SJohn McCall namespace test3 { 719757d036SJohn McCall namespace A { 729757d036SJohn McCall namespace B { 739757d036SJohn McCall opaque0 foo(); 749757d036SJohn McCall } 759757d036SJohn McCall } 769757d036SJohn McCall namespace C { 779757d036SJohn McCall using namespace A; 789757d036SJohn McCall } 799757d036SJohn McCall test0()809757d036SJohn McCall opaque0 test0() { 819757d036SJohn McCall using namespace C; 829757d036SJohn McCall using namespace B; 839757d036SJohn McCall return foo(); 849757d036SJohn McCall } 859757d036SJohn McCall 869757d036SJohn McCall namespace D { 879757d036SJohn McCall using namespace C; 889757d036SJohn McCall } 899757d036SJohn McCall namespace A { 909757d036SJohn McCall opaque1 foo(); 919757d036SJohn McCall } 929757d036SJohn McCall test1()939757d036SJohn McCall opaque1 test1() { 949757d036SJohn McCall using namespace D; 959757d036SJohn McCall return foo(); 969757d036SJohn McCall } 979757d036SJohn McCall } 989757d036SJohn McCall 999757d036SJohn McCall // Transitivity acts like synthetic using directives. 1009757d036SJohn McCall namespace test4 { 1019757d036SJohn McCall namespace A { 1029757d036SJohn McCall namespace B { 1039757d036SJohn McCall opaque0 foo(); // expected-note {{candidate}} 1049757d036SJohn McCall } 1059757d036SJohn McCall } 1069757d036SJohn McCall 1079757d036SJohn McCall namespace C { 1089757d036SJohn McCall using namespace A::B; 1099757d036SJohn McCall } 1109757d036SJohn McCall 1119757d036SJohn McCall opaque1 foo(); // expected-note {{candidate}} 1129757d036SJohn McCall 1139757d036SJohn McCall namespace A { 1149757d036SJohn McCall namespace D { 1159757d036SJohn McCall using namespace C; 1169757d036SJohn McCall } 1179757d036SJohn McCall test()1189757d036SJohn McCall opaque0 test() { 1199757d036SJohn McCall using namespace D; 1209757d036SJohn McCall return foo(); 1219757d036SJohn McCall } 1229757d036SJohn McCall } 1239757d036SJohn McCall test()1249757d036SJohn McCall opaque0 test() { 1259757d036SJohn McCall using namespace A::D; 1269757d036SJohn McCall return foo(); // expected-error {{call to 'foo' is ambiguous}} 1279757d036SJohn McCall } 1289757d036SJohn McCall } 129caef2448SJohn McCall 130caef2448SJohn McCall // Bug: using directives should be followed when parsing default 131caef2448SJohn McCall // arguments in scoped declarations. 132caef2448SJohn McCall class test5 { 133caef2448SJohn McCall int inc(int x); 134caef2448SJohn McCall }; 135caef2448SJohn McCall namespace Test5 { 136caef2448SJohn McCall int default_x = 0; 137caef2448SJohn McCall } 138caef2448SJohn McCall using namespace Test5; inc(int x=default_x)139caef2448SJohn McCallint test5::inc(int x = default_x) { 140caef2448SJohn McCall return x+1; 141caef2448SJohn McCall } 142