【问题标题】:Function-scope name in generic lambda trailing return type won't compile (MSVC)通用 lambda 尾随返回类型中的函数范围名称无法编译 (MSVC)
【发布时间】:2019-04-22 05:11:35
【问题描述】:

给定以下代码 sn-p,案例 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'

【问题讨论】:

  • A bug? 在 MSVC 中?不可能!

标签: visual-c++ c++14 trailing-return-type generic-lambda


【解决方案1】:

这是 MSVC 中的一个错误。我开了一个bug:Error instantiating lambda template 修复由赞成票优先。随意支持这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-02
    • 2017-03-16
    • 1970-01-01
    • 2013-01-04
    • 1970-01-01
    • 2019-02-04
    • 2015-09-10
    • 1970-01-01
    相关资源
    最近更新 更多