| 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 |
typedef int (S::*P) (); |
| 11 |
|
| 12 |
consteval P |
| 13 |
foo () |
| 14 |
{ |
| 15 |
return &S::foo; |
| 16 |
} |
| 17 |
|
| 18 |
consteval P |
| 19 |
bar () |
| 20 |
{ |
| 21 |
return &S::bar; |
| 22 |
} |
| 23 |
|
| 24 |
consteval int |
| 25 |
baz () |
| 26 |
{ |
| 27 |
S s; |
| 28 |
return (s.*(foo ())) () + (s.*(bar ())) (); |
| 29 |
} |
| 30 |
|
| 31 |
static_assert (baz () == 3); |
| 32 |
|
| 33 |
constexpr P a = foo (); // { dg-error "immediate evaluation returns address of immediate function" } |
| 34 |
constexpr P b = bar (); // { dg-error "immediate evaluation returns address of immediate function" } |