https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109243
Bug ID: 109243 Summary: Side cast of pointer-to-member with UB is incorrectly accepted in constant evaluation Product: gcc Version: 13.0 Status: UNCONFIRMED Keywords: accepts-invalid Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: de34 at live dot cn Target Milestone: --- The following code snippet is incorrectly accepted by gcc (perhaps in all versions supporting constexpr) (Godbolt link: https://godbolt.org/z/GqodcGWPe): ``` struct B1 { char i; }; struct B2 { char j; }; struct D : B1, B2 {}; constexpr auto mp = static_cast<char B2::*>(static_cast<char D::*>(&B1::i)); ``` According to [expr.static.cast]/13, such static_cast (performing side cast) has undefined behavior, and should not be accepted as a constant (sub)expression. (Unfortunately, there're well-defined manners to create a non-null pointer-to-member with offset -1, see https://github.com/itanium-cxx-abi/cxx-abi/pull/163).