blob: 9a611c38ad6dad764643a5c5c8074bba51dc7773 [file] [log] [blame]
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -std=c++98 -verify %s
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +00002namespace A {
3 struct C {
4 static int cx;
Douglas Gregor04e9a032009-03-11 23:52:16 +00005
6 static int cx2;
7
8 static int Ag1();
9 static int Ag2();
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +000010 };
11 int ax;
12 void Af();
13}
14
15A:: ; // expected-error {{expected unqualified-id}}
John McCall1f476a12010-02-26 08:45:28 +000016// FIXME: redundant errors
17::A::ax::undef ex3; // expected-error {{no member named}} expected-error {{unknown type name}}
18A::undef1::undef2 ex4; // expected-error {{no member named 'undef1'}} expected-error {{unknown type name}}
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +000019
Douglas Gregor04e9a032009-03-11 23:52:16 +000020int A::C::Ag1() { return 0; }
21
Douglas Gregor170512f2009-04-01 23:51:29 +000022static int A::C::Ag2() { return 0; } // expected-error{{'static' can}}
Douglas Gregor04e9a032009-03-11 23:52:16 +000023
24int A::C::cx = 17;
25
26
Douglas Gregor170512f2009-04-01 23:51:29 +000027static int A::C::cx2 = 17; // expected-error{{'static' can}}
Douglas Gregor04e9a032009-03-11 23:52:16 +000028
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +000029class C2 {
Douglas Gregorad590502008-12-15 23:53:10 +000030 void m(); // expected-note{{member declaration nearly matches}}
31
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);
35
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +000036 int x;
37};
38
John McCall85f90552010-03-10 11:27:22 +000039void C2::m() const { } // expected-error{{out-of-line definition of 'm' does not match any declaration in 'C2'}}
Douglas Gregorad590502008-12-15 23:53:10 +000040
John McCall85f90552010-03-10 11:27:22 +000041void C2::f(int) { } // expected-error{{out-of-line definition of 'f' does not match any declaration in 'C2'}}
Douglas Gregorad590502008-12-15 23:53:10 +000042
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +000043void C2::m() {
44 x = 0;
45}
46
47namespace B {
Chris Lattnerf7e69d52008-11-23 20:28:15 +000048 void ::A::Af() {} // expected-error {{definition or redeclaration of 'Af' not in a namespace enclosing 'A'}}
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +000049}
50
51void f1() {
Douglas Gregorad590502008-12-15 23:53:10 +000052 void A::Af(); // expected-error {{definition or redeclaration of 'Af' not allowed inside a function}}
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +000053}
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 {};
Douglas Gregorf5af3582010-03-31 23:17:41 +000067struct A::undef; // expected-error {{no struct named 'undef' in namespace 'A'}}
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +000068
Argyrios Kyrtzidis9e59b572008-11-09 23:41:00 +000069namespace A2 {
70 typedef int INT;
71 struct RC;
Argyrios Kyrtzidis0d09c492008-11-19 18:01:13 +000072 struct CC {
73 struct NC;
74 };
Argyrios Kyrtzidis9e59b572008-11-09 23:41:00 +000075}
76
77struct A2::RC {
78 INT x;
79};
80
Argyrios Kyrtzidis0d09c492008-11-19 18:01:13 +000081struct A2::CC::NC {
82 void m() {}
83};
84
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +000085void 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; }
Douglas Gregor19500292008-12-16 06:37:47 +000090 { typedef int A; A::ax = 0; } // expected-error{{expected a class or namespace}}
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +000091 { typedef A::C A; A::ax = 0; } // expected-error {{no member named 'ax'}}
92 { typedef A::C A; A::cx = 0; }
93}
Argyrios Kyrtzidis89709ac2008-11-19 15:22:16 +000094
95// make sure the following doesn't hit any asserts
Chris Lattner869c6612009-04-12 22:23:27 +000096void f4(undef::C); // expected-error {{use of undeclared identifier 'undef'}} \
97 expected-error {{variable has incomplete type 'void'}}
Douglas Gregorad590502008-12-15 23:53:10 +000098
99typedef void C2::f5(int); // expected-error{{typedef declarator cannot be qualified}}
100
101void f6(int A2::RC::x); // expected-error{{parameter declarator cannot be qualified}}
102
103int A2::RC::x; // expected-error{{non-static data member defined out-of-line}}
104
Douglas Gregorf4f296d2009-03-23 23:06:20 +0000105void A2::CC::NC::m(); // expected-error{{out-of-line declaration of a member must be a definition}}
Douglas Gregor19500292008-12-16 06:37:47 +0000106
107
108namespace E {
109 int X = 5;
110
111 namespace Nested {
112 enum E {
113 X = 0
114 };
115
116 void f() {
117 return E::X; // expected-error{{expected a class or namespace}}
118 }
119 }
120}
Douglas Gregor1dc98262008-12-26 15:00:45 +0000121
122
123class Operators {
124 Operators operator+(const Operators&) const; // expected-note{{member declaration nearly matches}}
125 operator bool();
126};
127
John McCall85f90552010-03-10 11:27:22 +0000128Operators Operators::operator+(const Operators&) { // expected-error{{out-of-line definition of 'operator+' does not match any declaration in 'Operators'}}
Douglas Gregor1dc98262008-12-26 15:00:45 +0000129 Operators ops;
130 return ops;
131}
132
133Operators Operators::operator+(const Operators&) const {
134 Operators ops;
135 return ops;
136}
137
138Operators::operator bool() {
139 return true;
140}
Douglas Gregor8af63e42009-02-06 17:46:57 +0000141
142namespace A {
143 void g(int&); // expected-note{{member declaration nearly matches}}
144}
145
Douglas Gregore40876a2009-10-13 21:16:44 +0000146void A::f() {} // expected-error{{out-of-line definition of 'f' does not match any declaration in namespace 'A'}}
Douglas Gregor8af63e42009-02-06 17:46:57 +0000147
Douglas Gregore40876a2009-10-13 21:16:44 +0000148void A::g(const int&) { } // expected-error{{out-of-line definition of 'g' does not match any declaration in namespace 'A'}}
Douglas Gregor8af63e42009-02-06 17:46:57 +0000149
150struct Struct { };
151
John McCall85f90552010-03-10 11:27:22 +0000152void Struct::f() { } // expected-error{{out-of-line definition of 'f' does not match any declaration in 'Struct'}}
Douglas Gregor8af63e42009-02-06 17:46:57 +0000153
154void global_func(int);
155void global_func2(int);
156
157namespace N {
158 void ::global_func(int) { } // expected-error{{definition or redeclaration of 'global_func' cannot name the global scope}}
159
160 void f();
161 // FIXME: if we move this to a separate definition of N, things break!
162}
163void ::global_func2(int) { } // expected-error{{definition or redeclaration of 'global_func2' cannot name the global scope}}
164
165void N::f() { } // okay
Douglas Gregorc2fd6262009-03-06 19:06:37 +0000166
John McCall85f90552010-03-10 11:27:22 +0000167struct Y; // expected-note{{forward declaration of 'Y'}}
168Y::foo y; // expected-error{{incomplete type 'Y' named in nested name specifier}} \
Douglas Gregor15e56022009-10-13 23:27:22 +0000169 // expected-error{{no type named 'foo' in}}
Douglas Gregor26897462009-03-11 16:48:53 +0000170
Douglas Gregorc2fd6262009-03-06 19:06:37 +0000171X::X() : a(5) { } // expected-error{{use of undeclared identifier 'X'}} \
Anders Carlsson75fdaa42009-03-25 02:58:17 +0000172 // expected-error{{C++ requires a type specifier for all declarations}} \
173 // expected-error{{only constructors take base initializers}}
Chris Lattner5558e9f2009-06-26 04:27:47 +0000174
Argyrios Kyrtzidis1a176f02009-07-21 06:43:26 +0000175struct foo_S {
176 static bool value;
177};
178bool (foo_S::value);
Chris Lattner5558e9f2009-06-26 04:27:47 +0000179
180
181namespace somens {
John McCalle1ac8d12010-01-13 00:25:19 +0000182 struct a { }; // expected-note{{candidate constructor (the implicit copy constructor)}}
Chris Lattner5558e9f2009-06-26 04:27:47 +0000183}
184
185template <typename T>
186class foo {
187};
188
189
Chris Lattner1c428032009-12-07 01:36:53 +0000190// PR4452 / PR4451
191foo<somens:a> a2; // expected-error {{unexpected ':' in nested name specifier}}
Chris Lattner5558e9f2009-06-26 04:27:47 +0000192
Douglas Gregora4b592a2009-12-19 03:01:41 +0000193somens::a a3 = a2; // expected-error {{no viable conversion}}
Chris Lattner5558e9f2009-06-26 04:27:47 +0000194
John McCallea305ed2009-12-18 10:40:03 +0000195// typedefs and using declarations.
196namespace test1 {
197 namespace ns {
198 class Counter { static int count; };
199 typedef Counter counter;
200 }
201 using ns::counter;
Chris Lattner5558e9f2009-06-26 04:27:47 +0000202
John McCallea305ed2009-12-18 10:40:03 +0000203 class Test {
204 void test1() {
205 counter c;
206 c.count++;
207 counter::count++;
208 }
209 };
210}
John McCall1f4ee7b2009-12-19 09:28:58 +0000211
212// We still need to do lookup in the lexical scope, even if we push a
213// non-lexical scope.
214namespace test2 {
215 namespace ns {
Sebastian Redl497c0a42010-01-26 18:52:33 +0000216 extern int *count_ptr;
John McCall1f4ee7b2009-12-19 09:28:58 +0000217 }
218 namespace {
219 int count = 0;
220 }
221
222 int *ns::count_ptr = &count;
223}
John McCall69f9dbc2010-02-08 19:26:07 +0000224
225// PR6259, invalid case
226namespace test3 {
227 // FIXME: this should really only trigger once
228 class A; // expected-note 2 {{forward declaration}}
229 void foo(const char *path) {
John McCall85f90552010-03-10 11:27:22 +0000230 A::execute(path); // expected-error 2 {{incomplete type 'test3::A' named in nested name specifier}}
John McCall69f9dbc2010-02-08 19:26:07 +0000231 }
232}