1 // RUN: %clang_cc1 -std=c++2a -verify %s 2 3 constexpr int non_class = 42; 4 constexpr int arr_non_class[5] = {1, 2, 3}; 5 6 struct A { 7 int member = 1; ~AA8 constexpr ~A() { member = member + 1; } 9 }; 10 constexpr A class_ = {}; 11 constexpr A arr_class[5] = {{}, {}}; 12 13 struct Mutable { 14 mutable int member = 1; // expected-note {{declared here}} ~MutableMutable15 constexpr ~Mutable() { member = member + 1; } // expected-note {{read of mutable member}} 16 }; 17 constexpr Mutable mut_member; // expected-error {{must have constant destruction}} expected-note {{in call}} 18 19 struct MutableStore { 20 mutable int member = 1; // expected-note {{declared here}} ~MutableStoreMutableStore21 constexpr ~MutableStore() { member = 2; } // expected-note {{assignment to mutable member}} 22 }; 23 constexpr 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. 26 struct MutableConst { 27 struct HasConstMember { 28 const int n = 4; 29 }; 30 mutable HasConstMember hcm; // expected-note {{here}} ~MutableConstMutableConst31 constexpr ~MutableConst() { 32 int q = hcm.n; // expected-note {{read of mutable}} 33 } 34 }; 35 constexpr MutableConst mc; // expected-error {{must have constant destruction}} expected-note {{in call}} 36 37 struct Temporary { 38 int &&temp; ~TemporaryTemporary39 constexpr ~Temporary() { 40 int n = temp; // expected-note {{outside the expression that created the temporary}} 41 } 42 }; 43 constexpr Temporary t = {3}; // expected-error {{must have constant destruction}} expected-note {{created here}} expected-note {{in call}} 44