blob: dc8eda59942300c5e7e18c2d1b28fb9c84ebd3db [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}}
Douglas Gregor15e56022009-10-13 23:27:22 +000016::A::ax::undef ex3; // expected-error {{no member named}}
17A::undef1::undef2 ex4; // expected-error {{no member named 'undef1'}}
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +000018
Douglas Gregor04e9a032009-03-11 23:52:16 +000019int A::C::Ag1() { return 0; }
20
Douglas Gregor170512f2009-04-01 23:51:29 +000021static int A::C::Ag2() { return 0; } // expected-error{{'static' can}}
Douglas Gregor04e9a032009-03-11 23:52:16 +000022
23int A::C::cx = 17;
24
25
Douglas Gregor170512f2009-04-01 23:51:29 +000026static int A::C::cx2 = 17; // expected-error{{'static' can}}
Douglas Gregor04e9a032009-03-11 23:52:16 +000027
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +000028class C2 {
Douglas Gregorad590502008-12-15 23:53:10 +000029 void m(); // expected-note{{member declaration nearly matches}}
30
31 void f(const int& parm); // expected-note{{member declaration nearly matches}}
32 void f(int) const; // expected-note{{member declaration nearly matches}}
33 void f(float);
34
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +000035 int x;
36};
37
Douglas Gregore40876a2009-10-13 21:16:44 +000038void C2::m() const { } // expected-error{{out-of-line definition of 'm' does not match any declaration in 'class C2'}}
Douglas Gregorad590502008-12-15 23:53:10 +000039
Douglas Gregore40876a2009-10-13 21:16:44 +000040void C2::f(int) { } // expected-error{{out-of-line definition of 'f' does not match any declaration in 'class C2'}}
Douglas Gregorad590502008-12-15 23:53:10 +000041
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +000042void C2::m() {
43 x = 0;
44}
45
46namespace B {
Chris Lattnerf7e69d52008-11-23 20:28:15 +000047 void ::A::Af() {} // expected-error {{definition or redeclaration of 'Af' not in a namespace enclosing 'A'}}
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +000048}
49
50void f1() {
Douglas Gregorad590502008-12-15 23:53:10 +000051 void A::Af(); // expected-error {{definition or redeclaration of 'Af' not allowed inside a function}}
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +000052}
53
54void f2() {
55 A:: ; // expected-error {{expected unqualified-id}}
56 A::C::undef = 0; // expected-error {{no member named 'undef'}}
57 ::A::C::cx = 0;
58 int x = ::A::ax = A::C::cx;
59 x = sizeof(A::C);
60 x = sizeof(::A::C::cx);
61}
62
63A::C c1;
64struct A::C c2;
65struct S : public A::C {};
66struct A::undef; // expected-error {{'undef' does not name a tag member in the specified scope}}
67
Argyrios Kyrtzidis9e59b572008-11-09 23:41:00 +000068namespace A2 {
69 typedef int INT;
70 struct RC;
Argyrios Kyrtzidis0d09c492008-11-19 18:01:13 +000071 struct CC {
72 struct NC;
73 };
Argyrios Kyrtzidis9e59b572008-11-09 23:41:00 +000074}
75
76struct A2::RC {
77 INT x;
78};
79
Argyrios Kyrtzidis0d09c492008-11-19 18:01:13 +000080struct A2::CC::NC {
81 void m() {}
82};
83
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +000084void f3() {
85 N::x = 0; // expected-error {{use of undeclared identifier 'N'}}
86 int N;
87 N::x = 0; // expected-error {{expected a class or namespace}}
88 { int A; A::ax = 0; }
Douglas Gregor19500292008-12-16 06:37:47 +000089 { typedef int A; A::ax = 0; } // expected-error{{expected a class or namespace}}
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +000090 { typedef A::C A; A::ax = 0; } // expected-error {{no member named 'ax'}}
91 { typedef A::C A; A::cx = 0; }
92}
Argyrios Kyrtzidis89709ac2008-11-19 15:22:16 +000093
94// make sure the following doesn't hit any asserts
Chris Lattner869c6612009-04-12 22:23:27 +000095void f4(undef::C); // expected-error {{use of undeclared identifier 'undef'}} \
96 expected-error {{variable has incomplete type 'void'}}
Douglas Gregorad590502008-12-15 23:53:10 +000097
98typedef void C2::f5(int); // expected-error{{typedef declarator cannot be qualified}}
99
100void f6(int A2::RC::x); // expected-error{{parameter declarator cannot be qualified}}
101
102int A2::RC::x; // expected-error{{non-static data member defined out-of-line}}
103
Douglas Gregorf4f296d2009-03-23 23:06:20 +0000104void A2::CC::NC::m(); // expected-error{{out-of-line declaration of a member must be a definition}}
Douglas Gregor19500292008-12-16 06:37:47 +0000105
106
107namespace E {
108 int X = 5;
109
110 namespace Nested {
111 enum E {
112 X = 0
113 };
114
115 void f() {
116 return E::X; // expected-error{{expected a class or namespace}}
117 }
118 }
119}
Douglas Gregor1dc98262008-12-26 15:00:45 +0000120
121
122class Operators {
123 Operators operator+(const Operators&) const; // expected-note{{member declaration nearly matches}}
124 operator bool();
125};
126
Douglas Gregore40876a2009-10-13 21:16:44 +0000127Operators Operators::operator+(const Operators&) { // expected-error{{out-of-line definition of 'operator+' does not match any declaration in 'class Operators'}}
Douglas Gregor1dc98262008-12-26 15:00:45 +0000128 Operators ops;
129 return ops;
130}
131
132Operators Operators::operator+(const Operators&) const {
133 Operators ops;
134 return ops;
135}
136
137Operators::operator bool() {
138 return true;
139}
Douglas Gregor8af63e42009-02-06 17:46:57 +0000140
141namespace A {
142 void g(int&); // expected-note{{member declaration nearly matches}}
143}
144
Douglas Gregore40876a2009-10-13 21:16:44 +0000145void 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 +0000146
Douglas Gregore40876a2009-10-13 21:16:44 +0000147void 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 +0000148
149struct Struct { };
150
Douglas Gregore40876a2009-10-13 21:16:44 +0000151void Struct::f() { } // expected-error{{out-of-line definition of 'f' does not match any declaration in 'struct Struct'}}
Douglas Gregor8af63e42009-02-06 17:46:57 +0000152
153void global_func(int);
154void global_func2(int);
155
156namespace N {
157 void ::global_func(int) { } // expected-error{{definition or redeclaration of 'global_func' cannot name the global scope}}
158
159 void f();
160 // FIXME: if we move this to a separate definition of N, things break!
161}
162void ::global_func2(int) { } // expected-error{{definition or redeclaration of 'global_func2' cannot name the global scope}}
163
164void N::f() { } // okay
Douglas Gregorc2fd6262009-03-06 19:06:37 +0000165
Douglas Gregor26897462009-03-11 16:48:53 +0000166struct Y; // expected-note{{forward declaration of 'struct Y'}}
167Y::foo y; // expected-error{{incomplete type 'struct Y' named in nested name specifier}} \
Douglas Gregor15e56022009-10-13 23:27:22 +0000168 // expected-error{{no type named 'foo' in}}
Douglas Gregor26897462009-03-11 16:48:53 +0000169
Douglas Gregorc2fd6262009-03-06 19:06:37 +0000170X::X() : a(5) { } // expected-error{{use of undeclared identifier 'X'}} \
Anders Carlsson75fdaa42009-03-25 02:58:17 +0000171 // expected-error{{C++ requires a type specifier for all declarations}} \
172 // expected-error{{only constructors take base initializers}}
Chris Lattner5558e9f2009-06-26 04:27:47 +0000173
Argyrios Kyrtzidis1a176f02009-07-21 06:43:26 +0000174struct foo_S {
175 static bool value;
176};
177bool (foo_S::value);
Chris Lattner5558e9f2009-06-26 04:27:47 +0000178
179
180namespace somens {
181 struct a { };
182}
183
184template <typename T>
185class foo {
186};
187
188
Chris Lattner1c428032009-12-07 01:36:53 +0000189// PR4452 / PR4451
190foo<somens:a> a2; // expected-error {{unexpected ':' in nested name specifier}}
Chris Lattner5558e9f2009-06-26 04:27:47 +0000191
Chris Lattner1c428032009-12-07 01:36:53 +0000192somens::a a3 = a2; // expected-error {{cannot initialize 'a3' with an lvalue of type 'foo<somens::a>'}}
Chris Lattner5558e9f2009-06-26 04:27:47 +0000193
John McCallea305ed2009-12-18 10:40:03 +0000194// typedefs and using declarations.
195namespace test1 {
196 namespace ns {
197 class Counter { static int count; };
198 typedef Counter counter;
199 }
200 using ns::counter;
Chris Lattner5558e9f2009-06-26 04:27:47 +0000201
John McCallea305ed2009-12-18 10:40:03 +0000202 class Test {
203 void test1() {
204 counter c;
205 c.count++;
206 counter::count++;
207 }
208 };
209}