![](/img/trans.png)
[英]Lambda copying a reference to a lambda reference VS2017 compile error
[英]__declspec(noinline) on lambda function inside template class throws syntax error in VS2017
在嘗試使用斷言宏調試問題時,我遇到了這個問題。 在模板類中的lambda函數上使用__declspec(noinline)會在Visual Studio 2017中生成語法警告:
錯誤C2760:語法錯誤:意外標記'__declspec',預期'{'
這是失敗的代碼:
template<class R>
class test
{
public:
void DoStuff()
{
[]() __declspec(noinline) { }; // syntax error
}
};
int WinMain(void)
{
return 0;
}
如果我轉到我的項目設置並在項目屬性對話框的常規部分中將我的平台工具集從v141(vs2017)切換到v140(vs2015),則錯誤消失。
如果我將類更改為不是模板類,它也會正確編譯:
class test
{
public:
void DoStuff()
{
[]() __declspec(noinline) { }; // compiles fine
}
};
int WinMain(void)
{
return 0;
}
我很好奇為什么使用v141平台工具集不會成功。 是否有其他項目設置可能會影響這個?
它適用於VC ++ 2019,所以可能只是2017年的回歸?
我能夠通過將Visual Studio 2017更新到最新版本(15.9.7)來解決這個問題。 以前我運行的是15.6.7版。 感謝所有關注和評論的人! :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.