gcc/libstdc++-v3/include/std
Jonathan Wakely caf80d87b5 PR libstdc++/87431 fix regression introduced by r264574
The previous patch for PR 87431 assumed that initialing a scalar type
could not throw, but it can obtain its value via a conversion operator,
which could throw. This meant the variant could get into a valueless
state, but the valueless_by_exception() member function would always
return false.

This patch fixes it by changing the emplace members to have strong
exception safety when initializing a contained value of trivially
copyable type. The _M_valid() member gets a corresponding change to
always return true for trivially copyable types, not just scalar types.

Strong exception safety (i.e. never becoming valueless) is achieved by
only replacing the current contained value once any potentially throwing
operations have completed. If constructing the new contained value can
throw then a new std::variant object is constructed to hold it, and then
move-assigned to *this (which won't throw).

	PR libstdc++/87431
	* include/std/variant (_Variant_storage<true, _Types...>::_M_valid):
	Check is_trivially_copyable instead of is_scalar.
	(variant::emplace<N, Args>(Args&&...)): If construction of the new
	contained value can throw and its type is trivially copyable then
	construct into a temporary variant and move from it, to provide the
	strong exception safety guarantee.
	(variant::emplace<N, U, Args>(initializer_list<U>, Args&&...)):
	Likewise.
	* testsuite/20_util/variant/87431.cc: New test.
	* testsuite/20_util/variant/run.cc: Adjust test so that throwing
	conversion causes valueless state.

From-SVN: r267614
2019-01-06 20:52:34 +00:00
..
algorithm Update copyright years. 2019-01-01 13:31:55 +01:00
any Update copyright years. 2019-01-01 13:31:55 +01:00
array Update copyright years. 2019-01-01 13:31:55 +01:00
atomic Update copyright years. 2019-01-01 13:31:55 +01:00
bit Update copyright years. 2019-01-01 13:31:55 +01:00
bitset Update copyright years. 2019-01-01 13:31:55 +01:00
charconv Update copyright years. 2019-01-01 13:31:55 +01:00
chrono Update copyright years. 2019-01-01 13:31:55 +01:00
codecvt Update copyright years. 2019-01-01 13:31:55 +01:00
complex Update copyright years. 2019-01-01 13:31:55 +01:00
condition_variable Update copyright years. 2019-01-01 13:31:55 +01:00
deque Update copyright years. 2019-01-01 13:31:55 +01:00
filesystem Update copyright years. 2019-01-01 13:31:55 +01:00
forward_list Update copyright years. 2019-01-01 13:31:55 +01:00
fstream Update copyright years. 2019-01-01 13:31:55 +01:00
functional Update copyright years. 2019-01-01 13:31:55 +01:00
future PR libstdc++/88607 replace some more UTF-8 characters 2019-01-03 22:07:52 +00:00
iomanip Update copyright years. 2019-01-01 13:31:55 +01:00
ios Update copyright years. 2019-01-01 13:31:55 +01:00
iosfwd Update copyright years. 2019-01-01 13:31:55 +01:00
iostream Update copyright years. 2019-01-01 13:31:55 +01:00
istream Update copyright years. 2019-01-01 13:31:55 +01:00
iterator Update copyright years. 2019-01-01 13:31:55 +01:00
limits Update copyright years. 2019-01-01 13:31:55 +01:00
list Update copyright years. 2019-01-01 13:31:55 +01:00
locale Update copyright years. 2019-01-01 13:31:55 +01:00
map Update copyright years. 2019-01-01 13:31:55 +01:00
memory Update copyright years. 2019-01-01 13:31:55 +01:00
memory_resource Update copyright years. 2019-01-01 13:31:55 +01:00
mutex Update copyright years. 2019-01-01 13:31:55 +01:00
numeric Update copyright years. 2019-01-01 13:31:55 +01:00
optional Update copyright years. 2019-01-01 13:31:55 +01:00
ostream Update copyright years. 2019-01-01 13:31:55 +01:00
queue Update copyright years. 2019-01-01 13:31:55 +01:00
random Update copyright years. 2019-01-01 13:31:55 +01:00
ratio Update copyright years. 2019-01-01 13:31:55 +01:00
regex Update copyright years. 2019-01-01 13:31:55 +01:00
scoped_allocator Update copyright years. 2019-01-01 13:31:55 +01:00
set Update copyright years. 2019-01-01 13:31:55 +01:00
shared_mutex Update copyright years. 2019-01-01 13:31:55 +01:00
sstream Update copyright years. 2019-01-01 13:31:55 +01:00
stack Update copyright years. 2019-01-01 13:31:55 +01:00
stdexcept Update copyright years. 2019-01-01 13:31:55 +01:00
streambuf Update copyright years. 2019-01-01 13:31:55 +01:00
string Update copyright years. 2019-01-01 13:31:55 +01:00
string_view Update copyright years. 2019-01-01 13:31:55 +01:00
system_error Update copyright years. 2019-01-01 13:31:55 +01:00
thread Update copyright years. 2019-01-01 13:31:55 +01:00
tuple Update copyright years. 2019-01-01 13:31:55 +01:00
type_traits Update copyright years. 2019-01-01 13:31:55 +01:00
typeindex Update copyright years. 2019-01-01 13:31:55 +01:00
unordered_map Update copyright years. 2019-01-01 13:31:55 +01:00
unordered_set Update copyright years. 2019-01-01 13:31:55 +01:00
utility Update copyright years. 2019-01-01 13:31:55 +01:00
valarray Update copyright years. 2019-01-01 13:31:55 +01:00
variant PR libstdc++/87431 fix regression introduced by r264574 2019-01-06 20:52:34 +00:00
vector Update copyright years. 2019-01-01 13:31:55 +01:00
version Update copyright years. 2019-01-01 13:31:55 +01:00