[PATCH] c++: designated init of char array by string constant [PR55227]

Marek Polacek polacek@redhat.com
Thu Nov 18 15:36:02 GMT 2021


On Wed, Nov 17, 2021 at 10:23:58PM -0500, will wray wrote:
> V2 Patch
> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51828

Can you please post the v2 here on the mailing list?  It will be easier
for us to reply.  Preferably with the subject adjusted to say [PATCH v2] ...
 
> On Wed, Nov 17, 2021 at 10:06 PM will wray <wjwray@gmail.com> wrote:
> >
> > Thanks for the review Marek;
> > I'll post the updated patch in a follow-on message and on bugzilla.
> >
> > On Mon, Nov 15, 2021 at 8:03 PM Marek Polacek <polacek@redhat.com> wrote:
> >
> > > I also noticed the C++ FE rejects
> > >
> > >   struct A { char x[4]; };
> > >   struct B { struct A a; };
> > >   struct B b = { .a.x = "abc" };
> > > but the C FE accepts it.  But that's for another time.
> >
> > Yes, the nested case is invalid for C++, valid for C.
> > c.f. cppreference aggregate init.
> >
> > > > +      reshape_iter stripd = {};
> > >
> > > Since the previous variables spell it "stripped" maybe call it stripped_iter.
> >
> > I've left it as "stripd"; the top level reshape_iter is just "d", non-verbose,
> > so "stripped_d" inappropriately over-verbose.
> >
> > > > @@ -6836,7 +6838,8 @@ reshape_init_r (tree type, reshape_iter *d, tree first_initializer_p,
> > > >        array types (one value per array element).  */
> > > >        if (TREE_CODE (stripped_str_init) == STRING_CST)
> > > >       {
> > > > -       if (has_designator_problem (d, complain))
> > >
> > > So the logic here is that...
> >
> > Yes, you get the logic exactly... took me a few rounds to get it.
> >
> > > Nice to finally remove this, but let's keep this part of the comment.
> >
> > Agreed, and reinstated.
> >
> > > BRACE_ENCLOSED_INITIALIZER_P checks that it gets a CONSTRUCTOR so you
> > > can remove the first check.
> >
> > Nice, thanks; missed that.
> >
> > > > +// { dg-do compile }
> > > > +// { dg-options "-pedantic" }
> > >
> > > FWIW, if you remove the dg-options, -pedantic-errors will be used so you could
> > > drop it and then use dg-error instead of dg-warning below but this is OK too.
> >
> > I'd copied that from another desigN.C test, now I've copied the simpler:
> >
> > +// { dg-options "" }
> >
> > and removed all of the noisy dg-warning tests
> >
> > > We should probably test more:
> > > - nested structs
> > > - anonymous unions
> > > - test when the initializer is too long
> > > - multidim arrays:
> >
> > Cut-n-paste'd your multidim array test, and added a couple more
> >
> > > Hope this is useful...
> >
> > Very useful, thanks again
> 

Marek



More information about the Gcc-patches mailing list