From 122f69aa0022c2404640d7d00907799fc729427f Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Fri, 24 Sep 2021 14:26:24 +0300 Subject: [PATCH] properly initilize enable_shared_from_this if the type is const --- .../interprocess/smart_ptr/shared_ptr.hpp | 2 +- test/shared_ptr_test.cpp | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/boost/interprocess/smart_ptr/shared_ptr.hpp b/include/boost/interprocess/smart_ptr/shared_ptr.hpp index 91401c7..9f50ef0 100644 --- a/include/boost/interprocess/smart_ptr/shared_ptr.hpp +++ b/include/boost/interprocess/smart_ptr/shared_ptr.hpp @@ -56,7 +56,7 @@ namespace ipcdetail{ template inline void sp_enable_shared_from_this (shared_count const & pn - ,enable_shared_from_this *pe + ,enable_shared_from_this const*pe ,T *ptr) { diff --git a/test/shared_ptr_test.cpp b/test/shared_ptr_test.cpp index d0a6dae..e937450 100644 --- a/test/shared_ptr_test.cpp +++ b/test/shared_ptr_test.cpp @@ -596,6 +596,32 @@ void test_alias() shared_memory_object::remove(process_name.c_str()); } + +struct std_deleter +{ + typedef const void* pointer; + + void operator()(const void* p) const; +}; + +struct shared_from_this_tester: enable_shared_from_this< + const shared_from_this_tester, std::allocator, std_deleter +> {}; + +void std_deleter::operator()(const void* p) const +{ + delete static_cast(p); +} + + +void test_const_shared_from_this() +{ + shared_ptr, std_deleter> cptr( + new shared_from_this_tester() + ); + BOOST_TEST( cptr->shared_from_this().get() == cptr.get() ); +} + int main() { if(0 != simple_test()) @@ -608,5 +634,6 @@ int main() return 1; test_alias(); + test_const_shared_from_this(); }