https://gcc.gnu.org/g:f793be787135ce7c52b169bf053af225b4828945

commit r15-2358-gf793be787135ce7c52b169bf053af225b4828945
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Fri Jul 26 17:23:03 2024 +0100

    libstdc++: Fix -Wsign-compare warning in <charconv>
    
    Cast ptrdiff_t to size_t to avoid a -Wsign-compare warning. We can check
    in __to_chars_i that the ptrdiff_t won't be negative, so that we know
    the cast is safe.
    
    libstdc++-v3/ChangeLog:
    
            * include/std/charconv (__to_chars_16, __to_chars_10)
            (__to_chars_8, __to_chars_2, __to_chars): Cast ptrdiff_t to
            size_t for comparison.
            (__to_chars_i): Check for first >= last instead of first == last
            for initial sanity check.

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

diff --git a/libstdc++-v3/include/std/charconv 
b/libstdc++-v3/include/std/charconv
index e516e3b2da86..00c4f206922a 100644
--- a/libstdc++-v3/include/std/charconv
+++ b/libstdc++-v3/include/std/charconv
@@ -126,7 +126,7 @@ namespace __detail
 
       const unsigned __len = __to_chars_len(__val, __base);
 
-      if (__builtin_expect((__last - __first) < __len, 0))
+      if (__builtin_expect(size_t(__last - __first) < __len, 0))
        {
          __res.ptr = __last;
          __res.ec = errc::value_too_large;
@@ -166,7 +166,7 @@ namespace __detail
 
       const unsigned __len = (__to_chars_len_2(__val) + 3) / 4;
 
-      if (__builtin_expect((__last - __first) < __len, 0))
+      if (__builtin_expect(size_t(__last - __first) < __len, 0))
        {
          __res.ptr = __last;
          __res.ec = errc::value_too_large;
@@ -212,7 +212,7 @@ namespace __detail
 
       const unsigned __len = __to_chars_len(__val, 10);
 
-      if (__builtin_expect((__last - __first) < __len, 0))
+      if (__builtin_expect(size_t(__last - __first) < __len, 0))
        {
          __res.ptr = __last;
          __res.ec = errc::value_too_large;
@@ -246,7 +246,7 @@ namespace __detail
       else
        __len = (__to_chars_len_2(__val) + 2) / 3;
 
-      if (__builtin_expect((__last - __first) < __len, 0))
+      if (__builtin_expect(size_t(__last - __first) < __len, 0))
        {
          __res.ptr = __last;
          __res.ec = errc::value_too_large;
@@ -288,7 +288,7 @@ namespace __detail
 
       const unsigned __len = __to_chars_len_2(__val);
 
-      if (__builtin_expect((__last - __first) < __len, 0))
+      if (__builtin_expect(size_t(__last - __first) < __len, 0))
        {
          __res.ptr = __last;
          __res.ec = errc::value_too_large;
@@ -323,7 +323,7 @@ namespace __detail
       using _Up = __detail::__unsigned_least_t<_Tp>;
       _Up __unsigned_val = __value;
 
-      if (__first == __last) [[__unlikely__]]
+      if (__first >= __last) [[__unlikely__]]
        return { __last, errc::value_too_large };
 
       if (__value == 0)

Reply via email to