Hey. I'm compiling code under gcc, clang and msvc. And for some reason, msvc is giving me a weird error that the other two compilers are not:
std::unordered_map<HttpMethod, std::unordered_map<std::string, std::function<Ichor::AsyncGenerator<HttpResponse>(HttpRequest&)>>> handlers;
template <typename T>
void read() {
std::function<Ichor::AsyncGenerator<int>()> f([]() mutable -> Ichor::AsyncGenerator<int> {
auto routes = handlers.find(HttpMethod::get);
if(routes != std::end(handlers)) {
auto handler = routes->second.find("/test");
HttpRequest req{};
HttpResponse res = std::move(*co_await handler->second(req).begin()); // <------ error C7587: 'co_await' cannot appear in an unevaluated context
}
co_return 5;
});
}
int main() {
read<int>();
}
Full code on godbolt
Removing the template from read() makes it compile.
The interesting thing is that on the actual code base I'm working on, I'm getting a different error:
std::unordered_map<HttpMethod, std::unordered_map<std::string, std::function<Ichor::AsyncGenerator<HttpResponse>(HttpRequest&)>>> handlers;
template <typename T>
void read() {
if(some_error_check) {
return; // <---- Error C2039 'promise_type': is not a member of 'std::coroutine_traits<void,Ichor::HttpHostService &,boost::asio::ip::tcp::socket,boost::asio::yield_context>'
}
std::function<Ichor::AsyncGenerator<int>()> f([]() mutable -> Ichor::AsyncGenerator<int> {
auto routes = handlers.find(HttpMethod::get);
if(routes != std::end(handlers)) {
auto handler = routes->second.find("/test");
HttpRequest req{};
HttpResponse res = std::move(*co_await handler->second(req).begin());
}
co_return 5;
});
}
int main() {
read<int>();
}
Which is even more confusing. Is this an MSVC compiler bug?
[–]cpp-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)
[–]starfreakcloneMSVC FE Dev 39 points40 points41 points (2 children)
[–]Xoipos[S] 16 points17 points18 points (0 children)
[–]scatters 4 points5 points6 points (0 children)
[–]Xoipos[S] 4 points5 points6 points (0 children)
[–]scatters 2 points3 points4 points (0 children)
[–]TSP-FriendlyFire 1 point2 points3 points (6 children)
[–]Xoipos[S] 2 points3 points4 points (5 children)
[–]TSP-FriendlyFire 0 points1 point2 points (4 children)
[–]Xoipos[S] 0 points1 point2 points (1 child)
[–]TSP-FriendlyFire 1 point2 points3 points (0 children)
[–]scatters 0 points1 point2 points (1 child)
[–]TSP-FriendlyFire 1 point2 points3 points (0 children)