blob: 3cc006af23dc0cb7ba6f7a16a51ec2a27304be5d [file] [log] [blame]
Richard Smith446161b2014-03-03 21:12:53 +00001// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -fcxx-exceptions %s
Charles Li1a88adb2016-04-14 23:47:07 +00002// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -fcxx-exceptions -std=c++98 %s
3// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -fcxx-exceptions -std=c++11 %s
4
Sebastian Redlf4485de2008-11-08 15:40:37 +00005class C;
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +00006class C {
7public:
8protected:
9 typedef int A,B;
10 static int sf(), u;
11
12 struct S {};
Douglas Gregoraa8c9722010-07-13 06:24:26 +000013 enum {}; // expected-warning{{declaration does not declare anything}}
Douglas Gregorf19ac0e2010-04-08 21:33:23 +000014 int; // expected-warning {{declaration does not declare anything}}
Argyrios Kyrtzidisf4ebe9e2008-06-28 08:10:48 +000015 int : 1, : 2;
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +000016
17public:
Richard Smith87f5dc52012-07-23 05:45:25 +000018 void m0() {}; // ok, one extra ';' is permitted
19 void m1() {}
20 ; // ok, one extra ';' is permitted
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +000021 void m() {
22 int l = 2;
Richard Smith87f5dc52012-07-23 05:45:25 +000023 };; // expected-warning{{extra ';' after member function definition}}
Douglas Gregor8a4db832011-01-19 16:41:58 +000024
Richard Trieu2f7dc462012-05-16 19:04:59 +000025 template<typename T> void mt(T) { }
Richard Smith87f5dc52012-07-23 05:45:25 +000026 ;
Douglas Gregor8a4db832011-01-19 16:41:58 +000027 ; // expected-warning{{extra ';' inside a class}}
28
Sebastian Redlf4485de2008-11-08 15:40:37 +000029 virtual int vf() const volatile = 0;
Richard Smith40cdd7a2015-06-29 23:19:23 +000030
31 virtual int vf0() = 0l; // expected-error {{does not look like a pure-specifier}}
32 virtual int vf1() = 1; // expected-error {{does not look like a pure-specifier}}
33 virtual int vf2() = 00; // expected-error {{does not look like a pure-specifier}}
34 virtual int vf3() = 0x0; // expected-error {{does not look like a pure-specifier}}
35 virtual int vf4() = 0.0; // expected-error {{does not look like a pure-specifier}}
36 virtual int vf5(){0}; // expected-error +{{}} expected-warning {{unused}}
37 virtual int vf5a(){0;}; // function definition, expected-warning {{unused}}
38 virtual int vf6()(0); // expected-error +{{}} expected-note +{{}}
39 virtual int vf7() = { 0 }; // expected-error {{does not look like a pure-specifier}}
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +000040
41private:
42 int x,f(),y,g();
Sebastian Redlf4485de2008-11-08 15:40:37 +000043 inline int h();
44 static const int sci = 10;
Sebastian Redlccdfaba2008-11-14 23:42:31 +000045 mutable int mi;
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +000046};
Sebastian Redlf4485de2008-11-08 15:40:37 +000047void glo()
48{
49 struct local {};
50}
Chris Lattnerd19c1c02008-12-18 01:12:00 +000051
52// PR3177
53typedef union {
54 __extension__ union {
55 int a;
56 float b;
57 } y;
58} bug3177;
59
David Blaikieeba32c22011-10-13 06:08:43 +000060// check that we don't consume the token after the access specifier
61// when it's not a colon
62class D {
63public // expected-error{{expected ':'}}
64 int i;
65};
66
67// consume the token after the access specifier if it's a semicolon
68// that was meant to be a colon
69class E {
70public; // expected-error{{expected ':'}}
71 int i;
72};
73
Richard Trieu0d730542012-01-21 02:59:18 +000074class F {
Charles Li1a88adb2016-04-14 23:47:07 +000075 int F1 { return 1; }
76#if __cplusplus <= 199711L
77 // expected-error@-2 {{function definition does not declare parameters}}
78#else
79 // expected-error@-4 {{expected expression}}
80 // expected-error@-5 {{expected}}
81 // expected-note@-6 {{to match this '{'}}
82 // expected-error@-7 {{expected ';' after class}}
83#endif
84
85 void F2 {}
86#if __cplusplus <= 199711L
87 // expected-error@-2 {{function definition does not declare parameters}}
88#else
89 // expected-error@-4 {{variable has incomplete type 'void'}}
90 // expected-error@-5 {{expected ';' after top level declarator}}
91#endif
92
Richard Trieu0d730542012-01-21 02:59:18 +000093 typedef int F3() { return 0; } // expected-error{{function definition declared 'typedef'}}
94 typedef void F4() {} // expected-error{{function definition declared 'typedef'}}
95};
Charles Li1a88adb2016-04-14 23:47:07 +000096#if __cplusplus >= 201103L
97// expected-error@-2 {{extraneous closing brace}}
98#endif
Richard Trieu0d730542012-01-21 02:59:18 +000099
Richard Smithefd009d2012-03-27 00:56:56 +0000100namespace ctor_error {
101 class Foo {};
102 // By [class.qual]p2, this is a constructor declaration.
103 Foo::Foo (F) = F(); // expected-error{{does not match any declaration in 'ctor_error::Foo'}}
104
105 class Ctor { // expected-note{{not complete until the closing '}'}}
106 Ctor(f)(int); // ok
107 Ctor(g(int)); // ok
108 Ctor(x[5]); // expected-error{{incomplete type}}
109
110 Ctor(UnknownType *); // expected-error{{unknown type name 'UnknownType'}}
Richard Smith01910232012-03-29 01:46:00 +0000111 void operator+(UnknownType*); // expected-error{{unknown type name 'UnknownType'}}
Richard Smithefd009d2012-03-27 00:56:56 +0000112 };
113
114 Ctor::Ctor (x) = { 0 }; // \
115 // expected-error{{qualified reference to 'Ctor' is a constructor name}}
116
Richard Smithefd009d2012-03-27 00:56:56 +0000117 Ctor::Ctor(UnknownType *) {} // \
Richard Smith01910232012-03-29 01:46:00 +0000118 // expected-error{{unknown type name 'UnknownType'}}
119 void Ctor::operator+(UnknownType*) {} // \
120 // expected-error{{unknown type name 'UnknownType'}}
Richard Smithefd009d2012-03-27 00:56:56 +0000121}
122
Richard Smithb1402ae2013-03-18 22:52:47 +0000123namespace nns_decl {
124 struct A {
125 struct B;
126 };
127 namespace N {
128 union C;
129 }
130 struct A::B; // expected-error {{forward declaration of struct cannot have a nested name specifier}}
131 union N::C; // expected-error {{forward declaration of union cannot have a nested name specifier}}
132}
133
Richard Smithaa31b4b2012-09-06 01:37:56 +0000134// PR13775: Don't assert here.
135namespace PR13775 {
136 class bar
137 {
138 public:
139 void foo ();
140 void baz ();
141 };
142 void bar::foo ()
143 {
144 baz x(); // expected-error 3{{}}
145 }
146}
147
Serge Pavlov1de51512013-12-09 05:25:47 +0000148class pr16989 {
149 void tpl_mem(int *) {
150 return;
151 class C2 {
152 void f();
153 };
154 void C2::f() {} // expected-error{{function definition is not allowed here}}
155 };
156};
157
Richard Smith446161b2014-03-03 21:12:53 +0000158namespace CtorErrors {
159 struct A {
160 A(NonExistent); // expected-error {{unknown type name 'NonExistent'}}
161 };
162 struct B {
163 B(NonExistent) : n(0) {} // expected-error {{unknown type name 'NonExistent'}}
164 int n;
165 };
166 struct C {
167 C(NonExistent) try {} catch (...) {} // expected-error {{unknown type name 'NonExistent'}}
168 };
169 struct D {
170 D(NonExistent) {} // expected-error {{unknown type name 'NonExistent'}}
171 };
172}
173
Richard Smithefa6f732014-09-06 02:06:12 +0000174namespace DtorErrors {
Richard Smith64e033f2015-01-15 00:48:52 +0000175 struct A { ~A(); int n; } a;
176 ~A::A() { n = 0; } // expected-error {{'~' in destructor name should be after nested name specifier}} expected-note {{previous}}
Richard Smithefa6f732014-09-06 02:06:12 +0000177 A::~A() {} // expected-error {{redefinition}}
178
179 struct B { ~B(); } *b;
180 DtorErrors::~B::B() {} // expected-error {{'~' in destructor name should be after nested name specifier}}
181
182 void f() {
183 a.~A::A(); // expected-error {{'~' in destructor name should be after nested name specifier}}
184 b->~DtorErrors::~B::B(); // expected-error {{'~' in destructor name should be after nested name specifier}}
185 }
Richard Smith64e033f2015-01-15 00:48:52 +0000186
187 struct C; // expected-note {{forward decl}}
188 ~C::C() {} // expected-error {{incomplete}} expected-error {{'~' in destructor name should be after nested name specifier}}
189
190 struct D { struct X {}; ~D() throw(X); };
191 ~D::D() throw(X) {} // expected-error {{'~' in destructor name should be after nested name specifier}}
Nico Weberd0045862015-01-30 04:05:15 +0000192
193 ~Undeclared::Undeclared() {} // expected-error {{use of undeclared identifier 'Undeclared'}} expected-error {{'~' in destructor name should be after nested name specifier}}
Benjamin Kramer3012e592015-03-29 14:35:39 +0000194 ~Undeclared:: {} // expected-error {{expected identifier}} expected-error {{'~' in destructor name should be after nested name specifier}}
Nico Weberf9e37be2015-01-30 16:53:11 +0000195
196 struct S {
197 // For another struct's destructor, emit the same diagnostic like for
198 // A::~A() in addition to the "~ in the wrong place" one.
199 ~A::A() {} // expected-error {{'~' in destructor name should be after nested name specifier}} expected-error {{non-friend class member '~A' cannot have a qualified name}}
200 A::~A() {} // expected-error {{non-friend class member '~A' cannot have a qualified name}}
201
202 // An inline destructor with a redundant class name should also get the
203 // same diagnostic as S::~S.
204 ~S::S() {} // expected-error {{'~' in destructor name should be after nested name specifier}} expected-error {{extra qualification on member '~S'}}
205
206 // This just shouldn't crash.
207 int I; // expected-note {{declared here}}
208 ~I::I() {} // expected-error {{'I' is not a class, namespace, or enumeration}} expected-error {{'~' in destructor name should be after nested name specifier}}
209 };
Nico Weber7f8ec522015-02-02 05:33:50 +0000210
211 struct T {};
212 T t1 = t1.T::~T<int>; // expected-error {{destructor name 'T' does not refer to a template}} expected-error {{expected '(' for function-style cast or type construction}} expected-error {{expected expression}}
213 // Emit the same diagnostic as for the previous case, plus something about ~.
214 T t2 = t2.~T::T<int>; // expected-error {{'~' in destructor name should be after nested name specifier}} expected-error {{destructor name 'T' does not refer to a template}} expected-error {{expected '(' for function-style cast or type construction}} expected-error {{expected expression}}
Richard Smithefa6f732014-09-06 02:06:12 +0000215}
216
Richard Smith3d1a94c2014-08-12 00:22:39 +0000217namespace BadFriend {
218 struct A {
219 friend int : 3; // expected-error {{friends can only be classes or functions}}
220 friend void f() = 123; // expected-error {{illegal initializer}}
221 friend virtual void f(); // expected-error {{'virtual' is invalid in friend declarations}}
222 friend void f() final; // expected-error {{'final' is invalid in friend declarations}}
223 friend void f() override; // expected-error {{'override' is invalid in friend declarations}}
224 };
225}
226
Richard Smith95e1fb02014-08-27 03:23:12 +0000227class PR20760_a {
Charles Li1a88adb2016-04-14 23:47:07 +0000228 int a = ); // expected-error {{expected expression}}
229#if __cplusplus <= 199711L
230 // expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}}
231#endif
232
233 int b = }; // expected-error {{expected expression}}
234#if __cplusplus <= 199711L
235 // expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}}
236#endif
237
238 int c = ]; // expected-error {{expected expression}}
239#if __cplusplus <= 199711L
240 // expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}}
241#endif
242
Richard Smith95e1fb02014-08-27 03:23:12 +0000243};
244class PR20760_b {
Charles Li1a88adb2016-04-14 23:47:07 +0000245 int d = d); // expected-error {{expected ';'}}
246#if __cplusplus <= 199711L
247 // expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}}
248#endif
249
250 int e = d]; // expected-error {{expected ';'}}
251#if __cplusplus <= 199711L
252 // expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}}
253#endif
254
255 int f = d // expected-error {{expected ';'}}
256#if __cplusplus <= 199711L
257 // expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}}
258#endif
259
Richard Smith95e1fb02014-08-27 03:23:12 +0000260};
261
Nico Weberef03e702014-09-10 00:59:37 +0000262namespace PR20887 {
263class X1 { a::operator=; }; // expected-error {{undeclared identifier 'a'}}
264class X2 { a::a; }; // expected-error {{undeclared identifier 'a'}}
265}
266
Richard Smithb1c217e2015-01-13 02:24:58 +0000267class BadExceptionSpec {
268 void f() throw(int; // expected-error {{expected ')'}} expected-note {{to match}}
Richard Trieu1d3b58e2015-05-12 21:36:35 +0000269 void g() throw(
270 int(
271 ; // expected-error {{unexpected ';' before ')'}}
Richard Smithb1c217e2015-01-13 02:24:58 +0000272 ));
273};
274
David Blaikieeba32c22011-10-13 06:08:43 +0000275// PR11109 must appear at the end of the source file
276class pr11109r3 { // expected-note{{to match this '{'}}
277 public // expected-error{{expected ':'}} expected-error{{expected '}'}} expected-error{{expected ';' after class}}