diff --git a/src/agnocastlib/include/agnocast_smart_pointer.hpp b/src/agnocastlib/include/agnocast_smart_pointer.hpp index e186e721..32518379 100644 --- a/src/agnocastlib/include/agnocast_smart_pointer.hpp +++ b/src/agnocastlib/include/agnocast_smart_pointer.hpp @@ -73,7 +73,7 @@ class ipc_shared_ptr timestamp_(r.timestamp_), is_created_by_sub_(r.is_created_by_sub_) { - if (!is_created_by_sub_) { + if (ptr_ != nullptr && !is_created_by_sub_) { RCLCPP_ERROR( logger, "Copying an ipc_shared_ptr is not allowed if it was created by borrow_loaned_message()."); diff --git a/src/agnocastlib/test/test_agnocast_smart_pointer.cpp b/src/agnocastlib/test/test_agnocast_smart_pointer.cpp index 498e7d75..cabfc80a 100644 --- a/src/agnocastlib/test/test_agnocast_smart_pointer.cpp +++ b/src/agnocastlib/test/test_agnocast_smart_pointer.cpp @@ -72,6 +72,14 @@ TEST_F(AgnocastSmartPointerTest, copy_constructor_isnt_created_by_sub) "Copying an ipc_shared_ptr is not allowed if it was created by borrow_loaned_message()."); } +TEST_F(AgnocastSmartPointerTest, copy_constructor_empty) +{ + EXPECT_GLOBAL_CALL(increment_rc_core, increment_rc_core(dummy_tn, dummy_pid, dummy_ts)).Times(0); + EXPECT_GLOBAL_CALL(decrement_rc, decrement_rc(dummy_tn, dummy_pid, dummy_ts)).Times(0); + agnocast::ipc_shared_ptr sut; + EXPECT_NO_THROW(agnocast::ipc_shared_ptr sut2{sut}); +} + TEST_F(AgnocastSmartPointerTest, move_constructor_normal) { int * ptr = new int(0);