| 1 |
// PR c++/122772 |
| 2 |
// { dg-do run } |
| 3 |
|
| 4 |
struct S { int y : 7; } s; |
| 5 |
struct T { int x; int z : 7; } t; |
| 6 |
int cnt, mode; |
| 7 |
|
| 8 |
int |
| 9 |
foo () |
| 10 |
{ |
| 11 |
#if __cplusplus >= 201703L |
| 12 |
if (cnt != 1 + (mode & 1)) |
| 13 |
__builtin_abort (); |
| 14 |
#endif |
| 15 |
++cnt; |
| 16 |
return 2; |
| 17 |
} |
| 18 |
|
| 19 |
int |
| 20 |
bar () |
| 21 |
{ |
| 22 |
#if __cplusplus >= 201703L |
| 23 |
if (cnt != 0) |
| 24 |
__builtin_abort (); |
| 25 |
#endif |
| 26 |
++cnt; |
| 27 |
return 40; |
| 28 |
} |
| 29 |
|
| 30 |
S & |
| 31 |
baz () |
| 32 |
{ |
| 33 |
#if __cplusplus >= 201703L |
| 34 |
if (cnt != 2 + (mode & 1)) |
| 35 |
__builtin_abort (); |
| 36 |
#endif |
| 37 |
if (mode & 2) |
| 38 |
__builtin_abort (); |
| 39 |
++cnt; |
| 40 |
return s; |
| 41 |
} |
| 42 |
|
| 43 |
T & |
| 44 |
qux () |
| 45 |
{ |
| 46 |
#if __cplusplus >= 201703L |
| 47 |
if (cnt != 2 + (mode & 1)) |
| 48 |
__builtin_abort (); |
| 49 |
#endif |
| 50 |
if ((mode & 2) == 0) |
| 51 |
__builtin_abort (); |
| 52 |
++cnt; |
| 53 |
return t; |
| 54 |
} |
| 55 |
|
| 56 |
bool |
| 57 |
fred (bool x) |
| 58 |
{ |
| 59 |
#if __cplusplus >= 201703L |
| 60 |
if (cnt != 1) |
| 61 |
__builtin_abort (); |
| 62 |
#endif |
| 63 |
++cnt; |
| 64 |
return x; |
| 65 |
} |
| 66 |
|
| 67 |
void |
| 68 |
plugh (bool b) |
| 69 |
{ |
| 70 |
S x; |
| 71 |
x.y = 5; |
| 72 |
mode = 0; |
| 73 |
cnt = 0; |
| 74 |
(x.y = foo ()) += bar (); |
| 75 |
if (cnt != 2 || x.y != 42) |
| 76 |
__builtin_abort (); |
| 77 |
x.y = 5; |
| 78 |
cnt = 0; |
| 79 |
(baz ().y = foo ()) += bar (); |
| 80 |
if (cnt != 3 || s.y != 42) |
| 81 |
__builtin_abort (); |
| 82 |
s.y = 5; |
| 83 |
mode = (b ? 0 : 2); |
| 84 |
cnt = 0; |
| 85 |
(b ? (baz ().y = foo ()) : (qux ().z = foo ())) += bar (); |
| 86 |
if (cnt != 3 || (b ? (s.y != 42) : (t.z != 42))) |
| 87 |
__builtin_abort (); |
| 88 |
s.y = 5; |
| 89 |
t.z = 5; |
| 90 |
mode |= 1; |
| 91 |
cnt = 0; |
| 92 |
(fred (b) ? (baz ().y = foo ()) : (qux ().z = foo ())) += bar (); |
| 93 |
if (cnt != 4 || (b ? (s.y != 42) : (t.z != 42))) |
| 94 |
__builtin_abort (); |
| 95 |
s.y = 5; |
| 96 |
t.z = 5; |
| 97 |
mode = 0; |
| 98 |
cnt = 0; |
| 99 |
++x.y += bar (); |
| 100 |
if (cnt != 1 || x.y != 46) |
| 101 |
__builtin_abort (); |
| 102 |
cnt = 0; |
| 103 |
x.y = 9; |
| 104 |
--x.y += bar (); |
| 105 |
if (cnt != 1 || x.y != 48) |
| 106 |
__builtin_abort (); |
| 107 |
} |
| 108 |
|
| 109 |
int |
| 110 |
main () |
| 111 |
{ |
| 112 |
plugh (false); |
| 113 |
plugh (true); |
| 114 |
} |