1
2// Copyright 2019 Peter Dimov
3//
4// Distributed under the Boost Software License, Version 1.0.
5//
6// See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt
8
9#if defined(_MSC_VER)
10# pragma warning( disable: 4702 ) // unreachable code
11#endif
12
13#include <boost/variant2/variant.hpp>
14#include <boost/core/lightweight_test.hpp>
15#include <stdexcept>
16
17using namespace boost::variant2;
18
19struct Y1
20{
21 Y1() noexcept {} // =default fails on msvc-14.0
22
23 Y1(Y1&&)
24 {
25 throw std::runtime_error( "Y1(Y1&&)" );
26 }
27
28 Y1& operator=(Y1&&) = default;
29};
30
31struct Y2
32{
33 Y2() noexcept {}
34
35 Y2(Y2&&)
36 {
37 throw std::runtime_error( "Y2(Y2&&)" );
38 }
39
40 Y2& operator=(Y2&&) = default;
41};
42
43void test()
44{
45 variant<Y1, Y2> v1( in_place_type_t<Y1>{} );
46 variant<Y1, Y2> v2( in_place_type_t<Y2>{} );
47
48 BOOST_TEST_THROWS( v1 = std::move( v2 ), std::runtime_error )
49}
50
51int main()
52{
53 test();
54 return boost::report_errors();
55}
56

source code of boost/libs/variant2/test/variant_move_assign_throw.cpp