Commit graph

14792 commits

Author SHA1 Message Date
Jonathan Wakely
15cc291887 libstdc++: Fix std::char_traits<C>::move [PR113200]
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.
2024-01-05 10:23:35 +00:00
Cassio Neri
2cb3d42d3f libstdc++: Remove UB from month and weekday additions and subtractions.
The following invoke signed integer overflow (UB) [1]:

  month   + months{MAX} // where MAX is the maximum value of months::rep
  month   + months{MIN} // where MIN is the maximum value of months::rep
  month   - months{MIN} // where MIN is the minimum value of months::rep
  weekday + days  {MAX} // where MAX is the maximum value of days::rep
  weekday - days  {MIN} // where MIN is the minimum value of days::rep

For the additions to MAX, the crux of the problem is that, in libstdc++,
months::rep and days::rep are int64_t. Other implementations use int32_t, cast
operands to int64_t and perform arithmetic operations without risk of
overflowing.

For month + months{MIN}, the implementation follows the Standard's "returns
clause" and evaluates:

   modulo(static_cast<long long>(unsigned{__x}) + (__y.count() - 1), 12);

Overflow occurs when MIN - 1 is evaluated. Casting to a larger type could help
but, unfortunately again, this is not possible for libstdc++.

For the subtraction of MIN, the problem is that -MIN is not representable.

It's fair to say that the intention is for these additions/subtractions to
be performed in modulus (12 or 7) arithmetic so that no overflow is expected.

To fix these UB, this patch implements:

  template <unsigned __d, typename _T>
  unsigned __add_modulo(unsigned __x, _T __y);

  template <unsigned __d, typename _T>
  unsigned __sub_modulo(unsigned __x, _T __y);

which respectively, returns the remainder of Euclidean division of, __x + __y
and __x - __y by __d without overflowing. These functions replace

  constexpr unsigned __modulo(long long __n, unsigned __d);

which also calculates the reminder of __n, where __n is the result of the
addition or subtraction. Hence, these operations might invoke UB before __modulo
is called and thus, __modulo can't do anything to remediate the issue.

In addition to solve the UB issues, __add_modulo and __sub_modulo allow better
codegen (shorter and branchless) on x86-64 and ARM [2].

[1] https://godbolt.org/z/a9YfWdn57
[2] https://godbolt.org/z/Gh36cr7E4

libstdc++-v3/ChangeLog:

	* include/std/chrono: Fix + and - for months and weekdays.
	* testsuite/std/time/month/1.cc: Add constexpr tests against overflow.
	* testsuite/std/time/month/2.cc: New test for extreme values.
	* testsuite/std/time/weekday/1.cc: Add constexpr tests against overflow.
	* testsuite/std/time/weekday/2.cc: New test for extreme values.
2024-01-05 10:23:35 +00:00
Jonathan Wakely
9f3eb93e72 libstdc++: Use if-constexpr in std::__try_use_facet [PR113099]
As noted in the PR, we can use if-constexpr for the explicit
instantantiation definitions that are compiled with -std=gnu++11. We
just need to disable the -Wc++17-extensions diagnostics.

libstdc++-v3/ChangeLog:

	PR libstdc++/113099
	* include/bits/locale_classes.tcc (__try_use_facet): Use
	if-constexpr for C++11 and up.
2024-01-05 10:23:35 +00:00
Jakub Jelinek
1ccad1f136 Update copyright years. 2024-01-05 08:54:28 +01:00
GCC Administrator
81d1a6e971 Daily bump. 2024-01-05 00:18:48 +00:00
Ken Matsui
f151db0f0e
libstdc++: Use _GLIBCXX_USE_BUILTIN_TRAIT
This patch uses _GLIBCXX_USE_BUILTIN_TRAIT macro instead of __has_builtin
in the type_traits header for traits that have a corresponding fallback
non-built-in implementation.  This macro supports to toggle the use of
built-in traits in the type_traits header through
_GLIBCXX_DO_NOT_USE_BUILTIN_TRAITS macro, without needing to modify the
source code.

libstdc++-v3/ChangeLog:

	* include/std/type_traits: Use _GLIBCXX_USE_BUILTIN_TRAIT.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-01-04 16:16:54 -08:00
Arsen Arsenović
589781c1d2
libstdc++: fix typo in <generator>
libstdc++-v3/ChangeLog:

	* include/std/generator (_Subyield_state::_M_jump_in): Fix typo
	reported by Will Hawkins <hawkinsw@obs.cr>.
2024-01-04 19:51:54 +01:00
Arsen Arsenović
29ad18f0cf
libstdc++: rename _A badname in <generator>
libstdc++-v3/ChangeLog:

	* include/std/generator (_Stateless_alloc): Rename typename _A
	to _All.
2024-01-04 19:51:54 +01:00
GCC Administrator
eb84e8d3e2 Daily bump. 2024-01-04 00:18:45 +00:00
Jakub Jelinek
a945c346f5 Update copyright years. 2024-01-03 12:19:35 +01:00
Jakub Jelinek
8c22aed4b0 Rotate ChangeLog files.
Rotate ChangeLog files for ChangeLogs with yearly cadence.
2024-01-03 11:29:39 +01:00
Patrick Palka
a138b99646 libstdc++: testsuite: Reduce max_size_type.cc exec time [PR113175]
The adjustment to max_size_type.cc in r14-205-g83470a5cd4c3d2
inadvertently increased the execution time of this test by over 5x due
to making the two main loops actually run in the signed_p case instead
of being dead code.

To compensate, this patch cuts the relevant loops' range [-1000,1000] by
10x as proposed in the PR.  This shouldn't significantly weaken the test
since the same important edge cases are still checked in the smaller range
and/or elsewhere.  On my machine this reduces the test's execution time by
roughly 10x (and 1.6x relative to before r14-205).

	PR testsuite/113175

libstdc++-v3/ChangeLog:

	* testsuite/std/ranges/iota/max_size_type.cc (test02): Reduce
	'limit' to 100 from 1000 and adjust 'log2_limit' accordingly.
	(test03): Likewise.
2024-01-02 21:31:20 -05:00
GCC Administrator
3a7dd24ead Daily bump. 2024-01-01 00:18:40 +00:00
Hans-Peter Nilsson
26fe2808d8 libstdc++ testsuite/20_util/hash/quality.cc: Increase timeout 3x
Testing for mmix (a 64-bit target using Knuth's simulator).  The test
is largely pruned for simulators, but still needs 5m57s on my laptop
from 3.5 years ago to run to successful completion.  Perhaps slow
hosted targets could also have problems so increasing the timeout
limit, not just for simulators but for everyone, and by more than a
factor 2.

	* testsuite/20_util/hash/quality.cc: Increase timeout by a factor 3.
2023-12-31 18:17:13 +01:00
François Dumont
505110bb91 libstdc++: [_Hashtable] Extend the small size optimization
A number of methods were still not using the small size optimization which
is to prefer an O(N) research to a hash computation as long as N is small.

libstdc++-v3/ChangeLog:

	* include/bits/hashtable.h: Move comment about all equivalent values
	being next to each other in the class documentation header.
	(_M_reinsert_node, _M_merge_unique): Implement small size optimization.
	(_M_find_tr, _M_count_tr, _M_equal_range_tr): Likewise.
2023-12-31 18:00:29 +01:00
François Dumont
91b334d027 libstdc++: [_Hashtable] Enhance performance benches
Add benches on insert with hint and before begin cache.

libstdc++-v3/ChangeLog:

	* testsuite/performance/23_containers/insert/54075.cc: Add lookup on unknown entries
	w/o copy to see potential impact of memory fragmentation enhancements.
	* testsuite/performance/23_containers/insert/unordered_multiset_hint.cc: Enhance hash
	functor to make it perfect, exactly 1 entry per bucket. Also use hash functor tagged as
	slow or not to bench w/o hash code cache.
	* testsuite/performance/23_containers/insert/unordered_set_hint.cc: New test case. Like
	previous one but using std::unordered_set.
	* testsuite/performance/23_containers/insert/unordered_set_range_insert.cc: New test case.
	Check performance of range-insertion compared to individual insertions.
	* testsuite/performance/23_containers/insert_erase/unordered_small_size.cc: Add same bench
	but after a copy to demonstrate impact of enhancements regarding memory fragmentation.
2023-12-31 17:53:27 +01:00
GCC Administrator
0a529d196b Daily bump. 2023-12-23 00:17:03 +00:00
Christophe Lyon
05d353b794 Allow overriding EXPECT
While investigating possible race conditions in the GCC testsuites
caused by bufferization issues, I wanted to investigate workarounds
similar to GDB's READ1 [1], and I noticed it was not always possible
to override EXPECT when running 'make check'.

This patch adds the missing support in various Makefiles.

I was not able to test the patch for all the libraries updated here,
but I confirmed it works as intended/needed for libstdc++.

libatomic, libitm, libgomp already work as intended because their
Makefiles do not have:
MAKEOVERRIDES=

Tested on (native) aarch64-linux-gnu, confirmed the patch introduces
the behaviour I want in gcc, g++, gfortran and libstdc++.

I updated (but could not test) libgm2, libphobos, libquadmath and
libssp for consistency since their Makefiles have MAKEOVERRIDES=

libffi, libgo, libsanitizer seem to need a similar update, but they
are imported from their respective upstream repo, so should not be
patched here.

[1] https://github.com/bminor/binutils-gdb/blob/master/gdb/testsuite/README#L269

2023-12-21  Christophe Lyon  <christophe.lyon@linaro.org>

	gcc/
	* Makefile.in: Allow overriding EXEPCT.

	libgm2/
	* Makefile.am: Allow overriding EXEPCT.
	* Makefile.in: Regenerate.

	libphobos/
	* Makefile.am: Allow overriding EXEPCT.
	* Makefile.in: Regenerate.

	libquadmath/
	* Makefile.am: Allow overriding EXEPCT.
	* Makefile.in: Regenerate.

	libssp/
	* Makefile.am: Allow overriding EXEPCT.
	* Makefile.in: Regenerate.

	libstdc++-v3/
	* Makefile.am: Allow overriding EXEPCT.
	* Makefile.in: Regenerate.
2023-12-22 10:24:56 +00:00
GCC Administrator
cdfaa4aa52 Daily bump. 2023-12-22 00:18:02 +00:00
Arsen Arsenović
ec2ec24a4d
libstdc++: implement std::generator
libstdc++-v3/ChangeLog:

	* include/Makefile.am: Install std/generator, bits/elements_of.h
	as freestanding.
	* include/Makefile.in: Regenerate.
	* include/bits/version.def: Add __cpp_lib_generator.
	* include/bits/version.h: Regenerate.
	* include/precompiled/stdc++.h: Include <generator>.
	* include/std/ranges: Include bits/elements_of.h
	* include/bits/elements_of.h: New file.
	* include/std/generator: New file.
	* testsuite/24_iterators/range_generators/01.cc: New test.
	* testsuite/24_iterators/range_generators/02.cc: New test.
	* testsuite/24_iterators/range_generators/copy.cc: New test.
	* testsuite/24_iterators/range_generators/except.cc: New test.
	* testsuite/24_iterators/range_generators/synopsis.cc: New test.
	* testsuite/24_iterators/range_generators/subrange.cc: New test.
2023-12-21 22:59:22 +01:00
Arsen Arsenović
a6bbaab273
libstdc++: add missing include in ranges_util.h
libstdc++-v3/ChangeLog:

	* include/bits/ranges_util.h: Add missing <bits/invoke.h>
	include.
2023-12-21 22:54:28 +01:00
GCC Administrator
08c5d26afa Daily bump. 2023-12-19 00:17:36 +00:00
Patrick Palka
4f54e65678 libstdc++: Make ranges::to closure objects SFINAE-friendly [PR112802]
This also happens to fix composition of these closure objects.

	PR libstdc++/112802
	PR libstdc++/113068

libstdc++-v3/ChangeLog:

	* include/std/ranges (__detail::_To::operator()): Add constraints.
	(__detail::_To2::operator()): Likewise.
	* testsuite/std/ranges/conv/1.cc (test_sfinae): New test.
	(test_composition): New test.
2023-12-18 18:05:36 -05:00
GCC Administrator
7e6f0faa8b Daily bump. 2023-12-17 00:17:30 +00:00
Jonathan Wakely
1f7acbf042 libstdc++: Fix bootstrap on AIX due to fileno macro
On AIX fileno is a function-like macro, so enclose the name in
parentheses to ensure we use the real function.

libstdc++-v3/ChangeLog:

	* src/c++23/print.cc (__open_terminal(FILE*)): Avoid fileno
	macro.
2023-12-16 23:52:30 +00:00
H.J. Lu
308e9d693c libstdc++: Update some baseline_symbols.txt (x32)
* config/abi/post/x86_64-linux-gnu/x32/baseline_symbols.txt:
	Updated.
2023-12-16 10:43:27 -08:00
Ken Matsui
61d6dee992
libstdc++: Optimize std::remove_pointer compilation performance
This patch optimizes the compilation performance of std::remove_pointer
by dispatching to the new remove_pointer built-in trait.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (remove_pointer): Use __remove_pointer
	built-in trait.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2023-12-16 08:59:40 -08:00
Ken Matsui
4b11101365
libstdc++: Optimize std::is_object compilation performance
This patch optimizes the compilation performance of std::is_object
by dispatching to the new __is_object built-in trait.

libstdc++-v3/ChangeLog:
	* include/std/type_traits (is_object): Use __is_object built-in
	trait.
	(is_object_v): Likewise.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2023-12-16 08:59:39 -08:00
Ken Matsui
cdd4387c5b
libstdc++: Optimize std::is_function compilation performance
This patch optimizes the compilation performance of std::is_function
by dispatching to the new __is_function built-in trait.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_function): Use __is_function
	built-in trait.
	(is_function_v): Likewise. Optimize its implementation.  Move
	this under is_const_v as this depends on is_const_v.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2023-12-16 08:59:38 -08:00
Ken Matsui
e86cfcaef2
libstdc++: Optimize std::is_reference compilation performance
This patch optimizes the compilation performance of std::is_reference
by dispatching to the new __is_reference built-in trait.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_reference): Use __is_reference
	built-in trait.
	(is_reference_v): Likewise.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2023-12-16 08:59:36 -08:00
Ken Matsui
fa454b8dd0
libstdc++: Optimize std::is_member_object_pointer compilation performance
This patch optimizes the compilation performance of
std::is_member_object_pointer by dispatching to the new
__is_member_object_pointer built-in trait.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_member_object_pointer): Use
	__is_member_object_pointer built-in trait.
	(is_member_object_pointer_v): Likewise.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2023-12-16 08:59:35 -08:00
Ken Matsui
53f9d0cc07
libstdc++: Optimize std::is_member_function_pointer compilation performance
This patch optimizes the compilation performance of
std::is_member_function_pointer by dispatching to the new
__is_member_function_pointer built-in trait.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_member_function_pointer): Use
	__is_member_function_pointer built-in trait.
	(is_member_function_pointer_v): Likewise.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2023-12-16 08:59:34 -08:00
Ken Matsui
d95e54347f
libstdc++: Optimize std::is_member_pointer compilation performance
This patch optimizes the compilation performance of std::is_member_pointer
by dispatching to the new __is_member_pointer built-in trait.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_member_pointer): Use
	__is_member_pointer built-in trait.
	(is_member_pointer_v): Likewise.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2023-12-16 08:59:33 -08:00
Ken Matsui
4a235f8eb0
libstdc++: Optimize std::is_scoped_enum compilation performance
This patch optimizes the compilation performance of std::is_scoped_enum
by dispatching to the new __is_scoped_enum built-in trait.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_scoped_enum): Use
	__is_scoped_enum built-in trait.
	(is_scoped_enum_v): Likewise.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2023-12-16 08:59:32 -08:00
Ken Matsui
8843cff6c9
libstdc++: Optimize std::is_bounded_array compilation performance
This patch optimizes the compilation performance of std::is_bounded_array
by dispatching to the new __is_bounded_array built-in trait.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_bounded_array_v): Use
	__is_bounded_array built-in trait.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2023-12-16 08:59:31 -08:00
Ken Matsui
7fd9c349e4
libstdc++: Optimize std::is_array compilation performance
This patch optimizes the compilation performance of std::is_array
by dispatching to the new __is_array built-in trait.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_array): Use __is_array built-in
	trait.
	(is_array_v): Likewise.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2023-12-16 08:59:30 -08:00
GCC Administrator
ea54b390ae Daily bump. 2023-12-16 00:17:35 +00:00
Jonathan Wakely
1d8ac2a74f libstdc++: Fix std::print test case for Windows
libstdc++-v3/ChangeLog:

	* src/c++23/print.cc (__write_to_terminal) [_WIN32]: If handle
	does not refer to the console then just write to it using normal
	file I/O.
	* testsuite/27_io/print/2.cc (as_printed_to_terminal): Print
	error message on failure.
	(test_utf16_transcoding): Adjust for as_printed_to_terminal
	modifying its argument.
2023-12-15 13:20:49 +00:00
Jonathan Wakely
7d2e100058 libstdc++: Simplify std::vprint_unicode for non-Windows targets
Since we don't need to do anything special to print Unicode on
non-Windows targets, we might as well just use std::vprint_nonunicode to
implement std::vprint_unicode. Removing the duplicated code should
reduce code size in cases where those calls aren't inlined.

Also use an RAII type for the unused case where a non-Windows target
calls __open_terminal(streambuf*) and needs to fclose the result. This
makes the code futureproof in case we ever start using the
__write_terminal function for non-Windows targets.

libstdc++-v3/ChangeLog:

	* include/std/ostream (vprint_unicode) [_WIN32]: Use RAII guard.
	(vprint_unicode) [!_WIN32]: Just call vprint_nonunicode.
	* include/std/print (vprint_unicode) [!_WIN32]: Likewise.
2023-12-15 13:20:49 +00:00
Jonathan Wakely
8a5cac92e7 libstdc++: Do not add padding for std::print to std::ostream
Tim Song pointed out that although std::print behaves as a formatted
output function, it does "determine padding" using the stream's flags.

libstdc++-v3/ChangeLog:

	* include/std/ostream (vprint_nonunicode, vprint_unicode): Do
	not insert padding.
	* testsuite/27_io/basic_ostream/print/1.cc: Adjust expected
	behaviour.
2023-12-15 13:20:49 +00:00
GCC Administrator
f998335ac0 Daily bump. 2023-12-15 00:17:17 +00:00
Jonathan Wakely
fe54b57728 libstdc++: Implement C++23 <print> header [PR107760]
This adds the C++23 std::print functions, which use std::format to write
to a FILE stream or std::ostream (defaulting to stdout).

The new extern symbols are in the libstdc++exp.a archive, so we aren't
committing to stable symbols in the DSO yet. There's a UTF-8 validating
and transcoding function added by this change. That can certainly be
optimized, but it's internal to libstdc++exp.a so can be tweaked later
at leisure.

Currently the external symbols work for all targets, but are only
actually used for Windows, where it's necessary to transcode to UTF-16
to write to the console.  The standard seems to encourage us to also
diagnose invalid UTF-8 for non-Windows targets when writing to a
terminal (and only when writing to a terminal), but I'm reliably
informed that that wasn't the intent of the wording. Checking for
invalid UTF-8 sequences only needs to happen for Windows, which is good
as checking for a terminal requires a call to isatty, and on Linux that
uses an ioctl syscall, which would make std::print ten times slower!

Testing the std::print behaviour is difficult if it depends on whether
the output stream is connected to a Windows console or not, as we can't
(as far as I know) do that non-interactively in DejaGNU. One of the new
tests uses the internal __write_to_terminal function directly. That
allows us to verify its UTF-8 error handling on POSIX targets, even
though that's not actually used by std::print. For Windows, that
__write_to_terminal function transcodes to UTF-16 but then uses
WriteConsoleW which fails unless it really is writing to the console.
That means the 27_io/print/2.cc test FAILs on Windows. The UTF-16
transcoding has been manually tested using mingw-w64 and Wine, and
appears to work.

libstdc++-v3/ChangeLog:

	PR libstdc++/107760
	* include/Makefile.am: Add new header.
	* include/Makefile.in: Regenerate.
	* include/bits/version.def (__cpp_lib_print): Define.
	* include/bits/version.h: Regenerate.
	* include/std/format (__literal_encoding_is_utf8): New function.
	(_Seq_sink::view()): New member function.
	* include/std/ostream (vprintf_nonunicode, vprintf_unicode)
	(print, println): New functions.
	* include/std/print: New file.
	* src/c++23/Makefile.am: Add new source file.
	* src/c++23/Makefile.in: Regenerate.
	* src/c++23/print.cc: New file.
	* testsuite/27_io/basic_ostream/print/1.cc: New test.
	* testsuite/27_io/print/1.cc: New test.
	* testsuite/27_io/print/2.cc: New test.
2023-12-14 23:59:24 +00:00
Jonathan Wakely
29ad35a1db libstdc++: Fix filebuf::native_handle() for Windows
libstdc++-v3/ChangeLog:

	* acinclude.m4 (GLIBCXX_CHECK_FILEBUF_NATIVE_HANDLES): Add
	missing header to configure test. Check correct variable.
	* config/io/basic_file_stdio.cc (__basic_file<char>::native_handle):
	Fix typo.
	* configure: Regenerate.
	* testsuite/27_io/basic_filebuf/native_handle/char/1.cc: Do not
	call CloseHandle on the native handle.
	* testsuite/27_io/basic_filebuf/native_handle/wchar_t/1.cc:
	Likewise.
2023-12-14 23:59:21 +00:00
Jonathan Wakely
3fa0f9404b libstdc++: Tweaks for std::format fast path
Fix an incorrect call to _Sink::_M_reserve() which should have passed
the __n parameter. This was not actually a problem because it was in an
discarded statement, because only the _Seq_sink<basic_string<C>>
specialization was used.

Also add some branch prediction hints, explanatory comments, and debug
mode assertions to _Seq_sink.

libstdc++-v3/ChangeLog:

	* include/std/format (_Seq_sink): Fix missing argument in
	discarded statement. Add comments, likely/unlikely attributes
	and debug assertions as sanity checks.
2023-12-14 22:04:43 +00:00
Jonathan Wakely
0c773209fc libstdc++: Add dg-output to two tests
These tests are expected to run interactively, with the output checked
by eye. Nobody ever does that, but we can at least use dg-output to
check that the output is as expected.

libstdc++-v3/ChangeLog:

	* testsuite/27_io/objects/char/2.cc: Use dg-output.
	* testsuite/27_io/objects/wchar_t/2.cc: Use dg-output.
2023-12-14 22:04:43 +00:00
Jonathan Wakely
2ef5200a6f libstdc++: Fix %S format of duration with floating-point rep
I got the order of arguments to std::format_to wrong. It was in a
discarded statement, for a case which wasn't being tested.

libstdc++-v3/ChangeLog:

	* include/bits/chrono_io.h (__formatter_chrono::_M_S): Fix order
	of arguments to std::format_to.
	* testsuite/20_util/duration/io.cc: Test subsecond duration with
	floating-point rep.
2023-12-14 22:04:42 +00:00
Jonathan Wakely
7d00a59229 libstdc++: Make __gnu_debug::vector usable in constant expressions [PR109536]
This makes constexpr std::vector (mostly) work in Debug Mode. All safe
iterator instrumentation and checking is disabled during constant
evaluation, because it requires mutex locks and calls to non-inline
functions defined in libstdc++.so. It should be OK to disable the safety
checks, because most UB should be detected during constant evaluation
anyway.

We could try to enable the full checking in constexpr, but it would mean
wrapping all the non-inline functions like _M_attach with an inline
_M_constexpr_attach that does the iterator housekeeping inline without
mutex locks when called for constant evaluation, and calls the
non-inline function at runtime. That could be done in future if we find
that we've lost safety or useful checking by disabling the safe
iterators.

There are a few test failures in C++20 mode, which I'm unable to
explain. The _Safe_iterator::operator++() member gives errors for using
non-constexpr functions during constant evaluation, even though those
functions are guarded by std::is_constant_evaluated() checks. The same
code works fine for C++23 and up.

libstdc++-v3/ChangeLog:

	PR libstdc++/109536
	* include/bits/c++config (__glibcxx_constexpr_assert): Remove
	macro.
	* include/bits/stl_algobase.h (__niter_base, __copy_move_a)
	(__copy_move_backward_a, __fill_a, __fill_n_a, __equal_aux)
	(__lexicographical_compare_aux): Add constexpr to overloads for
	debug mode iterators.
	* include/debug/helper_functions.h (__unsafe): Add constexpr.
	* include/debug/macros.h (_GLIBCXX_DEBUG_VERIFY_COND_AT): Remove
	macro, folding it into ...
	(_GLIBCXX_DEBUG_VERIFY_AT_F): ... here. Do not use
	__glibcxx_constexpr_assert.
	* include/debug/safe_base.h (_Safe_iterator_base): Add constexpr
	to some member functions. Omit attaching, detaching and checking
	operations during constant evaluation.
	* include/debug/safe_container.h (_Safe_container): Likewise.
	* include/debug/safe_iterator.h (_Safe_iterator): Likewise.
	* include/debug/safe_iterator.tcc (__niter_base, __copy_move_a)
	(__copy_move_backward_a, __fill_a, __fill_n_a, __equal_aux)
	(__lexicographical_compare_aux): Add constexpr.
	* include/debug/vector (_Safe_vector, vector): Add constexpr.
	Omit safe iterator operations during constant evaluation.
	* testsuite/23_containers/vector/bool/capacity/constexpr.cc:
	Remove dg-xfail-if for debug mode.
	* testsuite/23_containers/vector/bool/cmp_c++20.cc: Likewise.
	* testsuite/23_containers/vector/bool/cons/constexpr.cc:
	Likewise.
	* testsuite/23_containers/vector/bool/element_access/1.cc:
	Likewise.
	* testsuite/23_containers/vector/bool/element_access/constexpr.cc:
	Likewise.
	* testsuite/23_containers/vector/bool/modifiers/assign/constexpr.cc:
	Likewise.
	* testsuite/23_containers/vector/bool/modifiers/constexpr.cc:
	Likewise.
	* testsuite/23_containers/vector/bool/modifiers/swap/constexpr.cc:
	Likewise.
	* testsuite/23_containers/vector/capacity/constexpr.cc:
	Likewise.
	* testsuite/23_containers/vector/cmp_c++20.cc: Likewise.
	* testsuite/23_containers/vector/cons/constexpr.cc: Likewise.
	* testsuite/23_containers/vector/data_access/constexpr.cc:
	Likewise.
	* testsuite/23_containers/vector/element_access/constexpr.cc:
	Likewise.
	* testsuite/23_containers/vector/modifiers/assign/constexpr.cc:
	Likewise.
	* testsuite/23_containers/vector/modifiers/constexpr.cc:
	Likewise.
	* testsuite/23_containers/vector/modifiers/swap/constexpr.cc:
	Likewise.
	* testsuite/23_containers/vector/cons/destructible_debug_neg.cc:
	Adjust dg-error line number.
2023-12-14 16:07:48 +00:00
GCC Administrator
e8018ccff9 Daily bump. 2023-12-14 00:18:00 +00:00
Jonathan Wakely
ad537ccd52 libstdc++: Fix regression in std::format output of %Y for negative years
The change in r14-6468-ga01462ae8bafa8 was only supposed to apply to %C
formats, not %Y.

libstdc++-v3/ChangeLog:

	* include/bits/chrono_io.h (__formatter_chrono::_M_C_y_Y): Do
	not round century down for %Y formats.
2023-12-13 12:30:14 +00:00
GCC Administrator
8a5d6ce0e8 Daily bump. 2023-12-13 00:17:49 +00:00