[gcc r14-9363] doc: Fix docs for -dD regarding predefined macros

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

commit r14-9363-ge2e4b603ced350447a8d0e2c5f4d419b8f69b6a6
Author: Jonathan Wakely 
Date:   Tue Mar 5 16:09:06 2024 +

doc: Fix docs for -dD regarding predefined macros

The manual has always claimed that -dD differs from -dM by not
outputting predefined macros, but that's untrue. It has been untrue
since GCC 3.0 (probably with the change to use libcpp as the default
preprocessor implementation).

gcc/ChangeLog:

* doc/cppopts.texi: Remove incorrect claim about -dD not
outputting predefined macros.

Diff:
---
 gcc/doc/cppopts.texi | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/gcc/doc/cppopts.texi b/gcc/doc/cppopts.texi
index fa8f3d88c89..5b5b0848ae8 100644
--- a/gcc/doc/cppopts.texi
+++ b/gcc/doc/cppopts.texi
@@ -524,8 +524,7 @@ interpreted as a synonym for @option{-fdump-rtl-mach}.
 
 @opindex dD
 @item -dD
-Like @option{-dM} except in two respects: it does @emph{not} include the
-predefined macros, and it outputs @emph{both} the @samp{#define}
+Like @option{-dM} except that it outputs @emph{both} the @samp{#define}
 directives and the result of preprocessing.  Both kinds of output go to
 the standard output file.


[gcc r15-283] libstdc++: Simplify std::variant comparison operators

2024-05-07 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:6709e35457a30b2184fa8337aa4abdd2c0edaeb3

commit r15-283-g6709e35457a30b2184fa8337aa4abdd2c0edaeb3
Author: Jonathan Wakely 
Date:   Thu Mar 28 14:19:45 2024 +

libstdc++: Simplify std::variant comparison operators

libstdc++-v3/ChangeLog:

* include/std/variant (_VARIANT_RELATION_FUNCTION_TEMPLATE):
Simplify.

Diff:
---
 libstdc++-v3/include/std/variant | 20 +---
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 8072e1f17a8..bf05eec9a6b 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -1245,7 +1245,7 @@ namespace __variant
 # define _VARIANT_RELATION_FUNCTION_CONSTRAINTS(TYPES, OP)
 #endif
 
-#define _VARIANT_RELATION_FUNCTION_TEMPLATE(__OP, __NAME) \
+#define _VARIANT_RELATION_FUNCTION_TEMPLATE(__OP) \
   template \
 _VARIANT_RELATION_FUNCTION_CONSTRAINTS(_Types, __OP) \
 constexpr bool \
@@ -1262,22 +1262,20 @@ namespace __variant
{ \
  auto& __this_mem = std::get<__rhs_index>(__lhs);  \
   __ret = __this_mem __OP __rhs_mem; \
+ return; \
 } \
- else \
-   __ret = (__lhs.index() + 1) __OP (__rhs_index + 1); \
 } \
-  else \
-__ret = (__lhs.index() + 1) __OP (__rhs_index + 1); \
+ __ret = (__lhs.index() + 1) __OP (__rhs_index + 1); \
}, __rhs); \
   return __ret; \
 }
 
-  _VARIANT_RELATION_FUNCTION_TEMPLATE(<, less)
-  _VARIANT_RELATION_FUNCTION_TEMPLATE(<=, less_equal)
-  _VARIANT_RELATION_FUNCTION_TEMPLATE(==, equal)
-  _VARIANT_RELATION_FUNCTION_TEMPLATE(!=, not_equal)
-  _VARIANT_RELATION_FUNCTION_TEMPLATE(>=, greater_equal)
-  _VARIANT_RELATION_FUNCTION_TEMPLATE(>, greater)
+  _VARIANT_RELATION_FUNCTION_TEMPLATE(<)
+  _VARIANT_RELATION_FUNCTION_TEMPLATE(<=)
+  _VARIANT_RELATION_FUNCTION_TEMPLATE(==)
+  _VARIANT_RELATION_FUNCTION_TEMPLATE(!=)
+  _VARIANT_RELATION_FUNCTION_TEMPLATE(>=)
+  _VARIANT_RELATION_FUNCTION_TEMPLATE(>)
 
 #undef _VARIANT_RELATION_FUNCTION_TEMPLATE


[gcc r15-285] libstdc++: Fix handling of incomplete UTF-8 sequences in _Unicode_view

2024-05-07 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:3f04f3939ea0ac8fdd766a60655d29de2ffb44e5

commit r15-285-g3f04f3939ea0ac8fdd766a60655d29de2ffb44e5
Author: Jonathan Wakely 
Date:   Wed May 1 17:09:39 2024 +0100

libstdc++: Fix handling of incomplete UTF-8 sequences in _Unicode_view

Eddie Nolan reported to me that _Unicode_view was not correctly
implementing the substitution of ill-formed subsequences with U+FFFD,
due to failing to increment the counter when the iterator reaches the
end of the sequence before a multibyte sequence is complete.  As a
result, the incomplete sequence was not completely consumed, and then
the remaining character was treated as another ill-formed sequence,
giving two U+FFFD characters instead of one.

To avoid similar mistakes in future, this change introduces a lambda
that increments the iterator and the counter together. This ensures the
counter is always incremented when the iterator is incremented, so that
we always know how many characters have been consumed.

libstdc++-v3/ChangeLog:

* include/bits/unicode.h (_Unicode_view::_M_read_utf8): Ensure
count of characters consumed is correct when the end of the
input is reached unexpectedly.
* testsuite/ext/unicode/view.cc: Test incomplete UTF-8
sequences.

Diff:
---
 libstdc++-v3/include/bits/unicode.h| 24 +++-
 libstdc++-v3/testsuite/ext/unicode/view.cc |  7 +++
 2 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/libstdc++-v3/include/bits/unicode.h 
b/libstdc++-v3/include/bits/unicode.h
index 29813b743dc..46238143fb6 100644
--- a/libstdc++-v3/include/bits/unicode.h
+++ b/libstdc++-v3/include/bits/unicode.h
@@ -261,9 +261,13 @@ namespace __unicode
   {
_Guard<_Iter> __g{this, _M_curr()};
char32_t __c{};
-   uint8_t __u = *_M_curr()++;
const uint8_t __lo_bound = 0x80, __hi_bound = 0xBF;
+   uint8_t __u = *_M_curr()++;
uint8_t __to_incr = 1;
+   auto __incr = [&, this] {
+ ++__to_incr;
+ return ++_M_curr();
+   };
 
if (__u <= 0x7F) [[likely]]  // 0x00 to 0x7F
  __c = __u;
@@ -281,8 +285,7 @@ namespace __unicode
else
  {
__c = (__c << 6) | (__u & 0x3F);
-   ++_M_curr();
-   ++__to_incr;
+   __incr();
  }
  }
else if (__u <= 0xEF) // 0xE0 to 0xEF
@@ -295,11 +298,10 @@ namespace __unicode
 
if (__u < __lo_bound_2 || __u > __hi_bound_2) [[unlikely]]
  __c = _S_error();
-   else if (++_M_curr() == _M_last) [[unlikely]]
+   else if (__incr() == _M_last) [[unlikely]]
  __c = _S_error();
else
  {
-   ++__to_incr;
__c = (__c << 6) | (__u & 0x3F);
__u = *_M_curr();
 
@@ -308,8 +310,7 @@ namespace __unicode
else
  {
__c = (__c << 6) | (__u & 0x3F);
-   ++_M_curr();
-   ++__to_incr;
+   __incr();
  }
  }
  }
@@ -323,21 +324,19 @@ namespace __unicode
 
if (__u < __lo_bound_2 || __u > __hi_bound_2) [[unlikely]]
  __c = _S_error();
-   else if (++_M_curr() == _M_last) [[unlikely]]
+   else if (__incr() == _M_last) [[unlikely]]
  __c = _S_error();
else
  {
-   ++__to_incr;
__c = (__c << 6) | (__u & 0x3F);
__u = *_M_curr();
 
if (__u < __lo_bound || __u > __hi_bound) [[unlikely]]
  __c = _S_error();
-   else if (++_M_curr() == _M_last) [[unlikely]]
+   else if (__incr() == _M_last) [[unlikely]]
  __c = _S_error();
else
  {
-   ++__to_incr;
__c = (__c << 6) | (__u & 0x3F);
__u = *_M_curr();
 
@@ -346,8 +345,7 @@ namespace __unicode
else
  {
__c = (__c << 6) | (__u & 0x3F);
-   ++_M_curr();
-   ++__to_incr;
+   __incr();
  }
  }
  }
diff --git a/libstdc++-v3/testsuite/ext/unicode/view.cc 
b/libstdc++-v3/testsuite/ext/unicode/view.cc
index ee23b0b1d8a..6f3c099bd84 100644
--- a/libstdc++-v3/testsuite/ext/unicode/view.cc
+++ b/libstdc++-v3/testsuite/ext/unicode/view.cc
@@ -55,6 +55,13 @@ test_illformed_utf8()
   VERIFY( std::ranges::equal(v5, 
u8"\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\x41\uFFFD\uFFFD\x42"sv) );
   uc::_Utf8_view v6("\xe1\x80\xe2\xf0\x91\x92\xf1\xbf\x41"sv); // Table 3-11
   VERIFY( std::ranges::equal(v6, u8"\uFFFD\uFFFD\uFFFD\uFFFD\x41"sv) );
+
+  uc::_Utf32_view v7("\xe1\x80"sv);
+  VERIFY( std::ranges::equal(v7, U

[gcc r14-10206] libstdc++: Guard uses of is_pointer_interconvertible_v [PR114891]

2024-05-14 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:4d3b358fd757ddd09cbee202f47939043c78676c

commit r14-10206-g4d3b358fd757ddd09cbee202f47939043c78676c
Author: Jonathan Wakely 
Date:   Tue Apr 30 09:48:00 2024 +0100

libstdc++: Guard uses of is_pointer_interconvertible_v [PR114891]

This type trait isn't supported by Clang 18. It's only used in static
assertions, so they can just be omitted if the trait isn't available.

libstdc++-v3/ChangeLog:

PR libstdc++/114891
* include/std/generator: Check feature test macro before using
is_pointer_interconvertible_v.

(cherry picked from commit 1fbe1a50d86df11f434351cf62461a32747f9710)

Diff:
---
 libstdc++-v3/include/std/generator | 8 
 1 file changed, 8 insertions(+)

diff --git a/libstdc++-v3/include/std/generator 
b/libstdc++-v3/include/std/generator
index 789016b5a883..1d5acc914203 100644
--- a/libstdc++-v3/include/std/generator
+++ b/libstdc++-v3/include/std/generator
@@ -322,8 +322,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template
auto await_suspend(std::coroutine_handle<_Promise> __c) noexcept
{
+#ifdef __glibcxx_is_pointer_interconvertible
  static_assert(is_pointer_interconvertible_base_of_v<
_Promise_erased, _Promise>);
+#endif
 
  auto& __n = __c.promise()._M_nest;
  return __n._M_pop();
@@ -344,8 +346,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template
void await_suspend(std::coroutine_handle<_Promise>) noexcept
{
+#ifdef __glibcxx_is_pointer_interconvertible
  static_assert(is_pointer_interconvertible_base_of_v<
_Promise_erased, _Promise>);
+#endif
  _M_bottom_value = ::std::addressof(_M_value);
}
 
@@ -375,8 +379,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::coroutine_handle<>
await_suspend(std::coroutine_handle<_Promise> __p) noexcept
{
+#ifdef __glibcxx_is_pointer_interconvertible
  static_assert(is_pointer_interconvertible_base_of_v<
_Promise_erased, _Promise>);
+#endif
 
  auto __c = _Coro_handle::from_address(__p.address());
  auto __t = _Coro_handle::from_address(this->_M_gen._M_coro.address());
@@ -685,8 +691,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return { coroutine_handle::from_promise(*this) }; }
   };
 
+#ifdef __glibcxx_is_pointer_interconvertible
   static_assert(is_pointer_interconvertible_base_of_v<_Erased_promise,
promise_type>);
+#endif
 
   generator(const generator&) = delete;


[gcc r14-10207] libstdc++: Fix typo in std::stacktrace::max_size [PR115063]

2024-05-14 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:c60205cd4aeea586b7b1fe06baa9861b6d279648

commit r14-10207-gc60205cd4aeea586b7b1fe06baa9861b6d279648
Author: Jonathan Wakely 
Date:   Mon May 13 16:25:13 2024 +0100

libstdc++: Fix typo in std::stacktrace::max_size [PR115063]

libstdc++-v3/ChangeLog:

PR libstdc++/115063
* include/std/stacktrace (basic_stacktrace::max_size): Fix typo
in reference to _M_alloc member.
* testsuite/19_diagnostics/stacktrace/stacktrace.cc: Check
max_size() compiles.

(cherry picked from commit dd9677f3343ca2a4b4aab9428b8129774accac29)

Diff:
---
 libstdc++-v3/include/std/stacktrace|  2 +-
 libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc | 10 ++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/stacktrace 
b/libstdc++-v3/include/std/stacktrace
index 92a69a53d986..d217d63af3bb 100644
--- a/libstdc++-v3/include/std/stacktrace
+++ b/libstdc++-v3/include/std/stacktrace
@@ -430,7 +430,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   [[nodiscard]]
   size_type
   max_size() const noexcept
-  { return _Impl::_S_max_size(_M_impl._M_alloc); }
+  { return _Impl::_S_max_size(_M_alloc); }
 
   [[nodiscard]]
   const_reference
diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc 
b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
index 070c4157471c..a49cddfef268 100644
--- a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
+++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
@@ -206,10 +206,20 @@ test_pr105031()
   s = auto(s);
 }
 
+void
+test_pr115063()
+{
+  // PR libstdc++/115063
+  // compilation error: std::basic_stracktrace::max_size()
+  std::stacktrace s;
+  VERIFY( s.max_size() != 0 );
+}
+
 int main()
 {
   test_cons();
   test_assign();
   test_swap();
   test_pr105031();
+  test_pr115063();
 }


[gcc r13-8768] libstdc++: Fix run_doxygen for Doxygen 1.10 man page format

2024-05-14 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:bce15a5d7d2c4053b8d5e718f00db8eb20116cb6

commit r13-8768-gbce15a5d7d2c4053b8d5e718f00db8eb20116cb6
Author: Jonathan Wakely 
Date:   Thu Apr 25 13:24:56 2024 +0100

libstdc++: Fix run_doxygen for Doxygen 1.10 man page format

Doxygen switched from \fC to \fR in its man page output:
https://github.com/doxygen/doxygen/pull/10497

This breaks our script that expects \fC so change the regaulr expression
to work with either style.

libstdc++-v3/ChangeLog:

* scripts/run_doxygen: Adjust sed pattern to match '\fR' for
new man output that Doxygen 1.10 generates.

(cherry picked from commit c9cc1c850c6d084752207b6cf247a0a48bae0d52)

Diff:
---
 libstdc++-v3/scripts/run_doxygen | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/scripts/run_doxygen b/libstdc++-v3/scripts/run_doxygen
index 42ed9eb4f5df..9c11a0cfa1fd 100644
--- a/libstdc++-v3/scripts/run_doxygen
+++ b/libstdc++-v3/scripts/run_doxygen
@@ -294,7 +294,11 @@ $gxx $cppflags $cxxflags 
${srcdir}/doc/doxygen/stdheader.cc -o ./stdheader || ex
 problematic=`grep -E -l '#include <.*h>' [a-z]*.3`
 for f in $problematic; do
 # this is also slow, but safe and easy to debug
-oldh=`sed -n '/fC#include .*/\1/p' $f`
+oldh=`sed -n '/f[CR]#include .*/\1/p' $f`
+if [ "$oldh" == "" ]; then
+  echo "ERROR: Doxygen man page formatting changed" 2>&1
+  continue
+fi
 newh=`echo $oldh | sed 's/&\\././g' | ./stdheader`
 sed "s=${oldh/\\/.}=${newh}=" $f > TEMP && mv TEMP $f
 done


[gcc r13-8769] libstdc++: Fix typo in Doxygen comment

2024-05-14 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:ebc61a9c4c730bf5562db25b1fcc06d615e33e66

commit r13-8769-gebc61a9c4c730bf5562db25b1fcc06d615e33e66
Author: Jonathan Wakely 
Date:   Thu Apr 25 13:52:00 2024 +0100

libstdc++: Fix typo in Doxygen comment

libstdc++-v3/ChangeLog:

* include/std/chrono (tzdb_list): Fix typo in Doxygen comment.

(cherry picked from commit 6391cf8bd9c1d71805d9aba00b25fdaa550f39c8)

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

diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono
index edb782f6f10e..1f3f897d932a 100644
--- a/libstdc++-v3/include/std/chrono
+++ b/libstdc++-v3/include/std/chrono
@@ -2790,7 +2790,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /** Remove the tzdb object _after_ the one the iterator refers to.
*
-   * Calling this function concurently with any of `front()`, `begin()`,
+   * Calling this function concurrently with any of `front()`, `begin()`,
* or `end()` does not cause a data race, but in general this function
* is not thread-safe. The behaviour may be undefined if erasing an
* element from the list while another thread is calling the same


[gcc r15-481] libstdc++: Fix typo in std::stacktrace::max_size [PR115063]

2024-05-14 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:ccc26a1af07b34ce2e7d3b2497f27992d1b1bbc2

commit r15-481-gccc26a1af07b34ce2e7d3b2497f27992d1b1bbc2
Author: Jonathan Wakely 
Date:   Mon May 13 16:25:13 2024 +0100

libstdc++: Fix typo in std::stacktrace::max_size [PR115063]

libstdc++-v3/ChangeLog:

PR libstdc++/115063
* include/std/stacktrace (basic_stacktrace::max_size): Fix typo
in reference to _M_alloc member.
* testsuite/19_diagnostics/stacktrace/stacktrace.cc: Check
max_size() compiles.

Diff:
---
 libstdc++-v3/include/std/stacktrace|  2 +-
 libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc | 10 ++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/stacktrace 
b/libstdc++-v3/include/std/stacktrace
index 92a69a53d986..d217d63af3bb 100644
--- a/libstdc++-v3/include/std/stacktrace
+++ b/libstdc++-v3/include/std/stacktrace
@@ -430,7 +430,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   [[nodiscard]]
   size_type
   max_size() const noexcept
-  { return _Impl::_S_max_size(_M_impl._M_alloc); }
+  { return _Impl::_S_max_size(_M_alloc); }
 
   [[nodiscard]]
   const_reference
diff --git a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc 
b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
index 070c4157471c..a49cddfef268 100644
--- a/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
+++ b/libstdc++-v3/testsuite/19_diagnostics/stacktrace/stacktrace.cc
@@ -206,10 +206,20 @@ test_pr105031()
   s = auto(s);
 }
 
+void
+test_pr115063()
+{
+  // PR libstdc++/115063
+  // compilation error: std::basic_stracktrace::max_size()
+  std::stacktrace s;
+  VERIFY( s.max_size() != 0 );
+}
+
 int main()
 {
   test_cons();
   test_assign();
   test_swap();
   test_pr105031();
+  test_pr115063();
 }


[gcc r14-10208] libstdc++: Guard dynamic_cast use in src/c++23/print.cc [PR115015]

2024-05-14 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:eefa4c06483f95f5076687ed6aae5c6001731164

commit r14-10208-geefa4c06483f95f5076687ed6aae5c6001731164
Author: Jonathan Wakely 
Date:   Tue May 14 14:32:23 2024 +0100

libstdc++: Guard dynamic_cast use in src/c++23/print.cc [PR115015]

Do not use dynamic_cast unconditionally, in case libstdc++ is built with
-fno-rtti.

libstdc++-v3/ChangeLog:

PR libstdc++/115015
* src/c++23/print.cc (__open_terminal(streambuf*)) [!__cpp_rtti]:
Do not use dynamic_cast.

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

diff --git a/libstdc++-v3/src/c++23/print.cc b/libstdc++-v3/src/c++23/print.cc
index aceca6f9139b..99a19cd45002 100644
--- a/libstdc++-v3/src/c++23/print.cc
+++ b/libstdc++-v3/src/c++23/print.cc
@@ -87,7 +87,7 @@ namespace
   void*
   __open_terminal(std::streambuf* sb)
   {
-#ifndef _GLIBCXX_USE_STDIO_PURE
+#if ! defined _GLIBCXX_USE_STDIO_PURE && defined __cpp_rtti
 using namespace __gnu_cxx;
 
 if (auto fb = dynamic_cast*>(sb))


[gcc r15-3652] libstdc++: Enable most of for freestanding

2024-09-15 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:1dde83f0ec313166fc91e6784a0ca2e3db46acee

commit r15-3652-g1dde83f0ec313166fc91e6784a0ca2e3db46acee
Author: Jonathan Wakely 
Date:   Mon Jan 15 14:09:21 2024 +

libstdc++: Enable most of  for freestanding

This makes durations, time points and calendrical types available for
freestanding. The clocks and time zone utilities are disabled for
freestanding, as they require functions in the hosted lib.

Add support for a new macro _GLIBCXX_NO_FREESTANDING_CHRONO which can be
used to explicitly disable  for freestanding.

libstdc++-v3/ChangeLog:

* doc/xml/manual/using.xml (_GLIBCXX_NO_FREESTANDING_CHRONO):
Document macro.
* doc/html/*: Regenerate.
* include/bits/chrono.h [_GLIBCXX_NO_FREESTANDING_CHRONO]:
Only include  when this macro is defined.
[_GLIBCXX_HOSTED]: Only define clocks for hosted.
* include/bits/version.def (chrono_udls): Remove hosted=yes.
* include/bits/version.h: Regenerate.
* include/std/chrono [_GLIBCXX_HOSTED]: Only define clocks and
time zone utilities for hosted.
* testsuite/std/time/freestanding.cc: New test.

Diff:
---
 libstdc++-v3/doc/html/manual/using_macros.html  |  7 
 libstdc++-v3/doc/xml/manual/using.xml   | 12 ++
 libstdc++-v3/include/bits/chrono.h  | 24 +---
 libstdc++-v3/include/bits/version.def   |  1 -
 libstdc++-v3/include/bits/version.h |  2 +-
 libstdc++-v3/include/std/chrono | 24 +---
 libstdc++-v3/testsuite/std/time/freestanding.cc | 52 +
 7 files changed, 109 insertions(+), 13 deletions(-)

diff --git a/libstdc++-v3/doc/html/manual/using_macros.html 
b/libstdc++-v3/doc/html/manual/using_macros.html
index ae5646926307..67623b5e2aff 100644
--- a/libstdc++-v3/doc/html/manual/using_macros.html
+++ b/libstdc++-v3/doc/html/manual/using_macros.html
@@ -124,4 +124,11 @@
 must be present on all vector operations or none, so this macro must
 be defined to the same value for all translation units that create,
 destroy, or modify vectors.
+  _GLIBCXX_NO_FREESTANDING_CHRONO
+   Undefined by default. When defined, the
+    header cannot
+   be used with -ffreestanding.
+   When not defined, durations, time points, and calendar types are
+   available for freestanding, but the standard clocks and the time zone
+   database are not (because they require OS support).
   Prev Up NextHeaders Home 
Dual ABI
\ No newline at end of file
diff --git a/libstdc++-v3/doc/xml/manual/using.xml 
b/libstdc++-v3/doc/xml/manual/using.xml
index 6675359f3b3c..4e1c70040b56 100644
--- a/libstdc++-v3/doc/xml/manual/using.xml
+++ b/libstdc++-v3/doc/xml/manual/using.xml
@@ -1321,6 +1321,18 @@ g++ -Winvalid-pch -I. -include stdc++.h -H -g -O2 
hello.cc -o test.exe
 destroy, or modify vectors.
   
 
+
+_GLIBCXX_NO_FREESTANDING_CHRONO
+
+  
+   Undefined by default. When defined, the
+    header cannot
+   be used with -ffreestanding.
+   When not defined, durations, time points, and calendar types are
+   available for freestanding, but the standard clocks and the time zone
+   database are not (because they require OS support).
+  
+
 
 
   
diff --git a/libstdc++-v3/include/bits/chrono.h 
b/libstdc++-v3/include/bits/chrono.h
index 0773867da716..fd9c4642f4f2 100644
--- a/libstdc++-v3/include/bits/chrono.h
+++ b/libstdc++-v3/include/bits/chrono.h
@@ -37,7 +37,9 @@
 #include 
 #include 
 #include 
-#include 
+#if _GLIBCXX_HOSTED
+# include 
+#endif
 #include  // for literals support.
 #if __cplusplus >= 202002L
 # include 
@@ -50,7 +52,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
-#if __cplusplus >= 201703L
+#if __cplusplus >= 201703L && _GLIBCXX_HOSTED
   namespace filesystem { struct __file_clock; };
 #endif
 
@@ -372,7 +374,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   { };
 #endif // C++20
 
-#ifdef __glibcxx_chrono // C++ >= 17 && HOSTED
+#if __cplusplus >= 201703L // C++ >= 17
 /** Convert a `duration` to type `ToDur` and round down.
  *
  * If the duration cannot be represented exactly in the result type,
@@ -1196,6 +1198,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 /// @}
 /// @} group chrono
 
+#if _GLIBCXX_HOSTED
 // Clocks.
 
 // Why nanosecond resolution as the default?
@@ -1310,9 +1313,18 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
 template<> inline constexpr bool is_clock_v = true;
 /// @}
 #endif // C++20
+#elif __cplusplus >= 202002L
+// Define a fake clock like chrono::local_t so that sys_time etc.
+// can be used for freestanding.
+struct __sys_t;
+template
+  using sys_time = time_point<__sys_t, _Duration>;
+using sys_seconds = sys_time;
+using sys_days = sys_tim

[gcc r15-3050] libstdc++: Fix indentation of lines that follow a [[likely]] attribute

2024-08-20 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:91ae46853858a2aa4eb8640ce1a72124679a3909

commit r15-3050-g91ae46853858a2aa4eb8640ce1a72124679a3909
Author: Jonathan Wakely 
Date:   Mon Aug 19 16:56:28 2024 +0100

libstdc++: Fix indentation of lines that follow a [[likely]] attribute

libstdc++-v3/ChangeLog:

* include/std/text_encoding: Fix indentation.

Diff:
---
 libstdc++-v3/include/std/text_encoding | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/text_encoding 
b/libstdc++-v3/include/std/text_encoding
index 83d023bc71bd..49405a214d5f 100644
--- a/libstdc++-v3/include/std/text_encoding
+++ b/libstdc++-v3/include/std/text_encoding
@@ -518,7 +518,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 operator++()
 {
   if (_M_dereferenceable()) [[likely]]
-  ++_M_rep;
+   ++_M_rep;
   else
{
  __glibcxx_assert(_M_dereferenceable());
@@ -533,7 +533,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   const bool __decrementable
= _M_rep != nullptr && _M_rep[-1]._M_id == _M_id;
   if (__decrementable) [[likely]]
-  --_M_rep;
+   --_M_rep;
   else
{
  __glibcxx_assert(__decrementable);


[gcc r15-3124] libstdc++: Make std::vector::reference constructor private [PR115098]

2024-08-23 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:b25b101bc380004b82e25d2b1ef306856c75d864

commit r15-3124-gb25b101bc380004b82e25d2b1ef306856c75d864
Author: Jonathan Wakely 
Date:   Wed Aug 21 21:19:46 2024 +0100

libstdc++: Make std::vector::reference constructor private [PR115098]

The standard says this constructor should be private.  LWG 4141 proposes
to remove it entirely. We still need it, but it doesn't need to be
public.

For std::bitset the default constructor is already private (and never
even defined) but there's a non-standard constructor that's public, but
doesn't need to be.

libstdc++-v3/ChangeLog:

PR libstdc++/115098
* include/bits/stl_bvector.h (_Bit_reference): Make default
constructor private. Declare vector and bit iterators as
friends.
* include/std/bitset (bitset::reference): Make constructor and
data members private.
* testsuite/20_util/bitset/115098.cc: New test.
* testsuite/23_containers/vector/bool/115098.cc: New test.

Diff:
---
 libstdc++-v3/include/bits/stl_bvector.h| 12 +---
 libstdc++-v3/include/std/bitset|  5 +
 libstdc++-v3/testsuite/20_util/bitset/115098.cc| 11 +++
 libstdc++-v3/testsuite/23_containers/vector/bool/115098.cc |  8 
 4 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_bvector.h 
b/libstdc++-v3/include/bits/stl_bvector.h
index c45b7ff3320d..42261ac5915f 100644
--- a/libstdc++-v3/include/bits/stl_bvector.h
+++ b/libstdc++-v3/include/bits/stl_bvector.h
@@ -81,6 +81,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 
   struct _Bit_reference
   {
+  private:
+template friend class vector;
+friend struct _Bit_iterator;
+friend struct _Bit_const_iterator;
+
+_GLIBCXX20_CONSTEXPR
+_Bit_reference() _GLIBCXX_NOEXCEPT : _M_p(0), _M_mask(0) { }
+
 _Bit_type * _M_p;
 _Bit_type _M_mask;
 
@@ -88,9 +96,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 _Bit_reference(_Bit_type * __x, _Bit_type __y)
 : _M_p(__x), _M_mask(__y) { }
 
-_GLIBCXX20_CONSTEXPR
-_Bit_reference() _GLIBCXX_NOEXCEPT : _M_p(0), _M_mask(0) { }
-
+  public:
 #if __cplusplus >= 201103L
 _Bit_reference(const _Bit_reference&) = default;
 #endif
diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset
index e5d677ff059c..2e82a0e289d5 100644
--- a/libstdc++-v3/include/std/bitset
+++ b/libstdc++-v3/include/std/bitset
@@ -870,10 +870,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_WordT* _M_wp;
size_t  _M_bpos;
 
-   // left undefined
-   reference();
-
-  public:
_GLIBCXX23_CONSTEXPR
reference(bitset& __b, size_t __pos) _GLIBCXX_NOEXCEPT
{
@@ -881,6 +877,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
  _M_bpos = _Base::_S_whichbit(__pos);
}
 
+  public:
 #if __cplusplus >= 201103L
reference(const reference&) = default;
 #endif
diff --git a/libstdc++-v3/testsuite/20_util/bitset/115098.cc 
b/libstdc++-v3/testsuite/20_util/bitset/115098.cc
new file mode 100644
index ..52d6a0ec3781
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/bitset/115098.cc
@@ -0,0 +1,11 @@
+// { dg-do compile { target c++11 } }
+
+#include 
+
+using namespace std;
+
+static_assert( ! is_default_constructible::reference>::value,
+"std::bitset::reference is not default constructible");
+
+static_assert( ! is_constructible::reference, bitset<10>&, 
size_t>::value,
+"std::bitset::reference is not default constructible");
diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/115098.cc 
b/libstdc++-v3/testsuite/23_containers/vector/bool/115098.cc
new file mode 100644
index ..3df8b8017950
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/bool/115098.cc
@@ -0,0 +1,8 @@
+// { dg-do compile { target c++11 } }
+
+#include 
+
+static_assert(
+!std::is_default_constructible::reference>::value,
+"std::vector::reference is not default constructible"
+);


[gcc r15-3133] libstdc++: Optimize __try_use_facet for const types

2024-08-23 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:952e67c0d131300f263d729a0fe07bc3655dad27

commit r15-3133-g952e67c0d131300f263d729a0fe07bc3655dad27
Author: Jonathan Wakely 
Date:   Wed May 22 16:49:31 2024 +0100

libstdc++: Optimize __try_use_facet for const types

LWG 436 confirmed that const-qualified types are valid arguments for
Facet template parameters (but volatile-qualified types are not). Use the
fast path in std::use_facet and std::has_facet for const T as well as T.

libstdc++-v3/ChangeLog:

* include/bits/locale_classes.tcc (__try_use_facet): Also avoid
dynamic_cast for const-qualified facet types.

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

diff --git a/libstdc++-v3/include/bits/locale_classes.tcc 
b/libstdc++-v3/include/bits/locale_classes.tcc
index c79574e58de8..d5ef1911057b 100644
--- a/libstdc++-v3/include/bits/locale_classes.tcc
+++ b/libstdc++-v3/include/bits/locale_classes.tcc
@@ -110,7 +110,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // We know these standard facets are always installed in every locale
   // so dynamic_cast always succeeds, just use static_cast instead.
 #define _GLIBCXX_STD_FACET(...) \
-  if _GLIBCXX_CONSTEXPR (__is_same(_Facet, __VA_ARGS__)) \
+  if _GLIBCXX_CONSTEXPR (__is_same(const _Facet, const __VA_ARGS__)) \
return static_cast(__facets[__i])
 
   _GLIBCXX_STD_FACET(ctype);


[gcc r15-3132] libstdc++: Fix std::allocator_traits::construct constraints [PR108619]

2024-08-23 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:8cf51d7516b92b352c358c14ab4e456ae53c3371

commit r15-3132-g8cf51d7516b92b352c358c14ab4e456ae53c3371
Author: Jonathan Wakely 
Date:   Wed Jul 10 23:14:19 2024 +0100

libstdc++: Fix std::allocator_traits::construct constraints [PR108619]

Using std::is_constructible in the constraints introduces a spurious
dependency on the type being destructible, which should not be required
for constructing with an allocator. The test case shows a case where the
type has a private destructor, which can be destroyed by the allocator,
but std::is_destructible and std::is_constructible are false.

Similarly, using is_nothrow_constructible in the noexcept-specifiers
for the construct members of allocator_traits and std::allocator,
__gnu_cxx::__new_allocator, and __gnu_cxx::__malloc_allocator gives the
wrong answer if the type isn't destructible.
We need a new type trait to define those correctly, so that we only
check if the placement new-expression is nothrow after using
is_constructible to check that it would be well-formed.

Instead of just fixing the overly restrictive constraint to check for
placement new, rewrite allocator_traits in terms of 'if constexpr' using
variable templates and the detection idiom.

Although we can use 'if constexpr' and variable templates in C++11 with
appropriate uses of diagnostic pragmas, we can't have constexpr
functions with multiple return statements. This means that in C++11 mode
the _S_nothrow_construct and _S_nothrow_destroy helpers used for
noexcept-specifiers still need to be overlaods using enable_if. Nearly
everything else can be simplified to reduce overload resolution and
enable_if checks.

libstdc++-v3/ChangeLog:

PR libstdc++/108619
* include/bits/alloc_traits.h (__allocator_traits_base): Add
variable templates for detecting which allocator operations are
supported.
(allocator_traits): Use 'if constexpr' instead of dispatching to
overloads constrained with enable_if.
(allocator_traits>::construct): Use Construct if
construct_at is not supported. Use
__is_nothrow_new_constructible for noexcept-specifier.
(allocator_traits>::construct): Use
__is_nothrow_new_constructible for noexcept-specifier.
* include/bits/new_allocator.h (construct): Likewise.
* include/ext/malloc_allocator.h (construct): Likewise.
* include/std/type_traits (__is_nothrow_new_constructible): New
variable template.
* testsuite/20_util/allocator/89510.cc: Adjust expected results.
* testsuite/ext/malloc_allocator/89510.cc: Likewise.
* testsuite/ext/new_allocator/89510.cc: Likewise.
* testsuite/20_util/allocator_traits/members/108619.cc: New test.

Diff:
---
 libstdc++-v3/include/bits/alloc_traits.h   | 351 ++---
 libstdc++-v3/include/bits/new_allocator.h  |   2 +-
 libstdc++-v3/include/ext/malloc_allocator.h|   2 +-
 libstdc++-v3/include/std/type_traits   |  15 +
 libstdc++-v3/testsuite/20_util/allocator/89510.cc  |  14 +-
 .../20_util/allocator_traits/members/108619.cc |  35 ++
 .../testsuite/ext/malloc_allocator/89510.cc|  14 +-
 libstdc++-v3/testsuite/ext/new_allocator/89510.cc  |  14 +-
 8 files changed, 314 insertions(+), 133 deletions(-)

diff --git a/libstdc++-v3/include/bits/alloc_traits.h 
b/libstdc++-v3/include/bits/alloc_traits.h
index 82fc79c7b9f9..c2acc2ab2070 100644
--- a/libstdc++-v3/include/bits/alloc_traits.h
+++ b/libstdc++-v3/include/bits/alloc_traits.h
@@ -48,10 +48,19 @@ namespace std _GLIBCXX_VISIBILITY(default)
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #if __cplusplus >= 201103L
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wc++14-extensions" // for variable templates
+#pragma GCC diagnostic ignored "-Wc++17-extensions" // for if-constexpr
+
   /// @cond undocumented
   struct __allocator_traits_base
   {
+#if __cpp_concepts
+template
+#else
 template
+#endif
   struct __rebind : __replace_first_arg<_Tp, _Up>
   {
static_assert(is_same<
@@ -61,8 +70,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   };
 
 template
+#if __cpp_concepts
+  requires requires { typename _Tp::template rebind<_Up>::other; }
+  struct __rebind<_Tp, _Up>
+#else
   struct __rebind<_Tp, _Up,
  __void_t::other>>
+#endif
   {
using type = typename _Tp::template rebind<_Up>::other;
 
@@ -89,6 +103,135 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   using __pocs = typename _Tp::propagate_on_container_swap;
 template
   using __equal = __type_identity;
+
+// __has_allocate_hint is true if a.allocate(n, hint) is well-formed.
+#if __cpp_concepts
+template
+  static constexpr bool __has_allocate_hint
+ 

[gcc r15-3131] libstdc++: Only use std::time_put in std::format for non-C locales

2024-08-23 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:43b8153c26655a7a00f1584fcb4f511dc5e45fab

commit r15-3131-g43b8153c26655a7a00f1584fcb4f511dc5e45fab
Author: Jonathan Wakely 
Date:   Wed Jul 31 16:32:44 2024 +0100

libstdc++: Only use std::time_put in std::format for non-C locales

When testing on Solaris I noticed that std/time/year/io.cc was FAILing
because the year 1642 was being formatted as "+(" by %Ey. This turns out
to be because we defer to std::time_put for modified conversion specs,
and std::time_put uses std::strftime, and that's undefined for years
before 1970. In particular, years before 1900 mean that the tm_year
field is negative, which then causes incorrect results from strftime on
at least Solaris and AIX.

I've raised the general problem with LWG, but we can fix the FAILing
test case (and probably improve performance slightly) by ignoring the E
and O modifiers when the formatting locale is the "C" locale. The
modifiers have no effect for the C locale, so we can just treat %Ey as
%y and format it directly. This doesn't fix anything when the formatting
locale isn't the C locale, but that case is not adequately tested, so
doesn't cause any FAIL right now!

The naïve fix would be simply:

  if (__mod)
if (auto __loc = _M_locale(__ctx); __loc != locale::classic())
  // ...

However when the format string doesn't use the 'L' option, _M_locale
always returns locale::classic(). In that case, we make a copy of the
classic locale (which calls the non-inline copy constructor in
the library), then make another copy of the classic locale, then compare
the two. We can avoid all that by checking for the 'L' option first,
instead of letting _M_locale do that:

  if (__mod && _M_spec._M_localized)
if (auto __loc = __ctx.locale(); __loc != locale::classic())
  // ...

We could optimize this further if we had a __is_classic(__loc) function
that would do the __loc == locale::classic() check without making any
copies or non-inline calls. That would require examining the locale's
_M_impl member, and probably require checking its name, because the
locale::_S_classic singleton is not exported from the library.

For _M_S the change is slightly different from the other functions,
because if we skip using std::time_put for %OS then we fall through to
the code that potentially prints fractional seconds, but the %OS format
only prints whole seconds. So we need to format whole seconds directly
when not using std::time_put, instead of falling through to the code
below.

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h (__formatter_chrono::_M_C_y_Y):
Ignore modifiers unless the formatting locale is not the C
locale.
(__formatter_chrono::_M_d_e): Likewise.
(__formatter_chrono::_M_H_I): Likewise.
(__formatter_chrono::_M_m): Likewise.
(__formatter_chrono::_M_M): Likewise.
(__formatter_chrono::_M_S): Likewise.
(__formatter_chrono::_M_u_w): Likewise.
(__formatter_chrono::_M_U_V_W): Likewise.

Diff:
---
 libstdc++-v3/include/bits/chrono_io.h | 133 +++---
 1 file changed, 74 insertions(+), 59 deletions(-)

diff --git a/libstdc++-v3/include/bits/chrono_io.h 
b/libstdc++-v3/include/bits/chrono_io.h
index a449ffdc5583..38a0b002c81c 100644
--- a/libstdc++-v3/include/bits/chrono_io.h
+++ b/libstdc++-v3/include/bits/chrono_io.h
@@ -917,13 +917,14 @@ namespace __format
 
  chrono::year __y = _S_year(__t);
 
- if (__mod) [[unlikely]]
-   {
- struct tm __tm{};
- __tm.tm_year = (int)__y - 1900;
- return _M_locale_fmt(std::move(__out), _M_locale(__ctx), __tm,
-  __conv, __mod);
-   }
+ if (__mod && _M_spec._M_localized) [[unlikely]]
+   if (auto __loc = __ctx.locale(); __loc != locale::classic())
+ {
+   struct tm __tm{};
+   __tm.tm_year = (int)__y - 1900;
+   return _M_locale_fmt(std::move(__out), __loc, __tm,
+__conv, __mod);
+ }
 
  basic_string<_CharT> __s;
  int __yi = (int)__y;
@@ -985,13 +986,14 @@ namespace __format
  chrono::day __d = _S_day(__t);
  unsigned __i = (unsigned)__d;
 
- if (__mod) [[unlikely]]
-   {
- struct tm __tm{};
- __tm.tm_mday = __i;
- return _M_locale_fmt(std::move(__out), _M_locale(__ctx), __tm,
-  (char)__conv, 'O');
-   }
+ if (__mod && _M_spec._M_localized) [[unlikely]]
+   if (auto __loc = __ctx.locale(); __loc != locale::classic())
+ {
+   struct tm __tm{};
+   __tm.tm_mday = __i;
+  

[gcc r15-3134] libstdc++: Implement LWG 3746 for std::optional

2024-08-23 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:c429d509a86d61b21298b787948e24a9c97084e3

commit r15-3134-gc429d509a86d61b21298b787948e24a9c97084e3
Author: Jonathan Wakely 
Date:   Tue Jun 25 21:58:34 2024 +0100

libstdc++: Implement LWG 3746 for std::optional

This avoids constraint recursion in operator<=> for std::optional.
The resolution was approved in Kona 2022.

libstdc++-v3/ChangeLog:

* include/std/optional (__is_derived_from_optional): New
concept.
(operator<=>): Use __is_derived_from_optional.
* testsuite/20_util/optional/relops/lwg3746.cc: New test.

Diff:
---
 libstdc++-v3/include/std/optional| 12 ++--
 .../testsuite/20_util/optional/relops/lwg3746.cc | 20 
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/optional 
b/libstdc++-v3/include/std/optional
index 6651686cd1d0..933a5b15e569 100644
--- a/libstdc++-v3/include/std/optional
+++ b/libstdc++-v3/include/std/optional
@@ -1581,9 +1581,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 { return !__rhs; }
 #endif // three-way-comparison
 
+#if __cpp_lib_concepts
   // _GLIBCXX_RESOLVE_LIB_DEFECTS
   // 4072. std::optional comparisons: constrain harder
-#if __cpp_lib_concepts
 # define _REQUIRES_NOT_OPTIONAL(T) requires (!__is_optional_v)
 #else
 # define _REQUIRES_NOT_OPTIONAL(T)
@@ -1675,8 +1675,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 { return !__rhs || __lhs >= *__rhs; }
 
 #ifdef __cpp_lib_three_way_comparison
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 3746. optional's spaceship with U with a type derived from optional
+  // causes infinite constraint meta-recursion
+  template
+concept __is_derived_from_optional = requires (const _Tp& __t) {
+  [](const optional<_Up>&){ }(__t);
+};
+
   template
-requires (!__is_optional_v<_Up>)
+requires (!__is_derived_from_optional<_Up>)
   && three_way_comparable_with<_Up, _Tp>
 constexpr compare_three_way_result_t<_Tp, _Up>
 operator<=> [[nodiscard]] (const optional<_Tp>& __x, const _Up& __v)
diff --git a/libstdc++-v3/testsuite/20_util/optional/relops/lwg3746.cc 
b/libstdc++-v3/testsuite/20_util/optional/relops/lwg3746.cc
new file mode 100644
index ..46065f8e901d
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/optional/relops/lwg3746.cc
@@ -0,0 +1,20 @@
+// { dg-do compile { target c++20 } }
+
+// LWG 3746. optional's spaceship with U with a type derived from optional
+// causes infinite constraint meta-recursion
+
+#include 
+
+struct S : std::optional
+{
+bool operator==(const S&) const;
+bool operator<(const S&) const;
+bool operator>(const S&) const;
+bool operator<=(const S&) const;
+bool operator>=(const S&) const;
+};
+
+auto cmp(const S& s, const std::optional& o)
+{
+  return s <=> o;
+}


[gcc r15-3141] libstdc++: Hide std::tuple internals from Doxygen docs

2024-08-23 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:5cfee9360c90da8171e9f6bb71568bdc4c296e6e

commit r15-3141-g5cfee9360c90da8171e9f6bb71568bdc4c296e6e
Author: Jonathan Wakely 
Date:   Fri Aug 23 22:06:43 2024 +0100

libstdc++: Hide std::tuple internals from Doxygen docs

libstdc++-v3/ChangeLog:

* include/std/tuple: Do not include implementation details in
Doxygen documentation.

Diff:
---
 libstdc++-v3/include/std/tuple | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple
index 93b649e7d211..70cf4dba7b93 100644
--- a/libstdc++-v3/include/std/tuple
+++ b/libstdc++-v3/include/std/tuple
@@ -66,6 +66,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 class tuple;
 
+  /// @cond undocumented
   template
 struct __is_empty_non_tuple : is_empty<_Tp> { };
 
@@ -823,6 +824,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static constexpr bool __is_explicitly_constructible()
{ return false; }
 };
+  /// @endcond
 
   /// Primary class template, tuple
   template


[gcc r15-3216] c++: Add correct copyright dates to output of gen-cxxapi-file.py

2024-08-27 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:ff4aa45535bc0103e4417e72386089a5421fe520

commit r15-3216-gff4aa45535bc0103e4417e72386089a5421fe520
Author: Jonathan Wakely 
Date:   Tue Aug 27 12:17:03 2024 +0100

c++: Add correct copyright dates to output of gen-cxxapi-file.py

This ensures the generated output says something like 2022-2024 rather
than just 2024.

gcc/cp/ChangeLog:

* gen-cxxapi-file.py: Fix copyright dates in generated output.

Diff:
---
 gcc/cp/gen-cxxapi-file.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/cp/gen-cxxapi-file.py b/gcc/cp/gen-cxxapi-file.py
index 31ed5b16ce45..6d08f46069bb 100644
--- a/gcc/cp/gen-cxxapi-file.py
+++ b/gcc/cp/gen-cxxapi-file.py
@@ -95,7 +95,7 @@ def hints(script, content):
 %struct-type
 %{{
 /* This file is auto-generated by {:s}.  */
-/* Copyright (C) {:s} Free Software Foundation, Inc.
+/* Copyright (C) 2022-{:s} Free Software Foundation, Inc.
 
 This file is part of GCC.


[gcc r15-3217] c++: Add most missing C++20 and C++23 names to cxxapi-data.csv

2024-08-27 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:470a27859d8a47a99f389f1dc6edb82c08b16e21

commit r15-3217-g470a27859d8a47a99f389f1dc6edb82c08b16e21
Author: Jonathan Wakely 
Date:   Tue Aug 27 12:19:47 2024 +0100

c++: Add most missing C++20 and C++23 names to cxxapi-data.csv

This includes uncommenting the atomic_flag non-member functions, which
were added by PR libstdc++/103934.

Also generate a hint for std::ignore, which was recently tweaked to be
more generally useful by P2968R2, which r15-2324 implemented.

gcc/cp/ChangeLog:

* cxxapi-data.csv: Add C++20 and C++23 names from ,
, , , , and .
Set cxx11 dialect for std::ignore in . Uncomment
atomic_flag functions from .
* std-name-hint.gperf: Regenerate.
* std-name-hint.h: Regenerate.

Diff:
---
 gcc/cp/cxxapi-data.csv |   96 ++-
 gcc/cp/std-name-hint.gperf |   82 ++
 gcc/cp/std-name-hint.h | 2029 
 3 files changed, 1295 insertions(+), 912 deletions(-)

diff --git a/gcc/cp/cxxapi-data.csv b/gcc/cp/cxxapi-data.csv
index 1cbf774acd7c..bd397fb2acb8 100644
--- a/gcc/cp/cxxapi-data.csv
+++ b/gcc/cp/cxxapi-data.csv
@@ -197,16 +197,16 @@
 ,atomic_uintmax_t,1,cxx20
 
,atomic_signed_lock_free,1,cxx11,__cpp_lib_atomic_lock_free_type_aliases
 
,atomic_unsigned_lock_free,1,cxx11,__cpp_lib_atomic_lock_free_type_aliases
-# libstdc++/103934 ,atomic_flag_test,1,no
-# libstdc++/103934 ,atomic_flag_test_explicit,1,no
+,atomic_flag_test,1,no
+,atomic_flag_test_explicit,1,no
 ,atomic_flag_test_and_set,1,no
 ,atomic_flag_test_and_set_explicit,1,no
 ,atomic_flag_clear,1,no
 ,atomic_flag_clear_explicit,1,no
-# libstdc++/103934 ,atomic_flag_wait,1,no
-# libstdc++/103934 ,atomic_flag_wait_explicit,1,no
-# libstdc++/103934 ,atomic_flag_notify_one,1,no
-# libstdc++/103934 ,atomic_flag_notify_all,1,no
+,atomic_flag_wait,1,no
+,atomic_flag_wait_explicit,1,no
+,atomic_flag_notify_one,1,no
+,atomic_flag_notify_all,1,no
 ,atomic_thread_fence,1,no
 ,atomic_signal_fence,1,no
 ,barrier,1,no
@@ -238,7 +238,48 @@
 ,to_chars,1,no
 ,from_chars_result,1,no
 ,from_chars,1,no
-#  TODO
+,chrono::duration,1,cxx11
+,chrono::nanoseconds,1,cxx11
+,chrono::microseconds,1,cxx11
+,chrono::milliseconds,1,cxx11
+,chrono::seconds,1,cxx11
+,chrono::minutes,1,cxx11
+,chrono::hours,1,cxx11
+,chrono::days,1,cxx20
+,chrono::weeks,1,cxx20
+,chrono::months,1,cxx20
+,chrono::years,1,cxx20
+,chrono::duration_cast,1,cxx11
+,chrono::time_point,1,cxx11
+,chrono::time_point_cast,1,cxx11
+,chrono::system_clock,1,cxx11
+,chrono::steady_clock,1,cxx11
+,chrono::high_resolution_clock,1,cxx11
+,chrono::utc_clock,1,cxx20
+,chrono::tai_clock,1,cxx20
+,chrono::gps_clock,1,cxx20
+,chrono::file_clock,1,cxx20
+,chrono::local_t,1,cxx20
+,chrono::clock_cast,1,cxx20
+,chrono::time_zone,1,cxx20
+,chrono::zoned_time,1,cxx20
+,chrono::tzdb,1,cxx20
+,chrono::tzdb_list,1,cxx20
+,chrono::get_tzdb,1,cxx20
+,chrono::get_tzdb_list,1,cxx20
+,chrono::reload_tzdb,1,cxx20
+,chrono::remote_version,1,cxx20
+,chrono::locate_zone,1,cxx20
+,chrono::leap_second,1,cxx20
+,chrono::leap_second_info,1,cxx20
+,chrono::get_leap_second_info,1,cxx20
+# c++/106851 ,chrono::abs,1,cxx17
+# c++/106851 ,chrono::floor,1,cxx17
+# c++/106851 ,chrono::ceil,1,cxx17
+,chrono::round,1,cxx17
+,chrono::from_stream,1,cxx20
+,chrono::parse,1,cxx20
+#  TODO the rest
 #  TODO
 ,weak_equality,1,cxx20
 ,strong_equality,1,cxx20
@@ -311,6 +352,33 @@
 # ,sorted_equivalent,1,no
 # ,erase_if,1,no
 # ,uses_allocator,1,no
+,format,1,cxx20
+,format_to,1,cxx20
+,format_to_n,1,cxx20
+,formatted_size,1,cxx20
+,vformat,1,cxx20
+,vformat_to,1,cxx20
+,formatter,1,cxx20
+,range_formatter,1,cxx23
+,range_format,1,cxx23
+,formattable,1,cxx23
+,format_error,1,cxx20
+,basic_format_parse_context,1,cxx20
+,format_parse_context,1,cxx20
+,wformat_parse_context,1,cxx20
+,basic_format_context,1,cxx20
+,format_context,1,cxx20
+,wformat_context,1,cxx20
+,basic_format_string,1,cxx20
+,format_string,1,cxx20
+,wformat_string,1,cxx20
+,basic_format_arg,1,cxx20
+,basic_format_args,1,cxx20
+,format_args,1,cxx20
+,wformat_args,1,cxx20
+,make_format_args,1,cxx20
+,make_wformat_args,1,cxx20
+,runtime_format,1,cxx26
 ,forward_list,1,cxx11
 ,operator==,1,no
 ,operator<=>,1,no
@@ -361,6 +429,8 @@
 ,shared_future,1,no
 ,packaged_task,1,cxx11
 ,async,1,cxx11
+,generator,1,cxx23
+# c++/106851 ,pmr::generator,1,no
 ,initializer_list,1,no
 ,begin,1,no
 ,end,1,no
@@ -433,6 +503,9 @@
 ,ostreambuf_iterator,1,cxx98
 ,prev,1,cxx11
 ,reverse_iterator,1,cxx98
+,common_iterator,1,cxx20
+,counted_iterator,1,cxx20
+,const_iterator,1,cxx23
 #  TODO the rest
 ,latch,1,no
 ,list,1,cxx98
@@ -590,6 +663,8 @@
 ,flush_emit,1,cxx20
 ,operator<<,1,no
 #  TODO
+,print,1,cxx23
+,println,1,cxx23
 ,queue,1,cxx98
 ,operator==,1,no
 ,operator!=,1,no
@@ -720,6 +795,11 @@
 ,range_error,1,cxx98
 ,overflow_error,1,cxx98
 ,underflow_error,1,cxx98
+,float16_t,1,cxx23
+,float32_t,1,cxx23
+,float64_t,1,cxx23
+,float128_

[gcc r15-3265] libstdc++: Fix @headername for bits/cpp_type_traits.h

2024-08-28 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:f6ed7a61a7c906f8fb7f8059132225c9bc41f3b2

commit r15-3265-gf6ed7a61a7c906f8fb7f8059132225c9bc41f3b2
Author: Kim Gräsman 
Date:   Tue Aug 27 17:08:47 2024 +0100

libstdc++: Fix @headername for bits/cpp_type_traits.h

There is no file ext/type_traits, point it to ext/type_traits.h instead.

libstdc++-v3/ChangeLog:

* include/bits/cpp_type_traits.h: Improve doxygen file docs.

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

diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h 
b/libstdc++-v3/include/bits/cpp_type_traits.h
index 4bfb4521e064..ff74c5572458 100644
--- a/libstdc++-v3/include/bits/cpp_type_traits.h
+++ b/libstdc++-v3/include/bits/cpp_type_traits.h
@@ -24,7 +24,7 @@
 
 /** @file bits/cpp_type_traits.h
  *  This is an internal header file, included by other library headers.
- *  Do not attempt to use it directly. @headername{ext/type_traits}
+ *  Do not attempt to use it directly. @headername{ext/type_traits.h}
  */
 
 // Written by Gabriel Dos Reis 


[gcc r15-3267] doc: Add Dhruv Matani to Contributors

2024-08-28 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:9740a1b0dc10c93f325fb17dacea7d123bc0cdd2

commit r15-3267-g9740a1b0dc10c93f325fb17dacea7d123bc0cdd2
Author: Jonathan Wakely 
Date:   Wed Aug 28 11:49:46 2024 +0100

doc: Add Dhruv Matani to Contributors

gcc/ChangeLog:

* doc/contrib.texi (Contributors): Add Dhruv Matani.

Diff:
---
 gcc/doc/contrib.texi | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/doc/contrib.texi b/gcc/doc/contrib.texi
index 32e89d6df25c..7714d52823b1 100644
--- a/gcc/doc/contrib.texi
+++ b/gcc/doc/contrib.texi
@@ -645,6 +645,9 @@ John Marino for contributing the DragonFly BSD port.
 Philip Martin for lots of libstdc++ string and vector iterator fixes and
 improvements, and string clean up and testsuites.
 
+@item
+Dhruv Matani for work on libstdc++ allocators.
+
 @item
 Michael Matz for his work on dominance tree discovery, the x86-64 port,
 link-time optimization framework and general optimization improvements.


[gcc r15-3418] libstdc++: Add missing feature-test macro in various headers

2024-09-03 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:efe6efb6f315c7f97be8a850e0a84ff7f6651d85

commit r15-3418-gefe6efb6f315c7f97be8a850e0a84ff7f6651d85
Author: Dhruv Chawla 
Date:   Mon Aug 26 11:09:19 2024 +0530

libstdc++: Add missing feature-test macro in various headers

version.syn#2 requires various headers to define
__cpp_lib_allocator_traits_is_always_equal. Currently, only  was
defining this macro. Implement fixes for the other headers as well.

Signed-off-by: Dhruv Chawla 

libstdc++-v3/ChangeLog:

* include/std/deque: Define macro
__glibcxx_want_allocator_traits_is_always_equal.
* include/std/forward_list: Likewise.
* include/std/list: Likewise.
* include/std/map: Likewise.
* include/std/scoped_allocator: Likewise.
* include/std/set: Likewise.
* include/std/string: Likewise.
* include/std/unordered_map: Likewise.
* include/std/unordered_set: Likewise.
* include/std/vector: Likewise.
* testsuite/20_util/headers/memory/version.cc: New test.
* testsuite/20_util/scoped_allocator/version.cc: Likewise.
* testsuite/21_strings/headers/string/version.cc: Likewise.
* testsuite/23_containers/deque/version.cc: Likewise.
* testsuite/23_containers/forward_list/version.cc: Likewise.
* testsuite/23_containers/list/version.cc: Likewise.
* testsuite/23_containers/map/version.cc: Likewise.
* testsuite/23_containers/set/version.cc: Likewise.
* testsuite/23_containers/unordered_map/version.cc: Likewise.
* testsuite/23_containers/unordered_set/version.cc: Likewise.
* testsuite/23_containers/vector/version.cc: Likewise.

Diff:
---
 libstdc++-v3/include/std/deque| 1 +
 libstdc++-v3/include/std/forward_list | 1 +
 libstdc++-v3/include/std/list | 1 +
 libstdc++-v3/include/std/map  | 1 +
 libstdc++-v3/include/std/scoped_allocator | 3 +++
 libstdc++-v3/include/std/set  | 1 +
 libstdc++-v3/include/std/string   | 1 +
 libstdc++-v3/include/std/unordered_map| 1 +
 libstdc++-v3/include/std/unordered_set| 1 +
 libstdc++-v3/include/std/vector   | 1 +
 libstdc++-v3/testsuite/20_util/headers/memory/version.cc  | 8 
 libstdc++-v3/testsuite/20_util/scoped_allocator/version.cc| 8 
 libstdc++-v3/testsuite/21_strings/headers/string/version.cc   | 8 
 libstdc++-v3/testsuite/23_containers/deque/version.cc | 8 
 libstdc++-v3/testsuite/23_containers/forward_list/version.cc  | 8 
 libstdc++-v3/testsuite/23_containers/list/version.cc  | 8 
 libstdc++-v3/testsuite/23_containers/map/version.cc   | 8 
 libstdc++-v3/testsuite/23_containers/set/version.cc   | 8 
 libstdc++-v3/testsuite/23_containers/unordered_map/version.cc | 8 
 libstdc++-v3/testsuite/23_containers/unordered_set/version.cc | 8 
 libstdc++-v3/testsuite/23_containers/vector/version.cc| 8 
 21 files changed, 100 insertions(+)

diff --git a/libstdc++-v3/include/std/deque b/libstdc++-v3/include/std/deque
index 0bf8309c19a7..69f8c0dcdccf 100644
--- a/libstdc++-v3/include/std/deque
+++ b/libstdc++-v3/include/std/deque
@@ -68,6 +68,7 @@
 #include 
 #include 
 
+#define __glibcxx_want_allocator_traits_is_always_equal
 #define __glibcxx_want_erase_if
 #define __glibcxx_want_nonmember_container_access
 #include 
diff --git a/libstdc++-v3/include/std/forward_list 
b/libstdc++-v3/include/std/forward_list
index 5ac74360808d..dfd7d48d1219 100644
--- a/libstdc++-v3/include/std/forward_list
+++ b/libstdc++-v3/include/std/forward_list
@@ -45,6 +45,7 @@
 # include 
 #endif
 
+#define __glibcxx_want_allocator_traits_is_always_equal
 #define __glibcxx_want_erase_if
 #define __glibcxx_want_incomplete_container_elements
 #define __glibcxx_want_list_remove_return_type
diff --git a/libstdc++-v3/include/std/list b/libstdc++-v3/include/std/list
index fce4e3d925b1..ff632fc1ab2f 100644
--- a/libstdc++-v3/include/std/list
+++ b/libstdc++-v3/include/std/list
@@ -69,6 +69,7 @@
 # include 
 #endif
 
+#define __glibcxx_want_allocator_traits_is_always_equal
 #define __glibcxx_want_erase_if
 #define __glibcxx_want_incomplete_container_elements
 #define __glibcxx_want_list_remove_return_type
diff --git a/libstdc++-v3/include/std/map b/libstdc++-v3/include/std/map
index 4a96e59a5bc1..6520d9f744fe 100644
--- a/libstdc++-v3/include/std/map
+++ b/libstdc++-v3/include/std/map
@@ -69,6 +69,7 @@
 # include 
 #endif
 
+#define __glibcxx_want_allocator_traits_is_always_equal
 #define __glibcxx_want_erase_if
 #define __glibcxx_want_generic_associative_l

[gcc r15-3423] libstdc++: Specialize std::disable_sized_sentinel_for for std::move_iterator [PR116549]

2024-09-03 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:819deae0a5bee079a7d5582fafaa098c26144ae8

commit r15-3423-g819deae0a5bee079a7d5582fafaa098c26144ae8
Author: Jonathan Wakely 
Date:   Mon Sep 2 11:29:13 2024 +0100

libstdc++: Specialize std::disable_sized_sentinel_for for 
std::move_iterator [PR116549]

LWG 3736 added a partial specialization of this variable template for
two std::move_iterator types. This is needed for the case where the
types satisfy std::sentinel_for and are subtractable, but do not model
the semantics requirements of std::sized_sentinel_for.

libstdc++-v3/ChangeLog:

PR libstdc++/116549
* include/bits/stl_iterator.h (disable_sized_sentinel_for):
Define specialization for two move_iterator types, as per LWG
3736.
* testsuite/24_iterators/move_iterator/lwg3736.cc: New test.

Diff:
---
 libstdc++-v3/include/bits/stl_iterator.h   |  8 
 .../24_iterators/move_iterator/lwg3736.cc  | 52 ++
 2 files changed, 60 insertions(+)

diff --git a/libstdc++-v3/include/bits/stl_iterator.h 
b/libstdc++-v3/include/bits/stl_iterator.h
index d38230572709..20c0319f3a7a 100644
--- a/libstdc++-v3/include/bits/stl_iterator.h
+++ b/libstdc++-v3/include/bits/stl_iterator.h
@@ -1822,6 +1822,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 { return _ReturnType(__i); }
 
 #if __cplusplus > 201703L && __glibcxx_concepts
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 3736.  move_iterator missing disable_sized_sentinel_for specialization
+  template
+requires (!sized_sentinel_for<_Iterator1, _Iterator2>)
+inline constexpr bool
+disable_sized_sentinel_for,
+  move_iterator<_Iterator2>> = true;
+
   // [iterators.common] Common iterators
 
   namespace __detail
diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3736.cc 
b/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3736.cc
new file mode 100644
index ..eaf791b30893
--- /dev/null
+++ b/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3736.cc
@@ -0,0 +1,52 @@
+// { dg-do compile { target c++20 } }
+
+// 3736.  move_iterator missing disable_sized_sentinel_for specialization
+
+#include 
+
+template using MoveIter = std::move_iterator;
+
+using std::sized_sentinel_for;
+using std::disable_sized_sentinel_for;
+
+// These assertions always passed, even without LWG 3736:
+static_assert(sized_sentinel_for, MoveIter>);
+static_assert(sized_sentinel_for, MoveIter>);
+static_assert(not sized_sentinel_for, MoveIter>);
+static_assert(not sized_sentinel_for, std::default_sentinel_t>);
+static_assert(not disable_sized_sentinel_for, MoveIter>);
+
+// These types don't satisfy sized_sentinel_for anyway (because the subtraction
+// is ill-formed) but LWG 3736 makes the variable template explicitly false:
+static_assert(disable_sized_sentinel_for, MoveIter>);
+
+struct Iter
+{
+  using iterator_category = std::random_access_iterator_tag;
+  using value_type = int;
+  using pointer = int*;
+  using reference = int&;
+  using difference_type = long;
+
+  Iter() = default;
+  Iter& operator++();
+  Iter operator++(int);
+  Iter& operator--();
+  Iter operator--(int);
+  reference operator*() const;
+  pointer operator->() const;
+  Iter& operator+=(difference_type);
+  Iter& operator-=(difference_type);
+  friend Iter operator+(Iter, difference_type);
+  friend Iter operator+(difference_type, Iter);
+  friend Iter operator-(Iter, difference_type);
+  friend difference_type operator-(Iter, Iter);
+  bool operator==(Iter) const;
+};
+
+// Specialize the variable template so that Iter is not its own sized sentinel:
+template<> constexpr bool std::disable_sized_sentinel_for = true;
+static_assert( not sized_sentinel_for );
+
+// LWG 3736 means that affects std::move_iterator as well:
+static_assert( not sized_sentinel_for, MoveIter> );


[gcc r15-3424] libstdc++: Fix error handling in fs::hard_link_count for Windows

2024-09-03 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:71b1639c67b91554420cc38eb4c82323e535c816

commit r15-3424-g71b1639c67b91554420cc38eb4c82323e535c816
Author: Jonathan Wakely 
Date:   Mon Sep 2 12:16:49 2024 +0100

libstdc++: Fix error handling in fs::hard_link_count for Windows

The recent change to use auto_win_file_handle for
std::filesystem::hard_link_count caused a regression. The
std::error_code argument should be cleared if no error occurs, but this
no longer happens. Add a call to ec.clear() in fs::hard_link_count to
fix this.

Also change the auto_win_file_handle class to take a reference to the
std::error_code and set it if an error occurs, to slightly simplify the
control flow in the fs::equiv_files function.

libstdc++-v3/ChangeLog:

* src/c++17/fs_ops.cc (auto_win_file_handle): Add error_code&
member and set it if CreateFileW or GetFileInformationByHandle
fails.
(fs::equiv_files) [_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Simplify
control flow.
(fs::hard_link_count) [_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Clear ec
on success.
* testsuite/27_io/filesystem/operations/hard_link_count.cc:
Check error handling.

Diff:
---
 libstdc++-v3/src/c++17/fs_ops.cc   | 59 --
 .../27_io/filesystem/operations/hard_link_count.cc | 24 +
 2 files changed, 57 insertions(+), 26 deletions(-)

diff --git a/libstdc++-v3/src/c++17/fs_ops.cc b/libstdc++-v3/src/c++17/fs_ops.cc
index 9606afa9f1f7..946fefd9e449 100644
--- a/libstdc++-v3/src/c++17/fs_ops.cc
+++ b/libstdc++-v3/src/c++17/fs_ops.cc
@@ -829,23 +829,37 @@ namespace
   struct auto_win_file_handle
   {
 explicit
-auto_win_file_handle(const wchar_t* p)
+auto_win_file_handle(const wchar_t* p, std::error_code& ec) noexcept
 : handle(CreateFileW(p, 0,
 FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
-0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0))
-{ }
+0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0)),
+  ec(ec)
+{
+  if (handle == INVALID_HANDLE_VALUE)
+   ec = std::__last_system_error();
+}
 
 ~auto_win_file_handle()
 { if (*this) CloseHandle(handle); }
 
-explicit operator bool() const
+explicit operator bool() const noexcept
 { return handle != INVALID_HANDLE_VALUE; }
 
-bool get_info()
-{ return GetFileInformationByHandle(handle, &info); }
+bool get_info() noexcept
+{
+  if (GetFileInformationByHandle(handle, &info))
+   return true;
+  ec = std::__last_system_error();
+  return false;
+}
 
 HANDLE handle;
 BY_HANDLE_FILE_INFORMATION info;
+// Like errno, we only set this on error and never clear it.
+// This propagates an error_code to the caller when something goes wrong,
+// but the caller should not assume a non-zero ec means an error happened
+// unless they explicitly cleared it before passing it to our constructor.
+std::error_code& ec;
   };
 }
 #endif
@@ -866,23 +880,14 @@ fs::equiv_files([[maybe_unused]] const char_type* p1, 
const stat_type& st1,
   if (st1.st_mode != st2.st_mode || st1.st_dev != st2.st_dev)
 return false;
 
-  // Need to use GetFileInformationByHandle to get more info about the files.
-  auto_win_file_handle h1(p1);
-  auto_win_file_handle h2(p2);
-  if (!h1 || !h2)
-{
-  if (!h1 && !h2)
-   ec = __last_system_error();
-  return false;
-}
-  if (!h1.get_info() || !h2.get_info())
-{
-  ec = __last_system_error();
-  return false;
-}
-  return h1.info.dwVolumeSerialNumber == h2.info.dwVolumeSerialNumber
-  && h1.info.nFileIndexHigh == h2.info.nFileIndexHigh
-  && h1.info.nFileIndexLow == h2.info.nFileIndexLow;
+  // Use GetFileInformationByHandle to get more info about the files.
+  if (auto_win_file_handle h1{p1, ec})
+if (auto_win_file_handle h2{p2, ec})
+  if (h1.get_info() && h2.get_info())
+   return h1.info.dwVolumeSerialNumber == h2.info.dwVolumeSerialNumber
+&& h1.info.nFileIndexHigh == h2.info.nFileIndexHigh
+&& h1.info.nFileIndexLow == h2.info.nFileIndexLow;
+  return false;
 #endif // _GLIBCXX_FILESYSTEM_IS_WINDOWS
 }
 #endif // NEED_DO_COPY_FILE
@@ -1007,10 +1012,12 @@ std::uintmax_t
 fs::hard_link_count(const path& p, error_code& ec) noexcept
 {
 #if _GLIBCXX_FILESYSTEM_IS_WINDOWS
-  auto_win_file_handle h(p.c_str());
+  auto_win_file_handle h(p.c_str(), ec);
   if (h && h.get_info())
-return static_cast(h.info.nNumberOfLinks);
-  ec = __last_system_error();
+{
+  ec.clear();
+  return static_cast(h.info.nNumberOfLinks);
+}
   return static_cast(-1);
 #elif defined _GLIBCXX_HAVE_SYS_STAT_H
   return do_stat(p, ec, std::mem_fn(&stat_type::st_nlink),
diff --git 
a/libstdc++-v3/testsuite/27_io/filesystem/operations/hard_link_count.cc 
b/libstdc+

[gcc r14-10636] libstdc++: Fix std::variant to reject array types [PR116381]

2024-09-04 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:3b8a67b0cfc072f027eab24fb72d48d10cc890b4

commit r14-10636-g3b8a67b0cfc072f027eab24fb72d48d10cc890b4
Author: Jonathan Wakely 
Date:   Tue Aug 20 16:52:22 2024 +0100

libstdc++: Fix std::variant to reject array types [PR116381]

For the backport, rejecting array types is only done in strict modes.

libstdc++-v3/ChangeLog:

PR libstdc++/116381
* include/std/variant (variant): Fix conditions for
static_assert to match the spec.
* testsuite/20_util/variant/types_neg.cc: New test.

(cherry picked from commit 1e10b3b8825ee398f077500af6ae1f5db180983a)

Diff:
---
 libstdc++-v3/include/std/variant| 11 +++
 libstdc++-v3/testsuite/20_util/variant/types_neg.cc | 18 ++
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 4e56134a6f7..834bb548f13 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -1374,10 +1374,13 @@ namespace __variant
 
   static_assert(sizeof...(_Types) > 0,
"variant must have at least one alternative");
-  static_assert(!(std::is_reference_v<_Types> || ...),
-   "variant must have no reference alternative");
-  static_assert(!(std::is_void_v<_Types> || ...),
-   "variant must have no void alternative");
+#ifdef __STRICT_ANSI__
+  static_assert(((std::is_object_v<_Types> && !is_array_v<_Types>) && ...),
+   "variant alternatives must be non-array object types");
+#else
+  static_assert((std::is_object_v<_Types> && ...),
+   "variant alternatives must be object types");
+#endif
 
   using _Base = __detail::__variant::_Variant_base<_Types...>;
 
diff --git a/libstdc++-v3/testsuite/20_util/variant/types_neg.cc 
b/libstdc++-v3/testsuite/20_util/variant/types_neg.cc
new file mode 100644
index 000..7d970e961c2
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/variant/types_neg.cc
@@ -0,0 +1,18 @@
+// { dg-do compile { target c++17 } }
+// { dg-add-options strict_std }
+
+# include 
+
+std::variant<> v0; // { dg-error "here" }
+// { dg-error "must have at least one alternative" "" { target *-*-* } 0 }
+std::variant v1; // { dg-error "here" }
+std::variant v2; // { dg-error "here" }
+std::variant v3; // { dg-error "here" }
+std::variant v4; // { dg-error "here" }
+std::variant v5; // { dg-error "here" }
+std::variant v6; // { dg-error "here" }
+// { dg-error "must be non-array object types" "" { target *-*-* } 0 }
+
+// All of variant's base classes are instantiated before checking any
+// static_assert, so we get lots of errors before the expected errors above.
+// { dg-excess-errors "" }


[gcc r14-10638] libstdc++: Specialize std::disable_sized_sentinel_for for std::move_iterator [PR116549]

2024-09-04 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:ee37d750262579a81799c5b56fe1ab936a840120

commit r14-10638-gee37d750262579a81799c5b56fe1ab936a840120
Author: Jonathan Wakely 
Date:   Mon Sep 2 11:29:13 2024 +0100

libstdc++: Specialize std::disable_sized_sentinel_for for 
std::move_iterator [PR116549]

LWG 3736 added a partial specialization of this variable template for
two std::move_iterator types. This is needed for the case where the
types satisfy std::sentinel_for and are subtractable, but do not model
the semantics requirements of std::sized_sentinel_for.

libstdc++-v3/ChangeLog:

PR libstdc++/116549
* include/bits/stl_iterator.h (disable_sized_sentinel_for):
Define specialization for two move_iterator types, as per LWG
3736.
* testsuite/24_iterators/move_iterator/lwg3736.cc: New test.

(cherry picked from commit 819deae0a5bee079a7d5582fafaa098c26144ae8)

Diff:
---
 libstdc++-v3/include/bits/stl_iterator.h   |  8 
 .../24_iterators/move_iterator/lwg3736.cc  | 52 ++
 2 files changed, 60 insertions(+)

diff --git a/libstdc++-v3/include/bits/stl_iterator.h 
b/libstdc++-v3/include/bits/stl_iterator.h
index d3823057270..20c0319f3a7 100644
--- a/libstdc++-v3/include/bits/stl_iterator.h
+++ b/libstdc++-v3/include/bits/stl_iterator.h
@@ -1822,6 +1822,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 { return _ReturnType(__i); }
 
 #if __cplusplus > 201703L && __glibcxx_concepts
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 3736.  move_iterator missing disable_sized_sentinel_for specialization
+  template
+requires (!sized_sentinel_for<_Iterator1, _Iterator2>)
+inline constexpr bool
+disable_sized_sentinel_for,
+  move_iterator<_Iterator2>> = true;
+
   // [iterators.common] Common iterators
 
   namespace __detail
diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3736.cc 
b/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3736.cc
new file mode 100644
index 000..eaf791b3089
--- /dev/null
+++ b/libstdc++-v3/testsuite/24_iterators/move_iterator/lwg3736.cc
@@ -0,0 +1,52 @@
+// { dg-do compile { target c++20 } }
+
+// 3736.  move_iterator missing disable_sized_sentinel_for specialization
+
+#include 
+
+template using MoveIter = std::move_iterator;
+
+using std::sized_sentinel_for;
+using std::disable_sized_sentinel_for;
+
+// These assertions always passed, even without LWG 3736:
+static_assert(sized_sentinel_for, MoveIter>);
+static_assert(sized_sentinel_for, MoveIter>);
+static_assert(not sized_sentinel_for, MoveIter>);
+static_assert(not sized_sentinel_for, std::default_sentinel_t>);
+static_assert(not disable_sized_sentinel_for, MoveIter>);
+
+// These types don't satisfy sized_sentinel_for anyway (because the subtraction
+// is ill-formed) but LWG 3736 makes the variable template explicitly false:
+static_assert(disable_sized_sentinel_for, MoveIter>);
+
+struct Iter
+{
+  using iterator_category = std::random_access_iterator_tag;
+  using value_type = int;
+  using pointer = int*;
+  using reference = int&;
+  using difference_type = long;
+
+  Iter() = default;
+  Iter& operator++();
+  Iter operator++(int);
+  Iter& operator--();
+  Iter operator--(int);
+  reference operator*() const;
+  pointer operator->() const;
+  Iter& operator+=(difference_type);
+  Iter& operator-=(difference_type);
+  friend Iter operator+(Iter, difference_type);
+  friend Iter operator+(difference_type, Iter);
+  friend Iter operator-(Iter, difference_type);
+  friend difference_type operator-(Iter, Iter);
+  bool operator==(Iter) const;
+};
+
+// Specialize the variable template so that Iter is not its own sized sentinel:
+template<> constexpr bool std::disable_sized_sentinel_for = true;
+static_assert( not sized_sentinel_for );
+
+// LWG 3736 means that affects std::move_iterator as well:
+static_assert( not sized_sentinel_for, MoveIter> );


[gcc r14-10637] libstdc++: Add missing feature-test macro in various headers

2024-09-04 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:469602619d32c24382c6f1c3e3d95c3db606c770

commit r14-10637-g469602619d32c24382c6f1c3e3d95c3db606c770
Author: Dhruv Chawla 
Date:   Mon Aug 26 11:09:19 2024 +0530

libstdc++: Add missing feature-test macro in various headers

version.syn#2 requires various headers to define
__cpp_lib_allocator_traits_is_always_equal. Currently, only  was
defining this macro. Implement fixes for the other headers as well.

Signed-off-by: Dhruv Chawla 

libstdc++-v3/ChangeLog:

* include/std/deque: Define macro
__glibcxx_want_allocator_traits_is_always_equal.
* include/std/forward_list: Likewise.
* include/std/list: Likewise.
* include/std/map: Likewise.
* include/std/scoped_allocator: Likewise.
* include/std/set: Likewise.
* include/std/string: Likewise.
* include/std/unordered_map: Likewise.
* include/std/unordered_set: Likewise.
* include/std/vector: Likewise.
* testsuite/20_util/headers/memory/version.cc: New test.
* testsuite/20_util/scoped_allocator/version.cc: Likewise.
* testsuite/21_strings/headers/string/version.cc: Likewise.
* testsuite/23_containers/deque/version.cc: Likewise.
* testsuite/23_containers/forward_list/version.cc: Likewise.
* testsuite/23_containers/list/version.cc: Likewise.
* testsuite/23_containers/map/version.cc: Likewise.
* testsuite/23_containers/set/version.cc: Likewise.
* testsuite/23_containers/unordered_map/version.cc: Likewise.
* testsuite/23_containers/unordered_set/version.cc: Likewise.
* testsuite/23_containers/vector/version.cc: Likewise.

(cherry picked from commit efe6efb6f315c7f97be8a850e0a84ff7f6651d85)

Diff:
---
 libstdc++-v3/include/std/deque| 1 +
 libstdc++-v3/include/std/forward_list | 1 +
 libstdc++-v3/include/std/list | 1 +
 libstdc++-v3/include/std/map  | 1 +
 libstdc++-v3/include/std/scoped_allocator | 3 +++
 libstdc++-v3/include/std/set  | 1 +
 libstdc++-v3/include/std/string   | 1 +
 libstdc++-v3/include/std/unordered_map| 1 +
 libstdc++-v3/include/std/unordered_set| 1 +
 libstdc++-v3/include/std/vector   | 1 +
 libstdc++-v3/testsuite/20_util/headers/memory/version.cc  | 8 
 libstdc++-v3/testsuite/20_util/scoped_allocator/version.cc| 8 
 libstdc++-v3/testsuite/21_strings/headers/string/version.cc   | 8 
 libstdc++-v3/testsuite/23_containers/deque/version.cc | 8 
 libstdc++-v3/testsuite/23_containers/forward_list/version.cc  | 8 
 libstdc++-v3/testsuite/23_containers/list/version.cc  | 8 
 libstdc++-v3/testsuite/23_containers/map/version.cc   | 8 
 libstdc++-v3/testsuite/23_containers/set/version.cc   | 8 
 libstdc++-v3/testsuite/23_containers/unordered_map/version.cc | 8 
 libstdc++-v3/testsuite/23_containers/unordered_set/version.cc | 8 
 libstdc++-v3/testsuite/23_containers/vector/version.cc| 8 
 21 files changed, 100 insertions(+)

diff --git a/libstdc++-v3/include/std/deque b/libstdc++-v3/include/std/deque
index 0bf8309c19a..69f8c0dcdcc 100644
--- a/libstdc++-v3/include/std/deque
+++ b/libstdc++-v3/include/std/deque
@@ -68,6 +68,7 @@
 #include 
 #include 
 
+#define __glibcxx_want_allocator_traits_is_always_equal
 #define __glibcxx_want_erase_if
 #define __glibcxx_want_nonmember_container_access
 #include 
diff --git a/libstdc++-v3/include/std/forward_list 
b/libstdc++-v3/include/std/forward_list
index 5ac74360808..dfd7d48d121 100644
--- a/libstdc++-v3/include/std/forward_list
+++ b/libstdc++-v3/include/std/forward_list
@@ -45,6 +45,7 @@
 # include 
 #endif
 
+#define __glibcxx_want_allocator_traits_is_always_equal
 #define __glibcxx_want_erase_if
 #define __glibcxx_want_incomplete_container_elements
 #define __glibcxx_want_list_remove_return_type
diff --git a/libstdc++-v3/include/std/list b/libstdc++-v3/include/std/list
index fce4e3d925b..ff632fc1ab2 100644
--- a/libstdc++-v3/include/std/list
+++ b/libstdc++-v3/include/std/list
@@ -69,6 +69,7 @@
 # include 
 #endif
 
+#define __glibcxx_want_allocator_traits_is_always_equal
 #define __glibcxx_want_erase_if
 #define __glibcxx_want_incomplete_container_elements
 #define __glibcxx_want_list_remove_return_type
diff --git a/libstdc++-v3/include/std/map b/libstdc++-v3/include/std/map
index 4a96e59a5bc..6520d9f744f 100644
--- a/libstdc++-v3/include/std/map
+++ b/libstdc++-v3/include/std/map
@@ -69,6 +69,7 @@
 # include 
 #endif
 
+#define __glibcxx_want_allocator_traits_is_always_equal
 #defin

[gcc r14-10640] libstdc++: Fix overwriting files with fs::copy_file on Windows

2024-09-04 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:35c98149a5c7af9159fa7615d8d827b3aaa3cc97

commit r14-10640-g35c98149a5c7af9159fa7615d8d827b3aaa3cc97
Author: Jonathan Wakely 
Date:   Tue Jul 30 10:55:55 2024 +0100

libstdc++: Fix overwriting files with fs::copy_file on Windows

There are no inode numbers on Windows filesystems, so stat_type::st_ino
is always zero and the check for equivalent files in do_copy_file was
incorrectly identifying distinct files as equivalent. This caused
copy_file to incorrectly report errors when trying to overwrite existing
files.

The fs::equivalent function already does the right thing on Windows, so
factor that logic out into a new function that can be reused by
fs::copy_file.

The tests for fs::copy_file were quite inadequate, so this also adds
checks for that function's error conditions.

libstdc++-v3/ChangeLog:

* src/c++17/fs_ops.cc (auto_win_file_handle): Change constructor
parameter from const path& to const wchar_t*.
(fs::equiv_files): New function.
(fs::equivalent): Use equiv_files.
* src/filesystem/ops-common.h (fs::equiv_files): Declare.
(do_copy_file): Use equiv_files.
* src/filesystem/ops.cc (fs::equiv_files): Define.
(fs::copy, fs::equivalent): Use equiv_files.
* testsuite/27_io/filesystem/operations/copy.cc: Test
overwriting directory contents recursively.
* testsuite/27_io/filesystem/operations/copy_file.cc: Test
overwriting existing files.

(cherry picked from commit 017e3f89b081e4828a588a3bd27b5feacea042b7)

Diff:
---
 libstdc++-v3/src/c++17/fs_ops.cc   |  71 +++-
 libstdc++-v3/src/filesystem/ops-common.h   |  12 +-
 libstdc++-v3/src/filesystem/ops.cc |  18 ++-
 .../testsuite/27_io/filesystem/operations/copy.cc  |   9 ++
 .../27_io/filesystem/operations/copy_file.cc   | 122 +
 5 files changed, 199 insertions(+), 33 deletions(-)

diff --git a/libstdc++-v3/src/c++17/fs_ops.cc b/libstdc++-v3/src/c++17/fs_ops.cc
index 81227c49dfd..9606afa9f1f 100644
--- a/libstdc++-v3/src/c++17/fs_ops.cc
+++ b/libstdc++-v3/src/c++17/fs_ops.cc
@@ -350,7 +350,7 @@ fs::copy(const path& from, const path& to, copy_options 
options,
   f = make_file_status(from_st);
 
   if (exists(t) && !is_other(t) && !is_other(f)
-  && to_st.st_dev == from_st.st_dev && to_st.st_ino == from_st.st_ino)
+  && fs::equiv_files(from.c_str(), from_st, to.c_str(), to_st, ec))
 {
   ec = std::make_error_code(std::errc::file_exists);
   return;
@@ -829,8 +829,8 @@ namespace
   struct auto_win_file_handle
   {
 explicit
-auto_win_file_handle(const fs::path& p_)
-: handle(CreateFileW(p_.c_str(), 0,
+auto_win_file_handle(const wchar_t* p)
+: handle(CreateFileW(p, 0,
 FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0))
 { }
@@ -850,6 +850,44 @@ namespace
 }
 #endif
 
+#ifdef _GLIBCXX_HAVE_SYS_STAT_H
+#ifdef NEED_DO_COPY_FILE // Only define this once, not in cow-fs_ops.o too
+bool
+fs::equiv_files([[maybe_unused]] const char_type* p1, const stat_type& st1,
+   [[maybe_unused]] const char_type* p2, const stat_type& st2,
+   [[maybe_unused]] error_code& ec)
+{
+#if ! _GLIBCXX_FILESYSTEM_IS_WINDOWS
+  // For POSIX the device ID and inode number uniquely identify a file.
+  return st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino;
+#else
+  // For Windows st_ino is not set, so can't be used to distinguish files.
+  // We can compare modes and device IDs as a cheap initial check:
+  if (st1.st_mode != st2.st_mode || st1.st_dev != st2.st_dev)
+return false;
+
+  // Need to use GetFileInformationByHandle to get more info about the files.
+  auto_win_file_handle h1(p1);
+  auto_win_file_handle h2(p2);
+  if (!h1 || !h2)
+{
+  if (!h1 && !h2)
+   ec = __last_system_error();
+  return false;
+}
+  if (!h1.get_info() || !h2.get_info())
+{
+  ec = __last_system_error();
+  return false;
+}
+  return h1.info.dwVolumeSerialNumber == h2.info.dwVolumeSerialNumber
+  && h1.info.nFileIndexHigh == h2.info.nFileIndexHigh
+  && h1.info.nFileIndexLow == h2.info.nFileIndexLow;
+#endif // _GLIBCXX_FILESYSTEM_IS_WINDOWS
+}
+#endif // NEED_DO_COPY_FILE
+#endif // _GLIBCXX_HAVE_SYS_STAT_H
+
 bool
 fs::equivalent(const path& p1, const path& p2, error_code& ec) noexcept
 {
@@ -881,30 +919,7 @@ fs::equivalent(const path& p1, const path& p2, error_code& 
ec) noexcept
   ec.clear();
   if (is_other(s1) || is_other(s2))
return false;
-#if _GLIBCXX_FILESYSTEM_IS_WINDOWS
-  // st_ino is not set, so can't be used to distinguish files
-  if (st1.st_mode != st2.st_mode || st1.st_dev != st2.st_dev)
-   return false;
-
-  auto_win_fil

[gcc r15-3573] libstdc++: Add missing exception specifications in tests

2024-09-10 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:4e1e50458b2004d0f08ac8c64f89b85fc1a87057

commit r15-3573-g4e1e50458b2004d0f08ac8c64f89b85fc1a87057
Author: Jonathan Wakely 
Date:   Tue Sep 10 16:59:29 2024 +0100

libstdc++: Add missing exception specifications in tests

Since r15-3532-g7cebc6384a0ad6 18_support/new_nothrow.cc fails in C++98 
mode because G++
diagnoses missing exception specifications for the user-defined
(de)allocation functions. Add throw(std::bad_alloc) and throw() for
C++98 mode.

Similarly, 26_numerics/headers/numeric/synopsis.cc fails in C++20 mode
because the declarations of gcd and lcm are not noexcept.

libstdc++-v3/ChangeLog:

* testsuite/18_support/new_nothrow.cc (THROW_BAD_ALLOC): Define
macro to add exception specifications for C++98 mode.
(NOEXCEPT): Expand to throw() for C++98 mode.
* testsuite/26_numerics/headers/numeric/synopsis.cc (gcd, lcm):
Add noexcept.

Diff:
---
 libstdc++-v3/testsuite/18_support/new_nothrow.cc   | 18 ++
 .../testsuite/26_numerics/headers/numeric/synopsis.cc  |  4 ++--
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/libstdc++-v3/testsuite/18_support/new_nothrow.cc 
b/libstdc++-v3/testsuite/18_support/new_nothrow.cc
index a3251f5ad64e..551b71dfa589 100644
--- a/libstdc++-v3/testsuite/18_support/new_nothrow.cc
+++ b/libstdc++-v3/testsuite/18_support/new_nothrow.cc
@@ -41,7 +41,15 @@ static void new_handler ()
 throw MyBadAlloc ();
 }
 
-void* operator new (size_t n)
+#if __cplusplus >= 201103L
+# define THROW_BAD_ALLOC noexcept(false)
+# define NOEXCEPT noexcept
+# else
+# define THROW_BAD_ALLOC throw(std::bad_alloc)
+# define NOEXCEPT throw()
+#endif
+
+void* operator new (size_t n) THROW_BAD_ALLOC
 {
 static size_t cntr;
 
@@ -64,12 +72,6 @@ void* operator new (size_t n)
 }
 }
 
-#if __cplusplus >= 201103L
-#define NOEXCEPT noexcept
-#else
-#define NOEXCEPT
-#endif
-
 void operator delete (void *p) NOEXCEPT
 {
 ++delete_called;
@@ -77,7 +79,7 @@ void operator delete (void *p) NOEXCEPT
 free (static_cast(p) - 1);
 }
 
-void* operator new[] (size_t n)
+void* operator new[] (size_t n) THROW_BAD_ALLOC
 {
 ++new_vec_called;
 return operator new(n);
diff --git a/libstdc++-v3/testsuite/26_numerics/headers/numeric/synopsis.cc 
b/libstdc++-v3/testsuite/26_numerics/headers/numeric/synopsis.cc
index 87670090f72f..8c33974c2e96 100644
--- a/libstdc++-v3/testsuite/26_numerics/headers/numeric/synopsis.cc
+++ b/libstdc++-v3/testsuite/26_numerics/headers/numeric/synopsis.cc
@@ -161,10 +161,10 @@ namespace std {
 
 #if __cplusplus > 201703L
   template
-constexpr common_type_t gcd(M m, N n);
+constexpr common_type_t gcd(M m, N n) noexcept;
 
   template
-constexpr common_type_t lcm(M m, N n);
+constexpr common_type_t lcm(M m, N n) noexcept;
 
   template
 constexpr T midpoint(T a, T b) noexcept;


[gcc r15-3575] libstdc++: std::string move assignment should not use POCCA trait [PR116641]

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

commit r15-3575-gc07cf418fdde0c192e370a8d76a991cc7215e9c4
Author: Jonathan Wakely 
Date:   Tue Sep 10 14:25:41 2024 +0100

libstdc++: std::string move assignment should not use POCCA trait [PR116641]

The changes to implement LWG 2579 (r10-327-gdb33efde17932f) made
std::string::assign use the propagate_on_container_copy_assignment
(POCCA) trait, for consistency with operator=(const basic_string&).
However, this also unintentionally affected operator=(basic_string&&)
which calls assign(str) to make a deep copy when performing a move is
not possible. The fix is for the move assignment operator to call
_M_assign(str) instead of assign(str), as this just does the deep copy
and doesn't check the POCCA trait first.

The bug only affects the unlikely/useless combination of POCCA==true and
POCMA==false, but we should fix it for correctness anyway. it should
also make move assignment slightly cheaper to compile and execute,
because we skip the extra code in assign(const basic_string&).

libstdc++-v3/ChangeLog:

PR libstdc++/116641
* include/bits/basic_string.h (operator=(basic_string&&)): Call
_M_assign instead of assign.
* testsuite/21_strings/basic_string/allocator/116641.cc: New
test.

Diff:
---
 libstdc++-v3/include/bits/basic_string.h   |  2 +-
 .../21_strings/basic_string/allocator/116641.cc| 53 ++
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/basic_string.h 
b/libstdc++-v3/include/bits/basic_string.h
index 944bd230704b..120c0bc9a179 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -915,7 +915,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
  __str._M_data(__str._M_use_local_data());
  }
else // Need to do a deep copy
- assign(__str);
+ _M_assign(__str);
__str.clear();
return *this;
   }
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/allocator/116641.cc 
b/libstdc++-v3/testsuite/21_strings/basic_string/allocator/116641.cc
new file mode 100644
index ..a1a411b87faa
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/allocator/116641.cc
@@ -0,0 +1,53 @@
+// { dg-do run { target c++11 } }
+// { dg-require-effective-target cxx11_abi }
+
+// Bug 116641 - std::string move assignment incorrectly depends on POCCA
+
+#include 
+#include 
+
+template
+struct Alloc
+{
+  using value_type = T;
+  using propagate_on_container_swap = std::false_type;
+  using propagate_on_container_copy_assignment = std::true_type;
+  using propagate_on_container_move_assignment = std::false_type;
+
+  Alloc(int id) : id(id) { }
+
+  template
+Alloc(const Alloc& a) : id(a.id) { }
+
+  T* allocate(unsigned long n)
+  { return std::allocator().allocate(n); }
+
+  void deallocate(T* p, unsigned long n)
+  { std::allocator().deallocate(p, n); }
+
+  Alloc& operator=(const Alloc&) { throw; }
+
+  bool operator==(const Alloc& a) const { return id == a.id; }
+  bool operator!=(const Alloc& a) const { return id != a.id; }
+
+  int id;
+};
+
+void
+test_pr116641()
+{
+  Alloc a1(1), a2(2);
+  std::basic_string, Alloc> s1(a1), s2(a2);
+
+  s1 = "allocator should not propagate on move assignment";
+  VERIFY( s1.get_allocator() == a1 );
+  VERIFY( s2.get_allocator() == a2 );
+  s2 = std::move(s1);
+  VERIFY( s1.get_allocator() == a1 );
+  VERIFY( s2.get_allocator() == a2 );
+}
+
+int main()
+{
+  test_pr116641();
+}


[gcc r15-3614] c++: Make __builtin_launder reject invalid types [PR116673]

2024-09-12 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:9fe57e4879de93b6e3c7b4c226f42d5f3a48474f

commit r15-3614-g9fe57e4879de93b6e3c7b4c226f42d5f3a48474f
Author: Jonathan Wakely 
Date:   Wed Sep 11 11:47:44 2024 +0100

c++: Make __builtin_launder reject invalid types [PR116673]

The standard says that std::launder is ill-formed for function pointers
and cv void pointers, so there's no reason for __builtin_launder to
accept them. This change allows implementations of std::launder to defer
to the built-in for error checking, although libstdc++ will continue to
diagnose it directly for more user-friendly diagnostics.

PR c++/116673

gcc/cp/ChangeLog:

* semantics.cc (finish_builtin_launder): Diagnose function
pointers and cv void pointers.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/launder2.C: Adjust dg-error strings.
* g++.dg/cpp1z/launder10.C: New test.

Diff:
---
 gcc/cp/semantics.cc|  6 +++---
 gcc/testsuite/g++.dg/cpp1z/launder10.C | 15 +++
 gcc/testsuite/g++.dg/cpp1z/launder2.C  |  6 +++---
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 63212afafb3b..8219d6410b8e 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -13482,10 +13482,10 @@ finish_builtin_launder (location_t loc, tree arg, 
tsubst_flags_t complain)
 arg = decay_conversion (arg, complain);
   if (error_operand_p (arg))
 return error_mark_node;
-  if (!type_dependent_expression_p (arg)
-  && !TYPE_PTR_P (TREE_TYPE (arg)))
+  if (!type_dependent_expression_p (arg) && !TYPE_PTROB_P (TREE_TYPE (arg)))
 {
-  error_at (loc, "non-pointer argument to %<__builtin_launder%>");
+  error_at (loc, "type %qT of argument to %<__builtin_launder%> "
+   "is not a pointer to object type", TREE_TYPE (arg));
   return error_mark_node;
 }
   if (processing_template_decl)
diff --git a/gcc/testsuite/g++.dg/cpp1z/launder10.C 
b/gcc/testsuite/g++.dg/cpp1z/launder10.C
new file mode 100644
index ..2109a2e38393
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/launder10.C
@@ -0,0 +1,15 @@
+// PR c++/116673
+// { dg-do compile }
+
+void
+bar (void *p)
+{
+  __builtin_launder (bar); // { dg-error {argument to '__builtin_launder'} }
+  __builtin_launder (p);   // { dg-error {argument to '__builtin_launder'} }
+  const void* cp = p;
+  __builtin_launder (cp);  // { dg-error {argument to '__builtin_launder'} }
+  volatile void* vp = p;
+  __builtin_launder (vp);  // { dg-error {argument to '__builtin_launder'} }
+  const volatile void* cvp = p;
+  __builtin_launder (cvp); // { dg-error {argument to '__builtin_launder'} }
+}
diff --git a/gcc/testsuite/g++.dg/cpp1z/launder2.C 
b/gcc/testsuite/g++.dg/cpp1z/launder2.C
index 9cd1779704b3..a2d448612655 100644
--- a/gcc/testsuite/g++.dg/cpp1z/launder2.C
+++ b/gcc/testsuite/g++.dg/cpp1z/launder2.C
@@ -4,11 +4,11 @@ int a;
 int *b = __builtin_launder (); // { dg-error "wrong number of 
arguments to" }
 int *c = __builtin_launder (&a, 2);// { dg-error "wrong number of 
arguments to" }
 int *d = __builtin_launder (&a);
-int e = __builtin_launder (a); // { dg-error "non-pointer argument to" 
}
+int e = __builtin_launder (a); // { dg-error "not a pointer to object 
type" }
 int &f = a;
-int g = __builtin_launder (f); // { dg-error "non-pointer argument to" 
}
+int g = __builtin_launder (f); // { dg-error "not a pointer to object 
type" }
 
-template  T f1 (T x) { return __builtin_launder (x); } // { 
dg-error "non-pointer argument to" }
+template  T f1 (T x) { return __builtin_launder (x); } // { 
dg-error "not a pointer to object type" }
 template  T f2 (T x) { return __builtin_launder (x); }
 
 int h = f1 (a);


[gcc r15-3637] c++: Fix g++.dg/ext/sve-sizeless-1.C regression

2024-09-14 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:bec1f2ce4ad3fe56906d6429b542a290e574b3eb

commit r15-3637-gbec1f2ce4ad3fe56906d6429b542a290e574b3eb
Author: Jonathan Wakely 
Date:   Fri Sep 13 08:18:53 2024 +0100

c++: Fix g++.dg/ext/sve-sizeless-1.C regression

This aarch64-*-* test needs an update for the diagnostic I changed in
r15-3614-g9fe57e4879de93.

gcc/testsuite/ChangeLog:

* g++.dg/ext/sve-sizeless-1.C: Adjust dg-error string.

Diff:
---
 gcc/testsuite/g++.dg/ext/sve-sizeless-1.C | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/ext/sve-sizeless-1.C 
b/gcc/testsuite/g++.dg/ext/sve-sizeless-1.C
index 9f05ca5a855a..adee37a0551e 100644
--- a/gcc/testsuite/g++.dg/ext/sve-sizeless-1.C
+++ b/gcc/testsuite/g++.dg/ext/sve-sizeless-1.C
@@ -301,7 +301,7 @@ statements (int n)
 
   // Other built-ins
 
-  __builtin_launder (sve_sc1); // { dg-error {non-pointer argument to 
'__builtin_launder'} }
+  __builtin_launder (sve_sc1); // { dg-error {not a pointer to object type} }
   __builtin_memcpy (&sve_sc1, &sve_sc2, 2);
 
   // Lambdas


[gcc r15-3639] libstdc++: Refactor loops in std::__platform_semaphore

2024-09-14 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:01670a4095791733e0389acead832e3da757c9d7

commit r15-3639-g01670a4095791733e0389acead832e3da757c9d7
Author: Jonathan Wakely 
Date:   Mon Sep 2 12:29:04 2024 +0100

libstdc++: Refactor loops in std::__platform_semaphore

Refactor the loops to all use the same form, and to not need explicit
'break' or 'continue' jumps. This also avoids a -Wunused-variable
warning with -Wsystem-headers.

Also fix a bug for absolute timeouts specified with a time that isn't
implicitly convertible to __clock_t::time_point, e.g. one with a higher
resolution such as picoseconds. Use chrono::ceil to round up to the next
time point representable by the clock.

libstdc++-v3/ChangeLog:

* include/bits/semaphore_base.h (__platform_semaphore): Refactor
loops to all use similar forms.
(__platform_semaphore::_M_try_acquire_until): Use chrono::ceil
to explicitly convert to __clock_t::time_point.
* testsuite/30_threads/semaphore/try_acquire_for.cc: Check that
using a very high resolution timeout compiles.
* testsuite/30_threads/semaphore/platform_try_acquire_for.cc:
New test.

Diff:
---
 libstdc++-v3/include/bits/semaphore_base.h | 58 --
 .../semaphore/platform_try_acquire_for.cc  |  7 +++
 .../30_threads/semaphore/try_acquire_for.cc| 13 +
 3 files changed, 40 insertions(+), 38 deletions(-)

diff --git a/libstdc++-v3/include/bits/semaphore_base.h 
b/libstdc++-v3/include/bits/semaphore_base.h
index 44a68645e477..2b19c9c6c6ac 100644
--- a/libstdc++-v3/include/bits/semaphore_base.h
+++ b/libstdc++-v3/include/bits/semaphore_base.h
@@ -73,52 +73,37 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 _GLIBCXX_ALWAYS_INLINE void
 _M_acquire() noexcept
 {
-  for (;;)
-   {
- auto __err = sem_wait(&_M_semaphore);
- if (__err && (errno == EINTR))
-   continue;
- else if (__err)
-   std::__terminate();
- else
-   break;
-   }
+  while (sem_wait(&_M_semaphore))
+   if (errno != EINTR)
+ std::__terminate();
 }
 
 _GLIBCXX_ALWAYS_INLINE bool
 _M_try_acquire() noexcept
 {
-  for (;;)
+  while (sem_trywait(&_M_semaphore))
{
- auto __err = sem_trywait(&_M_semaphore);
- if (__err && (errno == EINTR))
-   continue;
- else if (__err && (errno == EAGAIN))
+ if (errno == EAGAIN) // already locked
return false;
- else if (__err)
+ else if (errno != EINTR)
std::__terminate();
- else
-   break;
+ // else got EINTR so retry
}
   return true;
 }
 
 _GLIBCXX_ALWAYS_INLINE void
-_M_release(std::ptrdiff_t __update) noexcept
+_M_release(ptrdiff_t __update) noexcept
 {
   for(; __update != 0; --__update)
-   {
-  auto __err = sem_post(&_M_semaphore);
-  if (__err)
-std::__terminate();
-   }
+   if (sem_post(&_M_semaphore))
+ std::__terminate();
 }
 
 bool
 _M_try_acquire_until_impl(const chrono::time_point<__clock_t>& __atime)
   noexcept
 {
-
   auto __s = chrono::time_point_cast(__atime);
   auto __ns = chrono::duration_cast(__atime - __s);
 
@@ -128,19 +113,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static_cast(__ns.count())
   };
 
-  for (;;)
+  while (sem_timedwait(&_M_semaphore, &__ts))
{
- if (auto __err = sem_timedwait(&_M_semaphore, &__ts))
-   {
- if (errno == EINTR)
-   continue;
- else if (errno == ETIMEDOUT || errno == EINVAL)
-   return false;
- else
-   std::__terminate();
-   }
- else
-   break;
+ if (errno == ETIMEDOUT)
+   return false;
+ else if (errno != EINTR)
+   std::__terminate();
}
   return true;
 }
@@ -152,10 +130,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   {
if constexpr (std::is_same_v<__clock_t, _Clock>)
  {
-   return _M_try_acquire_until_impl(__atime);
+   using _Dur = __clock_t::duration;
+   return _M_try_acquire_until_impl(chrono::ceil<_Dur>(__atime));
  }
else
  {
+   // TODO: if _Clock is monotonic_clock we could use
+   // sem_clockwait with CLOCK_MONOTONIC.
+
const typename _Clock::time_point __c_entry = _Clock::now();
const auto __s_entry = __clock_t::now();
const auto __delta = __atime - __c_entry;
diff --git 
a/libstdc++-v3/testsuite/30_threads/semaphore/platform_try_acquire_for.cc 
b/libstdc++-v3/testsuite/30_threads/semaphore/platform_try_acquire_for.cc
new file mode 100644
index ..bf6cd142bf01
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/semaphore/platform_try_acquire_for.

[gcc r15-1626] libstdc++: Replace viewcvs links in docs with cgit links

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

commit r15-1626-g9d8021d1875677286c3dde90dfed2aca864edad0
Author: Jonathan Wakely 
Date:   Tue Jun 25 13:35:17 2024 +0100

libstdc++: Replace viewcvs links in docs with cgit links

libstdc++-v3/ChangeLog:

* doc/xml/faq.xml: Replace viewcvs links with cgit links.
* doc/xml/manual/allocator.xml: Likewise.
* doc/xml/manual/mt_allocator.xml: Likewise.
* doc/html/*: Regenerate.

Diff:
---
 libstdc++-v3/doc/html/api.html  |  2 +-
 libstdc++-v3/doc/html/faq.html  |  2 +-
 libstdc++-v3/doc/html/manual/memory.html| 10 +-
 libstdc++-v3/doc/html/manual/mt_allocator_impl.html |  6 +++---
 libstdc++-v3/doc/xml/faq.xml|  2 +-
 libstdc++-v3/doc/xml/manual/allocator.xml   | 10 +-
 libstdc++-v3/doc/xml/manual/mt_allocator.xml|  6 +++---
 7 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/libstdc++-v3/doc/html/api.html b/libstdc++-v3/doc/html/api.html
index b494d91f9af..d2cff093d8f 100644
--- a/libstdc++-v3/doc/html/api.html
+++ b/libstdc++-v3/doc/html/api.html
@@ -38,4 +38,4 @@
 
   In addition, a rendered set of man pages are available in the same
   location specified above. Start with C++Intro(3).
-Prev Up Next Home 

+Prev Up Next Home 

\ No newline at end of file
diff --git a/libstdc++-v3/doc/html/faq.html b/libstdc++-v3/doc/html/faq.html
index dcb94ba67dc..507555839f2 100644
--- a/libstdc++-v3/doc/html/faq.html
+++ b/libstdc++-v3/doc/html/faq.html
@@ -147,7 +147,7 @@
  The libstdc++ project is contributed to by several developers
  all over the world, in the same way as GCC or the Linux kernel.
  The current maintainers are listed in the
- https://gcc.gnu.org/viewcvs/gcc/trunk/MAINTAINERS?view=co"; 
target="_top">MAINTAINERS
+ https://gcc.gnu.org/cgit/gcc/tree/MAINTAINERS"; 
target="_top">MAINTAINERS
  file (look for "c++ runtime libs").
 
 Development and discussion is held on the libstdc++ mailing
diff --git a/libstdc++-v3/doc/html/manual/memory.html 
b/libstdc++-v3/doc/html/manual/memory.html
index 08ad2fd4dd8..6b707105969 100644
--- a/libstdc++-v3/doc/html/manual/memory.html
+++ b/libstdc++-v3/doc/html/manual/memory.html
@@ -120,8 +120,8 @@
Over multiple iterations, various STL container
  objects have elements inserted to some maximum amount. A variety
  of allocators are tested.
- Test source for http://gcc.gnu.org/viewcvs/gcc/trunk/libstdc%2B%2B-v3/testsuite/performance/23_containers/insert/sequence.cc?view=markup";
 target="_top">sequence
- and http://gcc.gnu.org/viewcvs/gcc/trunk/libstdc%2B%2B-v3/testsuite/performance/23_containers/insert/associative.cc?view=markup";
 target="_top">associative
+ Test source for https://gcc.gnu.org/cgit/gcc/tree/libstdc++-v3/testsuite/performance/23_containers/insert/sequence.cc";
 target="_top">sequence
+ and https://gcc.gnu.org/cgit/gcc/tree/libstdc++-v3/testsuite/performance/23_containers/insert/associative.cc";
 target="_top">associative
  containers.

Insertion and erasure in a multi-threaded environment.
@@ -130,14 +130,14 @@
  on a per-thread basis, as well as measuring thread contention
  for memory resources.
  Test source
-http://gcc.gnu.org/viewcvs/gcc/trunk/libstdc%2B%2B-v3/testsuite/performance/23_containers/insert_erase/associative.cc?view=markup";
 target="_top">here.
+https://gcc.gnu.org/cgit/gcc/tree/libstdc++-v3/testsuite/performance/23_containers/insert_erase/associative.cc";
 target="_top">here.

 A threaded producer/consumer model.

Test source for
- http://gcc.gnu.org/viewcvs/gcc/trunk/libstdc++-v3/testsuite/performance/23_containers/producer_consumer/sequence.cc?view=markup";
 target="_top">sequence
+ https://gcc.gnu.org/cgit/gcc/tree/libstdc++-v3/testsuite/performance/23_containers/producer_consumer/sequence.cc";
 target="_top">sequence
  and
- http://gcc.gnu.org/viewcvs/gcc/trunk/libstdc++-v3/testsuite/performance/23_containers/producer_consumer/associative.cc?view=markup";
 target="_top">associative
+ https://gcc.gnu.org/cgit/gcc/tree/libstdc++-v3/testsuite/performance/23_containers/producer_consumer/associative.cc";
 target="_top">associative
  containers.
  
  Since GCC 12 the default choice for
diff --git a/libstdc++-v3/doc/html/manual/mt_allocator_impl.html 
b/libstdc++-v3/doc/html/manual/mt_allocator_impl.html
index 2e5926add00..c69b9c5b55a 100644
--- a/libstdc++-v3/doc/html/manual/mt_allocator_impl.html
+++ b/libstdc++-v3/doc/html/manual/mt_allocator_impl.html
@@ -155,7 +155,7 @@ that uses it is fully constructed. For most (but not all) 
STL
 containers, this works, as an instance of the allocator is constructed
 as part of a container's constructor. However, this assumption is
 implementation-specific, and subject to change. For an

[gcc r11-11537] libstdc++: Replace reference to mainline in release branch docs

2024-06-25 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:7d60b932ccd658078173abc13251e0a120dafd9d

commit r11-11537-g7d60b932ccd658078173abc13251e0a120dafd9d
Author: Jonathan Wakely 
Date:   Tue Jun 25 23:20:49 2024 +0100

libstdc++: Replace reference to mainline in release branch docs

libstdc++-v3/ChangeLog:

* doc/xml/manual/status_cxx2023.xml: Change reference from
mainline GCC to the release branch.
* doc/html/manual/status.html: Regenerate.

Diff:
---
 libstdc++-v3/doc/html/manual/status.html   | 3 +--
 libstdc++-v3/doc/xml/manual/status_cxx2023.xml | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/doc/html/manual/status.html 
b/libstdc++-v3/doc/html/manual/status.html
index 3805e9e24f0..838cba72f47 100644
--- a/libstdc++-v3/doc/html/manual/status.html
+++ b/libstdc++-v3/doc/html/manual/status.html
@@ -1702,8 +1702,7 @@ options. The pre-defined symbol
 __cplusplus is used to check for the
 presence of the required flag.
 
-This section describes the C++23 and library TS support in mainline GCC,
-not in any particular release.
+This section describes the C++23 and library TS support in the GCC 11 release 
series.
 
 The following table lists new library features that have been accepted into
 the C++23 working draft. The "Proposal" column provides a link to the
diff --git a/libstdc++-v3/doc/xml/manual/status_cxx2023.xml 
b/libstdc++-v3/doc/xml/manual/status_cxx2023.xml
index 75f31f55aa9..381f989d482 100644
--- a/libstdc++-v3/doc/xml/manual/status_cxx2023.xml
+++ b/libstdc++-v3/doc/xml/manual/status_cxx2023.xml
@@ -20,8 +20,7 @@ presence of the required flag.
 
 
 
-This section describes the C++23 and library TS support in mainline GCC,
-not in any particular release.
+This section describes the C++23 and library TS support in the GCC 11 release 
series.
 
 
 


[gcc r14-10347] libstdc++: Remove confusing text from status tables for release branch

2024-06-25 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:f91d9b3e91e6077c3cab6d703375f186f1d8d43b

commit r14-10347-gf91d9b3e91e6077c3cab6d703375f186f1d8d43b
Author: Jonathan Wakely 
Date:   Tue Jun 25 23:25:54 2024 +0100

libstdc++: Remove confusing text from status tables for release branch

When I tried to make the release branch versions of these docs refer to
the release branch instead of "mainline GCC", for some reason I left the
text "not any particular release" there. That's just confusing, because
the docs are for a particular release, the latest on that branch. Remove
that confusing text in several places.

libstdc++-v3/ChangeLog:

* doc/xml/manual/status_cxx1998.xml: Remove confusing "not in
any particular release" text.
* doc/xml/manual/status_cxx2011.xml: Likewise.
* doc/xml/manual/status_cxx2014.xml: Likewise.
* doc/xml/manual/status_cxx2017.xml: Likewise.
* doc/xml/manual/status_cxx2020.xml: Likewise.
* doc/xml/manual/status_cxx2023.xml: Likewise.
* doc/xml/manual/status_cxxtr1.xml: Likewise.
* doc/xml/manual/status_cxxtr24733.xml: Likewise.
* doc/html/manual/status.html: Regenerate.

Diff:
---
 libstdc++-v3/doc/html/manual/status.html  | 16 
 libstdc++-v3/doc/xml/manual/status_cxx1998.xml|  2 +-
 libstdc++-v3/doc/xml/manual/status_cxx2011.xml|  2 +-
 libstdc++-v3/doc/xml/manual/status_cxx2014.xml|  2 +-
 libstdc++-v3/doc/xml/manual/status_cxx2017.xml|  2 +-
 libstdc++-v3/doc/xml/manual/status_cxx2020.xml|  2 +-
 libstdc++-v3/doc/xml/manual/status_cxx2023.xml|  2 +-
 libstdc++-v3/doc/xml/manual/status_cxxtr1.xml |  2 +-
 libstdc++-v3/doc/xml/manual/status_cxxtr24733.xml |  2 +-
 9 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/libstdc++-v3/doc/html/manual/status.html 
b/libstdc++-v3/doc/html/manual/status.html
index c13ec20feaa..6dc4535aff6 100644
--- a/libstdc++-v3/doc/html/manual/status.html
+++ b/libstdc++-v3/doc/html/manual/status.html
@@ -6,7 +6,7 @@
 This status table is based on the table of contents of ISO/IEC 14882:2003.
 
 This section describes the C++ support in
-the GCC 14 release series, not in any particular release.
+the GCC 14 release series.
 Table 1.1. C++ 1998/2003 Implementation 
StatusSectionDescriptionStatusComments
18
   
@@ -161,7 +161,7 @@ since that release.
 This status table is based on the table of contents of ISO/IEC 14882:2011.
 
 This section describes the C++11 support in
-the GCC 14 release series, not in any particular release.
+the GCC 14 release series.
 Table 1.2. C++ 2011 Implementation 
StatusSectionDescriptionStatusComments
18
   
@@ -434,7 +434,7 @@ Some subclauses are not shown in the table where the 
content is unchanged
 since C++11 and the implementation is complete.
 
 This section describes the C++14 and library TS support in
-the GCC 14 release series, not in any particular release.
+the GCC 14 release series.
 Table 1.3. C++ 2014 Implementation 
StatusSectionDescriptionStatusComments
18
   
@@ -579,7 +579,7 @@ so the API and ABI of features added in C++17 is only stable
 since that release.
 
 This section describes the C++17 and library TS support in
-the GCC 14 release series, not in any particular release.
+the GCC 14 release series.
 
 The following table lists new library features that are included in
 the C++17 standard. The "Proposal" column provides a link to the
@@ -1255,7 +1255,7 @@ options. The pre-defined symbol
 presence of the required flag.
 
 This section describes the C++20 and library TS support in
-the GCC 14 release series, not in any particular release.
+the GCC 14 release series.
 
 The following table lists new library features that are included in
 the C++20 standard. The "Proposal" column provides a link to the
@@ -1725,7 +1725,7 @@ options. The pre-defined symbol
 presence of the required flag.
 
 This section describes the C++23 and library TS support in
-the GCC 14 release series, not in any particular release.
+the GCC 14 release series.
 
 The following table lists new library features that have been accepted into
 the C++23 working draft. The "Proposal" column provides a link to the
@@ -2213,7 +2213,7 @@ In this implementation the header names are prefixed by
 , and so on.
 
 This page describes the TR1 support in
-the GCC 14 release series, not in any particular release.
+the GCC 14 release series.
 Table 1.11. C++ TR1 Implementation 
StatusSectionDescriptionStatusComments2General Utilities2.1Reference wrappers 
 2.1.1Additions to header  
synopsisY 2.1.2Class template reference_wrapper  2.1.2.1reference_wrapper construct/copy/destroyY 2.1.2.2reference_wrapper assignmentY 2.1.2.3reference_wrapper accessY 2.1.2.4reference_wrapper invocationY 2.1.2.5reference_wrapper helper functionsY 
 2.2Smart pointers  2.2.1Additions to header  
synopsisY 2.2.2Class bad

[gcc r15-1663] libstdc++: Fix std::chrono::tzdb to work with vanguard format

2024-06-26 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:0ca8d56f2085715f27ee536c6c344bc47af49cdd

commit r15-1663-g0ca8d56f2085715f27ee536c6c344bc47af49cdd
Author: Jonathan Wakely 
Date:   Tue Apr 30 09:52:13 2024 +0100

libstdc++: Fix std::chrono::tzdb to work with vanguard format

I found some issues in the std::chrono::tzdb parser by testing the
tzdata "vanguard" format, which uses new features that aren't enabled in
the "main" and "rearguard" data formats.

Since 2024a the keyword "minimum" is no longer valid for the FROM and TO
fields in a Rule line, which means that "m" is now a valid abbreviation
for "maximum". Previously we expected either "mi" or "ma". For backwards
compatibility, a FROM field beginning with "mi" is still supported and
is treated as 1900. The "maximum" keyword is only allowed in TO now,
because it makes no sense in FROM. To support these changes the
minmax_year and minmax_year2 classes for parsing FROM and TO are
replaced with a single years_from_to class that reads both fields.

The vanguard format makes use of %z in Zone FORMAT fields, which caused
an exception to be thrown from ZoneInfo::set_abbrev because no % or /
characters were expected when a Zone doesn't use a named Rule. The
ZoneInfo::to(sys_info&) function now uses format_abbrev_str to replace
any %z with the current offset. Although format_abbrev_str also checks
for %s and STD/DST formats, those only make sense when a named Rule is
in effect, so won't occur when ZoneInfo::to(sys_info&) is used.

This change also implements a feature that has always been missing from
time_zone::_M_get_sys_info: finding the Rule that is active before the
specified time point, so that we can correctly handle %s in the FORMAT
for the first new sys_info that gets created. This requires implementing
a poorly documented feature of zic, to get the LETTERS field from a
later transition, as described at
https://mm.icann.org/pipermail/tz/2024-April/058891.html
In order for this to work we need to be able to distinguish an empty
letters field (as used by CE%sT where the variable part is either empty
or "S") from "the letters field is not known for this transition". The
tzdata file uses "-" for an empty letters field, which libstdc++ was
previously replacing with "" when the Rule was parsed. Instead, we now
preserve the "-" in the Rule object, so that "" can be used for the case
where we don't know the letters (and so need to decide it).

libstdc++-v3/ChangeLog:

* src/c++20/tzdb.cc (minmax_year, minmax_year2): Remove.
(years_from_to): New class replacing minmax_year and
minmax_year2.
(format_abbrev_str, select_std_or_dst_abbrev): Move earlier in
the file. Handle "-" for letters.
(ZoneInfo::to): Use format_abbrev_str to expand %z.
(ZoneInfo::set_abbrev): Remove exception. Change parameter from
reference to value.
(operator>>(istream&, Rule&)): Do not clear letters when it
contains "-".
(time_zone::_M_get_sys_info): Add missing logic to find the Rule
in effect before the time point.
* testsuite/std/time/tzdb/1.cc: Adjust for vanguard format using
"GMT" as the Zone name, not as a Link to "Etc/GMT".
* testsuite/std/time/time_zone/sys_info_abbrev.cc: New test.

Diff:
---
 libstdc++-v3/src/c++20/tzdb.cc | 265 +
 .../std/time/time_zone/sys_info_abbrev.cc  | 106 +
 libstdc++-v3/testsuite/std/time/tzdb/1.cc  |   6 +-
 3 files changed, 274 insertions(+), 103 deletions(-)

diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc
index c7c7cc9deee..7e8cce7ce8c 100644
--- a/libstdc++-v3/src/c++20/tzdb.cc
+++ b/libstdc++-v3/src/c++20/tzdb.cc
@@ -342,51 +342,103 @@ namespace std::chrono
   friend istream& operator>>(istream&, on_day&);
 };
 
-// Wrapper for chrono::year that reads a year, or one of the keywords
-// "minimum" or "maximum", or an unambiguous prefix of a keyword.
-struct minmax_year
+// Wrapper for two chrono::year values, which reads the FROM and TO
+// fields of a Rule line. The FROM field is a year and TO is a year or
+// one of the keywords "maximum" or "only" (or an abbreviation of those).
+// For backwards compatibility, the keyword "minimum" is recognized
+// for FROM and interpreted as 1900.
+struct years_from_to
 {
-  year& y;
+  year& from;
+  year& to;
 
-  friend istream& operator>>(istream& in, minmax_year&& y)
+  friend istream& operator>>(istream& in, years_from_to&& yy)
   {
-   if (ws(in).peek() == 'm') // keywords "minimum" or "maximum"
+   string s;
+   auto c = ws(in).peek();
+   if (c == 'm') [[unlikely]] // keyword "minimum"
  {
-   string s;

[gcc r15-1667] libstdc++: Add script to update docs for a new release branch

2024-06-26 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:0731985920cdeeeb028f03ddb8a7f035565c1594

commit r15-1667-g0731985920cdeeeb028f03ddb8a7f035565c1594
Author: Jonathan Wakely 
Date:   Tue Jun 25 23:59:19 2024 +0100

libstdc++: Add script to update docs for a new release branch

This should be run on a release branch after branching from trunk.
Various links and references to trunk in the docs will be updated to
refer to the new release branch.

libstdc++-v3/ChangeLog:

* scripts/update_release_branch.sh: New file.

Diff:
---
 libstdc++-v3/scripts/update_release_branch.sh | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/libstdc++-v3/scripts/update_release_branch.sh 
b/libstdc++-v3/scripts/update_release_branch.sh
new file mode 100755
index 000..f8109ed0ba3
--- /dev/null
+++ b/libstdc++-v3/scripts/update_release_branch.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+# This should be run on a release branch after branching from trunk.
+# Various links and references to trunk in the docs will be updated to
+# refer to the new release branch.
+
+# The major version of the new release branch.
+major=$1
+(($major)) || { echo "$0: Integer argument expected" >& 2 ; exit 1; }
+
+# This assumes GNU sed
+sed -i "s@^mainline GCC, not in any particular major.\$@the GCC ${major} 
series.@" doc/xml/manual/status_cxx*.xml
+sed -i 
's@https://gcc.gnu.org/cgit/gcc/tree/libstdc++-v3/testsuite/[^"]\+@&?h=releases%2Fgcc-'${major}@
 doc/xml/manual/allocator.xml doc/xml/manual/mt_allocator.xml
+sed -i 
"s@https://gcc.gnu.org/onlinedocs/gcc/Invoking-GCC.html@https://gcc.gnu.org/onlinedocs/gcc-${major}.1.0/gcc/Invoking-GCC.html@";
 doc/xml/manual/using.xml


[gcc r15-1689] libstdc++: Add debug assertions to std::vector [PR103191]

2024-06-27 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:8fd84bc009b3073666a24047c78a04c19eeab752

commit r15-1689-g8fd84bc009b3073666a24047c78a04c19eeab752
Author: Jonathan Wakely 
Date:   Tue Jun 18 10:57:45 2024 +0100

libstdc++: Add debug assertions to std::vector [PR103191]

This adds debug assertions for std::vector element access.

libstdc++-v3/ChangeLog:

PR libstdc++/103191
* include/bits/stl_bvector.h (vector::operator[])
(vector::front, vector::back): Add debug assertions.
* testsuite/23_containers/vector/bool/element_access/constexpr.cc:
Remove dg-error that no longer triggers.

Diff:
---
 libstdc++-v3/include/bits/stl_bvector.h| 30 +-
 .../vector/bool/element_access/constexpr.cc|  2 +-
 2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_bvector.h 
b/libstdc++-v3/include/bits/stl_bvector.h
index 52153cadf8f..8685cc64cc4 100644
--- a/libstdc++-v3/include/bits/stl_bvector.h
+++ b/libstdc++-v3/include/bits/stl_bvector.h
@@ -1084,12 +1084,18 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
   reference
   operator[](size_type __n)
-  { return begin()[__n]; }
+  {
+   __glibcxx_requires_subscript(__n);
+   return begin()[__n];
+  }
 
   _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
   const_reference
   operator[](size_type __n) const
-  { return begin()[__n]; }
+  {
+   __glibcxx_requires_subscript(__n);
+   return begin()[__n];
+  }
 
 protected:
   _GLIBCXX20_CONSTEXPR
@@ -1133,22 +1139,34 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
   reference
   front()
-  { return *begin(); }
+  {
+   __glibcxx_requires_nonempty();
+   return *begin();
+  }
 
   _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
   const_reference
   front() const
-  { return *begin(); }
+  {
+   __glibcxx_requires_nonempty();
+   return *begin();
+  }
 
   _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
   reference
   back()
-  { return *(end() - 1); }
+  {
+   __glibcxx_requires_nonempty();
+   return *(end() - 1);
+  }
 
   _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
   const_reference
   back() const
-  { return *(end() - 1); }
+  {
+   __glibcxx_requires_nonempty();
+   return *(end() - 1);
+  }
 
   _GLIBCXX20_CONSTEXPR
   void
diff --git 
a/libstdc++-v3/testsuite/23_containers/vector/bool/element_access/constexpr.cc 
b/libstdc++-v3/testsuite/23_containers/vector/bool/element_access/constexpr.cc
index bff9f7b4e0f..7c60e5db4d1 100644
--- 
a/libstdc++-v3/testsuite/23_containers/vector/bool/element_access/constexpr.cc
+++ 
b/libstdc++-v3/testsuite/23_containers/vector/bool/element_access/constexpr.cc
@@ -115,4 +115,4 @@ template
   constexpr std::true_type
   access_empty_front() { return {}; }
 
-static_assert( ! access_empty_front() ); // { dg-error "ambiguous" "PR 103191" 
{ target { ! debug_mode } } }
+static_assert( ! access_empty_front() );


[gcc r15-1693] libstdc++: Fix std::codecvt for empty dest [PR37475]

2024-06-27 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:73ad57c244c283bf6da0c16630212f11b945eda5

commit r15-1693-g73ad57c244c283bf6da0c16630212f11b945eda5
Author: Jonathan Wakely 
Date:   Tue Jun 11 16:45:43 2024 +0100

libstdc++: Fix std::codecvt for empty dest 
[PR37475]

For the GNU locale model, codecvt::do_out and codecvt::do_in incorrectly
return 'ok' when the destination range is empty. That happens because
detecting incomplete output is done in the loop body, and the loop is
never even entered if to == to_end.

By restructuring the loop condition so that we check the output range
separately, we can ensure that for a non-empty source range, we always
enter the loop at least once, and detect if the destination range is too
small.

The loops also seem easier to reason about if we return immediately on
any error, instead of checking the result twice on every iteration. We
can use an RAII type to restore the locale before returning, which also
simplifies all the other member functions.

libstdc++-v3/ChangeLog:

PR libstdc++/37475
* config/locale/gnu/codecvt_members.cc (Guard): New RAII type.
(do_out, do_in): Return partial if the destination is empty but
the source is not. Use Guard to restore locale on scope exit.
Return immediately on any conversion error.
(do_encoding, do_max_length, do_length): Use Guard.
* testsuite/22_locale/codecvt/in/char/37475.cc: New test.
* testsuite/22_locale/codecvt/in/wchar_t/37475.cc: New test.
* testsuite/22_locale/codecvt/out/char/37475.cc: New test.
* testsuite/22_locale/codecvt/out/wchar_t/37475.cc: New test.

Diff:
---
 libstdc++-v3/config/locale/gnu/codecvt_members.cc  | 117 +
 .../testsuite/22_locale/codecvt/in/char/37475.cc   |  23 
 .../22_locale/codecvt/in/wchar_t/37475.cc  |  23 
 .../testsuite/22_locale/codecvt/out/char/37475.cc  |  23 
 .../22_locale/codecvt/out/wchar_t/37475.cc |  23 
 5 files changed, 142 insertions(+), 67 deletions(-)

diff --git a/libstdc++-v3/config/locale/gnu/codecvt_members.cc 
b/libstdc++-v3/config/locale/gnu/codecvt_members.cc
index 034713d236e..794f25a5f35 100644
--- a/libstdc++-v3/config/locale/gnu/codecvt_members.cc
+++ b/libstdc++-v3/config/locale/gnu/codecvt_members.cc
@@ -37,8 +37,23 @@ namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
-  // Specializations.
 #ifdef _GLIBCXX_USE_WCHAR_T
+namespace
+{
+  // RAII type for changing and restoring the current thread's locale.
+  struct Guard
+  {
+#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
+explicit Guard(__c_locale loc) : old(__uselocale(loc)) { }
+~Guard() { __uselocale(old); }
+#else
+explicit Guard(__c_locale) { }
+#endif
+__c_locale old;
+  };
+}
+
+  // Specializations.
   codecvt_base::result
   codecvt::
   do_out(state_type& __state, const intern_type* __from,
@@ -46,22 +61,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 extern_type* __to, extern_type* __to_end,
 extern_type*& __to_next) const
   {
-result __ret = ok;
 state_type __tmp_state(__state);
-
-#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
-__c_locale __old = __uselocale(_M_c_locale_codecvt);
-#endif
+Guard g(_M_c_locale_codecvt);
 
 // wcsnrtombs is *very* fast but stops if encounters NUL characters:
 // in case we fall back to wcrtomb and then continue, in a loop.
 // NB: wcsnrtombs is a GNU extension
-for (__from_next = __from, __to_next = __to;
-__from_next < __from_end && __to_next < __to_end
-&& __ret == ok;)
+__from_next = __from;
+__to_next = __to;
+while (__from_next < __from_end)
   {
-   const intern_type* __from_chunk_end = wmemchr(__from_next, L'\0',
- __from_end - __from_next);
+   if (__to_next >= __to_end)
+ return partial;
+
+   const intern_type* __from_chunk_end
+ = wmemchr(__from_next, L'\0', __from_end - __from_next);
if (!__from_chunk_end)
  __from_chunk_end = __from_end;
 
@@ -77,12 +91,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
for (; __from < __from_next; ++__from)
  __to_next += wcrtomb(__to_next, *__from, &__tmp_state);
__state = __tmp_state;
-   __ret = error;
+   return error;
  }
else if (__from_next && __from_next < __from_chunk_end)
  {
__to_next += __conv;
-   __ret = partial;
+   return partial;
  }
else
  {
@@ -90,13 +104,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__to_next += __conv;
  }
 
-   if (__from_next < __from_end && __ret == ok)
+   if (__from_next < __from_end)
  {
extern_type __buf[MB_LEN_MAX];
__tmp_state = __state;
const s

[gcc r15-1714] libstdc++: Do not use C++11 alignof in C++98 mode [PR104395]

2024-06-28 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:03d3aeb0e0fa7dec9bd702cabf57ef73cdc32704

commit r15-1714-g03d3aeb0e0fa7dec9bd702cabf57ef73cdc32704
Author: Jonathan Wakely 
Date:   Wed Jun 26 14:09:07 2024 +0100

libstdc++: Do not use C++11 alignof in C++98 mode [PR104395]

When -faligned-new (or Clang's -faligned-allocation) is used our
allocators try to support extended alignments, gated on the
__cpp_aligned_new macro. However, because they use alignof(_Tp) which is
not a keyword in C++98 mode, using -std=c++98 -faligned-new results in
errors from  and other headers.

We could change them to use __alignof__ instead of alignof, but that
would potentially alter the result of the conditions, because e.g.
alignof(long long) != __alignof__(long long) on some targets. That's
probably not an issue for any types with extended alignment, so maybe it
would be a safe change.

For now, it seems acceptable to just disable the extended alignment
support in C++98 mode, so that -faligned-new enables std::align_val_t
and the corresponding operator new overloads, but doesn't affect
std::allocator, __gnu_cxx::__bitmap_allocator etc.

libstdc++-v3/ChangeLog:

PR libstdc++/104395
* include/bits/new_allocator.h: Disable extended alignment
support in C++98 mode.
* include/bits/stl_tempbuf.h: Likewise.
* include/ext/bitmap_allocator.h: Likewise.
* include/ext/malloc_allocator.h: Likewise.
* include/ext/mt_allocator.h: Likewise.
* include/ext/pool_allocator.h: Likewise.
* testsuite/ext/104395.cc: New test.

Diff:
---
 libstdc++-v3/include/bits/new_allocator.h   | 4 ++--
 libstdc++-v3/include/bits/stl_tempbuf.h | 6 +++---
 libstdc++-v3/include/ext/bitmap_allocator.h | 4 ++--
 libstdc++-v3/include/ext/malloc_allocator.h | 2 +-
 libstdc++-v3/include/ext/mt_allocator.h | 4 ++--
 libstdc++-v3/include/ext/pool_allocator.h   | 4 ++--
 libstdc++-v3/testsuite/ext/104395.cc| 8 
 7 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/libstdc++-v3/include/bits/new_allocator.h 
b/libstdc++-v3/include/bits/new_allocator.h
index 0e90c8819ac..5dcdee11c4d 100644
--- a/libstdc++-v3/include/bits/new_allocator.h
+++ b/libstdc++-v3/include/bits/new_allocator.h
@@ -140,7 +140,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::__throw_bad_alloc();
  }
 
-#if __cpp_aligned_new
+#if __cpp_aligned_new && __cplusplus >= 201103L
if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
  {
std::align_val_t __al = std::align_val_t(alignof(_Tp));
@@ -161,7 +161,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 # define _GLIBCXX_SIZED_DEALLOC(p, n) (p)
 #endif
 
-#if __cpp_aligned_new
+#if __cpp_aligned_new && __cplusplus >= 201103L
if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
  {
_GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n),
diff --git a/libstdc++-v3/include/bits/stl_tempbuf.h 
b/libstdc++-v3/include/bits/stl_tempbuf.h
index 759c4937744..0f267054613 100644
--- a/libstdc++-v3/include/bits/stl_tempbuf.h
+++ b/libstdc++-v3/include/bits/stl_tempbuf.h
@@ -85,7 +85,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
if (__builtin_expect(size_t(__len) > (size_t(-1) / sizeof(_Tp)), 0))
  return 0;
 
-#if __cpp_aligned_new
+#if __cpp_aligned_new && __cplusplus >= 201103L
if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
  return (_Tp*) _GLIBCXX_OPERATOR_NEW(__len * sizeof(_Tp),
  align_val_t(alignof(_Tp)),
@@ -107,7 +107,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 # define _GLIBCXX_SIZED_DEALLOC(T, p, n) (p)
 #endif
 
-#if __cpp_aligned_new
+#if __cpp_aligned_new && __cplusplus >= 201103L
if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
  {
_GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(_Tp, __p, __len),
@@ -168,7 +168,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 inline void
 return_temporary_buffer(_Tp* __p)
 {
-#if __cpp_aligned_new
+#if __cpp_aligned_new && __cplusplus >= 201103L
   if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
_GLIBCXX_OPERATOR_DELETE(__p, align_val_t(alignof(_Tp)));
   else
diff --git a/libstdc++-v3/include/ext/bitmap_allocator.h 
b/libstdc++-v3/include/ext/bitmap_allocator.h
index ef2ee13187b..45b2283ca30 100644
--- a/libstdc++-v3/include/ext/bitmap_allocator.h
+++ b/libstdc++-v3/include/ext/bitmap_allocator.h
@@ -1017,7 +1017,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
if (__n > this->max_size())
  std::__throw_bad_alloc();
 
-#if __cpp_aligned_new
+#if __cpp_aligned_new && __cplusplus >= 201103L
if (alignof(value_type) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
  {
const size_type __b = __n * sizeof(value_type);
@@ -1044,7 +1044,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   {
if (__builtin_expect(__p != 0, true))

[gcc r15-1715] libstdc++: Extend std::equal memcmp optimization to std::byte [PR101485]

2024-06-28 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:fab60eaa94b50b1eea84f0d001004c851d4c781b

commit r15-1715-gfab60eaa94b50b1eea84f0d001004c851d4c781b
Author: Jonathan Wakely 
Date:   Fri Jun 28 11:14:39 2024 +0100

libstdc++: Extend std::equal memcmp optimization to std::byte [PR101485]

We optimize std::equal to memcmp for integers and pointers, which means
that std::byte comparisons generate bigger code than char comparisons.

We can't use memcmp for arbitrary enum types, because they could have an
overloaded operator== that has custom semantics, but we know that
std::byte doesn't do that.

libstdc++-v3/ChangeLog:

PR libstdc++/101485
* include/bits/stl_algobase.h (__equal_aux1): Check for
std::byte as well.
* testsuite/25_algorithms/equal/101485.cc: New test.

Diff:
---
 libstdc++-v3/include/bits/stl_algobase.h |  6 +-
 libstdc++-v3/testsuite/25_algorithms/equal/101485.cc | 11 +++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/stl_algobase.h 
b/libstdc++-v3/include/bits/stl_algobase.h
index 57ff2f7cb08..dec1e4c79d8 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -1257,7 +1257,11 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
   typedef typename iterator_traits<_II1>::value_type _ValueType1;
   const bool __simple = ((__is_integer<_ValueType1>::__value
 #if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
- || __is_pointer(_ValueType1)
+   || __is_pointer(_ValueType1)
+#endif
+#if __glibcxx_byte && __glibcxx_type_trait_variable_templates
+   // bits/cpp_type_traits.h declares std::byte
+   || is_same_v<_ValueType1, byte>
 #endif
 ) && __memcmpable<_II1, _II2>::__value);
   return std::__equal<__simple>::equal(__first1, __last1, __first2);
diff --git a/libstdc++-v3/testsuite/25_algorithms/equal/101485.cc 
b/libstdc++-v3/testsuite/25_algorithms/equal/101485.cc
new file mode 100644
index 000..1fbb40acae9
--- /dev/null
+++ b/libstdc++-v3/testsuite/25_algorithms/equal/101485.cc
@@ -0,0 +1,11 @@
+// { dg-options "-O0" }
+// { dg-do compile { target c++17 } }
+// { dg-final { scan-assembler "memcmp" } }
+
+#include 
+#include 
+
+bool eq(std::byte const* p, std::byte const* q, unsigned n)
+{
+  return std::equal(p, p + n, q);
+}


[gcc r13-8877] libstdc++: Fix std::format for chrono::duration with unsigned rep [PR115668]

2024-06-28 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:4b64a1051a927a65a9acefbbb5714a8118c320bc

commit r13-8877-g4b64a1051a927a65a9acefbbb5714a8118c320bc
Author: Jonathan Wakely 
Date:   Wed Jun 26 20:22:54 2024 +0100

libstdc++: Fix std::format for chrono::duration with unsigned rep [PR115668]

Using std::chrono::abs is only valid if numeric_limits::is_signed
is true, so using it unconditionally made it ill-formed to format a
duration with an unsigned rep.

The duration formatter might as well negate the duration itself instead
of using chrono::abs, because it already needs to check for a negative
value.

libstdc++-v3/ChangeLog:

PR libstdc++/115668
* include/bits/chrono_io.h (formatter::format):
Do not use chrono::abs.
* testsuite/20_util/duration/io.cc: Check formatting a duration
with unsigned rep.

(cherry picked from commit dafa750c8a6f0a088677871bfaad054881737ab1)

Diff:
---
 libstdc++-v3/include/bits/chrono_io.h | 5 -
 libstdc++-v3/testsuite/20_util/duration/io.cc | 6 ++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/chrono_io.h 
b/libstdc++-v3/include/bits/chrono_io.h
index 1838ad1a8c6..d63f7c40d83 100644
--- a/libstdc++-v3/include/bits/chrono_io.h
+++ b/libstdc++-v3/include/bits/chrono_io.h
@@ -1608,7 +1608,10 @@ namespace __format
format(const chrono::duration<_Rep, _Period>& __d,
   basic_format_context<_Out, _CharT>& __fc) const
{
- return _M_f._M_format(chrono::abs(__d), __fc, __d < __d.zero());
+ if constexpr (numeric_limits<_Rep>::is_signed)
+   if (__d < __d.zero())
+ return _M_f._M_format(-__d, __fc, true);
+ return _M_f._M_format(__d, __fc, false);
}
 
 private:
diff --git a/libstdc++-v3/testsuite/20_util/duration/io.cc 
b/libstdc++-v3/testsuite/20_util/duration/io.cc
index 2043f0c4e9d..b7028a4e6c6 100644
--- a/libstdc++-v3/testsuite/20_util/duration/io.cc
+++ b/libstdc++-v3/testsuite/20_util/duration/io.cc
@@ -101,6 +101,12 @@ test_format()
   std::chrono::duration d{0.5};
   s = std::format("{}", d);
   VERIFY( s == "0.5ms" );
+
+  std::chrono::duration u{500}; // PR libstdc++/115668
+  s = std::format("{}", u);
+  VERIFY( s == "500ms" );
+  s = std::format("{:%Q %q}", u);
+  VERIFY( s == "500 ms" );
 }
 
 int main()


[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-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, &Y::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();
 }


[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> );
+}


[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
 // .
 
-#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 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:
   typename _AllocTraits::pointer

[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);


[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:_ZNKSt17__gnu_cxx_ieee1287num_getIwSt19istreambuf_iteratorIwSt11char_traitsIwEEE14_M_extract_intB5cxx11IlEES4_S4_S4_RSt8ios_baseRSt12_Ios_I

[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.


[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-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
 // .
 
-// 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/e

[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
 // .
 
+// { 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/performance/ext/pb_ds/multimap_text_insert_mem.hpp
index 9ce235381bd8..ab755312c69a 100644
--- a/l

[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-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 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()


[gcc r15-2307] libstdc++: Implement LWG 3836 for std::expected bool conversions

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

commit r15-2307-gdca6a9a940e46d0c2d115a4702d648529a42efa9
Author: Jonathan Wakely 
Date:   Wed Jul 24 18:08:03 2024 +0100

libstdc++: Implement LWG 3836 for std::expected bool conversions

libstdc++-v3/ChangeLog:

* include/std/expected (expected): Constrain constructors to
prevent problematic bool conversions, as per LWG 3836.
* testsuite/20_util/expected/lwg3836.cc: New test.

Diff:
---
 libstdc++-v3/include/std/expected  | 59 --
 libstdc++-v3/testsuite/20_util/expected/lwg3836.cc | 34 +
 2 files changed, 77 insertions(+), 16 deletions(-)

diff --git a/libstdc++-v3/include/std/expected 
b/libstdc++-v3/include/std/expected
index 86026c3947a1..2594cfe131c0 100644
--- a/libstdc++-v3/include/std/expected
+++ b/libstdc++-v3/include/std/expected
@@ -314,6 +314,17 @@ namespace __expected
  __guard.release();
}
 }
+
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // 3836. std::expected conversion constructor
+  // expected(const expected&) should take precedence over
+  // expected(U&&) with operator bool
+
+  // If T is cv bool, remove_cvref_t is not a specialization of expected.
+  template
+concept __not_constructing_bool_from_expected
+  = ! is_same_v, bool>
+ || ! __is_expected>;
 }
 /// @endcond
 
@@ -327,26 +338,41 @@ namespace __expected
   static_assert( ! __expected::__is_unexpected> );
   static_assert( __expected::__can_be_unexpected<_Er> );
 
-  template>
+  // If T is not cv bool, converts-from-any-cvref> and
+  // is_constructible, cv expected ref-qual> are false.
+  template,
+  typename = remove_cv_t<_Tp>>
static constexpr bool __cons_from_expected
- = __or_v&>,
-  is_constructible<_Tp, expected<_Up, _Err>>,
-  is_constructible<_Tp, const expected<_Up, _Err>&>,
-  is_constructible<_Tp, const expected<_Up, _Err>>,
-  is_convertible&, _Tp>,
-  is_convertible, _Tp>,
-  is_convertible&, _Tp>,
-  is_convertible, _Tp>,
-  is_constructible<_Unex, expected<_Up, _Err>&>,
-  is_constructible<_Unex, expected<_Up, _Err>>,
-  is_constructible<_Unex, const expected<_Up, _Err>&>,
-  is_constructible<_Unex, const expected<_Up, _Err>>
+ = __or_v&>,
+  is_constructible<_Tp, expected<_Up, _Gr>>,
+  is_constructible<_Tp, const expected<_Up, _Gr>&>,
+  is_constructible<_Tp, const expected<_Up, _Gr>>,
+  is_convertible&, _Tp>,
+  is_convertible, _Tp>,
+  is_convertible&, _Tp>,
+  is_convertible, _Tp>,
+  is_constructible<_Unex, expected<_Up, _Gr>&>,
+  is_constructible<_Unex, expected<_Up, _Gr>>,
+  is_constructible<_Unex, const expected<_Up, _Gr>&>,
+  is_constructible<_Unex, const expected<_Up, _Gr>>
  >;
 
-  template
+  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+  // If t is cv bool, we know it can be constructed from expected,
+  // but we don't want to cause the expected(U&&) constructor to be used,
+  // so we only check the is_constructible, ...> cases.
+  template
+   static constexpr bool __cons_from_expected<_Up, _Gr, _Unex, bool>
+ = __or_v&>,
+  is_constructible<_Unex, expected<_Up, _Gr>>,
+  is_constructible<_Unex, const expected<_Up, _Gr>&>,
+  is_constructible<_Unex, const expected<_Up, _Gr>>
+ >;
+
+  template
constexpr static bool __explicit_conv
  = __or_v<__not_>,
-  __not_>
+  __not_>
  >;
 
   template
@@ -445,8 +471,9 @@ namespace __expected
   template
requires (!is_same_v, expected>)
  && (!is_same_v, in_place_t>)
- && (!__expected::__is_unexpected>)
  && is_constructible_v<_Tp, _Up>
+ && (!__expected::__is_unexpected>)
+ && __expected::__not_constructing_bool_from_expected<_Tp, _Up>
constexpr explicit(!is_convertible_v<_Up, _Tp>)
expected(_Up&& __v)
noexcept(is_nothrow_constructible_v<_Tp, _Up>)
diff --git a/libstdc++-v3/testsuite/20_util/expected/lwg3836.cc 
b/libstdc++-v3/testsuite/20_util/expected/lwg3836.cc
new file mode 100644
index ..cd029c449632
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/expected/lwg3836.cc
@@ -0,0 +1,34 @@
+// { dg-do run { target c++23 } }
+
+#include 
+#include 
+
+constexpr void
+test_convert_contained_value_to_bool()
+{
+  struct BaseError { };
+  struct DerivedError : BaseError { };
+
+  std::expected e = false;
+
+  // Should use expected(const expected&) ctor, not expected(U&&):
+  std::expected e2 = 

[gcc r14-9406] libstdc++: Do not require a time-of-day when parsing sys_days [PR114240]

2024-03-08 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:3e8ee03edd018eed43444755f601cdb9d5931654

commit r14-9406-g3e8ee03edd018eed43444755f601cdb9d5931654
Author: Jonathan Wakely 
Date:   Fri Mar 8 16:15:57 2024 +

libstdc++: Do not require a time-of-day when parsing sys_days [PR114240]

When parsing a std::chrono::sys_days (or a sys_time with an even longer
period) we should not require a time-of-day to be present in the input,
because we can't represent that in the result type anyway.

Rather than trying to decide which specializations should require a
time-of-date and which should not, follow the direction of Howard
Hinnant's date library, which allows extracting a sys_time of any period
from input that only contains a date, defaulting the time-of-day part to
00:00:00. This seems consistent with the intent of the standard, which
says it's an error "If the parse fails to decode a valid date" (i.e., it
doesn't care about decoding a valid time, only a date).

libstdc++-v3/ChangeLog:

PR libstdc++/114240
* include/bits/chrono_io.h (_Parser::operator()): Assume
hours(0) for a time_point, so that a time is not required
to be present.
* testsuite/std/time/parse/114240.cc: New test.

Diff:
---
 libstdc++-v3/include/bits/chrono_io.h   | 12 -
 libstdc++-v3/testsuite/std/time/parse/114240.cc | 36 +
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/chrono_io.h 
b/libstdc++-v3/include/bits/chrono_io.h
index eaa36b8a074..b9eb3d2be53 100644
--- a/libstdc++-v3/include/bits/chrono_io.h
+++ b/libstdc++-v3/include/bits/chrono_io.h
@@ -3157,6 +3157,16 @@ namespace __detail
  minutes __tz_offset = __bad_min;
  basic_string<_CharT, _Traits> __tz_abbr;
 
+ if ((_M_need & _ChronoParts::_TimeOfDay)
+   && (_M_need & _ChronoParts::_Year))
+   {
+ // For time_points assume "00:00:00" is implicitly present,
+ // so we don't fail to parse if it's not (PR libstdc++/114240).
+ // We will still fail to parse if there's no year+month+day.
+ __h = hours(0);
+ __parts = _ChronoParts::_TimeOfDay;
+   }
+
  // bool __is_neg = false; // TODO: how is this handled for parsing?
 
  _CharT __mod{}; // One of 'E' or 'O' or nul.
@@ -4098,7 +4108,7 @@ namespace __detail
  const bool __need_wday = _M_need & _ChronoParts::_Weekday;
 
  // Whether the caller wants _M_sys_days and _M_time.
- // Only true for time_points.
+ // Only true for durations and time_points.
  const bool __need_time = _M_need & _ChronoParts::_TimeOfDay;
 
  if (__need_wday && __wday != __bad_wday)
diff --git a/libstdc++-v3/testsuite/std/time/parse/114240.cc 
b/libstdc++-v3/testsuite/std/time/parse/114240.cc
new file mode 100644
index 000..46310efd09a
--- /dev/null
+++ b/libstdc++-v3/testsuite/std/time/parse/114240.cc
@@ -0,0 +1,36 @@
+// { dg-do run { target c++20 } }
+
+// PR libstdc++/114240 sys_days not being parsed with only a date in the stream
+
+#include 
+#include 
+#include 
+
+template
+void
+test_parse_date_only()
+{
+  using namespace std::chrono;
+
+  using CDays = time_point;
+  CDays td;
+  std::istringstream is("2024-03-05");
+  VERIFY( is >> parse("%Y-%m-%d ", td) );
+  if constexpr (std::is_same_v)
+VERIFY( td == static_cast>(2024y/March/5) );
+  else
+  {
+auto tp = clock_cast(sys_days(2024y/March/5));
+VERIFY( td == time_point_cast(tp) );
+  }
+}
+
+int main()
+{
+  test_parse_date_only();
+  test_parse_date_only();
+  test_parse_date_only();
+  test_parse_date_only();
+  test_parse_date_only();
+  test_parse_date_only();
+}


[gcc r13-8422] libstdc++: Fix a -Wsign-compare warning in std::list

2024-03-12 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:66c55e4f57135f2df09daeea94e0900862c54799

commit r13-8422-g66c55e4f57135f2df09daeea94e0900862c54799
Author: Jonathan Wakely 
Date:   Wed Aug 9 11:28:56 2023 +0100

libstdc++: Fix a -Wsign-compare warning in std::list

libstdc++-v3/ChangeLog:

* include/bits/list.tcc (list::sort(Cmp)): Fix -Wsign-compare
warning for loop condition.

(cherry picked from commit 9bd194434acb47fac80aad45ed04039e0535d1fe)

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

diff --git a/libstdc++-v3/include/bits/list.tcc 
b/libstdc++-v3/include/bits/list.tcc
index 3e5b1f7b972..344386aa4d0 100644
--- a/libstdc++-v3/include/bits/list.tcc
+++ b/libstdc++-v3/include/bits/list.tcc
@@ -654,7 +654,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
{
  // Move all nodes back into *this.
  __carry._M_put_all(end()._M_node);
- for (int __i = 0; __i < sizeof(__tmp)/sizeof(__tmp[0]); ++__i)
+ for (size_t __i = 0; __i < sizeof(__tmp)/sizeof(__tmp[0]); ++__i)
__tmp[__i]._M_put_all(end()._M_node);
  __throw_exception_again;
}


[gcc r13-8428] libstdc++: Remove UB from month and weekday additions and subtractions.

2024-03-12 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:2d3cc6806a9fc3c9ac299bb021819bcb5e7605ea

commit r13-8428-g2d3cc6806a9fc3c9ac299bb021819bcb5e7605ea
Author: Cassio Neri 
Date:   Sun Dec 10 11:31:31 2023 +

libstdc++: Remove UB from month and weekday additions and subtractions.

The following invoke signed integer overflow (UB) [1]:

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

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

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

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

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

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

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

To fix these UB, this patch implements:

  template 
  unsigned __add_modulo(unsigned __x, _T __y);

  template 
  unsigned __sub_modulo(unsigned __x, _T __y);

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

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

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

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

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

libstdc++-v3/ChangeLog:

* include/std/chrono: Fix + and - for months and weekdays.
* testsuite/std/time/month/1.cc: Add constexpr tests against 
overflow.
* testsuite/std/time/month/2.cc: New test for extreme values.
* testsuite/std/time/weekday/1.cc: Add constexpr tests against 
overflow.
* testsuite/std/time/weekday/2.cc: New test for extreme values.

(cherry picked from commit 2cb3d42d3f3e7a5345ee7a6f3676a10c84864d72)

Diff:
---
 libstdc++-v3/include/std/chrono  | 79 +++-
 libstdc++-v3/testsuite/std/time/month/1.cc   | 19 +++
 libstdc++-v3/testsuite/std/time/month/2.cc   | 32 +++
 libstdc++-v3/testsuite/std/time/weekday/1.cc | 16 +-
 libstdc++-v3/testsuite/std/time/weekday/2.cc | 32 +++
 5 files changed, 151 insertions(+), 27 deletions(-)

diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono
index c303eedd464..b2abf90cf71 100644
--- a/libstdc++-v3/include/std/chrono
+++ b/libstdc++-v3/include/std/chrono
@@ -503,18 +503,47 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 namespace __detail
 {
-  // Compute the remainder of the Euclidean division of __n divided by __d.
-  // Euclidean division truncates toward negative infinity and always
-  // produces a remainder in the range of [0,__d-1] (whereas standard
-  // division truncates toward zero and yields a nonpositive remainder
-  // for negative __n).
+  // Helper to __add_modulo and __sub_modulo.
+  template 
+  consteval auto
+  __modulo_offset()
+  {
+   using _Up = make_unsigned_t<_Tp>;
+   auto constexpr __a = _Up(-1) - _Up(255 + __d - 2);
+   auto constexpr __b = _Up(__d * (__a / __d) - 1);
+   // Notice: b <= a - 1 <= _Up(-1) - (255 + d - 1) and b % d = d - 1.
+   return _Up(-1) - __b; // >= 255 + d - 1
+  }
+
+  // Compute the remainder of the Euclidean division of __x + __y divided 
by
+  // __d without overflowing.  Typically, __x <= 255 + d - 1 is sum of
+  // weekday/month with a shift in [0, d - 1] and __y is a duration count.
+  template 
+  constexpr unsigned
+  __add_modulo(unsigned __x, _Tp __y)
+  {
+   using _Up = make_unsigned_t<_Tp>;
+   // For __y >= 0, _Up(__y) has the same mathematical value as __y and
+   // this function simply returns (__x + _Up(__y)) % d.  Typically, this
+   // doesn't overflow since the range of _Up contains many more positive
+

[gcc r13-8430] libstdc++: Fix std::basic_format_arg::handle for BasicFormatters

2024-03-12 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:826f7e5ca3bddf3ff82bc52c09e84f5d35b24dbf

commit r13-8430-g826f7e5ca3bddf3ff82bc52c09e84f5d35b24dbf
Author: Jonathan Wakely 
Date:   Wed Feb 28 15:05:08 2024 +

libstdc++: Fix std::basic_format_arg::handle for BasicFormatters

std::basic_format_arg::handle is supposed to format its value as const
if that is valid, to reduce the number of instantiations of the
formatter's format function. I made a silly typo so that it checks
formattable_with not formattable_with,
which breaks support for BasicFormatters i.e. ones that can only format
non-const types.

There's a static_assert in the handle constructor which is supposed to
improve diagnostics for trying to format a const argument with a
formatter that doesn't support it. That condition can't fail, because
the std::basic_format_arg constructor is already constrained to check
that the argument type is formattable. The static_assert can be removed.

libstdc++-v3/ChangeLog:

* include/std/format (basic_format_arg::handle::__maybe_const_t):
Fix condition to check if const type is formattable.
(basic_format_arg::handle::handle(T&)): Remove redundant
static_assert.
* testsuite/std/format/formatter/basic.cc: New test.

(cherry picked from commit 02ca9d3f0c5d2b0255df28f021834dd67ad79bc2)

Diff:
---
 libstdc++-v3/include/std/format|  6 +-
 .../testsuite/std/format/formatter/basic.cc| 24 ++
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index 7bcaddb3715..a938d65a7b9 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -2866,7 +2866,7 @@ namespace __format
// Format as const if possible, to reduce instantiations.
template
  using __maybe_const_t
-   = __conditional_t<__formattable<_Tp>, const _Tp, _Tp>;
+   = __conditional_t<__formattable, const _Tp, _Tp>;
 
template
  static void
@@ -2884,10 +2884,6 @@ namespace __format
  explicit
  handle(_Tp& __val) noexcept
  {
-   if constexpr (!__formattable)
- static_assert(!is_const_v<_Tp>, "std::format argument must be "
- "non-const for this type");
-
this->_M_ptr = __builtin_addressof(__val);
auto __func = _S_format<__maybe_const_t<_Tp>>;
this->_M_func = reinterpret_cast(__func);
diff --git a/libstdc++-v3/testsuite/std/format/formatter/basic.cc 
b/libstdc++-v3/testsuite/std/format/formatter/basic.cc
new file mode 100644
index 000..56c18864135
--- /dev/null
+++ b/libstdc++-v3/testsuite/std/format/formatter/basic.cc
@@ -0,0 +1,24 @@
+// { dg-do compile { target c++20 } }
+
+// BasicFormatter requirements do not require a const parameter.
+
+#include 
+
+struct X { };
+
+template<> struct std::formatter
+{
+  constexpr auto parse(format_parse_context& ctx)
+  { return ctx.begin(); }
+
+  // Takes non-const X&
+  format_context::iterator format(X&, format_context& ctx) const
+  {
+auto out = ctx.out();
+*out++ = 'x';
+return out;
+  }
+};
+
+X x;
+auto s = std::format("{}", x);


[gcc r12-10209] libstdc++: Remove unnecessary "& 1" from year_month_day_last::day()

2024-03-13 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:d472bd346ddd1d679ecd3ff392fda98343ed7a36

commit r12-10209-gd472bd346ddd1d679ecd3ff392fda98343ed7a36
Author: Cassio Neri 
Date:   Sat Nov 11 16:44:58 2023 +

libstdc++: Remove unnecessary "& 1" from year_month_day_last::day()

When year_month_day_last::day() was implemented, Dr. Matthias Kretz realised
that the operation "& 1" wasn't necessary but we did not patch it at that
time. This patch removes the unnecessary operation.

libstdc++-v3/ChangeLog:

* include/std/chrono (year_month_day_last::day): Remove &1.

(cherry picked from commit b011535456396a6846ff24fb5b1baea8fe0a33b1)

Diff:
---
 libstdc++-v3/include/std/chrono | 24 ++--
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono
index f5a88331b1b..5c1b7a8daf4 100644
--- a/libstdc++-v3/include/std/chrono
+++ b/libstdc++-v3/include/std/chrono
@@ -1468,22 +1468,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   {
const auto __m = static_cast(month());
 
-   // Excluding February, the last day of month __m is either 30 or 31 or,
-   // in another words, it is 30 + b = 30 | b, where b is in {0, 1}.
+   // The result is unspecified if __m < 1 or __m > 12.  Hence, assume
+   // 1 <= __m <= 12.  For __m != 2, day() == 30 or day() == 31 or, in
+   // other words, day () == 30 | b, where b is in {0, 1}.
 
-   // If __m in {1, 3, 4, 5, 6, 7}, then b is 1 if, and only if __m is odd.
-   // Hence, b = __m & 1 = (__m ^ 0) & 1.
+   // If __m in {1, 3, 4, 5, 6, 7}, then b is 1 if, and only if, __m is
+   // odd.  Hence, b = __m & 1 = (__m ^ 0) & 1.
 
-   // If __m in {8, 9, 10, 11, 12}, then b is 1 if, and only if __m is 
even.
-   // Hence, b = (__m ^ 1) & 1.
+   // If __m in {8, 9, 10, 11, 12}, then b is 1 if, and only if, __m is
+   // even.  Hence, b = (__m ^ 1) & 1.
 
// Therefore, b = (__m ^ c) & 1, where c = 0, if __m < 8, or c = 1 if
// __m >= 8, that is, c = __m >> 3.
 
-   // The above mathematically justifies this implementation whose
-   // performance does not depend on look-up tables being on the L1 cache.
-   return chrono::day{__m != 2 ? ((__m ^ (__m >> 3)) & 1) | 30
-   : _M_y.is_leap() ? 29 : 28};
+   // Since 30 = (0)_2 and __m <= 31 = (1)_2, the "& 1" in b's
+   // calculation is unnecessary.
+
+   // The performance of this implementation does not depend on look-up
+   // tables being on the L1 cache.
+   return chrono::day{__m != 2 ? (__m ^ (__m >> 3)) | 30
+ : _M_y.is_leap() ? 29 : 28};
   }
 
   constexpr


[gcc r12-10208] libstdc++: Fix UB in weekday::weekday(sys_days) and add test

2024-03-13 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:2d5eee092aa3cbfb50496ed4b224600de2e7fb08

commit r12-10208-g2d5eee092aa3cbfb50496ed4b224600de2e7fb08
Author: Cassio Neri 
Date:   Sun Nov 12 01:33:52 2023 +

libstdc++: Fix UB in weekday::weekday(sys_days) and add test

The following has undefined behaviour (signed overflow) [1]:
weekday max{sys_days{days{numeric_limits::max()}}};

The issue is in this line when __n is very large and __n + 4 overflows:
return weekday(__n >= -4 ? (__n + 4) % 7 : (__n + 5) % 7 + 6);

In addition to fixing this bug, the new implementation makes the compiler 
emit
shorter and branchless code for x86-64 and ARM [2].

[1] https://godbolt.org/z/1s5bv7KfT
[2] https://godbolt.org/z/zKsabzrhs

libstdc++-v3/ChangeLog:

* include/std/chrono (weekday::_S_from_days): Fix UB.
* testsuite/std/time/weekday/1.cc: Add test for overflow.

(cherry picked from commit f6ce081d0ffb5f25d71eb2f30fcfdff7f20dba22)

Diff:
---
 libstdc++-v3/include/std/chrono  | 11 +--
 libstdc++-v3/testsuite/std/time/weekday/1.cc |  9 +
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono
index 83e0e5b8bd0..f5a88331b1b 100644
--- a/libstdc++-v3/include/std/chrono
+++ b/libstdc++-v3/include/std/chrono
@@ -573,8 +573,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   static constexpr weekday
   _S_from_days(const days& __d)
   {
-   auto __n = __d.count();
-   return weekday(__n >= -4 ? (__n + 4) % 7 : (__n + 5) % 7 + 6);
+   using _Rep = days::rep;
+   using _URep = make_unsigned_t<_Rep>;
+   const auto __n = __d.count();
+   const auto __m = static_cast<_URep>(__n);
+
+   // 1970-01-01 (__n =  0, __m = 0) -> Thursday (4)
+   // 1969-31-12 (__n = -1, __m = _URep(-1)) -> Wednesday (3)
+   const auto __offset = __n >= 0 ? _URep(4) : 3 - _URep(-1) % 7 - 7;
+   return weekday((__m + __offset) % 7);
   }
 
 public:
diff --git a/libstdc++-v3/testsuite/std/time/weekday/1.cc 
b/libstdc++-v3/testsuite/std/time/weekday/1.cc
index 6e7989ec103..96cd5ebc0d8 100644
--- a/libstdc++-v3/testsuite/std/time/weekday/1.cc
+++ b/libstdc++-v3/testsuite/std/time/weekday/1.cc
@@ -21,6 +21,7 @@
 // Class template day [time.cal.weekday]
 
 #include 
+#include 
 
 constexpr void
 constexpr_weekday()
@@ -38,6 +39,14 @@ constexpr_weekday()
   static_assert(weekday{3}[2].weekday() == weekday{3});
   static_assert(weekday{3}[last].weekday() == weekday{3});
 
+  // Test for UB (overflow).
+  {
+using rep = days::rep;
+using std::numeric_limits;
+constexpr weekday max{sys_days{days{numeric_limits::max()}}};
+constexpr weekday min{sys_days{days{numeric_limits::min()}}};
+  }
+
   static_assert(weekday{sys_days{1900y/January/1}} == Monday);
   static_assert(weekday{sys_days{1970y/January/1}} == Thursday);
   static_assert(weekday{sys_days{2020y/August/21}} == Friday);


[gcc r14-9455] libstdc++: Document that _GLIBCXX_CONCEPT_CHECKS might be removed in future

2024-03-13 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:d6490157b3e7ec45a024d1a2acc96e53934dbb0e

commit r14-9455-gd6490157b3e7ec45a024d1a2acc96e53934dbb0e
Author: Jonathan Wakely 
Date:   Thu Mar 7 12:00:55 2024 +

libstdc++: Document that _GLIBCXX_CONCEPT_CHECKS might be removed in future

The macro-based concept checks are unmaintained and do not support C++11
or later, so reject valid code. If nobody plans to update them we should
consider removing them. Alternatively, we could ignore the macro for
C++11 and later, so they have no effect and don't reject valid code.

libstdc++-v3/ChangeLog:

* doc/xml/manual/debug.xml: Document that concept checking might
be removed in future.
* doc/xml/manual/extensions.xml: Likewise.

Diff:
---
 libstdc++-v3/doc/xml/manual/debug.xml  |  2 ++
 libstdc++-v3/doc/xml/manual/extensions.xml | 18 --
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/libstdc++-v3/doc/xml/manual/debug.xml 
b/libstdc++-v3/doc/xml/manual/debug.xml
index 42d4d32aa29..7f6d0876fc6 100644
--- a/libstdc++-v3/doc/xml/manual/debug.xml
+++ b/libstdc++-v3/doc/xml/manual/debug.xml
@@ -351,6 +351,8 @@
 
The Compile-Time
   Checks extension has compile-time checks for many algorithms.
+  These checks were designed for C++98 and have not been updated to work
+  with C++11 and later standards. They might be removed at a future date.
   
 
 
diff --git a/libstdc++-v3/doc/xml/manual/extensions.xml 
b/libstdc++-v3/doc/xml/manual/extensions.xml
index d4fe2f509d4..490a50cc331 100644
--- a/libstdc++-v3/doc/xml/manual/extensions.xml
+++ b/libstdc++-v3/doc/xml/manual/extensions.xml
@@ -77,8 +77,7 @@ extensions, be aware of two things:
   object file.  The checks are also cleaner and easier to read and
   understand.

-   They are off by default for all versions of GCC from 3.0 to 3.4 (the
-  latest release at the time of writing).
+   They are off by default for all GCC 3.0 and all later versions.
   They can be enabled at configure time with
   --enable-concept-checks.
   You can enable them on a per-translation-unit basis with
@@ -89,10 +88,17 @@ extensions, be aware of two things:

 
Please note that the concept checks only validate the requirements
-   of the old C++03 standard. C++11 was expected to have first-class
-   support for template parameter constraints based on concepts in the core
-   language. This would have obviated the need for the library-simulated 
concept
-   checking described above, but was not part of C++11.
+   of the old C++03 standard and reject some valid code that meets the relaxed
+   requirements of C++11 and later standards.
+   C++11 was expected to have first-class support for template parameter
+   constraints based on concepts in the core language.
+   This would have obviated the need for the library-simulated concept checking
+   described above, but was not part of C++11.
+   C++20 adds a different model of concepts, which is now used to constrain
+   some new parts of the C++20 library, e.g. the
+    header and the new overloads in the
+    header for working with ranges.
+   The old library-simulated concept checks might be removed at a future date.

 
 


[gcc r14-9457] libstdc++: Move test error_category to global scope

2024-03-13 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:a8c7c3a40953e34f57278d224a07dc3698c64a84

commit r14-9457-ga8c7c3a40953e34f57278d224a07dc3698c64a84
Author: Jonathan Wakely 
Date:   Wed Mar 13 10:02:12 2024 +

libstdc++: Move test error_category to global scope

A recent GDB change causes this test to fail due to missing RTTI for the
custom_cast type. This is presumably because the custom_cat type was
defined as a local class, so has no linkage. Moving it to local scope
seems to fix the test regressions, and probably makes the test more
realistic as a local class with no linkage isn't practical to use as an
error category that almost certainly needs to be referred to in other
scopes.

libstdc++-v3/ChangeLog:

* testsuite/libstdc++-prettyprinters/cxx11.cc: Move custom_cat
to namespace scope.

Diff:
---
 libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc 
b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
index f867ea18306..2f75d12703c 100644
--- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
+++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
@@ -63,6 +63,11 @@ struct datum
 
 std::unique_ptr global;
 
+struct custom_cat : std::error_category {
+  const char* name() const noexcept { return "miaow"; }
+  std::string message(int) const { return ""; }
+};
+
 int
 main()
 {
@@ -179,10 +184,7 @@ main()
   std::error_condition ecinval = 
std::make_error_condition(std::errc::invalid_argument);
   // { dg-final { note-test ecinval {std::error_condition = {"generic": 
EINVAL}} } }
 
-  struct custom_cat : std::error_category {
-const char* name() const noexcept { return "miaow"; }
-std::string message(int) const { return ""; }
-  } cat;
+  custom_cat cat;
   std::error_code emiaow(42, cat);
   // { dg-final { note-test emiaow {std::error_code = {custom_cat: 42}} } }
   std::error_condition ecmiaow(42, cat);


[gcc r14-9473] libstdc++: Add missing clear_padding in __atomic_float constructor

2024-03-14 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:0adc8c5f146b108f99c4df09e43276e3a2419262

commit r14-9473-g0adc8c5f146b108f99c4df09e43276e3a2419262
Author: xndcn 
Date:   Fri Feb 16 11:00:13 2024 +

libstdc++: Add missing clear_padding in __atomic_float constructor

For 80-bit long double we need to clear the padding bits on
construction.

libstdc++-v3/ChangeLog:

* include/bits/atomic_base.h (__atomic_float::__atomic_float(Fp)):
Clear padding.
* testsuite/29_atomics/atomic_float/compare_exchange_padding.cc:
New test.

Signed-off-by: xndcn 

Reviewed-by: Jonathan Wakely 

Diff:
---
 libstdc++-v3/include/bits/atomic_base.h|  2 +-
 .../atomic_float/compare_exchange_padding.cc   | 53 ++
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/atomic_base.h 
b/libstdc++-v3/include/bits/atomic_base.h
index b857b441169..dd360302f80 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -1283,7 +1283,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   constexpr
   __atomic_float(_Fp __t) : _M_fp(__t)
-  { }
+  { __atomic_impl::__clear_padding(_M_fp); }
 
   __atomic_float(const __atomic_float&) = delete;
   __atomic_float& operator=(const __atomic_float&) = delete;
diff --git 
a/libstdc++-v3/testsuite/29_atomics/atomic_float/compare_exchange_padding.cc 
b/libstdc++-v3/testsuite/29_atomics/atomic_float/compare_exchange_padding.cc
new file mode 100644
index 000..49626ac6651
--- /dev/null
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_float/compare_exchange_padding.cc
@@ -0,0 +1,53 @@
+// { dg-do run { target c++20 } }
+// { dg-options "-O0" }
+// { dg-additional-options "[atomic_link_flags [get_multilibs]] -latomic" }
+
+#include 
+#include 
+#include 
+#include 
+
+template
+void __attribute__((noinline,noipa))
+fill_padding(T& f)
+{
+  T mask;
+  std::memset(&mask, 0xff, sizeof(T));
+  __builtin_clear_padding(&mask);
+  unsigned char* ptr_f = (unsigned char*)&f;
+  unsigned char* ptr_mask = (unsigned char*)&mask;
+  for (unsigned i = 0; i < sizeof(T); i++)
+  {
+if (ptr_mask[i] == 0x00)
+{
+  ptr_f[i] = 0xff;
+}
+  }
+}
+
+void
+test01()
+{
+  // test for long double with padding (float80)
+  if constexpr (std::numeric_limits::digits == 64)
+  {
+long double f = 0.5f; // long double has padding bits on x86
+fill_padding(f);
+std::atomic as{ f }; // padding cleared on constructor
+long double t = 1.5;
+
+as.fetch_add(t);
+long double s = f + t;
+t = as.load();
+VERIFY(s == t); // padding ignored on comparison
+fill_padding(s);
+VERIFY(as.compare_exchange_weak(s, f)); // padding cleared on cmpexchg
+fill_padding(f);
+VERIFY(as.compare_exchange_strong(f, t)); // padding cleared on cmpexchg
+  }
+}
+
+int main()
+{
+  test01();
+}


[gcc r14-9478] libstdc++: Add nodiscard in

2024-03-14 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:df483ebd24689a3bebfae2089637a00eca0e5a12

commit r14-9478-gdf483ebd24689a3bebfae2089637a00eca0e5a12
Author: Jonathan Wakely 
Date:   Mon Feb 26 13:17:13 2024 +

libstdc++: Add nodiscard in 

Add the [[nodiscard]] attribute to several functions in .
These all have no side effects and are only called for their return
value (e.g. std::count) or produce a result that must not be discarded
for correctness (e.g. std::remove).

I was intending to add the attribute to a number of other functions like
std::copy_if, std::unique_copy, std::set_union, and std::set_difference.
I stopped when I noticed that MSVC doesn't use it on those functions,
which I suspect is because they're often used with an insert iterator
(e.g. std::back_insert_iterator). In that case it doesn't matter if
you discard the result, because you have the container to tell you how
many elements were copied to the output range.

libstdc++-v3/ChangeLog:

* include/bits/stl_algo.h (find_end, all_of, none_of, any_of)
(find_if_not, is_partitioned, partition_point, remove)
(remove_if, unique, lower_bound, upper_bound, equal_range)
(binary_search, includes, is_sorted, is_sorted_until, minmax)
(minmax_element, is_permutation, clamp, find_if, find_first_of)
(adjacent_find, count, count_if, search, search_n, min_element)
(max_element): Add nodiscard attribute.
* include/bits/stl_algobase.h (min, max, lower_bound, equal)
(lexicographical_compare, lexicographical_compare_three_way)
(mismatch): Likewise.
* include/bits/stl_heap.h (is_heap, is_heap_until): Likewise.
* testsuite/25_algorithms/equal/debug/1_neg.cc: Add dg-warning.
* testsuite/25_algorithms/equal/debug/2_neg.cc: Likewise.
* testsuite/25_algorithms/equal/debug/3_neg.cc: Likewise.
* testsuite/25_algorithms/find_first_of/concept_check_1.cc:
Likewise.
* testsuite/25_algorithms/is_permutation/2.cc: Likewise.
* testsuite/25_algorithms/lexicographical_compare/71545.cc:
Likewise.
* testsuite/25_algorithms/lower_bound/33613.cc: Likewise.
* testsuite/25_algorithms/lower_bound/debug/irreflexive.cc:
Likewise.
* testsuite/25_algorithms/lower_bound/debug/partitioned_neg.cc:
Likewise.
* testsuite/25_algorithms/lower_bound/debug/partitioned_pred_neg.cc:
Likewise.
* testsuite/25_algorithms/minmax/3.cc: Likewise.
* testsuite/25_algorithms/search/78346.cc: Likewise.
* testsuite/25_algorithms/search_n/58358.cc: Likewise.
* testsuite/25_algorithms/unique/1.cc: Likewise.
* testsuite/25_algorithms/unique/11480.cc: Likewise.
* testsuite/25_algorithms/upper_bound/33613.cc: Likewise.
* testsuite/25_algorithms/upper_bound/debug/partitioned_neg.cc:
Likewise.
* testsuite/25_algorithms/upper_bound/debug/partitioned_pred_neg.cc:
Likewise.
* testsuite/ext/concept_checks.cc: Likewise.
* testsuite/ext/is_heap/47709.cc: Likewise.
* testsuite/ext/is_sorted/cxx0x.cc: Likewise.

Diff:
---
 libstdc++-v3/include/bits/stl_algo.h   | 102 ++---
 libstdc++-v3/include/bits/stl_algobase.h   |  32 +++
 libstdc++-v3/include/bits/stl_heap.h   |   8 +-
 .../testsuite/25_algorithms/equal/debug/1_neg.cc   |   1 +
 .../testsuite/25_algorithms/equal/debug/2_neg.cc   |   1 +
 .../testsuite/25_algorithms/equal/debug/3_neg.cc   |   1 +
 .../25_algorithms/find_first_of/concept_check_1.cc |   1 +
 .../testsuite/25_algorithms/is_permutation/2.cc|   1 +
 .../25_algorithms/lexicographical_compare/71545.cc |   1 +
 .../testsuite/25_algorithms/lower_bound/33613.cc   |   1 +
 .../25_algorithms/lower_bound/debug/irreflexive.cc |   1 +
 .../lower_bound/debug/partitioned_neg.cc   |   1 +
 .../lower_bound/debug/partitioned_pred_neg.cc  |   1 +
 libstdc++-v3/testsuite/25_algorithms/minmax/3.cc   |   1 +
 .../testsuite/25_algorithms/search/78346.cc|   1 +
 .../testsuite/25_algorithms/search_n/58358.cc  |   1 +
 libstdc++-v3/testsuite/25_algorithms/unique/1.cc   |   1 +
 .../testsuite/25_algorithms/unique/11480.cc|   2 +-
 .../testsuite/25_algorithms/upper_bound/33613.cc   |   1 +
 .../upper_bound/debug/partitioned_neg.cc   |   1 +
 .../upper_bound/debug/partitioned_pred_neg.cc  |   1 +
 libstdc++-v3/testsuite/ext/concept_checks.cc   |   4 +
 libstdc++-v3/testsuite/ext/is_heap/47709.cc|   1 +
 libstdc++-v3/testsuite/ext/is_sorted/cxx0x.cc  |   1 +
 24 files changed, 95 insertions(+), 72 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_algo.h 
b/libstdc++-v3/include/bits/stl_algo.h
index 7a0cf6b673

[gcc r13-8441] libstdc++: Fix typo in C++20 status table

2024-03-15 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:d92942efb33c84275521186d351bee854f39c4f2

commit r13-8441-gd92942efb33c84275521186d351bee854f39c4f2
Author: Jonathan Wakely 
Date:   Fri Mar 15 17:04:22 2024 +

libstdc++: Fix typo in C++20 status table

libstdc++-v3/ChangeLog:

* doc/xml/manual/status_cxx2023.xml: Close parenthesis.
* doc/html/manual/status.html: Regenerate.

Diff:
---
 libstdc++-v3/doc/html/manual/status.html   | 2 +-
 libstdc++-v3/doc/xml/manual/status_cxx2023.xml | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/doc/html/manual/status.html 
b/libstdc++-v3/doc/html/manual/status.html
index c732f35da0c..6f5c0238d8e 100644
--- a/libstdc++-v3/doc/html/manual/status.html
+++ b/libstdc++-v3/doc/html/manual/status.html
@@ -1903,7 +1903,7 @@ or any notes about the implementation.
 https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2255r2.html"; 
target="_top">
 P2255R2
 
-   13.1 (missing changes to std::tuple  __cpp_lib_reference_from_temporary >= 202202L 

+   13.1 (missing changes to std::tuple)  __cpp_lib_reference_from_temporary >= 202202L 

 Strings and text
string contains function 
 https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1679r3.html"; 
target="_top">
diff --git a/libstdc++-v3/doc/xml/manual/status_cxx2023.xml 
b/libstdc++-v3/doc/xml/manual/status_cxx2023.xml
index d1eacbfb0d6..a3105bcde19 100644
--- a/libstdc++-v3/doc/xml/manual/status_cxx2023.xml
+++ b/libstdc++-v3/doc/xml/manual/status_cxx2023.xml
@@ -491,7 +491,7 @@ or any notes about the implementation.
 P2255R2
 
   
-   13.1 (missing changes to std::tuple 

+   13.1 (missing changes to std::tuple) 

__cpp_lib_reference_from_temporary >= 202202L 

 


[gcc r12-10221] libstdc++: Add missing std::tuple constructor [PR114147]

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:fbdeeb1604d52a8ece8631f70ecd64d925d31741

commit r12-10221-gfbdeeb1604d52a8ece8631f70ecd64d925d31741
Author: Jonathan Wakely 
Date:   Fri Mar 1 11:16:58 2024 +

libstdc++: Add missing std::tuple constructor [PR114147]

I caused a regression with commit r10-908 by adding a constraint to the
non-explicit allocator-extended default constructor, but seemingly
forgot to add an explicit overload with the corresponding constraint.

libstdc++-v3/ChangeLog:

PR libstdc++/114147
* include/std/tuple (tuple::tuple(allocator_arg_t, const Alloc&)):
Add missing overload of allocator-extended default constructor.
(tuple::tuple(allocator_arg_t, const Alloc&)): Likewise.
* testsuite/20_util/tuple/cons/114147.cc: New test.

(cherry picked from commit 0a545ac7000501844670add0b3560ebdbcb123c6)

Diff:
---
 libstdc++-v3/include/std/tuple  | 14 ++
 libstdc++-v3/testsuite/20_util/tuple/cons/114147.cc | 15 +++
 2 files changed, 29 insertions(+)

diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple
index 6d0060a191c..04b77113a84 100644
--- a/libstdc++-v3/include/std/tuple
+++ b/libstdc++-v3/include/std/tuple
@@ -801,6 +801,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
tuple(allocator_arg_t __tag, const _Alloc& __a)
: _Inherited(__tag, __a) { }
 
+  template::value> = false>
+   _GLIBCXX20_CONSTEXPR
+   explicit
+   tuple(allocator_arg_t __tag, const _Alloc& __a)
+   : _Inherited(__tag, __a) { }
+
   template= 1),
   _ImplicitCtor<_NotEmpty, const _Elements&...> = true>
_GLIBCXX20_CONSTEXPR
@@ -1155,6 +1162,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
tuple(allocator_arg_t __tag, const _Alloc& __a)
: _Inherited(__tag, __a) { }
 
+  template::value, _T1, _T2> = false>
+   _GLIBCXX20_CONSTEXPR
+   explicit
+   tuple(allocator_arg_t __tag, const _Alloc& __a)
+   : _Inherited(__tag, __a) { }
+
   template = true>
_GLIBCXX20_CONSTEXPR
diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/114147.cc 
b/libstdc++-v3/testsuite/20_util/tuple/cons/114147.cc
new file mode 100644
index 000..916e7204964
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/tuple/cons/114147.cc
@@ -0,0 +1,15 @@
+// { dg-do compile { target c++11 } }
+
+// PR libstdc++/114147
+// tuple allocator-extended ctor requires non-explicit default ctor
+
+#include 
+#include 
+
+struct X { explicit X(); };
+
+std::allocator a;
+std::tuple t0(std::allocator_arg, a);
+std::tuple t1(std::allocator_arg, a);
+std::tuple t2(std::allocator_arg, a);
+std::tuple t3(std::allocator_arg, a);


[gcc r12-10222] libstdc++: Simplify lifetime of eh_globals variable [PR107500]

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:d9076dafa12c93e96b349035fb59050151403866

commit r12-10222-gd9076dafa12c93e96b349035fb59050151403866
Author: Jonathan Wakely 
Date:   Thu Nov 3 11:48:57 2022 +

libstdc++: Simplify lifetime of eh_globals variable [PR107500]

Since this is a trivial type, we probably don't need to do anything to
ensure it's still accessible after other static dtors.

libstdc++-v3/ChangeLog:

PR libstdc++/107500
* libsupc++/eh_globals.cc (eh_globals): Remove immortalizing
wrapper.
(__cxxabiv1::__cxa_get_globals_fast): Adjust.
(__cxxabiv1::__cxa_get_globals): Adjust.

(cherry picked from commit 418999fe382c608facf57f96b53a9cb12d2fdd20)

Diff:
---
 libstdc++-v3/libsupc++/eh_globals.cc | 21 +
 1 file changed, 5 insertions(+), 16 deletions(-)

diff --git a/libstdc++-v3/libsupc++/eh_globals.cc 
b/libstdc++-v3/libsupc++/eh_globals.cc
index 0aadb692a96..74e8a454ecc 100644
--- a/libstdc++-v3/libsupc++/eh_globals.cc
+++ b/libstdc++-v3/libsupc++/eh_globals.cc
@@ -70,19 +70,8 @@ __cxxabiv1::__cxa_get_globals() _GLIBCXX_NOTHROW
 
 namespace
 {
-  struct constant_init
-  {
-union {
-  unsigned char unused;
-  __cxa_eh_globals obj;
-};
-constexpr constant_init() : obj() { }
-
-~constant_init() { /* do nothing, union member is not destroyed */ }
-  };
-
   // Single-threaded fallback buffer.
-  __constinit constant_init eh_globals;
+  __constinit __cxa_eh_globals eh_globals;
 }
 
 #if __GTHREADS
@@ -143,7 +132,7 @@ __cxxabiv1::__cxa_get_globals_fast() _GLIBCXX_NOTHROW
   if (init._S_init)
 g = static_cast<__cxa_eh_globals*>(__gthread_getspecific(init._M_key));
   else
-g = &eh_globals.obj;
+g = &eh_globals;
   return g;
 }
 
@@ -168,7 +157,7 @@ __cxxabiv1::__cxa_get_globals() _GLIBCXX_NOTHROW
}
 }
   else
-g = &eh_globals.obj;
+g = &eh_globals;
   return g;
 }
 
@@ -176,11 +165,11 @@ __cxxabiv1::__cxa_get_globals() _GLIBCXX_NOTHROW
 
 extern "C" __cxa_eh_globals*
 __cxxabiv1::__cxa_get_globals_fast() _GLIBCXX_NOTHROW
-{ return &eh_globals.obj; }
+{ return &eh_globals; }
 
 extern "C" __cxa_eh_globals*
 __cxxabiv1::__cxa_get_globals() _GLIBCXX_NOTHROW
-{ return &eh_globals.obj; }
+{ return &eh_globals; }
 
 #endif


[gcc r12-10223] libstdc++: Update outdated docs on contributing

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:57f4c935f915454879a0d13f0319ba09c9c01309

commit r12-10223-g57f4c935f915454879a0d13f0319ba09c9c01309
Author: Jonathan Wakely 
Date:   Wed Feb 28 11:24:47 2024 +

libstdc++: Update outdated docs on contributing

We don't want a separate ChangeLog submission now.

libstdc++-v3/ChangeLog:

* doc/xml/manual/appendix_contributing.xml: Replace outdated
info on ChangeLog entries.
* doc/html/manual/appendix_contributing.html: Regenerate.

(cherry picked from commit 7c7c937b5e71cf2b53f462cfa6a1df39b5538cee)

Diff:
---
 libstdc++-v3/doc/html/manual/appendix_contributing.html | 16 +---
 libstdc++-v3/doc/xml/manual/appendix_contributing.xml   | 16 +---
 2 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/libstdc++-v3/doc/html/manual/appendix_contributing.html 
b/libstdc++-v3/doc/html/manual/appendix_contributing.html
index 8be678eb919..2d04cadd4e8 100644
--- a/libstdc++-v3/doc/html/manual/appendix_contributing.html
+++ b/libstdc++-v3/doc/html/manual/appendix_contributing.html
@@ -79,19 +79,19 @@
  bug. For new features a description of the feature and your
  implementation.

- A ChangeLog entry as plain text; see the various
- ChangeLog files for format and content. If you are
- using emacs as your editor, simply position the insertion
- point at the beginning of your change and hit CX-4a to bring
- up the appropriate ChangeLog entry. See--magic! Similar
- functionality also exists for vi.
+ A ChangeLog entry as part of the Git commit message. Check
+ some recent commits for format and content. The
+ contrib/mklog.py script can be used to
+ generate a ChangeLog template for commit messages. See
+ http://gcc.gnu.org/gitwrite.html"; 
target="_top">Read-write Git access
+ for scripts and aliases that are useful here.

  A testsuite submission or sample program that will
  easily and simply show the existing error or test new
  functionality.

  The patch itself. If you are using the Git repository use
- git diff or git format-patch
+ git show or git format-patch
  to produce a patch;
  otherwise, use diff -cp OLD 
NEW. If your
  version of diff does not support these options, then get the
@@ -102,6 +102,8 @@
  patches and related discussion should be sent to the
  libstdc++ mailing list. In common with the rest of GCC,
  patches should also be sent to the gcc-patches mailing list.
+ So you could send your email To:libstd...@gcc.gnu.org and
+ Cc:gcc-patc...@gcc.gnu.org for example.
Prev Up NextPart IV. 
   Appendices
  Home 
Directory Layout and Source Conventions
\ No newline at end of file
diff --git a/libstdc++-v3/doc/xml/manual/appendix_contributing.xml 
b/libstdc++-v3/doc/xml/manual/appendix_contributing.xml
index ceb21f4478a..074baf0fb4d 100644
--- a/libstdc++-v3/doc/xml/manual/appendix_contributing.xml
+++ b/libstdc++-v3/doc/xml/manual/appendix_contributing.xml
@@ -151,12 +151,12 @@
 
   

- A ChangeLog entry as plain text; see the various
- ChangeLog files for format and content. If you are
- using emacs as your editor, simply position the insertion
- point at the beginning of your change and hit CX-4a to bring
- up the appropriate ChangeLog entry. See--magic! Similar
- functionality also exists for vi.
+ A ChangeLog entry as part of the Git commit message. Check
+ some recent commits for format and content. The
+ contrib/mklog.py script can be used to
+ generate a ChangeLog template for commit messages. See
+ http://www.w3.org/1999/xlink"; 
xlink:href="http://gcc.gnu.org/gitwrite.html";>Read-write Git access
+ for scripts and aliases that are useful here.

   
 
@@ -171,7 +171,7 @@
   

  The patch itself. If you are using the Git repository use
- git diff or git format-patch
+ git show or git format-patch
  to produce a patch;
  otherwise, use diff -cp OLD NEW. If your
  version of diff does not support these options, then get the
@@ -186,6 +186,8 @@
  patches and related discussion should be sent to the
  libstdc++ mailing list. In common with the rest of GCC,
  patches should also be sent to the gcc-patches mailing list.
+ So you could send your email To:libstd...@gcc.gnu.org and
+ Cc:gcc-patc...@gcc.gnu.org for example.

   
 


[gcc r12-10224] libstdc++: Change some URLs in the manual to use https

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:7b9fa0982f4db0a64aacfe5018708a89f956245a

commit r12-10224-g7b9fa0982f4db0a64aacfe5018708a89f956245a
Author: Jonathan Wakely 
Date:   Wed Feb 28 14:36:28 2024 +

libstdc++: Change some URLs in the manual to use https

libstdc++-v3/ChangeLog:

* doc/xml/manual/appendix_contributing.xml: Change URLs to use
https.
* doc/html/manual/*: Regenerate.

(cherry picked from commit 06866bc368f828fa4f3dad25588d038414944c2e)

Diff:
---
 libstdc++-v3/doc/html/manual/appendix_contributing.html |  8 
 libstdc++-v3/doc/html/manual/source_code_style.html |  4 ++--
 libstdc++-v3/doc/xml/manual/appendix_contributing.xml   | 12 ++--
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/libstdc++-v3/doc/html/manual/appendix_contributing.html 
b/libstdc++-v3/doc/html/manual/appendix_contributing.html
index 2d04cadd4e8..25d0944e187 100644
--- a/libstdc++-v3/doc/html/manual/appendix_contributing.html
+++ b/libstdc++-v3/doc/html/manual/appendix_contributing.html
@@ -10,7 +10,7 @@
 Table of 
ContentsContributor 
ChecklistReadingAssignmentGetting 
SourcesSubmitting 
PatchesDirectory Layout and Source 
ConventionsCoding StyleBad 
IdentifiersBy 
ExampleDesign Notes
   The GNU C++ Library is part of GCC and follows the same development model,
   so the general rules for
-  http://gcc.gnu.org/contribute.html"; 
target="_top">contributing
+  https://gcc.gnu.org/contribute.html"; 
target="_top">contributing
   to GCC apply. Active
   contributors are assigned maintainership responsibility, and given
   write access to the source repository. First-time contributors
@@ -34,7 +34,7 @@
  http://www.open-std.org/jtc1/sc22/wg21/"; 
target="_top">http://www.open-std.org/jtc1/sc22/wg21

  Peruse
- the http://www.gnu.org/prep/standards/"; 
target="_top">GNU
+ the https://www.gnu.org/prep/standards/"; 
target="_top">GNU
  Coding Standards, and chuckle when you hit the part
  about “Using Languages Other 
Than C”.

@@ -46,7 +46,7 @@
  library-specific information found in
   Porting and Maintenance.
   Assignment
-  See the http://gcc.gnu.org/contribute.html#legal"; 
target="_top">legal prerequisites for all GCC contributions.
+  See the https://gcc.gnu.org/contribute.html#legal"; 
target="_top">legal prerequisites for all GCC contributions.
 
   Historically, the libstdc++ assignment form added the following
   question:
@@ -83,7 +83,7 @@
  some recent commits for format and content. The
  contrib/mklog.py script can be used to
  generate a ChangeLog template for commit messages. See
- http://gcc.gnu.org/gitwrite.html"; 
target="_top">Read-write Git access
+ https://gcc.gnu.org/gitwrite.html"; 
target="_top">Read-write Git access
  for scripts and aliases that are useful here.

  A testsuite submission or sample program that will
diff --git a/libstdc++-v3/doc/html/manual/source_code_style.html 
b/libstdc++-v3/doc/html/manual/source_code_style.html
index 24e0d693127..1c0d00a5df8 100644
--- a/libstdc++-v3/doc/html/manual/source_code_style.html
+++ b/libstdc++-v3/doc/html/manual/source_code_style.html
@@ -197,13 +197,13 @@
   it is intended to precede the recommendations of the GNU Coding
   Standard, which can be referenced in full here:
 
-  http://www.gnu.org/prep/standards/standards.html#Formatting"; 
target="_top">http://www.gnu.org/prep/standards/standards.html#Formatting
+  https://www.gnu.org/prep/standards/standards.html#Formatting"; 
target="_top">https://www.gnu.org/prep/standards/standards.html#Formatting
 
   The rest of this is also interesting reading, but skip the "Design
   Advice" part.
 
   The GCC coding conventions are here, and are also useful:
-  http://gcc.gnu.org/codingconventions.html"; 
target="_top">http://gcc.gnu.org/codingconventions.html
+  https://gcc.gnu.org/codingconventions.html"; 
target="_top">https://gcc.gnu.org/codingconventions.html
 
   In addition, because it doesn't seem to be stated explicitly anywhere
   else, there is an 80 column source limit.
diff --git a/libstdc++-v3/doc/xml/manual/appendix_contributing.xml 
b/libstdc++-v3/doc/xml/manual/appendix_contributing.xml
index 074baf0fb4d..2509330d807 100644
--- a/libstdc++-v3/doc/xml/manual/appendix_contributing.xml
+++ b/libstdc++-v3/doc/xml/manual/appendix_contributing.xml
@@ -20,7 +20,7 @@
 
   The GNU C++ Library is part of GCC and follows the same development model,
   so the general rules for
-  http://www.w3.org/1999/xlink"; 
xlink:href="http://gcc.gnu.org/contribute.html";>contributing
+  http://www.w3.org/1999/xlink"; 
xlink:href="https://gcc.gnu.org/contribute.html";>contributing
   to GCC apply. Active
   contributors are assigned maintainership responsibility, and given
   write access to the source repository. First-time con

[gcc r12-10225] libstdc++: Move test error_category to global scope

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:a0bca5584725153ad560b97a33a07e3c56f6f953

commit r12-10225-ga0bca5584725153ad560b97a33a07e3c56f6f953
Author: Jonathan Wakely 
Date:   Wed Mar 13 10:02:12 2024 +

libstdc++: Move test error_category to global scope

A recent GDB change causes this test to fail due to missing RTTI for the
custom_cast type. This is presumably because the custom_cat type was
defined as a local class, so has no linkage. Moving it to local scope
seems to fix the test regressions, and probably makes the test more
realistic as a local class with no linkage isn't practical to use as an
error category that almost certainly needs to be referred to in other
scopes.

libstdc++-v3/ChangeLog:

* testsuite/libstdc++-prettyprinters/cxx11.cc: Move custom_cat
to namespace scope.

(cherry picked from commit a8c7c3a40953e34f57278d224a07dc3698c64a84)

Diff:
---
 libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc 
b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
index f97640a0189..c79f0fab602 100644
--- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
+++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
@@ -63,6 +63,11 @@ struct datum
 
 std::unique_ptr global;
 
+struct custom_cat : std::error_category {
+  const char* name() const noexcept { return "miaow"; }
+  std::string message(int) const { return ""; }
+};
+
 int
 main()
 {
@@ -179,10 +184,7 @@ main()
   std::error_condition ecinval = 
std::make_error_condition(std::errc::invalid_argument);
   // { dg-final { note-test ecinval {std::error_condition = {"generic": 
EINVAL}} } }
 
-  struct custom_cat : std::error_category {
-const char* name() const noexcept { return "miaow"; }
-std::string message(int) const { return ""; }
-  } cat;
+  custom_cat cat;
   std::error_code emiaow(42, cat);
   // { dg-final { note-test emiaow {std::error_code = {custom_cat: 42}} } }
   std::error_condition ecmiaow(42, cat);


[gcc r12-10227] libstdc++: Fix access error in __gnu_test::uneq_allocator

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:80e88183d47ca4d7c8441355f736fc918d7d05dc

commit r12-10227-g80e88183d47ca4d7c8441355f736fc918d7d05dc
Author: Jonathan Wakely 
Date:   Thu Nov 23 14:34:59 2023 +

libstdc++: Fix access error in __gnu_test::uneq_allocator

The operator== function is only a friend of the LHS argument, so cannot
access the private member of the RHS argument. Use the public accessor
instead.

libstdc++-v3/ChangeLog:

* testsuite/util/testsuite_allocator.h (uneq_allocator): Fix
equality operator for heterogeneous comparisons.

(cherry picked from commit 0585daf7de0673ade9feca1be66a68178786b48d)

Diff:
---
 libstdc++-v3/testsuite/util/testsuite_allocator.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/testsuite/util/testsuite_allocator.h 
b/libstdc++-v3/testsuite/util/testsuite_allocator.h
index f33f602d2af..0c41181b4a5 100644
--- a/libstdc++-v3/testsuite/util/testsuite_allocator.h
+++ b/libstdc++-v3/testsuite/util/testsuite_allocator.h
@@ -418,7 +418,7 @@ namespace __gnu_test
operator==(const uneq_allocator& a,
   const uneq_allocator::other>& b)
-   { return a.personality == b.personality; }
+   { return a.personality == b.get_personality(); }
 
   template
friend inline bool


[gcc r12-10226] libstdc++: Correct notes about std::call_once in manual [PR66146]

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:415457babf04d077929956ea97132448b0dc4b2c

commit r12-10226-g415457babf04d077929956ea97132448b0dc4b2c
Author: Jonathan Wakely 
Date:   Thu Mar 14 11:52:17 2024 +

libstdc++: Correct notes about std::call_once in manual [PR66146]

The bug with exceptions thrown during a std::call_once call affects all
targets, so fix the docs that say it only affects non-Linux targets.

libstdc++-v3/ChangeLog:

PR libstdc++/66146
* doc/xml/manual/status_cxx2011.xml: Remove mention of Linux in
note about std::call_once.
* doc/xml/manual/status_cxx2014.xml: Likewise.
* doc/xml/manual/status_cxx2017.xml: Likewise.
* doc/html/manual/status.html: Regenerate.

(cherry picked from commit e6836bbbd7a01af0791c02087e568b4822418c0d)

Diff:
---
 libstdc++-v3/doc/html/manual/status.html   | 6 +++---
 libstdc++-v3/doc/xml/manual/status_cxx2011.xml | 2 +-
 libstdc++-v3/doc/xml/manual/status_cxx2014.xml | 2 +-
 libstdc++-v3/doc/xml/manual/status_cxx2017.xml | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libstdc++-v3/doc/html/manual/status.html 
b/libstdc++-v3/doc/html/manual/status.html
index 76d7d58a831..a6494912c07 100644
--- a/libstdc++-v3/doc/html/manual/status.html
+++ b/libstdc++-v3/doc/html/manual/status.html
@@ -217,7 +217,7 @@ not in any particular release.
30
   
Thread support
-  30.1GeneralY 30.2RequirementsY 30.3Threads  30.3.1Class threadPartialthread::id 
comparisons not well-defined30.3.2Namespace this_threadY 30.4Mutual exclusion 
 30.4.1Mutex requirements  
30.4.1.1In general 
 30.4.1.2Mutex types  
30.4.1.2.1Class mutexY 
30.4.1.2.2Class recursive_mutexY 30.4.1.3Timed mutex types  
30.4.1.3.1Class timed_mutexY 
30.4.1.3.2Class recursive_timed_mutexY 30.
 4.2Locks  
30.4.2.1Class template 
lock_guardY 30.4.2.2Class template unique_lockY 30.4.3Generic locking algorithmsY 30.4.4Call once 
 30.4.4.1Struct once_flagY 30.4.4.2Function call_onceYException support is broken on non
 -Linux targets.
+  30.1GeneralY 30.2RequirementsY 30.3Threads  30.3.1Class threadPartialthread::id 
comparisons not well-defined30.3.2Namespace this_threadY 30.4Mutual exclusion 
 30.4.1Mutex requirements  
30.4.1.1In general 
 30.4.1.2Mutex types  
30.4.1.2.1Class mutexY 
30.4.1.2.2Class recursive_mutexY 30.4.1.3Timed mutex types  
30.4.1.3.1Class timed_mutexY 
30.4.1.3.2Class recursive_timed_mutexY 30.
 4.2Locks  
30.4.2.1Class template 
lock_guardY 30.4.2.2Class template unique_lockY 30.4.3Generic locking algorithmsY 30.4.4Call once 
 30.4.4.1Struct once_flagY 30.4.4.2Function call_onceYException support is broken.
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66146"; target="_top">PR
66146.
   30.5Condition 
variablesY 30.5.1Class condition_variableY 30.5.2Class 
condition_variable_anyY 30.6Futures  
30.6.1Overview  30.6.2Error handlingY 30.6.3Class future_errorY 
30.6.4Shared stateY 
30.6.5Class template promiseY 
30.6.6Class template futureY 
30.6.7Class template shared_futureY 
30.6.8Function template 
asyncY 
30.6.9Class template packaged_taskY 

@@ -490,7 +490,7 @@ not in any particular release.
30
   
Thread support
-  30.1GeneralY 30.2RequirementsY 30.3Threads  30.3.1Class threadPartialthread::id 
comparisons not well-defined30.3.2Namespace this_threadY 30.4Mutual exclusion 
 30.4.1Mutex requirements  
30.4.1.1In general 
 30.4.1.2Mutex types  
30.4.1.2.1Class mutexY 
30.4.1.2.2Class recursive_mutexY 30.4.1.3Timed mutex types  
30.4.1.3.1Class timed_mutexY 
30.4.1.3.2Class recursive_timed_mutexY 30.
 4.1.4Shared timed mutex types 
 30.4.1.4.1Class shared_timed_mutexY 30.4.2Locks  30.4.2.1Class template lock_guardY 30.4.2.2Class template unique_lockY 
30.4.2.3Class template 
shared_lockY 30.4.3Generic locking algorithmsY <
 td align="left">30.4.4Call once 
 30.4.4.1Struct once_flagY 30.4.4.2Function call_onceBrokenException support is broken on non-Linux targets.
+  30.1GeneralY 30.2RequirementsY 30.3Threads  30.3.1Class threadPartialthread::id 
comparisons not well-defined30.3.2Namespace this_threadY 30.4Mutual exclusion 
 30.4.1Mutex requirements  
30.4.1.1In general 
 30.4.1.2Mutex types  
30.4.1.2.1Class mutexY 
30.4.1.2.2Class recursive_mutexY 30.4.1.3Timed mutex types  
30.4.1.3.1Class timed_mutexY 
30.4.1.3.2Class recursive_timed_mutexY 30.
 4.1.4Shared timed mutex types 
 30.4.1.4.1Class shared_timed_mutexY 30.4.2Locks  30.4.2.1Class template lock_guardY 30.4.2.2Class template unique_lockY 
30.4.2.3Class template 
shared_lockY 30.4.3Generic locking algorithmsY <
 td align="left">30.4.4Call once 
 30.4.4.1Struct once_flagY 30.4.4.2Function call_onceBrokenException support is broken.
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66146"; target="_top">PR
66146.
   30.5Condition 
variablesY 30.5.1Class condition_variableY 30.5.2Class 
condition_variable_anyY 30.6Futures  
30.6.1O

[gcc r12-10232] libstdc++: Fix unconditional -Werror in libbacktrace directory

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:02a64d50d7780184428630e748fc301cb04ef96b

commit r12-10232-g02a64d50d7780184428630e748fc301cb04ef96b
Author: Alexey Lapshin 
Date:   Fri Sep 8 11:23:16 2023 +0100

libstdc++: Fix unconditional -Werror in libbacktrace directory

The -Werror flag should depend on the --enable-werror configure option.

libstdc++-v3/ChangeLog:

* src/libbacktrace/Makefile.am: Remove -Werror.
* src/libbacktrace/Makefile.in: Regenerate.

(cherry picked from commit 1a0c6decd2112267c88438466df2e1c46b20248e)

Diff:
---
 libstdc++-v3/src/libbacktrace/Makefile.am | 2 +-
 libstdc++-v3/src/libbacktrace/Makefile.in | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/src/libbacktrace/Makefile.am 
b/libstdc++-v3/src/libbacktrace/Makefile.am
index d8221c2c65a..94bbdb88b52 100644
--- a/libstdc++-v3/src/libbacktrace/Makefile.am
+++ b/libstdc++-v3/src/libbacktrace/Makefile.am
@@ -45,7 +45,7 @@ libstdc___libbacktrace_la_CPPFLAGS = \
$(BACKTRACE_CPPFLAGS)
 
 WARN_FLAGS = -W -Wall -Wwrite-strings -Wmissing-format-attribute \
--Wcast-qual -Werror
+-Wcast-qual
 C_WARN_FLAGS = $(WARN_FLAGS) -Wstrict-prototypes -Wmissing-prototypes 
-Wold-style-definition -Wno-unused-but-set-variable
 CXX_WARN_FLAGS = $(WARN_FLAGS) -Wno-unused-parameter
 AM_CFLAGS = \
diff --git a/libstdc++-v3/src/libbacktrace/Makefile.in 
b/libstdc++-v3/src/libbacktrace/Makefile.in
index a7eb4d69cde..ad4fe7ae4a8 100644
--- a/libstdc++-v3/src/libbacktrace/Makefile.in
+++ b/libstdc++-v3/src/libbacktrace/Makefile.in
@@ -368,7 +368,7 @@ VTV_CXXFLAGS = @VTV_CXXFLAGS@
 VTV_CXXLINKFLAGS = @VTV_CXXLINKFLAGS@
 VTV_PCH_CXXFLAGS = @VTV_PCH_CXXFLAGS@
 WARN_FLAGS = -W -Wall -Wwrite-strings -Wmissing-format-attribute \
--Wcast-qual -Werror
+-Wcast-qual
 
 XMLCATALOG = @XMLCATALOG@
 XMLLINT = @XMLLINT@


[gcc r12-10233] libstdc++: Update outdated default -std in testing docs

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:8364faf223e54c0ddf7ab35eda158533e5195bb6

commit r12-10233-g8364faf223e54c0ddf7ab35eda158533e5195bb6
Author: Jonathan Wakely 
Date:   Fri Sep 8 16:28:06 2023 +0100

libstdc++: Update outdated default -std in testing docs

libstdc++-v3/ChangeLog:

* doc/xml/manual/test.xml: Update reference to -std=gnu++14 as
the default.
* doc/html/manual/test.html: Regenerate.

(cherry picked from commit d8e351d8d656720f4037e0a86a4a6c73629e5307)

Diff:
---
 libstdc++-v3/doc/html/manual/test.html | 10 +-
 libstdc++-v3/doc/xml/manual/test.xml   | 10 +-
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/libstdc++-v3/doc/html/manual/test.html 
b/libstdc++-v3/doc/html/manual/test.html
index ef56a305687..168e247c52f 100644
--- a/libstdc++-v3/doc/html/manual/test.html
+++ b/libstdc++-v3/doc/html/manual/test.html
@@ -452,7 +452,7 @@ cat 27_io/objects/char/3_xin.in | a.outc++11_only. However, 
this means
 the test will be skipped by default (because the default mode is
-gnu++14), and so will only run when
+gnu++17), and so will only run when
 -std=gnu++11 or -std=c++11 is used
 explicitly. For tests that require a specific standard it is better to
 use a dg-options directive:
@@ -466,13 +466,13 @@ cat 27_io/objects/char/3_xin.in | 
a.outdg-options instead of (or in 
addition to)
 an effective target, so that they are not skipped by default.
-For example, tests for C++17 features should use
-// { dg-options "-std=gnu++17" }
+For example, tests for C++20 features should use
+// { dg-options "-std=gnu++20" }
 before any dg-do such as:
-// { dg-do run "c++17" }
+// { dg-do run { target c++20 } }
 The dg-options directive must come first, so 
that
 the -std flag has already been added to the 
options
-before checking the c++17 target.
+before checking the c++20 effective target.
   Examples of Test 
Directives
 Example 1: Testing compilation only:
 
diff --git a/libstdc++-v3/doc/xml/manual/test.xml 
b/libstdc++-v3/doc/xml/manual/test.xml
index ee00b06e385..17666114810 100644
--- a/libstdc++-v3/doc/xml/manual/test.xml
+++ b/libstdc++-v3/doc/xml/manual/test.xml
@@ -749,7 +749,7 @@ cat 27_io/objects/char/3_xin.in | a.out
 be run for a specific standard (and not later standards) using an
 effective target like c++11_only. However, this means
 the test will be skipped by default (because the default mode is
-gnu++14), and so will only run when
+gnu++17), and so will only run when
 -std=gnu++11 or -std=c++11 is used
 explicitly. For tests that require a specific standard it is better to
 use a dg-options directive:
@@ -765,13 +765,13 @@ cat 27_io/objects/char/3_xin.in | a.out
 Similarly, tests which depend on a newer standard than the default
 must use dg-options instead of (or in addition to)
 an effective target, so that they are not skipped by default.
-For example, tests for C++17 features should use
-// { dg-options "-std=gnu++17" }
+For example, tests for C++20 features should use
+// { dg-options "-std=gnu++20" }
 before any dg-do such as:
-// { dg-do run "c++17" }
+// { dg-do run { target c++20 } }
 The dg-options directive must come first, so that
 the -std flag has already been added to the options
-before checking the c++17 target.
+before checking the c++20 effective target.
   
 
 Examples of Test 
Directives


[gcc r12-10228] libstdc++: Fix uses of signed types with functions

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:ac0cf0786bb3da60f412afe800fd385686b9517d

commit r12-10228-gac0cf0786bb3da60f412afe800fd385686b9517d
Author: Jonathan Wakely 
Date:   Tue Nov 14 10:56:57 2023 +

libstdc++: Fix  uses of signed types with  functions

In  we pass the int __base parameter to our internal versions
of  functions, __bit_width and __countr_zero. Those functions are
only defined for unsigned types, so we need to convert the base to
unsigned. The base must be in the range [2,36] so we can mask off the
low bits and then convert that to unsigned, so that we don't need to
care about negative values becoming large unsigned values.

libstdc++-v3/ChangeLog:

* include/std/charconv (__from_chars_pow2_base): Convert base to
unsigned for call to __countr_zero.
(__from_chars_alnum): Likewise for call to __bit_width.

(cherry picked from commit 1c15303375f7089ff985b085ab877b11ebfbc4b7)

Diff:
---
 libstdc++-v3/include/std/charconv | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/std/charconv 
b/libstdc++-v3/include/std/charconv
index b4d37435fa0..365a22dab58 100644
--- a/libstdc++-v3/include/std/charconv
+++ b/libstdc++-v3/include/std/charconv
@@ -458,7 +458,7 @@ namespace __detail
 
   // __glibcxx_assert((__base & (__base - 1)) == 0);
   // __glibcxx_assert(_DecOnly ? __base <= 8 : __base <= 32);
-  const int __log2_base = __countr_zero(__base);
+  const int __log2_base = __countr_zero(unsigned(__base & 0x3f));
 
   const ptrdiff_t __len = __last - __first;
   ptrdiff_t __i = 0;
@@ -510,9 +510,9 @@ namespace __detail
 __from_chars_alnum(const char*& __first, const char* __last, _Tp& __val,
   int __base)
 {
-  // __glibcxx_assert(!_DecOnly || __base <= 10);
+  // __glibcxx_assert(_DecOnly ? __base <= 10 : __base <= 36);
 
-  const int __bits_per_digit = __bit_width(__base);
+  const int __bits_per_digit = __bit_width(unsigned(__base & 0x3f));
   int __unused_bits_lower_bound = __gnu_cxx::__int_traits<_Tp>::__digits;
   for (; __first != __last; ++__first)
{


[gcc r12-10237] libstdc++: Remove unconditional use of atomics in Debug Mode

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:73d0816f570c26e856d94d56491e50332fd8b425

commit r12-10237-g73d0816f570c26e856d94d56491e50332fd8b425
Author: Jonathan Wakely 
Date:   Mon Sep 11 16:42:54 2023 +0100

libstdc++: Remove unconditional use of atomics in Debug Mode

The fix for PR 91910 (r10-3426-gf7a3a382279585) introduced unconditional
uses of atomics into src/c++11/debug.cc, which causes linker errors for
arm4t where GCC emits an unresolved reference to __sync_synchronize.

By making the uses of atomics depend on _GLIBCXX_HAS_GTHREADS we can
avoid those unconditional references to __sync_synchronize for targets
where the atomics are unnecessary. As a minor performance optimization
we can also check the __gnu_cxx::__is_single_threaded function to avoid
atomics for single-threaded programs even where they don't cause linker
errors.

libstdc++-v3/ChangeLog:

* src/c++11/debug.cc (acquire_sequence_ptr_for_lock): New
function.
(reset_sequence_ptr): New function.
(_Safe_iterator_base::_M_detach)
(_Safe_local_iterator_base::_M_detach): Replace bare atomic_load
with acquire_sequence_ptr_for_lock.
(_Safe_iterator_base::_M_reset): Replace bare atomic_store with
reset_sequence_ptr.

(cherry picked from commit 4a2766ed00a47904dc8b85bf0538aa116d8e658b)

Diff:
---
 libstdc++-v3/src/c++11/debug.cc | 32 +---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/src/c++11/debug.cc b/libstdc++-v3/src/c++11/debug.cc
index 4706defedf1..1bfc6ccc581 100644
--- a/libstdc++-v3/src/c++11/debug.cc
+++ b/libstdc++-v3/src/c++11/debug.cc
@@ -24,6 +24,7 @@
 
 #include 
 #include 
+#include  // __is_single_threaded
 
 #include 
 #include 
@@ -173,6 +174,31 @@ namespace
__old->_M_reset();
   }
   }
+
+  void*
+  acquire_sequence_ptr_for_lock(__gnu_debug::_Safe_sequence_base*& seq)
+  {
+#ifdef __GTHREADS
+if (!__gnu_cxx::__is_single_threaded())
+  return __atomic_load_n(&seq, __ATOMIC_ACQUIRE);
+#endif
+return seq;
+  }
+
+  void
+  reset_sequence_ptr(__gnu_debug::_Safe_sequence_base*& seq)
+  {
+#ifdef __GTHREADS
+if (!__gnu_cxx::__is_single_threaded())
+  {
+   __atomic_store_n(&seq, (__gnu_debug::_Safe_sequence_base*)nullptr,
+__ATOMIC_RELEASE);
+   return;
+  }
+#endif
+seq = nullptr;
+  }
+
 } // anonymous namespace
 
 namespace __gnu_debug
@@ -403,7 +429,7 @@ namespace __gnu_debug
 // If the sequence destructor runs between loading the pointer and
 // locking the mutex, it will detach this iterator and set _M_sequence
 // to null, and then _M_detach_single() will do nothing.
-if (auto seq = __atomic_load_n(&_M_sequence, __ATOMIC_ACQUIRE))
+if (auto seq = acquire_sequence_ptr_for_lock(_M_sequence))
   {
__gnu_cxx::__scoped_lock sentry(get_safe_base_mutex(seq));
_M_detach_single();
@@ -425,7 +451,7 @@ namespace __gnu_debug
   _Safe_iterator_base::
   _M_reset() throw ()
   {
-__atomic_store_n(&_M_sequence, (_Safe_sequence_base*)0, __ATOMIC_RELEASE);
+reset_sequence_ptr(_M_sequence);
 _M_version = 0;
 _M_prior = 0;
 _M_next = 0;
@@ -485,7 +511,7 @@ namespace __gnu_debug
   _Safe_local_iterator_base::
   _M_detach()
   {
-if (auto seq = __atomic_load_n(&_M_sequence, __ATOMIC_ACQUIRE))
+if (auto seq = acquire_sequence_ptr_for_lock(_M_sequence))
   {
__gnu_cxx::__scoped_lock sentry(get_safe_base_mutex(seq));
_M_detach_single();


[gcc r12-10239] libstdc++: Qualify calls to std::_Destroy and _Destroy_aux

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:5c4cd53ffd70205b2b136661b3be175dec0ce8d7

commit r12-10239-g5c4cd53ffd70205b2b136661b3be175dec0ce8d7
Author: Jonathan Wakely 
Date:   Fri Jun 30 21:09:01 2023 +0100

libstdc++: Qualify calls to std::_Destroy and _Destroy_aux

These calls should be qualified to prevent ADL, which can cause errors
for incomplete types that are associated classes.

libstdc++-v3/ChangeLog:

* include/bits/alloc_traits.h (_Destroy): Qualify call.
* include/bits/stl_construct.h (_Destroy, _Destroy_n): Likewise.
* testsuite/23_containers/vector/cons/destroy-adl.cc: New test.

(cherry picked from commit 33245d6b87a284495304c9952813b6b83d5df99f)

Diff:
---
 libstdc++-v3/include/bits/alloc_traits.h  |  2 +-
 libstdc++-v3/include/bits/stl_construct.h |  4 ++--
 .../testsuite/23_containers/vector/cons/destroy-adl.cc| 11 +++
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/bits/alloc_traits.h 
b/libstdc++-v3/include/bits/alloc_traits.h
index a4d06d3fc7a..5cc52babef8 100644
--- a/libstdc++-v3/include/bits/alloc_traits.h
+++ b/libstdc++-v3/include/bits/alloc_traits.h
@@ -847,7 +847,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 _Destroy(_ForwardIterator __first, _ForwardIterator __last,
 allocator<_Tp>&)
 {
-  _Destroy(__first, __last);
+  std::_Destroy(__first, __last);
 }
 
 _GLIBCXX_END_NAMESPACE_VERSION
diff --git a/libstdc++-v3/include/bits/stl_construct.h 
b/libstdc++-v3/include/bits/stl_construct.h
index 9531222809c..a081f26adc3 100644
--- a/libstdc++-v3/include/bits/stl_construct.h
+++ b/libstdc++-v3/include/bits/stl_construct.h
@@ -190,7 +190,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 #if __cplusplus >= 202002L
   if (std::__is_constant_evaluated())
-   return _Destroy_aux::__destroy(__first, __last);
+   return std::_Destroy_aux::__destroy(__first, __last);
 #endif
   std::_Destroy_aux<__has_trivial_destructor(_Value_type)>::
__destroy(__first, __last);
@@ -239,7 +239,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 #if __cplusplus >= 202002L
   if (std::__is_constant_evaluated())
-   return _Destroy_n_aux::__destroy_n(__first, __count);
+   return std::_Destroy_n_aux::__destroy_n(__first, __count);
 #endif
   return std::_Destroy_n_aux<__has_trivial_destructor(_Value_type)>::
__destroy_n(__first, __count);
diff --git a/libstdc++-v3/testsuite/23_containers/vector/cons/destroy-adl.cc 
b/libstdc++-v3/testsuite/23_containers/vector/cons/destroy-adl.cc
new file mode 100644
index 000..5623842e9b1
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/cons/destroy-adl.cc
@@ -0,0 +1,11 @@
+// { dg-do compile }
+
+#include 
+
+template struct Holder { T t; }; // { dg-bogus "incomplete type" }
+struct Incomplete;
+
+void destroy(std::vector*>* p)
+{
+  p->~vector();
+}


[gcc r12-10238] libstdc++: Check for std::ratio in arithmetic and comparisons [PR110593]

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:ae8302e18f15f0befb372762b20a3a790a19a925

commit r12-10238-gae8302e18f15f0befb372762b20a3a790a19a925
Author: Jonathan Wakely 
Date:   Wed Jul 19 18:18:46 2023 +0100

libstdc++: Check for std::ratio in arithmetic and comparisons [PR110593]

The standard says that it should be ill-formed to use std::ratio_equal
etc. with types which are not specializations of std::ratio. This
implements that requirement.

We don't need to add assertions to every one of the class templates,
because many of them are implemented in terms of other ones. For
example, ratio_divide and ratio_subtract can rely on the assertions in
ratio_multiply and ratio_add respectively.

libstdc++-v3/ChangeLog:

PR libstdc++/110593
* include/bits/chrono.h (duration): Improve static assert
messages.
(__is_ratio): Move to ...
* include/std/ratio (__is_ratio): ... here.
(__is_ratio_v): New variable template and partial
specialization.
(__are_both_ratios): New function template.
(__ratio_multiply, ratio_equal, ratio_less, __ratio_add):
Add static assertion.
* testsuite/20_util/ratio/requirements/type_constraints.cc:
New test.
* testsuite/20_util/duration/requirements/typedefs_neg1.cc:
Adjust expected error.
* testsuite/20_util/duration/requirements/typedefs_neg2.cc:
Likewise.

(cherry picked from commit 2d614822e9ea2a3d8800045d66e3220743753d09)

Diff:
---
 libstdc++-v3/include/bits/chrono.h | 19 ++--
 libstdc++-v3/include/std/ratio | 53 --
 .../20_util/duration/requirements/typedefs_neg1.cc |  2 +-
 .../20_util/duration/requirements/typedefs_neg2.cc |  2 +-
 .../20_util/ratio/requirements/type_constraints.cc | 34 ++
 5 files changed, 87 insertions(+), 23 deletions(-)

diff --git a/libstdc++-v3/include/bits/chrono.h 
b/libstdc++-v3/include/bits/chrono.h
index c585cac3d8a..d09f8563a59 100644
--- a/libstdc++-v3/include/bits/chrono.h
+++ b/libstdc++-v3/include/bits/chrono.h
@@ -483,26 +483,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return numeric_limits<_Rep>::lowest(); }
   };
 
-/// @cond undocumented
-
-template
-  struct __is_ratio
-  : std::false_type
-  { };
-
-template
-  struct __is_ratio>
-  : std::true_type
-  { };
-
-/// @endcond
-
 template
   class duration
   {
-   static_assert(!__is_duration<_Rep>::value, "rep cannot be a duration");
+   static_assert(!__is_duration<_Rep>::value,
+ "rep cannot be a std::chrono::duration");
static_assert(__is_ratio<_Period>::value,
- "period must be a specialization of ratio");
+ "period must be a specialization of std::ratio");
static_assert(_Period::num > 0, "period must be positive");
 
template
diff --git a/libstdc++-v3/include/std/ratio b/libstdc++-v3/include/std/ratio
index 5a5643d2999..32a4da25a93 100644
--- a/libstdc++-v3/include/std/ratio
+++ b/libstdc++-v3/include/std/ratio
@@ -289,9 +289,43 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /// @cond undocumented
 
+  template
+struct __is_ratio
+: std::false_type
+{ };
+
+  template
+struct __is_ratio>
+: std::true_type
+{ };
+
+#if __cpp_variable_templates
+  template
+constexpr bool __is_ratio_v = false;
+  template
+constexpr bool __is_ratio_v> = true;
+#endif
+
+  template
+constexpr bool
+__are_both_ratios() noexcept
+{
+#if __cpp_variable_templates && __cpp_if_constexpr
+  if constexpr (__is_ratio_v<_R1>)
+   if constexpr (__is_ratio_v<_R2>)
+ return true;
+  return false;
+#else
+  return __and_<__is_ratio<_R1>, __is_ratio<_R2>>::value;
+#endif
+}
+
   template
 struct __ratio_multiply
 {
+  static_assert(std::__are_both_ratios<_R1, _R2>(),
+   "both template arguments must be a std::ratio");
+
 private:
   static const intmax_t __gcd1 =
 __static_gcd<_R1::num, _R2::den>::value;
@@ -356,7 +390,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 struct ratio_equal
 : integral_constant
-{ };
+{
+  static_assert(std::__are_both_ratios<_R1, _R2>(),
+   "both template arguments must be a std::ratio");
+};
 
   /// ratio_not_equal
   template
@@ -402,7 +439,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 struct ratio_less
 : __ratio_less_impl<_R1, _R2>::type
-{ };
+{
+  static_assert(std::__are_both_ratios<_R1, _R2>(),
+   "both template arguments must be a std::ratio");
+};
 
   /// ratio_less_equal
   template
@@ -430,13 +470,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template 
 inline constexpr bool ratio_less_v = ratio_less<_R1, _R2>::value;
   template 
-

[gcc r12-10244] libstdc++: Fix std::abs(__float128) for -NaN and -0.0 [PR109758]

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:9f381ebb7211c1359f5de87760148096fcba3357

commit r12-10244-g9f381ebb7211c1359f5de87760148096fcba3357
Author: Jonathan Wakely 
Date:   Wed May 10 12:20:58 2023 +0100

libstdc++: Fix std::abs(__float128) for -NaN and -0.0 [PR109758]

The current implementation of this non-standard overload of std::abs
incorrectly returns a negative value for negative NaNs and negative
zero, because x < 0 is false in both cases.

Use fabsl(long double) or fabsf128(_Float128) if those do the right
thing.  Otherwise, use __builtin_signbit(x) instead of x < 0 to detect
negative inputs. This assumes that __builtin_signbit handles __float128
correctly, but that seems to be true for all of GCC, clang and icc.

libstdc++-v3/ChangeLog:

PR libstdc++/109758
* include/bits/std_abs.h (abs(__float128)): Handle negative NaN
and negative zero correctly.
* testsuite/26_numerics/headers/cmath/109758.cc: New test.

(cherry picked from commit af595613acbd9863198ae69c7b1c9e856bca9e4f)

Diff:
---
 libstdc++-v3/include/bits/std_abs.h| 13 +-
 .../testsuite/26_numerics/headers/cmath/109758.cc  | 52 ++
 2 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/bits/std_abs.h 
b/libstdc++-v3/include/bits/std_abs.h
index c8d589d2b0a..bd14addd159 100644
--- a/libstdc++-v3/include/bits/std_abs.h
+++ b/libstdc++-v3/include/bits/std_abs.h
@@ -101,11 +101,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   __extension__ inline _GLIBCXX_CONSTEXPR
   __float128
   abs(__float128 __x)
-  { return __x < 0 ? -__x : __x; }
+  {
+#if defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128)
+return __builtin_fabsl(__x);
+#elif defined(_GLIBCXX_HAVE_FLOAT128_MATH)
+return __builtin_fabsf128(__x);
+#else
+// Assume that __builtin_signbit works for __float128.
+return __builtin_signbit(__x) ? -__x : __x;
+#endif
+  }
 #endif
 
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
-} // extern "C"++"
+} // extern "C++"
 
 #endif // _GLIBCXX_BITS_STD_ABS_H
diff --git a/libstdc++-v3/testsuite/26_numerics/headers/cmath/109758.cc 
b/libstdc++-v3/testsuite/26_numerics/headers/cmath/109758.cc
new file mode 100644
index 000..c9716d3d372
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/headers/cmath/109758.cc
@@ -0,0 +1,52 @@
+// { dg-do run }
+// PR libstdc++/109758 std::abs(__float128) doesn't support NaN
+
+#include 
+#include 
+
+#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
+void
+test_nan()
+{
+  __float128 nan = __builtin_nanl("");
+  VERIFY( !__builtin_signbit(std::abs(nan)) );
+  VERIFY( !__builtin_signbit(std::abs(-nan)) );
+}
+
+void
+test_zero()
+{
+  __float128 zero = 0.0;
+  VERIFY( !__builtin_signbit(std::abs(zero)) );
+  VERIFY( !__builtin_signbit(std::abs(zero * -2.0)) );
+}
+
+void
+test_neg()
+{
+  VERIFY( std::abs((__float128)-1.0) == -1.0 );
+  VERIFY( std::abs((__float128)-2e9) == -2e9 );
+  VERIFY( std::abs((__float128)-3e-4) == 3e-4 );
+}
+
+void
+test_inf()
+{
+  __float128 inf = __builtin_huge_vall();
+  VERIFY( std::abs(inf) == inf );
+  VERIFY( std::abs(-inf) == inf );
+}
+
+#if __cplusplus >= 201103L
+static_assert( std::abs((__float128)-1.0) == (__float128)1.0,
+  "std::abs(__float128) is usable in constant expressions" );
+#endif
+
+int main()
+{
+  test_nan();
+  test_zero();
+}
+#else
+int main() { }
+#endif


[gcc r12-10247] libstdc++: Add likely/unlikely attributes to implementation

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:ec9735922b6f28cf704c8a7850a34aed82675b91

commit r12-10247-gec9735922b6f28cf704c8a7850a34aed82675b91
Author: Jonathan Wakely 
Date:   Fri Feb 24 21:28:11 2023 +

libstdc++: Add likely/unlikely attributes to  implementation

For the common case of converting valid text this improves performance
significantly.

libstdc++-v3/ChangeLog:

* src/c++11/codecvt.cc: Add [[likely]] and [[unlikely]]
attributes.

(cherry picked from commit a41a56dee5c2d48337739d60c43cab5074bcc8e7)

Diff:
---
 libstdc++-v3/src/c++11/codecvt.cc | 92 +++
 1 file changed, 46 insertions(+), 46 deletions(-)

diff --git a/libstdc++-v3/src/c++11/codecvt.cc 
b/libstdc++-v3/src/c++11/codecvt.cc
index 03f0bfda972..5b0bcb0eaa4 100644
--- a/libstdc++-v3/src/c++11/codecvt.cc
+++ b/libstdc++-v3/src/c++11/codecvt.cc
@@ -256,19 +256,19 @@ namespace
   return incomplete_mb_character;
 char32_t c1 = (unsigned char) from[0];
 // https://en.wikipedia.org/wiki/UTF-8#Sample_code
-if (c1 < 0x80)
+if (c1 < 0x80) [[likely]]
 {
   ++from;
   return c1;
 }
-else if (c1 < 0xC2) // continuation or overlong 2-byte sequence
+else if (c1 < 0xC2) [[unlikely]] // continuation or overlong 2-byte 
sequence
   return invalid_mb_sequence;
 else if (c1 < 0xE0) // 2-byte sequence
 {
-  if (avail < 2)
+  if (avail < 2) [[unlikely]]
return incomplete_mb_character;
   char32_t c2 = (unsigned char) from[1];
-  if ((c2 & 0xC0) != 0x80)
+  if ((c2 & 0xC0) != 0x80) [[unlikely]]
return invalid_mb_sequence;
   char32_t c = (c1 << 6) + c2 - 0x3080;
   if (c <= maxcode)
@@ -277,17 +277,17 @@ namespace
 }
 else if (c1 < 0xF0) // 3-byte sequence
 {
-  if (avail < 2)
+  if (avail < 2) [[unlikely]]
return incomplete_mb_character;
   char32_t c2 = (unsigned char) from[1];
-  if ((c2 & 0xC0) != 0x80)
+  if ((c2 & 0xC0) != 0x80) [[unlikely]]
return invalid_mb_sequence;
-  if (c1 == 0xE0 && c2 < 0xA0) // overlong
+  if (c1 == 0xE0 && c2 < 0xA0) [[unlikely]] // overlong
return invalid_mb_sequence;
-  if (avail < 3)
+  if (avail < 3) [[unlikely]]
return incomplete_mb_character;
   char32_t c3 = (unsigned char) from[2];
-  if ((c3 & 0xC0) != 0x80)
+  if ((c3 & 0xC0) != 0x80) [[unlikely]]
return invalid_mb_sequence;
   char32_t c = (c1 << 12) + (c2 << 6) + c3 - 0xE2080;
   if (c <= maxcode)
@@ -296,31 +296,31 @@ namespace
 }
 else if (c1 < 0xF5 && maxcode > 0x) // 4-byte sequence
 {
-  if (avail < 2)
+  if (avail < 2) [[unlikely]]
return incomplete_mb_character;
   char32_t c2 = (unsigned char) from[1];
-  if ((c2 & 0xC0) != 0x80)
+  if ((c2 & 0xC0) != 0x80) [[unlikely]]
return invalid_mb_sequence;
-  if (c1 == 0xF0 && c2 < 0x90) // overlong
+  if (c1 == 0xF0 && c2 < 0x90) [[unlikely]] // overlong
return invalid_mb_sequence;
-  if (c1 == 0xF4 && c2 >= 0x90) // > U+10
+  if (c1 == 0xF4 && c2 >= 0x90) [[unlikely]] // > U+10
return invalid_mb_sequence;
-  if (avail < 3)
+  if (avail < 3) [[unlikely]]
return incomplete_mb_character;
   char32_t c3 = (unsigned char) from[2];
-  if ((c3 & 0xC0) != 0x80)
+  if ((c3 & 0xC0) != 0x80) [[unlikely]]
return invalid_mb_sequence;
-  if (avail < 4)
+  if (avail < 4) [[unlikely]]
return incomplete_mb_character;
   char32_t c4 = (unsigned char) from[3];
-  if ((c4 & 0xC0) != 0x80)
+  if ((c4 & 0xC0) != 0x80) [[unlikely]]
return invalid_mb_sequence;
   char32_t c = (c1 << 18) + (c2 << 12) + (c3 << 6) + c4 - 0x3C82080;
   if (c <= maxcode)
from += 4;
   return c;
 }
-else // > U+10
+else [[unlikely]] // > U+10
   return invalid_mb_sequence;
   }
 
@@ -330,20 +330,20 @@ namespace
   {
 if (code_point < 0x80)
   {
-   if (to.size() < 1)
+   if (to.size() < 1) [[unlikely]]
  return false;
to = code_point;
   }
 else if (code_point <= 0x7FF)
   {
-   if (to.size() < 2)
+   if (to.size() < 2) [[unlikely]]
  return false;
to = (code_point >> 6) + 0xC0;
to = (code_point & 0x3F) + 0x80;
   }
 else if (code_point <= 0x)
   {
-   if (to.size() < 3)
+   if (to.size() < 3) [[unlikely]]
  return false;
to = (code_point >> 12) + 0xE0;
to = ((code_point >> 6) & 0x3F) + 0x80;
@@ -351,14 +351,14 @@ namespace
   }
 else if (code_point <= 0x10)
   {
-   if (to.size() < 4)
+   if (to.size() < 4) [[unlikely]]
  return false;
to = (code_point >> 18) + 0xF0;
to = ((code_point >> 12) & 0x3F) + 0x80;
to = ((code_point >> 6) & 0x3F) + 0x80;
to = (code_point & 0x3F) + 0x80;
   

[gcc r12-10252] libstdc++: Fix exception thrown by std::shared_lock::unlock() [PR112089]

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:c285c1b9a940bde745f296e1bfc1a5cfddb63254

commit r12-10252-gc285c1b9a940bde745f296e1bfc1a5cfddb63254
Author: Jonathan Wakely 
Date:   Thu Oct 26 16:51:30 2023 +0100

libstdc++: Fix exception thrown by std::shared_lock::unlock() [PR112089]

The incorrect errc constant here looks like a copy&paste error.

libstdc++-v3/ChangeLog:

PR libstdc++/112089
* include/std/shared_mutex (shared_lock::unlock): Change errc
constant to operation_not_permitted.
* testsuite/30_threads/shared_lock/locking/112089.cc: New test.

(cherry picked from commit 0c305f3dec9a992dd775a3b9607b7b1e8c051859)

Diff:
---
 libstdc++-v3/include/std/shared_mutex  |  2 +-
 .../30_threads/shared_lock/locking/112089.cc   | 23 ++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/shared_mutex 
b/libstdc++-v3/include/std/shared_mutex
index 817a9587d87..0a61bedbe12 100644
--- a/libstdc++-v3/include/std/shared_mutex
+++ b/libstdc++-v3/include/std/shared_mutex
@@ -801,7 +801,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   unlock()
   {
if (!_M_owns)
- __throw_system_error(int(errc::resource_deadlock_would_occur));
+ __throw_system_error(int(errc::operation_not_permitted));
_M_pm->unlock_shared();
_M_owns = false;
   }
diff --git a/libstdc++-v3/testsuite/30_threads/shared_lock/locking/112089.cc 
b/libstdc++-v3/testsuite/30_threads/shared_lock/locking/112089.cc
new file mode 100644
index 000..432c17591a1
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/shared_lock/locking/112089.cc
@@ -0,0 +1,23 @@
+// { dg-do run { target c++14 } }
+// { dg-require-gthreads "" }
+// { dg-additional-options "-pthread" { target pthread } }
+
+#include 
+#include 
+#include 
+
+// PR libstdc++/112089 shared_lock::unlock should throw operation_not_permitted
+
+int main()
+{
+  std::shared_lock l;
+  try
+  {
+l.unlock();
+VERIFY( false );
+  }
+  catch (const std::system_error& e)
+  {
+VERIFY( e.code() == std::errc::operation_not_permitted );
+  }
+}


[gcc r12-10246] libstdc++: Fix Unicode codecvt and add tests [PR86419]

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:12c193e5723f08694c8784457200112bae117063

commit r12-10246-g12c193e5723f08694c8784457200112bae117063
Author: Dimitrij Mijoski 
Date:   Tue Jan 10 13:58:59 2023 +0100

libstdc++: Fix Unicode codecvt and add tests [PR86419]

Fixes the conversion from UTF-8 to UTF-16 to properly return partial
instead ok.
Fixes the conversion from UTF-16 to UTF-8 to properly return partial
instead ok.
Fixes the conversion from UTF-8 to UCS-2 to properly return partial
instead error.
Fixes the conversion from UTF-8 to UCS-2 to treat 4-byte UTF-8 sequences
as error just by seeing the leading byte.
Fixes UTF-8 decoding for all codecvts so they detect error at the end of
the input range when the last code point is also incomplete.

libstdc++-v3/ChangeLog:

PR libstdc++/86419
* src/c++11/codecvt.cc (read_utf8_code_point): Correctly detect
errors in incomplete multibyte sequences.
(utf16_in): Remove surrogates parameter. Fix conditions for
returning partial.
(utf16_out): Fix condition for returning partial.
(ucs2_in): Do not pass surrogates argument to utf16_in.
* testsuite/22_locale/codecvt/codecvt_unicode.cc: New test.
* testsuite/22_locale/codecvt/codecvt_unicode.h: New header for
tests.
* testsuite/22_locale/codecvt/codecvt_unicode_wchar_t.cc: New
test.

(cherry picked from commit 02dab998665dda0f6df31740e8897c42de3d740f)

Diff:
---
 libstdc++-v3/src/c++11/codecvt.cc  |   36 +-
 .../testsuite/22_locale/codecvt/codecvt_unicode.cc |   68 ++
 .../testsuite/22_locale/codecvt/codecvt_unicode.h  | 1269 
 .../22_locale/codecvt/codecvt_unicode_wchar_t.cc   |   59 +
 4 files changed, 1414 insertions(+), 18 deletions(-)

diff --git a/libstdc++-v3/src/c++11/codecvt.cc 
b/libstdc++-v3/src/c++11/codecvt.cc
index 9f8cb767732..03f0bfda972 100644
--- a/libstdc++-v3/src/c++11/codecvt.cc
+++ b/libstdc++-v3/src/c++11/codecvt.cc
@@ -277,13 +277,15 @@ namespace
 }
 else if (c1 < 0xF0) // 3-byte sequence
 {
-  if (avail < 3)
+  if (avail < 2)
return incomplete_mb_character;
   char32_t c2 = (unsigned char) from[1];
   if ((c2 & 0xC0) != 0x80)
return invalid_mb_sequence;
   if (c1 == 0xE0 && c2 < 0xA0) // overlong
return invalid_mb_sequence;
+  if (avail < 3)
+   return incomplete_mb_character;
   char32_t c3 = (unsigned char) from[2];
   if ((c3 & 0xC0) != 0x80)
return invalid_mb_sequence;
@@ -292,9 +294,9 @@ namespace
from += 3;
   return c;
 }
-else if (c1 < 0xF5) // 4-byte sequence
+else if (c1 < 0xF5 && maxcode > 0x) // 4-byte sequence
 {
-  if (avail < 4)
+  if (avail < 2)
return incomplete_mb_character;
   char32_t c2 = (unsigned char) from[1];
   if ((c2 & 0xC0) != 0x80)
@@ -302,10 +304,14 @@ namespace
   if (c1 == 0xF0 && c2 < 0x90) // overlong
return invalid_mb_sequence;
   if (c1 == 0xF4 && c2 >= 0x90) // > U+10
-  return invalid_mb_sequence;
+   return invalid_mb_sequence;
+  if (avail < 3)
+   return incomplete_mb_character;
   char32_t c3 = (unsigned char) from[2];
   if ((c3 & 0xC0) != 0x80)
return invalid_mb_sequence;
+  if (avail < 4)
+   return incomplete_mb_character;
   char32_t c4 = (unsigned char) from[3];
   if ((c4 & 0xC0) != 0x80)
return invalid_mb_sequence;
@@ -527,12 +533,11 @@ namespace
   // Flag indicating whether to process UTF-16 or UCS2
   enum class surrogates { allowed, disallowed };
 
-  // utf8 -> utf16 (or utf8 -> ucs2 if s == surrogates::disallowed)
-  template
+  // utf8 -> utf16 (or utf8 -> ucs2 if maxcode <= 0x)
+  template 
   codecvt_base::result
-  utf16_in(range& from, range& to,
-  unsigned long maxcode = max_code_point, codecvt_mode mode = {},
-  surrogates s = surrogates::allowed)
+  utf16_in(range &from, range &to,
+  unsigned long maxcode = max_code_point, codecvt_mode mode = {})
   {
 read_utf8_bom(from, mode);
 while (from.size() && to.size())
@@ -540,12 +545,7 @@ namespace
auto orig = from;
const char32_t codepoint = read_utf8_code_point(from, maxcode);
if (codepoint == incomplete_mb_character)
- {
-   if (s == surrogates::allowed)
- return codecvt_base::partial;
-   else
- return codecvt_base::error; // No surrogates in UCS2
- }
+ return codecvt_base::partial;
if (codepoint > maxcode)
  return codecvt_base::error;
if (!write_utf16_code_point(to, codepoint, mode))
@@ -554,7 +554,7 @@ namespace
return codecvt_base::partial;
  }
   }
-return codecvt_base::ok;
+return from.size() ? codecvt_base::partial : codecvt_base::ok;
   }
 
   // utf16 -> utf8 (

[gcc r12-10254] libstdc++: Add static_assert to std::integer_sequence [PR112473]

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:dc0964f43dcee46dcd1843287a541668fd08a4a8

commit r12-10254-gdc0964f43dcee46dcd1843287a541668fd08a4a8
Author: Jonathan Wakely 
Date:   Fri Nov 10 12:21:52 2023 +

libstdc++: Add static_assert to std::integer_sequence [PR112473]

C++20 allows class types as non-type template parameters, but
std::integer_sequence explicitly disallows them. Enforce that.

libstdc++-v3/ChangeLog:

PR libstdc++/112473
* include/bits/utility.h (integer_sequence): Add static_assert.
* testsuite/20_util/integer_sequence/112473.cc: New test.

(cherry picked from commit 0953497a81f1e320989b9f2aaa7f56747eddd4a0)

Diff:
---
 libstdc++-v3/include/bits/utility.h   | 3 +++
 libstdc++-v3/testsuite/20_util/integer_sequence/112473.cc | 8 
 2 files changed, 11 insertions(+)

diff --git a/libstdc++-v3/include/bits/utility.h 
b/libstdc++-v3/include/bits/utility.h
index 180866e3581..6483a8e537e 100644
--- a/libstdc++-v3/include/bits/utility.h
+++ b/libstdc++-v3/include/bits/utility.h
@@ -163,6 +163,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
 struct integer_sequence
 {
+#if __cplusplus >= 202002L
+  static_assert(is_integral_v<_Tp>);
+#endif
   typedef _Tp value_type;
   static constexpr size_t size() noexcept { return sizeof...(_Idx); }
 };
diff --git a/libstdc++-v3/testsuite/20_util/integer_sequence/112473.cc 
b/libstdc++-v3/testsuite/20_util/integer_sequence/112473.cc
new file mode 100644
index 000..14abfbc8149
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/integer_sequence/112473.cc
@@ -0,0 +1,8 @@
+// { dg-do compile { target c++20 } }
+
+// PR libstdc++/112473 - integer_sequence accepts non-integer types
+
+#include 
+
+std::integer_sequence, std::pair{0, 0}> ic;
+// { dg-error "static assertion failed" "" { target *-*-* } 0 }


[gcc r12-10255] libstdc++: Explicitly default some copy ctors and assignments

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:a389921f175c30e8ca0da38ccb79ed60cf744fd4

commit r12-10255-ga389921f175c30e8ca0da38ccb79ed60cf744fd4
Author: Jonathan Wakely 
Date:   Tue Aug 8 16:24:31 2023 +0100

libstdc++: Explicitly default some copy ctors and assignments

The standard says that the implicit copy assignment operator is
deprecated for classes that have a user-provided copy constructor, and
vice versa.

libstdc++-v3/ChangeLog:

* include/bits/new_allocator.h (__new_allocator): Define copy
assignment operator as defaulted.
* include/std/complex (complex, complex)
(complex): Define copy constructor as defaulted.

(cherry picked from commit 008e439f34d4b356825a6c9b70245143f00bd353)

Diff:
---
 libstdc++-v3/include/bits/new_allocator.h |  4 
 libstdc++-v3/include/std/complex  | 12 
 2 files changed, 16 insertions(+)

diff --git a/libstdc++-v3/include/bits/new_allocator.h 
b/libstdc++-v3/include/bits/new_allocator.h
index 99f7a2ee51e..d066d015a9d 100644
--- a/libstdc++-v3/include/bits/new_allocator.h
+++ b/libstdc++-v3/include/bits/new_allocator.h
@@ -86,6 +86,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX20_CONSTEXPR
__new_allocator(const __new_allocator<_Tp1>&) _GLIBCXX_USE_NOEXCEPT { }
 
+#if __cplusplus >= 201103L
+  __new_allocator& operator=(const __new_allocator&) = default;
+#endif
+
 #if __cplusplus <= 201703L
   ~__new_allocator() _GLIBCXX_USE_NOEXCEPT { }
 
diff --git a/libstdc++-v3/include/std/complex b/libstdc++-v3/include/std/complex
index 8f9368fd7d0..bdc238e73b0 100644
--- a/libstdc++-v3/include/std/complex
+++ b/libstdc++-v3/include/std/complex
@@ -1098,6 +1098,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   }
 #endif
 
+#if __cplusplus >= 201103L
+  _GLIBCXX14_CONSTEXPR complex(const complex&) = default;
+#endif
+
   explicit _GLIBCXX_CONSTEXPR complex(const complex&);
   explicit _GLIBCXX_CONSTEXPR complex(const complex&);
 
@@ -1244,6 +1248,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   }
 #endif
 
+#if __cplusplus >= 201103L
+  _GLIBCXX14_CONSTEXPR complex(const complex&) = default;
+#endif
+
   _GLIBCXX_CONSTEXPR complex(const complex& __z)
   : _M_value(__z.__rep()) { }
 
@@ -1391,6 +1399,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   }
 #endif
 
+#if __cplusplus >= 201103L
+  _GLIBCXX14_CONSTEXPR complex(const complex&) = default;
+#endif
+
   _GLIBCXX_CONSTEXPR complex(const complex& __z)
   : _M_value(__z.__rep()) { }


[gcc r12-10257] libstdc++: Define std::basic_stringbuf::view() for old std::string ABI

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:e35b26c2442b61e7f45deb5ef3062d0ab6ec584b

commit r12-10257-ge35b26c2442b61e7f45deb5ef3062d0ab6ec584b
Author: Jonathan Wakely 
Date:   Tue Jan 31 22:32:15 2023 +

libstdc++: Define std::basic_stringbuf::view() for old std::string ABI

Unlike the new str()&& members in , there is no real difficulty
in supporting the new view() members for the old std::string ABI.
Enabling it fixes errors in  where std::ostringstream::view() is
used by ostream insertion operators for calendar types.

We just need to use [[gnu::always_inline]] on the view() members for the
old ABI, because the library doesn't contain instantiations of them for
the old ABI. Making them always inline avoids needing to add those
instantiations and export them.

libstdc++-v3/ChangeLog:

* include/std/sstream  (basic_stringbuf::view): Define for old
std::string ABI.
(basic_istringstream::view, basic_stringstream::view)
(basic_stringstream::view): Likewise.
* testsuite/27_io/basic_istringstream/view/char/1.cc: Remove
{ dg-require-effective-target cxx11_abi }.
* testsuite/27_io/basic_istringstream/view/wchar_t/1.cc:
Likewise.
* testsuite/27_io/basic_ostringstream/view/char/1.cc: Likewise.
* testsuite/27_io/basic_ostringstream/view/wchar_t/1.cc:
Likewise.
* testsuite/27_io/basic_stringbuf/view/char/1.cc: Likewise.
* testsuite/27_io/basic_stringbuf/view/wchar_t/1.cc: Likewise.
* testsuite/27_io/basic_stringstream/view/char/1.cc: Likewise.
* testsuite/27_io/basic_stringstream/view/wchar_t/1.cc:
Likewise.

(cherry picked from commit 331b4f168a06cd85fe40fd03b48b128cc8af399c)

Diff:
---
 libstdc++-v3/include/std/sstream   | 32 +-
 .../27_io/basic_istringstream/view/char/1.cc   |  1 -
 .../27_io/basic_istringstream/view/wchar_t/1.cc|  1 -
 .../27_io/basic_ostringstream/view/char/1.cc   |  1 -
 .../27_io/basic_ostringstream/view/wchar_t/1.cc|  1 -
 .../testsuite/27_io/basic_stringbuf/view/char/1.cc |  1 -
 .../27_io/basic_stringbuf/view/wchar_t/1.cc|  1 -
 .../27_io/basic_stringstream/view/char/1.cc|  1 -
 .../27_io/basic_stringstream/view/wchar_t/1.cc |  1 -
 9 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/libstdc++-v3/include/std/sstream b/libstdc++-v3/include/std/sstream
index bc7d636e702..3a86888a76c 100644
--- a/libstdc++-v3/include/std/sstream
+++ b/libstdc++-v3/include/std/sstream
@@ -41,10 +41,15 @@
 
 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
 # define _GLIBCXX_LVAL_REF_QUAL &
+# define _GLIBCXX_SSTREAM_ALWAYS_INLINE
 #else
 # define _GLIBCXX_LVAL_REF_QUAL
+// For symbols that are not exported from libstdc++.so for the COW string ABI.
+# define _GLIBCXX_SSTREAM_ALWAYS_INLINE [[__gnu__::__always_inline__]]
 #endif
 
+
+
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -249,7 +254,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
return __ret;
   }
 
-#if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
+#if __cplusplus > 201703L
+#if _GLIBCXX_USE_CXX11_ABI
 #if __cpp_concepts
   template<__allocator_like _SAlloc>
basic_string<_CharT, _Traits, _SAlloc>
@@ -273,7 +279,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
_M_sync(_M_string.data(), 0, 0);
return __str;
   }
+#endif // cxx11 ABI
 
+  _GLIBCXX_SSTREAM_ALWAYS_INLINE
   basic_string_view
   view() const noexcept
   {
@@ -696,7 +704,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   str() const _GLIBCXX_LVAL_REF_QUAL
   { return _M_stringbuf.str(); }
 
-#if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
+#if __cplusplus > 201703L
+#if _GLIBCXX_USE_CXX11_ABI
 #if __cpp_concepts
   template<__allocator_like _SAlloc>
basic_string<_CharT, _Traits, _SAlloc>
@@ -707,11 +716,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   __string_type
   str() &&
   { return std::move(_M_stringbuf).str(); }
+#endif // cxx11 ABI
 
+  _GLIBCXX_SSTREAM_ALWAYS_INLINE
   basic_string_view
   view() const noexcept
   { return _M_stringbuf.view(); }
-#endif
+#endif // C++20
 
   /**
*  @brief  Setting a new buffer.
@@ -917,7 +928,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   str() const _GLIBCXX_LVAL_REF_QUAL
   { return _M_stringbuf.str(); }
 
-#if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
+#if __cplusplus > 201703L
+#if _GLIBCXX_USE_CXX11_ABI
 #if __cpp_concepts
   template<__allocator_like _SAlloc>
basic_string<_CharT, _Traits, _SAlloc>
@@ -928,11 +940,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   __string_type
   str() &&
   { return std::move(_M_stringbuf).str(); }
+#endif // cxx11 ABI
 
+  _GLIBCXX_SSTREAM_ALWAYS_INLINE
   basic_string_view
   view() const noexcept
   { return _M_stringbuf.view(); }
-

[gcc r12-10265] libstdc++: Add macros for the inline namespace std::_V2

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:f8ab9b7c08161739242b2760f881a3918373cd46

commit r12-10265-gf8ab9b7c08161739242b2760f881a3918373cd46
Author: Jonathan Wakely 
Date:   Wed May 11 16:35:45 2022 +0100

libstdc++: Add macros for the inline namespace std::_V2

Use macros to open and close the inline namespace _V2 that is used for
ABI versioning of individual components such as chrono::system_clock.

This allows the namespace to be hidden in the docs generated by Doxygen,
so that we document std::foo instead of std::_V2::foo.

This also makes it easy to remove that namespace entirely for the
gnu-versioned-namespace build, where everything is already versioned as
std::__8 and there are no backwards compatibility guarantees.

libstdc++-v3/ChangeLog:

* doc/doxygen/user.cfg.in (PREDEFINED): Expand new macros to
nothing.
* include/bits/c++config (_GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE)
(_GLIBCXX_END_INLINE_ABI_NAMESPACE): Define new macros.
* include/bits/algorithmfwd.h (_V2::__rotate): Use new macros
for the namespace.
* include/bits/chrono.h (chrono::_V2::system_clock): Likewise.
* include/bits/stl_algo.h (_V2::__rotate): Likewise.
* include/std/condition_variable (_V2::condition_variable_any):
Likewise.
* include/std/system_error (_V2::error_category): Likewise.

(cherry picked from commit e4905f11852d722cd711b53a5626245528ace1d2)

Diff:
---
 libstdc++-v3/doc/doxygen/user.cfg.in|  2 ++
 libstdc++-v3/include/bits/algorithmfwd.h| 15 ---
 libstdc++-v3/include/bits/c++config | 11 +--
 libstdc++-v3/include/bits/chrono.h  |  4 ++--
 libstdc++-v3/include/bits/stl_algo.h|  5 ++---
 libstdc++-v3/include/std/condition_variable |  4 ++--
 libstdc++-v3/include/std/system_error   |  5 +++--
 7 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/libstdc++-v3/doc/doxygen/user.cfg.in 
b/libstdc++-v3/doc/doxygen/user.cfg.in
index b095addd10c..ba85d4bb2a8 100644
--- a/libstdc++-v3/doc/doxygen/user.cfg.in
+++ b/libstdc++-v3/doc/doxygen/user.cfg.in
@@ -2348,6 +2348,8 @@ PREDEFINED = __cplusplus=202002L \
  "_GLIBCXX_END_NAMESPACE_CONTAINER= " \
  "_GLIBCXX_END_NAMESPACE_CXX11= " \
  "_GLIBCXX_END_NAMESPACE_LDBL= " \
+"-D_GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(X)= " \
+"-D_GLIBCXX_END_INLINE_ABI_NAMESPACE(X)= " \
  "_GLIBCXX_TEMPLATE_ARGS=...  " \
  "_GLIBCXX_DEPRECATED= " \
  "_GLIBCXX_DEPRECATED_SUGGEST(E)= " \
diff --git a/libstdc++-v3/include/bits/algorithmfwd.h 
b/libstdc++-v3/include/bits/algorithmfwd.h
index 5b85b0bc60d..4cfc53f4968 100644
--- a/libstdc++-v3/include/bits/algorithmfwd.h
+++ b/libstdc++-v3/include/bits/algorithmfwd.h
@@ -601,13 +601,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 _OIter
 reverse_copy(_BIter, _BIter, _OIter);
 
-  inline namespace _V2
-  {
-template
-  _GLIBCXX20_CONSTEXPR
-  _FIter
-  rotate(_FIter, _FIter, _FIter);
-  }
+_GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2)
+
+  template
+_GLIBCXX20_CONSTEXPR
+_FIter
+rotate(_FIter, _FIter, _FIter);
+
+_GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
 
   template
 _GLIBCXX20_CONSTEXPR
diff --git a/libstdc++-v3/include/bits/c++config 
b/libstdc++-v3/include/bits/c++config
index 2798b9786dc..150b0bc5834 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -345,13 +345,16 @@ namespace __gnu_cxx
 # define _GLIBCXX_DEFAULT_ABI_TAG
 #endif
 
-// Defined if inline namespaces are used for versioning.
+// Non-zero if inline namespaces are used for versioning the entire library.
 #define _GLIBCXX_INLINE_VERSION 
 
-// Inline namespace for symbol versioning.
 #if _GLIBCXX_INLINE_VERSION
+// Inline namespace for symbol versioning of (nearly) everything in std.
 # define _GLIBCXX_BEGIN_NAMESPACE_VERSION namespace __8 {
 # define _GLIBCXX_END_NAMESPACE_VERSION }
+// Unused when everything in std is versioned anyway.
+# define _GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(X)
+# define _GLIBCXX_END_INLINE_ABI_NAMESPACE(X)
 
 namespace std
 {
@@ -376,8 +379,12 @@ _GLIBCXX_END_NAMESPACE_VERSION
 }
 
 #else
+// Unused.
 # define _GLIBCXX_BEGIN_NAMESPACE_VERSION
 # define _GLIBCXX_END_NAMESPACE_VERSION
+// Used to version individual components, e.g. std::_V2::error_category.
+# define _GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(X) inline namespace X {
+# define _GLIBCXX_END_INLINE_ABI_NAMESPACE(X)   } // inline namespace X
 #endif
 
 // Inline namespaces for special modes: debug, parallel.
diff --git a/libstdc++-v3/include/bits/chrono.h 
b/libstdc++-v3/include/bits/chrono.h
index d09f8563a59..43d91b8713b 100644
--- a/libstdc++-v3/include/bits/chrono.h
+++ b/libstdc++-v3/include/bits/chro

[gcc r12-10259] libstdc++: use grep -E instead of egrep in scripts

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:c6f80dca4e51eaab3f12884e19b3dbbfe9cdffd7

commit r12-10259-gc6f80dca4e51eaab3f12884e19b3dbbfe9cdffd7
Author: Xi Ruoyao 
Date:   Fri Jun 24 15:02:23 2022 +0800

libstdc++: use grep -E instead of egrep in scripts

egrep has been deprecated in favor of grep -E for a long time, and the
next grep release (3.8 or 4.0) will print a warning of egrep is used.
Stop using egrep so we won't see the warning.

grep's from GNU, BSD (including Mac OS X), AIX, BusyBox all support -E
and -F.  Solaris grep doesn't support -E, but extract_symvers.in already
contains a special case for Solaris and doxygen documentation generation
is already broken on non-GNU.

libstdc++-v3/ChangeLog:

* scripts/extract_symvers.in: Use grep -E instead of egrep.
* scripts/run_doxygen: Likewise.

(cherry picked from commit fa4e97907fc979f550c3f02cde03d9c35f99df9b)

Diff:
---
 libstdc++-v3/scripts/extract_symvers.in | 4 ++--
 libstdc++-v3/scripts/run_doxygen| 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/scripts/extract_symvers.in 
b/libstdc++-v3/scripts/extract_symvers.in
index dd9f63d4f16..d8ea62355ae 100755
--- a/libstdc++-v3/scripts/extract_symvers.in
+++ b/libstdc++-v3/scripts/extract_symvers.in
@@ -54,8 +54,8 @@ SunOS)
   ${readelf} ${lib} |\
   sed -e 's/ \[: [A-Fa-f0-9]*\] //' -e '/\.dynsym/,/^$/p;d' |\
   sed -e 's/ \[: [0-9]*\] //' |\
-  egrep -v ' (LOCAL|UND) ' |\
-  egrep -v ' 
(_DYNAMIC|_GLOBAL_OFFSET_TABLE_|_PROCEDURE_LINKAGE_TABLE_|_edata|_end|_etext)$' 
|\
+  grep -E -v ' (LOCAL|UND) ' |\
+  grep -E -v ' 
(_DYNAMIC|_GLOBAL_OFFSET_TABLE_|_PROCEDURE_LINKAGE_TABLE_|_edata|_end|_etext)$' 
|\
   sed -e 's/ : / :_/g' |\
   sed -e 's/ : / :_/g' |\
   sed -e 's/ : / :_/g' |\
diff --git a/libstdc++-v3/scripts/run_doxygen b/libstdc++-v3/scripts/run_doxygen
index 86da071d86c..50514c744c9 100644
--- a/libstdc++-v3/scripts/run_doxygen
+++ b/libstdc++-v3/scripts/run_doxygen
@@ -291,7 +291,7 @@ cxxflags="-Og -g -std=gnu++23"
 $gxx $cppflags $cxxflags ${srcdir}/doc/doxygen/stdheader.cc -o ./stdheader || 
exit 1
 # Doxygen outputs something like "\fC#include \fP" and
 # we want that internal header to be replaced with something like .
-problematic=`egrep -l '#include <.*h>' [a-z]*.3`
+problematic=`grep -E -l '#include <.*h>' [a-z]*.3`
 for f in $problematic; do
 # this is also slow, but safe and easy to debug
 oldh=`sed -n '/fC#include .*/\1/p' $f`
@@ -303,7 +303,7 @@ rm stdheader
 # Some of the pages for generated modules have text that confuses certain
 # implementations of man(1), e.g. on GNU/Linux.  We need to have another
 # top-level *roff tag to /stop/ the .SH NAME entry.
-problematic=`egrep --files-without-match '^\.SH SYNOPSIS' [A-Z]*.3`
+problematic=`grep -E --files-without-match '^\.SH SYNOPSIS' [A-Z]*.3`
 #problematic='Containers.3 Sequences.3 Assoc_containers.3 Iterator_types.3'
 
 for f in $problematic; do


[gcc r12-10267] libstdc++: Improve doxygen docs for

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:f0db5dfce8c729def8ce12ff7e3ed3b1e4f49467

commit r12-10267-gf0db5dfce8c729def8ce12ff7e3ed3b1e4f49467
Author: Jonathan Wakely 
Date:   Wed May 11 23:52:20 2022 +0100

libstdc++: Improve doxygen docs for 

libstdc++-v3/ChangeLog:

* include/std/atomic: Suppress doxygen docs for
implementation details.
* include/bits/atomic_base.h: Likewise.
* include/bits/shared_ptr_atomic.h: Use markdown. Fix grouping
so that std::atomic is not added to the pointer abstractions
group.

(cherry picked from commit 1566ca0969ac4a14f7434d710e75dd89da303e75)

Diff:
---
 libstdc++-v3/include/bits/atomic_base.h   | 39 ---
 libstdc++-v3/include/bits/shared_ptr_atomic.h | 32 +-
 libstdc++-v3/include/std/atomic   |  8 +++---
 3 files changed, 54 insertions(+), 25 deletions(-)

diff --git a/libstdc++-v3/include/bits/atomic_base.h 
b/libstdc++-v3/include/bits/atomic_base.h
index 5cf217dbf28..d29e4434177 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -86,6 +86,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 } memory_order;
 #endif
 
+  /// @cond undocumented
   enum __memory_order_modifier
 {
   __memory_order_mask  = 0x0,
@@ -93,6 +94,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   __memory_order_hle_acquire   = 0x1,
   __memory_order_hle_release   = 0x2
 };
+  /// @endcond
 
   constexpr memory_order
   operator|(memory_order __m, __memory_order_modifier __mod)
@@ -106,6 +108,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 return memory_order(int(__m) & int(__mod));
   }
 
+  /// @cond undocumented
+
   // Drop release ordering as per [atomics.types.operations.req]/21
   constexpr memory_order
   __cmpexch_failure_order2(memory_order __m) noexcept
@@ -128,6 +132,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
&& (__m & __memory_order_mask) != memory_order_acq_rel;
   }
 
+  // Base types for atomics.
+  template
+struct __atomic_base;
+
+  /// @endcond
+
   _GLIBCXX_ALWAYS_INLINE void
   atomic_thread_fence(memory_order __m) noexcept
   { __atomic_thread_fence(int(__m)); }
@@ -145,16 +155,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   return __ret;
 }
 
-  // Base types for atomics.
-  template
-struct __atomic_base;
-
-#if __cplusplus <= 201703L
-# define _GLIBCXX20_INIT(I)
-#else
+#if __cplusplus >= 202002L
 # define __cpp_lib_atomic_value_initialization 201911L
+#endif
+
+/// @cond undocumented
+#if __cpp_lib_atomic_value_initialization
 # define _GLIBCXX20_INIT(I) = I
+#else
+# define _GLIBCXX20_INIT(I)
 #endif
+/// @endcond
 
 #define ATOMIC_VAR_INIT(_VI) { _VI }
 
@@ -171,8 +182,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 typedef unsigned char __atomic_flag_data_type;
 #endif
 
-  /**
-   *  @brief Base type for atomic_flag.
+  /// @cond undocumented
+
+  /*
+   *  Base type for atomic_flag.
*
*  Base type is POD with data, allowing atomic_flag to derive from
*  it and meet the standard layout type requirement. In addition to
@@ -190,6 +203,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   _GLIBCXX_END_EXTERN_C
 
+  /// @endcond
+
 #define ATOMIC_FLAG_INIT { 0 }
 
   /// atomic_flag
@@ -295,6 +310,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 { return __i ? __GCC_ATOMIC_TEST_AND_SET_TRUEVAL : 0; }
   };
 
+  /// @cond undocumented
 
   /// Base class for atomic integrals.
   //
@@ -936,7 +952,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   { return __atomic_fetch_sub(&_M_p, _M_type_size(__d), int(__m)); }
 };
 
+  /// @endcond
+
 #if __cplusplus > 201703L
+  /// @cond undocumented
+
   // Implementation details of atomic_ref and atomic.
   namespace __atomic_impl
   {
@@ -1936,6 +1956,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   _Tp** _M_ptr;
 };
 
+  /// @endcond
 #endif // C++2a
 
   /// @} group atomics
diff --git a/libstdc++-v3/include/bits/shared_ptr_atomic.h 
b/libstdc++-v3/include/bits/shared_ptr_atomic.h
index e903fe89424..51ad32ce21b 100644
--- a/libstdc++-v3/include/bits/shared_ptr_atomic.h
+++ b/libstdc++-v3/include/bits/shared_ptr_atomic.h
@@ -64,9 +64,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /**
* @addtogroup pointer_abstractions
+   * @relates shared_ptr
* @{
*/
-  /// @relates shared_ptr @{
 
   /// @cond undocumented
 
@@ -120,8 +120,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*  @param  __p A non-null pointer to a shared_ptr object.
*  @return @c *__p
*
-   *  The memory order shall not be @c memory_order_release or
-   *  @c memory_order_acq_rel.
+   *  The memory order shall not be `memory_order_release` or
+   *  `memory_order_acq_rel`.
*  @{
   */
   template
@@ -156,8 +156,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*  @param  __p A non-null pointer to a shared_ptr object.
*  @param  __r The value to store.
*
-   *  The memory order shall not be @c memory_order_acquire or
-   *  @c memory_order_acq_rel.
+   *

[gcc r12-10261] libstdc++: Simplify detection idiom using concepts

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:1bb467f4910dc4abd90a7be98653b63113e5d6d3

commit r12-10261-g1bb467f4910dc4abd90a7be98653b63113e5d6d3
Author: Jonathan Wakely 
Date:   Fri Sep 23 23:16:30 2022 +0100

libstdc++: Simplify detection idiom using concepts

Add a simpler definition of std::__detected_or using concepts.  This
also replaces the __detector::value_t member which should have been using
a reserved name.

Use __detected_or in pointer_traits.

libstdc++-v3/ChangeLog:

* include/bits/alloc_traits.h (allocator_traits::is_always_equal):
Only instantiate is_empty if needed.
* include/bits/ptr_traits.h (__ptr_traits_impl::difference_type)
(__ptr_traits_impl::rebind): Use __detected_or.
* include/experimental/type_traits (is_same_v): Add a partial
specialization instead of instantiating the std::is_same class
template.
(detected_t): Redefine in terms of detected_or_t.
(is_detected, is_detected_v): Redefine in terms of detected_t.
* include/std/type_traits [__cpp_concepts] (__detected_or): Add
new definition using concepts.
(__detector::value_t): Rename to __is_detected.
* testsuite/17_intro/names.cc: Check value_t isn't used.

(cherry picked from commit 2b667beba693e876322af7c6682f9bc885c5ec28)

Diff:
---
 libstdc++-v3/include/bits/alloc_traits.h  |  4 ++--
 libstdc++-v3/include/bits/ptr_traits.h| 27 +--
 libstdc++-v3/include/experimental/type_traits | 24 
 libstdc++-v3/include/std/type_traits  | 27 ---
 libstdc++-v3/testsuite/17_intro/names.cc  |  1 +
 5 files changed, 44 insertions(+), 39 deletions(-)

diff --git a/libstdc++-v3/include/bits/alloc_traits.h 
b/libstdc++-v3/include/bits/alloc_traits.h
index 5cc52babef8..25496bc6f83 100644
--- a/libstdc++-v3/include/bits/alloc_traits.h
+++ b/libstdc++-v3/include/bits/alloc_traits.h
@@ -72,7 +72,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 template
   using __pocs = typename _Tp::propagate_on_container_swap;
 template
-  using __equal = typename _Tp::is_always_equal;
+  using __equal = __type_identity;
   };
 
   template
@@ -207,7 +207,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* otherwise @c is_empty::type
   */
   using is_always_equal
-   = __detected_or_t::type, __equal, _Alloc>;
+   = typename __detected_or_t, __equal, _Alloc>::type;
 
   template
using rebind_alloc = __alloc_rebind<_Alloc, _Tp>;
diff --git a/libstdc++-v3/include/bits/ptr_traits.h 
b/libstdc++-v3/include/bits/ptr_traits.h
index 8360c3b6557..ae8810706ab 100644
--- a/libstdc++-v3/include/bits/ptr_traits.h
+++ b/libstdc++-v3/include/bits/ptr_traits.h
@@ -144,29 +144,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 struct __ptr_traits_impl : __ptr_traits_ptr_to<_Ptr, _Elt>
 {
 private:
-  template
-   struct __difference { using type = ptrdiff_t; };
-
   template
-#if __cpp_concepts
-   requires requires { typename _Tp::difference_type; }
-   struct __difference<_Tp>
-#else
-   struct __difference<_Tp, __void_t>
-#endif
-   { using type = typename _Tp::difference_type; };
-
-  template
-   struct __rebind : __replace_first_arg<_Tp, _Up> { };
+   using __diff_t = typename _Tp::difference_type;
 
   template
-#if __cpp_concepts
-   requires requires { typename _Tp::template rebind<_Up>; }
-   struct __rebind<_Tp, _Up>
-#else
-   struct __rebind<_Tp, _Up, __void_t>>
-#endif
-   { using type = typename _Tp::template rebind<_Up>; };
+   using __rebind = __type_identity>;
 
 public:
   /// The pointer type.
@@ -176,11 +158,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   using element_type = _Elt;
 
   /// The type used to represent the difference between two pointers.
-  using difference_type = typename __difference<_Ptr>::type;
+  using difference_type = __detected_or_t;
 
   /// A pointer to a different type.
   template
-using rebind = typename __rebind<_Ptr, _Up>::type;
+   using rebind = typename __detected_or_t<__replace_first_arg<_Ptr, _Up>,
+   __rebind, _Ptr, _Up>::type;
 };
 
   // _GLIBCXX_RESOLVE_LIB_DEFECTS
diff --git a/libstdc++-v3/include/experimental/type_traits 
b/libstdc++-v3/include/experimental/type_traits
index af5970e80d0..fa25a1c2be2 100644
--- a/libstdc++-v3/include/experimental/type_traits
+++ b/libstdc++-v3/include/experimental/type_traits
@@ -223,7 +223,9 @@ template 
 
 // See C++14 20.10.6, type relations
 template 
-  constexpr bool is_same_v = is_same<_Tp, _Up>::value;
+  constexpr bool is_same_v = false;
+template 
+  constexpr bool is_same_v<_Tp, _Tp> = true;
 template 
   constexpr bool is_base_of_v = is_base_of<_Base, _Derived>::value;
 template 
@@ -266,23 +268,21 @@ struct nonesuch : pr

[gcc r12-10266] libstdc++: Stop defining C++0x compat symbols for versioned namespace

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:914a226e3cda5a640c9640580a21d780eb829057

commit r12-10266-g914a226e3cda5a640c9640580a21d780eb829057
Author: Jonathan Wakely 
Date:   Mon May 16 16:54:52 2022 +0100

libstdc++: Stop defining C++0x compat symbols for versioned namespace

The src/c++11/compatibility*-c++0x.cc files define symbols that need to
be exported for ancient versions of libstdc++.so.6 due to changes
between C++0x and the final C++11 standard. Those symbols are not needed
in the libstdc++.so.8 library, and we can skip building them entirely.

This also fixes the build failure I introduced last week when making the
versioned namespace config not use the _V2 namespace for compat symbols.

libstdc++-v3/ChangeLog:

* src/Makefile.am [ENABLE_SYMVERS_GNU_NAMESPACE] (cxx11_sources):
Do not build the compatibility*-c++0x.cc objects.
* src/Makefile.in: Regenerate.
* src/c++11/compatibility-c++0x.cc [_GLIBCXX_INLINE_VERSION]:
Refuse to build for the versioned namespace.
* src/c++11/compatibility-chrono.cc: Likewise.
* src/c++11/compatibility-condvar.cc: Likewise.
* src/c++11/compatibility-thread-c++0x.cc: Likewise.
* src/c++11/chrono.cc (system_clock, steady_clock):
Use macros to define in inline namespace _V2, matching the
declarations in .
* src/c++11/system_error.cc (system_category, generic_category):
Likewise.

(cherry picked from commit 357d6fcd41e771128226b7916166f537b2d53a29)

Diff:
---
 libstdc++-v3/src/Makefile.am   | 16 +++
 libstdc++-v3/src/Makefile.in   | 31 +-
 libstdc++-v3/src/c++11/chrono.cc   |  5 ++--
 libstdc++-v3/src/c++11/compatibility-c++0x.cc  |  4 +++
 libstdc++-v3/src/c++11/compatibility-chrono.cc |  4 +++
 libstdc++-v3/src/c++11/compatibility-condvar.cc|  4 +++
 .../src/c++11/compatibility-thread-c++0x.cc|  4 +++
 libstdc++-v3/src/c++11/system_error.cc |  8 --
 8 files changed, 54 insertions(+), 22 deletions(-)

diff --git a/libstdc++-v3/src/Makefile.am b/libstdc++-v3/src/Makefile.am
index 9c3f4aca655..b83c222d51d 100644
--- a/libstdc++-v3/src/Makefile.am
+++ b/libstdc++-v3/src/Makefile.am
@@ -96,6 +96,16 @@ else
 ldbl_alt128_compat_sources =
 endif
 
+if ENABLE_SYMVERS_GNU_NAMESPACE
+cxx0x_compat_sources =
+else
+cxx0x_compat_sources = \
+   compatibility-atomic-c++0x.cc \
+   compatibility-c++0x.cc \
+   compatibility-chrono.cc \
+   compatibility-condvar.cc \
+   compatibility-thread-c++0x.cc
+endif
 
 parallel_compat_sources = \
compatibility-parallel_list.cc  compatibility-parallel_list-2.cc
@@ -108,11 +118,7 @@ cxx98_sources = \
${ldbl_compat_sources}
 
 cxx11_sources = \
-   compatibility-c++0x.cc \
-   compatibility-atomic-c++0x.cc \
-   compatibility-thread-c++0x.cc \
-   compatibility-chrono.cc \
-   compatibility-condvar.cc \
+   ${cxx0x_compat_sources} \
${ldbl_alt128_compat_sources}
 
 libstdc___la_SOURCES = $(cxx98_sources) $(cxx11_sources)
diff --git a/libstdc++-v3/src/Makefile.in b/libstdc++-v3/src/Makefile.in
index 4a06f6cfec1..cef290c5d11 100644
--- a/libstdc++-v3/src/Makefile.in
+++ b/libstdc++-v3/src/Makefile.in
@@ -153,14 +153,17 @@ am__DEPENDENCIES_1 =
 @GLIBCXX_LDBL_COMPAT_TRUE@am__objects_1 = compatibility-ldbl.lo
 am__objects_2 = compatibility.lo compatibility-debug_list.lo \
compatibility-debug_list-2.lo $(am__objects_1)
-@ENABLE_DUAL_ABI_TRUE@@GLIBCXX_LDBL_ALT128_COMPAT_TRUE@am__objects_3 = 
compatibility-ldbl-alt128-cxx11.lo
-@GLIBCXX_LDBL_ALT128_COMPAT_TRUE@am__objects_4 =  \
+@ENABLE_SYMVERS_GNU_NAMESPACE_FALSE@am__objects_3 = 
compatibility-atomic-c++0x.lo \
+@ENABLE_SYMVERS_GNU_NAMESPACE_FALSE@   compatibility-c++0x.lo \
+@ENABLE_SYMVERS_GNU_NAMESPACE_FALSE@   compatibility-chrono.lo \
+@ENABLE_SYMVERS_GNU_NAMESPACE_FALSE@   compatibility-condvar.lo \
+@ENABLE_SYMVERS_GNU_NAMESPACE_FALSE@   compatibility-thread-c++0x.lo
+@ENABLE_DUAL_ABI_TRUE@@GLIBCXX_LDBL_ALT128_COMPAT_TRUE@am__objects_4 = 
compatibility-ldbl-alt128-cxx11.lo
+@GLIBCXX_LDBL_ALT128_COMPAT_TRUE@am__objects_5 =  \
 @GLIBCXX_LDBL_ALT128_COMPAT_TRUE@  compatibility-ldbl-alt128.lo \
-@GLIBCXX_LDBL_ALT128_COMPAT_TRUE@  $(am__objects_3)
-am__objects_5 = compatibility-c++0x.lo compatibility-atomic-c++0x.lo \
-   compatibility-thread-c++0x.lo compatibility-chrono.lo \
-   compatibility-condvar.lo $(am__objects_4)
-am_libstdc___la_OBJECTS = $(am__objects_2) $(am__objects_5)
+@GLIBCXX_LDBL_ALT128_COMPAT_TRUE@  $(am__objects_4)
+am__objects_6 = $(am__objects_3) $(am__objects_5)
+am_libstdc___la_OBJECTS = $(am__objects_2) $(am__objects_6)
 libstdc___la_OBJECTS = $(am_libstdc___la_OBJECTS)
 @VTV_CYGMIN_FALSE@am_libstdc___la_rpath = -rpath $(toolexeclibdir)
 @VTV_CYGMIN_TRUE@am_libstdc___la_rpat

[gcc r12-10273] libstdc++: Fix -Wsystem-headers warnings

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:2d174d4181896129d465cbf42dc454f4f906892b

commit r12-10273-g2d174d4181896129d465cbf42dc454f4f906892b
Author: Jonathan Wakely 
Date:   Sat Nov 5 12:35:55 2022 +

libstdc++: Fix -Wsystem-headers warnings

Fix some problems noticed with -Wsystem-headers.

libstdc++-v3/ChangeLog:

* include/bits/stl_tempbuf.h (_Temporary_buffer): Disable
warnings about get_temporary_buffer being deprecated.
* include/ext/functional (mem_fun1, mem_fun1_ref): Disable
warnings about mem_fun1_t, const_mem_fun1_t, mem_fun1_ref_t and
const_mem_fun1_ref_t being deprecated.
* include/std/spanstream (basic_spanbuf::setbuf): Add assertion
and adjust to avoid narrowing warning.
* libsupc++/exception_ptr.h [!__cpp_rtti && !__cpp_exceptions]
(make_exception_ptr): Add missing inline specifier.

(cherry picked from commit 8f6d25f19bae521c3d028bcdcd69019540b8c3b9)

Diff:
---
 libstdc++-v3/include/bits/stl_tempbuf.h | 3 +++
 libstdc++-v3/include/ext/functional | 4 ++--
 libstdc++-v3/include/std/spanstream | 3 ++-
 libstdc++-v3/libsupc++/exception_ptr.h  | 2 +-
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_tempbuf.h 
b/libstdc++-v3/include/bits/stl_tempbuf.h
index db7cdb14ca9..f8323d4ab71 100644
--- a/libstdc++-v3/include/bits/stl_tempbuf.h
+++ b/libstdc++-v3/include/bits/stl_tempbuf.h
@@ -254,6 +254,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  __ucr(__first, __last, __seed);
 }
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
   template
 _Temporary_buffer<_ForwardIterator, _Tp>::
 _Temporary_buffer(_ForwardIterator __seed, size_type __original_len)
@@ -278,6 +280,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
}
 }
+#pragma GCC diagnostic pop
 
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
diff --git a/libstdc++-v3/include/ext/functional 
b/libstdc++-v3/include/ext/functional
index 19cd8d5b563..11c2de1294b 100644
--- a/libstdc++-v3/include/ext/functional
+++ b/libstdc++-v3/include/ext/functional
@@ -394,8 +394,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 { _M_initialize(161803398u); }
   };
 
-#pragma GCC diagnostic pop
-
   // Mem_fun adaptor helper functions mem_fun1 and mem_fun1_ref,
   // provided for backward compatibility, they are no longer part of
   // the C++ standard.
@@ -420,6 +418,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 mem_fun1_ref(_Ret (_Tp::*__f)(_Arg) const)
 { return std::const_mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); }
 
+#pragma GCC diagnostic pop
+
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
 
diff --git a/libstdc++-v3/include/std/spanstream 
b/libstdc++-v3/include/std/spanstream
index 5855b286efe..8fd74b8f9cb 100644
--- a/libstdc++-v3/include/std/spanstream
+++ b/libstdc++-v3/include/std/spanstream
@@ -134,7 +134,8 @@ template
 basic_streambuf<_CharT, _Traits>*
 setbuf(_CharT* __s, streamsize __n) override
 {
-  span({__s, __n});
+  __glibcxx_assert(__n >= 0);
+  this->span(std::span<_CharT>(__s, __n));
   return this;
 }
 
diff --git a/libstdc++-v3/libsupc++/exception_ptr.h 
b/libstdc++-v3/libsupc++/exception_ptr.h
index 6433f059e9c..07e456237db 100644
--- a/libstdc++-v3/libsupc++/exception_ptr.h
+++ b/libstdc++-v3/libsupc++/exception_ptr.h
@@ -271,7 +271,7 @@ namespace std
   // instead of a working one compiled with RTTI and/or exceptions enabled.
   template
 __attribute__ ((__always_inline__))
-exception_ptr
+inline exception_ptr
 make_exception_ptr(_Ex) _GLIBCXX_USE_NOEXCEPT
 { return exception_ptr(); }
 #endif


[gcc r12-10262] libstdc++: Update std::pointer_traits to match new LWG 3545 wording

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:57eb0358d0e0925f9e5aa282ed7f0274f6ff794e

commit r12-10262-g57eb0358d0e0925f9e5aa282ed7f0274f6ff794e
Author: Jonathan Wakely 
Date:   Mon Sep 26 18:59:45 2022 +0100

libstdc++: Update std::pointer_traits to match new LWG 3545 wording

It was pointed out in recent LWG 3545 discussion that having a
constrained partial specialization of std::pointer_traits can cause
ambiguities with program-defined specializations. For example, the
addition to the testcase has:

template requires std::derived_from;

This would be ambiguous with the library's own constrained partial
specialization:

template requires requires { typename Ptr::element_type; }
struct std::pointer_traits;

Neither specialization is more specialized than the other for a type
that is derived from base_type and also has an element_type member.

The solution is to remove the library's partial specialization, and do
the check for Ptr::element_type in the __ptr_traits_elem helper (which
is what we already do for !__cpp_concepts anyway).

libstdc++-v3/ChangeLog:

* include/bits/ptr_traits.h (__ptr_traits_elem) [__cpp_concepts]:
Also define the __ptr_traits_elem class template for the
concepts case.
(pointer_traits): Remove constrained partial
specialization.
* testsuite/20_util/pointer_traits/lwg3545.cc: Check for
ambiguitiy with program-defined partial specialization.

(cherry picked from commit 03cb9ed8dd603dbb77762ca948fc6381ba190731)

Diff:
---
 libstdc++-v3/include/bits/ptr_traits.h   | 20 ++--
 .../testsuite/20_util/pointer_traits/lwg3545.cc  | 17 +
 2 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/libstdc++-v3/include/bits/ptr_traits.h 
b/libstdc++-v3/include/bits/ptr_traits.h
index ae8810706ab..71370ff4fc9 100644
--- a/libstdc++-v3/include/bits/ptr_traits.h
+++ b/libstdc++-v3/include/bits/ptr_traits.h
@@ -73,25 +73,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 struct __replace_first_arg<_SomeTemplate<_Tp, _Types...>, _Up>
 { using type = _SomeTemplate<_Up, _Types...>; };
 
-#if __cpp_concepts
-  // When concepts are supported detection of _Ptr::element_type is done
-  // by a requires-clause, so __ptr_traits_elem_t only needs to do this:
-  template
-using __ptr_traits_elem_t = typename __get_first_arg<_Ptr>::type;
-#else
   // Detect the element type of a pointer-like type.
   template
 struct __ptr_traits_elem : __get_first_arg<_Ptr>
 { };
 
   // Use _Ptr::element_type if is a valid type.
+#if __cpp_concepts
+  template requires requires { typename _Ptr::element_type; }
+struct __ptr_traits_elem<_Ptr, void>
+{ using type = typename _Ptr::element_type; };
+#else
   template
 struct __ptr_traits_elem<_Ptr, __void_t>
 { using type = typename _Ptr::element_type; };
+#endif
 
   template
 using __ptr_traits_elem_t = typename __ptr_traits_elem<_Ptr>::type;
-#endif
 
   /// @endcond
 
@@ -182,13 +181,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 struct pointer_traits : __ptr_traits_impl<_Ptr, __ptr_traits_elem_t<_Ptr>>
 { };
 
-#if __cpp_concepts
-  template requires requires { typename _Ptr::element_type; }
-struct pointer_traits<_Ptr>
-: __ptr_traits_impl<_Ptr, typename _Ptr::element_type>
-{ };
-#endif
-
   /**
* @brief  Partial specialization for built-in pointers.
* @headerfile memory
diff --git a/libstdc++-v3/testsuite/20_util/pointer_traits/lwg3545.cc 
b/libstdc++-v3/testsuite/20_util/pointer_traits/lwg3545.cc
index 08c3ed01b75..93c64a353bd 100644
--- a/libstdc++-v3/testsuite/20_util/pointer_traits/lwg3545.cc
+++ b/libstdc++-v3/testsuite/20_util/pointer_traits/lwg3545.cc
@@ -99,3 +99,20 @@ static_assert( is_same, 
clever_ptr>::value, "" );
 static_assert( is_same, std::ptrdiff_t>::value, "" );
 static_assert( is_same, clever_ptr>::value, "" );
 static_assert( is_same, clever_ptr>::value, "" );
+
+#ifdef __cpp_concepts
+struct ptr_base { };
+
+// Program-defined specialization must not be ambiguous with primary template.
+template requires std::derived_from
+struct std::pointer_traits
+{
+  using element_type = int;
+  using difference_type = long;
+  using pointer = P;
+};
+
+struct Ptr : ptr_base { using element_type = int; };
+
+using E = std::pointer_traits::element_type;
+#endif


[gcc r12-10264] libstdc++: Disable Doxygen GROUP_NESTED_COMPOUNDS config option

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:d9f006da30def40747792d3ea37add1d80e02444

commit r12-10264-gd9f006da30def40747792d3ea37add1d80e02444
Author: Jonathan Wakely 
Date:   Wed May 11 16:46:03 2022 +0100

libstdc++: Disable Doxygen GROUP_NESTED_COMPOUNDS config option

Before Doxygen version 1.9.2 this option is broken (see
https://github.com/doxygen/doxygen/issues/8638 for more details) and
classes are not added to the correct groups by @ingroup and @addtogroup.

Also remove the obsolete CLASS_DIAGRAMS option that causes a warning.

libstdc++-v3/ChangeLog:

* doc/doxygen/user.cfg.in (GROUP_NESTED_COMPOUNDS): Set to NO.
(CLASS_DIAGRAMS): Remove obsolete option.

(cherry picked from commit 9c3a8fe34aeacabc2f62acef7f8f9108cb109238)

Diff:
---
 libstdc++-v3/doc/doxygen/user.cfg.in | 11 +--
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/libstdc++-v3/doc/doxygen/user.cfg.in 
b/libstdc++-v3/doc/doxygen/user.cfg.in
index bdff43c5f0a..b095addd10c 100644
--- a/libstdc++-v3/doc/doxygen/user.cfg.in
+++ b/libstdc++-v3/doc/doxygen/user.cfg.in
@@ -388,7 +388,7 @@ DISTRIBUTE_GROUP_DOC   = YES
 # is disabled and one has to add nested compounds explicitly via \ingroup.
 # The default value is: NO.
 
-GROUP_NESTED_COMPOUNDS = YES
+GROUP_NESTED_COMPOUNDS = NO
 
 # Set the SUBGROUPING tag to YES to allow class member groups of the same type
 # (for instance a group of public functions) to be put as a subgroup of that
@@ -2473,15 +2473,6 @@ EXTERNAL_PAGES = YES
 # Configuration options related to the dot tool
 #---
 
-# If the CLASS_DIAGRAMS tag is set to YES, doxygen will generate a class 
diagram
-# (in HTML and LaTeX) for classes with base or super classes. Setting the tag 
to
-# NO turns the diagrams off. Note that this option also works with HAVE_DOT
-# disabled, but it is recommended to install and use dot, since it yields more
-# powerful graphs.
-# The default value is: YES.
-
-CLASS_DIAGRAMS = YES
-
 # You can include diagrams made with dia in doxygen documentation. Doxygen will
 # then run dia to produce the diagram and insert it in the documentation. The
 # DIA_PATH tag allows you to specify the directory where the dia binary 
resides.


[gcc r12-10275] libstdc++: Fix -Wsystem-headers warnings in tests

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:7abc86119e4ebb13d3fffc7e2b038e2629aa2fc1

commit r12-10275-g7abc86119e4ebb13d3fffc7e2b038e2629aa2fc1
Author: Jonathan Wakely 
Date:   Mon Nov 7 15:00:34 2022 +

libstdc++: Fix -Wsystem-headers warnings in tests

libstdc++-v3/ChangeLog:

* testsuite/18_support/new_nothrow.cc: Add missing noexcept
to operator delete replacements.
* testsuite/20_util/any/cons/92156.cc: Disable
-Winit-list-lifetime warnings from instantiating invalid
specialization of manager function.
* testsuite/20_util/any/modifiers/92156.cc: Likewise.
* testsuite/20_util/default_delete/void_neg.cc: Prune additional
diagnostics.
* testsuite/20_util/headers/memory/synopsis.cc: Add missing
noexcept.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Prune
additional diagnostic.
* testsuite/20_util/unique_ptr/creation/for_overwrite.cc: Add
missing noexcept to operator delete replacements.
* testsuite/21_strings/basic_string/cons/char/103919.cc:
Likewise.
* testsuite/23_containers/map/modifiers/emplace/92300.cc:
Likewise.
* testsuite/23_containers/map/modifiers/insert/92300.cc:
Likewise.
* testsuite/24_iterators/headers/iterator/range_access_c++11.cc:
Add missing noexcept to synopsis declarations.
* testsuite/24_iterators/headers/iterator/range_access_c++14.cc:
Likewise.
* testsuite/24_iterators/headers/iterator/range_access_c++17.cc:
Likewise.

(cherry picked from commit bbcb84bba0a21ff367c95d3d0970926992b20cdd)

Diff:
---
 libstdc++-v3/testsuite/18_support/new_nothrow.cc   | 14 ++
 libstdc++-v3/testsuite/20_util/any/cons/92156.cc   |  1 +
 libstdc++-v3/testsuite/20_util/any/modifiers/92156.cc  |  1 +
 libstdc++-v3/testsuite/20_util/default_delete/void_neg.cc  |  3 +++
 libstdc++-v3/testsuite/20_util/headers/memory/synopsis.cc  |  2 +-
 libstdc++-v3/testsuite/20_util/shared_ptr/cons/void_neg.cc |  2 ++
 .../testsuite/20_util/unique_ptr/creation/for_overwrite.cc |  4 ++--
 .../testsuite/21_strings/basic_string/cons/char/103919.cc  |  4 ++--
 .../testsuite/23_containers/map/modifiers/emplace/92300.cc |  4 ++--
 .../testsuite/23_containers/map/modifiers/insert/92300.cc  |  4 ++--
 .../24_iterators/headers/iterator/range_access_c++11.cc|  4 ++--
 .../24_iterators/headers/iterator/range_access_c++14.cc| 12 ++--
 .../24_iterators/headers/iterator/range_access_c++17.cc| 12 ++--
 13 files changed, 40 insertions(+), 27 deletions(-)

diff --git a/libstdc++-v3/testsuite/18_support/new_nothrow.cc 
b/libstdc++-v3/testsuite/18_support/new_nothrow.cc
index b0ef4e966b8..a9e9da0ce81 100644
--- a/libstdc++-v3/testsuite/18_support/new_nothrow.cc
+++ b/libstdc++-v3/testsuite/18_support/new_nothrow.cc
@@ -63,7 +63,13 @@ void* operator new (size_t n)
 }
 }
 
-void operator delete (void *p)
+#if __cplusplus >= 201103L
+#define NOEXCEPT noexcept
+#else
+#define NOEXCEPT
+#endif
+
+void operator delete (void *p) NOEXCEPT
 {
 ++delete_called;
 if (p)
@@ -76,18 +82,18 @@ void* operator new[] (size_t n)
 return operator new(n);
 }
 
-void operator delete[] (void *p)
+void operator delete[] (void *p) NOEXCEPT
 {
 ++delete_vec_called;
 operator delete(p);
 }
 
 #if __cplusplus >= 201402L
-void operator delete (void *p, std::size_t)
+void operator delete (void *p, std::size_t) noexcept
 {
   ::operator delete(p);
 }
-void operator delete[] (void *p, std::size_t)
+void operator delete[] (void *p, std::size_t) noexcept
 {
   ::operator delete[](p);
 }
diff --git a/libstdc++-v3/testsuite/20_util/any/cons/92156.cc 
b/libstdc++-v3/testsuite/20_util/any/cons/92156.cc
index 71e9dd94090..0e768df9a00 100644
--- a/libstdc++-v3/testsuite/20_util/any/cons/92156.cc
+++ b/libstdc++-v3/testsuite/20_util/any/cons/92156.cc
@@ -1,4 +1,5 @@
 // { dg-do run { target c++17 } }
+// { dg-options "-Wno-init-list-lifetime" }
 
 // Copyright (C) 2020-2022 Free Software Foundation, Inc.
 //
diff --git a/libstdc++-v3/testsuite/20_util/any/modifiers/92156.cc 
b/libstdc++-v3/testsuite/20_util/any/modifiers/92156.cc
index d8f9893667b..b98d0e8e92a 100644
--- a/libstdc++-v3/testsuite/20_util/any/modifiers/92156.cc
+++ b/libstdc++-v3/testsuite/20_util/any/modifiers/92156.cc
@@ -1,4 +1,5 @@
 // { dg-do run { target c++17 } }
+// { dg-options "-Wno-init-list-lifetime" }
 
 // Copyright (C) 2020-2022 Free Software Foundation, Inc.
 //
diff --git a/libstdc++-v3/testsuite/20_util/default_delete/void_neg.cc 
b/libstdc++-v3/testsuite/20_util/default_delete/void_neg.cc
index f6aefc0a7ff..04042c2d745 100644
--- a/libstdc++-v3/testsuite/20_util/default_delete/void_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/default_delete/void_neg.cc
@@ -27,3 +27,6 @@ void test01()
   d(nullptr);  

[gcc r12-10278] libstdc++: Add @headerfile and @since to doxygen comments [PR40380]

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:afefe951acd8bae13be0e1b700262316254ce935

commit r12-10278-gafefe951acd8bae13be0e1b700262316254ce935
Author: Jonathan Wakely 
Date:   Wed Apr 26 22:48:35 2023 +0100

libstdc++: Add @headerfile and @since to doxygen comments [PR40380]

libstdc++-v3/ChangeLog:

PR libstdc++/40380
* include/bits/basic_string.h: Improve doxygen comments.
* include/bits/cow_string.h: Likewise.
* include/bits/forward_list.h: Likewise.
* include/bits/fs_dir.h: Likewise.
* include/bits/fs_path.h: Likewise.
* include/bits/quoted_string.h: Likewise.
* include/bits/stl_bvector.h: Likewise.
* include/bits/stl_map.h: Likewise.
* include/bits/stl_multimap.h: Likewise.
* include/bits/stl_multiset.h: Likewise.
* include/bits/stl_set.h: Likewise.
* include/bits/stl_vector.h: Likewise.
* include/bits/unordered_map.h: Likewise.
* include/bits/unordered_set.h: Likewise.
* include/std/filesystem: Likewise.
* include/std/iomanip: Likewise.

(cherry picked from commit 865869dc6943eb5dee855bc1ea88b09b7dabc641)

Diff:
---
 libstdc++-v3/include/bits/basic_string.h  |  2 ++
 libstdc++-v3/include/bits/cow_string.h|  2 ++
 libstdc++-v3/include/bits/forward_list.h  |  2 ++
 libstdc++-v3/include/bits/fs_dir.h| 35 +--
 libstdc++-v3/include/bits/fs_path.h   | 18 +++-
 libstdc++-v3/include/bits/quoted_string.h | 12 +++
 libstdc++-v3/include/bits/stl_bvector.h   |  2 ++
 libstdc++-v3/include/bits/stl_map.h   |  2 ++
 libstdc++-v3/include/bits/stl_multimap.h  |  2 ++
 libstdc++-v3/include/bits/stl_multiset.h  |  3 ++-
 libstdc++-v3/include/bits/stl_set.h   |  2 ++
 libstdc++-v3/include/bits/stl_vector.h|  2 ++
 libstdc++-v3/include/bits/unordered_map.h |  4 
 libstdc++-v3/include/bits/unordered_set.h |  4 
 libstdc++-v3/include/std/filesystem   |  2 ++
 libstdc++-v3/include/std/iomanip  |  1 +
 16 files changed, 87 insertions(+), 8 deletions(-)

diff --git a/libstdc++-v3/include/bits/basic_string.h 
b/libstdc++-v3/include/bits/basic_string.h
index 3f38f20dd18..e02b1b97c5c 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -69,6 +69,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
*
*  @ingroup strings
*  @ingroup sequences
+   *  @headerfile string
+   *  @since C++98
*
*  @tparam _CharT  Type of character
*  @tparam _Traits  Traits for character type, defaults to
diff --git a/libstdc++-v3/include/bits/cow_string.h 
b/libstdc++-v3/include/bits/cow_string.h
index 87720690cd3..6dd23883429 100644
--- a/libstdc++-v3/include/bits/cow_string.h
+++ b/libstdc++-v3/include/bits/cow_string.h
@@ -54,6 +54,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*
*  @ingroup strings
*  @ingroup sequences
+   *  @headerfile string
+   *  @since C++98
*
*  @tparam _CharT  Type of character
*  @tparam _Traits  Traits for character type, defaults to
diff --git a/libstdc++-v3/include/bits/forward_list.h 
b/libstdc++-v3/include/bits/forward_list.h
index bbb1740296b..69725a255e8 100644
--- a/libstdc++-v3/include/bits/forward_list.h
+++ b/libstdc++-v3/include/bits/forward_list.h
@@ -406,6 +406,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*  and fixed time insertion/deletion at any point in the sequence.
*
*  @ingroup sequences
+   *  @headerfile forward_list
+   *  @since C++11
*
*  @tparam _Tp  Type of element.
*  @tparam _Alloc  Allocator type, defaults to allocator<_Tp>.
diff --git a/libstdc++-v3/include/bits/fs_dir.h 
b/libstdc++-v3/include/bits/fs_dir.h
index 84e8e8984e8..968a5cf52a0 100644
--- a/libstdc++-v3/include/bits/fs_dir.h
+++ b/libstdc++-v3/include/bits/fs_dir.h
@@ -52,6 +52,10 @@ namespace filesystem
*/
 
   /// Information about a file's type and permissions.
+  /**
+   * @headerfile filesystem
+   * @since C++17
+   */
   class file_status
   {
   public:
@@ -94,6 +98,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   class recursive_directory_iterator;
 
   /// The value type used by directory iterators
+  /**
+   * @headerfile filesystem
+   * @since C++17
+   */
   class directory_entry
   {
   public:
@@ -354,7 +362,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
 file_type  _M_type = file_type::none;
   };
 
+  /// @cond undocumented
+
   /// Proxy returned by post-increment on directory iterators.
+  /**
+   * @headerfile filesystem
+   * @since C++17
+   */
   struct __directory_iterator_proxy
   {
 const directory_entry& operator*() const& noexcept { return _M_entry; }
@@ -370,8 +384,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
 
 directory_entry _M_entry;
   };
+  /// @endcond
 
   /// Iterator type for traversing the entries in a single directory.
+  /**
+   * @headerfile filesystem
+   * @since C++17
+   */
   class directory_ite

[gcc r12-10279] libstdc++: Implement P2538R1 ADL-proof std::projected

2024-03-18 Thread Jonathan Wakely via Gcc-cvs
https://gcc.gnu.org/g:2d604183c99ef0cea5d7540a7a466fb1d1453a58

commit r12-10279-g2d604183c99ef0cea5d7540a7a466fb1d1453a58
Author: Jonathan Wakely 
Date:   Fri Jun 23 12:18:11 2023 +0100

libstdc++: Implement P2538R1 ADL-proof std::projected

This was recently approved for C++26, but there's no harm in
implementing it unconditionally for C++20 and C++23. As it says in the
paper, it doesn't change the meaning of any valid code. It only enables
things that were previously ill-formed for questionable reasons.

libstdc++-v3/ChangeLog:

* include/bits/iterator_concepts.h (projected): Replace class
template with alias template denoting an ADL-proofed helper.
(incremental_traits>): Remove.
* testsuite/24_iterators/indirect_callable/projected-adl.cc:
New test.

(cherry picked from commit 6eafdfc73c21d7a5e59e18c9dee275af5bf6d979)

Diff:
---
 libstdc++-v3/include/bits/iterator_concepts.h  | 35 --
 .../indirect_callable/projected-adl.cc | 42 ++
 2 files changed, 67 insertions(+), 10 deletions(-)

diff --git a/libstdc++-v3/include/bits/iterator_concepts.h 
b/libstdc++-v3/include/bits/iterator_concepts.h
index cf66c63f395..6e032b08eb7 100644
--- a/libstdc++-v3/include/bits/iterator_concepts.h
+++ b/libstdc++-v3/include/bits/iterator_concepts.h
@@ -771,19 +771,34 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   && invocable<_Fn, iter_reference_t<_Is>...>
 using indirect_result_t = invoke_result_t<_Fn, iter_reference_t<_Is>...>;
 
+  namespace __detail
+  {
+template
+  struct __projected
+  {
+   struct __type
+   {
+ using value_type = remove_cvref_t>;
+ indirect_result_t<_Proj&, _Iter> operator*() const; // not defined
+   };
+  };
+
+template
+  struct __projected<_Iter, _Proj>
+  {
+   struct __type
+   {
+ using value_type = remove_cvref_t>;
+ using difference_type = iter_difference_t<_Iter>;
+ indirect_result_t<_Proj&, _Iter> operator*() const; // not defined
+   };
+  };
+  } // namespace __detail
+
   /// [projected], projected
   template _Proj>
-struct projected
-{
-  using value_type = remove_cvref_t>;
-
-  indirect_result_t<_Proj&, _Iter> operator*() const; // not defined
-};
-
-  template
-struct incrementable_traits>
-{ using difference_type = iter_difference_t<_Iter>; };
+using projected = typename __detail::__projected<_Iter, _Proj>::__type;
 
   // [alg.req], common algorithm requirements
 
diff --git 
a/libstdc++-v3/testsuite/24_iterators/indirect_callable/projected-adl.cc 
b/libstdc++-v3/testsuite/24_iterators/indirect_callable/projected-adl.cc
new file mode 100644
index 000..4c2a0955c6e
--- /dev/null
+++ b/libstdc++-v3/testsuite/24_iterators/indirect_callable/projected-adl.cc
@@ -0,0 +1,42 @@
+// { dg-options "-std=gnu++20" }
+// { dg-do compile { target c++20 } }
+
+// P2538R1 ADL-proof std::projected
+// https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2538r1.html
+
+#include 
+
+template
+  concept has_diff_type = requires { typename T::difference_type; };
+
+static_assert( has_diff_type> );
+
+struct Indy {
+  using value_type = int;
+  int operator*() const { return 0; }
+};
+static_assert( ! std::weakly_incrementable );
+static_assert( ! has_diff_type> );
+
+
+// Examples from the paper:
+
+template struct Holder { T t; };
+struct Incomplete;
+
+void test_concepts()
+{
+  using T = Holder*;
+  static_assert(std::equality_comparable);
+  (void) std::indirectly_comparable>;
+  (void) std::sortable;
+}
+
+#include 
+
+void test_count()
+{
+  Holder* a = nullptr;
+  (void) std::count(&a, &a, nullptr);
+  (void) std::ranges::count(&a, &a, nullptr); // { dg-bogus "." }
+}


  1   2   3   4   5   6   >