This looks like a compiler bug, but the case is so simple I am a bit skeptical, so I am looking for a confirmation. Reproducible with both VS2010 and VS2012. The below example does not compile. This error is given:
Error 1 error C2440: 'type cast' : cannot convert from 'ConvertibleToAny' to 'OtherType<_Ty>' test.cpp 40
If you move the position of the move constructor OtherType(ThisType &&)
above the constructor OtherType( int )
, it suddenly compiles.
#include "stdafx.h"
#include <string>
using namespace std;
template<class _Ty>
struct OtherType
{
typedef OtherType<_Ty> ThisType;
OtherType()
{
}
OtherType( int )
{
}
// The move constructor
OtherType(ThisType && )
{
}
};
struct ConvertibleToAny
{
template <class AnyType>
operator AnyType()
{
return AnyType();
}
};
int _tmain(int argc, _TCHAR* argv[])
{
(OtherType<wstring>) ConvertibleToAny();
return 0;
}
Is this a bug or is this expected behavior? If it's expected, please quote the relevant paragraph from the C++11 specification. I already posted this as a bug at Microsoft Connect, click here to open it.