1 // RUN: %clang_cc1 -fsyntax-only -std=c++98 -verify -fblocks %s 2 namespace A { 3 struct C { 4 static int cx; 5 6 static int cx2; 7 8 static int Ag1(); 9 static int Ag2(); 10 }; 11 int ax; 12 void Af(); 13 } 14 15 A:: ; // expected-error {{expected unqualified-id}} 16 // FIXME: there is a member 'ax'; it's just not a class. 17 ::A::ax::undef ex3; // expected-error {{no member named 'ax'}} 18 A::undef1::undef2 ex4; // expected-error {{no member named 'undef1'}} 19 20 int A::C::Ag1() { return 0; } 21 22 static int A::C::Ag2() { return 0; } // expected-error{{'static' can}} 23 24 int A::C::cx = 17; 25 26 27 static int A::C::cx2 = 17; // expected-error{{'static' can}} 28 29 class C2 { 30 void m(); // expected-note{{member declaration does not match because it is not const qualified}} 31 32 void f(const int& parm); // expected-note{{type of 1st parameter of member declaration does not match definition ('const int &' vs 'int')}} 33 void f(int) const; // expected-note{{member declaration does not match because it is const qualified}} 34 void f(float); 35 36 int x; 37 }; 38 39 void C2::m() const { } // expected-error{{out-of-line definition of 'm' does not match any declaration in 'C2'}} 40 41 void C2::f(int) { } // expected-error{{out-of-line definition of 'f' does not match any declaration in 'C2'}} 42 43 void C2::m() { 44 x = 0; 45 } 46 47 namespace B { 48 void ::A::Af() {} // expected-error {{cannot define or redeclare 'Af' here because namespace 'B' does not enclose namespace 'A'}} 49 } 50 51 void f1() { 52 void A::Af(); // expected-error {{definition or redeclaration of 'Af' not allowed inside a function}} 53 void (^x)() = ^{ void A::Af(); }; // expected-error {{definition or redeclaration of 'Af' not allowed inside a block}} 54 } 55 56 void f2() { 57 A:: ; // expected-error {{expected unqualified-id}} 58 A::C::undef = 0; // expected-error {{no member named 'undef'}} 59 ::A::C::cx = 0; 60 int x = ::A::ax = A::C::cx; 61 x = sizeof(A::C); 62 x = sizeof(::A::C::cx); 63 } 64 65 A::C c1; 66 struct A::C c2; 67 struct S : public A::C {}; 68 struct A::undef; // expected-error {{no struct named 'undef' in namespace 'A'}} 69 70 namespace A2 { 71 typedef int INT; 72 struct RC; 73 struct CC { 74 struct NC; 75 }; 76 } 77 78 struct A2::RC { 79 INT x; 80 }; 81 82 struct A2::CC::NC { 83 void m() {} 84 }; 85 86 void f3() { 87 N::x = 0; // expected-error {{use of undeclared identifier 'N'}} 88 // FIXME: Consider including the kind of entity that 'N' is ("variable 'N' 89 // declared here", "template 'X' declared here", etc) to help explain what it 90 // is if it's 'not a class, namespace, or scoped enumeration'. 91 int N; // expected-note {{'N' declared here}} 92 N::x = 0; // expected-error {{'N' is not a class, namespace, or scoped enumeration}} 93 { int A; A::ax = 0; } 94 { typedef int A; A::ax = 0; } // expected-error{{'A' (aka 'int') is not a class, namespace, or scoped enumeration}} 95 { typedef A::C A; A::ax = 0; } // expected-error {{no member named 'ax'}} 96 { typedef A::C A; A::cx = 0; } 97 } 98 99 // make sure the following doesn't hit any asserts 100 void f4(undef::C); // expected-error {{use of undeclared identifier 'undef'}} 101 102 typedef void C2::f5(int); // expected-error{{typedef declarator cannot be qualified}} 103 104 void f6(int A2::RC::x); // expected-error{{parameter declarator cannot be qualified}} 105 106 int A2::RC::x; // expected-error{{non-static data member defined out-of-line}} 107 108 void A2::CC::NC::m(); // expected-error{{out-of-line declaration of a member must be a definition}} 109 110 111 namespace E { 112 int X = 5; 113 114 namespace Nested { 115 enum E { 116 X = 0 117 }; 118 119 void f() { 120 return E::X; // expected-error{{'E::Nested::E' is not a class, namespace, or scoped enumeration}} 121 } 122 } 123 } 124 125 126 class Operators { 127 Operators operator+(const Operators&) const; // expected-note{{member declaration does not match because it is const qualified}} 128 operator bool(); 129 }; 130 131 Operators Operators::operator+(const Operators&) { // expected-error{{out-of-line definition of 'operator+' does not match any declaration in 'Operators'}} 132 Operators ops; 133 return ops; 134 } 135 136 Operators Operators::operator+(const Operators&) const { 137 Operators ops; 138 return ops; 139 } 140 141 Operators::operator bool() { 142 return true; 143 } 144 145 namespace A { 146 void g(int&); // expected-note{{type of 1st parameter of member declaration does not match definition ('int &' vs 'const int &')}} 147 } 148 149 void A::f() {} // expected-error-re{{out-of-line definition of 'f' does not match any declaration in namespace 'A'{{$}}}} 150 151 void A::g(const int&) { } // expected-error{{out-of-line definition of 'g' does not match any declaration in namespace 'A'}} 152 153 struct Struct { }; 154 155 void Struct::f() { } // expected-error{{out-of-line definition of 'f' does not match any declaration in 'Struct'}} 156 157 void global_func(int); 158 void global_func2(int); 159 160 namespace N { 161 void ::global_func(int) { } // expected-error{{definition or redeclaration of 'global_func' cannot name the global scope}} 162 163 void f(); 164 // FIXME: if we move this to a separate definition of N, things break! 165 } 166 void ::global_func2(int) { } // expected-warning{{extra qualification on member 'global_func2'}} 167 168 void N::f() { } // okay 169 170 struct Y; // expected-note{{forward declaration of 'Y'}} 171 Y::foo y; // expected-error{{incomplete type 'Y' named in nested name specifier}} 172 173 X::X() : a(5) { } // expected-error{{use of undeclared identifier 'X'}} 174 175 struct foo_S { 176 static bool value; 177 }; 178 bool (foo_S::value); 179 180 181 namespace somens { 182 struct a { }; // expected-note{{candidate constructor (the implicit copy constructor)}} 183 } 184 185 template <typename T> 186 class foo { 187 }; 188 189 190 // PR4452 / PR4451 191 foo<somens:a> a2; // expected-error {{unexpected ':' in nested name specifier}} 192 193 somens::a a3 = a2; // expected-error {{no viable conversion}} 194 195 // typedefs and using declarations. 196 namespace test1 { 197 namespace ns { 198 class Counter { public: static int count; }; 199 typedef Counter counter; 200 } 201 using ns::counter; 202 203 class Test { 204 void test1() { 205 counter c; 206 c.count++; 207 counter::count++; 208 } 209 }; 210 } 211 212 // We still need to do lookup in the lexical scope, even if we push a 213 // non-lexical scope. 214 namespace test2 { 215 namespace ns { 216 extern int *count_ptr; 217 } 218 namespace { 219 int count = 0; 220 } 221 222 int *ns::count_ptr = &count; 223 } 224 225 // PR6259, invalid case 226 namespace test3 { 227 class A; // expected-note {{forward declaration}} 228 void foo(const char *path) { 229 A::execute(path); // expected-error {{incomplete type 'test3::A' named in nested name specifier}} 230 } 231 } 232 233 namespace PR7133 { 234 namespace A { 235 class Foo; 236 } 237 238 namespace A { 239 namespace B { 240 bool foo(Foo &); 241 } 242 } 243 244 bool A::B::foo(Foo &) { 245 return false; 246 } 247 } 248 249 class CLASS { 250 void CLASS::foo2(); // expected-error {{extra qualification on member 'foo2'}} 251 }; 252 253 namespace PR8159 { 254 class B { }; 255 256 class A { 257 int A::a; // expected-error{{extra qualification on member 'a'}} 258 static int A::b; // expected-error{{extra qualification on member 'b'}} 259 int ::c; // expected-error{{non-friend class member 'c' cannot have a qualified name}} 260 }; 261 } 262 263 namespace rdar7980179 { 264 class A { void f0(); }; // expected-note {{previous}} 265 int A::f0() {} // expected-error {{return type of out-of-line definition of 'rdar7980179::A::f0' differs}} 266 } 267 268 namespace alias = A; 269 double *dp = (alias::C*)0; // expected-error{{cannot initialize a variable of type 'double *' with an rvalue of type 'alias::C *'}} 270 271 // http://llvm.org/PR10109 272 namespace PR10109 { 273 template<typename T> 274 struct A { 275 protected: 276 struct B; 277 struct B::C; // expected-error {{requires a template parameter list}} \ 278 // expected-error {{no struct named 'C'}} \ 279 // expected-error{{non-friend class member 'C' cannot have a qualified name}} 280 }; 281 282 template<typename T> 283 struct A2 { 284 protected: 285 struct B; 286 }; 287 template <typename T> 288 struct A2<T>::B::C; // expected-error {{no struct named 'C'}} 289 } 290 291 namespace PR13033 { 292 namespace NS { 293 int a; // expected-note {{'NS::a' declared here}} 294 int longer_b; //expected-note {{'NS::longer_b' declared here}} 295 } 296 297 // Suggest adding a namespace qualifier to both variable names even though one 298 // is only a single character long. 299 int foobar = a + longer_b; // expected-error {{use of undeclared identifier 'a'; did you mean 'NS::a'?}} \ 300 // expected-error {{use of undeclared identifier 'longer_b'; did you mean 'NS::longer_b'?}} 301 } 302 303 // <rdar://problem/13853540> 304 namespace N { 305 struct X { }; 306 namespace N { 307 struct Foo { 308 struct N::X *foo(); // expected-error{{no struct named 'X' in namespace 'N::N'}} 309 }; 310 } 311 } 312 313 namespace TypedefNamespace { typedef int F; }; 314 TypedefNamespace::F::NonexistentName BadNNSWithCXXScopeSpec; // expected-error {{'F' (aka 'int') is not a class, namespace, or scoped enumeration}} 315