]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix -Wformat warning in std::string
authorJonathan Wakely <jwakely@redhat.com>
Wed, 1 Oct 2025 12:31:59 +0000 (13:31 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 7 Oct 2025 11:11:21 +0000 (12:11 +0100)
The __throw_out_of_range_fmt function works like fprintf and so the
arguments corresponding to %zu specifiers need to be size_t. The
std::basic_string<C,T,A>::size_type type is A::size_type which is not
necessarily size_t. Add explicit casts to avoid a -Wformat warning with
-Wsystem-headers.

libstdc++-v3/ChangeLog:

* include/bits/basic_string.h (basic_string::_M_check): Cast
size_type arguments to size_t.

libstdc++-v3/include/bits/basic_string.h

index 708104984d2dc6d276bc80ae97830f746deeb6f0..8ae6569f50160137ed7d60b541b91539a45c18be 100644 (file)
@@ -411,7 +411,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
        if (__pos > this->size())
          __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > "
                                       "this->size() (which is %zu)"),
-                                  __s, __pos, this->size());
+                                  __s, (size_t)__pos, (size_t)this->size());
        return __pos;
       }