llvm / llvm/llvm-project

[coroutines] `initial-await-resume-called` not set before `await-resume` evaluation

Open
#189,399 1 comment 0 reactions 0 assignees View on GitHub
coroutines
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

https://godbolt.org/z/ea89KEazz

In this example, `unhandled_exception` is not called when `co_await promise.initial_suspend();` throws, even if `await-resume` has been evaluated.

```cpp
#include
#include

struct Awaiter {
auto await_ready() { return true; }
auto await_suspend(auto) {}
auto await_resume() { std::cout << "resume" << std::endl; }

~Awaiter() noexcept (false) {
std::cout << "~Awaiter()" << std::endl;
throw 0;
}
};

struct Tag {
struct promise_type {
Tag get_return_object() { return {}; }
Awaiter initial_suspend() { return {}; }
std::suspend_never final_suspend() noexcept {
std::cout << "final" << std::endl;
return {};
}
void return_void() {}
void unhandled_exception() { std::cout << "unhandled" << std::endl; }
};
};

Tag Coroutine() {
std::cout << "#1" << std::endl;
co_return;
}

int main() {
try {
Coroutine();
} catch (...) {
std::cout << "catch" << std::endl;
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.