Commit Graph

6237 Commits

Author SHA1 Message Date
Jonathan Wakely 4fe5c8c730 Add noexcept to filesystem::path query functions
In the standard these member functions are specified in terms of the
potentially-throwing path decompositions functions, but we implement
them without constructing any new paths or doing anything else that can
throw.

	PR libstdc++/71044
	* include/bits/fs_path.h (path::has_root_name)
	(path::has_root_directory, path::has_root_path)
	(path::has_relative_path, path::has_parent_path)
	(path::has_filename, path::has_stem, path::has_extension)
	(path::is_absolute, path::is_relative, path::_M_find_extension): Add
	noexcept.
	* src/c++17/fs_path.cc (path::has_root_name)
	(path::has_root_directory, path::has_root_path)
	(path::has_relative_path, path::has_parent_path)
	(path::has_filename, path::_M_find_extension): Add noexcept.

From-SVN: r268713
2019-02-09 00:25:39 +00:00
Jonathan Wakely 373c726ec6 PR libstdc++/89102 fix common_type<> and common_type<T> specializations
This is a partial implementation of the revised std::common_type rules
from P0435R1.

	PR libstdc++/89102 (partial)
	* include/std/type_traits (common_type<>): Define.
	(common_type<T>): Derive from common_type<T, T>.
	* testsuite/20_util/common_type/requirements/explicit_instantiation.cc:
	Test zero-length template argument list.
	* testsuite/20_util/common_type/requirements/sfinae_friendly_1.cc:
	Test additional single argument cases.
	* testsuite/20_util/common_type/requirements/sfinae_friendly_2.cc:
	Adjust expected error.

From-SVN: r268586
2019-02-06 17:25:26 +00:00
Jonathan Wakely 5bb89e0a28 PR libstdc++/89128 add deduction guides for container adaptors
PR libstdc++/89128
	* include/bits/stl_queue.h (queue, priority_queue): Add deduction
	guides.
	* include/bits/stl_stack.h (stack): Likewise.
	* testsuite/23_containers/priority_queue/deduction.cc: New test.
	* testsuite/23_containers/queue/deduction.cc: New test.
	* testsuite/23_containers/stack/deduction.cc: New test.

From-SVN: r268566
2019-02-05 22:58:22 +00:00
Jonathan Wakely ed99e818e0 PR libstdc++/89194 untangle is_convertible and is_nothrow_convertible
The additional logic added to __is_convertible_helper in order to
support is_nothrow_convertible makes some uses of is_convertible
ill-formed. This appears to be due to PR c++/87603, but can be avoided
just by defining a separate helper for is_nothrow_convertible. The same
problems are likely to still exist for is_nothrow_convertible, but that
is new and so won't cause regressions for existing users of
is_convertible.

	PR libstdc++/89194
	* include/std/type_traits (__is_convertible_helper)
	(__is_convertible_helper<_From, _To, false>): Revert changes to
	support is_nothrow_convertible.
	(__is_nt_convertible_helper): New helper.
	(is_nothrow_convertible): Use __is_nt_convertible_helper.

From-SVN: r268543
2019-02-05 15:45:24 +00:00
Jonathan Wakely 258bd1d63a PR libstdc++/89130 restore support for non-MoveConstructible types
The changes to "relocate" std::vector elements can lead to new errors
outside the immediate context, because moving the elements to new
storage no longer makes use of the move-if-noexcept utilities. This
means that types with deleted moves no longer degenerate to copies, but
are just ill-formed. The errors happen while instantiating the
noexcept-specifier for __relocate_object_a, when deciding whether to try
to relocate.

This patch introduces indirections to avoid the ill-formed
instantiations of std::__relocate_object_a. In order to avoid using
if-constexpr prior to C++17 this is done by tag dispatching. After this
patch all uses of std::__relocate_a are guarded by checks that will
support sensible code (i.e. code not using custom allocators that fool
the new checks).

	PR libstdc++/89130
	* include/bits/alloc_traits.h (__is_copy_insertable_impl): Rename to
	__is_alloc_insertable_impl. Replace single type member with two
	members, one for each of copy and move insertable.
	(__is_move_insertable): New trait for internal use.
	* include/bits/stl_vector.h (vector::_S_nothrow_relocate(true_type))
	(vector::_S_nothrow_relocate(true_type)): New functions to
	conditionally check if __relocate_a can throw.
	(vector::_S_use_relocate()): Dispatch to _S_nothrow_relocate based
	on __is_move_insertable.
	(vector::_S_do_relocate): New overloaded functions to conditionally
	call __relocate_a.
	(vector::_S_relocate): New function that dispatches to _S_do_relocate
	based on _S_use_relocate.
	* include/bits/vector.tcc (vector::reserve, vector::_M_realloc_insert)
	(vector::_M_default_append): Call _S_relocate instead of __relocate_a.
	* testsuite/23_containers/vector/modifiers/push_back/89130.cc: New.

From-SVN: r268537
2019-02-05 14:45:00 +00:00
Jonathan Wakely 2781287255 PR libstdc++/89090 avoid C++17 features in C++11/C++14 code
Although GCC and Clang both allow these features pre-C++17 in system
headers, Clang does issue warnings with -Wsystem-headers. It can also
complicate bisection and/or testcase reduction if # line markers are
stripped, because the code won't be known to come from system headers.

	PR libstdc++/89090
	* include/bits/stl_uninitialized.h (__relocate_a_1): Make unused
	parameter unnamed. Add message to static assertion.
	* include/bits/vector.tcc (vector::reserve, vector::_M_realloc_insert)
	(vector::_M_default_append): Use _GLIBCXX17_CONSTEXPR for if constexpr
	in C++11 code.

From-SVN: r268536
2019-02-05 14:44:56 +00:00
Marc Glisse 9aa2470ab2 Rename __is_trivially_relocatable to __is_bitwise_relocatable.
2019-02-05  Marc Glisse  <marc.glisse@inria.fr>

	PR libstdc++/87106
	* include/bits/stl_uninitialized.h (__is_trivially_relocatable):
	Rename...
	(__is_bitwise_relocatable): ... to this.
	(__relocate_a_1): Adapt.
	* include/bits/stl_deque.h (__is_trivially_relocatable): Rename...
	(__is_bitwise_relocatable): ... to this.

From-SVN: r268532
2019-02-05 09:33:36 +00:00
Jonathan Wakely f7f07df5e2 Avoid ambiguity between C++2a std::erase_if and LFTS version
These calls should have been qualified to avoid ADL anyway, but in C++2a
it becomes essential to qualify the calls in experimental::erase because
std::erase_if is also declared and the calls become ambiguous.

	* include/experimental/forward_list (experimental::erase): Qualify
	call to erase_if.
	* include/experimental/list (experimental::erase): Likewise.
	* include/std/forward_list (std::erase): Likewise.
	* include/std/list (std::erase): Likewise.

From-SVN: r268356
2019-01-29 00:47:38 +00:00
Jonathan Wakely 1f48525ded Ensure pool resources always use normal mode vector
The __pool_resource::_M_unpooled member was declared with type
std::vector, which means that the type depends on whether debug mode is
active or not. Because the non-inline definitions in
src/c++17/memory_resource.cc are never compiled with debug mode, the
type declared in the header doesn't match the type in the library
definitions, leading to undefined behaviour.

The solution is to ensure the header always uses the non-debug vector,
even when debug mode is active. To make this easier a new alias template
is defined: _GLIBCXX_STD_C::pmr::vector.

	* include/std/memory_resource (__pool_resource::_M_unpooled): Use
	normal mode vector, even for debug mode.
	* include/std/vector [_GLIBCXX_DEBUG] (_GLIBCXX_STD_C::pmr::vector):
	Define alias template for normal mode vector.

From-SVN: r268354
2019-01-29 00:47:25 +00:00
Jonathan Wakely c98f255154 PR libstdc++/68737 Do not use vsnprintf on HPUX
It doesn't conform to the spec, so use vsprintf with a large buffer
instead.

	PR libstdc++/68737
	* config/locale/generic/c_locale.h (__convert_from_v)
	[_GLIBCXX_USE_C99_STDIO]: Also check _GLIBCXX_HAVE_BROKEN_VSNPRINTF.
	* config/os/hpux/os_defines.h: Define _GLIBCXX_HAVE_BROKEN_VSNPRINTF.
	* include/bits/locale_facets.tcc (num_put::_M_insert_float)
	[_GLIBCXX_USE_C99_STDIO]: Also check _GLIBCXX_HAVE_BROKEN_VSNPRINTF.

From-SVN: r268350
2019-01-28 23:58:57 +00:00
Jonathan Wakely e658669fe1 PR libstdc++/88840 delay evaluation of constant until type is complete
Clang fails to compile std::vector<Incomplete> because the static member
__use_relocate cannot be evaluated for an incomplete type. Replace with
a static member function that will not be odr-used until needed, by
which point the type must be complete.

	PR libstdc++/88840
	* include/bits/stl_vector.h (vector::__use_relocate): Replace static
	data member with static member function _S_use_relocate().
	* include/bits/vector.tcc (vector::reserve, vector::_M_realloc_insert)
	(vector::_M_default_append): Use _S_use_relocate() instead of
	__use_relocate.

From-SVN: r268239
2019-01-24 15:39:25 +00:00
Jakub Jelinek 8f10fb5065 re PR ipa/86590 (Codegen is poor when passing std::string by value with _GLIBCXX_EXTERN_TEMPLATE undefined)
PR libstdc++/86590
	* include/bits/char_traits.h (__constant_string_p,
	__constant_char_array_p): Use __builtin_is_constant_evaluated if
	available.

From-SVN: r268112
2019-01-21 12:55:52 +01:00
Ulrich Drepper d715f55431 Fix after P0600.
gcc/testsuite/ChangeLog
2019-02-20  Ulrich Drepper  <drepper@redhat.com>

	Fix after P0600.
	* g++.dg/init/new39.C: Don't just ignore result of new.

libstdc++/ChangeLog
2019-02-20  Ulrich Drepper  <drepper@redhat.com>

	Implement C++20 P0600r1.
	* include/backward/hash_map: Add nodiscard attribute to empty.
	* include/backward/hash_set: Likewise.
	* backward/hashtable.h: Likewise.
	* include/bits/basic_string.h: Likewise.
	* include/bits/forward_list.h: Likewise.
	* include/bits/hashtable.h: Likewise.
	* include/bits/regex.h: Likewise.
	* include/bits/stl_deque.h: Likewise.
	* include/bits/stl_list.h: Likewise.
	* include/bits/stl_map.h: Likewise.
	* include/bits/stl_multimap.h: Likewise.
	* include/bits/stl_multiset.h: Likewise.
	* include/bits/stl_queue.h: Likewise.
	* include/bits/stl_set.h: Likewise.
	* include/bits/stl_stack.h: Likewise.
	* include/bits/stl_tree.h: Likewise.
	* include/bits/stl_vector.h: Likewise.
	* include/bits/unordered_map.h: Likewise.
	* include/bits/unordered_set.h: Likewise.
	* include/debug/array: Likewise.
	* include/experimental/any: Likewise.
	* include/experimental/bits/fs_path.h: Likewise.
	* include/experimental/internet: Likewise.
	* include/experimental/string_view: Likewise.
	* include/ext/pb_ds/detail/bin_search_tree_/info_fn_imps.hpp:
	Likewise.
	* include/ext/pb_ds/detail/binary_heap_/binary_heap_.hpp:
	Likewise.
	* include/ext/pb_ds/detail/binary_heap_/info_fn_imps.hpp:
	Likewise.
	* include/ext/pb_ds/detail/cc_hash_table_map_/cc_ht_map_.hpp:
	Likewise.
	* include/ext/pb_ds/detail/cc_hash_table_map_/info_fn_imps.hpp:
	Likewise.
	* include/ext/pb_ds/detail/cc_hash_table_map_/size_fn_imps.hpp:
	Likewise.
	* include/ext/pb_ds/detail/gp_hash_table_map_/gp_ht_map_.hpp:
	Likewise.
	* include/ext/pb_ds/detail/gp_hash_table_map_/info_fn_imps.hpp:
	Likewise.
	* include/ext/pb_ds/detail/left_child_next_sibling_heap_/info_fn_imps.hpp:
	Likewise.
	*
include/ext/pb_ds/detail/left_child_next_sibling_heap_/left_child_next_sibling_heap_.hpp:
	Likewise.
	* include/ext/pb_ds/detail/list_update_map_/info_fn_imps.hpp:
	Likewise.
	* include/ext/pb_ds/detail/list_update_map_/lu_map_.hpp:
	Likewise.
	* include/ext/pb_ds/detail/ov_tree_map_/info_fn_imps.hpp:
	Likewise.
	* include/ext/pb_ds/detail/ov_tree_map_/ov_tree_map_.hp:
	Likewise.
	* include/ext/pb_ds/detail/pat_trie_/info_fn_imps.hpp:
	Likewise.
	* include/ext/pb_ds/detail/pat_trie_/pat_trie_.hpp:
	Likewise.
	* include/ext/pb_ds/detail/rc_binomial_heap_/rc.hpp:
	Likewise.
	* include/ext/pb_ds/detail/tree_trace_base.hpp: Likewise.
	* include/ext/pb_ds/trie_policy.hpp: Likewise.
	* include/ext/rope: Likewise.
	* include/ext/slist: Likewise.
	* include/ext/vstring.h: Likewise.
	* include/profile/array: Likewise.
	* include/std/array: Likewise.
	* include/tr1/array: Likewise.
	* include/tr1/hashtable.h: Likewise.
	* include/tr1/regex: Likewise.
	* include/tr2/dynamic_bitset: Likewise.
	* include/bits/alloc_traits.h: Add nodiscard attribute to
	allocate.
	* include/experimental/memory_resource: Likewise.
	* include/ext/alloc_traits.h: Likewise.
	* include/ext/array_allocator.h: Likewise.
	* include/ext/bitmap_allocator.h: Likewise.
	* include/ext/debug_allocator.h: Likewise.
	* include/ext/extptr_allocator.h: Likewise.
	* include/ext/mt_allocator.h: Likewise.
	* include/ext/new_allocator.h: Likewise.
	* include/ext/pool_allocator.h: Likewise.
	* include/ext/throw_allocator.h: Likewise.
	* include/std/scoped_allocator: Likewise.
	* libsupc++/eh_alloc.cc: Likewise.
	* include/std/future: Add nodiscard attribute to async.
	* libsupc++/new: Add nodiscard attribute to new.

From-SVN: r268111
2019-01-21 11:47:30 +00:00
Jonathan Wakely fb54aa5915 PR libstdc++/88782 avoid ODR problems in std::make_shared
The old version of _Sp_counted_ptr_inplace::_M_get_deleter (up to GCC
8.2.0) expects to be passed a real std::typeinfo object, so mixing that
with the new definition of the __shared_ptr constructor (which always
passes the fake tag) leads to accessing the fake object as a real
std::typeinfo. Instead of trying to make it safe to mix the old and new
definitions, just stop using that function. By passing a reference to
__shared_ptr::_M_ptr to the __shared_count constructor it can be set
directly, without needing to obtain the pointer via the _M_get_deleter
back-channel. This avoids a virtual dispatch (which fixes PR 87514).

This means that code built against new libstdc++ headers doesn't use
_M_get_deleter at all, and so make_shared works the same whether RTTI is
enabled or not.

Also change _M_get_deleter so that it checks for a real type_info object
even when RTTI is disabled, by calling a library function. Unless
libstdc++ itself is built without RTTI that library function will be
able to test if it's the right type_info. This means the new definition
of _M_get_deleter can handle both the fake type_info tag and a real
type_info object, even if built without RTTI.

If linking to objects built against older versions of libstdc++ then if
all objects use -frtti or all use -fno-rtti, then the caller of
_M_get_deleter and the definition of _M_get_deleter will be consistent
and it will work. If mixing -frtti with -fno-rtti it can still fail if
the linker picks an old definition of _M_get_deleter and an old
__shared_ptr constructor that are incompatible. In that some or all
objects might need to be recompiled.

	PR libstdc++/87514
	PR libstdc++/87520
	PR libstdc++/88782
	* config/abi/pre/gnu.ver (GLIBCXX_3.4.26): Export new symbol.
	* include/bits/shared_ptr.h
	(shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...))
	(allocate_shared): Change to use new tag type.
	* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_eq):
	Declare new member function.
	(_Sp_alloc_shared_tag): Define new type.
	(_Sp_counted_ptr_inplace): Declare __shared_count<_Lp> as a friend.
	(_Sp_counted_ptr_inplace::_M_get_deleter) [!__cpp_rtti]: Use
	_Sp_make_shared_tag::_S_eq to check type_info.
	(__shared_count(Ptr, Deleter),__shared_count(Ptr, Deleter, Alloc)):
	Constrain to prevent being called with _Sp_alloc_shared_tag.
	(__shared_count(_Sp_make_shared_tag, const _Alloc&, Args&&...)):
	Replace constructor with ...
	(__shared_count(Tp*&, _Sp_alloc_shared_tag<_Alloc>, Args&&...)): Use
	reference parameter so address of the new object can be returned to
	the caller. Obtain the allocator from the tag type.
	(__shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...)): Replace
	constructor with ...
	(__shared_ptr(_Sp_alloc_shared_tag<Alloc>, Args&&...)): Pass _M_ptr
	to the __shared_count constructor.
	(__allocate_shared): Change to use new tag type.
	* src/c++11/shared_ptr.cc (_Sp_make_shared_tag::_S_eq): Define.

From-SVN: r268086
2019-01-18 21:28:48 +00:00
Ulrich Drepper ec0d53719f PR libstdc++/88738 treat shared_ptr and unique_ptr more like plain old pointers
PR libstdc++/88738
        Warn about unused comparisons of shared_ptr/unique_ptr
        * include/bits/c++config [_GLIBCXX_NODISCARD]: Define.
        * include/bits/shared_ptr.h: Use it for operator ==, !=,
        <, <=, >, >= for shared_ptr.
        * include/bits/unique_ptr.h: Likewise for unique_ptr.

From-SVN: r267964
2019-01-16 08:01:22 +00:00
Jonathan Wakely 10ddff67d3 Update value of __cpp_lib_shared_ptr_arrays macro
* include/bits/shared_ptr_base.h (__cpp_lib_shared_ptr_arrays): Define
	as 201611L, because P0497R0 changes are supported.
	* include/std/version (__cpp_lib_shared_ptr_arrays): Likewise.

From-SVN: r267938
2019-01-15 13:13:11 +00:00
Jonathan Wakely 6e3dd211ca Fix more missing or incorrect feature test macros
* include/bits/erase_if.h [__cplusplus > 201703L]
	(__cpp_lib_erase_if): Only define for C++2a.
	* include/std/iterator [__cplusplus >= 201402L && !_GLIBCXX_DEBUG]
	(__cpp_lib_null_iterators): Define.
	* include/std/version [__cplusplus >= 201402L && !_GLIBCXX_DEBUG]
	(__cpp_lib_null_iterators): Define.
	[__cpp_impl_destroying_delete] (__cpp_lib_destroying_delete): Define.

From-SVN: r267937
2019-01-15 12:58:19 +00:00
Jonathan Wakely 56a9eaf9ab Fix missing or incorrect feature test macros
* doc/xml/manual/status_cxx2017.xml: Document P0032R3 and P0307R2
	status.
	* include/bits/stl_uninitialized.h (__cpp_lib_raw_memory_algorithms):
	Define.
	* include/std/any (__cpp_lib_any): Define as 201606L, because P0032R3
	changes are supported.
	* include/std/optional (__cpp_lib_optional): Likewise.
	* include/std/variant (__cpp_lib_variant): Likewise.
	* include/std/version [!__STRICT_ANSI__]
	(__cpp_lib_uncaught_exceptions): Define as long integer.
	[__cplusplus >= 201703L] (__cpp_lib_any)
	(__cpp_lib_raw_memory_algorithms, __cpp_lib_uncaught_exceptions)
	(__cpp_lib_variant): Define for C++17.
	[__cplusplus >= 201703L] (__cpp_lib_optional): Update value and define
	as long integer.
	* libsupc++/exception (__cpp_lib_uncaught_exceptions): Define as long
	integer.

From-SVN: r267936
2019-01-15 12:01:12 +00:00
Jonathan Wakely aaeac1568d P0357R3 reference_wrapper for incomplete types
This patch implements the C++2a proposal to allow incomplete types in
std::reference_wrapper, which was previously undefined.

The change cannot be implemented for earlier standards, because prior to
C++2a std::reference_wrapper has a weak result type, so must inspect the
template argument to see if it defines a nested result_type member. That
is deprecated (but still required) in C++17, and removed from C++2a.

The removal of the base class from reference_wrapper is a potential ABI
change, as it could alter the layout of a type which derives from
reference_wrapper<T> and from an empty type with _Weak_result_type<T> as
a base class.  Previously the repeated _Weak_result_type<T> base class
would have prevented the empty base-class optimization, but if
reference_wrapper<T> no longer derives from it, the empty class could be
placed at the same address as the reference_wrapper<T> base.  In
practice, the only types which derive from _Weak_result_type or from
_Reference_wrapper_base_memfun or any of its base classes are non-empty
types defined in libstdc++: std::reference_wrapper, std::function, and
std::_Bind. As they are non-empty types, they are not eligible for EBO
anyway.

	* include/bits/refwrap.h [__cplusplus > 201703L]
	(_Refwrap_base_arg1, _Refwrap_base_arg2, _Reference_wrapper_base)
	(_Reference_wrapper_base_memfun): Do not define for C++2a.
	(reference_wrapper): Do not derive from _Reference_wrapper_base_memfun
	for C++2a.
	(reference_wrapper::operator()): Add static assertion.
	* testsuite/20_util/reference_wrapper/incomplete.cc: New test.

From-SVN: r267866
2019-01-11 23:41:11 +00:00
Jonathan Wakely 5e9aed14dc P0972R0 <chrono> zero(), min(), and max() should be noexcept
This paper has been included in the C++20 draft, but the changes to add
noexcept can be made unconditionally, to apply for C++11 too.

	* include/std/chrono (duration_values::zero(), duration_values::min())
	(duration_values::max()): Add noexcept.
	(duration::zero(), duration::min(), duration::max()): Likewise.
	(time_point::zero(), time_point::min(), time_point::max()): Likewise.
	* testsuite/20_util/duration/requirements/noexcept.cc: New test.
	* testsuite/20_util/time_point/requirements/noexcept.cc: New test.

From-SVN: r267865
2019-01-11 23:41:05 +00:00
Jonathan Wakely e334d7a702 Fix location of __cpp_lib_erase_if macro
This macro should only be defined for C++2a, not C++17.

	* include/std/version (__cpp_lib_erase_if): Move to C++20 group.

From-SVN: r267863
2019-01-11 23:40:58 +00:00
Jakub Jelinek 8aa1550e23 Remove trailing whitespace from latest commit.
From-SVN: r267849
2019-01-11 17:55:13 +01:00
Jakub Jelinek 134a6f7b10 type_traits (__cpp_lib_is_constant_evaluated): Define.
* include/std/type_traits (__cpp_lib_is_constant_evaluated): Define.
	* include/std/version (__cpp_lib_is_constant_evaluated): Define.

From-SVN: r267847
2019-01-11 17:01:23 +01:00
Jonathan Wakely 17a73b3c47 PR libstdc++/88802 define std::hash<nullptr_t> for C++17
PR libstdc++/88802
	* include/bits/functional_hash.h (hash<nullptr_t>): Define
	specialization for C++17 (P0513R0, LWG 2817).
	* testsuite/20_util/hash/nullptr.cc: New test.

From-SVN: r267845
2019-01-11 14:54:49 +00:00
Jonathan Wakely 45a8d80fec Define __cpp_lib_erase_if feature test macro
The C++2a draft specifies the value 201811L for this, but as an
extension we return the number of elements erased. This is expected to
be standardised, so the macro has the value 201900L until a proper value
is specified in the draft.

	* include/bits/erase_if.h: Define __cpp_lib_erase_if.
	* include/std/deque: Likewise.
	* include/std/forward_list: Likewise.
	* include/std/list: Likewise.
	* include/std/string: Likewise.
	* include/std/vector: Likewise.
	* include/std/version: Likewise.
	* testsuite/21_strings/basic_string/erasure.cc: Test macro.
	* testsuite/23_containers/deque/erasure.cc: Likewise.
	* testsuite/23_containers/forward_list/erasure.cc: Likewise.
	* testsuite/23_containers/list/erasure.cc: Likewise.
	* testsuite/23_containers/map/erasure.cc: Likewise.
	* testsuite/23_containers/set/erasure.cc: Likewise.
	* testsuite/23_containers/unordered_map/erasure.cc: Likewise.
	* testsuite/23_containers/unordered_set/erasure.cc: Likewise.
	* testsuite/23_containers/vector/erasure.cc: Likewise.

From-SVN: r267810
2019-01-10 13:49:31 +00:00
Jonathan Wakely cbe0bca404 Check AI_NUMERICSERV is defined before using it
The AI_NUMERICSERV constant is missing from old Darwin systems, so only
use it if it's supported.

	* include/experimental/internet [AI_NUMERICSERV]
	(resolver_base::numeric_service): Define conditionally.
	* testsuite/experimental/net/internet/resolver/base.cc: Test it
	conditionally.
	* testsuite/experimental/net/internet/resolver/ops/lookup.cc:
	Likewise.

From-SVN: r267809
2019-01-10 13:21:54 +00:00
Ville Voutilainen c3799b164f Implement LWG 2221: formatted output operator for nullptr
2019-01-10  Ville Voutilainen  <ville.voutilainen@gmail.com>
	    Jonathan Wakely  <jwakely@redhat.com>

	Implement LWG 2221
	* config/abi/pre/gnu.ver (GLIBCXX_3.4): Tighten patterns.
	(GLIBCXX_3.4.26): Add new exports.
	* include/Makefile.am: Add ostream-inst.cc. Move string-inst.cc to
	correct list of sources.
	* include/Makefile.in: Regenerate.
	* include/std/ostream (operator<<(nullptr_t)): New member function.
	* src/c++17/ostream-inst.cc: New file.
	* testsuite/27_io/basic_ostream/inserters_other/char/lwg2221.cc: New
	test.

Co-Authored-By: Jonathan Wakely <jwakely@redhat.com>

From-SVN: r267808
2019-01-10 13:14:57 +00:00
Jakub Jelinek 6cdf1946f6 re PR tree-optimization/88775 (Optimize std::string assignment)
PR tree-optimization/88775
	* include/bits/stl_function.h (greater<_Tp*>::operator(),
	less<_Tp*>::operator(), greater_equal<_Tp*>::operator(),
	less_equal<_Tp*>::operator()): Use __builtin_is_constant_evaluated
	instead of __builtin_constant_p if available.  Don't bother with
	the pointer comparison in C++11 and earlier.

From-SVN: r267800
2019-01-10 11:56:56 +01:00
Sandra Loosemore 6791469314 PR other/16615 [1/5]
2019-01-09  Sandra Loosemore  <sandra@codesourcery.com>

	PR other/16615 [1/5]

	contrib/
	* mklog: Mechanically replace "can not" with "cannot".

	gcc/
	* Makefile.in: Mechanically replace "can not" with "cannot".
	* alias.c: Likewise.
	* builtins.c: Likewise.
	* calls.c: Likewise.
	* cgraph.c: Likewise.
	* cgraph.h: Likewise.
	* cgraphclones.c: Likewise.
	* cgraphunit.c: Likewise.
	* combine-stack-adj.c: Likewise.
	* combine.c: Likewise.
	* common/config/i386/i386-common.c: Likewise.
	* config/aarch64/aarch64.c: Likewise.
	* config/alpha/sync.md: Likewise.
	* config/arc/arc.c: Likewise.
	* config/arc/predicates.md: Likewise.
	* config/arm/arm-c.c: Likewise.
	* config/arm/arm.c: Likewise.
	* config/arm/arm.h: Likewise.
	* config/arm/arm.md: Likewise.
	* config/arm/cortex-r4f.md: Likewise.
	* config/csky/csky.c: Likewise.
	* config/csky/csky.h: Likewise.
	* config/darwin-f.c: Likewise.
	* config/epiphany/epiphany.md: Likewise.
	* config/i386/i386.c: Likewise.
	* config/i386/sol2.h: Likewise.
	* config/m68k/m68k.c: Likewise.
	* config/mcore/mcore.h: Likewise.
	* config/microblaze/microblaze.md: Likewise.
	* config/mips/20kc.md: Likewise.
	* config/mips/sb1.md: Likewise.
	* config/nds32/nds32.c: Likewise.
	* config/nds32/predicates.md: Likewise.
	* config/pa/pa.c: Likewise.
	* config/rs6000/e300c2c3.md: Likewise.
	* config/rs6000/rs6000.c: Likewise.
	* config/s390/s390.h: Likewise.
	* config/sh/sh.c: Likewise.
	* config/sh/sh.md: Likewise.
	* config/spu/vmx2spu.h: Likewise.
	* cprop.c: Likewise.
	* dbxout.c: Likewise.
	* df-scan.c: Likewise.
	* doc/cfg.texi: Likewise.
	* doc/extend.texi: Likewise.
	* doc/fragments.texi: Likewise.
	* doc/gty.texi: Likewise.
	* doc/invoke.texi: Likewise.
	* doc/lto.texi: Likewise.
	* doc/md.texi: Likewise.
	* doc/objc.texi: Likewise.
	* doc/rtl.texi: Likewise.
	* doc/tm.texi: Likewise.
	* dse.c: Likewise.
	* emit-rtl.c: Likewise.
	* emit-rtl.h: Likewise.
	* except.c: Likewise.
	* expmed.c: Likewise.
	* expr.c: Likewise.
	* fold-const.c: Likewise.
	* genautomata.c: Likewise.
	* gimple-fold.c: Likewise.
	* hard-reg-set.h: Likewise.
	* ifcvt.c: Likewise.
	* ipa-comdats.c: Likewise.
	* ipa-cp.c: Likewise.
	* ipa-devirt.c: Likewise.
	* ipa-fnsummary.c: Likewise.
	* ipa-icf.c: Likewise.
	* ipa-inline-transform.c: Likewise.
	* ipa-inline.c: Likewise.
	* ipa-polymorphic-call.c: Likewise.
	* ipa-profile.c: Likewise.
	* ipa-prop.c: Likewise.
	* ipa-pure-const.c: Likewise.
	* ipa-reference.c: Likewise.
	* ipa-split.c: Likewise.
	* ipa-visibility.c: Likewise.
	* ipa.c: Likewise.
	* ira-build.c: Likewise.
	* ira-color.c: Likewise.
	* ira-conflicts.c: Likewise.
	* ira-costs.c: Likewise.
	* ira-int.h: Likewise.
	* ira-lives.c: Likewise.
	* ira.c: Likewise.
	* ira.h: Likewise.
	* loop-invariant.c: Likewise.
	* loop-unroll.c: Likewise.
	* lower-subreg.c: Likewise.
	* lra-assigns.c: Likewise.
	* lra-constraints.c: Likewise.
	* lra-eliminations.c: Likewise.
	* lra-lives.c: Likewise.
	* lra-remat.c: Likewise.
	* lra-spills.c: Likewise.
	* lra.c: Likewise.
	* lto-cgraph.c: Likewise.
	* lto-streamer-out.c: Likewise.
	* postreload-gcse.c: Likewise.
	* predict.c: Likewise.
	* profile-count.h: Likewise.
	* profile.c: Likewise.
	* recog.c: Likewise.
	* ree.c: Likewise.
	* reload.c: Likewise.
	* reload1.c: Likewise.
	* reorg.c: Likewise.
	* resource.c: Likewise.
	* rtl.def: Likewise.
	* rtl.h: Likewise.
	* rtlanal.c: Likewise.
	* sched-deps.c: Likewise.
	* sched-ebb.c: Likewise.
	* sched-rgn.c: Likewise.
	* sel-sched-ir.c: Likewise.
	* sel-sched.c: Likewise.
	* shrink-wrap.c: Likewise.
	* simplify-rtx.c: Likewise.
	* symtab.c: Likewise.
	* target.def: Likewise.
	* toplev.c: Likewise.
	* tree-call-cdce.c: Likewise.
	* tree-cfg.c: Likewise.
	* tree-complex.c: Likewise.
	* tree-core.h: Likewise.
	* tree-eh.c: Likewise.
	* tree-inline.c: Likewise.
	* tree-loop-distribution.c: Likewise.
	* tree-nrv.c: Likewise.
	* tree-profile.c: Likewise.
	* tree-sra.c: Likewise.
	* tree-ssa-alias.c: Likewise.
	* tree-ssa-dce.c: Likewise.
	* tree-ssa-dom.c: Likewise.
	* tree-ssa-forwprop.c: Likewise.
	* tree-ssa-loop-im.c: Likewise.
	* tree-ssa-loop-ivcanon.c: Likewise.
	* tree-ssa-loop-ivopts.c: Likewise.
	* tree-ssa-loop-niter.c: Likewise.
	* tree-ssa-phionlycprop.c: Likewise.
	* tree-ssa-phiopt.c: Likewise.
	* tree-ssa-propagate.c: Likewise.
	* tree-ssa-threadedge.c: Likewise.
	* tree-ssa-threadupdate.c: Likewise.
	* tree-ssa-uninit.c: Likewise.
	* tree-ssanames.c: Likewise.
	* tree-streamer-out.c: Likewise.
	* tree.c: Likewise.
	* tree.h: Likewise.
	* vr-values.c: Likewise.

	gcc/ada/
	* exp_ch9.adb: Mechanically replace "can not" with "cannot".
	* libgnat/s-regpat.ads: Likewise.
	* par-ch4.adb: Likewise.
	* set_targ.adb: Likewise.
	* types.ads: Likewise.

	gcc/cp/
	* cp-tree.h: Mechanically replace "can not" with "cannot".
	* parser.c: Likewise.
	* pt.c: Likewise.

	gcc/fortran/
	* class.c: Mechanically replace "can not" with "cannot".
	* decl.c: Likewise.
	* expr.c: Likewise.
	* gfc-internals.texi: Likewise.
	* intrinsic.texi: Likewise.
	* invoke.texi: Likewise.
	* io.c: Likewise.
	* match.c: Likewise.
	* parse.c: Likewise.
	* primary.c: Likewise.
	* resolve.c: Likewise.
	* symbol.c: Likewise.
	* trans-array.c: Likewise.
	* trans-decl.c: Likewise.
	* trans-intrinsic.c: Likewise.
	* trans-stmt.c: Likewise.

	gcc/go/
	* go-backend.c: Mechanically replace "can not" with "cannot".
	* go-gcc.cc: Likewise.

	gcc/lto/
	* lto-partition.c: Mechanically replace "can not" with "cannot".
	* lto-symtab.c: Likewise.
	* lto.c: Likewise.

	gcc/objc/
	* objc-act.c: Mechanically replace "can not" with "cannot".

	libbacktrace/
	* backtrace.h: Mechanically replace "can not" with "cannot".

	libgcc/
	* config/c6x/libunwind.S: Mechanically replace "can not" with
	"cannot".
	* config/tilepro/atomic.h: Likewise.
	* config/vxlib-tls.c: Likewise.
	* generic-morestack-thread.c: Likewise.
	* generic-morestack.c: Likewise.
	* mkmap-symver.awk: Likewise.

	libgfortran/
	* caf/single.c: Mechanically replace "can not" with "cannot".
	* io/unit.c: Likewise.

	libobjc/
	* class.c: Mechanically replace "can not" with "cannot".
	* objc/runtime.h: Likewise.
	* sendmsg.c: Likewise.

	liboffloadmic/
	* include/coi/common/COIResult_common.h: Mechanically replace
	"can not" with "cannot".
	* include/coi/source/COIBuffer_source.h: Likewise.

	libstdc++-v3/
	* include/ext/bitmap_allocator.h: Mechanically replace "can not"
	with "cannot".

From-SVN: r267783
2019-01-09 16:37:45 -05:00
Jonathan Wakely 50b0a3d672 Remove some more code duplication in std::optional
Hoist the duplicated code from the _Optional_payload partial
specializations into the _Optional_payload_base base class.

	* include/std/optional (_Optional_payload_base::_M_copy_assign): New
	member function to perform non-trivial assignment.
	(_Optional_payload_base::_M_move_assign): Likewise.
	(_Optional_payload<T, true, false, true>::operator=)
	(_Optional_payload<T, true, true, false>::operator=)
	(_Optional_payload<T, true, false, false>::operator=): Call
	_M_copy_assign and/or _M_move_assign to do non-trivial assignments.

From-SVN: r267761
2019-01-09 10:40:49 +00:00
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
Jonathan Wakely 9f5391ee95 PR libstdc++/88066 use <> for includes not ""
Using #include "..." to include a header in the same directory fails if
the user compiles with -I-, so always use something like <bits/...> for
internal headers.

I haven't added tests for this, because dg-options adds options to the
end, and the position of -I- matters (if it's at the end then the tests
won't find any headers in the build tree, as they're specified by -I
options earlier in the flags). It's been manually tested though.

	PR libstdc++/88066
	* include/bits/locale_conv.h: Use <> for includes not "".
	* include/ext/random: Likewise.
	* include/ext/vstring.h: Likewise.

From-SVN: r267726
2019-01-08 13:25:19 +00:00
Jonathan Wakely e002afaa8e PR libstdc++/87787 avoid undefined null args to memcpy and memmove
The C++ char_traits and ctype APIs do not disallow null pointer
arguments, so we need explicit checks to ensure we don't forward null
pointers to memcpy or memmove.

	PR libstdc++/87787
	* include/bits/char_traits.h (char_traits::move): Do not pass null
	pointers to memmove.
	* include/bits/locale_facets.h
	(ctype<char>::widen(const char*, const char*, char*)): Do not
	pass null pointers to memcpy.
	(ctype<char>::narrow(const char*, const char*, char, char*)):
	Likewise.
	(ctype<char>::do_widen(const char*, const char*, char*)):
	Likewise.
	(ctype<char>::do_narrow(const char*, const char*, char, char*)):
	Likewise.

From-SVN: r267651
2019-01-07 14:58:44 +00:00
Jonathan Wakely caf80d87b5 PR libstdc++/87431 fix regression introduced by r264574
The previous patch for PR 87431 assumed that initialing a scalar type
could not throw, but it can obtain its value via a conversion operator,
which could throw. This meant the variant could get into a valueless
state, but the valueless_by_exception() member function would always
return false.

This patch fixes it by changing the emplace members to have strong
exception safety when initializing a contained value of trivially
copyable type. The _M_valid() member gets a corresponding change to
always return true for trivially copyable types, not just scalar types.

Strong exception safety (i.e. never becoming valueless) is achieved by
only replacing the current contained value once any potentially throwing
operations have completed. If constructing the new contained value can
throw then a new std::variant object is constructed to hold it, and then
move-assigned to *this (which won't throw).

	PR libstdc++/87431
	* include/std/variant (_Variant_storage<true, _Types...>::_M_valid):
	Check is_trivially_copyable instead of is_scalar.
	(variant::emplace<N, Args>(Args&&...)): If construction of the new
	contained value can throw and its type is trivially copyable then
	construct into a temporary variant and move from it, to provide the
	strong exception safety guarantee.
	(variant::emplace<N, U, Args>(initializer_list<U>, Args&&...)):
	Likewise.
	* testsuite/20_util/variant/87431.cc: New test.
	* testsuite/20_util/variant/run.cc: Adjust test so that throwing
	conversion causes valueless state.

From-SVN: r267614
2019-01-06 20:52:34 +00:00
Jonathan Wakely beb04ce9d4 Define new filesystem::__file_clock type
In C++17 the clock used for filesystem::file_time_type is unspecified,
allowing it to be chrono::system_clock. The C++2a draft requires it to
be a distinct type, with additional member functions to convert to/from
other clocks (either the system clock or UTC). In order to avoid an ABI
change later, this patch defines a new distinct type now, which will be
used for std::chrono::file_clock later.

	* include/bits/fs_fwd.h (__file_clock): Define new clock.
	(file_time_type): Redefine in terms of __file_clock.
	* src/filesystem/ops-common.h (file_time): Add FIXME comment about
	overflow.
	* src/filesystem/std-ops.cc (is_set(perm_options, perm_options)): Give
	internal linkage.
	(internal_file_lock): New helper type for accessing __file_clock.
	(do_copy_file): Use internal_file_lock to convert system time to
	file_time_type.
	(last_write_time(const path&, error_code&)): Likewise.
	(last_write_time(const path&, file_time_type, error_code&)): Likewise.

From-SVN: r267602
2019-01-05 20:03:22 +00:00
Jonathan Wakely 1a289fa362 Export explicit instantiations for C++17 members of std::string
The C++17 standard added some new members to std::basic_string, which
were not previously instantiated in the library. This meant that the
extern template declarations had to be disabled for C++17 mode. With
this patch the new members are instantiated in the library and so the
explicit instantiation declarations can be used for C++17.

The new members added by C++2a are still not exported, and so the
explicit instantiation declarations are still disabled for C++2a.

	* config/abi/pre/gnu.ver (GLIBCXX_3.4.21): Make patterns less greedy
	for const member functions of std::basic_string.
	(GLIBCXX_3.4.26): Export member functions of std::basic_string added
	in C++17.
	* include/bits/basic_string.h (basic_string(__sv_wrapper, const A&)):
	Make non-standard constructor private.
	[!_GLIBCXX_USE_CXX11_ABI] (basic_string(__sv_wrapper, const A&)):
	Likewise.
	* include/bits/basic_string.tcc (std::string, std::wstring): Declare
	explicit instantiations for C++17 as well as earlier dialects.
	* src/c++17/Makefile.am: Add new source files.
	* src/c++17/Makefile.in: Regenerate.
	* src/c++17/cow-string-inst.cc: New file defining explicit
	instantiations for basic_string member functions added in C++17.
	* src/c++17/string-inst.cc: Likewise.

From-SVN: r267585
2019-01-04 23:23:22 +00:00
Jonathan Wakely 4ff3e65090 Add allocator-extended copy/move ctors to COW string
Add these constructors from C++11 which were missing from the COW
basic_string. Additionally simplify the definitions of the
basic_string::reference and basic_string::const_reference types as
required by C++11.

This allows filesystem::path::string<Allocator>() to be simplified, so
that the same code is used for both basic_string implementations.

	* config/abi/pre/gnu.ver (GLIBCXX_3.4.26): Export allocator-extended
	copy/move constructors for old std::basic_string.
	* include/bits/basic_string.h [!_GLIBCXX_USE_CXX11_ABI]
	(basic_string::reference, basic_string::const_reference): Define
	as plain references for C++11 and later.
	(basic_string::basic_string()): Put constructor body outside
	preprocessor conditional groups.
	(basic_string::basic_string(basic_string&&)): Move _Alloc_hider
	instead of copying it.
	(basic_string::basic_string(const basic_string&, const _Alloc&)):
	Define.
	(basic_string::basic_string(basic_string&&, const _Alloc&)):
	Define.
	* include/bits/fs_path.h [!_GLIBCXX_USE_CXX11_ABI]: Remove special
	cases for old basic_string.
	* testsuite/21_strings/basic_string/cons/char/8.cc: Test
	allocator-extended constructors unconditionally. Add extra members to
	allocator type when using old string ABI.
	* testsuite/21_strings/basic_string/allocator/71964.cc: Enable test
	for old string ABI.
	* testsuite/21_strings/basic_string/cons/wchar_t/8.cc: Likewise.

From-SVN: r267584
2019-01-04 23:23:17 +00:00
Jonathan Wakely 73d968d945 Fix bugs in filesystem::path::lexically_normal()
Using path::_List::erase(const_iterator) to remove a non-final component
in path::lexically_normal() is a bug, because it leaves the following
component with an incorrect _M_pos value.

Instead of providing erase members that allow removing components from
the middle, replace them with pop_back() and
_M_erase_from(const_iterator) which only allow removing elements at the
end. Most uses of erase are unaffected, because they only remove
elements from the end anyway. The one use of erasure from the middle in
lexically_normal() is replaced by calls to pop_back() and/or clearing
the last component to leave it as an empty final filename.

Also replace the "???" comment in lexically_normal() to document when
that branch is taken.

	* include/bits/fs_path.h (path::_List::erase): Replace both overloads
	with ...
	(path::pop_back(), path::_M_erase_from(const_iterator)): New member
	functions that will only erase elements at the end.
	* src/filesystem/std-path.cc (path::_List::_Impl::pop_back()): Define.
	(path::_List::_Impl::_M_erase_from(const_iterator)): Define.
	(path::_List::operator=(const _List&)): Use _M_erase_from(p) instead
	of erase(p, end()).
	(path::_List::pop_back()): Define.
	(path::_List::_M_erase_from(const_iterator)): Define.
	(path::operator/=(const path&)): Use pop_back to remove last component
	and _M_erase_from to remove multiple components.
	(path::_M_append(basic_string_view<value_type>)): Likewise.
	(path::operator+=(const path&)): Likewise.
	(path::_M_concat(basic_string_view<value_type>)): Likewise.
	(path::remove_filename()): Likewise.
	(path::lexically_normal()): Use _List::_Impl iterators instead of
	path::iterator. Use pop_back to remove components from the end. Clear
	trailing filename, instead of using erase(const_iterator) to remove
	a non-final component.
	* testsuite/27_io/filesystem/path/generation/normal.cc: Test
	additional cases.
	* testsuite/27_io/filesystem/path/generation/normal2.cc: New test.

From-SVN: r267576
2019-01-04 14:03:59 +00:00
Jonathan Wakely 43f1a5e1d8 PR libstdc++/88607 replace some more UTF-8 characters
2019-01-03  Jonathan Wakely  <jwakely@redhat.com>
	    Jakub Jelinek  <jakub@redhat.com>

	PR libstdc++/88607
	* include/experimental/memory: Replace UTF-8 quote characters.
	* include/std/future: Replace UTF-8 "em dash" characters.

Co-Authored-By: Jakub Jelinek <jakub@redhat.com>

From-SVN: r267565
2019-01-03 22:07:52 +00:00
Jonathan Wakely 3c732e6fe8 PR libstdc++/88607 replace or remove unnecessary UTF-8 characters
There are a number of UTF-8 characters in comments which add no value
and can be replaced with ASCII equivalents, or removed entirely for the
section sign (U+00A7).

	PR libstdc++/88607
	* include/bits/forward_list.h: Replace UTF-8 "ligature fi" character.
	* include/debug/forward_list: Likewise.
	* include/experimental/bits/shared_ptr.h: Remove UTF-8 "section sign"
	character.
	* include/experimental/chrono: Likewise.
	* include/experimental/functional: Likewise.
	* include/experimental/ratio: Likewise.
	* include/experimental/system_error: Likewise.
	* include/experimental/tuple: Likewise.
	* include/experimental/type_traits: Likewise.
	* include/parallel/workstealing.h: Replace UTF-8 "en dash" character.
	* include/parallel/multiseq_selection.h: Likewise.

From-SVN: r267564
2019-01-03 20:38:11 +00:00
Jakub Jelinek a554497024 Update copyright years.
From-SVN: r267494
2019-01-01 13:31:55 +01:00
François Dumont 23d5fd6cd6 Respect pointer_traits on node deallocation in _ReuseOrAllocNode parenthesis operator.
2018-12-23  François Dumont  <fdumont@gcc.gnu.org>

	Respect pointer_traits on node deallocation in _ReuseOrAllocNode
	parenthesis operator.

	* include/bits/hashtable_policy.h
	(_Hashtable_alloc<>::_M_deallocate_node_ptr(__node_type*)): New.
	(_Hashtable_alloc<>::_M_deallocate_node(__node_type*)): Use latter.
	(_ReuseOrAllocNode<>::operator<_Arg>()(_Arg&&)): Likewise.

From-SVN: r267380
2018-12-23 18:05:23 +00:00
Jonathan Wakely 4894e316a8 LWG 3171: restore stream insertion for filesystem::directory_entry
* include/bits/fs_dir.h (operator<<): Overload for directory_entry,
	as per LWG 3171.
	* testsuite/27_io/filesystem/directory_entry/lwg3171.cc: New test.

From-SVN: r267238
2018-12-18 16:57:36 +00:00
Jonathan Wakely 36313a6bce LWG 2936: update path::compare logic and optimize string comparisons
The resolution for LWG 2936 defines the comparison more precisely, which
this patch implements. The patch also defines comparisons with strings
to work without constructing a temporary path object (so avoids any
memory allocations).

	* include/bits/fs_path.h (path::compare(const string_type&))
	(path::compare(const value_type*)): Add noexcept and construct a
	string view to compare to instead of a path.
	(path::compare(basic_string_view<value_type>)): Add noexcept. Remove
	inline definition.
	* src/filesystem/std-path.cc (path::_Parser): Track last type read
	from input.
	(path::_Parser::next()): Return a final empty component when the
	input ends in a non-root directory separator.
	(path::_M_append(basic_string_view<value_type>)): Remove special cases
	for trailing non-root directory separator.
	(path::_M_concat(basic_string_view<value_type>)): Likewise.
	(path::compare(const path&)): Implement LWG 2936.
	(path::compare(basic_string_view<value_type>)): Define in terms of
	components returned by parser, consistent with LWG 2936.
	* testsuite/27_io/filesystem/path/compare/lwg2936.cc: New.
	* testsuite/27_io/filesystem/path/compare/path.cc: Test more cases.
	* testsuite/27_io/filesystem/path/compare/strings.cc: Likewise.

From-SVN: r267235
2018-12-18 15:52:33 +00:00
Jonathan Wakely 49cefcf3f0 LWG 3040: define starts_with/ends_with as proposed
* include/std/string_view [__cplusplus > 201703L]
	(basic_string_view::starts_with(basic_string_view)): Implement
	proposed resolution of LWG 3040 to avoid redundant length check.
	(basic_string_view::starts_with(_CharT)): Implement proposed
	resolution of LWG 3040 to check at most one character.
	(basic_string_view::ends_with(_CharT)): Likewise.

From-SVN: r267234
2018-12-18 15:34:43 +00:00
Jonathan Wakely 4f87bb8d6e PR libstdc++/71044 optimize std::filesystem::path construction
This new implementation has a smaller footprint than the previous
implementation, due to replacing std::vector<_Cmpt> with a custom pimpl
type that only needs a single pointer. The _M_type enumeration is also
combined with the pimpl type, by using a tagged pointer, reducing
sizeof(path) further still.

Construction and modification of paths is now done more efficiently, by
splitting the input into a stack-based buffer of string_view objects
instead of a dynamically-allocated vector containing strings. Once the
final size is known only a single allocation is needed to reserve space
for it.  The append and concat operations no longer require constructing
temporary path objects, nor re-parsing the entire native pathname.

This results in algorithmic improvements to path construction, and
working with large paths is much faster.

	PR libstdc++/71044
	* include/bits/fs_path.h (path::path(path&&)): Add noexcept when
	appropriate. Move _M_cmpts instead of reparsing the native pathname.
	(path::operator=(const path&)): Do not define as defaulted.
	(path::operator/=, path::append): Call _M_append.
	(path::concat): Call _M_concat.
	(path::path(string_type, _Type): Change type of first parameter to
	basic_string_view<value_type>.
	(path::_M_append(basic_string_view<value_type>)): New member function.
	(path::_M_concat(basic_string_view<value_type>)): New member function.
	(_S_convert(value_type*, __null_terminated)): Return string view.
	(_S_convert(const value_type*, __null_terminated)): Return string view.
	(_S_convert(value_type*, value_type*))
	(_S_convert(const value_type*, const value_type*)): Add overloads for
	pairs of pointers.
	(_S_convert(_InputIterator, __null_terminated)): Construct string_type
	explicitly, for cases where _S_convert returns a string view.
	(path::_S_is_dir_sep): Replace with non-member is_dir_sep.
	(path::_M_trim, path::_M_add_root_name, path::_M_add_root_dir)
	(path::_M_add_filename): Remove.
	(path::_M_type()): New member function to replace _M_type data member.
	(path::_List): Define new struct type instead of using std::vector.
	(path::_Cmpt::_Cmpt(string_type, _Type, size_t)): Change type of
	first parameter to basic_string_view<value_type>.
	(path::operator+=(const path&)): Do not define inline.
	(path::operator+=(const string_type&)): Call _M_concat.
	(path::operator+=(const value_type*)): Likewise.
	(path::operator+=(value_type)): Likewise.
	(path::operator+=(basic_string_view<value_type>)): Likewise.
	(path::operator/=(const path&)): Do not define inline.
	(path::_M_append(path)): Remove.
	* python/libstdcxx/v6/printers.py (StdPathPrinter): New printer that
	understands the new path::_List type.
	* src/filesystem/std-path.cc (is_dir_sep): New function to replace
	path::_S_is_dir_sep.
	(path::_Parser): New helper class to parse strings as paths.
	(path::_List::_Impl): Define container type for path components.
	(path::_List): Define members.
	(path::operator=(const path&)): Define explicitly, to provide the
	strong exception safety guarantee.
	(path::operator/=(const path&)): Implement manually by processing
	each component of the argument, rather than using _M_split_cmpts
	to parse the entire string again.
	(path::_M_append(string_type)): Likewise.
	(path::operator+=(const path&)): Likewise.
	(path::_M_concat(string_type)): Likewise.
	(path::remove_filename()): Perform trim directly instead of calling
	_M_trim().
	(path::_M_split_cmpts()): Rewrite in terms of _Parser class.
	(path::_M_trim, path::_M_add_root_name, path::_M_add_root_dir)
	(path::_M_add_filename): Remove.
	* testsuite/27_io/filesystem/path/append/source.cc: Test appending a
	string view that aliases the path.
	testsuite/27_io/filesystem/path/concat/strings.cc: Test concatenating
	a string view that aliases the path.

From-SVN: r267106
2018-12-13 20:33:55 +00:00
Jonathan Wakely 9e16052644 Overload std::distance and std::advance for path::iterator
Although filesystem::path::iterator is only a bidirectional iterator,
the underlying sequence has random access iterators (specifically, raw
pointers). This means std::distance and std::advance can be implemented
more efficiently than the generic versions which apply ++ and --
repeatedly.

	PR libstdc++/71044 (partial)
	* include/bits/fs_path.h (__path_iter_distance, __path_iter_advance):
	New friend functions to implement std::distance and std::advance more
	efficiently.
	(distance, advance): Add overloads for path::iterator.
	* testsuite/27_io/filesystem/path/itr/components.cc: Test new
	overload.

From-SVN: r267057
2018-12-12 16:13:49 +00:00
Jonathan Wakely 6b7c0b5559 PR libstdc++/80762 avoid ambiguous __constructible_from<void, void>
Ensure we don't try to instantiate __is_constructible_from<void, void>,
because there are two partial specializations that are equally good
matches.

	PR libstdc++/80762
	* include/bits/fs_path.h (path::_Path): Use remove_cv_t and is_void.
	* include/experimental/bits/fs_path.h (path::_Path): Likewise.
	* testsuite/27_io/filesystem/path/construct/80762.cc: New test.
	* testsuite/experimental/filesystem/path/construct/80762.cc: New test.

From-SVN: r267056
2018-12-12 16:13:43 +00:00
Jakub Jelinek 0d7924f2e7 P0595R2 - is_constant_evaluated
P0595R2 - is_constant_evaluated
	* include/bits/c++config (_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED):
	Define if __builtin_is_constant_evaluated is available.
	* include/std/type_traits (std::is_constant_evaluated): New constexpr
	inline function.
	* testsuite/20_util/is_constant_evaluated/1.cc: New test.
	* testsuite/20_util/is_constant_evaluated/noexcept.cc: New test.

From-SVN: r267045
2018-12-12 09:31:01 +01:00
Edward Smith-Rowland d012ab6057 PR libstdc++/88341 - Complex norm doesn't compile with C++11
2018-12-03  Edward Smith-Rowland  <3dw4rd@verizon.net>

	PR libstdc++/88341 - Complex norm doesn't compile with C++11
	* include/std/complex (_S_do_it): Make C++20 constexpr.
	* testsuite/26_numerics/complex/value_operations/pr88341.cc: New test.

From-SVN: r266788
2018-12-04 16:26:39 +00:00