gcc/libstdc++-v3/include/bits
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
..
algorithmfwd.h Update copyright years. 2018-01-03 11:03:58 +01:00
alloc_traits.h Relocation (= move+destroy) 2018-10-25 13:03:13 +00:00
allocated_ptr.h Update copyright years. 2018-01-03 11:03:58 +01:00
allocator.h Relocation (= move+destroy) 2018-10-25 13:03:13 +00:00
atomic_base.h re PR libstdc++/54005 (Use __atomic_always_lock_free in libstdc++ is_lock_free instead of __atomic_is_lock_free) 2018-11-11 22:20:19 +00:00
atomic_futex.h Remove <chrono> dependency on _GLIBCXX_USE_C99_STDINT_TR1 2018-07-26 15:01:55 +01:00
basic_ios.h Update copyright years. 2018-01-03 11:03:58 +01:00
basic_ios.tcc Update copyright years. 2018-01-03 11:03:58 +01:00
basic_string.h PR libstdc++/87749 fix (and optimize) string move construction 2018-10-25 16:34:04 +01:00
basic_string.tcc PR libstdc++/58265 implement LWG 2063 for COW strings 2018-07-05 16:56:06 +01:00
boost_concept_check.h Update copyright years. 2018-01-03 11:03:58 +01:00
c++0x_warning.h Update copyright years. 2018-01-03 11:03:58 +01:00
c++config Don't unconditionally define feature test macros in <version> 2018-07-31 23:31:14 +01:00
char_traits.h Remove char16_t and char32_t dependency on <stdint.h> 2018-07-26 15:02:01 +01:00
codecvt.h Remove char16_t and char32_t dependency on <stdint.h> 2018-07-26 15:02:01 +01:00
concept_check.h Update copyright years. 2018-01-03 11:03:58 +01:00
cpp_type_traits.h Add std::__is_byte<std::byte> specialization 2018-06-27 11:30:52 +01:00
deque.tcc PR libstdc++/78448 limit vector::max_size and deque::max_size 2018-08-22 23:22:40 +01:00
enable_special_members.h Update copyright years. 2018-01-03 11:03:58 +01:00
forward_list.h PR libstdc++/87809 avoid invalid expressions in exception specifications 2018-10-30 14:49:43 +00:00
forward_list.tcc P0646R1 Improving the Return Value of Erase-Like Algorithms I 2018-07-04 21:15:01 +01:00
fs_dir.h PR libstdc++/86597 directory_entry observers should clear error_code 2018-08-08 14:09:19 +01:00
fs_fwd.h Update copyright years. 2018-01-03 11:03:58 +01:00
fs_ops.h Avoid redundant calls to filesystem::status_known 2018-01-04 13:46:22 +00:00
fs_path.h LWG 2989 hide path iostream operators from normal lookup 2018-06-18 19:59:44 +01:00
fstream.tcc PR libstdc++/85343 overload __throw_ios_failure to take errno 2018-08-14 13:09:57 +01:00
functexcept.h PR libstdc++/85343 overload __throw_ios_failure to take errno 2018-08-14 13:09:57 +01:00
functional_hash.h Update copyright years. 2018-01-03 11:03:58 +01:00
gslice.h Update copyright years. 2018-01-03 11:03:58 +01:00
gslice_array.h PR libstdc++/83860 avoid dangling references in valarray closure types 2018-05-02 17:41:46 +01:00
hashtable.h re PR libstdc++/83709 (Inserting duplicates into an unordered associative containers causes the container to invalidate iterators) 2018-01-09 21:05:10 +00:00
hashtable_policy.h Avoid undefined shifts in ceil2 operations 2018-08-30 16:07:35 +01:00
indirect_array.h Update copyright years. 2018-01-03 11:03:58 +01:00
invoke.h Update copyright years. 2018-01-03 11:03:58 +01:00
ios_base.h Define special members as defaulted 2018-06-08 17:43:14 +01:00
istream.tcc Update copyright years. 2018-01-03 11:03:58 +01:00
list.tcc P0646R1 Improving the Return Value of Erase-Like Algorithms I 2018-07-04 21:15:01 +01:00
locale_classes.h Update copyright years. 2018-01-03 11:03:58 +01:00
locale_classes.tcc Update copyright years. 2018-01-03 11:03:58 +01:00
locale_conv.h P0935R0 Eradicating unnecessarily explicit default constructors 2018-06-14 15:12:24 +01:00
locale_facets.h Remove char16_t and char32_t dependency on <stdint.h> 2018-07-26 15:02:01 +01:00
locale_facets.tcc Update copyright years. 2018-01-03 11:03:58 +01:00
locale_facets_nonio.h Update copyright years. 2018-01-03 11:03:58 +01:00
locale_facets_nonio.tcc Update copyright years. 2018-01-03 11:03:58 +01:00
localefwd.h Update copyright years. 2018-01-03 11:03:58 +01:00
mask_array.h PR libstdc++/83860 avoid dangling references in valarray closure types 2018-05-02 17:41:46 +01:00
memoryfwd.h Update copyright years. 2018-01-03 11:03:58 +01:00
move.h Update copyright years. 2018-01-03 11:03:58 +01:00
node_handle.h PR libstdc++/82966 fix swapping of node handles 2018-05-14 15:27:54 +01:00
ostream.tcc Update copyright years. 2018-01-03 11:03:58 +01:00
ostream_insert.h Update copyright years. 2018-01-03 11:03:58 +01:00
parse_numbers.h PR libstdc++/84671 handle digit separators in duration literals 2018-03-02 20:38:50 +00:00
postypes.h Define std::fpos special members as defaulted 2018-06-04 17:07:55 +01:00
predefined_ops.h Update copyright years. 2018-01-03 11:03:58 +01:00
ptr_traits.h Update copyright years. 2018-01-03 11:03:58 +01:00
quoted_string.h PR libstdc++/86008 add std::quoted support for string_view 2018-06-06 07:05:07 +01:00
random.h Fix regression in std::random_device default constructor 2018-10-16 23:42:39 +01:00
random.tcc PR libstdc++/85749 constrain seed sequences for random number engines 2018-05-15 16:36:46 +01:00
range_access.h Update copyright years. 2018-01-03 11:03:58 +01:00
refwrap.h LWG 2993 reference_wrapper<T> conversion from T&& 2018-06-15 15:19:47 +01:00
regex.h Optimize std::sub_match comparisons using string_view-like type 2018-07-02 21:31:11 +01:00
regex.tcc Add missing noexcept on definition to match declaration 2018-06-26 13:24:47 +01:00
regex_automaton.h PR libstdc++/85098 add missing definitions for static constants 2018-05-18 17:14:04 +01:00
regex_automaton.tcc Don't use __glibcxx_assert to check class invariants 2018-09-19 12:20:51 +01:00
regex_compiler.h Optimize std::sub_match comparisons using string_view-like type 2018-07-02 21:31:11 +01:00
regex_compiler.tcc PR libstdc++/85098 add missing definitions for static constants 2018-05-18 17:14:04 +01:00
regex_constants.h Update copyright years. 2018-01-03 11:03:58 +01:00
regex_error.h Update copyright years. 2018-01-03 11:03:58 +01:00
regex_executor.h Update copyright years. 2018-01-03 11:03:58 +01:00
regex_executor.tcc Fix compilation error with _GLIBCXX_PARALLEL 2018-10-19 14:46:24 +01:00
regex_scanner.h Update copyright years. 2018-01-03 11:03:58 +01:00
regex_scanner.tcc Update copyright years. 2018-01-03 11:03:58 +01:00
shared_ptr.h PR libstdc++/87278 restore support for std::make_shared<volatile T>() 2018-09-11 12:50:39 +01:00
shared_ptr_atomic.h Update copyright years. 2018-01-03 11:03:58 +01:00
shared_ptr_base.h PR libstdc++/87520 Always pass type-punned type_info reference 2018-11-22 13:42:39 +00:00
slice_array.h PR libstdc++/83860 avoid dangling references in valarray closure types 2018-05-02 17:41:46 +01:00
specfun.h Update copyright years. 2018-01-03 11:03:58 +01:00
sstream.tcc Update copyright years. 2018-01-03 11:03:58 +01:00
std_abs.h PR libstdc++/85729 add linkage specifications to headers 2018-05-10 13:35:45 +01:00
std_function.h Make std::function tolerate semantically non-CopyConstructible objects 2018-05-09 14:28:11 +01:00
std_mutex.h Move std::unique_lock definition to a separate header 2018-07-25 11:40:12 +01:00
stl_algo.h 2018-08-08 François Dumont <fdumont@gcc.gnu.org> 2018-08-08 20:28:21 +00:00
stl_algobase.h PR libstdc++/86658 fix __niter_wrap to not copy invalid iterators 2018-07-24 21:49:10 +01:00
stl_bvector.h PR libstdc++/87809 avoid invalid expressions in exception specifications 2018-10-30 14:49:43 +00:00
stl_construct.h Update copyright years. 2018-01-03 11:03:58 +01:00
stl_deque.h PR libstdc++/78448 limit vector::max_size and deque::max_size 2018-08-22 23:22:40 +01:00
stl_function.h PR libstdc++/85040 fix std::less<void> etc. ambiguities 2018-03-22 14:23:27 +00:00
stl_heap.h Update copyright years. 2018-01-03 11:03:58 +01:00
stl_iterator.h stl_iterator.h: Fix comment. 2018-08-05 15:33:58 +00:00
stl_iterator_base_funcs.h Update copyright years. 2018-01-03 11:03:58 +01:00
stl_iterator_base_types.h Update copyright years. 2018-01-03 11:03:58 +01:00
stl_list.h PR libstdc++/87809 avoid invalid expressions in exception specifications 2018-10-30 14:49:43 +00:00
stl_map.h PR libstdc++/87194 fix range insertion into maps and sets 2018-09-03 15:25:25 +01:00
stl_multimap.h PR libstdc++/87194 fix range insertion into maps and sets 2018-09-03 15:25:25 +01:00
stl_multiset.h PR libstdc++/87194 fix range insertion into maps and sets 2018-09-03 15:25:25 +01:00
stl_numeric.h PR libstdc++/84928 use std::move in <numeric> algorithms 2018-07-06 15:16:13 +01:00
stl_pair.h PR libstdc++/87822 fix layout change for nested std::pair 2018-10-31 12:29:02 +00:00
stl_queue.h Update copyright years. 2018-01-03 11:03:58 +01:00
stl_raw_storage_iter.h Update copyright years. 2018-01-03 11:03:58 +01:00
stl_relops.h Update copyright years. 2018-01-03 11:03:58 +01:00
stl_set.h PR libstdc++/87194 fix range insertion into maps and sets 2018-09-03 15:25:25 +01:00
stl_stack.h Update copyright years. 2018-01-03 11:03:58 +01:00
stl_tempbuf.h PR libstdc++/86954 use non-placement operator delete 2018-08-14 21:19:20 +01:00
stl_tree.h 2018-10-05 François Dumont <fdumont@gcc.gnu.org> 2018-10-05 16:01:39 +00:00
stl_uninitialized.h PR libstdc++/87787 fix UBsan error in std::vector 2018-11-09 20:14:07 +00:00
stl_vector.h PR libstdc++/87809 avoid invalid expressions in exception specifications 2018-10-30 14:49:43 +00:00
stream_iterator.h Define special members as defaulted 2018-06-08 17:43:14 +01:00
streambuf.tcc Update copyright years. 2018-01-03 11:03:58 +01:00
streambuf_iterator.h Define special members as defaulted 2018-06-08 17:43:14 +01:00
string_view.tcc Update copyright years. 2018-01-03 11:03:58 +01:00
stringfwd.h Define std::string and related typedefs outside __cxx11 namespace 2018-10-09 14:06:46 +01:00
uniform_int_dist.h P0935R0 Eradicating unnecessarily explicit default constructors 2018-06-14 14:32:53 +01:00
unique_lock.h Remove <chrono> dependency on _GLIBCXX_USE_C99_STDINT_TR1 2018-07-26 15:01:55 +01:00
unique_ptr.h PR libstdc++/87704 fix unique_ptr(nullptr_t) constructors 2018-10-23 14:10:26 +01:00
unordered_map.h PR libstdc++/78595 implement insertion into maps in terms of emplace 2018-09-03 15:25:12 +01:00
unordered_set.h P0458R2 Checking for Existence of an Element in Associative Containers 2018-07-04 19:16:26 +01:00
uses_allocator.h Refactor uses-allocator construction 2018-08-15 20:20:02 +01:00
valarray_after.h LWG 3074 make scalar types non-deduced in valarray non-member functions 2018-06-14 20:36:54 +01:00
valarray_array.h PR libstdc++/87641 correctly initialize accumulator in valarray::sum() 2018-10-18 16:38:50 +01:00
valarray_array.tcc Update copyright years. 2018-01-03 11:03:58 +01:00
valarray_before.h PR libstdc++/83860 avoid dangling references in valarray closure types 2018-05-02 17:41:46 +01:00
vector.tcc Relocation (= move+destroy) 2018-10-25 13:03:13 +00:00