1 // RUN: %clang_cc1 -fsyntax-only -verify %s 2 namespace Ns { 3 int f(); // expected-note{{previous declaration is here}} 4 5 enum E { 6 Enumerator 7 }; 8 } 9 namespace Ns { 10 double f(); // expected-error{{functions that differ only in their return type cannot be overloaded}} 11 12 int x = Enumerator; 13 } 14 15 namespace Ns2 { 16 float f(); 17 } 18 19 int y = Ns::Enumerator; 20 21 namespace Ns2 { 22 float f(int); // expected-note{{previous declaration is here}} 23 } 24 25 namespace Ns2 { 26 double f(int); // expected-error{{functions that differ only in their return type cannot be overloaded}} 27 } 28 29 namespace N { 30 int& f1(); 31 } 32 33 namespace N { 34 struct f1 { 35 static int member; 36 37 typedef int type; 38 39 void foo(type); 40 }; 41 42 void test_f1() { 43 int &i1 = f1(); 44 } 45 } 46 47 void N::f1::foo(int i) { 48 f1::member = i; 49 f1::type &ir = i; 50 } 51 52 namespace N { 53 float& f1(int x) { 54 N::f1::type& i1 = x; 55 f1::type& i2 = x; 56 } 57 58 struct f2 { 59 static int member; 60 }; 61 void f2(); 62 } 63 64 int i1 = N::f1::member; 65 typedef struct N::f1 type1; 66 int i2 = N::f2::member; 67 typedef struct N::f2 type2; 68 69 void test_f1(int i) { 70 int &v1 = N::f1(); 71 float &v2 = N::f1(i); 72 int v3 = ::i1; 73 int v4 = N::f1::member; 74 } 75 76 typedef int f2_type; 77 namespace a { 78 typedef int f2_type(int, int); 79 80 void test_f2() { 81 ::f2_type(1, 2); // expected-error {{excess elements in scalar initializer}} 82 } 83 } 84 85 // PR clang/3291 86 namespace a { 87 namespace a { // A1 88 namespace a { // A2 89 int i; 90 } 91 } 92 } 93 94 void test_a() { 95 a::a::i = 3; // expected-error{{no member named 'i'}} 96 a::a::a::i = 4; 97 } 98 99 struct Undef { // expected-note{{definition of 'Undef' is not complete until the closing '}'}} 100 typedef int type; 101 102 Undef::type member; 103 104 static int size = sizeof(Undef); // expected-error{{invalid application of 'sizeof' to an incomplete type 'Undef'}} 105 106 int f(); 107 }; 108 109 int Undef::f() { 110 return sizeof(Undef); 111 } 112 113 // PR clang/5667 114 namespace test1 { 115 template <typename T> struct is_class { 116 enum { value = 0 }; 117 }; 118 119 template <typename T> class ClassChecker { 120 bool isClass() { 121 return is_class<T>::value; 122 } 123 }; 124 125 template class ClassChecker<int>; 126 } 127 128 namespace PR6830 { 129 namespace foo { 130 131 class X { 132 public: 133 X() {} 134 }; 135 136 } // namespace foo 137 138 class Z { 139 public: 140 explicit Z(const foo::X& x) {} 141 142 void Work() {} 143 }; 144 145 void Test() { 146 Z(foo::X()).Work(); 147 } 148 } 149