https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114292
--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-14 branch has been updated by Simon Martin <simar...@gcc.gnu.org>: https://gcc.gnu.org/g:f86d274ab76fdd89d7afd9b2eab28f3a61749cfb commit r14-11426-gf86d274ab76fdd89d7afd9b2eab28f3a61749cfb Author: Simon Martin <si...@nasilyan.com> Date: Thu Mar 20 20:36:26 2025 +0100 c++: Don't prune constant capture proxies only used in array dimensions [PR114292] We currently ICE upon the following valid (under -Wno-vla) code === cut here === void f(int c) { constexpr int r = 4; [&](auto) { int t[r * c]; }(0); } === cut here === When parsing the lambda body, and more specifically the multiplication, we mark the lambda as LAMBDA_EXPR_CAPTURE_OPTIMIZED, which indicates to prune_lambda_captures that it might be possible to optimize out some captures. The problem is that prune_lambda_captures then misses the use of the r capture (because neither walk_tree_1 nor cp_walk_subtrees walks the dimensions of array types - here "r * c"), hence believes the capture can be pruned... and we trip on an assert when instantiating the lambda. This patch changes cp_walk_subtrees so that (1) when walking a DECL_EXPR, it also walks the DECL's type, and (2) when walking an INTEGER_TYPE and processing a template declaration, it also walks its TYPE_{MIN,MAX}_VALUE. PR c++/114292 gcc/cp/ChangeLog: * tree.cc (cp_walk_subtrees): Walk the type of DECL_EXPR declarations, as well as the TYPE_{MIN,MAX}_VALUE of INTEGER_TYPEs for template declarations. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/lambda-ice4.C: New test.