https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113457
--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Arsen Arsenovic <ar...@gcc.gnu.org>: https://gcc.gnu.org/g:5cca7517c5868b7b9aa13992145eb6082ac5d5b9 commit r15-3203-g5cca7517c5868b7b9aa13992145eb6082ac5d5b9 Author: Arsen ArsenoviÄ <ar...@aarsen.me> Date: Fri Aug 23 20:19:05 2024 +0200 c++/coros: do not assume coros don't nest [PR113457] In the testcase presented in the PR, during template expansion, an tsubst of an operand causes a lambda coroutine to be processed, causing it to get an initial suspend and final suspend. The code for assigning awaitable var names (get_awaitable_var) assumed that the sequence Is -> Is -> Fs -> Fs is impossible (i.e. that one could only 'open' one coroutine before closing it at a time), and reset the counter used for unique numbering each time a final suspend occured. This assumption is false in a few cases, usually when lambdas are involved. Instead of storing this counter in a static-storage variable, we can store it in coroutine_info. This struct is local to each function, so we don't need to worry about "cross-contamination" nor resetting. PR c++/113457 gcc/cp/ChangeLog: * coroutines.cc (struct coroutine_info): Add integer field awaitable_number. This is a counter used for assigning unique names to awaitable temporaries. (get_awaitable_var): Use awaitable_number from coroutine_info instead of the static int awn. gcc/testsuite/ChangeLog: * g++.dg/coroutines/pr113457-1.C: New test. * g++.dg/coroutines/pr113457.C: New test.