0

I have a virtual function inside a C++ templated task, and when it is compiled in Visual Studio 2015 (I have tried all combinations of Debug/Release and x86/x64), it consistently fails with compiler error C1001 on the following line of code:

e_Ty *d(new e_Ty[l]);

Where e_Ty is the template parameter of the class. This error only occurs when I use the template class with e_Ty set to std::pair<const int &, int &>. Is there a legitimate reason why this should not work, or is this a bug in MSVC?


EDIT

Notes:

  • l is a local variable that was declared (and assigned a value as a result of a function call) ahead of time.
  • I have tried using disabling optimization, using auto, and using assignment-style initialization, none of which worked.
  • Code compiles fine when e_Ty is int.
Nick Mertin
  • 1,149
  • 12
  • 27

2 Answers2

4

An internal compiler error, an ICE, is always a bug.

Please report it via Microsoft Connect.


The code in question,

e_Ty *d(new e_Ty[l]);

may or may not be correct depending on l, whether appropriate headers have been included, and so on. There's too little context to say. is invalid for e_Ty as a std::pair of references, because references need to be initialized, as noted by T.C.. But that doesn't matter for an ICE.

Community
  • 1
  • 1
Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331
  • Thank you, I'll submit it to Microsoft. Also, I edited my question to clarify that `l` is a local variable, and that it works with `int`. – Nick Mertin Jun 02 '16 at 21:47
  • 1
    _An internal compiler error, an ICE, is always a bug._ Someone would call it _a feature_ anyway. :-) – skypjack Jun 02 '16 at 22:02
  • See [this article](https://support.microsoft.com/en-us/kb/974229) for details on making a good repro – Chuck Walbourn Jun 03 '16 at 00:40
0

It's worth seeing if it's related to: C++11 constexpr causes compiler's internal error (C1001)

If there is a constexpr involved, VS2015 and VS2017 compilers have been reported to crash when used with template code.