Can (and maybe should) my coroutine promise class MyCoroutine::Promise have static or non-static initial_suspend and final_suspend methods?
static std::suspend_always initial_suspend() noexcept
{
return {};
}
static std::suspend_always final_suspend() noexcept
{
return {};
}
While this works fine (tested with GCC 13), Clang-Tidy complaints "Static member accessed through instance", when using this coroutine type:
MyCoroutine foo() // Clang-Tidy warning here
{
co_return;
}
This makes sense because "when a coroutine begins execution, it [...] calls promise.initial_suspend()" (see https://en.cppreference.com/w/cpp/language/coroutines.html) via instance, not via promise type.
So should I remove the static keyword from these methods (and make them const)? A this pointer is not required, but probably the compiler can inline and optimize these calls, anyway. Or are static methods a good idea here and is there a better way to deal with this warning?
Some of the examples from https://en.cppreference.com/w/cpp/language/coroutines.html do have static initial_suspend and final_suspend methods, some don't.
initial_suspendinserted by the compiler should not be triggering style criticisms like that.