visual-c++ - 通用 lambda 尾随返回类型中的函数范围名称无法编译 (MSVC)
问题描述
给定以下代码片段,案例 1、2、3 和 4 在 Visual Studio 2017 (/std:c++14) 中编译,但案例 5 没有。这是怎么回事?
int i;
auto case1 = [](auto) -> decltype(i, void()) {};
int main() {
int j;
auto case2 = [](int) -> decltype(j, void()) {};
auto case3 = [j](auto) -> decltype(j, void()) {};
auto case4 = [](auto) -> decltype(i, void()) {};
auto case5 = [](auto) -> decltype(j, void()) {};
case1(int()); // OK
case2(int()); // OK
case3(int()); // OK
case4(int()); // OK
case5(int()); // Error: message below
return 0;
}
这是编译器的输出。
main.cpp(15): error C2672: 'operator __surrogate_func': no matching overloaded function found
main.cpp(15): error C2893: Failed to specialize function template 'void main::<lambda_1>::operator ()(_T1) const'
main.cpp(15): note: With the following template arguments: '_T1=int'
解决方案
这是 MSVC 中的一个错误。我打开了一个错误:错误实例化 lambda 模板 修复由赞成票优先。随意赞成这个问题。
推荐阅读
- php - 循环帖子摘录返回空
- java - 将多个流合并到单个流中的正确模式
- app-store - 应用商店应用包名
- javascript - 获取 cookie 错误
- vue.js - 在没有 mapState 的情况下调用 vuex 存储
- python - django 在序列化时从模型实例中过滤一个对象
- html - iframe 内的内容重定向但不是整个页面
- java - 如何在 Java 中通过 WebClient 在 Vertx 路由器中使用期货
- python - 从 eig 函数改变特征向量的形式?
- selenium - 带有 Selenium 的 Capybara 加载页面时间过长导致 Net::ReadTimeout 错误