尝试从cppreference.com编译以下示例
#include <coroutine>
struct promise;
struct coroutine : std::coroutine_handle<promise>
{
using promise_type = struct promise;
};
struct promise {
coroutine get_return_object()
{
return { coroutine::from_promise(*this) };
}
std::suspend_always initial_suspend() noexcept { return {}; }
std::suspend_never final_suspend() noexcept { return {}; }
void return_void() {}
void unhandled_exception() {}
};
struct S {
int i;
coroutine f() {
std::cout << i;
co_return;
}
};但编译错误:
error C3789: this function cannot be a coroutine: 'coroutine::promise' does not declare the member 'get_return_object()'编译器: MSVC2019,/std:c++latest
微软(R) C/C++优化编译器版本19.29.30137用于x86
但是GCC12编译它,MSVC有什么问题吗?
EDIT1
与MSVC2022相同的错误
为x86优化编译器版本19.30.30709
/std:c++latest
发布于 2022-02-09 09:52:35
正如该网站所述:
工作正在进行中:这个页面正在进行更新,以反映C++20工作草案中包含的Coroutines技术规范的各个部分。
此示例不能使用MSVC2019编译器运行。您可以使用此版本安装并试用该版本:
https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes
https://stackoverflow.com/questions/71044540
复制相似问题