gcc/libstdc++-v3/include/bits
Jonathan Wakely 47a468bdbe Fix std::variant regression caused by never-valueless optimization
A regression was introduced by the recent changes to provide the strong
exception safety guarantee for "never valueless" types that have O(1),
non-throwing move assignment. The problematic code is:

  else if constexpr (__detail::__variant::_Never_valueless_alt<type>())
    {
      // This construction might throw:
      variant __tmp(in_place_index<_Np>, __il,
                    std::forward<_Args>(__args)...);
      // But _Never_valueless_alt<type> means this won't:
      *this = std::move(__tmp);
    }

When the variant is not assignable, the assignment is ill-formed, so
should not be attempted. When the variant has a copy assignment operator
but not a move assignment operator, the assignment performs a copy
assignment and that could throw, so should not be attempted.

The solution is to only take that branch when the variant has a move
assignment operator, which is determined by the _Traits::_S_move_assign
constant. When that is false the strong exception safety guarantee is
not possible, and so the __never_valueless function should also depend
on _S_move_assign.

While testing the fixes for this I noticed that the partial
specialization _Never_valueless_alt<basic_string<C,T,A>> incorrectly
assumed that is_nothrow_move_constructible<basic_string<C,T,A>> is
always true, but that's wrong for fully-dynamic COW strings. Fix the
partial specialization, and improve the comment describing
_Never_valueless_alt to be clear it depends on move construction as well
as move assignment.

Finally, I also observed that _Variant_storage<false, T...>::_M_valid()
was not taking advantage of the __never_valueless<T...>() function to
avoid a runtime check. Only the _Variant_storage<true, T...>::_M_valid()
function was using __never_valueless. That is also fixed.

	PR libstdc++/87431
	* include/bits/basic_string.h (_Never_valueless_alt): Make partial
	specialization also depend on is_nothrow_move_constructible.
	* include/std/variant (__detail::__variant::__never_valueless()):
	Only true if the variant would have a move assignment operator.
	(__detail::__variant::_Variant_storage<false, T...>::_M_valid()):
	Check __never_valueless<T...>().
	(variant::emplace): Only perform non-throwing move assignments
	for never-valueless alternatives if the variant has a move assignment
	operator.
	* testsuite/20_util/variant/compile.cc: Check that never-valueless
	types can be emplaced into non-assignable variants.
	* testsuite/20_util/variant/run.cc: Check that never-valueless types
	don't get copied when emplaced into non-assignable variants.

From-SVN: r270502
2019-04-23 10:55:33 +01:00
..
algorithmfwd.h Update copyright years. 2019-01-01 13:31:55 +01:00
alloc_traits.h PR libstdc++/89477 constrain deduction guides for maps and sets 2019-02-26 23:12:44 +00:00
allocated_ptr.h Update copyright years. 2019-01-01 13:31:55 +01:00
allocator.h Update copyright years. 2019-01-01 13:31:55 +01:00
atomic_base.h re PR libstdc++/89641 (std::atomic<T> no longer works) 2019-03-11 12:49:13 +01:00
atomic_futex.h Update copyright years. 2019-01-01 13:31:55 +01:00
basic_ios.h Update copyright years. 2019-01-01 13:31:55 +01:00
basic_ios.tcc Update copyright years. 2019-01-01 13:31:55 +01:00
basic_string.h Fix std::variant regression caused by never-valueless optimization 2019-04-23 10:55:33 +01:00
basic_string.tcc Export explicit instantiations for C++17 members of std::string 2019-01-04 23:23:22 +00:00
boost_concept_check.h Update copyright years. 2019-01-01 13:31:55 +01:00
c++0x_warning.h Update copyright years. 2019-01-01 13:31:55 +01:00
c++config Delegate PSTL configuration to pstl/pstl_config.h 2019-04-20 23:20:03 +00:00
char_traits.h PR libstdc++/89446 fix null pointer dereference in char_traits 2019-02-23 03:01:59 +00:00
codecvt.h P0482R5 char8_t: Standard library support 2019-02-19 02:54:42 +00:00
concept_check.h Update copyright years. 2019-01-01 13:31:55 +01:00
cpp_type_traits.h P0482R5 char8_t: Standard library support 2019-02-19 02:54:42 +00:00
deque.tcc Update copyright years. 2019-01-01 13:31:55 +01:00
enable_special_members.h Update copyright years. 2019-01-01 13:31:55 +01:00
erase_if.h Fix more missing or incorrect feature test macros 2019-01-15 12:58:19 +00:00
forward_list.h Fix after P0600. 2019-01-21 11:47:30 +00:00
forward_list.tcc PR libstdc++/90105 make forward_list::sort stable 2019-04-17 22:47:20 +01:00
fs_dir.h Use hidden friends for directory iterator comparisons 2019-04-05 17:56:31 +01:00
fs_fwd.h Define new filesystem::__file_clock type 2019-01-05 20:03:22 +00:00
fs_ops.h Update copyright years. 2019-01-01 13:31:55 +01:00
fs_path.h Make filesystem::path safe for self assignment 2019-04-05 17:56:14 +01:00
fstream.tcc Update copyright years. 2019-01-01 13:31:55 +01:00
functexcept.h Update copyright years. 2019-01-01 13:31:55 +01:00
functional_hash.h P0482R5 char8_t: Standard library support 2019-02-19 02:54:42 +00:00
gslice_array.h Update copyright years. 2019-01-01 13:31:55 +01:00
gslice.h Update copyright years. 2019-01-01 13:31:55 +01:00
hashtable_policy.h Update copyright years. 2019-01-01 13:31:55 +01:00
hashtable.h PR libstdc++/85965 delay static assertions until types are complete 2019-03-26 15:28:48 +00:00
indirect_array.h Update copyright years. 2019-01-01 13:31:55 +01:00
invoke.h Update copyright years. 2019-01-01 13:31:55 +01:00
ios_base.h Update copyright years. 2019-01-01 13:31:55 +01:00
istream.tcc Update copyright years. 2019-01-01 13:31:55 +01:00
list.tcc Update copyright years. 2019-01-01 13:31:55 +01:00
locale_classes.h Update copyright years. 2019-01-01 13:31:55 +01:00
locale_classes.tcc Update copyright years. 2019-01-01 13:31:55 +01:00
locale_conv.h P0482R5 char8_t: Standard library support 2019-02-19 02:54:42 +00:00
locale_facets_nonio.h Update copyright years. 2019-01-01 13:31:55 +01:00
locale_facets_nonio.tcc Update copyright years. 2019-01-01 13:31:55 +01:00
locale_facets.h P0482R5 char8_t: Standard library support 2019-02-19 02:54:42 +00:00
locale_facets.tcc PR libstdc++/68737 Do not use vsnprintf on HPUX 2019-01-28 23:58:57 +00:00
localefwd.h P0482R5 char8_t: Standard library support 2019-02-19 02:54:42 +00:00
mask_array.h Update copyright years. 2019-01-01 13:31:55 +01:00
memoryfwd.h Update copyright years. 2019-01-01 13:31:55 +01:00
move.h Update copyright years. 2019-01-01 13:31:55 +01:00
node_handle.h Update copyright years. 2019-01-01 13:31:55 +01:00
ostream_insert.h Update copyright years. 2019-01-01 13:31:55 +01:00
ostream.tcc Update copyright years. 2019-01-01 13:31:55 +01:00
parse_numbers.h Update copyright years. 2019-01-01 13:31:55 +01:00
postypes.h P0482R5 char8_t: Standard library support 2019-02-19 02:54:42 +00:00
predefined_ops.h Update copyright years. 2019-01-01 13:31:55 +01:00
ptr_traits.h Constexpr in std::pointer_traits (P1006R1) 2019-03-06 11:32:42 +00:00
quoted_string.h Update copyright years. 2019-01-01 13:31:55 +01:00
random.h Update copyright years. 2019-01-01 13:31:55 +01:00
random.tcc Update copyright years. 2019-01-01 13:31:55 +01:00
range_access.h Update copyright years. 2019-01-01 13:31:55 +01:00
refwrap.h P0357R3 reference_wrapper for incomplete types 2019-01-11 23:41:11 +00:00
regex_automaton.h Update copyright years. 2019-01-01 13:31:55 +01:00
regex_automaton.tcc Update copyright years. 2019-01-01 13:31:55 +01:00
regex_compiler.h Update copyright years. 2019-01-01 13:31:55 +01:00
regex_compiler.tcc Update copyright years. 2019-01-01 13:31:55 +01:00
regex_constants.h Update copyright years. 2019-01-01 13:31:55 +01:00
regex_error.h Update copyright years. 2019-01-01 13:31:55 +01:00
regex_executor.h Update copyright years. 2019-01-01 13:31:55 +01:00
regex_executor.tcc Update copyright years. 2019-01-01 13:31:55 +01:00
regex_scanner.h Update copyright years. 2019-01-01 13:31:55 +01:00
regex_scanner.tcc Update copyright years. 2019-01-01 13:31:55 +01:00
regex.h Fix after P0600. 2019-01-21 11:47:30 +00:00
regex.tcc Update copyright years. 2019-01-01 13:31:55 +01:00
shared_ptr_atomic.h Update copyright years. 2019-01-01 13:31:55 +01:00
shared_ptr_base.h PR libstdc++/88782 avoid ODR problems in std::make_shared 2019-01-18 21:28:48 +00:00
shared_ptr.h PR libstdc++/87431 re-adjust never-valueless optimizations 2019-04-05 17:56:09 +01:00
slice_array.h Update copyright years. 2019-01-01 13:31:55 +01:00
specfun.h Update copyright years. 2019-01-01 13:31:55 +01:00
sstream.tcc Update copyright years. 2019-01-01 13:31:55 +01:00
std_abs.h Document LWG 2735 status and add test 2019-02-14 09:07:09 +00:00
std_function.h PR libstdc++/87431 re-adjust never-valueless optimizations 2019-04-05 17:56:09 +01:00
std_mutex.h Update copyright years. 2019-01-01 13:31:55 +01:00
stl_algo.h Update copyright years. 2019-01-01 13:31:55 +01:00
stl_algobase.h Avoid -Wconversion warnings when -Wsystem-headers is used 2019-03-22 16:45:48 +00:00
stl_bvector.h Update copyright years. 2019-01-01 13:31:55 +01:00
stl_construct.h Update copyright years. 2019-01-01 13:31:55 +01:00
stl_deque.h Rename __is_trivially_relocatable to __is_bitwise_relocatable. 2019-02-05 09:33:36 +00:00
stl_function.h re PR tree-optimization/88775 (Optimize std::string assignment) 2019-01-10 11:56:56 +01:00
stl_heap.h Update copyright years. 2019-01-01 13:31:55 +01:00
stl_iterator_base_funcs.h Update copyright years. 2019-01-01 13:31:55 +01:00
stl_iterator_base_types.h Update copyright years. 2019-01-01 13:31:55 +01:00
stl_iterator.h Update copyright years. 2019-01-01 13:31:55 +01:00
stl_list.h Fix after P0600. 2019-01-21 11:47:30 +00:00
stl_map.h PR libstdc++/89477 constrain deduction guides for maps and sets 2019-02-26 23:12:44 +00:00
stl_multimap.h PR libstdc++/89477 constrain deduction guides for maps and sets 2019-02-26 23:12:44 +00:00
stl_multiset.h PR libstdc++/89477 constrain deduction guides for maps and sets 2019-02-26 23:12:44 +00:00
stl_numeric.h Update copyright years. 2019-01-01 13:31:55 +01:00
stl_pair.h Update copyright years. 2019-01-01 13:31:55 +01:00
stl_queue.h PR libstdc++/89477 constrain deduction guides for maps and sets 2019-02-26 23:12:44 +00:00
stl_raw_storage_iter.h Update copyright years. 2019-01-01 13:31:55 +01:00
stl_relops.h Update copyright years. 2019-01-01 13:31:55 +01:00
stl_set.h PR libstdc++/89477 constrain deduction guides for maps and sets 2019-02-26 23:12:44 +00:00
stl_stack.h PR libstdc++/89477 constrain deduction guides for maps and sets 2019-02-26 23:12:44 +00:00
stl_tempbuf.h Update copyright years. 2019-01-01 13:31:55 +01:00
stl_tree.h PR libstdc++/85965 delay static assertions until types are complete 2019-03-26 15:28:48 +00:00
stl_uninitialized.h PR libstdc++/89090 avoid C++17 features in C++11/C++14 code 2019-02-05 14:44:56 +00:00
stl_vector.h PR libstdc++/87431 re-adjust never-valueless optimizations 2019-04-05 17:56:09 +01:00
stream_iterator.h Update copyright years. 2019-01-01 13:31:55 +01:00
streambuf_iterator.h Update copyright years. 2019-01-01 13:31:55 +01:00
streambuf.tcc Update copyright years. 2019-01-01 13:31:55 +01:00
string_view.tcc Update copyright years. 2019-01-01 13:31:55 +01:00
stringfwd.h P0482R5 char8_t: Standard library support 2019-02-19 02:54:42 +00:00
uniform_int_dist.h Update copyright years. 2019-01-01 13:31:55 +01:00
unique_lock.h Update copyright years. 2019-01-01 13:31:55 +01:00
unique_ptr.h PR libstdc++/87431 re-adjust never-valueless optimizations 2019-04-05 17:56:09 +01:00
unordered_map.h PR libstdc++/89477 constrain deduction guides for maps and sets 2019-02-26 23:12:44 +00:00
unordered_set.h PR libstdc++/89477 constrain deduction guides for maps and sets 2019-02-26 23:12:44 +00:00
uses_allocator.h DR 2586 fix value category in uses-allocator checks 2019-02-14 15:08:33 +00:00
valarray_after.h Update copyright years. 2019-01-01 13:31:55 +01:00
valarray_array.h Update copyright years. 2019-01-01 13:31:55 +01:00
valarray_array.tcc Update copyright years. 2019-01-01 13:31:55 +01:00
valarray_before.h Update copyright years. 2019-01-01 13:31:55 +01:00
vector.tcc PR libstdc++/89130 restore support for non-MoveConstructible types 2019-02-05 14:45:00 +00:00