| 1 |
// P2564R3 |
| 2 |
// { dg-do compile { target c++20 } } |
| 3 |
// { dg-options "-Wno-c++23-extensions" } |
| 4 |
|
| 5 |
consteval int id (int i) { return i; } |
| 6 |
|
| 7 |
constexpr int |
| 8 |
f1 (auto i) |
| 9 |
{ |
| 10 |
auto p = &id; // { dg-message "promoted to an immediate function because its body contains an immediate-escalating expression .id." } |
| 11 |
(void) p; |
| 12 |
return i; |
| 13 |
} |
| 14 |
|
| 15 |
constexpr int |
| 16 |
f2 (auto i) |
| 17 |
{ |
| 18 |
return f1 (i); |
| 19 |
} |
| 20 |
|
| 21 |
constexpr int |
| 22 |
f3 (auto i) |
| 23 |
{ |
| 24 |
return f2 (i); |
| 25 |
} |
| 26 |
|
| 27 |
constexpr int |
| 28 |
f4 (auto i) |
| 29 |
{ |
| 30 |
return f3 (i); |
| 31 |
} |
| 32 |
|
| 33 |
constexpr int |
| 34 |
f5 (auto i) |
| 35 |
{ |
| 36 |
return f4 (i); // { dg-message "promoted to an immediate function because its body contains an immediate-escalating expression .f4<int>\\(i\\)." } |
| 37 |
} |
| 38 |
|
| 39 |
constexpr int |
| 40 |
f6 (auto) |
| 41 |
{ |
| 42 |
// This call is a constant expression, so don't promote f6. |
| 43 |
return f4 (42); |
| 44 |
} |
| 45 |
|
| 46 |
constexpr int |
| 47 |
f7 (auto i) |
| 48 |
{ |
| 49 |
if consteval { |
| 50 |
auto p = &id; |
| 51 |
(void) p; |
| 52 |
} |
| 53 |
return i; |
| 54 |
} |
| 55 |
|
| 56 |
constexpr int |
| 57 |
f8 (auto i) |
| 58 |
{ |
| 59 |
if not consteval { |
| 60 |
(void) 0; |
| 61 |
} else { |
| 62 |
auto p = &id; |
| 63 |
(void) p; |
| 64 |
} |
| 65 |
return i; |
| 66 |
} |
| 67 |
|
| 68 |
constexpr int |
| 69 |
f9 (auto i) |
| 70 |
{ |
| 71 |
if consteval { |
| 72 |
return id(i); |
| 73 |
} |
| 74 |
return i; |
| 75 |
} |
| 76 |
|
| 77 |
constexpr int |
| 78 |
f10 (auto i) |
| 79 |
{ |
| 80 |
if not consteval { |
| 81 |
(void) 0; |
| 82 |
} else { |
| 83 |
return id(i); |
| 84 |
} |
| 85 |
return i; |
| 86 |
} |
| 87 |
|
| 88 |
void |
| 89 |
g (int non_const) |
| 90 |
{ |
| 91 |
f1 (42); |
| 92 |
f1 (non_const); // { dg-error "call to consteval function .f1<int>\\(non_const\\). is not a constant expression" } |
| 93 |
// { dg-error ".non_const. is not a constant expression" "" { target *-*-* } .-1 } |
| 94 |
f5 (42); |
| 95 |
f5 (non_const); // { dg-error "call to consteval function .f5<int>\\(non_const\\). is not a constant expression" } |
| 96 |
// { dg-error ".non_const. is not a constant expression" "" { target *-*-* } .-1 } |
| 97 |
f6 (42); |
| 98 |
f6 (non_const); |
| 99 |
f7 (42); |
| 100 |
f7 (non_const); |
| 101 |
f8 (42); |
| 102 |
f8 (non_const); |
| 103 |
f9 (42); |
| 104 |
f9 (non_const); |
| 105 |
f10 (42); |
| 106 |
f10 (non_const); |
| 107 |
} |