1 // RUN: %clang_cc1 -verify -fsyntax-only -std=c++11 -pedantic-errors -triple x86_64-linux-gnu %s 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 } 9 10 struct S {}; 11 enum E { e, }; 12 13 auto f() -> struct S { 14 return S(); 15 } 16 auto g() -> enum E { 17 return E(); 18 } 19 20 int decltype(f())::*ptr_mem_decltype; 21 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 28 void i() = delete;;; // expected-error {{extra ';' after member function definition}} 29 }; 30 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 }; 37 38 static_assert(something, ""); // expected-error {{undeclared identifier}} 39 40 // PR9903 41 struct SS { 42 typedef void d() = default; // expected-error {{function definition declared 'typedef'}} expected-error {{only special member functions may be defaulted}} 43 }; 44 45 using PR14855 = int S::; // expected-error {{expected ';' after alias declaration}} 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; 51 constexpr auto f() const -> decltype((n)); 52 }; f() const53constexpr const int &ConstexprTrailingReturn::f() const { return n; } 54 55 namespace TestIsValidAfterTypeSpecifier { 56 struct s {} v; 57 58 struct s 59 thread_local tl; 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 } 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}} 82 auto f() -> int (*f)(); // expected-error {{type-id cannot have a name}} 83 auto g = []() -> int (*f)() {}; // expected-error {{type-id cannot have a name}} 84 } 85 86 namespace FinalOverride { 87 struct Base { 88 virtual void *f(); 89 virtual void *g(); 90 virtual void *h(); 91 virtual void *i(); 92 }; 93 struct Derived : Base { 94 virtual auto f() -> void *final; 95 virtual auto g() -> void *override; 96 virtual auto h() -> void *final override; 97 virtual auto i() -> void *override final; 98 }; 99 } 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 } 109 110 namespace DuplicateSpecifier { 111 constexpr constexpr int f(); // expected-warning {{duplicate 'constexpr' declaration specifier}} 112 constexpr int constexpr a = 0; // expected-warning {{duplicate 'constexpr' declaration specifier}} 113 114 struct A { 115 friend constexpr int constexpr friend f(); // expected-warning {{duplicate 'friend' declaration specifier}} \ 116 // expected-warning {{duplicate 'constexpr' declaration specifier}} 117 friend struct A friend; // expected-warning {{duplicate 'friend'}} expected-error {{'friend' must appear first}} 118 }; 119 } 120 121 namespace ColonColonDecltype { 122 struct S { struct T {}; }; 123 ::decltype(S())::T invalid; // expected-error {{expected unqualified-id}} 124 } 125 126 struct Base { virtual void f() = 0; virtual void g() = 0; virtual void h() = 0; }; 127 struct MemberComponentOrder : Base { fMemberComponentOrder128 void f() override __asm__("foobar") __attribute__(( )) {} 129 void g() __attribute__(( )) override; hMemberComponentOrder130 void h() __attribute__(( )) override {} 131 }; 132 133 void NoMissingSemicolonHere(struct S 134 [3]); 135 template<int ...N> void NoMissingSemicolonHereEither(struct S 136 ... [N]); 137 138 // This must be at the end of the file; we used to look ahead past the EOF token here. 139 // expected-error@+1 {{expected unqualified-id}} 140 using 141