From 5e9443a40081e9311cc6b9623ac90e01a6fde010 Mon Sep 17 00:00:00 2001 From: Markus Blatt <mblatt@dune-project.org> Date: Sun, 21 Oct 2012 16:14:21 +0000 Subject: [PATCH] Support counting even if the pointer type is converted to a compatible base class. Previously class A{}; class B: public A{}; shared_ptr<A> b(new B); shared_ptr<B> b(a); b.get_count()==1 && b.get_count()==1 would wrongly hold true. [[Imported from SVN: r7046]] --- dune/common/test/shared_ptrtest.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/dune/common/test/shared_ptrtest.cc b/dune/common/test/shared_ptrtest.cc index 6085ce599..c5a9ad655 100644 --- a/dune/common/test/shared_ptrtest.cc +++ b/dune/common/test/shared_ptrtest.cc @@ -65,6 +65,23 @@ int main(){ // test conversion in make_shared shared_ptr<A> a=test_make_shared(); + { + shared_ptr<B> b(new B); + a=b; + + if(b.use_count()!=2) { + std::cout << "Reference count is wrong! "<<__LINE__<<":"<< + __FILE__<<std::endl; + ret=1; + } + + if(a.use_count()!=2) { + std::cout << "Reference count is wrong! "<<__LINE__<<":"<< + __FILE__<<std::endl; + ret=1; + } + + } // print the type of the shared_ptr, so we know whether we are // checking dune's shared_ptr or some std one std::cout << "=== checking shared_ptr type: " << className(foo) -- GitLab