From: Jason Merrill Date: Tue, 12 Apr 2022 21:46:59 +0000 (-0400) Subject: c++: empty base constexpr -fno-elide-ctors [PR105245] X-Git-Tag: releases/gcc-10.4.0~149 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c7905a9f10d28dfd27ddf21d3bf38a3e261ee10;p=thirdparty%2Fgcc.git c++: empty base constexpr -fno-elide-ctors [PR105245] The patch for 100111 extended our handling of empty base elision to the case where the derived class has no other fields, but we still need to make sure that there's some initializer for the derived object. PR c++/105245 PR c++/100111 gcc/cp/ChangeLog: * constexpr.c (cxx_eval_store_expression): Build a CONSTRUCTOR as needed in empty base handling. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/constexpr-empty2.C: Add -fno-elide-constructors. --- diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 28b0a88a6582..31af214a28c8 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -5149,6 +5149,12 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, { /* See above on initialization of empty bases. */ gcc_assert (is_empty_class (TREE_TYPE (init)) && !lval); + if (!*valp) + { + /* But do make sure we have something in *valp. */ + *valp = build_constructor (type, NULL); + CONSTRUCTOR_NO_CLEARING (*valp) = no_zero_init; + } return init; } else diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-empty2.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-empty2.C index 2acfa98364b4..9768b89904ed 100644 --- a/gcc/testsuite/g++.dg/cpp1y/constexpr-empty2.C +++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-empty2.C @@ -1,4 +1,5 @@ // { dg-do compile { target c++14 } } +// { dg-additional-options -fno-elide-constructors } struct A {