c++: nested lambda capturing a capture proxy [PR94376]
authorPatrick Palka <ppalka@redhat.com>
Fri, 19 Nov 2021 13:54:25 +0000 (08:54 -0500)
committerPatrick Palka <ppalka@redhat.com>
Fri, 19 Nov 2021 13:54:25 +0000 (08:54 -0500)
commitfd740165e54151ea794fca34904f5c2e2ea1dcda
treec0481c3654f63b5d76040b0ac7fe6214a18d8923
parentf316727e5f6a4c58b63bdee9ad6be785f97f5ee7
c++: nested lambda capturing a capture proxy [PR94376]

Here when determining the type of the FIELD_DECL for the by-value capture
of 'i' in the inner lambda, we incorrectly give it the type const int
instead of int since the effective initializer is the proxy for the outer
capture, and this proxy is const since the outer lambda is non-mutable.

This patch fixes this by making lambda_capture_field_type handle
by-value capturing of capture proxies specially, namely we instead
consider the type of their FIELD_DECL which unlike the proxy has the
true cv-quals of the captured entity.

PR c++/94376

gcc/cp/ChangeLog:

* lambda.c (lambda_capture_field_type): Simplify by handling the
is_this case first.  When capturing by-value a capture proxy,
consider the type of the corresponding field instead.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/lambda/lambda-nested9.C: New test.
gcc/cp/lambda.c
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nested9.C [new file with mode: 0644]