From: Patrick Palka <ppalka@redhat.com>
To: Marek Polacek <polacek@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
Jason Merrill <jason@redhat.com>,
Patrick Palka <ppalka@redhat.com>
Subject: Re: [PATCH] c++: fix ICE with designated initializer [PR110114]
Date: Wed, 19 Jul 2023 14:32:15 -0400 (EDT) [thread overview]
Message-ID: <3efd2e0c-1c18-de91-4708-dfd1892ecb11@idea> (raw)
In-Reply-To: <20230719180053.46101-1-polacek@redhat.com>
On Wed, 19 Jul 2023, Marek Polacek wrote:
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
LGTM. It might be preferable to check COMPLETE_TYPE_P in the caller
instead, so that we avoid inspecting CLASSTYPE_NON_AGGREGATE on an
incomplete class type, and so that the caller doesn't "commit" to
building an aggregate conversion.
>
> -- >8 --
>
> r13-1227 added an assert checking that the index in a CONSTRUCTOR
> is a FIELD_DECL. That's a reasonable assumption but in this case
> we never called reshape_init due to the type being incomplete, and
> so the index remained an identifier node: get_class_binding never
> got around to looking up the FIELD_DECL.
>
> We can avoid the crash by returning early in build_aggr_conv; we'd
> return NULL anyway due to:
>
> if (i < CONSTRUCTOR_NELTS (ctor))
> return NULL;
>
> PR c++/110114
>
> gcc/cp/ChangeLog:
>
> * call.cc (build_aggr_conv): Return early if the type isn't
> complete.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/cpp2a/desig28.C: New test.
> * g++.dg/cpp2a/desig29.C: New test.
> ---
> gcc/cp/call.cc | 5 +++++
> gcc/testsuite/g++.dg/cpp2a/desig28.C | 17 +++++++++++++++++
> gcc/testsuite/g++.dg/cpp2a/desig29.C | 10 ++++++++++
> 3 files changed, 32 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/cpp2a/desig28.C
> create mode 100644 gcc/testsuite/g++.dg/cpp2a/desig29.C
>
> diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
> index b55230d98aa..0af20a81717 100644
> --- a/gcc/cp/call.cc
> +++ b/gcc/cp/call.cc
> @@ -986,6 +986,11 @@ build_aggr_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
> tree empty_ctor = NULL_TREE;
> hash_set<tree, true> pset;
>
> + /* We've called complete_type on TYPE before calling this function, but
> + perhaps it wasn't successful. */
> + if (!COMPLETE_TYPE_P (type))
> + return nullptr;
> +
> /* We already called reshape_init in implicit_conversion, but it might not
> have done anything in the case of parenthesized aggr init. */
>
> diff --git a/gcc/testsuite/g++.dg/cpp2a/desig28.C b/gcc/testsuite/g++.dg/cpp2a/desig28.C
> new file mode 100644
> index 00000000000..b63265fea51
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/desig28.C
> @@ -0,0 +1,17 @@
> +// PR c++/110114
> +// { dg-do compile { target c++20 } }
> +
> +struct A {
> + int a,b;
> +};
> +
> +struct B;
> +
> +void foo(const A &) {}
> +void foo(const B &) {}
> +
> +int
> +main ()
> +{
> + foo({.a=0});
> +}
> diff --git a/gcc/testsuite/g++.dg/cpp2a/desig29.C b/gcc/testsuite/g++.dg/cpp2a/desig29.C
> new file mode 100644
> index 00000000000..bd1a82b041d
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/desig29.C
> @@ -0,0 +1,10 @@
> +// PR c++/110114
> +// { dg-do compile { target c++20 } }
> +
> +struct B;
> +
> +void foo(const B &) {}
> +
> +int main() {
> + foo({.a=0}); // { dg-error "invalid" }
> +}
>
> base-commit: 2971ff7b1d564ac04b537d907c70e6093af70832
> --
> 2.41.0
>
>
next prev parent reply other threads:[~2023-07-19 18:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-19 18:00 Marek Polacek
2023-07-19 18:32 ` Patrick Palka [this message]
2023-07-19 18:38 ` Marek Polacek
2023-07-19 19:24 ` Jason Merrill
2023-07-20 14:08 ` [PATCH v2] " Marek Polacek
2023-07-20 14:29 ` Jason Merrill
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=3efd2e0c-1c18-de91-4708-dfd1892ecb11@idea \
--to=ppalka@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=polacek@redhat.com \
/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: link
Be 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).