https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120716
--- Comment #4 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:387cc9f80fcfd8b7d3fc142ef01bb05a46f0f244 commit r16-1992-g387cc9f80fcfd8b7d3fc142ef01bb05a46f0f244 Author: Jason Merrill <ja...@redhat.com> Date: Thu Jul 3 16:52:56 2025 -0400 c++: trivial lambda pruning [PR120716] In this testcase there is nothing in the lambda except a static_assert which mentions a variable from the enclosing scope but does not odr-use it, so we want prune_lambda_captures to remove its capture. Since the lambda is so empty, there's nothing in the body except the DECL_EXPR of the capture proxy, so pop_stmt_list moves that into the enclosing STATEMENT_LIST and passes the 'body' STATEMENT_LIST to free_stmt_list. As a result, passing 'body' to prune_lambda_captures is wrong; we should instead pass the enclosing scope, i.e. cur_stmt_list. PR c++/120716 gcc/cp/ChangeLog: * lambda.cc (finish_lambda_function): Pass cur_stmt_list to prune_lambda_captures. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/lambda/lambda-constexpr3.C: New test. * g++.dg/cpp0x/lambda/lambda-constexpr3a.C: New test.