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};
8 constexpr ~A() { member
= member
+ 1; }
10 constexpr A class_
= {};
11 constexpr A arr_class
[5] = {{}, {}};
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}}
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.
27 struct HasConstMember
{
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}}
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}}
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