brintos

brintos / llvm-project-archived public Read only

0
0
Text · 13.5 KiB · 0e0fc73 Raw
395 lines · cpp
1// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors2// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify=expected,cxx11-14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors3// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,cxx11-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,since-cxx20 -fexceptions -fcxx-exceptions -pedantic-errors6// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx20,since-cxx23 -fexceptions -fcxx-exceptions -pedantic-errors7// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx20,since-cxx23 -fexceptions -fcxx-exceptions -pedantic-errors8 9namespace std {10struct type_info{};11} // namespace std12 13// cwg2504 is in cwg2504.cpp14 15namespace cwg2512 { // cwg2512: 2.716struct A; // #cwg2512-A17void foo(A* p) {18  typeid(*p);19  // expected-error@-1 {{'typeid' of incomplete type 'A'}}20  //   expected-note@#cwg2512-A {{forward declaration of 'cwg2512::A'}}21}22} // namespace cwg251223 24namespace cwg2516 { // cwg2516: 3.025                   // NB: reusing 1482 test26#if __cplusplus >= 201103L27template <typename T> struct S {28  typedef char I;29};30enum E2 : S<E2>::I { e };31// since-cxx11-error@-1 {{use of undeclared identifier 'E2'}}32#endif33} // namespace cwg251634 35namespace cwg2517 { // cwg2517: 2136#if __cplusplus >= 202002L37template<typename ArrayType>38concept LargeArray = requires (ArrayType my_array) {39  requires my_array.size() > 5;40};41 42struct Big {43  constexpr int size() const { return 100; }44};45 46struct Small {47  constexpr int size() const { return 3; }48};49 50static_assert(LargeArray<Big>);51static_assert(!LargeArray<Small>);52#endif53} // namespace cwg251754 55namespace cwg2518 { // cwg2518: 1756 57#if __cplusplus >= 201103L58template <class T>59void f(T t) {60  if constexpr (sizeof(T) != sizeof(int)) {61  // cxx11-14-error@-1 {{constexpr if is a C++17 extension}}62    static_assert(false, "must be int-sized");63    // since-cxx11-error@-1 {{static assertion failed: must be int-sized}}64    //   since-cxx11-note@#cwg2518-f-c {{in instantiation of function template specialization 'cwg2518::f<char>' requested here}}65  }66}67 68void g(char c) {69  f(0);70  f(c); // #cwg2518-f-c71}72 73template <typename Ty>74struct S {75  static_assert(false);76  // cxx11-14-error@-1 {{'static_assert' with no message is a C++17 extension}}77  // since-cxx11-error@-2 {{static assertion failed}}78  //   since-cxx11-note@#cwg2518-S-double {{in instantiation of template class 'cwg2518::S<double>' requested here}}79};80 81template <>82struct S<int> {};83 84template <>85struct S<float> {};86 87int test_specialization() {88  S<int> s1;89  S<float> s2;90  S<double> s3; // #cwg2518-S-double91}92#endif93 94} // namespace cwg251895 96namespace cwg2521 { // cwg2521: 1797#if __cplusplus >= 201103L98#pragma clang diagnostic push99#pragma clang diagnostic warning "-Wdeprecated-literal-operator"100long double operator""      _\u03C0___(long double);101// since-cxx11-warning@-1 {{identifier '_π___' preceded by whitespace in a literal operator declaration is deprecated}}102// since-cxx11-warning@-2 {{user-defined literal suffixes containing '__' are reserved}}103 104template <char... Chars> decltype(sizeof 0)105operator""  _div();106// since-cxx11-warning@-1 {{identifier '_div' preceded by whitespace in a literal operator declaration is deprecated}}107 108using ::cwg2521::operator"" _\u03C0___;109// since-cxx11-warning@-1 {{identifier '_π___' preceded by whitespace in a literal operator declaration is deprecated}}110using ::cwg2521::operator""_div;111 112long double operator"" _RESERVED(long double);113// since-cxx11-warning@-1 {{identifier '_RESERVED' preceded by whitespace in a literal operator declaration is deprecated}}114#pragma clang diagnostic pop115#endif116} // namespace cwg2521117 118namespace cwg2547 { // cwg2547: 20119#if __cplusplus >= 202302L120struct S;121// since-cxx23-note@-1 {{forward declaration of 'cwg2547::S'}}122// since-cxx23-note@-2 {{forward declaration of 'cwg2547::S'}}123// since-cxx23-note@-3 {{forward declaration of 'cwg2547::S'}}124bool operator==(S, S) = default;  // error: S is not complete125// since-cxx23-error@-1 {{variable has incomplete type 'S'}}126// since-cxx23-error@-2 {{variable has incomplete type 'S'}}127// since-cxx23-error@-3 {{equality comparison operator is not a friend of incomplete class 'cwg2547::S'}}128struct S {129  friend bool operator==(S, const S&) = default; // error: parameters of different types130  // since-cxx23-error@-1 {{parameters for defaulted equality comparison operator must have the same type (found 'S' vs 'const S &')}}131};132enum E { };133bool operator==(E, E) = default;  // error: not a member or friend of a class134// since-cxx23-error@-1 {{invalid parameter type for non-member defaulted equality comparison operator; found 'E', expected class or reference to a constant class}}135 136struct S2 {137  bool operator==(this int, S2) = default;138  // since-cxx23-error@-1 {{invalid parameter type for defaulted equality comparison operator; found 'int', expected 'const cwg2547::S2 &'}}139};140#endif141} // namespace cwg2547142 143namespace cwg2553 { // cwg2553: 18 review 2023-07-14144#if __cplusplus >= 202302L145struct B {146  virtual void f(this B&); 147  // since-cxx23-error@-1 {{an explicit object parameter cannot appear in a virtual function}}148  static void f(this B&);149  // since-cxx23-error@-1 {{an explicit object parameter cannot appear in a static function}}150  virtual void g(); // #cwg2553-g151};152struct D : B {153  void g(this D&);154  // since-cxx23-error@-1 {{an explicit object parameter cannot appear in a virtual function}}155  //   since-cxx23-note@#cwg2553-g {{overridden virtual function is here}}156};157#endif158} // namespace cwg2553159 160namespace cwg2554 { // cwg2554: 18 review 2021-12-10161#if __cplusplus >= 202302L162struct B {163  virtual void f(); // #cwg2554-g164};165 166struct D : B {167  void f(this D&);168  // since-cxx23-error@-1 {{an explicit object parameter cannot appear in a virtual function}}169  //   since-cxx23-note@#cwg2554-g {{overridden virtual function is here}}170};171 172struct D2 : B {173  void f(this B&);174  // since-cxx23-error@-1 {{an explicit object parameter cannot appear in a virtual function}}175  //   since-cxx23-note@#cwg2554-g {{overridden virtual function is here}}176};177struct T {};178struct D3 : B {179  void f(this T&);180  // since-cxx23-error@-1 {{an explicit object parameter cannot appear in a virtual function}}181  //   since-cxx23-note@#cwg2554-g {{overridden virtual function is here}}182};183#endif184} // namespace cwg2554185 186namespace cwg2561 { // cwg2561: no187#if __cplusplus >= 202302L188struct C {189    constexpr C(auto) { }190};191void foo() {192    constexpr auto b = [](this C) { return 1; };193    // FIXME: closure type shouldn't have a conversion function to function194    //        pointer, because explicit object parameter is present. 195    constexpr int (*fp)(C) = b;196    static_assert(fp(1) == 1);197    static_assert((&decltype(b)::operator())(1) == 1);198}199#endif200} // namespace cwg2561201 202namespace cwg2565 { // cwg2565: 16 open 2023-06-07203#if __cplusplus >= 202002L204  template<typename T>205    concept C = requires (typename T::type x) {206      x + 1;207    };208  static_assert(!C<int>);209 210  // Variant of this as reported in GH57487.211  template<bool B> struct bool_constant212  { static constexpr bool value = B; };213 214  template<typename T>215    using is_referenceable216       = bool_constant<requires (T&) { true; }>;217 218  static_assert(!is_referenceable<void>::value);219  static_assert(is_referenceable<int>::value);220 221  template<typename T, typename U>222  concept TwoParams = requires (T *a, U b){ true;}; // #cwg2565-TPC223 224  template<typename T, typename U>225    requires TwoParams<T, U> // #cwg2565-TPSREQ226  struct TwoParamsStruct{};227 228  using TPSU = TwoParamsStruct<void, void>;229  // since-cxx20-error@-1 {{constraints not satisfied for class template 'TwoParamsStruct' [with T = void, U = void]}}230  //   since-cxx20-note@#cwg2565-TPSREQ {{because 'TwoParams<void, void>' evaluated to false}}231  //   since-cxx20-note@#cwg2565-TPC {{because 'b' would be invalid: argument may not have 'void' type}}232 233  template<typename T, typename ...U>234  concept Variadic = requires (U* ... a, T b){ true;}; // #cwg2565-VC235 236  template<typename T, typename ...U>237    requires Variadic<T, U...> // #cwg2565-VSREQ238  struct VariadicStruct{};239 240  using VSU = VariadicStruct<void, int, char, double>;241  // since-cxx20-error@-1 {{constraints not satisfied for class template 'VariadicStruct' [with T = void, U = <int, char, double>]}}242  //   since-cxx20-note@#cwg2565-VSREQ {{because 'Variadic<void, int, char, double>' evaluated to false}}243  //   since-cxx20-note@#cwg2565-VC {{because 'b' would be invalid: argument may not have 'void' type}}244 245  template<typename T>246  concept ErrorRequires = requires (ErrorRequires auto x) { // #cwg2565-expr247  // since-cxx20-error@-1 {{a concept definition cannot refer to itself}}248  //   since-cxx20-note@-2 {{declared here}}249  // since-cxx20-error@-3 {{'auto' not allowed in requires expression parameter}}250    x;251  };252  static_assert(ErrorRequires<int>);253  // since-cxx20-error@-1 {{static assertion failed}} \254  //   since-cxx20-note@-1 {{because 'int' does not satisfy 'ErrorRequires'}} \255  //   since-cxx20-note@#cwg2565-expr {{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}256 257  template<typename T>258  concept NestedErrorInRequires = requires (T x) { // #cwg2565-NEIR259    requires requires (NestedErrorInRequires auto y) { // #cwg2565-NEIR-inner260    // since-cxx20-error@-1 {{a concept definition cannot refer to itself}}261    //   since-cxx20-note@#cwg2565-NEIR {{declared here}}262    // since-cxx20-error@-3 {{'auto' not allowed in requires expression parameter}}263      y;264    };265  };266  static_assert(NestedErrorInRequires<int>);267  // since-cxx20-error@-1 {{static assertion failed}} \268  //   since-cxx20-note@-1 {{because 'int' does not satisfy 'NestedErrorInRequires'}} \269  //   since-cxx20-note-re@#cwg2565-NEIR-inner {{because {{.*}} would be invalid: constraint depends on a previously diagnosed expression}}270 271#endif272} // namespace cwg2565273 274namespace cwg2583 { // cwg2583: 19275#if __cplusplus >= 201103L276struct A {277  int i;278  char c;279};280 281struct B {282  int i;283  alignas(8) char c;284};285 286union U {287  A a;288  B b;289};290 291union V {292  A a;293  alignas(64) B b;294};295 296static_assert(!__is_layout_compatible(A, B), "");297static_assert(__is_layout_compatible(U, V), "");298#endif299} // namespace cwg2583300 301namespace cwg2586 { // cwg2586: 20302#if __cplusplus >= 202302L303struct X {304  X& operator=(this X&, const X&) = default;305  X& operator=(this X&, X&) = default;306  X& operator=(this X&&, X&&) = default;307  // FIXME: The notes could be clearer on *how* the type differs308  // e.g., "if an explicit object parameter is used it must be of type reference to 'X'"309  X& operator=(this int, const X&) = default;310  // since-cxx23-warning@-1 {{explicitly defaulted copy assignment operator is implicitly deleted}}311  //   since-cxx23-note@-2 {{function is implicitly deleted because its declared type does not match the type of an implicit copy assignment operator}}312  X& operator=(this X, const X&) = default;313  // since-cxx23-warning@-1 {{explicitly defaulted copy assignment operator is implicitly deleted}}314  //   since-cxx23-note@-2 {{function is implicitly deleted because its declared type does not match the type of an implicit copy assignment operator}}315};316struct Y {317  void operator=(this int, const Y&); // This is copy constructor, suppresses implicit declaration318};319static_assert([]<typename T = Y>{320  return !requires(T t, const T& ct) { t = ct; };321}());322 323struct Z {324  bool operator==(this const Z&, const Z&) = default;325  bool operator==(this Z, Z) = default;326  bool operator==(this Z, const Z&) = default;327  // since-cxx23-error@-1 {{parameters for defaulted equality comparison operator must have the same type (found 'Z' vs 'const Z &')}}328  bool operator==(this const Z&, Z) = default;329  // since-cxx23-error@-1 {{parameters for defaulted equality comparison operator must have the same type (found 'const Z &' vs 'Z')}}330  bool operator==(this int, Z) = default;331  // since-cxx23-error@-1 {{invalid parameter type for defaulted equality comparison operator; found 'int', expected 'const cwg2586::Z &'}}332};333#endif334} // namespace cwg2586335 336namespace cwg2598 { // cwg2598: 18337#if __cplusplus >= 201103L338struct NonLiteral {339    NonLiteral();340};341 342struct anonymous1 {343    union {} a;344};345static_assert(__is_literal(anonymous1), "");346 347struct anonymous2 {348    union { char c; };349};350static_assert(__is_literal(anonymous2), "");351 352struct anonymous3 {353    union { char c; NonLiteral NL; };354};355static_assert(__is_literal(anonymous3), "");356 357struct anonymous4 {358    union { NonLiteral NL; };359};360static_assert(!__is_literal(anonymous4), "");361 362union empty {};363static_assert(__is_literal(empty), "");364 365union union1 { char c; };366static_assert(__is_literal(union1), "");367 368union union2 { char c; NonLiteral NL;};369static_assert(__is_literal(union2), "");370 371union union3 { NonLiteral NL;};372static_assert(!__is_literal(union3), "");373 374union union4 { union4(); };375static_assert(!__is_literal(union4), "");376 377union union5 { static NonLiteral NL; };378static_assert(__is_literal(union5), "");379 380struct Literal { constexpr Literal() {} };381union union6 { NonLiteral NL; Literal L; };382static_assert(__is_literal(union6), "");383 384#if __cplusplus >= 202003L385struct A { A(); };386union U {387  A a;388  constexpr U() {}389  constexpr ~U() {}390};391static_assert(!__is_literal(U), "");392#endif393#endif394} // namespace cwg2598395