diff options
author | Jason Merrill <jason@redhat.com> | 2022-04-12 17:46:59 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2022-04-13 10:17:52 -0400 |
commit | ec03862f809e544a9b7d28067e51597dc92a0244 (patch) | |
tree | ffd41024862ee3acf24a4bcead8c5f9024b30b93 | |
parent | 31350635bfd90beea79b0e9220008da12bbb5d22 (diff) | |
download | gcc-ec03862f809e544a9b7d28067e51597dc92a0244.zip gcc-ec03862f809e544a9b7d28067e51597dc92a0244.tar.gz gcc-ec03862f809e544a9b7d28067e51597dc92a0244.tar.bz2 |
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.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.
-rw-r--r-- | gcc/cp/constexpr.cc | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1y/constexpr-empty2.C | 1 |
2 files changed, 7 insertions, 0 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 1ce1842..b170053 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 2acfa98..9768b89 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 { |