VS 2010 Compiler Crash

Started by
3 comments, last by _moagstar_ 11 years, 11 months ago
Hi all!

I've found a peculiar bug in Visual Studio 2010. I'm not really sure why it happens, or what I'm doing wrong.
Anyway, here's the code:


// compilerCrash.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
template <class T>
class fatalError {
public:
T* fatalError::getObject(int i){
return new T(i);
}
T *fatalError::getObject(const char *j){
return new T(j);
}
};
class foo{
public:
foo(int i){
std::cout<<i;
}
foo(const char *j){
std::cout<<j;
}
void print(){
std::cout<<"printing";
}
};
int _tmain(int argc, _TCHAR* argv[])
{

foo f(20);
int id = (int)&f;
fatalError<foo> fatal;
fatal.getObject(id)->print();;
return 0;
}


Compiler Output:

1>------ Build started: Project: compilerCrash, Configuration: Debug Win32 ------
1>Build started 5/1/2012 8:37:12 AM.
1>InitializeBuildStatus:
1> Creating "Debug\compilerCrash.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1> compilerCrash.cpp
1>d:\siddu\programmming\tests\compilercrash\compilercrash\compilercrash.cpp(14): 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.
1> Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information
1> d:\siddu\programmming\tests\compilercrash\compilercrash\compilercrash.cpp(18) : see reference to class template instantiation 'fatalError<T>' being compiled
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.77
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


On removing the fatalError:: part within the member function definitions, the compiler becomes normal. for some reason, it causes the compiler to crash.

Are you guys able to reproduce this? and why is this happening? I'm sure I'm missing something, but I'm not sure *what* I'm missing.

Thanks all!

a WIP 2d game engine: https://code.google.com/p/modulusengine/

English is not my first language, so do feel free to correct me :)

Advertisement
File a bugreport: http://connect.microsoft.com/VisualStudio
This happens occasionally with compilers, they sometimes die on peculiar instruction arrangements. Usually shuffling things around or doing them a bit differently solves the issue, but it's good practice to make the developers working on the compiler aware of it (even if it's been reported before), so you should still file a bug report.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

thanks for the info :)

a WIP 2d game engine: https://code.google.com/p/modulusengine/

English is not my first language, so do feel free to correct me :)

Although it is a bug with the compiler that you don't get an appropriate error here, these messages are usually caused by something wrong in your code. This is the bug in your code:


template <class T>
class fatalError {
public:
/*
Doing qualified name look-up of a class that is being defined
T* fatalError::getObject(int i){
return new T(i);
}
T *fatalError::getObject(const char *j){
return new T(j);
}
*/
T* getObject(int i){
return new T(i);
}
T *getObject(const char *j){
return new T(j);
}
};


This compiles fine with the modifications above.

EDIT : Sorry, I missed the "[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]On removing the fatalError:: part within the member function definitions" part[/background]

[/font]

This topic is closed to new replies.

Advertisement