[Bug libstdc++/55123] [C++11] Construction of shared_ptr<const T> from unique_ptr<const T> fails

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Oct 29 18:24:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55123

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-10-29 18:23:58 UTC ---
Actually the fix is trivial, we never need allocator<_Tp> , so can just ensure
we never instantiate allocator<_Tp>, then it doesn't matter if _Tp is const.


--- bits/shared_ptr_base.h.orig 2012-10-29 18:22:44.904507722 +0000
+++ bits/shared_ptr_base.h      2012-10-29 18:22:46.654191961 +0000
@@ -622,7 +622,7 @@
        _S_create_from_up(std::unique_ptr<_Tp, _Del>&& __r,
          typename std::enable_if<!std::is_reference<_Del>::value>::type* = 0)
        {
-         return new _Sp_counted_deleter<_Tp*, _Del, std::allocator<_Tp>,
+         return new _Sp_counted_deleter<_Tp*, _Del, std::allocator<void>,
            _Lp>(__r.get(), __r.get_deleter());
        }

@@ -633,7 +633,7 @@
        {
          typedef typename std::remove_reference<_Del>::type _Del1;
          typedef std::reference_wrapper<_Del1> _Del2;
-         return new _Sp_counted_deleter<_Tp*, _Del2, std::allocator<_Tp>,
+         return new _Sp_counted_deleter<_Tp*, _Del2, std::allocator<void>,
            _Lp>(__r.get(), std::ref(__r.get_deleter()));
        }



More information about the Gcc-bugs mailing list