blob: 3c1c3602691b4076489c91caf08c3624d5649d25 [file] [log] [blame]
Richard Smitha6e8b682019-09-04 20:30:37 +00001// RUN: %clang_cc1 -verify -fsyntax-only -std=c++2a -pedantic-errors -triple x86_64-linux-gnu %s
Richard Smith09f76ee2011-10-19 21:33:05 +00002
3// Make sure we know these are legitimate commas and not typos for ';'.
4namespace Commas {
5 int a,
6 b [[ ]],
7 c alignas(double);
8}
Richard Smithbfdb1082012-03-12 08:56:40 +00009
10struct S {};
Richard Smith87f5dc52012-07-23 05:45:25 +000011enum E { e, };
Richard Smithbfdb1082012-03-12 08:56:40 +000012
13auto f() -> struct S {
14 return S();
15}
16auto g() -> enum E {
17 return E();
18}
Richard Smith87f5dc52012-07-23 05:45:25 +000019
Richard Smith83c2ecf2016-02-02 23:34:49 +000020int decltype(f())::*ptr_mem_decltype;
21
Richard Smith87f5dc52012-07-23 05:45:25 +000022class ExtraSemiAfterMemFn {
23 // Due to a peculiarity in the C++11 grammar, a deleted or defaulted function
24 // is permitted to be followed by either one or two semicolons.
25 void f() = delete // expected-error {{expected ';' after delete}}
26 void g() = delete; // ok
27 void h() = delete;; // ok
Richard Smith87e79512012-10-17 23:31:46 +000028 void i() = delete;;; // expected-error {{extra ';' after member function definition}}
Richard Smith87f5dc52012-07-23 05:45:25 +000029};
Richard Smith7ac3c6a2012-07-24 20:24:58 +000030
Richard Smith87e79512012-10-17 23:31:46 +000031int *const const p = 0; // expected-error {{duplicate 'const' declaration specifier}}
32const const int *q = 0; // expected-error {{duplicate 'const' declaration specifier}}
33
34struct MultiCV {
35 void f() const const; // expected-error {{duplicate 'const' declaration specifier}}
36};
Richard Smith76965712012-09-13 19:12:50 +000037
38static_assert(something, ""); // expected-error {{undeclared identifier}}
Richard Smith2603b092012-11-15 22:54:20 +000039
40// PR9903
41struct SS {
Richard Smithd052a5782019-10-22 17:44:08 -070042 typedef void d() = default; // expected-error {{function definition declared 'typedef'}} expected-error {{only special member functions and comparison operators may be defaulted}}
Richard Smith2603b092012-11-15 22:54:20 +000043};
Richard Smith5f044ad2013-01-08 22:43:49 +000044
45using PR14855 = int S::; // expected-error {{expected ';' after alias declaration}}
Richard Smith01141a92013-01-14 01:55:13 +000046
47// Ensure that 'this' has a const-qualified type in a trailing return type for
48// a constexpr function.
49struct ConstexprTrailingReturn {
50 int n;
Richard Smith034185c2013-04-21 01:08:50 +000051 constexpr auto f() const -> decltype((n));
Richard Smith01141a92013-01-14 01:55:13 +000052};
53constexpr const int &ConstexprTrailingReturn::f() const { return n; }
Richard Smith1ac67d12013-01-19 03:48:05 +000054
55namespace TestIsValidAfterTypeSpecifier {
56struct s {} v;
57
Richard Smith1ac67d12013-01-19 03:48:05 +000058struct s
Richard Smithb4a9e862013-04-12 22:46:28 +000059thread_local tl;
Richard Smith1ac67d12013-01-19 03:48:05 +000060
61struct s
62&r0 = v;
63
64struct s
65&&r1 = s();
66
67struct s
68bitand r2 = v;
69
70struct s
71and r3 = s();
72
73enum E {};
74enum E
75[[]] e;
76
77}
Richard Smith9ce302e2013-07-11 05:10:21 +000078
79namespace PR5066 {
80 using T = int (*f)(); // expected-error {{type-id cannot have a name}}
81 template<typename T> using U = int (*f)(); // expected-error {{type-id cannot have a name}}
Richard Smithe303e352018-02-02 22:24:54 +000082 auto f() -> int (*f)(); // expected-error {{only variables can be initialized}} expected-error {{expected ';'}}
Richard Smith9ce302e2013-07-11 05:10:21 +000083 auto g = []() -> int (*f)() {}; // expected-error {{type-id cannot have a name}}
84}
Richard Smithf39720b2013-10-13 22:12:28 +000085
86namespace FinalOverride {
87 struct Base {
Alexander Potapenkoe2e8b0e2014-10-03 09:02:53 +000088 virtual void *f();
Richard Smithf39720b2013-10-13 22:12:28 +000089 virtual void *g();
90 virtual void *h();
91 virtual void *i();
92 };
93 struct Derived : Base {
Alexander Potapenkoe2e8b0e2014-10-03 09:02:53 +000094 virtual auto f() -> void *final;
Richard Smithf39720b2013-10-13 22:12:28 +000095 virtual auto g() -> void *override;
96 virtual auto h() -> void *final override;
97 virtual auto i() -> void *override final;
98 };
99}
Richard Smith37a45dd2013-10-24 01:21:09 +0000100
101namespace UsingDeclAttrs {
102 using T __attribute__((aligned(1))) = int;
103 using T [[gnu::aligned(1)]] = int;
104 static_assert(alignof(T) == 1, "");
105
106 using [[gnu::aligned(1)]] T = int; // expected-error {{an attribute list cannot appear here}}
107 using T = int [[gnu::aligned(1)]]; // expected-error {{'aligned' attribute cannot be applied to types}}
108}
Richard Smithc0a5d5b2014-01-10 21:27:55 +0000109
110namespace DuplicateSpecifier {
Richard Smitha6e8b682019-09-04 20:30:37 +0000111 constexpr constexpr int f(); // expected-error {{duplicate 'constexpr' declaration specifier}}
112 constexpr int constexpr a = 0; // expected-error {{duplicate 'constexpr' declaration specifier}}
Richard Smithc0a5d5b2014-01-10 21:27:55 +0000113
114 struct A {
115 friend constexpr int constexpr friend f(); // expected-warning {{duplicate 'friend' declaration specifier}} \
Richard Smitha6e8b682019-09-04 20:30:37 +0000116 // expected-error {{duplicate 'constexpr' declaration specifier}}
Richard Smithc0a5d5b2014-01-10 21:27:55 +0000117 friend struct A friend; // expected-warning {{duplicate 'friend'}} expected-error {{'friend' must appear first}}
118 };
Richard Smitha6e8b682019-09-04 20:30:37 +0000119
120 constinit constexpr int n1 = 0; // expected-error {{cannot combine with previous 'constinit'}}
121 constexpr constinit int n2 = 0; // expected-error {{cannot combine with previous 'constexpr'}}
122 constinit constinit int n3 = 0; // expected-error {{duplicate 'constinit' declaration specifier}}
123
124 consteval constexpr int f1(); // expected-error {{cannot combine with previous 'consteval'}}
125 constexpr consteval int f2(); // expected-error {{cannot combine with previous 'constexpr'}}
126 consteval consteval int f3(); // expected-error {{duplicate 'consteval' declaration specifier}}
127
128 constinit consteval int wat = 0; // expected-error {{cannot combine with previous 'constinit'}}
129 consteval constinit int huh(); // expected-error {{cannot combine with previous 'consteval'}}
Richard Smithc0a5d5b2014-01-10 21:27:55 +0000130}
Richard Smith72553fc2014-01-23 23:53:27 +0000131
Richard Smitha9d10012014-10-04 01:57:39 +0000132namespace ColonColonDecltype {
133 struct S { struct T {}; };
134 ::decltype(S())::T invalid; // expected-error {{expected unqualified-id}}
135}
136
Richard Smithaf3b3252017-05-18 19:21:48 +0000137namespace AliasDeclEndLocation {
138 template<typename T> struct A {};
139 // Ensure that we correctly determine the end of this declaration to be the
140 // end of the annotation token, not the beginning.
141 using B = AliasDeclEndLocation::A<int
142 > // expected-error {{expected ';' after alias declaration}}
143 +;
Richard Smithaf3b3252017-05-18 19:21:48 +0000144 using C = AliasDeclEndLocation::A<int
145 >\
146> // expected-error {{expected ';' after alias declaration}}
147 ;
Richard Smith74639b12017-05-19 01:54:59 +0000148 using D = AliasDeclEndLocation::A<int
149 > // expected-error {{expected ';' after alias declaration}}
Richard Smithb5f81712018-04-30 05:25:48 +0000150 // FIXME: After splitting this >> into two > tokens, we incorrectly determine
151 // the end of the template-id to be after the *second* '>'.
152 using E = AliasDeclEndLocation::A<int>>;
153#define GGG >>>
154 using F = AliasDeclEndLocation::A<int GGG;
155 // expected-error@-1 {{expected ';' after alias declaration}}
Richard Smith74639b12017-05-19 01:54:59 +0000156 B something_else;
Richard Smithaf3b3252017-05-18 19:21:48 +0000157}
158
Richard Smith72553fc2014-01-23 23:53:27 +0000159struct Base { virtual void f() = 0; virtual void g() = 0; virtual void h() = 0; };
160struct MemberComponentOrder : Base {
161 void f() override __asm__("foobar") __attribute__(( )) {}
Richard Smith4b5a9492014-01-24 22:34:35 +0000162 void g() __attribute__(( )) override;
163 void h() __attribute__(( )) override {}
Richard Smith72553fc2014-01-23 23:53:27 +0000164};
Richard Smith843f18f2014-08-13 02:13:15 +0000165
166void NoMissingSemicolonHere(struct S
167 [3]);
168template<int ...N> void NoMissingSemicolonHereEither(struct S
169 ... [N]);
Richard Smithc7ae3e02015-07-21 00:23:34 +0000170
171// This must be at the end of the file; we used to look ahead past the EOF token here.
Richard Smith6f1daa42016-12-16 00:58:48 +0000172// expected-error@+1 {{expected unqualified-id}} expected-error@+1{{expected ';'}}
Richard Smithc7ae3e02015-07-21 00:23:34 +0000173using