【发布时间】: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