Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to co_await in a catch clause?

The following code:

try {
  throw 42;
} catch (int i) {
  co_await somefuture;
}

compiles with clang 6 and 7 with -fcoroutines-ts. However, it does not compile with Visual C++ 15 (2017) Visual C++ 16 (2019) with /await with the error

C2304: 'co_await' cannot be used inside of a catch block

The C++20 standard draft and cppreference do not seem to mention anything about it.

Is it a missing feature in the Microsoft compiler or did I misunderstand the standard?

like image 414
Philippe Avatar asked Apr 12 '19 13:04

Philippe


1 Answers

From [expr.await], emphasis mine:

An await-expression shall appear only in a potentially-evaluated expression within the compound-statement of a function-body outside of a handler ([except]).

MSVC is correct to reject.

like image 170
Barry Avatar answered Oct 06 '22 09:10

Barry