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

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <[email protected]>:

https://gcc.gnu.org/g:a96d7250389d05ab8f8a68c2c3cfad3c709a6cb4

commit r16-8483-ga96d7250389d05ab8f8a68c2c3cfad3c709a6cb4
Author: Jakub Jelinek <[email protected]>
Date:   Mon Apr 6 23:10:46 2026 +0200

    c++: Fix up handling of for-range-decls of expansion stmt [PR124488]

    The following testcase is rejected, because we don't set all the needed
    flags on range_decl in cp_parser_expansion_statement.  During parsing
    of the expansion stmt body, it should be treated as if there is a decl
    with value dependent initializer in a template, because the value it will
    have is yet to be determined (and possibly different in each instantiation
    of the body).
    For such decls, cp_finish_decl normally conservatively sets
    DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (because it might be initialized
    by constant expression) and for non-references also sets TREE_CONSTANT
    if decl_maybe_constant_var_p.  Furthermore, those have a value dependent
    initializer and DECL_DEPENDENT_INIT_P is set on those too.

    The following patch arranges all of that for the range_decl.

    2026-04-06  Jakub Jelinek  <[email protected]>

            PR c++/124488
            * parser.cc (cp_parser_expansion_statement): Set
            DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P, DECL_DEPENDENT_INIT_P
and
            if maybe constant non-reference TREE_CONSTANT on range_decl.
            * pt.cc (tsubst_stmt) <case TEMPLATE_FOR_STMT>: Set
            DECL_DEPENDENT_INIT_P on decl.

            * g++.dg/cpp26/expansion-stmt33.C: New test.

    Reviewed-by: Jason Merrill <[email protected]>

Reply via email to