Debian Codegraph @

gcc/testsuite/g++.dg/expr/for6.C

raw
1 // PR c++/86769
2 // { dg-do run { target c++11 } }
3
4 int v;
5
6 struct S {
7 int s;
8 S (int x) : s(x)
9 {
10 if ((v != 0 || s != 0) && (v != 3 || s != 1))
11 __builtin_abort ();
12 ++v;
13 }
14 ~S ()
15 {
16 if ((v != 2 || s != 0) && (v != 4 || s != 1))
17 __builtin_abort ();
18 ++v;
19 }
20 operator bool () const { return true; }
21 };
22
23 void
24 foo (const S &s)
25 {
26 if (v != 1 || s.s != 0)
27 __builtin_abort ();
28 ++v;
29 }
30
31 int
32 main ()
33 {
34 for (int i = 0; S j{i}; foo (j))
35 {
36 if (++i == 2)
37 break;
38 }
39 }