On Sun, Jan 22, 2023 at 03:40:26PM -0500, Jason Merrill wrote: > > 2023-01-21 Jakub Jelinek <ja...@redhat.com> > > > > PR c++/108474 > > * cp-gimplify.cc (cp_fold_r): Handle structured bindings > > vars like anon union artificial vars. > > > > * g++.dg/cpp1z/decomp57.C: New test. > > * g++.dg/cpp1z/decomp58.C: New test. > > > > --- gcc/cp/cp-gimplify.cc.jj 2023-01-19 23:27:27.998400866 +0100 > > +++ gcc/cp/cp-gimplify.cc 2023-01-20 11:00:06.093446737 +0100 > > @@ -1012,8 +1012,12 @@ cp_fold_r (tree *stmt_p, int *walk_subtr > > case VAR_DECL: > > /* In initializers replace anon union artificial VAR_DECLs > > - with their DECL_VALUE_EXPRs, as nothing will do it later. */ > > - if (DECL_ANON_UNION_VAR_P (stmt) && !data->genericize) > > + with their DECL_VALUE_EXPRs, as nothing will do it later. > > + Ditto for structured bindings. */ > > + if (!data->genericize > > + && DECL_HAS_VALUE_EXPR_P (stmt) > > + && (DECL_ANON_UNION_VAR_P (stmt) > > + || (DECL_DECOMPOSITION_P (stmt) && DECL_DECOMP_BASE (stmt)))) > > Is there a reason not to do this for all cases of DECL_HAS_VALUE_EXPR_P, > without the extra checks?
I was just trying to be careful, because unfortunately this spot doesn't mean it really is only expanded in static var DECL_INITIAL, it can make it into dynamic initializers, and most of DECL_VALUE_EXPRs appear only in runtime code, otherwise we'd have much more of these issues. But if you think it is ok, I'll test tonight a version just with if (!data->genericize && DECL_HAS_VALUE_EXPR_P (stmt) Jakub