mirror of
https://github.com/boostorg/variant2.git
synced 2025-07-29 11:47:36 +02:00
Do not trivially copy/move assign when not trivially copy/move constructible
This commit is contained in:
51
test/variant_move_assign_throw.cpp
Normal file
51
test/variant_move_assign_throw.cpp
Normal file
@ -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 <boost/variant2/variant.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
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<Y1, Y2> v1( in_place_type_t<Y1>{} );
|
||||
variant<Y1, Y2> v2( in_place_type_t<Y2>{} );
|
||||
|
||||
BOOST_TEST_THROWS( v1 = std::move( v2 ), std::runtime_error )
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test();
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user