Skip to content

Commit faa2373

Browse files
author
MarcoFalke
committed
refactor: Enable clang-tidy bugprone-unused-return-value
This requires some small refactors to silence false-positive warnings. Also, expand the bugprone-unused-return-value.CheckedReturnTypes option to include util::Result, and util::Expected.
1 parent fa114be commit faa2373

File tree

6 files changed

+10
-6
lines changed

6 files changed

+10
-6
lines changed

src/.clang-tidy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ bugprone-string-constructor,
77
bugprone-use-after-move,
88
bugprone-lambda-function-name,
99
bugprone-unhandled-self-assignment,
10+
bugprone-unused-return-value,
1011
misc-unused-using-decls,
1112
misc-no-recursion,
1213
modernize-deprecated-headers,
@@ -36,3 +37,5 @@ CheckOptions:
3637
value: false
3738
- key: bugprone-unhandled-self-assignment.WarnOnlyIfThisHasSuspiciousField
3839
value: false
40+
- key: bugprone-unused-return-value.CheckedReturnTypes
41+
value: '^::std::error_code$;^::std::error_condition$;^::std::errc$;^::std::expected$;^::util::Result$;^::util::Expected$'

src/bench/coin_selection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static void BnBExhaustion(benchmark::Bench& bench)
130130
bench.run([&] {
131131
// Benchmark
132132
CAmount target = make_hard_case(17, utxo_pool);
133-
SelectCoinsBnB(utxo_pool, target, 0, MAX_STANDARD_TX_WEIGHT); // Should exhaust
133+
[[maybe_unused]] auto _{SelectCoinsBnB(utxo_pool, target, /*cost_of_change=*/0, MAX_STANDARD_TX_WEIGHT)}; // Should exhaust
134134

135135
// Cleanup
136136
utxo_pool.clear();

src/bitcoin-cli.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,7 @@ static UniValue CallRPC(BaseRequestHandler* rh, const std::string& strMethod, co
899899
throw CConnectionFailed("uri-encode failed");
900900
}
901901
}
902-
int r = evhttp_make_request(evcon.get(), req.get(), EVHTTP_REQ_POST, endpoint.c_str());
903-
req.release(); // ownership moved to evcon in above call
902+
int r = evhttp_make_request(evcon.get(), req.release(), EVHTTP_REQ_POST, endpoint.c_str());
904903
if (r != 0) {
905904
throw CConnectionFailed("send http request failed");
906905
}

src/httpserver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
330330
std::unique_ptr<HTTPWorkItem> item(new HTTPWorkItem(std::move(hreq), path, i->handler));
331331
assert(g_work_queue);
332332
if (g_work_queue->Enqueue(item.get())) {
333-
item.release(); /* if true, queue took ownership */
333+
[[maybe_unused]] auto _{item.release()}; /* if true, queue took ownership */
334334
} else {
335335
LogWarning("Request rejected because http work queue depth exceeded, it can be increased with the -rpcworkqueue= setting");
336336
item->req->WriteReply(HTTP_SERVICE_UNAVAILABLE, "Work queue depth exceeded");

src/ipc/test/ipc_test.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ void IpcPipeTest()
6363
auto foo_client = std::make_unique<mp::ProxyClient<gen::FooInterface>>(
6464
connection_client->m_rpc_system->bootstrap(mp::ServerVatId().vat_id).castAs<gen::FooInterface>(),
6565
connection_client.get(), /* destroy_connection= */ true);
66-
connection_client.release();
66+
{
67+
[[maybe_unused]] auto _{connection_client.release()};
68+
}
6769
foo_promise.set_value(std::move(foo_client));
6870

6971
auto connection_server = std::make_unique<mp::Connection>(loop, kj::mv(pipe.ends[1]), [&](mp::Connection& connection) {

src/wallet/test/fuzz/spend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ FUZZ_TARGET(wallet_create_transaction, .init = initialize_setup)
9898

9999
std::optional<unsigned int> change_pos;
100100
if (fuzzed_data_provider.ConsumeBool()) change_pos = fuzzed_data_provider.ConsumeIntegral<unsigned int>();
101-
(void)CreateTransaction(*fuzzed_wallet.wallet, recipients, change_pos, coin_control);
101+
[[maybe_unused]] auto _{CreateTransaction(*fuzzed_wallet.wallet, recipients, change_pos, coin_control)};
102102
}
103103
} // namespace
104104
} // namespace wallet

0 commit comments

Comments
 (0)