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.
Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/105245 PR c++/100111 gcc/cp/ChangeLog: * constexpr.cc (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. --- gcc/cp/constexpr.cc | 6 ++++++ gcc/testsuite/g++.dg/cpp1y/constexpr-empty2.C | 1 + 2 files changed, 7 insertions(+) diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 1ce1842430d..b170053e8e1 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -5933,6 +5933,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, nullptr); + 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 2acfa98364b..9768b89904e 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 { base-commit: 31350635bfd90beea79b0e9220008da12bbb5d22 -- 2.27.0