https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121250
Bug ID: 121250 Summary: Accepts invalid program containing function call via member pointer to member in derived class during constant evaluation Product: gcc Version: 16.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: keinfluegeltier at posteo dot de Target Milestone: --- The following program is ill-formed, but accepted by GCC (see https://godbolt.org/z/rYEq8ndbz): struct A { }; struct B : A { constexpr void foo() {} }; consteval void test() { auto p = &B::foo; auto q = static_cast<void (A::*)()>(p); A a; (a.*q)(); } int main() { test(); } The call via member function pointer would have undefined behavior because the member `B::foo` to which `q` refers is not a direct or indirect member of the most derived class `A` of `a`. Therefore the constant evaluation of `test()` must fail and the program is ill-formed.