Fix warning about using implicitly defined copy constructor/assignment by completing the Rule of 5 for test allocator

This commit is contained in:
LeonineKing1199 2021-11-18 15:58:34 -08:00
parent c8abaf32ee
commit e29f762116

View File

@ -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<T>(x) {}
cxx11_allocator& operator=(cxx11_allocator const& x)
{
cxx11_allocator_base<T>::operator=(x);
return *this;
}
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
cxx11_allocator& operator=(cxx11_allocator&& x) BOOST_UNORDERED_NOEXCEPT
{
cxx11_allocator_base<T>::operator=(static_cast<cxx11_allocator&&>(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<T>(x) {}
cxx11_allocator& operator=(cxx11_allocator const& x)
{
cxx11_allocator_base<T>::operator=(x);
return *this;
}
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
cxx11_allocator& operator=(cxx11_allocator&& x) BOOST_UNORDERED_NOEXCEPT
{
cxx11_allocator_base<T>::operator=(static_cast<cxx11_allocator&&>(x));
return *this;
}
#endif
// When not propagating swap, allocators are always equal
// to avoid undefined behaviour.
bool operator==(cxx11_allocator const& x) const