blob: f75b279a44933a839166141644ea3da3cfe7acc3 [file] [log] [blame]
Douglas Gregor6e7c27c2009-03-11 16:48:53 +00001// RUN: clang -fsyntax-only -std=c++98 -verify %s
Argiris Kirtzidis054a2632008-11-08 17:17:31 +00002namespace A {
3 struct C {
4 static int cx;
5 };
6 int ax;
7 void Af();
8}
9
10A:: ; // expected-error {{expected unqualified-id}}
Douglas Gregor195492c2009-03-06 19:06:37 +000011::A::ax::undef ex3; // expected-error {{expected a class or namespace}} expected-error {{invalid token after top level declarator}}
12A::undef1::undef2 ex4; // expected-error {{no member named 'undef1'}} expected-error {{invalid token after top level declarator}}
Argiris Kirtzidis054a2632008-11-08 17:17:31 +000013
14class C2 {
Douglas Gregorc5cbc242008-12-15 23:53:10 +000015 void m(); // expected-note{{member declaration nearly matches}}
16
17 void f(const int& parm); // expected-note{{member declaration nearly matches}}
18 void f(int) const; // expected-note{{member declaration nearly matches}}
19 void f(float);
20
Argiris Kirtzidis054a2632008-11-08 17:17:31 +000021 int x;
22};
23
Douglas Gregorc5cbc242008-12-15 23:53:10 +000024void C2::m() const { } // expected-error{{out-of-line definition does not match any declaration in 'C2'}}
25
26void C2::f(int) { } // expected-error{{out-of-line definition does not match any declaration in 'C2'}}
27
Argiris Kirtzidis054a2632008-11-08 17:17:31 +000028void C2::m() {
29 x = 0;
30}
31
32namespace B {
Chris Lattner254de7d2008-11-23 20:28:15 +000033 void ::A::Af() {} // expected-error {{definition or redeclaration of 'Af' not in a namespace enclosing 'A'}}
Argiris Kirtzidis054a2632008-11-08 17:17:31 +000034}
35
36void f1() {
Douglas Gregorc5cbc242008-12-15 23:53:10 +000037 void A::Af(); // expected-error {{definition or redeclaration of 'Af' not allowed inside a function}}
Argiris Kirtzidis054a2632008-11-08 17:17:31 +000038}
39
40void f2() {
41 A:: ; // expected-error {{expected unqualified-id}}
42 A::C::undef = 0; // expected-error {{no member named 'undef'}}
43 ::A::C::cx = 0;
44 int x = ::A::ax = A::C::cx;
45 x = sizeof(A::C);
46 x = sizeof(::A::C::cx);
47}
48
49A::C c1;
50struct A::C c2;
51struct S : public A::C {};
52struct A::undef; // expected-error {{'undef' does not name a tag member in the specified scope}}
53
Argiris Kirtzidis881964b2008-11-09 23:41:00 +000054namespace A2 {
55 typedef int INT;
56 struct RC;
Argiris Kirtzidis9cd599b2008-11-19 18:01:13 +000057 struct CC {
58 struct NC;
59 };
Argiris Kirtzidis881964b2008-11-09 23:41:00 +000060}
61
62struct A2::RC {
63 INT x;
64};
65
Argiris Kirtzidis9cd599b2008-11-19 18:01:13 +000066struct A2::CC::NC {
67 void m() {}
68};
69
Argiris Kirtzidis054a2632008-11-08 17:17:31 +000070void f3() {
71 N::x = 0; // expected-error {{use of undeclared identifier 'N'}}
72 int N;
73 N::x = 0; // expected-error {{expected a class or namespace}}
74 { int A; A::ax = 0; }
Douglas Gregorb6bf5442008-12-16 06:37:47 +000075 { typedef int A; A::ax = 0; } // expected-error{{expected a class or namespace}}
76 { int A(); A::ax = 0; }
Argiris Kirtzidis054a2632008-11-08 17:17:31 +000077 { typedef A::C A; A::ax = 0; } // expected-error {{no member named 'ax'}}
78 { typedef A::C A; A::cx = 0; }
79}
Argiris Kirtzidis4c642e12008-11-19 15:22:16 +000080
81// make sure the following doesn't hit any asserts
Chris Lattner921342c2008-11-23 23:17:07 +000082void f4(undef::C); // expected-error {{use of undeclared identifier 'undef'}} // expected-error {{expected ')'}} expected-note {{to match this '('}} // expected-error {{variable has incomplete type 'void'}}
Douglas Gregorc5cbc242008-12-15 23:53:10 +000083
84typedef void C2::f5(int); // expected-error{{typedef declarator cannot be qualified}}
85
86void f6(int A2::RC::x); // expected-error{{parameter declarator cannot be qualified}}
87
88int A2::RC::x; // expected-error{{non-static data member defined out-of-line}}
89
Douglas Gregor195492c2009-03-06 19:06:37 +000090void A2::CC::NC::m(); // expected-error{{out-of-line declaration of a member must be a definition}} \
91 // expected-error{{out-of-line declaration of a member must be a definition}}
Douglas Gregorb6bf5442008-12-16 06:37:47 +000092
93
94namespace E {
95 int X = 5;
96
97 namespace Nested {
98 enum E {
99 X = 0
100 };
101
102 void f() {
103 return E::X; // expected-error{{expected a class or namespace}}
104 }
105 }
106}
Douglas Gregor853dd392008-12-26 15:00:45 +0000107
108
109class Operators {
110 Operators operator+(const Operators&) const; // expected-note{{member declaration nearly matches}}
111 operator bool();
112};
113
114Operators Operators::operator+(const Operators&) { // expected-error{{out-of-line definition does not match any declaration in 'Operators'}}
115 Operators ops;
116 return ops;
117}
118
119Operators Operators::operator+(const Operators&) const {
120 Operators ops;
121 return ops;
122}
123
124Operators::operator bool() {
125 return true;
126}
Douglas Gregor46cfe452009-02-06 17:46:57 +0000127
128namespace A {
129 void g(int&); // expected-note{{member declaration nearly matches}}
130}
131
132void A::f() {} // expected-error{{out-of-line definition does not match any declaration in 'A'}}
133
134void A::g(const int&) { } // expected-error{{out-of-line definition does not match any declaration in 'A'}}
135
136struct Struct { };
137
138void Struct::f() { } // expected-error{{out-of-line definition does not match any declaration in 'Struct'}}
139
140void global_func(int);
141void global_func2(int);
142
143namespace N {
144 void ::global_func(int) { } // expected-error{{definition or redeclaration of 'global_func' cannot name the global scope}}
145
146 void f();
147 // FIXME: if we move this to a separate definition of N, things break!
148}
149void ::global_func2(int) { } // expected-error{{definition or redeclaration of 'global_func2' cannot name the global scope}}
150
151void N::f() { } // okay
Douglas Gregor195492c2009-03-06 19:06:37 +0000152
Douglas Gregor6e7c27c2009-03-11 16:48:53 +0000153struct Y; // expected-note{{forward declaration of 'struct Y'}}
154Y::foo y; // expected-error{{incomplete type 'struct Y' named in nested name specifier}} \
155 // FIXME: ugly: expected-error{{invalid token after top level declarator}}
156
Douglas Gregor195492c2009-03-06 19:06:37 +0000157X::X() : a(5) { } // expected-error{{use of undeclared identifier 'X'}} \
158 // expected-error{{expected function body after function declarator}}
Douglas Gregor6e7c27c2009-03-11 16:48:53 +0000159