Date: Fri, 7 Feb 2014 11:04:40 -0700 From: Alan Somers <asomers@freebsd.org> To: FreeBSD CURRENT <freebsd-current@freebsd.org>, "freebsd-testing@freebsd.org" <freebsd-testing@freebsd.org>, theraven@freebsd.org, Brooks Davis <brooks@freebsd.org>, Dimitry Andric <dim@freebsd.org> Subject: contrib/libc++/include/locale contains -Wsign-compare errors Message-ID: <CAOtMX2juj%2B=-bo0kznhLi01QxjVkdvJoT890q%2BBYhoKSpwpXng@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
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) @@ -1012,7 +1012,7 @@ 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()); @@ -1062,7 +1062,7 @@ 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()); @@ -1116,7 +1116,7 @@ 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());
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAOtMX2juj%2B=-bo0kznhLi01QxjVkdvJoT890q%2BBYhoKSpwpXng>