aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/constexpr.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2021-04-16 17:37:07 +0200
committerJakub Jelinek <jakub@redhat.com>2021-04-16 17:44:03 +0200
commit35e8b38a91d9fb49a4759649576f15e76c129d99 (patch)
tree49ae45c6708611d0f597beb5d0fbe0eb2398e8bc /gcc/cp/constexpr.c
parent4b53f4cde2accd328e5de4f164dc390d33446216 (diff)
downloadgcc-35e8b38a91d9fb49a4759649576f15e76c129d99.zip
gcc-35e8b38a91d9fb49a4759649576f15e76c129d99.tar.gz
gcc-35e8b38a91d9fb49a4759649576f15e76c129d99.tar.bz2
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 <jakub@redhat.com> 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.
Diffstat (limited to 'gcc/cp/constexpr.c')
-rw-r--r--gcc/cp/constexpr.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index b74bbac..0fb0ab4 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;