| 1 |
// PR c++/86769 |
| 2 |
// { dg-do run { target c++11 } } |
| 3 |
|
| 4 |
int d, e, f, g, h; |
| 5 |
struct A { |
| 6 |
int a; |
| 7 |
A (int x) : a(x) { ++d; ++h; } |
| 8 |
~A () { --d; ++h; } |
| 9 |
A (const A &x) : a(x.a) { ++d; ++h; } |
| 10 |
operator bool () { return a != 0; } |
| 11 |
}; |
| 12 |
struct B { |
| 13 |
B () { ++e; ++h; } |
| 14 |
~B () { --e; ++h; } |
| 15 |
B (const B &) { ++e; ++h; } |
| 16 |
}; |
| 17 |
|
| 18 |
int |
| 19 |
foo (B, int x) |
| 20 |
{ |
| 21 |
if (e != 1) |
| 22 |
__builtin_abort (); |
| 23 |
if (f ? x - 1 != (f - 1) % 3 : x) |
| 24 |
__builtin_abort (); |
| 25 |
++f; |
| 26 |
if (x == 1) |
| 27 |
return ++g < 3; |
| 28 |
return 0; |
| 29 |
} |
| 30 |
|
| 31 |
int |
| 32 |
bar (int n) |
| 33 |
{ |
| 34 |
if (e != 0 || d != n) |
| 35 |
__builtin_abort (); |
| 36 |
return 0; |
| 37 |
} |
| 38 |
|
| 39 |
int |
| 40 |
main () |
| 41 |
{ |
| 42 |
for (A a = (bar (0), foo (B {}, 0)); |
| 43 |
A b = (bar (1), foo (B {}, 1)); |
| 44 |
bar (2), foo (B {}, 3)) |
| 45 |
A c = (bar (2), foo (B {}, 2)); |
| 46 |
if (f != 8 || h != 28 || d || e) |
| 47 |
__builtin_abort (); |
| 48 |
f = 0; g = -2; h = 0; |
| 49 |
for (A a = (bar (0), foo (B {}, 0)); |
| 50 |
A b = (bar (1), foo (B {}, 1)); |
| 51 |
bar (2), foo (B {}, 3)) |
| 52 |
{ |
| 53 |
A c = (bar (2), foo (B {}, 2)); |
| 54 |
bar (3); |
| 55 |
} |
| 56 |
if (f != 14 || h != 48 || d || e) |
| 57 |
__builtin_abort (); |
| 58 |
f = 0; g = 0; h = 0; |
| 59 |
{ |
| 60 |
A a = (bar (0), foo (B {}, 0)); |
| 61 |
while (A b = (bar (1), foo (B {}, 1))) |
| 62 |
{ |
| 63 |
A c = (bar (2), foo (B {}, 2)); |
| 64 |
bar (3); |
| 65 |
foo (B {}, 3); |
| 66 |
} |
| 67 |
} |
| 68 |
if (f != 8 || h != 28 || d || e) |
| 69 |
__builtin_abort (); |
| 70 |
f = 0; g = -5; h = 0; |
| 71 |
for (A a = (bar (0), foo (B {}, 0)); |
| 72 |
A b = (bar (1), foo (B {}, 1)); |
| 73 |
bar (2), foo (B {}, 3)) |
| 74 |
{ |
| 75 |
if (f == 5) |
| 76 |
{ |
| 77 |
bar (2); |
| 78 |
foo (B {}, 2); |
| 79 |
bar (2); |
| 80 |
continue; |
| 81 |
} |
| 82 |
if (f == 11) |
| 83 |
break; |
| 84 |
A c = (bar (2), foo (B {}, 2)); |
| 85 |
bar (3); |
| 86 |
} |
| 87 |
if (f != 11 || h != 36 || d || e) |
| 88 |
__builtin_abort (); |
| 89 |
f = 0; g = -5; h = 0; |
| 90 |
{ |
| 91 |
A a = (bar (0), foo (B {}, 0)); |
| 92 |
while (A b = (bar (1), foo (B {}, 1))) |
| 93 |
{ |
| 94 |
if (f == 5) |
| 95 |
{ |
| 96 |
bar (2); |
| 97 |
foo (B {}, 2); |
| 98 |
bar (2); |
| 99 |
foo (B {}, 3); |
| 100 |
bar (2); |
| 101 |
continue; |
| 102 |
} |
| 103 |
else if (f == 11) |
| 104 |
break; |
| 105 |
A c = (bar (2), foo (B {}, 2)); |
| 106 |
bar (3); |
| 107 |
foo (B {}, 3); |
| 108 |
} |
| 109 |
} |
| 110 |
if (f != 11 || h != 36 || d || e) |
| 111 |
__builtin_abort (); |
| 112 |
} |