Skip to content
Snippets Groups Projects
  1. Feb 02, 2024
    • Jonathan Wakely's avatar
      libstdc++: Make std::function deduction guide support explicit object functions [PR113335] · 6f751494
      Jonathan Wakely authored
      This makes the deduction guides for std::function and std::packaged_task
      work for explicit object member functions, i.e. "deducing this", as per
      LWG 3617.
      
      libstdc++-v3/ChangeLog:
      
      	PR libstdc++/113335
      	* include/bits/std_function.h (__function_guide_helper): Add
      	partial specialization for explicit object member functions, as
      	per LWG 3617.
      	* testsuite/20_util/function/cons/deduction_c++23.cc: Check
      	explicit object member functions.
      	* testsuite/30_threads/packaged_task/cons/deduction_c++23.cc:
      	Likewise.
      6f751494
    • Jonathan Wakely's avatar
      libstdc++: Fix experimental/names.cc failure on AIX · f9292935
      Jonathan Wakely authored
      This fails due to "u" being used in a system header.
      
      FAIL: experimental/names.cc  -std=gnu++17 (test for excess errors)
      Excess errors:
      /usr/include/sys/poll.h:77: error: expected unqualified-id before ';' token
      /usr/include/sys/poll.h:77: error: expected ')' before ';' token
      
      FAIL: experimental/names.cc  -std=gnu++17 (test for excess errors)
      Excess errors:
      /usr/include/sys/poll.h:102: error: expected unqualified-id before ';' token
      /usr/include/sys/poll.h:102: error: expected ')' before ';' token
      
      libstdc++-v3/ChangeLog:
      
      	* testsuite/17_intro/names.cc [_AIX]: Undefine "u".
      f9292935
    • Jonathan Wakely's avatar
      libstdc++: Implement some missing functions for net::ip::network_v6 · 5b069117
      Jonathan Wakely authored
      libstdc++-v3/ChangeLog:
      
      	* include/experimental/internet (network_v6::network): Define.
      	(network_v6::hosts): Finish implementing.
      	(network_v6::to_string): Do not concatenate std::string to
      	arbitrary std::basic_string specialization.
      	* testsuite/experimental/net/internet/network/v6/cons.cc: New
      	test.
      5b069117
    • Jonathan Wakely's avatar
      libstdc++: Fix invalid order in PSTL inplace_merge test [PR90276] · a6286584
      Jonathan Wakely authored
      This looks like a typo in the upstream test that causes a failure in
      debug mode. It has been reported upstream.
      
      libstdc++-v3/ChangeLog:
      
      	PR libstdc++/90276
      	* testsuite/25_algorithms/pstl/alg_merge/inplace_merge.cc: Fix
      	comparison function to use less-than instead of equality.
      a6286584
    • Jonathan Wakely's avatar
      libstdc++: Avoid reusing moved-from iterators in PSTL tests [PR90276] · 723a7c1a
      Jonathan Wakely authored
      The reverse_invoker utility for PSTL tests uses forwarding references for
      all parameters, but some of those parameters get forwarded to move
      constructors which then leave the objects in a moved-from state. When
      the parameters are forwarded a second time that results in making new
      copies of moved-from iterators.  For libstdc++ debug mode iterators, the
      moved-from state is singular, which means copying them will abort at
      runtime.
      
      The fix is to make copies of iterator arguments instead of forwarding
      them.
      
      The callers of reverse_invoker::operator() also forward the iterators
      multiple times, but that's OK because reverse_invoker accepts them by
      forwarding reference but then breaks the chain of forwarding and copies
      them as lvalues.
      
      libstdc++-v3/ChangeLog:
      
      	PR libstdc++/90276
      	* testsuite/util/pstl/test_utils.h (reverse_invoker): Do not use
      	perfect forwarding for iterator arguments.
      723a7c1a
    • Jonathan Wakely's avatar
      libstdc++: Allow explicit conversion of string views with different traits · f60d7e1c
      Jonathan Wakely authored
      This was changed by LWG 3857.
      
      libstdc++-v3/ChangeLog:
      
      	* include/std/string_view (basic_string_view(R&&)): Remove
      	constraint that traits_type must be the same, as per LWG 3857.
      	* testsuite/21_strings/basic_string_view/cons/char/range_c++20.cc:
      	Explicit conversion between different specializations should be
      	allowed.
      	* testsuite/21_strings/basic_string_view/cons/wchar_t/range_c++20.cc:
      	Likewise.
      f60d7e1c
  2. Feb 01, 2024
    • Patrick Palka's avatar
      libstdc++: Implement P2165R4 changes to std::pair/tuple/etc [PR113309] · 65b4cba9
      Patrick Palka authored
      
      This implements the C++23 paper P2165R4 Compatibility between tuple,
      pair and tuple-like objects, which builds upon many changes from the
      earlier C++23 paper P2321R2 zip.
      
      Some declarations had to be moved around so that they're visible from
      <bits/stl_pair.h> without introducing new includes and bloating the
      header.  In the end, the only new include is for <bits/utility.h> from
      <bits/stl_iterator.h>, for tuple_element_t.
      
      	PR libstdc++/113309
      	PR libstdc++/109203
      
      libstdc++-v3/ChangeLog:
      
      	* include/bits/ranges_util.h (__detail::__pair_like): Don't
      	define in C++23 mode.
      	(__detail::__pair_like_convertible_from): Adjust as per P2165R4.
      	(__detail::__is_subrange<subrange>): Moved from <ranges>.
      	(__detail::__is_tuple_like_v<subrange>): Likewise.
      	* include/bits/stl_iterator.h: Include <bits/utility.h> for
      	C++23.
      	(__different_from): Move to <concepts>.
      	(__iter_key_t): Adjust for C++23 as per P2165R4.
      	(__iter_val_t): Likewise.
      	* include/bits/stl_pair.h (pair, array): Forward declare.
      	(get): Forward declare all overloads relevant to P2165R4
      	tuple-like constructors.
      	(__is_tuple_v): Define for C++23.
      	(__is_tuple_like_v): Define for C++23.
      	(__tuple_like): Define for C++23 as per P2165R4.
      	(__pair_like): Define for C++23 as per P2165R4.
      	(__eligibile_tuple_like): Define for C++23.
      	(__eligibile_pair_like): Define for C++23.
      	(pair::_S_constructible_from_pair_like): Define for C++23.
      	(pair::_S_convertible_from_pair_like): Define for C++23.
      	(pair::_S_dangles_from_pair_like): Define for C++23.
      	(pair::pair): Define overloads taking a tuple-like type for
      	C++23 as per P2165R4.
      	(pair::_S_assignable_from_tuple_like): Define for C++23.
      	(pair::_S_const_assignable_from_tuple_like): Define for C++23.
      	(pair::operator=): Define overloads taking a tuple-like type for
      	C++23 as per P2165R4.
      	* include/bits/utility.h (ranges::__detail::__is_subrange):
      	Moved from <ranges>.
      	* include/bits/version.def (tuple_like): Define for C++23.
      	* include/bits/version.h: Regenerate.
      	* include/std/concepts (__different_from): Moved from
      	<bits/stl_iterator.h>.
      	(ranges::__swap::__adl_swap): Clarify which __detail namespace.
      	* include/std/map (__cpp_lib_tuple_like): Define C++23.
      	* include/std/ranges (__detail::__is_subrange): Moved to
      	<bits/utility.h>.
      	(__detail::__is_subrange<subrange>): Moved to <bits/ranges_util.h>
      	(__detail::__has_tuple_element): Adjust for C++23 as per P2165R4.
      	(__detail::__tuple_or_pair): Remove as per P2165R4.  Replace all
      	uses with plain tuple as per P2165R4.
      	* include/std/tuple (__cpp_lib_tuple_like): Define for C++23.
      	(__tuple_like_tag_t): Define for C++23.
      	(__tuple_cmp): Forward declare for C++23.
      	(_Tuple_impl::_Tuple_impl): Define overloads taking
      	__tuple_like_tag_t and a tuple-like type for C++23.
      	(_Tuple_impl::_M_assign): Likewise.
      	(tuple::__constructible_from_tuple_like): Define for C++23.
      	(tuple::__convertible_from_tuple_like): Define for C++23.
      	(tuple::__dangles_from_tuple_like): Define for C++23.
      	(tuple::tuple): Define overloads taking a tuple-like type for
      	C++23 as per P2165R4.
      	(tuple::__assignable_from_tuple_like): Define for C++23.
      	(tuple::__const_assignable_from_tuple_like): Define for C++23.
      	(tuple::operator=): Define overloads taking a tuple-like type
      	for C++23 as per P2165R4.
      	(tuple::__tuple_like_common_comparison_category): Define for C++23.
      	(tuple::operator<=>): Define overload taking a tuple-like type
      	for C++23 as per P2165R4.
      	(array, get): Forward declarations moved to <bits/stl_pair.h>.
      	(tuple_cat): Constrain with __tuple_like for C++23 as per P2165R4.
      	(apply): Likewise.
      	(make_from_tuple): Likewise.
      	(__tuple_like_common_reference): Define for C++23.
      	(basic_common_reference): Adjust as per P2165R4.
      	(__tuple_like_common_type): Define for C++23.
      	(common_type): Adjust as per P2165R4.
      	* include/std/unordered_map (__cpp_lib_tuple_like): Define for
      	C++23.
      	* include/std/utility (__cpp_lib_tuple_like): Define for C++23.
      	* testsuite/std/ranges/zip/1.cc (test01): Adjust to handle pair
      	and 2-tuple interchangeably.
      	(test05): New test.
      	* testsuite/20_util/pair/p2165r4.cc: New test.
      	* testsuite/20_util/tuple/p2165r4.cc: New test.
      
      Reviewed-by: default avatarJonathan Wakely <jwakely@redhat.com>
      65b4cba9
    • Jonathan Wakely's avatar
      libstdc++: Update expected error for debug/constexpr*_neg.cc tests · 52e9b708
      Jonathan Wakely authored
      We no longer hit a __builtin_unreachable() in these tests, so we need to
      update the dg-error patterns to match _Error_formatter::_M_error().
      
      We can also remove some dg-prune-output directives matching notes saying
      "in 'constexpr' expansion" because that's done globally in prune.exp.
      
      libstdc++-v3/ChangeLog:
      
      	* testsuite/25_algorithms/copy/debug/constexpr_neg.cc: Adjust
      	dg-error pattern.
      	* testsuite/25_algorithms/copy_backward/debug/constexpr_neg.cc:
      	Likewise.
      	* testsuite/25_algorithms/equal/debug/constexpr_neg.cc:
      	Likewise.
      	* testsuite/25_algorithms/lower_bound/debug/constexpr_partitioned_neg.cc:
      	Likewise.
      	* testsuite/25_algorithms/lower_bound/debug/constexpr_partitioned_pred_neg.cc:
      	Likewise.
      	* testsuite/25_algorithms/lower_bound/debug/constexpr_valid_range_neg.cc:
      	Likewise.
      	* testsuite/25_algorithms/upper_bound/debug/constexpr_partitioned_neg.cc:
      	Likewise.
      	* testsuite/25_algorithms/upper_bound/debug/constexpr_partitioned_pred_neg.cc:
      	Likewise.
      	* testsuite/25_algorithms/upper_bound/debug/constexpr_valid_range_neg.cc:
      	Likewise.
      52e9b708
  3. Jan 31, 2024
  4. Jan 30, 2024
  5. Jan 22, 2024
  6. Jan 21, 2024
    • Jonathan Wakely's avatar
      libstdc++: Fix std::format for floating-point chrono::time_point [PR113500] · 7431fcea
      Jonathan Wakely authored
      Currently trying to use std::format with certain specializations of
      std::chrono::time_point is ill-formed, due to one member function of the
      __formatter_chrono type which tries to write a time_point to an ostream.
      For sys_time<floating-point> or sys_time with a period greater than days
      there is no operator<< that can be used.
      
      That operator<< is only needed when using an empty chrono-specs in the
      format string, like "{}", but the ill-formed expression gives an error
      even if not actually used. This means it's not possible to format some
      other specializations of chrono::time_point, even when using a non-empty
      chrono-specs.
      
      This fixes it by avoiding using 'os << t' for all chrono::time_point
      specializations, and instead using std::format("{:L%F %T}", t). So that
      we continue to reject std::format("{}", sys_time{1.0s}) a check for
      empty chrono-specs is added to the formatter<sys_time<D>, C>
      specialization.
      
      While testing this I noticed that the output for %S with a
      floating-point duration was incorrect, as the subseconds part was being
      appended to the seconds without a decimal point, and without the correct
      number of leading zeros.
      
      libstdc++-v3/ChangeLog:
      
      	PR libstdc++/113500
      	* include/bits/chrono_io.h (__formatter_chrono::_M_S): Fix
      	printing of subseconds with floating-point rep.
      	(__formatter_chrono::_M_format_to_ostream): Do not write
      	time_point specializations directly to the ostream.
      	(formatter<chrono::sys_time<D>, C>::parse): Do not allow an
      	empty chrono-spec if the type fails to meet the constraints for
      	writing to an ostream with operator<<.
      	* testsuite/std/time/clock/file/io.cc: Check formatting
      	non-integral times with empty chrono-specs.
      	* testsuite/std/time/clock/gps/io.cc: Likewise.
      	* testsuite/std/time/clock/utc/io.cc: Likewise.
      	* testsuite/std/time/hh_mm_ss/io.cc: Likewise.
      7431fcea
    • Jonathan Wakely's avatar
      libstdc++: Fix std::chrono::file_clock conversions for low-precision times · fba15da8
      Jonathan Wakely authored
      THe std::chrono::file_clock conversions were not using common_type and
      so failed to compile when converting anything that should have increased
      precision after arithmetic with a std::chrono::seconds value.
      
      libstdc++-v3/ChangeLog:
      
      	* include/bits/chrono.h (__file_clock::from_sys)
      	(__file_clock::to_sys, __file_clock::_S_from_sys)
      	(__file_clock::_S_to_sys): Use common_type for return type.
      	* testsuite/std/time/clock/file/members.cc: Check round trip
      	conversion for time with lower precision that seconds.
      fba15da8
    • Jonathan Wakely's avatar
      libstdc++: Fix std::format floating-point alternate forms [PR113512] · a57439d6
      Jonathan Wakely authored
      The logic for handling '#' forms was ... not good. The count of
      significant figures just counted digits, instead of ignoring leading
      zeros. And when moving the result from the stack buffer to a dynamic
      string the exponent could get lost in some cases.
      
      libstdc++-v3/ChangeLog:
      
      	PR libstdc++/113512
      	* include/std/format (__formatter_fp::format): Fix logic for
      	alternate forms.
      	* testsuite/std/format/functions/format.cc: Check buggy cases of
      	alternate forms with g presentation type.
      a57439d6
  7. Jan 19, 2024
    • Jonathan Wakely's avatar
      libstdc++: Fix P2255R2 dangling checks for std::tuple in C++17 [PR108822] · 502a3c03
      Jonathan Wakely authored
      I accidentally used && in a fold-expression instead of || which meant
      that in C++17 the tuple(UElements&&...) constructor only failed its
      debug assertion if all tuple elements were dangling references. Some
      missing tests (noted as "TODO") meant this wasn't tested.
      
      This fixes the fold expression and adds the missing tests.
      
      libstdc++-v3/ChangeLog:
      
      	PR libstdc++/108822
      	* include/std/tuple (__glibcxx_no_dangling_refs) [C++17]: Fix
      	wrong fold-operator.
      	* testsuite/20_util/tuple/dangling_ref.cc: Check tuples with one
      	element and three elements. Check allocator-extended
      	constructors.
      502a3c03
  8. Jan 18, 2024
    • Patrick Palka's avatar
      libstdc++/debug: Fix constexpr _Safe_iterator in C++20 mode [PR109536] · 3d3145e9
      Patrick Palka authored
      
      Some _Safe_iterator member functions define a variable of non-literal
      type __gnu_cxx::__scoped_lock, which automatically disqualifies them from
      being constexpr in C++20 mode even if that code path is never constant
      evaluated.  This restriction was lifted by P2242R3 for C++23, but we
      need to work around it in C++20 mode.  To that end this patch defines
      a pair of macros that encapsulate the lambda-based workaround mentioned
      in that paper and uses it to make these functions valid C++20 constexpr
      functions.  The augmented std::vector test element_access/constexpr.cc
      now successfully compiles in C++20 mode with -D_GLIBCXX_DEBUG (and it
      should test all member functions modified by this patch).
      
      	PR libstdc++/109536
      
      libstdc++-v3/ChangeLog:
      
      	* include/debug/safe_base.h (_Safe_sequence_base::_M_swap):
      	Remove _GLIBCXX20_CONSTEXPR from non-inline member function.
      	* include/debug/safe_iterator.h
      	(_GLIBCXX20_CONSTEXPR_NON_LITERAL_SCOPE_BEGIN): Define.
      	(_GLIBCXX20_CONSTEXPR_NON_LITERAL_SCOPE_END): Define.
      	(_Safe_iterator::operator=): Use them around the code path that
      	defines a variable of type __gnu_cxx::__scoped_lock.
      	(_Safe_iterator::operator++): Likewise.
      	(_Safe_iterator::operator--): Likewise.
      	(_Safe_iterator::operator+=): Likewise.
      	(_Safe_iterator::operator-=): Likewise.
      	* testsuite/23_containers/vector/element_access/constexpr.cc
      	(test_iterators): Test more iterator operations.
      	* testsuite/23_containers/vector/bool/element_access/constexpr.cc
      	(test_iterators): Likewise.
      	* testsuite/std/ranges/adaptors/all.cc (test08) [_GLIBCXX_DEBUG]:
      	Remove.
      
      Reviewed-by: default avatarJonathan Wakely <jwakely@redhat.com>
      3d3145e9
    • Jonathan Wakely's avatar
      libstdc++: Fix std::format test for Solaris [PR113450] · db42a0a9
      Jonathan Wakely authored
      When int8_t is a typedef for char (rather than signed char) this test
      fails because it tries to format a char, which is treated differently
      from formatting other integral types (including signed char).
      
      Use signed char explicitly so the result doesn't depend on the
      non-portable definition of int8_t.
      
      libstdc++-v3/ChangeLog:
      
      	PR libstdc++/113450
      	* testsuite/std/format/functions/format.cc: Use signed char
      	instead of int8_t.
      db42a0a9
  9. Jan 17, 2024
    • Jonathan Wakely's avatar
      libstdc++: Implement C++26 std::text_encoding (P1885R12) [PR113318] · df0a668b
      Jonathan Wakely authored
      
      This is another C++26 change, approved in Varna 2023. We require a new
      static array of data that is extracted from the IANA Character Sets
      database. A new Python script to generate a header from the IANA CSV
      file is added.
      
      The text_encoding class is basically just a pointer to an {ID,name} pair
      in the static array. The aliases view is also just the same pointer (or
      empty), and the view's iterator moves forwards and backwards in the
      array while the array elements have the same ID (or to one element
      further, for a past-the-end iterator).
      
      Because those iterators refer to a global array that never goes out of
      scope, there's no reason they should every produce undefined behaviour
      or indeterminate values.  They should either have well-defined
      behaviour, or abort. The overhead of ensuring those properties is pretty
      low, so seems worth it.
      
      This means that an aliases_view iterator should never be able to access
      out-of-bounds. A non-value-initialized iterator always points to an
      element of the static array even when not dereferenceable (the array has
      unreachable entries at the start and end, which means that even a
      past-the-end iterator for the last encoding in the array still points to
      valid memory).  Dereferencing an iterator can always return a valid
      array element, or "" for a non-dereferenceable iterator (but doing so
      will abort when assertions are enabled).  In the language being proposed
      for C++26, dereferencing an invalid iterator erroneously returns "".
      Attempting to increment/decrement past the last/first element in the
      view is erroneously a no-op, so aborts when assertions are enabled, and
      doesn't change value otherwise.
      
      Similarly, constructing a std::text_encoding with an invalid id (one
      that doesn't have the value of an enumerator) erroneously behaves the
      same as constructing with id::unknown, or aborts with assertions
      enabled.
      
      libstdc++-v3/ChangeLog:
      
      	PR libstdc++/113318
      	* acinclude.m4 (GLIBCXX_CONFIGURE): Add c++26 directory.
      	(GLIBCXX_CHECK_TEXT_ENCODING): Define.
      	* config.h.in: Regenerate.
      	* configure: Regenerate.
      	* configure.ac: Use GLIBCXX_CHECK_TEXT_ENCODING.
      	* include/Makefile.am: Add new headers.
      	* include/Makefile.in: Regenerate.
      	* include/bits/locale_classes.h (locale::encoding): Declare new
      	member function.
      	* include/bits/unicode.h (__charset_alias_match): New function.
      	* include/bits/text_encoding-data.h: New file.
      	* include/bits/version.def (text_encoding): Define.
      	* include/bits/version.h: Regenerate.
      	* include/std/text_encoding: New file.
      	* src/Makefile.am: Add new subdirectory.
      	* src/Makefile.in: Regenerate.
      	* src/c++26/Makefile.am: New file.
      	* src/c++26/Makefile.in: New file.
      	* src/c++26/text_encoding.cc: New file.
      	* src/experimental/Makefile.am: Include c++26 convenience
      	library.
      	* src/experimental/Makefile.in: Regenerate.
      	* python/libstdcxx/v6/printers.py (StdTextEncodingPrinter): New
      	printer.
      	* scripts/gen_text_encoding_data.py: New file.
      	* testsuite/22_locale/locale/encoding.cc: New test.
      	* testsuite/ext/unicode/charset_alias_match.cc: New test.
      	* testsuite/std/text_encoding/cons.cc: New test.
      	* testsuite/std/text_encoding/members.cc: New test.
      	* testsuite/std/text_encoding/requirements.cc: New test.
      
      Reviewed-by: default avatarUlrich Drepper <drepper.fsp@gmail.com>
      Reviewed-by: default avatarPatrick Palka <ppalka@redhat.com>
      df0a668b
    • Patrick Palka's avatar
      libstdc++: Implement P2540R1 change to views::cartesian_product() · 98966f32
      Patrick Palka authored
      
      This paper changes the identity element of views::cartesian_product to a
      singleton range instead of an empty range.  It was approved alongside
      the main cartesian_product paper P2374R4, but unfortunately was overlooked
      when implementing the main paper.
      
      libstdc++-v3/ChangeLog:
      
      	* include/std/ranges (views::_CartesianProduct::operator()):
      	Adjust identity case as per P2540R1.
      	* testsuite/std/ranges/cartesian_product/1.cc (test01):
      	Adjust expected result of the identity case.
      
      Reviewed-by: default avatarJonathan Wakely <jwakely@redhat.com>
      98966f32
  10. Jan 15, 2024
    • Patrick Palka's avatar
      libstdc++: Implement P2836R1 changes to const_iterator · 731444b3
      Patrick Palka authored
      
      libstdc++-v3/ChangeLog:
      
      	* include/bits/stl_iterator.h (const_iterator): Define conversion
      	operators as per P2836R1.
      	* include/bits/version.def (ranges_as_const): Update value.
      	* include/bits/version.h: Regenerate.
      	* testsuite/24_iterators/const_iterator/1.cc (test04): New test.
      	* testsuite/std/ranges/adaptors/as_const/1.cc: Adjust expected
      	value of __cpp_lib_ranges_as_const.
      	* testsuite/std/ranges/version_c++23.cc: Likewise.
      
      Reviewed-by: default avatarJonathan Wakely <jwakely@redhat.com>
      731444b3
  11. Jan 13, 2024
    • Jonathan Wakely's avatar
      libstdc++: Implement P2255R2 dangling checks for std::tuple [PR108822] · f8a5298c
      Jonathan Wakely authored
      
      This is the last part of PR libstdc++/108822 implementing P2255R2, which
      makes it ill-formed to create a std::tuple that would bind a reference
      to a temporary.
      
      The dangling checks are implemented as deleted constructors for C++20
      and higher, and as Debug Mode static assertions in the constructor body
      for older standards. This is similar to the r13-6084-g916ce577ad109b
      changes for std::pair.
      
      As part of this change, I've reimplemented most of std::tuple for C++20,
      making use of concepts to replace the enable_if constraints, and using
      conditional explicit to avoid duplicating most constructors. We could
      use conditional explicit for the C++11 implementation too (with pragmas
      to disables the -Wc++17-extensions warnings), but that should be done as
      a stage 1 change for GCC 15 rather than now.
      
      The partial specialization for std::tuple<T1, T2> is no longer used for
      C++20 (or more precisely, for a C++20 compiler that supports concepts
      and conditional explicit). The additional constructors and assignment
      operators that take std::pair arguments have been added to the C++20
      implementation of the primary template, with sizeof...(_Elements)==2
      constraints. This avoids reimplementing all the other constructors in
      the std::tuple<T1, T2> partial specialization to use concepts. This way
      we avoid four implementations of every constructor and only have three!
      (The primary template has an implementation of each constructor for
      C++11 and another for C++20, and the tuple<T1,T2> specialization has an
      implementation of each for C++11, so that's three for each constructor.)
      
      In order to make the constraints more efficient on the C++20 version of
      the default constructor I've also added a variable template for the
      __is_implicitly_default_constructible trait, implemented using concepts.
      
      libstdc++-v3/ChangeLog:
      
      	PR libstdc++/108822
      	* include/std/tuple (tuple): Add checks for dangling references.
      	Reimplement constraints and constant expressions using C++20
      	features.
      	* include/std/type_traits [C++20]
      	(__is_implicitly_default_constructible_v): Define.
      	(__is_implicitly_default_constructible): Use variable template.
      	* testsuite/20_util/tuple/dangling_ref.cc: New test.
      
      Reviewed-by: default avatarPatrick Palka <ppalka@redhat.com>
      f8a5298c
    • Patrick Palka's avatar
      libstdc++: Implement C++23 std::bind_back from P2387R3 [PR108827] · ac1a399b
      Patrick Palka authored
      The implementation is based off of std::bind_front.  Since this is a
      C++23 feature we use deducing this unconditionally.
      
      	PR libstdc++/108827
      	PR libstdc++/111327
      
      libstdc++-v3/ChangeLog:
      
      	* include/bits/version.def (bind_back): Define.
      	* include/bits/version.h: Regenerate.
      	* include/std/functional (_Bind_back): Define for C++23.
      	(bind_back): Likewise.
      	* testsuite/20_util/function_objects/bind_back/1.cc: New test
      	(adapted from corresponding bind_front test).
      	* testsuite/20_util/function_objects/bind_back/111327.cc: Likewise.
      ac1a399b
    • Patrick Palka's avatar
      libstdc++: Use C++23 deducing this in std::bind_front · 3e1ffa7d
      Patrick Palka authored
      This simplifies the operator() of _Bind_front using C++23 deducing
      this, allowing us to condense multiple operator() overloads into one.
      
      In passing I think we can remove _Bind_front's defaulted special member
      declarations and just let the compiler implicitly generate them for us.
      
      libstdc++-v3/ChangeLog:
      
      	* include/std/functional (_Bind_front): Remove =default special
      	member function declarations.
      	(_Bind_front::operator()): Implement using C++23 deducing this
      	when available.
      	* testsuite/20_util/function_objects/bind_front/111327.cc:
      	Adjust testcase to expect better errors in C++23 mode.
      3e1ffa7d
    • Jonathan Wakely's avatar
      libstdc++: Fix non-portable results from 64-bit std::subtract_with_carry_engine [PR107466] · c224dec0
      Jonathan Wakely authored
      I implemented the resolution of LWG 3809 in r13-4364-ga64775a0edd469 but
      it was recently noted in the MSVC STL github repo that the change causes
      possible truncation for 64-bit seeds. Whether the truncation occurs (and
      to what value) depends on the width of uint_least32_t which is not
      portable, so the output of the PRNG for 64-bit seed values is no longer
      the same as in C++20, and no longer portable across platforms.
      
      That new issue was filed as LWG 4014. I proposed a new change which
      reduces the seed by the LCG's modulus before the conversion to
      uint_least32_t. This ensures that 64-bit seed values are consistently
      reduced by the modulus before any truncation. This removes the
      platform-dependent behaviour and restores the old behaviour for
      std::subtract_with_carry_engine specializations using a 64-bit result
      type (such as std::ranlux48_base).
      
      libstdc++-v3/ChangeLog:
      
      	PR libstdc++/107466
      	* include/bits/random.tcc (subtract_with_carry_engine::seed):
      	Implement proposed resolution of LWG 4014.
      	* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error
      	line number.
      	* testsuite/26_numerics/random/subtract_with_carry_engine/cons/lwg3809.cc:
      	Check for expected result of 64-bit engine with seed that
      	doesn't fit in 32-bits.
      c224dec0
  12. Jan 12, 2024
    • Jonathan Wakely's avatar
      libstdc++: Fix std::runtime_format deviations from the spec [PR113320] · 5fbc1b2e
      Jonathan Wakely authored
      
      I seem to have implemented this feature based on the P2918R0 revision,
      not the final P2918R2 one that was approved for C++26. This commit fixes
      it.
      
      The runtime-format-string type should not have a publicly accessible
      data member, so add a constructor and make it a friend of
      basic_format_string. It should also be non-copyable, so that it can only
      be constructed from a prvalue via temporary materialization. Change the
      basic_format_string constructor parameter to pass by value. Also add
      noexcept to the constructors and runtime_format generator functions.
      
      libstdc++-v3/ChangeLog:
      
      	PR libstdc++/113320
      	* include/std/format (__format::_Runtime_format_string): Add
      	constructor and disable copy operations.
      	(basic_format_string(_Runtime_format_string)): Add noexcept and
      	take parameter by value not rvalue reference.
      	(runtime_format): Add noexcept.
      	* testsuite/std/format/runtime_format.cc: Check noexcept. Check
      	that construction is only possible from prvalues, not xvalues.
      
      Reviewed-by: default avatarDaniel Krügler <daniel.kruegler@gmail.com>
      5fbc1b2e
    • Jonathan Wakely's avatar
      libstdc++: Implement C++23 P1951R1 (Default Args for pair's Forwarding Ctor) [PR105505] · 35f8c661
      Jonathan Wakely authored
      This was approved for C++23 at he June 2021 virtual meeting.
      
      This allows more efficient construction of std::pair members when {} is
      used as a constructor argument. The perfect forwarding constructor can
      be used, so that the member variables are constructed from forwarded
      arguments instead of being copy constructed from temporaries.
      
      libstdc++-v3/ChangeLog:
      
      	PR libstdc++/105505
      	* include/bits/stl_pair.h (pair::pair(U1&&, U2&&)) [C++23]: Add
      	default template arguments, as per P1951R1.
      	* testsuite/20_util/pair/cons/default_tmpl_args.cc: New test.
      35f8c661
  13. Jan 11, 2024
    • François Dumont's avatar
      libstdc++: [_GLIBCXX_DEBUG] Fix assignment of value-initialized iterator [PR112477] · 46afbeb8
      François Dumont authored
      
      Now that _M_Detach do not reset iterator _M_version value we need to reset it when
      the iterator is attached to a new sequence, even if this sequencer is null when
      assigning a value-initialized iterator. In this case _M_version shall be resetted to 0.
      
      libstdc++-v3/ChangeLog:
      
      	PR libstdc++/112477
      	* src/c++11/debug.cc
      	(_Safe_iterator_base::_M_attach): Reset _M_version to 0 if attaching to null
      	sequence.
      	(_Safe_iterator_base::_M_attach_single): Likewise.
      	(_Safe_local_iterator_base::_M_attach): Likewise.
      	(_Safe_local_iterator_base::_M_attach_single): Likewise.
      	* testsuite/23_containers/map/debug/112477.cc: New test case.
      
      Reviewed-by: default avatarJonathan Wakely <jwakely@redhat.com>
      46afbeb8
    • Patrick Palka's avatar
      libstdc++/ranges: Use C++23 deducing this in _Pipe and _Partial · d2cb4693
      Patrick Palka authored
      This simplifies the operator() of the _Pipe and _Partial range adaptor
      closure objects using C++23 deducing this, allowing us to condense
      multiple operator() overloads into one.
      
      The new __like_t alias template is similar to the expositional one from
      P0847R6 except it's implemented in terms of forward_like instead of vice
      versa, and thus ours always yields a reference so e.g. __like_t<A, char>
      is char&& instead of char.  For our purposes (forwarding) this shouldn't
      make a difference, I think..
      
      libstdc++-v3/ChangeLog:
      
      	* include/bits/move.h (__like_t): Define in C++23 mode.
      	* include/std/ranges (views::__adaptor::Partial::operator()):
      	Implement using C++23 deducing this when available.
      	(views::__adaptor::_Pipe::operator()): Likewise.
      	* testsuite/std/ranges/adaptors/100577.cc: Adjust testcase to
      	accept new "no match for call" errors issued in C++23 mode.
      	* testsuite/std/ranges/adaptors/lazy_split_neg.cc: Likewise.
      d2cb4693
    • Jonathan Wakely's avatar
      libstdc++: Add GDB printer for std::integral_constant · cd2022f3
      Jonathan Wakely authored
      libstdc++-v3/ChangeLog:
      
      	* python/libstdcxx/v6/printers.py (StdIntegralConstantPrinter):
      	Add printer for std::integral_constant.
      	* testsuite/libstdc++-prettyprinters/cxx11.cc: Test it.
      cd2022f3
    • Ken Matsui's avatar
      libstdc++: Fix error handling in filesystem::equivalent [PR113250] · df147e2e
      Ken Matsui authored
      
      This patch made std::filesystem::equivalent correctly throw an exception
      when either path does not exist as per [fs.op.equivalent]/4.
      
      	PR libstdc++/113250
      
      libstdc++-v3/ChangeLog:
      
      	* src/c++17/fs_ops.cc (fs::equivalent): Use || instead of &&.
      	* src/filesystem/ops.cc (fs::equivalent): Likewise.
      	* testsuite/27_io/filesystem/operations/equivalent.cc: Handle
      	error codes.
      	* testsuite/experimental/filesystem/operations/equivalent.cc:
      	Likewise.
      
      Signed-off-by: default avatarKen Matsui <kmatsui@gcc.gnu.org>
      Reviewed-by: default avatarJonathan Wakely <jwakely@redhat.com>
      df147e2e
  14. Jan 09, 2024
    • Jonathan Wakely's avatar
      libstdc++: Fix Unicode property detection functions · ea314ccd
      Jonathan Wakely authored
      Fix some copy & pasted logic in __is_extended_pictographic. This
      function should yield false for the values before the first edge, not
      true. Also add a missing boundary condition check in __incb_property.
      
      Also Fix an off-by-one error in _Utf_iterator::operator++() that would
      make dereferencing a past-the-end iterator undefined (where the intended
      design is that the iterator is always incrementable and dereferenceable,
      for better memory safety).
      
      Also simplify the grapheme view iterator, which still contained some
      remnants of an earlier design I was experimenting with.
      
      Slightly tweak the gen_libstdcxx_unicode_data.py script so that the
      _Gcb_property enumerators are in the order we encounter them in the data
      file, instead of sorting them alphabetically. Start with the "Other"
      property at value 0, because that's the default property for anything
      not in the file. This makes no practical difference, but seems cleaner.
      It causes the values in the __gcb_edges table to change, so can only be
      done now before anybody is using this code yet. The enumerator values
      and table entries become ABI artefacts for the function using them.
      
      contrib/ChangeLog:
      
      	* unicode/gen_libstdcxx_unicode_data.py: Print out Gcb_property
      	enumerators in the order they're seen, not alphabetical order.
      
      libstdc++-v3/ChangeLog:
      
      	* include/bits/unicode-data.h: Regenerate.
      	* include/bits/unicode.h (_Utf_iterator::operator++()): Fix off
      	by one error.
      	(__incb_property): Add missing check for values before the
      	first edge.
      	(__is_extended_pictographic): Invert return values to fix
      	copy&pasted logic.
      	(_Grapheme_cluster_view::_Iterator): Remove second iterator
      	member and find end of cluster lazily.
      	* testsuite/ext/unicode/grapheme_view.cc: New test.
      	* testsuite/ext/unicode/properties.cc: New test.
      	* testsuite/ext/unicode/view.cc: New test.
      ea314ccd
  15. Jan 08, 2024
    • Jonathan Wakely's avatar
      libstdc++: Remove std::__unicode::__null_sentinel · eb846114
      Jonathan Wakely authored
      The name __null_sentinel is defined as a macro by newlib, so we can't
      use it as an identifier. That variable is not actually used by
      libstdc++, it was added because P2728R6 proposes std::uc::null_sentinel.
      Since we don't need it and it breaks bootstrap for newlib targets, just
      remove it. A null sentinel can still be used by constructing a
      _Null_sentinel_t object as needed, rather than having a named object of
      that type predefined.
      
      libstdc++-v3/ChangeLog:
      
      	* include/bits/unicode.h (__null_sentinel): Remove.
      	* testsuite/17_intro/names.cc: Add __null_sentinel.
      eb846114
    • Jonathan Wakely's avatar
      libstdc++: Implement P2918R0 "Runtime format strings II" for C++26 · cddaff46
      Jonathan Wakely authored
      This adds std::runtime_format for C++26. These new overloaded functions
      enhance the std::format API so that it isn't necessary to use the less
      ergonomic std::vformat and std::make_format_args (which are meant to be
      implementation details). This was approved in Kona 2023 for C++26.
      
      libstdc++-v3/ChangeLog:
      
      	* include/std/format (__format::_Runtime_format_string): Define
      	new class template.
      	(basic_format_string): Add non-consteval constructor for runtime
      	format strings.
      	(runtime_format): Define new function for C++26.
      	* testsuite/std/format/runtime_format.cc: New test.
      cddaff46
    • Jonathan Wakely's avatar
      libstdc++: Implement P2905R2 "Runtime format strings" for C++20 · 2a8ee259
      Jonathan Wakely authored
      This change makes std::make_format_args refuse to create dangling
      references to temporaries. This makes the std::vformat API safer. This
      was approved in Kona 2023 as a DR for C++20 so the change is implemented
      unconditionally.
      
      libstdc++-v3/ChangeLog:
      
      	* include/bits/chrono_io.h (__formatter_chrono): Always use
      	lvalue arguments to make_format_args.
      	* include/std/format (make_format_args): Change parameter pack
      	from forwarding references to lvalue references. Remove use of
      	remove_reference_t which is now unnecessary.
      	(format_to, formatted_size): Remove incorrect forwarding of
      	arguments.
      	* include/std/ostream (print): Remove forwarding of arguments.
      	* include/std/print (print): Likewise.
      	* testsuite/20_util/duration/io.cc: Use lvalues as arguments to
      	make_format_args.
      	* testsuite/std/format/arguments/args.cc: Likewise.
      	* testsuite/std/format/arguments/lwg3810.cc: Likewise.
      	* testsuite/std/format/functions/format.cc: Likewise.
      	* testsuite/std/format/functions/vformat_to.cc: Likewise.
      	* testsuite/std/format/string.cc: Likewise.
      	* testsuite/std/time/day/io.cc: Likewise.
      	* testsuite/std/time/month/io.cc: Likewise.
      	* testsuite/std/time/weekday/io.cc: Likewise.
      	* testsuite/std/time/year/io.cc: Likewise.
      	* testsuite/std/time/year_month_day/io.cc: Likewise.
      	* testsuite/std/format/arguments/args_neg.cc: New test.
      2a8ee259
    • Jonathan Wakely's avatar
      libstdc++: Add Unicode-aware width estimation for std::format · 37a4c5c2
      Jonathan Wakely authored
      This implements the requirements in the following proposals, which
      dictate how std::format deals with non-ASCII strings:
      https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1868r1.html
      https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2572r1.html
      https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2675r1.pdf
      
      There are two parts to this. The width estimation for strings must only
      count the width of the first character in an extended grapheme cluster.
      That requires implementing the algorithm for detecting cluster breaks,
      which requires a number of lookup tables of the grapheme cluster break
      properties (and Indic_Conjunct_Break and Extended_Pictographic
      properties) of every code point. Additionally, some characters have a
      field width of 2, which requires another lookup table of field widths
      for every code point.  The tables added in this commit do not contain
      entries for every code point from 0 to 0x10FFFF as that would be very
      inefficient and use too much memory. Instead the tables only contain the
      code points that form an "edge" for a property, omitting all the code
      points that have the same property as the preceding one. We can use a
      binary search to find the closest code point in the table that is not
      greater than the one we're looking for.
      
      The tables are generated by a new Python script added to the
      contrib/unicode directory, and a new data file downloaded from the
      Unicode Consortium website.
      
      The rules for extended grapheme cluster breaking are implemented for the
      latest Unicode standard, version 15.1.0.
      
      libstdc++-v3/ChangeLog:
      
      	* include/Makefile.am: Add new headers.
      	* include/Makefile.in: Regenerate.
      	* include/bits/unicode.h: New file.
      	* include/bits/unicode-data.h: New file.
      	* include/std/format: Include <bits/unicode.h>.
      	(__literal_encoding_is_utf8): Move to <bits/unicode.h>.
      	(_Spec::_M_fill): Change type to char32_t.
      	(_Spec::_M_parse_fill_and_align): Read a Unicode scalar value
      	instead of a single character.
      	(__write_padded): Change __fill_char parameter to char32_t and
      	encode it into the output.
      	(__formatter_str::format): Use new __unicode::__field_width and
      	__unicode::__truncate functions.
      	* include/std/ostream: Adjust namespace qualification for
      	__literal_encoding_is_utf8.
      	* include/std/print: Likewise.
      	* src/c++23/print.cc: Add [[unlikely]] attribute to error path.
      	* testsuite/ext/unicode/view.cc: New test.
      	* testsuite/std/format/functions/format.cc: Add missing examples
      	from the standard demonstrating alignment with non-ASCII
      	characters. Add examples checking correct handling of extended
      	grapheme clusters.
      
      contrib/ChangeLog:
      
      	* unicode/README: Add notes about generating libstdc++ tables.
      	* unicode/GraphemeBreakProperty.txt: New file.
      	* unicode/emoji-data.txt: New file.
      	* unicode/gen_libstdcxx_unicode_data.py: New file.
      37a4c5c2
    • Jonathan Wakely's avatar
      libstdc++: Implement P2909R4 ("Dude, where's my char?") for C++20 · 74a0dab1
      Jonathan Wakely authored
      This change ensures that char and wchar_t arguments are formatted
      consistently when using integer presentation types. This avoids
      non-portable std::format output that depends on whether char and wchar_t
      happen to be signed or unsigned on the target. Formatting '\xff' as an
      integer will now always format 255 and not sometimes -1. This was
      approved in Kona 2023 as a DR for C++20 so the change is implemented
      unconditionally.
      
      Also make character formatters check for _Pres_c explicitly and call
      _M_format_character directly. This avoid the overhead of calling format
      and _S_to_character and then calling _M_format_character anyway.
      
      libstdc++-v3/ChangeLog:
      
      	* include/bits/version.def (format_uchar): Define.
      	* include/bits/version.h: Regenerate.
      	* include/std/format (formatter<C, C>::format): Check for
      	_Pres_c and call _M_format_character directly. Cast C to its
      	unsigned equivalent for formatting as an integer.
      	(formatter<char, wchar_t>::format): Likewise.
      	(basic_format_arg(T&)): Store char arguments as unsigned char
      	for formatting to a wide string.
      	* testsuite/std/format/functions/format.cc: Adjust test. Check
      	formatting of
      74a0dab1
  16. Jan 07, 2024
    • Jonathan Wakely's avatar
      libstdc++: Remove dg-timeout-factor from test · 7d11d813
      Jonathan Wakely authored
      As the comment notes, the increased timeout was needed because of PR
      102780, but that was fixed long ago.
      
      libstdc++-v3/ChangeLog:
      
      	* testsuite/20_util/variant/87619.cc: Remove dg-timeout-factor.
      7d11d813
    • Jonathan Wakely's avatar
      libstdc++: Optimize std::is_trivially_destructible_v · 7af436ad
      Jonathan Wakely authored
      This reduces the overhead of using std::is_trivially_destructible_v and
      as a result fixes some recent regressions seen with a non-default
      GLIBCXX_TESTSUITE_STDS env var:
      FAIL: 20_util/variant/87619.cc  -std=gnu++20 (test for excess errors)
      FAIL: 20_util/variant/87619.cc  -std=gnu++23 (test for excess errors)
      FAIL: 20_util/variant/87619.cc  -std=gnu++26 (test for excess errors)
      
      libstdc++-v3/ChangeLog:
      
      	* include/std/type_traits (is_trivially_destructible_v): Use
      	built-in directly when concepts are supported.
      	* testsuite/20_util/is_trivially_destructible/value_v.cc: New
      	test.
      7af436ad
  17. Jan 06, 2024
    • Gwenole Beauchesne's avatar
      libstdc++: Fix testsuite with -Wformat · ff981616
      Gwenole Beauchesne authored
      
      Fix testsuite when compiling with -Wformat. Use nonnull arguments so
      that -Wformat does not cause extraneous output to be reported as an
      error.
      
      FAIL: tr1/8_c_compatibility/cinttypes/functions.cc (test for excess errors)
      
      libstdc++-v3/ChangeLog:
      
      	* testsuite/tr1/8_c_compatibility/cinttypes/functions.cc: Use
      	nonnull arguments to strtoimax() and wcstoimax() functions.
      
      Signed-off-by: default avatarGwenole Beauchesne <gb.devel@gmail.com>
      ff981616
  18. Jan 05, 2024
    • Jonathan Wakely's avatar
      libstdc++: Fix std::char_traits<C>::move [PR113200] · 15cc2918
      Jonathan Wakely authored
      The current constexpr implementation of std::char_traits<C>::move relies
      on being able to compare the pointer parameters, which is not allowed
      for unrelated pointers. We can use __builtin_constant_p to determine
      whether it's safe to compare the pointers directly. If not, then we know
      the ranges must be disjoint and so we can use char_traits<C>::copy to
      copy forwards from the first character to the last. If the pointers can
      be compared directly, then we can simplify the condition for copying
      backwards to just two pointer comparisons.
      
      libstdc++-v3/ChangeLog:
      
      	PR libstdc++/113200
      	* include/bits/char_traits.h (__gnu_cxx::char_traits::move): Use
      	__builtin_constant_p to check for unrelated pointers that cannot
      	be compared during constant evaluation.
      	* testsuite/21_strings/char_traits/requirements/113200.cc: New
      	test.
      15cc2918
Loading