| 1 |
// PR c++/102753 |
| 2 |
// { dg-do compile { target c++20 } } |
| 3 |
|
| 4 |
struct S { |
| 5 |
constexpr S () : s (0) {} |
| 6 |
consteval int foo () { return 1; } |
| 7 |
virtual consteval int bar () { return 2; } |
| 8 |
int s; |
| 9 |
}; |
| 10 |
|
| 11 |
consteval int foo () { return 42; } |
| 12 |
|
| 13 |
consteval int |
| 14 |
bar (int (*fn) () = &foo) |
| 15 |
{ |
| 16 |
return fn (); |
| 17 |
} |
| 18 |
|
| 19 |
consteval int |
| 20 |
baz (int (S::*fn) () = &S::foo) |
| 21 |
{ |
| 22 |
S s; |
| 23 |
return (s.*fn) (); |
| 24 |
} |
| 25 |
|
| 26 |
consteval int |
| 27 |
qux (int (S::*fn) () = &S::bar) |
| 28 |
{ |
| 29 |
S s; |
| 30 |
return (s.*fn) (); |
| 31 |
} |
| 32 |
|
| 33 |
static_assert (bar () == 42); |
| 34 |
static_assert (baz () == 1); |
| 35 |
static_assert (qux () == 2); |