aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/decl.cc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2022-01-20 09:18:45 -0500
committerJason Merrill <jason@redhat.com>2022-01-20 15:23:43 -0500
commitcc01cd9397fe99e707bcc5b98bb33d807ba610d7 (patch)
tree6712a6c9d974d8e159226230652b802229bee605 /gcc/cp/decl.cc
parent30b38394b482ce894d9bc81731a0eea8711f4587 (diff)
downloadgcc-cc01cd9397fe99e707bcc5b98bb33d807ba610d7.zip
gcc-cc01cd9397fe99e707bcc5b98bb33d807ba610d7.tar.gz
gcc-cc01cd9397fe99e707bcc5b98bb33d807ba610d7.tar.bz2
c++: designator for base class member [PR101405]
A C++20 designator must name a direct non-static member of the class; in this case it names a member of a base class, and we should give an error instead of crashing. PR c++/101405 gcc/cp/ChangeLog: * decl.cc (reshape_init_class): Reject designator for a member of another class. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/desig20.C: New test.
Diffstat (limited to 'gcc/cp/decl.cc')
-rw-r--r--gcc/cp/decl.cc14
1 files changed, 10 insertions, 4 deletions
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 1cbe9a3..8e54218 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -6569,16 +6569,22 @@ reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
tree ictx = DECL_CONTEXT (field);
if (!same_type_ignoring_top_level_qualifiers_p (ictx, type))
{
- gcc_assert (ANON_AGGR_TYPE_P (ictx));
/* Find the anon aggr that is a direct member of TYPE. */
- while (true)
+ while (ANON_AGGR_TYPE_P (ictx))
{
tree cctx = TYPE_CONTEXT (ictx);
if (same_type_ignoring_top_level_qualifiers_p (cctx, type))
- break;
+ goto found;
ictx = cctx;
}
- /* And then the TYPE member with that anon aggr type. */
+
+ /* Not found, e.g. FIELD is a member of a base class. */
+ if (complain & tf_error)
+ error ("%qD is not a direct member of %qT", field, type);
+ return error_mark_node;
+
+ found:
+ /* Now find the TYPE member with that anon aggr type. */
tree aafield = TYPE_FIELDS (type);
for (; aafield; aafield = TREE_CHAIN (aafield))
if (TREE_TYPE (aafield) == ictx)