]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: empty base constexpr -fno-elide-ctors [PR105245]
authorJason Merrill <jason@redhat.com>
Tue, 12 Apr 2022 21:46:59 +0000 (17:46 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 13 Apr 2022 14:17:52 +0000 (10:17 -0400)
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.

gcc/cp/constexpr.cc
gcc/testsuite/g++.dg/cpp1y/constexpr-empty2.C

index 1ce1842430d03ec6297ef7afaeb4afaf83657e51..b170053e8e160645c45e4ea0ed6145d48b03d3dd 100644 (file)
@@ -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
index 2acfa98364b495de85adb0374fdaaf14213acd53..9768b89904edfd0afc183effd74544606c810d00 100644 (file)
@@ -1,4 +1,5 @@
 // { dg-do compile { target c++14 } }
+// { dg-additional-options -fno-elide-constructors }
 
 struct A
 {