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

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

https://gcc.gnu.org/g:6bfec5d7b8b87f505d974da8e24240af11b9914e

commit r16-7213-g6bfec5d7b8b87f505d974da8e24240af11b9914e
Author: Nathaniel Shead <[email protected]>
Date:   Sat Jan 24 19:34:53 2026 +1100

    c++: Fix cp_fold_non_odr_use_1 [PR123557,PR123738]

    This fixes two issues with cp_fold_non_odr_use_1:

    - When called to fold away a reference, it considers the use to not be
      an lvalue and so 'maybe_constant_value' folds all the way through the
      nested INDIRECT_REF to a prvalue.  Fixed by folding the op0 of the
      INDIRECT_REF rather than the ref itself and avoiding a double
      cp_fold_non_odr_use_1.

    - When used to fold away the initializing expression for an INIT_EXPR,
      it doesn't mark any new TARGET_EXPRs as eliding.  Fixed by reapplying
      'set_target_expr_eliding' for the initializer of an INIT_EXPR if it
      got modified during ff_only_non_odr walk.

            PR c++/123557
            PR c++/123738

    gcc/cp/ChangeLog:

            * cp-gimplify.cc (cp_fold_maybe_rvalue): Call
            cp_fold_non_odr_use_1 before recursing cp_fold.
            (cp_fold): Pass op0 to cp_fold_non_odr_use_1 when folding a
            reference.  Reapply set_target_expr_eliding on the initializing
            expression of an INIT_EXPR.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/constexpr-ice22.C: New test.
            * g++.dg/cpp2a/constexpr-ref2.C: New test.

    Signed-off-by: Nathaniel Shead <[email protected]>
    Reviewed-by: Jason Merrill <[email protected]>

Reply via email to