public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-7789] c++: tweak PR103337 fix Date: Wed, 23 Mar 2022 19:37:21 +0000 (GMT) [thread overview] Message-ID: <20220323193721.E68CC3858C2C@sourceware.org> (raw) https://gcc.gnu.org/g:2cd0c9a5310420e1039be5e514a818b6d381d89f commit r12-7789-g2cd0c9a5310420e1039be5e514a818b6d381d89f Author: Jason Merrill <jason@redhat.com> Date: Wed Mar 23 13:22:25 2022 -0400 c++: tweak PR103337 fix Patrick suggested a way to implement the designated-init handling without (temporarily) modifying the CONSTRUCTOR being reshaped. PR c++/103337 gcc/cp/ChangeLog: * decl.cc (reshape_single_init): New. (reshape_init_class): Use it. Diff: --- gcc/cp/decl.cc | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 34d9dad9fb0..efef1b7370f 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -6543,6 +6543,21 @@ reshape_init_vector (tree type, reshape_iter *d, tsubst_flags_t complain) NULL_TREE, complain); } +/* Subroutine of reshape_init*: We're initializing an element with TYPE from + INIT, in isolation from any designator or other initializers. */ + +static tree +reshape_single_init (tree type, tree init, tsubst_flags_t complain) +{ + /* We could also implement this by wrapping init in a new CONSTRUCTOR and + calling reshape_init, but this way can just live on the stack. */ + constructor_elt elt = { /*index=*/NULL_TREE, init }; + reshape_iter iter = { &elt, &elt + 1 }; + return reshape_init_r (type, &iter, + /*first_initializer_p=*/NULL_TREE, + complain); +} + /* Subroutine of reshape_init_r, processes the initializers for classes or union. Parameters are the same of reshape_init_r. */ @@ -6690,24 +6705,19 @@ reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p, if (direct_desig) { - /* The designated field F is initialized from this one element: - Temporarily clear the designator so a recursive reshape_init_class - doesn't try to find it again in F, and adjust d->end so we don't - try to use the next initializer to initialize another member of F. + /* The designated field F is initialized from this one element. - Note that we don't want these changes if we found the designator - inside an anon aggr above; we leave them alone to implement: + Note that we don't want to do this if we found the designator + inside an anon aggr above; we use the normal code to implement: "If the element is an anonymous union member and the initializer list is a brace-enclosed designated- initializer-list, the element is initialized by the designated-initializer-list { D }, where D is the designated- initializer-clause naming a member of the anonymous union member." */ - auto end_ = make_temp_override (d->end, d->cur + 1); - auto idx_ = make_temp_override (d->cur->index, NULL_TREE); - field_init = reshape_init_r (TREE_TYPE (field), d, - /*first_initializer_p=*/NULL_TREE, - complain); + field_init = reshape_single_init (TREE_TYPE (field), + d->cur->value, complain); + d->cur++; } else field_init = reshape_init_r (TREE_TYPE (field), d,
reply other threads:[~2022-03-23 19:37 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=20220323193721.E68CC3858C2C@sourceware.org \ --to=jason@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).