Only do delayed diagnostics if there were no errors when parsing the decl.
[clang/stm8.git] / test / SemaCXX / nested-name-spec.cpp
blob8ba02fe242ecb8c1c94008c334f6ff54d79adb13
1 // RUN: %clang_cc1 -fsyntax-only -std=c++98 -verify %s
2 namespace A {
3 struct C {
4 static int cx;
6 static int cx2;
8 static int Ag1();
9 static int Ag2();
11 int ax;
12 void Af();
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'}}
20 int A::C::Ag1() { return 0; }
22 static int A::C::Ag2() { return 0; } // expected-error{{'static' can}}
24 int A::C::cx = 17;
27 static int A::C::cx2 = 17; // expected-error{{'static' can}}
29 class C2 {
30 void m(); // expected-note{{member declaration nearly matches}}
32 void f(const int& parm); // expected-note{{member declaration nearly matches}}
33 void f(int) const; // expected-note{{member declaration nearly matches}}
34 void f(float);
36 int x;
39 void C2::m() const { } // expected-error{{out-of-line definition of 'm' does not match any declaration in 'C2'}}
41 void C2::f(int) { } // expected-error{{out-of-line definition of 'f' does not match any declaration in 'C2'}}
43 void C2::m() {
44 x = 0;
47 namespace B {
48 void ::A::Af() {} // expected-error {{definition or redeclaration of 'Af' not in a namespace enclosing 'A'}}
51 void f1() {
52 void A::Af(); // expected-error {{definition or redeclaration of 'Af' not allowed inside a function}}
55 void 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);
64 A::C c1;
65 struct A::C c2;
66 struct S : public A::C {};
67 struct A::undef; // expected-error {{no struct named 'undef' in namespace 'A'}}
69 namespace A2 {
70 typedef int INT;
71 struct RC;
72 struct CC {
73 struct NC;
77 struct A2::RC {
78 INT x;
81 struct A2::CC::NC {
82 void m() {}
85 void f3() {
86 N::x = 0; // expected-error {{use of undeclared identifier 'N'}}
87 int N;
88 N::x = 0; // expected-error {{expected a class or namespace}}
89 { int A; A::ax = 0; }
90 { typedef int A; A::ax = 0; } // expected-error{{expected a class or namespace}}
91 { typedef A::C A; A::ax = 0; } // expected-error {{no member named 'ax'}}
92 { typedef A::C A; A::cx = 0; }
95 // make sure the following doesn't hit any asserts
96 void f4(undef::C); // expected-error {{use of undeclared identifier 'undef'}} \
97 expected-error {{variable has incomplete type 'void'}}
99 typedef void C2::f5(int); // expected-error{{typedef declarator cannot be qualified}}
101 void f6(int A2::RC::x); // expected-error{{parameter declarator cannot be qualified}}
103 int A2::RC::x; // expected-error{{non-static data member defined out-of-line}}
105 void A2::CC::NC::m(); // expected-error{{out-of-line declaration of a member must be a definition}}
108 namespace E {
109 int X = 5;
111 namespace Nested {
112 enum E {
113 X = 0
116 void f() {
117 return E::X; // expected-error{{expected a class or namespace}}
123 class Operators {
124 Operators operator+(const Operators&) const; // expected-note{{member declaration nearly matches}}
125 operator bool();
128 Operators Operators::operator+(const Operators&) { // expected-error{{out-of-line definition of 'operator+' does not match any declaration in 'Operators'}}
129 Operators ops;
130 return ops;
133 Operators Operators::operator+(const Operators&) const {
134 Operators ops;
135 return ops;
138 Operators::operator bool() {
139 return true;
142 namespace A {
143 void g(int&); // expected-note{{member declaration nearly matches}}
146 void A::f() {} // expected-error{{out-of-line definition of 'f' does not match any declaration in namespace 'A'}}
148 void A::g(const int&) { } // expected-error{{out-of-line definition of 'g' does not match any declaration in namespace 'A'}}
150 struct Struct { };
152 void Struct::f() { } // expected-error{{out-of-line definition of 'f' does not match any declaration in 'Struct'}}
154 void global_func(int);
155 void global_func2(int);
157 namespace N {
158 void ::global_func(int) { } // expected-error{{definition or redeclaration of 'global_func' cannot name the global scope}}
160 void f();
161 // FIXME: if we move this to a separate definition of N, things break!
163 void ::global_func2(int) { } // expected-error{{definition or redeclaration of 'global_func2' cannot name the global scope}}
165 void N::f() { } // okay
167 struct Y; // expected-note{{forward declaration of 'Y'}}
168 Y::foo y; // expected-error{{incomplete type 'Y' named in nested name specifier}}
170 X::X() : a(5) { } // expected-error{{use of undeclared identifier 'X'}} \
171 // expected-error{{C++ requires a type specifier for all declarations}} \
172 // expected-error{{only constructors take base initializers}}
174 struct foo_S {
175 static bool value;
177 bool (foo_S::value);
180 namespace somens {
181 struct a { }; // expected-note{{candidate constructor (the implicit copy constructor)}}
184 template <typename T>
185 class foo {
189 // PR4452 / PR4451
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.
195 namespace test1 {
196 namespace ns {
197 class Counter { public: static int count; };
198 typedef Counter counter;
200 using ns::counter;
202 class Test {
203 void test1() {
204 counter c;
205 c.count++;
206 counter::count++;
211 // We still need to do lookup in the lexical scope, even if we push a
212 // non-lexical scope.
213 namespace test2 {
214 namespace ns {
215 extern int *count_ptr;
217 namespace {
218 int count = 0;
221 int *ns::count_ptr = &count;
224 // PR6259, invalid case
225 namespace 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}}
232 namespace PR7133 {
233 namespace A {
234 class Foo;
237 namespace A {
238 namespace B {
239 bool foo(Foo &);
243 bool A::B::foo(Foo &) {
244 return false;
248 class CLASS {
249 void CLASS::foo2(); // expected-warning {{extra qualification on member 'foo2'}}
252 namespace PR8159 {
253 class B { };
255 class A {
256 int A::a; // expected-warning{{extra qualification on member 'a'}}
257 static int A::b; // expected-warning{{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 {{out-of-line definition of 'rdar7980179::A::f0' differ from the declaration in the return type}}
267 namespace alias = A;
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
271 namespace PR10109 {
272 template<typename T>
273 struct A {
274 protected:
275 struct B;
276 struct B::C; // expected-error {{requires a template parameter list}} \
277 // expected-error {{no struct named 'C'}}
280 template<typename T>
281 struct A2 {
282 protected:
283 struct B;
285 template <typename T>
286 struct A2<T>::B::C; // expected-error {{no struct named 'C'}}