I encountered a very strange symptom. Who can tell me what the root cause is?
My VC++ compiler version is latest: "Microsoft Visual C++ 2010 : 01019-532-2002102-70860"
Steps to reproduce:
- Create an empty win32 console project
- Add a new cpp file named main.cpp
- Paste the following code into main.cpp
- Compile
- The compiler crashes and reports the following message:
\bug\main.cpp(54893757): fatal error C1001: An internal error has occurred in the compiler. (compiler file 'msc1.cpp', line 1420)
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.
This error occurred in injected text:
d:\bug\main.cpp(63) : see reference to function template instantiation 'XDummy Test(T)' being compiled with [ T=int ]
Build FAILED.
Below is the source code of main.cpp:
#include <vector>
template<class It_>
struct trait_dummy
{
static const int value = std::tr1::is_convertible<typename iterator_traits<It_>::iterator_category, int>::value;
};
template<class It_>
class X
{
public:
template<class T_>
X(T_& rColl)
{}
};
template<class T_>
X<typename T_::iterator> f(T_ rColl, std::false_type)
{
return X<typename T_::iterator>(rColl);
}
template<class T_>
auto f(T_& rColl) -> decltype(f(rColl, std::false_type()))
{
return f(rColl, std::false_type());
}
template<class It_>
X<It_> f(It_ first, size_t nSize, typename std::tr1::enable_if<trait_dummy<It_>::value>::type* dummy = 0)
{
return X<It_>(first, first + nSize);
}
class XTest
{
public:
void foo()
{
auto v = f(m_Suite);
}
std::vector<int> m_Suite;
};
const int g_dummy = 0;
class XDummy
{
public:
XDummy(int, int, int, int dummy = g_dummy)
{}
};
template<class T>
XDummy Test(T)
{
return XDummy(0, 0, 0);
}
int main()
{
Test(0);
//XTest().foo();
return 0;
}