diff options
author | Marek Polacek <polacek@redhat.com> | 2021-11-08 12:55:52 -0500 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2021-11-09 11:36:19 -0500 |
commit | a648acc3b4ce528464ca23ee233de8f320542195 (patch) | |
tree | a8d1d9529b84e9b2fee3b12a96f0dc2b9bb1f651 /gcc/cp | |
parent | 78dd0de956cbc5a021d3c5e3eb39308c3207936e (diff) | |
download | gcc-a648acc3b4ce528464ca23ee233de8f320542195.zip gcc-a648acc3b4ce528464ca23ee233de8f320542195.tar.gz gcc-a648acc3b4ce528464ca23ee233de8f320542195.tar.bz2 |
c++: Skip unnamed bit-fields more
As Jason noticed in
<https://gcc.gnu.org/pipermail/gcc-patches/2021-November/583592.html>,
we shouldn't require an initializer for an unnamed bit-field, because,
as [class.bit] says, they cannot be initialized.
gcc/cp/ChangeLog:
* class.c (default_init_uninitialized_part): Use
next_initializable_field.
* method.c (walk_field_subobs): Skip unnamed bit-fields.
gcc/testsuite/ChangeLog:
* g++.dg/init/bitfield6.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/class.c | 7 | ||||
-rw-r--r-- | gcc/cp/method.c | 4 |
2 files changed, 6 insertions, 5 deletions
diff --git a/gcc/cp/class.c b/gcc/cp/class.c index f16e50b..bf92300 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -5455,10 +5455,9 @@ default_init_uninitialized_part (tree type) if (r) return r; } - for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t)) - if (TREE_CODE (t) == FIELD_DECL - && !DECL_ARTIFICIAL (t) - && !DECL_INITIAL (t)) + for (t = next_initializable_field (TYPE_FIELDS (type)); t; + t = next_initializable_field (DECL_CHAIN (t))) + if (!DECL_INITIAL (t) && !DECL_ARTIFICIAL (t)) { r = default_init_uninitialized_part (TREE_TYPE (t)); if (r) diff --git a/gcc/cp/method.c b/gcc/cp/method.c index 1023aef..935946f 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -2295,7 +2295,9 @@ walk_field_subobs (tree fields, special_function_kind sfk, tree fnname, { tree mem_type, argtype, rval; - if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field)) + if (TREE_CODE (field) != FIELD_DECL + || DECL_ARTIFICIAL (field) + || DECL_UNNAMED_BIT_FIELD (field)) continue; /* Variant members only affect deletedness. In particular, they don't |