From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id EDA8A3892460; Fri, 16 Apr 2021 15:44:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EDA8A3892460 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-8222] c++: Fix empty base stores in cxx_eval_store_expression [PR100111] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 4b53f4cde2accd328e5de4f164dc390d33446216 X-Git-Newrev: 35e8b38a91d9fb49a4759649576f15e76c129d99 Message-Id: <20210416154423.EDA8A3892460@sourceware.org> Date: Fri, 16 Apr 2021 15:44:23 +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: Fri, 16 Apr 2021 15:44:24 -0000 https://gcc.gnu.org/g:35e8b38a91d9fb49a4759649576f15e76c129d99 commit r11-8222-g35e8b38a91d9fb49a4759649576f15e76c129d99 Author: Jakub Jelinek Date: Fri Apr 16 17:37:07 2021 +0200 c++: Fix empty base stores in cxx_eval_store_expression [PR100111] In r11-6895 handling of empty bases has been fixed such that non-lval stores of empty classes are not added when the type of *valp doesn't match the type of the initializer, but as this testcase shows it is done only when *valp is non-NULL. If it is NULL, we still shouldn't add empty class constructors if the type of the constructor elt *valp points to doesn't match. 2021-04-16 Jakub Jelinek PR c++/100111 * constexpr.c (cxx_eval_store_expression): Don't add CONSTRUCTORs for empty classes into *valp when types don't match even when *valp is NULL. * g++.dg/cpp0x/constexpr-100111.C: New test. Diff: --- gcc/cp/constexpr.c | 8 ++++++++ gcc/testsuite/g++.dg/cpp0x/constexpr-100111.C | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index b74bbac3cd2..0fb0ab44b39 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -5538,6 +5538,14 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, CONSTRUCTOR_NO_CLEARING (*valp) = CONSTRUCTOR_NO_CLEARING (init); } + else if (TREE_CODE (init) == CONSTRUCTOR + && !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (init), + type)) + { + /* See above on initialization of empty bases. */ + gcc_assert (is_empty_class (TREE_TYPE (init)) && !lval); + return init; + } else *valp = init; diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-100111.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-100111.C new file mode 100644 index 00000000000..446d21d03c5 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-100111.C @@ -0,0 +1,7 @@ +// PR c++/100111 +// { dg-do compile { target c++11 } } +// { dg-options "-fno-elide-constructors" } + +struct A {}; +struct B : A { int b; constexpr B (A x) : A(x), b() {} }; +struct C { B c; constexpr C () : c({}) {} } d;