2013-02-21 04:19:27 +08:00
// RUN: %clang_cc1 -verify -std=c++11 -Wno-anonymous-pack-parens %s
2010-04-24 09:30:46 +08:00
// RUN: cp %s %t
2011-10-14 06:29:44 +08:00
// RUN: not %clang_cc1 -x c++ -std=c++11 -fixit %t
// RUN: %clang_cc1 -Wall -pedantic -x c++ -std=c++11 %t
2009-11-23 21:46:08 +08:00
/* This is a test of the various code modification hints that only
apply in C + + 0 x . */
2010-04-24 09:30:46 +08:00
struct A {
2009-11-23 21:46:08 +08:00
explicit operator int ( ) ; // expected-note{{conversion to integral type}}
} ;
2010-04-24 09:30:46 +08:00
void x ( ) {
2009-11-23 21:46:08 +08:00
switch ( A ( ) ) { // expected-error{{explicit conversion to}}
}
}
2011-04-15 22:24:37 +08:00
using : : T = void ; // expected-error {{name defined in alias declaration must be an identifier}}
using typename U = void ; // expected-error {{name defined in alias declaration must be an identifier}}
using typename : : V = void ; // expected-error {{name defined in alias declaration must be an identifier}}
2011-09-30 03:11:37 +08:00
2011-10-20 05:33:05 +08:00
namespace SemiCommaTypo {
int m { } ,
n [ [ ] ] , // expected-error {{expected ';' at end of declaration}}
int o ;
2012-01-10 06:31:44 +08:00
struct Base {
2014-10-03 17:02:53 +08:00
virtual void f2 ( ) , f3 ( ) ;
2012-01-10 06:31:44 +08:00
} ;
struct MemberDeclarator : Base {
int k : 4 ,
//[[]] : 1, FIXME: test this once we support attributes here
: 9 , // expected-error {{expected ';' at end of declaration}}
char c , // expected-error {{expected ';' at end of declaration}}
typedef void F ( ) , / / expected - error { { expected ' ; ' at end of declaration } }
F f1 ,
2014-10-03 17:02:53 +08:00
f2 final ,
2012-01-10 06:31:44 +08:00
f3 override , // expected-error {{expected ';' at end of declaration}}
} ;
2011-10-20 05:33:05 +08:00
}
2012-01-10 09:33:14 +08:00
namespace ScopedEnum {
enum class E { a } ;
enum class E b = E : : a ; // expected-error {{must use 'enum' not 'enum class'}}
struct S {
friend enum class E ; // expected-error {{must use 'enum' not 'enum class'}}
} ;
}
2012-02-11 01:46:20 +08:00
struct S2 {
void f ( int i ) ;
void g ( int i ) ;
} ;
void S2 : : f ( int i ) {
( void ) [ & , & i , & i ] { } ; // expected-error 2{{'&' cannot precede a capture when the capture default is '&'}}
( void ) [ = , this ] { this - > g ( 5 ) ; } ; // expected-error{{'this' cannot be explicitly captured}}
( void ) [ i , i ] { } ; // expected-error{{'i' can appear only once in a capture list}}
( void ) [ & , i , i ] { } ; // expected-error{{'i' can appear only once in a capture list}}
2012-02-17 09:39:04 +08:00
( void ) [ ] mutable { } ; // expected-error{{lambda requires '()' before 'mutable'}}
( void ) [ ] - > int { } ; // expected-error{{lambda requires '()' before return type}}
2012-02-11 01:46:20 +08:00
}
2012-03-08 10:39:21 +08:00
# define bar "bar"
const char * p = " foo " bar ; // expected-error {{requires a space between}}
# define ord - '0'
int k = ' 4 ' ord ; // expected-error {{requires a space between}}
2012-03-09 07:06:02 +08:00
void operator " x " _y ( char ) ; // expected-error {{must be '""'}}
void operator L " " _z ( char ) ; // expected-error {{encoding prefix}}
void operator " x " " y " U " z " " " _whoops " z " " y " ( char ) ; // expected-error {{must be '""'}}
void f ( ) {
' b ' _y ;
' c ' _z ;
' d ' _whoops ;
}
2012-03-29 09:16:42 +08:00
template < typename . . . Ts > struct MisplacedEllipsis {
int a ( Ts . . . ( x ) ) ; // expected-error {{'...' must immediately precede declared identifier}}
int b ( Ts . . . & x ) ; // expected-error {{'...' must immediately precede declared identifier}}
int c ( Ts . . . & ) ; // expected-error {{'...' must be innermost component of anonymous pack declaration}}
int d ( Ts . . . ( . . . & . . . ) ) ; // expected-error 2{{'...' must be innermost component of anonymous pack declaration}}
int e ( Ts . . . * [ ] ) ; // expected-error {{'...' must be innermost component of anonymous pack declaration}}
int f ( Ts . . . ( . . . * ) ( ) ) ; // expected-error 2{{'...' must be innermost component of anonymous pack declaration}}
int g ( Ts . . . ( ) ) ; // ok
} ;
namespace TestMisplacedEllipsisRecovery {
MisplacedEllipsis < int , char > me ;
int i ; char k ;
int * ip ; char * kp ;
int ifn ( ) ; char kfn ( ) ;
int a = me . a ( i , k ) ;
int b = me . b ( i , k ) ;
int c = me . c ( i , k ) ;
int d = me . d ( i , k ) ;
int e = me . e ( & ip , & kp ) ;
int f = me . f ( ifn , kfn ) ;
int g = me . g ( ifn , kfn ) ;
}
2012-04-06 13:26:43 +08:00
2012-04-06 14:28:32 +08:00
template < template < typename > . . . Foo , // expected-error {{template template parameter requires 'class' after the parameter list}}
template < template < template < typename > > > > // expected-error 3 {{template template parameter requires 'class' after the parameter list}}
2012-04-06 13:26:43 +08:00
void func ( ) ;
2012-04-07 06:40:38 +08:00
template < int * ip > struct IP { } ; // expected-note{{declared here}}
IP < 0 > ip0 ; // expected-error{{null non-type template argument must be cast to template parameter type 'int *'}}
2012-06-26 05:37:02 +08:00
namespace MissingSemi {
struct a // expected-error {{expected ';' after struct}}
struct b // expected-error {{expected ';' after struct}}
enum x : int { x1 , x2 , x3 } // expected-error {{expected ';' after enum}}
struct c // expected-error {{expected ';' after struct}}
enum x : int // expected-error {{expected ';' after enum}}
// FIXME: The following gives a poor diagnostic (we parse the 'int' and the
// 'struct' as part of the same enum-base.
// enum x : int
// struct y
namespace N {
struct d // expected-error {{expected ';' after struct}}
}
}
2013-01-30 09:22:18 +08:00
namespace NonStaticConstexpr {
struct foo {
constexpr int i ; // expected-error {{non-static data member cannot be constexpr; did you intend to make it const?}}
constexpr int j = 7 ; // expected-error {{non-static data member cannot be constexpr; did you intend to make it static?}}
2014-04-15 05:00:40 +08:00
constexpr const int k ; // expected-error {{non-static data member cannot be constexpr; did you intend to make it const?}}
foo ( ) : i ( 3 ) , k ( 4 ) {
2013-01-30 09:22:18 +08:00
}
static int get_j ( ) {
return j ;
}
} ;
}
2013-06-13 10:02:51 +08:00
int RegisterVariable ( ) {
register int n ; // expected-warning {{'register' storage class specifier is deprecated}}
return n ;
}
2014-06-06 10:58:59 +08:00
namespace MisplacedParameterPack {
template < typename Args . . . > // expected-error {{'...' must immediately precede declared identifier}}
void misplacedEllipsisInTypeParameter ( Args . . . ) ;
template < typename . . . Args . . . > // expected-error {{'...' must immediately precede declared identifier}}
void redundantEllipsisInTypeParameter ( Args . . . ) ;
template < template < typename > class Args . . . > // expected-error {{'...' must immediately precede declared identifier}}
void misplacedEllipsisInTemplateTypeParameter ( Args < int > . . . ) ;
template < template < typename > class . . . Args . . . > // expected-error {{'...' must immediately precede declared identifier}}
void redundantEllipsisInTemplateTypeParameter ( Args < int > . . . ) ;
template < int N . . . > // expected-error {{'...' must immediately precede declared identifier}}
void misplacedEllipsisInNonTypeTemplateParameter ( ) ;
template < int . . . N . . . > // expected-error {{'...' must immediately precede declared identifier}}
void redundantEllipsisInNonTypeTemplateParameter ( ) ;
}
2015-03-25 08:53:27 +08:00
2015-03-25 08:53:33 +08:00
namespace MisplacedDeclAndRefSpecAfterVirtSpec {
2015-03-25 08:53:27 +08:00
struct B {
virtual void f ( ) ;
virtual void f ( ) volatile const ;
} ;
struct D : B {
virtual void f ( ) override ;
virtual void f ( ) override final const volatile ; // expected-error {{'const' qualifier may not appear after the virtual specifier 'final'}} expected-error {{'volatile' qualifier may not appear after the virtual specifier 'final'}}
} ;
2015-03-25 08:53:33 +08:00
struct B2 {
virtual void f ( ) & ;
virtual void f ( ) volatile const & & ;
} ;
struct D2 : B2 {
virtual void f ( ) override & ; // expected-error {{'&' qualifier may not appear after the virtual specifier 'override'}}
virtual void f ( ) override final const volatile & & ; // expected-error {{'const' qualifier may not appear after the virtual specifier 'final'}} expected-error {{'volatile' qualifier may not appear after the virtual specifier 'final'}} expected-error {{'&&' qualifier may not appear after the virtual specifier 'final'}}
} ;
2015-03-25 08:53:27 +08:00
}