From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id 5D61838515CC; Thu, 12 May 2022 21:15:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5D61838515CC MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-10722] c++: empty base constexpr -fno-elide-ctors [PR105245] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: 20dc7a2119cc0a4e5ddc4a6899a7350621f05440 X-Git-Newrev: 6c7905a9f10d28dfd27ddf21d3bf38a3e261ee10 Message-Id: <20220512211534.5D61838515CC@sourceware.org> Date: Thu, 12 May 2022 21:15:34 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 May 2022 21:15:34 -0000 https://gcc.gnu.org/g:6c7905a9f10d28dfd27ddf21d3bf38a3e261ee10 commit r10-10722-g6c7905a9f10d28dfd27ddf21d3bf38a3e261ee10 Author: Jason Merrill Date: Tue Apr 12 17:46:59 2022 -0400 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: --- gcc/cp/constexpr.c | 6 ++++++ gcc/testsuite/g++.dg/cpp1y/constexpr-empty2.C | 1 + 2 files changed, 7 insertions(+) diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 28b0a88a658..31af214a28c 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 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 {