]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: ICE with 'this' in lambda signature [PR120748]
authorJason Merrill <jason@redhat.com>
Thu, 3 Jul 2025 16:05:12 +0000 (12:05 -0400)
committerJason Merrill <jason@redhat.com>
Thu, 3 Jul 2025 22:54:01 +0000 (18:54 -0400)
commite9549b5ee8496af12bac3ebfa3ec0aa8487fb725
tree3c977728f8ec01263632b7b09f464999e82ca79c
parentdc90649466a54ab61926d88500a05f59a55cb055
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.
gcc/cp/lambda.cc
gcc/cp/parser.cc
gcc/testsuite/g++.dg/cpp0x/this1.C
gcc/testsuite/g++.dg/cpp2a/lambda-targ16.C [new file with mode: 0644]