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

Status : 

  Deferred<br /><br />
		The product team has reviewed this issue and has deferred it for consideration at a later time.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


2
0
Sign in
to vote
ID 762036 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 9/11/2012 12:43:43 AM
Access Restriction Public

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;
}
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)