1 // RUN: %clang_cc1 -fsyntax-only -std=c++98 -verify -fblocks %s
11 int ax; // expected-note {{'ax' declared here}}
15 A:: ; // expected-error {{expected unqualified-id}}
16 ::A::ax::undef ex3; // expected-error {{'ax' is not a class, namespace, or enumeration}}
17 A::undef1::undef2 ex4; // expected-error {{no member named 'undef1'}}
19 int A::C::Ag1() { return 0; }
21 static int A::C::Ag2() { return 0; } // expected-error{{'static' can}}
26 static int A::C::cx2 = 17; // expected-error{{'static' can}}
29 void m(); // expected-note{{member declaration does not match because it is not const qualified}}
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}}
38 void C2::m() const { } // expected-error{{out-of-line definition of 'm' does not match any declaration in 'C2'}}
40 void C2::f(int) { } // expected-error{{out-of-line definition of 'f' does not match any declaration in 'C2'}}
47 void ::A::Af() {} // expected-error {{cannot define or redeclare 'Af' here because namespace 'B' does not enclose namespace 'A'}}
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}}
56 A:: ; // expected-error {{expected unqualified-id}}
57 A::C::undef = 0; // expected-error {{no member named 'undef'}}
59 int x = ::A::ax = A::C::cx;
61 x = sizeof(::A::C::cx);
66 struct S : public A::C {};
67 struct A::undef; // expected-error {{no struct named 'undef' in namespace 'A'}}
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}}
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; }
98 // make sure the following doesn't hit any asserts
99 void f4(undef::C); // expected-error {{use of undeclared identifier 'undef'}}
101 typedef void C2::f5(int); // expected-error{{typedef declarator cannot be qualified}}
103 void f6(int A2::RC::x); // expected-error{{parameter declarator cannot be qualified}}
105 int A2::RC::x; // expected-error{{non-static data member defined out-of-line}}
107 void A2::CC::NC::m(); // expected-error{{out-of-line declaration of a member must be a definition}}
119 return E::X; // expected-warning{{use of enumeration in a nested name specifier is a C++11 extension}}
126 Operators operator+(const Operators&) const; // expected-note{{member declaration does not match because it is const qualified}}
130 Operators Operators::operator+(const Operators&) { // expected-error{{out-of-line definition of 'operator+' does not match any declaration in 'Operators'}}
135 Operators Operators::operator+(const Operators&) const {
140 Operators::operator bool() {
145 void g(int&); // expected-note{{type of 1st parameter of member declaration does not match definition ('int &' vs 'const int &')}}
148 void A::f() {} // expected-error-re{{out-of-line definition of 'f' does not match any declaration in namespace 'A'{{$}}}}
150 void A::g(const int&) { } // expected-error{{out-of-line definition of 'g' does not match any declaration in namespace 'A'}}
154 void Struct::f() { } // expected-error{{out-of-line definition of 'f' does not match any declaration in 'Struct'}}
156 void global_func(int);
157 void global_func2(int);
160 void ::global_func(int) { } // expected-error{{definition or redeclaration of 'global_func' cannot name the global scope}}
163 // FIXME: if we move this to a separate definition of N, things break!
165 void ::global_func2(int) { } // expected-warning{{extra qualification on member 'global_func2'}}
167 void N::f() { } // okay
169 struct Y; // expected-note{{forward declaration of 'Y'}}
170 Y::foo y; // expected-error{{incomplete type 'Y' named in nested name specifier}}
172 X::X() : a(5) { } // expected-error{{use of undeclared identifier 'X'}}
181 struct a { }; // expected-note{{candidate constructor (the implicit copy constructor)}}
184 template <typename T>
190 foo<somens:a> a2; // expected-error {{unexpected ':' in nested name specifier}}
192 somens::a a3 = a2; // expected-error {{no viable conversion}}
194 // typedefs and using declarations.
197 class Counter { public: static int count; };
198 typedef Counter counter;
211 // We still need to do lookup in the lexical scope, even if we push a
212 // non-lexical scope.
215 extern int *count_ptr;
221 int *ns::count_ptr = &count;
224 // PR6259, invalid case
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}}
243 bool A::B::foo(Foo &) {
249 void CLASS::foo2(); // expected-error {{extra qualification on member 'foo2'}}
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}}
262 namespace 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}}
268 double *dp = (alias::C*)0; // expected-error{{cannot initialize a variable of type 'double *' with an rvalue of type 'alias::C *'}}
270 // http://llvm.org/PR10109
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}}
286 template <typename T>
287 struct A2<T>::B::C; // expected-error {{no struct named 'C'}}
292 int a; // expected-note {{'NS::a' declared here}}
293 int longer_b; //expected-note {{'NS::longer_b' declared here}}
296 // Suggest adding a namespace qualifier to both variable names even though one
297 // is only a single character long.
298 int 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'?}}
302 // <rdar://problem/13853540>
307 struct N::X *foo(); // expected-error{{no struct named 'X' in namespace 'N::N'}}
312 namespace TypedefNamespace { typedef int F; };
313 TypedefNamespace::F::NonexistentName BadNNSWithCXXScopeSpec; // expected-error {{'TypedefNamespace::F' (aka 'int') is not a class, namespace, or enumeration}}
326 struct C2 { static const unsigned N1 = 1; };
329 static const int B3 = 3;
333 // Function declarators
334 struct S1a { int f(C1::C2); };
335 struct S1b { int f(C1:C2); }; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
341 C1::C2 f(C1:C2); // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
345 int f(C1::C2), C2 : N1;
349 int g : B1:B2; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
352 // Inside square brackets
357 int f[C2:N1]; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
361 int f(int xx[B1::B3 ? C2::N1 : B1::B2]);
364 int f(int xx[B1::B3 ? C2::N1 : B1:B2]); // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
367 int f(int xx[B1:B3 ? C2::N1 : B1::B2]); // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
375 C1::C2 m1 : B1:B2; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
381 static const int N = 3;
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 '::'?}}
389 // Template parameters
390 template <int N> struct T1 {
392 static const unsigned N1 = N;
396 T1<C2:N1> var_1b; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
397 template<int N> int F() {}
398 int (*X1)() = (B1::B2 ? F<1> : F<2>);
399 int (*X2)() = (B1:B2 ? F<1> : F<2>); // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
401 // Bit fields + templates
403 T1<B1::B2>::C1 m1 : T1<B1::B2>::N1;
406 T1<B1:B2>::C1 m1 : T1<B1::B2>::N1; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
409 T1<B1::B2>::C1 m1 : T1<B1:B2>::N1; // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
416 enum an_enumeration {
417 ENUMERATOR // expected-note{{'ENUMERATOR' declared here}}
421 int x1 = ns::an_enumeration::ENUMERATOR; // expected-warning{{use of enumeration in a nested name specifier is a C++11 extension}}
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}} \
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'}}
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'}}
440 c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d;
441 // expected-error@-1 16{{unknown type name 'c'}}
442 c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d;
443 // expected-error@-1 16{{unknown type name 'c'}}
444 c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d;
445 // expected-error@-1 16{{unknown type name 'c'}}
446 c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d; c d;
447 // expected-error@-1 16{{unknown type name 'c'}}
450 typedef C D; // expected-error{{unknown type name 'C'}}
452 // expected-error@-1{{'PR30619::A::B::D' (aka 'int') is not a class, namespace, or enumeration}}