aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2021-01-22 13:17:10 -0500
committerJason Merrill <jason@redhat.com>2021-01-25 10:36:27 -0500
commit94ff4c9dd98f39280fba22d1ad0958fb25a5363b (patch)
treeab662beb03a2eb1997cef9866d0c14c4d3f5f3b4 /gcc/cp
parent10c83fb7131779ee27fbaa9091065ca6cfedc0c5 (diff)
downloadgcc-94ff4c9dd98f39280fba22d1ad0958fb25a5363b.zip
gcc-94ff4c9dd98f39280fba22d1ad0958fb25a5363b.tar.gz
gcc-94ff4c9dd98f39280fba22d1ad0958fb25a5363b.tar.bz2
c++: [[no_unique_address]] in empty base [PR98463]
In this testcase, cxx_eval_store_expression got confused trying to build up CONSTRUCTORs for initializing a subobject because the subobject is a member of an empty base. In C++14 mode and below we don't build FIELD_DECLs for empty bases, so the CONSTRUCTOR skipped the empty base, and treated the member as a member of the derived class, which breaks. Fixed by recognizing this situation and giving up on trying to build a CONSTRUCTOR for the inner target at that point; since it doesn't have any data, we don't need to actually store anything. gcc/cp/ChangeLog: PR c++/98463 * constexpr.c (get_or_insert_ctor_field): Add check. (cxx_eval_store_expression): Handle discontinuity of refs. gcc/testsuite/ChangeLog: PR c++/98463 * g++.dg/cpp2a/no_unique_address8.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/constexpr.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index b787919..c121753 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -3474,7 +3474,9 @@ get_or_insert_ctor_field (tree ctor, tree index, int pos_hint = -1)
}
else
{
- gcc_assert (TREE_CODE (index) == FIELD_DECL);
+ gcc_assert (TREE_CODE (index) == FIELD_DECL
+ && (same_type_ignoring_top_level_qualifiers_p
+ (DECL_CONTEXT (index), TREE_TYPE (ctor))));
/* We must keep the CONSTRUCTOR's ELTS in FIELD order.
Usually we meet initializers in that order, but it is
@@ -5277,7 +5279,7 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t,
};
CONSTRUCTOR_ELTS (ary_ctor)->quick_push (elt);
}
-
+
*valp = ary_ctor;
}
@@ -5289,6 +5291,18 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t,
type = refs->pop();
tree index = refs->pop();
+ if (TREE_CODE (index) == FIELD_DECL
+ && !(same_type_ignoring_top_level_qualifiers_p
+ (DECL_CONTEXT (index), TREE_TYPE (*valp))))
+ {
+ /* INDEX isn't a member of *valp. This can happen if it's a member
+ of an empty base which isn't represented with a FIELD_DECL. Stop
+ trying to build a CONSTRUCTOR for the inner target; we'll notice
+ this disconnect again below and just return init. */
+ gcc_assert (is_empty_class (DECL_CONTEXT (index)));
+ break;
+ }
+
if (code == UNION_TYPE && CONSTRUCTOR_NELTS (*valp)
&& CONSTRUCTOR_ELT (*valp, 0)->index != index)
{