blob: 4c3ecee090516723fa5b4cf83297f68814cc2111 [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc -fsyntax-only -std=c++98 -verify %s
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +00002namespace A {
3 struct C {
4 static int cx;
Douglas Gregor656de632009-03-11 23:52:16 +00005
6 static int cx2;
7
8 static int Ag1();
9 static int Ag2();
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +000010 };
11 int ax;
12 void Af();
13}
14
15A:: ; // expected-error {{expected unqualified-id}}
Chris Lattnerf4382f52009-04-14 22:17:06 +000016::A::ax::undef ex3; // expected-error {{expected a class or namespace}} expected-error {{unknown type name 'undef'}}
17A::undef1::undef2 ex4; // expected-error {{no member named 'undef1'}} expected-error {{unknown type name 'undef2'}}
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +000018
Douglas Gregor656de632009-03-11 23:52:16 +000019int A::C::Ag1() { return 0; }
20
Douglas Gregora3a83512009-04-01 23:51:29 +000021static int A::C::Ag2() { return 0; } // expected-error{{'static' can}}
Douglas Gregor656de632009-03-11 23:52:16 +000022
23int A::C::cx = 17;
24
25
Douglas Gregora3a83512009-04-01 23:51:29 +000026static int A::C::cx2 = 17; // expected-error{{'static' can}}
Douglas Gregor656de632009-03-11 23:52:16 +000027
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +000028class C2 {
Douglas Gregor584049d2008-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 Kyrtzidisef6e6472008-11-08 17:17:31 +000035 int x;
36};
37
Douglas Gregor584049d2008-12-15 23:53:10 +000038void C2::m() const { } // expected-error{{out-of-line definition does not match any declaration in 'C2'}}
39
40void C2::f(int) { } // expected-error{{out-of-line definition does not match any declaration in 'C2'}}
41
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +000042void C2::m() {
43 x = 0;
44}
45
46namespace B {
Chris Lattner011bb4e2008-11-23 20:28:15 +000047 void ::A::Af() {} // expected-error {{definition or redeclaration of 'Af' not in a namespace enclosing 'A'}}
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +000048}
49
50void f1() {
Douglas Gregor584049d2008-12-15 23:53:10 +000051 void A::Af(); // expected-error {{definition or redeclaration of 'Af' not allowed inside a function}}
Argyrios Kyrtzidisef6e6472008-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 Kyrtzidis52393042008-11-09 23:41:00 +000068namespace A2 {
69 typedef int INT;
70 struct RC;
Argyrios Kyrtzidis77407b82008-11-19 18:01:13 +000071 struct CC {
72 struct NC;
73 };
Argyrios Kyrtzidis52393042008-11-09 23:41:00 +000074}
75
76struct A2::RC {
77 INT x;
78};
79
Argyrios Kyrtzidis77407b82008-11-19 18:01:13 +000080struct A2::CC::NC {
81 void m() {}
82};
83
Argyrios Kyrtzidisef6e6472008-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 Gregor3dde5a32008-12-16 06:37:47 +000089 { typedef int A; A::ax = 0; } // expected-error{{expected a class or namespace}}
90 { int A(); A::ax = 0; }
Argyrios Kyrtzidisef6e6472008-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 Kyrtzidis08b2c372008-11-19 15:22:16 +000094
95// make sure the following doesn't hit any asserts
Chris Lattner8129edb2009-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 Gregor584049d2008-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 Gregor2dc0e642009-03-23 23:06:20 +0000105void A2::CC::NC::m(); // expected-error{{out-of-line declaration of a member must be a definition}}
Douglas Gregor3dde5a32008-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 Gregor70316a02008-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
128Operators Operators::operator+(const Operators&) { // expected-error{{out-of-line definition does not match any declaration in 'Operators'}}
129 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 Gregor4ce205f2009-02-06 17:46:57 +0000141
142namespace A {
143 void g(int&); // expected-note{{member declaration nearly matches}}
144}
145
146void A::f() {} // expected-error{{out-of-line definition does not match any declaration in 'A'}}
147
148void A::g(const int&) { } // expected-error{{out-of-line definition does not match any declaration in 'A'}}
149
150struct Struct { };
151
152void Struct::f() { } // expected-error{{out-of-line definition does not match any declaration in 'Struct'}}
153
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 Gregor9fa14a52009-03-06 19:06:37 +0000166
Douglas Gregor4fdf1fa2009-03-11 16:48:53 +0000167struct Y; // expected-note{{forward declaration of 'struct Y'}}
168Y::foo y; // expected-error{{incomplete type 'struct Y' named in nested name specifier}} \
Chris Lattnerf4382f52009-04-14 22:17:06 +0000169 // expected-error{{unknown type name 'foo'}}
Douglas Gregor4fdf1fa2009-03-11 16:48:53 +0000170
Douglas Gregor9fa14a52009-03-06 19:06:37 +0000171X::X() : a(5) { } // expected-error{{use of undeclared identifier 'X'}} \
Anders Carlssona7b35212009-03-25 02:58:17 +0000172 // expected-error{{C++ requires a type specifier for all declarations}} \
173 // expected-error{{only constructors take base initializers}}