Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / expr / expr.const / p6-2a.cpp
bloba937474d53b221cbd64290d335f6c57757cd63e4
1 // RUN: %clang_cc1 -std=c++2a -verify %s
3 constexpr int non_class = 42;
4 constexpr int arr_non_class[5] = {1, 2, 3};
6 struct A {
7 int member = 1;
8 constexpr ~A() { member = member + 1; }
9 };
10 constexpr A class_ = {};
11 constexpr A arr_class[5] = {{}, {}};
13 struct Mutable {
14 mutable int member = 1; // expected-note {{declared here}}
15 constexpr ~Mutable() { member = member + 1; } // expected-note {{read of mutable member}}
17 constexpr Mutable mut_member; // expected-error {{must have constant destruction}} expected-note {{in call}}
19 struct MutableStore {
20 mutable int member = 1; // expected-note {{declared here}}
21 constexpr ~MutableStore() { member = 2; } // expected-note {{assignment to mutable member}}
23 constexpr MutableStore mut_store; // expected-error {{must have constant destruction}} expected-note {{in call}}
25 // Note: the constant destruction rules disallow this example even though hcm.n is a const object.
26 struct MutableConst {
27 struct HasConstMember {
28 const int n = 4;
30 mutable HasConstMember hcm; // expected-note {{here}}
31 constexpr ~MutableConst() {
32 int q = hcm.n; // expected-note {{read of mutable}}
35 constexpr MutableConst mc; // expected-error {{must have constant destruction}} expected-note {{in call}}
37 struct Temporary {
38 int &&temp;
39 constexpr ~Temporary() {
40 int n = temp; // expected-note {{outside the expression that created the temporary}}
43 constexpr Temporary t = {3}; // expected-error {{must have constant destruction}} expected-note {{created here}} expected-note {{in call}}
45 namespace P1073R3 {
46 consteval int f() { return 42; } // expected-note 2 {{declared here}}
47 consteval auto g() { return f; }
48 consteval int h(int (*p)() = g()) { return p(); }
49 constexpr int r = h();
50 constexpr 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}}
53 static_assert(r == 42);
54 } // namespace P1073R3