9

Here's a 10-line C++11 program, vastly simplified from a program I'm working on:

template <typename T> class Base { public:
    template <typename S> Base(S x) {}
};
template <typename T> class Child : public Base<T> { public:
    using Base<T>::Base;
};
template <> class Child<int> : public Base<int> { public:
    using Base<int>::Base;
};

int main()
{
    Child<int> child(8.0f);
}

MSVC 2015 outputs:

1>------ Build started: Project: MyProject, Configuration: Debug Win32 ------
1>  filename.cpp
1>path\to\filename(10): fatal error C1001: An internal error has occurred in the compiler.
1>  (compiler file 'msc1.cpp', line 1393)
1>   To work around this problem, try simplifying or changing the program near the locations listed above.
1>  Please choose the Technical Support command on the Visual C++
1>   Help menu, or open the Technical Support help file for more information

N.B. MSVC 2015 support for inheriting constructors is new with that version.

I've already submitted a bug report on this, since at the very least the compiler should not crash. However, can I have confirmation that this is correct C++ usage/a workaround?

Bug report here

Praetorian
  • 106,671
  • 19
  • 240
  • 328
geometrian
  • 14,775
  • 10
  • 56
  • 132
  • 0_0 what is this code supposed to do? – David Haim Jul 25 '15 at 21:02
  • 2
    @DavidHaim: It's an inheriting constructor declaration. – Kerrek SB Jul 25 '15 at 21:02
  • 2
    What else do you expect from MSCV? Workaround: use a decent compiler, such as clang, instead. – Walter Jul 25 '15 at 21:13
  • 1
    What is "MSCV", @Walter? – Lightness Races in Orbit Jul 25 '15 at 21:21
  • 1
    This is not a program, and you can improve the code's readability by eliding the unnecessary `public`s: http://coliru.stacked-crooked.com/a/164072087e303251 Going further, I would actually advise making it slightly longer but with better spacing: http://coliru.stacked-crooked.com/a/1b1fe7c6d2509a97 Just a thought. – Lightness Races in Orbit Jul 25 '15 at 21:22
  • Please link to your bug report, for reference. – Lightness Races in Orbit Jul 25 '15 at 21:23
  • @imallett: Probably worth raising an issue on Connect, too. – Lightness Races in Orbit Jul 25 '15 at 21:25
  • @LightnessRacesinOrbit I sent it via the built-in reporter in the IDE. I have had [problems](http://superuser.com/questions/942441/i-cant-submit-a-bug-report-because-the-bug-reporter-has-a-bug) submitting it through connect. If someone here could submit it, that would be great.¶ If you just want a shorter bug, here's a tweetable version: `#define t template//cause ICE\nt class B{t B(T){}};t class C:B<>{using B::B;};template<>class C<>:B<>{using B::B;};Cc(1)`. – geometrian Jul 25 '15 at 21:27
  • 1
    I don't see the value in making it unreadable, personally. – Lightness Races in Orbit Jul 25 '15 at 21:28
  • The page works fine. Choose your compiler from the dropdown list and the form will load. – Lightness Races in Orbit Jul 25 '15 at 21:30
  • "To work around this problem, try simplifying or changing the program near the locations listed above" – o.O Sure, instead of MS fixing their buggy compiler, you should carefully craft your code so that it doesn't accidentally trigger their bug. Well done! – The Paramagnetic Croissant Jul 25 '15 at 21:36
  • 3
    @imallett I think your connect bug report needs more detail. You should at least provide the error message (like you have here) rather than just the smartass comments. – Jonathan Potter Jul 25 '15 at 22:01
  • @JonathanPotter I can't edit any of the fields; only upload new documents. In any case, I don't especially regret going for simplicity. Simply-expressed problems are cluttered by extraneous detail. I only added the output here because it's SO. MS should be able to figure out what their own compiler prints. – geometrian Jul 25 '15 at 22:07
  • @imallett You don't consider sticking the _in 10 lines_ phrase at the end to be extraneous detail? – Beta Carotin Jul 25 '15 at 22:19
  • @BetaCarotin touché. Note though, that it helps clarify that the problem can be reproduced in a simple example, not in some huge codebase. When people report bugs this way to me, I appreciate it since it means the poster was thoughtful enough to reduce it to something easy to play with. Again, though, I can't change the bug report's text. – geometrian Jul 25 '15 at 22:23
  • 1
    @imallett My comment was based on being familiar with connect and the sort of information they need before they will investigate an issue. What's the point of making it harder for them? Surely the goal is to get the bug fixed. – Jonathan Potter Jul 25 '15 at 22:42
  • The `template<>` construct looks mighty suspicious to me. Is it even valid syntax? What's the purpose of a template without parameters? – ivan_pozdeev Aug 01 '15 at 05:42
  • 1
    @ivan_pozdeev it's called [template specialization](http://en.cppreference.com/w/cpp/language/template_specialization); it's relatively common. – geometrian Aug 01 '15 at 06:12

1 Answers1

6

As mentioned in the comments, it seems to be a MSVC issue. Quickly compiled it with Clang and -std=c++11, no problems there.

deviantfan
  • 11,268
  • 3
  • 32
  • 49
Nibor
  • 1,236
  • 9
  • 23
  • well if it is internal compiler error, chances are, it is not mandated by standard, so obviously it is MSVC problem – Creris Jul 25 '15 at 21:29
  • 4
    @Creris: You've missed the point. It could be ill-formed in C++ _and_ trigger an ICE in the compiler. The OP is asking whether that's the case (it's not). – Lightness Races in Orbit Jul 25 '15 at 21:31
  • 1
    @LightnessRacesinOrbit its still MVSC problem tho, ill or non-ill formed program, they shouldnt cause internal errors – Creris Jul 25 '15 at 21:32
  • 2
    @Creris: Yes, we all know that. That is not what this question is about. The OP is simply asking whether the program is ill-formed. That's it. – Lightness Races in Orbit Jul 25 '15 at 21:33
  • 5
    This is a terrible thing. Checking it in some other compiler is not a proof of anything. Only Standard quotes can really back up that it is correct. Also the fact that MSVC ICEs means there's clearly *some* MSVC issue here, but that does not make the code correct or incorrect. – Puppy Jul 25 '15 at 22:09
  • 3
    An ICE is always a compiler bug. If the C++ is ill-formed, it should trigger a compilation error or warning, never an ICE. File the bug on connect. From the command-ilne, be sure to run ``cl -Bv`` to capture the exact version number – Chuck Walbourn Jul 26 '15 at 03:58