Home Dashboard Directory Help
Search

Faulty implementation of shared_ptr(nullptr_t) constructor by Jim Barry


Status: 

Closed


1
0
Sign in
to vote
Type: Bug
ID: 771549
Opened: 11/18/2012 1:42:10 PM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

The constructor that initializes a shared_ptr from nullptr is faulty. According to the C++11 Standard (section 20.7.2.2), this constructor should be equivalent to the default constructor:

constexpr shared_ptr(nullptr_t) : shared_ptr() { }

Unfortunately, the implementation in Visual C++ 2012 looks like this:

shared_ptr(nullptr_t)
        {    // construct with nullptr
        _Resetp((_Ty *)0);
        }

This causes the wasteful allocation of an internal control block, which pointlessly guards a null pointer. It also causes a compiler error in the case that "_Ty" has a protected destructor.
Details
Sign in to post a comment.
Posted by Microsoft on 4/29/2014 at 12:31 PM
Thank you for reporting this issue. This issue has been fixed in Visual Studio 2013. You can install a trial version of Visual Studio 2013 with the fix from: http://go.microsoft.com/?linkid=9832436
Posted by Microsoft on 12/17/2012 at 4:48 PM
Hi,

Thanks for reporting this bug. We've fixed it, and the fix will be available in the next release of our C++ Standard Library implementation.

Note: Connect doesn't notify me about comments. If you have any further questions, please E-mail me.

Stephan T. Lavavej
Senior Developer - Visual C++ Libraries
stl@microsoft.com
Posted by Microsoft on 11/19/2012 at 9:29 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 11/19/2012 at 9:51 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.