https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121579
Bug ID: 121579 Summary: static_cast involving pointers to members is too loose during constant evaluation Product: gcc Version: 16.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: luigighiron at gmail dot com Target Milestone: --- GCC incorrectly allows the following program: consteval int foo(){ struct A{char x;}; struct B{char y;}; struct C:A,B{}; char C::*p=&A::x; char B::*q=static_cast<char B::*>(p); C c{}; return((B&)c).*q; } int main(){ return foo(); } This program should be rejected since the static_cast has undefined behavior. The member x is neither in B, nor a class derived from B.