From 5e787bfbd0c637141455f7579a59eaefe4b8d98a Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 15 Feb 2023 08:37:37 +0000 Subject: [PATCH 01/10] Add option to run `clang-tidy` with compiler --- .clang-tidy | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 9 +++++++++ 2 files changed, 57 insertions(+) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 00000000..53c842cc --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,48 @@ +Checks: ' +-*, +bugprone-*, +-bugprone-easily-swappable-parameters, +-bugprone-exception-escape, +-bugprone-move-forwarding-reference, +-bugprone-narrowing-conversions, +-bugprone-reserved-identifier, +-bugprone-suspicious-semicolon, +misc-*, +-misc-non-private-member-variables-in-classes, +-misc-no-recursion, +-misc-unconventional-assign-operator, +-misc-unused-parameters, +modernize-*, +-modernize-avoid-c-arrays, +-modernize-concat-nested-namespaces, +-modernize-deprecated-headers, +-modernize-return-braced-init-list, +-modernize-use-emplace, +-modernize-use-equals-default, +-modernize-use-nodiscard, +-modernize-use-nullptr, +-modernize-use-trailing-return-type, +-modernize-use-using, +performance-*, +-performance-faster-string-find, +-performance-inefficient-vector-operation, +-performance-noexcept-move-constructor, +-performance-unnecessary-value-param, +readability-*, +-readability-braces-around-statements, +-readability-convert-member-functions-to-static, +-readability-else-after-return, +-readability-function-cognitive-complexity, +-readability-identifier-length, +-readability-implicit-bool-conversion, +-readability-inconsistent-declaration-parameter-name, +-readability-magic-numbers, +-readability-make-member-function-const, +-readability-named-parameter, +-readability-uppercase-literal-suffix, +-readability-use-anyofallof, +' +CheckOptions: + - key: modernize-use-override.IgnoreDestructors + value: true +HeaderFilterRegex: 'example/calculator.h|example/init.h|example/printer.h|include/mp/proxy-io.h|include/mp/proxy-types.h|include/mp/proxy.h|include/mp/util.h|test/mp/test/foo-types.h|test/mp/test/foo.h' diff --git a/CMakeLists.txt b/CMakeLists.txt index 717e38a5..04f68c8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,15 @@ project("Libmultiprocess" CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED YES) +option(Libmultiprocess_ENABLE_CLANG_TIDY "Run clang-tidy with the compiler." OFF) +if(Libmultiprocess_ENABLE_CLANG_TIDY) + find_program(CLANG_TIDY_EXECUTABLE NAMES clang-tidy) + if(NOT CLANG_TIDY_EXECUTABLE) + message(FATAL_ERROR "Libmultiprocess_ENABLE_CLANG_TIDY is ON but clang-tidy is not found.") + endif() + set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE}") +endif() + include(CMakePushCheckState) include(CheckCXXSourceCompiles) include(GNUInstallDirs) From 8dd83bbd9128f1732178490946f7eaa3178c17d4 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Thu, 26 Jan 2023 21:35:36 +0000 Subject: [PATCH 02/10] clang-tidy: Suppress `bugprone-suspicious-semicolon` check warning See https://clang.llvm.org/extra/clang-tidy/checks/bugprone/suspicious-semicolon.html --- .clang-tidy | 1 - src/mp/proxy.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 53c842cc..eeb9197b 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -6,7 +6,6 @@ bugprone-*, -bugprone-move-forwarding-reference, -bugprone-narrowing-conversions, -bugprone-reserved-identifier, --bugprone-suspicious-semicolon, misc-*, -misc-non-private-member-variables-in-classes, -misc-no-recursion, diff --git a/src/mp/proxy.cpp b/src/mp/proxy.cpp index e1ae9b84..adf10e18 100644 --- a/src/mp/proxy.cpp +++ b/src/mp/proxy.cpp @@ -209,7 +209,7 @@ void EventLoop::removeClient(std::unique_lock& lock) m_cv.notify_all(); Unlock(lock, [&] { char buffer = 0; - KJ_SYSCALL(write(m_post_fd, &buffer, 1)); + KJ_SYSCALL(write(m_post_fd, &buffer, 1)); // NOLINT(bugprone-suspicious-semicolon) }); } } From 1a33c35a3b5d6d85745240dc9332b14b41c3923d Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Thu, 26 Jan 2023 21:35:49 +0000 Subject: [PATCH 03/10] clang-tidy: Fix `modernize-return-braced-init-list` check See https://clang.llvm.org/extra/clang-tidy/checks/modernize/return-braced-init-list.html --- .clang-tidy | 1 - include/mp/proxy-io.h | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index eeb9197b..e707546e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -15,7 +15,6 @@ modernize-*, -modernize-avoid-c-arrays, -modernize-concat-nested-namespaces, -modernize-deprecated-headers, --modernize-return-braced-init-list, -modernize-use-emplace, -modernize-use-equals-default, -modernize-use-nodiscard, diff --git a/include/mp/proxy-io.h b/include/mp/proxy-io.h index 07e83a0f..76a64e74 100644 --- a/include/mp/proxy-io.h +++ b/include/mp/proxy-io.h @@ -159,8 +159,8 @@ class EventLoop logger << "{" << LongThreadName(m_exe_name) << "} "; return logger; } - Logger logPlain() { return Logger(false, m_log_fn); } - Logger raise() { return Logger(true, m_log_fn); } + Logger logPlain() { return {false, m_log_fn}; } + Logger raise() { return {true, m_log_fn}; } //! Process name included in thread names so combined debug output from //! multiple processes is easier to understand. From 18b52c166381aac5951de2e96d822f7077406fd2 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Thu, 26 Jan 2023 21:36:29 +0000 Subject: [PATCH 04/10] clang-tidy: Fix `modernize-use-emplace` check See https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-emplace.html --- .clang-tidy | 1 - src/mp/gen.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index e707546e..88988677 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -15,7 +15,6 @@ modernize-*, -modernize-avoid-c-arrays, -modernize-concat-nested-namespaces, -modernize-deprecated-headers, --modernize-use-emplace, -modernize-use-equals-default, -modernize-use-nodiscard, -modernize-use-nullptr, diff --git a/src/mp/gen.cpp b/src/mp/gen.cpp index 7c13ae00..69f4a967 100644 --- a/src/mp/gen.cpp +++ b/src/mp/gen.cpp @@ -616,7 +616,7 @@ int main(int argc, char** argv) auto cwd = fs->getCurrentPath(); #endif for (size_t i = 4; i < argc; ++i) { - import_paths.push_back(argv[i]); + import_paths.emplace_back(argv[i]); } for (const char* path : {CMAKE_INSTALL_PREFIX "/include", capnp_PREFIX "/include"}) { #ifdef HAVE_KJ_FILESYSTEM From 9f86c9a0a867e8aeb9c92ac13d71a9b7770a1626 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sun, 12 Feb 2023 14:15:06 +0000 Subject: [PATCH 05/10] clang-tidy: Fix `modernize-use-equals-default` check See https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-equals-default.html --- .clang-tidy | 1 - include/mp/util.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 88988677..ea7d4db5 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -15,7 +15,6 @@ modernize-*, -modernize-avoid-c-arrays, -modernize-concat-nested-namespaces, -modernize-deprecated-headers, --modernize-use-equals-default, -modernize-use-nodiscard, -modernize-use-nullptr, -modernize-use-trailing-return-type, diff --git a/include/mp/util.h b/include/mp/util.h index ccbea6c9..9ccd3fac 100644 --- a/include/mp/util.h +++ b/include/mp/util.h @@ -337,7 +337,7 @@ struct AsyncCallable } AsyncCallable(const AsyncCallable&) = default; AsyncCallable(AsyncCallable&&) = default; - ~AsyncCallable() noexcept {} + ~AsyncCallable() noexcept = default; ResultOf operator()() const { return (m_callable->value)(); } mutable std::shared_ptr> m_callable; }; From ae416f903f4fe887c8bed5cd89bcc325c8015e93 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sun, 12 Feb 2023 12:27:47 +0000 Subject: [PATCH 06/10] clang-tidy: Fix `modernize-use-nullptr` check See https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-nullptr.html --- .clang-tidy | 1 - include/mp/proxy-types.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index ea7d4db5..b21052bf 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -16,7 +16,6 @@ modernize-*, -modernize-concat-nested-namespaces, -modernize-deprecated-headers, -modernize-use-nodiscard, --modernize-use-nullptr, -modernize-use-trailing-return-type, -modernize-use-using, performance-*, diff --git a/include/mp/proxy-types.h b/include/mp/proxy-types.h index 902bd240..9f4b0345 100644 --- a/include/mp/proxy-types.h +++ b/include/mp/proxy-types.h @@ -461,7 +461,7 @@ decltype(auto) CustomReadField(TypeList, InvokeContext& invoke_context, Input&& input, ReadDest&& read_dest, - typename std::enable_if::value>::type* enable = 0) + typename std::enable_if::value>::type* enable = nullptr) { auto value = input.get(); if (value < std::numeric_limits::min() || value > std::numeric_limits::max()) { From a435b24e64478d26601639861d789adb5e25405d Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Thu, 26 Jan 2023 21:37:03 +0000 Subject: [PATCH 07/10] clang-tidy: Fix `performance-faster-string-find` check See https://clang.llvm.org/extra/clang-tidy/checks/performance/faster-string-find.html --- .clang-tidy | 1 - src/mp/gen.cpp | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index b21052bf..6f07f37c 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -19,7 +19,6 @@ modernize-*, -modernize-use-trailing-return-type, -modernize-use-using, performance-*, --performance-faster-string-find, -performance-inefficient-vector-operation, -performance-noexcept-move-constructor, -performance-unnecessary-value-param, diff --git a/src/mp/gen.cpp b/src/mp/gen.cpp index 69f4a967..d59f02eb 100644 --- a/src/mp/gen.cpp +++ b/src/mp/gen.cpp @@ -149,7 +149,7 @@ void Generate(kj::StringPtr src_prefix, } std::string include_base = include_path; - std::string::size_type p = include_base.rfind("."); + std::string::size_type p = include_base.rfind('.'); if (p != std::string::npos) include_base.erase(p); std::vector args; @@ -238,7 +238,7 @@ void Generate(kj::StringPtr src_prefix, GetAnnotationText(file_schema.getProto(), NAMESPACE_ANNOTATION_ID, &message_namespace); std::string base_name = include_base; - size_t output_slash = base_name.rfind("/"); + size_t output_slash = base_name.rfind('/'); if (output_slash != std::string::npos) { base_name.erase(0, output_slash + 1); } From 463bead1f30e52850dbfb05d489e5507d59018c2 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Thu, 26 Jan 2023 21:37:15 +0000 Subject: [PATCH 08/10] clang-tidy: Fix `performance-inefficient-vector-operation` check See https://clang.llvm.org/extra/clang-tidy/checks/performance/inefficient-vector-operation.html --- .clang-tidy | 1 - src/mp/util.cpp | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-tidy b/.clang-tidy index 6f07f37c..5512a3d1 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -19,7 +19,6 @@ modernize-*, -modernize-use-trailing-return-type, -modernize-use-using, performance-*, --performance-inefficient-vector-operation, -performance-noexcept-move-constructor, -performance-unnecessary-value-param, readability-*, diff --git a/src/mp/util.cpp b/src/mp/util.cpp index 72043a03..408bbf8a 100644 --- a/src/mp/util.cpp +++ b/src/mp/util.cpp @@ -128,6 +128,7 @@ int SpawnProcess(int& pid, FdToArgsFn&& fd_to_args) void ExecProcess(const std::vector& args) { std::vector argv; + argv.reserve(args.size()); for (const auto& arg : args) { argv.push_back(const_cast(arg.c_str())); } From 037fec47c8ed9bd819cc989ef9500adbf9018c67 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sun, 12 Feb 2023 12:19:15 +0000 Subject: [PATCH 09/10] clang-tidy: Fix `performance-unnecessary-value-param` check See https://clang.llvm.org/extra/clang-tidy/checks/performance/unnecessary-value-param.html --- .clang-tidy | 1 - include/mp/proxy-io.h | 2 +- test/mp/test/foo.h | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 5512a3d1..923b42cb 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -20,7 +20,6 @@ modernize-*, -modernize-use-using, performance-*, -performance-noexcept-move-constructor, --performance-unnecessary-value-param, readability-*, -readability-braces-around-statements, -readability-convert-member-functions-to-static, diff --git a/include/mp/proxy-io.h b/include/mp/proxy-io.h index 76a64e74..1f3b4ccb 100644 --- a/include/mp/proxy-io.h +++ b/include/mp/proxy-io.h @@ -276,7 +276,7 @@ class Connection } Connection(EventLoop& loop, kj::Own&& stream_, - std::function<::capnp::Capability::Client(Connection&)> make_client) + const std::function<::capnp::Capability::Client(Connection&)>& make_client) : m_loop(loop), m_stream(kj::mv(stream_)), m_network(*m_stream, ::capnp::rpc::twoparty::Side::SERVER, ::capnp::ReaderOptions()), m_rpc_system(::capnp::makeRpcServer(m_network, make_client(*this))) diff --git a/test/mp/test/foo.h b/test/mp/test/foo.h index 769e9eee..b9f881d1 100644 --- a/test/mp/test/foo.h +++ b/test/mp/test/foo.h @@ -48,7 +48,7 @@ class FooImplementation void initThreadMap() {} int callback(FooCallback& callback, int arg) { return callback.call(arg); } int callbackUnique(std::unique_ptr callback, int arg) { return callback->call(arg); } - int callbackShared(std::shared_ptr callback, int arg) { return callback->call(arg); } + int callbackShared(std::shared_ptr callback, int arg) { return callback->call(arg); } // NOLINT(performance-unnecessary-value-param) void saveCallback(std::shared_ptr callback) { m_callback = std::move(callback); } int callbackSaved(int arg) { return m_callback->call(arg); } int callbackExtended(ExtendedCallback& callback, int arg) { return callback.callExtended(arg); } From 594466ae975a8370bfed8f6de05bbcf92289dd8f Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Thu, 26 Jan 2023 21:37:52 +0000 Subject: [PATCH 10/10] clang-tidy: Fix `readability-make-member-function-const` check See https://clang.llvm.org/extra/clang-tidy/checks/readability/make-member-function-const.html --- .clang-tidy | 1 - src/mp/gen.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 923b42cb..3ab59c7b 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -29,7 +29,6 @@ readability-*, -readability-implicit-bool-conversion, -readability-inconsistent-declaration-parameter-name, -readability-magic-numbers, --readability-make-member-function-const, -readability-named-parameter, -readability-uppercase-literal-suffix, -readability-use-anyofallof, diff --git a/src/mp/gen.cpp b/src/mp/gen.cpp index d59f02eb..a027ab33 100644 --- a/src/mp/gen.cpp +++ b/src/mp/gen.cpp @@ -92,7 +92,7 @@ struct Format m_os << value; return *this; } - operator std::string() { return m_os.str(); } + operator std::string() const { return m_os.str(); } std::ostringstream m_os; };