From: Marek Polacek <polacek@redhat.com>
To: Martin Sebor <msebor@gmail.com>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>, Jason Merrill <jason@redhat.com>
Subject: Re: [PATCH] avoid user-constructible types in reshape_init_array (PR 90938)
Date: Wed, 12 Feb 2020 00:01:00 -0000 [thread overview]
Message-ID: <20200212000146.GN18589@redhat.com> (raw)
In-Reply-To: <be3471da-e0b4-fee6-a74d-a69aff7dc7a8@gmail.com>
On Tue, Feb 11, 2020 at 01:00:05PM -0700, Martin Sebor wrote:
> r270155, committed in GCC 9, introduced a transformation that strips
> redundant trailing zero initializers from array initializer lists in
> order to support string literals as template arguments.
>
> The transformation neglected to consider the case of array elements
> of trivial class types with user-defined conversion ctors and either
> defaulted or deleted default ctors. (It didn't occur to me that
> those qualify as trivial types despite the user-defined ctors.) As
> a result, some valid initialization expressions are rejected when
> the explicit zero-initializers are dropped in favor of the (deleted)
> default ctor, and others are eliminated in favor of the defaulted
> ctor instead of invoking a user-defined conversion ctor, leading to
> wrong code.
>
> The attached patch fixes that but avoiding this transformation for
> such types.
>
> Tested on x86_64-linux. I'd like to commit the patch to both trunk
> and to GCC 9 (with testsuite adjustments if necessary).
>
> Martin
> PR c++/90938 - Initializing array with {1} works but not {0}
>
> gcc/cp/ChangeLog:
>
> PR c++/90938
> * decl.c (reshape_init_array_1): Avoid types with non-trivial
> user-defined ctors.
>
> gcc/testsuite/ChangeLog:
>
> PR c++/90938
> * g++.dg/init/array55.C: New test.
> * g++.dg/init/array56.C: New test.
>
> diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
> index 31a556a0a1f..60731cb3f9d 100644
> --- a/gcc/cp/decl.c
> +++ b/gcc/cp/decl.c
> @@ -6051,11 +6051,14 @@ reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d,
> break;
> }
>
> - if (sized_array_p && trivial_type_p (elt_type))
> + if (sized_array_p
> + && trivial_type_p (elt_type)
> + && !TYPE_NEEDS_CONSTRUCTING (elt_type))
Looks like this will still do the wrong thing for
struct X
{
X () = delete;
X (int) = delete;
};
X x1[1] { 0 }; // use of deleted function
which should be rejected since we use a deleted function, but
TYPE_NEEDS_CONSTRUCTING will be 0 fox X, so we'd do the truncation
and the initialization would succeed.
Marek
next prev parent reply other threads:[~2020-02-12 0:01 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-11 20:00 Martin Sebor
2020-02-12 0:01 ` Marek Polacek [this message]
2020-02-12 0:38 ` Martin Sebor
2020-02-12 0:29 ` Jason Merrill
2020-02-12 20:22 ` Martin Sebor
2020-02-12 21:57 ` Marek Polacek
2020-02-13 22:59 ` Jason Merrill
2020-02-14 20:06 ` Martin Sebor
2020-02-17 17:54 ` Jason Merrill
2020-02-22 0:42 ` Martin Sebor
2020-02-24 22:04 ` Jason Merrill
2020-03-04 17:41 ` Jason Merrill
2020-03-04 21:16 ` Martin Sebor
2020-03-04 22:24 ` 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=20200212000146.GN18589@redhat.com \
--to=polacek@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=msebor@gmail.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).