This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] avoid user-constructible types in reshape_init_array (PR 90938)
On Wed, Feb 12, 2020 at 01:21:58PM -0700, Martin Sebor wrote:
> On 2/11/20 5:28 PM, Jason Merrill wrote:
> > On 2/11/20 9:00 PM, 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,
> >
> > Hmm, a type with only a deleted default constructor is not trivial, that
> > should have been OK already.
>
> For Marek's test case:
> struct A { A () == delete; A (int) = delete; };
>
> trivial_type_p() returns true (as does __is_trivial (A) in both GCC
> and Clang).
>
> [class.prop] says that
>
> A trivial class is a class that is trivially copyable and has one
> or more default constructors (10.3.4.1), all of which are either
> trivial or deleted and at least one of which is not deleted.
>
> That sounds like A above is not trivial because it doesn't have
> at least one default ctor that's not deleted, but both GCC and
> Clang say it is. What am I missing? Is there some other default
> constructor hiding in there that I don't know about?
Note that [class.prop]/2 now says something other than that:
"A trivial class is a class that is trivially copyable and has one or
more eligible default constructors ([class.default.ctor]), all of which
are trivial."
I think this changed in P0848R3 (Conditionally Trivial Special Member
Functions).
Here A has a default constructor, but it's not eligible: [special]/6 says
"An eligible special member function is a special member function for which:
-- the function is not deleted,
[...]"
So it seems that A should not be trivial. But the wording you quoted
also means that: it was changed in
CWG1496 Triviality with deleted and missing default constructors
but we don't implement that (https://gcc.gnu.org/PR85723).
So going further down memory lane, [class.prop] used to say
"A trivial class is a class that has a default constructor (12.1), has no
non-trivial default constructors, and is trivially copyable."
which A is (because it has an implicit copy ctor).
So I think it all comes down to the fact that neither g++ not clang++
implement CWG 1496. And that's probably GCC 11 work.
Marek