blob: 2b6de3363b7e68f7a7a9acaa6e534f0ba744f579 [file] [log] [blame]
Douglas Gregor3dde5a32008-12-16 06:37:47 +00001// RUN: clang -fsyntax-only -verify -std=c++98 %s
Sebastian Redlddf7e992009-02-08 10:28:44 +00002// fails due to exact diagnostic matching
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +00003namespace A {
4 struct C {
5 static int cx;
6 };
7 int ax;
8 void Af();
9}
10
11A:: ; // expected-error {{expected unqualified-id}}
Douglas Gregor9fa14a52009-03-06 19:06:37 +000012::A::ax::undef ex3; // expected-error {{expected a class or namespace}} expected-error {{invalid token after top level declarator}}
13A::undef1::undef2 ex4; // expected-error {{no member named 'undef1'}} expected-error {{invalid token after top level declarator}}
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +000014
15class C2 {
Douglas Gregor584049d2008-12-15 23:53:10 +000016 void m(); // expected-note{{member declaration nearly matches}}
17
18 void f(const int& parm); // expected-note{{member declaration nearly matches}}
19 void f(int) const; // expected-note{{member declaration nearly matches}}
20 void f(float);
21
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +000022 int x;
23};
24
Douglas Gregor584049d2008-12-15 23:53:10 +000025void C2::m() const { } // expected-error{{out-of-line definition does not match any declaration in 'C2'}}
26
27void C2::f(int) { } // expected-error{{out-of-line definition does not match any declaration in 'C2'}}
28
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +000029void C2::m() {
30 x = 0;
31}
32
33namespace B {
Chris Lattner011bb4e2008-11-23 20:28:15 +000034 void ::A::Af() {} // expected-error {{definition or redeclaration of 'Af' not in a namespace enclosing 'A'}}
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +000035}
36
37void f1() {
Douglas Gregor584049d2008-12-15 23:53:10 +000038 void A::Af(); // expected-error {{definition or redeclaration of 'Af' not allowed inside a function}}
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +000039}
40
41void f2() {
42 A:: ; // expected-error {{expected unqualified-id}}
43 A::C::undef = 0; // expected-error {{no member named 'undef'}}
44 ::A::C::cx = 0;
45 int x = ::A::ax = A::C::cx;
46 x = sizeof(A::C);
47 x = sizeof(::A::C::cx);
48}
49
50A::C c1;
51struct A::C c2;
52struct S : public A::C {};
53struct A::undef; // expected-error {{'undef' does not name a tag member in the specified scope}}
54
Argyrios Kyrtzidis52393042008-11-09 23:41:00 +000055namespace A2 {
56 typedef int INT;
57 struct RC;
Argyrios Kyrtzidis77407b82008-11-19 18:01:13 +000058 struct CC {
59 struct NC;
60 };
Argyrios Kyrtzidis52393042008-11-09 23:41:00 +000061}
62
63struct A2::RC {
64 INT x;
65};
66
Argyrios Kyrtzidis77407b82008-11-19 18:01:13 +000067struct A2::CC::NC {
68 void m() {}
69};
70
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +000071void f3() {
72 N::x = 0; // expected-error {{use of undeclared identifier 'N'}}
73 int N;
74 N::x = 0; // expected-error {{expected a class or namespace}}
75 { int A; A::ax = 0; }
Douglas Gregor3dde5a32008-12-16 06:37:47 +000076 { typedef int A; A::ax = 0; } // expected-error{{expected a class or namespace}}
77 { int A(); A::ax = 0; }
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +000078 { typedef A::C A; A::ax = 0; } // expected-error {{no member named 'ax'}}
79 { typedef A::C A; A::cx = 0; }
80}
Argyrios Kyrtzidis08b2c372008-11-19 15:22:16 +000081
82// make sure the following doesn't hit any asserts
Chris Lattner28eb7e92008-11-23 23:17:07 +000083void 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 Gregor584049d2008-12-15 23:53:10 +000084
85typedef void C2::f5(int); // expected-error{{typedef declarator cannot be qualified}}
86
87void f6(int A2::RC::x); // expected-error{{parameter declarator cannot be qualified}}
88
89int A2::RC::x; // expected-error{{non-static data member defined out-of-line}}
90
Douglas Gregor9fa14a52009-03-06 19:06:37 +000091void A2::CC::NC::m(); // expected-error{{out-of-line declaration of a member must be a definition}} \
92 // expected-error{{out-of-line declaration of a member must be a definition}}
Douglas Gregor3dde5a32008-12-16 06:37:47 +000093
94
95namespace E {
96 int X = 5;
97
98 namespace Nested {
99 enum E {
100 X = 0
101 };
102
103 void f() {
104 return E::X; // expected-error{{expected a class or namespace}}
105 }
106 }
107}
Douglas Gregor70316a02008-12-26 15:00:45 +0000108
109
110class Operators {
111 Operators operator+(const Operators&) const; // expected-note{{member declaration nearly matches}}
112 operator bool();
113};
114
115Operators Operators::operator+(const Operators&) { // expected-error{{out-of-line definition does not match any declaration in 'Operators'}}
116 Operators ops;
117 return ops;
118}
119
120Operators Operators::operator+(const Operators&) const {
121 Operators ops;
122 return ops;
123}
124
125Operators::operator bool() {
126 return true;
127}
Douglas Gregor4ce205f2009-02-06 17:46:57 +0000128
129namespace A {
130 void g(int&); // expected-note{{member declaration nearly matches}}
131}
132
133void A::f() {} // expected-error{{out-of-line definition does not match any declaration in 'A'}}
134
135void A::g(const int&) { } // expected-error{{out-of-line definition does not match any declaration in 'A'}}
136
137struct Struct { };
138
139void Struct::f() { } // expected-error{{out-of-line definition does not match any declaration in 'Struct'}}
140
141void global_func(int);
142void global_func2(int);
143
144namespace N {
145 void ::global_func(int) { } // expected-error{{definition or redeclaration of 'global_func' cannot name the global scope}}
146
147 void f();
148 // FIXME: if we move this to a separate definition of N, things break!
149}
150void ::global_func2(int) { } // expected-error{{definition or redeclaration of 'global_func2' cannot name the global scope}}
151
152void N::f() { } // okay
Douglas Gregor9fa14a52009-03-06 19:06:37 +0000153
154X::X() : a(5) { } // expected-error{{use of undeclared identifier 'X'}} \
155 // expected-error{{expected function body after function declarator}}