On Wed, Jan 31, 2018 at 11:21 AM, Jakub Jelinek <ja...@redhat.com> wrote: > On Wed, Jan 31, 2018 at 11:05:17AM -0500, Jason Merrill wrote: >> > 2018-01-24 Jakub Jelinek <ja...@redhat.com> >> > >> > PR c++/83993 >> > * constexpr.c (cxx_eval_outermost_constant_expr): Don't clear >> > TREE_CONSTANT on ADDR_EXPRs. >> > >> > * g++.dg/init/pr83993-2.C: New test. >> > >> > --- gcc/cp/constexpr.c.jj 2018-01-24 13:38:40.572913190 +0100 >> > +++ gcc/cp/constexpr.c 2018-01-24 17:03:16.821440047 +0100 >> > @@ -4832,7 +4832,7 @@ cxx_eval_outermost_constant_expr (tree t >> > >> > if (non_constant_p && !allow_non_constant) >> > return error_mark_node; >> > - else if (non_constant_p && TREE_CONSTANT (r)) >> > + else if (non_constant_p && TREE_CONSTANT (r) && TREE_CODE (r) != >> > ADDR_EXPR) >> > { >> > /* This isn't actually constant, so unset TREE_CONSTANT. */ >> > if (EXPR_P (r)) >> >> Hmm, what if we check for ADDR_EXPR in the EXPR_P test, so we build a >> non-TREE_CONSTANT NOP_EXPR around the ADDR_EXPR instead? > > That looks like a good idea and works on the testcase in question, > ok for trunk if it passes bootstrap/regtest? > > 2018-01-31 Jason Merrill <ja...@redhat.com> > Jakub Jelinek <ja...@redhat.com> > > PR c++/83993 > * constexpr.c (cxx_eval_outermost_constant_expr): Build NOP_EXPR > around non-constant ADDR_EXPRs rather than clearing TREE_CONSTANT > on ADDR_EXPR. > > * g++.dg/init/pr83993-2.C: New test. > > --- gcc/cp/constexpr.c.jj 2018-01-30 12:30:24.279362188 +0100 > +++ gcc/cp/constexpr.c 2018-01-31 17:18:03.316302653 +0100 > @@ -4824,7 +4824,7 @@ cxx_eval_outermost_constant_expr (tree t > else if (non_constant_p && TREE_CONSTANT (r)) > { > /* This isn't actually constant, so unset TREE_CONSTANT. */ > - if (EXPR_P (r)) > + if (EXPR_P (r) && TREE_CODE (r) != ADDR_EXPR)
OK with an added comment about the middle end needing TREE_CONSTANT to stay set on ADDR_EXPR. Jason