https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118396
--- Comment #12 from Marek Polacek <mpolacek at gcc dot gnu.org> --- So I think I'll test this: --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -8871,9 +8871,17 @@ cxx_eval_outermost_constant_expr (tree t, bool allow_non_constant, /* Turn off -frounding-math for manifestly constant evaluation. */ warning_sentinel rm (flag_rounding_math, ctx.manifestly_const_eval == mce_true); - tree type = (object - ? cv_unqualified (TREE_TYPE (object)) - : initialized_type (t)); + tree type; + if (object) + { + type = cv_unqualified (TREE_TYPE (object)); + /* If there is an object to initialize, make sure we don't throw + away the initializer. */ + gcc_assert (!VOID_TYPE_P (initialized_type (t)) || constexpr_dtor); + } + else + type = initialized_type (t); + tree r = t; bool is_consteval = false; if (VOID_TYPE_P (type)) diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc index c7074b00cef..283c0fa3e26 100644 --- a/gcc/cp/cp-gimplify.cc +++ b/gcc/cp/cp-gimplify.cc @@ -1475,7 +1475,9 @@ cp_fold_r (tree *stmt_p, int *walk_subtrees, void *data_) cp_walk_tree (&init, cp_fold_r, data, NULL); cp_walk_tree (&TARGET_EXPR_CLEANUP (stmt), cp_fold_r, data, NULL); *walk_subtrees = 0; - if (!flag_no_inline) + /* Only attempt to evaluate the initializer if we're inlining and + the TARGET_EXPR is simple. */ + if (!flag_no_inline && !VOID_TYPE_P (TREE_TYPE (init))) { tree folded = maybe_constant_init (init, TARGET_EXPR_SLOT (stmt)); if (folded != init && TREE_CONSTANT (folded))