Debian Codegraph @

gcc/testsuite/g++.dg/cpp1z/eval-order11.C

raw
1 // PR c++/70796
2 // { dg-do run { target c++11 } }
3 // { dg-options "-fstrong-eval-order" { target c++14_down } }
4
5 struct A
6 {
7 int x = 0;
8 A & operator ++ () { ++x; return *this; }
9 };
10 struct B
11 {
12 A first, second;
13 B (A x, A y) : first{x}, second{y} {}
14 };
15 struct C
16 {
17 int first, second;
18 C (int x, int y) : first{x}, second{y} {}
19 };
20 struct D
21 {
22 int d;
23 void foo (int x, D *y)
24 {
25 if (y != this + 1)
26 __builtin_abort ();
27 d = x;
28 }
29 };
30 D d[2] = { { 1 }, { 2 } };
31
32 void
33 foo ()
34 {
35 int i = 0;
36 C p{++i, ++i};
37 if (p.first != 1 || p.second != 2)
38 __builtin_abort ();
39 }
40
41 void
42 bar ()
43 {
44 int i = 0;
45 C p{++i, ++i};
46 if (p.first != 1 || p.second != 2)
47 __builtin_abort ();
48 int &j = i;
49 C q{++j, ++j};
50 if (q.first != 3 || q.second != 4)
51 __builtin_abort ();
52 }
53
54 void
55 baz ()
56 {
57 int i = 0;
58 C p{(int &) ++i, (int &) ++i};
59 if (p.first != 1 || p.second != 2)
60 __builtin_abort ();
61 }
62
63 void
64 qux ()
65 {
66 A i;
67 B p{++i, ++i};
68 if (p.first.x != 1 || p.second.x != 2)
69 __builtin_abort ();
70 }
71
72 void
73 corge ()
74 {
75 D *p = &d[0];
76 p->foo (3, ++p);
77 if (d[0].d != 3 || d[1].d != 2)
78 __builtin_abort ();
79 }
80
81 int
82 main ()
83 {
84 bar ();
85 baz ();
86 foo ();
87 qux ();
88 corge ();
89 }