2015-12-13 74 views
0

用gcc 5.2和3.7鏗鏘下面的作品,但失敗MSVC 2015年:MSVC的std ::功能無法嵌套拉姆達接受通用拉姆達

#include <functional> 

int main() 
{ 
    auto const foo = [](auto&& i) { 
    auto const bar = []{ return 100; }; 
    return bar(); 
    }; 

    std::function<int(int)> fn = foo; 
    return 0; 
} 

難道是MSVC的錯誤或者是gcc和鏗鏘過於鬆懈?

+0

Visual Studio中的哪個版本? –

+0

vs2015 Nubcase

+2

如果將其更改爲'auto const foo = [](auto && i) - > int {' – melak47

回答

2

如果我使用Microsoft's official online compiler這是2015年12月3日更新的版本19.00.23602.0(x86)進行嘗試,我得到執行超時。刪除std::function<int(int)> fn = foo;將允許編譯成功。請隨時通過Visual Studio Connect告知微軟,以便他們調查錯誤並進行報告。是的,人們可以浪費時間翻閱標準,看看這是否是「合法」的代碼,但通過使用錯誤跟蹤器,您將獲得更大的回報。

內部編譯器錯誤是總是一個錯誤。

+2

我不知道ms提供了一個在線編譯器。感謝那。 – Nubcase

0

這是在Visual C++ 2015中的a bug,但它似乎已修復爲更新3。解決方法是指定外部lambda的返回類型(感謝melak47)。

這種失敗:

#include <functional> 

int main() 
{ 
    std::function<void (bool)> f = 
     [](auto&&) 
     { 
      []{}; 
     }; 
} 

有:

Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64 
Copyright (C) Microsoft Corporation. All rights reserved. 

a.cpp 
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\type_traits(1348): 
    error C2065: '_Args': undeclared identifier 
    [...and more]

但這個工程:

#include <functional> 

int main() 
{ 
    std::function<void (bool)> f = 
     [](auto&&) -> void 
     { 
      []{}; 
     }; 
}