On Tue, May 24, 2022 at 04:01:37PM -0400, Jason Merrill wrote:
> On 5/24/22 09:55, Marek Polacek wrote:
> > On Tue, May 24, 2022 at 08:36:39AM -0400, Jason Merrill wrote:
> > > On 5/16/22 11:36, Marek Polacek wrote:
> > > > +static tree
> > > > +replace_placeholders_for_class_temp_r (tree *tp, int *, void *data)
> > > > +{
> > > > + tree t = *tp;
> > > > + tree full_expr = *static_cast<tree *>(data);
> > > > +
> > > > + /* We're looking for a TARGET_EXPR nested in the whole expression.
> > > > */
> > > > + if (TREE_CODE (t) == TARGET_EXPR
> > > > + && !potential_prvalue_result_of (t, full_expr))
> > > > + {
> > > > + tree init = TARGET_EXPR_INITIAL (t);
> > > > + while (TREE_CODE (init) == COMPOUND_EXPR)
> > > > + init = TREE_OPERAND (init, 1);
> > >
> > > Hmm, how do we get a COMPOUND_EXPR around a CONSTRUCTOR?
> >
> > Sadly, that's possible for code like (from nsdmi-aggr18.C)
> >
> > struct D {
> > int x = 42;
> > B b = (true, A{x});
> > };
> >
> > where the TARGET_EXPR_INITIAL is
> > <<< Unknown tree: void_cst >>>, {.x=((struct D *) this)->x,
> > .y=(&<PLACEHOLDER_EXPR struct A>)->x}
>
> Hmm, perhaps cp_build_compound_expr should build an additional TARGET_EXPR
> around the COMPOUND_EXPR but leave the one inside alone. Feel free to
> investigate that if you'd like, or the patch is OK as is.
Sorry, I was unclear. The whole expression is:
TARGET_EXPR <D.2439, A::operator B (&TARGET_EXPR <D.2405, <<< Unknown tree:
void_cst >>>, {.x=((struct D *) this)->x, .y=(&<PLACEHOLDER_EXPR struct
A>)->x}>)>
so there *is* a TARGET_EXPR around the COMPOUND_EXPR. We'd have to build
a TARGET_EXPR around the COMPOUND_EXPR's RHS = the CONSTRUCTOR. Frankly,
I'm not sure if it's worth the effort. The while loop is somewhat unsightly
but not too bad.
Marek