From beb23867f8cfd5bc0c58b8044de3433b40c2b3e5 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 3 Feb 2023 14:42:41 -0500 Subject: Suppress/fix new warnings in clang-tidy 15 --- .clang-tidy | 1 + src/AlsaDriver.cpp | 4 ++-- src/Configuration.cpp | 2 +- src/JackLibDriver.cpp | 6 +++--- src/Patchage.cpp | 16 +++++++++------- src/Reactor.cpp | 2 +- src/TextViewLog.cpp | 8 ++++---- src/main.cpp | 10 +++++++--- 8 files changed, 28 insertions(+), 21 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index e9e208a..b751d0c 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -14,6 +14,7 @@ Checks: > -*-vararg, -abseil-string-find-str-contains, -altera-*, + -bugprone-assignment-in-if-condition, -bugprone-easily-swappable-parameters, -cert-dcl21-cpp, -cert-dcl50-cpp, diff --git a/src/AlsaDriver.cpp b/src/AlsaDriver.cpp index 83a0a48..7057b12 100644 --- a/src/AlsaDriver.cpp +++ b/src/AlsaDriver.cpp @@ -339,7 +339,7 @@ AlsaDriver::connect(const PortID& tail_id, const PortID& head_id) result = false; } - int ret = snd_seq_subscribe_port(_seq, subs); + const int ret = snd_seq_subscribe_port(_seq, subs); if (ret < 0) { _log.error( fmt::format("[ALSA] Subscription failed ({})", snd_strerror(ret))); @@ -380,7 +380,7 @@ AlsaDriver::disconnect(const PortID& tail_id, const PortID& head_id) return false; } - int ret = snd_seq_unsubscribe_port(_seq, subs); + const int ret = snd_seq_unsubscribe_port(_seq, subs); if (ret < 0) { _log.error(fmt::format("[ALSA] Failed to disconnect {} => {} ({})", tail_id, diff --git a/src/Configuration.cpp b/src/Configuration.cpp index 6490a88..7bc2b20 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -161,7 +161,7 @@ static std::vector get_filenames() { std::vector filenames; - std::string prefix; + const std::string prefix; const char* xdg_config_home = getenv("XDG_CONFIG_HOME"); const char* home = getenv("HOME"); diff --git a/src/JackLibDriver.cpp b/src/JackLibDriver.cpp index 2813a92..5133bc6 100644 --- a/src/JackLibDriver.cpp +++ b/src/JackLibDriver.cpp @@ -146,7 +146,7 @@ JackLibDriver::attach(const bool launch_daemon) void JackLibDriver::detach() { - std::lock_guard lock{_shutdown_mutex}; + const std::lock_guard lock{_shutdown_mutex}; if (_client) { jack_deactivate(_client); @@ -242,7 +242,7 @@ JackLibDriver::get_port_info(const jack_port_t* const port) void JackLibDriver::refresh(const EventSink& sink) { - std::lock_guard lock{_shutdown_mutex}; + const std::lock_guard lock{_shutdown_mutex}; if (!_client) { return; @@ -470,7 +470,7 @@ JackLibDriver::on_shutdown(void* const driver) So, since JACK is a hot mess and it's impossible to gracefully handle this situation, just leak the client. */ - std::lock_guard lock{me->_shutdown_mutex}; + const std::lock_guard lock{me->_shutdown_mutex}; me->_client = nullptr; me->_is_activated = false; diff --git a/src/Patchage.cpp b/src/Patchage.cpp index c3166c2..f2d2b59 100644 --- a/src/Patchage.cpp +++ b/src/Patchage.cpp @@ -139,8 +139,10 @@ port_order(const GanvPort* a, const GanvPort* b, void*) const auto* pa = dynamic_cast(Glib::wrap(a)); const auto* pb = dynamic_cast(Glib::wrap(b)); if (pa && pb) { - if (pa->order() && pb->order()) { - return *pa->order() - *pb->order(); + const auto oa = pa->order(); + const auto ob = pb->order(); + if (oa && ob) { + return *oa - *ob; } if (pa->order()) { @@ -218,11 +220,11 @@ Patchage::Patchage(Options options) gtk_window_set_default_icon_name("patchage"); // Create list model for buffer size selector - Glib::RefPtr buf_size_store = + const Glib::RefPtr buf_size_store = Gtk::ListStore::create(_buf_size_columns); for (size_t i = 32; i <= 4096; i *= 2) { - Gtk::TreeModel::Row row = *(buf_size_store->append()); - row[_buf_size_columns.label] = std::to_string(i); + const Gtk::TreeModel::Row row = *(buf_size_store->append()); + row[_buf_size_columns.label] = std::to_string(i); } _buf_size_combo->set_model(buf_size_store); @@ -750,7 +752,7 @@ Patchage::operator()(const setting::Zoom& setting) void Patchage::on_driver_event(const Event& event) { - std::lock_guard lock{_events_mutex}; + const std::lock_guard lock{_events_mutex}; _driver_events.emplace(event); } @@ -758,7 +760,7 @@ Patchage::on_driver_event(const Event& event) void Patchage::process_events() { - std::lock_guard lock{_events_mutex}; + const std::lock_guard lock{_events_mutex}; while (!_driver_events.empty()) { const Event& event = _driver_events.front(); diff --git a/src/Reactor.cpp b/src/Reactor.cpp index 44bca82..9fdb317 100644 --- a/src/Reactor.cpp +++ b/src/Reactor.cpp @@ -58,7 +58,7 @@ Reactor::Reactor(Configuration& conf, void Reactor::operator()(const action::ChangeSetting& action) { - SettingVisitor visitor{_conf}; + const SettingVisitor visitor{_conf}; std::visit(visitor, action.setting); } diff --git a/src/TextViewLog.cpp b/src/TextViewLog.cpp index 50d85b0..712b760 100644 --- a/src/TextViewLog.cpp +++ b/src/TextViewLog.cpp @@ -45,7 +45,7 @@ TextViewLog::TextViewLog(Widget& text_view) void TextViewLog::info(const std::string& msg) { - Glib::RefPtr buffer = _text_view->get_buffer(); + const Glib::RefPtr buffer = _text_view->get_buffer(); buffer->insert(buffer->end(), std::string("\n") + msg); _text_view->scroll_to_mark(buffer->get_insert(), 0); } @@ -53,7 +53,7 @@ TextViewLog::info(const std::string& msg) void TextViewLog::warning(const std::string& msg) { - Glib::RefPtr buffer = _text_view->get_buffer(); + const Glib::RefPtr buffer = _text_view->get_buffer(); buffer->insert_with_tag(buffer->end(), std::string("\n") + msg, _warning_tag); _text_view->scroll_to_mark(buffer->get_insert(), 0); } @@ -61,7 +61,7 @@ TextViewLog::warning(const std::string& msg) void TextViewLog::error(const std::string& msg) { - Glib::RefPtr buffer = _text_view->get_buffer(); + const Glib::RefPtr buffer = _text_view->get_buffer(); buffer->insert_with_tag(buffer->end(), std::string("\n") + msg, _error_tag); _text_view->scroll_to_mark(buffer->get_insert(), 0); } @@ -69,7 +69,7 @@ TextViewLog::error(const std::string& msg) int TextViewLog::min_height() const { - Glib::RefPtr buffer = _text_view->get_buffer(); + const Glib::RefPtr buffer = _text_view->get_buffer(); int y = 0; int line_height = 0; diff --git a/src/main.cpp b/src/main.cpp index 568ebca..6d09fe4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,7 +23,8 @@ #if USE_GETTEXT # include -# include + +# include #endif #include @@ -100,7 +101,10 @@ main(int argc, char** argv) #endif #if USE_GETTEXT - setlocale(LC_ALL, ""); + if (!setlocale(LC_ALL, "")) { + std::cerr << "patchage: failed to set locale\n"; + } + bindtextdomain("patchage", PATCHAGE_LOCALE_DIR); bind_textdomain_codeset("patchage", "UTF-8"); textdomain("patchage"); @@ -109,7 +113,7 @@ main(int argc, char** argv) try { Glib::thread_init(); - Gtk::Main app(argc, argv); + const Gtk::Main app(argc, argv); ++argv; --argc; -- cgit v1.2.1