Commit Graph

3747 Commits

Author SHA1 Message Date
Jonathan Wakely
c05986b936 Split <functional> into smaller pieces
* include/Makefile.am: Add <bits/refwrap.h> and <bits/std_function.h>.
	Order alphabetically.
	* include/Makefile.in: Regenerate.
	* include/bits/refwrap.h: New header.
	(_Maybe_get_result_type,_Weak_result_type_impl, _Weak_result_type)
	(_Reference_wrapper_base_impl, _Reference_wrapper_base)
	(reference_wrapper, ref, cref): Move here from <functional>.
	* include/bits/shared_ptr_base.h: Include <bits/refwrap.h> and
	<bits/stl_function.h> instead of <functional>.
	* include/bits/std_function.h: New header.
	(_Maybe_unary_or_binary_function, bad_function_call)
	(__is_location_invariant, _Nocopy_types, _Any_data)
	(_Simple_type_wrapper, _Function_base, _Function_handler, function):
	Move here from <functional>.
	* include/bits/unique_ptr.h: Include <bits/stl_function.h>.
	* include/std/functional: Include new headers and move components to
	them.
	* include/std/future: Include <bits/std_function.h> instead of
	<functional>.
	* include/std/mutex: Likewise.
	* include/std/regex: Likewise.
	* src/c++11/compatibility-thread-c++0x.cc: Include <functional>.
	* testsuite/20_util/default_delete/48631_neg.cc: Adjust dg-error line.
	* testsuite/20_util/default_delete/void_neg.cc: Likewise.
	* testsuite/20_util/unique_ptr/assign/48635_neg.cc: Adjust dg-error
	lines.
	* testsuite/20_util/unique_ptr/cons/cv_qual_neg.cc: Likewise.
	* testsuite/30_threads/packaged_task/49668.cc: Include <functional>.

From-SVN: r241410
2016-10-21 16:32:25 +01:00
Jonathan Wakely
a2e0054e1d Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
	(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
	* include/bits/shared_ptr.h (__sp_compatible_with)
	(__sp_is_constructible): New helper traits for shared_ptr.
	(shared_ptr::_Convertible): Replace with _Constructible.
	(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
	to base class.
	(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
	with _Constructible and _Assignable.
	(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
	instead of _Tp.
	(operator<): Likewise.
	(operator>): Define in terms of operator<.
	(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
	element_type instead of _Tp.
	(reinterpret_pointer_cast): Define for C++17.
	(weak_ptr::_Convertible): Replace with _Constructible.
	(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
	to base class.
	(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
	with _Constructible and _Assignable.
	* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
	with _Compatible.
	(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
	(__shared_ptr::_Compatible): New constraint for converting from
	other types of shared_ptr and weak_ptr.
	(__shared_ptr::_Assignable): Define in terms of _Compatible.
	(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
	constraints for converting from unique_ptr.
	(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
	template with _SaveConf, _Compatible and _Assignable. Remove
	__glibcxx_function_requires concept checks. Add static assertion for
	deleter expression being well-formed.
	(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
	(__shared_ptr::operator*, __shared_ptr::operator->)
	(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
	of _Tp.
	(operator<): Likewise.
	(operator>): Define in terms of operator<.
	(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
	element_type instead of _Tp.
	(reinterpret_pointer_cast): Define for C++17.
	(weak_ptr::_Convertible): Replace with _Compatible.
	(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
	conversions from other types of weak_ptr and shared_ptr.
	(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
	with _Constructible and _Assignable.
	(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
	* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
	dg-error pattern.
	* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
	* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
	* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.

From-SVN: r241373
2016-10-20 13:07:45 +01:00
Jonathan Wakely
88b3e63150 Tweak whitespace in std::allocator files
* include/bits/allocator.h: Remove trailing whitespace, tab-indent.
	* include/ext/new_allocator.h: Likewise.

From-SVN: r241371
2016-10-20 12:37:19 +01:00
Jonathan Wakely
1d6360c85b PR78052 Define std::allocator<void>::{construct,destroy}
PR libstdc++/78052
	* include/bits/allocator.h (allocator<void>::construct)
	(allocator<void>::destroy): Define.
	* testsuite/20_util/allocator/void.cc: New test.

From-SVN: r241365
2016-10-20 11:13:10 +01:00
Jonathan Wakely
f3070dab7a Make std::enable_shared_from_this cope with ambiguity
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&)): Call
	_M_enable_shared_from_this_with instead of
	__enable_shared_from_this_helper.
	* include/bits/shared_ptr.h (__enable_shared_from_this_helper):
	Remove overload for std::enable_shared_from_this..
	(__enable_shared_from_this_base): Define friend function to select a
	std::enable_shared_from_this base class.
	* include/bits/shared_ptr_base.h (__enable_shared_from_this_helper):
	Remove all overloads.
	(__shared_ptr): Change all relevant constructors to call
	_M_enable_shared_from_this_with instead of
	__enable_shared_from_this_helper.
	(__shared_ptr::__efst_base_t, __shared_ptr::__has_efst_base): Helpers
	to detect accessible and unambiguous enable_shared_from_this bases.
	(__shared_ptr::_M_enable_shared_from_this_with): New function to
	replace __enable_shared_from_this_helper overloads.
	(__enable_shared_from_this_helper): Remove overload for
	std::__enable_shared_from_this.
	(__enable_shared_from_this_base): Define friend function to select a
	std::__enable_shared_from_this base class.
	* include/experimental/bits/shared_ptr.h (experimental::shared_ptr):
	Change relevant constructors to call _M_enable_shared_from_this_with.
	(experimental::shared_ptr::__efst_base_t)
	(experimental::shared_ptr::__has_efst_base): Helpers to detect
	accessible and unambiguous enable_shared_from_this bases.
	(experimental::shared_ptr::_M_enable_shared_from_this_with): Define.
	(experimental::__enable_shared_from_this_helper): Remove overload for
	std::experimental::enable_shared_from_this.
	(experimental::__expt_enable_shared_from_this_base): Define friend
	function to select a std::experimental::enable_shared_from_this base.
	* testsuite/experimental/memory/shared_ptr/cons/
	enable_shared_from_this.cc: New test.
	* testsuite/experimental/memory/shared_ptr/cons/unique_ptr_ctor.cc:
	Adjust expected behaviour for shared_ptr<A[]>.

From-SVN: r241353
2016-10-19 21:13:14 +01:00
Jonathan Wakely
e182393e31 PR77990 refactor unique_ptr to encapsulate tuple
PR libstdc++/77990
	* include/bits/unique_ptr.h (__uniq_ptr_impl): New type to
	encapsulate implementation details.
	(unique_ptr::unique_ptr(_Up)): Don't copy deleter object.
	(unique_ptr::get, unique_ptr::get_deleter, unique_ptr::release):
	Call member functions of implementation object.
	(unique_ptr<T[], D>): Likewise.
	* python/libstdcxx/v6/printers.py (UniquePointerPrinter): Adjust for
	new implementation.
	* python/libstdcxx/v6/xmethods.py (UniquePtrGetWorker): Likewise.
	* testsuite/20_util/unique_ptr/assign/48635_neg.cc: Adjust dg-error
	lines.
	* testsuite/20_util/unique_ptr/assign/cv_qual.cc: Likewise.
	* testsuite/20_util/unique_ptr/cons/cv_qual.cc: Likewise.
	* testsuite/20_util/unique_ptr/cons/77990.cc: New test.

From-SVN: r241330
2016-10-19 10:34:57 +01:00
Jonathan Wakely
0aeb81f86f Don't define uses-allocator variable templates in C++11
* include/bits/uses_allocator.h (__is_uses_allocator_constructible_v)
	(__is_nothrow_uses_allocator_constructible_v): Only define for C++14
	and later.

From-SVN: r241301
2016-10-18 12:42:18 +01:00
Jonathan Wakely
12d3f34b33 PR77994 Convert std::sample size argument to suitable type
PR libstdc++/77994
	* include/bits/stl_algo.h (sample): Convert size argument to iterator
	difference type.
	* include/experimental/algorithm (experimental::sample): Likewise.
	* testsuite/25_algorithms/sample/2.cc: New test.

From-SVN: r241245
2016-10-17 15:39:23 +01:00
Jonathan Wakely
74cf9664e8 PR77987 Fix unique_ptr<T[], D>::reset(U) for T != U
PR libstdc++/77987
	* include/bits/unique_ptr.h (unique_ptr<T[], D>::reset<U>(U)): Copy
	value to pointer of the correct type to swap, to support conversions
	allowed by LWG 2118 / N4089.
	* testsuite/20_util/unique_ptr/assign/assign_neg.cc: Move test for
	incompatible deleters from ...
	* testsuite/20_util/unique_ptr/assign/cv_qual.cc: ... here.
	* testsuite/20_util/unique_ptr/modifiers/cv_qual.cc: Move tests for
	incompatible pointers to ...
	* testsuite/20_util/unique_ptr/modifiers/reset_neg.cc: ... here. Move
	destructor definition to base class. Test for invalid derived-to-base
	conversion.

From-SVN: r241235
2016-10-17 13:00:44 +01:00
Jonathan Wakely
594ef205ae Implement P0084R2, Emplace return type, for C++17
* doc/xml/manual/status_cxx2017.xml: Update status.
	* doc/html/*: Regenerate.
	* include/bits/deque.tcc (deque::emplace_front, deque::emplace_back):
	Return a reference in C++17 mode.
	* include/bits/forward_list.h (forward_list::emplace_front): Likewise.
	* include/bits/stl_bvector.h (vector<bool>::emplace_back): Likewise.
	* include/bits/stl_deque.h (deque::emplace_front, deque::emplace_back):
	Likewise.
	* include/bits/stl_list.h (list::emplace_front, list::emplace_back):
	Likewise.
	* include/bits/stl_queue.h (queue::emplace): Likewise.
	* include/bits/stl_stack.h (stack::emplace): Likewise.
	* include/bits/stl_vector.h (vector::emplace_back): Likewise.
	* include/bits/vector.tcc (vector::emplace_back): Likewise.
	* include/debug/deque (__gnu_debug::deque::emplace_front)
	(__gnu_debug::deque::emplace_back): Likewise.
	* include/debug/vector (__gnu_debug::vector::emplace_back): Likewise.
	* testsuite/23_containers/deque/modifiers/emplace/cxx17_return.cc:
	New.
	* testsuite/23_containers/forward_list/modifiers/
	emplace_cxx17_return.cc: New.
	* testsuite/23_containers/list/modifiers/emplace/cxx17_return.cc: New.
	* testsuite/23_containers/queue/members/emplace_cxx17_return.cc: New.
	* testsuite/23_containers/stack/members/emplace_cxx17_return.cc: New.
	* testsuite/23_containers/vector/bool/emplace_cxx17_return.cc: New.
	* testsuite/23_containers/vector/modifiers/emplace/cxx17_return.cc:
	New.

From-SVN: r241234
2016-10-17 13:00:38 +01:00
Eelis van der Weegen
38e34671fa Optimize std::shuffle by using generator to get two values at once
2016-10-14  Eelis van der Weegen  <eelis@eelis.net>

	* include/bits/stl_algo.h (shuffle): Extract two random numbers from
	each generator invocation when its range is large enough.

From-SVN: r241184
2016-10-14 20:40:32 +01:00
Jonathan Wakely
d67dd0be94 Avoid #include <functional> in other headers
* include/bits/shared_ptr_base.h: Include <functional>.
	[!__cpp_rtti]: Do not include <typeinfo>.
	* include/experimental/array: Do not include <functional>.
	* include/experimental/memory: Include <bits/functional_hash.h>
	instead of <functional>.
	* include/experimental/propagate_const: Include <bits/stl_function.h>,
	<bits/functional_hash.h>, and <bits/move.h> instead of <functional>.
	* include/experimental/tuple: Do not include <functional>.
	* include/std/future: Include <functional>.
	* include/std/memory: Do not include <functional>.
	* include/std/mutex: [_GLIBCXX_HAVE_TLS]: Likewise.
	* testsuite/20_util/shared_ptr/thread/default_weaktoshared.cc: Add
	missing includes.
	* testsuite/20_util/shared_ptr/thread/mutex_weaktoshared.cc: Likewise.
	* testsuite/20_util/specialized_algorithms/memory_management_tools/
	1.cc: Likewise.
	* testsuite/30_threads/call_once/60497.cc: Likewise.
	* testsuite/30_threads/lock/2.cc: Likewise.
	* testsuite/30_threads/thread/native_handle/cancel.cc: Likewise.
	* testsuite/experimental/algorithm/sample.cc: Likewise.
	* testsuite/experimental/array/make_array.cc: Likewise.
	* testsuite/experimental/array/neg.cc: Likewise. Adjust dg-error line.
	* testsuite/experimental/propagate_const/assignment/move_neg.cc:
	Adjust dg-error lines.
	* testsuite/experimental/propagate_const/cons/move_neg.cc: Likewise.
	* testsuite/experimental/propagate_const/requirements2.cc: Likewise.
	* testsuite/experimental/propagate_const/requirements3.cc: Likewise.
	* testsuite/experimental/propagate_const/requirements4.cc: Likewise.
	* testsuite/experimental/propagate_const/requirements5.cc: Likewise.

From-SVN: r241131
2016-10-13 17:59:19 +01:00
Jonathan Wakely
3e0c9334e9 Fix exception-specification of std::invoke
* include/bits/invoke.h (__invoke): Fix exception-specification.
	* include/std/functional (invoke): Likewise.
	* testsuite/20_util/function_objects/invoke/1.cc: New test.

From-SVN: r241089
2016-10-13 09:55:40 +01:00
Jonathan Wakely
e7722f1106 Define std::sample for C++17
* doc/xml/manual/status_cxx2017.xml: Add std::sample status.
	* doc/html/*: Regenerate.
	* include/experimental/algorithm (__sample): Move to bits/stl_algo.h
	and into namespace std.
	* include/bits/stl_algo.h (__sample): Define here. Fix invalid use
	of input iterator. Defend against overloaded comma operator.
	(sample): Define for C++17.
	* testsuite/25_algorithms/sample/1.cc: New test.

From-SVN: r241062
2016-10-12 16:26:48 +01:00
Jonathan Wakely
08a53a2eda Add missing return to uninitialized_default_construct_n
* include/bits/stl_uninitialized.h
	(__uninitialized_default_novalue_n_1<true>): Add missing return.
	* testsuite/20_util/specialized_algorithms/memory_management_tools/
	1.cc: Check return values of uninitialized_xxx_n algorithms.

From-SVN: r241033
2016-10-12 12:20:35 +01:00
Jonathan Wakely
4bb4acee68 Optimise std::list::assign(initializer_list<T>) slightly
* include/bits/stl_list.h (assign(initializer_list<value_type>)): Call
	_M_assign_dispatch directly with correct tag.

From-SVN: r240984
2016-10-11 11:33:41 +01:00
Jonathan Wakely
2c15eace95 More noexcept for standard mutex types and locks
* include/bits/std_mutex.h (mutex::native_handle)
	(lock_guard(mutex_type&, adopt_lock_t)
	(unique_lock(mutex_type&, adopt_lock_t): Add noexcept.
	* include/std/mutex (recursive_mutex, timed_mutex)
	(recursive_timed_mutex): Likewise.

From-SVN: r240980
2016-10-11 11:33:16 +01:00
Jonathan Wakely
9e023e3321 Implement constexpr std::addressof for C++17
* doc/xml/manual/intro.xml: Document DR 2296 status.
	* doc/xml/manual/status_cxx2017.xml: Update status.
	* include/bits/move.h (__addressof): Add _GLIBCXX_CONSTEXPR and
	call __builtin_addressof.
	(addressof): Add _GLIBCXX17_CONSTEXPR.
	* testsuite/20_util/addressof/requirements/constexpr.cc: New test.
	* testsuite/20_util/forward/c_neg.cc: Adjust dg-error lineno.
	* testsuite/20_util/forward/f_neg.cc: Likewise.

From-SVN: r240929
2016-10-10 16:34:28 +01:00
Jonathan Wakely
46942c8101 Define std::allocator<T>::is_always_equal
* include/bits/allocator.h (allocator<T>::is_always_equal): Define.
	* testsuite/20_util/allocator/requirements/typedefs.cc: Test for
	is_always_equal.
	* testsuite/util/testsuite_allocator.h
	(uneq_allocator::is_always_equal): Define as false_type.

From-SVN: r240920
2016-10-10 13:17:45 +01:00
Jonathan Wakely
208b8b69b6 Add noexcept to enable_shared_from_this::weak_from_this
* include/bits/shared_ptr.h (enable_shared_from_this::weak_from_this):
	Add noexcept.
	* include/bits/shared_ptr_base.h
	(__enable_shared_from_this::weak_from_this): Likewise.
	* testsuite/20_util/enable_shared_from_this/members/weak_from_this.cc:
	Test exception-specification of weak_from_this.

From-SVN: r240917
2016-10-10 12:44:05 +01:00
Jonathan Wakely
92805612f4 PR 70101 fix allocator-extended ctors for std::priority_queue
PR libstdc++/70101
	* include/bits/stl_queue.h (priority_queue): Fix allocator-extended
	constructors.
	* testsuite/23_containers/priority_queue/allocator.cc: New test.

From-SVN: r240781
2016-10-05 13:01:57 +01:00
Jonathan Wakely
a2a64b499a 77864 Fix noexcept conditions for map/set default constructors
PR libstdc++/77864
	* include/bits/stl_map.h (map::map()): Use nothrow constructibility
	of comparison function in conditional noexcept.
	* include/bits/stl_multimap.h (multimap::multimap()): Likewise.
	* include/bits/stl_multiset.h (multiset::multiset()): Likewise.
	* include/bits/stl_set.h (set::set()): Likewise.
	* testsuite/23_containers/map/cons/noexcept_default_construct.cc:
	New test.
	* testsuite/23_containers/multimap/cons/noexcept_default_construct.cc:
	Likewise.
	* testsuite/23_containers/multiset/cons/noexcept_default_construct.cc:
	Likewise.
	* testsuite/23_containers/set/cons/noexcept_default_construct.cc:
	Likewise.

From-SVN: r240780
2016-10-05 13:01:51 +01:00
Jonathan Wakely
d72d690a92 Remove invalid alias declaration from _Node_handle
* include/bits/node_handle.h (_Node_handle): Remove invalid and unused
	alias declaration.

From-SVN: r240779
2016-10-05 13:01:44 +01:00
Jonathan Wakely
e347987da8 Fix libstdc++ versioned namespace build
PR libstdc++/68323
	PR libstdc++/77794
	* config/abi/pre/gnu-versioned-namespace.ver: Add exports for
	__cxa_thread_atexit and __gnu_cxx::__freeres.
	* include/Makefile.am: Add <experimental/bits/lfts_config.h>
	* include/Makefile.in: Regenerate.
	* include.bits/basic_string.h: Fix nesting of versioned namespaces.
	* include/bits/c++config: Declare versioned namespaces for literals.
	* include/bits/regex.h (basic_regex, match_results): Add workarounds
	for PR c++/59256.
	* include/bits/uniform_int_dist.h: Fix nesting of versioned namespace.
	* include/std/chrono: Likewise.
	* include/std/complex: Likewise.
	* include/std/string_view: Likewise.
	* include/std/variant: Likewise. Add workaround for PR c++/59256.
	* include/experimental/bits/fs_fwd.h: Declare versioned namespace.
	* include/experimental/bits/lfts_config.h: Declare versioned
	namespaces.
	* include/experimental/algorithm: Include
	<experimental/bits/lfts_config.h>.
	* include/experimental/any: Likewise.
	* include/experimental/bits/erase_if.h: Likewise.
	* include/experimental/chrono: Likewise.
	* include/experimental/functional: Likewise.
	* include/experimental/memory_resource: Likewise.
	* include/experimental/optional: Likewise.
	* include/experimental/propagate_const: Likewise.
	* include/experimental/random: Likewise.
	* include/experimental/ratio: Likewise.
	* include/experimental/system_error: Likewise.
	* include/experimental/tuple: Likewise.
	* include/experimental/type_traits: Likewise.
	* include/experimental/utility: Likewise.
	* include/experimental/string_view: Likewise. Fix nesting of
	versioned namespaces.
	* include/experimental/bits/string_view.tcc: Reopen inline namespace
	for non-inline function definitions.
	* testsuite/17_intro/using_namespace_std_exp_neg.cc: New test.
	* testsuite/20_util/duration/literals/range.cc: Adjust dg-error line.
	* testsuite/experimental/any/misc/any_cast_neg.cc: Likewise.
	* testsuite/experimental/propagate_const/assignment/move_neg.cc:
	Likewise.
	* testsuite/experimental/propagate_const/cons/move_neg.cc: Likewise.
	* testsuite/experimental/propagate_const/requirements2.cc: Likewise.
	* testsuite/experimental/propagate_const/requirements3.cc: Likewise.
	* testsuite/experimental/propagate_const/requirements4.cc: Likewise.
	* testsuite/experimental/propagate_const/requirements5.cc: Likewise.
	* testsuite/ext/profile/mutex_extensions_neg.cc: Likewise.

From-SVN: r240714
2016-10-03 15:35:28 +01:00
Jonathan Wakely
6a0d23af49 Ensure "C++" language linkage for std::abs overloads
PR libstdc++/77814
	* include/bits/std_abs.h: Use "C++" language linkage.
	* testsuite/17_intro/headers/c++2011/linkage.cc: Move <complex.h> to
	the end. Add <stdalign.h>.

From-SVN: r240710
2016-10-03 12:50:46 +01:00
Jonathan Wakely
37b204de60 Implement LWG 2192 and LWG 2294 for std::abs
* doc/xml/manual/intro.xml: Document LWG 2192 changes.
	* doc/html/*: Regenerate.
	* include/Makefile.am: Add bits/std_abs.h.
	* include/Makefile.in: Regenerate.
	* include/bits/std_abs.h: New header defining all required overloads
	of std::abs in one place (LWG 2294).
	* include/c_global/cmath (abs(double), abs(float), abs(long double)):
	Move to bits/std_abs.h.
	(abs<_Tp>(_Tp)): Remove.
	* include/c_global/cstdlib (abs(long), abs(long long), abs(__int<N>)):
	Move to bits/std_abs.h.
	* testsuite/26_numerics/headers/cmath/dr2192.cc: New test.
	* testsuite/26_numerics/headers/cmath/dr2192_neg.cc: New test.
	* testsuite/26_numerics/headers/cstdlib/dr2192.cc: New test.
	* testsuite/26_numerics/headers/cstdlib/dr2192_neg.cc: New test.

From-SVN: r240660
2016-09-30 17:07:43 +01:00
Jonathan Wakely
1a08d2da0e Remove redefinition of __cpp_lib_array_constexpr
* include/bits/range_access.h (__cpp_lib_array_constexpr): Do not
	redefine macro defined in <bits/stl_iterator.h>.

From-SVN: r240488
2016-09-26 11:17:53 +01:00
Jonathan Wakely
976160b962 Add assertions to extract(const_iterator) functions
* include/bits/stl_map.h (map::extract(const_iterator)): Assert that
	iterator is not past-the-end.
	* include/bits/stl_multimap.h (multimap::extract(const_iterator)):
	Likewise.
	* include/bits/stl_multiset.h (multiset::extract(const_iterator)):
	Likewise.
	* include/bits/stl_set.h (set::extract(const_iterator)): Likewise.
	* include/bits/unordered_map.h (unordered_map::extract(const_iterator))
	(unordered_multimap::extract(const_iterator)): Likewise.
	* include/bits/unordered_set.h (unordered_set::extract(const_iterator))
	(unordered_multiset::extract(const_iterator)): Likewise.

From-SVN: r240487
2016-09-26 11:17:48 +01:00
Jonathan Wakely
1319041924 Avoid reallocation for basic_string::clear()
PR libstdc++/56166
	PR libstdc++/77582
	* include/bits/basic_string.h (basic_string::clear()): Drop reference
	and use empty rep.
	* include/ext/rc_string_base.h (__rc_string_base::_M_clear()):
	Likewise.
	* testsuite/21_strings/basic_string/56166.cc: New.
	* testsuite/ext/vstring/modifiers/clear/56166.cc: New.

From-SVN: r240447
2016-09-23 18:25:34 +01:00
Jonathan Wakely
a922c5ff6f Optimize truncating a basic_string
* include/bits/basic_string.h [_GLIBCXX_USE_CXX11_ABI]
	(basic_string::erase(size_type, size_type)): Add fast path for
	truncating the string, by calling _M_set_length directly.
	(basic_string::erase(__const_iterator, __const_iterator)): Likewise.
	* include/bits/basic_string.tcc [_GLIBCXX_USE_CXX11_ABI]
	(basic_string::resize(size_type, _CharT)): Likewise.

From-SVN: r240446
2016-09-23 18:25:23 +01:00
Jonathan Wakely
2dbe56bdfb Implement C++17 node extraction and insertion (P0083R5)
* doc/xml/manual/status_cxx2017.xml: Document status.
	* doc/html/*: Regenerate.
	* include/Makefile.am: Add bits/node_handle.h and reorder.
	* include/Makefile.in: Regenerate.
	* include/bits/hashtable.h (_Hashtable::node_type)
	(_Hashtable::insert_return_type, _Hashtable::_M_reinsert_node)
	(_Hashtable::_M_reinsert_node_multi, _Hashtable::extract)
	(_Hashtable::_M_merge_unique, _Hashtable::_M_merge_multi): Define.
	(_Hash_merge_helper): Define primary template.
	* include/bits/node_handle.h: New header.
	* include/bits/stl_map.h (map): Declare _Rb_tree_merge_helper as
	friend.
	(map::node_type, map::insert_return_type, map::extract, map::merge)
	(map::insert(node_type&&), map::insert(const_iterator, node_type&&)):
	Define new members.
	(_Rb_tree_merge_helper): Specialize for map.
	* include/bits/stl_multimap.h (multimap): Declare _Rb_tree_merge_helper
	as friend.
	(multimap::node_type, multimap::extract, multimap::merge)
	(multimap::insert(node_type&&))
	(multimap::insert(const_iterator, node_type&&)): Define.
	(_Rb_tree_merge_helper): Specialize for multimap.
	* include/bits/stl_multiset.h (multiset): Declare _Rb_tree_merge_helper
	as friend.
	(multiset::node_type, multiset::extract, multiset::merge)
	(multiset::insert(node_type&&))
	(multiset::insert(const_iterator, node_type&&)): Define.
	* include/bits/stl_set.h (set): Declare _Rb_tree_merge_helper as
	friend.
	(set::node_type, set::insert_return_type, set::extract, set::merge)
	(set::insert(node_type&&), set::insert(const_iterator, node_type&&)):
	Define.
	(_Rb_tree_merge_helper): Specialize for set.
	* include/bits/stl_tree.h (_Rb_tree): Declare _Rb_tree<> as friend.
	(_Rb_tree::node_type, _Rb_tree::insert_return_type)
	(_Rb_tree::_M_reinsert_node_unique, _Rb_tree::_M_reinsert_node_equal)
	(_Rb_tree::_M_reinsert_node_hint_unique)
	(_Rb_tree::_M_reinsert_node_hint_equal, _Rb_tree::extract)
	(_Rb_tree::_M_merge_unique, _Rb_tree::_M_merge_equal): Define.
	(_Rb_tree_merge_helper): Specialize for multiset.
	* include/bits/unordered_map.h (unordered_map): Declare
	unordered_map<> and unordered_multimap<> as friends.
	(unordered_map::node_type, unordered_map::insert_return_type)
	(unordered_map::extract, unordered_map::merge)
	(unordered_map::insert(node_type&&))
	(unordered_map::insert(const_iterator, node_type&&))
	(unordered_multimap): Declare _Hash_merge_helper as friend.
	(unordered_multimap::node_type, unordered_multimap::extract)
	(unordered_multimap::merge, unordered_multimap::insert(node_type&&))
	(unordered_multimap::insert(const_iterator, node_type&&)): Define.
	(_Hash_merge_helper): Specialize for unordered maps and multimaps.
	* include/bits/unordered_set.h (unordered_set, unordered_multiset):
	Declare _Hash_merge_helper as friend.
	(unordered_set::node_type, unordered_set::insert_return_type)
	(unordered_set::extract, unordered_set::merge)
	(unordered_set::insert(node_type&&))
	(unordered_set::insert(const_iterator, node_type&&)): Define.
	(unordered_multiset::node_type, unordered_multiset::extract)
	(unordered_multiset::merge, unordered_multiset::insert(node_type&&))
	(unordered_multiset::insert(const_iterator, node_type&&)): Define.
	(_Hash_merge_helper): Specialize for unordered sets and multisets.
	* include/debug/map.h (map): Add using declarations or forwarding
	functions for new members.
	* include/debug/map.h (multimap): Likewise.
	* include/debug/map.h (multiset): Likewise.
	* include/debug/map.h (set): Likewise.
	* include/debug/unordered_map (unordered_map, unordered_multimap):
	Likewise.
	* include/debug/unordered_set( unordered_set, unordered_multiset):
	Likewise.
	* python/libstdcxx/v6/printers.py (get_value_from_aligned_membuf): New
	helper function.
	(get_value_from_list_node, get_value_from_Rb_tree_node): Use helper.
	(StdNodeHandlePrinter): Define printer for node handles.
	(build_libstdcxx_dictionary): Register StdNodeHandlePrinter.
	* testsuite/23_containers/map/modifiers/extract.cc: New.
	* testsuite/23_containers/map/modifiers/merge.cc: New.
	* testsuite/23_containers/multimap/modifiers/extract.cc: New.
	* testsuite/23_containers/multimap/modifiers/merge.cc: New.
	* testsuite/23_containers/multiset/modifiers/extract.cc: New.
	* testsuite/23_containers/multiset/modifiers/merge.cc: New.
	* testsuite/23_containers/set/modifiers/extract.cc: New.
	* testsuite/23_containers/set/modifiers/merge.cc: New.
	* testsuite/23_containers/unordered_map/modifiers/extract.cc: New.
	* testsuite/23_containers/unordered_map/modifiers/merge.cc: New.
	* testsuite/23_containers/unordered_multimap/modifiers/extract.cc:
	New.
	* testsuite/23_containers/unordered_multimap/modifiers/merge.cc: New.
	* testsuite/23_containers/unordered_multiset/modifiers/extract.cc:
	New.
	* testsuite/23_containers/unordered_multiset/modifiers/merge.cc: New.
	* testsuite/23_containers/unordered_set/modifiers/extract.cc: New.
	* testsuite/23_containers/unordered_set/modifiers/merge.cc: New.
	* testsuite/23_containers/unordered_set/instantiation_neg.cc: Adjust
	dg-error lineno.
	* testsuite/libstdc++-prettyprinters/cxx17.cc: Test node handles.

From-SVN: r240363
2016-09-22 14:58:49 +01:00
Jonathan Wakely
64626fcaaa Always qualify std::forward in <variant>
* include/bits/uses_allocator.h (__uses_allocator_construct): Qualify
	std::forward and ::new. Cast pointer to void*.
	* include/std/variant (_Variant_storage, _Union, _Variant_base)
	(__access, __visit_invoke, variant, visit): Qualify std::forward.
	* testsuite/20_util/variant/compile.cc: Test for ADL problems.

From-SVN: r240344
2016-09-22 10:56:54 +01:00
Ville Voutilainen
f524d5b34a re PR libstdc++/77537 (pair constructors do not properly SFINAE)
PR libstdc++/77537
	Implement LWG 2729 for pair.
	* include/bits/stl_pair.h (_PCC): New.
	(_ConstructiblePair, _ImplicitlyConvertiblePair):
	Turn into static member functions of _PCC.
	(_MoveConstructiblePair, _ImplicitlyMoveConvertiblePair): Likewise.
	(_PCCP): New.
	(pair(const _T1&, const _T2&)): Adjust.
	(_PCCFP): New.
	(pair(const pair<_U1, _U2>&)): Adjust.
	(pair(_U1&&, const _T2&)): Likewise.
	(pair(const _T1&, _U2&&)): Likewise.
	(pair(_U1&&, _U2&&)): Likewise.
	(pair(pair<_U1, _U2>&&)): Likewise.
	(operator=(const pair&)): Make conditionally deleted.
	(operator=(pair&&)): Make conditionally suppressed.
	(operator=(const pair<_U1, _U2>&)): Constrain.
	(operator=(pair<_U1, _U2>&&): Likewise.
	* include/std/type_traits (__nonesuch): New.
	* testsuite/20_util/pair/traits.cc: New.

From-SVN: r240322
2016-09-21 19:48:35 +03:00
Ville Voutilainen
377f30c00f re PR libstdc++/77619 (uninitialized_meow_construct and friends not exception safe)
PR libstdc++/77619
	* include/bits/stl_construct.h: (_Construct_novalue): New.
	(_Destroy_n_aux, _Destroy_n): New.
	* include/bits/stl_uninitialized.h: (type_traits):
	New include in C++11 mode.
	(__uninitialized_default_novalue_1): New.
	(__uninitialized_default_novalue_n_1): Likewise.
	(__uninitialized_default_novalue): Likewise.
	(__uninitialized_default_novalue_n): Likewise.
	(__uninitialized_copy_n_pair): Likewise.
	(uninitialized_default_construct):
	Use __uninitialized_default_novalue.
	(uninitialized_default_construct_n):
	Use __uninitialized_default_novalue_n.
	(uninitialized_value_construct): Use __uninitialized_default.
	(uninitialized_value_construct_n): Use __uninitialized_default_n.
	(uninitialized_move): Use uninitialized_copy.
	(uninitialized_move_n): Use __uninitialized_copy_n_pair.
	(destroy_at): Use _Destroy.
	(destroy): Likewise.
	(destroy_n): Likewise.
	* testsuite/20_util/specialized_algorithms/
	memory_management_tools/1.cc: Add tests for exceptions,
	add tests for trivial cases for construct and move.

From-SVN: r240264
2016-09-20 18:15:36 +03:00
Ville Voutilainen
8e14a10cab Implement P0040R3, Extending memory management tools.
* include/bits/stl_uninitialized.h (utility): New include
	in C++17 mode.
	(uninitialized_default_construct): New.
	(uninitialized_default_construct_n): Likewise.
	(uninitialized_value_construct): Likewise.
	(uninitialized_value_construct_n): Likewise.
	(uninitialized_move): Likewise.
	(uninitialized_move_n): Likewise.
	(destroy_at, destroy, destroy_n): Likewise.
	* testsuite/20_util/specialized_algorithms/memory_management_tools/1.cc:
	New.

From-SVN: r240122
2016-09-13 22:26:02 +03:00
Jonathan Wakely
7663cae227 Constrain std::shared_ptr assignment and resetting
* include/bits/shared_ptr.h (_Assignable): New alias template.
	(shared_ptr::operator=(const shared_ptr<_Tp1>&))
	(shared_ptr::operator=(shared_ptr<_Tp1>&&))
	(shared_ptr::operator=(unique_ptr<_Tp1>&&)): Constrain with
	_Assignable.
	* include/bits/shared_ptr_base.h (_Assignable): New alias template.
	(__shared_ptr::operator=(const __shared_ptr<_Tp1>&))
	(__shared_ptr::operator=(__shared_ptr<_Tp1>&&))
	(__shared_ptr::operator=(unique_ptr<_Tp1>&&)): Constrain with
	_Assignable.
	(__shared_ptr::reset(_Tp1*), __shared_ptr::reset(_Tp1*, _Deleter))
	(__shared_ptr::reset(_Tp1*, _Deleter, _Alloc)): Constrain with
	_Convertible.
	* testsuite/20_util/shared_ptr/cons/43820_neg.cc: Change dg-error to
	match on any line.
	* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
	* testsuite/20_util/shared_ptr/assign/sfinae.cc: New test.
	* testsuite/20_util/shared_ptr/assign/shared_ptr_neg.cc: Update
	expected errors. Remove unnecessary code.
	* testsuite/20_util/shared_ptr/modifiers/reset_sfinae.cc: New test.

From-SVN: r239898
2016-08-31 17:57:20 +01:00
Jonathan Wakely
e46d22a821 Move comparison object in map/set move assignment
* include/bits/stl_tree.h (_Rb_tree::operator=(_Rb_tree&&)): Move
	comparison object.
	* testsuite/23_containers/set/move_comparison.cc: New test.

From-SVN: r239897
2016-08-31 17:57:14 +01:00
Tim Shen
4aebb4e4a6 re PR libstdc++/77356 (regex error for a ECMAScript syntax string)
PR libstdc++/77356
	* include/bits/regex_compiler.tcc(_M_insert_bracket_matcher,
	_M_expression_term): Modify to support dash literal.
	* include/bits/regex_scanner.h: Add dash as a token type to make
	a different from the mandated dash literal by escaping.
	* include/bits/regex_scanner.tcc(_M_scan_in_bracket): Emit dash
	token in bracket expression parsing.
	* testsuite/28_regex/regression.cc: Add new testcases.

From-SVN: r239794
2016-08-27 02:03:23 +00:00
Jonathan Wakely
10491e4c04 libstdc++/51960 move-construction for raw_storage_iterator
PR libstdc++/51960
	* doc/xml/manual/intro.xml: Document DR 2127 change.
	* doc/html/*: Regenerate.
	* include/bits/stl_raw_storage_iter.h (operator=(_Tp&&)): Add.
	(operator++(), operator++(int)): Use injected class name.
	* testsuite/20_util/raw_storage_iterator/dr2127.cc: New test.

From-SVN: r239781
2016-08-26 14:11:29 +01:00
Jonathan Wakely
86bbf15b6b Add new std::basic_string constructor (LWG 2583)
* config/abi/pre/gnu.ver (GLIBCXX_3.4, GLIBCXX_3.4.21): Use more
	precise patterns for basic_string constructors.
	(GLIBCXX_3.4.23): Export new constructors.
	* doc/xml/manual/intro.xml: Document LWG 2583 status.
	* doc/html/*: Regenerate.
	* include/bits/basic_string.h [_GLIBCXX_USE_CXX11_ABI]
	(basic_string(const basic_string&, size_type, const Alloc&)): Add
	new constructor for LWG 2583.
	(basic_string(const basic_string&, size_type, size_type)): Remove
	default argument.
	[!_GLIBCXX_USE_CXX11_ABI]: Likewise.
	* include/bits/basic_string.tcc [!_GLIBCXX_USE_CXX11_ABI]: Define it.
	* testsuite/21_strings/basic_string/cons/char/8.cc: New test.
	* testsuite/21_strings/basic_string/cons/wchar_t/8.cc: New test.

From-SVN: r239773
2016-08-26 11:41:37 +01:00
Aditya Kumar
9a38acdfdc Remove trailing whitespace in C++ headers
2016-08-24  Aditya Kumar  <hiraditya@msn.com>

	* include/bits/algorithmfwd.h: Remove trailing whitespace.
	* include/bits/shared_ptr_base.h: Likewise.

From-SVN: r239731
2016-08-24 09:03:01 +01:00
Jonathan Wakely
5ea387db6c libstdc++/77334 move assign RB trees of non-copyable types
PR libstdc++/77334
	* include/bits/stl_tree.h (_Rb_tree::_M_move_assign): New functions.
	(_Rb_tree::operator=(_Rb_tree&&)): Dispatch to _M_move_assign.
	* testsuite/23_containers/map/77334.cc: New test.

From-SVN: r239698
2016-08-23 14:15:12 +01:00
Jonathan Wakely
b405d54fcd Implement resolution of LWG DR 685 precisely
PR libstdc++/71771
	* include/bits/stl_iterator.h
	(operator-(reverse_iterator<Iter>, reverse_iterator<Iter>): Only
	define for C++98 mode.
	(operator-(move_iterator<Iter>, move_iterator<Iter>): Don't define.
	* testsuite/24_iterators/headers/iterator/synopsis.cc: Use
	-std=gnu++98.
	* testsuite/24_iterators/headers/iterator/synopsis_c++11.cc: New test.
	* testsuite/24_iterators/headers/iterator/synopsis_c++14.cc: New test.
	* testsuite/24_iterators/headers/iterator/synopsis_c++17.cc: New test.
	* testsuite/24_iterators/move_iterator/greedy_ops.cc: Don't test
	difference operator.
	* testsuite/24_iterators/reverse_iterator/greedy_ops.cc: Only test
	difference operator for C++98.
	* testsuite/24_iterators/reverse_iterator/71771.cc: New test.

From-SVN: r239691
2016-08-23 11:13:26 +01:00
Jonathan Wakely
06db992005 Add constexpr to <iterator> and <array> for C++17
* include/bits/c++config (_GLIBCXX17_CONSTEXPR): Define.
	* include/bits/range_access.h (begin, end, rbegin, rend, crbegin)
	(crend): Add _GLIBCXX17_CONSTEXPR as per P0031R0.
	* include/bits/stl_iterator.h (reverse_iterator, move_iterator)
	(__make_reverse_iterator, make_reverse_iterator, make_move_iterator):
	Likewise.
	* include/bits/stl_iterator_base_funcs.h (__distance, __advance): Add
	_GLIBCXX14_CONSTEXPR.
	(distance, advance, next, prev): Add _GLIBCXX17_CONSTEXPR.
	* include/std/array (array::begin, array::end, array::rbegin)
	(array::rend, array::cbegin, array:cend, array::crbegin)
	(array::crend, array::operator[], array::at, array::front)
	(array::back, array::data): Likewise.
	* testsuite/24_iterators/headers/iterator/range_access.cc: Replace
	with separate tests for C++11, C++14, and C++17.
	* testsuite/24_iterators/headers/iterator/range_access_c++11.cc: New.
	* testsuite/24_iterators/headers/iterator/range_access_c++14.cc: New.
	* testsuite/24_iterators/headers/iterator/range_access_c++17.cc: New.

From-SVN: r239690
2016-08-23 11:13:12 +01:00
Tim Shen
d79d625275 Split _M_dfs() into smaller functions.
* regex_executor.h(_M_handle_repeat, _M_handle_subexpr_begin)
	(_M_handle_subexpr_end, _M_handle_line_begin_assertion)
	(_M_handle_line_end_assertion, _M_handle_word_boundary)
	(_M_handle_subexpr_lookahead, _M_handle_match)
	(_M_handle_backref, _M_handle_accept, _M_handle_alternative):
	Add separate function declarations.
	* regex_executor.tcc: Split _M_dfs() into multiple handler functions.

From-SVN: r239673
2016-08-22 19:50:15 +00:00
Tim Shen
197c757cb1 Implement <variant>
* include/Makefile.am: Add new file std/variant.
	* include/Makefile.in: Generated from Makefile.am.
	* include/bits/enable_special_members.h: Add a tag type to allow
	the construction in non-default constructor.
	* include/bits/uses_allocator.h: Add convenience traits to
	detect constructibility.
	* include/std/variant: Implement <variant>.
	* testsuite/20_util/variant/compile.cc: Compile-time tests.
	* testsuite/20_util/variant/run.cc: Runtime tests.

From-SVN: r239590
2016-08-18 20:31:26 +00:00
Jonathan Wakely
657213f736 PR 77264 constrain new std::basic_string overloads
PR libstdc++/77264
	* include/bits/basic_string.h (operator=(__sv_type)
	(append(__sv_type), assign(__sv_type), insert(size_type, __sv_type))
	(replace(size_type, size_type, __sv_type))
	(replace(const_iterator, const_iterator, __sv_type))
	(find(__sv_type, size_type), rfind(__sv_type, size_type))
	(compare(size_type, size_type, __sv_type)): Reformat.
	(_If_sv): Define helper for SFINAE constaints.
	(append(const _Tp&, size_type, size_type))
	(assign(const _Tp&, size_type, size_type))
	(insert(size_type, const _Tp&, size_type, size_type))
	(replace(size_type, size_type, const _Tp&, size_type, size_type)):
	Use _If_sv.
	* testsuite/21_strings/basic_string/modifiers/append/char/4.cc: Test
	SFINAE constraints.
	* testsuite/21_strings/basic_string/modifiers/append/wchar_t/4.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/replace/char/7.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/replace/wchar_t/7.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/assign/char/4.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/assign/wchar_t/4.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/insert/char/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/insert/wchar_t/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/replace/char/7.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operations/compare/char/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operations/compare/wchar_t/2.cc:
	Likewise.

From-SVN: r239532
2016-08-17 14:38:52 +01:00
Jonathan Wakely
32917686b0 PR 72847 Prevent double-free in std::vector<bool>
PR libstdc++/72847
	* include/bits/stl_bvector.h (_Bvector_base::_M_deallocate): Zero
	pointers to start and end of storage.
	* testsuite/23_containers/vector/bool/72847.cc: New test.
	* include/bits/vector.tcc (vector<bool>::_M_reallocate): Only update
	_M_finish after deallocating.
	(vector<bool>::_M_fill_insert): Likewise.
	(vector<bool>::_M_insert_range): Likewise.
	(vector<bool>::_M_insert_aux): Likewise.

From-SVN: r239497
2016-08-16 12:33:16 +01:00
Ville Voutilainen
68a51b68bd Implement LWG 2758.
* include/bits/basic_string.h
	(append(__sv_type, size_type, size_type)): Turn into a template,
	change parameter type, constrain, add a conversion to __sv_type
	from the dependent parameter type.
	(assign(__sv_type, size_type, size_type)): Likewise.
	(insert(size_type, __sv_type, size_type, size_type)): Likewise.
	(replace(size_type, size_type, __sv_type, size_type, size_type)):
	Likewise.
	(compare(size_type, size_type,__sv_type, size_type, size_type)):
	Likewise.
	* testsuite/21_strings/basic_string/lwg2758.cc: New.

From-SVN: r239370
2016-08-11 17:45:23 +03:00
Jonathan Wakely
3e9f67e6a2 Add std::apply for C++17
* doc/xml/manual/status_cxx2017.xml: Add missing LFTSv2 features.
	* doc/html/manual/status.html: Regenerate.
	* include/Makefile.am: Add new header.
	* include/Makefile.in: Regenerate.
	* include/bits/invoke.h: New header.
	(__invoke): Make constexpr. Add && to types in exception specification.
	* include/experimental/tuple (apply, __apply_impl): Fix non-reserved
	names. Include <bits/invoke.h> and use std::__invoke.
	* include/std/functional (__invfwd, __invoke_impl, __invoke): Move to
	new header.
	(invoke): Add && to types in exception specification.
	* include/std/tuple (apply, __apply_impl): Define for C++17.
	* testsuite/20_util/tuple/apply/1.cc: New test.
	* testsuite/20_util/tuple/element_access/get_neg.cc: Adjust dg-error
	lineno.

From-SVN: r239183
2016-08-06 01:06:02 +01:00