任何內部錯誤(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
這裏出現了很多很多問題:什麼錯誤?爲什麼你使用模板顯然是函數調用,你是否包含了限制? – Zafi
我不確定是否有解釋。至少從語言的角度來看,這看起來不錯。如果這只是一個內部編譯器錯誤,那些沒有有用的解釋......除非你是編譯器編寫者。所以,ICE只需要向編譯器作者報告。 –
只是FYI,模板變量是C++ 14,而不是C++ 11。 – HolyBlackCat