| Issue |
171023
|
| Summary |
Add warning for coroutines without any `co_*` keywords in the definition
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
JankoDedic
|
This is a feature request for a Clang C++ compiler warning.
A function without any `co_*` keywords in its body is not a coroutine, even if it returns an awaitable type. What is intended to be a coroutine by the developer can accidentally become a normal function, which has entirely different behavior and can result in surprising bugs and undefined behavior. Some of these mistakes will be caught by `-Wreturn-type`, but not all of them.
Example: https://godbolt.org/z/8EfeTYdvq
```c++
#include <coroutine>
struct coroutine {
struct promise_type {
coroutine get_return_object() { return {}; }
std::suspend_always initial_suspend() { return {}; }
void return_void() {}
void unhandled_exception() {}
std::suspend_always final_suspend() noexcept { return {}; }
};
};
coroutine example() {
throw 67;
}
```
A compiler warning diagnosing functions with awaitable return types that don't have any `co_*` keywords in the definition could help entirely eliminate this class of bugs from codebases using coroutines.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs