1 // RUN: %clang_cc1 -verify -fsyntax-only -std=c++2a -pedantic-errors -triple x86_64-linux-gnu %s
3 // Make sure we know these are legitimate commas and not typos for ';'.
13 auto f() -> struct S
{
22 // PR19810: The ': E' here is not an enum-base, and the ':' is not a typo for '::'.
23 E e
= true ? *new enum E
: E
{};
24 // PR45726: This ':' is not an enum-base.
25 static_assert(_Generic(e
, enum E
: int{}, int: 1) == 0); // expected-error {{C11 extension}}
26 static_assert(_Generic(1, enum E
: int{}, int: 1) == 1); // expected-error {{C11 extension}}
29 namespace OpaqueEnumDecl
{
33 enum E
: int n
; // expected-error {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration}}
34 typedef enum E
: int T
; // expected-error {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration}}
35 typedef enum E
: int T
; // expected-error {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration}}
37 typedef enum E
: int T
; // expected-error {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration}}
40 // GCC incorrectly accepts this one
41 using T
= enum E
: int; // expected-error {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration}}
44 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}}
47 enum struct E a
; // expected-error {{must use 'enum' not 'enum struct'}}
48 enum class F b
; // expected-error {{must use 'enum' not 'enum class'}}
49 enum G
: int c
; // expected-error {{only permitted as a standalone declaration}}
50 enum struct H
: int d
; // expected-error {{only permitted as a standalone declaration}}
51 enum class I
: int e
; // expected-error {{only permitted as a standalone declaration}}
52 enum X x
; // expected-error {{ISO C++ forbids forward reference}} expected-error {{incomplete}} expected-note {{forward declaration}}
54 enum struct E
*pa
; // expected-error {{must use 'enum' not 'enum struct'}}
55 enum class F
*pb
; // expected-error {{must use 'enum' not 'enum class'}}
56 enum G
: int *pc
; // expected-error {{only permitted as a standalone declaration}}
57 enum struct H
: int *pd
; // expected-error {{only permitted as a standalone declaration}}
58 enum class I
: int *pe
; // expected-error {{only permitted as a standalone declaration}}
59 enum Y
*py
; // expected-error {{ISO C++ forbids forward reference}}
63 int decltype(f())::*ptr_mem_decltype
;
65 class ExtraSemiAfterMemFn
{
66 // Due to a peculiarity in the C++11 grammar, a deleted or defaulted function
67 // is permitted to be followed by either one or two semicolons.
68 void f() = delete // expected-error {{expected ';' after delete}}
69 void g() = delete; // ok
70 void h() = delete;; // ok
71 void i() = delete;;; // expected-error {{extra ';' after member function definition}}
74 int *const const p
= 0; // expected-error {{duplicate 'const' declaration specifier}}
75 const const int *q
= 0; // expected-error {{duplicate 'const' declaration specifier}}
78 void f() const const; // expected-error {{duplicate 'const' declaration specifier}}
81 static_assert(something
, ""); // expected-error {{undeclared identifier}}
85 typedef void d() = default; // expected-error {{function definition declared 'typedef'}} expected-error {{only special member functions and comparison operators may be defaulted}}
88 using PR14855
= int S::; // expected-error {{expected ';' after alias declaration}}
90 // Ensure that 'this' has a const-qualified type in a trailing return type for
91 // a constexpr function.
92 struct ConstexprTrailingReturn
{
94 constexpr auto f() const -> decltype((n
));
96 constexpr const int &ConstexprTrailingReturn::f() const { return n
; }
98 namespace TestIsValidAfterTypeSpecifier
{
123 using T
= int (*f
)(); // expected-error {{type-id cannot have a name}}
124 template<typename T
> using U
= int (*f
)(); // expected-error {{type-id cannot have a name}}
125 auto f() -> int (*f
)(); // expected-error {{only variables can be initialized}} expected-error {{expected ';'}}
126 auto g
= []() -> int (*f
)() {}; // expected-error {{type-id cannot have a name}}
129 namespace FinalOverride
{
136 struct Derived
: Base
{
137 virtual auto f() -> void *final
;
138 virtual auto g() -> void *override
;
139 virtual auto h() -> void *final override
;
140 virtual auto i() -> void *override final
;
144 namespace UsingDeclAttrs
{
145 using T
__attribute__((aligned(1))) = int;
146 using T
[[gnu::aligned(1)]] = int;
147 static_assert(alignof(T
) == 1, "");
149 using [[gnu::aligned(1)]] T
= int; // expected-error {{an attribute list cannot appear here}}
150 using T
= int [[gnu::aligned(1)]]; // expected-error {{'aligned' attribute cannot be applied to types}}
153 namespace DuplicateSpecifier
{
154 constexpr constexpr int f(); // expected-error {{duplicate 'constexpr' declaration specifier}}
155 constexpr int constexpr a
= 0; // expected-error {{duplicate 'constexpr' declaration specifier}}
158 friend constexpr int constexpr friend f(); // expected-warning {{duplicate 'friend' declaration specifier}} \
159 // expected-error {{duplicate 'constexpr' declaration specifier}}
160 friend struct A
friend; // expected-warning {{duplicate 'friend'}}
163 constinit
constexpr int n1
= 0; // expected-error {{cannot combine with previous 'constinit'}}
164 constexpr constinit
int n2
= 0; // expected-error {{cannot combine with previous 'constexpr'}}
165 constinit constinit
int n3
= 0; // expected-error {{duplicate 'constinit' declaration specifier}}
167 consteval
constexpr int f1(); // expected-error {{cannot combine with previous 'consteval'}}
168 constexpr consteval
int f2(); // expected-error {{cannot combine with previous 'constexpr'}}
169 consteval consteval
int f3(); // expected-error {{duplicate 'consteval' declaration specifier}}
171 constinit consteval
int wat
= 0; // expected-error {{cannot combine with previous 'constinit'}}
172 consteval constinit
int huh(); // expected-error {{cannot combine with previous 'consteval'}}
175 namespace ColonColonDecltype
{
176 struct S
{ struct T
{}; };
177 ::decltype(S())::T invalid
; // expected-error {{expected unqualified-id}}
180 namespace AliasDeclEndLocation
{
181 template<typename T
> struct A
{};
182 // Ensure that we correctly determine the end of this declaration to be the
183 // end of the annotation token, not the beginning.
184 using B
= AliasDeclEndLocation::A
<int
185 > // expected-error {{expected ';' after alias declaration}}
187 using C
= AliasDeclEndLocation::A
<int
189 > // expected-error {{expected ';' after alias declaration}}
191 using D
= AliasDeclEndLocation::A
<int
192 > // expected-error {{expected ';' after alias declaration}}
193 // FIXME: After splitting this >> into two > tokens, we incorrectly determine
194 // the end of the template-id to be after the *second* '>'.
195 using E
= AliasDeclEndLocation::A
<int>>;
197 using F
= AliasDeclEndLocation::A
<int GGG
;
198 // expected-error@-1 {{expected ';' after alias declaration}}
203 friend void f(PR47176
, int = 0) noexcept(true) {}
205 static_assert(noexcept(f(PR47176())), "");
207 struct Base
{ virtual void f() = 0; virtual void g() = 0; virtual void h() = 0; };
208 struct MemberComponentOrder
: Base
{
209 void f() override
__asm__("foobar") __attribute__(( )) {}
210 void g() __attribute__(( )) override
;
211 void h() __attribute__(( )) override
{}
214 void NoMissingSemicolonHere(struct S
216 template<int ...N
> void NoMissingSemicolonHereEither(struct S
... [N
]);
217 // expected-error@-1 {{'S' does not refer to the name of a parameter pack}} \
218 // expected-error@-1 {{declaration of anonymous struct must be a definition}} \
219 // expected-error@-1 {{expected parameter declarator}} \
220 // expected-error@-1 {{pack indexing is a C++2c extension}} \
224 // This must be at the end of the file; we used to look ahead past the EOF token here.
225 // expected-error@+1 {{expected unqualified-id}} expected-error@+1{{expected ';'}}