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

--- Comment #11 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <[email protected]>:

https://gcc.gnu.org/g:5d4c555d8b716d0899530281fd1d9b31df74d9f4

commit r17-6180-g5d4c555d8b716d0899530281fd1d9b31df74d9f4
Author: Jason Merrill <[email protected]>
Date:   Wed Nov 11 10:25:25 2026 -0500

    c++/contracts: rework constexpr handling

    Playing with using contract_assert for libstdc++ asserts led me to rework
    how they are handled in constant evaluation.

    The main change is that instead of always diagnosing under
    cxx_eval_outermost_constant_expr, we diagnose during evaluation if we're
    diagnosing.  This means that the diagnostics now get the cx_call_context,
    and (if terminating) we stop evaluating at that point.

    If not diagnosing, but we saw a violation in an otherwise-constant
    evaluation, we evaluate again to get the diagnostic in its call context.
    And to diagnose multiple observes.

    This approach also fixes non-const1.C, where we were wrongly complaining
    that the predicate is non-constant; since the whole initialization is
    non-constant, under [expr.const.init]/4.1 we shouldn't consider assertions
    yet.

    This also properly gets a diagnostic that an assertion fails in an
    initialization that is otherwise constant (p17-SMF*).

    Also for better context, I changed check_for_failed_contracts to
    1) use the location of the predicate, not the keyword.
    2) use cxx_constant_value or diagnose_failing_condition to explain
    what went wrong.

    This also works around an issue with maybe_unwind_expanded_macro_loc firing
    repeatedly in a single diagnostic group--which would be good to fix in
    general, but that's not this patch.

            PR c++/119497

    gcc/cp/ChangeLog:

            * constexpr.cc (check_for_failed_contracts): Add context.
            (cxx_eval_constant_expression): Refactor contract handling.
            Diagnose now if diagnosing.
            (cxx_eval_outermost_constant_expr): Re-evaluate to diagnose
            contract violations if otherwise constant.

    gcc/testsuite/ChangeLog:

            * g++.dg/contracts/cpp26/basic.contract.eval.p17-SMF-post.C
            * g++.dg/contracts/cpp26/basic.contract.eval.p17-SMF-pre.C
            * g++.dg/contracts/cpp26/basic.contract.eval.p17-SMF2.C
            * g++.dg/contracts/cpp26/basic.contract.eval.p7.3.C
            * g++.dg/contracts/cpp26/callerside-checks/ctor.C: Add diagnostic.
            * g++.dg/contracts/cpp26/non-const1.C: New test.

Reply via email to