C++ 11 constexpr导致编译器的内部错误(C1001)

lor*_*loc 3 c++ visual-c++ internal-compiler-error c++14 visual-studio-2015

我正在使用Visual Studio 2015 Update 3.

我收到一个致命的错误:

(代码C1001):编译器中发生内部错误.

这是代码:

template<typename T>
constexpr T epsilon = std::numeric_limits<T>::epsilon();
Run Code Online (Sandbox Code Playgroud)

我读过它是在Visual Studio Update 2中修复的.有人可以解释我为什么会收到此错误吗?提前致谢.

Che*_*Alf 7

任何内部错误(ICE)都是编译器错误.你得到它是因为你碰巧触发了这个bug.对于此编译器,您可以在Microsoft Connect上报告它.

对于这样的报告,您需要一个具有预期正确结果和错误结果的示例.

以下测试程序使用MinGW g ++ 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;
}
Run Code Online (Sandbox Code Playgroud)

输出:

2.22045e-016

使用Visual C++ 2015 update 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