From e29f762116426d4ee4e7cf6c51382bbd43547eb8 Mon Sep 17 00:00:00 2001 From: LeonineKing1199 Date: Thu, 18 Nov 2021 15:58:34 -0800 Subject: [PATCH] Fix warning about using implicitly defined copy constructor/assignment by completing the Rule of 5 for test allocator --- test/objects/cxx11_allocator.hpp | 66 +++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/test/objects/cxx11_allocator.hpp b/test/objects/cxx11_allocator.hpp index e96f8d94..12ee6be6 100644 --- a/test/objects/cxx11_allocator.hpp +++ b/test/objects/cxx11_allocator.hpp @@ -13,7 +13,14 @@ #include "../helpers/fwd.hpp" #include "../helpers/memory.hpp" -namespace test { +#if defined(BOOST_NO_CXX11_NOEXCEPT) +#define BOOST_UNORDERED_NOEXCEPT +#else +#define BOOST_UNORDERED_NOEXCEPT noexcept +#endif + +namespace test +{ struct allocator_false { enum @@ -178,8 +185,37 @@ namespace test { detail::tracker.allocator_ref(); } +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + cxx11_allocator_base(cxx11_allocator_base&& x) BOOST_UNORDERED_NOEXCEPT + { + tag_ = x.tag_; + selected_ = x.selected_; + + x.tag_ = -1; + x.selected_ = -1; + } +#endif + ~cxx11_allocator_base() { detail::tracker.allocator_unref(); } + cxx11_allocator_base& operator=(cxx11_allocator_base const& x) + { + tag_ = x.tag_; + selected_ = x.selected_; + return *this; + } + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + cxx11_allocator_base& operator=( + cxx11_allocator_base&& x) BOOST_UNORDERED_NOEXCEPT + { + tag_ = x.tag_; + selected_ = x.selected_; + + return *this; + } +#endif + pointer address(reference r) { return pointer(&r); } const_pointer address(const_reference r) { return const_pointer(&r); } @@ -264,6 +300,20 @@ namespace test { cxx11_allocator(cxx11_allocator const& x) : cxx11_allocator_base(x) {} + cxx11_allocator& operator=(cxx11_allocator const& x) + { + cxx11_allocator_base::operator=(x); + return *this; + } + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + cxx11_allocator& operator=(cxx11_allocator&& x) BOOST_UNORDERED_NOEXCEPT + { + cxx11_allocator_base::operator=(static_cast(x)); + return *this; + } +#endif + // When not propagating swap, allocators are always equal // to avoid undefined behaviour. bool operator==(cxx11_allocator const& x) const @@ -307,6 +357,20 @@ namespace test { cxx11_allocator(cxx11_allocator const& x) : cxx11_allocator_base(x) {} + cxx11_allocator& operator=(cxx11_allocator const& x) + { + cxx11_allocator_base::operator=(x); + return *this; + } + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + cxx11_allocator& operator=(cxx11_allocator&& x) BOOST_UNORDERED_NOEXCEPT + { + cxx11_allocator_base::operator=(static_cast(x)); + return *this; + } +#endif + // When not propagating swap, allocators are always equal // to avoid undefined behaviour. bool operator==(cxx11_allocator const& x) const