brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.8 KiB · 69a8d8a Raw
228 lines · cpp
1// RUN: %clang_cc1 -verify -fsyntax-only -std=c++2a -pedantic-errors -triple x86_64-linux-gnu %s2 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}9 10struct S {};11enum E { e, };12 13auto f() -> struct S {14  return S();15}16auto g() -> enum E {17  return E();18}19 20namespace EnumBase {21  enum E {};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}}27}28 29namespace OpaqueEnumDecl {30  enum E : int; // ok31 32  // PR4494133  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}}36  namespace Inner {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}}38  }39 40  // GCC incorrectly accepts this one41  using T = enum E : int; // expected-error {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration}}42 43  // PR19810 comment#244  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}}45 46  namespace PR24297 {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}}53 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}}60  }61}62 63int decltype(f())::*ptr_mem_decltype;64 65class ExtraSemiAfterMemFn {66  // Due to a peculiarity in the C++11 grammar, a deleted or defaulted function67  // is permitted to be followed by either one or two semicolons.68  void f() = delete // expected-error {{expected ';' after delete}}69  void g() = delete; // ok70  void h() = delete;; // ok71  void i() = delete;;; // expected-error {{extra ';' after member function definition}}72};73 74int *const const p = 0; // expected-error {{duplicate 'const' declaration specifier}}75const const int *q = 0; // expected-error {{duplicate 'const' declaration specifier}}76 77struct MultiCV {78  void f() const const; // expected-error {{duplicate 'const' declaration specifier}}79};80 81static_assert(something, ""); // expected-error {{undeclared identifier}}82 83// PR990384struct SS {85  typedef void d() = default; // expected-error {{function definition declared 'typedef'}} expected-error {{only special member functions and comparison operators may be defaulted}}86};87 88using PR14855 = int S::; // expected-error {{expected ';' after alias declaration}}89 90// Ensure that 'this' has a const-qualified type in a trailing return type for91// a constexpr function.92struct ConstexprTrailingReturn {93  int n;94  constexpr auto f() const -> decltype((n));95};96constexpr const int &ConstexprTrailingReturn::f() const { return n; }97 98namespace TestIsValidAfterTypeSpecifier {99struct s {} v;100 101struct s102thread_local tl;103 104struct s105&r0 = v;106 107struct s108&&r1 = s();109 110struct s111bitand r2 = v;112 113struct s114and r3 = s();115 116enum E {};117enum E118[[]] e;119 120}121 122namespace PR5066 {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}}127}128 129namespace FinalOverride {130  struct Base {131    virtual void *f();132    virtual void *g();133    virtual void *h();134    virtual void *i();135  };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;141  };142}143 144namespace UsingDeclAttrs {145  using T __attribute__((aligned(1))) = int;146  using T [[gnu::aligned(1)]] = int;147  static_assert(alignof(T) == 1, "");148 149  using [[gnu::aligned(1)]] T = int; // expected-error {{an attribute list cannot appear here}}150  using T = int [[gnu::aligned(1)]]; // expected-error {{'gnu::aligned' attribute cannot be applied to types}}151}152 153namespace DuplicateSpecifier {154  constexpr constexpr int f(); // expected-error {{duplicate 'constexpr' declaration specifier}}155  constexpr int constexpr a = 0; // expected-error {{duplicate 'constexpr' declaration specifier}}156 157  struct A {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'}}161  };162 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}}166 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}}170 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'}}173}174 175namespace ColonColonDecltype {176  struct S { struct T {}; };177  ::decltype(S())::T invalid; // expected-error {{expected unqualified-id}}178}179 180namespace AliasDeclEndLocation {181  template<typename T> struct A {};182  // Ensure that we correctly determine the end of this declaration to be the183  // end of the annotation token, not the beginning.184  using B = AliasDeclEndLocation::A<int185    > // expected-error {{expected ';' after alias declaration}}186    +;187  using C = AliasDeclEndLocation::A<int188    >\189> // expected-error {{expected ';' after alias declaration}}190    ;191  using D = AliasDeclEndLocation::A<int192    > // expected-error {{expected ';' after alias declaration}}193  // FIXME: After splitting this >> into two > tokens, we incorrectly determine194  // the end of the template-id to be after the *second* '>'.195  using E = AliasDeclEndLocation::A<int>>;196#define GGG >>>197  using F = AliasDeclEndLocation::A<int GGG;198  // expected-error@-1 {{expected ';' after alias declaration}}199  B something_else;200}201 202class PR47176 {203  friend void f(PR47176, int = 0) noexcept(true) {}204};205static_assert(noexcept(f(PR47176())), "");206 207struct Base { virtual void f() = 0; virtual void g() = 0; virtual void h() = 0; };208struct MemberComponentOrder : Base {209  void f() override __asm__("foobar") __attribute__(( )) {}210  void g() __attribute__(( )) override;211  void h() __attribute__(( )) override {}212};213 214void NoMissingSemicolonHere(struct S215                            [3]);216template<int ...N> void NoMissingSemicolonHereEither(struct S... [N]);217// expected-warning@-1 {{'S...[N]' is no longer a pack expansion but a pack indexing type; add a name to specify a pack expansion}} \218// expected-error@-1 {{'S' does not refer to the name of a parameter pack}} \219// expected-error@-1 {{declaration of anonymous struct must be a definition}} \220// expected-error@-1 {{expected parameter declarator}} \221// expected-error@-1 {{pack indexing is a C++2c extension}} \222 223 224 225// This must be at the end of the file; we used to look ahead past the EOF token here.226// expected-error@+1 {{expected unqualified-id}} expected-error@+1{{expected ';'}}227using228