https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94376
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Patrick Palka <ppa...@gcc.gnu.org>: https://gcc.gnu.org/g:89cf57ea35d1e0a0b818997c737ac70b7310d9d9 commit r12-6065-g89cf57ea35d1e0a0b818997c737ac70b7310d9d9 Author: Patrick Palka <ppa...@redhat.com> Date: Sun Dec 19 14:42:14 2021 -0500 c++: nested lambda capturing a capture proxy, cont [PR94376] The r12-5403 fix apparently doesn't handle the case where the inner lambda explicitly rather than implicitly captures the capture proxy from the outer lambda, which causes us to reject the first example in the testcase below. This is because compared to an implicit capture, the effective initializer for an explicit capture is wrapped in a location wrapper (pointing to within the capture list), and this wrapper foils the is_capture_proxy check added in r12-5403. The simplest fix appears to be to strip location wrappers accordingly before checking is_capture_proxy. And to help prevent against this kind of bug, this patch also makes is_capture_proxy assert it doesn't see a location wrapper. PR c++/94376 gcc/cp/ChangeLog: * lambda.c (lambda_capture_field_type): Strip location wrappers before checking for a capture proxy. (is_capture_proxy): Assert that we don't see a location wrapper. (mark_const_cap_r): Don't call is_constant_capture_proxy on a location wrapper. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/lambda/lambda-nested9a.C: New test.