c++: Fix up potential_constant_expression_1 FOR/WHILE_STMT handling [PR98672]
[gcc.git] / gcc / testsuite / g++.dg / cpp1y / constexpr-98672.C
1 // PR c++/98672
2 // { dg-do compile { target c++14 } }
3
4 void
5 foo ()
6 {
7 }
8
9 constexpr int
10 bar ()
11 {
12 for (int i = 0; i < 5; ++i)
13 return i;
14 foo ();
15 return 0;
16 }
17
18 constexpr int
19 baz ()
20 {
21 int i = 0;
22 while (i < 5)
23 {
24 if (i == 3)
25 return i;
26 else
27 ++i;
28 }
29 foo ();
30 return 0;
31 }
32
33 constexpr int
34 qux (int x)
35 {
36 if (x > 10)
37 ++x;
38 else
39 return 7;
40 foo ();
41 return 0;
42 }
43
44 constexpr int
45 corge (int x)
46 {
47 for (int a = 1; ; a++)
48 {
49 if (x > 10)
50 ++x;
51 else
52 return 4;
53 foo ();
54 }
55 }
56
57 constexpr int
58 garply (int x)
59 {
60 for (int a = 1; ; a++)
61 {
62 if (x > 10)
63 ++x;
64 else
65 break;
66 foo ();
67 }
68 return x;
69 }
70
71 constexpr int
72 waldo (int x)
73 {
74 for (int a = 1; ; a++)
75 {
76 if (x > 10)
77 break;
78 else
79 return 5;
80 foo ();
81 }
82 foo ();
83 return x;
84 }
85
86 constexpr int i = bar ();
87 constexpr int j = baz ();
88 constexpr int k = qux (4);
89 constexpr int l = corge (5);
90 constexpr int m = garply (2);
91 constexpr int n = waldo (-2);
92 static_assert (i == 0 && j == 3 && k == 7 && l == 4 && m == 2 && n == 5, "");