Go to file
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
INSTALL
config iconv.m4 (AM_ICONV_LINK): Don't overwrite CPPFLAGS. 2018-11-07 15:41:21 -07:00
contrib * update-copyright.py: Add Gerard Jungman as external author. 2019-01-01 13:20:46 +01:00
fixincludes Update GCC to autoconf 2.69, automake 1.15.1 (PR bootstrap/82856). 2018-10-31 17:03:16 +00:00
gcc PR c++/88538 - braced-init-list in template-argument-list. 2019-01-08 22:33:04 +00:00
gnattools PR81878: fix --disable-bootstrap --enable-languages=ada 2018-11-20 00:07:47 +00:00
gotools Update GCC to autoconf 2.69, automake 1.15.1 (PR bootstrap/82856). 2018-10-31 17:03:16 +00:00
include Update copyright years. 2019-01-01 13:31:55 +01:00
intl iconv.m4 (AM_ICONV_LINK): Don't overwrite CPPFLAGS. 2018-11-07 15:41:21 -07:00
libada Update copyright years. 2019-01-01 13:31:55 +01:00
libatomic Update copyright years. 2019-01-01 13:31:55 +01:00
libbacktrace Update copyright years. 2019-01-01 13:31:55 +01:00
libcc1 Update copyright years. 2019-01-01 13:31:55 +01:00
libcpp Update copyright years. 2019-01-01 13:31:55 +01:00
libdecnumber Update copyright years. 2019-01-01 13:31:55 +01:00
libffi Update GCC to autoconf 2.69, automake 1.15.1 (PR bootstrap/82856). 2018-10-31 17:03:16 +00:00
libgcc PR c/88546 - Copy attribute unusable for weakrefs 2019-01-04 17:57:30 -07:00
libgfortran re PR fortran/45424 ([F08] Add IS_CONTIGUOUS intrinsic) 2019-01-07 19:30:28 +00:00
libgo runtime: in doscanstackswitch, set gp->m before gogo 2019-01-07 22:07:26 +00:00
libgomp [nvptx] Fix libgomp.oacc-c-c++-common/vector-length-128-3.c 2019-01-07 08:09:49 +00:00
libhsail-rt Update copyright years. 2019-01-01 13:31:55 +01:00
libiberty Update copyright years. 2019-01-01 13:31:55 +01:00
libitm Update copyright years. 2019-01-01 13:31:55 +01:00
libobjc Update copyright years. 2019-01-01 13:31:55 +01:00
liboffloadmic Repair liboffloadmic after "(Partial) OpenMP 5.0 support for GCC 9" 2018-12-14 21:41:46 +01:00
libphobos Update copyright years. 2019-01-01 13:31:55 +01:00
libquadmath Update copyright years. 2019-01-01 13:31:55 +01:00
libsanitizer Cherry pick libsanitizer patch (https://reviews.llvm.org/D54856). 2018-12-27 09:47:20 +00:00
libssp Update copyright years. 2019-01-01 13:31:55 +01:00
libstdc++-v3 PR libstdc++/87855 fix optional for types with non-trivial copy/move 2019-01-08 23:00:46 +00:00
libvtv Update copyright years. 2019-01-01 13:31:55 +01:00
lto-plugin Update copyright years. 2019-01-01 13:31:55 +01:00
maintainer-scripts Add new maintainer script for PRs that can be closed. 2018-11-22 14:05:54 +00:00
zlib Update GCC to autoconf 2.69, automake 1.15.1 (PR bootstrap/82856). 2018-10-31 17:03:16 +00:00
.dir-locals.el
.gitattributes
.gitignore
ABOUT-NLS
COPYING
COPYING.LIB
COPYING.RUNTIME
COPYING3
COPYING3.LIB
ChangeLog Update config.guess, config.sub (PR target/88535) 2019-01-03 11:28:27 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
MAINTAINERS Update maintainer email address 2018-12-21 17:53:03 +00:00
Makefile.def Add D front-end, libphobos library, and D2 testsuite. 2018-10-28 19:51:47 +00:00
Makefile.in darwin - add configuration support for 'otool' 2018-12-05 21:57:00 +00:00
Makefile.tpl darwin - add configuration support for 'otool' 2018-12-05 21:57:00 +00:00
README
ar-lib Update GCC to autoconf 2.69, automake 1.15.1 (PR bootstrap/82856). 2018-10-31 17:03:16 +00:00
compile
config-ml.in Add D front-end, libphobos library, and D2 testsuite. 2018-10-28 19:51:47 +00:00
config.guess Update config.guess, config.sub (PR target/88535) 2019-01-03 11:28:27 +00:00
config.rpath
config.sub Update config.guess, config.sub (PR target/88535) 2019-01-03 11:28:27 +00:00
configure darwin - add configuration support for 'otool' 2018-12-05 21:57:00 +00:00
configure.ac darwin - add configuration support for 'otool' 2018-12-05 21:57:00 +00:00
depcomp
install-sh
libtool-ldflags
libtool.m4 Update GCC to autoconf 2.69, automake 1.15.1 (PR bootstrap/82856). 2018-10-31 17:03:16 +00:00
ltgcc.m4
ltmain.sh libtool.m4: Sort output of 'find' to enable deterministic builds. 2018-07-05 13:13:45 -06:00
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
missing
mkdep
mkinstalldirs
move-if-change
multilib.am Update GCC to autoconf 2.69, automake 1.15.1 (PR bootstrap/82856). 2018-10-31 17:03:16 +00:00
symlink-tree
test-driver Update GCC to autoconf 2.69, automake 1.15.1 (PR bootstrap/82856). 2018-10-31 17:03:16 +00:00
ylwrap

README

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.