boostorg / container

STL-like containers from Boost
http://www.boost.org/libs/container/
Boost Software License 1.0
96 stars 116 forks source link

small_vector does not propagate no throw properties of move operation of contained type #141

Closed adesitter closed 3 years ago

adesitter commented 4 years ago

Considering

include <boost/container/small_vector.hpp>

include

struct S_trivial { int i; }; static_assert(std::is_nothrow_move_constructible::value, ""); static_assert(std::is_nothrow_move_assignable::value, "");

struct S1 { int i = 0; }; static_assert(std::is_nothrow_move_constructible::value, ""); static_assert(std::is_nothrow_move_assignable::value, "");

struct S2 { int i = 0; S2(S2&&) noexcept; S2& operator=(S2&&) noexcept; }; static_assert(std::is_nothrow_move_constructible::value, ""); static_assert(std::is_nothrow_move_assignable::value, "");

// Succeed static_assert(std::is_nothrow_move_constructible<boost::container::small_vector<S_trivial, 1>>::value, ""); static_assert(std::is_nothrow_move_assignable<boost::container::small_vector<S_trivial, 1>>::value, "");

// Fail static_assert(std::is_nothrow_move_constructible<boost::container::small_vector<S1, 1>>::value, ""); static_assert(std::is_nothrow_move_assignable<boost::container::small_vector<S1, 1>>::value, "");

// Fail static_assert(std::is_nothrow_move_constructible<boost::container::small_vector<S2, 1>>::value, ""); static_assert(std::is_nothrow_move_assignable<boost::container::small_vector<S2, 1>>::value, "");

and using g++ 9.2 and boost 1.71, one can see that for S1 and S2 the noexcept propertties of the move operations are not propagated.

adesitter commented 4 years ago

It turns out that you can make it work with:

include

define BOOST_MOVE_HAS_NOTHROW_MOVE_ASSIGN(T) std::is_nothrow_move_assignable::value

include <boost/container/small_vector.hpp>

adesitter commented 4 years ago

This is the same issue as https://svn.boost.org/trac10/ticket/13487

palebedev commented 3 years ago

And likely related to more recent changes described in https://github.com/boostorg/move/issues/35 .

igaztanaga commented 3 years ago

Many thanks for the report and the patience. Apart from the boostorg/move#35, small_vector's move constructor incorrectly depended on is_nothrow_move_assignable.