]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/smart_ptr/test/intrusive_ptr_move_test.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / smart_ptr / test / intrusive_ptr_move_test.cpp
index 2f2f652c50fbacfae8313a267c009ff3f3e1017e..9079c8806aeb82eb0980314eafb8be6824608b93 100644 (file)
@@ -41,7 +41,7 @@ class base
 {
 private:
 
-    boost::detail::atomic_count use_count_;
+    mutable boost::detail::atomic_count use_count_;
 
     base(base const &);
     base & operator=(base const &);
@@ -69,24 +69,24 @@ public:
 
 #if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
 
-    inline friend void intrusive_ptr_add_ref(base * p)
+    inline friend void intrusive_ptr_add_ref(base const * p)
     {
         ++p->use_count_;
     }
 
-    inline friend void intrusive_ptr_release(base * p)
+    inline friend void intrusive_ptr_release(base const * p)
     {
         if(--p->use_count_ == 0) delete p;
     }
 
 #else
 
-    void add_ref()
+    void add_ref() const
     {
         ++use_count_;
     }
 
-    void release()
+    void release() const
     {
         if(--use_count_ == 0) delete this;
     }
@@ -103,12 +103,12 @@ long base::instances = 0;
 namespace boost
 {
 
-inline void intrusive_ptr_add_ref(N::base * p)
+inline void intrusive_ptr_add_ref(N::base const * p)
 {
     p->add_ref();
 }
 
-inline void intrusive_ptr_release(N::base * p)
+inline void intrusive_ptr_release(N::base const * p)
 {
     p->release();
 }
@@ -209,6 +209,58 @@ int main()
         BOOST_TEST( N::base::instances == 0 );
     }
 
+    {
+        boost::intrusive_ptr<X> px( new Y );
+
+        X * px2 = px.get();
+
+        boost::intrusive_ptr<Y> py = boost::static_pointer_cast<Y>( std::move( px ) );
+        BOOST_TEST( py.get() == px2 );
+        BOOST_TEST( px.get() == 0 );
+        BOOST_TEST( py->use_count() == 1 );
+    }
+
+    BOOST_TEST( N::base::instances == 0 );
+
+    {
+        boost::intrusive_ptr<X const> px( new X );
+
+        X const * px2 = px.get();
+
+        boost::intrusive_ptr<X> px3 = boost::const_pointer_cast<X>( std::move( px ) );
+        BOOST_TEST( px3.get() == px2 );
+        BOOST_TEST( px.get() == 0 );
+        BOOST_TEST( px3->use_count() == 1 );
+    }
+
+    BOOST_TEST( N::base::instances == 0 );
+
+    {
+        boost::intrusive_ptr<X> px( new Y );
+
+        X * px2 = px.get();
+
+        boost::intrusive_ptr<Y> py = boost::dynamic_pointer_cast<Y>( std::move( px ) );
+        BOOST_TEST( py.get() == px2 );
+        BOOST_TEST( px.get() == 0 );
+        BOOST_TEST( py->use_count() == 1 );
+    }
+
+    BOOST_TEST( N::base::instances == 0 );
+
+    {
+        boost::intrusive_ptr<X> px( new X );
+
+        X * px2 = px.get();
+
+        boost::intrusive_ptr<Y> py = boost::dynamic_pointer_cast<Y>( std::move( px ) );
+        BOOST_TEST( py.get() == 0 );
+        BOOST_TEST( px.get() == px2 );
+        BOOST_TEST( px->use_count() == 1 );
+    }
+
+    BOOST_TEST( N::base::instances == 0 );
+
     return boost::report_errors();
 }