From: Jason Merrill <jason@redhat.com>
To: Marek Polacek <polacek@redhat.com>,
GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] c++: Fix ICE with ill-formed array list-initialization [PR93712]
Date: Fri, 14 Feb 2020 08:13:00 -0000 [thread overview]
Message-ID: <2143009f-35d4-456d-78ac-46e748a55538@redhat.com> (raw)
In-Reply-To: <20200213195600.495394-1-polacek@redhat.com>
On 2/13/20 8:56 PM, Marek Polacek wrote:
> My P0388R4 patch changed build_array_conv to create an identity
> conversion at the start of the conversion chain.
Hmm, an identity conversion of {} suggests that it has a type, which it
doesn't in the language. I'm not strongly against it, but what was the
reason for this change?
> That was a sound change but now we crash in convert_like_real
>
> 7457 case ck_identity:
> 7458 if (BRACE_ENCLOSED_INITIALIZER_P (expr))
> 7459 {
> 7460 int nelts = CONSTRUCTOR_NELTS (expr);
> 7461 if (nelts == 0)
> 7462 expr = build_value_init (totype, complain);
> 7463 else if (nelts == 1)
> 7464 expr = CONSTRUCTOR_ELT (expr, 0)->value;
> 7465 else
> 7466 gcc_unreachable (); // HERE
> 7467 }
Right, this is assuming that any other {} will either be ill-formed or
handled by ck_aggr or ck_list. How are we getting here without going
through one of those?
> in a test like this
>
> int f (int const (&)[2])
> {
> return f({1, " "});
> }
>
> I considered fixing this when performing overload resolution (clang says
> "no matching function for call to 'f'"), but then it occured to me that
> we crash in different contexts too, so I'm just turning the assert into
> an early return.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2020-02-13 Marek Polacek <polacek@redhat.com>
>
> PR c++/93712 - ICE with ill-formed array list-initialization.
> * call.c (convert_like_real): Turn an assert into a return.
>
> * g++.dg/cpp0x/initlist-array11.C: New test.
> ---
> gcc/cp/call.c | 2 +-
> gcc/testsuite/g++.dg/cpp0x/initlist-array11.C | 10 ++++++++++
> 2 files changed, 11 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-array11.C
>
> diff --git a/gcc/cp/call.c b/gcc/cp/call.c
> index 51621b7dd87..eba0ed8041d 100644
> --- a/gcc/cp/call.c
> +++ b/gcc/cp/call.c
> @@ -7463,7 +7463,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
> else if (nelts == 1)
> expr = CONSTRUCTOR_ELT (expr, 0)->value;
> else
> - gcc_unreachable ();
> + return error_mark_node;
> }
> expr = mark_use (expr, /*rvalue_p=*/!convs->rvaluedness_matches_p,
> /*read_p=*/true, UNKNOWN_LOCATION,
> diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-array11.C b/gcc/testsuite/g++.dg/cpp0x/initlist-array11.C
> new file mode 100644
> index 00000000000..7e76b588471
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-array11.C
> @@ -0,0 +1,10 @@
> +// PR c++/93712 - ICE with ill-formed array list-initialization.
> +// { dg-do compile { target c++11 } }
> +
> +int f (const int (&)[2]);
> +
> +int g ()
> +{
> + const int (&r)[2] = {1, "foo"}; // { dg-error "invalid conversion" }
> + return f({1, "foo"}); // { dg-error "invalid conversion" }
> +}
>
> base-commit: 1d69147af203d4dcd2270429f90c93f1a37ddfff
>
next prev parent reply other threads:[~2020-02-14 8:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-13 19:56 Marek Polacek
2020-02-14 8:13 ` Jason Merrill [this message]
2020-02-19 18:30 ` Marek Polacek
2020-02-20 0:28 ` Jason Merrill
2020-02-21 23:49 ` [PATCH v2] " Marek Polacek
2020-02-24 14:54 ` 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=2143009f-35d4-456d-78ac-46e748a55538@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--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).