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

--- Comment #4 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:020ad96f2e18d483e577343b25f0d3a782065c7e

commit r16-6206-g020ad96f2e18d483e577343b25f0d3a782065c7e
Author: Nathaniel Shead <[email protected]>
Date:   Sun Dec 14 09:32:50 2025 +1100

    c++: Don't record lambdas in concept evaluations [PR123075]

    When evaluating a concept definition in a template, any lambdas in the
    definition of the concept get instantiated in the context of where the
    evaluation occurred.

    This causes two issues:

    - Any lambdas declared later in the body of the function get the wrong
      discriminator, which causes ABI divergences with Clang.

    - Modules streaming gets confused, because the lambda is keyed to an
      unrelated declaration.  Keying the lambda to the concept also doesn't
      work because we'd really want to key it to a concept instantiation
      (that doesn't exist) so that merging works correctly.

    I think really we just want to throw away these lambdas declarations
    after evaluating the concept.  They can (and will) be recreated in
    importers re-evaluating the concept with the given args regardless.

    This patch implements this by disabling scope recording for an
    instantiation of a lambda keyed to a concept, and pushing into an
    unrelated context so that the lambda's type is not mistakenly added
    into the scope it was instantiated from.

            PR c++/123075

    gcc/cp/ChangeLog:

            * constraint.cc (evaluate_concept_check): Push to an unrelated
            scope, but keep the same access context.
            * pt.cc (tsubst_lambda_expr): Don't record lambda scopes for
            lambdas attached to a concept.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/concepts-lambda25.C: New test.
            * g++.dg/modules/lambda-13.h: New test.
            * g++.dg/modules/lambda-13_a.H: New test.
            * g++.dg/modules/lambda-13_b.C: New test.

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

Reply via email to