Home Dashboard Directory Help
Search

Position/order of move constructor within class matters. Templated cast operator fails when used in conjunction with move constructor by Edward Gabriel Barbu


Status: 

Closed
 as Deferred Help for as Deferred


2
0
Sign in
to vote
Type: Bug
ID: 762036
Opened: 9/11/2012 12:43:43 AM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

This affects classes using the templated cast operator to convert to various types, such as Boost's generic_list<>, a.k.a boost::assign::list_of<>.

Reproducible in 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>' c:\users\eddie\documents\visual studio 2010\projects\test231\test231\test231.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;
}
Details
Sign in to post a comment.
Posted by Microsoft on 9/11/2012 at 2:06 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Microsoft Visual Studio Connect Support Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 9/11/2012 at 12:50 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.