[gcc r13-8943] libstdc++: Fix std::vector for -std=gnu++14 -fconcepts [PR116070]

2024-07-24 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:46d68bc90688745fc9f25795c371ecaf21e18b56

commit r13-8943-g46d68bc90688745fc9f25795c371ecaf21e18b56
Author: Jonathan Wakely 
Date:   Wed Jul 24 11:32:22 2024 +0100

libstdc++: Fix std::vector for -std=gnu++14 -fconcepts [PR116070]

This questionable combination of flags causes a number of errors. This
one in std::vector needs to be fixed in the gcc-13 branch so I'm
committing it separately to simplify backporting.

libstdc++-v3/ChangeLog:

PR libstdc++/116070
* include/bits/stl_bvector.h: Check feature test macro before
using is_default_constructible_v.

(cherry picked from commit 5fc9c40fea2481e56bf7bcc994cb40c71e28abb8)

Diff:
---
 libstdc++-v3/include/bits/stl_bvector.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/stl_bvector.h 
b/libstdc++-v3/include/bits/stl_bvector.h
index e18de7c62aa2..63e416053e0f 100644
--- a/libstdc++-v3/include/bits/stl_bvector.h
+++ b/libstdc++-v3/include/bits/stl_bvector.h
@@ -593,7 +593,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_GLIBCXX20_CONSTEXPR
_Bvector_impl() _GLIBCXX_NOEXCEPT_IF(
  is_nothrow_default_constructible<_Bit_alloc_type>::value)
-#if __cpp_concepts
+#if __cpp_concepts && __cpp_lib_type_trait_variable_templates
requires is_default_constructible_v<_Bit_alloc_type>
 #endif
: _Bit_alloc_type()


[committed 1/2] libstdc++: Fix std::vector for -std=gnu++14 -fconcepts [PR116070]

2024-07-24 Thread Jonathan Wakely
Tested x86_64-linux.

Pushed to trunk. Backports to follow after the 14.2 release.

-- >8 --

This questionable combination of flags causes a number of errors. This
one in std::vector needs to be fixed in the gcc-13 branch so I'm
committing it separately to simplify backporting.

libstdc++-v3/ChangeLog:

PR libstdc++/116070
* include/bits/stl_bvector.h: Check feature test macro before
using is_default_constructible_v.
---
 libstdc++-v3/include/bits/stl_bvector.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/stl_bvector.h 
b/libstdc++-v3/include/bits/stl_bvector.h
index 245e1c3b3a7..c45b7ff3320 100644
--- a/libstdc++-v3/include/bits/stl_bvector.h
+++ b/libstdc++-v3/include/bits/stl_bvector.h
@@ -593,7 +593,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_GLIBCXX20_CONSTEXPR
_Bvector_impl() _GLIBCXX_NOEXCEPT_IF(
  is_nothrow_default_constructible<_Bit_alloc_type>::value)
-#if __cpp_concepts
+#if __cpp_concepts && __glibcxx_type_trait_variable_templates
requires is_default_constructible_v<_Bit_alloc_type>
 #endif
: _Bit_alloc_type()
-- 
2.45.2



[committed 2/2] libstdc++: Fix and for -std=gnu++14 -fconcepts [PR116070]

2024-07-24 Thread Jonathan Wakely
Tested x86_64-linux.

Pushed to trunk. Backports to follow after the 14.2 release.

-- >8 --

This questionable combination of flags causes a number of errors. The
ones in the rvalue stream overloads need to be fixed in the gcc-14
branch so I'm committing it separately to simplify backporting.

libstdc++-v3/ChangeLog:

PR libstdc++/116070
* include/std/istream: Check feature test macro before using
is_class_v and is_same_v.
* include/std/ostream: Likewise.
---
 libstdc++-v3/include/std/istream | 2 +-
 libstdc++-v3/include/std/ostream | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/istream b/libstdc++-v3/include/std/istream
index 11d51d3e666..a2b207dae78 100644
--- a/libstdc++-v3/include/std/istream
+++ b/libstdc++-v3/include/std/istream
@@ -1069,7 +1069,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // 2328. Rvalue stream extraction should use perfect forwarding
   // 1203. More useful rvalue stream insertion
 
-#if __cpp_concepts >= 201907L
+#if __cpp_concepts >= 201907L && __glibcxx_type_trait_variable_templates
   template
 requires __derived_from_ios_base<_Is>
   && requires (_Is& __is, _Tp&& __t) { __is >> std::forward<_Tp>(__t); }
diff --git a/libstdc++-v3/include/std/ostream b/libstdc++-v3/include/std/ostream
index 8a21758d0a3..12be6c4fd17 100644
--- a/libstdc++-v3/include/std/ostream
+++ b/libstdc++-v3/include/std/ostream
@@ -768,7 +768,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // _GLIBCXX_RESOLVE_LIB_DEFECTS
   // 1203. More useful rvalue stream insertion
 
-#if __cpp_concepts >= 201907L
+#if __cpp_concepts >= 201907L && __glibcxx_type_trait_variable_templates
   // Use concepts if possible because they're cheaper to evaluate.
   template
 concept __derived_from_ios_base = is_class_v<_Tp>
-- 
2.45.2



[gcc r15-2273] libstdc++: Fix and for -std=gnu++14 -fconcepts [PR116070]

2024-07-24 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:6c22fe418cff57dad712c4b950638e6e2d09bd9c

commit r15-2273-g6c22fe418cff57dad712c4b950638e6e2d09bd9c
Author: Jonathan Wakely 
Date:   Wed Jul 24 11:32:22 2024 +0100

libstdc++: Fix  and  for -std=gnu++14 -fconcepts 
[PR116070]

This questionable combination of flags causes a number of errors. The
ones in the rvalue stream overloads need to be fixed in the gcc-14
branch so I'm committing it separately to simplify backporting.

libstdc++-v3/ChangeLog:

PR libstdc++/116070
* include/std/istream: Check feature test macro before using
is_class_v and is_same_v.
* include/std/ostream: Likewise.

Diff:
---
 libstdc++-v3/include/std/istream | 2 +-
 libstdc++-v3/include/std/ostream | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/istream b/libstdc++-v3/include/std/istream
index 11d51d3e666c..a2b207dae78c 100644
--- a/libstdc++-v3/include/std/istream
+++ b/libstdc++-v3/include/std/istream
@@ -1069,7 +1069,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // 2328. Rvalue stream extraction should use perfect forwarding
   // 1203. More useful rvalue stream insertion
 
-#if __cpp_concepts >= 201907L
+#if __cpp_concepts >= 201907L && __glibcxx_type_trait_variable_templates
   template
 requires __derived_from_ios_base<_Is>
   && requires (_Is& __is, _Tp&& __t) { __is >> std::forward<_Tp>(__t); }
diff --git a/libstdc++-v3/include/std/ostream b/libstdc++-v3/include/std/ostream
index 8a21758d0a33..12be6c4fd178 100644
--- a/libstdc++-v3/include/std/ostream
+++ b/libstdc++-v3/include/std/ostream
@@ -768,7 +768,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // _GLIBCXX_RESOLVE_LIB_DEFECTS
   // 1203. More useful rvalue stream insertion
 
-#if __cpp_concepts >= 201907L
+#if __cpp_concepts >= 201907L && __glibcxx_type_trait_variable_templates
   // Use concepts if possible because they're cheaper to evaluate.
   template
 concept __derived_from_ios_base = is_class_v<_Tp>


[gcc r15-2272] libstdc++: Fix std::vector for -std=gnu++14 -fconcepts [PR116070]

2024-07-24 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:5fc9c40fea2481e56bf7bcc994cb40c71e28abb8

commit r15-2272-g5fc9c40fea2481e56bf7bcc994cb40c71e28abb8
Author: Jonathan Wakely 
Date:   Wed Jul 24 11:32:22 2024 +0100

libstdc++: Fix std::vector for -std=gnu++14 -fconcepts [PR116070]

This questionable combination of flags causes a number of errors. This
one in std::vector needs to be fixed in the gcc-13 branch so I'm
committing it separately to simplify backporting.

libstdc++-v3/ChangeLog:

PR libstdc++/116070
* include/bits/stl_bvector.h: Check feature test macro before
using is_default_constructible_v.

Diff:
---
 libstdc++-v3/include/bits/stl_bvector.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/stl_bvector.h 
b/libstdc++-v3/include/bits/stl_bvector.h
index 245e1c3b3a77..c45b7ff3320d 100644
--- a/libstdc++-v3/include/bits/stl_bvector.h
+++ b/libstdc++-v3/include/bits/stl_bvector.h
@@ -593,7 +593,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_GLIBCXX20_CONSTEXPR
_Bvector_impl() _GLIBCXX_NOEXCEPT_IF(
  is_nothrow_default_constructible<_Bit_alloc_type>::value)
-#if __cpp_concepts
+#if __cpp_concepts && __glibcxx_type_trait_variable_templates
requires is_default_constructible_v<_Bit_alloc_type>
 #endif
: _Bit_alloc_type()


[gcc r15-2271] libstdc++: Remove duplicate include header from ranges_algobase.h

2024-07-24 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:c9d61cff97b92c64e7f0717b3fb64fff4c870321

commit r15-2271-gc9d61cff97b92c64e7f0717b3fb64fff4c870321
Author: Michael Levine 
Date:   Tue Jul 23 12:50:31 2024 +0100

libstdc++: Remove duplicate include header from ranges_algobase.h

The bits/stl_algobase.h header was added to bits/ranges_algobase.h
separately through two related commits:
r15-1106-g674d213ab91871
r15-1117-g0bb1db32ccf54a

The comment for the first time it is included in the file is also
incorrect (my error from that 2nd one) since it is really being included
for __memcmp, not __memcpy

This patch removes the duplicate header include.

libstdc++-v3/ChangeLog:

* include/bits/ranges_algobase.h: Remove duplicate include of
.

Signed-off-by: Michael Levine 

Diff:
---
 libstdc++-v3/include/bits/ranges_algobase.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/ranges_algobase.h 
b/libstdc++-v3/include/bits/ranges_algobase.h
index 7ce5ac314f25..fd35b8ba14cb 100644
--- a/libstdc++-v3/include/bits/ranges_algobase.h
+++ b/libstdc++-v3/include/bits/ranges_algobase.h
@@ -35,7 +35,6 @@
 #include 
 #include 
 #include 
-#include  // __memcpy
 #include  // ranges::begin, ranges::range etc.
 #include   // __invoke
 #include  // __is_byte


Re: [PATCH 1/8] libstdc++: Clean up @diff@ markup in some I/O tests

2024-07-24 Thread Jonathan Wakely
I've pushed this series to trunk now.

On Mon, 22 Jul 2024 at 17:34, Jonathan Wakely  wrote:
>
> Tested x86_64-linux.
>
> -- >8 --
>
> We have a number of 27_io/* tests with comments like this:
>
> // @require@ %-*.tst
> // @diff@ %-*.tst %-*.txt
>
> It seems that these declare required data files used by the test and a
> post-test action to compare the test output with the expected result.
> We do have tests that depend on some *.tst and/or *.txt files that are
> copied from testsuite/data into each test's working directory before it
> runs, so the comments are related to those dependencies.  However,
> nothing in the current test framework actually makes use of these
> comments. Currently, every test gets a fresh copy of every *.tst and
> *.txt file in the testsuite/data directory, whether the test actually
> requires them or not.
>
> This change is the first in a series to clean up this unused markup in
> the tests. This first step is to just remove all @require@ and @diff@
> comments where they seem to serve no purpose at all. These tests do not
> open any of the *.tst or *.txt files that are copied into the test's
> working directory from the testsuite/data directory, so they don't
> "require" any of those files, and there's no need to "diff" them after
> the test runs.
>
> libstdc++-v3/ChangeLog:
>
> * testsuite/27_io/basic_filebuf/close/char/4879.cc: Remove
> @require@ and @diff@ comments.
> * testsuite/27_io/basic_filebuf/close/char/9964.cc: Likewise.
> * testsuite/27_io/basic_filebuf/open/char/3.cc: Likewise.
> * testsuite/27_io/basic_filebuf/open/char/9507.cc: Likewise.
> * testsuite/27_io/basic_filebuf/sbumpc/char/1-out.cc: Likewise.
> * testsuite/27_io/basic_filebuf/sbumpc/char/2-out.cc: Likewise.
> * testsuite/27_io/basic_filebuf/sgetc/char/1-out.cc: Likewise.
> * testsuite/27_io/basic_filebuf/sgetc/char/2-out.cc: Likewise.
> * testsuite/27_io/basic_filebuf/sgetn/char/1-out.cc: Likewise.
> * testsuite/27_io/basic_filebuf/sgetn/char/2-out.cc: Likewise.
> * testsuite/27_io/basic_filebuf/snextc/char/2-out.cc: Likewise.
> * testsuite/27_io/basic_filebuf/sputbackc/char/1-io.cc:
> Likewise.
> * testsuite/27_io/basic_filebuf/sputbackc/char/1-out.cc:
> Likewise.
> * testsuite/27_io/basic_filebuf/sputbackc/char/2-io.cc:
> Likewise.
> * testsuite/27_io/basic_filebuf/sputbackc/char/2-out.cc:
> Likewise.
> * testsuite/27_io/basic_filebuf/sputc/char/1-out.cc: Likewise.
> * testsuite/27_io/basic_filebuf/sputc/char/2-out.cc: Likewise.
> * testsuite/27_io/basic_filebuf/sputn/char/1-out.cc: Likewise.
> * testsuite/27_io/basic_filebuf/sputn/char/2-out.cc: Likewise.
> * testsuite/27_io/basic_filebuf/sungetc/char/1-io.cc: Likewise.
> * testsuite/27_io/basic_filebuf/sungetc/char/1-out.cc: Likewise.
> * testsuite/27_io/basic_filebuf/sungetc/char/2-io.cc: Likewise.
> * testsuite/27_io/basic_filebuf/sungetc/char/2-out.cc: Likewise.
> * testsuite/27_io/basic_filebuf/sputc/char/1-io.cc: Likewise.
> Remove unused variable.
> * testsuite/27_io/basic_filebuf/sputn/char/2-io.cc: Likewise.
> * testsuite/27_io/basic_ofstream/cons/char/1.cc: Remove
> @require@ and @diff@ comments. Remove unused variables.
> * testsuite/27_io/basic_ofstream/rdbuf/char/2832.cc: Remove
> * testsuite/27_io/ios_base/sync_with_stdio/2.cc: Likewise.
> ---
>  .../testsuite/27_io/basic_filebuf/close/char/4879.cc   |  4 +---
>  .../testsuite/27_io/basic_filebuf/close/char/9964.cc   |  4 +---
>  .../testsuite/27_io/basic_filebuf/open/char/3.cc   |  4 +---
>  .../testsuite/27_io/basic_filebuf/open/char/9507.cc|  4 +---
>  .../testsuite/27_io/basic_filebuf/sbumpc/char/1-out.cc |  5 +
>  .../testsuite/27_io/basic_filebuf/sbumpc/char/2-out.cc |  5 +
>  .../testsuite/27_io/basic_filebuf/sgetc/char/1-out.cc  |  5 +
>  .../testsuite/27_io/basic_filebuf/sgetc/char/2-out.cc  |  5 +
>  .../testsuite/27_io/basic_filebuf/sgetn/char/1-out.cc  |  5 +
>  .../testsuite/27_io/basic_filebuf/sgetn/char/2-out.cc  |  5 +
>  .../testsuite/27_io/basic_filebuf/snextc/char/2-out.cc |  5 +
>  .../27_io/basic_filebuf/sputbackc/char/1-io.cc |  5 +
>  .../27_io/basic_filebuf/sputbackc/char/1-out.cc|  5 +
>  .../27_io/basic_filebuf/sputbackc/char/2-io.cc |  5 +
>  .../27_io/basic_filebuf/sputbackc/char/2-out.cc|  5 +
>  .../testsuite/27_io/basic_filebuf/sputc/char/1-io.cc   |  6 +-
>  .../testsuite/27_io/basic_filebuf/sputc/char/1-out.cc  |  5 +---

[gcc r15-2252] libstdc++: Rename tests [PR12048]

2024-07-24 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:4efe43a61334e231bcd3cf9150cd844dbdf9ed20

commit r15-2252-g4efe43a61334e231bcd3cf9150cd844dbdf9ed20
Author: Jonathan Wakely 
Date:   Mon Jul 22 15:50:19 2024 +0100

libstdc++: Rename tests [PR12048]

These have the wrong PR number in the filenames.

libstdc++-v3/ChangeLog:

PR libstdc++/12048
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-1.cc: Move to...
* testsuite/ext/stdio_sync_filebuf/wchar_t/12048-1.cc: ...here.
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-2.cc: Move to...
* testsuite/ext/stdio_sync_filebuf/wchar_t/12048-2.cc: ...here.
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-3.cc: Move to...
* testsuite/ext/stdio_sync_filebuf/wchar_t/12048-3.cc: ...here.
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-4.cc: Move to...
* testsuite/ext/stdio_sync_filebuf/wchar_t/12048-4.cc: ...here.

Diff:
---
 .../testsuite/ext/stdio_sync_filebuf/wchar_t/{12948-1.cc => 12048-1.cc}   | 0
 .../testsuite/ext/stdio_sync_filebuf/wchar_t/{12948-2.cc => 12048-2.cc}   | 0
 .../testsuite/ext/stdio_sync_filebuf/wchar_t/{12948-3.cc => 12048-3.cc}   | 0
 .../testsuite/ext/stdio_sync_filebuf/wchar_t/{12948-4.cc => 12048-4.cc}   | 0
 4 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-1.cc 
b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-1.cc
similarity index 100%
rename from libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-1.cc
rename to libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-1.cc
diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-2.cc 
b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-2.cc
similarity index 100%
rename from libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-2.cc
rename to libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-2.cc
diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-3.cc 
b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-3.cc
similarity index 100%
rename from libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-3.cc
rename to libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-3.cc
diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-4.cc 
b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-4.cc
similarity index 100%
rename from libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-4.cc
rename to libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-4.cc


[gcc r15-2251] libstdc++: Stop copying all data files into test directory

2024-07-24 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:cee008380b85bd1cac9c8a5b64266388471ec026

commit r15-2251-gcee008380b85bd1cac9c8a5b64266388471ec026
Author: Jonathan Wakely 
Date:   Mon Jul 22 14:07:32 2024 +0100

libstdc++: Stop copying all data files into test directory

This removes the TODO in libstdc++_init, so that we don't copy all *.tst
and *.txt files from testsuite/data into every test's working directory.
Instead, only the necessary files declared with dg-additional-files are
copied.

libstdc++-v3/ChangeLog:

* testsuite/lib/libstdc++.exp (libstdc++_init): Do not copy all
data files into test directory.

Diff:
---
 libstdc++-v3/testsuite/lib/libstdc++.exp | 5 -
 1 file changed, 5 deletions(-)

diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp 
b/libstdc++-v3/testsuite/lib/libstdc++.exp
index ef511949c7bc..4bf88e72d051 100644
--- a/libstdc++-v3/testsuite/lib/libstdc++.exp
+++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
@@ -158,11 +158,6 @@ proc libstdc++_init { testfile } {
 global dg-do-what-default
 set dg-do-what-default run
 
-# Copy all required data files.
-# TODO: Use dg-additional-files in individual tests instead of doing this.
-v3-copy-files [glob -nocomplain "$srcdir/data/*.tst"]
-v3-copy-files [glob -nocomplain "$srcdir/data/*.txt"]
-
 set ld_library_path_tmp ""
 
 # Locate libgcc.a so we don't need to account for different values of


[gcc r15-2250] libstdc++: Use dg-additional-files in some non-I/O tests

2024-07-24 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:171af3580de54d482c6a32fb249e96000a9e10b8

commit r15-2250-g171af3580de54d482c6a32fb249e96000a9e10b8
Author: Jonathan Wakely 
Date:   Mon Jul 22 15:15:16 2024 +0100

libstdc++: Use dg-additional-files in some non-I/O tests

libstdc++-v3/ChangeLog:

* testsuite/20_util/hash/chi2_q_document_words.cc: Use
dg-additional-files for input text.
* testsuite/performance/ext/pb_ds/all_text_find.cc: Likewise.
* testsuite/performance/ext/pb_ds/multimap_text_find.hpp:
Likewise.
* testsuite/performance/ext/pb_ds/multimap_text_insert.hpp:
Likewise.
* testsuite/performance/ext/pb_ds/multimap_text_insert_mem.hpp:
Likewise.
* testsuite/performance/ext/pb_ds/priority_queue_text_join.cc:
Likewise.
* testsuite/performance/ext/pb_ds/priority_queue_text_modify.hpp: 
Likewise.
* testsuite/performance/ext/pb_ds/priority_queue_text_pop_mem.cc: 
Likewise.
* testsuite/performance/ext/pb_ds/priority_queue_text_push.cc:
Likewise.
* testsuite/performance/ext/pb_ds/priority_queue_text_push_pop.cc: 
Likewise.
* testsuite/performance/ext/pb_ds/tree_text_insert.cc: Likewise.
* testsuite/performance/ext/pb_ds/tree_text_lor_find.cc:
Likewise.

Diff:
---
 libstdc++-v3/testsuite/20_util/hash/chi2_q_document_words.cc| 2 ++
 libstdc++-v3/testsuite/performance/ext/pb_ds/all_text_find.cc   | 2 ++
 libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find.hpp | 2 ++
 libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert.hpp   | 2 ++
 .../testsuite/performance/ext/pb_ds/multimap_text_insert_mem.hpp| 2 ++
 .../testsuite/performance/ext/pb_ds/priority_queue_text_join.cc | 2 ++
 .../testsuite/performance/ext/pb_ds/priority_queue_text_modify.hpp  | 2 ++
 .../testsuite/performance/ext/pb_ds/priority_queue_text_pop_mem.cc  | 2 ++
 .../testsuite/performance/ext/pb_ds/priority_queue_text_push.cc | 2 ++
 .../testsuite/performance/ext/pb_ds/priority_queue_text_push_pop.cc | 2 ++
 libstdc++-v3/testsuite/performance/ext/pb_ds/tree_text_insert.cc| 2 ++
 libstdc++-v3/testsuite/performance/ext/pb_ds/tree_text_lor_find.cc  | 2 ++
 12 files changed, 24 insertions(+)

diff --git a/libstdc++-v3/testsuite/20_util/hash/chi2_q_document_words.cc 
b/libstdc++-v3/testsuite/20_util/hash/chi2_q_document_words.cc
index a6ebc0011eba..3c77527c27ce 100644
--- a/libstdc++-v3/testsuite/20_util/hash/chi2_q_document_words.cc
+++ b/libstdc++-v3/testsuite/20_util/hash/chi2_q_document_words.cc
@@ -19,6 +19,8 @@
 // along with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
+// { dg-additional-files "thirty_years_among_the_dead_preproc.txt" }
+
 #include "chi2_quality.h"
 
 // Tests chi^2 for a set of words taken from a document written in English.
diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/all_text_find.cc 
b/libstdc++-v3/testsuite/performance/ext/pb_ds/all_text_find.cc
index 13c73a76647d..df822c3d5f78 100644
--- a/libstdc++-v3/testsuite/performance/ext/pb_ds/all_text_find.cc
+++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/all_text_find.cc
@@ -29,6 +29,8 @@
 // purpose. It is provided "as is" without express or implied
 // warranty.
 
+// { dg-additional-files "thirty_years_among_the_dead_preproc.txt" }
+
 /**
  * @file text_find_timing_test.cpp
  * Contains test for finding text.
diff --git 
a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find.hpp 
b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find.hpp
index 18e383ea17c6..dbaaf04a1b64 100644
--- a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find.hpp
+++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find.hpp
@@ -29,6 +29,8 @@
 // purpose. It is provided "as is" without express or implied
 // warranty.
 
+// { dg-additional-files "thirty_years_among_the_dead_preproc.txt" }
+
 /**
  * @file multimap_text_find_timing_test.cpp
  * Contains test for inserting text words.
diff --git 
a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert.hpp 
b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert.hpp
index 737be39a154b..2c86b52f30a2 100644
--- a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert.hpp
+++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert.hpp
@@ -29,6 +29,8 @@
 // purpose. It is provided "as is" without express or implied
 // warranty.
 
+// { dg-additional-files "thirty_years_among_the_dead_preproc.txt" }
+
 /**
  * @file multimap_text_insert_timing_test.cpp
  * Contains test for inserting text words.
diff --git 
a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_mem.hpp 
b/libstdc++-v3/testsuite/perf

[gcc r15-2249] libstdc++: Use dg-additional-files in some algorithm tests

2024-07-24 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:681417f7a0044b5603fa7d4db57c5aecc914fc8e

commit r15-2249-g681417f7a0044b5603fa7d4db57c5aecc914fc8e
Author: Jonathan Wakely 
Date:   Mon Jul 22 14:01:43 2024 +0100

libstdc++: Use dg-additional-files in some algorithm tests

Use the dg-additional-files directive to declare files that need to be
copied into the test's working directory. This is currently redundant
(as all .tst and .txt files are copied for all tests) but is a step
towards not copying all files.

libstdc++-v3/ChangeLog:

* testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc:
Use dg-additional-files.
* testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc:
Likewise.
* testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc:
Likewise.
* testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc:
Likewise.
* testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc:
Likewise.
* testsuite/25_algorithms/copy_n/istreambuf_iterator/deque.cc:
Likewise.
* testsuite/25_algorithms/find/istreambuf_iterators/char/2.cc:
Likewise.
* testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/2.cc:
Likewise.

Diff:
---
 .../testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc   | 1 +
 .../testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc| 1 +
 libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc  | 1 +
 .../testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc| 1 +
 libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc | 1 +
 libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/deque.cc | 1 +
 libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/char/2.cc | 1 +
 .../testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/2.cc   | 1 +
 8 files changed, 8 insertions(+)

diff --git 
a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc 
b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc
index 1a0635c0ccaa..c5414d4975dc 100644
--- 
a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc
+++ 
b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc
@@ -16,6 +16,7 @@
 // <http://www.gnu.org/licenses/>.
 
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_unformatted-1.txt" }
 
 #include 
 #include 
diff --git 
a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc
 
b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc
index 823e275da19f..c2fd748cbf09 100644
--- 
a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc
+++ 
b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc
@@ -16,6 +16,7 @@
 // <http://www.gnu.org/licenses/>.
 
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_unformatted-1.txt" }
 
 #include 
 #include 
diff --git 
a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc 
b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc
index 67888797047b..3d1c7c7595d8 100644
--- a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc
@@ -27,6 +27,7 @@
 #include 
 
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_unformatted-1.txt" }
 
 // In the occasion of libstdc++/25482
 void test01()
diff --git 
a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc 
b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc
index e1adccfdd216..8d380052313d 100644
--- a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc
@@ -18,6 +18,7 @@
 // <http://www.gnu.org/licenses/>.
 
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_unformatted-1.txt" }
 
 #include 
 #include 
diff --git 
a/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc 
b/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc
index 5179d78b455d..a437bedb420b 100644
--- a/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc
@@ -1,5 +1,6 @@
 // { dg-do run { target c++11 } }
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_unformatted-1.txt" }
 
 // Copyright (C) 2020-2024 Free Software Foundation, Inc.
 //
diff --git 
a/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/deque.cc 
b/libstdc++-v3/testsuite/25_algorithms/copy_n/

[gcc r15-2248] libstdc++: Add file-io-diff to replace @diff@ markup in I/O tests

2024-07-24 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:515da03a838db05443ebcc4c543a405bed764188

commit r15-2248-g515da03a838db05443ebcc4c543a405bed764188
Author: Jonathan Wakely 
Date:   Mon Jul 22 14:39:57 2024 +0100

libstdc++: Add file-io-diff to replace @diff@ markup in I/O tests

This adds a new dg-final action to compare two files after a test has
run, so that we can verify that fstream operations produce the expected
results. With this change, all uses of @diff@ that seem potentially
useful have been converted to actually compare the files and FAIL if
they differ.

The file-io-diff action can take two arguments naming the files to be
compared, or for convenience it can take a single string and will
compare STR.tst and STR.txt, as that's how it's commonly used.

Additionally, all remaining uses of @require@ are converted to
dg-additional-files directives, so that the TODO in libstdc++.exp can
be resolved.

libstdc++-v3/ChangeLog:

* testsuite/27_io/basic_filebuf/close/char/1.cc: Remove
@require@ and @diff@. Use dg-final file-io-diff action.
* testsuite/27_io/basic_istream/extractors_other/char/2.cc:
Likewise.
* testsuite/27_io/basic_istream/extractors_other/wchar_t/2.cc:
Likewise.
* testsuite/27_io/basic_istream/get/char/2.cc: Likewise.
* testsuite/27_io/basic_istream/get/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_istream/ignore/char/3.cc: Likewise.
* testsuite/27_io/basic_istream/ignore/wchar_t/3.cc: Likewise.
* testsuite/27_io/basic_istream/peek/char/6414.cc: Likewise.
* testsuite/27_io/basic_istream/peek/wchar_t/6414.cc: Likewise.
* testsuite/27_io/basic_istream/seekg/char/fstream.cc: Likewise.
* testsuite/27_io/basic_istream/seekg/wchar_t/fstream.cc:
Likewise.
* testsuite/27_io/basic_istream/tellg/char/fstream.cc: Likewise.
* testsuite/27_io/basic_istream/tellg/wchar_t/fstream.cc:
Likewise.
* testsuite/27_io/basic_ofstream/open/char/1.cc: Likewise.
* testsuite/27_io/basic_ostream/inserters_other/char/1.cc:
Likewise.
* testsuite/27_io/basic_ostream/inserters_other/wchar_t/1.cc:
Likewise.
* testsuite/27_io/ios_base/sync_with_stdio/1.cc: Likewise.
* testsuite/27_io/basic_ostream/inserters_other/char/2.cc:
Likewise. Check file positions.
* testsuite/27_io/basic_ostream/inserters_other/wchar_t/2.cc:
Likewise.
* testsuite/lib/libstdc++.exp (file-io-diff): New proc.

Diff:
---
 .../testsuite/27_io/basic_filebuf/close/char/1.cc  |  6 ++--
 .../27_io/basic_istream/extractors_other/char/2.cc |  9 --
 .../basic_istream/extractors_other/wchar_t/2.cc|  9 --
 .../testsuite/27_io/basic_istream/get/char/2.cc|  8 --
 .../testsuite/27_io/basic_istream/get/wchar_t/2.cc |  8 --
 .../testsuite/27_io/basic_istream/ignore/char/3.cc |  8 --
 .../27_io/basic_istream/ignore/wchar_t/3.cc|  8 --
 .../27_io/basic_istream/peek/char/6414.cc  |  9 --
 .../27_io/basic_istream/peek/wchar_t/6414.cc   |  9 --
 .../27_io/basic_istream/seekg/char/fstream.cc  | 10 +--
 .../27_io/basic_istream/seekg/wchar_t/fstream.cc   | 12 +---
 .../27_io/basic_istream/tellg/char/fstream.cc  | 10 +--
 .../27_io/basic_istream/tellg/wchar_t/fstream.cc   | 10 +--
 .../testsuite/27_io/basic_ofstream/open/char/1.cc  |  5 ++--
 .../27_io/basic_ostream/inserters_other/char/1.cc  |  8 --
 .../27_io/basic_ostream/inserters_other/char/2.cc  |  7 +++--
 .../basic_ostream/inserters_other/wchar_t/1.cc |  8 --
 .../basic_ostream/inserters_other/wchar_t/2.cc |  7 +++--
 .../testsuite/27_io/ios_base/sync_with_stdio/1.cc  |  5 ++--
 libstdc++-v3/testsuite/lib/libstdc++.exp   | 32 ++
 20 files changed, 131 insertions(+), 57 deletions(-)

diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc 
b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc
index e2b336a711d6..d9e9c53e3e6e 100644
--- a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc
@@ -15,14 +15,14 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// 27.8.1.3 filebuf member functions
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %-*.txt
+// C++98 27.8.1.3 filebuf member functions
 
 // various tests for filebuf::open() and filebuf::close() including
 // the non-portable functionality in the libstdc++-v3 IO library
 
 // { dg-require-fileio "" }
+// { dg-additional-files "filebuf_members-1.tst filebuf_members-1.txt" }
+// { dg-final { file-io-diff "filebuf_members-1" } }
 
 #include 
 #include 
diff --git 
a/libstd

[gcc r15-2247] libstdc++: Use dg-additional-files in some I/O tests

2024-07-24 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:687dc787d7523c46a9b5e1e9ac1062e44693dd3a

commit r15-2247-g687dc787d7523c46a9b5e1e9ac1062e44693dd3a
Author: Jonathan Wakely 
Date:   Mon Jul 22 14:01:43 2024 +0100

libstdc++: Use dg-additional-files in some I/O tests

Use the dg-additional-files directive to declare files that need to be
copied into the test's working directory. This is currently redundant
(as all .tst and .txt files are copied for all tests) but is a step
towards not copying all files.

libstdc++-v3/ChangeLog:

* testsuite/27_io/basic_filebuf/imbue/char/2.cc: Use
dg-additional-files.
* testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_filebuf/open/char/path.cc: Likewise.
* testsuite/27_io/basic_filebuf/pbackfail/char/9761.cc:
Likewise.
* testsuite/27_io/basic_filebuf/seekoff/char/3-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekoff/char/3-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekpos/char/3-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekpos/char/3-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/setbuf/char/1.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetn/char/3.cc: Likewise.
* testsuite/27_io/basic_filebuf/underflow/10096.cc: Likewise.
* testsuite/27_io/basic_fstream/cons/char/path.cc: Likewise.
* testsuite/27_io/basic_fstream/open/char/path.cc: Likewise.
* testsuite/27_io/basic_ifstream/assign/1.cc: Likewise.
* testsuite/27_io/basic_ifstream/cons/move.cc: Likewise.
* testsuite/27_io/basic_ifstream/cons/char/path.cc: Likewise.
* testsuite/27_io/basic_ifstream/open/char/path.cc: Likewise.
* testsuite/27_io/basic_ifstream/open/wchar_t/1.cc: Likewise.
* testsuite/27_io/objects/char/10.cc: Likewise.
* testsuite/27_io/objects/char/12048-1.cc: Likewise.
* testsuite/27_io/objects/char/12048-2.cc: Likewise.
* testsuite/27_io/objects/char/12048-3.cc: Likewise.
* testsuite/27_io/objects/char/12048-4.cc: Likewise.
* testsuite/27_io/objects/char/12048-5.cc: Likewise.
* testsuite/27_io/objects/wchar_t/12048-1.cc: Likewise.
* testsuite/27_io/objects/wchar_t/12048-2.cc: Likewise.
* testsuite/27_io/objects/wchar_t/12048-3.cc: Likewise.
* testsuite/27_io/objects/wchar_t/12048-4.cc: Likewise.
* testsuite/27_io/objects/wchar_t/12048-5.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/char/12048-1.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/char/12048-2.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/char/12048-3.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/char/12048-4.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-1.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-2.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-3.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-4.cc: Likewise.

Diff:
---
 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/2.cc| 4 +++-
 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc | 1 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/path.cc  | 1 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/pbackfail/char/9761.cc | 1 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-in.cc   | 3 ++-
 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-io.cc   | 3 ++-
 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/3-in.cc   | 1 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/3-io.cc   | 1 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/1.cc   | 1 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/3.cc| 1 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/10096.cc | 1 +
 libstdc++-v3/testsuite/27_io/basic_fstream/cons/char/path.cc  | 1 +
 libstdc++-v3/testsuite/27_io/basic_fstream/open/char/path.cc  | 1 +
 libstdc++-v3/testsuite/27_io/basic_ifstream/assign/1.cc   | 3 ++-
 libstdc++-v3/testsuite/27_io/basic_ifstream/cons/char/path.cc | 1 +
 libstdc++-v3/testsuite/27_io/basic_ifstream/cons/move.cc  | 3 ++-
 libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/path.cc | 1 +
 libstdc++-v3/testsuite/27_io/basic_ifstream/open/wchar_t/1.cc | 3 ++-
 libstdc++-v3/testsuite/27_io/objects/char/10.cc   | 1 +
 libstdc++-v3/testsuite/27_io/objects/char/12048-1.cc  | 1 +
 libstdc++-v3/testsuite/27_io/objects/char/12048-2.cc  | 1 +
 libstdc++-v3/testsuite/27_io/objects/char/12048-3.cc  | 1 +
 libstdc++-v3/testsuite/27_io/objects/char/12048-4.cc  | 1 +
 libstdc++-v3/testsuite/27_io/objects/char/12048-5.cc

[gcc r15-2246] libstdc++: Replace @require@ markup in some I/O tests

2024-07-24 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:dfd07532693c7df9e15920b7607672382122b38c

commit r15-2246-gdfd07532693c7df9e15920b7607672382122b38c
Author: Jonathan Wakely 
Date:   Wed Jul 17 13:27:19 2024 +0100

libstdc++: Replace @require@ markup in some I/O tests

We can replace the @require@ markup with { dg-additional-files ... }
directives, so that the required files are explicitly named and are
explicitly copied into place for tests that require it. This will allow
a later change to remove the "Copy all required data files" step in the
proc libstdc++_init in testsuite/lib/libstdc++.exp that is marked TODO.
This commit uses dg-additional-files for a subset of the files that
contain @require@.

Also remove the @diff@ markup where appears to be copy & pasted from
other test files, and so serves no purpose. For example, there is no
output file created by 27_io/basic_ifstream/cons/char/1.cc so there is
nothing for @diff@ to compare. Maybe the purpose was to check that
reading the .tst file with an ifstream doesn't change it, but we've
survived without doing those comparisons for many years so I think we
can remove those cases of @diff@ markup.

libstdc++-v3/ChangeLog:

* testsuite/27_io/basic_filebuf/close/char/2.cc: Remove
@require@ and @diff@ markup. Use dg-additional-files. Remove
unused variable.
* testsuite/27_io/basic_filebuf/close/char/3.cc: Remove
@require@ and @diff@ markup. Use dg-additional-files.
* testsuite/27_io/basic_filebuf/close/char/4.cc: Likewise.
* testsuite/27_io/basic_filebuf/close/char/5.cc: Likewise.
* testsuite/27_io/basic_filebuf/in_avail/char/1.cc: Likewise.
* testsuite/27_io/basic_filebuf/is_open/char/1.cc: Likewise.
* testsuite/27_io/basic_filebuf/open/char/1.cc: Likewise.
* testsuite/27_io/basic_filebuf/open/char/2.cc: Likewise.
* testsuite/27_io/basic_filebuf/sbumpc/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sbumpc/char/1-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sbumpc/char/2-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sbumpc/char/2-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekoff/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekoff/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekoff/char/2-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekoff/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekpos/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekpos/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekpos/char/2-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekpos/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetc/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetc/char/1-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetc/char/2-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetc/char/2-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetn/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetn/char/1-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetn/char/2-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetn/char/2-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/snextc/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/snextc/char/1-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/snextc/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/snextc/char/2-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/snextc/char/2-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputbackc/char/1-in.cc:
Likewise.
* testsuite/27_io/basic_filebuf/sputbackc/char/2-in.cc:
Likewise.
* testsuite/27_io/basic_filebuf/sputc/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputc/char/2-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputc/char/2-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputn/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputn/char/1-io.cc: Likewise.
Remove unused variable.
* testsuite/27_io/basic_filebuf/sputn/char/2-in.cc: Remove
@require@ and @diff@ markup. Use dg-additional-files.
* testsuite/27_io/basic_filebuf/sungetc/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sungetc/char/2-in.cc: Likewise.
* testsuite/27_io/basic_ifstream/cons/char/1.cc: Likewise.
* testsuite/27_io/basic_ifstream/open/char/1.cc: Likewise.
* testsuite/27_io/basic_ifstream/rdbuf/char/2832.cc: Likewise.
* testsuite/27_io

[gcc r15-2245] libstdc++: Clean up @diff@ markup in some I/O tests

2024-07-24 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:3216b131656f3056dae587584ad2104cc659aecd

commit r15-2245-g3216b131656f3056dae587584ad2104cc659aecd
Author: Jonathan Wakely 
Date:   Mon Jul 22 13:00:26 2024 +0100

libstdc++: Clean up @diff@ markup in some I/O tests

We have a number of 27_io/* tests with comments like this:

// @require@ %-*.tst
// @diff@ %-*.tst %-*.txt

It seems that these declare required data files used by the test and a
post-test action to compare the test output with the expected result.
We do have tests that depend on some *.tst and/or *.txt files that are
copied from testsuite/data into each test's working directory before it
runs, so the comments are related to those dependencies.  However,
nothing in the current test framework actually makes use of these
comments. Currently, every test gets a fresh copy of every *.tst and
*.txt file in the testsuite/data directory, whether the test actually
requires them or not.

This change is the first in a series to clean up this unused markup in
the tests. This first step is to just remove all @require@ and @diff@
comments where they seem to serve no purpose at all. These tests do not
open any of the *.tst or *.txt files that are copied into the test's
working directory from the testsuite/data directory, so they don't
"require" any of those files, and there's no need to "diff" them after
the test runs.

libstdc++-v3/ChangeLog:

* testsuite/27_io/basic_filebuf/close/char/4879.cc: Remove
@require@ and @diff@ comments.
* testsuite/27_io/basic_filebuf/close/char/9964.cc: Likewise.
* testsuite/27_io/basic_filebuf/open/char/3.cc: Likewise.
* testsuite/27_io/basic_filebuf/open/char/9507.cc: Likewise.
* testsuite/27_io/basic_filebuf/sbumpc/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sbumpc/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetc/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetc/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetn/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetn/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/snextc/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputbackc/char/1-io.cc:
Likewise.
* testsuite/27_io/basic_filebuf/sputbackc/char/1-out.cc:
Likewise.
* testsuite/27_io/basic_filebuf/sputbackc/char/2-io.cc:
Likewise.
* testsuite/27_io/basic_filebuf/sputbackc/char/2-out.cc:
Likewise.
* testsuite/27_io/basic_filebuf/sputc/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputc/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputn/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputn/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sungetc/char/1-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sungetc/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sungetc/char/2-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sungetc/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputc/char/1-io.cc: Likewise.
Remove unused variable.
* testsuite/27_io/basic_filebuf/sputn/char/2-io.cc: Likewise.
* testsuite/27_io/basic_ofstream/cons/char/1.cc: Remove
@require@ and @diff@ comments. Remove unused variables.
* testsuite/27_io/basic_ofstream/rdbuf/char/2832.cc: Remove
* testsuite/27_io/ios_base/sync_with_stdio/2.cc: Likewise.

Diff:
---
 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4879.cc  |  4 +---
 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/9964.cc  |  4 +---
 libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/3.cc  |  4 +---
 libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/9507.cc   |  4 +---
 .../testsuite/27_io/basic_filebuf/sbumpc/char/1-out.cc |  5 +
 .../testsuite/27_io/basic_filebuf/sbumpc/char/2-out.cc |  5 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-out.cc |  5 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-out.cc |  5 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-out.cc |  5 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-out.cc |  5 +
 .../testsuite/27_io/basic_filebuf/snextc/char/2-out.cc |  5 +
 .../testsuite/27_io/basic_filebuf/sputbackc/char/1-io.cc   |  5 +
 .../testsuite/27_io/basic_filebuf/sputbackc/char/1-out.cc  |  5 +
 .../testsuite/27_io/basic_filebuf/sputbackc/char/2-io.cc   |  5 +
 .../testsuite/27_io/basic_filebuf/sputbackc/char/2-out.cc  |  5 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/sput

Re: why are these std::set iterators of different type when compiling with -D_GLIBCXX_DEBUG

2024-07-24 Thread Jonathan Wakely via Gcc
On Wed, 24 Jul 2024 at 11:38, Dennis Luehring via Gcc  wrote:
>
> using latest gcc/STL
>
> -
> #include 
>
> using int_set1 = std::set>;
> using int_set2 = std::set;
>
> static_assert(std::is_same());
> -
>
>
> the two iterators are equal when not using _GLIBCXX_DEBUG but become
> different when using the define?

Your question belongs on either the libstdc++ or gcc-help mailing
list, not here. This list is for discussing development of GCC itself,
not help using it.

The standard says it's unspecified whether those types are the same,
so portable code should not assume they are/aren't the same. I don't
know for sure, but I assume somebody thought that making them
different was helpful to avoid non-portable code.


Re: [PATCH] libstdc++: Remove duplicate include header from ranges_algobase.h

2024-07-23 Thread Jonathan Wakely
On Mon, 22 Jul 2024 at 20:53, Michael Levine wrote:
>
> The bits/stl_algobase.h header was added to bits/ranges_algobase.h separately 
> through two related commits:
>
> https://github.com/gcc-mirror/gcc/commit/674d213ab91871652e96dc2de06e6f50682eebe0
>
> https://github.com/gcc-mirror/gcc/commit/0bb1db32ccf54a9de59bea718f7575f7ef22abf5
>
> The comment for the first time it is included in the file is also incorrect 
> (my error from that 2nd PR) since it is really being included for __memcmp, 
> not __memcpy

Oops, I thought I'd fixed that when I applied your patch.

> This patch removes the duplicate header include.

Thanks, I'll push this today.



[gcc r14-10503] libstdc++: Use [[maybe_unused]] attribute in src/c++23/print.cc

2024-07-23 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:b41487a883282b28a136fa16e1d941e14dae

commit r14-10503-gb41487a883282b28a136fa16e1d941e14dae
Author: Jonathan Wakely 
Date:   Tue Jul 23 10:08:52 2024 +0100

libstdc++: Use [[maybe_unused]] attribute in src/c++23/print.cc

This avoids some warnings when the preprocessor conditions are not met.

libstdc++-v3/ChangeLog:

* src/c++23/print.cc (__open_terminal): Use [[maybe_unused]] on
parameter.

(cherry picked from commit b40156d69153364315e071dc968227ce1c3bd2a8)

Diff:
---
 libstdc++-v3/src/c++23/print.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/src/c++23/print.cc b/libstdc++-v3/src/c++23/print.cc
index 558dc149d125..8ba714059672 100644
--- a/libstdc++-v3/src/c++23/print.cc
+++ b/libstdc++-v3/src/c++23/print.cc
@@ -67,7 +67,7 @@ namespace
   // This returns intptr_t that is either a Windows HANDLE
   // or 1 + a POSIX file descriptor. A zero return indicates failure.
   void*
-  __open_terminal(FILE* f)
+  __open_terminal([[maybe_unused]] FILE* f)
   {
 #ifndef _GLIBCXX_USE_STDIO_PURE
 if (f)
@@ -85,7 +85,7 @@ namespace
   }
 
   void*
-  __open_terminal(std::streambuf* sb)
+  __open_terminal([[maybe_unused]] std::streambuf* sb)
   {
 #if ! defined _GLIBCXX_USE_STDIO_PURE && defined __cpp_rtti
 using namespace __gnu_cxx;


[gcc r14-10502] libstdc++: Do not use isatty on avr [PR115482]

2024-07-23 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:5fad8874300ef67c577cc204e339dca6bca15467

commit r14-10502-g5fad8874300ef67c577cc204e339dca6bca15467
Author: Detlef Vollmann 
Date:   Tue Jul 23 09:25:22 2024 +0100

libstdc++: Do not use isatty on avr [PR115482]

avrlibc has an incomplete unistd.h that doesn't have isatty.
So building libstdc++ fails when compiling c++23/print.cc.
As a workaround I added a check for AVR.

libstdc++-v3/ChangeLog:

PR libstdc++/115482
* src/c++23/print.cc (__open_terminal) [__AVR__]: Do not use
isatty.

(cherry picked from commit 8439405e38c56b774cf3c65bdafae5f9e11d470a)

Diff:
---
 libstdc++-v3/src/c++23/print.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/src/c++23/print.cc b/libstdc++-v3/src/c++23/print.cc
index 99a19cd45002..558dc149d125 100644
--- a/libstdc++-v3/src/c++23/print.cc
+++ b/libstdc++-v3/src/c++23/print.cc
@@ -75,7 +75,7 @@ namespace
 #ifdef _WIN32
if (int fd = ::_fileno(f); fd >= 0)
  return check_for_console((void*)_get_osfhandle(fd));
-#elifdef _GLIBCXX_HAVE_UNISTD_H
+#elif defined _GLIBCXX_HAVE_UNISTD_H && ! defined __AVR__
if (int fd = (::fileno)(f); fd >= 0 && ::isatty(fd))
  return f;
 #endif
@@ -100,7 +100,7 @@ namespace
 #ifdef _WIN32
 if (auto fb = dynamic_cast(sb))
   return check_for_console(fb->native_handle());
-#elifdef _GLIBCXX_HAVE_UNISTD_H
+#elif defined _GLIBCXX_HAVE_UNISTD_H && ! defined __AVR__
 if (auto fb = dynamic_cast(sb))
   if (int fd = fb->native_handle(); fd >= 0 && ::isatty(fd))
return ::fdopen(::dup(fd), "w"); // Caller must call fclose.


[committed] libstdc++: Use [[maybe_unused]] attribute in src/c++23/print.cc

2024-07-23 Thread Jonathan Wakely
Tested x86_64-linux, built on avr.

Pushed to trunk.

-- >8 --

This avoids some warnings when the preprocessor conditions are not met.

libstdc++-v3/ChangeLog:

* src/c++23/print.cc (__open_terminal): Use [[maybe_unused]] on
parameter.
---
 libstdc++-v3/src/c++23/print.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/src/c++23/print.cc b/libstdc++-v3/src/c++23/print.cc
index 558dc149d12..8ba71405967 100644
--- a/libstdc++-v3/src/c++23/print.cc
+++ b/libstdc++-v3/src/c++23/print.cc
@@ -67,7 +67,7 @@ namespace
   // This returns intptr_t that is either a Windows HANDLE
   // or 1 + a POSIX file descriptor. A zero return indicates failure.
   void*
-  __open_terminal(FILE* f)
+  __open_terminal([[maybe_unused]] FILE* f)
   {
 #ifndef _GLIBCXX_USE_STDIO_PURE
 if (f)
@@ -85,7 +85,7 @@ namespace
   }
 
   void*
-  __open_terminal(std::streambuf* sb)
+  __open_terminal([[maybe_unused]] std::streambuf* sb)
   {
 #if ! defined _GLIBCXX_USE_STDIO_PURE && defined __cpp_rtti
 using namespace __gnu_cxx;
-- 
2.45.2



[committed] libstdc++: Do not use isatty on avr [PR115482]

2024-07-23 Thread Jonathan Wakely
I'm pushing this workaround from Detlef.

I incorrectly assumed that  is enough to ensure isatty is
present, but that isn't true for avr-libc.

It might be cleaner to add a proper autoconf check for isatty and dup,
but we don't have any reports of it failing for other targets. This
simple workaround solves the immediate problem in time for the 14.2
release.

Apart from using __write_to_terminal in the 27_io/print/2.cc test, the
functions in this file are not actually used for non-Windows targets. As
long as they compile and don't break the build, that's good enough.

Tested x86_64-linux, built on avr and mingw-w64.

Pushed to trunk, gcc-14 backport when testing finishes.

-- >8 --

avrlibc has an incomplete unistd.h that doesn't have isatty.
So building libstdc++ fails when compiling c++23/print.cc.
As a workaround I added a check for AVR.

libstdc++-v3/ChangeLog:

PR libstdc++/115482
* src/c++23/print.cc (__open_terminal) [__AVR__]: Do not use
isatty.
---
 libstdc++-v3/src/c++23/print.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/src/c++23/print.cc b/libstdc++-v3/src/c++23/print.cc
index 99a19cd4500..558dc149d12 100644
--- a/libstdc++-v3/src/c++23/print.cc
+++ b/libstdc++-v3/src/c++23/print.cc
@@ -75,7 +75,7 @@ namespace
 #ifdef _WIN32
if (int fd = ::_fileno(f); fd >= 0)
  return check_for_console((void*)_get_osfhandle(fd));
-#elifdef _GLIBCXX_HAVE_UNISTD_H
+#elif defined _GLIBCXX_HAVE_UNISTD_H && ! defined __AVR__
if (int fd = (::fileno)(f); fd >= 0 && ::isatty(fd))
  return f;
 #endif
@@ -100,7 +100,7 @@ namespace
 #ifdef _WIN32
 if (auto fb = dynamic_cast(sb))
   return check_for_console(fb->native_handle());
-#elifdef _GLIBCXX_HAVE_UNISTD_H
+#elif defined _GLIBCXX_HAVE_UNISTD_H && ! defined __AVR__
 if (auto fb = dynamic_cast(sb))
   if (int fd = fb->native_handle(); fd >= 0 && ::isatty(fd))
return ::fdopen(::dup(fd), "w"); // Caller must call fclose.
-- 
2.45.2



[gcc r15-2222] libstdc++: Use [[maybe_unused]] attribute in src/c++23/print.cc

2024-07-23 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:b40156d69153364315e071dc968227ce1c3bd2a8

commit r15--gb40156d69153364315e071dc968227ce1c3bd2a8
Author: Jonathan Wakely 
Date:   Tue Jul 23 10:08:52 2024 +0100

libstdc++: Use [[maybe_unused]] attribute in src/c++23/print.cc

This avoids some warnings when the preprocessor conditions are not met.

libstdc++-v3/ChangeLog:

* src/c++23/print.cc (__open_terminal): Use [[maybe_unused]] on
parameter.

Diff:
---
 libstdc++-v3/src/c++23/print.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/src/c++23/print.cc b/libstdc++-v3/src/c++23/print.cc
index 558dc149d125..8ba714059672 100644
--- a/libstdc++-v3/src/c++23/print.cc
+++ b/libstdc++-v3/src/c++23/print.cc
@@ -67,7 +67,7 @@ namespace
   // This returns intptr_t that is either a Windows HANDLE
   // or 1 + a POSIX file descriptor. A zero return indicates failure.
   void*
-  __open_terminal(FILE* f)
+  __open_terminal([[maybe_unused]] FILE* f)
   {
 #ifndef _GLIBCXX_USE_STDIO_PURE
 if (f)
@@ -85,7 +85,7 @@ namespace
   }
 
   void*
-  __open_terminal(std::streambuf* sb)
+  __open_terminal([[maybe_unused]] std::streambuf* sb)
   {
 #if ! defined _GLIBCXX_USE_STDIO_PURE && defined __cpp_rtti
 using namespace __gnu_cxx;


[gcc r15-2221] libstdc++: Do not use isatty on avr [PR115482]

2024-07-23 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:8439405e38c56b774cf3c65bdafae5f9e11d470a

commit r15-2221-g8439405e38c56b774cf3c65bdafae5f9e11d470a
Author: Detlef Vollmann 
Date:   Tue Jul 23 09:25:22 2024 +0100

libstdc++: Do not use isatty on avr [PR115482]

avrlibc has an incomplete unistd.h that doesn't have isatty.
So building libstdc++ fails when compiling c++23/print.cc.
As a workaround I added a check for AVR.

libstdc++-v3/ChangeLog:

PR libstdc++/115482
* src/c++23/print.cc (__open_terminal) [__AVR__]: Do not use
isatty.

Diff:
---
 libstdc++-v3/src/c++23/print.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/src/c++23/print.cc b/libstdc++-v3/src/c++23/print.cc
index 99a19cd45002..558dc149d125 100644
--- a/libstdc++-v3/src/c++23/print.cc
+++ b/libstdc++-v3/src/c++23/print.cc
@@ -75,7 +75,7 @@ namespace
 #ifdef _WIN32
if (int fd = ::_fileno(f); fd >= 0)
  return check_for_console((void*)_get_osfhandle(fd));
-#elifdef _GLIBCXX_HAVE_UNISTD_H
+#elif defined _GLIBCXX_HAVE_UNISTD_H && ! defined __AVR__
if (int fd = (::fileno)(f); fd >= 0 && ::isatty(fd))
  return f;
 #endif
@@ -100,7 +100,7 @@ namespace
 #ifdef _WIN32
 if (auto fb = dynamic_cast(sb))
   return check_for_console(fb->native_handle());
-#elifdef _GLIBCXX_HAVE_UNISTD_H
+#elif defined _GLIBCXX_HAVE_UNISTD_H && ! defined __AVR__
 if (auto fb = dynamic_cast(sb))
   if (int fd = fb->native_handle(); fd >= 0 && ::isatty(fd))
return ::fdopen(::dup(fd), "w"); // Caller must call fclose.


[PATCH 7/8] libstdc++: Stop copying all data files into test directory

2024-07-22 Thread Jonathan Wakely
Tested x86_64-linux.

-- >8 --

This removes the TODO in libstdc++_init, so that we don't copy all *.tst
and *.txt files from testsuite/data into every test's working directory.
Instead, only the necessary files declared with dg-additional-files are
copied.

libstdc++-v3/ChangeLog:

* testsuite/lib/libstdc++.exp (libstdc++_init): Do not copy all
data files into test directory.
---
 libstdc++-v3/testsuite/lib/libstdc++.exp | 5 -
 1 file changed, 5 deletions(-)

diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp 
b/libstdc++-v3/testsuite/lib/libstdc++.exp
index ef511949c7b..4bf88e72d05 100644
--- a/libstdc++-v3/testsuite/lib/libstdc++.exp
+++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
@@ -158,11 +158,6 @@ proc libstdc++_init { testfile } {
 global dg-do-what-default
 set dg-do-what-default run
 
-# Copy all required data files.
-# TODO: Use dg-additional-files in individual tests instead of doing this.
-v3-copy-files [glob -nocomplain "$srcdir/data/*.tst"]
-v3-copy-files [glob -nocomplain "$srcdir/data/*.txt"]
-
 set ld_library_path_tmp ""
 
 # Locate libgcc.a so we don't need to account for different values of
-- 
2.45.2



[PATCH 1/8] libstdc++: Clean up @diff@ markup in some I/O tests

2024-07-22 Thread Jonathan Wakely
Tested x86_64-linux.

-- >8 --

We have a number of 27_io/* tests with comments like this:

// @require@ %-*.tst
// @diff@ %-*.tst %-*.txt

It seems that these declare required data files used by the test and a
post-test action to compare the test output with the expected result.
We do have tests that depend on some *.tst and/or *.txt files that are
copied from testsuite/data into each test's working directory before it
runs, so the comments are related to those dependencies.  However,
nothing in the current test framework actually makes use of these
comments. Currently, every test gets a fresh copy of every *.tst and
*.txt file in the testsuite/data directory, whether the test actually
requires them or not.

This change is the first in a series to clean up this unused markup in
the tests. This first step is to just remove all @require@ and @diff@
comments where they seem to serve no purpose at all. These tests do not
open any of the *.tst or *.txt files that are copied into the test's
working directory from the testsuite/data directory, so they don't
"require" any of those files, and there's no need to "diff" them after
the test runs.

libstdc++-v3/ChangeLog:

* testsuite/27_io/basic_filebuf/close/char/4879.cc: Remove
@require@ and @diff@ comments.
* testsuite/27_io/basic_filebuf/close/char/9964.cc: Likewise.
* testsuite/27_io/basic_filebuf/open/char/3.cc: Likewise.
* testsuite/27_io/basic_filebuf/open/char/9507.cc: Likewise.
* testsuite/27_io/basic_filebuf/sbumpc/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sbumpc/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetc/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetc/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetn/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetn/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/snextc/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputbackc/char/1-io.cc:
Likewise.
* testsuite/27_io/basic_filebuf/sputbackc/char/1-out.cc:
Likewise.
* testsuite/27_io/basic_filebuf/sputbackc/char/2-io.cc:
Likewise.
* testsuite/27_io/basic_filebuf/sputbackc/char/2-out.cc:
Likewise.
* testsuite/27_io/basic_filebuf/sputc/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputc/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputn/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputn/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sungetc/char/1-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sungetc/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sungetc/char/2-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sungetc/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputc/char/1-io.cc: Likewise.
Remove unused variable.
* testsuite/27_io/basic_filebuf/sputn/char/2-io.cc: Likewise.
* testsuite/27_io/basic_ofstream/cons/char/1.cc: Remove
@require@ and @diff@ comments. Remove unused variables.
* testsuite/27_io/basic_ofstream/rdbuf/char/2832.cc: Remove
* testsuite/27_io/ios_base/sync_with_stdio/2.cc: Likewise.
---
 .../testsuite/27_io/basic_filebuf/close/char/4879.cc   |  4 +---
 .../testsuite/27_io/basic_filebuf/close/char/9964.cc   |  4 +---
 .../testsuite/27_io/basic_filebuf/open/char/3.cc   |  4 +---
 .../testsuite/27_io/basic_filebuf/open/char/9507.cc|  4 +---
 .../testsuite/27_io/basic_filebuf/sbumpc/char/1-out.cc |  5 +
 .../testsuite/27_io/basic_filebuf/sbumpc/char/2-out.cc |  5 +
 .../testsuite/27_io/basic_filebuf/sgetc/char/1-out.cc  |  5 +
 .../testsuite/27_io/basic_filebuf/sgetc/char/2-out.cc  |  5 +
 .../testsuite/27_io/basic_filebuf/sgetn/char/1-out.cc  |  5 +
 .../testsuite/27_io/basic_filebuf/sgetn/char/2-out.cc  |  5 +
 .../testsuite/27_io/basic_filebuf/snextc/char/2-out.cc |  5 +
 .../27_io/basic_filebuf/sputbackc/char/1-io.cc |  5 +
 .../27_io/basic_filebuf/sputbackc/char/1-out.cc|  5 +
 .../27_io/basic_filebuf/sputbackc/char/2-io.cc |  5 +
 .../27_io/basic_filebuf/sputbackc/char/2-out.cc|  5 +
 .../testsuite/27_io/basic_filebuf/sputc/char/1-io.cc   |  6 +-
 .../testsuite/27_io/basic_filebuf/sputc/char/1-out.cc  |  5 +
 .../testsuite/27_io/basic_filebuf/sputc/char/2-out.cc  |  5 +
 .../testsuite/27_io/basic_filebuf/sputn/char/1-out.cc  |  5 +
 .../testsuite/27_io/basic_filebuf/sputn/char/2-io.cc   |  6 +-
 .../testsuite/27_io/basic_filebuf/sputn/char/2-out.cc  |  5 +
 .../testsuite/27_io/basic_filebuf/sungetc/char/1-io.cc |  3 ---
 .../27_io/basic_filebuf/sungetc/char/1-out.cc  |  3 ---
 .../testsuite/27_io/basic_filebuf/sungetc/char/2-io.cc |  3 ---
 .../27_io/basic_filebuf/sungetc/char/2-out.cc  |  3 ---

[PATCH 5/8] libstdc++: Use dg-additional-files in some algorithm tests

2024-07-22 Thread Jonathan Wakely
Tested x86_64-linux.

-- >8 --

Use the dg-additional-files directive to declare files that need to be
copied into the test's working directory. This is currently redundant
(as all .tst and .txt files are copied for all tests) but is a step
towards not copying all files.

libstdc++-v3/ChangeLog:

* testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc:
Use dg-additional-files.
* testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc:
Likewise.
* testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc:
Likewise.
* testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc:
Likewise.
* testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc:
Likewise.
* testsuite/25_algorithms/copy_n/istreambuf_iterator/deque.cc:
Likewise.
* testsuite/25_algorithms/find/istreambuf_iterators/char/2.cc:
Likewise.
* testsuite/25_algorithms/find/istreambuf_iterators/wchar_t/2.cc:
Likewise.
---
 .../25_algorithms/advance/istreambuf_iterators/char/2.cc | 1 +
 .../25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc  | 1 +
 .../testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc   | 1 +
 .../25_algorithms/copy/streambuf_iterators/wchar_t/4.cc  | 1 +
 .../testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc  | 1 +
 .../testsuite/25_algorithms/copy_n/istreambuf_iterator/deque.cc  | 1 +
 .../testsuite/25_algorithms/find/istreambuf_iterators/char/2.cc  | 1 +
 .../25_algorithms/find/istreambuf_iterators/wchar_t/2.cc | 1 +
 8 files changed, 8 insertions(+)

diff --git 
a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc 
b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc
index 1a0635c0cca..c5414d4975d 100644
--- 
a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc
+++ 
b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc
@@ -16,6 +16,7 @@
 // .
 
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_unformatted-1.txt" }
 
 #include 
 #include 
diff --git 
a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc
 
b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc
index 823e275da19..c2fd748cbf0 100644
--- 
a/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc
+++ 
b/libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/wchar_t/2.cc
@@ -16,6 +16,7 @@
 // .
 
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_unformatted-1.txt" }
 
 #include 
 #include 
diff --git 
a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc 
b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc
index 67888797047..3d1c7c7595d 100644
--- a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc
@@ -27,6 +27,7 @@
 #include 
 
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_unformatted-1.txt" }
 
 // In the occasion of libstdc++/25482
 void test01()
diff --git 
a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc 
b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc
index e1adccfdd21..8d380052313 100644
--- a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/wchar_t/4.cc
@@ -18,6 +18,7 @@
 // .
 
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_unformatted-1.txt" }
 
 #include 
 #include 
diff --git 
a/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc 
b/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc
index 5179d78b455..a437bedb420 100644
--- a/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc
@@ -1,5 +1,6 @@
 // { dg-do run { target c++11 } }
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_unformatted-1.txt" }
 
 // Copyright (C) 2020-2024 Free Software Foundation, Inc.
 //
diff --git 
a/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/deque.cc 
b/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/deque.cc
index 14f58998fef..1353282f6a0 100644
--- a/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/deque.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/deque.cc
@@ -1,5 +1,6 @@
 // { dg-do run { target c++11 } }
 // { dg-require-fileio "" }
+// { dg-additional-files "istream_unformatted-1.txt" }
 
 // Copyright (C) 2020-2024 Free Software Foundation, Inc.
 //
diff --git 
a/libstdc++-v3/testsuite/25_algorithms/find/istreambuf_iterators/char/2.cc 

[PATCH 2/8] libstdc++: Replace @require@ markup in some I/O tests

2024-07-22 Thread Jonathan Wakely
Tested x86_64-linux.

-- >8 --

We can replace the @require@ markup with { dg-additional-files ... }
directives, so that the required files are explicitly named and are
explicitly copied into place for tests that require it. This will allow
a later change to remove the "Copy all required data files" step in the
proc libstdc++_init in testsuite/lib/libstdc++.exp that is marked TODO.
This commit uses dg-additional-files for a subset of the files that
contain @require@.

Also remove the @diff@ markup where appears to be copy & pasted from
other test files, and so serves no purpose. For example, there is no
output file created by 27_io/basic_ifstream/cons/char/1.cc so there is
nothing for @diff@ to compare. Maybe the purpose was to check that
reading the .tst file with an ifstream doesn't change it, but we've
survived without doing those comparisons for many years so I think we
can remove those cases of @diff@ markup.

libstdc++-v3/ChangeLog:

* testsuite/27_io/basic_filebuf/close/char/2.cc: Remove
@require@ and @diff@ markup. Use dg-additional-files. Remove
unused variable.
* testsuite/27_io/basic_filebuf/close/char/3.cc: Remove
@require@ and @diff@ markup. Use dg-additional-files.
* testsuite/27_io/basic_filebuf/close/char/4.cc: Likewise.
* testsuite/27_io/basic_filebuf/close/char/5.cc: Likewise.
* testsuite/27_io/basic_filebuf/in_avail/char/1.cc: Likewise.
* testsuite/27_io/basic_filebuf/is_open/char/1.cc: Likewise.
* testsuite/27_io/basic_filebuf/open/char/1.cc: Likewise.
* testsuite/27_io/basic_filebuf/open/char/2.cc: Likewise.
* testsuite/27_io/basic_filebuf/sbumpc/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sbumpc/char/1-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sbumpc/char/2-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sbumpc/char/2-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekoff/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekoff/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekoff/char/2-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekoff/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekpos/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekpos/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekpos/char/2-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekpos/char/2-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetc/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetc/char/1-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetc/char/2-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetc/char/2-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetn/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetn/char/1-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetn/char/2-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetn/char/2-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/snextc/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/snextc/char/1-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/snextc/char/1-out.cc: Likewise.
* testsuite/27_io/basic_filebuf/snextc/char/2-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/snextc/char/2-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputbackc/char/1-in.cc:
Likewise.
* testsuite/27_io/basic_filebuf/sputbackc/char/2-in.cc:
Likewise.
* testsuite/27_io/basic_filebuf/sputc/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputc/char/2-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputc/char/2-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputn/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sputn/char/1-io.cc: Likewise.
Remove unused variable.
* testsuite/27_io/basic_filebuf/sputn/char/2-in.cc: Remove
@require@ and @diff@ markup. Use dg-additional-files.
* testsuite/27_io/basic_filebuf/sungetc/char/1-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/sungetc/char/2-in.cc: Likewise.
* testsuite/27_io/basic_ifstream/cons/char/1.cc: Likewise.
* testsuite/27_io/basic_ifstream/open/char/1.cc: Likewise.
* testsuite/27_io/basic_ifstream/rdbuf/char/2832.cc: Likewise.
* testsuite/27_io/basic_istream/readsome/char/6746-2.cc:
Likewise.
* testsuite/27_io/basic_istream/readsome/wchar_t/6746-2.cc:
Likewise.
* testsuite/27_io/basic_istream/seekg/char/sstream.cc: Likewise.
* testsuite/27_io/basic_istream/seekg/wchar_t/sstream.cc:
Likewise.
* testsuite/27_io/basic_istream/tellg/char/1.cc: Likewise.
* testsuite/27_io/basic_istream/tellg/char/sstream.cc: Likewise.
* testsuite/27_io/basic_istream/tellg/wchar_t/1.cc: Likewise.
* 

[PATCH 8/8] libstdc++: Rename tests [PR12048]

2024-07-22 Thread Jonathan Wakely
Tested x86_64-linux.

-- >8 --

These have the wrong PR number in the filenames.

libstdc++-v3/ChangeLog:

PR libstdc++/12048
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-1.cc: Move to...
* testsuite/ext/stdio_sync_filebuf/wchar_t/12048-1.cc: ...here.
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-2.cc: Move to...
* testsuite/ext/stdio_sync_filebuf/wchar_t/12048-2.cc: ...here.
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-3.cc: Move to...
* testsuite/ext/stdio_sync_filebuf/wchar_t/12048-3.cc: ...here.
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-4.cc: Move to...
* testsuite/ext/stdio_sync_filebuf/wchar_t/12048-4.cc: ...here.
---
 .../ext/stdio_sync_filebuf/wchar_t/{12948-1.cc => 12048-1.cc} | 0
 .../ext/stdio_sync_filebuf/wchar_t/{12948-2.cc => 12048-2.cc} | 0
 .../ext/stdio_sync_filebuf/wchar_t/{12948-3.cc => 12048-3.cc} | 0
 .../ext/stdio_sync_filebuf/wchar_t/{12948-4.cc => 12048-4.cc} | 0
 4 files changed, 0 insertions(+), 0 deletions(-)
 rename libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/{12948-1.cc => 
12048-1.cc} (100%)
 rename libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/{12948-2.cc => 
12048-2.cc} (100%)
 rename libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/{12948-3.cc => 
12048-3.cc} (100%)
 rename libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/{12948-4.cc => 
12048-4.cc} (100%)

diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-1.cc 
b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-1.cc
similarity index 100%
rename from libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-1.cc
rename to libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-1.cc
diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-2.cc 
b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-2.cc
similarity index 100%
rename from libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-2.cc
rename to libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-2.cc
diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-3.cc 
b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-3.cc
similarity index 100%
rename from libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-3.cc
rename to libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-3.cc
diff --git a/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-4.cc 
b/libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-4.cc
similarity index 100%
rename from libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12948-4.cc
rename to libstdc++-v3/testsuite/ext/stdio_sync_filebuf/wchar_t/12048-4.cc
-- 
2.45.2



[PATCH 6/8] libstdc++: Use dg-additional-files in some non-I/O tests

2024-07-22 Thread Jonathan Wakely
Tested x86_64-linux.

-- >8 --

libstdc++-v3/ChangeLog:

* testsuite/20_util/hash/chi2_q_document_words.cc: Use
dg-additional-files for input text.
* testsuite/performance/ext/pb_ds/all_text_find.cc: Likewise.
* testsuite/performance/ext/pb_ds/multimap_text_find.hpp:
Likewise.
* testsuite/performance/ext/pb_ds/multimap_text_insert.hpp:
Likewise.
* testsuite/performance/ext/pb_ds/multimap_text_insert_mem.hpp:
Likewise.
* testsuite/performance/ext/pb_ds/priority_queue_text_join.cc:
Likewise.
* testsuite/performance/ext/pb_ds/priority_queue_text_modify.hpp: 
Likewise.
* testsuite/performance/ext/pb_ds/priority_queue_text_pop_mem.cc: 
Likewise.
* testsuite/performance/ext/pb_ds/priority_queue_text_push.cc:
Likewise.
* testsuite/performance/ext/pb_ds/priority_queue_text_push_pop.cc: 
Likewise.
* testsuite/performance/ext/pb_ds/tree_text_insert.cc: Likewise.
* testsuite/performance/ext/pb_ds/tree_text_lor_find.cc:
Likewise.
---
 libstdc++-v3/testsuite/20_util/hash/chi2_q_document_words.cc| 2 ++
 libstdc++-v3/testsuite/performance/ext/pb_ds/all_text_find.cc   | 2 ++
 .../testsuite/performance/ext/pb_ds/multimap_text_find.hpp  | 2 ++
 .../testsuite/performance/ext/pb_ds/multimap_text_insert.hpp| 2 ++
 .../performance/ext/pb_ds/multimap_text_insert_mem.hpp  | 2 ++
 .../testsuite/performance/ext/pb_ds/priority_queue_text_join.cc | 2 ++
 .../performance/ext/pb_ds/priority_queue_text_modify.hpp| 2 ++
 .../performance/ext/pb_ds/priority_queue_text_pop_mem.cc| 2 ++
 .../testsuite/performance/ext/pb_ds/priority_queue_text_push.cc | 2 ++
 .../performance/ext/pb_ds/priority_queue_text_push_pop.cc   | 2 ++
 .../testsuite/performance/ext/pb_ds/tree_text_insert.cc | 2 ++
 .../testsuite/performance/ext/pb_ds/tree_text_lor_find.cc   | 2 ++
 12 files changed, 24 insertions(+)

diff --git a/libstdc++-v3/testsuite/20_util/hash/chi2_q_document_words.cc 
b/libstdc++-v3/testsuite/20_util/hash/chi2_q_document_words.cc
index a6ebc0011eb..3c77527c27c 100644
--- a/libstdc++-v3/testsuite/20_util/hash/chi2_q_document_words.cc
+++ b/libstdc++-v3/testsuite/20_util/hash/chi2_q_document_words.cc
@@ -19,6 +19,8 @@
 // along with this library; see the file COPYING3.  If not see
 // .
 
+// { dg-additional-files "thirty_years_among_the_dead_preproc.txt" }
+
 #include "chi2_quality.h"
 
 // Tests chi^2 for a set of words taken from a document written in English.
diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/all_text_find.cc 
b/libstdc++-v3/testsuite/performance/ext/pb_ds/all_text_find.cc
index 13c73a76647..df822c3d5f7 100644
--- a/libstdc++-v3/testsuite/performance/ext/pb_ds/all_text_find.cc
+++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/all_text_find.cc
@@ -29,6 +29,8 @@
 // purpose. It is provided "as is" without express or implied
 // warranty.
 
+// { dg-additional-files "thirty_years_among_the_dead_preproc.txt" }
+
 /**
  * @file text_find_timing_test.cpp
  * Contains test for finding text.
diff --git 
a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find.hpp 
b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find.hpp
index 18e383ea17c..dbaaf04a1b6 100644
--- a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find.hpp
+++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find.hpp
@@ -29,6 +29,8 @@
 // purpose. It is provided "as is" without express or implied
 // warranty.
 
+// { dg-additional-files "thirty_years_among_the_dead_preproc.txt" }
+
 /**
  * @file multimap_text_find_timing_test.cpp
  * Contains test for inserting text words.
diff --git 
a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert.hpp 
b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert.hpp
index 737be39a154..2c86b52f30a 100644
--- a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert.hpp
+++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert.hpp
@@ -29,6 +29,8 @@
 // purpose. It is provided "as is" without express or implied
 // warranty.
 
+// { dg-additional-files "thirty_years_among_the_dead_preproc.txt" }
+
 /**
  * @file multimap_text_insert_timing_test.cpp
  * Contains test for inserting text words.
diff --git 
a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_mem.hpp 
b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_mem.hpp
index 9ce235381bd..ab755312c69 100644
--- a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_mem.hpp
+++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_mem.hpp
@@ -29,6 +29,8 @@
 // purpose. It is provided "as is" without express or implied
 // warranty.
 
+// { dg-additional-files "thirty_years_among_the_dead_preproc.txt" }
+
 /**
  * @file multimap_text_insert_mem_usage_test.cpp
  * Contains test for inserting text 

[PATCH 4/8] libstdc++: Add file-io-diff to replace @diff@ markup in I/O tests

2024-07-22 Thread Jonathan Wakely
Tested x86_64-linux.

-- >8 --

This adds a new dg-final action to compare two files after a test has
run, so that we can verify that fstream operations produce the expected
results. With this change, all uses of @diff@ that seem potentially
useful have been converted to actually compare the files and FAIL if
they differ.

The file-io-diff action can take two arguments naming the files to be
compared, or for convenience it can take a single string and will
compare STR.tst and STR.txt, as that's how it's commonly used.

Additionally, all remaining uses of @require@ are converted to
dg-additional-files directives, so that the TODO in libstdc++.exp can
be resolved.

libstdc++-v3/ChangeLog:

* testsuite/27_io/basic_filebuf/close/char/1.cc: Remove
@require@ and @diff@. Use dg-final file-io-diff action.
* testsuite/27_io/basic_istream/extractors_other/char/2.cc:
Likewise.
* testsuite/27_io/basic_istream/extractors_other/wchar_t/2.cc:
Likewise.
* testsuite/27_io/basic_istream/get/char/2.cc: Likewise.
* testsuite/27_io/basic_istream/get/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_istream/ignore/char/3.cc: Likewise.
* testsuite/27_io/basic_istream/ignore/wchar_t/3.cc: Likewise.
* testsuite/27_io/basic_istream/peek/char/6414.cc: Likewise.
* testsuite/27_io/basic_istream/peek/wchar_t/6414.cc: Likewise.
* testsuite/27_io/basic_istream/seekg/char/fstream.cc: Likewise.
* testsuite/27_io/basic_istream/seekg/wchar_t/fstream.cc:
Likewise.
* testsuite/27_io/basic_istream/tellg/char/fstream.cc: Likewise.
* testsuite/27_io/basic_istream/tellg/wchar_t/fstream.cc:
Likewise.
* testsuite/27_io/basic_ofstream/open/char/1.cc: Likewise.
* testsuite/27_io/basic_ostream/inserters_other/char/1.cc:
Likewise.
* testsuite/27_io/basic_ostream/inserters_other/wchar_t/1.cc:
Likewise.
* testsuite/27_io/ios_base/sync_with_stdio/1.cc: Likewise.
* testsuite/27_io/basic_ostream/inserters_other/char/2.cc:
Likewise. Check file positions.
* testsuite/27_io/basic_ostream/inserters_other/wchar_t/2.cc:
Likewise.
* testsuite/lib/libstdc++.exp (file-io-diff): New proc.
---
 .../27_io/basic_filebuf/close/char/1.cc   |  6 ++--
 .../basic_istream/extractors_other/char/2.cc  |  9 --
 .../extractors_other/wchar_t/2.cc |  9 --
 .../27_io/basic_istream/get/char/2.cc |  8 +++--
 .../27_io/basic_istream/get/wchar_t/2.cc  |  8 +++--
 .../27_io/basic_istream/ignore/char/3.cc  |  8 +++--
 .../27_io/basic_istream/ignore/wchar_t/3.cc   |  8 +++--
 .../27_io/basic_istream/peek/char/6414.cc |  9 --
 .../27_io/basic_istream/peek/wchar_t/6414.cc  |  9 --
 .../27_io/basic_istream/seekg/char/fstream.cc | 10 --
 .../basic_istream/seekg/wchar_t/fstream.cc| 10 --
 .../27_io/basic_istream/tellg/char/fstream.cc | 10 --
 .../basic_istream/tellg/wchar_t/fstream.cc| 10 --
 .../27_io/basic_ofstream/open/char/1.cc   |  5 ++-
 .../basic_ostream/inserters_other/char/1.cc   |  8 +++--
 .../basic_ostream/inserters_other/char/2.cc   |  7 ++--
 .../inserters_other/wchar_t/1.cc  |  8 +++--
 .../inserters_other/wchar_t/2.cc  |  7 ++--
 .../27_io/ios_base/sync_with_stdio/1.cc   |  5 +--
 libstdc++-v3/testsuite/lib/libstdc++.exp  | 32 +++
 20 files changed, 130 insertions(+), 56 deletions(-)

diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc 
b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc
index e2b336a711d..d9e9c53e3e6 100644
--- a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc
@@ -15,14 +15,14 @@
 // with this library; see the file COPYING3.  If not see
 // .
 
-// 27.8.1.3 filebuf member functions
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %-*.txt
+// C++98 27.8.1.3 filebuf member functions
 
 // various tests for filebuf::open() and filebuf::close() including
 // the non-portable functionality in the libstdc++-v3 IO library
 
 // { dg-require-fileio "" }
+// { dg-additional-files "filebuf_members-1.tst filebuf_members-1.txt" }
+// { dg-final { file-io-diff "filebuf_members-1" } }
 
 #include 
 #include 
diff --git 
a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/2.cc 
b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/2.cc
index 589402308c3..77543310caa 100644
--- a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/2.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/2.cc
@@ -17,11 +17,14 @@
 // with this library; see the file COPYING3.  If not see
 // .
 
-// 27.6.1.2.3 basic_istream::operator>>
-// @require@ %-*.tst %-*.txt
-// @diff@ %-*.tst %-*.txt
+// C++98 27.6.1.2.3 

[PATCH 3/8] libstdc++: Use dg-additional-files in some I/O tests

2024-07-22 Thread Jonathan Wakely
Tested x86_64-linux.

-- >8 --

Use the dg-additional-files directive to declare files that need to be
copied into the test's working directory. This is currently redundant
(as all .tst and .txt files are copied for all tests) but is a step
towards not copying all files.

libstdc++-v3/ChangeLog:

* testsuite/27_io/basic_filebuf/imbue/char/2.cc: Use
dg-additional-files.
* testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_filebuf/open/char/path.cc: Likewise.
* testsuite/27_io/basic_filebuf/pbackfail/char/9761.cc:
Likewise.
* testsuite/27_io/basic_filebuf/seekoff/char/3-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekoff/char/3-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekpos/char/3-in.cc: Likewise.
* testsuite/27_io/basic_filebuf/seekpos/char/3-io.cc: Likewise.
* testsuite/27_io/basic_filebuf/setbuf/char/1.cc: Likewise.
* testsuite/27_io/basic_filebuf/sgetn/char/3.cc: Likewise.
* testsuite/27_io/basic_filebuf/underflow/10096.cc: Likewise.
* testsuite/27_io/basic_fstream/cons/char/path.cc: Likewise.
* testsuite/27_io/basic_fstream/open/char/path.cc: Likewise.
* testsuite/27_io/basic_ifstream/assign/1.cc: Likewise.
* testsuite/27_io/basic_ifstream/cons/move.cc: Likewise.
* testsuite/27_io/basic_ifstream/cons/char/path.cc: Likewise.
* testsuite/27_io/basic_ifstream/open/char/path.cc: Likewise.
* testsuite/27_io/basic_ifstream/open/wchar_t/1.cc: Likewise.
* testsuite/27_io/objects/char/10.cc: Likewise.
* testsuite/27_io/objects/char/12048-1.cc: Likewise.
* testsuite/27_io/objects/char/12048-2.cc: Likewise.
* testsuite/27_io/objects/char/12048-3.cc: Likewise.
* testsuite/27_io/objects/char/12048-4.cc: Likewise.
* testsuite/27_io/objects/char/12048-5.cc: Likewise.
* testsuite/27_io/objects/wchar_t/12048-1.cc: Likewise.
* testsuite/27_io/objects/wchar_t/12048-2.cc: Likewise.
* testsuite/27_io/objects/wchar_t/12048-3.cc: Likewise.
* testsuite/27_io/objects/wchar_t/12048-4.cc: Likewise.
* testsuite/27_io/objects/wchar_t/12048-5.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/char/12048-1.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/char/12048-2.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/char/12048-3.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/char/12048-4.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-1.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-2.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-3.cc: Likewise.
* testsuite/ext/stdio_sync_filebuf/wchar_t/12948-4.cc: Likewise.
---
 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/2.cc| 4 +++-
 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc | 1 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/path.cc  | 1 +
 .../testsuite/27_io/basic_filebuf/pbackfail/char/9761.cc  | 1 +
 .../testsuite/27_io/basic_filebuf/seekoff/char/3-in.cc| 3 ++-
 .../testsuite/27_io/basic_filebuf/seekoff/char/3-io.cc| 3 ++-
 .../testsuite/27_io/basic_filebuf/seekpos/char/3-in.cc| 1 +
 .../testsuite/27_io/basic_filebuf/seekpos/char/3-io.cc| 1 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/1.cc   | 1 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/3.cc| 1 +
 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/10096.cc | 1 +
 libstdc++-v3/testsuite/27_io/basic_fstream/cons/char/path.cc  | 1 +
 libstdc++-v3/testsuite/27_io/basic_fstream/open/char/path.cc  | 1 +
 libstdc++-v3/testsuite/27_io/basic_ifstream/assign/1.cc   | 3 ++-
 libstdc++-v3/testsuite/27_io/basic_ifstream/cons/char/path.cc | 1 +
 libstdc++-v3/testsuite/27_io/basic_ifstream/cons/move.cc  | 3 ++-
 libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/path.cc | 1 +
 libstdc++-v3/testsuite/27_io/basic_ifstream/open/wchar_t/1.cc | 3 ++-
 libstdc++-v3/testsuite/27_io/objects/char/10.cc   | 1 +
 libstdc++-v3/testsuite/27_io/objects/char/12048-1.cc  | 1 +
 libstdc++-v3/testsuite/27_io/objects/char/12048-2.cc  | 1 +
 libstdc++-v3/testsuite/27_io/objects/char/12048-3.cc  | 1 +
 libstdc++-v3/testsuite/27_io/objects/char/12048-4.cc  | 1 +
 libstdc++-v3/testsuite/27_io/objects/char/12048-5.cc  | 1 +
 libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-1.cc   | 1 +
 libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-2.cc   | 1 +
 libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-3.cc   | 1 +
 libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-4.cc   | 1 +
 libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-5.cc   | 1 +
 libstdc++-v3/testsuite/ext/stdio_sync_filebuf/char/12048-1.cc | 1 +
 libstdc++-v3/testsuite/ext/stdio_sync_filebuf/char/12048-2.cc | 1 +
 

Re: [PATCH][contrib]: support json output from check_GNU_style_lib.py

2024-07-22 Thread Jonathan Wakely
On Mon, 22 Jul 2024 at 14:54, Filip Kastl  wrote:
>
> Hi Tamar,
>
> I wanted to try reviewing a patch and this seemed simple enough so I gave it a
> shot.  Hopefully this saves some time of the maintainer that eventually
> approves this :).
>
> I don't see any bug in the code.  I also tried running it on my own input and
> the output was correct.  So functionally the patch is good.  I have some
> remarks about the style though:
>
> - You sometimes put a space between function name and parentheses.  This
>   doesn't look python-ish and isn't consistent in the file.

It's the GNU C convention, but I really wish we didn't use it for
Python code too.

> - There's one very long line (check_GNU_style_lib.py:335).  I would shorten it
>   so it is at most 79 characters long.
> - On the same line, there is a space after { but not before }.  For
>   consistency, I would erase the space after {
> - On the same line there are spaces after :.  I think a more python-ish way
>   would be not to have those spaces there.  Here I'm maybe being too pedantic
>   so feel free to ignore this.  I think it will look nice either way.
>
> To summarize the last 3 points, I would replace this
>
> errlines.append({ "file" : locs[0], "row" : locs[1], "column" 
> : locs[2], "err" : e.console_error})
>
> with this
>
> errlines.append({"file": locs[0], "row": locs[1],
> "column": locs[2], "err": e.console_error})
>
> Cheers,
> Filip Kastl
>



Re: [PATCH,c++,wwwdocs] bugs: Remove old "export" non-bug

2024-07-22 Thread Jonathan Wakely
On Mon, 22 Jul 2024 at 07:51, Gerald Pfeifer  wrote:
>
> We have been carrying this note on the "original" export feature for ages,
> and I believe it's not actually a FAQ, if it ever was.
>
> Jonathan moved this down when adding a note on ADL last fall.
>
> I now propose to drop it.
>
> Thoughts?

Sounds good to me.

I keep meaning to make a similar change to
https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl-export-keyword
which is also outdated and irrelevant in 2024.

>
> Gerald
>
>
>
> diff --git a/htdocs/bugs/index.html b/htdocs/bugs/index.html
> index 40355911..7f2f485c 100644
> --- a/htdocs/bugs/index.html
> +++ b/htdocs/bugs/index.html
> @@ -622,17 +622,6 @@ and the scope operator, or compile using C++11 or later. 
> Defect report 1104
>  changed the parser rules so that :: works as expected.
>  
>
> -export
> -Most C++ compilers (G++ included) never implemented C++98
> -export, which was removed in C++11, and the keyword reused in
> -C++20 by the Modules feature. The C++98 feature was intended to support
> -separate compilation of template declarations and
> -definitions. Without export, a template definition must be in
> -scope to be used. The obvious workaround is simply to place all definitions 
> in
> -the header itself. Alternatively, the compilation unit containing template
> -definitions may be included from the header.
> -
> -
>  Common problems when upgrading the compiler
>
>  ABI changes
>



Re: C preprocessor bug

2024-07-22 Thread Jonathan Wakely via Gcc-bugs

On 22/07/24 12:24 +0300, Ovidiu Panait wrote:

Hi,

When processing large header files, the C preprocessor reports error 
on the wrong line.


This mailing list is for automated emails fom our bug tracker, not for
reporting bugs. Emails sent directly to this list will not get tracked
as bugs, and will generally be ignored.

To report a bug please follow the instructions at
https://gcc.gnu.org/bugs/ - thanks.



This is 100% reproducible on my side with gcc mainline.

Reproducer:

 # Build
mkdir build; cd build
../configure --host=x86_64-pc-linux-gnu --target=x86_64-wrs-linux 
--enable-languages=c --disable-multilib --disable-libstdcxx-pch 
--disable-libsanitizer --disable-libssp --disable-libquadmath 
--disable-libquadmath-support --disable-libgomp --disable-libvtv 
--disable-bootstrap

make all-host -j$(nproc)
mkdir install; make install-host DESTDIR=$(realpath ./install) -j$(nproc)


 # Generate testcase
mkdir testcase; cd testcase
cat > main.c < header1.h
for i in {1..327676}; do
    echo "extern int header1_begins;" >> header1.h
done
cat >> header1.h < header2.h


 # Test
../install/usr/local/bin/x86_64-wrs-linux-gcc main.c
In file included from main.c:4:
header1.h:327677:20: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or 
‘__attribute__’ before ‘ends’

327677 | #include "header2.h"
   |    ^


The line where the error is reported("327677") is bogus, the actual 
error is on the next line("327678") in header1.h:


$ cat -n header1.h | tail -n3
327676    extern int header1_begins;
327677    #include "header2.h"
327678    extern int header1 ends;


Ovidiu




Re: Safe Cascading Frees

2024-07-16 Thread Jonathan Wakely via Gcc
On Tue, 16 Jul 2024 at 19:26, M.C.A. (Marco) Devillers
 wrote:
>
> All your proposals now boil down to: Do explicit memory management
> whereas the developer supposes that is handled for them.

There's no explicit memory management in the loop I showed. It's
explicit control of lifetime, which is what all the containers in the
C++ library do for you.

If that's too much trouble to avoid unbounded stack growth, then use
data structures somebody else has already written which work
correctly.


Re: Safe Cascading Frees

2024-07-16 Thread Jonathan Wakely via Gcc
On Tue, 16 Jul 2024 at 19:12, Jonathan Wakely  wrote:
>
>
>
> On Tue, 16 Jul 2024, 18:51 M.C.A. (Marco) Devillers via Gcc, 
>  wrote:
>>
>> Document number:  SCF4C++00
>> Date:  2024-7-16
>> Audience:  GCC email list
>> Reply-to:  marco.devill...@gmail.com, gcc@gcc.gnu.org
>>
>> I. Introduction
>>
>> Because C++ smart pointers are based on RAII it is easy to trigger an
>> overflow of the C stack since destructors call each other. Smart
>> pointers are supposed to be safe, smart pointers are likely to be used
>> extensively in the future, and this behaviour could make a large
>> number of C++ programs core dump unexpectedly.
>> This proposal is to remove this behaviour from GCCs standard library
>
>
> Where does it exist in the library?
>
> The problem in your program is easily avoided, without changing the standard 
> or GCC's implementation of the standard library.
>
>> and also showcases a small trick by which that can be done.
>>
>> II. Motivation and Scope
>>
>> We all want smart pointers since they allow for easy and safe memory
>> management, this desire is only expected to increase over the
>> following decades.
>>
>> However due to RAII semantics it's easy to trigger an overflow of the
>> C stack once garbage goes out of scope. Observe the following trivial
>> program:
>>
>> #include 
>> #include 
>>
>> struct list_node {
>>using ptr = std::unique_ptr;
>>~list_node() {
>>}
>>
>>int x;
>>ptr next;
>> };
>>
>> int main() {
>>list_node::ptr next = nullptr;
>>
>>for(int i = 0; i < 10; ++i) { // decrease value to see it not segfault
>>next = list_node::ptr(new list_node{i, std::move(next)});
>>}
>> }
>>
>> Cascading frees will make this program core dump depending the size of
>> the list. Please note, that that program will segfault on for current
>> data-driven days relatively tiny sizes.
>
>
> So don't do that then. It's easy to add a loop to clean up the list. Or 
> create an actual list class to manage the nodes and do that loop in its 
> destructor. Nobody is forced to define a list only in terms of nodes, rather 
> than a list class that manages the nodes.

Or you can put the loop in the node destructor:

   ~list_node() {
 while (next)
   next = std::move(next->next);
   }

Unlike your cleanup stack, this doesn't require any additional memory
allocation or synchronization.


Re: Safe Cascading Frees

2024-07-16 Thread Jonathan Wakely via Gcc
On Tue, 16 Jul 2024, 18:51 M.C.A. (Marco) Devillers via Gcc, <
gcc@gcc.gnu.org> wrote:

> Document number:  SCF4C++00
> Date:  2024-7-16
> Audience:  GCC email list
> Reply-to:  marco.devill...@gmail.com, gcc@gcc.gnu.org
>
> I. Introduction
>
> Because C++ smart pointers are based on RAII it is easy to trigger an
> overflow of the C stack since destructors call each other. Smart
> pointers are supposed to be safe, smart pointers are likely to be used
> extensively in the future, and this behaviour could make a large
> number of C++ programs core dump unexpectedly.
> This proposal is to remove this behaviour from GCCs standard library
>

Where does it exist in the library?

The problem in your program is easily avoided, without changing the
standard or GCC's implementation of the standard library.

and also showcases a small trick by which that can be done.
>
> II. Motivation and Scope
>
> We all want smart pointers since they allow for easy and safe memory
> management, this desire is only expected to increase over the
> following decades.
>
> However due to RAII semantics it's easy to trigger an overflow of the
> C stack once garbage goes out of scope. Observe the following trivial
> program:
>
> #include 
> #include 
>
> struct list_node {
>using ptr = std::unique_ptr;
>~list_node() {
>}
>
>int x;
>ptr next;
> };
>
> int main() {
>list_node::ptr next = nullptr;
>
>for(int i = 0; i < 10; ++i) { // decrease value to see it not
> segfault
>next = list_node::ptr(new list_node{i, std::move(next)});
>}
> }
>
> Cascading frees will make this program core dump depending the size of
> the list. Please note, that that program will segfault on for current
> data-driven days relatively tiny sizes.
>

So don't do that then. It's easy to add a loop to clean up the list. Or
create an actual list class to manage the nodes and do that loop in its
destructor. Nobody is forced to define a list only in terms of nodes,
rather than a list class that manages the nodes.


> I give it to you that this is unsafe and unwanted behaviour since now
> every program employing nested structures can core dump easily and
> unexpectedly. For example: GUIs, editors, parsers, transformers, etc.
> The problem is only expected to worsen with more developers using safe
> pointers.
>
> The proposal is to remove this behaviour from the GCC standard library
> by hardening smart pointers in the following manner: instead of
> calling garbage recursively garbage is first offloaded to a stack and
> that stack destroys objects until it is empty. Or by any other means
> that removes segfaulting cascading frees.
>
> A reference implementation (not concurrent) for unique pointers is
> given as an Addendum. (The code is due to Alipha on libera.net).
>
> IV. Impact On the Standard
>
> This shouldn't impact other parts of the standard.
>
> V. Design Decisions
>
> Offload destructor calls to an explicit stack to make these calls
> sequential instead of recursive. A non-concurrent implementation of
> unique pointers is given below.
>
> VI. Technical Specifications
>
> This shouldn't change anything.
>
> VII. Acknowledgements
>
> This cascading free behaviour was noticed during the development of
> the Egel language interpreter, and the author has great interest in
> having this resolved. The problem was discussed on various channels
> and together with Alipha on libera.net a solution was developed.
>
> VIII. Addendum
>
> #include 
> #include 
> #include 
> #include 
> #include 
>
> namespace detail {
>   inline bool doing_cleanup = false;
>   inline std::vector> ptr_cleanup;
> }
>
> template
> class safe_unique_ptr {
> public:
>   safe_unique_ptr() : ptr() {}
>   safe_unique_ptr(T *p) : ptr(p) {}
>
>   safe_unique_ptr(safe_unique_ptr &) :
> ptr(std::exchange(other.ptr, nullptr)) {}
>
>   safe_unique_ptr =(safe_unique_ptr &) {
> cleanup(ptr);
> ptr = std::exchange(other.ptr, nullptr);
> return *this;
>   }
>
>   T *() const { return *ptr; }
>   T *operator->() const { return ptr; }
>
>   ~safe_unique_ptr() { cleanup(ptr); }
>
> private:
>   void cleanup(T *p) {
> using namespace detail;
>
> if(!p) return;
>
> if(!doing_cleanup) {
>   doing_cleanup = true;
>   delete p;
>
>   while(!ptr_cleanup.empty()) {
> std::function deleter = ptr_cleanup.back();
> ptr_cleanup.pop_back();
> deleted();
>   }
>
>   doing_cleanup = false;
> } else {
>   ptr_cleanup.push_back([p]() { delete p; });
> }
>   }
>
>   T *ptr;
> };
>
> struct list_node {
>   using ptr = safe_unique_ptr;
>   ~list_node() {}
>
>   int x;
>   ptr next;
> };
>


Re: [PATCH v3 1/6] libstdc++: Handle encodings in localized chrono formatting [PR109162]

2024-07-16 Thread Jonathan Wakely
On Tue, 16 Jul 2024 at 13:34, Jonathan Wakely  wrote:
>
> On Tue, 16 Jul 2024 at 13:05, Jonathan Wakely  wrote:
> >
> > On Fri, 12 Jul 2024 at 00:23, I wrote:
> > >
> > > I sent v1 of this patch in February, and it added the new symbols to
> > > libstdc++exp.a which meant users needed to use -lstdc++exp to format
> > > chrono types in C++23 mode. That was less than ideal.
> > >
> > > This v2 patch adds the new symbols to the main library, which means no
> > > extra step to get the new features, and we can enable them as a DR for
> > > C++20 mode. But that means we need new exports in the shared library,
> > > and so need to be more confident that the feature is stable and ready to
> > > go into the lib.
> > >
> > > I'm not 100% confident that we want to add a new, private facet to the
> > > std::locale, but it seems reasonable. And that's not exposed to users at
> > > all, as the two new symbols added to the library hide the creation and
> > > use of that facet.
> >
> > Here's v3, which fixes a missing export of the __sso_string constructors
> > and destructors, needed so that the old ABI can use the new function to
> > transcode a locale-specific string to UTF-8, with a std::string buffer.
> >
> > I haven't done so here, but we could keep a least recently used cache of
> > __encoding facets, so that repeatedly calling std::format with the same
> > locale doesn't need to keep re-checking the locale's encoding and then
> > re-opening the same iconv_t descriptor.
> >
> > This v3 patch also tweaks the commented out parts of
> > include/bits/version.def in preparation for enabling the C++26 
> > features in the following patches in this series.
> >
> > Tested x86_64-linux. I think this is ready to push now, but I'll wait a
> > bit for any comments on it.
> >
> > -- >8 --
> >
> > 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
> > localiz

Re: [PATCH v3 1/6] libstdc++: Handle encodings in localized chrono formatting [PR109162]

2024-07-16 Thread Jonathan Wakely
On Tue, 16 Jul 2024 at 13:05, Jonathan Wakely  wrote:
>
> On Fri, 12 Jul 2024 at 00:23, I wrote:
> >
> > I sent v1 of this patch in February, and it added the new symbols to
> > libstdc++exp.a which meant users needed to use -lstdc++exp to format
> > chrono types in C++23 mode. That was less than ideal.
> >
> > This v2 patch adds the new symbols to the main library, which means no
> > extra step to get the new features, and we can enable them as a DR for
> > C++20 mode. But that means we need new exports in the shared library,
> > and so need to be more confident that the feature is stable and ready to
> > go into the lib.
> >
> > I'm not 100% confident that we want to add a new, private facet to the
> > std::locale, but it seems reasonable. And that's not exposed to users at
> > all, as the two new symbols added to the library hide the creation and
> > use of that facet.
>
> Here's v3, which fixes a missing export of the __sso_string constructors
> and destructors, needed so that the old ABI can use the new function to
> transcode a locale-specific string to UTF-8, with a std::string buffer.
>
> I haven't done so here, but we could keep a least recently used cache of
> __encoding facets, so that repeatedly calling std::format with the same
> locale doesn't need to keep re-checking the locale's encoding and then
> re-opening the same iconv_t descriptor.
>
> This v3 patch also tweaks the commented out parts of
> include/bits/version.def in preparation for enabling the C++26 
> features in the following patches in this series.
>
> Tested x86_64-linux. I think this is ready to push now, but I'll wait a
> bit for any comments on it.
>
> -- >8 --
>
> 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

[PATCH] libstdc++: Remove __find_if unrolling for random access iterators

2024-07-16 Thread Jonathan Wakely
I have some follow-up patches which are enabled by this, so that other
algos which use std::__find_if can benefit from the memchr optimizations
recently added to std::find. Currently, they can't benefit because they
use the internal __find_if and only std::find is optimized.

Tested x86_64-linux. I intend to push this in the next day or two.

-- >8 --

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.
---
 libstdc++-v3/include/bits/stl_algo.h |  3 +-
 libstdc++-v3/include/bits/stl_algobase.h | 70 ++--
 2 files changed, 5 insertions(+), 68 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_algo.h 
b/libstdc++-v3/include/bits/stl_algo.h
index d250b2e04d4..541f53b 100644
--- a/libstdc++-v3/include/bits/stl_algo.h
+++ b/libstdc++-v3/include/bits/stl_algo.h
@@ -110,8 +110,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  _Predicate __pred)
 {
   return std::__find_if(__first, __last,
-   __gnu_cxx::__ops::__negate(__pred),
-   std::__iterator_category(__first));
+   __gnu_cxx::__ops::__negate(__pred));
 }
 
   /// Like find_if_not(), but uses and updates a count of the
diff --git a/libstdc++-v3/include/bits/stl_algobase.h 
b/libstdc++-v3/include/bits/stl_algobase.h
index dec1e4c79d8..27f6c377ad6 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -2098,77 +2098,15 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
 
 _GLIBCXX_END_NAMESPACE_ALGO
 
-  /// This is an overload used by find algos for the Input Iterator case.
-  template
-_GLIBCXX20_CONSTEXPR
-inline _InputIterator
-__find_if(_InputIterator __first, _InputIterator __last,
- _Predicate __pred, input_iterator_tag)
-{
-  while (__first != __last && !__pred(__first))
-   ++__first;
-  return __first;
-}
-
-  /// This is an overload used by find algos for the RAI case.
-  template
-_GLIBCXX20_CONSTEXPR
-_RandomAccessIterator
-__find_if(_RandomAccessIterator __first, _RandomAccessIterator __last,
- _Predicate __pred, random_access_iterator_tag)
-{
-  typename iterator_traits<_RandomAccessIterator>::difference_type
-   __trip_count = (__last - __first) >> 2;
-
-  for (; __trip_count > 0; --__trip_count)
-   {
- if (__pred(__first))
-   return __first;
- ++__first;
-
- if (__pred(__first))
-   return __first;
- ++__first;
-
- if (__pred(__first))
-   return __first;
- ++__first;
-
- if (__pred(__first))
-   return __first;
- ++__first;
-   }
-
-  switch (__last - __first)
-   {
-   case 3:
- if (__pred(__first))
-   return __first;
- ++__first;
- // FALLTHRU
-   case 2:
- if (__pred(__first))
-   return __first;
- ++__first;
- // FALLTHRU
-   case 1:
- if (__pred(__first))
-   return __first;
- ++__first;
- // FALLTHRU
-   case 0:
-   default:
- return __last;
-   }
-}
-
+  // Implementation of std::find_if, also used in std::remove_if and others.
   template
 _GLIBCXX20_CONSTEXPR
 inline _Iterator
 __find_if(_Iterator __first, _Iterator __last, _Predicate __pred)
 {
-  return __find_if(__first, __last, __pred,
-  std::__iterator_category(__first));
+  while (__first != __last && !__pred(__first))
+   ++__first;
+  return __first;
 }
 
   template
-- 
2.45.2



[PATCH 6/6] libstdc++: Bump __cpp_lib_format value for std::runtime_format

2024-07-16 Thread Jonathan Wakely
Tested x86_64-linux.

-- >8 --

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  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.
---
 libstdc++-v3/include/bits/version.def | 2 +-
 libstdc++-v3/include/bits/version.h   | 4 ++--
 libstdc++-v3/include/std/format   | 2 +-
 libstdc++-v3/testsuite/std/format/functions/format.cc | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libstdc++-v3/include/bits/version.def 
b/libstdc++-v3/include/bits/version.def
index ec330911d66..ee0a9e45c44 100644
--- a/libstdc++-v3/include/bits/version.def
+++ b/libstdc++-v3/include/bits/version.def
@@ -1171,7 +1171,7 @@ ftms = {
   // 202306 P2637R3 Member visit
   // 202311 P2918R2 Runtime format strings II
   values = {
-v = 202306;
+v = 202311;
 cxxmin = 26;
 hosted = yes;
   };
diff --git a/libstdc++-v3/include/bits/version.h 
b/libstdc++-v3/include/bits/version.h
index 148ee87e087..cee497d7443 100644
--- a/libstdc++-v3/include/bits/version.h
+++ b/libstdc++-v3/include/bits/version.h
@@ -1310,9 +1310,9 @@
 
 #if !defined(__cpp_lib_format)
 # if (__cplusplus >  202302L) && _GLIBCXX_HOSTED
-#  define __glibcxx_format 202306L
+#  define __glibcxx_format 202311L
 #  if defined(__glibcxx_want_all) || defined(__glibcxx_want_format)
-#   define __cpp_lib_format 202306L
+#   define __cpp_lib_format 202311L
 #  endif
 # elif (__cplusplus >= 202002L) && _GLIBCXX_HOSTED
 #  define __glibcxx_format 202304L
diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index f1a1f736a80..838cc18a78a 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -155,7 +155,7 @@ namespace __format
   = basic_format_string...>;
 #endif
 
-#if __cplusplus > 202302L
+#if __cpp_lib_format >= 202311L // >= C++26
   [[__gnu__::__always_inline__]]
   inline __format::_Runtime_format_string
   runtime_format(string_view __fmt) noexcept
diff --git a/libstdc++-v3/testsuite/std/format/functions/format.cc 
b/libstdc++-v3/testsuite/std/format/functions/format.cc
index 0549d171e5a..7fc42017045 100644
--- a/libstdc++-v3/testsuite/std/format/functions/format.cc
+++ b/libstdc++-v3/testsuite/std/format/functions/format.cc
@@ -8,7 +8,7 @@
 # error "Feature test macro for std::format is missing in "
 #elif __cpp_lib_format < 202110L
 # error "Feature test macro for std::format has wrong value in "
-#elif __cplusplus > 202302L && __cpp_lib_format < 202306L
+#elif __cplusplus > 202302L && __cpp_lib_format < 202311L
 # error "Feature test macro for std::format has wrong value in "
 #endif
 
@@ -24,7 +24,7 @@
 # error "Feature test macro for std::format is missing in "
 #elif __cpp_lib_format < 202110L
 # error "Feature test macro for std::format has wrong value in "
-#elif __cplusplus > 202302L && __cpp_lib_format < 202306L
+#elif __cplusplus > 202302L && __cpp_lib_format < 202311L
 # error "Feature test macro for std::format has wrong value in "
 #endif
 
-- 
2.45.2



[PATCH 5/6] libstdc++: Define C++26 member visit for std::basic_format_arg [PR110356]

2024-07-16 Thread Jonathan Wakely
Tested x86_64-linux.

-- >8 --

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.
---
 libstdc++-v3/include/bits/c++config   | 10 +
 libstdc++-v3/include/bits/version.def |  2 +-
 libstdc++-v3/include/bits/version.h   |  4 +-
 libstdc++-v3/include/std/format   | 16 +++
 .../testsuite/std/format/arguments/args.cc| 43 +++
 .../testsuite/std/format/functions/format.cc  |  4 +-
 .../testsuite/std/format/parse_ctx.cc |  2 +-
 7 files changed, 75 insertions(+), 6 deletions(-)

diff --git a/libstdc++-v3/include/bits/c++config 
b/libstdc++-v3/include/bits/c++config
index 6dca2d9467a..0f0cc7cd659 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -90,6 +90,8 @@
 //   _GLIBCXX20_DEPRECATED_SUGGEST( string-literal )
 //   _GLIBCXX23_DEPRECATED
 //   _GLIBCXX23_DEPRECATED_SUGGEST( string-literal )
+//   _GLIBCXX26_DEPRECATED
+//   _GLIBCXX26_DEPRECATED_SUGGEST( string-literal )
 #ifndef _GLIBCXX_USE_DEPRECATED
 # define _GLIBCXX_USE_DEPRECATED 1
 #endif
@@ -143,6 +145,14 @@
 # define _GLIBCXX23_DEPRECATED_SUGGEST(ALT)
 #endif
 
+#if defined(__DEPRECATED) && (__cplusplus >= 202400L)
+# define _GLIBCXX26_DEPRECATED [[__deprecated__]]
+# define _GLIBCXX26_DEPRECATED_SUGGEST(ALT) _GLIBCXX_DEPRECATED_SUGGEST(ALT)
+#else
+# define _GLIBCXX26_DEPRECATED
+# define _GLIBCXX26_DEPRECATED_SUGGEST(ALT)
+#endif
+
 // Macros for ABI tag attributes.
 #ifndef _GLIBCXX_ABI_TAG_CXX11
 # define _GLIBCXX_ABI_TAG_CXX11 __attribute ((__abi_tag__ ("cxx11")))
diff --git a/libstdc++-v3/include/bits/version.def 
b/libstdc++-v3/include/bits/version.def
index 806f1e9549b..ec330911d66 100644
--- a/libstdc++-v3/include/bits/version.def
+++ b/libstdc++-v3/include/bits/version.def
@@ -1171,7 +1171,7 @@ ftms = {
   // 202306 P2637R3 Member visit
   // 202311 P2918R2 Runtime format strings II
   values = {
-v = 202305;
+v = 202306;
 cxxmin = 26;
 hosted = yes;
   };
diff --git a/libstdc++-v3/include/bits/version.h 
b/libstdc++-v3/include/bits/version.h
index e8ca0faf5dc..148ee87e087 100644
--- a/libstdc++-v3/include/bits/version.h
+++ b/libstdc++-v3/include/bits/version.h
@@ -1310,9 +1310,9 @@
 
 #if !defined(__cpp_lib_format)
 # if (__cplusplus >  202302L) && _GLIBCXX_HOSTED
-#  define __glibcxx_format 202305L
+#  define __glibcxx_format 202306L
 #  if defined(__glibcxx_want_all) || defined(__glibcxx_want_format)
-#   define __cpp_lib_format 202305L
+#   define __cpp_lib_format 202306L
 #  endif
 # elif (__cplusplus >= 202002L) && _GLIBCXX_HOSTED
 #  define __glibcxx_format 202304L
diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index 0e61bc5e6bc..f1a1f736a80 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -3346,6 +3346,18 @@ namespace __format
   explicit operator bool() const noexcept
   { return _M_type != __format::_Arg_none; }
 
+#if __cpp_lib_format >= 202306L // >= C++26
+  template
+   decltype(auto)
+   visit(this basic_format_arg __arg, _Visitor&& __vis)
+   { return __arg._M_visit(std::forward<_Visitor>(__vis), __arg._M_type); }
+
+  template
+   _Res
+   visit(this basic_format_arg __arg, _Visitor&& __vis)
+   { return __arg._M_visit(std::forward<_Visitor>(__vis), __arg._M_type); }
+#endif
+
 private:
   template
friend class basic_format_args;
@@ -3631,6 +3643,7 @@ namespace __format
 };
 
   template
+_GLIBCXX26_DEPRECATED_SUGGEST("std::basic_format_arg::visit")
 inline decltype(auto)
 visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg)
 {
@@ -3666,6 +3679,8 @@ namespace __format
   }
   };
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
   template
 inline size_t
 __int_from_arg(const basic_format_arg<_Context>& __arg)
@@ -4299,6 +4314,7 @@ namespace __format
   else
return std::move(__sink)._M_finish().out;
 }
+#pragma GCC diagnostic pop
 
 } // namespace __format
 /// @endcond
diff --git a/libstdc++-v3/testsuite/std/format/arguments/args.cc 

[PATCH 3/6] libstdc++: Implement C++26 type checking for std::format args [PR115776]

2024-07-16 Thread Jonathan Wakely
Tested x86_64-linux.

-- >8 --

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.
---
 libstdc++-v3/include/bits/version.def |  10 +-
 libstdc++-v3/include/bits/version.h   |   7 +-
 libstdc++-v3/include/std/format   | 142 -
 .../testsuite/std/format/functions/format.cc  |   4 +
 .../testsuite/std/format/parse_ctx.cc | 145 ++
 .../testsuite/std/format/parse_ctx_neg.cc |  39 +
 libstdc++-v3/testsuite/std/format/string.cc   |  13 ++
 7 files changed, 347 insertions(+), 13 deletions(-)
 create mode 100644 libstdc++-v3/testsuite/std/format/parse_ctx_neg.cc

diff --git a/libstdc++-v3/include/bits/version.def 
b/libstdc++-v3/include/bits/version.def
index 1acc9cd5cb9..bcb33c18aa4 100644
--- a/libstdc++-v3/include/bits/version.def
+++ b/libstdc++-v3/include/bits/version.def
@@ -1165,11 +1165,11 @@ ftms = {
   // 202305 P2757R3 Type checking format args
   // 202306 P2637R3 Member visit
   // 202311 P2918R2 Runtime format strings II
-  // values = {
-// v = 202305;
-// cxxmin = 26;
-// hosted = yes;
-  // };
+  values = {
+v = 202305;
+cxxmin = 26;
+hosted = yes;
+  };
   // 201907 Text Formatting, Integration of chrono, printf corner cases.
   // 202106 std::format improvements.
   // 202110 Fixing locale handling in chrono formatters, generator-like types.
diff --git a/libstdc++-v3/include/bits/version.h 
b/libstdc++-v3/include/bits/version.h
index 5cd0e21..4d1af34bf8d 100644
--- a/libstdc++-v3/include/bits/version.h
+++ b/libstdc++-v3/include/bits/version.h
@@ -1304,7 +1304,12 @@
 #undef __glibcxx_want_barrier
 
 #if !defined(__cpp_lib_format)
-# if (__cplusplus >= 202002L) && _GLIBCXX_HOSTED
+# if (__cplusplus >  202302L) && _GLIBCXX_HOSTED
+#  define __glibcxx_format 202305L
+#  if defined(__glibcxx_want_all) || defined(__glibcxx_want_format)
+#   define __cpp_lib_format 202305L
+#  endif
+# elif (__cplusplus >= 202002L) && _GLIBCXX_HOSTED
 #  define __glibcxx_format 202304L
 #  if defined(__glibcxx_want_all) || defined(__glibcxx_want_format)
 #   define __cpp_lib_format 202304L
diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index 487177b5294..0e61bc5e6bc 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -222,6 +222,9 @@ namespace __format
   inline void
   __failed_to_parse_format_spec()
   { __throw_format_error("format error: failed to parse format-spec"); }
+
+  template class _Scanner;
+
 } // namespace __format
   /// @endcond
 
@@ -241,9 +244,8 @@ namespace __format
   using iterator = const_iterator;
 
   constexpr explicit
-  basic_format_parse_context(basic_string_view<_CharT> __fmt,
-size_t __num_args = 0) noexcept
-  : _M_begin(__fmt.begin()), _M_end(__fmt.end()), _M_num_args(__num_args)
+  basic_format_parse_context(basic_string_view<_CharT> __fmt) noexcept
+  : _M_begin(__fmt.begin()), _M_end(__fmt.end())
   { }
 
   basic_format_parse_context(const basic_format_parse_context&) = delete;
@@ -283,13 +285,78 @@ namespace __format
__format::__invalid_arg_id_in_format_string();
   }
 
+#if __cpp_lib_format >= 202305L
+  template
+   constexpr void
+   check_dynamic_spec(size_t __id) noexcept;
+
+  constexpr void
+  check_dynamic_spec_integral(size_t __id) noexcept
+  {
+   

[PATCH v3 1/6] libstdc++: Handle encodings in localized chrono formatting [PR109162]

2024-07-16 Thread Jonathan Wakely
On Fri, 12 Jul 2024 at 00:23, I wrote:
>
> I sent v1 of this patch in February, and it added the new symbols to
> libstdc++exp.a which meant users needed to use -lstdc++exp to format
> chrono types in C++23 mode. That was less than ideal.
>
> This v2 patch adds the new symbols to the main library, which means no
> extra step to get the new features, and we can enable them as a DR for
> C++20 mode. But that means we need new exports in the shared library,
> and so need to be more confident that the feature is stable and ready to
> go into the lib.
>
> I'm not 100% confident that we want to add a new, private facet to the
> std::locale, but it seems reasonable. And that's not exposed to users at
> all, as the two new symbols added to the library hide the creation and
> use of that facet.

Here's v3, which fixes a missing export of the __sso_string constructors
and destructors, needed so that the old ABI can use the new function to
transcode a locale-specific string to UTF-8, with a std::string buffer.

I haven't done so here, but we could keep a least recently used cache of
__encoding facets, so that repeatedly calling std::format with the same
locale doesn't need to keep re-checking the locale's encoding and then
re-opening the same iconv_t descriptor.

This v3 patch also tweaks the commented out parts of
include/bits/version.def in preparation for enabling the C++26 
features in the following patches in this series.

Tested x86_64-linux. I think this is ready to push now, but I'll wait a
bit for any comments on it.

-- >8 --

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.
---
 libstdc++-v3/acinclude.m4 |   2 +-
 libstdc++-v3/config/abi/pre/gnu.ver   |  18 +-
 libstdc++-v3/configure|   2 +-
 

[PATCH 4/6] libstdc++: Define C++26 member visit for std::variant [PR110356]

2024-07-16 Thread Jonathan Wakely
Tested x86_64-linux.

-- >8 --

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.
---
 libstdc++-v3/include/bits/version.def |   5 +
 libstdc++-v3/include/bits/version.h   |   7 +-
 libstdc++-v3/include/std/variant  |  48 +++
 .../testsuite/20_util/variant/visit.cc|   5 +-
 .../testsuite/20_util/variant/visit_member.cc | 117 ++
 5 files changed, 180 insertions(+), 2 deletions(-)
 create mode 100644 libstdc++-v3/testsuite/20_util/variant/visit_member.cc

diff --git a/libstdc++-v3/include/bits/version.def 
b/libstdc++-v3/include/bits/version.def
index bcb33c18aa4..806f1e9549b 100644
--- a/libstdc++-v3/include/bits/version.def
+++ b/libstdc++-v3/include/bits/version.def
@@ -478,6 +478,11 @@ ftms = {
 
 ftms = {
   name = variant;
+  values = {
+v = 202306;
+cxxmin = 26;
+extra_cond = "__cpp_concepts >= 202002L && __cpp_constexpr >= 201811L && 
__cpp_explicit_this_parameter";
+  };
   values = {
 v = 202106;
 cxxmin = 20;
diff --git a/libstdc++-v3/include/bits/version.h 
b/libstdc++-v3/include/bits/version.h
index 4d1af34bf8d..e8ca0faf5dc 100644
--- a/libstdc++-v3/include/bits/version.h
+++ b/libstdc++-v3/include/bits/version.h
@@ -529,7 +529,12 @@
 #undef __glibcxx_want_type_trait_variable_templates
 
 #if !defined(__cpp_lib_variant)
-# if (__cplusplus >= 202002L) && (__cpp_concepts >= 202002L && __cpp_constexpr 
>= 201811L)
+# if (__cplusplus >  202302L) && (__cpp_concepts >= 202002L && __cpp_constexpr 
>= 201811L && __cpp_explicit_this_parameter)
+#  define __glibcxx_variant 202306L
+#  if defined(__glibcxx_want_all) || defined(__glibcxx_want_variant)
+#   define __cpp_lib_variant 202306L
+#  endif
+# elif (__cplusplus >= 202002L) && (__cpp_concepts >= 202002L && 
__cpp_constexpr >= 201811L)
 #  define __glibcxx_variant 202106L
 #  if defined(__glibcxx_want_all) || defined(__glibcxx_want_variant)
 #   define __cpp_lib_variant 202106L
diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 3a23d9bc66d..154aab98812 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -1390,6 +1390,12 @@ namespace __detail::__variant
 constexpr __detail::__variant::__visit_result_t<_Visitor, _Variants...>
 visit(_Visitor&&, _Variants&&...);
 
+#if __cplusplus > 201703L
+  template
+constexpr _Res
+visit(_Visitor&&, _Variants&&...);
+#endif
+
   template
 _GLIBCXX20_CONSTEXPR
 inline enable_if_t<(is_move_constructible_v<_Types> && ...)
@@ -1758,6 +1764,48 @@ namespace __detail::__variant
  }, __rhs);
   }
 
+#if __cpp_lib_variant >= 202306L // >= C++26
+  // [variant.visit], visitation
+
+  /** Simple visitation for a single variant
+   *
+   * To visit a single variant you can use `var.visit(visitor)`
+   * instead of `std::visit(visitor, var)`.
+   *
+   * @since C++26
+   */
+  template
+   constexpr decltype(auto)
+   visit(this _Self&& __self, _Visitor&& __vis)
+   {
+ using _CVar = __conditional_t>,
+   const variant, variant>;
+ using _Var = __conditional_t,
+  _CVar&&, _CVar&>;
+ static_assert(is_same_v<__like_t<_Self, variant>, _Var>);
+ return std::visit(std::forward<_Visitor>(__vis), (_Var)__self);
+   }
+
+  /** Simple visitation for a single variant, with explicit return type
+   *
+   * To visit a single variant you can use `var.visit(visitor)`
+   * instead of `std::visit(visitor, var)`.
+   *
+   * @since C++26
+   */
+  template
+   constexpr _Res
+   visit(this _Self&& __self, _Visitor&& __vis)
+   {
+ using _CVar = __conditional_t>,
+   const variant, variant>;
+ using _Var = __conditional_t,
+  _CVar&&, _CVar&>;
+ static_assert(is_same_v<__like_t<_Self, variant>, _Var>);
+ return std::visit<_Res>(std::forward<_Visitor>(__vis), (_Var)__self);
+   }
+#endif
+
 private:
   template
friend constexpr decltype(auto)
diff --git a/libstdc++-v3/testsuite/20_util/variant/visit.cc 
b/libstdc++-v3/testsuite/20_util/variant/visit.cc
index 7f79e6107ab..6edc7d7c028 100644
--- a/libstdc++-v3/testsuite/20_util/variant/visit.cc
+++ b/libstdc++-v3/testsuite/20_util/variant/visit.cc
@@ -18,7 +18,7 @@
 // { dg-do run { target c++17 } }
 
 #include 
-#include 
+#include  // reference_wrapper
 #include 
 
 // N.B. there are more std::visit tests in ./compile.cc and ./run.cc
@@ 

[PATCH 2/6] libstdc++: Support P2510R3 "Formatting pointers" as a DR for C++20

2024-07-16 Thread Jonathan Wakely
Tested x86_64-linux.

-- >8 --

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.
---
 libstdc++-v3/include/bits/version.def|  6 +++---
 libstdc++-v3/include/bits/version.h  |  4 ++--
 libstdc++-v3/include/std/format  | 16 
 .../testsuite/std/format/functions/format.cc |  2 +-
 libstdc++-v3/testsuite/std/format/parse_ctx.cc   |  4 ++--
 5 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/libstdc++-v3/include/bits/version.def 
b/libstdc++-v3/include/bits/version.def
index 74947301760..1acc9cd5cb9 100644
--- a/libstdc++-v3/include/bits/version.def
+++ b/libstdc++-v3/include/bits/version.def
@@ -1162,12 +1162,11 @@ ftms = {
 
 ftms = {
   name = format;
-  // 202304 P2510R3 Formatting pointers
   // 202305 P2757R3 Type checking format args
   // 202306 P2637R3 Member visit
   // 202311 P2918R2 Runtime format strings II
   // values = {
-// v = 202304;
+// v = 202305;
 // cxxmin = 26;
 // hosted = yes;
   // };
@@ -1175,8 +1174,9 @@ ftms = {
   // 202106 std::format improvements.
   // 202110 Fixing locale handling in chrono formatters, generator-like types.
   // 202207 Encodings in localized formatting of chrono, basic-format-string.
+  // 202304 P2510R3 Formatting pointers
   values = {
-v = 202207;
+v = 202304;
 cxxmin = 20;
 hosted = yes;
   };
diff --git a/libstdc++-v3/include/bits/version.h 
b/libstdc++-v3/include/bits/version.h
index 9f8673395da..5cd0e21 100644
--- a/libstdc++-v3/include/bits/version.h
+++ b/libstdc++-v3/include/bits/version.h
@@ -1305,9 +1305,9 @@
 
 #if !defined(__cpp_lib_format)
 # if (__cplusplus >= 202002L) && _GLIBCXX_HOSTED
-#  define __glibcxx_format 202207L
+#  define __glibcxx_format 202304L
 #  if defined(__glibcxx_want_all) || defined(__glibcxx_want_format)
-#   define __cpp_lib_format 202207L
+#   define __cpp_lib_format 202304L
 #  endif
 # endif
 #endif /* !defined(__cpp_lib_format) && defined(__glibcxx_want_format) */
diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index a4921ce391b..487177b5294 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -2342,13 +2342,7 @@ namespace __format
 
 // _GLIBCXX_RESOLVE_LIB_DEFECTS
 // P2510R3 Formatting pointers
-#if __glibcxx_format >= 202304L || ! defined __STRICT_ANSI__
-# define _GLIBCXX_P2518R3 1
-#else
-# define _GLIBCXX_P2518R3 0
-#endif
-
-#if _GLIBCXX_P2518R3
+#if __glibcxx_format >= 202304L
__first = __spec._M_parse_zero_fill(__first, __last);
if (__finished())
  return __first;
@@ -2360,11 +2354,9 @@ namespace __format
  {
if (*__first == 'p')
  ++__first;
-#if _GLIBCXX_P2518R3
+#if __glibcxx_format >= 202304L
else if (*__first == 'P')
{
- // _GLIBCXX_RESOLVE_LIB_DEFECTS
- // P2510R3 Formatting pointers
  __spec._M_type = __format::_Pres_P;
  ++__first;
}
@@ -2388,7 +2380,7 @@ namespace __format
  int __n = __ptr - __buf;
  __buf[0] = '0';
  __buf[1] = 'x';
-#if _GLIBCXX_P2518R3
+#if __glibcxx_format >= 202304L
  if (_M_spec._M_type == __format::_Pres_P)
{
  __buf[1] = 'X';
@@ -2413,7 +2405,7 @@ namespace __format
}
 #endif
 
-#if _GLIBCXX_P2518R3
+#if __glibcxx_format >= 202304L
  if (_M_spec._M_zero_fill)
{
  size_t __width = _M_spec._M_get_width(__fc);
diff --git a/libstdc++-v3/testsuite/std/format/functions/format.cc 
b/libstdc++-v3/testsuite/std/format/functions/format.cc
index 78cc1ab482a..5152bb0b0d0 100644
--- a/libstdc++-v3/testsuite/std/format/functions/format.cc
+++ b/libstdc++-v3/testsuite/std/format/functions/format.cc
@@ -458,7 +458,7 @@ test_pointer()
   s = std::format("{:20} {:20p}", p, pc);
   VERIFY( s == (str_int + ' ' + str_int) );
 
-#if __cplusplus > 202302L || ! defined __STRICT_ANSI__
+#if __cpp_lib_format >= 202304L
   // P2510R3 Formatting pointers
   s = std::format("{:06} {:07P} {:08p}", (void*)0, (const void*)0, nullptr);
   VERIFY( s == "0x 0X0 0x00" );
diff --git a/libstdc++-v3/testsuite/std/format/parse_ctx.cc 
b/libstdc++-v3/testsuite/std/format/parse_ctx.cc
index 497427b54e5..3b3201c2a47 

Re: Why does sscanf fail to scan "" ? Bug?

2024-07-15 Thread Jonathan Wakely via Gcc
On Mon, 15 Jul 2024 at 14:16, U.Mutlu wrote:
>
> The below test code demonstrates that sscanf fails
> to parse the string "" (ie. an empty string inside "") in line2 (fErr=1).
> Is this a bug?

This mailing list is for discussing the development of GCC, and sscanf
is not part of GCC. The behaviour you're seeing is not caused by GCC
(and is not a bug).

> Or is there maybe a workaround format string to be used with sscanf ?

If sscanf returns 1 it means it failed to scan the "%15[^"]" string,
so you could try again using "" in the pattern.


Re: ☠ Buildbot (Sourceware): gcc-autoregen - failed 'git diff ...' (failure) (master)

2024-07-14 Thread Jonathan Wakely via Gcc-testresults
On Sun, 14 Jul 2024, 12:30 Alejandro Colomar via Gcc-help, <
gcc-h...@gcc.gnu.org> wrote:

> Hi!
>
> On Sun, Jul 14, 2024 at 10:01:34AM GMT, buil...@sourceware.org wrote:
> > A new failure has been detected on builder gcc-autoregen while building
> gcc.
> >
> > Full details are available at:
> > https://builder.sourceware.org/buildbot/#/builders/269/builds/6546
>
> Did I break anything?  I see the failure being `git diff --exit-code`,
> which doesn't seem like anything broken, but I don't know what that test
> is for, so I'll ask.
>

It checks that necessary auto-generated files have been regenerated and
committed.

If you didn't do anything related to that warning option that would have
affected the c.opts.urls file then it wasn't you (I think it was a change
from Marek).



> Cheers,
> Alex
>
> >
> > Build state: failed 'git diff ...' (failure)
> > Revision: 44c9403ed1833ae71a59e84f9e37af3182be0df5
> > Worker: bbo2
> > Build Reason: (unknown)
> > Blamelist: Alejandro Colomar 
> >
> > Steps:
> >
> > - 0: worker_preparation ( success )
> >
> > - 1: git checkout ( success )
> > Logs:
> > - stdio:
> https://builder.sourceware.org/buildbot/#/builders/269/builds/6546/steps/1/logs/stdio
> >
> > - 2: autoregen.py ( success )
> > Logs:
> > - stdio:
> https://builder.sourceware.org/buildbot/#/builders/269/builds/6546/steps/2/logs/stdio
> >
> > - 3: git diff ( success )
> > Logs:
> > - stdio:
> https://builder.sourceware.org/buildbot/#/builders/269/builds/6546/steps/3/logs/stdio
> >
> > - 4: mkdir objdir ( success )
> > Logs:
> > - stdio:
> https://builder.sourceware.org/buildbot/#/builders/269/builds/6546/steps/4/logs/stdio
> >
> > - 5: configure ( success )
> > Logs:
> > - stdio:
> https://builder.sourceware.org/buildbot/#/builders/269/builds/6546/steps/5/logs/stdio
> >
> > - 6: make html ( warnings )
> > Logs:
> > - stdio:
> https://builder.sourceware.org/buildbot/#/builders/269/builds/6546/steps/6/logs/stdio
> > - warnings (82):
> https://builder.sourceware.org/buildbot/#/builders/269/builds/6546/steps/6/logs/warnings__82_
> >
> > - 7: make regenerate-opt-urls ( success )
> > Logs:
> > - stdio:
> https://builder.sourceware.org/buildbot/#/builders/269/builds/6546/steps/7/logs/stdio
> >
> > - 8: git diff_1 ( failure )
> > Logs:
> > - stdio:
> https://builder.sourceware.org/buildbot/#/builders/269/builds/6546/steps/8/logs/stdio
> >
>
> --
> 
>


Re: [EXTERNAL] Re: g++12 broke my system of overloaded operator<

2024-07-12 Thread Jonathan Wakely via Gcc
On Fri, 12 Jul 2024 at 20:08, Dalbey, Keith  wrote:
>
> The means by which this FIX was implemented caused OTHER problems
>
> template 
> std::ostream& operator<<(std::ostream& os, const std::pair& pr)
> {
> os << "(" << pr.first << ", " << pr.second << ")";
> return os;
> }
>
> Will only work for CONCRETE classes that take the place of "F" and "S" IFF 
> each of their concrete operator<< 's is FORWARD DECLARED ahead of the above 
> template, so primitives like int and double should still work,  but if you 
> include this file in a header file that contains a concrete class that you 
> define an operator<< for, and then use in another file, you're SOL.

This is simply not true.

#include 
#include 

template 
std::ostream& operator<<(std::ostream& os, const std::pair& pr)
{
os << "(" << pr.first << ", " << pr.second << ")";
return os;
}

namespace ns {

  struct A { };

  inline std::ostream& operator<<(std::ostream& out, const A& a)
  {
return out << "A\n";
  }
}

#include 

int main()
{
  std::pair p{};
  std::cout << p;
}

This program works via ADL, because it uses namespaces correctly.

If you dump all your operator overloads in the global namespace, then
it doesn't work. So don't do that then.


Re: [EXTERNAL] Re: g++12 broke my system of overloaded operator<

2024-07-12 Thread Jonathan Wakely via Gcc
On Fri, 12 Jul 2024 at 20:08, Dalbey, Keith  wrote:
>
> The means by which this FIX was implemented caused OTHER problems
>
> template 
> std::ostream& operator<<(std::ostream& os, const std::pair& pr)
> {
> os << "(" << pr.first << ", " << pr.second << ")";
> return os;
> }
>
> Will only work for CONCRETE classes that take the place of "F" and "S" IFF 
> each of their concrete operator<< 's is FORWARD DECLARED ahead of the above 
> template, so primitives like int and double should still work,  but if you 
> include this file in a header file that contains a concrete class that you 
> define an operator<< for, and then use in another file, you're SOL.
>
> If you mix that with templated operator<< for vectors and std::shared_ptr  
> then there's a chicken and the egg problem for which STL templated operator<< 
> gets declared first/ but you can work around this by FORWARD declaring all of 
> your operator<< (including the concrete and templated ones) before 
> **Defining** the STL templated operator<< 's, but that means the header file 
> containing the STL templated operator<< 's can never be included in another 
> header file and it can only be included as *the absolute last header file* in 
> a .cpp file (so that all the concrete operator<< get declared before them, 
> and you may still need to forward declare some of the contents of the .cpp 
> file ahead of including this header file)
>
> But really a header file that can't be included in other header files and can 
> only be included as the absolute last header file in a .cpp file is a 
> unreasonable set of hoops to jump through to get TEMPLATED operator<< 's to 
> work, which should just work BECAUSE THEY'RE TEMPLATES

You keep insisting that templates should mean something that isn't
what they mean in C++, and isn't how they work in other compilers.

Maybe you should try writing correct C++ instead?


Re: [EXTERNAL] Re: g++12 broke my system of overloaded operator<

2024-07-12 Thread Jonathan Wakely via Gcc
On Fri, 12 Jul 2024 at 17:58, Dalbey, Keith via Gcc  wrote:
>
> I'm not going to argue about the change for CONCRETE operators, I'm going to 
> argue about the loss of power/flexibility for TEMPLATED operators, because it 
> defeats the whole purpose of TEMPLATED functions/operators otherwise

This is quite silly hyperbole. There are many, many good uses of
function templates that are not affected by when lookup is done, and
finding invalid declarations in the wrong scope is not "the whole
purpose" of function templates.

It's hard to take the rest of your email seriously after that.


>
> I've attached the header file in question... it's mostly about outputting STL 
> containers (like vectors, pairs, std::shared_ptr, the file name originates 
> when I was just using it for vectors but I since expanded it to other STL 
> containers, not sure that std::shared_ptr technically qualifies as a 
> "container")

The header isn't very helpful, can you show a minimal example of what
you're doing that no longer works? Maybe we can suggest how to do it
properly.

>From the header:
//put all the operator<< in the global namespace so they won't be
hidden by other custom operator<< in local namespaces

That's not how to do operator overloading, so no wonder it doesn't
work now. Lookup for operators uses Argument Dependent Lookup, which
depends on the correct use of namespaces so that the appropriate
overloads are found in associated namespaces of the argument types.

template 
inline std::ostream& operator<<(std::ostream& os, const std::pair& pr)

You should not add overloads like this for types you don't control. If
you're going to add this to the global namespace, where is typically
not going to be an associated namespace of its arguments, so ADL won't
work, then you need to make sure that the overload has been declared
prior to its use. That's really not unreasonable. Either use
namespaces properly so things can be found by ADL, or declare them
before use.

It's not reasonable to expect lookup to magically find later
declarations just because you used templates and you think that means
"find later declarations but only using infix operator syntax".


Re: g++12 broke my system of overloaded operator<

2024-07-12 Thread Jonathan Wakely via Gcc
On Fri, 12 Jul 2024 at 01:03, Dalbey, Keith via Gcc  wrote:
>
> So I'm on redhat 7 and just got devtoolsset-12 and code (a system of 
> overloaded<< operators) that was working with devtoolset-10 now break 
> (because of ordering)
>
> To not bury the lead..
>
> My code relies on the version 11 or older behavior (see below), and I don't 
> see how anyone could call the new behavior an improvement or correction 
> because it neuters/cancels out  the power/flexibility of the STL.   Yes one 
> could technically work around it by forward declaring templated operator<<  
> but that makes the system not extensible,  a common package/gitlab project 
> that handles this for the STL and then gets succeed into another library that 
> overloads the operator<< for concrete classes just doesn't work any more... 
> and that was my exact use case.
>
> Please reverse this change in future editions of gcc, it is absolutely awful.

Why would you want the example below to behave differently for
operator+(t, 0) and t+0 when they're two different ways to spell the
same function call?

The old behaviour was clearly a bug, and thankfully has been fixed.
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51577 for the bug
report I made about it years ago, which has a large number of
duplicates because other people also reported the old behaviour as a
bug. Because it was a bug, and people wanted GCC to follow the C++
standard.

I'm sorry you've written code that depends on a bug, but we're not
going to break GCC again to restore the bug.


>
> From this link
> https://developers.redhat.com/articles/2022/04/25/new-c-features-gcc-12#corrections_and_internal_improvements
> Corrections and internal improvements
> The changes described in this section bring GCC more in line with recent 
> changes to the standard, and permit behavior that previously did not work 
> correctly.
> Dependent operator lookup changes
> GCC 12 corrected a problem where the compiler performed an unqualified lookup 
> for a dependent operator expression at template definition time instead of at 
> instantiation time. The fix matches the existing behavior for dependent call 
> expressions. Consider the following test case demonstrating this change:
> #include 
>
> namespace N {
>   struct A { };
> }
>
> void operator+(N::A, double) {
>   std::cout << "#1 ";
> }
>
> template
> void f(T t) {
>   operator+(t, 0);
>   t + 0;
> }
>
> // Since it's not visible from the template definition, this later-declared
> // operator overload should not be considered when instantiating 
> f(N::A),
> // for either the call or operator expression.
> void operator+(N::A, int) {
>   std::cout << "#2 ";
> }
>
> int main() {
>   N::A a;
>   f(a);
>   std::cout << std::endl;
> }
> Copy snippet
> This program will print #1 #2 when compiled with versions 11 or older of GCC, 
> but GCC 12 correctly prints #1 #1. That's because previously only the call 
> expression resolved to the #1 overload, but with GCC 12 the operator 
> expression does too.


[gcc r13-8908] libstdc++: Fix std::to_array for trivial-ish types [PR115522]

2024-07-12 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:08463348c5cce84dc3c64ac4fbb20e2795ee104f

commit r13-8908-g08463348c5cce84dc3c64ac4fbb20e2795ee104f
Author: Jonathan Wakely 
Date:   Tue Jun 18 13:27:02 2024 +0100

libstdc++: Fix std::to_array for trivial-ish types [PR115522]

Due to PR c++/85723 the std::is_trivial trait is true for types with a
deleted default constructor, so the use of std::is_trivial in
std::to_array is not sufficient to ensure the type can be trivially
default constructed then filled using memcpy.

I also forgot that a type with a deleted assignment operator can still
be trivial, so we also need to check that it's assignable because the
is_constant_evaluated() path can't use memcpy.

Replace the uses of std::is_trivial with std::is_trivially_copyable
(needed for memcpy), std::is_trivially_default_constructible (needed so
that the default construction is valid and does no work) and
std::is_copy_assignable (needed for the constant evaluation case).

libstdc++-v3/ChangeLog:

PR libstdc++/115522
* include/std/array (to_array): Workaround the fact that
std::is_trivial is not sufficient to check that a type is
trivially default constructible and assignable.
* testsuite/23_containers/array/creation/115522.cc: New test.

(cherry picked from commit 510ce5eed69ee1bea9c2c696fe3b2301e16d1486)

Diff:
---
 libstdc++-v3/include/std/array |  8 --
 .../23_containers/array/creation/115522.cc | 33 ++
 2 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array
index edcac892b52d..dd9b4a0ab038 100644
--- a/libstdc++-v3/include/std/array
+++ b/libstdc++-v3/include/std/array
@@ -426,7 +426,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   static_assert(is_constructible_v<_Tp, _Tp&>);
   if constexpr (is_constructible_v<_Tp, _Tp&>)
{
- if constexpr (is_trivial_v<_Tp>)
+ if constexpr (is_trivially_copyable_v<_Tp>
+ && is_trivially_default_constructible_v<_Tp>
+ && is_copy_assignable_v<_Tp>)
{
  array, _Nm> __arr;
  if (!__is_constant_evaluated() && _Nm != 0)
@@ -455,7 +457,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   static_assert(is_move_constructible_v<_Tp>);
   if constexpr (is_move_constructible_v<_Tp>)
{
- if constexpr (is_trivial_v<_Tp>)
+ if constexpr (is_trivially_copyable_v<_Tp>
+ && is_trivially_default_constructible_v<_Tp>
+ && is_copy_assignable_v<_Tp>)
{
  array, _Nm> __arr;
  if (!__is_constant_evaluated() && _Nm != 0)
diff --git a/libstdc++-v3/testsuite/23_containers/array/creation/115522.cc 
b/libstdc++-v3/testsuite/23_containers/array/creation/115522.cc
new file mode 100644
index ..37073e002bdb
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/array/creation/115522.cc
@@ -0,0 +1,33 @@
+// { dg-do compile { target c++20 } }
+
+// PR libstdc++/115522 std::to_array no longer works for struct which is
+// trivial but not default constructible
+
+#include 
+
+void
+test_deleted_ctor()
+{
+  struct S
+  {
+S() = delete;
+S(int) { }
+  };
+
+  S arr[1] = {{1}};
+  auto arr1 = std::to_array(arr);
+  auto arr2 = std::to_array(std::move(arr));
+}
+
+void
+test_deleted_assignment()
+{
+  struct S
+  {
+void operator=(const S&) = delete;
+  };
+
+  S arr[1] = {};
+  auto a1 = std::to_array(arr);
+  auto a2 = std::to_array(std::move(arr));
+}


[gcc r14-10413] libstdc++: Fix unwanted #pragma messages from PSTL headers [PR113376]

2024-07-12 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:d920658cbb200729b7c2ad069fa4b6498e028ff1

commit r14-10413-gd920658cbb200729b7c2ad069fa4b6498e028ff1
Author: Jonathan Wakely 
Date:   Wed Jun 12 16:47:17 2024 +0100

libstdc++: Fix unwanted #pragma messages from PSTL headers [PR113376]

When we rebased the PSTL on upstream, in r14-2109-g3162ca09dbdc2e, a
change to how _PSTL_USAGE_WARNINGS is set was missed out, but the change
to how it's tested was included. This means that the macro is always
defined, so testing it with #ifdef (instead of using #if to test its
value) doesn't work as intended.

Revert the test to use #if again, since that part of the upstream change
was unnecessary in the first place (the macro is always defined, so
there's no need to use #ifdef to avoid -Wundef warnings).

libstdc++-v3/ChangeLog:

PR libstdc++/113376
* include/pstl/pstl_config.h: Use #if instead of #ifdef to test
the _PSTL_USAGE_WARNINGS macro.

(cherry picked from commit 99a1fe6c12c733fe4923a75a79d09a66ff8abcec)

Diff:
---
 libstdc++-v3/include/pstl/pstl_config.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/pstl/pstl_config.h 
b/libstdc++-v3/include/pstl/pstl_config.h
index ccb9dd32838d..e157e4d486f6 100644
--- a/libstdc++-v3/include/pstl/pstl_config.h
+++ b/libstdc++-v3/include/pstl/pstl_config.h
@@ -177,7 +177,7 @@
 
 #define _PSTL_PRAGMA_MESSAGE_IMPL(x) 
_PSTL_PRAGMA(message(_PSTL_STRING_CONCAT(_PSTL_PRAGMA_LOCATION, x)))
 
-#if defined(_PSTL_USAGE_WARNINGS)
+#if _PSTL_USAGE_WARNINGS
 #define _PSTL_PRAGMA_MESSAGE(x) _PSTL_PRAGMA_MESSAGE_IMPL(x)
 #define _PSTL_PRAGMA_MESSAGE_POLICIES(x) _PSTL_PRAGMA_MESSAGE_IMPL(x)
 #else


[gcc r14-10412] libstdc++: Fix std::to_array for trivial-ish types [PR115522]

2024-07-12 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:21c8708ba638f57cf904c8af3355318d9cf0f9e0

commit r14-10412-g21c8708ba638f57cf904c8af3355318d9cf0f9e0
Author: Jonathan Wakely 
Date:   Tue Jun 18 13:27:02 2024 +0100

libstdc++: Fix std::to_array for trivial-ish types [PR115522]

Due to PR c++/85723 the std::is_trivial trait is true for types with a
deleted default constructor, so the use of std::is_trivial in
std::to_array is not sufficient to ensure the type can be trivially
default constructed then filled using memcpy.

I also forgot that a type with a deleted assignment operator can still
be trivial, so we also need to check that it's assignable because the
is_constant_evaluated() path can't use memcpy.

Replace the uses of std::is_trivial with std::is_trivially_copyable
(needed for memcpy), std::is_trivially_default_constructible (needed so
that the default construction is valid and does no work) and
std::is_copy_assignable (needed for the constant evaluation case).

libstdc++-v3/ChangeLog:

PR libstdc++/115522
* include/std/array (to_array): Workaround the fact that
std::is_trivial is not sufficient to check that a type is
trivially default constructible and assignable.
* testsuite/23_containers/array/creation/115522.cc: New test.

(cherry picked from commit 510ce5eed69ee1bea9c2c696fe3b2301e16d1486)

Diff:
---
 libstdc++-v3/include/std/array |  8 --
 .../23_containers/array/creation/115522.cc | 33 ++
 2 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array
index 39695471e245..8710bf75924b 100644
--- a/libstdc++-v3/include/std/array
+++ b/libstdc++-v3/include/std/array
@@ -431,7 +431,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   static_assert(is_constructible_v<_Tp, _Tp&>);
   if constexpr (is_constructible_v<_Tp, _Tp&>)
{
- if constexpr (is_trivial_v<_Tp>)
+ if constexpr (is_trivially_copyable_v<_Tp>
+ && is_trivially_default_constructible_v<_Tp>
+ && is_copy_assignable_v<_Tp>)
{
  array, _Nm> __arr;
  if (!__is_constant_evaluated() && _Nm != 0)
@@ -460,7 +462,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   static_assert(is_move_constructible_v<_Tp>);
   if constexpr (is_move_constructible_v<_Tp>)
{
- if constexpr (is_trivial_v<_Tp>)
+ if constexpr (is_trivially_copyable_v<_Tp>
+ && is_trivially_default_constructible_v<_Tp>
+ && is_copy_assignable_v<_Tp>)
{
  array, _Nm> __arr;
  if (!__is_constant_evaluated() && _Nm != 0)
diff --git a/libstdc++-v3/testsuite/23_containers/array/creation/115522.cc 
b/libstdc++-v3/testsuite/23_containers/array/creation/115522.cc
new file mode 100644
index ..37073e002bdb
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/array/creation/115522.cc
@@ -0,0 +1,33 @@
+// { dg-do compile { target c++20 } }
+
+// PR libstdc++/115522 std::to_array no longer works for struct which is
+// trivial but not default constructible
+
+#include 
+
+void
+test_deleted_ctor()
+{
+  struct S
+  {
+S() = delete;
+S(int) { }
+  };
+
+  S arr[1] = {{1}};
+  auto arr1 = std::to_array(arr);
+  auto arr2 = std::to_array(std::move(arr));
+}
+
+void
+test_deleted_assignment()
+{
+  struct S
+  {
+void operator=(const S&) = delete;
+  };
+
+  S arr[1] = {};
+  auto a1 = std::to_array(arr);
+  auto a2 = std::to_array(std::move(arr));
+}


[gcc r11-11573] libstdc++: Add missing exports for ppc64le --with-long-double-format=ibm [PR105417]

2024-07-12 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:30ffca55041518b76cfd59877250a740a615b5ba

commit r11-11573-g30ffca55041518b76cfd59877250a740a615b5ba
Author: Jonathan Wakely 
Date:   Fri Apr 29 12:17:13 2022 +0100

libstdc++: Add missing exports for ppc64le --with-long-double-format=ibm 
[PR105417]

The --with-long-double-abi=ibm build is missing some exports that are
present in the --with-long-double-abi=ieee build. Those symbols never
should have been exported at all, but now that they have been, they
should be exported consistently by both ibm and ieee.

This simply defines them as aliases for equivalent symbols that are
already present. The abi-tag on num_get::_M_extract_int isn't really
needed, because it only uses a std::string as a local variable, not in
the return type or function parameters, so it's safe to define the
_M_extract_int[abi:cxx11] symbols as aliases for the corresponding
function without the abi-tag.

This causes some new symbols to be added to the GLIBCXX_3.4.29 version
for the ibm long double build mode, but there is no advantage to adding
them to 3.4.30 for that build. That would just create more
inconsistencies.

libstdc++-v3/ChangeLog:

PR libstdc++/105417
* config/abi/post/powerpc64-linux-gnu/baseline_symbols.txt:
Regenerate.
* src/c++11/compatibility-ldbl-alt128.cc [_GLIBCXX_USE_DUAL_ABI]:
Define __gnu_ieee128::num_get::_M_extract_int[abi:cxx11]
symbols as aliases for corresponding symbols without abi-tag.

(cherry picked from commit bb7cf39b05a216431a431499d0c36a6034f6acc4)

Diff:
---
 .../post/powerpc64-linux-gnu/baseline_symbols.txt  | 12 
 .../src/c++11/compatibility-ldbl-alt128.cc | 36 ++
 2 files changed, 48 insertions(+)

diff --git 
a/libstdc++-v3/config/abi/post/powerpc64-linux-gnu/baseline_symbols.txt 
b/libstdc++-v3/config/abi/post/powerpc64-linux-gnu/baseline_symbols.txt
index 941c96eb3ff4..e1cbf6510bd1 100644
--- a/libstdc++-v3/config/abi/post/powerpc64-linux-gnu/baseline_symbols.txt
+++ b/libstdc++-v3/config/abi/post/powerpc64-linux-gnu/baseline_symbols.txt
@@ -548,6 +548,12 @@ 
FUNC:_ZNKSt15basic_streambufIwSt11char_traitsIwEE6getlocEv@@GLIBCXX_3.4
 FUNC:_ZNKSt15basic_stringbufIcSt11char_traitsIcESaIcEE3strEv@@GLIBCXX_3.4
 FUNC:_ZNKSt15basic_stringbufIwSt11char_traitsIwESaIwEE3strEv@@GLIBCXX_3.4
 FUNC:_ZNKSt16bad_array_length4whatEv@@CXXABI_1.3.8
+FUNC:_ZNKSt17__gnu_cxx_ieee1287num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE14_M_extract_intB5cxx11IjEES4_S4_S4_RSt8ios_baseRSt12_Ios_IostateRT_@@GLIBCXX_IEEE128_3.4.29
+FUNC:_ZNKSt17__gnu_cxx_ieee1287num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE14_M_extract_intB5cxx11IlEES4_S4_S4_RSt8ios_baseRSt12_Ios_IostateRT_@@GLIBCXX_IEEE128_3.4.29
+FUNC:_ZNKSt17__gnu_cxx_ieee1287num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE14_M_extract_intB5cxx11ImEES4_S4_S4_RSt8ios_baseRSt12_Ios_IostateRT_@@GLIBCXX_IEEE128_3.4.29
+FUNC:_ZNKSt17__gnu_cxx_ieee1287num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE14_M_extract_intB5cxx11ItEES4_S4_S4_RSt8ios_baseRSt12_Ios_IostateRT_@@GLIBCXX_IEEE128_3.4.29
+FUNC:_ZNKSt17__gnu_cxx_ieee1287num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE14_M_extract_intB5cxx11IxEES4_S4_S4_RSt8ios_baseRSt12_Ios_IostateRT_@@GLIBCXX_IEEE128_3.4.29
+FUNC:_ZNKSt17__gnu_cxx_ieee1287num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE14_M_extract_intB5cxx11IyEES4_S4_S4_RSt8ios_baseRSt12_Ios_IostateRT_@@GLIBCXX_IEEE128_3.4.29
 
FUNC:_ZNKSt17__gnu_cxx_ieee1287num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE14_M_extract_intIjEES4_S4_S4_RSt8ios_baseRSt12_Ios_IostateRT_@@GLIBCXX_IEEE128_3.4.29
 
FUNC:_ZNKSt17__gnu_cxx_ieee1287num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE14_M_extract_intIlEES4_S4_S4_RSt8ios_baseRSt12_Ios_IostateRT_@@GLIBCXX_IEEE128_3.4.29
 
FUNC:_ZNKSt17__gnu_cxx_ieee1287num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE14_M_extract_intImEES4_S4_S4_RSt8ios_baseRSt12_Ios_IostateRT_@@GLIBCXX_IEEE128_3.4.29
@@ -579,6 +585,12 @@ 
FUNC:_ZNKSt17__gnu_cxx_ieee1287num_getIcSt19istreambuf_iteratorIcSt11char_traits
 
FUNC:_ZNKSt17__gnu_cxx_ieee1287num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE6do_getES4_S4_RSt8ios_baseRSt12_Ios_IostateRy@@GLIBCXX_IEEE128_3.4.29
 
FUNC:_ZNKSt17__gnu_cxx_ieee1287num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE8__do_getES4_S4_RSt8ios_baseRSt12_Ios_IostateRd@@GLIBCXX_IEEE128_3.4.29
 
FUNC:_ZNKSt17__gnu_cxx_ieee1287num_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE8__do_getES4_S4_RSt8ios_baseRSt12_Ios_IostateRg@@GLIBCXX_IEEE128_3.4.29
+FUNC:_ZNKSt17__gnu_cxx_ieee1287num_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE14_M_extract_intB5cxx11IjEES4_S4_S4_RSt8ios_baseRSt12_Ios_IostateRT_@@GLIBCXX_IEEE128_3.4.29
+FUNC

Re: [PATCH] [libstdc++] [testsuite] avoid arbitrary errno codes

2024-07-12 Thread Jonathan Wakely
On Fri, 12 Jul 2024 at 10:27, Jonathan Wakely  wrote:
>
> On Fri, 12 Jul 2024 at 09:27, Alexandre Oliva  wrote:
> >
> > On Jul 11, 2024, Jonathan Wakely  wrote:
> >
> > > There's no requirement that system_error uses strerror, that's just an
> > > implementation detail.
> >
> > *nod*.  I meant it was more of a libc test in the case that relied on
> > strerror.  But I fully agree that testing the C++ standard API makes
> > perfect sense.  It's just that maybe we want workarounds for cases in
> > which we implement in terms of libc, but libc doesn't live up to the
> > standard.  Tolerating NULL returns from strerror would be an easy one;
> > do we want that?  Checking strerror acceptable ranges (that don't
> > trigger runtime errors) before calling it, and taking an alternate path
> > when needed, that would be harder to do, and IMHO of dubious value.
>
> Yes, handling a null result from strerror seems sensible if that's the 
> reality.

Does this fix it for your target?

--- a/libstdc++-v3/src/c++11/system_error.cc
+++ b/libstdc++-v3/src/c++11/system_error.cc
@@ -110,7 +110,11 @@ namespace
#else
  string strerror_string(int err)
  {
-return strerror(err); // XXX Not thread-safe.
+auto str = strerror(err); // XXX Not thread-safe.
+if (str) [[__likely__]]
+  return str;
+// strerror should not return NULL, but some implementations do.
+return "Unknown error";
  }
#endif



Re: [PATCH] [libstdc++] [testsuite] avoid arbitrary errno codes

2024-07-12 Thread Jonathan Wakely
On Fri, 12 Jul 2024 at 09:27, Alexandre Oliva  wrote:
>
> On Jul 11, 2024, Jonathan Wakely  wrote:
>
> > There's no requirement that system_error uses strerror, that's just an
> > implementation detail.
>
> *nod*.  I meant it was more of a libc test in the case that relied on
> strerror.  But I fully agree that testing the C++ standard API makes
> perfect sense.  It's just that maybe we want workarounds for cases in
> which we implement in terms of libc, but libc doesn't live up to the
> standard.  Tolerating NULL returns from strerror would be an easy one;
> do we want that?  Checking strerror acceptable ranges (that don't
> trigger runtime errors) before calling it, and taking an alternate path
> when needed, that would be harder to do, and IMHO of dubious value.

Yes, handling a null result from strerror seems sensible if that's the reality.



[PATCH v2] libstdc++: Handle encodings in localized chrono formatting [PR109162]

2024-07-11 Thread Jonathan Wakely
I sent v1 of this patch in February, and it added the new symbols to
libstdc++exp.a which meant users needed to use -lstdc++exp to format
chrono types in C++23 mode. That was less than ideal.

This v2 patch adds the new symbols to the main library, which means no
extra step to get the new features, and we can enable them as a DR for
C++20 mode. But that means we need new exports in the shared library,
and so need to be more confident that the feature is stable and ready to
go into the lib.

I'm not 100% confident that we want to add a new, private facet to the
std::locale, but it seems reasonable. And that's not exposed to users at
all, as the two new symbols added to the library hide the creation and
use of that facet.

-- >8 --

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.
---
 libstdc++-v3/acinclude.m4 |   2 +-
 libstdc++-v3/config/abi/pre/gnu.ver   |  16 +-
 libstdc++-v3/configure|   2 +-
 libstdc++-v3/include/bits/chrono_io.h |  96 --
 libstdc++-v3/include/bits/version.def |  34 +++-
 libstdc++-v3/include/bits/version.h   |  11 +-
 libstdc++-v3/include/std/format   |  16 +-
 libstdc++-v3/src/c++20/Makefile.am|   8 +-
 libstdc++-v3/src/c++20/Makefile.in|  10 +-
 libstdc++-v3/src/c++20/format.cc  | 174 ++
 .../testsuite/std/time/format_localized.cc|  47 +
 libstdc++-v3/testsuite/util/testsuite_abi.cc  |   1 +
 12 files changed, 387 insertions(+), 30 deletions(-)
 create mode 100644 libstdc++-v3/src/c++20/format.cc
 create mode 100644 libstdc++-v3/testsuite/std/time/format_localized.cc

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index e04aae25360..e4ed583b3ae 100644
--- 

[committed] libstdc++: the specialization atomic_ref should use the primary template

2024-07-11 Thread Jonathan Wakely
On Thu, 23 May 2024 at 00:06, Lebrun-Grandie, Damien wrote:
>
> See patch attached to this email.

Thanks for the patch. Sorry it took a while, but I've now pushed it to
trunk, along with the test below.

Tested x86_64-linux. Pushed to trunk.

-- >8 --

The previous commit changed atomic_ref to not use the integral
specialization. This adds a test to verify that change. We can't
directly test that the primary template is used, but we can check that
the member functions of the integral specializations are not present.

libstdc++-v3/ChangeLog:

* testsuite/29_atomics/atomic_ref/bool.cc: New test.
---
 .../testsuite/29_atomics/atomic_ref/bool.cc   | 15 +++
 1 file changed, 15 insertions(+)
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic_ref/bool.cc

diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_ref/bool.cc 
b/libstdc++-v3/testsuite/29_atomics/atomic_ref/bool.cc
new file mode 100644
index 000..4702932627e
--- /dev/null
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_ref/bool.cc
@@ -0,0 +1,15 @@
+// { dg-do compile { target c++20 } }
+
+#include 
+
+template concept has_and = requires (T& a) { a &= false; };
+template concept has_or = requires (T& a) { a |= false; };
+template concept has_xor = requires (T& a) { a ^= false; };
+template concept has_fetch_add = requires (T& a) { a.fetch_add(true); 
};
+template concept has_fetch_sub = requires (T& a) { a.fetch_sub(true); 
};
+
+static_assert( not has_and> );
+static_assert( not has_or> );
+static_assert( not has_xor> );
+static_assert( not has_fetch_add> );
+static_assert( not has_fetch_sub> );
-- 
2.45.2



[gcc r15-1981] libstdc++: Test that std::atomic_ref uses the primary template

2024-07-11 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:43763bd75f1d37189ba08657a322e91d240e8cf3

commit r15-1981-g43763bd75f1d37189ba08657a322e91d240e8cf3
Author: Jonathan Wakely 
Date:   Thu Jul 11 21:23:15 2024 +0100

libstdc++: Test that std::atomic_ref uses the primary template

The previous commit changed atomic_ref to not use the integral
specialization. This adds a test to verify that change. We can't
directly test that the primary template is used, but we can check that
the member functions of the integral specializations are not present.

libstdc++-v3/ChangeLog:

* testsuite/29_atomics/atomic_ref/bool.cc: New test.

Diff:
---
 libstdc++-v3/testsuite/29_atomics/atomic_ref/bool.cc | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_ref/bool.cc 
b/libstdc++-v3/testsuite/29_atomics/atomic_ref/bool.cc
new file mode 100644
index ..4702932627e8
--- /dev/null
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_ref/bool.cc
@@ -0,0 +1,15 @@
+// { dg-do compile { target c++20 } }
+
+#include 
+
+template concept has_and = requires (T& a) { a &= false; };
+template concept has_or = requires (T& a) { a |= false; };
+template concept has_xor = requires (T& a) { a ^= false; };
+template concept has_fetch_add = requires (T& a) { a.fetch_add(true); 
};
+template concept has_fetch_sub = requires (T& a) { a.fetch_sub(true); 
};
+
+static_assert( not has_and> );
+static_assert( not has_or> );
+static_assert( not has_xor> );
+static_assert( not has_fetch_add> );
+static_assert( not has_fetch_sub> );


[gcc r15-1980] libstdc++: the specialization atomic_ref should use the primary template

2024-07-11 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:79d3f17b07884cc9486f5e6fb21beea97c153a55

commit r15-1980-g79d3f17b07884cc9486f5e6fb21beea97c153a55
Author: Damien Lebrun-Grandie 
Date:   Wed May 22 17:43:45 2024 -0400

libstdc++: the specialization atomic_ref should use the primary 
template

Per [atomics.ref.int] `bool` is excluded from the list of integral types
for which there is a specialization of the `atomic_ref` class template
and [Note 1] clearly states that `atomic_ref` "uses the primary
template" instead.

libstdc++-v3/ChangeLog:

* include/bits/atomic_base.h (__atomic_ref): Do not use integral
specialization for bool.

Signed-off-by: Damien Lebrun-Grandie 

Diff:
---
 libstdc++-v3/include/bits/atomic_base.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/atomic_base.h 
b/libstdc++-v3/include/bits/atomic_base.h
index 20901b7fc06f..1c2367b39b66 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -1478,7 +1478,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #undef _GLIBCXX20_INIT
 
   template, bool = is_floating_point_v<_Tp>>
+   bool = is_integral_v<_Tp> && !is_same_v<_Tp, bool>,
+   bool = is_floating_point_v<_Tp>>
 struct __atomic_ref;
 
   // base class for non-integral, non-floating-point, non-pointer types


[gcc r11-11571] libstdc++: Reverse arguments in constraint for std::optional's <=> [PR104606]

2024-07-11 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:1e0d60c6b097e9b0a96f7e763a10da11c412ef2c

commit r11-11571-g1e0d60c6b097e9b0a96f7e763a10da11c412ef2c
Author: Jonathan Wakely 
Date:   Wed Mar 27 21:51:13 2024 +

libstdc++: Reverse arguments in constraint for std::optional's <=> 
[PR104606]

This is a workaround for a possible compiler bug that causes constraint
recursion in the operator<=>(const optional&, const U&) overload.

libstdc++-v3/ChangeLog:

PR libstdc++/104606
* include/std/optional (operator<=>(const optional&, const U&)):
Reverse order of three_way_comparable_with template arguments.
* testsuite/20_util/optional/relops/104606.cc: New test.

(cherry picked from commit 7f65d8267fbfd19cf21a3dc71d27e989e75044a3)

Diff:
---
 libstdc++-v3/include/std/optional  |  2 +-
 .../testsuite/20_util/optional/relops/104606.cc| 18 ++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/optional 
b/libstdc++-v3/include/std/optional
index 449c27a80c46..b3fbd98c569a 100644
--- a/libstdc++-v3/include/std/optional
+++ b/libstdc++-v3/include/std/optional
@@ -1248,7 +1248,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template
 requires (!__is_optional_v<_Up>)
-  && three_way_comparable_with<_Tp, _Up>
+  && three_way_comparable_with<_Up, _Tp>
 constexpr compare_three_way_result_t<_Tp, _Up>
 operator<=>(const optional<_Tp>& __x, const _Up& __v)
 { return bool(__x) ? *__x <=> __v : strong_ordering::less; }
diff --git a/libstdc++-v3/testsuite/20_util/optional/relops/104606.cc 
b/libstdc++-v3/testsuite/20_util/optional/relops/104606.cc
new file mode 100644
index ..2b8df2452199
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/optional/relops/104606.cc
@@ -0,0 +1,18 @@
+// { dg-do compile { target c++17 } }
+
+// Bug 104606 comparison operator resolution with std::optional and -std=c++20
+
+#include 
+#include 
+#include 
+
+struct Value : std::variant> { };
+
+struct Comparator {
+  template  bool operator<=(const T &) { return true; }
+};
+
+std::optional o;
+Comparator c;
+
+auto x = c <= o;


Re: [PATCH] [libstdc++] [testsuite] avoid arbitrary errno codes

2024-07-11 Thread Jonathan Wakely
On Thu, 11 Jul 2024 at 17:23, Alexandre Oliva  wrote:
>
> On Jul 11, 2024, Jonathan Wakely  wrote:
>
> > And std::system_error doesn't limit the values that can be passed to
> > it either. So I'd prefer to keep testing with arbitrary int values,
> > because that *should* work.
>
> Fair enough, thanks.  I've seen portability documentation suggesting
> that strerror returns NULL on some systems, if the error code is
> unknown, and it didn't seem to me that libstdc++ was prepared to deal
> with that.  I'm not sure this system, on which I saw the failure,
> returns NULL or fails in some other way, but it's clear its behavior is
> not compliant with the relevant standards.  It makes sense to test for
> this condition, though IMHO that makes it more of a libc test than a
> libstdc++ test,

There's no requirement that system_error uses strerror, that's just an
implementation detail. So I think it makes sense to test at the user
visible API level that system_error works with arbitrary values, even
though that ends up depending on whether libc strerror also supports
them.

> compared with the patched version I proposed.  Not that
> I object to that :-)  I just hadn't understood the goal.
>
> Patch withdrawn.
>
> --
> Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
>Free Software Activist   GNU Toolchain Engineer
> More tolerance and less prejudice are key for inclusion and diversity
> Excluding neuro-others for not behaving ""normal"" is *not* inclusive
>



[committed] libstdc++: Disable expensive test for debug mode [PR108636]

2024-07-11 Thread Jonathan Wakely
Tested x86_64-linux. Pushed to trunk.

-- >8 --

This test uses -fkeep-inline-functions and with debug mode enabled that
compiles much slower and times out if the system is under heavy load.

The original problem being tested is independent of debug mode, so just
require normal mode for the test.

libstdc++-v3/ChangeLog:

PR libstdc++/108636
* testsuite/27_io/filesystem/path/108636.cc: Require normal
mode.
---
 libstdc++-v3/testsuite/27_io/filesystem/path/108636.cc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/108636.cc 
b/libstdc++-v3/testsuite/27_io/filesystem/path/108636.cc
index 73742df93b0..48435525d36 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/path/108636.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/108636.cc
@@ -1,6 +1,7 @@
 // { dg-do link { target c++17 } }
 // { dg-options "-fkeep-inline-functions" }
 // { dg-require-filesystem-ts "" }
+// { dg-require-normal-mode "too slow with debug mode" }
 
 #include 
 int main()
-- 
2.45.2



[gcc r15-1974] libstdc++: Disable expensive test for debug mode [PR108636]

2024-07-11 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:8dbc02ba43d9e89056f4ba21d664118377f7da40

commit r15-1974-g8dbc02ba43d9e89056f4ba21d664118377f7da40
Author: Jonathan Wakely 
Date:   Thu Jul 11 09:40:12 2024 +0100

libstdc++: Disable expensive test for debug mode [PR108636]

This test uses -fkeep-inline-functions and with debug mode enabled that
compiles much slower and times out if the system is under heavy load.

The original problem being tested is independent of debug mode, so just
require normal mode for the test.

libstdc++-v3/ChangeLog:

PR libstdc++/108636
* testsuite/27_io/filesystem/path/108636.cc: Require normal
mode.

Diff:
---
 libstdc++-v3/testsuite/27_io/filesystem/path/108636.cc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/108636.cc 
b/libstdc++-v3/testsuite/27_io/filesystem/path/108636.cc
index 73742df93b05..48435525d363 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/path/108636.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/108636.cc
@@ -1,6 +1,7 @@
 // { dg-do link { target c++17 } }
 // { dg-options "-fkeep-inline-functions" }
 // { dg-require-filesystem-ts "" }
+// { dg-require-normal-mode "too slow with debug mode" }
 
 #include 
 int main()


Re: [PATCH] [libstdc++] [testsuite] xfail 128bit from_chars on all aarch64-*-*

2024-07-11 Thread Jonathan Wakely
On Thu, 11 Jul 2024 at 14:21, Alexandre Oliva  wrote:
>
>
> Having observed failures of these two tests on yet another aarch64
> operating system, and having concluded that the conditions that
> trigger the problem ought to be present on all aarch64 targets, I'm
> now matching any aarch64 target_os to enable the workaround.

That's concerning, aarch64-unknown-linux-gnu with glibc should work OK
for float128_t, because aarch64 already has 128-bit long double, so
there's no good reason that float128_t wouldn't work. What are the
conditions that trigger the problem?

I've only just noticed that the macro name makes no sense, as this is
about float128_t, not long double. They're distinct types (although
for aarch64 they have the same representation). So we should at the
very least rename the macro to something like SKIP_FLOAT128, but I'd
also like to understand why float128_t fails on a target where long
double works OK and has the same binary128 representation.

>
> Regstrapped on x86_64-linux-gnu, also tested with gcc-13 targeting
> aarch64.  Ok to install?
>
>
> for  libstdc++-v3/ChangeLog
>
> * testsuite/20_util/from_chars/8.cc: Define SKIP_LONG_DOUBLE
> on all aarch64-*-* targets.
> * testsuite/20_util/to_chars/float128_c++23.cc: Xfail on all
> aarch64-*-* targets.
> ---
>  libstdc++-v3/testsuite/20_util/from_chars/8.cc |2 +-
>  .../testsuite/20_util/to_chars/float128_c++23.cc   |2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libstdc++-v3/testsuite/20_util/from_chars/8.cc 
> b/libstdc++-v3/testsuite/20_util/from_chars/8.cc
> index bacad89943b5f..e92b64349025e 100644
> --- a/libstdc++-v3/testsuite/20_util/from_chars/8.cc
> +++ b/libstdc++-v3/testsuite/20_util/from_chars/8.cc
> @@ -17,7 +17,7 @@
>
>  // { dg-do run { target c++23 } }
>  // { dg-add-options ieee }
> -// { dg-additional-options "-DSKIP_LONG_DOUBLE" { target aarch64-*-vxworks* 
> aarch64-*-rtems* } }
> +// { dg-additional-options "-DSKIP_LONG_DOUBLE" { target aarch64-*-* } }
>
>  #include 
>  #include 
> diff --git a/libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc 
> b/libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc
> index 6cb9cadcd2041..840131c1e5691 100644
> --- a/libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc
> +++ b/libstdc++-v3/testsuite/20_util/to_chars/float128_c++23.cc
> @@ -19,7 +19,7 @@
>  // { dg-require-effective-target ieee_floats }
>  // { dg-require-effective-target size32plus }
>  // { dg-add-options ieee }
> -// { dg-xfail-run-if "from_chars limited to double-precision" { 
> aarch64-*-vxworks* aarch64-*-rtems* } }
> +// { dg-xfail-run-if "from_chars limited to double-precision" { aarch64-*-* 
> } }
>
>  #include 
>  #include 
>
>
> --
> Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
>Free Software Activist   GNU Toolchain Engineer
> More tolerance and less prejudice are key for inclusion and diversity
> Excluding neuro-others for not behaving ""normal"" is *not* inclusive
>



Re: [PATCH] [libstdc++] [testsuite] require dfprt on some tests

2024-07-11 Thread Jonathan Wakely
On Thu, 11 Jul 2024 at 15:28, Jonathan Wakely  wrote:
>
> On Thu, 11 Jul 2024 at 14:22, Alexandre Oliva  wrote:
> >
> >
> > On a target that doesn't enable decimal float components in libgcc
> > (because the libc doens't define all required FE_* macros), but whose
> > compiler supports _Decimal* types, the effective target requirement
> > dfp passes, but several tests won't link because the runtime support
> > they depend on is missing.  State their dfprt requirement.
> >
> > Regstrapped on x86_64-linux-gnu, also tested with gcc-13 targeting
> > aarch64.  Ok to install?
>
> OK, thanks.

btw, you touched it last, so now you own the decimal floating-point code ;-)

>
>
> >
> >
> > for  libstdc++-v3/ChangeLog
> >
> > * testsuite/decimal/binary-arith.cc: Require dfprt.
> > * testsuite/decimal/comparison.cc: Likewise.
> > * testsuite/decimal/compound-assignment-memfunc.cc: Likewise.
> > * testsuite/decimal/make-decimal.cc: Likewise.
> > * testsuite/decimal/pr54036-1.cc: Likewise.
> > * testsuite/decimal/pr54036-2.cc: Likewise.
> > * testsuite/decimal/pr54036-3.cc: Likewise.
> > * testsuite/decimal/unary-arith.cc: Likewise.
> > ---
> >  libstdc++-v3/testsuite/decimal/binary-arith.cc |2 +-
> >  libstdc++-v3/testsuite/decimal/comparison.cc   |2 +-
> >  .../decimal/compound-assignment-memfunc.cc |2 +-
> >  .../testsuite/decimal/compound-assignment.cc   |2 +-
> >  libstdc++-v3/testsuite/decimal/make-decimal.cc |2 +-
> >  libstdc++-v3/testsuite/decimal/pr54036-1.cc|2 +-
> >  libstdc++-v3/testsuite/decimal/pr54036-2.cc|2 +-
> >  libstdc++-v3/testsuite/decimal/pr54036-3.cc|2 +-
> >  libstdc++-v3/testsuite/decimal/unary-arith.cc  |2 +-
> >  9 files changed, 9 insertions(+), 9 deletions(-)
> >
> > diff --git a/libstdc++-v3/testsuite/decimal/binary-arith.cc 
> > b/libstdc++-v3/testsuite/decimal/binary-arith.cc
> > index c10a8b6466cb0..3eeed7ea97501 100644
> > --- a/libstdc++-v3/testsuite/decimal/binary-arith.cc
> > +++ b/libstdc++-v3/testsuite/decimal/binary-arith.cc
> > @@ -15,7 +15,7 @@
> >  // with this library; see the file COPYING3.  If not see
> >  // <http://www.gnu.org/licenses/>.
> >
> > -// { dg-require-effective-target dfp }
> > +// { dg-require-effective-target dfprt }
> >
> >  // ISO/IEC TR 24733  3.2.8  Binary arithmetic operators.
> >
> > diff --git a/libstdc++-v3/testsuite/decimal/comparison.cc 
> > b/libstdc++-v3/testsuite/decimal/comparison.cc
> > index cf34c8d74badc..424dd8bd26659 100644
> > --- a/libstdc++-v3/testsuite/decimal/comparison.cc
> > +++ b/libstdc++-v3/testsuite/decimal/comparison.cc
> > @@ -15,7 +15,7 @@
> >  // with this library; see the file COPYING3.  If not see
> >  // <http://www.gnu.org/licenses/>.
> >
> > -// { dg-require-effective-target dfp }
> > +// { dg-require-effective-target dfprt }
> >
> >  // ISO/IEC TR 24733  3.2.9  Comparison operators.
> >
> > diff --git a/libstdc++-v3/testsuite/decimal/compound-assignment-memfunc.cc 
> > b/libstdc++-v3/testsuite/decimal/compound-assignment-memfunc.cc
> > index 817d4bb10b1e9..d520af9a68d49 100644
> > --- a/libstdc++-v3/testsuite/decimal/compound-assignment-memfunc.cc
> > +++ b/libstdc++-v3/testsuite/decimal/compound-assignment-memfunc.cc
> > @@ -15,7 +15,7 @@
> >  // with this library; see the file COPYING3.  If not see
> >  // <http://www.gnu.org/licenses/>.
> >
> > -// { dg-require-effective-target dfp }
> > +// { dg-require-effective-target dfprt }
> >
> >  // ISO/IEC TR 24733  3.2.2.6  Compound assignment (decimal32).
> >  // ISO/IEC TR 24733  3.2.3.6  Compound assignment (decimal64).
> > diff --git a/libstdc++-v3/testsuite/decimal/compound-assignment.cc 
> > b/libstdc++-v3/testsuite/decimal/compound-assignment.cc
> > index 2d3e325856988..5aa87e78a739a 100644
> > --- a/libstdc++-v3/testsuite/decimal/compound-assignment.cc
> > +++ b/libstdc++-v3/testsuite/decimal/compound-assignment.cc
> > @@ -15,7 +15,7 @@
> >  // with this library; see the file COPYING3.  If not see
> >  // <http://www.gnu.org/licenses/>.
> >
> > -// { dg-require-effective-target dfp }
> > +// { dg-require-effective-target dfprt }
> >
> >  // ISO/IEC TR 24733  3.2.2.6  Compound assignment (decimal32).
> >  // ISO/IEC TR 24733  3.2.3.6  Compound assignment (decimal64).
> > diff --git a/libstdc++-v3/testsuite/decimal/make-decimal.cc 
>

Re: [PATCH] [libstdc++] [testsuite] require dfprt on some tests

2024-07-11 Thread Jonathan Wakely
On Thu, 11 Jul 2024 at 14:22, Alexandre Oliva  wrote:
>
>
> On a target that doesn't enable decimal float components in libgcc
> (because the libc doens't define all required FE_* macros), but whose
> compiler supports _Decimal* types, the effective target requirement
> dfp passes, but several tests won't link because the runtime support
> they depend on is missing.  State their dfprt requirement.
>
> Regstrapped on x86_64-linux-gnu, also tested with gcc-13 targeting
> aarch64.  Ok to install?

OK, thanks.


>
>
> for  libstdc++-v3/ChangeLog
>
> * testsuite/decimal/binary-arith.cc: Require dfprt.
> * testsuite/decimal/comparison.cc: Likewise.
> * testsuite/decimal/compound-assignment-memfunc.cc: Likewise.
> * testsuite/decimal/make-decimal.cc: Likewise.
> * testsuite/decimal/pr54036-1.cc: Likewise.
> * testsuite/decimal/pr54036-2.cc: Likewise.
> * testsuite/decimal/pr54036-3.cc: Likewise.
> * testsuite/decimal/unary-arith.cc: Likewise.
> ---
>  libstdc++-v3/testsuite/decimal/binary-arith.cc |2 +-
>  libstdc++-v3/testsuite/decimal/comparison.cc   |2 +-
>  .../decimal/compound-assignment-memfunc.cc |2 +-
>  .../testsuite/decimal/compound-assignment.cc   |2 +-
>  libstdc++-v3/testsuite/decimal/make-decimal.cc |2 +-
>  libstdc++-v3/testsuite/decimal/pr54036-1.cc|2 +-
>  libstdc++-v3/testsuite/decimal/pr54036-2.cc|2 +-
>  libstdc++-v3/testsuite/decimal/pr54036-3.cc|2 +-
>  libstdc++-v3/testsuite/decimal/unary-arith.cc  |2 +-
>  9 files changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/libstdc++-v3/testsuite/decimal/binary-arith.cc 
> b/libstdc++-v3/testsuite/decimal/binary-arith.cc
> index c10a8b6466cb0..3eeed7ea97501 100644
> --- a/libstdc++-v3/testsuite/decimal/binary-arith.cc
> +++ b/libstdc++-v3/testsuite/decimal/binary-arith.cc
> @@ -15,7 +15,7 @@
>  // with this library; see the file COPYING3.  If not see
>  // .
>
> -// { dg-require-effective-target dfp }
> +// { dg-require-effective-target dfprt }
>
>  // ISO/IEC TR 24733  3.2.8  Binary arithmetic operators.
>
> diff --git a/libstdc++-v3/testsuite/decimal/comparison.cc 
> b/libstdc++-v3/testsuite/decimal/comparison.cc
> index cf34c8d74badc..424dd8bd26659 100644
> --- a/libstdc++-v3/testsuite/decimal/comparison.cc
> +++ b/libstdc++-v3/testsuite/decimal/comparison.cc
> @@ -15,7 +15,7 @@
>  // with this library; see the file COPYING3.  If not see
>  // .
>
> -// { dg-require-effective-target dfp }
> +// { dg-require-effective-target dfprt }
>
>  // ISO/IEC TR 24733  3.2.9  Comparison operators.
>
> diff --git a/libstdc++-v3/testsuite/decimal/compound-assignment-memfunc.cc 
> b/libstdc++-v3/testsuite/decimal/compound-assignment-memfunc.cc
> index 817d4bb10b1e9..d520af9a68d49 100644
> --- a/libstdc++-v3/testsuite/decimal/compound-assignment-memfunc.cc
> +++ b/libstdc++-v3/testsuite/decimal/compound-assignment-memfunc.cc
> @@ -15,7 +15,7 @@
>  // with this library; see the file COPYING3.  If not see
>  // .
>
> -// { dg-require-effective-target dfp }
> +// { dg-require-effective-target dfprt }
>
>  // ISO/IEC TR 24733  3.2.2.6  Compound assignment (decimal32).
>  // ISO/IEC TR 24733  3.2.3.6  Compound assignment (decimal64).
> diff --git a/libstdc++-v3/testsuite/decimal/compound-assignment.cc 
> b/libstdc++-v3/testsuite/decimal/compound-assignment.cc
> index 2d3e325856988..5aa87e78a739a 100644
> --- a/libstdc++-v3/testsuite/decimal/compound-assignment.cc
> +++ b/libstdc++-v3/testsuite/decimal/compound-assignment.cc
> @@ -15,7 +15,7 @@
>  // with this library; see the file COPYING3.  If not see
>  // .
>
> -// { dg-require-effective-target dfp }
> +// { dg-require-effective-target dfprt }
>
>  // ISO/IEC TR 24733  3.2.2.6  Compound assignment (decimal32).
>  // ISO/IEC TR 24733  3.2.3.6  Compound assignment (decimal64).
> diff --git a/libstdc++-v3/testsuite/decimal/make-decimal.cc 
> b/libstdc++-v3/testsuite/decimal/make-decimal.cc
> index aa75ac89d4792..560196cb305e1 100644
> --- a/libstdc++-v3/testsuite/decimal/make-decimal.cc
> +++ b/libstdc++-v3/testsuite/decimal/make-decimal.cc
> @@ -15,7 +15,7 @@
>  // with this library; see the file COPYING3.  If not see
>  // .
>
> -// { dg-require-effective-target dfp }
> +// { dg-require-effective-target dfprt }
>  // { dg-options "-Wno-pedantic" }
>
>  // ISO/IEC TR 24733  3.2.5  Initialization from coefficient and exponent.
> diff --git a/libstdc++-v3/testsuite/decimal/pr54036-1.cc 
> b/libstdc++-v3/testsuite/decimal/pr54036-1.cc
> index 508738701ca01..a07e4c351651c 100644
> --- a/libstdc++-v3/testsuite/decimal/pr54036-1.cc
> +++ b/libstdc++-v3/testsuite/decimal/pr54036-1.cc
> @@ -15,7 +15,7 @@
>  // with this library; see the file COPYING3.  If not see
>  // .
>
> -// { 

Re: [PATCH] [libstdc++] [testsuite] avoid arbitrary errno codes

2024-07-11 Thread Jonathan Wakely
On Thu, 11 Jul 2024 at 14:23, Alexandre Oliva  wrote:
>
>
> Passing an arbitrary error number to strerror* functions doesn't seem
> to be portable; 19_diagnostics/system_error/cons-1.cc is hitting
> runtime errors in the block that attempts to instantiate a
> std:;system_error for error number 95.  The range of errno macros
> defined on this target doesn't reach 95.

The C standard is clear:

"Typically, the values for errnum come from errno, but strerror shall
map any value of type int to a message. "

And std::system_error doesn't limit the values that can be passed to
it either. So I'd prefer to keep testing with arbitrary int values,
because that *should* work.


>
> I'm changing the test to try to use a couple of select error codes,
> falling back to a lower error number if neither are present.
> Hopefully this doesn't change the nature of what is being tested for.

I think it does.

>
> Regstrapped on x86_64-linux-gnu, also tested with gcc-13 targeting
> aarch64.  Ok to install?
>
>
> for  libstdc++-v3/ChangeLog
>
> * testsuite/19_diagnostics/system_error/cons-1.cc: Use lower
> error numbers, preferring some macro-defined ones.
> ---
>  .../19_diagnostics/system_error/cons-1.cc  |   14 --
>  1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/libstdc++-v3/testsuite/19_diagnostics/system_error/cons-1.cc 
> b/libstdc++-v3/testsuite/19_diagnostics/system_error/cons-1.cc
> index 16aa960b2ee28..e227c67542411 100644
> --- a/libstdc++-v3/testsuite/19_diagnostics/system_error/cons-1.cc
> +++ b/libstdc++-v3/testsuite/19_diagnostics/system_error/cons-1.cc
> @@ -37,8 +37,18 @@ int main()
>
>// 2
>{
> -std::system_error err2(95, std::system_category(), s);
> -VERIFY( err2.code() == std::error_code(95, std::system_category()) );
> +int eno;
> +#if defined EOPNOTSUPP
> +eno = EOPNOTSUPP;
> +#elif defined ENOSYS
> +eno = ENOSYS;
> +#else
> +// strerror (used to combine with the given message) may fail if
> +// the error number is out of range for the system.
> +eno = 42;
> +#endif
> +std::system_error err2(eno, std::system_category(), s);
> +VERIFY( err2.code() == std::error_code(eno, std::system_category()) );
>  VERIFY( std::string((err2.what(), s)).find(s) != std::string::npos );
>}
>
>
> --
> Alexandre Oliva, happy hackerhttps://FSFLA.org/blogs/lxo/
>Free Software Activist   GNU Toolchain Engineer
> More tolerance and less prejudice are key for inclusion and diversity
> Excluding neuro-others for not behaving ""normal"" is *not* inclusive
>



[committed] libstdc++: Make std::basic_format_context non-copyable [PR114387]

2024-07-10 Thread Jonathan Wakely
Tested x86_64-linux. Pushed to trunk. Probably a good idea to backport
it to 13 and 14, for consistency.

-- >8 --

Users are not supposed to create objects of this type, and there's no
reason it needs to be copyable. LWG 4061 makes it non-copyable and
non-default constructible.

libstdc++-v3/ChangeLog:

PR libstdc++/114387
* include/std/format (basic_format_context): Define copy
operations as deleted, as per LWG 4061.
* testsuite/std/format/context.cc: New test.
---
 libstdc++-v3/include/std/format  |  7 +++-
 libstdc++-v3/testsuite/std/format/context.cc | 36 
 2 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 libstdc++-v3/testsuite/std/format/context.cc

diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index 48deba2bcb2..16cee0d3c74 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -3851,6 +3851,12 @@ namespace __format
   : _M_args(__args), _M_out(std::move(__out)), _M_loc(__loc)
   { }
 
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 4061. Should std::basic_format_context be
+  //   default-constructible/copyable/movable?
+  basic_format_context(const basic_format_context&) = delete;
+  basic_format_context& operator=(const basic_format_context&) = delete;
+
   template
friend _Out2
__format::__do_vformat_to(_Out2, basic_string_view<_CharT2>,
@@ -3858,7 +3864,6 @@ namespace __format
  const locale*);
 
 public:
-  basic_format_context() = default;
   ~basic_format_context() = default;
 
   using iterator = _Out;
diff --git a/libstdc++-v3/testsuite/std/format/context.cc 
b/libstdc++-v3/testsuite/std/format/context.cc
new file mode 100644
index 000..5cc5e9c9ba2
--- /dev/null
+++ b/libstdc++-v3/testsuite/std/format/context.cc
@@ -0,0 +1,36 @@
+// { dg-do compile { target c++20 } }
+
+#include 
+
+template
+concept format_context_reqs = std::is_destructible_v
+  && (!std::is_default_constructible_v)
+  && (!std::is_copy_constructible_v)
+  && (!std::is_move_constructible_v)
+  && (!std::is_copy_assignable_v)
+  && (!std::is_move_assignable_v)
+  && requires (Context& ctx, const Context& cctx) {
+typename Context::iterator;
+typename Context::char_type;
+requires std::same_as,
+ std::formatter>;
+{ ctx.locale() } -> std::same_as;
+{ ctx.out() } -> std::same_as;
+{ ctx.advance_to(ctx.out()) } -> std::same_as;
+{ cctx.arg(1) } -> std::same_as>;
+  };
+
+template
+constexpr bool
+check(std::basic_format_context*)
+{
+  using context = std::basic_format_context;
+  static_assert( format_context_reqs );
+  static_assert( std::is_same_v );
+  static_assert( std::is_same_v );
+  return true;
+}
+
+static_assert( check( (std::format_context*)nullptr) );
+static_assert( check( (std::wformat_context*)nullptr) );
+static_assert( check( (std::basic_format_context*)nullptr) );
-- 
2.45.2



[committed] libstdc++: Minor optimization for std::locale::encoding()

2024-07-10 Thread Jonathan Wakely
Tested x86_64-linux. Pushed to trunk.

-- >8 --

For the C locale we know the encoding is ASCII, so we can avoid using
newlocale and nl_langinfo_l. Similarly, for an unnamed locale, we aren't
going to get a useful answer, so we can just use a default-constrcuted
std::text_encoding representing an unknown encoding.

libstdc++-v3/ChangeLog:

* src/c++26/text_encoding.cc (__locale_encoding): Add to unnamed
namespace.
(std::locale::encoding): Optimize for "C" and "*" names.
---
 libstdc++-v3/src/c++26/text_encoding.cc | 16 +---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/src/c++26/text_encoding.cc 
b/libstdc++-v3/src/c++26/text_encoding.cc
index b9a50ef1a00..efe2997562a 100644
--- a/libstdc++-v3/src/c++26/text_encoding.cc
+++ b/libstdc++-v3/src/c++26/text_encoding.cc
@@ -36,7 +36,9 @@
 namespace std
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
-
+namespace
+{
+// Attempt to determine the text_encoding used by the named locale.
 text_encoding
 __locale_encoding(const char* name)
 {
@@ -54,6 +56,7 @@ __locale_encoding(const char* name)
   return enc;
 }
 
+} // namespace
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
 
@@ -87,8 +90,15 @@ std::text_encoding::_M_is_environment() const
 std::text_encoding
 std::locale::encoding() const
 {
-  return std::__locale_encoding(name().c_str());
+  string name = this->name();
+  if (name.length() == 1)
+{
+  if (name[0] == 'C')
+   return text_encoding(text_encoding::ASCII);
+  if (name[0] == '*')
+   return {};
+}
+  return __locale_encoding(name.c_str());
 }
 #endif // CHAR_BIT == 8
-
 #endif // _GLIBCXX_USE_NL_LANGINFO_L
-- 
2.45.2



[gcc r15-1958] libstdc++: Make std::basic_format_context non-copyable [PR114387]

2024-07-10 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:d8cd8521185436ea45ed48c5dd481277e9b8a98d

commit r15-1958-gd8cd8521185436ea45ed48c5dd481277e9b8a98d
Author: Jonathan Wakely 
Date:   Wed Jul 10 10:27:24 2024 +0100

libstdc++: Make std::basic_format_context non-copyable [PR114387]

Users are not supposed to create objects of this type, and there's no
reason it needs to be copyable. LWG 4061 makes it non-copyable and
non-default constructible.

libstdc++-v3/ChangeLog:

PR libstdc++/114387
* include/std/format (basic_format_context): Define copy
operations as deleted, as per LWG 4061.
* testsuite/std/format/context.cc: New test.

Diff:
---
 libstdc++-v3/include/std/format  |  7 +-
 libstdc++-v3/testsuite/std/format/context.cc | 36 
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index 48deba2bcb2d..16cee0d3c74d 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -3851,6 +3851,12 @@ namespace __format
   : _M_args(__args), _M_out(std::move(__out)), _M_loc(__loc)
   { }
 
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 4061. Should std::basic_format_context be
+  //   default-constructible/copyable/movable?
+  basic_format_context(const basic_format_context&) = delete;
+  basic_format_context& operator=(const basic_format_context&) = delete;
+
   template
friend _Out2
__format::__do_vformat_to(_Out2, basic_string_view<_CharT2>,
@@ -3858,7 +3864,6 @@ namespace __format
  const locale*);
 
 public:
-  basic_format_context() = default;
   ~basic_format_context() = default;
 
   using iterator = _Out;
diff --git a/libstdc++-v3/testsuite/std/format/context.cc 
b/libstdc++-v3/testsuite/std/format/context.cc
new file mode 100644
index ..5cc5e9c9ba22
--- /dev/null
+++ b/libstdc++-v3/testsuite/std/format/context.cc
@@ -0,0 +1,36 @@
+// { dg-do compile { target c++20 } }
+
+#include 
+
+template
+concept format_context_reqs = std::is_destructible_v
+  && (!std::is_default_constructible_v)
+  && (!std::is_copy_constructible_v)
+  && (!std::is_move_constructible_v)
+  && (!std::is_copy_assignable_v)
+  && (!std::is_move_assignable_v)
+  && requires (Context& ctx, const Context& cctx) {
+typename Context::iterator;
+typename Context::char_type;
+requires std::same_as,
+ std::formatter>;
+{ ctx.locale() } -> std::same_as;
+{ ctx.out() } -> std::same_as;
+{ ctx.advance_to(ctx.out()) } -> std::same_as;
+{ cctx.arg(1) } -> std::same_as>;
+  };
+
+template
+constexpr bool
+check(std::basic_format_context*)
+{
+  using context = std::basic_format_context;
+  static_assert( format_context_reqs );
+  static_assert( std::is_same_v );
+  static_assert( std::is_same_v );
+  return true;
+}
+
+static_assert( check( (std::format_context*)nullptr) );
+static_assert( check( (std::wformat_context*)nullptr) );
+static_assert( check( (std::basic_format_context*)nullptr) );


[gcc r15-1957] libstdc++: Minor optimization for std::locale::encoding()

2024-07-10 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:9f758953eb2cb89e306025dc232ae20da6cb860a

commit r15-1957-g9f758953eb2cb89e306025dc232ae20da6cb860a
Author: Jonathan Wakely 
Date:   Wed Jul 10 17:47:56 2024 +0100

libstdc++: Minor optimization for std::locale::encoding()

For the C locale we know the encoding is ASCII, so we can avoid using
newlocale and nl_langinfo_l. Similarly, for an unnamed locale, we aren't
going to get a useful answer, so we can just use a default-constrcuted
std::text_encoding representing an unknown encoding.

libstdc++-v3/ChangeLog:

* src/c++26/text_encoding.cc (__locale_encoding): Add to unnamed
namespace.
(std::locale::encoding): Optimize for "C" and "*" names.

Diff:
---
 libstdc++-v3/src/c++26/text_encoding.cc | 16 +---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/src/c++26/text_encoding.cc 
b/libstdc++-v3/src/c++26/text_encoding.cc
index b9a50ef1a001..efe2997562a4 100644
--- a/libstdc++-v3/src/c++26/text_encoding.cc
+++ b/libstdc++-v3/src/c++26/text_encoding.cc
@@ -36,7 +36,9 @@
 namespace std
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
-
+namespace
+{
+// Attempt to determine the text_encoding used by the named locale.
 text_encoding
 __locale_encoding(const char* name)
 {
@@ -54,6 +56,7 @@ __locale_encoding(const char* name)
   return enc;
 }
 
+} // namespace
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
 
@@ -87,8 +90,15 @@ std::text_encoding::_M_is_environment() const
 std::text_encoding
 std::locale::encoding() const
 {
-  return std::__locale_encoding(name().c_str());
+  string name = this->name();
+  if (name.length() == 1)
+{
+  if (name[0] == 'C')
+   return text_encoding(text_encoding::ASCII);
+  if (name[0] == '*')
+   return {};
+}
+  return __locale_encoding(name.c_str());
 }
 #endif // CHAR_BIT == 8
-
 #endif // _GLIBCXX_USE_NL_LANGINFO_L


[committed] libstdc++: Use direct-initialization for std::vector's allocator [PR115854]

2024-07-10 Thread Jonathan Wakely
Tested x86_64-linux. Pushed to trunk. Backports could follow.

-- >8 --

The consensus in the standard committee is that this change shouldn't be
necessary, and the Allocator requirements should require conversions
between rebound allocators to be implicit. But we can make it work for
now anyway.

libstdc++-v3/ChangeLog:

PR libstdc++/115854
* include/bits/stl_bvector.h (_Bvector_base): Convert allocator
to rebound type explicitly.
* testsuite/23_containers/vector/allocator/115854.cc: New test.
* testsuite/23_containers/vector/bool/allocator/115854.cc: New test.
---
 libstdc++-v3/include/bits/stl_bvector.h|  2 +-
 .../testsuite/23_containers/vector/allocator/115854.cc | 10 ++
 .../23_containers/vector/bool/allocator/115854.cc  | 10 ++
 3 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 
libstdc++-v3/testsuite/23_containers/vector/allocator/115854.cc
 create mode 100644 
libstdc++-v3/testsuite/23_containers/vector/bool/allocator/115854.cc

diff --git a/libstdc++-v3/include/bits/stl_bvector.h 
b/libstdc++-v3/include/bits/stl_bvector.h
index 8685cc64cc4..245e1c3b3a7 100644
--- a/libstdc++-v3/include/bits/stl_bvector.h
+++ b/libstdc++-v3/include/bits/stl_bvector.h
@@ -654,7 +654,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 
   _GLIBCXX20_CONSTEXPR
   _Bvector_base(const allocator_type& __a)
-  : _M_impl(__a) { }
+  : _M_impl(_Bit_alloc_type(__a)) { }
 
 #if __cplusplus >= 201103L
   _Bvector_base(_Bvector_base&&) = default;
diff --git a/libstdc++-v3/testsuite/23_containers/vector/allocator/115854.cc 
b/libstdc++-v3/testsuite/23_containers/vector/allocator/115854.cc
new file mode 100644
index 000..6c9016b311f
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/allocator/115854.cc
@@ -0,0 +1,10 @@
+// { dg-do compile { target c++11 } }
+
+#include 
+#include 
+
+__gnu_test::ExplicitConsAlloc alloc;
+std::vector> v;
+std::vector> v1(alloc);
+std::vector> v2(v1, alloc);
+std::vector> v3(std::move(v1), alloc);
diff --git 
a/libstdc++-v3/testsuite/23_containers/vector/bool/allocator/115854.cc 
b/libstdc++-v3/testsuite/23_containers/vector/bool/allocator/115854.cc
new file mode 100644
index 000..14b28cc3e96
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/bool/allocator/115854.cc
@@ -0,0 +1,10 @@
+// { dg-do compile { target c++11 } }
+
+#include 
+#include 
+
+__gnu_test::ExplicitConsAlloc alloc;
+std::vector> v;
+std::vector> v1(alloc);
+std::vector> v2(v1, alloc);
+std::vector> v3(std::move(v1), 
alloc);
-- 
2.45.2



[gcc r15-1956] libstdc++: Use direct-initialization for std::vector's allocator [PR115854]

2024-07-10 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:c5efc6eca8e3eee7038ae218cf7e2dbe9ed9d82a

commit r15-1956-gc5efc6eca8e3eee7038ae218cf7e2dbe9ed9d82a
Author: Jonathan Wakely 
Date:   Wed Jul 10 10:29:52 2024 +0100

libstdc++: Use direct-initialization for std::vector's allocator 
[PR115854]

The consensus in the standard committee is that this change shouldn't be
necessary, and the Allocator requirements should require conversions
between rebound allocators to be implicit. But we can make it work for
now anyway.

libstdc++-v3/ChangeLog:

PR libstdc++/115854
* include/bits/stl_bvector.h (_Bvector_base): Convert allocator
to rebound type explicitly.
* testsuite/23_containers/vector/allocator/115854.cc: New test.
* testsuite/23_containers/vector/bool/allocator/115854.cc: New test.

Diff:
---
 libstdc++-v3/include/bits/stl_bvector.h|  2 +-
 .../testsuite/23_containers/vector/allocator/115854.cc | 10 ++
 .../testsuite/23_containers/vector/bool/allocator/115854.cc| 10 ++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/stl_bvector.h 
b/libstdc++-v3/include/bits/stl_bvector.h
index 8685cc64cc44..245e1c3b3a77 100644
--- a/libstdc++-v3/include/bits/stl_bvector.h
+++ b/libstdc++-v3/include/bits/stl_bvector.h
@@ -654,7 +654,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 
   _GLIBCXX20_CONSTEXPR
   _Bvector_base(const allocator_type& __a)
-  : _M_impl(__a) { }
+  : _M_impl(_Bit_alloc_type(__a)) { }
 
 #if __cplusplus >= 201103L
   _Bvector_base(_Bvector_base&&) = default;
diff --git a/libstdc++-v3/testsuite/23_containers/vector/allocator/115854.cc 
b/libstdc++-v3/testsuite/23_containers/vector/allocator/115854.cc
new file mode 100644
index ..6c9016b311f2
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/allocator/115854.cc
@@ -0,0 +1,10 @@
+// { dg-do compile { target c++11 } }
+
+#include 
+#include 
+
+__gnu_test::ExplicitConsAlloc alloc;
+std::vector> v;
+std::vector> v1(alloc);
+std::vector> v2(v1, alloc);
+std::vector> v3(std::move(v1), alloc);
diff --git 
a/libstdc++-v3/testsuite/23_containers/vector/bool/allocator/115854.cc 
b/libstdc++-v3/testsuite/23_containers/vector/bool/allocator/115854.cc
new file mode 100644
index ..14b28cc3e964
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/bool/allocator/115854.cc
@@ -0,0 +1,10 @@
+// { dg-do compile { target c++11 } }
+
+#include 
+#include 
+
+__gnu_test::ExplicitConsAlloc alloc;
+std::vector> v;
+std::vector> v1(alloc);
+std::vector> v2(v1, alloc);
+std::vector> v3(std::move(v1), 
alloc);


Re: [PATCH] libstdc++: ranges::find needs explicit conversion to size_t [PR115799]

2024-07-10 Thread Jonathan Wakely
Pushed to trunk.

On Mon, 8 Jul 2024 at 20:44, Jonathan Wakely  wrote:
>
> This fixes another problem with my recent changes to use memchr in
> std::find.
>
> Tested x86_64-linux.
>
> -- >8 --
>
> For an integer-class type we need to use an explicit conversion to size_t.
>
> libstdc++-v3/ChangeLog:
>
> PR libstdc++/115799
> * include/bits/ranges_util.h (__find_fn): Make conversion
> from difference type ti size_t explicit.
> * testsuite/25_algorithms/find/bytes.cc: Check ranges::find with
> __gnu_test::test_contiguous_range.
> * testsuite/std/ranges/range.cc: Adjust expected difference_type
> for __gnu_test::test_contiguous_range.
> * testsuite/util/testsuite_iterators.h (contiguous_iterator_wrapper):
> Use __max_diff_type as difference type.
> (test_range::sentinel, test_sized_range_sized_sent::sentinel):
> Ensure that operator- returns difference_type.
> ---
>  libstdc++-v3/include/bits/ranges_util.h   |  3 +-
>  .../testsuite/25_algorithms/find/bytes.cc | 10 +
>  libstdc++-v3/testsuite/std/ranges/range.cc|  5 ++-
>  .../testsuite/util/testsuite_iterators.h  | 42 ++-
>  4 files changed, 48 insertions(+), 12 deletions(-)
>
> diff --git a/libstdc++-v3/include/bits/ranges_util.h 
> b/libstdc++-v3/include/bits/ranges_util.h
> index a1f42875b11..e6d96073e87 100644
> --- a/libstdc++-v3/include/bits/ranges_util.h
> +++ b/libstdc++-v3/include/bits/ranges_util.h
> @@ -506,9 +506,10 @@ namespace ranges
> if (static_cast<_Vt>(__value) == __value) [[likely]]
>   if (__n > 0)
> {
> + const size_t __nu = static_cast(__n);
>   const int __ival = static_cast(__value);
>   const void* __p0 = std::to_address(__first);
> - if (auto __p1 = __builtin_memchr(__p0, __ival, __n))
> + if (auto __p1 = __builtin_memchr(__p0, __ival, 
> __nu))
> __n = (const char*)__p1 - (const char*)__p0;
> }
> return __first + __n;
> diff --git a/libstdc++-v3/testsuite/25_algorithms/find/bytes.cc 
> b/libstdc++-v3/testsuite/25_algorithms/find/bytes.cc
> index e1d6c01ab21..03dada0fec7 100644
> --- a/libstdc++-v3/testsuite/25_algorithms/find/bytes.cc
> +++ b/libstdc++-v3/testsuite/25_algorithms/find/bytes.cc
> @@ -114,9 +114,19 @@ test_non_characters()
>  #endif
>  }
>
> +#if __cpp_lib_ranges
> +void
> +test_pr115799c0(__gnu_test::test_contiguous_range r)
> +{
> +  // Non-common range with integer-class type as difference_type.
> +  (void) std::ranges::find(r, 'a');
> +}
> +#endif
> +
>  void
>  test_pr115799c2(__gnu_test::input_iterator_wrapper i)
>  {
> +  // Non-contiguous range of character type.
>(void) std::find(i, i, 'a');
>  }
>
> diff --git a/libstdc++-v3/testsuite/std/ranges/range.cc 
> b/libstdc++-v3/testsuite/std/ranges/range.cc
> index 760f6ffacfd..5464a9bf66b 100644
> --- a/libstdc++-v3/testsuite/std/ranges/range.cc
> +++ b/libstdc++-v3/testsuite/std/ranges/range.cc
> @@ -56,6 +56,7 @@ static_assert( 
> std::ranges::range&> );
>  using std::same_as;
>
>  using C = test_contiguous_range;
> +using R = test_random_access_range;
>  using I = test_input_range;
>  using O = test_output_range;
>
> @@ -69,7 +70,9 @@ static_assert( same_as,
>  static_assert( same_as,
>decltype(std::declval().end())> );
>
> -static_assert( same_as,
> +static_assert( ! same_as,
> +std::ptrdiff_t> ); // __detail::__max_diff_type
> +static_assert( same_as,
>std::ptrdiff_t> );
>  static_assert( same_as,
>std::ptrdiff_t> );
> diff --git a/libstdc++-v3/testsuite/util/testsuite_iterators.h 
> b/libstdc++-v3/testsuite/util/testsuite_iterators.h
> index ec2971284b4..e7f7abe222d 100644
> --- a/libstdc++-v3/testsuite/util/testsuite_iterators.h
> +++ b/libstdc++-v3/testsuite/util/testsuite_iterators.h
> @@ -34,6 +34,10 @@
>  #include 
>  #endif
>
> +#if __cplusplus > 201703L
> +#include 
> +#endif
> +
>  #ifndef _TESTSUITE_ITERATORS
>  #define _TESTSUITE_ITERATORS
>
> @@ -675,6 +679,9 @@ namespace __gnu_test
>
>using iterator_concept = std::contiguous_iterator_tag;
>
> +  // Use an integer-class type to try and break the library code.
> +  using difference_type = std::ranges::__detail::__max_diff_type;
> +
>contiguous_iterator_wrapper&
>operator++()
>{
>

[gcc r15-1955] libstdc++: ranges::find needs explicit conversion to size_t [PR115799]

2024-07-10 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:cda469a59e222496248025e0834a15d466f79d4a

commit r15-1955-gcda469a59e222496248025e0834a15d466f79d4a
Author: Jonathan Wakely 
Date:   Mon Jul 8 10:45:52 2024 +0100

libstdc++: ranges::find needs explicit conversion to size_t [PR115799]

For an integer-class type we need to use an explicit conversion to size_t.

libstdc++-v3/ChangeLog:

PR libstdc++/115799
* include/bits/ranges_util.h (__find_fn): Make conversion
from difference type ti size_t explicit.
* testsuite/25_algorithms/find/bytes.cc: Check ranges::find with
__gnu_test::test_contiguous_range.
* testsuite/std/ranges/range.cc: Adjust expected difference_type
for __gnu_test::test_contiguous_range.
* testsuite/util/testsuite_iterators.h 
(contiguous_iterator_wrapper):
Use __max_diff_type as difference type.
(test_range::sentinel, test_sized_range_sized_sent::sentinel):
Ensure that operator- returns difference_type.

Diff:
---
 libstdc++-v3/include/bits/ranges_util.h|  3 +-
 libstdc++-v3/testsuite/25_algorithms/find/bytes.cc | 10 ++
 libstdc++-v3/testsuite/std/ranges/range.cc |  5 ++-
 libstdc++-v3/testsuite/util/testsuite_iterators.h  | 42 --
 4 files changed, 48 insertions(+), 12 deletions(-)

diff --git a/libstdc++-v3/include/bits/ranges_util.h 
b/libstdc++-v3/include/bits/ranges_util.h
index a1f42875b11d..e6d96073e87b 100644
--- a/libstdc++-v3/include/bits/ranges_util.h
+++ b/libstdc++-v3/include/bits/ranges_util.h
@@ -506,9 +506,10 @@ namespace ranges
if (static_cast<_Vt>(__value) == __value) [[likely]]
  if (__n > 0)
{
+ const size_t __nu = static_cast(__n);
  const int __ival = static_cast(__value);
  const void* __p0 = std::to_address(__first);
- if (auto __p1 = __builtin_memchr(__p0, __ival, __n))
+ if (auto __p1 = __builtin_memchr(__p0, __ival, __nu))
__n = (const char*)__p1 - (const char*)__p0;
}
return __first + __n;
diff --git a/libstdc++-v3/testsuite/25_algorithms/find/bytes.cc 
b/libstdc++-v3/testsuite/25_algorithms/find/bytes.cc
index e1d6c01ab215..03dada0fec75 100644
--- a/libstdc++-v3/testsuite/25_algorithms/find/bytes.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/find/bytes.cc
@@ -114,9 +114,19 @@ test_non_characters()
 #endif
 }
 
+#if __cpp_lib_ranges
+void
+test_pr115799c0(__gnu_test::test_contiguous_range r)
+{
+  // Non-common range with integer-class type as difference_type.
+  (void) std::ranges::find(r, 'a');
+}
+#endif
+
 void
 test_pr115799c2(__gnu_test::input_iterator_wrapper i)
 {
+  // Non-contiguous range of character type.
   (void) std::find(i, i, 'a');
 }
 
diff --git a/libstdc++-v3/testsuite/std/ranges/range.cc 
b/libstdc++-v3/testsuite/std/ranges/range.cc
index 760f6ffacfdb..5464a9bf66bc 100644
--- a/libstdc++-v3/testsuite/std/ranges/range.cc
+++ b/libstdc++-v3/testsuite/std/ranges/range.cc
@@ -56,6 +56,7 @@ static_assert( 
std::ranges::range&> );
 using std::same_as;
 
 using C = test_contiguous_range;
+using R = test_random_access_range;
 using I = test_input_range;
 using O = test_output_range;
 
@@ -69,7 +70,9 @@ static_assert( same_as,
 static_assert( same_as,
   decltype(std::declval().end())> );
 
-static_assert( same_as,
+static_assert( ! same_as,
+std::ptrdiff_t> ); // __detail::__max_diff_type
+static_assert( same_as,
   std::ptrdiff_t> );
 static_assert( same_as,
   std::ptrdiff_t> );
diff --git a/libstdc++-v3/testsuite/util/testsuite_iterators.h 
b/libstdc++-v3/testsuite/util/testsuite_iterators.h
index ec2971284b4c..e7f7abe222d5 100644
--- a/libstdc++-v3/testsuite/util/testsuite_iterators.h
+++ b/libstdc++-v3/testsuite/util/testsuite_iterators.h
@@ -34,6 +34,10 @@
 #include 
 #endif
 
+#if __cplusplus > 201703L
+#include 
+#endif
+
 #ifndef _TESTSUITE_ITERATORS
 #define _TESTSUITE_ITERATORS
 
@@ -675,6 +679,9 @@ namespace __gnu_test
 
   using iterator_concept = std::contiguous_iterator_tag;
 
+  // Use an integer-class type to try and break the library code.
+  using difference_type = std::ranges::__detail::__max_diff_type;
+
   contiguous_iterator_wrapper&
   operator++()
   {
@@ -706,27 +713,42 @@ namespace __gnu_test
   }
 
   contiguous_iterator_wrapper&
-  operator+=(std::ptrdiff_t n)
+  operator+=(difference_type n)
   {
-   random_access_iterator_wrapper::operator+=(n);
+   auto d = static_cast(n);
+   random_access_iterator_wrapper::operator+=(d);
return *this;
   }
 
   friend contiguous_iterator_wrapper
-  operator+(contiguous_

[gcc r11-11567] libstdc++: Destroy allocators in re-inserted container nodes [PR114401]

2024-07-10 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:69ce8e406a2aa0aba5dcae5e419503ec105355b0

commit r11-11567-g69ce8e406a2aa0aba5dcae5e419503ec105355b0
Author: Jonathan Wakely 
Date:   Thu Mar 21 13:25:15 2024 +

libstdc++: Destroy allocators in re-inserted container nodes [PR114401]

The allocator objects in container node handles were not being destroyed
after the node was re-inserted into a container. They are stored in a
union and so need to be explicitly destroyed when the node becomes
empty. The containers were zeroing the node handle's pointer, which
makes it empty, causing the handle's destructor to think there's nothing
to clean up.

Add a new member function to the node handle which destroys the
allocator and zeros the pointer. Change the containers to call that
instead of just changing the pointer manually.

We can also remove the _M_empty member of the union which is not
necessary.

libstdc++-v3/ChangeLog:

PR libstdc++/114401
* include/bits/hashtable.h (_Hashtable::_M_reinsert_node): Call
release() on node handle instead of just zeroing its pointer.
(_Hashtable::_M_reinsert_node_multi): Likewise.
(_Hashtable::_M_merge_unique): Likewise.
* include/bits/node_handle.h (_Node_handle_common::release()):
New member function.
(_Node_handle_common::_Optional_alloc::_M_empty): Remove
unnecessary union member.
(_Node_handle_common): Declare _Hashtable as a friend.
* include/bits/stl_tree.h (_Rb_tree::_M_reinsert_node_unique):
Call release() on node handle instead of just zeroing its
pointer.
(_Rb_tree::_M_reinsert_node_equal): Likewise.
(_Rb_tree::_M_reinsert_node_hint_unique): Likewise.
(_Rb_tree::_M_reinsert_node_hint_equal): Likewise.
* testsuite/23_containers/multiset/modifiers/114401.cc: New test.
* testsuite/23_containers/set/modifiers/114401.cc: New test.
* testsuite/23_containers/unordered_multiset/modifiers/114401.cc: 
New test.
* testsuite/23_containers/unordered_set/modifiers/114401.cc: New 
test.

(cherry picked from commit c2e28df90a1640cebadef6c6c8ab5ea964071bb1)

Diff:
---
 libstdc++-v3/include/bits/hashtable.h  |   8 +-
 libstdc++-v3/include/bits/node_handle.h|  19 +++-
 libstdc++-v3/include/bits/stl_tree.h   |  10 +-
 .../23_containers/multiset/modifiers/114401.cc | 125 
 .../23_containers/set/modifiers/114401.cc  | 125 
 .../unordered_multiset/modifiers/114401.cc | 126 +
 .../unordered_set/modifiers/114401.cc  | 126 +
 7 files changed, 527 insertions(+), 12 deletions(-)

diff --git a/libstdc++-v3/include/bits/hashtable.h 
b/libstdc++-v3/include/bits/hashtable.h
index eeefa7859226..ad0d6731de0a 100644
--- a/libstdc++-v3/include/bits/hashtable.h
+++ b/libstdc++-v3/include/bits/hashtable.h
@@ -950,7 +950,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // DR 1189.
   // reserve, if present, comes from _Rehash_base.
 
-#if __cplusplus > 201402L
+#if __cplusplus > 201404L
   /// Re-insert an extracted node into a container with unique keys.
   insert_return_type
   _M_reinsert_node(node_type&& __nh)
@@ -975,7 +975,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  {
__ret.position
  = _M_insert_unique_node(__bkt, __code, __nh._M_ptr);
-   __nh._M_ptr = nullptr;
+   __nh.release();
__ret.inserted = true;
  }
  }
@@ -995,7 +995,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
auto __code = this->_M_hash_code(__k);
auto __ret
  = _M_insert_multi_node(__hint._M_cur, __code, __nh._M_ptr);
-   __nh._M_ptr = nullptr;
+   __nh.release();
return __ret;
   }
 
@@ -1062,7 +1062,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
  auto __nh = __src.extract(__pos);
  _M_insert_unique_node(__bkt, __code, __nh._M_ptr, __n_elt);
- __nh._M_ptr = nullptr;
+ __nh.release();
  __n_elt = 1;
}
  else if (__n_elt != 1)
diff --git a/libstdc++-v3/include/bits/node_handle.h 
b/libstdc++-v3/include/bits/node_handle.h
index 7d8d0dc8cea8..8f500c2f8303 100644
--- a/libstdc++-v3/include/bits/node_handle.h
+++ b/libstdc++-v3/include/bits/node_handle.h
@@ -168,6 +168,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_ptr = nullptr;
   }
 
+  // Destroys the allocator. Does not deallocate or destroy the node.
+  // Precondition: !empty()
+  // Postcondition: empty()
+  void
+  release() noexcept
+  {
+   _M_alloc.release();
+   _M_ptr = nullptr;
+  }
+
 protected:
   type

[gcc r12-10608] libstdc++: Fix _Atomic(T) macro in [PR115807]

2024-07-09 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:987e70f4290451abd98eda8b82e97b4ad25ee3c2

commit r12-10608-g987e70f4290451abd98eda8b82e97b4ad25ee3c2
Author: Jonathan Wakely 
Date:   Sun Jul 7 12:22:42 2024 +0100

libstdc++: Fix _Atomic(T) macro in  [PR115807]

The definition of the _Atomic(T) macro needs to refer to ::std::atomic,
not some other std::atomic relative to the current namespace.

libstdc++-v3/ChangeLog:

PR libstdc++/115807
* include/c_compatibility/stdatomic.h (_Atomic): Ensure it
refers to std::atomic in the global namespace.
* testsuite/29_atomics/headers/stdatomic.h/115807.cc: New test.

(cherry picked from commit 40d234dd6439e8c8cfbf3f375a61906aed35c80d)

Diff:
---
 libstdc++-v3/include/c_compatibility/stdatomic.h   |  2 +-
 .../testsuite/29_atomics/headers/stdatomic.h/115807.cc | 14 ++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/c_compatibility/stdatomic.h 
b/libstdc++-v3/include/c_compatibility/stdatomic.h
index b565a1c1ab18..2bb23decf8d1 100644
--- a/libstdc++-v3/include/c_compatibility/stdatomic.h
+++ b/libstdc++-v3/include/c_compatibility/stdatomic.h
@@ -34,7 +34,7 @@
 
 #define __cpp_lib_stdatomic_h 202011L
 
-#define _Atomic(_Tp) std::atomic<_Tp>
+#define _Atomic(_Tp) ::std::atomic<_Tp>
 
 using std::memory_order;
 using std::memory_order_relaxed;
diff --git a/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/115807.cc 
b/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/115807.cc
new file mode 100644
index ..14f320fe8357
--- /dev/null
+++ b/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/115807.cc
@@ -0,0 +1,14 @@
+// { dg-do compile { target c++23 } }
+#include 
+namespace other {
+  namespace std {
+int atomic = 0;
+  }
+  _Atomic(long) a{};
+}
+
+#include 
+
+namespace non::std {
+  static_assert( ::std::is_same_v<_Atomic(int), ::std::atomic> );
+}


[gcc r13-8900] libstdc++: Fix _Atomic(T) macro in [PR115807]

2024-07-09 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:c36ef56fc1df456a2174d7cb42967a0e871597c2

commit r13-8900-gc36ef56fc1df456a2174d7cb42967a0e871597c2
Author: Jonathan Wakely 
Date:   Sun Jul 7 12:22:42 2024 +0100

libstdc++: Fix _Atomic(T) macro in  [PR115807]

The definition of the _Atomic(T) macro needs to refer to ::std::atomic,
not some other std::atomic relative to the current namespace.

libstdc++-v3/ChangeLog:

PR libstdc++/115807
* include/c_compatibility/stdatomic.h (_Atomic): Ensure it
refers to std::atomic in the global namespace.
* testsuite/29_atomics/headers/stdatomic.h/115807.cc: New test.

(cherry picked from commit 40d234dd6439e8c8cfbf3f375a61906aed35c80d)

Diff:
---
 libstdc++-v3/include/c_compatibility/stdatomic.h   |  2 +-
 .../testsuite/29_atomics/headers/stdatomic.h/115807.cc | 14 ++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/c_compatibility/stdatomic.h 
b/libstdc++-v3/include/c_compatibility/stdatomic.h
index b565a1c1ab18..2bb23decf8d1 100644
--- a/libstdc++-v3/include/c_compatibility/stdatomic.h
+++ b/libstdc++-v3/include/c_compatibility/stdatomic.h
@@ -34,7 +34,7 @@
 
 #define __cpp_lib_stdatomic_h 202011L
 
-#define _Atomic(_Tp) std::atomic<_Tp>
+#define _Atomic(_Tp) ::std::atomic<_Tp>
 
 using std::memory_order;
 using std::memory_order_relaxed;
diff --git a/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/115807.cc 
b/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/115807.cc
new file mode 100644
index ..14f320fe8357
--- /dev/null
+++ b/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/115807.cc
@@ -0,0 +1,14 @@
+// { dg-do compile { target c++23 } }
+#include 
+namespace other {
+  namespace std {
+int atomic = 0;
+  }
+  _Atomic(long) a{};
+}
+
+#include 
+
+namespace non::std {
+  static_assert( ::std::is_same_v<_Atomic(int), ::std::atomic> );
+}


[gcc r13-8899] libstdc++: Define __glibcxx_assert_fail for non-verbose build [PR115585]

2024-07-09 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:3cd410fe4f48ffd841fcd5442d1f2d6350666330

commit r13-8899-g3cd410fe4f48ffd841fcd5442d1f2d6350666330
Author: Jonathan Wakely 
Date:   Fri Jun 28 15:14:15 2024 +0100

libstdc++: Define __glibcxx_assert_fail for non-verbose build [PR115585]

When the library is configured with --disable-libstdcxx-verbose the
assertions just abort instead of calling __glibcxx_assert_fail, and so I
didn't export that function for the non-verbose build. However, that
option is documented to not change the library ABI, so we still need to
export the symbol from the library. It could be needed by programs
compiled against the headers from a verbose build.

The non-verbose definition can just call abort so that it doesn't pull
in I/O symbols, which are unwanted in a non-verbose build.

libstdc++-v3/ChangeLog:

PR libstdc++/115585
* src/c++11/assert_fail.cc (__glibcxx_assert_fail): Add
definition for non-verbose builds.

(cherry picked from commit 52370c839edd04df86d3ff2b71fcdca0c7376a7f)

Diff:
---
 libstdc++-v3/src/c++11/assert_fail.cc | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/src/c++11/assert_fail.cc 
b/libstdc++-v3/src/c++11/assert_fail.cc
index 540e953da2e8..774ffa701189 100644
--- a/libstdc++-v3/src/c++11/assert_fail.cc
+++ b/libstdc++-v3/src/c++11/assert_fail.cc
@@ -22,10 +22,10 @@
 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 // <http://www.gnu.org/licenses/>.
 
-#include   // for std::fprintf, stderr
 #include  // for std::abort
 
 #ifdef _GLIBCXX_VERBOSE_ASSERT
+#include   // for std::fprintf, stderr
 namespace std
 {
   [[__noreturn__]]
@@ -41,4 +41,12 @@ namespace std
 abort();
   }
 }
+#else
+namespace std
+{
+  [[__noreturn__]]
+  void
+  __glibcxx_assert_fail(const char*, int, const char*, const char*) noexcept
+  { abort(); }
+}
 #endif


[gcc r14-10401] libstdc++: Fix _Atomic(T) macro in [PR115807]

2024-07-09 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:c94c8ff5f5769ab59cbdd46c8669aa7e3ac83a44

commit r14-10401-gc94c8ff5f5769ab59cbdd46c8669aa7e3ac83a44
Author: Jonathan Wakely 
Date:   Sun Jul 7 12:22:42 2024 +0100

libstdc++: Fix _Atomic(T) macro in  [PR115807]

The definition of the _Atomic(T) macro needs to refer to ::std::atomic,
not some other std::atomic relative to the current namespace.

libstdc++-v3/ChangeLog:

PR libstdc++/115807
* include/c_compatibility/stdatomic.h (_Atomic): Ensure it
refers to std::atomic in the global namespace.
* testsuite/29_atomics/headers/stdatomic.h/115807.cc: New test.

(cherry picked from commit 40d234dd6439e8c8cfbf3f375a61906aed35c80d)

Diff:
---
 libstdc++-v3/include/c_compatibility/stdatomic.h   |  2 +-
 .../testsuite/29_atomics/headers/stdatomic.h/115807.cc | 14 ++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/c_compatibility/stdatomic.h 
b/libstdc++-v3/include/c_compatibility/stdatomic.h
index 52daa16c9b1e..7236260795e4 100644
--- a/libstdc++-v3/include/c_compatibility/stdatomic.h
+++ b/libstdc++-v3/include/c_compatibility/stdatomic.h
@@ -35,7 +35,7 @@
 #ifdef __cpp_lib_stdatomic_h // C++ >= 23
 #include 
 
-#define _Atomic(_Tp) std::atomic<_Tp>
+#define _Atomic(_Tp) ::std::atomic<_Tp>
 
 using std::memory_order;
 using std::memory_order_relaxed;
diff --git a/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/115807.cc 
b/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/115807.cc
new file mode 100644
index ..14f320fe8357
--- /dev/null
+++ b/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/115807.cc
@@ -0,0 +1,14 @@
+// { dg-do compile { target c++23 } }
+#include 
+namespace other {
+  namespace std {
+int atomic = 0;
+  }
+  _Atomic(long) a{};
+}
+
+#include 
+
+namespace non::std {
+  static_assert( ::std::is_same_v<_Atomic(int), ::std::atomic> );
+}


[gcc r14-10400] libstdc++: Define __glibcxx_assert_fail for non-verbose build [PR115585]

2024-07-09 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:85a39a8aaf683766f8160b982ed4d7b8c44aede0

commit r14-10400-g85a39a8aaf683766f8160b982ed4d7b8c44aede0
Author: Jonathan Wakely 
Date:   Fri Jun 28 15:14:15 2024 +0100

libstdc++: Define __glibcxx_assert_fail for non-verbose build [PR115585]

When the library is configured with --disable-libstdcxx-verbose the
assertions just abort instead of calling __glibcxx_assert_fail, and so I
didn't export that function for the non-verbose build. However, that
option is documented to not change the library ABI, so we still need to
export the symbol from the library. It could be needed by programs
compiled against the headers from a verbose build.

The non-verbose definition can just call abort so that it doesn't pull
in I/O symbols, which are unwanted in a non-verbose build.

libstdc++-v3/ChangeLog:

PR libstdc++/115585
* src/c++11/assert_fail.cc (__glibcxx_assert_fail): Add
definition for non-verbose builds.

(cherry picked from commit 52370c839edd04df86d3ff2b71fcdca0c7376a7f)

Diff:
---
 libstdc++-v3/src/c++11/assert_fail.cc | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/src/c++11/assert_fail.cc 
b/libstdc++-v3/src/c++11/assert_fail.cc
index 6d99c7958f3e..76c8a5a5c2f9 100644
--- a/libstdc++-v3/src/c++11/assert_fail.cc
+++ b/libstdc++-v3/src/c++11/assert_fail.cc
@@ -22,10 +22,10 @@
 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 // <http://www.gnu.org/licenses/>.
 
-#include   // for std::fprintf, stderr
 #include  // for std::abort
 
 #ifdef _GLIBCXX_VERBOSE_ASSERT
+#include   // for std::fprintf, stderr
 namespace std
 {
   [[__noreturn__]]
@@ -41,4 +41,12 @@ namespace std
 abort();
   }
 }
+#else
+namespace std
+{
+  [[__noreturn__]]
+  void
+  __glibcxx_assert_fail(const char*, int, const char*, const char*) noexcept
+  { abort(); }
+}
 #endif


[PATCH] libstdc++: ranges::find needs explicit conversion to size_t [PR115799]

2024-07-08 Thread Jonathan Wakely
This fixes another problem with my recent changes to use memchr in
std::find.

Tested x86_64-linux.

-- >8 --

For an integer-class type we need to use an explicit conversion to size_t.

libstdc++-v3/ChangeLog:

PR libstdc++/115799
* include/bits/ranges_util.h (__find_fn): Make conversion
from difference type ti size_t explicit.
* testsuite/25_algorithms/find/bytes.cc: Check ranges::find with
__gnu_test::test_contiguous_range.
* testsuite/std/ranges/range.cc: Adjust expected difference_type
for __gnu_test::test_contiguous_range.
* testsuite/util/testsuite_iterators.h (contiguous_iterator_wrapper):
Use __max_diff_type as difference type.
(test_range::sentinel, test_sized_range_sized_sent::sentinel):
Ensure that operator- returns difference_type.
---
 libstdc++-v3/include/bits/ranges_util.h   |  3 +-
 .../testsuite/25_algorithms/find/bytes.cc | 10 +
 libstdc++-v3/testsuite/std/ranges/range.cc|  5 ++-
 .../testsuite/util/testsuite_iterators.h  | 42 ++-
 4 files changed, 48 insertions(+), 12 deletions(-)

diff --git a/libstdc++-v3/include/bits/ranges_util.h 
b/libstdc++-v3/include/bits/ranges_util.h
index a1f42875b11..e6d96073e87 100644
--- a/libstdc++-v3/include/bits/ranges_util.h
+++ b/libstdc++-v3/include/bits/ranges_util.h
@@ -506,9 +506,10 @@ namespace ranges
if (static_cast<_Vt>(__value) == __value) [[likely]]
  if (__n > 0)
{
+ const size_t __nu = static_cast(__n);
  const int __ival = static_cast(__value);
  const void* __p0 = std::to_address(__first);
- if (auto __p1 = __builtin_memchr(__p0, __ival, __n))
+ if (auto __p1 = __builtin_memchr(__p0, __ival, __nu))
__n = (const char*)__p1 - (const char*)__p0;
}
return __first + __n;
diff --git a/libstdc++-v3/testsuite/25_algorithms/find/bytes.cc 
b/libstdc++-v3/testsuite/25_algorithms/find/bytes.cc
index e1d6c01ab21..03dada0fec7 100644
--- a/libstdc++-v3/testsuite/25_algorithms/find/bytes.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/find/bytes.cc
@@ -114,9 +114,19 @@ test_non_characters()
 #endif
 }
 
+#if __cpp_lib_ranges
+void
+test_pr115799c0(__gnu_test::test_contiguous_range r)
+{
+  // Non-common range with integer-class type as difference_type.
+  (void) std::ranges::find(r, 'a');
+}
+#endif
+
 void
 test_pr115799c2(__gnu_test::input_iterator_wrapper i)
 {
+  // Non-contiguous range of character type.
   (void) std::find(i, i, 'a');
 }
 
diff --git a/libstdc++-v3/testsuite/std/ranges/range.cc 
b/libstdc++-v3/testsuite/std/ranges/range.cc
index 760f6ffacfd..5464a9bf66b 100644
--- a/libstdc++-v3/testsuite/std/ranges/range.cc
+++ b/libstdc++-v3/testsuite/std/ranges/range.cc
@@ -56,6 +56,7 @@ static_assert( 
std::ranges::range&> );
 using std::same_as;
 
 using C = test_contiguous_range;
+using R = test_random_access_range;
 using I = test_input_range;
 using O = test_output_range;
 
@@ -69,7 +70,9 @@ static_assert( same_as,
 static_assert( same_as,
   decltype(std::declval().end())> );
 
-static_assert( same_as,
+static_assert( ! same_as,
+std::ptrdiff_t> ); // __detail::__max_diff_type
+static_assert( same_as,
   std::ptrdiff_t> );
 static_assert( same_as,
   std::ptrdiff_t> );
diff --git a/libstdc++-v3/testsuite/util/testsuite_iterators.h 
b/libstdc++-v3/testsuite/util/testsuite_iterators.h
index ec2971284b4..e7f7abe222d 100644
--- a/libstdc++-v3/testsuite/util/testsuite_iterators.h
+++ b/libstdc++-v3/testsuite/util/testsuite_iterators.h
@@ -34,6 +34,10 @@
 #include 
 #endif
 
+#if __cplusplus > 201703L
+#include 
+#endif
+
 #ifndef _TESTSUITE_ITERATORS
 #define _TESTSUITE_ITERATORS
 
@@ -675,6 +679,9 @@ namespace __gnu_test
 
   using iterator_concept = std::contiguous_iterator_tag;
 
+  // Use an integer-class type to try and break the library code.
+  using difference_type = std::ranges::__detail::__max_diff_type;
+
   contiguous_iterator_wrapper&
   operator++()
   {
@@ -706,27 +713,42 @@ namespace __gnu_test
   }
 
   contiguous_iterator_wrapper&
-  operator+=(std::ptrdiff_t n)
+  operator+=(difference_type n)
   {
-   random_access_iterator_wrapper::operator+=(n);
+   auto d = static_cast(n);
+   random_access_iterator_wrapper::operator+=(d);
return *this;
   }
 
   friend contiguous_iterator_wrapper
-  operator+(contiguous_iterator_wrapper iter, std::ptrdiff_t n)
+  operator+(contiguous_iterator_wrapper iter, difference_type n)
   { return iter += n; }
 
   friend contiguous_iterator_wrapper
-  operator+(std::ptrdiff_t n, contiguous_iterator_wrapper iter)
+  operator+(difference_type n, 

[committed] libstdc++: Fix _Atomic(T) macro in [PR115807]

2024-07-08 Thread Jonathan Wakely
Tested x86_64-linux. Pushed to trunk. This should be backported too.

-- >8 --

The definition of the _Atomic(T) macro needs to refer to ::std::atomic,
not some other std::atomic relative to the current namespace.

libstdc++-v3/ChangeLog:

PR libstdc++/115807
* include/c_compatibility/stdatomic.h (_Atomic): Ensure it
refers to std::atomic in the global namespace.
* testsuite/29_atomics/headers/stdatomic.h/115807.cc: New test.
---
 libstdc++-v3/include/c_compatibility/stdatomic.h   |  2 +-
 .../29_atomics/headers/stdatomic.h/115807.cc   | 14 ++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 
libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/115807.cc

diff --git a/libstdc++-v3/include/c_compatibility/stdatomic.h 
b/libstdc++-v3/include/c_compatibility/stdatomic.h
index 5403b52a036..72b9446eb17 100644
--- a/libstdc++-v3/include/c_compatibility/stdatomic.h
+++ b/libstdc++-v3/include/c_compatibility/stdatomic.h
@@ -35,7 +35,7 @@
 #ifdef __cpp_lib_stdatomic_h // C++ >= 23
 #include 
 
-#define _Atomic(_Tp) std::atomic<_Tp>
+#define _Atomic(_Tp) ::std::atomic<_Tp>
 
 using std::memory_order;
 using std::memory_order_relaxed;
diff --git a/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/115807.cc 
b/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/115807.cc
new file mode 100644
index 000..14f320fe835
--- /dev/null
+++ b/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/115807.cc
@@ -0,0 +1,14 @@
+// { dg-do compile { target c++23 } }
+#include 
+namespace other {
+  namespace std {
+int atomic = 0;
+  }
+  _Atomic(long) a{};
+}
+
+#include 
+
+namespace non::std {
+  static_assert( ::std::is_same_v<_Atomic(int), ::std::atomic> );
+}
-- 
2.45.2



[gcc r15-1898] libstdc++: Fix _Atomic(T) macro in [PR115807]

2024-07-08 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:40d234dd6439e8c8cfbf3f375a61906aed35c80d

commit r15-1898-g40d234dd6439e8c8cfbf3f375a61906aed35c80d
Author: Jonathan Wakely 
Date:   Sun Jul 7 12:22:42 2024 +0100

libstdc++: Fix _Atomic(T) macro in  [PR115807]

The definition of the _Atomic(T) macro needs to refer to ::std::atomic,
not some other std::atomic relative to the current namespace.

libstdc++-v3/ChangeLog:

PR libstdc++/115807
* include/c_compatibility/stdatomic.h (_Atomic): Ensure it
refers to std::atomic in the global namespace.
* testsuite/29_atomics/headers/stdatomic.h/115807.cc: New test.

Diff:
---
 libstdc++-v3/include/c_compatibility/stdatomic.h   |  2 +-
 .../testsuite/29_atomics/headers/stdatomic.h/115807.cc | 14 ++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/c_compatibility/stdatomic.h 
b/libstdc++-v3/include/c_compatibility/stdatomic.h
index 5403b52a036d..72b9446eb170 100644
--- a/libstdc++-v3/include/c_compatibility/stdatomic.h
+++ b/libstdc++-v3/include/c_compatibility/stdatomic.h
@@ -35,7 +35,7 @@
 #ifdef __cpp_lib_stdatomic_h // C++ >= 23
 #include 
 
-#define _Atomic(_Tp) std::atomic<_Tp>
+#define _Atomic(_Tp) ::std::atomic<_Tp>
 
 using std::memory_order;
 using std::memory_order_relaxed;
diff --git a/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/115807.cc 
b/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/115807.cc
new file mode 100644
index ..14f320fe8357
--- /dev/null
+++ b/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/115807.cc
@@ -0,0 +1,14 @@
+// { dg-do compile { target c++23 } }
+#include 
+namespace other {
+  namespace std {
+int atomic = 0;
+  }
+  _Atomic(long) a{};
+}
+
+#include 
+
+namespace non::std {
+  static_assert( ::std::is_same_v<_Atomic(int), ::std::atomic> );
+}


[committed] libstdc++: Fix std::find for non-contiguous iterators [PR115799]

2024-07-07 Thread Jonathan Wakely
Tested x86_64-linux. Pushed to trunk.

-- >8 --

The r15-1857 change didn't correctly restrict the new optimization to
contiguous iterators.

libstdc++-v3/ChangeLog:

PR libstdc++/115799
* include/bits/stl_algo.h (find): Use 'if constexpr' so that
memchr optimization is a discarded statement for non-contiguous
iterators.
* testsuite/25_algorithms/find/bytes.cc: Check with input
iterators.
---
 libstdc++-v3/include/bits/stl_algo.h  | 44 +--
 .../testsuite/25_algorithms/find/bytes.cc |  7 +++
 2 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_algo.h 
b/libstdc++-v3/include/bits/stl_algo.h
index 45c3b591326..d250b2e04d4 100644
--- a/libstdc++-v3/include/bits/stl_algo.h
+++ b/libstdc++-v3/include/bits/stl_algo.h
@@ -3849,32 +3849,28 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
 #if __cpp_if_constexpr && __glibcxx_type_trait_variable_templates
   using _ValT = typename iterator_traits<_InputIterator>::value_type;
   if constexpr (__can_use_memchr_for_find<_ValT, _Tp>)
-   {
- // If converting the value to the 1-byte value_type alters its value,
- // then it would not be found by std::find using equality comparison.
- // We need to check this here, because otherwise something like
- // memchr("a", 'a'+256, 1) would give a false positive match.
- if (!(static_cast<_ValT>(__val) == __val))
-   return __last;
- else if (!__is_constant_evaluated())
-   {
- const void* __p0 = nullptr;
- if constexpr (is_pointer_v)
-   __p0 = std::__niter_base(__first);
+   if constexpr (is_pointer_v
 #if __cpp_lib_concepts
- else if constexpr (contiguous_iterator<_InputIterator>)
-   __p0 = std::to_address(__first);
+   || contiguous_iterator<_InputIterator>
 #endif
- if (__p0)
-   {
- const int __ival = static_cast(__val);
- if (auto __n = std::distance(__first, __last); __n > 0)
-   if (auto __p1 = __builtin_memchr(__p0, __ival, __n))
- return __first + ((const char*)__p1 - (const char*)__p0);
- return __last;
-   }
-   }
-   }
+)
+ {
+   // If conversion to the 1-byte value_type alters the value,
+   // it would not be found by std::find using equality comparison.
+   // We need to check this here, because otherwise something like
+   // memchr("a", 'a'+256, 1) would give a false positive match.
+   if (!(static_cast<_ValT>(__val) == __val))
+ return __last;
+   else if (!__is_constant_evaluated())
+ {
+   const void* __p0 = std::__to_address(__first);
+   const int __ival = static_cast(__val);
+   if (auto __n = std::distance(__first, __last); __n > 0)
+ if (auto __p1 = __builtin_memchr(__p0, __ival, __n))
+   return __first + ((const char*)__p1 - (const char*)__p0);
+   return __last;
+ }
+ }
 #endif
 
   return std::__find_if(__first, __last,
diff --git a/libstdc++-v3/testsuite/25_algorithms/find/bytes.cc 
b/libstdc++-v3/testsuite/25_algorithms/find/bytes.cc
index f4ac5d4018d..e1d6c01ab21 100644
--- a/libstdc++-v3/testsuite/25_algorithms/find/bytes.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/find/bytes.cc
@@ -3,6 +3,7 @@
 #include 
 #include  // std::byte
 #include 
+#include 
 
 // PR libstdc++/88545 made std::find use memchr as an optimization.
 // This test verifies that it didn't change any semantics.
@@ -113,6 +114,12 @@ test_non_characters()
 #endif
 }
 
+void
+test_pr115799c2(__gnu_test::input_iterator_wrapper i)
+{
+  (void) std::find(i, i, 'a');
+}
+
 int main()
 {
   test_char();
-- 
2.45.2



[committed] libstdc++: Fix memchr path in std::ranges::find for non-common range [PR115799]

2024-07-07 Thread Jonathan Wakely
Tested x86_64-linux. Pushed to trunk.

-- >8 --

The memchr optimization introduced in r15-1857 needs to advance the
start iterator instead of returning the sentinel.

libstdc++-v3/ChangeLog:

PR libstdc++/115799
* include/bits/ranges_util.h (__find_fn): Return iterator
instead of sentinel.
* testsuite/25_algorithms/find/constrained.cc: Check non-common
contiguous sized range of char.
---
 libstdc++-v3/include/bits/ranges_util.h   | 19 +--
 .../25_algorithms/find/constrained.cc | 10 ++
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/libstdc++-v3/include/bits/ranges_util.h 
b/libstdc++-v3/include/bits/ranges_util.h
index 186acae4f70..a1f42875b11 100644
--- a/libstdc++-v3/include/bits/ranges_util.h
+++ b/libstdc++-v3/include/bits/ranges_util.h
@@ -501,17 +501,16 @@ namespace ranges
  if constexpr (contiguous_iterator<_Iter>)
if (!is_constant_evaluated())
  {
-   if (static_cast>(__value) != __value)
- return __last;
-
+   using _Vt = iter_value_t<_Iter>;
auto __n = __last - __first;
-   if (__n > 0)
- {
-   const int __ival = static_cast(__value);
-   const void* __p0 = std::to_address(__first);
-   if (auto __p1 = __builtin_memchr(__p0, __ival, __n))
- __n = (const char*)__p1 - (const char*)__p0;
- }
+   if (static_cast<_Vt>(__value) == __value) [[likely]]
+ if (__n > 0)
+   {
+ const int __ival = static_cast(__value);
+ const void* __p0 = std::to_address(__first);
+ if (auto __p1 = __builtin_memchr(__p0, __ival, __n))
+   __n = (const char*)__p1 - (const char*)__p0;
+   }
return __first + __n;
  }
 
diff --git a/libstdc++-v3/testsuite/25_algorithms/find/constrained.cc 
b/libstdc++-v3/testsuite/25_algorithms/find/constrained.cc
index e94751fcf89..7357a40bcc4 100644
--- a/libstdc++-v3/testsuite/25_algorithms/find/constrained.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/find/constrained.cc
@@ -66,9 +66,19 @@ test02()
   static_assert(ranges::find(y, 5, ::j) == y+3);
 }
 
+void
+test_pr115799()
+{
+  const char str[3] = { 'a', 'b', 'c' };
+  __gnu_test::test_contiguous_sized_range r(str);
+  VERIFY(std::ranges::find(r, 'a') == std::ranges::begin(r));
+  VERIFY(std::ranges::find(r, 'a'+255) == std::ranges::end(r));
+}
+
 int
 main()
 {
   test01();
   test02();
+  test_pr115799();
 }
-- 
2.45.2



[gcc r15-1880] libstdc++: Fix std::find for non-contiguous iterators [PR115799]

2024-07-07 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:ce34fcc572a0dceebcffef76e98064546feebb38

commit r15-1880-gce34fcc572a0dceebcffef76e98064546feebb38
Author: Jonathan Wakely 
Date:   Sat Jul 6 21:34:29 2024 +0100

libstdc++: Fix std::find for non-contiguous iterators [PR115799]

The r15-1857 change didn't correctly restrict the new optimization to
contiguous iterators.

libstdc++-v3/ChangeLog:

PR libstdc++/115799
* include/bits/stl_algo.h (find): Use 'if constexpr' so that
memchr optimization is a discarded statement for non-contiguous
iterators.
* testsuite/25_algorithms/find/bytes.cc: Check with input
iterators.

Diff:
---
 libstdc++-v3/include/bits/stl_algo.h   | 44 ++
 libstdc++-v3/testsuite/25_algorithms/find/bytes.cc |  7 
 2 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_algo.h 
b/libstdc++-v3/include/bits/stl_algo.h
index 45c3b591326..d250b2e04d4 100644
--- a/libstdc++-v3/include/bits/stl_algo.h
+++ b/libstdc++-v3/include/bits/stl_algo.h
@@ -3849,32 +3849,28 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
 #if __cpp_if_constexpr && __glibcxx_type_trait_variable_templates
   using _ValT = typename iterator_traits<_InputIterator>::value_type;
   if constexpr (__can_use_memchr_for_find<_ValT, _Tp>)
-   {
- // If converting the value to the 1-byte value_type alters its value,
- // then it would not be found by std::find using equality comparison.
- // We need to check this here, because otherwise something like
- // memchr("a", 'a'+256, 1) would give a false positive match.
- if (!(static_cast<_ValT>(__val) == __val))
-   return __last;
- else if (!__is_constant_evaluated())
-   {
- const void* __p0 = nullptr;
- if constexpr (is_pointer_v)
-   __p0 = std::__niter_base(__first);
+   if constexpr (is_pointer_v
 #if __cpp_lib_concepts
- else if constexpr (contiguous_iterator<_InputIterator>)
-   __p0 = std::to_address(__first);
+   || contiguous_iterator<_InputIterator>
 #endif
- if (__p0)
-   {
- const int __ival = static_cast(__val);
- if (auto __n = std::distance(__first, __last); __n > 0)
-   if (auto __p1 = __builtin_memchr(__p0, __ival, __n))
- return __first + ((const char*)__p1 - (const char*)__p0);
- return __last;
-   }
-   }
-   }
+)
+ {
+   // If conversion to the 1-byte value_type alters the value,
+   // it would not be found by std::find using equality comparison.
+   // We need to check this here, because otherwise something like
+   // memchr("a", 'a'+256, 1) would give a false positive match.
+   if (!(static_cast<_ValT>(__val) == __val))
+ return __last;
+   else if (!__is_constant_evaluated())
+ {
+   const void* __p0 = std::__to_address(__first);
+   const int __ival = static_cast(__val);
+   if (auto __n = std::distance(__first, __last); __n > 0)
+ if (auto __p1 = __builtin_memchr(__p0, __ival, __n))
+   return __first + ((const char*)__p1 - (const char*)__p0);
+   return __last;
+ }
+ }
 #endif
 
   return std::__find_if(__first, __last,
diff --git a/libstdc++-v3/testsuite/25_algorithms/find/bytes.cc 
b/libstdc++-v3/testsuite/25_algorithms/find/bytes.cc
index f4ac5d4018d..e1d6c01ab21 100644
--- a/libstdc++-v3/testsuite/25_algorithms/find/bytes.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/find/bytes.cc
@@ -3,6 +3,7 @@
 #include 
 #include  // std::byte
 #include 
+#include 
 
 // PR libstdc++/88545 made std::find use memchr as an optimization.
 // This test verifies that it didn't change any semantics.
@@ -113,6 +114,12 @@ test_non_characters()
 #endif
 }
 
+void
+test_pr115799c2(__gnu_test::input_iterator_wrapper i)
+{
+  (void) std::find(i, i, 'a');
+}
+
 int main()
 {
   test_char();


[gcc r15-1879] libstdc++: Fix memchr path in std::ranges::find for non-common range [PR115799]

2024-07-07 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:762ee55d369a3257997092ef7853cf9dd4d5cc4f

commit r15-1879-g762ee55d369a3257997092ef7853cf9dd4d5cc4f
Author: Jonathan Wakely 
Date:   Fri Jul 5 18:58:00 2024 +0100

libstdc++: Fix memchr path in std::ranges::find for non-common range 
[PR115799]

The memchr optimization introduced in r15-1857 needs to advance the
start iterator instead of returning the sentinel.

libstdc++-v3/ChangeLog:

PR libstdc++/115799
* include/bits/ranges_util.h (__find_fn): Return iterator
instead of sentinel.
* testsuite/25_algorithms/find/constrained.cc: Check non-common
contiguous sized range of char.

Diff:
---
 libstdc++-v3/include/bits/ranges_util.h   | 19 +--
 .../testsuite/25_algorithms/find/constrained.cc   | 10 ++
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/libstdc++-v3/include/bits/ranges_util.h 
b/libstdc++-v3/include/bits/ranges_util.h
index 186acae4f70..a1f42875b11 100644
--- a/libstdc++-v3/include/bits/ranges_util.h
+++ b/libstdc++-v3/include/bits/ranges_util.h
@@ -501,17 +501,16 @@ namespace ranges
  if constexpr (contiguous_iterator<_Iter>)
if (!is_constant_evaluated())
  {
-   if (static_cast>(__value) != __value)
- return __last;
-
+   using _Vt = iter_value_t<_Iter>;
auto __n = __last - __first;
-   if (__n > 0)
- {
-   const int __ival = static_cast(__value);
-   const void* __p0 = std::to_address(__first);
-   if (auto __p1 = __builtin_memchr(__p0, __ival, __n))
- __n = (const char*)__p1 - (const char*)__p0;
- }
+   if (static_cast<_Vt>(__value) == __value) [[likely]]
+ if (__n > 0)
+   {
+ const int __ival = static_cast(__value);
+ const void* __p0 = std::to_address(__first);
+ if (auto __p1 = __builtin_memchr(__p0, __ival, __n))
+   __n = (const char*)__p1 - (const char*)__p0;
+   }
return __first + __n;
  }
 
diff --git a/libstdc++-v3/testsuite/25_algorithms/find/constrained.cc 
b/libstdc++-v3/testsuite/25_algorithms/find/constrained.cc
index e94751fcf89..7357a40bcc4 100644
--- a/libstdc++-v3/testsuite/25_algorithms/find/constrained.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/find/constrained.cc
@@ -66,9 +66,19 @@ test02()
   static_assert(ranges::find(y, 5, ::j) == y+3);
 }
 
+void
+test_pr115799()
+{
+  const char str[3] = { 'a', 'b', 'c' };
+  __gnu_test::test_contiguous_sized_range r(str);
+  VERIFY(std::ranges::find(r, 'a') == std::ranges::begin(r));
+  VERIFY(std::ranges::find(r, 'a'+255) == std::ranges::end(r));
+}
+
 int
 main()
 {
   test01();
   test02();
+  test_pr115799();
 }


[committed] libstdc++: Remove redundant 17_intro/headers tests

2024-07-06 Thread Jonathan Wakely
Tested x86_64-linux. Pushed to trunk.

-- >8 --

We have several nearly identical tests under 17_intro/headers which only
differ in a -std option set using dg-options. Since the testsuite now
supports running tests with multiple -std options (and I test that
regularly) we don't need these duplicated tests. We can remove most of
them and let the testsuite decide which -std option to use.

In the all_attributes.cc case the content of the tests is slightly
different, but they can be combined into one test that defines macros
conditionally based on __cplusplus checks.

The stdc++.cc tests could also be combined this way, but for now I've
just kept one version for c++98 and one for all later standards.

For stdc++_multiple_inclusion.cc we can remove the body of the files and
just include stdc++.cc twice. This means we don't need to add includes
to both stdc++.cc and stdc++_multiple_inclusion.cc, we only need to
update one place.

libstdc++-v3/ChangeLog:

* testsuite/17_intro/headers/c++1998/all_attributes.cc: Add
attribute names from later standards and remove dg-options.
* testsuite/17_intro/headers/c++1998/stdc++.cc: Add c++98_only
target selector.
* testsuite/17_intro/headers/c++1998/stdc++_multiple_inclusion.cc:
Remove content and include stdc++.cc twice instead.
* testsuite/17_intro/headers/c++2011/stdc++.cc: Replace
dg-options with c++11 target selector.
* testsuite/17_intro/headers/c++2011/stdc++_multiple_inclusion.cc:
Remove content and include stdc++.cc twice instead.
* testsuite/17_intro/headers/c++2011/all_attributes.cc: Removed.
* testsuite/17_intro/headers/c++2011/all_no_exceptions.cc: Removed.
* testsuite/17_intro/headers/c++2011/all_no_rtti.cc: Removed.
* testsuite/17_intro/headers/c++2011/all_pedantic_errors.cc: Removed.
* testsuite/17_intro/headers/c++2011/charset.cc: Removed.
* testsuite/17_intro/headers/c++2011/operator_names.cc: Removed.
* testsuite/17_intro/headers/c++2014/all_attributes.cc: Removed.
* testsuite/17_intro/headers/c++2014/all_no_exceptions.cc: Removed.
* testsuite/17_intro/headers/c++2014/all_no_rtti.cc: Removed.
* testsuite/17_intro/headers/c++2014/all_pedantic_errors.cc: Removed.
* testsuite/17_intro/headers/c++2014/charset.cc: Removed.
* testsuite/17_intro/headers/c++2014/operator_names.cc: Removed.
* testsuite/17_intro/headers/c++2014/stdc++.cc: Removed.
* testsuite/17_intro/headers/c++2014/stdc++_multiple_inclusion.cc: 
Removed.
* testsuite/17_intro/headers/c++2017/all_attributes.cc: Removed.
* testsuite/17_intro/headers/c++2017/all_no_exceptions.cc: Removed.
* testsuite/17_intro/headers/c++2017/all_no_rtti.cc: Removed.
* testsuite/17_intro/headers/c++2017/all_pedantic_errors.cc: Removed.
* testsuite/17_intro/headers/c++2017/charset.cc: Removed.
* testsuite/17_intro/headers/c++2017/operator_names.cc: Removed.
* testsuite/17_intro/headers/c++2017/stdc++.cc: Removed.
* testsuite/17_intro/headers/c++2017/stdc++_multiple_inclusion.cc: 
Removed.
* testsuite/17_intro/headers/c++2020/all_attributes.cc: Removed.
* testsuite/17_intro/headers/c++2020/all_no_exceptions.cc: Removed.
* testsuite/17_intro/headers/c++2020/all_no_rtti.cc: Removed.
* testsuite/17_intro/headers/c++2020/all_pedantic_errors.cc: Removed.
* testsuite/17_intro/headers/c++2020/charset.cc: Removed.
* testsuite/17_intro/headers/c++2020/operator_names.cc: Removed.
* testsuite/17_intro/headers/c++2020/stdc++.cc: Removed.
* testsuite/17_intro/headers/c++2020/stdc++_multiple_inclusion.cc: 
Removed.
---
 .../headers/c++1998/all_attributes.cc |  20 ++-
 .../17_intro/headers/c++1998/stdc++.cc|   2 +-
 .../c++1998/stdc++_multiple_inclusion.cc  |  53 +---
 .../headers/c++2011/all_attributes.cc |  44 ---
 .../headers/c++2011/all_no_exceptions.cc  |  21 
 .../17_intro/headers/c++2011/all_no_rtti.cc   |  21 
 .../headers/c++2011/all_pedantic_errors.cc|  21 
 .../17_intro/headers/c++2011/charset.cc   |   5 -
 .../headers/c++2011/operator_names.cc |  30 -
 .../17_intro/headers/c++2011/stdc++.cc|   5 +-
 .../c++2011/stdc++_multiple_inclusion.cc  | 100 +--
 .../headers/c++2014/all_attributes.cc |  44 ---
 .../headers/c++2014/all_no_exceptions.cc  |  21 
 .../17_intro/headers/c++2014/all_no_rtti.cc   |  21 
 .../headers/c++2014/all_pedantic_errors.cc|  21 
 .../17_intro/headers/c++2014/charset.cc   |   5 -
 .../headers/c++2014/operator_names.cc |  30 -
 .../17_intro/headers/c++2014/stdc++.cc|  70 ---
 .../c++2014/stdc++_multiple_inclusion.cc  | 117 --
 .../headers/c++2017/all_attributes.cc |  43 ---
 

[committed] libstdc++: Use reserved form of [[__likely__]] in

2024-07-06 Thread Jonathan Wakely
Tested x86_64-linux. Pushed to trunk.

-- >8 --

We should not use [[unlikely]] before C++20, so use [[__unlikely__]]
instead.

libstdc++-v3/ChangeLog:

* include/std/variant (_Variant_storage::_M_reset): Use
__unlikely__ form of attribute instead of unlikely.
---
 libstdc++-v3/include/std/variant | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 13ea1dd3849..3a23d9bc66d 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -492,7 +492,7 @@ namespace __variant
   constexpr void
   _M_reset()
   {
-   if (!_M_valid()) [[unlikely]]
+   if (!_M_valid()) [[__unlikely__]]
  return;
 
std::__do_visit([](auto&& __this_mem) mutable
-- 
2.45.2



Re: [committed] libstdc++: Use reserved form of [[__likely__]] in

2024-07-06 Thread Jonathan Wakely
This one needs to be backported too.

On Sat, 6 Jul 2024 at 21:18, Jonathan Wakely  wrote:
>
> Tested x86_64-linux. Pushed to trunk.
>
> -- >8 --
>
> We should not use [[unlikely]] before C++20, so use [[__unlikely__]]
> instead.
>
> libstdc++-v3/ChangeLog:
>
> * include/std/variant (_Variant_storage::_M_reset): Use
> __unlikely__ form of attribute instead of unlikely.
> ---
>  libstdc++-v3/include/std/variant | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libstdc++-v3/include/std/variant 
> b/libstdc++-v3/include/std/variant
> index 13ea1dd3849..3a23d9bc66d 100644
> --- a/libstdc++-v3/include/std/variant
> +++ b/libstdc++-v3/include/std/variant
> @@ -492,7 +492,7 @@ namespace __variant
>constexpr void
>_M_reset()
>{
> -   if (!_M_valid()) [[unlikely]]
> +   if (!_M_valid()) [[__unlikely__]]
>   return;
>
> std::__do_visit([](auto&& __this_mem) mutable
> --
> 2.45.2
>



[committed] libstdc++: Restore support for including in extern "C" [PR115797]

2024-07-06 Thread Jonathan Wakely
Tested x86_64-linux. Pushed to trunk.

-- >8 --

The r15-1857 change means that  is included by  for
C++17 and up, which breaks code including  inside an extern "C"
block. Although doing that is not allowed by the C++ standard, there's
lots of existing code which incorrectly thinks it's a good idea and so
we try to support it.

libstdc++-v3/ChangeLog:

PR libstdc++/115797
* include/std/type_traits: Ensure "C++" language linkage.
* testsuite/17_intro/headers/c++2011/linkage.cc: Replace
dg-options with c++11 target selector.
---
 libstdc++-v3/include/std/type_traits   | 3 +++
 libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc | 3 +--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/type_traits 
b/libstdc++-v3/include/std/type_traits
index a31de2ee4ab..c39a3792537 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -62,6 +62,8 @@
 #define __glibcxx_want_void_t
 #include 
 
+extern "C++"
+{
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -4111,6 +4113,7 @@ template
 
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
+} // extern "C++"
 
 #endif  // C++11
 
diff --git a/libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc 
b/libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc
index c43384efbaa..1825801cec9 100644
--- a/libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc
+++ b/libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc
@@ -15,8 +15,7 @@
 // with this library; see the file COPYING3.  If not see
 // .
 
-// { dg-options "-std=gnu++11" }
-// { dg-do compile }
+// { dg-do compile { target c++11 } }
 
 // libstdc++/69386
 
-- 
2.45.2



[gcc r15-1877] libstdc++: Remove redundant 17_intro/headers tests

2024-07-06 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:3fc913104d2a8000bba169049e0fc143640c7793

commit r15-1877-g3fc913104d2a8000bba169049e0fc143640c7793
Author: Jonathan Wakely 
Date:   Fri Jul 5 20:06:01 2024 +0100

libstdc++: Remove redundant 17_intro/headers tests

We have several nearly identical tests under 17_intro/headers which only
differ in a -std option set using dg-options. Since the testsuite now
supports running tests with multiple -std options (and I test that
regularly) we don't need these duplicated tests. We can remove most of
them and let the testsuite decide which -std option to use.

In the all_attributes.cc case the content of the tests is slightly
different, but they can be combined into one test that defines macros
conditionally based on __cplusplus checks.

The stdc++.cc tests could also be combined this way, but for now I've
just kept one version for c++98 and one for all later standards.

For stdc++_multiple_inclusion.cc we can remove the body of the files and
just include stdc++.cc twice. This means we don't need to add includes
to both stdc++.cc and stdc++_multiple_inclusion.cc, we only need to
update one place.

libstdc++-v3/ChangeLog:

* testsuite/17_intro/headers/c++1998/all_attributes.cc: Add
attribute names from later standards and remove dg-options.
* testsuite/17_intro/headers/c++1998/stdc++.cc: Add c++98_only
target selector.
* testsuite/17_intro/headers/c++1998/stdc++_multiple_inclusion.cc:
Remove content and include stdc++.cc twice instead.
* testsuite/17_intro/headers/c++2011/stdc++.cc: Replace
dg-options with c++11 target selector.
* testsuite/17_intro/headers/c++2011/stdc++_multiple_inclusion.cc:
Remove content and include stdc++.cc twice instead.
* testsuite/17_intro/headers/c++2011/all_attributes.cc: Removed.
* testsuite/17_intro/headers/c++2011/all_no_exceptions.cc: Removed.
* testsuite/17_intro/headers/c++2011/all_no_rtti.cc: Removed.
* testsuite/17_intro/headers/c++2011/all_pedantic_errors.cc: 
Removed.
* testsuite/17_intro/headers/c++2011/charset.cc: Removed.
* testsuite/17_intro/headers/c++2011/operator_names.cc: Removed.
* testsuite/17_intro/headers/c++2014/all_attributes.cc: Removed.
* testsuite/17_intro/headers/c++2014/all_no_exceptions.cc: Removed.
* testsuite/17_intro/headers/c++2014/all_no_rtti.cc: Removed.
* testsuite/17_intro/headers/c++2014/all_pedantic_errors.cc: 
Removed.
* testsuite/17_intro/headers/c++2014/charset.cc: Removed.
* testsuite/17_intro/headers/c++2014/operator_names.cc: Removed.
* testsuite/17_intro/headers/c++2014/stdc++.cc: Removed.
* testsuite/17_intro/headers/c++2014/stdc++_multiple_inclusion.cc: 
Removed.
* testsuite/17_intro/headers/c++2017/all_attributes.cc: Removed.
* testsuite/17_intro/headers/c++2017/all_no_exceptions.cc: Removed.
* testsuite/17_intro/headers/c++2017/all_no_rtti.cc: Removed.
* testsuite/17_intro/headers/c++2017/all_pedantic_errors.cc: 
Removed.
* testsuite/17_intro/headers/c++2017/charset.cc: Removed.
* testsuite/17_intro/headers/c++2017/operator_names.cc: Removed.
* testsuite/17_intro/headers/c++2017/stdc++.cc: Removed.
* testsuite/17_intro/headers/c++2017/stdc++_multiple_inclusion.cc: 
Removed.
* testsuite/17_intro/headers/c++2020/all_attributes.cc: Removed.
* testsuite/17_intro/headers/c++2020/all_no_exceptions.cc: Removed.
* testsuite/17_intro/headers/c++2020/all_no_rtti.cc: Removed.
* testsuite/17_intro/headers/c++2020/all_pedantic_errors.cc: 
Removed.
* testsuite/17_intro/headers/c++2020/charset.cc: Removed.
* testsuite/17_intro/headers/c++2020/operator_names.cc: Removed.
* testsuite/17_intro/headers/c++2020/stdc++.cc: Removed.
* testsuite/17_intro/headers/c++2020/stdc++_multiple_inclusion.cc: 
Removed.

Diff:
---
 .../17_intro/headers/c++1998/all_attributes.cc |  20 +++-
 .../testsuite/17_intro/headers/c++1998/stdc++.cc   |   2 +-
 .../headers/c++1998/stdc++_multiple_inclusion.cc   |  53 +-
 .../17_intro/headers/c++2011/all_attributes.cc |  44 
 .../17_intro/headers/c++2011/all_no_exceptions.cc  |  21 
 .../17_intro/headers/c++2011/all_no_rtti.cc|  21 
 .../headers/c++2011/all_pedantic_errors.cc |  21 
 .../testsuite/17_intro/headers/c++2011/charset.cc  |   5 -
 .../17_intro/headers/c++2011/operator_names.cc |  30 --
 .../testsuite/17_intro/headers/c++2011/stdc++.cc   |   5 +-
 .../headers/c++2011/stdc++_multiple_inclusion.cc   | 100 +-
 .../17_intro/headers/c++2014/all_attributes.cc |  44

[gcc r15-1876] libstdc++: Use reserved form of [[__likely__]] in

2024-07-06 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:9f1cd51766f251aafe0f1b898892f79855892729

commit r15-1876-g9f1cd51766f251aafe0f1b898892f79855892729
Author: Jonathan Wakely 
Date:   Fri Jul 5 20:00:04 2024 +0100

libstdc++: Use reserved form of [[__likely__]] in 

We should not use [[unlikely]] before C++20, so use [[__unlikely__]]
instead.

libstdc++-v3/ChangeLog:

* include/std/variant (_Variant_storage::_M_reset): Use
__unlikely__ form of attribute instead of unlikely.

Diff:
---
 libstdc++-v3/include/std/variant | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 13ea1dd3849..3a23d9bc66d 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -492,7 +492,7 @@ namespace __variant
   constexpr void
   _M_reset()
   {
-   if (!_M_valid()) [[unlikely]]
+   if (!_M_valid()) [[__unlikely__]]
  return;
 
std::__do_visit([](auto&& __this_mem) mutable


[gcc r15-1875] libstdc++: Restore support for including in extern "C" [PR115797]

2024-07-06 Thread Jonathan Wakely via Libstdc++-cvs
https://gcc.gnu.org/g:dcc735aaeae1cc985a143ade883db748fb10554d

commit r15-1875-gdcc735aaeae1cc985a143ade883db748fb10554d
Author: Jonathan Wakely 
Date:   Fri Jul 5 18:39:50 2024 +0100

libstdc++: Restore support for including  in extern "C" [PR115797]

The r15-1857 change means that  is included by  for
C++17 and up, which breaks code including  inside an extern "C"
block. Although doing that is not allowed by the C++ standard, there's
lots of existing code which incorrectly thinks it's a good idea and so
we try to support it.

libstdc++-v3/ChangeLog:

PR libstdc++/115797
* include/std/type_traits: Ensure "C++" language linkage.
* testsuite/17_intro/headers/c++2011/linkage.cc: Replace
dg-options with c++11 target selector.

Diff:
---
 libstdc++-v3/include/std/type_traits   | 3 +++
 libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc | 3 +--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/type_traits 
b/libstdc++-v3/include/std/type_traits
index a31de2ee4ab..c39a3792537 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -62,6 +62,8 @@
 #define __glibcxx_want_void_t
 #include 
 
+extern "C++"
+{
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -4111,6 +4113,7 @@ template
 
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
+} // extern "C++"
 
 #endif  // C++11
 
diff --git a/libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc 
b/libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc
index c43384efbaa..1825801cec9 100644
--- a/libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc
+++ b/libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc
@@ -15,8 +15,7 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// { dg-options "-std=gnu++11" }
-// { dg-do compile }
+// { dg-do compile { target c++11 } }
 
 // libstdc++/69386


Re: [PATCH v1] Remove 'restrict' from 'nptr' in strtol(3)-like functions

2024-07-05 Thread Jonathan Wakely via Gcc
On Fri, 5 Jul 2024 at 21:55, Alejandro Colomar  wrote:
>
> On Fri, Jul 05, 2024 at 09:28:46PM GMT, Jonathan Wakely wrote:
> > > If we marked endptr as "write_only" (which it might already
> > > be) then a future warning mechanism for -Wrestrict could
> > > ignore the content of *endptr.
> >
> >
> > That seems more useful. Add semantic information instead of taking it
> > away. If the concern is a hypothetical future compiler warning that
> > would give false positives for perfectly valid uses of strtol, then
> > the problem is the compiler warning, not strtol. If additional
> > information can be added to avoid the false positives (and also
> > possibly optimize the code better), then that wouldn't require a
> > change to the standard motivated by a hypothetical compiler warning.
>
> Let me be a little bit sarcastic.
>
> If so, let's take down -Wrestrict at all, because it triggers false
> positives at the same rate.  How is it even in -Wall and not just
> -Wextra?
>
> Here's a false positive:
>
> $ cat d.c
> int is_same_pointer(const char *restrict ca, char *restrict a)
> {
> return ca == a;

This is a strawman argument, because all your example functions have
been pretty useless and/or not good uses of restrict.

Yes, if you put restrict on functions where you don't ever access any
objects through the pointers, the restrict qualifiers are misleading
and so compilers might give bad warnings for your bad API.

> }
>
> int main(void)
> {
> char x = 3;
> char *xp = 
> is_same_pointer(xp, xp);
> }
> $ cc -Wall d.c
> d.c: In function ‘main’:
> d.c:10:9: warning: passing argument 2 to ‘restrict’-qualified 
> parameter aliases with argument 1 [-Wrestrict]
>10 | d(xp, xp);
>   | ^~~
>
> It's impossible to know if a use of restrict causes UB without reading
> both the source code of the caller and the callee, so except for
> -fanalyzer, it's impossible to diagnose something with certainty.
>
> So, it's certainly not something we want in -Wall.
>
> Or should I remove the 'restrict' qualifier from that function, loosing
> "precious" semantic information, just because the compiler doesn't like
> it?
>
> Cheers,
> Alex
>
>
> --
> <https://www.alejandro-colomar.es/>


Re: [PATCH v1] Remove 'restrict' from 'nptr' in strtol(3)-like functions

2024-07-05 Thread Jonathan Wakely via Gcc
On Fri, 5 Jul 2024 at 21:26, Martin Uecker  wrote:
>
> Am Freitag, dem 05.07.2024 um 21:28 +0200 schrieb Alejandro Colomar:
>
> ...
> >
> > > > Showing that you can contrive a case where a const char* restrict and
> > > > char** restrict can alias doesn't mean there's a problem with strtol.
> > >
> > > I think his point is that a const char* restrict and something which
> > > is stored in a char* whose address is then passed can alias and there
> > > a warning would make sense in other situations.
> >
> > Indeed.
> >
> > > But I am also not convinced removing restrict would be an improvement.
> > > It would make more sense to have an annotation that indicates that
> > > endptr is only used as output.
> >
> > What is the benefit of keeping restrict there?  It doesn't provide any
> > benefits, AFAICS.
>
> Not really I think.  I am generally not a fan of restrict.
> IMHO it is misdesigned and I would like to see it replaced
> with something better.  But I also not convinced it really
> helps to remove it here.
>
> If we marked endptr as "write_only" (which it might already
> be) then a future warning mechanism for -Wrestrict could
> ignore the content of *endptr.


That seems more useful. Add semantic information instead of taking it
away. If the concern is a hypothetical future compiler warning that
would give false positives for perfectly valid uses of strtol, then
the problem is the compiler warning, not strtol. If additional
information can be added to avoid the false positives (and also
possibly optimize the code better), then that wouldn't require a
change to the standard motivated by a hypothetical compiler warning.


  1   2   3   4   5   6   7   8   9   10   >