https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124488

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2026-03-19

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The reason why this works in e.g.
template <int N>
void
foo ()
{
  constexpr int a = N;
  auto c = [] () { return a; };
}
void
bar ()
{
  foo <42> ();
}
is that cp_finish_decl in that case has:
9672          if (init_const_expr_p)
9673            {
9674              /* Set these flags now for templates.  We'll update the flags
in
9675                 store_init_value for instantiations.  */
9676              DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
9677              if (decl_maybe_constant_var_p (decl)
9678                  /* FIXME setting TREE_CONSTANT on refs breaks the back
end.  */
9679                  && !TYPE_REF_P (type))
9680                TREE_CONSTANT (decl) = true;
9681            }
For the range declaration in expansion statement, we don't currently set that
while parsing the body of the expansion statement.  DECL_INITIAL is NULL_TREE
at that point too.  So, will need to figure out tomorrow if it is enough to
just set those two flags during parsing or if we need to temporarily set
DECL_INITIAL to something magic which will be treated as value dependent.

Reply via email to