[Boost-bugs] [Boost C++ Libraries] #11132: Boost.Variant's boost::recursive_wrapper missing noexcept specified on move constructor

Subject: [Boost-bugs] [Boost C++ Libraries] #11132: Boost.Variant's boost::recursive_wrapper missing noexcept specified on move constructor
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-03-20 19:46:56


#11132: Boost.Variant's boost::recursive_wrapper missing noexcept specified on move
constructor
------------------------------+---------------------
 Reporter: peterhuene@… | Owner: ebf
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: variant
  Version: Boost 1.57.0 | Severity: Problem
 Keywords: |
------------------------------+---------------------
 Using a sequence container of recursive variant, like
 std::vector<recursive_variant_>, results in the variant type not being
 movable.

 Example:
 {{{
 #include <boost/variant.hpp>
 #include <vector>

 using namespace std;
 using namespace boost;

 struct foo
 {
         foo() = default;
         foo(foo&&) noexcept = default;
         foo(foo const&) = delete;
 };

 int main() {
         typedef make_recursive_variant<
                 foo,
                 vector<recursive_variant_>
>::type variant_type;

         vector<variant_type> value;
         value.emplace_back();
         variant_type other = std::move(value);
 }
 }}}

 This errors at the move assignment because variant_type is not movable.
 The reason it is not movable is because boost::recursive_wrapper's move
 constructor is not marked as noexcept, which is a requirement for vector
 to enable move semantics.

 Currently boost::recursive_wrapper's move constructor is not marked
 noexcept because it allocates a new T when being moved.

 I propose that boost::recursive_wrapper be changed to store a
 shared_ptr<T> instead of T* so that, when moved, we move the shared_ptr,
 which is a noexcept operation. For the overload that constructs by T&&,
 we can leave as not specifying noexcept and construct with:

 {{{
 _p(new T(detail::variant::move(operand)))
 }}}

 The copy semantics of boost::recursive_wrapper can be left as-is.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/11132>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:18 UTC