[PATCH] D16480: [libcxx] NFC: suppress warning on systems where sizeof(int) == sizeof(long)

Ben Craig via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 22 12:09:25 PST 2016


bcraig created this revision.
bcraig added a reviewer: mclow.lists.
bcraig added a subscriber: cfe-commits.

The old code produced a couple of these warnings...

src/string.cpp:95:11: warning: comparison of constant -2147483648 with expression of type 'long' (range [-2147483648, 2147483647]) is always false [-Wtautological-constant-out-of-range-compare]
    if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)
        ~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
src/string.cpp:95:11: note: place two sets of parentheses around the constant to silence this warning
    if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)


This patch follows the advice of the note, as the comparison is reasonable on many 64-bit systems.

http://reviews.llvm.org/D16480

Files:
  src/string.cpp

Index: src/string.cpp
===================================================================
--- src/string.cpp
+++ src/string.cpp
@@ -91,7 +91,7 @@
 {
     // Use long as no Standard string to integer exists.
     long r = as_integer_helper<long>( func, s, idx, base, strtol );
-    if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)
+    if (r < ((numeric_limits<int>::min())) || ((numeric_limits<int>::max())) < r)
         throw_from_string_out_of_range(func);
     return static_cast<int>(r);
 }
@@ -136,7 +136,7 @@
 {
     // Use long as no Stantard string to integer exists.
     long r = as_integer_helper<long>( func, s, idx, base, wcstol );
-    if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)
+    if (r < ((numeric_limits<int>::min())) || ((numeric_limits<int>::max())) < r)
         throw_from_string_out_of_range(func);
     return static_cast<int>(r);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16480.45722.patch
Type: text/x-patch
Size: 908 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160122/bb5c7731/attachment.bin>


More information about the cfe-commits mailing list