Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/consteval20.C

raw
1 // PR c++/102753
2 // { dg-do compile { target c++20 } }
3
4 struct S {
5 consteval int foo () const { return 42; }
6 };
7
8 constexpr S s;
9
10 int
11 bar ()
12 {
13 auto c = &S::foo; // { dg-error "taking address of an immediate function" }
14 constexpr auto d = &S::foo; // { dg-error "constant evaluation returns address of immediate function" }
15 static auto e = &S::foo; // { dg-error "taking address of an immediate function" }
16 return (s.*&S::foo) (); // { dg-error "taking address of an immediate function" }
17 }
18
19 constexpr auto a = &S::foo; // { dg-error "constant evaluation returns address of immediate function" }
20 auto b = &S::foo; // { dg-error "taking address of an immediate function" }
21
22 consteval int
23 baz ()
24 {
25 return (s.*&S::foo) ();
26 }
27
28 static_assert (baz () == 42);