Faulty implementation of shared_ptr(nullptr_t) constructor - by Jim Barry

Status : 

 


1
0
Sign in
to vote
ID 771549 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 11/18/2012 1:42:10 PM
Access Restriction Public

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. 
Sign in to post a comment.
Posted by Deon [MSFT] 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 Stephan [MSFT] 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 Macy [MSFT] 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 Macy [MSFT] 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)