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

时间:2016-08-01 10:05:12

标签: c++ visual-c++ visual-studio-2015 c++14 internal-compiler-error

我正在使用Visual Studio 2015 Update 3。

我收到致命错误:

  

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

以下是代码:

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

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

2 个答案:

答案 0 :(得分:7)

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

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

以下测试程序编译&amp;与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;
}

输出:

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

答案 1 :(得分:1)

我已将此问题视为微软的一个错误,但自2017年初以来,他们已经解决了这个问题,而且从我今天看到的情况还没有发布。

我还提供了一个关于GitLab的项目,并在此向Microsoft提供了有关此项目的信息:https://gitlab.com/cppocl/tostring

加载.sln并使用Visual Studio 2015更新2或3以及Visual Studio Enterprise 2017版本15.3.1编译当前崩溃。

似乎模板和constexpr的组合会导致编译器崩溃。

我已经看到Visual Studio 2017的报告描述了类似的问题。

此链接显示已修复的待处理版本: https://developercommunity.visualstudio.com/content/problem/18155/msvc-2017-c-fatal-error-c1001-constexpr-initializa.html

Visual Studio 2015积压的与constexpr相关的错误在这里: https://blogs.msdn.microsoft.com/vcblog/2015/12/02/constexpr-in-vs2015-update-1/

编辑: 我也不相信更改优化设置会有所不同,正如其他帖子所推荐的那样。 到目前为止,我已经尝试了这些设置并应用了推荐的补丁但没有成功。