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);
 }


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);
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to