public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Marek Polacek <mpolacek@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-5064] c++: Skip unnamed bit-fields more Date: Tue, 9 Nov 2021 16:38:16 +0000 (GMT) [thread overview] Message-ID: <20211109163816.66FD03858404@sourceware.org> (raw) https://gcc.gnu.org/g:a648acc3b4ce528464ca23ee233de8f320542195 commit r12-5064-ga648acc3b4ce528464ca23ee233de8f320542195 Author: Marek Polacek <polacek@redhat.com> Date: Mon Nov 8 12:55:52 2021 -0500 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. Diff: --- gcc/cp/class.c | 7 +++---- gcc/cp/method.c | 4 +++- gcc/testsuite/g++.dg/init/bitfield6.C | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/gcc/cp/class.c b/gcc/cp/class.c index f16e50b9de9..bf92300a178 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 1023aefc575..935946f5eef 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 diff --git a/gcc/testsuite/g++.dg/init/bitfield6.C b/gcc/testsuite/g++.dg/init/bitfield6.C new file mode 100644 index 00000000000..70854ee9588 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/bitfield6.C @@ -0,0 +1,20 @@ +// { dg-do compile { target c++11 } } + +struct A +{ + int : 8; + int i = 42; +}; + +constexpr A a; + +struct B : A { +}; + +constexpr B b; + +struct C { + int : 0; +}; + +constexpr C c;
reply other threads:[~2021-11-09 16:38 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211109163816.66FD03858404@sourceware.org \ --to=mpolacek@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).