gcc/libstdc++-v3/include
Jonathan Wakely a942dfca6a PR libstdc++/87520 Always pass type-punned type_info reference
The implementations of std::make_shared for -frtti and -fno-rtti are not
compatible, because they pass different arguments to
_Sp_counted_ptr_inplace::_M_get_deleter and so can't interoperate.
Either the argument doesn't match the expected value, and so the
shared_ptr::_M_ptr member is never set, or the type-punned reference is
treated as a real std::type_info object and gets dereferenced.

This patch removes the differences between -frtti and -fno-rtti, so that
typeid is never used, and the type-punned reference is used in both
cases. For backwards compatibility with existing code that passes
typeid(_Sp_make_shared_tag) that still needs to be handled, but only
after checking that the argument is not the type-punned reference (so
it's safe to treat as a real std::type_info object). The reference is
bound to an object of literal type, so that it doesn't need a guard
variable to make its initialization thread-safe.

This patch also fixes 87520 by ensuring that the type-punned reference
is bound to "a region of storage of suitable size and alignment to
contain an object of the reference's type" (as per the proposed
resolution of Core DR 453).

If all objects are built with the fixed version of GCC then -frtti and
-fno-rtti can be mixed freely and std::make_shared will work correctly.
If some objects are built with unfixed GCC versions then problems can
still arise, depending on which template instantiations are kept by the
linker.

	PR libstdc++/85930
	PR libstdc++/87520
	* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_ti)
	[__cpp_rtti]: Define even when RTTI is enabled. Use array of
	sizeof(type_info) so that type-punned reference binds to an object
	of the correct size as well as correct alignment.
	(_Sp_counted_ptr_inplace::_M_get_deleter) [__cpp_rtti]: Check for
	_S_ti() reference even when RTTI is enabled.
	(__shared_ptr(_Sp_make_shared_tag, const _Alloc&, _Args&&...))
	[__cpp_rtti]: Pass _S_ti() instead of typeid(_Sp_make_shared_tag).

From-SVN: r266376
2018-11-22 13:42:39 +00:00
..
backward P0935R0 Eradicating unnecessarily explicit default constructors 2018-06-14 15:12:24 +01:00
bits PR libstdc++/87520 Always pass type-punned type_info reference 2018-11-22 13:42:39 +00:00
c Update copyright years. 2018-01-03 11:03:58 +01:00
c_compatibility Update copyright years. 2018-01-03 11:03:58 +01:00
c_global cstddef: Add versioned namespace. 2018-10-24 05:20:35 +00:00
c_std Update copyright years. 2018-01-03 11:03:58 +01:00
debug re PR libstdc++/87872 (debug list::splice should not call _M_transfer_from_if on self-splices) 2018-11-06 20:20:06 +00:00
decimal Update copyright years. 2018-01-03 11:03:58 +01:00
experimental Fix versioned namespace macros for Networking TS 2018-10-16 17:12:51 +01:00
ext 2018-11-19 François Dumont <fdumont@gcc.gnu.org> 2018-11-19 21:02:17 +00:00
parallel Update copyright years. 2018-01-03 11:03:58 +01:00
precompiled Add initial version of C++17 <memory_resource> header 2018-07-24 22:09:55 +01:00
profile Update copyright years. 2018-01-03 11:03:58 +01:00
std PR libstdc++/88111 Make maximum block size depend on size_t width 2018-11-21 18:40:55 +00:00
tr1 PR libstdc++/83566 - cyl_bessel_j returns wrong result for x>1000 2018-11-18 18:32:26 +00:00
tr2 PR libstdc++/87784 fix dynamic_bitset::push_back 2018-10-30 14:49:32 +00:00
Makefile.am Initial commit of Networking TS implementation 2018-10-12 11:50:15 +01:00
Makefile.in Update GCC to autoconf 2.69, automake 1.15.1 (PR bootstrap/82856). 2018-10-31 17:03:16 +00:00