aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2020-04-30 11:36:17 -0400
committerMarek Polacek <polacek@redhat.com>2020-05-01 16:32:23 -0400
commit30da2906ac521749aef8260fc1d942e62073f19d (patch)
treeee4e6c68c78be8a57c3ce437992da983e533f6df /gcc/cp
parent13ec6724cd543fed0211aa60a7f963ad40a2b5b2 (diff)
downloadgcc-30da2906ac521749aef8260fc1d942e62073f19d.zip
gcc-30da2906ac521749aef8260fc1d942e62073f19d.tar.gz
gcc-30da2906ac521749aef8260fc1d942e62073f19d.tar.bz2
c++: Parenthesized-init of aggregates accepts invalid code [PR94885]
Here we have (conceptually *) something like struct B { }; struct D : B { }; D(0); // invalid and in C++20 the ()-initialization has created a { 0 } constructor that it tries to initialize an object of type D with. We should reject initializing an object of type B from 0, but we wrongly accept it because process_init_constructor_record skips initializers for empty bases/fields: if (DECL_SIZE (field) && integer_zerop (DECL_SIZE (field)) && !TREE_SIDE_EFFECTS (next)) /* Don't add trivial initialization of an empty base/field to the constructor, as they might not be ordered the way the back-end expects. */ continue; but here 'next' was error_mark_node, returned by massage_elt_init, so we wound up with { } which would validly value-initialize the object. [*] Usually digest_init in build_new_method_call_1 would detect this, but in this case the instance is is_dummy_object and we don't call digest just yet. PR c++/94885 * typeck2.c (process_init_constructor_record): Return PICFLAG_ERRONEOUS if an initializer element was erroneous. * g++.dg/cpp2a/paren-init26.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/typeck2.c6
2 files changed, 11 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 0675f98..0b6b0ee 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2020-05-01 Marek Polacek <polacek@redhat.com>
+
+ PR c++/94885
+ * typeck2.c (process_init_constructor_record): Return PICFLAG_ERRONEOUS
+ if an initializer element was erroneous.
+
2020-05-01 Jason Merrill <jason@redhat.com>
PR c++/90479
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 56fd9ba..9e5d145 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -1661,7 +1661,11 @@ process_init_constructor_record (tree type, tree init, int nested, int flags,
++idx;
}
}
- if (next)
+ if (next == error_mark_node)
+ /* We skip initializers for empty bases/fields, so skipping an invalid
+ one could make us accept invalid code. */
+ return PICFLAG_ERRONEOUS;
+ else if (next)
/* Already handled above. */;
else if (DECL_INITIAL (field))
{