1// RUN: %clang_cc1 -fsyntax-only -std=c++98 -verify -fblocks %s 2namespace 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; // expected-note {{'ax' declared here}} 12 void Af(); 13} 14 15A:: ; // expected-error {{expected unqualified-id}} 16::A::ax::undef ex3; // expected-error {{'ax' is not a class, namespace, or enumeration}} 17A::undef1::undef2 ex4; // expected-error {{no member named 'undef1'}} 18 19int A::C::Ag1() { return 0; } 20 21static int A::C::Ag2() { return 0; } // expected-error{{'static' can}} 22 23int A::C::cx = 17; 24 25 26static int A::C::cx2 = 17; // expected-error{{'static' can}} 27 28class C2 { 29 void m(); // expected-note{{member declaration does not match because it is not const qualified}} 30 31 void f(const int& parm); // expected-note{{type of 1st parameter of member declaration does not match definition ('const int &' vs 'int')}} 32 void f(int) const; // expected-note{{member declaration does not match because it is const qualified}} 33 void f(float); 34 35 int x; 36}; 37 38void C2::m() const { } // expected-error{{out-of-line definition of 'm' does not match any declaration in 'C2'}} 39 40void C2::f(int) { } // expected-error{{out-of-line definition of 'f' does not match any declaration in 'C2'}} 41 42void C2::m() { 43 x = 0; 44} 45 46namespace B { 47 void ::A::Af() {} // expected-error {{cannot define or redeclare 'Af' here because namespace 'B' does not enclose namespace 'A'}} 48} 49 50void f1() { 51 void A::Af(); // expected-error {{definition or redeclaration of 'Af' not allowed inside a function}} 52 void (^x)() = ^{ void A::Af(); }; // expected-error {{definition or redeclaration of 'Af' not allowed inside a block}} 53} 54 55void f2() { 56 A:: ; // expected-error {{expected unqualified-id}} 57 A::C::undef = 0; // expected-error {{no member named 'undef'}} 58 ::A::C::cx = 0; 59 int x = ::A::ax = A::C::cx; 60 x = sizeof(A::C); 61 x = sizeof(::A::C::cx); 62} 63 64A::C c1; 65struct A::C c2; 66struct S : public A::C {}; 67struct A::undef; // expected-error {{no struct named 'undef' in namespace 'A'}} 68 69namespace A2 { 70 typedef int INT; 71 struct RC; 72 struct CC { 73 struct NC; 74 }; 75} 76 77struct A2::RC { 78 INT x; 79}; 80 81struct A2::CC::NC { 82 void m() {} 83}; 84 85void f3() { 86 N::x = 0; // expected-error {{use of undeclared identifier 'N'}} 87 // FIXME: Consider including the kind of entity that 'N' is ("variable 'N' 88 // declared here", "template 'X' declared here", etc) to help explain what it 89 // is if it's 'not a class, namespace, or scoped enumeration'. 90 int N; // expected-note {{'N' declared here}} 91 N::x = 0; // expected-error {{'N' is not a class, namespace, or enumeration}} 92 { int A; A::ax = 0; } 93 { typedef int A; A::ax = 0; } // expected-error{{'A' (aka 'int') is not a class, namespace, or enumeration}} 94 { typedef A::C A; A::ax = 0; } // expected-error {{no member named 'ax'}} 95 { typedef A::C A; A::cx = 0; } 96} 97 98// make sure the following doesn't hit any asserts 99void f4(undef::C); // expected-error {{use of undeclared identifier 'undef'}} 100 101typedef void C2::f5(int); // expected-error{{typedef declarator cannot be qualified}} 102 103void f6(int A2::RC::x); // expected-error{{parameter declarator cannot be qualified}} 104 105int A2::RC::x; // expected-error{{non-static data member defined out-of-line}} 106 107void A2::CC::NC::m(); // expected-error{{out-of-line declaration of a member must be a definition}} 108 109 110namespace E { 111 int X = 5; 112 113 namespace Nested { 114 enum E { 115 X = 0 116 }; 117 118 int f() { 119 return E::X; // expected-warning{{use of enumeration in a nested name specifier is a C++11 extension}} 120 } 121 } 122} 123 124 125class Operators { 126 Operators operator+(const Operators&) const; // expected-note{{member declaration does not match because it is const qualified}} 127 operator bool(); 128}; 129 130Operators Operators::operator+(const Operators&) { // expected-error{{out-of-line definition of 'operator+' does not match any declaration in 'Operators'}} 131 Operators ops; 132 return ops; 133} 134 135Operators Operators::operator+(const Operators&) const { 136 Operators ops; 137 return ops; 138} 139 140Operators::operator bool() { 141 return true; 142} 143 144namespace A { 145 void g(int&); // expected-note{{type of 1st parameter of member declaration does not match definition ('int &' vs 'const int &')}} 146} 147 148void A::f() {} // expected-error-re{{out-of-line definition of 'f' does not match any declaration in namespace 'A'{{$}}}} 149 150void A::g(const int&) { } // expected-error{{out-of-line definition of 'g' does not match any declaration in namespace 'A'}} 151 152struct Struct { }; 153 154void Struct::f() { } // expected-error{{out-of-line definition of 'f' does not match any declaration in 'Struct'}} 155 156void global_func(int); 157void global_func2(int); 158 159namespace N { 160 void ::global_func(int) { } // expected-error{{definition or redeclaration of 'global_func' cannot name the global scope}} 161 162 void f(); 163 // FIXME: if we move this to a separate definition of N, things break! 164} 165void ::global_func2(int) { } // expected-warning{{extra qualification on member 'global_func2'}} 166 167void N::f() { } // okay 168 169struct Y; // expected-note{{forward declaration of 'Y'}} 170Y::foo y; // expected-error{{incomplete type 'Y' named in nested name specifier}} 171 172X::X() : a(5) { } // expected-error{{use of undeclared identifier 'X'}} 173 174struct foo_S { 175 static bool value; 176}; 177bool (foo_S::value); 178 179 180namespace somens { 181 struct a { }; // expected-note{{candidate constructor (the implicit copy constructor)}} 182} 183 184template <typename T> 185class foo { 186}; 187 188 189// PR4452 / PR4451 190foo<somens:a> a2; // expected-error {{unexpected ':' in nested name specifier}} 191 192somens::a a3 = a2; // expected-error {{no viable conversion}} 193 194// typedefs and using declarations. 195namespace test1 { 196 namespace ns { 197 class Counter { public: static int count; }; 198 typedef Counter counter; 199 } 200 using ns::counter; 201 202 class Test { 203 void test1() { 204 counter c; 205 c.count++; 206 counter::count++; 207 } 208 }; 209} 210 211// We still need to do lookup in the lexical scope, even if we push a 212// non-lexical scope. 213namespace test2 { 214 namespace ns { 215 extern int *count_ptr; 216 } 217 namespace { 218 int count = 0; 219 } 220 221 int *ns::count_ptr = &count; 222} 223 224// PR6259, invalid case 225namespace test3 { 226 class A; // expected-note {{forward declaration}} 227 void foo(const char *path) { 228 A::execute(path); // expected-error {{incomplete type 'test3::A' named in nested name specifier}} 229 } 230} 231 232namespace PR7133 { 233 namespace A { 234 class Foo; 235 } 236 237 namespace A { 238 namespace B { 239 bool foo(Foo &); 240 } 241 } 242 243 bool A::B::foo(Foo &) { 244 return false; 245 } 246} 247 248class CLASS { 249 void CLASS::foo2(); // expected-error {{extra qualification on member 'foo2'}} 250}; 251 252namespace PR8159 { 253 class B { }; 254 255 class A { 256 int A::a; // expected-error{{extra qualification on member 'a'}} 257 static int A::b; // expected-error{{extra qualification on member 'b'}} 258 int ::c; // expected-error{{non-friend class member 'c' cannot have a qualified name}} 259 }; 260} 261 262namespace rdar7980179 { 263 class A { void f0(); }; // expected-note {{previous}} 264 int A::f0() {} // expected-error {{return type of out-of-line definition of 'rdar7980179::A::f0' differs}} 265} 266 267namespace alias = A; 268double *dp = (alias::C*)0; // expected-error{{cannot initialize a variable of type 'double *' with an rvalue of type 'alias::C *'}} 269 270// http://llvm.org/PR10109 271namespace PR10109 { 272template<typename T> 273struct A { 274protected: 275 struct B; 276 struct B::C; // expected-error {{requires a template parameter list}} \ 277 // expected-error {{no struct named 'C'}} \ 278 // expected-error{{non-friend class member 'C' cannot have a qualified name}} 279}; 280 281template<typename T> 282struct A2 { 283protected: 284 struct B; 285}; 286template <typename T> 287struct A2<T>::B::C; // expected-error {{no struct named 'C'}} 288} 289 290namespace PR13033 { 291namespace NS { 292 int a; // expected-note {{'NS::a' declared here}} 293 int longer_b; //expected-note {{'NS::longer_b' declared here}} 294} 295 296// Suggest adding a namespace qualifier to both variable names even though one 297// is only a single character long. 298int foobar = a + longer_b; // expected-error {{use of undeclared identifier 'a'; did you mean 'NS::a'?}} \ 299 // expected-error {{use of undeclared identifier 'longer_b'; did you mean 'NS::longer_b'?}} 300} 301 302// <rdar://problem/13853540> 303namespace N { 304 struct X { }; 305 namespace N { 306 struct Foo { 307 struct N::X *foo(); // expected-error{{no struct named 'X' in namespace 'N::N'}} 308 }; 309 } 310} 311 312namespace TypedefNamespace { typedef int F; }; 313TypedefNamespace::F::NonexistentName BadNNSWithCXXScopeSpec; // expected-error {{'F' (aka 'int') is not a class, namespace, or enumeration}} 314 315namespace PR18587 { 316 317struct C1 { 318 int a, b, c; 319 typedef int C2; 320 struct B1 { 321 struct B2 { 322 int a, b, c; 323 }; 324 }; 325}; 326struct C2 { static const unsigned N1 = 1; }; 327struct B1 { 328 enum E1 { B2 = 2 }; 329 static const int B3 = 3; 330}; 331const int N1 = 2; 332 333// Function declarators 334struct S1a { int f(C1::C2); }; 335struct S1b { int f(C1:C2); }; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}} 336 337struct S2a { 338 C1::C2 f(C1::C2); 339}; 340struct S2c { 341 C1::C2 f(C1:C2); // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}} 342}; 343 344struct S3a { 345 int f(C1::C2), C2 : N1; 346 int g : B1::B2; 347}; 348struct S3b { 349 int g : B1:B2; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}} 350}; 351 352// Inside square brackets 353struct S4a { 354 int f[C2::N1]; 355}; 356struct S4b { 357 int f[C2:N1]; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}} 358}; 359 360struct S5a { 361 int f(int xx[B1::B3 ? C2::N1 : B1::B2]); 362}; 363struct S5b { 364 int f(int xx[B1::B3 ? C2::N1 : B1:B2]); // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}} 365}; 366struct S5c { 367 int f(int xx[B1:B3 ? C2::N1 : B1::B2]); // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}} 368}; 369 370// Bit fields 371struct S6a { 372 C1::C2 m1 : B1::B2; 373}; 374struct S6c { 375 C1::C2 m1 : B1:B2; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}} 376}; 377struct S6d { 378 int C2:N1; 379}; 380struct S6e { 381 static const int N = 3; 382 B1::E1 : N; 383}; 384struct S6g { 385 C1::C2 : B1:B2; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}} 386 B1::E1 : B1:B2; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}} 387}; 388 389// Template parameters 390template <int N> struct T1 { 391 int a,b,c; 392 static const unsigned N1 = N; 393 typedef unsigned C1; 394}; 395T1<C2::N1> var_1a; 396T1<C2:N1> var_1b; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}} 397template<int N> int F() {} 398int (*X1)() = (B1::B2 ? F<1> : F<2>); 399int (*X2)() = (B1:B2 ? F<1> : F<2>); // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}} 400 401// Bit fields + templates 402struct S7a { 403 T1<B1::B2>::C1 m1 : T1<B1::B2>::N1; 404}; 405struct S7b { 406 T1<B1:B2>::C1 m1 : T1<B1::B2>::N1; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}} 407}; 408struct S7c { 409 T1<B1::B2>::C1 m1 : T1<B1:B2>::N1; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}} 410}; 411 412} 413 414namespace PR16951 { 415 namespace ns { 416 enum an_enumeration { 417 ENUMERATOR // expected-note{{'ENUMERATOR' declared here}} 418 }; 419 } 420 421 int x1 = ns::an_enumeration::ENUMERATOR; // expected-warning{{use of enumeration in a nested name specifier is a C++11 extension}} 422 423 int x2 = ns::an_enumeration::ENUMERATOR::vvv; // expected-warning{{use of enumeration in a nested name specifier is a C++11 extension}} \ 424 // expected-error{{'ENUMERATOR' is not a class, namespace, or enumeration}} \ 425 426 int x3 = ns::an_enumeration::X; // expected-warning{{use of enumeration in a nested name specifier is a C++11 extension}} \ 427 // expected-error{{no member named 'X'}} 428 429 enum enumerator_2 { 430 ENUMERATOR_2 431 }; 432 433 int x4 = enumerator_2::ENUMERATOR_2; // expected-warning{{use of enumeration in a nested name specifier is a C++11 extension}} 434 int x5 = enumerator_2::X2; // expected-warning{{use of enumeration in a nested name specifier is a C++11 extension}} \ 435 // expected-error{{no member named 'X2' in 'PR16951::enumerator_2'}} 436 437} 438