From 59c6381157d72d697c5c076d53b04bc523917110 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Mon, 14 Oct 2024 13:30:59 +0200 Subject: [PATCH 1/2] Replace a few C-style casts with `static_cast`. --- hilti/runtime/include/types/integer.h | 2 +- hilti/runtime/src/tests/integer.cc | 12 ++++++------ hilti/toolchain/src/compiler/coercer.cc | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/hilti/runtime/include/types/integer.h b/hilti/runtime/include/types/integer.h index 2bf1ce028..561133a32 100644 --- a/hilti/runtime/include/types/integer.h +++ b/hilti/runtime/include/types/integer.h @@ -340,7 +340,7 @@ inline hilti::rt::integer::safe bits(hilti::rt::integer::safe v, uin if ( range == width ) return v; - const auto mask = ((uint64_t(1) << range) - uint64_t(1U)) << lower; + const auto mask = ((static_cast(1) << range) - static_cast(1U)) << lower; return (v & mask) >> lower; } diff --git a/hilti/runtime/src/tests/integer.cc b/hilti/runtime/src/tests/integer.cc index 0e89e5840..c186b25be 100644 --- a/hilti/runtime/src/tests/integer.cc +++ b/hilti/runtime/src/tests/integer.cc @@ -51,17 +51,17 @@ TEST_CASE("flip32") { const auto max = std::numeric_limits::max(); // NOLINTNEXTLINE(bugprone-integer-division) - CHECK_EQ(integer::flip32(max / 2), std::pow(uint64_t(256), 4) - 256 / 2 - 1); + CHECK_EQ(integer::flip32(max / 2), std::pow(static_cast(256), 4) - 256 / 2 - 1); - CHECK_EQ(integer::flip32(max - 3), std::pow(uint64_t(256), 4) - std::pow(256, 3) * 3 - 1); - CHECK_EQ(integer::flip32(max - 2), std::pow(uint64_t(256), 4) - std::pow(256, 3) * 2 - 1); - CHECK_EQ(integer::flip32(max - 1), std::pow(uint64_t(256), 4) - std::pow(256, 3) * 1 - 1); - CHECK_EQ(integer::flip32(max - 0), std::pow(uint64_t(256), 4) - std::pow(256, 3) * 0 - 1); + CHECK_EQ(integer::flip32(max - 3), std::pow(static_cast(256), 4) - std::pow(256, 3) * 3 - 1); + CHECK_EQ(integer::flip32(max - 2), std::pow(static_cast(256), 4) - std::pow(256, 3) * 2 - 1); + CHECK_EQ(integer::flip32(max - 1), std::pow(static_cast(256), 4) - std::pow(256, 3) * 1 - 1); + CHECK_EQ(integer::flip32(max - 0), std::pow(static_cast(256), 4) - std::pow(256, 3) * 0 - 1); } TEST_CASE("flip64") { CHECK_EQ(integer::flip64(0), 0); - CHECK_EQ(integer::flip64(1), std::pow(uint64_t(256), 7) * 1); + CHECK_EQ(integer::flip64(1), std::pow(static_cast(256), 7) * 1); CHECK_EQ(integer::flip64(2), std::pow(256, 7) * 2); CHECK_EQ(integer::flip64(3), std::pow(256, 7) * 3); diff --git a/hilti/toolchain/src/compiler/coercer.cc b/hilti/toolchain/src/compiler/coercer.cc index 97954ed2c..f97f55763 100644 --- a/hilti/toolchain/src/compiler/coercer.cc +++ b/hilti/toolchain/src/compiler/coercer.cc @@ -137,7 +137,7 @@ struct VisitorCtor : visitor::PreOrder { switch ( t->isWildcard() ? 64 : t->width() ) { case 8: if ( static_cast(int8_t(d)) == d ) - result = builder->ctorSignedInteger(int64_t(d), 8, n->meta()); + result = builder->ctorSignedInteger(static_cast(d), 8, n->meta()); break; case 16: @@ -167,7 +167,7 @@ struct VisitorCtor : visitor::PreOrder { case 16: if ( static_cast(static_cast(d)) == d ) - result = builder->ctorUnsignedInteger(uint64_t(d), 16, n->meta()); + result = builder->ctorUnsignedInteger(static_cast(d), 16, n->meta()); break; case 32: From 1ae59943878ed90f02a4e3eb821dca52bbd94651 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Mon, 14 Oct 2024 13:32:10 +0200 Subject: [PATCH 2/2] Disable cpplint iwyu check. This check gets easily confused and e.g., suggests to include stdlib headers already included in the header for a file, or suggests including `` for our internal `string` namespace. --- CPPLINT.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CPPLINT.cfg b/CPPLINT.cfg index 41f8f87a6..5dcfa5fb1 100644 --- a/CPPLINT.cfg +++ b/CPPLINT.cfg @@ -1,2 +1,2 @@ # Copyright (c) 2020-2023 by the Zeek Project. See LICENSE for details. -filter=-,+build/include_what_you_use,+readability/casting +filter=-,+readability/casting