Skip to content

Commit 8e0720b

Browse files
committed
Fix msvc compiler error C4146 (unary minus operator applied to unsigned type)
On msvc14, int literal '-2147483648' is invalid, because '2147483648' is unsigned type and cant't apply minus operator to unsigned type. To define the int literal correctly, use '-2147483647 - 1' formula that is also used to define INT_MIN in limits.h.
1 parent 292112f commit 8e0720b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/test/util_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ BOOST_AUTO_TEST_CASE(test_ParseInt32)
321321
BOOST_CHECK(ParseInt32("1234", &n) && n == 1234);
322322
BOOST_CHECK(ParseInt32("01234", &n) && n == 1234); // no octal
323323
BOOST_CHECK(ParseInt32("2147483647", &n) && n == 2147483647);
324-
BOOST_CHECK(ParseInt32("-2147483648", &n) && n == -2147483648);
324+
BOOST_CHECK(ParseInt32("-2147483648", &n) && n == (-2147483647 - 1)); // (-2147483647 - 1) equals INT_MIN
325325
BOOST_CHECK(ParseInt32("-1234", &n) && n == -1234);
326326
// Invalid values
327327
BOOST_CHECK(!ParseInt32("", &n));

0 commit comments

Comments
 (0)