Search

Compile error when explicitly instantiating shared_ptr by jmcmod

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 649531
Opened: 3/4/2011 5:01:54 PM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
Unable to use explicit instantiation on shared_ptr since upgrading to Visual Studio 2010.

I believe the problem exists in the routine below because _Mybase (which is _Ptr_base) does not have a swap method. It, instead, has a _Swap method.

    void swap(_Myt&& _Right)
        {    // exchange contents with movable _Right
        _Mybase::swap(_STD move(_Right));
        }

I removed the explicit instantiation and it resolved my problem.

Note that the problem can also manifest via the following (granted it would be a strange thing to do):
std::tr1::shared_ptr<int> a;
a.swap(std::tr1::shared_ptr<int>(new int(1)));
Details (expand)

Visual Studio/Silverlight/Tooling version

Visual Studio 2010

What category (if any) best represents this feedback?

Compatibility

Steps to reproduce

#include <memory>

// Produces: Error C2039: 'swap': is not a member of 'std::tr1::_Ptr_base<_Ty>'
template class std::tr1::shared_ptr<int>;

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\memory(1571): error C2039: 'swap' : is not a member of 'std::tr1::_Ptr_base<_Ty>'
1>         with
1>         [
1>             _Ty=int
1>         ]
1>         c:\program files (x86)\microsoft visual studio 10.0\vc\include\memory(1570) : while compiling class template member function 'void std::tr1::shared_ptr<_Ty>::swap(std::tr1::shared_ptr<_Ty> &&)'
1>         with
1>         [
1>             _Ty=int
1>         ]
1>         c:\users\jeremyc\documents\visual studio 2010\projects\testsmartptrswap\testsmartptrswap\testsmartptrswap.cpp(11) : see reference to class template instantiation 'std::tr1::shared_ptr<_Ty>' being compiled
1>         with
1>         [
1>             _Ty=int
1>         ]

Expected results

No error
File Attachments
File Name Submitted By Submitted On File Size  
TestSmartPtrSwap.cpp 3/4/2011 183 bytes
Sign in to post a comment.
Posted by Microsoft on 3/7/2011 at 7:47 PM
Hi,

Thanks for reporting this bug. We've already fixed it, and the fix will be available in VC11. According to the latest C++0x Working Paper, shared_ptr isn't supposed to have an rvalue swap, much less a broken one. We've removed it, allowing shared_ptr to be explicitly instantiated again.

If you have any further questions, feel free to E-mail me at stl@microsoft.com .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by Microsoft on 3/6/2011 at 6:21 PM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.
Posted by Microsoft on 3/4/2011 at 5:14 PM
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.