]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: trivial lambda pruning [PR120716]
authorJason Merrill <jason@redhat.com>
Thu, 3 Jul 2025 20:52:56 +0000 (16:52 -0400)
committerJason Merrill <jason@redhat.com>
Thu, 3 Jul 2025 22:54:28 +0000 (18:54 -0400)
commit387cc9f80fcfd8b7d3fc142ef01bb05a46f0f244
tree8f0ea8783087aa3c1ec0f296a00b6f9de399fc97
parente9549b5ee8496af12bac3ebfa3ec0aa8487fb725
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.
gcc/cp/lambda.cc
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-constexpr3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-constexpr3a.C [new file with mode: 0644]