1 // PR c++/79232
2 // { dg-do run }
3 // { dg-options "-fstrong-eval-order" }
4 
5 int last = 0;
6 
7 int
foo(int i)8 foo (int i)
9 {
10   if (i != last + 1)
11     __builtin_abort ();
12   last = i;
13   return i;
14 }
15 
16 char a, b;
17 int c;
18 
19 char &
bar(int i,int j)20 bar (int i, int j)
21 {
22   foo (i);
23   return j ? a : b;
24 }
25 
26 int
main()27 main ()
28 {
29   (foo (2) ? bar (3, 0) : bar (3, 1)) = foo (1);
30   if (last != 3)
31     __builtin_abort ();
32   last = 0;
33   (foo (2), foo (3) ? bar (4, 0) : bar (4, 1)) = foo (1);
34   if (last != 4)
35     __builtin_abort ();
36   last = 0;
37   (foo (2), (foo (3) ? bar (4, 0) : bar (4, 1))) = foo (1);
38   if (last != 4)
39     __builtin_abort ();
40   last = 0;
41   (foo (2), foo (3), foo (4) ? bar (5, 0) : bar (5, 1)) = foo (1);
42   if (last != 5)
43     __builtin_abort ();
44   last = 0;
45   (foo (2), (foo (3), (foo (4) ? bar (5, 0) : bar (5, 1)))) = foo (1);
46   if (last != 5)
47     __builtin_abort ();
48   last = 0;
49   --c = foo (1);
50   if (c != 1)
51     __builtin_abort ();
52   last = 0;
53   (foo (2), --c) = foo (1);
54   if (last != 2 || c != 1)
55     __builtin_abort ();
56   last = 0;
57   (foo (2), foo (3), --c) = foo (1);
58   if (last != 3 || c != 1)
59     __builtin_abort ();
60   last = 0;
61   (foo (2), (foo (3), --c)) = foo (1);
62   if (last != 3 || c != 1)
63     __builtin_abort ();
64   last = 0;
65   bar (2, 0) = foo (1);
66   if (last != 2)
67     __builtin_abort ();
68   last = 0;
69   (foo (2), bar (3, 0)) = foo (1);
70   if (last != 3)
71     __builtin_abort ();
72   last = 0;
73   (foo (2), foo (3), bar (4, 0)) = foo (1);
74   if (last != 4)
75     __builtin_abort ();
76   last = 0;
77   (foo (2), (foo (3), bar (4, 0))) = foo (1);
78   if (last != 4)
79     __builtin_abort ();
80 }
81