brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · a937474 Raw
55 lines · cpp
1// RUN: %clang_cc1 -std=c++2a -verify %s2 3constexpr int non_class = 42;4constexpr int arr_non_class[5] = {1, 2, 3};5 6struct A {7  int member = 1;8  constexpr ~A() { member = member + 1; }9};10constexpr A class_ = {};11constexpr A arr_class[5] = {{}, {}};12 13struct Mutable {14  mutable int member = 1; // expected-note {{declared here}}15  constexpr ~Mutable() { member = member + 1; } // expected-note {{read of mutable member}}16};17constexpr Mutable mut_member; // expected-error {{must have constant destruction}} expected-note {{in call}}18 19struct MutableStore {20  mutable int member = 1; // expected-note {{declared here}}21  constexpr ~MutableStore() { member = 2; } // expected-note {{assignment to mutable member}}22};23constexpr MutableStore mut_store; // expected-error {{must have constant destruction}} expected-note {{in call}}24 25// Note: the constant destruction rules disallow this example even though hcm.n is a const object.26struct MutableConst {27  struct HasConstMember {28    const int n = 4;29  };30  mutable HasConstMember hcm; // expected-note {{here}}31  constexpr ~MutableConst() {32    int q = hcm.n; // expected-note {{read of mutable}}33  }34};35constexpr MutableConst mc; // expected-error {{must have constant destruction}} expected-note {{in call}}36 37struct Temporary {38  int &&temp;39  constexpr ~Temporary() {40    int n = temp; // expected-note {{outside the expression that created the temporary}}41  }42};43constexpr Temporary t = {3}; // expected-error {{must have constant destruction}} expected-note {{created here}} expected-note {{in call}}44 45namespace P1073R3 {46consteval int f() { return 42; } // expected-note 2 {{declared here}}47consteval auto g() { return f; }48consteval int h(int (*p)() = g()) { return p(); }49constexpr int r = h();50constexpr auto e = g();  // expected-error {{call to consteval function 'P1073R3::g' is not a constant expression}} \51                            expected-error {{constexpr variable 'e' must be initialized by a constant expression}} \52                            expected-note 2 {{pointer to a consteval declaration is not a constant expression}}53static_assert(r == 42);54} // namespace P1073R355