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