2019-09-05 04:30:37 +08:00
// RUN: %clang_cc1 -verify -fsyntax-only -std=c++2a -pedantic-errors -triple x86_64-linux-gnu %s
2011-10-20 05:33:05 +08:00
// Make sure we know these are legitimate commas and not typos for ';'.
namespace Commas {
int a ,
b [[ ]] ,
c alignas ( double ) ;
}
2012-03-12 16:56:40 +08:00
struct S { } ;
2012-07-23 13:45:25 +08:00
enum E { e , } ;
2012-03-12 16:56:40 +08:00
auto f ( ) - > struct S {
return S ( ) ;
}
auto g ( ) - > enum E {
return E ( ) ;
}
2012-07-23 13:45:25 +08:00
Fix parsing of enum-base to follow C++11 rules.
Previously we implemented non-standard disambiguation rules to
distinguish an enum-base from a bit-field but otherwise treated a :
after an elaborated-enum-specifier as introducing an enum-base. That
misparses various examples (anywhere an elaborated-type-specifier can
appear followed by a colon, such as within a ternary operator or
_Generic).
We now implement the C++11 rules, with the old cases accepted as
extensions where that seemed reasonable. These amount to:
* an enum-base must always be accompanied by an enum definition (except
in a standalone declaration of the form 'enum E : T;')
* in a member-declaration, 'enum E :' always introduces an enum-base,
never a bit-field
* in a type-specifier (or similar context), 'enum E :' is not
permitted; the colon means whatever else it would mean in that
context.
Fixed underlying types for enums are also permitted in Objective-C and
under MS extensions, plus as a language extension in all other modes.
The behavior in ObjC and MS extensions modes is unchanged (but the
bit-field disambiguation is a bit better); remaining language modes
follow the C++11 rules.
Fixes PR45726, PR39979, PR19810, PR44941, and most of PR24297, plus C++
core issues 1514 and 1966.
2020-05-09 10:24:18 +08:00
namespace EnumBase {
enum E { } ;
// PR19810: The ': E' here is not an enum-base, and the ':' is not a typo for '::'.
E e = true ? * new enum E : E { } ;
// PR45726: This ':' is not an enum-base.
static_assert ( _Generic ( e , enum E : int { } , int : 1 ) = = 0 ) ; // expected-error {{C11 extension}}
static_assert ( _Generic ( 1 , enum E : int { } , int : 1 ) = = 1 ) ; // expected-error {{C11 extension}}
}
namespace OpaqueEnumDecl {
enum E : int ; // ok
// PR44941
enum E : int n ; // expected-error {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration}}
typedef enum E : int T ; // expected-error {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration}}
typedef enum E : int T ; // expected-error {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration}}
namespace Inner {
typedef enum E : int T ; // expected-error {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration}}
}
// GCC incorrectly accepts this one
using T = enum E : int ; // expected-error {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration}}
// PR19810 comment#2
int x [ sizeof ( enum E : int ) ] ; // expected-error {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration}}
namespace PR24297 {
2020-05-11 04:14:51 +08:00
enum struct E a ; // expected-error {{must use 'enum' not 'enum struct'}}
enum class F b ; // expected-error {{must use 'enum' not 'enum class'}}
Fix parsing of enum-base to follow C++11 rules.
Previously we implemented non-standard disambiguation rules to
distinguish an enum-base from a bit-field but otherwise treated a :
after an elaborated-enum-specifier as introducing an enum-base. That
misparses various examples (anywhere an elaborated-type-specifier can
appear followed by a colon, such as within a ternary operator or
_Generic).
We now implement the C++11 rules, with the old cases accepted as
extensions where that seemed reasonable. These amount to:
* an enum-base must always be accompanied by an enum definition (except
in a standalone declaration of the form 'enum E : T;')
* in a member-declaration, 'enum E :' always introduces an enum-base,
never a bit-field
* in a type-specifier (or similar context), 'enum E :' is not
permitted; the colon means whatever else it would mean in that
context.
Fixed underlying types for enums are also permitted in Objective-C and
under MS extensions, plus as a language extension in all other modes.
The behavior in ObjC and MS extensions modes is unchanged (but the
bit-field disambiguation is a bit better); remaining language modes
follow the C++11 rules.
Fixes PR45726, PR39979, PR19810, PR44941, and most of PR24297, plus C++
core issues 1514 and 1966.
2020-05-09 10:24:18 +08:00
enum G : int c ; // expected-error {{only permitted as a standalone declaration}}
enum struct H : int d ; // expected-error {{only permitted as a standalone declaration}}
enum class I : int e ; // expected-error {{only permitted as a standalone declaration}}
enum X x ; // expected-error {{ISO C++ forbids forward reference}} expected-error {{incomplete}} expected-note {{forward declaration}}
2020-05-11 04:14:51 +08:00
enum struct E * pa ; // expected-error {{must use 'enum' not 'enum struct'}}
Fix parsing of enum-base to follow C++11 rules.
Previously we implemented non-standard disambiguation rules to
distinguish an enum-base from a bit-field but otherwise treated a :
after an elaborated-enum-specifier as introducing an enum-base. That
misparses various examples (anywhere an elaborated-type-specifier can
appear followed by a colon, such as within a ternary operator or
_Generic).
We now implement the C++11 rules, with the old cases accepted as
extensions where that seemed reasonable. These amount to:
* an enum-base must always be accompanied by an enum definition (except
in a standalone declaration of the form 'enum E : T;')
* in a member-declaration, 'enum E :' always introduces an enum-base,
never a bit-field
* in a type-specifier (or similar context), 'enum E :' is not
permitted; the colon means whatever else it would mean in that
context.
Fixed underlying types for enums are also permitted in Objective-C and
under MS extensions, plus as a language extension in all other modes.
The behavior in ObjC and MS extensions modes is unchanged (but the
bit-field disambiguation is a bit better); remaining language modes
follow the C++11 rules.
Fixes PR45726, PR39979, PR19810, PR44941, and most of PR24297, plus C++
core issues 1514 and 1966.
2020-05-09 10:24:18 +08:00
enum class F * pb ; // expected-error {{must use 'enum' not 'enum class'}}
2020-05-11 04:14:51 +08:00
enum G : int * pc ; // expected-error {{only permitted as a standalone declaration}}
enum struct H : int * pd ; // expected-error {{only permitted as a standalone declaration}}
enum class I : int * pe ; // expected-error {{only permitted as a standalone declaration}}
Fix parsing of enum-base to follow C++11 rules.
Previously we implemented non-standard disambiguation rules to
distinguish an enum-base from a bit-field but otherwise treated a :
after an elaborated-enum-specifier as introducing an enum-base. That
misparses various examples (anywhere an elaborated-type-specifier can
appear followed by a colon, such as within a ternary operator or
_Generic).
We now implement the C++11 rules, with the old cases accepted as
extensions where that seemed reasonable. These amount to:
* an enum-base must always be accompanied by an enum definition (except
in a standalone declaration of the form 'enum E : T;')
* in a member-declaration, 'enum E :' always introduces an enum-base,
never a bit-field
* in a type-specifier (or similar context), 'enum E :' is not
permitted; the colon means whatever else it would mean in that
context.
Fixed underlying types for enums are also permitted in Objective-C and
under MS extensions, plus as a language extension in all other modes.
The behavior in ObjC and MS extensions modes is unchanged (but the
bit-field disambiguation is a bit better); remaining language modes
follow the C++11 rules.
Fixes PR45726, PR39979, PR19810, PR44941, and most of PR24297, plus C++
core issues 1514 and 1966.
2020-05-09 10:24:18 +08:00
enum Y * py ; // expected-error {{ISO C++ forbids forward reference}}
}
}
2016-02-03 07:34:49 +08:00
int decltype ( f ( ) ) : : * ptr_mem_decltype ;
2012-07-23 13:45:25 +08:00
class ExtraSemiAfterMemFn {
// Due to a peculiarity in the C++11 grammar, a deleted or defaulted function
// is permitted to be followed by either one or two semicolons.
void f ( ) = delete / / expected - error { { expected ' ; ' after delete } }
void g ( ) = delete ; // ok
void h ( ) = delete ; ; // ok
2012-10-18 07:31:46 +08:00
void i ( ) = delete ; ; ; // expected-error {{extra ';' after member function definition}}
2012-07-23 13:45:25 +08:00
} ;
2012-07-25 04:24:58 +08:00
2012-10-18 07:31:46 +08:00
int * const const p = 0 ; // expected-error {{duplicate 'const' declaration specifier}}
const const int * q = 0 ; // expected-error {{duplicate 'const' declaration specifier}}
struct MultiCV {
void f ( ) const const ; // expected-error {{duplicate 'const' declaration specifier}}
} ;
2012-09-14 03:12:50 +08:00
static_assert ( something , " " ) ; // expected-error {{undeclared identifier}}
2012-11-16 06:54:20 +08:00
// PR9903
struct SS {
2019-10-23 08:44:08 +08:00
typedef void d ( ) = default ; // expected-error {{function definition declared 'typedef'}} expected-error {{only special member functions and comparison operators may be defaulted}}
2012-11-16 06:54:20 +08:00
} ;
2013-01-09 06:43:49 +08:00
using PR14855 = int S : : ; // expected-error {{expected ';' after alias declaration}}
2013-01-14 09:55:13 +08:00
// Ensure that 'this' has a const-qualified type in a trailing return type for
// a constexpr function.
struct ConstexprTrailingReturn {
int n ;
2013-04-21 09:08:50 +08:00
constexpr auto f ( ) const - > decltype ( ( n ) ) ;
2013-01-14 09:55:13 +08:00
} ;
constexpr const int & ConstexprTrailingReturn : : f ( ) const { return n ; }
2013-01-19 11:48:05 +08:00
namespace TestIsValidAfterTypeSpecifier {
struct s { } v ;
struct s
2013-04-13 06:46:28 +08:00
thread_local tl ;
2013-01-19 11:48:05 +08:00
struct s
& r0 = v ;
struct s
& & r1 = s ( ) ;
struct s
bitand r2 = v ;
struct s
and r3 = s ( ) ;
enum E { } ;
enum E
[ [ ] ] e ;
}
2013-07-11 13:10:21 +08:00
namespace PR5066 {
using T = int ( * f ) ( ) ; // expected-error {{type-id cannot have a name}}
template < typename T > using U = int ( * f ) ( ) ; // expected-error {{type-id cannot have a name}}
2018-02-03 06:24:54 +08:00
auto f ( ) - > int ( * f ) ( ) ; // expected-error {{only variables can be initialized}} expected-error {{expected ';'}}
2013-07-11 13:10:21 +08:00
auto g = [ ] ( ) - > int ( * f ) ( ) { } ; // expected-error {{type-id cannot have a name}}
}
2013-10-14 06:12:28 +08:00
namespace FinalOverride {
struct Base {
2014-10-03 17:02:53 +08:00
virtual void * f ( ) ;
2013-10-14 06:12:28 +08:00
virtual void * g ( ) ;
virtual void * h ( ) ;
virtual void * i ( ) ;
} ;
struct Derived : Base {
2014-10-03 17:02:53 +08:00
virtual auto f ( ) - > void * final ;
2013-10-14 06:12:28 +08:00
virtual auto g ( ) - > void * override ;
virtual auto h ( ) - > void * final override ;
virtual auto i ( ) - > void * override final ;
} ;
}
2013-10-24 09:21:09 +08:00
namespace UsingDeclAttrs {
using T __attribute__ ( ( aligned ( 1 ) ) ) = int ;
using T [[gnu::aligned(1)]] = int ;
static_assert ( alignof ( T ) = = 1 , " " ) ;
using [[gnu::aligned(1)]] T = int ; // expected-error {{an attribute list cannot appear here}}
using T = int [[gnu::aligned(1)]] ; // expected-error {{'aligned' attribute cannot be applied to types}}
}
2014-01-11 05:27:55 +08:00
namespace DuplicateSpecifier {
2019-09-05 04:30:37 +08:00
constexpr constexpr int f ( ) ; // expected-error {{duplicate 'constexpr' declaration specifier}}
constexpr int constexpr a = 0 ; // expected-error {{duplicate 'constexpr' declaration specifier}}
2014-01-11 05:27:55 +08:00
struct A {
friend constexpr int constexpr friend f ( ) ; / / expected - warning { { duplicate ' friend ' declaration specifier } } \
2019-09-05 04:30:37 +08:00
// expected-error {{duplicate 'constexpr' declaration specifier}}
2014-01-11 05:27:55 +08:00
friend struct A friend ; // expected-warning {{duplicate 'friend'}} expected-error {{'friend' must appear first}}
} ;
2019-09-05 04:30:37 +08:00
constinit constexpr int n1 = 0 ; // expected-error {{cannot combine with previous 'constinit'}}
constexpr constinit int n2 = 0 ; // expected-error {{cannot combine with previous 'constexpr'}}
constinit constinit int n3 = 0 ; // expected-error {{duplicate 'constinit' declaration specifier}}
consteval constexpr int f1 ( ) ; // expected-error {{cannot combine with previous 'consteval'}}
constexpr consteval int f2 ( ) ; // expected-error {{cannot combine with previous 'constexpr'}}
consteval consteval int f3 ( ) ; // expected-error {{duplicate 'consteval' declaration specifier}}
constinit consteval int wat = 0 ; // expected-error {{cannot combine with previous 'constinit'}}
consteval constinit int huh ( ) ; // expected-error {{cannot combine with previous 'consteval'}}
2014-01-11 05:27:55 +08:00
}
2014-01-24 07:53:27 +08:00
2014-10-04 09:57:39 +08:00
namespace ColonColonDecltype {
struct S { struct T { } ; } ;
: : decltype ( S ( ) ) : : T invalid ; // expected-error {{expected unqualified-id}}
}
2017-05-19 03:21:48 +08:00
namespace AliasDeclEndLocation {
template < typename T > struct A { } ;
// Ensure that we correctly determine the end of this declaration to be the
// end of the annotation token, not the beginning.
using B = AliasDeclEndLocation : : A < int
> // expected-error {{expected ';' after alias declaration}}
+ ;
using C = AliasDeclEndLocation : : A < int
> \
> // expected-error {{expected ';' after alias declaration}}
;
2017-05-19 09:54:59 +08:00
using D = AliasDeclEndLocation : : A < int
> // expected-error {{expected ';' after alias declaration}}
2018-04-30 13:25:48 +08:00
// FIXME: After splitting this >> into two > tokens, we incorrectly determine
// the end of the template-id to be after the *second* '>'.
using E = AliasDeclEndLocation : : A < int > > ;
# define GGG >>>
using F = AliasDeclEndLocation : : A < int GGG ;
// expected-error@-1 {{expected ';' after alias declaration}}
2017-05-19 09:54:59 +08:00
B something_else ;
2017-05-19 03:21:48 +08:00
}
2020-09-25 09:07:05 +08:00
class PR47176 {
friend void f ( PR47176 , int = 0 ) noexcept ( true ) { }
} ;
static_assert ( noexcept ( f ( PR47176 ( ) ) ) , " " ) ;
2014-01-24 07:53:27 +08:00
struct Base { virtual void f ( ) = 0 ; virtual void g ( ) = 0 ; virtual void h ( ) = 0 ; } ;
struct MemberComponentOrder : Base {
void f ( ) override __asm__ ( " foobar " ) __attribute__ ( ( ) ) { }
2014-01-25 06:34:35 +08:00
void g ( ) __attribute__ ( ( ) ) override ;
void h ( ) __attribute__ ( ( ) ) override { }
2014-01-24 07:53:27 +08:00
} ;
2014-08-13 10:13:15 +08:00
void NoMissingSemicolonHere ( struct S
[ 3 ] ) ;
template < int . . . N > void NoMissingSemicolonHereEither ( struct S
. . . [ N ] ) ;
2015-07-21 08:23:34 +08:00
// This must be at the end of the file; we used to look ahead past the EOF token here.
2016-12-16 08:58:48 +08:00
// expected-error@+1 {{expected unqualified-id}} expected-error@+1{{expected ';'}}
2015-07-21 08:23:34 +08:00
using