18fbe78f6SDaniel Dunbar // RUN: %clang_cc1 -fsyntax-only -verify %s 291f84216SDouglas Gregor namespace Ns { 391f84216SDouglas Gregor int f(); // expected-note{{previous declaration is here}} 407665a69SDouglas Gregor 507665a69SDouglas Gregor enum E { 607665a69SDouglas Gregor Enumerator 707665a69SDouglas Gregor }; 891f84216SDouglas Gregor } 991f84216SDouglas Gregor namespace Ns { 1091f84216SDouglas Gregor double f(); // expected-error{{functions that differ only in their return type cannot be overloaded}} 1107665a69SDouglas Gregor 1207665a69SDouglas Gregor int x = Enumerator; 1391f84216SDouglas Gregor } 1491f84216SDouglas Gregor 1591f84216SDouglas Gregor namespace Ns2 { 1691f84216SDouglas Gregor float f(); 1791f84216SDouglas Gregor } 1891f84216SDouglas Gregor 1907665a69SDouglas Gregor int y = Ns::Enumerator; 2007665a69SDouglas Gregor 2191f84216SDouglas Gregor namespace Ns2 { 2291f84216SDouglas Gregor float f(int); // expected-note{{previous declaration is here}} 2391f84216SDouglas Gregor } 2491f84216SDouglas Gregor 2591f84216SDouglas Gregor namespace Ns2 { 2691f84216SDouglas Gregor double f(int); // expected-error{{functions that differ only in their return type cannot be overloaded}} 2791f84216SDouglas Gregor } 2891f84216SDouglas Gregor 2991f84216SDouglas Gregor namespace N { 3091f84216SDouglas Gregor int& f1(); 3191f84216SDouglas Gregor } 3291f84216SDouglas Gregor 3391f84216SDouglas Gregor namespace N { 3491f84216SDouglas Gregor struct f1 { 3591f84216SDouglas Gregor static int member; 3602a0acd0SDouglas Gregor 3702a0acd0SDouglas Gregor typedef int type; 3802a0acd0SDouglas Gregor 3902a0acd0SDouglas Gregor void foo(type); 4091f84216SDouglas Gregor }; 4191f84216SDouglas Gregor test_f1()4291f84216SDouglas Gregor void test_f1() { 4391f84216SDouglas Gregor int &i1 = f1(); 4491f84216SDouglas Gregor } 4591f84216SDouglas Gregor } 4691f84216SDouglas Gregor foo(int i)47dee1be8eSDouglas Gregorvoid N::f1::foo(int i) { 48dee1be8eSDouglas Gregor f1::member = i; 49dee1be8eSDouglas Gregor f1::type &ir = i; 50dee1be8eSDouglas Gregor } 5102a0acd0SDouglas Gregor 5291f84216SDouglas Gregor namespace N { f1(int x)5302a0acd0SDouglas Gregor float& f1(int x) { 5402a0acd0SDouglas Gregor N::f1::type& i1 = x; 5534074326SDouglas Gregor f1::type& i2 = x; 5602a0acd0SDouglas Gregor } 5791f84216SDouglas Gregor 5891f84216SDouglas Gregor struct f2 { 5991f84216SDouglas Gregor static int member; 6091f84216SDouglas Gregor }; 6191f84216SDouglas Gregor void f2(); 6291f84216SDouglas Gregor } 6391f84216SDouglas Gregor 6491f84216SDouglas Gregor int i1 = N::f1::member; 6591f84216SDouglas Gregor typedef struct N::f1 type1; 6691f84216SDouglas Gregor int i2 = N::f2::member; 6791f84216SDouglas Gregor typedef struct N::f2 type2; 6891f84216SDouglas Gregor test_f1(int i)6991f84216SDouglas Gregorvoid test_f1(int i) { 7091f84216SDouglas Gregor int &v1 = N::f1(); 7191f84216SDouglas Gregor float &v2 = N::f1(i); 726fead6e3SChris Lattner int v3 = ::i1; 73c7acfdfeSDouglas Gregor int v4 = N::f1::member; 7491f84216SDouglas Gregor } 756fead6e3SChris Lattner 76c69537feSChris Lattner typedef int f2_type; 77c69537feSChris Lattner namespace a { 78c69537feSChris Lattner typedef int f2_type(int, int); 79c69537feSChris Lattner test_f2()80c69537feSChris Lattner void test_f2() { 818ec5173fSDouglas Gregor ::f2_type(1, 2); // expected-error {{excess elements in scalar initializer}} 82c69537feSChris Lattner } 83c69537feSChris Lattner } 84c69537feSChris Lattner 85f3252787SDouglas Gregor // PR clang/3291 86f3252787SDouglas Gregor namespace a { 87f3252787SDouglas Gregor namespace a { // A1 88f3252787SDouglas Gregor namespace a { // A2 89f7b63e3eSKaelyn Uhrain int i; // expected-note{{'a::a::a::i' declared here}} 90f3252787SDouglas Gregor } 91f3252787SDouglas Gregor } 92f3252787SDouglas Gregor } 93f3252787SDouglas Gregor test_a()94f3252787SDouglas Gregorvoid test_a() { 95f7b63e3eSKaelyn Uhrain a::a::i = 3; // expected-error{{no member named 'i' in namespace 'a::a'; did you mean 'a::a::a::i'?}} 96f3252787SDouglas Gregor a::a::a::i = 4; 97*6ed72516SAlp Toker a::a::j = 3; // expected-error-re{{no member named 'j' in namespace 'a::a'{{$}}}} 98f3252787SDouglas Gregor } 99c69537feSChris Lattner 10085f90559SJohn McCall struct Undef { // expected-note{{definition of 'Undef' is not complete until the closing '}'}} 101dee1be8eSDouglas Gregor typedef int type; 102dee1be8eSDouglas Gregor 103dee1be8eSDouglas Gregor Undef::type member; 104dee1be8eSDouglas Gregor 10585f90559SJohn McCall static int size = sizeof(Undef); // expected-error{{invalid application of 'sizeof' to an incomplete type 'Undef'}} 106dee1be8eSDouglas Gregor 107dee1be8eSDouglas Gregor int f(); 108dee1be8eSDouglas Gregor }; 109dee1be8eSDouglas Gregor f()110dee1be8eSDouglas Gregorint Undef::f() { 111dee1be8eSDouglas Gregor return sizeof(Undef); 112dee1be8eSDouglas Gregor } 1131a49e9dcSJohn McCall 1141a49e9dcSJohn McCall // PR clang/5667 1151a49e9dcSJohn McCall namespace test1 { 1161a49e9dcSJohn McCall template <typename T> struct is_class { 1171a49e9dcSJohn McCall enum { value = 0 }; 1181a49e9dcSJohn McCall }; 1191a49e9dcSJohn McCall 1201a49e9dcSJohn McCall template <typename T> class ClassChecker { isClass()1211a49e9dcSJohn McCall bool isClass() { 1221a49e9dcSJohn McCall return is_class<T>::value; 1231a49e9dcSJohn McCall } 1241a49e9dcSJohn McCall }; 1251a49e9dcSJohn McCall 1261a49e9dcSJohn McCall template class ClassChecker<int>; 1271a49e9dcSJohn McCall } 1282c4a7501SDouglas Gregor 1292c4a7501SDouglas Gregor namespace PR6830 { 1302c4a7501SDouglas Gregor namespace foo { 1312c4a7501SDouglas Gregor 1322c4a7501SDouglas Gregor class X { 1332c4a7501SDouglas Gregor public: X()1342c4a7501SDouglas Gregor X() {} 1352c4a7501SDouglas Gregor }; 1362c4a7501SDouglas Gregor 1372c4a7501SDouglas Gregor } // namespace foo 1382c4a7501SDouglas Gregor 1392c4a7501SDouglas Gregor class Z { 1402c4a7501SDouglas Gregor public: Z(const foo::X & x)1412c4a7501SDouglas Gregor explicit Z(const foo::X& x) {} 1422c4a7501SDouglas Gregor Work()1432c4a7501SDouglas Gregor void Work() {} 1442c4a7501SDouglas Gregor }; 1452c4a7501SDouglas Gregor Test()1462c4a7501SDouglas Gregor void Test() { 1472c4a7501SDouglas Gregor Z(foo::X()).Work(); 1482c4a7501SDouglas Gregor } 1492c4a7501SDouglas Gregor } 150c3921484SNick Lewycky 151c3921484SNick Lewycky namespace pr12339 { 1520ffa3317SDavid Majnemer extern "C" void i; // expected-error{{variable has incomplete type 'void'}} 153c3921484SNick Lewycky pr12339::FOO // expected-error{{no type named 'FOO' in namespace 'pr12339'}} 154c3921484SNick Lewycky } // expected-error{{expected unqualified-id}} 155