| 1 |
// P2564R3 |
| 2 |
// { dg-do compile { target c++20 } } |
| 3 |
// { dg-options "-fdiagnostics-show-caret" } |
| 4 |
// Test diagnostic. |
| 5 |
|
| 6 |
consteval int id (int i) { return i; } |
| 7 |
constexpr int foo (int i ) { return i; } |
| 8 |
|
| 9 |
constexpr int |
| 10 |
foobar (auto i) |
| 11 |
{ |
| 12 |
return i + id (i); |
| 13 |
/* { dg-begin-multiline-output "" } |
| 14 |
return i + id (i); |
| 15 |
~~~^~~ |
| 16 |
{ dg-end-multiline-output "" } */ |
| 17 |
} |
| 18 |
|
| 19 |
void |
| 20 |
g (int x) |
| 21 |
{ |
| 22 |
foobar (x); // { dg-error "10:call to consteval function .foobar<int>\\(x\\). is not a constant expression" } |
| 23 |
// { dg-error ".x. is not a constant expression" "" { target *-*-* } .-1 } |
| 24 |
/* { dg-begin-multiline-output "" } |
| 25 |
foobar (x); |
| 26 |
~~~~~~~^~~ |
| 27 |
{ dg-end-multiline-output "" } */ |
| 28 |
} |
| 29 |
|
| 30 |
constexpr int |
| 31 |
f2 (auto i) |
| 32 |
{ |
| 33 |
auto p = &id; |
| 34 |
/* { dg-begin-multiline-output "" } |
| 35 |
auto p = &id; |
| 36 |
^~~ |
| 37 |
{ dg-end-multiline-output "" } */ |
| 38 |
return p (i); |
| 39 |
} |
| 40 |
|
| 41 |
void |
| 42 |
g2 (int x) |
| 43 |
{ |
| 44 |
f2 (x); // { dg-error "6:call to consteval function .f2<int>\\(x\\). is not a constant expression|not a constant expression" } |
| 45 |
/* { dg-begin-multiline-output "" } |
| 46 |
f2 (x); |
| 47 |
~~~^~~ |
| 48 |
{ dg-end-multiline-output "" } */ |
| 49 |
} |