给定以下代码片段,case 1、2、3和4在Visual Studio2017 (/std:c++14)中编译,但case 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'发布于 2018-11-23 13:45:35
这是MSVC中的一个错误。我打开了一个bug:Error instantiating lambda template修复的优先级是由投票决定的。请随时为这个问题加票。
https://stackoverflow.com/questions/53381468
复制相似问题