From 98d7763c81cbe334f2dc4f10102c71cf13a095e8 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 28 Sep 2022 11:28:31 +0200 Subject: [PATCH] vlc_shared_data_ptr: accept implicit ctor for null The main constructor, accepting a pointer, is explicit: my_ptr_type *p = ...; MySharedPtr ptr = p; /* invalid */ MySharedPtr ptr{ p }; /* ok */ This prevents to mistakenly assign a pointer to a shared pointer. However, assignment to nullptr should be acceptable: MySharedPtr ptr = nullptr; /* should be ok */ --- include/vlc_cxx_helpers.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/vlc_cxx_helpers.hpp b/include/vlc_cxx_helpers.hpp index 6da64337e9..ba33fb061c 100644 --- a/include/vlc_cxx_helpers.hpp +++ b/include/vlc_cxx_helpers.hpp @@ -171,6 +171,11 @@ public: HOLD(ptr); } + vlc_shared_data_ptr(std::nullptr_t) + : ptr(nullptr) + { + } + vlc_shared_data_ptr(const vlc_shared_data_ptr &other) : vlc_shared_data_ptr(other.ptr) {}