c++c++20c++23c++-coroutinelanguage-specifications

is co_await promise.initial_suspend() preformed in a try catch block?


In some resources the following translation for coroutine:

{
   promise-type promise promise-constructor-arguments ;
   try {
      co_await promise.initial_suspend() ;
      function-body
   } catch ( ... ) {
      if (!initial-await-resume-called)
         throw ;
      promise.unhandled_exception() ;
   }
final-suspend :
   co_await promise.final_suspend() ;
}

Here for example: https://eel.is/c++draft/dcl.fct.def.coroutine#11

{
   P p;
   co_await p.initial_suspend(); // initial suspend point
   try { F } catch(...) { p .unhandled_exception(); }
final_suspend :
   co_await p.final_suspend(); // final suspend point
}

Here for example: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4680.pdf

The first puts co_await promise.initial_suspend(); inside the try block and the second doesn't. Which one is the C++20 or C++23 standard?


Solution

  • This April 3, 2020 build of the C++ standard, the closest you can get to the C++20 standard for free, put the initial_suspend point in the try-block, just like the current revision you cited.