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

--- 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:
       //

Reply via email to