2

我使用Visual Studio 2015年更新3C++ 11 constexpr使編譯器的內部錯誤(C1001)

我得到一個致命的錯誤:

(code C1001) : An internal error has occurred in the compiler.

下面是代碼:

template<typename T> 
constexpr T epsilon = std::numeric_limits<T>::epsilon(); 

我讀過它在Visual Studio Update 2中修復了。有人能解釋我爲什麼會出現這個錯誤嗎?提前致謝。

+0

這裏出現了很多很多問題:什麼錯誤?爲什麼你使用模板顯然是函數調用,你是否包含了限制? – Zafi

+0

我不確定是否有解釋。至少從語言的角度來看,這看起來不錯。如果這只是一個內部編譯器錯誤,那些沒有有用的解釋......除非你是編譯器編寫者。所以,ICE只需要向編譯器作者報告。 –

+1

只是FYI,模板變量是C++ 14,而不是C++ 11。 – HolyBlackCat

回答

6

任何內部錯誤(ICE)都是編譯器錯誤。你得到它是因爲你碰巧觸發了這個錯誤。對於這個編譯器,你可以在Microsoft Connect上報告它。

對於這樣的報告,您需要一個預期的正確結果和錯誤結果的示例。

以下測試程序編譯&運行很好地使用MinGW克++ 5.1

#include <limits> 

template<typename T> 
constexpr T epsilon = std::numeric_limits<T>::epsilon(); 

#include <iostream> 
using namespace std; 
auto main() -> int 
{ 
    cout << epsilon<double> << endl; 
} 

輸出:

 
2.22045e-016 

用Visual C++ 2015更新2它產生一個ICE:

 
foo.cpp(10): fatal error C1001: An internal error has occurred in the compiler. 
(compiler file 'f:\dd\vctools\compiler\cxxfe\sl\p1\c\symbols.c', line 28114) 
To work around this problem, try simplifying or changing the program near the locations listed above. 
Please choose the Technical Support command on the Visual C++ 
Help menu, or open the Technical Support help file for more information 
foo.cpp(10): note: see reference to variable template 'const double epsilon' being compiled 

編譯器版本:

 
> cl /nologo- 2>&1 | find "++" 
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23725 for x86