diff --git a/libc/test/src/stdlib/strtol_test.cpp b/libc/test/src/stdlib/strtol_test.cpp --- a/libc/test/src/stdlib/strtol_test.cpp +++ b/libc/test/src/stdlib/strtol_test.cpp @@ -12,6 +12,7 @@ #include #include +#include TEST(LlvmLibcStrToLTest, InvalidBase) { const char *ten = "10"; @@ -27,7 +28,8 @@ errno = 0; ASSERT_EQ(__llvm_libc::strtol(ten, &str_end, 10), 10l); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - ten, 2l); + EXPECT_EQ(str_end - ten, ptrdiff_t(2)); + errno = 0; ASSERT_EQ(__llvm_libc::strtol(ten, nullptr, 10), 10l); ASSERT_EQ(errno, 0); @@ -36,39 +38,39 @@ errno = 0; ASSERT_EQ(__llvm_libc::strtol(hundred, &str_end, 10), 100l); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - hundred, 3l); + EXPECT_EQ(str_end - hundred, ptrdiff_t(3)); const char *negative = "-100"; errno = 0; ASSERT_EQ(__llvm_libc::strtol(negative, &str_end, 10), -100l); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - negative, 4l); + EXPECT_EQ(str_end - negative, ptrdiff_t(4)); const char *big_number = "123456789012345"; errno = 0; ASSERT_EQ(__llvm_libc::strtol(big_number, &str_end, 10), 123456789012345l); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - big_number, 15l); + EXPECT_EQ(str_end - big_number, ptrdiff_t(15)); const char *big_negative_number = "-123456789012345"; errno = 0; ASSERT_EQ(__llvm_libc::strtol(big_negative_number, &str_end, 10), -123456789012345l); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - big_negative_number, 16l); + EXPECT_EQ(str_end - big_negative_number, ptrdiff_t(16)); const char *too_big_number = "123456789012345678901"; errno = 0; ASSERT_EQ(__llvm_libc::strtol(too_big_number, &str_end, 10), LONG_MAX); ASSERT_EQ(errno, ERANGE); - EXPECT_EQ(str_end - too_big_number, 21l); + EXPECT_EQ(str_end - too_big_number, ptrdiff_t(21)); const char *too_big_negative_number = "-123456789012345678901"; errno = 0; ASSERT_EQ(__llvm_libc::strtol(too_big_negative_number, &str_end, 10), LONG_MIN); ASSERT_EQ(errno, ERANGE); - EXPECT_EQ(str_end - too_big_negative_number, 22l); + EXPECT_EQ(str_end - too_big_negative_number, ptrdiff_t(22)); const char *long_number_range_test = "10000000000000000000000000000000000000000000000000"; @@ -76,7 +78,7 @@ ASSERT_EQ(__llvm_libc::strtol(long_number_range_test, &str_end, 10), LONG_MAX); ASSERT_EQ(errno, ERANGE); - EXPECT_EQ(str_end - long_number_range_test, 50l); + EXPECT_EQ(str_end - long_number_range_test, ptrdiff_t(50)); } TEST(LlvmLibcStrToLTest, MessyBaseTenDecode) { @@ -86,61 +88,61 @@ errno = 0; ASSERT_EQ(__llvm_libc::strtol(spaces_before, &str_end, 10), 10l); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - spaces_before, 7l); + EXPECT_EQ(str_end - spaces_before, ptrdiff_t(7)); const char *spaces_after = "10 "; errno = 0; ASSERT_EQ(__llvm_libc::strtol(spaces_after, &str_end, 10), 10l); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - spaces_after, 2l); + EXPECT_EQ(str_end - spaces_after, ptrdiff_t(2)); const char *word_before = "word10"; errno = 0; ASSERT_EQ(__llvm_libc::strtol(word_before, &str_end, 10), 0l); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - word_before, 0l); + EXPECT_EQ(str_end - word_before, ptrdiff_t(0)); const char *word_after = "10word"; errno = 0; ASSERT_EQ(__llvm_libc::strtol(word_after, &str_end, 10), 10l); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - word_after, 2l); + EXPECT_EQ(str_end - word_after, ptrdiff_t(2)); const char *two_numbers = "10 999"; errno = 0; ASSERT_EQ(__llvm_libc::strtol(two_numbers, &str_end, 10), 10l); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - two_numbers, 2l); + EXPECT_EQ(str_end - two_numbers, ptrdiff_t(2)); const char *two_signs = "--10 999"; errno = 0; ASSERT_EQ(__llvm_libc::strtol(two_signs, &str_end, 10), 0l); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - two_signs, 1l); + EXPECT_EQ(str_end - two_signs, ptrdiff_t(1)); const char *sign_before = "+2=4"; errno = 0; ASSERT_EQ(__llvm_libc::strtol(sign_before, &str_end, 10), 2l); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - sign_before, 2l); + EXPECT_EQ(str_end - sign_before, ptrdiff_t(2)); const char *sign_after = "2+2=4"; errno = 0; ASSERT_EQ(__llvm_libc::strtol(sign_after, &str_end, 10), 2l); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - sign_after, 1l); + EXPECT_EQ(str_end - sign_after, ptrdiff_t(1)); const char *tab_before = "\t10"; errno = 0; ASSERT_EQ(__llvm_libc::strtol(tab_before, &str_end, 10), 10l); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - tab_before, 3l); + EXPECT_EQ(str_end - tab_before, ptrdiff_t(3)); const char *all_together = "\t -12345and+67890"; errno = 0; ASSERT_EQ(__llvm_libc::strtol(all_together, &str_end, 10), -12345l); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - all_together, 9l); + EXPECT_EQ(str_end - all_together, ptrdiff_t(9)); } static char int_to_b36_char(int input) { @@ -250,13 +252,13 @@ errno = 0; ASSERT_EQ(__llvm_libc::strtol(no_prefix, &str_end, 16), 0x123abcl); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - no_prefix, 6l); + EXPECT_EQ(str_end - no_prefix, ptrdiff_t(6)); const char *yes_prefix = "0x456def"; errno = 0; ASSERT_EQ(__llvm_libc::strtol(yes_prefix, &str_end, 16), 0x456defl); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - yes_prefix, 8l); + EXPECT_EQ(str_end - yes_prefix, ptrdiff_t(8)); } TEST(LlvmLibcStrToLTest, AutomaticBaseSelection) { @@ -266,24 +268,24 @@ errno = 0; ASSERT_EQ(__llvm_libc::strtol(base_ten, &str_end, 0), 12345l); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - base_ten, 5l); + EXPECT_EQ(str_end - base_ten, ptrdiff_t(5)); const char *base_sixteen_no_prefix = "123abc"; errno = 0; ASSERT_EQ(__llvm_libc::strtol(base_sixteen_no_prefix, &str_end, 0), 123l); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - base_sixteen_no_prefix, 3l); + EXPECT_EQ(str_end - base_sixteen_no_prefix, ptrdiff_t(3)); const char *base_sixteen_with_prefix = "0x456def"; errno = 0; ASSERT_EQ(__llvm_libc::strtol(base_sixteen_with_prefix, &str_end, 0), 0x456defl); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - base_sixteen_with_prefix, 8l); + EXPECT_EQ(str_end - base_sixteen_with_prefix, ptrdiff_t(8)); const char *base_eight_with_prefix = "012345"; errno = 0; ASSERT_EQ(__llvm_libc::strtol(base_eight_with_prefix, &str_end, 0), 012345l); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - base_eight_with_prefix, 6l); + EXPECT_EQ(str_end - base_eight_with_prefix, ptrdiff_t(6)); } diff --git a/libc/test/src/stdlib/strtoll_test.cpp b/libc/test/src/stdlib/strtoll_test.cpp --- a/libc/test/src/stdlib/strtoll_test.cpp +++ b/libc/test/src/stdlib/strtoll_test.cpp @@ -12,6 +12,7 @@ #include #include +#include TEST(LlvmLibcStrToLLTest, InvalidBase) { const char *ten = "10"; @@ -27,7 +28,7 @@ errno = 0; ASSERT_EQ(__llvm_libc::strtoll(ten, &str_end, 10), 10ll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - ten, 2l); + EXPECT_EQ(str_end - ten, ptrdiff_t(2)); errno = 0; ASSERT_EQ(__llvm_libc::strtoll(ten, nullptr, 10), 10ll); ASSERT_EQ(errno, 0); @@ -36,53 +37,53 @@ errno = 0; ASSERT_EQ(__llvm_libc::strtoll(hundred, &str_end, 10), 100ll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - hundred, 3l); + EXPECT_EQ(str_end - hundred, ptrdiff_t(3)); const char *negative = "-100"; errno = 0; ASSERT_EQ(__llvm_libc::strtoll(negative, &str_end, 10), -100ll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - negative, 4l); + EXPECT_EQ(str_end - negative, ptrdiff_t(4)); const char *big_number = "123456789012345"; errno = 0; ASSERT_EQ(__llvm_libc::strtoll(big_number, &str_end, 10), 123456789012345ll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - big_number, 15l); + EXPECT_EQ(str_end - big_number, ptrdiff_t(15)); const char *big_negative_number = "-123456789012345"; errno = 0; ASSERT_EQ(__llvm_libc::strtoll(big_negative_number, &str_end, 10), -123456789012345ll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - big_negative_number, 16l); + EXPECT_EQ(str_end - big_negative_number, ptrdiff_t(16)); const char *long_long_max_number = "9223372036854775807"; errno = 0; ASSERT_EQ(__llvm_libc::strtoll(long_long_max_number, &str_end, 10), 9223372036854775807ll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - long_long_max_number, 19l); + EXPECT_EQ(str_end - long_long_max_number, ptrdiff_t(19)); const char *long_long_min_number = "-9223372036854775808"; errno = 0; ASSERT_EQ(__llvm_libc::strtoll(long_long_min_number, &str_end, 10), -9223372036854775807ll - 1ll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - long_long_min_number, 20l); + EXPECT_EQ(str_end - long_long_min_number, ptrdiff_t(20)); const char *too_big_number = "123456789012345678901"; errno = 0; ASSERT_EQ(__llvm_libc::strtoll(too_big_number, &str_end, 10), LLONG_MAX); ASSERT_EQ(errno, ERANGE); - EXPECT_EQ(str_end - too_big_number, 21l); + EXPECT_EQ(str_end - too_big_number, ptrdiff_t(21)); const char *too_big_negative_number = "-123456789012345678901"; errno = 0; ASSERT_EQ(__llvm_libc::strtoll(too_big_negative_number, &str_end, 10), LLONG_MIN); ASSERT_EQ(errno, ERANGE); - EXPECT_EQ(str_end - too_big_negative_number, 22l); + EXPECT_EQ(str_end - too_big_negative_number, ptrdiff_t(22)); const char *long_number_range_test = "10000000000000000000000000000000000000000000000000"; @@ -90,7 +91,7 @@ ASSERT_EQ(__llvm_libc::strtoll(long_number_range_test, &str_end, 10), LLONG_MAX); ASSERT_EQ(errno, ERANGE); - EXPECT_EQ(str_end - long_number_range_test, 50l); + EXPECT_EQ(str_end - long_number_range_test, ptrdiff_t(50)); const char *long_long_max_number_with_numbers_after = "9223372036854775807123"; @@ -99,7 +100,9 @@ &str_end, 10), LLONG_MAX); ASSERT_EQ(errno, ERANGE); - EXPECT_EQ(str_end - long_long_max_number_with_numbers_after, 22l); + EXPECT_EQ( + static_cast(str_end - long_long_max_number_with_numbers_after), + 22ll); } TEST(LlvmLibcStrToLLTest, MessyBaseTenDecode) { @@ -109,61 +112,61 @@ errno = 0; ASSERT_EQ(__llvm_libc::strtoll(spaces_before, &str_end, 10), 10ll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - spaces_before, 7l); + EXPECT_EQ(str_end - spaces_before, ptrdiff_t(7)); const char *spaces_after = "10 "; errno = 0; ASSERT_EQ(__llvm_libc::strtoll(spaces_after, &str_end, 10), 10ll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - spaces_after, 2l); + EXPECT_EQ(str_end - spaces_after, ptrdiff_t(2)); const char *word_before = "word10"; errno = 0; ASSERT_EQ(__llvm_libc::strtoll(word_before, &str_end, 10), 0ll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - word_before, 0l); + EXPECT_EQ(str_end - word_before, ptrdiff_t(0)); const char *word_after = "10word"; errno = 0; ASSERT_EQ(__llvm_libc::strtoll(word_after, &str_end, 10), 10ll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - word_after, 2l); + EXPECT_EQ(str_end - word_after, ptrdiff_t(2)); const char *two_numbers = "10 999"; errno = 0; ASSERT_EQ(__llvm_libc::strtoll(two_numbers, &str_end, 10), 10ll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - two_numbers, 2l); + EXPECT_EQ(str_end - two_numbers, ptrdiff_t(2)); const char *two_signs = "--10 999"; errno = 0; ASSERT_EQ(__llvm_libc::strtoll(two_signs, &str_end, 10), 0ll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - two_signs, 1l); + EXPECT_EQ(str_end - two_signs, ptrdiff_t(1)); const char *sign_before = "+2=4"; errno = 0; ASSERT_EQ(__llvm_libc::strtoll(sign_before, &str_end, 10), 2ll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - sign_before, 2l); + EXPECT_EQ(str_end - sign_before, ptrdiff_t(2)); const char *sign_after = "2+2=4"; errno = 0; ASSERT_EQ(__llvm_libc::strtoll(sign_after, &str_end, 10), 2ll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - sign_after, 1l); + EXPECT_EQ(str_end - sign_after, ptrdiff_t(1)); const char *tab_before = "\t10"; errno = 0; ASSERT_EQ(__llvm_libc::strtoll(tab_before, &str_end, 10), 10ll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - tab_before, 3l); + EXPECT_EQ(str_end - tab_before, ptrdiff_t(3)); const char *all_together = "\t -12345and+67890"; errno = 0; ASSERT_EQ(__llvm_libc::strtoll(all_together, &str_end, 10), -12345ll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - all_together, 9l); + EXPECT_EQ(str_end - all_together, ptrdiff_t(9)); } static char int_to_b36_char(int input) { @@ -274,13 +277,13 @@ errno = 0; ASSERT_EQ(__llvm_libc::strtoll(no_prefix, &str_end, 16), 0x123abcll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - no_prefix, 6l); + EXPECT_EQ(str_end - no_prefix, ptrdiff_t(6)); const char *yes_prefix = "0x456def"; errno = 0; ASSERT_EQ(__llvm_libc::strtoll(yes_prefix, &str_end, 16), 0x456defll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - yes_prefix, 8l); + EXPECT_EQ(str_end - yes_prefix, ptrdiff_t(8)); } TEST(LlvmLibcStrToLLTest, AutomaticBaseSelection) { @@ -290,25 +293,25 @@ errno = 0; ASSERT_EQ(__llvm_libc::strtoll(base_ten, &str_end, 0), 12345ll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - base_ten, 5l); + EXPECT_EQ(str_end - base_ten, ptrdiff_t(5)); const char *base_sixteen_no_prefix = "123abc"; errno = 0; ASSERT_EQ(__llvm_libc::strtoll(base_sixteen_no_prefix, &str_end, 0), 123ll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - base_sixteen_no_prefix, 3l); + EXPECT_EQ(str_end - base_sixteen_no_prefix, ptrdiff_t(3)); const char *base_sixteen_with_prefix = "0x456def"; errno = 0; ASSERT_EQ(__llvm_libc::strtoll(base_sixteen_with_prefix, &str_end, 0), 0x456defll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - base_sixteen_with_prefix, 8l); + EXPECT_EQ(str_end - base_sixteen_with_prefix, ptrdiff_t(8)); const char *base_eight_with_prefix = "012345"; errno = 0; ASSERT_EQ(__llvm_libc::strtoll(base_eight_with_prefix, &str_end, 0), 012345ll); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - base_eight_with_prefix, 6l); + EXPECT_EQ(str_end - base_eight_with_prefix, ptrdiff_t(6)); } diff --git a/libc/test/src/stdlib/strtoul_test.cpp b/libc/test/src/stdlib/strtoul_test.cpp --- a/libc/test/src/stdlib/strtoul_test.cpp +++ b/libc/test/src/stdlib/strtoul_test.cpp @@ -12,6 +12,7 @@ #include #include +#include TEST(LlvmLibcStrToULTest, InvalidBase) { const char *ten = "10"; @@ -27,7 +28,7 @@ errno = 0; ASSERT_EQ(__llvm_libc::strtoul(ten, &str_end, 10), 10ul); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - ten, 2l); + EXPECT_EQ(str_end - ten, ptrdiff_t(2)); errno = 0; ASSERT_EQ(__llvm_libc::strtoul(ten, nullptr, 10), 10ul); ASSERT_EQ(errno, 0); @@ -36,32 +37,32 @@ errno = 0; ASSERT_EQ(__llvm_libc::strtoul(hundred, &str_end, 10), 100ul); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - hundred, 3l); + EXPECT_EQ(str_end - hundred, ptrdiff_t(3)); const char *negative = "-100"; errno = 0; ASSERT_EQ(__llvm_libc::strtoul(negative, &str_end, 10), -(100ul)); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - negative, 4l); + EXPECT_EQ(str_end - negative, ptrdiff_t(4)); const char *big_number = "123456789012345"; errno = 0; ASSERT_EQ(__llvm_libc::strtoul(big_number, &str_end, 10), 123456789012345ul); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - big_number, 15l); + EXPECT_EQ(str_end - big_number, ptrdiff_t(15)); const char *too_big_number = "123456789012345678901"; errno = 0; ASSERT_EQ(__llvm_libc::strtoul(too_big_number, &str_end, 10), ULONG_MAX); ASSERT_EQ(errno, ERANGE); - EXPECT_EQ(str_end - too_big_number, 21l); + EXPECT_EQ(str_end - too_big_number, ptrdiff_t(21)); const char *too_big_negative_number = "-123456789012345678901"; errno = 0; ASSERT_EQ(__llvm_libc::strtoul(too_big_negative_number, &str_end, 10), ULONG_MAX); ASSERT_EQ(errno, ERANGE); - EXPECT_EQ(str_end - too_big_negative_number, 22l); + EXPECT_EQ(str_end - too_big_negative_number, ptrdiff_t(22)); const char *long_number_range_test = "10000000000000000000000000000000000000000000000000"; @@ -69,7 +70,7 @@ ASSERT_EQ(__llvm_libc::strtoul(long_number_range_test, &str_end, 10), ULONG_MAX); ASSERT_EQ(errno, ERANGE); - EXPECT_EQ(str_end - long_number_range_test, 50l); + EXPECT_EQ(str_end - long_number_range_test, ptrdiff_t(50)); } TEST(LlvmLibcStrToULTest, MessyBaseTenDecode) { @@ -79,61 +80,61 @@ errno = 0; ASSERT_EQ(__llvm_libc::strtoul(spaces_before, &str_end, 10), 10ul); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - spaces_before, 7l); + EXPECT_EQ(str_end - spaces_before, ptrdiff_t(7)); const char *spaces_after = "10 "; errno = 0; ASSERT_EQ(__llvm_libc::strtoul(spaces_after, &str_end, 10), 10ul); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - spaces_after, 2l); + EXPECT_EQ(str_end - spaces_after, ptrdiff_t(2)); const char *word_before = "word10"; errno = 0; ASSERT_EQ(__llvm_libc::strtoul(word_before, &str_end, 10), 0ul); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - word_before, 0l); + EXPECT_EQ(str_end - word_before, ptrdiff_t(0)); const char *word_after = "10word"; errno = 0; ASSERT_EQ(__llvm_libc::strtoul(word_after, &str_end, 10), 10ul); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - word_after, 2l); + EXPECT_EQ(str_end - word_after, ptrdiff_t(2)); const char *two_numbers = "10 999"; errno = 0; ASSERT_EQ(__llvm_libc::strtoul(two_numbers, &str_end, 10), 10ul); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - two_numbers, 2l); + EXPECT_EQ(str_end - two_numbers, ptrdiff_t(2)); const char *two_signs = "--10 999"; errno = 0; ASSERT_EQ(__llvm_libc::strtoul(two_signs, &str_end, 10), 0ul); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - two_signs, 1l); + EXPECT_EQ(str_end - two_signs, ptrdiff_t(1)); const char *sign_before = "+2=4"; errno = 0; ASSERT_EQ(__llvm_libc::strtoul(sign_before, &str_end, 10), 2ul); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - sign_before, 2l); + EXPECT_EQ(str_end - sign_before, ptrdiff_t(2)); const char *sign_after = "2+2=4"; errno = 0; ASSERT_EQ(__llvm_libc::strtoul(sign_after, &str_end, 10), 2ul); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - sign_after, 1l); + EXPECT_EQ(str_end - sign_after, ptrdiff_t(1)); const char *tab_before = "\t10"; errno = 0; ASSERT_EQ(__llvm_libc::strtoul(tab_before, &str_end, 10), 10ul); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - tab_before, 3l); + EXPECT_EQ(str_end - tab_before, ptrdiff_t(3)); const char *all_together = "\t -12345and+67890"; errno = 0; ASSERT_EQ(__llvm_libc::strtoul(all_together, &str_end, 10), -(12345ul)); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - all_together, 9l); + EXPECT_EQ(str_end - all_together, ptrdiff_t(9)); } static char int_to_b36_char(int input) { @@ -244,13 +245,13 @@ errno = 0; ASSERT_EQ(__llvm_libc::strtoul(no_prefix, &str_end, 16), 0x123abcul); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - no_prefix, 6l); + EXPECT_EQ(str_end - no_prefix, ptrdiff_t(6)); const char *yes_prefix = "0x456def"; errno = 0; ASSERT_EQ(__llvm_libc::strtoul(yes_prefix, &str_end, 16), 0x456deful); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - yes_prefix, 8l); + EXPECT_EQ(str_end - yes_prefix, ptrdiff_t(8)); } TEST(LlvmLibcStrToULTest, AutomaticBaseSelection) { @@ -260,25 +261,25 @@ errno = 0; ASSERT_EQ(__llvm_libc::strtoul(base_ten, &str_end, 0), 12345ul); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - base_ten, 5l); + EXPECT_EQ(str_end - base_ten, ptrdiff_t(5)); const char *base_sixteen_no_prefix = "123abc"; errno = 0; ASSERT_EQ(__llvm_libc::strtoul(base_sixteen_no_prefix, &str_end, 0), 123ul); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - base_sixteen_no_prefix, 3l); + EXPECT_EQ(str_end - base_sixteen_no_prefix, ptrdiff_t(3)); const char *base_sixteen_with_prefix = "0x456def"; errno = 0; ASSERT_EQ(__llvm_libc::strtoul(base_sixteen_with_prefix, &str_end, 0), 0x456deful); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - base_sixteen_with_prefix, 8l); + EXPECT_EQ(str_end - base_sixteen_with_prefix, ptrdiff_t(8)); const char *base_eight_with_prefix = "012345"; errno = 0; ASSERT_EQ(__llvm_libc::strtoul(base_eight_with_prefix, &str_end, 0), 012345ul); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - base_eight_with_prefix, 6l); + EXPECT_EQ(str_end - base_eight_with_prefix, ptrdiff_t(6)); } diff --git a/libc/test/src/stdlib/strtoull_test.cpp b/libc/test/src/stdlib/strtoull_test.cpp --- a/libc/test/src/stdlib/strtoull_test.cpp +++ b/libc/test/src/stdlib/strtoull_test.cpp @@ -12,6 +12,7 @@ #include #include +#include TEST(LlvmLibcStrToULLTest, InvalidBase) { const char *ten = "10"; @@ -27,7 +28,7 @@ errno = 0; ASSERT_EQ(__llvm_libc::strtoull(ten, &str_end, 10), 10ull); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - ten, 2l); + EXPECT_EQ(str_end - ten, ptrdiff_t(2)); errno = 0; ASSERT_EQ(__llvm_libc::strtoull(ten, nullptr, 10), 10ull); ASSERT_EQ(errno, 0); @@ -36,40 +37,40 @@ errno = 0; ASSERT_EQ(__llvm_libc::strtoull(hundred, &str_end, 10), 100ull); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - hundred, 3l); + EXPECT_EQ(str_end - hundred, ptrdiff_t(3)); const char *negative = "-100"; errno = 0; ASSERT_EQ(__llvm_libc::strtoull(negative, &str_end, 10), -(100ull)); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - negative, 4l); + EXPECT_EQ(str_end - negative, ptrdiff_t(4)); const char *big_number = "123456789012345"; errno = 0; ASSERT_EQ(__llvm_libc::strtoull(big_number, &str_end, 10), 123456789012345ull); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - big_number, 15l); + EXPECT_EQ(str_end - big_number, ptrdiff_t(15)); const char *unsigned_long_long_max_number = "18446744073709551615"; errno = 0; ASSERT_EQ(__llvm_libc::strtoull(unsigned_long_long_max_number, &str_end, 10), 18446744073709551615ull); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - unsigned_long_long_max_number, 20l); + EXPECT_EQ(str_end - unsigned_long_long_max_number, ptrdiff_t(20)); const char *too_big_number = "123456789012345678901"; errno = 0; ASSERT_EQ(__llvm_libc::strtoull(too_big_number, &str_end, 10), ULLONG_MAX); ASSERT_EQ(errno, ERANGE); - EXPECT_EQ(str_end - too_big_number, 21l); + EXPECT_EQ(str_end - too_big_number, ptrdiff_t(21)); const char *too_big_negative_number = "-123456789012345678901"; errno = 0; ASSERT_EQ(__llvm_libc::strtoull(too_big_negative_number, &str_end, 10), ULLONG_MAX); ASSERT_EQ(errno, ERANGE); - EXPECT_EQ(str_end - too_big_negative_number, 22l); + EXPECT_EQ(str_end - too_big_negative_number, ptrdiff_t(22)); const char *long_number_range_test = "10000000000000000000000000000000000000000000000000"; @@ -77,7 +78,7 @@ ASSERT_EQ(__llvm_libc::strtoull(long_number_range_test, &str_end, 10), ULLONG_MAX); ASSERT_EQ(errno, ERANGE); - EXPECT_EQ(str_end - long_number_range_test, 50l); + EXPECT_EQ(str_end - long_number_range_test, ptrdiff_t(50)); } TEST(LlvmLibcStrToULLTest, MessyBaseTenDecode) { @@ -87,61 +88,61 @@ errno = 0; ASSERT_EQ(__llvm_libc::strtoull(spaces_before, &str_end, 10), 10ull); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - spaces_before, 7l); + EXPECT_EQ(str_end - spaces_before, ptrdiff_t(7)); const char *spaces_after = "10 "; errno = 0; ASSERT_EQ(__llvm_libc::strtoull(spaces_after, &str_end, 10), 10ull); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - spaces_after, 2l); + EXPECT_EQ(str_end - spaces_after, ptrdiff_t(2)); const char *word_before = "word10"; errno = 0; ASSERT_EQ(__llvm_libc::strtoull(word_before, &str_end, 10), 0ull); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - word_before, 0l); + EXPECT_EQ(str_end - word_before, ptrdiff_t(0)); const char *word_after = "10word"; errno = 0; ASSERT_EQ(__llvm_libc::strtoull(word_after, &str_end, 10), 10ull); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - word_after, 2l); + EXPECT_EQ(str_end - word_after, ptrdiff_t(2)); const char *two_numbers = "10 999"; errno = 0; ASSERT_EQ(__llvm_libc::strtoull(two_numbers, &str_end, 10), 10ull); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - two_numbers, 2l); + EXPECT_EQ(str_end - two_numbers, ptrdiff_t(2)); const char *two_signs = "--10 999"; errno = 0; ASSERT_EQ(__llvm_libc::strtoull(two_signs, &str_end, 10), 0ull); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - two_signs, 1l); + EXPECT_EQ(str_end - two_signs, ptrdiff_t(1)); const char *sign_before = "+2=4"; errno = 0; ASSERT_EQ(__llvm_libc::strtoull(sign_before, &str_end, 10), 2ull); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - sign_before, 2l); + EXPECT_EQ(str_end - sign_before, ptrdiff_t(2)); const char *sign_after = "2+2=4"; errno = 0; ASSERT_EQ(__llvm_libc::strtoull(sign_after, &str_end, 10), 2ull); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - sign_after, 1l); + EXPECT_EQ(str_end - sign_after, ptrdiff_t(1)); const char *tab_before = "\t10"; errno = 0; ASSERT_EQ(__llvm_libc::strtoull(tab_before, &str_end, 10), 10ull); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - tab_before, 3l); + EXPECT_EQ(str_end - tab_before, ptrdiff_t(3)); const char *all_together = "\t -12345and+67890"; errno = 0; ASSERT_EQ(__llvm_libc::strtoull(all_together, &str_end, 10), -(12345ull)); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - all_together, 9l); + EXPECT_EQ(str_end - all_together, ptrdiff_t(9)); } static char int_to_b36_char(int input) { @@ -255,13 +256,13 @@ errno = 0; ASSERT_EQ(__llvm_libc::strtoull(no_prefix, &str_end, 16), 0x123abcull); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - no_prefix, 6l); + EXPECT_EQ(str_end - no_prefix, ptrdiff_t(6)); const char *yes_prefix = "0x456def"; errno = 0; ASSERT_EQ(__llvm_libc::strtoull(yes_prefix, &str_end, 16), 0x456defull); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - yes_prefix, 8l); + EXPECT_EQ(str_end - yes_prefix, ptrdiff_t(8)); } TEST(LlvmLibcStrToULLTest, AutomaticBaseSelection) { @@ -271,25 +272,25 @@ errno = 0; ASSERT_EQ(__llvm_libc::strtoull(base_ten, &str_end, 0), 12345ull); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - base_ten, 5l); + EXPECT_EQ(str_end - base_ten, ptrdiff_t(5)); const char *base_sixteen_no_prefix = "123abc"; errno = 0; ASSERT_EQ(__llvm_libc::strtoull(base_sixteen_no_prefix, &str_end, 0), 123ull); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - base_sixteen_no_prefix, 3l); + EXPECT_EQ(str_end - base_sixteen_no_prefix, ptrdiff_t(3)); const char *base_sixteen_with_prefix = "0x456def"; errno = 0; ASSERT_EQ(__llvm_libc::strtoull(base_sixteen_with_prefix, &str_end, 0), 0x456defull); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - base_sixteen_with_prefix, 8l); + EXPECT_EQ(str_end - base_sixteen_with_prefix, ptrdiff_t(8)); const char *base_eight_with_prefix = "012345"; errno = 0; ASSERT_EQ(__llvm_libc::strtoull(base_eight_with_prefix, &str_end, 0), 012345ull); ASSERT_EQ(errno, 0); - EXPECT_EQ(str_end - base_eight_with_prefix, 6l); + EXPECT_EQ(str_end - base_eight_with_prefix, ptrdiff_t(6)); } diff --git a/libc/utils/CPP/Limits.h b/libc/utils/CPP/Limits.h --- a/libc/utils/CPP/Limits.h +++ b/libc/utils/CPP/Limits.h @@ -39,8 +39,8 @@ }; template <> class NumericLimits { public: - static constexpr long max() { return ULONG_MAX; } - static constexpr long min() { return 0; } + static constexpr unsigned long max() { return ULONG_MAX; } + static constexpr unsigned long min() { return 0; } }; template <> class NumericLimits { public: @@ -49,8 +49,8 @@ }; template <> class NumericLimits { public: - static constexpr long max() { return ULLONG_MAX; } - static constexpr long min() { return 0; } + static constexpr unsigned long long max() { return ULLONG_MAX; } + static constexpr unsigned long long min() { return 0; } }; } // namespace cpp