Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/constexpr-dtor17.C

raw
1 // PR c++/105440
2 // { dg-do compile { target c++20 } }
3
4 struct basic_string {
5 char _M_local_buf[32];
6 char* _M_p;
7 constexpr basic_string() : _M_p{_M_local_buf} { }
8 constexpr void f() { if (_M_p) { } }
9 constexpr ~basic_string() { if (_M_p) { } }
10 };
11
12 template<int N>
13 struct array {
14 basic_string _M_elems[N];
15 };
16
17 constexpr basic_string get() { return {}; }
18
19 constexpr bool f1() {
20 array<1> a{get()};
21 a._M_elems[0].f();
22
23 return true;
24 }
25
26 constexpr bool f2() {
27 array<2> a2{get(), get()};
28 array<3> a3{get(), get(), get()};
29
30 for (basic_string& e : a2._M_elems)
31 e.f();
32 for (basic_string& e : a3._M_elems)
33 e.f();
34
35 return true;
36 }
37
38 static_assert(f1());
39 static_assert(f2());