diff --git a/include/boost/variant2/variant.hpp b/include/boost/variant2/variant.hpp index de9b8d3..12e58ab 100644 --- a/include/boost/variant2/variant.hpp +++ b/include/boost/variant2/variant.hpp @@ -1201,7 +1201,7 @@ public: // assignment template..., detail::is_trivially_copy_assignable...>, E1> + class E2 = mp11::mp_if..., detail::is_trivially_copy_constructible..., detail::is_trivially_copy_assignable...>, E1> > BOOST_CXX14_CONSTEXPR variant& operator=( variant const & r ) noexcept { @@ -1232,7 +1232,7 @@ private: public: template..., detail::is_trivially_copy_assignable...>>, E1>, + class E2 = mp11::mp_if..., detail::is_trivially_copy_constructible..., detail::is_trivially_copy_assignable...>>, E1>, class E3 = mp11::mp_if..., std::is_copy_assignable...>, E1> > BOOST_CXX14_CONSTEXPR variant& operator=( variant const & r ) @@ -1243,7 +1243,7 @@ public: } template..., detail::is_trivially_move_assignable...>, E1> + class E2 = mp11::mp_if..., detail::is_trivially_move_constructible..., detail::is_trivially_move_assignable...>, E1> > BOOST_CXX14_CONSTEXPR variant& operator=( variant && r ) noexcept { @@ -1274,7 +1274,7 @@ private: public: template..., detail::is_trivially_move_assignable...>>, E1>, + class E2 = mp11::mp_if..., detail::is_trivially_move_constructible..., detail::is_trivially_move_assignable...>>, E1>, class E3 = mp11::mp_if..., std::is_move_assignable...>, E1> > variant& operator=( variant && r ) diff --git a/test/Jamfile b/test/Jamfile index 5d869a0..714f5e2 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -68,3 +68,6 @@ run variant_valueless.cpp ; run variant_copy_construct_throw.cpp ; run variant_move_construct_throw.cpp ; run variant_convert_construct_throw.cpp ; + +run variant_copy_assign_throw.cpp ; +run variant_move_assign_throw.cpp ; diff --git a/test/variant_copy_assign_throw.cpp b/test/variant_copy_assign_throw.cpp new file mode 100644 index 0000000..3b39cfb --- /dev/null +++ b/test/variant_copy_assign_throw.cpp @@ -0,0 +1,51 @@ + +// Copyright 2019 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include + +using namespace boost::variant2; + +struct Y1 +{ + Y1(){} // =default fails on msvc-14.0 + + Y1(Y1 const&) + { + throw std::runtime_error( "Y1(Y1 const&)" ); + } + + Y1& operator=(Y1 const&) = default; +}; + +struct Y2 +{ + Y2(){} + + Y2(Y2 const&) + { + throw std::runtime_error( "Y2(Y2 const&)" ); + } + + Y2& operator=(Y2 const&) = default; +}; + +void test() +{ + variant v1( in_place_type_t{} ); + variant v2( in_place_type_t{} ); + + BOOST_TEST_THROWS( v1 = v2, std::runtime_error ) +} + +int main() +{ + test(); + return boost::report_errors(); +} diff --git a/test/variant_move_assign_throw.cpp b/test/variant_move_assign_throw.cpp new file mode 100644 index 0000000..59b3b8e --- /dev/null +++ b/test/variant_move_assign_throw.cpp @@ -0,0 +1,51 @@ + +// Copyright 2019 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include + +using namespace boost::variant2; + +struct Y1 +{ + Y1(){} // =default fails on msvc-14.0 + + Y1(Y1&&) + { + throw std::runtime_error( "Y1(Y1&&)" ); + } + + Y1& operator=(Y1&&) = default; +}; + +struct Y2 +{ + Y2(){} + + Y2(Y2&&) + { + throw std::runtime_error( "Y2(Y2&&)" ); + } + + Y2& operator=(Y2&&) = default; +}; + +void test() +{ + variant v1( in_place_type_t{} ); + variant v2( in_place_type_t{} ); + + BOOST_TEST_THROWS( v1 = std::move( v2 ), std::runtime_error ) +} + +int main() +{ + test(); + return boost::report_errors(); +}