From e29f762116426d4ee4e7cf6c51382bbd43547eb8 Mon Sep 17 00:00:00 2001 From: LeonineKing1199 Date: Thu, 18 Nov 2021 15:58:34 -0800 Subject: [PATCH 1/4] 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 From fe439890e8f93cf3e1c0cf4106370727941dcf55 Mon Sep 17 00:00:00 2001 From: LeonineKing1199 Date: Fri, 19 Nov 2021 10:10:02 -0800 Subject: [PATCH 2/4] Remove unneeded macro as Config defines `BOOST_NOEXCEPT` --- test/objects/cxx11_allocator.hpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/test/objects/cxx11_allocator.hpp b/test/objects/cxx11_allocator.hpp index 12ee6be6..0dc4ce24 100644 --- a/test/objects/cxx11_allocator.hpp +++ b/test/objects/cxx11_allocator.hpp @@ -13,12 +13,6 @@ #include "../helpers/fwd.hpp" #include "../helpers/memory.hpp" -#if defined(BOOST_NO_CXX11_NOEXCEPT) -#define BOOST_UNORDERED_NOEXCEPT -#else -#define BOOST_UNORDERED_NOEXCEPT noexcept -#endif - namespace test { struct allocator_false @@ -186,7 +180,7 @@ namespace test } #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) - cxx11_allocator_base(cxx11_allocator_base&& x) BOOST_UNORDERED_NOEXCEPT + cxx11_allocator_base(cxx11_allocator_base&& x) BOOST_NOEXCEPT { tag_ = x.tag_; selected_ = x.selected_; @@ -207,7 +201,7 @@ namespace test #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) cxx11_allocator_base& operator=( - cxx11_allocator_base&& x) BOOST_UNORDERED_NOEXCEPT + cxx11_allocator_base&& x) BOOST_NOEXCEPT { tag_ = x.tag_; selected_ = x.selected_; @@ -307,7 +301,7 @@ namespace test } #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) - cxx11_allocator& operator=(cxx11_allocator&& x) BOOST_UNORDERED_NOEXCEPT + cxx11_allocator& operator=(cxx11_allocator&& x) BOOST_NOEXCEPT { cxx11_allocator_base::operator=(static_cast(x)); return *this; @@ -364,7 +358,7 @@ namespace test } #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) - cxx11_allocator& operator=(cxx11_allocator&& x) BOOST_UNORDERED_NOEXCEPT + cxx11_allocator& operator=(cxx11_allocator&& x) BOOST_NOEXCEPT { cxx11_allocator_base::operator=(static_cast(x)); return *this; From 6984e6a4f2c99ec6208d4fb1e96bf2ee30167b5b Mon Sep 17 00:00:00 2001 From: LeonineKing1199 Date: Tue, 23 Nov 2021 10:57:26 -0800 Subject: [PATCH 3/4] Remove unnecessary move support --- test/objects/cxx11_allocator.hpp | 38 -------------------------------- 1 file changed, 38 deletions(-) diff --git a/test/objects/cxx11_allocator.hpp b/test/objects/cxx11_allocator.hpp index 0dc4ce24..3e5f11c8 100644 --- a/test/objects/cxx11_allocator.hpp +++ b/test/objects/cxx11_allocator.hpp @@ -179,17 +179,6 @@ namespace test detail::tracker.allocator_ref(); } -#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) - cxx11_allocator_base(cxx11_allocator_base&& x) BOOST_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) @@ -199,17 +188,6 @@ namespace test return *this; } -#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) - cxx11_allocator_base& operator=( - cxx11_allocator_base&& x) BOOST_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); } @@ -300,14 +278,6 @@ namespace test return *this; } -#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) - cxx11_allocator& operator=(cxx11_allocator&& x) BOOST_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 @@ -357,14 +327,6 @@ namespace test return *this; } -#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) - cxx11_allocator& operator=(cxx11_allocator&& x) BOOST_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 From 69b882a14b3a99ebefda79029c4f72a985105cf3 Mon Sep 17 00:00:00 2001 From: LeonineKing1199 Date: Tue, 23 Nov 2021 11:10:03 -0800 Subject: [PATCH 4/4] Add defaulted copy assignment operators when supported --- test/objects/cxx11_allocator.hpp | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/test/objects/cxx11_allocator.hpp b/test/objects/cxx11_allocator.hpp index 3e5f11c8..8f3a7711 100644 --- a/test/objects/cxx11_allocator.hpp +++ b/test/objects/cxx11_allocator.hpp @@ -181,12 +181,9 @@ namespace test ~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_DEFAULTED_FUNCTIONS) + cxx11_allocator_base& operator=(cxx11_allocator_base const& x) = default; +#endif pointer address(reference r) { return pointer(&r); } @@ -272,11 +269,9 @@ 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_DEFAULTED_FUNCTIONS) + cxx11_allocator& operator=(cxx11_allocator const& x) = default; +#endif // When not propagating swap, allocators are always equal // to avoid undefined behaviour. @@ -321,11 +316,9 @@ 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_DEFAULTED_FUNCTIONS) + cxx11_allocator& operator=(cxx11_allocator const& x) = default; +#endif // When not propagating swap, allocators are always equal // to avoid undefined behaviour.