Ticket #7911: varant_noexcept.patch

File varant_noexcept.patch, 3.8 KB (added by Antony Polukhin, 9 years ago)

Patch to resolve this issue

  • boost/variant/variant.hpp

     
    226226
    227227#endif // BOOST_MPL_CFG_MSVC_60_ETI_BUG workaround
    228228
     229#ifndef BOOST_NO_CXX11_NOEXCEPT
    229230///////////////////////////////////////////////////////////////////////////////
     231// (detail) metafunction is_variant_move_noexcept
     232//
     233// Returns true_type if all the types are nothrow move constructible.
     234//
     235template <class Types>
     236struct is_variant_move_noexcept {
     237    typedef typename boost::mpl::find_if<
     238        Types, mpl::not_<boost::is_nothrow_move_constructible<boost::mpl::_1> >
     239    >::type iterator_t;
     240
     241    typedef typename boost::mpl::end<Types>::type end_t;
     242    typedef typename boost::is_same<
     243        iterator_t, end_t
     244    >::type type;
     245};
     246#endif // BOOST_NO_CXX11_NOEXCEPT
     247
     248///////////////////////////////////////////////////////////////////////////////
    230249// (detail) metafunction make_storage
    231250//
    232251// Provides an aligned storage type capable of holding any of the types
     
    12891308          internal_types, never_uses_backup_flag
    12901309        >::type storage_t;
    12911310
     1311#ifndef BOOST_NO_CXX11_NOEXCEPT
     1312    typedef typename detail::variant::is_variant_move_noexcept<
     1313        internal_types
     1314    > variant_move_noexcept;
     1315#endif
     1316
    12921317private: // helpers, for representation (below)
    12931318
    12941319    // which_ on:
     
    13751400
    13761401public: // structors
    13771402
    1378     ~variant()
     1403    ~variant() BOOST_NOEXCEPT
    13791404    {
    13801405        destroy_content();
    13811406    }
     
    17661791    }
    17671792   
    17681793#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
    1769     variant(variant&& operand)
     1794    variant(variant&& operand) BOOST_NOEXCEPT_IF(variant_move_noexcept::type::value)
    17701795    {
    17711796        // Move the value of operand into *this...
    17721797        detail::variant::move_into visitor( storage_.address() );
     
    21772202    }
    21782203
    21792204#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
    2180     variant& operator=(variant&& rhs)
     2205    variant& operator=(variant&& rhs) BOOST_NOEXCEPT_IF(variant_move_noexcept::type::value)
    21812206    {
    21822207        variant_assign( detail::variant::move(rhs) );
    21832208        return *this;
  • libs/variant/test/rvalue_test.cpp

     
    33// See http://www.boost.org for updates, documentation, and revision history.
    44//-----------------------------------------------------------------------------
    55//
    6 // Copyright (c) 2012
    7 // Antony Polukhin
     6// Copyright (c) 2012-2013 Antony Polukhin
    87//
    98// Distributed under the Boost Software License, Version 1.0. (See
    109// accompanying file LICENSE_1_0.txt or copy at
     
    1413
    1514#include "boost/test/minimal.hpp"
    1615#include "boost/variant.hpp"
     16#include "boost/type_traits/is_nothrow_move_assignable.hpp"
    1717
    1818// This test requires rvalue references support
    1919
     
    3434    BOOST_CHECK(true);
    3535}
    3636
     37void run_moves_are_noexcept()
     38{
     39    BOOST_CHECK(true);
     40}
     41
    3742#else
    3843
    3944class move_copy_conting_class {
     
    177182    BOOST_CHECK(vi.which() == 1);
    178183}
    179184
     185void run_moves_are_noexcept() {
     186#ifndef BOOST_NO_CXX11_NOEXCEPT
     187    typedef boost::variant<int, short, double> variant_noexcept_t;
     188    BOOST_CHECK(boost::is_nothrow_move_assignable<variant_noexcept_t>::value);
     189    BOOST_CHECK(boost::is_nothrow_move_constructible<variant_noexcept_t>::value);
     190
     191    typedef boost::variant<int, short, double, move_only_structure> variant_except_t;
     192    BOOST_CHECK(!boost::is_nothrow_move_assignable<variant_except_t>::value);
     193    BOOST_CHECK(!boost::is_nothrow_move_constructible<variant_except_t>::value);
    180194#endif
     195}
    181196
     197#endif
    182198
     199
    183200int test_main(int , char* [])
    184201{
    185202   run();
    186203   run1();
    187204   run_move_only();
     205   run_moves_are_noexcept();
    188206   return 0;
    189 }
    190  No newline at end of file
     207}