From 858dcf09e01e6ea9aeb32ac956c57c1b74ca4485 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 27 Aug 2024 19:25:19 +0200 Subject: [PATCH] refactor: clean-up some clang-tidy warnings --- .clang-tidy | 2 +- src/c/instance.cpp | 2 +- src/hub.cpp | 4 ++-- src/instance.cpp | 28 ++++++++++++++-------------- test/endpoint_unx.cpp | 2 +- test/tests.cpp | 4 ++-- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 301af57..f8c14f2 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,2 +1,2 @@ --- -Checks: '*,-llvmlibc-*,-readability-*,-google-readability-*,-fuchsia-*,-hicpp-exception-baseclass,-altera-*,-hicpp-braces-around-statements,-google-runtime-int,-misc-non-private-member-variables-in-classes,-cert-err58-cpp,-hicpp-no-array-decay,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-type-union-access,-hicpp-signed-bitwise,-cppcoreguidelines-avoid-magic-numbers,-misc-no-recursion,-bugprone-easily-swappable-parameters,-cppcoreguidelines-owning-memory,-cppcoreguidelines-macro-usage,-google-objc-*' +Checks: '*,-llvmlibc-*,-readability-*,-google-readability-*,-fuchsia-*,-hicpp-exception-baseclass,-altera-*,-hicpp-braces-around-statements,-google-runtime-int,-misc-non-private-member-variables-in-classes,-cert-err58-cpp,-hicpp-no-array-decay,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-type-union-access,-hicpp-signed-bitwise,-cppcoreguidelines-avoid-magic-numbers,-misc-no-recursion,-bugprone-easily-swappable-parameters,-cppcoreguidelines-owning-memory,-cppcoreguidelines-macro-usage,-cppcoreguidelines-avoid-const-or-ref-data-members,-google-objc-*' diff --git a/src/c/instance.cpp b/src/c/instance.cpp index 6c79d60..48232b8 100644 --- a/src/c/instance.cpp +++ b/src/c/instance.cpp @@ -40,7 +40,7 @@ auto thespian_self() -> thespian_handle { auto thespian_spawn_link(thespian_behaviour b, thespian_behaviour_state s, const char *name, thespian_env env, thespian_handle *handle) -> int { - thespian::env_t empty_env_{}; + const thespian::env_t empty_env_{}; thespian::env_t env_ = env ? *reinterpret_cast(env) : empty_env_; // NOLINT diff --git a/src/hub.cpp b/src/hub.cpp index afc693a..2c8c24c 100644 --- a/src/hub.cpp +++ b/src/hub.cpp @@ -33,12 +33,12 @@ hub::pipe::~pipe() = default; struct subscribe_queue : public hub::pipe { [[nodiscard]] auto push(const handle &from, filter f) { - lock_guard lock(m_); + const lock_guard lock(m_); q_.push_back(move(f)); return from.send("subscribe_filtered"); } auto pop() -> filter { - lock_guard lock(m_); + const lock_guard lock(m_); filter f = move(q_.front()); q_.pop_front(); return f; diff --git a/src/instance.cpp b/src/instance.cpp index cc03122..213cae3 100644 --- a/src/instance.cpp +++ b/src/instance.cpp @@ -1292,7 +1292,7 @@ struct acceptor_impl { void listen(string_view origpath, mode m) { private_call(); - string path = unx_mode_path(m, origpath); + const string path = unx_mode_path(m, origpath); if (auto ec = acceptor_.bind(path)) { auto _ = owner_.send("acceptor", tag_, "error", ec.value(), ec.message()); return; @@ -1353,7 +1353,7 @@ struct connector_impl { void connect(string_view origpath, mode m) { private_call(); open_ = true; - string path = unx_mode_path(m, origpath); + const string path = unx_mode_path(m, origpath); socket_.connect(path, [this](error_code ec) -> void { if (!open_) return; @@ -1574,7 +1574,7 @@ struct connector { static auto connect(in6_addr ip, port_t port, milliseconds retry_time, size_t retry_count) -> expected { - handle owner = self(); + const handle owner = self(); return spawn_link( [=]() { trap(true); @@ -1628,7 +1628,7 @@ struct acceptor { } static auto start(in6_addr ip, port_t port) -> expected { - handle owner = self(); + const handle owner = self(); return spawn_link( [=]() { trap(true); @@ -1709,7 +1709,7 @@ struct connector { static auto connect(string_view path, mode m_, milliseconds retry_time, size_t retry_count) -> expected { - handle owner = self(); + const handle owner = self(); return spawn_link( [path{string(path)}, m_, owner, retry_time, retry_count]() { trap(true); @@ -1765,7 +1765,7 @@ struct acceptor { } static auto start(string_view path, mode m_) -> expected { - handle owner = self(); + const handle owner = self(); return spawn_link( [path{string(path)}, m_, owner]() { trap(true); @@ -1804,7 +1804,7 @@ auto isenabled(context &ctx) -> bool { return isenabled(impl(ctx)); } void disable(context_impl &ctx) { auto prev = ctx.debug_enabled.fetch_sub(1, memory_order_relaxed); if (prev == 1) { - lock_guard lock(ctx.registry_mux); + const lock_guard lock(ctx.registry_mux); ctx.registry.clear(); } } @@ -1820,7 +1820,7 @@ void register_instance(context_impl &ctx, const handle &h) { return; // if (trace) // trace(array("register", name, ref_m(r))); - lock_guard lock(ctx.registry_mux); + const lock_guard lock(ctx.registry_mux); ctx.registry[name] = h; } } @@ -1828,14 +1828,14 @@ void register_instance(context_impl &ctx, const handle &h) { void unregister_instance(context_impl &ctx, const string &name) { if (not isenabled(ctx)) return; - lock_guard lock(ctx.registry_mux); + const lock_guard lock(ctx.registry_mux); // if (trace) // trace(array("unregister", name, ref_m(handle_ref(registry[name])))); ctx.registry.erase(name); } auto get_name(context_impl &ctx, const string &name) -> handle { - lock_guard lock(ctx.registry_mux); + const lock_guard lock(ctx.registry_mux); auto r = ctx.registry.find(name); return r != ctx.registry.end() ? r->second : handle{}; } @@ -1843,7 +1843,7 @@ auto get_name(context_impl &ctx, const string &name) -> handle { auto get_names(context_impl &ctx) -> buffer { vector names; { - lock_guard lock(ctx.registry_mux); + const lock_guard lock(ctx.registry_mux); for (const auto &a : ctx.registry) if (not a.second.expired()) names.push_back(a.first); @@ -1877,7 +1877,7 @@ struct connection { pos = str.find_first_of(delim); if (pos == string::npos) return make_pair(str, ""); - string word(str.data(), pos); + const string word(str.data(), pos); str.erase(0, pos + 1); return make_pair(word, str); } @@ -1886,7 +1886,7 @@ struct connection { if (buf.empty()) { vector expired_names; { - lock_guard lock(ctx.registry_mux); + const lock_guard lock(ctx.registry_mux); bool first{true}; for (const auto &a : ctx.registry) { if (not a.second.expired()) { @@ -1909,7 +1909,7 @@ struct connection { } else { auto x = getword(buf); buf = x.second; - handle a = get_name(ctx, x.first); + const handle a = get_name(ctx, x.first); if (a.expired()) { s.write("error: "); s.write(x.first); diff --git a/test/endpoint_unx.cpp b/test/endpoint_unx.cpp index f3783ad..da29011 100644 --- a/test/endpoint_unx.cpp +++ b/test/endpoint_unx.cpp @@ -86,7 +86,7 @@ struct controller { auto endpoint_unx(context &ctx, bool &result, env_t env_) -> ::result { stringstream ss; ss << "/net/vdbonline/thespian/endpoint_t_" << getpid(); - string path = ss.str(); + const string path = ss.str(); return to_result(ctx.spawn_link( [path]() { link(env().proc("log")); diff --git a/test/tests.cpp b/test/tests.cpp index 555cfde..b37b873 100644 --- a/test/tests.cpp +++ b/test/tests.cpp @@ -50,7 +50,7 @@ struct logger { auto receive(const buffer &m) { if (verbose) { - std::lock_guard lock(trace_m); + const std::lock_guard lock(trace_m); cout << name << ": "; auto dump = [&](auto val) { cout << val << " "; }; for (const auto val : m) @@ -115,7 +115,7 @@ extern "C" auto runtestcase(const char *name) -> int { env_t env{}; env_t log_env{}; auto trace = [&](const buffer &buf) { - lock_guard lock(trace_m); + const lock_guard lock(trace_m); cout << buf.to_json() << '\n'; }; log_env.on_trace(trace);