-
Notifications
You must be signed in to change notification settings - Fork 15.6k
Open
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzercoroutinesC++20 coroutinesC++20 coroutines
Description
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
#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.
Metadata
Metadata
Assignees
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzercoroutinesC++20 coroutinesC++20 coroutines