gcc/libstdc++-v3/include/std
Jonathan Wakely d942bc80e4 PR libstdc++/87855 fix optional for types with non-trivial copy/move
When the contained value is not trivially copy (or move) constructible
the union's copy (or move) constructor will be deleted, and so the
_Optional_payload delegating constructors are invalid. G++ fails to
diagnose this because it incorrectly performs copy elision in the
delegating constructors. Clang does diagnose it (llvm.org/PR40245).

The solution is to avoid performing any copy (or move) when the
contained value's copy (or move) constructor isn't trivial. Instead the
contained value can be constructed by calling _M_construct. This is OK,
because the relevant constructor doesn't need to be constexpr when the
contained value isn't trivially copy (or move) constructible.

Additionally, this patch removes a lot of code duplication in the
_Optional_payload partial specializations and the _Optional_base partial
specialization, by hoisting it into common base classes.

The Python pretty printer for std::optional needs to be adjusted to
support the new layout. Retain support for the old layout, and add a
test to verify that the support still works.

	PR libstdc++/87855
	* include/std/optional (_Optional_payload_base): New class template
	for common code hoisted from _Optional_payload specializations. Use
	a template for the union, to allow a partial specialization for
	types with non-trivial destructors. Add constructors for in-place
	initialization to the union.
	(_Optional_payload(bool, const _Optional_payload&)): Use _M_construct
	to perform non-trivial copy construction, instead of relying on
	non-standard copy elision in a delegating constructor.
	(_Optional_payload(bool, _Optional_payload&&)): Likewise for
	non-trivial move construction.
	(_Optional_payload): Derive from _Optional_payload_base and use it
	for everything except the non-trivial assignment operators, which are
	defined as needed.
	(_Optional_payload<false, C, M>): Derive from the specialization
	_Optional_payload<true, false, false> and add a destructor.
	(_Optional_base_impl::_M_destruct, _Optional_base_impl::_M_reset):
	Forward to corresponding members of _Optional_payload.
	(_Optional_base_impl::_M_is_engaged, _Optional_base_impl::_M_get):
	Hoist common members from _Optional_base.
	(_Optional_base): Make all members and base class public.
	(_Optional_base::_M_get, _Optional_base::_M_is_engaged): Move to
	_Optional_base_impl.
	* python/libstdcxx/v6/printers.py (StdExpOptionalPrinter): Add
	support for new std::optional layout.
	* testsuite/libstdc++-prettyprinters/compat.cc: New test.

From-SVN: r267742
2019-01-08 23:00:46 +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 PR libstdc++/87855 fix optional for types with non-trivial copy/move 2019-01-08 23:00:46 +00: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