https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123611
--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <[email protected]>: https://gcc.gnu.org/g:75930efa22fb722e734307332a81ed1505178ae6 commit r16-7280-g75930efa22fb722e734307332a81ed1505178ae6 Author: Jakub Jelinek <[email protected]> Date: Wed Feb 4 12:29:24 2026 +0100 c++: Perform the iterating expansion stmt N evaluation in immediate context [PR123611] For the N evaluation for iterating expansion stmts where the standard says to evaluate: [] consteval { std::ptrdiff_t result = 0; for (auto i = begin; i != end; ++i) ++result; return result; // distance from begin to end }() right now (subject to further changes in CWG3140) I wanted to save compile time/memory and effort to actually construct the lambda and it is evaluated just using TARGET_EXPRs. On the following testcase it makes a difference, when the lambda is consteval, the expressions inside of it are evaluated in immediate context and so the testcase should be accepted, but we currently reject it when i has consteval-only type and expansion stmt doesn't appear in an immediate or immediate-escalating function. The following patch fixes this by forcing in_immediate_context () to be true around the evaluation. 2026-02-04 Jakub Jelinek <[email protected]> PR c++/123611 * pt.cc (finish_expansion_stmt): Temporarily enable in_immediate_context () for the iterating expansion stmt N computation. * g++.dg/reflect/expansion-stmt1.C: New test.
