1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -verify -fsyntax-only -std=c++11 -pedantic-errors -triple x86_64-linux-gnu %s 2f4a2713aSLionel Sambuc 3f4a2713aSLionel Sambuc // Make sure we know these are legitimate commas and not typos for ';'. 4f4a2713aSLionel Sambuc namespace Commas { 5f4a2713aSLionel Sambuc int a, 6f4a2713aSLionel Sambuc b [[ ]], 7f4a2713aSLionel Sambuc c alignas(double); 8f4a2713aSLionel Sambuc } 9f4a2713aSLionel Sambuc 10f4a2713aSLionel Sambuc struct S {}; 11f4a2713aSLionel Sambuc enum E { e, }; 12f4a2713aSLionel Sambuc 13f4a2713aSLionel Sambuc auto f() -> struct S { 14f4a2713aSLionel Sambuc return S(); 15f4a2713aSLionel Sambuc } 16f4a2713aSLionel Sambuc auto g() -> enum E { 17f4a2713aSLionel Sambuc return E(); 18f4a2713aSLionel Sambuc } 19f4a2713aSLionel Sambuc 20f4a2713aSLionel Sambuc class ExtraSemiAfterMemFn { 21f4a2713aSLionel Sambuc // Due to a peculiarity in the C++11 grammar, a deleted or defaulted function 22f4a2713aSLionel Sambuc // is permitted to be followed by either one or two semicolons. 23f4a2713aSLionel Sambuc void f() = delete // expected-error {{expected ';' after delete}} 24f4a2713aSLionel Sambuc void g() = delete; // ok 25f4a2713aSLionel Sambuc void h() = delete;; // ok 26f4a2713aSLionel Sambuc void i() = delete;;; // expected-error {{extra ';' after member function definition}} 27f4a2713aSLionel Sambuc }; 28f4a2713aSLionel Sambuc 29f4a2713aSLionel Sambuc int *const const p = 0; // expected-error {{duplicate 'const' declaration specifier}} 30f4a2713aSLionel Sambuc const const int *q = 0; // expected-error {{duplicate 'const' declaration specifier}} 31f4a2713aSLionel Sambuc 32f4a2713aSLionel Sambuc struct MultiCV { 33f4a2713aSLionel Sambuc void f() const const; // expected-error {{duplicate 'const' declaration specifier}} 34f4a2713aSLionel Sambuc }; 35f4a2713aSLionel Sambuc 36f4a2713aSLionel Sambuc static_assert(something, ""); // expected-error {{undeclared identifier}} 37f4a2713aSLionel Sambuc 38f4a2713aSLionel Sambuc // PR9903 39f4a2713aSLionel Sambuc struct SS { 40f4a2713aSLionel Sambuc typedef void d() = default; // expected-error {{function definition declared 'typedef'}} expected-error {{only special member functions may be defaulted}} 41f4a2713aSLionel Sambuc }; 42f4a2713aSLionel Sambuc 43f4a2713aSLionel Sambuc using PR14855 = int S::; // expected-error {{expected ';' after alias declaration}} 44f4a2713aSLionel Sambuc 45f4a2713aSLionel Sambuc // Ensure that 'this' has a const-qualified type in a trailing return type for 46f4a2713aSLionel Sambuc // a constexpr function. 47f4a2713aSLionel Sambuc struct ConstexprTrailingReturn { 48f4a2713aSLionel Sambuc int n; 49f4a2713aSLionel Sambuc constexpr auto f() const -> decltype((n)); 50f4a2713aSLionel Sambuc }; f() const51f4a2713aSLionel Sambucconstexpr const int &ConstexprTrailingReturn::f() const { return n; } 52f4a2713aSLionel Sambuc 53f4a2713aSLionel Sambuc namespace TestIsValidAfterTypeSpecifier { 54f4a2713aSLionel Sambuc struct s {} v; 55f4a2713aSLionel Sambuc 56f4a2713aSLionel Sambuc struct s 57f4a2713aSLionel Sambuc thread_local tl; 58f4a2713aSLionel Sambuc 59f4a2713aSLionel Sambuc struct s 60f4a2713aSLionel Sambuc &r0 = v; 61f4a2713aSLionel Sambuc 62f4a2713aSLionel Sambuc struct s 63f4a2713aSLionel Sambuc &&r1 = s(); 64f4a2713aSLionel Sambuc 65f4a2713aSLionel Sambuc struct s 66f4a2713aSLionel Sambuc bitand r2 = v; 67f4a2713aSLionel Sambuc 68f4a2713aSLionel Sambuc struct s 69f4a2713aSLionel Sambuc and r3 = s(); 70f4a2713aSLionel Sambuc 71f4a2713aSLionel Sambuc enum E {}; 72f4a2713aSLionel Sambuc enum E 73f4a2713aSLionel Sambuc [[]] e; 74f4a2713aSLionel Sambuc 75f4a2713aSLionel Sambuc } 76f4a2713aSLionel Sambuc 77f4a2713aSLionel Sambuc namespace PR5066 { 78f4a2713aSLionel Sambuc using T = int (*f)(); // expected-error {{type-id cannot have a name}} 79f4a2713aSLionel Sambuc template<typename T> using U = int (*f)(); // expected-error {{type-id cannot have a name}} 80f4a2713aSLionel Sambuc auto f() -> int (*f)(); // expected-error {{type-id cannot have a name}} 81f4a2713aSLionel Sambuc auto g = []() -> int (*f)() {}; // expected-error {{type-id cannot have a name}} 82f4a2713aSLionel Sambuc } 83f4a2713aSLionel Sambuc 84f4a2713aSLionel Sambuc namespace FinalOverride { 85f4a2713aSLionel Sambuc struct Base { 86f4a2713aSLionel Sambuc virtual void *f(); 87f4a2713aSLionel Sambuc virtual void *g(); 88f4a2713aSLionel Sambuc virtual void *h(); 89f4a2713aSLionel Sambuc virtual void *i(); 90f4a2713aSLionel Sambuc }; 91f4a2713aSLionel Sambuc struct Derived : Base { 92f4a2713aSLionel Sambuc virtual auto f() -> void *final; 93f4a2713aSLionel Sambuc virtual auto g() -> void *override; 94f4a2713aSLionel Sambuc virtual auto h() -> void *final override; 95f4a2713aSLionel Sambuc virtual auto i() -> void *override final; 96f4a2713aSLionel Sambuc }; 97f4a2713aSLionel Sambuc } 98f4a2713aSLionel Sambuc 99f4a2713aSLionel Sambuc namespace UsingDeclAttrs { 100f4a2713aSLionel Sambuc using T __attribute__((aligned(1))) = int; 101f4a2713aSLionel Sambuc using T [[gnu::aligned(1)]] = int; 102f4a2713aSLionel Sambuc static_assert(alignof(T) == 1, ""); 103f4a2713aSLionel Sambuc 104f4a2713aSLionel Sambuc using [[gnu::aligned(1)]] T = int; // expected-error {{an attribute list cannot appear here}} 105f4a2713aSLionel Sambuc using T = int [[gnu::aligned(1)]]; // expected-error {{'aligned' attribute cannot be applied to types}} 106f4a2713aSLionel Sambuc } 107*0a6a1f1dSLionel Sambuc 108*0a6a1f1dSLionel Sambuc namespace DuplicateSpecifier { 109*0a6a1f1dSLionel Sambuc constexpr constexpr int f(); // expected-warning {{duplicate 'constexpr' declaration specifier}} 110*0a6a1f1dSLionel Sambuc constexpr int constexpr a = 0; // expected-warning {{duplicate 'constexpr' declaration specifier}} 111*0a6a1f1dSLionel Sambuc 112*0a6a1f1dSLionel Sambuc struct A { 113*0a6a1f1dSLionel Sambuc friend constexpr int constexpr friend f(); // expected-warning {{duplicate 'friend' declaration specifier}} \ 114*0a6a1f1dSLionel Sambuc // expected-warning {{duplicate 'constexpr' declaration specifier}} 115*0a6a1f1dSLionel Sambuc friend struct A friend; // expected-warning {{duplicate 'friend'}} expected-error {{'friend' must appear first}} 116*0a6a1f1dSLionel Sambuc }; 117*0a6a1f1dSLionel Sambuc } 118*0a6a1f1dSLionel Sambuc 119*0a6a1f1dSLionel Sambuc namespace ColonColonDecltype { 120*0a6a1f1dSLionel Sambuc struct S { struct T {}; }; 121*0a6a1f1dSLionel Sambuc ::decltype(S())::T invalid; // expected-error {{expected unqualified-id}} 122*0a6a1f1dSLionel Sambuc } 123*0a6a1f1dSLionel Sambuc 124*0a6a1f1dSLionel Sambuc struct Base { virtual void f() = 0; virtual void g() = 0; virtual void h() = 0; }; 125*0a6a1f1dSLionel Sambuc struct MemberComponentOrder : Base { fMemberComponentOrder126*0a6a1f1dSLionel Sambuc void f() override __asm__("foobar") __attribute__(( )) {} 127*0a6a1f1dSLionel Sambuc void g() __attribute__(( )) override; hMemberComponentOrder128*0a6a1f1dSLionel Sambuc void h() __attribute__(( )) override {} 129*0a6a1f1dSLionel Sambuc }; 130*0a6a1f1dSLionel Sambuc 131*0a6a1f1dSLionel Sambuc void NoMissingSemicolonHere(struct S 132*0a6a1f1dSLionel Sambuc [3]); 133*0a6a1f1dSLionel Sambuc template<int ...N> void NoMissingSemicolonHereEither(struct S 134*0a6a1f1dSLionel Sambuc ... [N]); 135