https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114292
--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Simon Martin <simar...@gcc.gnu.org>: https://gcc.gnu.org/g:ceabea405ffdc851736e240111be9b297ad86c53 commit r15-7238-gceabea405ffdc851736e240111be9b297ad86c53 Author: Simon Martin <si...@nasilyan.com> Date: Wed Jan 22 16:19:47 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, it also walks its TYPE_{MIN,MAX}_VALUE. Note that #2 makes a <case INTEGER_TYPE> redundant in for_each_template_parm_r, and removes it. PR c++/114292 gcc/cp/ChangeLog: * pt.cc (for_each_template_parm_r) <INTEGER_TYPE>: Remove case now handled by cp_walk_subtrees. * tree.cc (cp_walk_subtrees): Walk the type of DECL_EXPR declarations, as well as the TYPE_{MIN,MAX}_VALUE of INTEGER_TYPEs. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/lambda-ice4.C: New test.