brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.7 KiB · 34119a1 Raw
218 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,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors3// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors4// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors5// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors6// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors7// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors8 9 10namespace cwg2211 { // cwg2211: 811#if __cplusplus >= 201103L12void f() {13  int a;14  auto f = [a](int a) { (void)a; };15  // since-cxx11-error@-1 {{a lambda parameter cannot shadow an explicitly captured entity}}16  //   since-cxx11-note@-2 {{variable 'a' is explicitly captured here}}17  auto g = [=](int a) { (void)a; };18}19#endif20} // namespace cwg221121 22namespace cwg2213 { // cwg2213: 2.723template <typename T, typename U>24struct A;25 26template <typename U>27struct A<int, U>;28} // namespace cwg221329 30namespace cwg2229 { // cwg2229: 731struct AnonBitfieldQualifiers {32  const unsigned : 1;33  // expected-error@-1 {{anonymous bit-field cannot have qualifiers}}34  volatile unsigned : 1;35  // expected-error@-1 {{anonymous bit-field cannot have qualifiers}}36  const volatile unsigned : 1;37  // expected-error@-1 {{anonymous bit-field cannot have qualifiers}}38 39  unsigned : 1;40  const unsigned i1 : 1;41  volatile unsigned i2 : 1;42  const volatile unsigned i3 : 1;43};44} // namespace cwg222945 46namespace cwg2233 { // cwg2233: 1147#if __cplusplus >= 201103L48template <typename... T>49void f(int i = 0, T... args) {}50 51template <typename... T>52void g(int i = 0, T... args, T... args2) {}53 54template <typename... T>55void h(int i = 0, T... args, int j = 1) {}56 57template <typename... T, typename... U>58void i(int i = 0, T... args, int j = 1, U... args2) {}59 60template <class... Ts>61void j(int i = 0, Ts... ts) {}62 63template <>64void j<int>(int i, int j) {}65 66template67void j(int, int, int);68 69extern template70void j(int, int, int, int);71 72// PR2302973// Ensure instantiating the templates works.74void use() {75  f();76  f(0, 1);77  f<int>(1, 2);78  g<int>(1, 2, 3);79  h(0, 1);80  i();81  i(3);82  i<int>(3, 2);83  i<int>(3, 2, 1);84  i<int, int>(1, 2, 3, 4, 5);85  j();86  j(1);87  j(1, 2);88  j<int>(1, 2);89}90 91namespace MultilevelSpecialization {92  template<typename ...T> struct A {93    template <T... V> void f(int i = 0, int (&... arr)[V]);94  };95  template<> template<>96    void A<int, int>::f<1, 1>(int i, int (&arr1a)[1], int (&arr2a)[1]) {}97 98  // FIXME: I believe this example is valid, at least up to the first explicit99  // specialization, but Clang can't cope with explicit specializations that100  // expand packs into a sequence of parameters. If we ever start accepting101  // that, we'll need to decide whether it's OK for arr1a to be missing its102  // default argument -- how far back do we look when determining whether a103  // parameter was expanded from a pack?104  //   -- zygoloid 2020-06-02105  template<typename ...T> struct B { // #cwg2233-B106    template <T... V> void f(int i = 0, int (&... arr)[V]);107  };108  template<> template<int a, int b>109    void B<int, int>::f(int i, int (&arr1)[a], int (&arr2)[b]) {}110    // since-cxx11-error@-1 {{out-of-line definition of 'f' does not match any declaration in 'cwg2233::MultilevelSpecialization::B<int, int>'}}111    //   since-cxx11-note@#cwg2233-B {{defined here}}112  template<> template<>113    void B<int, int>::f<1, 1>(int i, int (&arr1a)[1], int (&arr2a)[1]) {}114}115 116namespace CheckAfterMerging1 {117  template <typename... T> void f() {118    void g(int, int = 0);119    void g(int = 0, T...);120    g();121  }122  void h() { f<int>(); }123}124 125namespace CheckAfterMerging2 {126  template <typename... T> void f() {127    void g(int = 0, T...);128    void g(int, int = 0);129    g();130  }131  void h() { f<int>(); }132}133#endif134} // namespace cwg2233135 136namespace cwg2267 { // cwg2267: no137#if __cplusplus >= 201103L138struct A {} a;139struct B { explicit B(const A&); }; // #cwg2267-struct-B140 141struct D { D(); };142struct C { explicit operator D(); } c;143 144B b1(a);145const B &b2{a}; // FIXME ill-formed146const B &b3(a);147// since-cxx11-error@-1 {{no viable conversion from 'struct A' to 'const B'}}148//   since-cxx11-note@#cwg2267-struct-B {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'struct A' to 'const B &' for 1st argument}}149//   since-cxx11-note@#cwg2267-struct-B {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'struct A' to 'B &&' for 1st argument}}150//   since-cxx11-note@#cwg2267-struct-B {{explicit constructor is not a candidate}}151 152D d1(c);153const D &d2{c}; // FIXME ill-formed154const D &d3(c); // FIXME ill-formed155#endif156} // namespace cwg2267157 158namespace cwg2273 { // cwg2273: 3.3159#if __cplusplus >= 201103L160struct A {161  A(int = 0) = delete; // #cwg2273-A162};163 164struct B : A { // #cwg2273-B165  using A::A;166};167 168B b;169// since-cxx11-error@-1 {{call to implicitly-deleted default constructor of 'B'}}170//   since-cxx11-note@#cwg2273-B {{default constructor of 'B' is implicitly deleted because base class 'A' has a deleted default constructor}}171//   since-cxx11-note@#cwg2273-A {{'A' has been explicitly marked deleted here}}172#endif173} // namespace cwg2273174 175namespace cwg2277 { // cwg2277: partial176#if __cplusplus >= 201103L177struct A {178  A(int, int = 0);179  void f(int, int = 0); // #cwg2277-A-f180};181struct B : A {182  B(int);183  using A::A;184 185  void f(int); // #cwg2277-B-f186  using A::f;187};188 189void g() {190  B b{0};191  b.f(0); // FIXME: this is well-formed for the same reason as initialization of 'b' above192  // since-cxx11-error@-1 {{call to member function 'f' is ambiguous}}193  //   since-cxx11-note@#cwg2277-A-f {{candidate function}}194  //   since-cxx11-note@#cwg2277-B-f {{candidate function}}195}196#endif197} // namespace cwg2277198 199namespace cwg2285 { // cwg2285: 4200// Note: Clang 4 implements this DR but it set a wrong value of `__cplusplus`201#if __cplusplus >= 201703L202  void test() {203    using T = int[1];204    auto [a] = T{a};205    // since-cxx17-error@-1 {{binding 'a' cannot appear in the initializer of its own structured binding declaration}}206  }207#endif208} // namespace cwg2285209 210namespace cwg2292 { // cwg2292: 9211#if __cplusplus >= 201103L212  template<typename T> using id = T;213  void test(int *p) {214    p->template id<int>::~id<int>();215  }216#endif217} // namespace cwg2292218