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

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-15 branch has been updated by Patrick Palka
<[email protected]>:

https://gcc.gnu.org/g:1a4b58635ab1df834a4d0deb2dfcd4fae311b475

commit r15-10735-g1a4b58635ab1df834a4d0deb2dfcd4fae311b475
Author: Patrick Palka <[email protected]>
Date:   Mon Jan 26 21:59:48 2026 -0500

    c++: leaky uid-sensitive constexpr evaluation [PR122494, PR123814]

    In the PR122494 testcase we constant evaluate 'B<int>::v == 0' first
    during warning-dependent folding, which is restricted to avoid unnecessary
    template instantiation.  During this restricted evaluation we do
    decl_constant_value on v which in turn manifestly constant evaluates v's
    initializer.  But this nested evaluation is incorrectly still restricted
    since the restriction mechanism is controlled by a global flag.  This
    causes constraint checking for A<int> to spuriously fail.

    We could narrowly fix this by guarding the decl_constant_value code path
    with uid_sensitive_constexpr_evaluation_p but that would overly
    pessimize warning-dependent folding of constexpr variables with simple
    initializers.  The problem is ultimately that the restriction mechanism
    is misdesigned, and it shouldn't be a global toggle, instead it should
    be local to the constexpr evaluation context and propagated accordingly.

    The PR123814 testcase is similar except that the nested manifestly
    constant evaluation happens through __fold_builtin_source_location
    (which performs arbitrary tsubst).

    Until we remove or reimplement the mechanism, this patch disables the
    mechanism during nested manifestly constant evaluation.  We don't ever
    want such evaluation to be restricted since it has semantic consequences.

            PR c++/122494
            PR c++/123814

    gcc/cp/ChangeLog:

            * constexpr.cc (cxx_eval_outermost_constant_expr): Clear
            uid_sensitive_constexpr_evaluation_value when mce_true.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/concepts-pr122494.C: New test.
            * g++.dg/cpp2a/concepts-pr123814.C: New test.

    Reviewed-by: Jason Merrill <[email protected]>
    (cherry picked from commit 9cb5c879e722bb63d5ff5621cd77f402cb94a316)

Reply via email to