| 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 |
consteval auto baz () { return foo; } |
| 13 |
consteval auto qux () { return &S::foo; } |
| 14 |
consteval auto corge () { return &S::bar; } |
| 15 |
|
| 16 |
consteval int |
| 17 |
bar () |
| 18 |
{ |
| 19 |
S s; |
| 20 |
constexpr auto fn1 = foo; // { dg-error "constant evaluation returns address of immediate function" } |
| 21 |
constexpr auto fn2 = &foo; // { dg-error "constant evaluation returns address of immediate function" } |
| 22 |
constexpr auto fn3 = &S::foo; // { dg-error "constant evaluation returns address of immediate function" } |
| 23 |
constexpr auto fn4 = &S::bar; // { dg-error "constant evaluation returns address of immediate function" } |
| 24 |
constexpr auto fn5 = baz (); // { dg-error "immediate evaluation returns address of immediate function" } |
| 25 |
constexpr auto fn6 = qux (); // { dg-error "immediate evaluation returns address of immediate function" } |
| 26 |
constexpr auto fn7 = corge (); // { dg-error "immediate evaluation returns address of immediate function" } |
| 27 |
return fn1 () + fn2 () + (s.*fn3) () + (s.*fn4) () + fn5 () + (s.*fn6) () + (s.*fn7) (); |
| 28 |
} |
| 29 |
|
| 30 |
auto a = bar (); // { dg-error "bar" } |