https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118523
--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Marek Polacek <mpola...@gcc.gnu.org>: https://gcc.gnu.org/g:f3f02493dfa8858c3fb2bc0da0d6d7320921408a commit r15-7103-gf3f02493dfa8858c3fb2bc0da0d6d7320921408a Author: Marek Polacek <pola...@redhat.com> Date: Thu Jan 16 11:22:59 2025 -0500 c++: fix wrong-code with constexpr prvalue opt [PR118396] The recent r15-6369 unfortunately caused a bad wrong-code issue. Here we have TARGET_EXPR <D.2996, (void) (D.2996 = {.status=0, .data={._vptr.Foo=&_ZTV3Foo + 16}})> and call cp_fold_r -> maybe_constant_init with object=D.2996. In cxx_eval_outermost_constant_expr we now take the type of the object if present. An object can't have type 'void' and so we continue to evaluate the initializer. That evaluates into a VOID_CST, meaning we disregard the whole initializer, and terrible things ensue. For non-simple TARGET_EXPRs, we should return ctx.ctor rather than the result of cxx_eval_constant_expression. PR c++/118396 PR c++/118523 gcc/cp/ChangeLog: * constexpr.cc (cxx_eval_outermost_constant_expr): For non-simple TARGET_EXPRs, return ctx.ctor rather than the result of cxx_eval_constant_expression. If TYPE and the type of R don't match, return the original expression. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/constexpr-prvalue4.C: New test. * g++.dg/cpp1y/constexpr-prvalue3.C: New test. Reviewed-by: Jason Merrill <ja...@redhat.com>