[PATCH] D21708: [libcxx] fix compiler warning of autological-constant-out-of-range-compare
Weiming Zhao via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 24 17:22:55 PDT 2016
weimingz created this revision.
weimingz added a subscriber: cfe-commits.
warning: comparison of constant -2147483648 with expression of type 'long' (range [-2147483648, 2147483647]) is always false [-Wtautological-constant-out-of-range-compare]
As int and long maybe the same size on most architectures, the test doesn't really tell if the value is out of range or not.
The fix changes to "long long". But may still not the best way as there is no guarantee that it would be bigger than int.
http://reviews.llvm.org/D21708
Files:
src/string.cpp
Index: src/string.cpp
===================================================================
--- src/string.cpp
+++ src/string.cpp
@@ -90,7 +90,7 @@
as_integer(const string& func, const string& s, size_t* idx, int base )
{
// Use long as no Standard string to integer exists.
- long r = as_integer_helper<long>( func, s, idx, base, strtol );
+ long long r = as_integer_helper<long long>( func, s, idx, base, strtol );
if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)
throw_from_string_out_of_range(func);
return static_cast<int>(r);
@@ -135,7 +135,7 @@
as_integer( const string& func, const wstring& s, size_t* idx, int base )
{
// Use long as no Stantard string to integer exists.
- long r = as_integer_helper<long>( func, s, idx, base, wcstol );
+ long long r = as_integer_helper<long long>( func, s, idx, base, wcstol );
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: D21708.61859.patch
Type: text/x-patch
Size: 1042 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160625/1995ab95/attachment.bin>
More information about the cfe-commits
mailing list