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 17 using namespace boost::variant2; 18 19 struct Y1 20 { Y1Y121 Y1() noexcept {} // =default fails on msvc-14.0 22 Y1Y123 Y1(Y1 const&) 24 { 25 throw std::runtime_error( "Y1(Y1 const&)" ); 26 } 27 28 Y1& operator=(Y1 const&) = default; 29 }; 30 31 struct Y2 32 { Y2Y233 Y2() noexcept {} 34 Y2Y235 Y2(Y2 const&) 36 { 37 throw std::runtime_error( "Y2(Y2 const&)" ); 38 } 39 40 Y2& operator=(Y2 const&) = default; 41 }; 42 test()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 = v2, std::runtime_error ) 49 } 50 main()51int main() 52 { 53 test(); 54 return boost::report_errors(); 55 } 56