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

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <ja...@gcc.gnu.org>:

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

commit r16-1991-ge9549b5ee8496af12bac3ebfa3ec0aa8487fb725
Author: Jason Merrill <ja...@redhat.com>
Date:   Thu Jul 3 12:05:12 2025 -0400

    c++: ICE with 'this' in lambda signature [PR120748]

    This testcase was crashing from infinite recursion in the diagnostic
    machinery, trying to print the lambda signature, which referred to the
    __this capture field in the lambda, which wanted to print the lambda again.

    But we don't want the signature to refer to the capture field; 'this' in an
    unevaluated context refers to the 'this' from the enclosing function, not
    the capture.

    After fixing that, we still wrongly rejected the B case because
    THIS_FORBIDDEN is set in a default (template) argument.  Since we don't
    distinguish between THIS_FORBIDDEN being set for a default argument and it
    being set for a static member function, let's just ignore it if
    cp_unevaluated_operand; we'll give a better diagnostic for the static memfn
    case in finish_this_expr.

            PR c++/120748

    gcc/cp/ChangeLog:

            * lambda.cc (lambda_expr_this_capture): Don't return a FIELD_DECL.
            * parser.cc (cp_parser_primary_expression): Ignore THIS_FORBIDDEN
            if cp_unevaluated_operand.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/lambda-targ16.C: New test.
            * g++.dg/cpp0x/this1.C: Adjust diagnostics.

Reply via email to