aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include
AgeCommit message (Collapse)AuthorFilesLines
2024-08-28libstdc++: Fix -Wunused-variable warning in <format>Jonathan Wakely1-0/+5
libstdc++-v3/ChangeLog: * include/std/format (format_parse_context::check_dynamic_spec): Add [[maybe_unused]] attribute and comment.
2024-08-28libstdc++: Remove unused typedef in <ranges>Jonathan Wakely1-1/+0
This local typedef should have been removed in r14-6199-g45630fbcf7875b. libstdc++-v3/ChangeLog: * include/std/ranges (to): Remove unused typedef.
2024-08-28libstdc++: Fix @headername for bits/cpp_type_traits.hKim Gräsman1-1/+1
There is no file ext/type_traits, point it to ext/type_traits.h instead. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h: Improve doxygen file docs.
2024-08-28libstdc++: avoid -Wsign-compareJason Merrill2-2/+3
-Wsign-compare complained about these comparisons between (unsigned) size_t and (signed) streamsize, or between (unsigned) native_handle_type and (signed) -1. Fixed by adding casts to unify the types. libstdc++-v3/ChangeLog: * include/std/istream: Add cast to avoid -Wsign-compare. * include/std/stacktrace: Likewise.
2024-08-28libstdc++: avoid -Wzero-as-null-pointer-constantJason Merrill1-1/+1
libstdc++-v3/ChangeLog: * include/std/coroutine (coroutine_handle): Use nullptr instead of 0 as initializer for _M_fr_ptr.
2024-08-28libstdc++: add missing returnJason Merrill1-0/+1
The return seems to have been lost in the r15-1858 RAII overhaul. libstdc++-v3/ChangeLog: * include/bits/stl_uninitialized.h (__uninitialized_move_copy): Add missing return.
2024-08-28libstdc++: remove extra semicolonsJason Merrill1-12/+12
The semicolons after each macro invocation here end up following the closing brace of a function, leading to -Wextra-semi pedwarns. libstdc++-v3/ChangeLog: * include/decimal/decimal.h (_DEFINE_DECIMAL_BINARY_OP_WITH_INT): Remove redundant semicolons.
2024-08-23libstdc++: Hide std::tuple internals from Doxygen docsJonathan Wakely1-0/+2
libstdc++-v3/ChangeLog: * include/std/tuple: Do not include implementation details in Doxygen documentation.
2024-08-23libstdc++: Improve Doxygen docs for std::allocator_traits specializationsJonathan Wakely2-4/+21
The main fix here is to use @header so that the docs show the correct header file instead of an internal header like alloc_traits.h. libstdc++-v3/ChangeLog: * include/bits/alloc_traits.h: Improve doxygen docs for allocator_traits specializations. * include/bits/memory_resource.h: Likewise.
2024-08-23libstdc++: Implement LWG 3746 for std::optionalJonathan Wakely1-2/+10
This avoids constraint recursion in operator<=> for std::optional. The resolution was approved in Kona 2022. libstdc++-v3/ChangeLog: * include/std/optional (__is_derived_from_optional): New concept. (operator<=>): Use __is_derived_from_optional. * testsuite/20_util/optional/relops/lwg3746.cc: New test.
2024-08-23libstdc++: Optimize __try_use_facet for const typesJonathan Wakely1-1/+1
LWG 436 confirmed that const-qualified types are valid arguments for Facet template parameters (but volatile-qualified types are not). Use the fast path in std::use_facet and std::has_facet for const T as well as T. libstdc++-v3/ChangeLog: * include/bits/locale_classes.tcc (__try_use_facet): Also avoid dynamic_cast for const-qualified facet types.
2024-08-23libstdc++: Fix std::allocator_traits::construct constraints [PR108619]Jonathan Wakely4-109/+261
Using std::is_constructible in the constraints introduces a spurious dependency on the type being destructible, which should not be required for constructing with an allocator. The test case shows a case where the type has a private destructor, which can be destroyed by the allocator, but std::is_destructible and std::is_constructible are false. Similarly, using is_nothrow_constructible in the noexcept-specifiers for the construct members of allocator_traits and std::allocator, __gnu_cxx::__new_allocator, and __gnu_cxx::__malloc_allocator gives the wrong answer if the type isn't destructible. We need a new type trait to define those correctly, so that we only check if the placement new-expression is nothrow after using is_constructible to check that it would be well-formed. Instead of just fixing the overly restrictive constraint to check for placement new, rewrite allocator_traits in terms of 'if constexpr' using variable templates and the detection idiom. Although we can use 'if constexpr' and variable templates in C++11 with appropriate uses of diagnostic pragmas, we can't have constexpr functions with multiple return statements. This means that in C++11 mode the _S_nothrow_construct and _S_nothrow_destroy helpers used for noexcept-specifiers still need to be overlaods using enable_if. Nearly everything else can be simplified to reduce overload resolution and enable_if checks. libstdc++-v3/ChangeLog: PR libstdc++/108619 * include/bits/alloc_traits.h (__allocator_traits_base): Add variable templates for detecting which allocator operations are supported. (allocator_traits): Use 'if constexpr' instead of dispatching to overloads constrained with enable_if. (allocator_traits<allocator<T>>::construct): Use Construct if construct_at is not supported. Use __is_nothrow_new_constructible for noexcept-specifier. (allocator_traits<allocator<void>>::construct): Use __is_nothrow_new_constructible for noexcept-specifier. * include/bits/new_allocator.h (construct): Likewise. * include/ext/malloc_allocator.h (construct): Likewise. * include/std/type_traits (__is_nothrow_new_constructible): New variable template. * testsuite/20_util/allocator/89510.cc: Adjust expected results. * testsuite/ext/malloc_allocator/89510.cc: Likewise. * testsuite/ext/new_allocator/89510.cc: Likewise. * testsuite/20_util/allocator_traits/members/108619.cc: New test.
2024-08-23libstdc++: Only use std::time_put in std::format for non-C localesJonathan Wakely1-59/+74
When testing on Solaris I noticed that std/time/year/io.cc was FAILing because the year 1642 was being formatted as "+(" by %Ey. This turns out to be because we defer to std::time_put for modified conversion specs, and std::time_put uses std::strftime, and that's undefined for years before 1970. In particular, years before 1900 mean that the tm_year field is negative, which then causes incorrect results from strftime on at least Solaris and AIX. I've raised the general problem with LWG, but we can fix the FAILing test case (and probably improve performance slightly) by ignoring the E and O modifiers when the formatting locale is the "C" locale. The modifiers have no effect for the C locale, so we can just treat %Ey as %y and format it directly. This doesn't fix anything when the formatting locale isn't the C locale, but that case is not adequately tested, so doesn't cause any FAIL right now! The naïve fix would be simply: if (__mod) if (auto __loc = _M_locale(__ctx); __loc != locale::classic()) // ... However when the format string doesn't use the 'L' option, _M_locale always returns locale::classic(). In that case, we make a copy of the classic locale (which calls the non-inline copy constructor in the library), then make another copy of the classic locale, then compare the two. We can avoid all that by checking for the 'L' option first, instead of letting _M_locale do that: if (__mod && _M_spec._M_localized) if (auto __loc = __ctx.locale(); __loc != locale::classic()) // ... We could optimize this further if we had a __is_classic(__loc) function that would do the __loc == locale::classic() check without making any copies or non-inline calls. That would require examining the locale's _M_impl member, and probably require checking its name, because the locale::_S_classic singleton is not exported from the library. For _M_S the change is slightly different from the other functions, because if we skip using std::time_put for %OS then we fall through to the code that potentially prints fractional seconds, but the %OS format only prints whole seconds. So we need to format whole seconds directly when not using std::time_put, instead of falling through to the code below. libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (__formatter_chrono::_M_C_y_Y): Ignore modifiers unless the formatting locale is not the C locale. (__formatter_chrono::_M_d_e): Likewise. (__formatter_chrono::_M_H_I): Likewise. (__formatter_chrono::_M_m): Likewise. (__formatter_chrono::_M_M): Likewise. (__formatter_chrono::_M_S): Likewise. (__formatter_chrono::_M_u_w): Likewise. (__formatter_chrono::_M_U_V_W): Likewise.
2024-08-23libstdc++: Define operator== for hash table iterators [PR115939]Jonathan Wakely1-2/+78
Currently iterators for unordered containers do not directly define operator== and operator!= overloads. Instead they rely on the base class defining them, which is done so that iterator and const_iterator comparisons work using the same overloads. However this means a derived-to-base conversion is needed to call those operators, and PR libstdc++/115939 shows that this can be ambiguous (for -pedantic) when another overloaded operator could be used after an implicit conversion. This change defines operator== and operator!= directly for _Node_iterator and _Node_const_iterator so that no derived-to-base conversions are needed. The new overloads just forward to the base class ones, so the implementation is still shared and doesn't need to be duplicated. libstdc++-v3/ChangeLog: PR libstdc++/115939 * include/bits/hashtable_policy.h (_Node_iterator): Add operator== and operator!=. (_Node_const_iterator): Likewise. * testsuite/23_containers/unordered_map/115939.cc: New test.
2024-08-23libstdc++: Fix std::random_shuffle for low RAND_MAX [PR88935]Giovanni Bajo1-9/+33
When RAND_MAX is small and the number of elements being shuffled is close to it, we get very uneven distributions in std::random_shuffle. This uses a simple xorshift generator seeded by std::rand if we can't rely on std::rand itself. libstdc++-v3/ChangeLog: PR libstdc++/88935 * include/bits/stl_algo.h (random_shuffle) [RAND_MAX < INT_MAX]: Use xorshift instead of rand(). * testsuite/25_algorithms/random_shuffle/88935.cc: New test. Co-authored-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Giovanni Bajo <rasky@develer.com>
2024-08-23libstdc++: Make debug sequence members mutable [PR116369]Jonathan Wakely1-2/+2
We need to be able to attach debug mode iterators to const containers, so the safe iterator constructor uses const_cast to get a modifiable pointer to the container. If the container was defined as const, that const_cast to access its members results in undefined behaviour. PR 116369 shows a case where it results in a segfault because the container is in a rodata section (which shouldn't have happened, but the undefined behaviour in the library still exists in any case). This makes the _M_iterators and _M_const_iterators data members mutable, so that it's safe to modify them even if the declared type of the container is a const type. Ideally we would not need the const_cast at all. Instead, the _M_attach member (and everything it calls) should be const-qualified. That would work fine now, because the members that it ends up modifying are mutable. Making that change would require a number of new exports from the shared library, and would require retaining the old non-const member functions (maybe as symbol aliases) for backwards compatibility. That might be worth changing at some point, but isn't done here. libstdc++-v3/ChangeLog: PR c++/116369 * include/debug/safe_base.h (_Safe_sequence_base::_M_iterators): Add mutable specifier. (_Safe_sequence_base::_M_const_iterators): Likewise.
2024-08-23libstdc++: Simplify C++20 implementation of std::variantJonathan Wakely1-46/+37
For C++20 the __detail::__variant::_Uninitialized primary template can be used for all types, because _Variant_union can have a non-trivially destructible union member in C++20, and the constrained user-provided destructor will ensure we don't destroy inactive objects. Since we always use the primary template for C++20, we don't need the _Uninitialized::_M_get accessors to abstract the difference between the primary template and the partial specialization. That allows us to simplify __get_n for C++20 too. Also improve the comments that explain the uses of _Uninitialized and when/why _Variant_union needs a user-provided destructor. libstdc++-v3/ChangeLog: * include/std/variant [C++20] (_Uninitialized): Always use the primary template. [C++20] (__get_n): Access the _M_storage member directly.
2024-08-23libstdc++: Make std::vector<bool>::reference constructor private [PR115098]Jonathan Wakely2-7/+10
The standard says this constructor should be private. LWG 4141 proposes to remove it entirely. We still need it, but it doesn't need to be public. For std::bitset the default constructor is already private (and never even defined) but there's a non-standard constructor that's public, but doesn't need to be. libstdc++-v3/ChangeLog: PR libstdc++/115098 * include/bits/stl_bvector.h (_Bit_reference): Make default constructor private. Declare vector and bit iterators as friends. * include/std/bitset (bitset::reference): Make constructor and data members private. * testsuite/20_util/bitset/115098.cc: New test. * testsuite/23_containers/vector/bool/115098.cc: New test.
2024-08-22libstdc++: Optimize std::projected<I, std::identity>Patrick Palka1-0/+5
Algorithms that are generalized to take projections typically default the projection to std::identity, which is equivalent to no projection at all. In that case, I believe we could shortcut the projection logic to return the iterator unchanged rather than wrapping it. This should reduce compile times especially after P2609R3 which made the indirect invocability concepts more expensive to check when actual projections are involved. libstdc++-v3/ChangeLog: * include/bits/iterator_concepts.h (__detail::__projected): Define an optimized partial specialization for when the projection is std::identity. * testsuite/24_iterators/indirect_callable/projected.cc: Verify the optimization. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-08-22libstdc++: Implement P2997R1 changes to the indirect invocability conceptsPatrick Palka3-14/+15
This implements the changes of this C++26 paper as a DR against C++20. In passing this patch removes the std/ranges/version_c++23.cc test which is now mostly obsolete after the version.def FTM refactoring, and instead expands the __cpp_lib_ranges checks in another test so that it verifies the exact value of the FTM on a per language version basis. libstdc++-v3/ChangeLog: * include/bits/iterator_concepts.h (indirectly_unary_invocable): Relax as per P2997R1. (indirectly_regular_unary_invocable): Likewise. (indirect_unary_predicate): Likewise. (indirect_binary_predicate): Likewise. (indirect_equivalence_relation): Likewise. (indirect_strict_weak_order): Likewise. * include/bits/version.def (ranges): Update value for C++26. * include/bits/version.h: Regenerate. * testsuite/24_iterators/indirect_callable/p2997r1.cc: New test. * testsuite/std/ranges/version_c++23.cc: Remove. * testsuite/std/ranges/headers/ranges/synopsis.cc: Refine the __cpp_lib_ranges checks. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-08-22libstdc++: Implement P2609R3 changes to the indirect invocability conceptsPatrick Palka3-18/+49
This implements the changes of this C++23 paper as a DR against C++20. Note that after the later P2538R1 "ADL-proof std::projected" (which we already implement), we can't use a simple partial specialization to match specializations of the 'projected' alias template. So instead we identify such specializations using a pair of distinguishing member aliases. libstdc++-v3/ChangeLog: * include/bits/iterator_concepts.h (__detail::__indirect_value): Define. (__indirect_value_t): Define as per P2609R3. (iter_common_reference_t): Adjust as per P2609R3. (indirectly_unary_invocable): Likewise. (indirectly_regular_unary_invocable): Likewise. (indirect_unary_predicate): Likewise. (indirect_binary_predicate): Likewise. (indirect_equivalence_relation): Likewise. (indirect_strict_weak_order): Likewise. (__detail::__projected::__type): Define member aliases __projected_Iter and __projected_Proj providing the template arguments of the current specialization. * include/bits/version.def (ranges): Update value. * include/bits/version.h: Regenerate. * testsuite/24_iterators/indirect_callable/p2609r3.cc: New test. * testsuite/std/ranges/version_c++23.cc: Update expected value of __cpp_lib_ranges macro. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-08-21libstdc++: Use strlen for std::char_traits<char8_t>::length [PR102958]Jonathan Wakely1-4/+1
libstdc++-v3/ChangeLog: PR tree-optimization/102958 * include/bits/char_traits.h (char_traits<char8_t>::length): Use strlen.
2024-08-21libstdc++: Fix std::variant to reject array types [PR116381]Jonathan Wakely1-4/+2
libstdc++-v3/ChangeLog: PR libstdc++/116381 * include/std/variant (variant): Fix conditions for static_assert to match the spec. * testsuite/20_util/variant/types_neg.cc: New test.
2024-08-20libstdc++: Remove redundant reclaration of std::optionalJonathan Wakely1-3/+0
We've already declared optional at the top of the header, so don't need to do it again. libstdc++-v3/ChangeLog: * include/std/optional: Remove redundant redeclaration.
2024-08-20libstdc++: Fix indentation of lines that follow a [[likely]] attributeJonathan Wakely1-2/+2
libstdc++-v3/ChangeLog: * include/std/text_encoding: Fix indentation.
2024-08-08c++, libstdc++: Implement C++26 P2747R2 - constexpr placement new [PR115744]Jakub Jelinek2-0/+19
With the PR115754 fix in, constexpr placement new mostly just works, so this patch just adds constexpr keyword to the placement new operators in <new>, adds FTMs and testsuite coverage. There is one accepts-invalid though, the new (p + 1) int[]{2, 3}; // error (in this paper) case from the paper. Can we handle that incrementally? The problem with that is I think calling operator new now that it is constexpr should be fine even in that case in constant expressions, so int *p = std::allocator<int>{}.allocate(3); int *q = operator new[] (sizeof (int) * 2, p + 1); should be ok, so it can't be easily the placement new operator call itself on whose constexpr evaluation we try something special, it should be on the new expression, but constexpr.cc actually sees only <<< Unknown tree: expr_stmt (void) (TARGET_EXPR <D.2640, (void *) TARGET_EXPR <D.2641, VIEW_CONVERT_EXPR<int *>(b) + 4>>, TARGET_EXPR <D.2642, operator new [] (8, NON_LVALUE_EXPR <D.2640>)>, int * D.2643; <<< Unknown tree: expr_stmt (void) (D.2643 = (int *) D.2642) >>>; and that is just fine by the preexisting constexpr evaluation rules. Should build_new_1 emit some extra cast for the array cases with placement new in maybe_constexpr_fn (current_function_decl) that the existing P2738 code would catch? 2024-08-08 Jakub Jelinek <jakub@redhat.com> PR c++/115744 gcc/c-family/ * c-cppbuiltin.cc (c_cpp_builtins): Change __cpp_constexpr from 202306L to 202406L for C++26. gcc/testsuite/ * g++.dg/cpp2a/construct_at.h (operator new, operator new[]): Use constexpr instead of inline if __cpp_constexpr >= 202406L. * g++.dg/cpp26/constexpr-new1.C: New test. * g++.dg/cpp26/constexpr-new2.C: New test. * g++.dg/cpp26/constexpr-new3.C: New test. * g++.dg/cpp26/feat-cxx26.C (__cpp_constexpr): Adjust expected value. libstdc++-v3/ * libsupc++/new (__glibcxx_want_constexpr_new): Define before including bits/version.h. (_GLIBCXX_PLACEMENT_CONSTEXPR): Define. (operator new, operator new[]): Use it for placement new instead of inline. * include/bits/version.def (constexpr_new): New FTM. * include/bits/version.h: Regenerate.
2024-08-06libstdc++: Fix some undeclared uses of uintptr_t [PR116247]Jonathan Wakely3-1/+3
libstdc++-v3/ChangeLog: PR libstdc++/116247 * include/bits/fs_path.h: Use __UINTPTR_TYPE__ instead of uintptr_t. * include/bits/shared_ptr_atomic.h: Likewise. * include/ext/pointer.h: Include <stdint.h>.
2024-08-03libstdc++: use concrete return type for std::forward_likePatrick Palka1-23/+24
Inspired by https://github.com/llvm/llvm-project/issues/101614 this inverts the relationship between forward_like and __like_t so that forward_like is defined in terms of __like_t and with a concrete return type. __like_t in turn is defined via partial specializations that pattern match on the const- and reference-ness of T. This turns out to be more SFINAE friendly and significantly cheaper to compile than the previous implementation. libstdc++-v3/ChangeLog: * include/bits/move.h (__like_impl): New metafunction. (__like_t): Redefine in terms of __like_impl. (forward_like): Redefine in terms of __like_t. * testsuite/20_util/forward_like/2_neg.cc: Don't expect error outside the immediate context anymore. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-08-01libstdc++: Remove unused helper traitsJonathan Wakely2-10/+0
These are not used anywhere, we have more efficient variable templates for them instead. They're not documented as extensions, and are easy for users to write if they need them. libstdc++-v3/ChangeLog: * include/bits/utility.h (__is_in_place_type): Remove. * include/std/variant (__is_in_place_tag): Remove.
2024-08-01libstdc++: Remove unnecessary uses of <stdint.h>Jonathan Wakely4-10/+17
We don't need to include all of <stdint.h> when we only need uintptr_t from it. By using GCC's internal macro we avoid unnecessarily declaring everything in <stdint.h>. This helps users to avoid accidentally relying on those names being declared without explicitly including the header. libstdc++-v3/ChangeLog: * include/bits/align.h (align, assume_aligned): Use __UINTPTR_TYPE__ instead of uintptr_t. Do not include <stdint.h>. * include/bits/atomic_base.h (__atomic_ref): Likewise. * include/bits/atomic_wait.h (__waiter_pool_base::_S_for): Likewise. * include/std/atomic: Include <cstdint>.
2024-08-01libstdc++: Remove unused parameters from atomic impl detailsJonathan Wakely1-4/+2
libstdc++-v3/ChangeLog: * include/bits/atomic_base.h (__atomic_impl::compare_exchange_weak): Remove unused parameter. (__atomic_impl::compare_exchange_strong): Likewise.
2024-08-01libstdc++: Use memcmp to optimize std::bitset::_M_is_equal() [PR113807]Jonathan Wakely1-4/+10
As noted in the PR the compiler doesn't seem able to do this on its own, so we get better code at all optimization levels by using memcmp. libstdc++-v3/ChangeLog: PR libstdc++/113807 * include/std/bitset (bitset::_M_is_equal()): Use memcmp to optimize operator==.
2024-08-01libstdc++: Constrain std::basic_string default constructor [PR113841]Jonathan Wakely2-0/+8
This is needed to avoid errors outside the immediate context when evaluating is_default_constructible_v<basic_string<C, T, A>> when A is not default constructible. This change is not sufficient to solve the problem because there are a large number of member functions which have a default argument that constructs an allocator. libstdc++-v3/ChangeLog: PR libstdc++/113841 * include/bits/basic_string.h (basic_string::basic_string()): Constrain so that it's only present if the allocator is default constructible. * include/bits/cow_string.h (basic_string::basic_string()): Likewise. * testsuite/21_strings/basic_string/cons/113841.cc: New test.
2024-08-01libstdc++: Remove noexcept from non-const std::basic_string::data() [PR99942]Jonathan Wakely1-1/+6
The C++17 non-const overload of data() allows modifying the string contents directly, so for the COW string we must do a copy-on-write to unshare it. That means allocating, which can throw, so it shouldn't be noexcept. libstdc++-v3/ChangeLog: PR libstdc++/99942 * include/bits/cow_string.h (data()): Change to noexcept(false).
2024-07-31libstdc++: Bump __cpp_lib_format value for std::runtime_formatJonathan Wakely3-4/+4
We already supported this feature, but couldn't set the feature test macro accordingly because we were missing support for older features. Now that we support all the older <format> changes, we can set this to the correct value. libstdc++-v3/ChangeLog: * include/bits/version.def (format): Update value for C++26. * include/bits/version.h: Regenerate. * include/std/format (runtime_format, wruntime_format): Check __cpp_lib_format instead of __cplusplus. * testsuite/std/format/functions/format.cc: Update expected value of macro for C++26 mode.
2024-07-31libstdc++: Define C++26 member visit for std::basic_format_arg [PR110356]Jonathan Wakely4-3/+29
Implement the std::format changes from P2637R3. This adds visit member functions to std::basic_format_arg and deprecates the non-member function std::visit_format_arg. libstdc++-v3/ChangeLog: PR libstdc++/110356 * include/bits/c++config (_GLIBCXX26_DEPRECATED): Define. (_GLIBCXX26_DEPRECATED_SUGGEST): Define. * include/bits/version.def (format): Update for C++26. * include/bits/version.h: Regenerate. * include/std/format (basic_format_arg::visit): New member functions. (visit_format_arg): Add deprecated attribute. * testsuite/std/format/arguments/args.cc: Expect deprecated warnings. Check member visit. * testsuite/std/format/functions/format.cc: Update expected value for __cpp_lib_format macro. * testsuite/std/format/parse_ctx.cc: Add dg-warning for deprecation.
2024-07-31libstdc++: Define C++26 member visit for std::variant [PR110356]Jonathan Wakely3-1/+57
Implement the std::variant changes from P2637R3. libstdc++-v3/ChangeLog: PR libstdc++/110356 * include/bits/version.def (variant): Update for C++26. * include/bits/version.h: Regenerate. * include/std/variant (variant::visit): New member functions. * testsuite/20_util/variant/visit.cc: Check second alternative. * testsuite/20_util/variant/visit_member.cc: New test.
2024-07-31libstdc++: Implement C++26 type checking for std::format args [PR115776]Jonathan Wakely3-13/+146
Implement the changes from P2757R3, which enhance the parse context to be able to do type checking on format arguments, and to use that to ensure that args used for width and precisions are integral types. libstdc++-v3/ChangeLog: PR libstdc++/115776 * include/bits/version.def (format): Update for C++26. * include/bits/version.h: Regenerate. * include/std/format (basic_format_parse_context): Remove default argument from constructor and split into two constructors. Make the constructor taking size_t private for C++26 and later. (basic_format_parse_context::check_dynamic_spec): New member function template. (basic_format_parse_context::check_dynamic_spec_integral): New member function. (basic_format_parse_context::check_dynamic_spec_string): Likewise. (__format::_Spec::_S_parse_width_or_precision): Use check_dynamic_spec_integral. (__format::__to_arg_t_enum): New helper function. (basic_format_arg): Declare __to_arg_t_enum as friend. (__format::_Scanner): Define and use a derived parse context type. (__format::_Checking_scanner): Make arg types available to parse context. * testsuite/std/format/functions/format.cc: Check for new values of __cpp_lib_format macro. * testsuite/std/format/parse_ctx.cc: Check all members of basic_format_parse_context. * testsuite/std/format/parse_ctx_neg.cc: New test. * testsuite/std/format/string.cc: Add more checks for dynamic width and precision args.
2024-07-31libstdc++: Support P2510R3 "Formatting pointers" as a DR for C++20Jonathan Wakely3-17/+9
We already enable this for -std=gnu++20 but we can do it for -std=c++20 too. Both libc++ and MSVC also treat this change as a DR for C++20. Now that the previous change to the value of __cpp_lib_format is supported, we can finally update it to 202304 to indicate support for this feature too. libstdc++-v3/ChangeLog: * include/bits/version.def (format): Update value for P2510R3. * include/bits/version.h: Regenerate. * include/std/format (_GLIBCXX_P2518R3): Remove misspelled macro and check __glibcxx_format instead. * testsuite/std/format/functions/format.cc: Check value of the __cpp_lib_format macro for formatting pointers support. * testsuite/std/format/parse_ctx.cc: Likewise.
2024-07-31libstdc++: Handle encodings in localized chrono formatting [PR109162]Jonathan Wakely4-22/+122
This implements the C++23 paper P2419R2 (Clarify handling of encodings in localized formatting of chrono types). The requirement is that when the literal encoding is "a Unicode encoding form" and the formatting locale uses a different encoding, any locale-specific strings such as "août" for std::chrono::August should be converted to the literal encoding. Using the recently-added std::locale::encoding() function we can check the locale's encoding and then use iconv if a conversion is needed. Because nl_langinfo_l and iconv_open both allocate memory, a naive implementation would perform multiple allocations and deallocations for every snippet of locale-specific text that needs to be converted to UTF-8. To avoid that, a new internal locale::facet is defined to store the text_encoding and an iconv_t descriptor, which are then cached in the formatting locale. This requires access to the internals of a std::locale object in src/c++20/format.cc, so that new file needs to be compiled with -fno-access-control, as well as -std=gnu++26 in order to use std::text_encoding. Because the new std::text_encoding and std::locale::encoding() symbols are only in the libstdc++exp.a archive, we need to include src/c++26/text_encoding.cc in the main library, but not export its symbols yet. This means they can be used by the two new functions which are exported from the main library. The encoding conversions are done for C++20, treating it as a DR that resolves LWG 3656. With this change we can increase the value of the __cpp_lib_format macro for C++23. The value should be 202207 for P2419R2, but we already implement P2510R3 (Formatting pointers) so can use the value 202304. libstdc++-v3/ChangeLog: PR libstdc++/109162 * acinclude.m4 (libtool_VERSION): Update to 6:34:0. * config/abi/pre/gnu.ver: Disambiguate old patters. Add new GLIBCXX_3.4.34 symbol version and new exports. * configure: Regenerate. * include/bits/chrono_io.h (_ChronoSpec::_M_locale_specific): Add new accessor functions to use a reserved bit in _Spec. (__formatter_chrono::_M_parse): Use _M_locale_specific(true) when chrono-specs contains locale-dependent conversion specifiers. (__formatter_chrono::_M_format): Open iconv descriptor if conversion to UTF-8 will be needed. (__formatter_chrono::_M_write): New function to write a localized string with possible character conversion. (__formatter_chrono::_M_a_A, __formatter_chrono::_M_b_B) (__formatter_chrono::_M_p, __formatter_chrono::_M_r) (__formatter_chrono::_M_x, __formatter_chrono::_M_X) (__formatter_chrono::_M_locale_fmt): Use _M_write. * include/bits/version.def (format): Update value. * include/bits/version.h: Regenerate. * include/std/format (_GLIBCXX_P2518R3): Check feature test macro instead of __cplusplus. (basic_format_context): Declare __formatter_chrono as friend. * src/c++20/Makefile.am: Add new file. * src/c++20/Makefile.in: Regenerate. * src/c++20/format.cc: New file. * testsuite/std/time/format_localized.cc: New test. * testsuite/util/testsuite_abi.cc: Add new symbol version.
2024-07-30libstdc++: Fix formatter for low-resolution chrono::zoned_time (LWG 4124)Jonathan Wakely1-3/+9
This implements the proposed resolution of LWG 4124, so that low-resolution chrono::zoned_time objects can be formatted. The formatter for zoned_time<D, P> needs to account for get_local_time returning local_time<common_type_t<D, seconds>> not local_time<D>. libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (__local_time_fmt_for): New alias template. (formatter<zoned_time<D, P>>): Use __local_time_fmt_for. * testsuite/std/time/zoned_time/io.cc: Check zoned_time<minutes> can be formatted.
2024-07-30libstdc++: Fix std::format output for std::chrono::zoned_timeJonathan Wakely1-11/+35
When formatting a chrono::zoned_time with an empty chrono-specs, we were only formatting its _M_time member, but the ostream insertion operator uses the format "{:L%F %T %Z}" which includes the time zone abbreviation. The %Z should also be used when formatting with an empty chrono-specs. This commit makes _M_format_to_ostream handle __local_time_fmt specializations directly, rather than calling itself recursively to format the _M_time member. We need to be able to customize the output of _M_format_to_ostream for __local_time_fmt, because we use that type for gps_time and tai_time as well as for zoned_time and __local_time_fmt. When formatting gps_time and tai_time we don't want to include the time zone abbreviation in the "{}" output, but for zoned_time we do want to. We can reuse the __is_neg flag passed to _M_format_to_ostream (via _M_format) to say that we want the time zone abbreviation. Currently the __is_neg flag is only used for duration specializations, so it's available for __local_time_fmt to use. In addition to fixing the zoned_time output to use %Z, this commit also changes the __local_time_fmt output to use %Z. Previously it didn't use it, just like zoned_time. The standard doesn't actually say how to format local-time-format-t for an empty chrono-specs, but this behaviour seems sensible and is what I'm proposing as part of LWG 4124. While testing this I noticed that some chrono types were not being tested with empty chrono-specs, so this adds more tests. I also noticed that std/time/clock/local/io.cc was testing tai_time instead of local_time, which was completely wrong. That's fixed now too. libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (__local_fmt_t): Remove unused declaration. (__formatter_chrono::_M_format_to_ostream): Add explicit handling for specializations of __local_time_fmt, including the time zone abbreviation in the output if __is_neg is true. (formatter<chrono::tai_time<D>>::format): Add comment. (formatter<chrono::gps_time<D>>::format): Likewise. (formatter<chrono::__detail::__local_time_fmt::format): Call _M_format with true for the __is_neg flag. * testsuite/std/time/clock/gps/io.cc: Remove unused variable. * testsuite/std/time/clock/local/io.cc: Fix test error that checked tai_time instead of local_time. Add tests for local-time-format-t formatting. * testsuite/std/time/clock/system/io.cc: Check empty chrono-specs. * testsuite/std/time/clock/tai/io.cc: Likewise. * testsuite/std/time/zoned_time/io.cc: Likewise.
2024-07-30libstdc++: Implement LWG 3886 for std::optional and std::expectedJonathan Wakely2-10/+10
This uses remove_cv_t<T> for the default template argument used for deducing a type for a braced-init-list used with std::optional and std::expected. libstdc++-v3/ChangeLog: * include/std/expected (expected(U&&), operator=(U&&)) (value_or): Use remove_cv_t on default template argument, as per LWG 3886. * include/std/optional (optional(U&&), operator=(U&&)) (value_or): Likewise. * testsuite/20_util/expected/lwg3886.cc: New test. * testsuite/20_util/optional/cons/lwg3886.cc: New test.
2024-07-27libstdc++: Fix -Wsign-compare warning in <charconv>Jonathan Wakely1-6/+6
Cast ptrdiff_t to size_t to avoid a -Wsign-compare warning. We can check in __to_chars_i that the ptrdiff_t won't be negative, so that we know the cast is safe. libstdc++-v3/ChangeLog: * include/std/charconv (__to_chars_16, __to_chars_10) (__to_chars_8, __to_chars_2, __to_chars): Cast ptrdiff_t to size_t for comparison. (__to_chars_i): Check for first >= last instead of first == last for initial sanity check.
2024-07-27libstdc++: Add comment noting LWG 3617 supportJonathan Wakely1-0/+2
The resolution was implemented in r14-8752-g6f75149488b74a but I didn't add the usual _GLIBCXX_RESOLVE_LIB_DEFECTS comment. libstdc++-v3/ChangeLog: * include/bits/std_function.h: Add comment about LWG 3617 being supported.
2024-07-27libstdc++: Remove __find_if unrolling for random access iteratorsJonathan Wakely2-68/+5
As the numbers in PR libstdc++/88545 show, the manual loop unrolling in std::__find_if doesn't actually help these days, and it prevents the compiler from auto-vectorizing. Remove the dispatching on iterator_category and just use the simple loop for all iterator categories. libstdc++-v3/ChangeLog: * include/bits/stl_algobase.h (__find_if): Remove overloads for dispatching on iterator_category. Do not unroll loop manually. * include/bits/stl_algo.h (__find_if_not): Remove iterator_category argument from __find_if call.
2024-07-25libstdc++: Add static_assert to std::expected for LWG 3843 and 3940Jonathan Wakely1-0/+8
libstdc++-v3/ChangeLog: * include/std/expected (expected::value): Add assertions for LWG 3843 requirements. (expected<cv void, E>::value): Add assertions for LWG 3940 requirements.
2024-07-25libstdc++: Remove std::basic_format_args default constructor (LWG 4106)Jonathan Wakely1-2/+0
There's no valid use case for default constructing this type, so the committee approved removing the default constructor. libstdc++-v3/ChangeLog: * include/std/format (basic_format_args): Remove default constructor, as per LWG 4106. * testsuite/std/format/arguments/args.cc: Check it isn't default constructible.
2024-07-25libstdc++: Implement P2968R2 "Making std::ignore a first-class object"Jonathan Wakely2-31/+29
This was recently approved for C++26, but we can apply the changes for all modes back to C++11. There's no reason not to make the assignment usable in constant expressions for C++11 mode, and noexcept for all modes. Move the definitions to <bits/utility.h> so they're available in <utility> as well as <tuple>. libstdc++-v3/ChangeLog: * include/bits/utility.h (_Swallow_assign): Make assignment constexpr for C++11 as well, and add noexcept. * include/std/tuple (_Swallow_assign, ignore): Move to bits/utility.h. * testsuite/20_util/headers/utility/ignore.cc: New test.
2024-07-25libstdc++: Reorder template params of std::optional comparisons (LWG 2945)Jonathan Wakely1-18/+18
libstdc++-v3/ChangeLog: * include/std/optional: Reorder parameters in comparison operators as per LWG 2945.