brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.4 KiB · 96e4674 Raw
202 lines · cpp
1// RUN: %clang_cc1 -std=c++98 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors2// RUN: %clang_cc1 -std=c++11 %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors3// RUN: %clang_cc1 -std=c++14 %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors4// RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors5// RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors6// RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors7// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors8 9namespace std {10  __extension__ typedef __SIZE_TYPE__ size_t;11 12  template<typename T> struct initializer_list {13    const T *p; size_t n;14    initializer_list(const T *p, size_t n);15  };16} // namespace std17 18namespace cwg930 { // cwg930: 2.719#if __cplusplus >= 201103L20static_assert(alignof(int[]) == alignof(int), "");21static_assert(alignof(int[][2]) == alignof(int[2]), "");22#endif23} // namespace cwg93024 25namespace cwg948 { // cwg948: 3.726#if __cplusplus >= 201103L27  class A {28  public:29     constexpr A(int v) : v(v) { }30     constexpr operator int() const { return v; }31  private:32     int v;33  };34 35  constexpr int id(int x)36  {37    return x;38  }39 40  void f() {41     if (constexpr int i = id(101)) { }42     switch (constexpr int i = id(2)) { default: break; case 2: break; }43     for (; constexpr int i = id(0); ) { }44     while (constexpr int i = id(0)) { }45 46     if (constexpr A i = 101) { }47     switch (constexpr A i = 2) { default: break; case 2: break; }48     for (; constexpr A i = 0; ) { }49     while (constexpr A i = 0) { }50  }51#endif52} // namespace cwg94853 54namespace cwg952 { // cwg952: 2.855namespace example1 {56struct A {57  typedef int I; // #cwg952-I58};59struct B : private A { // #cwg952-B60};61struct C : B {62  void f() {63    I i1;64    // expected-error@-1 {{'I' is a private member of 'cwg952::example1::A'}}65    //   expected-note@#cwg952-B {{constrained by private inheritance here}}66    //   expected-note@#cwg952-I {{member is declared here}}67  }68  I i2;69  // expected-error@-1 {{'I' is a private member of 'cwg952::example1::A'}}70  //   expected-note@#cwg952-B {{constrained by private inheritance here}}71  //   expected-note@#cwg952-I {{member is declared here}}72  struct D {73    I i3;74    // expected-error@-1 {{'I' is a private member of 'cwg952::example1::A'}}75    //   expected-note@#cwg952-B {{constrained by private inheritance here}}76    //   expected-note@#cwg952-I {{member is declared here}}77    void g() {78      I i4;79      // expected-error@-1 {{'I' is a private member of 'cwg952::example1::A'}}80      //   expected-note@#cwg952-B {{constrained by private inheritance here}}81      //   expected-note@#cwg952-I {{member is declared here}}82    }83  };84};85} // namespace example186namespace example2 {87struct A {88protected:89  static int x;90};91struct B : A {92  friend int get(B) { return x; }93};94} // namespace example295} // namespace cwg95296 97namespace cwg960 { // cwg960: 3.098struct a {};99class A {100#if __cplusplus >= 201103L101  // Check lvalue ref vs rvalue ref vs pointer.102  virtual a& rvalue_ref();103  virtual a&& lvalue_ref();104  virtual a& rvalue_vs_lvalue_ref(); // #cwg960-A-rvalue_vs_lvalue_ref105  virtual a&& lvalue_vs_rvalue_ref(); // #cwg960-A-lvalue_vs_rvalue_ref106  virtual a& rvalue_ref_vs_pointer(); // #cwg960-A-rvalue_ref_vs_pointer107  virtual a* pointer_vs_rvalue_ref(); // #cwg960-A-pointer_vs_rvalue_ref108  virtual a&& lvalue_ref_vs_pointer(); // #cwg960-A-lvalue_ref_vs_pointer109  virtual a* pointer_vs_lvalue_ref(); // #cwg960-A-pointer_vs_lvalue_ref110#endif111};112 113class B : A {114#if __cplusplus >= 201103L115  // Check lvalue ref vs rvalue ref vs pointer.116  a& rvalue_ref() override;117  a&& lvalue_ref() override;118 119  a&& rvalue_vs_lvalue_ref() override; 120  // since-cxx11-error@-1 {{virtual function 'rvalue_vs_lvalue_ref' has a different return type ('a &&') than the function it overrides (which has return type 'a &')}}121  //   since-cxx11-note@#cwg960-A-rvalue_vs_lvalue_ref {{overridden virtual function is here}}122 123  a& lvalue_vs_rvalue_ref() override;124  // since-cxx11-error@-1 {{virtual function 'lvalue_vs_rvalue_ref' has a different return type ('a &') than the function it overrides (which has return type 'a &&')}}125  //   since-cxx11-note@#cwg960-A-lvalue_vs_rvalue_ref {{overridden virtual function is here}}126 127  a* rvalue_ref_vs_pointer() override;128  // since-cxx11-error@-1 {{virtual function 'rvalue_ref_vs_pointer' has a different return type ('a *') than the function it overrides (which has return type 'a &')}}129  //   since-cxx11-note@#cwg960-A-rvalue_ref_vs_pointer {{overridden virtual function is here}}130 131  a& pointer_vs_rvalue_ref() override;132  // since-cxx11-error@-1 {{virtual function 'pointer_vs_rvalue_ref' has a different return type ('a &') than the function it overrides (which has return type 'a *')}}133  //   since-cxx11-note@#cwg960-A-pointer_vs_rvalue_ref {{overridden virtual function is here}}134 135  a* lvalue_ref_vs_pointer() override;136  // since-cxx11-error@-1 {{virtual function 'lvalue_ref_vs_pointer' has a different return type ('a *') than the function it overrides (which has return type 'a &&')}}137  //   since-cxx11-note@#cwg960-A-lvalue_ref_vs_pointer {{overridden virtual function is here}}138 139  a&& pointer_vs_lvalue_ref() override;140  // since-cxx11-error@-1 {{virtual function 'pointer_vs_lvalue_ref' has a different return type ('a &&') than the function it overrides (which has return type 'a *')}}141  //   since-cxx11-note@#cwg960-A-pointer_vs_lvalue_ref {{overridden virtual function is here}}142#endif143};144 145} // namespace cwg960146 147namespace cwg974 { // cwg974: 3.3148#if __cplusplus >= 201103L149  void test() {150    auto lam = [](int x = 42) { return x; };151  }152#endif153} // namespace cwg974154 155namespace cwg977 { // cwg977: 2.7156enum E { e = E() }; // #cwg977-E157#if !defined(_WIN32) || defined(__MINGW32__)158// expected-error@#cwg977-E {{invalid use of incomplete type 'E'}}159//   expected-note@#cwg977-E {{definition of 'cwg977::E' is not complete until the closing '}'}}160#endif161#if __cplusplus >= 201103L162enum E2 : int { e2 = E2() };163enum struct E3 { e = static_cast<int>(E3()) };164enum struct E4 : int { e = static_cast<int>(E4()) };165#endif166} // namespace cwg977167 168namespace cwg990 { // cwg990: 3.5169#if __cplusplus >= 201103L170  struct A { // #cwg990-A171    A(std::initializer_list<int>); // #cwg990-A-init-list172  };173  struct B {174    A a;175  };176  B b1 { };177  B b2 { 1 };178  // since-cxx11-error@-1 {{no viable conversion from 'int' to 'A'}}179  //   since-cxx11-note@#cwg990-A {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const A &' for 1st argument}}180  //   since-cxx11-note@#cwg990-A {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'A &&' for 1st argument}}181  //   since-cxx11-note@#cwg990-A-init-list {{candidate constructor not viable: no known conversion from 'int' to 'std::initializer_list<int>' for 1st argument}}182  B b3 { { 1 } };183 184  struct C {185    C();186    C(int);187    C(std::initializer_list<int>) = delete; // #cwg990-deleted188  };189  C c1[3] { 1 }; // ok190  C c2[3] { 1, {2} };191  // since-cxx11-error@-1 {{call to deleted constructor of 'C'}}192  //   since-cxx11-note@#cwg990-deleted {{'C' has been explicitly marked deleted here}}193 194  struct D {195    D();196    D(std::initializer_list<int>);197    D(std::initializer_list<double>);198  };199  D d{};200#endif201} // namespace cwg990202