3

I am using Visual Studio 2015 Update 3.

I get a fatal error:

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

Here is the code :

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

I read it was fixed in Visual Studio Update 2. Can someone explain me why I am getting this error? Thanks in advance.

ildjarn
  • 62,044
  • 9
  • 127
  • 211
  • Many, many questions arise here: what error? Why are you using template for what is clearly a function call, have you included limits? – Zafi Aug 01 '16 at 10:07
  • I'm not sure there _is_ an explanation. At least not from a language perspective, where this looks OK. If this is just an internal compiler error, those don't have useful explanations... unless you're a compiler writer. So, ICEs just need to be reported to the compiler writer. – underscore_d Aug 01 '16 at 10:14
  • 1
    Just FYI, template variables are C++14, not C++11. – HolyBlackCat Aug 01 '16 at 10:23
  • 1
    Can you also try with update 5? Maybe someone else found it already and it got fixed in the meantime.. – stijn Aug 01 '16 at 10:43
  • Because there is an internal error. A bug. What more do you need to know? – Lightness Races in Orbit Aug 01 '16 at 11:21
  • @LightnessRacesinOrbit Indeed, especially that the remaining knowledge is already given by the full error message, as quoted by Alf: `Please choose the Technical Support command on the Visual C++ Help menu`. This, one must hope, will lead the user to somewhere they can report it. – underscore_d Aug 01 '16 at 11:30
  • Sorry, I confused some C++11 with some C++14 features. So.. should I report it to the technical support? –  Aug 01 '16 at 12:07
  • Of course, because by doing so, they can ensure it's fixed for you and other users in a subsequent version. – underscore_d Aug 01 '16 at 12:50
  • @Zafi: If that line of code triggers an ICE, there is no need for further explanation. Even if the code was terribly wrong or you just input nonsense, it shouldn't happen. An ICE is a _compiler bug_ and should _never_ occur. This must be fixed by the MSVS developers. – andreee Jun 12 '18 at 08:11
  • @andreee: Originally the error was not mentioned, so it was unclear what the issue was... – Zafi Jun 12 '18 at 08:38

2 Answers2

8

Any internal error (ICE) is a compiler bug. You get it because you have happened to trigger that bug. For this compiler you can report it at Microsoft Connect.

For such a report you need an example with an expected correct result, and the erroneous result.

The following test program compiles & runs nicely with 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;
}

Output:

2.22045e-016

With Visual C++ 2015 update 2 it produces an 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

Compiler version:

> cl /nologo- 2>&1 | find "++"
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23725 for x86
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331
1

I've raised this as a bug with Microsoft, but they have had a fix since early 2017 which has not been released from what I can see as of today.

I've also provided a project on GitLab and given information to Microsoft for this project here: https://gitlab.com/cppocl/tostring

Loading the .sln and compiling currently crashes with Visual Studio 2015 update 2 or 3, and Visual Studio Enterprise 2017 version 15.3.1.

It does seem that the combination of template and constexpr causes the compiler to crash.

I've seen reports for Visual Studio 2017 describing similar types of problems.

This link says fixed pending release: https://developercommunity.visualstudio.com/content/problem/18155/msvc-2017-c-fatal-error-c1001-constexpr-initializa.html

Visual Studio 2015 backlog of bugs relating to constexpr is here: https://blogs.msdn.microsoft.com/vcblog/2015/12/02/constexpr-in-vs2015-update-1/

EDIT: I also don't believe changing optimization settings will make any difference, as has been recommended in other posts. I have experimented with these settings and applied recommended patches without success so far.