18

I have ran into a problem compiling some template code with Visual Stuido 2010 SP1, cl.exe version 16.0.40219.1

The following code will cause the compiler to access violate:

template<typename T>
class A
{
    A(){}
};

template<typename T>
class B : public A<T>
{
    using A::A(); // Compiler access violates
    // **EDIT**
    //using A<T>::A<T>; // Compiler succeeds
    //using A<T>::A(); // Compiler reports error
};

int main(int argc, char* argv[])
{
    return 0;
}

It generates the following error (in addition to the "cl.exe has stopped working, C0000005 exception):

1>d:\projects\cpptest\cpptest\cpptest.cpp(11): fatal error C1001: An internal error has occurred in the compiler.
1>  (compiler file 'msc1.cpp', line 1420)
1>   To work around this problem, try simplifying or changing the program near the locations listed above.

The code compiles fine (well, that is, it emits a proper error message and doesn't crash the compiler) in Dev-C++ with g++.

main.cpp:11: error: `template<class T> class A' used without template parameters
main.cpp:11: error: expected nested-name-specifier before "A"
main.cpp:11: error: using-declaration for non-member at class scope
main.cpp:11: error: expected `;' before '(' token
main.cpp:11: error: expected unqualified-id before ')' token
make.exe: *** [main.o] Error 1

EDIT The following, however, compiles fine, without access violation, so it seems this is related to templates:

class A
{
    A(){}
};

class B : public A
{
    using A::A;
};

int main(int argc, char* argv[])
{
    return 0;
}

Do you think this is worth reporting to Microsoft? Can anyone else reproduce this? Maybe try in Visual Studio 2013 to see if it still occurs?

namezero
  • 2,203
  • 3
  • 24
  • 37
  • 2
    Reproducable here, Microsoft C/C++ Compiler 17.00.51106.1. – Nemanja Boric Sep 12 '13 at 13:04
  • 19
    An internal compiler error is always a bug – Jesse Good Sep 12 '13 at 13:09
  • Also, in `class A`, you don't need `A::` before constructor inside your class definition. – Nemanja Boric Sep 12 '13 at 13:10
  • Yes, that's what I thought. I tried searching on Microsoft Connect, but I couldn't find anything about this being reported. – namezero Sep 12 '13 at 13:11
  • Err, I corrected this in the code. It was a leftover from playing around with the code. Removing it doesn't change the behavior. – namezero Sep 12 '13 at 13:12
  • 2
    If you can reproduce this problem, please click on "I can [reproduce this bug] too" here: https://connect.microsoft.com/VisualStudio/feedback/details/800362/visual-studio-2010-sp1-c-cl-exe-access-violation#details – namezero Sep 12 '13 at 13:14
  • Where do you see an access violation? –  Sep 12 '13 at 13:19
  • 1
    @namezero Yes, but it makes your code compileable in gcc-4.8 (with `using A::A;`). – Nemanja Boric Sep 12 '13 at 13:21
  • @hvd: here: cpptest.cpp(11). I get the "cl.exe has stopped working" windows dialog, exception code C0000005. – namezero Sep 12 '13 at 13:22
  • 3
    In VS2013 (RC) it doesn't build with "error C2143: syntax error : missing ';' before '(' line 16 column 1". After adding the missing `;` it builds but crashes the compiler with "error C1001: An internal error has occurred in the compiler.". – Grimthorr Sep 12 '13 at 13:23
  • @Nemanja Boric: Yes, A::A works fin in Dev-C++ too. – namezero Sep 12 '13 at 13:25
  • 3
    @namezero Ah yes, you're right, I missed what that code means. There is pretty much no case where an access violation is *not* a bug in the code (so in this case, the compiler itself). –  Sep 12 '13 at 13:27
  • 1
    Reproducable here, too. Visual Studio 2010 Professional – fecub Sep 12 '13 at 13:35
  • @hvd: My thinking exactly. I just wanted to conform the StackOverflow "question" rules and phrase it as a question. Also, I'm usually careful about crying compiler bug, but I don't think faulty source code input should be able to crash the compiler. – namezero Sep 12 '13 at 13:36

2 Answers2

4

Since this is reproducible by others on Visual C++ platforms, I have opened a bug report on Microsoft Connect as "answer".

Also, as workaround, the following syntax works:

using A<T>::A<T>;
namezero
  • 2,203
  • 3
  • 24
  • 37
0

Update 2013-12-06: Microsoft has confirmed the issue and the issue will be fixed in the Visual Studio 2013 C++ compiler.

namezero
  • 2,203
  • 3
  • 24
  • 37