| 1 |
// { dg-do compile } |
| 2 |
// Explicit { dg-require-effective-target exceptions_enabled } to avoid verify compiler messages FAILs for '-fno-exceptions'. |
| 3 |
// { dg-options "-std=c++2a" } |
| 4 |
|
| 5 |
consteval int bar (int i) { if (i != 1) throw 1; return 0; } // { dg-error "is not a constant expression" } |
| 6 |
|
| 7 |
constexpr int a = bar (1); |
| 8 |
constexpr int b = bar (2); // { dg-message "in 'constexpr' expansion of" } |
| 9 |
constexpr int c = 0 ? bar (3) : 1; |
| 10 |
const int d = bar (4); // { dg-message "in 'constexpr' expansion of" } |
| 11 |
// { dg-error "call to consteval function" "" { target *-*-* } .-1 } |
| 12 |
const int e = 0 ? bar (5) : 1; |
| 13 |
int f = bar (1); |
| 14 |
int g = bar (6); // { dg-message "in 'constexpr' expansion of" } |
| 15 |
// { dg-error "call to consteval function" "" { target *-*-* } .-1 } |
| 16 |
int h = 0 ? bar (7) : 1; |
| 17 |
|
| 18 |
void |
| 19 |
foo () |
| 20 |
{ |
| 21 |
constexpr int a = bar (1); |
| 22 |
constexpr int b = bar (2); // { dg-message "in 'constexpr' expansion of" } |
| 23 |
constexpr int c = 0 ? bar (3) : 1; |
| 24 |
const int d = bar (4); // { dg-message "in 'constexpr' expansion of" } |
| 25 |
// { dg-error "call to consteval function" "" { target *-*-* } .-1 } |
| 26 |
const int e = 0 ? bar (5) : 1; |
| 27 |
int f = bar (1); |
| 28 |
int g = bar (6); // { dg-message "in 'constexpr' expansion of" } |
| 29 |
// { dg-error "call to consteval function" "" { target *-*-* } .-1 } |
| 30 |
int h = 0 ? bar (7) : 1; // { dg-message "in 'constexpr' expansion of" } |
| 31 |
// { dg-error "call to consteval function" "" { target *-*-* } .-1 } |
| 32 |
h += 0 ? bar (8) : 1; // { dg-message "in 'constexpr' expansion of" } |
| 33 |
// { dg-error "call to consteval function" "" { target *-*-* } .-1 } |
| 34 |
if (0) |
| 35 |
bar (9); // { dg-message "in 'constexpr' expansion of" } |
| 36 |
// { dg-error "call to consteval function" "" { target *-*-* } .-1 } |
| 37 |
else |
| 38 |
bar (10); // { dg-message "in 'constexpr' expansion of" } |
| 39 |
// { dg-error "call to consteval function" "" { target *-*-* } .-1 } |
| 40 |
if (1) |
| 41 |
bar (11); // { dg-message "in 'constexpr' expansion of" } |
| 42 |
// { dg-error "call to consteval function" "" { target *-*-* } .-1 } |
| 43 |
else |
| 44 |
bar (12); // { dg-message "in 'constexpr' expansion of" } |
| 45 |
// { dg-error "call to consteval function" "" { target *-*-* } .-1 } |
| 46 |
if constexpr (0) |
| 47 |
bar (13); |
| 48 |
else |
| 49 |
bar (14); // { dg-message "in 'constexpr' expansion of" } |
| 50 |
// { dg-error "call to consteval function" "" { target *-*-* } .-1 } |
| 51 |
if constexpr (1) |
| 52 |
bar (15); // { dg-message "in 'constexpr' expansion of" } |
| 53 |
// { dg-error "call to consteval function" "" { target *-*-* } .-1 } |
| 54 |
else |
| 55 |
bar (16); |
| 56 |
} |
| 57 |
|
| 58 |
consteval int |
| 59 |
baz () |
| 60 |
{ |
| 61 |
constexpr int a = bar (1); |
| 62 |
constexpr int b = bar (2); // { dg-message "in 'constexpr' expansion of" } |
| 63 |
constexpr int c = 0 ? bar (3) : 1; |
| 64 |
const int d = bar (4); |
| 65 |
const int e = 0 ? bar (5) : 1; |
| 66 |
int f = bar (1); |
| 67 |
int g = bar (6); |
| 68 |
int h = 0 ? bar (7) : 1; |
| 69 |
h += 0 ? bar (8) : 1; |
| 70 |
if (0) |
| 71 |
bar (9); |
| 72 |
else |
| 73 |
bar (10); |
| 74 |
if (1) |
| 75 |
bar (11); |
| 76 |
else |
| 77 |
bar (12); |
| 78 |
if constexpr (0) |
| 79 |
bar (13); |
| 80 |
else |
| 81 |
bar (14); |
| 82 |
if constexpr (1) |
| 83 |
bar (15); |
| 84 |
else |
| 85 |
bar (16); |
| 86 |
return 0; |
| 87 |
} |
| 88 |
|
| 89 |
template <typename T> |
| 90 |
void |
| 91 |
qux () |
| 92 |
{ |
| 93 |
// Used to give errors errors here, but not since we moved consteval |
| 94 |
// function folding to cp_fold_r which isn't called on uninstantiated |
| 95 |
// templates. |
| 96 |
if (0) |
| 97 |
bar (2); |
| 98 |
else |
| 99 |
bar (3); |
| 100 |
if (1) |
| 101 |
bar (4); |
| 102 |
else |
| 103 |
bar (5); |
| 104 |
if constexpr (0) |
| 105 |
bar (6); |
| 106 |
else |
| 107 |
bar (7); |
| 108 |
if constexpr (1) |
| 109 |
bar (8); |
| 110 |
else |
| 111 |
bar (9); |
| 112 |
if (0) |
| 113 |
bar ((T) 2); |
| 114 |
else |
| 115 |
bar ((T) 3); |
| 116 |
if (1) |
| 117 |
bar ((T) 4); |
| 118 |
else |
| 119 |
bar ((T) 5); |
| 120 |
if constexpr (0) |
| 121 |
bar ((T) 6); |
| 122 |
else |
| 123 |
bar ((T) 7); |
| 124 |
if constexpr (1) |
| 125 |
bar ((T) 8); |
| 126 |
else |
| 127 |
bar ((T) 9); |
| 128 |
} |
| 129 |
|
| 130 |
template <typename T> |
| 131 |
void |
| 132 |
quux () |
| 133 |
{ |
| 134 |
if (0) |
| 135 |
bar ((T) 2); // { dg-message "in 'constexpr' expansion of" } |
| 136 |
// { dg-error "call to consteval function" "" { target *-*-* } .-1 } |
| 137 |
else |
| 138 |
bar ((T) 3); // { dg-message "in 'constexpr' expansion of" } |
| 139 |
// { dg-error "call to consteval function" "" { target *-*-* } .-1 } |
| 140 |
if (1) |
| 141 |
bar ((T) 4); // { dg-message "in 'constexpr' expansion of" } |
| 142 |
// { dg-error "call to consteval function" "" { target *-*-* } .-1 } |
| 143 |
else |
| 144 |
bar ((T) 5); // { dg-message "in 'constexpr' expansion of" } |
| 145 |
// { dg-error "call to consteval function" "" { target *-*-* } .-1 } |
| 146 |
if constexpr (0) |
| 147 |
bar ((T) 6); |
| 148 |
else |
| 149 |
bar ((T) 7); // { dg-message "in 'constexpr' expansion of" } |
| 150 |
// { dg-error "call to consteval function" "" { target *-*-* } .-1 } |
| 151 |
if constexpr (1) |
| 152 |
bar ((T) 8); // { dg-message "in 'constexpr' expansion of" } |
| 153 |
// { dg-error "call to consteval function" "" { target *-*-* } .-1 } |
| 154 |
else |
| 155 |
bar ((T) 9); |
| 156 |
} |
| 157 |
|
| 158 |
void |
| 159 |
corge () |
| 160 |
{ |
| 161 |
quux <int> (); |
| 162 |
} |