1 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic -fcxx-exceptions %s
2 // 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
13 enum {}; // expected-warning{{declaration does not declare anything}}
14 int; // expected-warning {{declaration does not declare anything}}
18 void m0() {}; // ok, one extra ';' is permitted
20 ; // ok, one extra ';' is permitted
23 };; // expected-warning{{extra ';' after member function definition}}
25 template<typename T
> void mt(T
) { }
27 ; // expected-warning{{extra ';' inside a class}}
29 virtual int vf() const volatile = 0;
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}}
40 virtual int PR45267() = \
41 0; // ok, despite escaped newline
46 static const int sci
= 10;
62 // check that we don't consume the token after the access specifier
63 // when it's not a colon
65 public // expected-error{{expected ':'}}
69 // consume the token after the access specifier if it's a semicolon
70 // that was meant to be a colon
72 public; // expected-error{{expected ':'}}
78 #if __cplusplus <= 199711L
79 // expected-error@-2 {{function definition does not declare parameters}}
81 // expected-error@-4 {{expected expression}}
82 // expected-error@-5 {{expected}}
83 // expected-note@-6 {{to match this '{'}}
84 // expected-error@-7 {{expected ';' after class}}
88 #if __cplusplus <= 199711L
89 // expected-error@-2 {{function definition does not declare parameters}}
91 // expected-error@-4 {{variable has incomplete type 'void'}}
92 // expected-error@-5 {{expected ';' after top level declarator}}
95 typedef int F3() { return 0; } // expected-error{{function definition declared 'typedef'}}
96 typedef void F4() {} // expected-error{{function definition declared 'typedef'}}
98 #if __cplusplus >= 201103L
99 // expected-error@-2 {{extraneous closing brace}}
102 namespace ctor_error
{
104 // By [class.qual]p2, this is a constructor declaration.
105 Foo::Foo (F
) = F(); // expected-error{{does not match any declaration in 'ctor_error::Foo'}}
107 class Ctor
{ // expected-note{{not complete until the closing '}'}}
110 Ctor(x
[5]); // expected-error{{incomplete type}}
112 Ctor(UnknownType
*); // expected-error{{unknown type name 'UnknownType'}}
113 void operator+(UnknownType
*); // expected-error{{unknown type name 'UnknownType'}}
116 Ctor::Ctor (x
) = { 0 }; // \
117 // expected-error{{qualified reference to 'Ctor' is a constructor name}}
119 Ctor::Ctor(UnknownType
*) {} // \
120 // expected-error{{unknown type name 'UnknownType'}}
121 void Ctor::operator+(UnknownType
*) {} // \
122 // expected-error{{unknown type name 'UnknownType'}}
132 struct A::B
; // expected-error {{forward declaration of struct cannot have a nested name specifier}}
133 union N::C
; // expected-error {{forward declaration of union cannot have a nested name specifier}}
136 // PR13775: Don't assert here.
146 baz
x(); // expected-error 3{{}}
151 void tpl_mem(int *) {
156 void C2::f() {} // expected-error{{function definition is not allowed here}}
160 namespace CtorErrors
{
162 A(NonExistent
); // expected-error {{unknown type name 'NonExistent'}}
165 B(NonExistent
) : n(0) {} // expected-error {{unknown type name 'NonExistent'}}
169 C(NonExistent
) try {} catch (...) {} // expected-error {{unknown type name 'NonExistent'}}
172 D(NonExistent
) {} // expected-error {{unknown type name 'NonExistent'}}
176 namespace DtorErrors
{
177 struct A
{ ~A(); int n
; } a
;
178 ~A::A() { n
= 0; } // expected-error {{'~' in destructor name should be after nested name specifier}} expected-note {{previous}}
179 A::~A() {} // expected-error {{redefinition}}
181 struct B
{ ~B(); } *b
;
182 DtorErrors::~B::B() {} // expected-error {{'~' in destructor name should be after nested name specifier}}
185 a
.~A::A(); // expected-error {{'~' in destructor name should be after nested name specifier}}
186 b
->~DtorErrors::~B::B(); // expected-error {{'~' in destructor name should be after nested name specifier}}
189 struct C
; // expected-note {{forward decl}}
190 ~C::C() {} // expected-error {{incomplete}} expected-error {{'~' in destructor name should be after nested name specifier}}
192 struct D
{ struct X
{}; ~D() throw(X
); };
193 ~D::D() throw(X
) {} // expected-error {{'~' in destructor name should be after nested name specifier}}
195 ~Undeclared::Undeclared() {} // expected-error {{use of undeclared identifier 'Undeclared'}} expected-error {{'~' in destructor name should be after nested name specifier}}
196 ~Undeclared:: {} // expected-error {{expected identifier}} expected-error {{'~' in destructor name should be after nested name specifier}}
199 // For another struct's destructor, emit the same diagnostic like for
200 // A::~A() in addition to the "~ in the wrong place" one.
201 ~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}}
202 A::~A() {} // expected-error {{non-friend class member '~A' cannot have a qualified name}}
204 // An inline destructor with a redundant class name should also get the
205 // same diagnostic as S::~S.
206 ~S::S() {} // expected-error {{'~' in destructor name should be after nested name specifier}} expected-error {{extra qualification on member '~S'}}
208 // This just shouldn't crash.
209 int I
; // expected-note {{declared here}}
210 ~I::I() {} // expected-error {{'I' is not a class, namespace, or enumeration}} expected-error {{'~' in destructor name should be after nested name specifier}}
214 T t1
= t1
.T::~T
<int>; // expected-error {{destructor name 'T' does not refer to a template}}
215 // Emit the same diagnostic as for the previous case, plus something about ~.
216 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}}
219 namespace BadFriend
{
221 friend int : 3; // expected-error {{friends can only be classes or functions}}
222 friend void f() = 123; // expected-error {{illegal initializer}}
223 friend virtual void f(); // expected-error {{'virtual' is invalid in friend declarations}}
224 friend void f() final
; // expected-error {{'final' is invalid in friend declarations}}
225 friend void f() override
; // expected-error {{'override' is invalid in friend declarations}}
230 int a
= ); // expected-error {{expected expression}}
231 #if __cplusplus <= 199711L
232 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}}
235 int b
= }; // expected-error {{expected expression}}
236 #if __cplusplus <= 199711L
237 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}}
240 int c
= ]; // expected-error {{expected expression}}
241 #if __cplusplus <= 199711L
242 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}}
247 int d
= d
); // expected-error {{expected ';'}}
248 #if __cplusplus <= 199711L
249 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}}
252 int e
= d
]; // expected-error {{expected ';'}}
253 #if __cplusplus <= 199711L
254 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}}
257 int f
= d
// expected-error {{expected ';'}}
258 #if __cplusplus <= 199711L
259 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}}
265 class X1
{ a::operator=; }; // expected-error {{undeclared identifier 'a'}}
266 class X2
{ a::a
; }; // expected-error {{undeclared identifier 'a'}}
269 class BadExceptionSpec
{
270 void f() throw(int; // expected-error {{expected ')'}} expected-note {{to match}}
273 ; // expected-error {{unexpected ';' before ')'}}
279 struct A
{} ::PR41192::a
; // ok, no missing ';' here expected-warning {{extra qualification}}
281 #if __cplusplus >= 201103L
283 struct D
{ static C c
; };
284 struct C
{} decltype(D())::c
; // expected-error {{'decltype' cannot be used to name a declaration}}
288 namespace ArrayMemberAccess
{
291 template<typename T
> int f() const;
293 void f(const A (&a
)[]) {
294 // OK: not a template-id.
295 bool cond
= a
->x
< 10 && a
->x
> 0;
296 // OK: a template-id.
301 namespace UndeclaredBaseTemplate
{
302 template<class> struct imp
;
303 template<class T
> struct is_member_function_pointer
: undeclared
<imp
<T
>::member
> {}; // expected-error {{unknown template name 'undeclared'}}
306 // PR11109 must appear at the end of the source file
307 class pr11109r3
{ // expected-note{{to match this '{'}}
308 public // expected-error{{expected ':'}} expected-error{{expected '}'}} expected-error{{expected ';' after class}}