blob: d6bf5d78ab534157f33e9874c63db4d3fb1f4844 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
// PR c++/86769
// { dg-do compile { target c++20 } }
struct A {
int *a;
constexpr A (int x) : a (new int (x)) {}
constexpr A (const A &x) : a (new int (x.a[0])) {}
constexpr ~A () { delete a; }
constexpr operator bool () { return *a != 0; }
};
constexpr int
foo ()
{
int i = 0;
for (A a = 0; A b = a.a[0] < 16; a.a[0] += b.a[0])
i += a.a[0] + b.a[0];
return i;
}
static_assert (foo () == 136);
constexpr int
bar ()
{
int i = 0;
A a = 0;
while (A b = a.a[0] < 15)
{
i += a.a[0] + b.a[0];
a.a[0] += b.a[0];
}
return i;
}
static_assert (bar () == 120);
|