diff --git a/.github/workflows/amalgamate-ubuntu24.yml b/.github/workflows/amalgamate-ubuntu24.yml index a7982d4..c2651fb 100644 --- a/.github/workflows/amalgamate-ubuntu24.yml +++ b/.github/workflows/amalgamate-ubuntu24.yml @@ -14,4 +14,4 @@ jobs: python3 ./script/amalgamate.py > build/fast_float/fast_float.h && cp tests/string_test.cpp build/ && cd build && - g++ string_test.cpp + g++ -Werror=old-style-cast string_test.cpp diff --git a/benchmarks/bench_ip.cpp b/benchmarks/bench_ip.cpp index a3bd124..cfb4525 100644 --- a/benchmarks/bench_ip.cpp +++ b/benchmarks/bench_ip.cpp @@ -113,10 +113,10 @@ int main() { buf.reserve(N * ip_size); for (size_t i = 0; i < N; ++i) { - uint8_t a = (uint8_t)dist(rng); - uint8_t b = (uint8_t)dist(rng); - uint8_t c = (uint8_t)dist(rng); - uint8_t d = (uint8_t)dist(rng); + uint8_t a = static_cast(dist(rng)); + uint8_t b = static_cast(dist(rng)); + uint8_t c = static_cast(dist(rng)); + uint8_t d = static_cast(dist(rng)); std::string ip_line = make_ip_line(a, b, c, d); ip_line.resize(ip_size, ' '); // pad to fixed size buf.append(ip_line); @@ -132,7 +132,7 @@ int main() { std::string buffer(ip_size * N, ' '); pretty_print(volume, bytes, "memcpy baseline", counters::bench([&]() { - std::memcpy((char *)buffer.data(), buf.data(), bytes); + std::memcpy(buffer.data(), buf.data(), bytes); })); pretty_print(volume, bytes, "just_seek_ip_end (no parse)", @@ -143,7 +143,7 @@ int main() { int ok = 0; for (size_t i = 0; i < N; ++i) { const char *q = seek_ip_end(p, pend); - sum += (uint32_t)(q - p); + sum += static_cast(q - p); p += ip_size; } sink += sum; diff --git a/benchmarks/bench_uint16.cpp b/benchmarks/bench_uint16.cpp index c4cef81..a17db57 100644 --- a/benchmarks/bench_uint16.cpp +++ b/benchmarks/bench_uint16.cpp @@ -75,7 +75,7 @@ int main() { buffer.reserve(N * 6); // up to 5 digits + delimiter for (size_t i = 0; i < N; ++i) { - uint16_t val = (uint16_t)dist(rng); + uint16_t val = static_cast(dist(rng)); expected.push_back(val); std::string s = std::to_string(val); buffer.append(s); diff --git a/include/fast_float/bigint.h b/include/fast_float/bigint.h index b7edf12..297bad4 100644 --- a/include/fast_float/bigint.h +++ b/include/fast_float/bigint.h @@ -623,8 +623,8 @@ struct bigint : pow5_tables<> { // Work around clang bug https://godbolt.org/z/zedh7rrhc // This is similar to https://github.com/llvm/llvm-project/issues/47746, // except the workaround described there don't work here - FASTFLOAT_TRY(small_mul( - vec, limb(((void)small_power_of_5[0], small_power_of_5[exp])))); + FASTFLOAT_TRY(small_mul(vec, limb((static_cast(small_power_of_5[0]), + small_power_of_5[exp])))); } return true; diff --git a/include/fast_float/digit_comparison.h b/include/fast_float/digit_comparison.h index 7ac20da..c29a83e 100644 --- a/include/fast_float/digit_comparison.h +++ b/include/fast_float/digit_comparison.h @@ -403,8 +403,8 @@ negative_digit_comp(bigint &real_digits, adjusted_mantissa am, round(am, [ord](adjusted_mantissa &a, am_pow_t shift) { round_nearest_tie_even( a, shift, [ord](bool is_odd, bool _, bool __) -> bool { - (void)_; // not needed, since we've done our comparison - (void)__; // not needed, since we've done our comparison + static_cast(_); // not needed, since we've done our comparison + static_cast(__); // not needed, since we've done our comparison if (ord > 0) { return true; } else if (ord < 0) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 19f2452..f8cc134 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -49,7 +49,7 @@ function(fast_float_add_cpp_test TEST_NAME) target_compile_options(${TEST_NAME} PUBLIC /EHsc) endif() if(NOT WIN32) - target_compile_options(${TEST_NAME} PUBLIC -Werror -Wall -Wextra -Weffc++) + target_compile_options(${TEST_NAME} PUBLIC -Werror -Wall -Wextra -Weffc++ -Wold-style-cast) target_compile_options(${TEST_NAME} PUBLIC -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wconversion -Wsign-conversion) endif() target_link_libraries(${TEST_NAME} PUBLIC fast_float supplemental-data) diff --git a/tests/basictest.cpp b/tests/basictest.cpp index 981cbe3..7e12442 100644 --- a/tests/basictest.cpp +++ b/tests/basictest.cpp @@ -1061,7 +1061,7 @@ void basic_test(float val) { do { \ constexpr int verify_comptime_var = \ (basic_test(__VA_ARGS__), 0); \ - (void)verify_comptime_var; \ + static_cast(verify_comptime_var); \ } while (false) #define verify_options_runtime(...) \ @@ -1073,7 +1073,7 @@ void basic_test(float val) { do { \ constexpr int verify_options_comptime_var = \ (basic_test(__VA_ARGS__, options), 0); \ - (void)verify_options_comptime_var; \ + static_cast(verify_options_comptime_var); \ } while (false) #if defined(FASTFLOAT_CONSTEXPR_TESTS) diff --git a/tests/exhaustive32_midpoint.cpp b/tests/exhaustive32_midpoint.cpp index d1fc160..8feba7d 100644 --- a/tests/exhaustive32_midpoint.cpp +++ b/tests/exhaustive32_midpoint.cpp @@ -61,7 +61,7 @@ template char *to_string(T d, char *buffer) { } void strtof_from_string(char const *st, float &d) { - char *pr = (char *)st; + char *pr = const_cast(st); #if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) || \ defined(sun) || defined(__sun) d = cygwin_strtof_l(st, &pr); diff --git a/tests/string_test.cpp b/tests/string_test.cpp index 69d2a31..b0d3b20 100644 --- a/tests/string_test.cpp +++ b/tests/string_test.cpp @@ -125,7 +125,7 @@ template bool test() { template void strtod_from_string(std::string const &st, T &d); template <> void strtod_from_string(std::string const &st, double &d) { - char *pr = (char *)st.c_str(); + char *pr = const_cast(st.c_str()); #if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) || \ defined(sun) || defined(__sun) d = cygwin_strtod_l(pr, &pr); @@ -142,7 +142,7 @@ template <> void strtod_from_string(std::string const &st, double &d) { } template <> void strtod_from_string(std::string const &st, float &d) { - char *pr = (char *)st.c_str(); + char *pr = const_cast(st.c_str()); #if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) || \ defined(sun) || defined(__sun) d = cygwin_strtof_l(st.c_str(), &pr);