2014-03-04 05:12:53 +08:00
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -fcxx-exceptions %s
2016-04-15 07:47:07 +08:00
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -fcxx-exceptions -std=c++98 %s
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -fcxx-exceptions -std=c++11 %s
2008-11-08 23:40:37 +08:00
class C ;
2008-06-25 06:12:16 +08:00
class C {
public :
protected :
typedef int A , B ;
static int sf ( ) , u ;
struct S { } ;
2010-07-13 14:24:26 +08:00
enum { } ; // expected-warning{{declaration does not declare anything}}
2010-04-09 05:33:23 +08:00
int ; // expected-warning {{declaration does not declare anything}}
2008-06-28 16:10:48 +08:00
int : 1 , : 2 ;
2008-06-25 06:12:16 +08:00
public :
2012-07-23 13:45:25 +08:00
void m0 ( ) { } ; // ok, one extra ';' is permitted
void m1 ( ) { }
; // ok, one extra ';' is permitted
2008-06-25 06:12:16 +08:00
void m ( ) {
int l = 2 ;
2012-07-23 13:45:25 +08:00
} ; ; // expected-warning{{extra ';' after member function definition}}
2011-01-20 00:41:58 +08:00
2012-05-17 03:04:59 +08:00
template < typename T > void mt ( T ) { }
2012-07-23 13:45:25 +08:00
;
2011-01-20 00:41:58 +08:00
; // expected-warning{{extra ';' inside a class}}
2008-11-08 23:40:37 +08:00
virtual int vf ( ) const volatile = 0 ;
2015-06-30 07:19:23 +08:00
virtual int vf0 ( ) = 0l ; // expected-error {{does not look like a pure-specifier}}
virtual int vf1 ( ) = 1 ; // expected-error {{does not look like a pure-specifier}}
virtual int vf2 ( ) = 00 ; // expected-error {{does not look like a pure-specifier}}
virtual int vf3 ( ) = 0x0 ; // expected-error {{does not look like a pure-specifier}}
virtual int vf4 ( ) = 0.0 ; // expected-error {{does not look like a pure-specifier}}
virtual int vf5 ( ) { 0 } ; // expected-error +{{}} expected-warning {{unused}}
virtual int vf5a ( ) { 0 ; } ; // function definition, expected-warning {{unused}}
virtual int vf6 ( ) ( 0 ) ; // expected-error +{{}} expected-note +{{}}
virtual int vf7 ( ) = { 0 } ; // expected-error {{does not look like a pure-specifier}}
2008-06-25 06:12:16 +08:00
private :
int x , f ( ) , y , g ( ) ;
2008-11-08 23:40:37 +08:00
inline int h ( ) ;
static const int sci = 10 ;
2008-11-15 07:42:31 +08:00
mutable int mi ;
2008-06-25 06:12:16 +08:00
} ;
2008-11-08 23:40:37 +08:00
void glo ( )
{
struct local { } ;
}
2008-12-18 09:12:00 +08:00
// PR3177
typedef union {
__extension__ union {
int a ;
float b ;
} y ;
} bug3177 ;
2011-10-13 14:08:43 +08:00
// check that we don't consume the token after the access specifier
// when it's not a colon
class D {
public // expected-error{{expected ':'}}
int i ;
} ;
// consume the token after the access specifier if it's a semicolon
// that was meant to be a colon
class E {
public ; // expected-error{{expected ':'}}
int i ;
} ;
2012-01-21 10:59:18 +08:00
class F {
2016-04-15 07:47:07 +08:00
int F1 { return 1 ; }
# if __cplusplus <= 199711L
// expected-error@-2 {{function definition does not declare parameters}}
# else
// expected-error@-4 {{expected expression}}
// expected-error@-5 {{expected}}
// expected-note@-6 {{to match this '{'}}
// expected-error@-7 {{expected ';' after class}}
# endif
void F2 { }
# if __cplusplus <= 199711L
// expected-error@-2 {{function definition does not declare parameters}}
# else
// expected-error@-4 {{variable has incomplete type 'void'}}
// expected-error@-5 {{expected ';' after top level declarator}}
# endif
2012-01-21 10:59:18 +08:00
typedef int F3 ( ) { return 0 ; } // expected-error{{function definition declared 'typedef'}}
typedef void F4 ( ) { } // expected-error{{function definition declared 'typedef'}}
} ;
2016-04-15 07:47:07 +08:00
# if __cplusplus >= 201103L
// expected-error@-2 {{extraneous closing brace}}
# endif
2012-01-21 10:59:18 +08:00
2012-03-27 08:56:56 +08:00
namespace ctor_error {
class Foo { } ;
// By [class.qual]p2, this is a constructor declaration.
Foo : : Foo ( F ) = F ( ) ; // expected-error{{does not match any declaration in 'ctor_error::Foo'}}
class Ctor { // expected-note{{not complete until the closing '}'}}
Ctor ( f ) ( int ) ; // ok
Ctor ( g ( int ) ) ; // ok
Ctor ( x [ 5 ] ) ; // expected-error{{incomplete type}}
Ctor ( UnknownType * ) ; // expected-error{{unknown type name 'UnknownType'}}
2012-03-29 09:46:00 +08:00
void operator + ( UnknownType * ) ; // expected-error{{unknown type name 'UnknownType'}}
2012-03-27 08:56:56 +08:00
} ;
Ctor : : Ctor ( x ) = { 0 } ; / / \
// expected-error{{qualified reference to 'Ctor' is a constructor name}}
Ctor : : Ctor ( UnknownType * ) { } / / \
2012-03-29 09:46:00 +08:00
// expected-error{{unknown type name 'UnknownType'}}
void Ctor : : operator + ( UnknownType * ) { } / / \
// expected-error{{unknown type name 'UnknownType'}}
2012-03-27 08:56:56 +08:00
}
2013-03-19 06:52:47 +08:00
namespace nns_decl {
struct A {
struct B ;
} ;
namespace N {
union C ;
}
struct A : : B ; // expected-error {{forward declaration of struct cannot have a nested name specifier}}
union N : : C ; // expected-error {{forward declaration of union cannot have a nested name specifier}}
}
2012-09-06 09:37:56 +08:00
// PR13775: Don't assert here.
namespace PR13775 {
class bar
{
public :
void foo ( ) ;
void baz ( ) ;
} ;
void bar : : foo ( )
{
baz x ( ) ; // expected-error 3{{}}
}
}
2013-12-09 13:25:47 +08:00
class pr16989 {
void tpl_mem ( int * ) {
return ;
class C2 {
void f ( ) ;
} ;
void C2 : : f ( ) { } // expected-error{{function definition is not allowed here}}
} ;
} ;
2014-03-04 05:12:53 +08:00
namespace CtorErrors {
struct A {
A ( NonExistent ) ; // expected-error {{unknown type name 'NonExistent'}}
} ;
struct B {
B ( NonExistent ) : n ( 0 ) { } // expected-error {{unknown type name 'NonExistent'}}
int n ;
} ;
struct C {
C ( NonExistent ) try { } catch ( . . . ) { } // expected-error {{unknown type name 'NonExistent'}}
} ;
struct D {
D ( NonExistent ) { } // expected-error {{unknown type name 'NonExistent'}}
} ;
}
2014-09-06 10:06:12 +08:00
namespace DtorErrors {
2015-01-15 08:48:52 +08:00
struct A { ~ A ( ) ; int n ; } a ;
~ A : : A ( ) { n = 0 ; } // expected-error {{'~' in destructor name should be after nested name specifier}} expected-note {{previous}}
2014-09-06 10:06:12 +08:00
A : : ~ A ( ) { } // expected-error {{redefinition}}
struct B { ~ B ( ) ; } * b ;
DtorErrors : : ~ B : : B ( ) { } // expected-error {{'~' in destructor name should be after nested name specifier}}
void f ( ) {
a . ~ A : : A ( ) ; // expected-error {{'~' in destructor name should be after nested name specifier}}
b - > ~ DtorErrors : : ~ B : : B ( ) ; // expected-error {{'~' in destructor name should be after nested name specifier}}
}
2015-01-15 08:48:52 +08:00
struct C ; // expected-note {{forward decl}}
~ C : : C ( ) { } // expected-error {{incomplete}} expected-error {{'~' in destructor name should be after nested name specifier}}
struct D { struct X { } ; ~ D ( ) throw ( X ) ; } ;
~ D : : D ( ) throw ( X ) { } // expected-error {{'~' in destructor name should be after nested name specifier}}
2015-01-30 12:05:15 +08:00
~ Undeclared : : Undeclared ( ) { } // expected-error {{use of undeclared identifier 'Undeclared'}} expected-error {{'~' in destructor name should be after nested name specifier}}
2015-03-29 22:35:39 +08:00
~ Undeclared : : { } // expected-error {{expected identifier}} expected-error {{'~' in destructor name should be after nested name specifier}}
2015-01-31 00:53:11 +08:00
struct S {
// For another struct's destructor, emit the same diagnostic like for
// A::~A() in addition to the "~ in the wrong place" one.
~ 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}}
A : : ~ A ( ) { } // expected-error {{non-friend class member '~A' cannot have a qualified name}}
// An inline destructor with a redundant class name should also get the
// same diagnostic as S::~S.
~ S : : S ( ) { } // expected-error {{'~' in destructor name should be after nested name specifier}} expected-error {{extra qualification on member '~S'}}
// This just shouldn't crash.
int I ; // expected-note {{declared here}}
~ I : : I ( ) { } // expected-error {{'I' is not a class, namespace, or enumeration}} expected-error {{'~' in destructor name should be after nested name specifier}}
} ;
2015-02-02 13:33:50 +08:00
struct T { } ;
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}}
// Emit the same diagnostic as for the previous case, plus something about ~.
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}}
2014-09-06 10:06:12 +08:00
}
2014-08-12 08:22:39 +08:00
namespace BadFriend {
struct A {
friend int : 3 ; // expected-error {{friends can only be classes or functions}}
friend void f ( ) = 123 ; // expected-error {{illegal initializer}}
friend virtual void f ( ) ; // expected-error {{'virtual' is invalid in friend declarations}}
friend void f ( ) final ; // expected-error {{'final' is invalid in friend declarations}}
friend void f ( ) override ; // expected-error {{'override' is invalid in friend declarations}}
} ;
}
2014-08-27 11:23:12 +08:00
class PR20760_a {
2016-04-15 07:47:07 +08:00
int a = ) ; // expected-error {{expected expression}}
# if __cplusplus <= 199711L
// expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}}
# endif
int b = } ; // expected-error {{expected expression}}
# if __cplusplus <= 199711L
// expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}}
# endif
int c = ] ; // expected-error {{expected expression}}
# if __cplusplus <= 199711L
// expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}}
# endif
2014-08-27 11:23:12 +08:00
} ;
class PR20760_b {
2016-04-15 07:47:07 +08:00
int d = d ) ; // expected-error {{expected ';'}}
# if __cplusplus <= 199711L
// expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}}
# endif
int e = d ] ; // expected-error {{expected ';'}}
# if __cplusplus <= 199711L
// expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}}
# endif
int f = d // expected-error {{expected ';'}}
# if __cplusplus <= 199711L
// expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}}
# endif
2014-08-27 11:23:12 +08:00
} ;
2014-09-10 08:59:37 +08:00
namespace PR20887 {
class X1 { a : : operator = ; } ; // expected-error {{undeclared identifier 'a'}}
class X2 { a : : a ; } ; // expected-error {{undeclared identifier 'a'}}
}
2015-01-13 10:24:58 +08:00
class BadExceptionSpec {
void f ( ) throw ( int ; // expected-error {{expected ')'}} expected-note {{to match}}
2015-05-13 05:36:35 +08:00
void g ( ) throw (
int (
; // expected-error {{unexpected ';' before ')'}}
2015-01-13 10:24:58 +08:00
) ) ;
} ;
2011-10-13 14:08:43 +08:00
// PR11109 must appear at the end of the source file
class pr11109r3 { // expected-note{{to match this '{'}}
public // expected-error{{expected ':'}} expected-error{{expected '}'}} expected-error{{expected ';' after class}}