contrib/libc++/include/locale contains -Wsign-compare errors

From: Alan Somers <asomers_at_freebsd.org>
Date: Fri, 7 Feb 2014 11:04:40 -0700
contrib/libc++/include/locale compares integers of different signs.
With our CXXFLAG settings, this causes "WITH_TESTS=1 make buildworld"
to fail while compiling libatf-c++, as I mentioned in another thread.
I've now written a minimal test case.  Just #include locale and
compile it with the right settings.

$ cat use_locale.cpp
#include <locale>
$ c++   -Wsystem-headers -Werror -Wsign-compare -Wno-unused-parameter
-Wno-c++11-extensions  -c -o use_locale.o use_locale.cpp
In file included from use_locale.cpp:1:
/usr/include/c++/v1/locale:1016:27: error: comparison of integers of different
      signs: 'long' and 'size_type' (aka 'unsigned long')
      [-Werror,-Wsign-compare]
        if (__a_end - __a == __buf.size())
            ~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~
/usr/include/c++/v1/locale:1066:27: error: comparison of integers of different
      signs: 'long' and 'size_type' (aka 'unsigned long')
      [-Werror,-Wsign-compare]
        if (__a_end - __a == __buf.size())
            ~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~
/usr/include/c++/v1/locale:1120:27: error: comparison of integers of different
      signs: 'long' and 'size_type' (aka 'unsigned long')
      [-Werror,-Wsign-compare]
        if (__a_end - __a == __buf.size())
            ~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~
3 errors generated.


The below patch fixes the problem, but I don't have the confidence to
change the system C++ library myself.  Can somebody please review it?


Index: contrib/libc++/include/locale
===================================================================
--- contrib/libc++/include/locale       (revision 261283)
+++ contrib/libc++/include/locale       (working copy)
_at__at_ -1012,7 +1012,7 _at__at_
     unsigned __dc = 0;
     for (; __b != __e; ++__b)
     {
-        if (__a_end - __a == __buf.size())
+        if ((size_t)(__a_end - __a) == __buf.size())
         {
             size_t __tmp = __buf.size();
             __buf.resize(2*__buf.size());
_at__at_ -1062,7 +1062,7 _at__at_
     unsigned __dc = 0;
     for (; __b != __e; ++__b)
     {
-        if (__a_end - __a == __buf.size())
+        if ((size_t)(__a_end - __a) == __buf.size())
         {
             size_t __tmp = __buf.size();
             __buf.resize(2*__buf.size());
_at__at_ -1116,7 +1116,7 _at__at_
     char __exp = 'E';
     for (; __b != __e; ++__b)
     {
-        if (__a_end - __a == __buf.size())
+        if ((size_t)(__a_end - __a) == __buf.size())
         {
             size_t __tmp = __buf.size();
             __buf.resize(2*__buf.size());
Received on Fri Feb 07 2014 - 17:04:43 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:46 UTC