From a6920380144a96bf0b127c0ae2d49c86deb826b1 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 31 Jan 2025 23:31:44 +0000 Subject: [PATCH 01/14] cmake: Skip linting for generated sources --- CMakeLists.txt | 1 + cmake/TargetCapnpSources.cmake | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a01d08c..61e1be6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,7 @@ configure_file(include/mp/config.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/mp/co # Generated C++ Capn'Proto schema files capnp_generate_cpp(MP_PROXY_SRCS MP_PROXY_HDRS include/mp/proxy.capnp) +set_source_files_properties(${MP_PROXY_SRCS} PROPERTIES SKIP_LINTING ON) # util library add_library(mputil OBJECT src/mp/util.cpp) diff --git a/cmake/TargetCapnpSources.cmake b/cmake/TargetCapnpSources.cmake index cdc86c6..f614bb1 100644 --- a/cmake/TargetCapnpSources.cmake +++ b/cmake/TargetCapnpSources.cmake @@ -66,18 +66,20 @@ function(target_capnp_sources target include_prefix) set(generated_headers "") foreach(capnp_file IN LISTS TCS_UNPARSED_ARGUMENTS) - add_custom_command( - OUTPUT ${capnp_file}.c++ ${capnp_file}.h ${capnp_file}.proxy-client.c++ ${capnp_file}.proxy-types.h ${capnp_file}.proxy-server.c++ ${capnp_file}.proxy-types.c++ ${capnp_file}.proxy.h - COMMAND Libmultiprocess::mpgen ${CMAKE_CURRENT_SOURCE_DIR} ${include_prefix} ${CMAKE_CURRENT_SOURCE_DIR}/${capnp_file} ${TCS_IMPORT_PATHS} ${MP_INCLUDE_DIR} - DEPENDS ${capnp_file} - VERBATIM - ) - target_sources(${target} PRIVATE + set(generated_sources ${CMAKE_CURRENT_BINARY_DIR}/${capnp_file}.c++ ${CMAKE_CURRENT_BINARY_DIR}/${capnp_file}.proxy-client.c++ ${CMAKE_CURRENT_BINARY_DIR}/${capnp_file}.proxy-server.c++ ${CMAKE_CURRENT_BINARY_DIR}/${capnp_file}.proxy-types.c++ ) + add_custom_command( + OUTPUT ${generated_sources} ${capnp_file}.h ${capnp_file}.proxy-types.h ${capnp_file}.proxy.h + COMMAND Libmultiprocess::mpgen ${CMAKE_CURRENT_SOURCE_DIR} ${include_prefix} ${CMAKE_CURRENT_SOURCE_DIR}/${capnp_file} ${TCS_IMPORT_PATHS} ${MP_INCLUDE_DIR} + DEPENDS ${capnp_file} + VERBATIM + ) + target_sources(${target} PRIVATE ${generated_sources}) + set_source_files_properties(${generated_sources} PROPERTIES SKIP_LINTING ON) list(APPEND generated_headers ${capnp_file}.h) endforeach() From 3c07ab89afd23a649b6af9aa38f03bc64261aea1 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 31 Jan 2025 23:31:55 +0000 Subject: [PATCH 02/14] clang-tidy: Disable `misc-use-anonymous-namespace` check The benefit of this check is questionable, so it has been disabled. See: https://clang.llvm.org/extra/clang-tidy/checks/misc/use-anonymous-namespace.html --- .clang-tidy | 1 + 1 file changed, 1 insertion(+) diff --git a/.clang-tidy b/.clang-tidy index 3ab59c7..5699a6f 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -11,6 +11,7 @@ misc-*, -misc-no-recursion, -misc-unconventional-assign-operator, -misc-unused-parameters, +-misc-use-anonymous-namespace, modernize-*, -modernize-avoid-c-arrays, -modernize-concat-nested-namespaces, From d6523b60a01d806b13d6e8e0bc117595282e6baa Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 31 Jan 2025 23:32:04 +0000 Subject: [PATCH 03/14] clang-tidy: Disable `performance-avoid-endl` check See: https://clang.llvm.org/extra/clang-tidy/checks/performance/avoid-endl.html --- .clang-tidy | 1 + 1 file changed, 1 insertion(+) diff --git a/.clang-tidy b/.clang-tidy index 5699a6f..2d29f12 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -20,6 +20,7 @@ modernize-*, -modernize-use-trailing-return-type, -modernize-use-using, performance-*, +-performance-avoid-endl, -performance-noexcept-move-constructor, readability-*, -readability-braces-around-statements, From 1cc0bf573fdd23ce190b58c20e88bc21f943e3bb Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 31 Jan 2025 23:32:18 +0000 Subject: [PATCH 04/14] clang-tidy: Fix `bugprone-crtp-constructor-accessibility` check See: https://clang.llvm.org/extra/clang-tidy/checks/bugprone/empty-catch.html --- include/mp/proxy-types.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/mp/proxy-types.h b/include/mp/proxy-types.h index 6c1b1aa..40cce32 100644 --- a/include/mp/proxy-types.h +++ b/include/mp/proxy-types.h @@ -314,6 +314,9 @@ struct IterateFieldsHelper { static_cast(this)->handleField(std::forward(arg1), std::forward(arg2), ParamList()); } +private: + IterateFieldsHelper() = default; + friend Derived; }; struct IterateFields : IterateFieldsHelper From 5a15744d4af1f53ca69dde37c78491499aa60307 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 31 Jan 2025 23:32:31 +0000 Subject: [PATCH 05/14] clang-tidy: Suppress `bugprone-empty-catch` check warning See: https://clang.llvm.org/extra/clang-tidy/checks/bugprone/empty-catch.html --- include/mp/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mp/util.h b/include/mp/util.h index 032fc0f..3966e28 100644 --- a/include/mp/util.h +++ b/include/mp/util.h @@ -157,7 +157,7 @@ struct DestructorCatcher { } ~DestructorCatcher() noexcept try { - } catch (const kj::Exception& e) { + } catch (const kj::Exception& e) { // NOLINT(bugprone-empty-catch) } }; From f983b09a31d156c5b9e72523a2c3e27260af9b90 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 31 Jan 2025 23:32:56 +0000 Subject: [PATCH 06/14] clang-tidy: Fix `modernize-type-traits` check See: https://clang.llvm.org/extra/clang-tidy/checks/modernize/type-traits.html --- include/mp/proxy-types.h | 30 +++++++++++++++--------------- include/mp/proxy.h | 2 +- include/mp/util.h | 8 ++++---- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/include/mp/proxy-types.h b/include/mp/proxy-types.h index 40cce32..384ecaa 100644 --- a/include/mp/proxy-types.h +++ b/include/mp/proxy-types.h @@ -39,17 +39,17 @@ struct StructField // clang-format off template auto get() const -> decltype(A::get(this->m_struct)) { return A::get(this->m_struct); } - template auto has() const -> typename std::enable_if::type { return A::getHas(m_struct); } - template auto has() const -> typename std::enable_if::type { return A::has(m_struct); } - template auto has() const -> typename std::enable_if::type { return true; } - template auto want() const -> typename std::enable_if::type { return A::getWant(m_struct); } - template auto want() const -> typename std::enable_if::type { return true; } + template auto has() const -> std::enable_if_t { return A::getHas(m_struct); } + template auto has() const -> std::enable_if_t { return A::has(m_struct); } + template auto has() const -> std::enable_if_t { return true; } + template auto want() const -> std::enable_if_t { return A::getWant(m_struct); } + template auto want() const -> std::enable_if_t { return true; } template decltype(auto) set(Args&&... args) const { return A::set(this->m_struct, std::forward(args)...); } template decltype(auto) init(Args&&... args) const { return A::init(this->m_struct, std::forward(args)...); } - template auto setHas() const -> typename std::enable_if::type { return A::setHas(m_struct); } - template auto setHas() const -> typename std::enable_if::type { } - template auto setWant() const -> typename std::enable_if::type { return A::setWant(m_struct); } - template auto setWant() const -> typename std::enable_if::type { } + template auto setHas() const -> std::enable_if_t { return A::setHas(m_struct); } + template auto setHas() const -> std::enable_if_t { } + template auto setWant() const -> std::enable_if_t { return A::setWant(m_struct); } + template auto setWant() const -> std::enable_if_t { } // clang-format on }; @@ -375,14 +375,14 @@ struct ClientParam // position when unpacking tuple might be slower than pattern matching // approach in the stack overflow solution template - auto callBuild(Args&&... args) -> typename std::enable_if<(I < sizeof...(Types))>::type + auto callBuild(Args&&... args) -> std::enable_if_t<(I < sizeof...(Types))> { callBuild(std::forward(args)..., std::get(m_client_param->m_values)); } template auto callBuild(ClientInvokeContext& invoke_context, Params& params, ParamList, Values&&... values) -> - typename std::enable_if<(I == sizeof...(Types))>::type + std::enable_if_t<(I == sizeof...(Types))> { MaybeBuildField(std::integral_constant(), ParamList(), invoke_context, Make(params), std::forward(values)...); @@ -403,14 +403,14 @@ struct ClientParam } template - auto callRead(Args&&... args) -> typename std::enable_if<(I < sizeof...(Types))>::type + auto callRead(Args&&... args) -> std::enable_if_t<(I < sizeof...(Types))> { callRead(std::forward(args)..., std::get(m_client_param->m_values)); } template auto callRead(ClientInvokeContext& invoke_context, Results& results, TypeList, Values&&... values) - -> typename std::enable_if::type + -> std::enable_if_t { MaybeReadField(std::integral_constant(), TypeList...>(), invoke_context, Make(results), ReadDestUpdate(values)...); @@ -651,7 +651,7 @@ void clientInvoke(ProxyClient& proxy_client, const GetRequest& get_request, Fiel //! duplication and branching in generic code that forwards calls to functions. template auto ReplaceVoid(Fn&& fn, Ret&& ret) -> - typename std::enable_if::value, decltype(ret())>::type + std::enable_if_t, decltype(ret())> { fn(); return ret(); @@ -660,7 +660,7 @@ auto ReplaceVoid(Fn&& fn, Ret&& ret) -> //! Overload of above for non-void `fn()` case. template auto ReplaceVoid(Fn&& fn, Ret&& ret) -> - typename std::enable_if::value, decltype(fn())>::type + std::enable_if_t, decltype(fn())> { return fn(); } diff --git a/include/mp/proxy.h b/include/mp/proxy.h index 92c0fa5..76be099 100644 --- a/include/mp/proxy.h +++ b/include/mp/proxy.h @@ -198,7 +198,7 @@ struct FunctionTraits<_Result (_Class::*const)(_Params...)> template using Param = typename std::tuple_element>::type; using Fields = - typename std::conditional::value, Params, TypeList<_Params..., _Result>>::type; + std::conditional_t, Params, TypeList<_Params..., _Result>>; }; //! Traits class for a proxy method, providing the same diff --git a/include/mp/util.h b/include/mp/util.h index 3966e28..6ed631e 100644 --- a/include/mp/util.h +++ b/include/mp/util.h @@ -43,9 +43,9 @@ struct TypeList //! Example: //! Make(5, true) // Constructs std::pair(5, true); template