1 // RUN: %clang_cc1 -std=c++14 -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
{
103 class Foo
{}; // #defined-here
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'}}
106 // expected-note@#defined-here{{defined here}}
108 class Ctor
{ // expected-note{{not complete until the closing '}'}}
111 Ctor(x
[5]); // expected-error{{incomplete type}}
113 Ctor(UnknownType
*); // expected-error{{unknown type name 'UnknownType'}}
114 void operator+(UnknownType
*); // expected-error{{unknown type name 'UnknownType'}}
117 Ctor::Ctor (x
) = { 0 }; // \
118 // expected-error{{qualified reference to 'Ctor' is a constructor name}}
120 Ctor::Ctor(UnknownType
*) {} // \
121 // expected-error{{unknown type name 'UnknownType'}}
122 void Ctor::operator+(UnknownType
*) {} // \
123 // expected-error{{unknown type name 'UnknownType'}}
133 struct A::B
; // expected-error {{forward declaration of struct cannot have a nested name specifier}}
134 union N::C
; // expected-error {{forward declaration of union cannot have a nested name specifier}}
137 // PR13775: Don't assert here.
147 baz
x(); // expected-error 3{{}}
152 void tpl_mem(int *) {
157 void C2::f() {} // expected-error{{function definition is not allowed here}}
161 namespace CtorErrors
{
163 A(NonExistent
); // expected-error {{unknown type name 'NonExistent'}}
166 B(NonExistent
) : n(0) {} // expected-error {{unknown type name 'NonExistent'}}
170 C(NonExistent
) try {} catch (...) {} // expected-error {{unknown type name 'NonExistent'}}
173 D(NonExistent
) {} // expected-error {{unknown type name 'NonExistent'}}
177 namespace DtorErrors
{
178 struct A
{ ~A(); int n
; } a
;
179 ~A::A() { n
= 0; } // expected-error {{'~' in destructor name should be after nested name specifier}} expected-note {{previous}}
180 A::~A() {} // expected-error {{redefinition}}
182 struct B
{ ~B(); } *b
;
183 DtorErrors::~B::B() {} // expected-error {{'~' in destructor name should be after nested name specifier}}
186 a
.~A::A(); // expected-error {{'~' in destructor name should be after nested name specifier}}
187 b
->~DtorErrors::~B::B(); // expected-error {{'~' in destructor name should be after nested name specifier}}
190 struct C
; // expected-note {{forward decl}}
191 ~C::C() {} // expected-error {{incomplete}} expected-error {{'~' in destructor name should be after nested name specifier}}
193 struct D
{ struct X
{}; ~D() throw(X
); };
194 ~D::D() throw(X
) {} // expected-error {{'~' in destructor name should be after nested name specifier}}
196 ~Undeclared::Undeclared() {} // expected-error {{use of undeclared identifier 'Undeclared'}} expected-error {{'~' in destructor name should be after nested name specifier}}
197 ~Undeclared:: {} // expected-error {{expected identifier}} expected-error {{'~' in destructor name should be after nested name specifier}}
200 // For another struct's destructor, emit the same diagnostic like for
201 // A::~A() in addition to the "~ in the wrong place" one.
202 ~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}}
203 A::~A() {} // expected-error {{non-friend class member '~A' cannot have a qualified name}}
205 // An inline destructor with a redundant class name should also get the
206 // same diagnostic as S::~S.
207 ~S::S() {} // expected-error {{'~' in destructor name should be after nested name specifier}} expected-error {{extra qualification on member '~S'}}
209 // This just shouldn't crash.
210 int I
; // expected-note {{declared here}}
211 ~I::I() {} // expected-error {{'I' is not a class, namespace, or enumeration}} expected-error {{'~' in destructor name should be after nested name specifier}}
215 T t1
= t1
.T::~T
<int>; // expected-error {{destructor name 'T' does not refer to a template}}
216 // Emit the same diagnostic as for the previous case, plus something about ~.
217 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}}
220 namespace BadFriend
{
222 friend int : 3; // expected-error {{friends can only be classes or functions}}
223 friend void f() = 123; // expected-error {{illegal initializer}}
224 friend virtual void f(); // expected-error {{'virtual' is invalid in friend declarations}}
225 friend void f() final
; // expected-error {{'final' is invalid in friend declarations}}
226 friend void f() override
; // expected-error {{'override' is invalid in friend declarations}}
231 int a
= ); // expected-error {{expected expression}}
232 #if __cplusplus <= 199711L
233 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}}
236 int b
= }; // expected-error {{expected expression}}
237 #if __cplusplus <= 199711L
238 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}}
241 int c
= ]; // expected-error {{expected expression}}
242 #if __cplusplus <= 199711L
243 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}}
248 int d
= d
); // expected-error {{expected ';'}}
249 #if __cplusplus <= 199711L
250 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}}
253 int e
= d
]; // expected-error {{expected ';'}}
254 #if __cplusplus <= 199711L
255 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}}
258 int f
= d
// expected-error {{expected ';'}}
259 #if __cplusplus <= 199711L
260 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}}
266 class X1
{ a::operator=; }; // expected-error {{undeclared identifier 'a'}}
267 class X2
{ a::a
; }; // expected-error {{undeclared identifier 'a'}}
270 class BadExceptionSpec
{
271 void f() throw(int; // expected-error {{expected ')'}} expected-note {{to match}}
274 ; // expected-error {{unexpected ';' before ')'}}
280 struct A
{} ::PR41192::a
; // ok, no missing ';' here expected-warning {{extra qualification}}
282 #if __cplusplus >= 201103L
284 struct D
{ static C c
; };
285 struct C
{} decltype(D())::c
; // expected-error {{a 'decltype' specifier cannot be used in a declarative nested name specifier}}
289 namespace ArrayMemberAccess
{
292 template<typename T
> int f() const;
294 void f(const A (&a
)[]) {
295 // OK: not a template-id.
296 bool cond
= a
->x
< 10 && a
->x
> 0;
297 // OK: a template-id.
302 namespace UndeclaredBaseTemplate
{
303 template<class> struct imp
;
304 template<class T
> struct is_member_function_pointer
: undeclared
<imp
<T
>::member
> {}; // expected-error {{unknown template name 'undeclared'}}
307 // PR11109 must appear at the end of the source file
308 class pr11109r3
{ // expected-note{{to match this '{'}}
309 public // expected-error{{expected ':'}} expected-error{{expected '}'}} expected-error{{expected ';' after class}}