Debian Codegraph @

gcc/testsuite/g++.dg/cpp23/consteval-if2.C

raw
1 // P1938R3
2 // { dg-do compile { target c++20 } }
3 // { dg-options "" }
4
5 constexpr bool f()
6 {
7 if consteval (true) {} // { dg-error "'if consteval' requires compound statement" }
8 // { dg-error "expected" "" { target *-*-* } .-1 }
9 // { dg-warning "'if consteval' only available with" "" { target c++20_only } .-2 }
10 if not consteval (false) {} // { dg-error "'if consteval' requires compound statement" }
11 // { dg-error "expected" "" { target *-*-* } .-1 }
12 // { dg-warning "'if consteval' only available with" "" { target c++20_only } .-2 }
13 if consteval if (true) {} // { dg-error "'if consteval' requires compound statement" }
14 // { dg-warning "'if consteval' only available with" "" { target c++20_only } .-1 }
15 if ! consteval {} else ; // { dg-error "'if consteval' requires compound statement" }
16 // { dg-warning "'if consteval' only available with" "" { target c++20_only } .-1 }
17 if consteval {} else if (true) {} // { dg-error "'if consteval' requires compound statement" }
18 // { dg-warning "'if consteval' only available with" "" { target c++20_only } .-1 }
19 if (true)
20 if consteval // { dg-warning "'if consteval' only available with" "" { target c++20_only } }
21 {
22 }
23 else ; // { dg-error "'if consteval' requires compound statement" }
24 return false;
25 }
26
27 consteval int foo (int x) { return x; }
28 consteval int bar () { return 2; }
29
30 constexpr int
31 baz (int x)
32 {
33 int r = 0;
34 if not consteval // { dg-warning "'if consteval' only available with" "" { target c++20_only } }
35 {
36 r += foo (x); // { dg-error "not a constant expression" }
37 }
38 else
39 {
40 r += bar ();
41 }
42 if consteval // { dg-warning "'if consteval' only available with" "" { target c++20_only } }
43 {
44 r += 2 * bar ();
45 }
46 else
47 {
48 r += foo (8 * x); // { dg-error "is not a constant expression" }
49 }
50 if ! consteval // { dg-warning "'if consteval' only available with" "" { target c++20_only } }
51 {
52 r += foo (32 * x);// { dg-error "not a constant expression" }
53 }
54 if consteval // { dg-warning "'if consteval' only available with" "" { target c++20_only } }
55 {
56 r += 32 * bar ();
57 }
58 return r;
59 }
60
61 // This function is not instantiated so NDR.
62 template <typename T>
63 constexpr int
64 qux (int x)
65 {
66 int r = 0;
67 if not consteval // { dg-warning "'if consteval' only available with" "" { target c++20_only } }
68 {
69 r += foo (x); // { dg-error "'x' is not a constant expression" "" { xfail *-*-* } }
70 }
71 else
72 {
73 r += bar ();
74 }
75 if consteval // { dg-warning "'if consteval' only available with" "" { target c++20_only } }
76 {
77 r += 2 * bar ();
78 }
79 else
80 {
81 r += foo (8 * x); // { dg-error "is not a constant expression" "" { xfail *-*-* } }
82 }
83 if ! consteval // { dg-warning "'if consteval' only available with" "" { target c++20_only } }
84 {
85 r += foo (32 * x);// { dg-error "is not a constant expression" "" { xfail *-*-* } }
86 }
87 if consteval // { dg-warning "'if consteval' only available with" "" { target c++20_only } }
88 {
89 r += 32 * bar ();
90 }
91 return r;
92 }
93
94 template <typename T>
95 constexpr T
96 corge (T x)
97 {
98 T r = 0;
99 if not consteval // { dg-warning "'if consteval' only available with" "" { target c++20_only } }
100 {
101 r += foo (x);
102 }
103 else
104 {
105 r += bar ();
106 }
107 if consteval // { dg-warning "'if consteval' only available with" "" { target c++20_only } }
108 {
109 r += 2 * bar ();
110 }
111 else
112 {
113 r += foo (8 * x);
114 }
115 if ! consteval // { dg-warning "'if consteval' only available with" "" { target c++20_only } }
116 {
117 r += foo (32 * x);
118 }
119 if consteval // { dg-warning "'if consteval' only available with" "" { target c++20_only } }
120 {
121 r += 32 * bar ();
122 }
123 return r;
124 }
125
126 int
127 garply (int x)
128 {
129 return corge (x); // { dg-error "is not a constant expression" }
130 }