| 1 |
// PR c++/102753 |
| 2 |
// { dg-do compile { target c++20 } } |
| 3 |
// { dg-options "" } |
| 4 |
|
| 5 |
struct S { |
| 6 |
constexpr S () : s (0) {} |
| 7 |
consteval int foo () { return 1; } |
| 8 |
virtual consteval int bar () { return 2; } |
| 9 |
int s; |
| 10 |
}; |
| 11 |
|
| 12 |
consteval int foo () { return 42; } |
| 13 |
|
| 14 |
constexpr int |
| 15 |
bar () |
| 16 |
{ |
| 17 |
if consteval { // { dg-warning "'if consteval' only available with" "" { target c++20_only } } |
| 18 |
int (*fn1) () = foo; |
| 19 |
int (S::*fn2) () = &S::foo; |
| 20 |
int (S::*fn3) () = &S::bar; |
| 21 |
S s; |
| 22 |
return fn1 () + (s.*fn2) () + (s.*fn3) (); |
| 23 |
} |
| 24 |
return 0; |
| 25 |
} |
| 26 |
|
| 27 |
static_assert (bar () == 45); |