brintos

brintos / llvm-project-archived public Read only

0
0
Text · 12.8 KiB · 42a7c4d Raw
347 lines · cpp
1// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify=expected,cxx98-14,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors2// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify=expected,cxx98-14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors3// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,cxx98-14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors4// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors5// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors6// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors7// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors8 9#if __cplusplus == 199711L10#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)11// cxx98-error@-1 {{variadic macros are a C99 feature}}12#endif13 14namespace std {15  typedef __SIZE_TYPE__ size_t;16 17  template<typename E> struct initializer_list {18    const E *p; size_t n;19    initializer_list(const E *p, size_t n);20    initializer_list();21  };22 23  struct type_info;24}25 26namespace cwg2100 { // cwg2100: 1227  template<const int *P, bool = true> struct X {};28  template<typename T> struct A {29    static const int n = 1;30    int f() {31      return X<&n>::n; // ok, value-dependent32    }33    int g() {34      static const int n = 2; // #cwg2100-n35      return X<&n>::n; // ok, value-dependent36      // cxx98-14-error@-1 {{non-type template argument refers to object 'n' that does not have linkage}}37      //   cxx98-14-note@#cwg2100-n {{non-type template argument refers to object here}}38    }39  };40  template<const int *P> struct X<P> {41#if __cplusplus == 199711L42    static const int n = 0;43#else44    static const int n = *P;45#endif46  };47  int q = A<int>().f() + A<int>().g();48 49  // Corresponding constructs where the address is not taken are not50  // value-dependent.51  template<int N, bool = true> struct Y {};52  template<typename T> struct B {53    static const int n = 1;54    int f() {55      return Y<n>::declared_later;56      // expected-error@-1 {{no member named 'declared_later' in 'cwg2100::Y<1>'}}57    }58    int g() {59      static const int n = 2;60      return Y<n>::declared_later;61      // expected-error@-1 {{no member named 'declared_later' in 'cwg2100::Y<2>'}}62    }63  };64  template<int N> struct Y<N> {65    static const int declared_later = 0;66  };67} // namespace cwg210068 69namespace cwg2103 { // cwg2103: 2.770  void f() {71    int a;72    int &r = a; // #cwg2103-r73    struct Inner {74      void f() {75        int &s = r;76        // expected-error@-1 {{reference to local variable 'r' declared in enclosing function 'cwg2103::f'}}77        //   expected-note@#cwg2103-r {{'r' declared here}}78        (void)s;79      }80    };81  }82} // namespace cwg210383 84namespace cwg2120 { // cwg2120: 785  struct A {};86  struct B : A {};87  struct C { A a; };88  struct D { C c[5]; };89  struct E : B { D d; };90  static_assert(__is_standard_layout(B), "");91  static_assert(__is_standard_layout(D), "");92  static_assert(!__is_standard_layout(E), "");93} // namespace cwg212094 95namespace cwg2126 { // cwg2126: 1296#if __cplusplus >= 201103L97  struct A { int n; };98 99  const A &a = {1};              // const temporary100  A &b = (A &)(const A &)A{1};   // const temporary101  A &&c = (A &&)(const A &)A{1}; // const temporary102 103  A &&d = {1};                   // non-const temporary #cwg21260-d104  const A &e = (A &)(A &&) A{1}; // non-const temporary #cwg21260-e105  A &&f = (A &&)(A &&) A{1};     // non-const temporary #cwg21260-f106 107  constexpr const A &g = {1};    // const temporary108  constexpr A &&h = {1};         // non-const temporary #cwg21260-h109 110  struct B { const A &a; };111  B i = {{1}};           // extending decl not usable in constant expr #cwg21260-i112  const B j = {{1}};     // extending decl not usable in constant expr #cwg21260-j113  constexpr B k = {{1}}; // extending decl usable in constant expr114 115  static_assert(a.n == 1, "");116  static_assert(b.n == 1, "");117  static_assert(c.n == 1, "");118  static_assert(d.n == 1, "");119  // since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}120  //   since-cxx11-note@-2 {{read of temporary is not allowed in a constant expression outside the expression that created the temporary}}121  //   since-cxx11-note@#cwg21260-d {{temporary created here}}122  static_assert(e.n == 1, "");123  // since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}124  //   since-cxx11-note@-2 {{read of temporary is not allowed in a constant expression outside the expression that created the temporary}}125  //   since-cxx11-note@#cwg21260-e {{temporary created here}}126  static_assert(f.n == 1, "");127  // since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}128  //   since-cxx11-note@-2 {{read of temporary is not allowed in a constant expression outside the expression that created the temporary}}129  //   since-cxx11-note@#cwg21260-f {{temporary created here}}130  static_assert(g.n == 1, "");131  static_assert(h.n == 1, "");132  // since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}133  //   since-cxx11-note@-2 {{read of temporary is not allowed in a constant expression outside the expression that created the temporary}}134  //   since-cxx11-note@#cwg21260-h {{temporary created here}}135  static_assert(i.a.n == 1, "");136  // since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}137  //   since-cxx11-note@-2 {{read of non-constexpr variable 'i' is not allowed in a constant expression}}138  //   since-cxx11-note@#cwg21260-i {{declared here}}139  static_assert(j.a.n == 1, "");140  // since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}141  //   since-cxx11-note@-2 {{read of temporary is not allowed in a constant expression outside the expression that created the temporary}}142  //   since-cxx11-note@#cwg21260-j {{temporary created here}}143  static_assert(k.a.n == 1, "");144#endif145} // namespace cwg2126146 147namespace cwg2137 { // cwg2137: 20148#if __cplusplus >= 201103L149  struct Q {150    Q();151    Q(Q&&);152    Q(std::initializer_list<Q>) = delete; // #cwg2137-Qcons153  };154 155  Q x = Q { Q() };156  // since-cxx11-error@-1 {{call to deleted constructor of 'Q'}}157  //   since-cxx11-note@#cwg2137-Qcons {{'Q' has been explicitly marked deleted here}}158 159  int f(Q); // #cwg2137-f160  int y = f({ Q() });161  // since-cxx11-error@-1 {{call to deleted constructor of 'Q'}}162  //   since-cxx11-note@#cwg2137-Qcons {{'Q' has been explicitly marked deleted here}}163  //   since-cxx11-note@#cwg2137-f {{passing argument to parameter here}}164 165  struct U {166    U();167    U(const U&);168  };169 170  struct Derived : U {171    Derived();172    Derived(const Derived&);173  } d;174 175  int g(Derived);176  int g(U(&&)[1]) = delete;177 178  int z = g({ d });179#endif180} // namespace cwg2137181 182namespace cwg2140 { // cwg2140: 9183#if __cplusplus >= 201103L184  union U { int a; decltype(nullptr) b; };185  constexpr int *test(U u) {186    return u.b;187  }188  static_assert(!test({123}), "u.b should be valid even when b is inactive");189#endif190} // namespace cwg2140191 192namespace cwg2141 { // cwg2141: 17193struct A{};194 195template <typename T>196struct B{};197 198void foo() {199  struct A *b = (1 == 1) ? new struct A : new struct A;200  struct S *a = (1 == 1) ? new struct S : new struct S;201  // expected-error@-1 {{allocation of incomplete type 'struct S'}}202  //   expected-note@-2 {{forward declaration of 'S'}}203  // expected-error@-3 {{allocation of incomplete type 'struct S'}}204  //   expected-note@-4 {{forward declaration of 'S'}}205 206#if __cplusplus >= 201103L207  A *aa = new struct A{};208  B<int> *bb = new struct B<int>{};209  (void)new struct C{};210  // since-cxx11-error@-1 {{allocation of incomplete type 'struct C'}}211  //   since-cxx11-note@-2 {{forward declaration of 'C'}}212 213  struct A *c = (1 == 1) ? new struct A {} : new struct A {};214 215  alignof(struct D{});216  // since-cxx11-error@-1 {{'D' cannot be defined in a type specifier}}217#endif218 219  sizeof(struct E{});220  // expected-error@-1 {{'E' cannot be defined in a type specifier}}221 222}223} // namespace cwg2141224 225// cwg2149 is in cwg2149.cpp226 227namespace cwg2157 { // cwg2157: 11228#if __cplusplus >= 201103L229  enum E : int;230  struct X {231    enum cwg2157::E : int();232    // since-cxx11-error@-1 {{ISO C++ only allows ':' in member enumeration declaration to introduce a fixed underlying type, not an anonymous bit-field}}233  };234#endif235} // namespace cwg2157236 237// cwg2165: na238 239namespace cwg2170 { // cwg2170: 9240#if __cplusplus >= 201103L241  void f() {242    constexpr int arr[3] = {1, 2, 3}; // #cwg2170-arr243    struct S {244      int get(int n) { return arr[n]; }245      const int &get_ref(int n) { return arr[n]; }246      // since-cxx11-warning@-1 {{reference to stack memory associated with local variable 'arr' returned}} FIXME247      // since-cxx11-error@-2 {{reference to local variable 'arr' declared in enclosing function 'cwg2170::f'}}248      //   since-cxx11-note@#cwg2170-arr {{'arr' declared here}}249    };250  }251#endif252} // namespace cwg2170253 254namespace cwg2171 { // cwg2171: 15255#if __cplusplus >= 201103L256 257struct NonConstCopy {258  NonConstCopy(NonConstCopy &) = default;259  NonConstCopy &operator=(NonConstCopy &) = default;260};261 262static_assert(__is_trivially_copyable(NonConstCopy), "");263static_assert(__is_trivially_constructible(NonConstCopy, NonConstCopy &), "");264static_assert(!__is_trivially_constructible(NonConstCopy, NonConstCopy), "");265static_assert(!__is_trivially_constructible(NonConstCopy, const NonConstCopy &), "");266static_assert(!__is_trivially_constructible(NonConstCopy, NonConstCopy &&), "");267 268static_assert(__is_trivially_assignable(NonConstCopy, NonConstCopy &), "");269static_assert(__is_trivially_assignable(NonConstCopy &, NonConstCopy &), "");270static_assert(!__is_trivially_assignable(NonConstCopy &, const NonConstCopy &), "");271static_assert(!__is_trivially_assignable(NonConstCopy &, NonConstCopy), "");272static_assert(!__is_trivially_assignable(NonConstCopy &, NonConstCopy &&), "");273static_assert(__is_trivially_assignable(NonConstCopy &&, NonConstCopy &), "");274static_assert(!__is_trivially_assignable(NonConstCopy &&, const NonConstCopy &), "");275static_assert(!__is_trivially_assignable(NonConstCopy &&, NonConstCopy), "");276static_assert(!__is_trivially_assignable(NonConstCopy &&, NonConstCopy &&), "");277 278#endif279} // namespace cwg2171280 281namespace cwg2191 { // cwg2191: 19282#if __cplusplus >= 201103L283struct B { virtual void f() { } };284struct D : B { } d;285static_assert(noexcept(typeid(d)), "");286static_assert(!noexcept(typeid(*static_cast<D*>(nullptr))), "");287#endif288} // namespace cwg2191289 290namespace cwg2180 { // cwg2180: 3.0291  class A {292    A &operator=(const A &); // #cwg2180-A-copy293    A &operator=(A &&); // #cwg2180-A-move294    // cxx98-error@-1 {{rvalue references are a C++11 extension}}295  };296 297  struct B : virtual A { // #cwg2180-B298    B &operator=(const B &);299    B &operator=(B &&);300    // cxx98-error@-1 {{rvalue references are a C++11 extension}}301    virtual void foo() = 0;302  };303  B &B::operator=(const B&) = default; // #cwg2180-B-copy304  // cxx98-error@-1 {{defaulted function definitions are a C++11 extension}}305  // cxx98-error@-2 {{'operator=' is a private member of 'cwg2180::A'}}306  //   cxx98-note@-3 {{in defaulted copy assignment operator for 'cwg2180::B' first required here}}307  //   cxx98-note@#cwg2180-A-copy {{implicitly declared private here}}308  // since-cxx11-error@#cwg2180-B-copy {{defaulting this copy assignment operator would delete it after its first declaration}}309  //   since-cxx11-note@#cwg2180-B {{copy assignment operator of 'B' is implicitly deleted because base class 'A' has an inaccessible copy assignment operator}}310  B &B::operator=(B&&) = default; // #cwg2180-B-move311  // cxx98-error@-1 {{rvalue references are a C++11 extension}}312  // cxx98-error@-2 {{defaulted function definitions are a C++11 extension}}313  // cxx98-error@-3 {{'operator=' is a private member of 'cwg2180::A'}}314  //   cxx98-note@-4 {{in defaulted move assignment operator for 'cwg2180::B' first required here}}315  //   cxx98-note@#cwg2180-A-move {{implicitly declared private here}}316  // since-cxx11-error@#cwg2180-B-move {{defaulting this move assignment operator would delete it after its first declaration}}317  //   since-cxx11-note@#cwg2180-B {{move assignment operator of 'B' is implicitly deleted because base class 'A' has an inaccessible move assignment operator}}318} // namespace cwg2180319 320namespace cwg2199 { // cwg2199: 3.8321                   // NB: reusing part of cwg407 test322namespace A {323  struct S {};324}325namespace B {326  typedef int S;327}328namespace E {329  typedef A::S S;330  using A::S;331  struct S s;332}333namespace F {334  typedef A::S S;335}336namespace G {337  using namespace A;338  using namespace F;339  struct S s;340}341namespace H {342  using namespace F;343  using namespace A;344  struct S s;345}346} // namespace cwg2199347