summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/experimental
AgeCommit message (Collapse)Author
2022-08-03libstdc++: Make std::lcm and std::gcd detect overflow [PR105844]Jonathan Wakely
When I fixed PR libstdc++/92978 I introduced a regression whereby std::lcm(INT_MIN, 1) and std::lcm(50000, 49999) would no longer produce errors during constant evaluation. Those calls are undefined, because they violate the preconditions that |m| and the result can be represented in the return type (which is int in both those cases). The regression occurred because __absu<unsigned>(INT_MIN) is well-formed, due to the explicit casts to unsigned in that new helper function, and the out-of-range multiplication is well-formed, because unsigned arithmetic wraps instead of overflowing. To fix 92978 I made std::gcm and std::lcm calculate |m| and |n| immediately, yielding a common unsigned type that was used to calculate the result. That was partly correct, but there's no need to use an unsigned type. Doing so only suppresses the overflow errors so the compiler can't detect them. This change replaces __absu with __abs_r that returns the common type (not its corresponding unsigned type). This way we can detect overflow in __abs_r when required, while still supporting the most-negative value when it can be represented in the result type. To detect LCM results that are out of range of the result type we still need explicit checks, because neither constant evaluation nor UBsan will complain about unsigned wrapping for cases such as std::lcm(500000u, 499999u). We can detect those overflows efficiently by using __builtin_mul_overflow and asserting. libstdc++-v3/ChangeLog: PR libstdc++/105844 * include/experimental/numeric (experimental::gcd): Simplify assertions. Use __abs_r instead of __absu. (experimental::lcm): Likewise. Remove use of __detail::__lcm so overflow can be detected. * include/std/numeric (__detail::__absu): Rename to __abs_r and change to allow signed result type, so overflow can be detected. (__detail::__lcm): Remove. (gcd): Simplify assertions. Use __abs_r instead of __absu. (lcm): Likewise. Remove use of __detail::__lcm so overflow can be detected. * testsuite/26_numerics/gcd/gcd_neg.cc: Adjust dg-error lines. * testsuite/26_numerics/lcm/lcm_neg.cc: Likewise. * testsuite/26_numerics/gcd/105844.cc: New test. * testsuite/26_numerics/lcm/105844.cc: New test. (cherry picked from commit 671970a5621e18e7079b4ca113e56434c858db66)
2022-06-14libstdc++: Rename __null_terminated to avoid collision with Apple SDKMark Mentovai
The macOS 13 SDK (and equivalent-version iOS and other Apple OS SDKs) contain this definition in <sys/cdefs.h>: 863 #define __null_terminated This collides with the use of __null_terminated in libstdc++'s experimental fs_path.h. As libstdc++'s use of this token is entirely internal to fs_path.h, the simplest workaround, renaming it, is most appropriate. Here, it's renamed to __nul_terminated, referencing the NUL ('\0') value that is used to terminate the strings in the context in which this tag structure is used. libstdc++-v3/ChangeLog: * include/experimental/bits/fs_path.h (__detail::__null_terminated): Rename to __nul_terminated to avoid colliding with a macro in Apple's SDK. Signed-off-by: Mark Mentovai <mark@mentovai.com> (cherry picked from commit 254e88b3d7e8abcc236be3451609834371cf4d5d)
2022-05-13libstdc++: ppc: conditionalize vsx-only simd intrinsicsAlexandre Oliva
libstdc++'s bits/simd.h section for PowerPC, guarded by __ALTIVEC__, defines various intrinsic vector types that are only available with __VSX__: 64-bit long double, double, (un)signed long long, and 64-bit (un)signed long. experimental/simd/standard_abi_usable{,_2}.cc tests error out reporting the unmet requirements when the target cpu doesn't enable VSX. Make the reported instrinsic types conditional on __VSX__ so that <experimental/simd> can be used on PowerPC variants that do not support VSX. for libstdc++-v3/ChangeLog * include/experimental/bits/simd.h [__ALTIVEC__]: Require VSX for double, long long, and 64-bit long intrinsic types. [__ALTIVEC__] (__intrinsic_type): Mention 128-bit in preexisting long double diagnostic, adjust no-VSX double diagnostic to cover 64-bit long double as well. (cherry picked from commit 469c76f0d94d03e29467a9d1e77cd3613f46ac2f)
2022-04-11libstdc++: Move Filesystem TS path definitions out of class bodyJonathan Wakely
This fixes some errors with clang caused by instantiating vector<_Cmpt> before the _Cmpt type is complete. libstdc++-v3/ChangeLog: * include/experimental/bits/fs_path.h (path): Define special members after path::_Cmpt is complete.
2022-04-01libstdc++: Fix mismatched noexcept-specifiers in Filesystem TSJonathan Wakely
The copy_file fix should have been part of r12-7063-gda72e0fd20f87b. The path::begin() fix should have been part of r12-3930-gf2b7f56a15d9cb. Thanks to Timm Bäder for reporting this one. libstdc++-v3/ChangeLog: * include/experimental/bits/fs_fwd.h (copy_file): Remove incorrect noexcept from declaration. * include/experimental/bits/fs_path.h (path::begin, path::end): Add noexcept to declarations, to match definitions.
2022-04-01libstdc++: Fix filenames in Doxygen @file commentsTimm Bäder
Reviewed-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: * include/bits/fs_ops.h: Fix filename in Doxygen comment. * include/experimental/bits/fs_ops.h: Likewise.
2022-02-04libstdc++: Remove un-implementable noexcept from Filesystem TS operationsJonathan Wakely
LWG 3014 removed these incorrect noexcept specifications from the C++17 std::filesystem operations. They are also incorrect on the experimental TS versions and should be removed from them too. libstdc++-v3/ChangeLog: * include/experimental/bits/fs_ops.h (fs::copy_file): Remove noexcept. (fs::create_directories): Likewise. (fs::remove_all): Likewise. * src/filesystem/ops.cc (fs::copy_file): Remove noexcept. (fs::create_directories): Likewise. (fs::remove_all): Likewise.
2022-01-19libstdc++: Fix for non-constexpr math_errhandlingMatthias Kretz
Use SFINAE magic to support: "It is unspecified whether math_errhandling is a macro or an identifier with external linkage." [C Standard] Signed-off-by: Matthias Kretz <m.kretz@gsi.de> libstdc++-v3/ChangeLog: * include/experimental/bits/simd.h (__floating_point_flags): Do not rely on math_errhandling to expand to a constant expression.
2022-01-17libstdc++: Don't fail if math_errhandling is not definedMatthias Kretz
Older glibc does not define math_errhandling with -ffast-math, in which case floating-point exceptions are not used. Signed-off-by: Matthias Kretz <m.kretz@gsi.de> libstdc++-v3/ChangeLog: * include/experimental/bits/simd.h (__floating_point_flags): Do not rely on the presence of the math_errhandling macro.
2022-01-15libstdc++: Fix ODR issues with different -m flagsMatthias Kretz
Explicitly support use of the stdx::simd implementation in situations where the user links TUs that were compiled with different -m flags. In general, this is always a (quasi) ODR violation for inline functions because at least codegen may differ in important ways. However, in the resulting executable only one (unspecified which one) of them might be used. For simd we want to support users to compile code multiple times, with different -m flags and have a runtime dispatch to the TU matching the target CPU. But if internal functions are not inlined this may lead to unexpected performance loss or execution of illegal instructions. Therefore, inline functions that are not marked as always_inline must use an additional template parameter somewhere in their name, to disambiguate between the different -m translations. Signed-off-by: Matthias Kretz <m.kretz@gsi.de> libstdc++-v3/ChangeLog: * include/experimental/bits/simd.h: Move feature detection bools and add __have_avx512bitalg, __have_avx512vbmi2, __have_avx512vbmi, __have_avx512ifma, __have_avx512cd, __have_avx512vnni, __have_avx512vpopcntdq. (__detail::__machine_flags): New function which returns a unique uint64 depending on relevant -m and -f flags. (__detail::__odr_helper): New type alias for either an anonymous type or a type specialized with the __machine_flags number. (_SimdIntOperators): Change template parameters from _Impl to _Tp, _Abi because _Impl now has an __odr_helper parameter which may be _OdrEnforcer from the anonymous namespace, which makes for a bad base class. (many): Either add __odr_helper template parameter or mark as always_inline. * include/experimental/bits/simd_detail.h: Add defines for AVX512BITALG, AVX512VBMI2, AVX512VBMI, AVX512IFMA, AVX512CD, AVX512VNNI, AVX512VPOPCNTDQ, and AVX512VP2INTERSECT. * include/experimental/bits/simd_builtin.h: Add __odr_helper template parameter or mark as always_inline. * include/experimental/bits/simd_fixed_size.h: Ditto. * include/experimental/bits/simd_math.h: Ditto. * include/experimental/bits/simd_scalar.h: Ditto. * include/experimental/bits/simd_neon.h: Add __odr_helper template parameter. * include/experimental/bits/simd_ppc.h: Ditto. * include/experimental/bits/simd_x86.h: Ditto.
2022-01-03Update copyright years.Jakub Jelinek
2021-12-09libstdc++: Fix non-reserved name in std::allocator base class [PR64135]Jonathan Wakely
The possible base classes of std::allocator are new_allocator and malloc_allocator, which both cause a non-reserved name to be declared in every program that includes the definition of std::allocator. This is non-conforming. This change replaces __gnu_cxx::new_allocator with std::__new_allocator which is identical except for using a reserved name. The non-standard extension __gnu_cxx::new_allocator is preserved as a thin wrapper over std::__new_allocator. There is no problem with the extension using a non-reserved name now that it's not included by default in other headers. The same change could be done to __gnu_cxx::malloc_allocator but as it's not the default configuration it can wait. libstdc++-v3/ChangeLog: PR libstdc++/64135 * config/allocator/new_allocator_base.h: Include <bits/new_allocator.h> instead of <ext/new_allocator.h>. (__allocator_base): Use std::__new_allocator instead of __gnu_cxx::new_allocator. * doc/xml/manual/allocator.xml: Document new default base class for std::allocator. * doc/xml/manual/evolution.xml: Likewise. * doc/html/*: Regenerate. * include/Makefile.am: Add bits/new_allocator.h. * include/Makefile.in: Regenerate. * include/experimental/memory_resource (new_delete_resource): Use std::__new_allocator instead of __gnu_cxx::new_allocator. * include/ext/new_allocator.h (new_allocator): Derive from std::__new_allocator. Move implementation to ... * include/bits/new_allocator.h: New file. * testsuite/20_util/allocator/64135.cc: New test.
2021-11-20libstdc++: [_GLIBCXX_DEBUG] Reduce performance impact on std::erase_ifFrançois Dumont
Bypass the _GLIBCXX_DEBUG additional checks in std::__detail::__erase_node_if used by all implementations of std::erase_if for node based containers. libstdc++-v3/ChangeLog: * include/bits/erase_if.h (__erase_nodes_if): Add _UnsafeContainer template parameter. Use it to get iterators to work with. * include/debug/macros.h (__glibcxx_check_erase2): New. * include/debug/map.h (map<>::erase(_Base_const_iterator)): New. (map<>::erase(const_iterator)): Use latter. * include/debug/multimap.h (multimap<>::erase(_Base_const_iterator)): New. (multimap<>::erase(const_iterator)): Use latter. * include/debug/multiset.h (multiset<>::erase(_Base_const_iterator)): New. (multiset<>::erase(const_iterator)): Use latter. * include/debug/set.h (set<>::erase(_Base_const_iterator)): New. (set<>::erase(const_iterator)): Use latter. * include/debug/unordered_map (unordered_map<>::erase(_Base_const_iterator)): New. (unordered_multimap<>::erase(const_iterator)): New. * include/debug/unordered_set (unordered_set<>::erase(_Base_const_iterator)): New. (unordered_multiset<>::erase(const_iterator)): New. * include/experimental/map (erase_if): Adapt. * include/experimental/set (erase_if): Adapt. * include/experimental/unordered_map (erase_if): Adapt. * include/experimental/unordered_set (erase_if): Adapt. * include/std/map (erase_if): Adapt. * include/std/set (erase_if): Adapt. * include/std/unordered_map (erase_if): Adapt. * include/std/unordered_set (erase_if): Adapt.
2021-11-17libstdc++: Use std::construct_at in net::ip::addressJonathan Wakely
Using placement-new isn't valid in constant expressions, so this replaces it with std::construct_at (via the std::_Construct function that is usable before C++20). libstdc++-v3/ChangeLog: * include/experimental/internet (address): Use std::_Construct to initialize union members.
2021-11-15c++: check constexpr constructor bodyJason Merrill
The implicit constexpr patch revealed that our checks for constexpr constructors that could possibly produce a constant value (which otherwise are IFNDR) was failing to look at most of the function body. Fixing that required some library tweaks. gcc/cp/ChangeLog: * constexpr.c (maybe_save_constexpr_fundef): Also check whether the body of a constructor is potentially constant. libstdc++-v3/ChangeLog: * src/c++17/memory_resource.cc: Add missing constexpr. * include/experimental/internet: Only mark copy constructor as constexpr with __cpp_constexpr_dynamic_alloc. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/constexpr-89285-2.C: Expect error. * g++.dg/cpp1y/constexpr-89285.C: Adjust error.
2021-10-09libstdc++: Always define typedefs and hash functions for wide strings [PR 98725]Jonathan Wakely
The wstring and wstring_view typedefs should be enabled even if <wchar.h> isn't supported, because char_traits<wchar_t> works unconditionally. Similarly, the std::hash specializations for wide strings do not depend on <wchar.h> support. Although the primary template works OK for std::char_traits<wchar_t> in the absence of <wchar.h> support, this patch still defines it as an explicit specialization for compatibility with declarations that expect it to be specialized. The explicit specialization just uses the same __gnu_cxx::char_traits base class as the primary template. libstdc++-v3/ChangeLog: PR libstdc++/98725 * include/bits/char_traits.h (char_traits<wchar_t>): Define explicit specialization unconditionally. * include/bits/basic_string.h (hash<wstring>): Define unconditionally. Do not check _GLIBCXX_USE_WCHAR_T. * include/bits/stringfwd.h (wstring): Likewise. * include/debug/string (wstring): Likewise. * include/experimental/string_view (experimental::wstring_view) (hash<experimental::wstring_view>): Likewise. * include/std/string (pmr::wstring, hash<pmr::wstring>): Likewise. * include/std/string_view (wstring_view, hash<wstring_view>): Likewise.
2021-10-08libstdc++: Restore debug checks in uniform container erasure functionsJonathan Wakely
This partially reverts commit 561078480ffb5adb68577276c6b23e4ee7b39272. If we avoid all debug mode checks when erasing elements then we fail to invalidate safe iterators to the removed elements. This reverts the recent changes in r12-4083 and r12-4233, restoring the debug checking. libstdc++-v3/ChangeLog: * include/experimental/deque (erase, erase_if): Revert changes to avoid debug mode overhead. * include/experimental/map (erase, erase_if): Likewise. * include/experimental/set (erase, erase_if): Likewise. * include/experimental/unordered_map (erase, erase_if): Likewise. * include/experimental/unordered_set (erase, erase_if): Likewise. * include/experimental/vector (erase, erase_if): Likewise. * include/std/deque (erase, erase_if): Likewise. * include/std/map (erase, erase_if): Likewise. * include/std/set (erase, erase_if): Likewise. * include/std/unordered_map (erase, erase_if): Likewise. * include/std/unordered_set (erase, erase_if): Likewise. * include/std/vector (erase, erase_if): Likewise.
2021-10-07libstdc++: Move C++14 <chrono> components to new <bits/chrono.h> headerJonathan Wakely
This moves the "classic" contents of <chrono> to a new header, so that <future>, <thread> etc. can get use durations and clocks without calendar types, time zones, and chrono I/O. libstdc++-v3/ChangeLog: * include/Makefile.am: Add new header. * include/Makefile.in: Regenerate. * include/std/chrono (duration, time_point, system_clock) (steady_clock, high_resolution_clock, chrono_literals, sys_time) (file_clock, file_time): Move to ... * include/bits/chrono.h: New file. * include/bits/atomic_futex.h: Include new header instead of <chrono>. * include/bits/atomic_timed_wait.h: Likewise. * include/bits/fs_fwd.h: Likewise. * include/bits/semaphore_base.h: Likewise. * include/bits/this_thread_sleep.h: Likewise. * include/bits/unique_lock.h: Likewise. * include/experimental/bits/fs_fwd.h: Likewise. * include/experimental/chrono: Likewise. * include/experimental/io_context: Likewise. * include/experimental/netfwd: Likewise. * include/experimental/timer: Likewise. * include/std/condition_variable: Likewise. * include/std/mutex: Likewise. * include/std/shared_mutex: Likewise.
2021-10-07libstdc++: Avoid debug checks in uniform container erasure functionsJonathan Wakely
In commit r12-4083 I tried to make the std::erase and std::erase_if function avoid the unnecessary overhead of safe iterators. It didn't work, for two reasons. Firstly, for the RB tree containers the __niter_base function is a no-op (because the iterators aren't random access) so the safe iterators were still used. Secondly, for the cases where __niter_base did remove the safe iterator layer, there was still unnecessary overhead to create a new safe iterator and link it to the container. This solves the problem by simply binding a reference to the non-debug version of the conainer. For normal mode this is a no-op, and for debug mode it binds a reference to the debug container's base class. That means the rest of the function operates directly on the non-debug container, and avoids all checking. For std::basic_string there's no need to unwrap anything, because we use std::basic_string directly in debug mode anyway. libstdc++-v3/ChangeLog: * include/bits/erase_if.h (__erase_nodes_if): Remove redundant __niter_base calls. * include/std/string (erase, erase_if): Likewise. * include/std/deque (erase, erase_if): Access non-debug container directly. * include/std/map (erase, erase_if): Likewise. * include/std/set (erase, erase_if): Likewise. * include/std/unordered_map (erase, erase_if): Likewise. * include/std/unordered_set (erase, erase_if): Likewise. * include/std/vector (erase, erase_if): Likewise. * include/experimental/deque (erase, erase_if): Likewise. * include/experimental/map (erase, erase_if): Likewise. * include/experimental/set (erase, erase_if): Likewise. * include/experimental/unordered_map (erase, erase_if): Likewise. * include/experimental/unordered_set (erase, erase_if): Likewise. * include/experimental/vector (erase, erase_if): Likewise.
2021-10-01libstdc++: Add std::__conditional_t alias templateJonathan Wakely
This change is inspired by the suggestion in http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1715r0.html The new std::__conditional_t alias template is functionally equivalent to std::conditional_t but should be more efficient to compile, due to only ever instantiating two specializations (std::__conditional<true> and std::__conditional<false>) rather than a new specialization for every use of std::conditional. The new alias template is also available in C++11, unlike the C++14 std::conditional_t alias. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: * include/std/type_traits (__conditional): New class template for internal uses of std::conditional. (__conditional_t): New alias template to replace conditional_t. (__and_, __or_, __result_of_memfun, __result_of_memobj): Use __conditional_t instead of conditional::type. * include/bits/atomic_base.h (__atomic_impl::_Diff): Likewise. * include/bits/hashtable.h (_Hashtable): Likewise. * include/bits/hashtable_policy.h (_Node_iterator, _Insert_base) (_Local_iterator): Likewise. Replace typedefs with using-declarations. * include/bits/move.h (move_if_noexcept): Use __conditional_t. * include/bits/parse_numbers.h (_Select_int_base): Likewise. * include/bits/ptr_traits.h (__make_not_void): Likewise. * include/bits/ranges_algobase.h (__copy_or_move_backward) (__copy_or_move): Likewise. * include/bits/ranges_base.h (borrowed_iterator_t): Likewise. * include/bits/ranges_util.h (borrowed_subrange_t): Likewise. * include/bits/regex_compiler.h (_BracketMatcher): Use __conditional_t. Replace typedefs with using-declarations. * include/bits/shared_ptr_base.h (__shared_count): Use __conditional_t. * include/bits/stl_algobase.h (__copy_move, __copy_move_backward): Likewise. * include/bits/stl_iterator.h (__detail::__clamp_iter_cat) (reverse_iterator::iterator_concept) (__make_move_if_noexcept_iterator) (iterator_traits<common_iterator<_It, _Sent>>) (iterator_traits<counted_iterator<_It>>): Likewise. * include/bits/stl_pair.h (_PCC, pair::operator=): Likewise. * include/bits/stl_tree.h (_Rb_tree::insert_return_type) (_Rb_tree::_M_clone_node): Likewise. * include/bits/unique_ptr.h (unique_ptr(unique_ptr<U,E>&&)): Likewise. * include/bits/uses_allocator.h (__uses_alloc): Likewise. (__is_uses_allocator_predicate): Likewise. * include/debug/functions.h (__foreign_iterator_aux2): Likewise. * include/experimental/any (any::_Manager, __any_caster): Likewise. * include/experimental/executor (async_completion): Likewise. * include/experimental/functional (__boyer_moore_base_t): Likewise. * include/std/any (any::_Manager): Likewise. * include/std/functional (__boyer_moore_base_t): Likewise. * include/std/ranges (borrowed_iterator_t) (borrowed_subrange_t, __detail::__maybe_present_t) (__detail::__maybe_const_t, split_view): Likewise. * include/std/tuple (__empty_not_final, tuple::operator=): Likewise. * include/std/variant (__detail::__variant::__get_t): Likewise.
2021-09-17libstdc++: Add 'noexcept' to path::iterator membersJonathan Wakely
All path::iterator operations are non-throwing. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: * include/bits/fs_path.h (path::iterator): Add noexcept to all member functions and friend functions. (distance): Add noexcept. (advance): Add noexcept and inline. * include/experimental/bits/fs_path.h (path::iterator): Add noexcept to all member functions.
2021-08-31libstdc++: Improve error handling in Net TS name resolutionJonathan Wakely
Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: * include/experimental/internet (__make_resolver_error_code): Handle EAI_SYSTEM errors. (basic_resolver_results): Use __make_resolver_error_code. Use Glibc NI_MAXHOST and NI_MAXSERV values for buffer sizes.
2021-08-26libstdc++: Make Networking TS headers more portable [PR100285]Jonathan Wakely
Add more preprocessor conditions to check for constants being defined before using them, so that the Networking TS headers can be compiled on a wider range of platforms. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: PR libstdc++/100285 * configure.ac: Check for O_NONBLOCK. * configure: Regenerate. * include/experimental/internet: Include <ws2tcpip.h> for Windows. Use preprocessor conditions around more constants. * include/experimental/socket: Use preprocessor conditions around more constants. * testsuite/experimental/net/internet/resolver/base.cc: Only use constants when the corresponding C macro is defined. * testsuite/experimental/net/socket/basic_socket.cc: Likewise. * testsuite/experimental/net/socket/socket_base.cc: Likewise. Make preprocessor checks more fine-grained.
2021-08-12libstdc++: Add [[nodiscard]] to experimental::randintJonathan Wakely
Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: * include/experimental/random (experimental::randint): Add nodiscard attribute.
2021-07-27libstdc++: Simplify std::optional::value()Jonathan Wakely
The structure of these functions likely dates from the time before G++ fully supported C++14 extended constexpr, so that the throw expression had to be the operand of a conditional expression. That is not true now, so we can use a more straightforward version of the code. We can also simplify the declaration of __throw_bad_optional_access by using the C++11-style [[noreturn]] attribute so that a separate declaration isn't needed. libstdc++-v3/ChangeLog: * include/experimental/optional (__throw_bad_optional_access): Replace GNU attribute with C++11 attribute. (optional::value, optional::value_or): Use if statements instead of conditional expressions. * include/std/optional (__throw_bad_optional_access) (optional::value, optional::value_or): Likewise.
2021-07-27libstdc++: Remove unnecessary uses of <utility>Jonathan Wakely
The <algorithm> header includes <utility>, with a comment referring to UK-300, a National Body comment on the C++11 draft. That comment proposed to move std::swap to <utility> and then require <algorithm> to include <utility>. The comment was rejected, so we do not need to implement the suggestion. For backwards compatibility with C++03 we do want <algorithm> to define std::swap, but it does so anyway via <bits/move.h>. We don't need the whole of <utility> to do that. A few other headers that need std::swap can include <bits/move.h> to get it, instead of <utility>. There are several headers that include <utility> to get std::pair, but they can use <bits/stl_pair.h> to get it without also including the rel_ops namespace and other contents of <utility>. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: * include/std/algorithm: Do not include <utility>. * include/std/functional: Likewise. * include/std/regex: Include <bits/stl_pair.h> instead of <utility>. * include/debug/map.h: Likewise. * include/debug/multimap.h: Likewise. * include/debug/multiset.h: Likewise. * include/debug/set.h: Likewise. * include/debug/vector: Likewise. * include/bits/fs_path.h: Likewise. * include/bits/unique_ptr.h: Do not include <utility>. * include/experimental/any: Likewise. * include/experimental/executor: Likewise. * include/experimental/memory: Likewise. * include/experimental/optional: Likewise. * include/experimental/socket: Use __exchange instead of std::exchange. * src/filesystem/ops-common.h: Likewise. * testsuite/20_util/default_delete/48631_neg.cc: Adjust expected errors to not use a hardcoded line number. * testsuite/20_util/default_delete/void_neg.cc: Likewise. * testsuite/20_util/specialized_algorithms/uninitialized_copy/constrained.cc: Include <utility> for std::as_const. * testsuite/20_util/specialized_algorithms/uninitialized_default_construct/constrained.cc: Likewise. * testsuite/20_util/specialized_algorithms/uninitialized_move/constrained.cc: Likewise. * testsuite/20_util/specialized_algorithms/uninitialized_value_construct/constrained.cc: Likewise. * testsuite/23_containers/vector/cons/destructible_debug_neg.cc: Adjust dg-error line number.
2021-07-01libstdc++: Improvements to Doxygen markupJonathan Wakely
This attempst to improve the doxygen output to work around what seems to be some bugs in doxygen (issues 8635 and 8638). The @addtogroup command doesn't work for entities inside a nested namespace (see 8635) so we need to close and reopen groups on entering and elaving nested namespaces. This fixes the problem that chrono::duration and chrono::time_point were not documented in the "Time" documentation group. I am unable to make the path classes appear as part of their relevant groups (File System and Filesystem TS), nor the contents of <exception> or <system_error>. I have made some minor improvements to the docs for those types, including starting to address PR 97001 by adding @since to the doxygen comments. This change also excludes the <experimental/bits/net.h> header from Doxygen processing, so we don't get an unwanted "Networking-ts" group in the documentation. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: * doc/doxygen/doxygroups.cc: Fix docs for std::literals. * doc/doxygen/user.cfg.in: Exclude the Networking TS header. Add some more predefined macros. * include/bits/fs_fwd.h: Move @addtogroup commands inside namespaces. Add better documentation. * include/bits/fs_path.h: Likewise. * include/experimental/bits/fs_fwd.h: Likewise. * include/experimental/bits/fs_path.h: Likewise. * include/ext/throw_allocator.h: Fix typo and improve docs. * include/std/chrono: Move @addtogroup commands. * include/std/system_error: Move @addtogroup commands. * libsupc++/exception: Improve documentation. * libsupc++/exception.h: Add @since documentation.
2021-07-01libstdc++: Improve Doxygen documentation groups [PR 101258]Jonathan Wakely
This defines some new Doxygen groups for C++17 variable templates and for the contents of <experimental/type_traits>. By documenting the group as a whole and adding each template to a group we don't need to document them individually. Also mark more internals with "@cond undocumented" so that Doxygen ignores them by default. Also make Doxygen process <experimental/simd>. For some reason, many of the class templates in <type_traits> do not appear in the "Metaprogramming" group. For example, add_cv, remove_extent, and all the is_xxx_constructible and is_xxx_assignable traits. For some reason, Doxygen doesn't include them in the group, despite doing it correctly for other traits in the same header. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: PR libstdc++/101258 * doc/doxygen/user.cfg.in (INPUT): Add <experimental/simd>. (COLS_IN_ALPHA_INDEX): Remove obsolete tag. (PREDEFINED): Add/fix some more macros that need to be expanded. * include/bits/random.h: Stop Doxygen from documenting internal implementation details. * include/bits/random.tcc: Likewise. * include/bits/this_thread_sleep.h: Fix @file name. * include/experimental/bits/simd.h: Add to Doxygen group. Do not document internal implementation details. * include/experimental/bits/simd_detail.h: Do not document internal implementation details. * include/experimental/simd: Define Doxygen groups. * include/experimental/type_traits: Improve documentation for the header file. Define groups. Use @since commands. * include/std/scoped_allocator (scoped_allocator_adaptor): Move declaration before undocumented region. * include/std/type_traits (true_type, false_type): Use using declaration instead of typedef. (is_invocable_v, is_nothrow_invocable_v, is_invocable_r_v) (is_nothrow_invocable_r_v): Move definitions next to other C++17 variable templates. Do not document internal implementation details. Move misplaced group-end command. Define group for variable templates. * include/std/variant: Do not document internal implementation details. * testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error line number.
2021-07-01libstdc++: Make <experimental/simd> depend on C++17Jonathan Wakely
Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: * include/experimental/simd: Do not define anything pre-C++17.
2021-06-25libstdc++: Make use of __builtin_bit_cast for simdMatthias Kretz
The __bit_cast function was a hack to achieve what __builtin_bit_cast can do, therefore use __builtin_bit_cast if possible. However, __builtin_bit_cast cannot be used to cast from/to fixed_size_simd, since it isn't trivially copyable (in the language sense — in principle it is). Therefore add __proposed::simd_bit_cast to enable the use case required in the test framework. Signed-off-by: Matthias Kretz <m.kretz@gsi.de> libstdc++-v3/ChangeLog: * include/experimental/bits/simd.h (__bit_cast): Implement via __builtin_bit_cast #if available. (__proposed::simd_bit_cast): Add overloads for simd and simd_mask, which use __builtin_bit_cast (or __bit_cast #if not available), which return an object of the requested type with the same bits as the argument. * include/experimental/bits/simd_math.h: Use simd_bit_cast instead of __bit_cast to allow casts to fixed_size_simd. (copysign): Remove branch that was only required if __bit_cast cannot be constexpr. * testsuite/experimental/simd/tests/bits/test_values.h: Switch from __bit_cast to __proposed::simd_bit_cast since the former will not cast fixed_size objects anymore.
2021-06-24libstdc++: Fix internal names: add missing underscoresMatthias Kretz
Signed-off-by: Matthias Kretz <m.kretz@gsi.de> libstdc++-v3/ChangeLog: * include/experimental/bits/simd_math.h (_GLIBCXX_SIMD_MATH_CALL2_): Rename arg2_ to __arg2. (_GLIBCXX_SIMD_MATH_CALL3_): Rename arg2_ to __arg2 and arg3_ to __arg3.
2021-06-24libstdc++: Ensure unrolled loops inline the lambdaMatthias Kretz
Signed-off-by: Matthias Kretz <m.kretz@gsi.de> libstdc++-v3/ChangeLog: * include/experimental/bits/simd.h (__execute_on_index_sequence) (__execute_on_index_sequence_with_return) (__call_with_n_evaluations, __call_with_subscripts): Add flatten attribute.
2021-06-24libstdc++: Avoid raising fp exceptions in trunc, floor, and ceilMatthias Kretz
Signed-off-by: Matthias Kretz <m.kretz@gsi.de> libstdc++-v3/ChangeLog: * include/experimental/bits/simd_x86.h (_S_trunc, _S_floor) (_S_ceil): Set bit 8 (_MM_FROUND_NO_EXC) on AVX and SSE4.1 roundp[sd] calls.
2021-06-24libstdc++: Fix condition when AVX512F ldexp implementation is usedMatthias Kretz
This improves codegen of ldexp if AVX512VL is available. Signed-off-by: Matthias Kretz <m.kretz@gsi.de> libstdc++-v3/ChangeLog: * include/experimental/bits/simd_x86.h (_S_ldexp): The AVX512F implementation doesn't require a _VecBltnBtmsk ABI tag, it requires either a 64-Byte input (in which case AVX512F must be available) or AVX512VL.
2021-06-24libstdc++: Minor simd_math cleanupsMatthias Kretz
Signed-off-by: Matthias Kretz <m.kretz@gsi.de> libstdc++-v3/ChangeLog: * include/experimental/bits/simd_math.h: Undefine internal macros after use. (frexp): Move #if to a more sensible position and reformat preceding code. (logb): Call _SimdImpl::_S_logb for fixed_size instead of duplicating the code here. (modf): Simplify condition.
2021-06-24libstdc++: Remove incorrect fabs(simd) overloadMatthias Kretz
fabs(int) returns double, this one didn't. This overload is not specified in the Parallelism TS 2. Also remove the comment about labs and llabs: it doesn't belong here. Signed-off-by: Matthias Kretz <m.kretz@gsi.de> libstdc++-v3/ChangeLog: * include/experimental/bits/simd_math.h (fabs): Remove fabs(simd<integral>) overload.
2021-06-24libstdc++: Improve simd fixed_size codegenMatthias Kretz
Sometimes fixed_size objects will get unnecessarily copied on the stack. The simd implementation should never pass _SimdTuple by value to avoid requiring the optimizer to see through these copies. Signed-off-by: Matthias Kretz <m.kretz@gsi.de> libstdc++-v3/ChangeLog: * include/experimental/bits/simd_converter.h (_SimdConverter::operator()): Pass _SimdTuple by const-ref. * include/experimental/bits/simd_fixed_size.h (_GLIBCXX_SIMD_FIXED_OP): Pass binary operator _SimdTuple arguments by const-ref. (_S_masked_unary): Pass _SimdTuple by const-ref.
2021-06-24libstdc++: Remove dead code in simdMatthias Kretz
This helper type became unused at some point. Signed-off-by: Matthias Kretz <m.kretz@gsi.de> libstdc++-v3/ChangeLog: * include/experimental/bits/simd_fixed_size.h (_AbisInSimdTuple): Removed.
2021-06-24libstdc++: Improve copysign(simd) codegenMatthias Kretz
This also resolves a test failure on aarch64 with -ffast-math and fixed_size<N> with large N. Signed-off-by: Matthias Kretz <m.kretz@gsi.de> libstdc++-v3/ChangeLog: * include/experimental/bits/simd.h: Add missing operator~ overload for simd<floating-point> to __float_bitwise_operators. * include/experimental/bits/simd_builtin.h (_SimdImplBuiltin::_S_complement): Bitcast to int (and back) to implement complement for floating-point vectors. * include/experimental/bits/simd_fixed_size.h (_SimdImplFixedSize::_S_copysign): New function, forwarding to copysign implementation of _SimdTuple members. * include/experimental/bits/simd_math.h (copysign): Call _SimdImpl::_S_copysign for fixed_size arguments. Simplify generic copysign implementation using the new ~ operator.
2021-06-11libstdc++: Fix filesystem::path comparisons for C++23Jonathan Wakely
In C++23 there is a basic_string_view(Range&&) constructor, which is constrained to take a range (specifically, a contiguous_range). When the filesystem::path comparison operators call lhs.compare(rhs) the overload taking a string_view is considered, which means checking whether path satisfies the range concept. That satisfaction result changes depending whether path::iterator is complete, which is ill-formed; no diagnostic required. To avoid the problem, this change ensures that the overload resolution is performed in a context where path::iterator is complete and the range concept is satisfied. (The result of overload resolution is always that the compare(const path&) overload is the best match, but we still have to consider the compare(basic_string_view<value_type>) one to decide if it even participates in overload resolution). For std::filesystem::path we can't define the comparison operators later in the file, because they are hidden friends, so a new helper is introduced that gets defined when everything else is complete. For std::experimental::filesystem::path we can just move the definitions of the comparison operators later in the file. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: * include/bits/fs_path.h (operator==, operator<=>): Use new _S_compare function. (path::_S_compare): New function to call path::compare in a context where path::iterator is complete. * include/experimental/bits/fs_path.h (operator<, operator==): Define after path::iterator is complete. * testsuite/27_io/filesystem/path/native/conv_c++23.cc: New test. * testsuite/experimental/filesystem/path/native/conv_c++23.cc: New test.
2021-06-08libstdc++: Finish implementing LWG 3413 for propagate_constJonathan Wakely
We already have conditional noexcept so this just constrains the non-member swap overload. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: * include/experimental/propagate_const (swap): Constrain. * testsuite/experimental/propagate_const/swap/lwg3413.cc: New test.
2021-05-17libstdc++: Fix filesystem::path constraints for volatile [PR 100630]Jonathan Wakely
The constraint check for filesystem::path construction uses decltype(__is_path_src(declval<Source>())) which mean it considers conversion from an rvalue. When Source is a volatile-qualified type it cannot use is_path_src(const Unknown&) because a const lvalue reference can only bind to a non-volatile rvalue. Since the relevant path members all have a const Source& parameter, the constraint should be defined in terms of declval<const Source&>(), not declval<Source>(). This avoids the problem of volatile-qualified rvalues, because we no longer use an rvalue at all. libstdc++-v3/ChangeLog: PR libstdc++/100630 * include/experimental/bits/fs_path.h (__is_constructible_from): Test construction from a const lvalue, not an rvalue. * testsuite/27_io/filesystem/path/construct/100630.cc: New test. * testsuite/experimental/filesystem/path/construct/100630.cc: New test.
2021-04-30libstdc++: Use <sys/socket.h> features conditionally [PR 100285]Jonathan Wakely
This makes the uses of getsockopt and setsockopt in <experimental/socket> conditional on the availability of <sys/socket.h>. It also fixes a test to check for <sys/socket.h> instead of <socket.h>. libstdc++-v3/ChangeLog: PR libstdc++/100285 * include/experimental/socket (__basic_socket_impl::set_option) (__basic_socket_impl::get_option) [!_GLIBCXX_HAVE_SYS_SOCKET_H]: Just set error code. * testsuite/experimental/net/socket/socket_base.cc: CHeck for <sys/socket.h> not <socket.h>.
2021-04-27libstdc++: Minor refactoring in <experimental/internet>Jonathan Wakely
libstdc++-v3/ChangeLog: * include/experimental/internet (address_v6::bytes_type): Adjust formatting. (basic_endpoint): Define _M_is_v6() to put all checks for AF_INET6 in one place. (basic_endpoint::resize): Simplify. (operator==(const tcp&, const tcp&)): Add constexpr and noexcept. (operator!=(const tcp&, const tcp&)): Likewise. (operator==(const udp&, const udp&)): Likewise. (operator!=(const udp&, const udp&)): Likewise. * testsuite/experimental/net/internet/tcp.cc: New test. * testsuite/experimental/net/internet/udp.cc: New test.
2021-04-27libstdc++: Better preprocessor conditions in net::ip [PR 100286]Jonathan Wakely
This improves the use of preprocessor conditionas to enable/disable members of namespace net::ip according to what is supported by the target. This fixes PR 100286 by ensuring that the to_string member functions are always defined for the address_v4 and address_v6 classes. On the other hand, the IP protocol classes and internet socket option classes aren't useful at all if the corresponding constants (such as IPPROTO_TCP or IPV6_MULTICAST_HOPS) aren't define. So those types are not defined at all if they can't be used. The net/internet/socket/opt.cc test uses __has_include to check whether or not to expect the types to be available. libstdc++-v3/ChangeLog: PR libstdc++/100286 * include/experimental/internet (resolver_errc, resolver_category()) (make_error_code, make_error_condition): Define unconditionally, only make enumerators and use of gai_strerror depend on the availability of <netdb.h>. (address_v4::to_string): Use correct constant for string length. (address_v4::to_string, address_v6::to_string): Define unconditionally, throw if unsupported. (make_address_v4, make_address_v6): Define unconditionally. Return an error if unsupported. (tcp, udp, v6_only, unicast::hops, multicast::*): Define conditionally, * testsuite/experimental/net/internet/socket/opt.cc: Check for <netinet/in.h> and <netinet/tcp.h> before using types from namespace net::ip.
2021-04-27libstdc++: Define net::socket_base::message_flags operators as friends [PR ↵Jonathan Wakely
100285] The overloaded operators for socket_base::message_flags should only be defined when the message_flags type itself is defined. Rather than duplicate the preprocessor conditional, this moves the operators into the same scope as the type, defining them as hidden friends. As well as fixing the bug, this has all the usual advantages of hidden friends (they are not visible to normal name lookup for unrelated types). For consistency, do the same for the resolver_base::flags bitmask operators too. libstdc++-v3/ChangeLog: PR libstdc++/100285 * include/experimental/internet (resolver_base::flags): Define overloaded operators as hidden friends. * include/experimental/socket (socket_base::message_flags): Likewise.
2021-04-26libstdc++: Fix internet socket option classesJonathan Wakely
Similar to the previous commit, this fixes various problems with the socket options classes in the <internet> header: - The constructors were not noexcept. - The __sockopt_base<T>::value() member function was present unconditionally (so was defined for socket_base::linger which is incorrect). - The __socket_crtp<C, T>::operator=(T) assignment operator was not noexcept, and was hidden in the derived classes. - The MulticastSocketOptions incorrectly used a union, incorrectly defined resize and const data() member functions, and their constructors were unimplemented. Also, where appropriate: - Use class instead of struct for the socket option types. - Define the _S_level and _S_name constants as private. - Declare the __socket_crtp base as a friend. libstdc++-v3/ChangeLog: * include/experimental/internet (tcp::no_delay, v6_only) (unicast::hops, multicast::hops, multicast::enable_loopback): Change access of base class and static data members. Add using-declaration for __socket_crtp::operator=(_Tp). (multicast::__mcastopt): New type. (multicast::join_group, multicast::leave_group): Derive from __mcastopt for common implementation. * include/experimental/socket: Add comment. * testsuite/experimental/net/internet/socket/opt.cc: New test. * testsuite/experimental/net/socket/socket_base.cc: Check for protected constructor/destructor of socket_base. Check for explicit constructors of socket option classes.
2021-04-26libstdc++: Fix socket option classesJonathan Wakely
This fixes some flaws in the socket option types defined in net::socket_base: - The constructors were not noexcept. - The __sockopt_base<T>::value() member function was present unconditionally (so was defined for socket_base::linger which is incorrect). - The __socket_crtp<C, T>::operator=(T) assignment operator was not noexcept, and was hidden in the derived classes. Also: - Use class instead of struct for the socket option types. - Define the _S_level and _S_name constants as private. - Declare the __socket_crtp base as a friend. libstdc++-v3/ChangeLog: * include/experimental/bits/net.h (__socket_base): Add bool template parameter to allow BooleanSocketOption and IntegerSocketOption to have different __socket_base<int> base classes. (__socket_base<bool>): Adjust base class. (__socket_base<int>): Add partial specialization. (__socket_crtp::operator=(_Tp)): Add noexcept-specifier. * include/experimental/socket (socket_base::broadcast) (socket_base::debug, socket_base::do_not_route) (socket_base::keep_alive, socket_base::linger) (socket_base::out_of_band_inline) (socket_base::receive_buffer_size) (socket_base::receive_low_watermark) (socket_base::reuse_address, socket_base::send_buffer_size) (socket_base::send_low_watermark): Add using-declaration for __socket_crtp::operator=(_Tp). * testsuite/experimental/net/socket/socket_base.cc: Check properties of socket option types.
2021-04-26libstdc++: Simplify definition of net::ip::resolver_base constantsJonathan Wakely
libstdc++-v3/ChangeLog: * include/experimental/internet (resolver_base::flags): Remove enumerators. Initialize constants directly with desired values. Make all operators constexpr and noexcept. * testsuite/experimental/net/internet/resolver/base.cc: Use __gnu_test::test_bitmask_values for bitmask type. Check construction and destruction is protected.
2021-04-26libstdc++: Add missing 'inline' specifiers to net::ip functions [PR 100259]Jonathan Wakely
libstdc++-v3/ChangeLog: PR libstdc++/100259 * include/experimental/internet (net::ip::make_error_code) (net::ip::make_error_condition, net::ip::make_network_v4) (net::ip::operator==(const udp&, const udp&)): Add 'inline'.