Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: treat clang-tidy warnings as errors #1745

Merged
merged 14 commits into from
Jan 11, 2024
3 changes: 2 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FormatStyle: file
HeaderFilterRegex: 'silkworm/(api|core|infra|node|sentry|rpc|sync)/.+\.hpp$'
WarningsAsErrors: '-*'
WarningsAsErrors: '*'
Checks: >
abseil-*,
-abseil-string-find-str-contains,
Expand Down Expand Up @@ -64,6 +64,7 @@ Checks: >
-misc-no-recursion,
-misc-non-private-member-variables-in-classes,
-misc-redundant-expression,
-misc-unused-using-decls,
-misc-use-anonymous-namespace,
modernize-*,
-modernize-avoid-c-arrays,
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/compiler_warnings.cmake)

if(SILKWORM_CLANG_TIDY)
find_program(CLANG_TIDY clang-tidy REQUIRED)
set(CMAKE_C_CLANG_TIDY "${CLANG_TIDY};-warnings-as-errors=*")
set(CMAKE_C_CLANG_TIDY "${CLANG_TIDY}")
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY}")
endif()

Expand Down
20 changes: 8 additions & 12 deletions cmd/common/db_checklist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,17 @@ void run_db_checklist(NodeSettings& node_settings, bool init_if_empty) {
const auto known_value_activation{known_value.get<uint64_t>()};
const auto active_value_activation{active_value.get<uint64_t>()};
if (known_value_activation != active_value_activation) {
bool must_throw{false};
if (!known_value_activation && active_value_activation &&
active_value_activation <= header_download_progress) {
const bool must_throw{
// Can't de-activate an already activated fork block
must_throw = true;
} else if (!active_value_activation && known_value_activation &&
known_value_activation <= header_download_progress) {
(!known_value_activation && active_value_activation &&
active_value_activation <= header_download_progress) ||
// Can't activate a fork block BEFORE current height
must_throw = true;
} else if (known_value_activation && active_value_activation &&
std::min(known_value_activation, active_value_activation) <=
header_download_progress) {
(!active_value_activation && known_value_activation &&
known_value_activation <= header_download_progress) ||
// Can change activation height BEFORE current height
must_throw = true;
}
(known_value_activation && active_value_activation &&
std::min(known_value_activation, active_value_activation) <=
header_download_progress)};
if (must_throw) {
throw std::runtime_error("Can't apply modified chain config key " +
known_key + " from " +
Expand Down
3 changes: 2 additions & 1 deletion cmd/silkworm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ int main(int argc, char* argv[]) {
};

// Execution: the execution layer engine
// NOLINTNEXTLINE(cppcoreguidelines-slicing)
silkworm::node::Node execution_node{settings.node_settings, sentry_client, chaindata_db};
execution::LocalClient& execution_client{execution_node.execution_local_client()};

Expand All @@ -306,7 +307,7 @@ int main(int argc, char* argv[]) {
};
chainsync::Sync chain_sync_process{
context_pool.any_executor(),
chaindata_db,
chaindata_db, // NOLINT(cppcoreguidelines-slicing)
execution_client,
sentry_client,
*node_settings.chain_config,
Expand Down
5 changes: 4 additions & 1 deletion silkworm/capi/sentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ SILKWORM_EXPORT int silkworm_sentry_start(SilkwormHandle handle, const struct Si
std::latch sentry_started{1};
std::exception_ptr startup_ex_ptr;

handle->sentry_thread = std::make_unique<std::thread>([settings = std::move(settings), &sentry_stop_signal = handle->sentry_stop_signal, &sentry_started, &startup_ex_ptr] {
handle->sentry_thread = std::make_unique<std::thread>([settings = std::move(settings),
&sentry_stop_signal = handle->sentry_stop_signal,
&sentry_started,
&startup_ex_ptr]() mutable {
try {
log::set_thread_name("sentry-run");
sentry_run(std::move(settings), sentry_stop_signal.slot(), sentry_started);
Expand Down
1 change: 1 addition & 0 deletions silkworm/capi/silkworm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ SILKWORM_EXPORT int silkworm_init(
auto snapshot_repository = std::make_unique<snapshot::SnapshotRepository>();
db::DataModel::set_snapshot_repository(snapshot_repository.get());

// NOLINTNEXTLINE(bugprone-unhandled-exception-at-new)
*handle = new SilkwormInstance{
{}, // context_pool_settings
make_path(settings->data_dir_path),
Expand Down
4 changes: 0 additions & 4 deletions silkworm/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ else()
add_compile_options(-fno-exceptions)
endif()

if(SILKWORM_CLANG_TIDY)
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY};-warnings-as-errors=*")
endif()

file(
GLOB_RECURSE
SILKWORM_CORE_SRC
Expand Down
4 changes: 0 additions & 4 deletions silkworm/infra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ find_package(gRPC REQUIRED)
find_package(GTest REQUIRED)
find_package(magic_enum REQUIRED)

if(SILKWORM_CLANG_TIDY)
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY};-warnings-as-errors=*")
endif()

add_subdirectory(test_util)

set(TARGET silkworm_infra)
Expand Down
4 changes: 0 additions & 4 deletions silkworm/node/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ find_package(magic_enum REQUIRED)
find_package(Protobuf REQUIRED)
find_package(roaring REQUIRED)

if(SILKWORM_CLANG_TIDY)
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY};-warnings-as-errors=*")
endif()

file(
GLOB_RECURSE
SILKWORM_NODE_SRC
Expand Down
4 changes: 0 additions & 4 deletions silkworm/rpc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ find_package(jwt-cpp REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(roaring REQUIRED)

if(SILKWORM_CLANG_TIDY)
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY};-warnings-as-errors=*")
endif()

# Silkrpc library
file(
GLOB_RECURSE
Expand Down
2 changes: 0 additions & 2 deletions silkworm/rpc/commands/engine_api_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@

namespace silkworm::rpc::commands {

using evmc::literals::operator""_bytes32;

namespace {
//! This dummy transaction just gives you the same cursor over and over again.
class DummyTransaction : public ethdb::Transaction {
Expand Down
2 changes: 0 additions & 2 deletions silkworm/rpc/common/util_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ TEST_CASE("print Bytes", "[rpc][common][util]") {
CHECK_NOTHROW(test_util::null_stream() << b);
}

using evmc::literals::operator""_address, evmc::literals::operator""_bytes32;

TEST_CASE("byte view from string", "[rpc][common][util]") {
CHECK(silkworm::byte_view_of_string("").empty());
}
Expand Down
2 changes: 0 additions & 2 deletions silkworm/rpc/core/account_walker_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@

namespace silkworm::rpc {

using evmc::literals::operator""_address;

static const nlohmann::json empty;
static const std::string zeros = "00000000000000000000000000000000000000000000000000000000000000000000000000000000"; // NOLINT

Expand Down
1 change: 0 additions & 1 deletion silkworm/rpc/core/estimate_gas_oracle_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ struct RemoteDatabaseTest : test::KVTestBase {
};

using testing::_;
using testing::InvokeWithoutArgs;
using testing::Return;

TEST_CASE("EstimateGasException") {
Expand Down
2 changes: 0 additions & 2 deletions silkworm/rpc/core/evm_debug_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@

namespace silkworm::rpc::debug {

using evmc::literals::operator""_address;

using testing::InvokeWithoutArgs;

static Bytes kZeroKey{*silkworm::from_hex("0000000000000000")};
Expand Down
2 changes: 0 additions & 2 deletions silkworm/rpc/core/evm_executor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@

namespace silkworm::rpc {

using evmc::literals::operator""_address, evmc::literals::operator""_bytes32;

#ifndef SILKWORM_SANITIZE
TEST_CASE("EVMExecutor") {
silkworm::test_util::SetLogVerbosityGuard log_guard{log::Level::kNone};
Expand Down
3 changes: 0 additions & 3 deletions silkworm/rpc/core/evm_trace_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@

namespace silkworm::rpc::trace {

using evmc::literals::operator""_address;
using evmc::literals::operator""_bytes32;

using testing::InvokeWithoutArgs;

static Bytes kZeroKey{*silkworm::from_hex("0000000000000000")};
Expand Down
2 changes: 0 additions & 2 deletions silkworm/rpc/core/gas_price_oracle_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

namespace silkworm {

using evmc::literals::operator""_address;

static const evmc::address kBeneficiary = 0xe5ef458d37212a06e3f59d40c454e76150ae7c31_address;
static const evmc::address kFromTnx1 = 0xe5ef458d37212a06e3f59d40c454e76150ae7c32_address;
static const evmc::address kFromTnx2 = 0xe5ef458d37212a06e3f59d40c454e76150ae7c33_address;
Expand Down
1 change: 0 additions & 1 deletion silkworm/rpc/core/rawdb/chain_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ using testing::_;
using testing::Invoke;
using testing::InvokeWithoutArgs;
using testing::Unused;
using evmc::literals::operator""_bytes32;

static silkworm::Bytes kNumber{*silkworm::from_hex("00000000003D0900")};
static silkworm::Bytes kTotalBurnt{*silkworm::from_hex("0000000000000005")};
Expand Down
1 change: 0 additions & 1 deletion silkworm/rpc/core/state_reader_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

namespace silkworm::rpc {

using evmc::literals::operator""_bytes32;
using testing::_;
using testing::InvokeWithoutArgs;

Expand Down
3 changes: 0 additions & 3 deletions silkworm/rpc/core/storage_walker_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@

namespace silkworm::rpc {

using evmc::literals::operator""_address;
using evmc::literals::operator""_bytes32;

const nlohmann::json empty;
const std::string zeros = "00000000000000000000000000000000000000000000000000000000000000000000000000000000"; // NOLINT

Expand Down
3 changes: 0 additions & 3 deletions silkworm/rpc/txpool/miner_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@

namespace silkworm::rpc::txpool {

using Catch::Matchers::Message;
using testing::_;

using evmc::literals::operator""_bytes32;
using StrictMockMiningStub = testing::StrictMock<::txpool::MockMiningStub>;

Expand Down
2 changes: 0 additions & 2 deletions silkworm/rpc/txpool/transaction_pool_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ inline bool operator==(const AddReply& lhs, const AddReply& rhs) {

namespace silkworm::rpc::txpool {

using testing::_;

using evmc::literals::operator""_address, evmc::literals::operator""_bytes32;
using StrictMockTxpoolStub = testing::StrictMock<::txpool::MockTxpoolStub>;

Expand Down
4 changes: 0 additions & 4 deletions silkworm/sentry/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ find_package(Microsoft.GSL REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(Snappy REQUIRED)

if(SILKWORM_CLANG_TIDY)
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY};-warnings-as-errors=*")
endif()

# sentry common
add_subdirectory(common)

Expand Down
4 changes: 0 additions & 4 deletions silkworm/sync/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
find_package(absl REQUIRED)
find_package(magic_enum REQUIRED)

if(SILKWORM_CLANG_TIDY)
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY};-warnings-as-errors=*")
endif()

file(GLOB_RECURSE SILKWORM_SYNC_SRC CONFIGURE_DEPENDS "*.cpp" "*.hpp")
list(FILTER SILKWORM_SYNC_SRC EXCLUDE REGEX "_test\\.cpp$")

Expand Down