Patchwork [v2,4.6] shared_ptr needs explicit copy constructor

login
register
mail settings
Submitter Chase Douglas
Date Jan. 3, 2012, 7:17 p.m.
Message ID <1325618257-2435-1-git-send-email-chase.douglas@canonical.com>
Download mbox | patch
Permalink /patch/134060/
State New
Headers show

Comments

Chase Douglas - Jan. 3, 2012, 7:17 p.m.
When compiling with a compiler that is conformant to the c++11 spec for PR
c++/50500, std::shared_ptr must have an explicitly defined copy constructor.

Backported from revisions 180159 and 173882. The rest of the revisions include
new functionality, so only this part should be applied to 4.6.

This has been tested on an x86_64 host with g++ 4.6 and clang 3.0 as the C++
compilers. A shared library utilizing std::shared_ptr with an extensive
testsuite has shown no regressions when compiled with g++. Unfortunately, gtest
does not compile under clang, so I cannot verify correct behavior under that
scenario.

PR c++/50500
* include/bits/shared_ptr.h: Add lazy copy ops even if there's a move
* include/bits/shared_ptr_base.h: Define special member functions as defaulted
Jonathan Wakely - Jan. 3, 2012, 8:34 p.m.
On 3 January 2012 19:17, Chase Douglas wrote:
>
> PR c++/50500
> * include/bits/shared_ptr.h: Add lazy copy ops even if there's a move

That is the ChangeLog for the front-end part of 50500, isn't it?
Should be something like "Default copy ctor and assignment."

Otherwise this is OK to check in, thanks.

(Do you need me to do the actual check in or can Matthias do it?)
Chase Douglas - Jan. 3, 2012, 8:45 p.m.
On 01/03/2012 12:34 PM, Jonathan Wakely wrote:
> On 3 January 2012 19:17, Chase Douglas wrote:
>>
>> PR c++/50500
>> * include/bits/shared_ptr.h: Add lazy copy ops even if there's a move
> 
> That is the ChangeLog for the front-end part of 50500, isn't it?
> Should be something like "Default copy ctor and assignment."

I just copied the changelog text from commit 180159. That was the
suggested approach in the style guidelines, though I do agree that
"Default copy ctor and assignment" makes more sense. What do you suggest
I do?

> Otherwise this is OK to check in, thanks.
> 
> (Do you need me to do the actual check in or can Matthias do it?)

I don't know if Matthias can do it. I copied him to keep him in the loop
since he is the toolchain maintainer for Ubuntu and I would like to get
this into the next release. If you have access, I would suggest you do
it since Matthias hasn't been involved in the generation or review of
this patch.

Thanks!

-- Chase
Jonathan Wakely - Jan. 3, 2012, 8:49 p.m.
On 3 January 2012 20:45, Chase Douglas wrote:
> On 01/03/2012 12:34 PM, Jonathan Wakely wrote:
>> On 3 January 2012 19:17, Chase Douglas wrote:
>>>
>>> PR c++/50500
>>> * include/bits/shared_ptr.h: Add lazy copy ops even if there's a move
>>
>> That is the ChangeLog for the front-end part of 50500, isn't it?
>> Should be something like "Default copy ctor and assignment."
>
> I just copied the changelog text from commit 180159. That was the
> suggested approach in the style guidelines, though I do agree that
> "Default copy ctor and assignment" makes more sense. What do you suggest
> I do?

Use the text from the libstdc++-v3/ChangeLog for the shared_prt.h change:
http://gcc.gnu.org/viewcvs/trunk/libstdc%2B%2B-v3/ChangeLog?r1=180159&r2=180158&pathrev=180159

You can look in libstdc++-v3/ChangeLog to find that too.

Jason's commit message was the text from gcc/cp/ChangeLog, but he
touched several parts (the C++ front-end, the C++ library and the
testsuite) which all have their own ChangeLog files.


>> Otherwise this is OK to check in, thanks.
>>
>> (Do you need me to do the actual check in or can Matthias do it?)
>
> I don't know if Matthias can do it. I copied him to keep him in the loop
> since he is the toolchain maintainer for Ubuntu and I would like to get
> this into the next release. If you have access, I would suggest you do
> it since Matthias hasn't been involved in the generation or review of
> this patch.

OK, I'll do it.

Thanks.

Patch

--- a/src/libstdc++-v3/include/bits/shared_ptr.h	(revision 180158)
+++ b/src/libstdc++-v3/include/bits/shared_ptr.h	(revision 180159)
@@ -211,6 +211,7 @@ 
        *  @param  __r  A %shared_ptr.
        *  @post   get() == __r.get() && use_count() == __r.use_count()
        */
+      shared_ptr(const shared_ptr&) = default; // never throws
       template<typename _Tp1, typename = typename
 	       std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
 	shared_ptr(const shared_ptr<_Tp1>& __r)
@@ -264,6 +265,7 @@ 
       constexpr shared_ptr(nullptr_t __p)
       : __shared_ptr<_Tp>(__p) { }
 
+      shared_ptr& operator=(const shared_ptr&) = default;
       template<typename _Tp1>
 	shared_ptr&
 	operator=(const shared_ptr<_Tp1>& __r) // never throws
--- a/src/libstdc++-v3/include/bits/shared_ptr_base.h	2011/03/22 15:15:03	171293
+++ b/src/libstdc++-v3/include/bits/shared_ptr_base.h	2011/05/18 22:59:17	173882
@@ -799,7 +801,8 @@ 
 	: _M_ptr(__p), _M_refcount(__r._M_refcount) // never throws
 	{ }
 
-      //  generated copy constructor, assignment, destructor are fine.
+      __shared_ptr(const __shared_ptr&) = default; // never throws
+      __shared_ptr& operator=(const __shared_ptr&) = default; // never throws
 
       template<typename _Tp1, typename = typename
 	       std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
@@ -1216,7 +1220,8 @@ 
       : _M_ptr(0), _M_refcount() // never throws
       { }
 
-      // Generated copy constructor, assignment, destructor are fine.
+      __weak_ptr(const __weak_ptr&) = default; // never throws
+      __weak_ptr& operator=(const __weak_ptr&) = default; // never throws
 
       // The "obvious" converting constructor implementation:
       //