Richard Smith | a6e8b68 | 2019-09-04 20:30:37 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -fsyntax-only -std=c++2a -pedantic-errors -triple x86_64-linux-gnu %s |
Richard Smith | 09f76ee | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 2 | |
| 3 | // Make sure we know these are legitimate commas and not typos for ';'. |
| 4 | namespace Commas { |
| 5 | int a, |
| 6 | b [[ ]], |
| 7 | c alignas(double); |
| 8 | } |
Richard Smith | bfdb108 | 2012-03-12 08:56:40 +0000 | [diff] [blame] | 9 | |
| 10 | struct S {}; |
Richard Smith | 87f5dc5 | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 11 | enum E { e, }; |
Richard Smith | bfdb108 | 2012-03-12 08:56:40 +0000 | [diff] [blame] | 12 | |
| 13 | auto f() -> struct S { |
| 14 | return S(); |
| 15 | } |
| 16 | auto g() -> enum E { |
| 17 | return E(); |
| 18 | } |
Richard Smith | 87f5dc5 | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 19 | |
Richard Smith | 83c2ecf | 2016-02-02 23:34:49 +0000 | [diff] [blame] | 20 | int decltype(f())::*ptr_mem_decltype; |
| 21 | |
Richard Smith | 87f5dc5 | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 22 | class 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 Smith | 87e7951 | 2012-10-17 23:31:46 +0000 | [diff] [blame] | 28 | void i() = delete;;; // expected-error {{extra ';' after member function definition}} |
Richard Smith | 87f5dc5 | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 29 | }; |
Richard Smith | 7ac3c6a | 2012-07-24 20:24:58 +0000 | [diff] [blame] | 30 | |
Richard Smith | 87e7951 | 2012-10-17 23:31:46 +0000 | [diff] [blame] | 31 | int *const const p = 0; // expected-error {{duplicate 'const' declaration specifier}} |
| 32 | const const int *q = 0; // expected-error {{duplicate 'const' declaration specifier}} |
| 33 | |
| 34 | struct MultiCV { |
| 35 | void f() const const; // expected-error {{duplicate 'const' declaration specifier}} |
| 36 | }; |
Richard Smith | 7696571 | 2012-09-13 19:12:50 +0000 | [diff] [blame] | 37 | |
| 38 | static_assert(something, ""); // expected-error {{undeclared identifier}} |
Richard Smith | 2603b09 | 2012-11-15 22:54:20 +0000 | [diff] [blame] | 39 | |
| 40 | // PR9903 |
| 41 | struct SS { |
Richard Smith | d052a578 | 2019-10-22 17:44:08 -0700 | [diff] [blame] | 42 | typedef void d() = default; // expected-error {{function definition declared 'typedef'}} expected-error {{only special member functions and comparison operators may be defaulted}} |
Richard Smith | 2603b09 | 2012-11-15 22:54:20 +0000 | [diff] [blame] | 43 | }; |
Richard Smith | 5f044ad | 2013-01-08 22:43:49 +0000 | [diff] [blame] | 44 | |
| 45 | using PR14855 = int S::; // expected-error {{expected ';' after alias declaration}} |
Richard Smith | 01141a9 | 2013-01-14 01:55:13 +0000 | [diff] [blame] | 46 | |
| 47 | // Ensure that 'this' has a const-qualified type in a trailing return type for |
| 48 | // a constexpr function. |
| 49 | struct ConstexprTrailingReturn { |
| 50 | int n; |
Richard Smith | 034185c | 2013-04-21 01:08:50 +0000 | [diff] [blame] | 51 | constexpr auto f() const -> decltype((n)); |
Richard Smith | 01141a9 | 2013-01-14 01:55:13 +0000 | [diff] [blame] | 52 | }; |
| 53 | constexpr const int &ConstexprTrailingReturn::f() const { return n; } |
Richard Smith | 1ac67d1 | 2013-01-19 03:48:05 +0000 | [diff] [blame] | 54 | |
| 55 | namespace TestIsValidAfterTypeSpecifier { |
| 56 | struct s {} v; |
| 57 | |
Richard Smith | 1ac67d1 | 2013-01-19 03:48:05 +0000 | [diff] [blame] | 58 | struct s |
Richard Smith | b4a9e86 | 2013-04-12 22:46:28 +0000 | [diff] [blame] | 59 | thread_local tl; |
Richard Smith | 1ac67d1 | 2013-01-19 03:48:05 +0000 | [diff] [blame] | 60 | |
| 61 | struct s |
| 62 | &r0 = v; |
| 63 | |
| 64 | struct s |
| 65 | &&r1 = s(); |
| 66 | |
| 67 | struct s |
| 68 | bitand r2 = v; |
| 69 | |
| 70 | struct s |
| 71 | and r3 = s(); |
| 72 | |
| 73 | enum E {}; |
| 74 | enum E |
| 75 | [[]] e; |
| 76 | |
| 77 | } |
Richard Smith | 9ce302e | 2013-07-11 05:10:21 +0000 | [diff] [blame] | 78 | |
| 79 | namespace 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 Smith | e303e35 | 2018-02-02 22:24:54 +0000 | [diff] [blame] | 82 | auto f() -> int (*f)(); // expected-error {{only variables can be initialized}} expected-error {{expected ';'}} |
Richard Smith | 9ce302e | 2013-07-11 05:10:21 +0000 | [diff] [blame] | 83 | auto g = []() -> int (*f)() {}; // expected-error {{type-id cannot have a name}} |
| 84 | } |
Richard Smith | f39720b | 2013-10-13 22:12:28 +0000 | [diff] [blame] | 85 | |
| 86 | namespace FinalOverride { |
| 87 | struct Base { |
Alexander Potapenko | e2e8b0e | 2014-10-03 09:02:53 +0000 | [diff] [blame] | 88 | virtual void *f(); |
Richard Smith | f39720b | 2013-10-13 22:12:28 +0000 | [diff] [blame] | 89 | virtual void *g(); |
| 90 | virtual void *h(); |
| 91 | virtual void *i(); |
| 92 | }; |
| 93 | struct Derived : Base { |
Alexander Potapenko | e2e8b0e | 2014-10-03 09:02:53 +0000 | [diff] [blame] | 94 | virtual auto f() -> void *final; |
Richard Smith | f39720b | 2013-10-13 22:12:28 +0000 | [diff] [blame] | 95 | virtual auto g() -> void *override; |
| 96 | virtual auto h() -> void *final override; |
| 97 | virtual auto i() -> void *override final; |
| 98 | }; |
| 99 | } |
Richard Smith | 37a45dd | 2013-10-24 01:21:09 +0000 | [diff] [blame] | 100 | |
| 101 | namespace 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 Smith | c0a5d5b | 2014-01-10 21:27:55 +0000 | [diff] [blame] | 109 | |
| 110 | namespace DuplicateSpecifier { |
Richard Smith | a6e8b68 | 2019-09-04 20:30:37 +0000 | [diff] [blame] | 111 | constexpr constexpr int f(); // expected-error {{duplicate 'constexpr' declaration specifier}} |
| 112 | constexpr int constexpr a = 0; // expected-error {{duplicate 'constexpr' declaration specifier}} |
Richard Smith | c0a5d5b | 2014-01-10 21:27:55 +0000 | [diff] [blame] | 113 | |
| 114 | struct A { |
| 115 | friend constexpr int constexpr friend f(); // expected-warning {{duplicate 'friend' declaration specifier}} \ |
Richard Smith | a6e8b68 | 2019-09-04 20:30:37 +0000 | [diff] [blame] | 116 | // expected-error {{duplicate 'constexpr' declaration specifier}} |
Richard Smith | c0a5d5b | 2014-01-10 21:27:55 +0000 | [diff] [blame] | 117 | friend struct A friend; // expected-warning {{duplicate 'friend'}} expected-error {{'friend' must appear first}} |
| 118 | }; |
Richard Smith | a6e8b68 | 2019-09-04 20:30:37 +0000 | [diff] [blame] | 119 | |
| 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 Smith | c0a5d5b | 2014-01-10 21:27:55 +0000 | [diff] [blame] | 130 | } |
Richard Smith | 72553fc | 2014-01-23 23:53:27 +0000 | [diff] [blame] | 131 | |
Richard Smith | a9d1001 | 2014-10-04 01:57:39 +0000 | [diff] [blame] | 132 | namespace ColonColonDecltype { |
| 133 | struct S { struct T {}; }; |
| 134 | ::decltype(S())::T invalid; // expected-error {{expected unqualified-id}} |
| 135 | } |
| 136 | |
Richard Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 137 | namespace 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 Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 144 | using C = AliasDeclEndLocation::A<int |
| 145 | >\ |
| 146 | > // expected-error {{expected ';' after alias declaration}} |
| 147 | ; |
Richard Smith | 74639b1 | 2017-05-19 01:54:59 +0000 | [diff] [blame] | 148 | using D = AliasDeclEndLocation::A<int |
| 149 | > // expected-error {{expected ';' after alias declaration}} |
Richard Smith | b5f8171 | 2018-04-30 05:25:48 +0000 | [diff] [blame] | 150 | // 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 Smith | 74639b1 | 2017-05-19 01:54:59 +0000 | [diff] [blame] | 156 | B something_else; |
Richard Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 157 | } |
| 158 | |
Richard Smith | 72553fc | 2014-01-23 23:53:27 +0000 | [diff] [blame] | 159 | struct Base { virtual void f() = 0; virtual void g() = 0; virtual void h() = 0; }; |
| 160 | struct MemberComponentOrder : Base { |
| 161 | void f() override __asm__("foobar") __attribute__(( )) {} |
Richard Smith | 4b5a949 | 2014-01-24 22:34:35 +0000 | [diff] [blame] | 162 | void g() __attribute__(( )) override; |
| 163 | void h() __attribute__(( )) override {} |
Richard Smith | 72553fc | 2014-01-23 23:53:27 +0000 | [diff] [blame] | 164 | }; |
Richard Smith | 843f18f | 2014-08-13 02:13:15 +0000 | [diff] [blame] | 165 | |
| 166 | void NoMissingSemicolonHere(struct S |
| 167 | [3]); |
| 168 | template<int ...N> void NoMissingSemicolonHereEither(struct S |
| 169 | ... [N]); |
Richard Smith | c7ae3e0 | 2015-07-21 00:23:34 +0000 | [diff] [blame] | 170 | |
| 171 | // This must be at the end of the file; we used to look ahead past the EOF token here. |
Richard Smith | 6f1daa4 | 2016-12-16 00:58:48 +0000 | [diff] [blame] | 172 | // expected-error@+1 {{expected unqualified-id}} expected-error@+1{{expected ';'}} |
Richard Smith | c7ae3e0 | 2015-07-21 00:23:34 +0000 | [diff] [blame] | 173 | using |