This PR:
- introduces the
-DLibmultiprocess_ENABLE_CLANG_TIDYconfiguration option, which allows to "run clang-tidy with the compiler" - fixes some
clang-tidy's warnings, which are easy-to-review and useful on their own
This PR:
-DLibmultiprocess_ENABLE_CLANG_TIDY configuration option, which allows to "run clang-tidy with the compiler"clang-tidy's warnings, which are easy-to-review and useful on their ownI got one warning during make, same as on master, building on Ubuntu 22.10 with clang 15.0.6:
[ 75%] Built target multiprocess
[ 87%] Building CXX object CMakeFiles/mpgen.dir/src/mp/gen.cpp.o
/home/sjors/dev/libmultiprocess/src/mp/gen.cpp: In function ‘void Generate(kj::StringPtr, kj::StringPtr, kj::StringPtr, kj::ArrayPtr<const kj::StringPtr>)’:
/home/sjors/dev/libmultiprocess/src/mp/gen.cpp:179:44: warning: ‘capnp::ParsedSchema capnp::SchemaParser::parseDiskFile(kj::StringPtr, kj::StringPtr, kj::ArrayPtr<const kj::StringPtr>) const’ is deprecated [-Wdeprecated-declarations]
179 | auto file_schema = parser.parseDiskFile(src_file, src_file, import_paths);
| ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/sjors/dev/libmultiprocess/src/mp/gen.cpp:9:
/usr/include/capnp/schema-parser.h:101:16: note: declared here
101 | ParsedSchema parseDiskFile(kj::StringPtr displayName, kj::StringPtr diskPath,
| ^~~~~~~~~~~~~
[100%] Linking CXX executable mpgen
[100%] Built target mpgen
make check fails entirely though, while on master it works fine.
[ 73%] Building CXX object test/CMakeFiles/mptest.dir/mp/test/foo.capnp.proxy-server.c++.o
In file included from /home/sjors/dev/libmultiprocess/include/mp/proxy.h:8,
from /home/sjors/dev/libmultiprocess/build/test/mp/test/foo.capnp.proxy.h:8,
from /home/sjors/dev/libmultiprocess/build/test/mp/test/foo.capnp.proxy-types.h:6,
from /home/sjors/dev/libmultiprocess/build/test/mp/test/foo.capnp.proxy-server.c++:3:
/home/sjors/dev/libmultiprocess/include/mp/util.h: In instantiation of ‘mp::AsyncCallable<typename std::remove_reference<_T
…
/home/sjors/dev/libmultiprocess/build/test/mp/test/foo.capnp.proxy-server.c++:23:24: required from here
/home/sjors/dev/libmultiprocess/include/mp/util.h:349:24: error: no matching function for call to ‘forward(kj::CaptureByMove<kj::CaptureByMove<mp::PassField<Accessor<foo_fields::Context, 17>,
…
ooInterface::CallbackResults> > > >&)’
349 | return std::forward(callable);
| ~~~~~~~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/12/bits/stl_pair.h:61,
from /usr/include/c++/12/bits/stl_algobase.h:64,
from /usr/include/c++/12/bits/stl_tree.h:63,
from /usr/include/c++/12/map:60,
from /home/sjors/dev/libmultiprocess/test/mp/test/foo.h:8,
from /home/sjors/dev/libmultiprocess/build/test/mp/test/foo.capnp.proxy.h:7:
/usr/include/c++/12/bits/move.h:77:5: note: candidate: ‘template<class _Tp> constexpr _Tp&& std::forward(typename remove_reference<_Tp>::type&)’
77 | forward(typename std::remove_reference<_Tp>::type& __t) noexcept
make check works with ceb3a4b8a0d5d04d7a8573a3dca4f71b4a8b04da
re: https://github.com/chaincodelabs/libmultiprocess/pull/83#issuecomment-1426695225
Note: warning about deprecated parseDiskFile call is reported as a standalone issue in #39
7 | @@ -8,6 +8,15 @@ project("Libmultiprocess" CXX) 8 | set(CMAKE_CXX_STANDARD 17) 9 | set(CMAKE_CXX_STANDARD_REQUIRED YES) 10 | 11 | +option(MULTIPROCESS_RUN_CLANG_TIDY "Run clang-tidy with the compiler." OFF)
In commit "Add option to run clang-tidy with compiler" (f3b2bfcbe7ecca087d75e96df1496687f8ff4c0a)
Would it make sense to call the option ENABLE_CLANG_TIDY instead of MULTIPROCESS_RUN_CLANG_TIDY? I don't see a reason to prefix option names with the project name, and the other options don't do this
The goal of prefixing is to minimize risk of option name clash when this library is a subproject of another project. For example, https://github.com/bitcoin-core/secp256k1/pull/1113.
Ok, I didn't think about this being used as a subdirectory inside another project. Could we then prefix project options with the project name like Libmultiprocess_ENABLE_CLANG_TIDY. I do also prefer ENABLE to RUN for the cmake option name, because at the CMakeLists.txt level, this isn't adding more build steps, just setting another option.
Confirmed ceb3a4b8a0d5d04d7a8573a3dca4f71b4a8b04da is working and runs clang but I didn't review the individual commits yet.
I also noticed one new warning is shown now (using clang-tidy 14.0.6)
include/mp/proxy-types.h:162:85: warning: the parameter 'perhaps' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
.then([&server, invoke, req](kj::Maybe<Thread::Server&> perhaps) {
^
const &
47 | @@ -48,7 +48,7 @@ class FooImplementation 48 | void initThreadMap() {} 49 | int callback(FooCallback& callback, int arg) { return callback.call(arg); } 50 | int callbackUnique(std::unique_ptr<FooCallback> callback, int arg) { return callback->call(arg); } 51 | - int callbackShared(std::shared_ptr<FooCallback> callback, int arg) { return callback->call(arg); } 52 | + int callbackShared(std::shared_ptr<FooCallback> callback, int arg) { return callback->call(arg); } // NOLINT(performance-unnecessary-value-param)
In commit "clang-tidy: Fix performance-unnecessary-value-param check" (0498ed86bc6d1a6bdbabf98f2e39468dc5c90823)
Note: I think it does make sense to suppress this lint warning than try to avoid it. Could potentially avoid it by changing this argument to const shared_ptr but there's currently no IPC serialization code to handle const shared_ptr only shared_ptr, so it does't compile. Also I don't think it would make sense to add const shared_ptr serialization code because most cases where you would pass const shared<ptr> it probably makes more sense to pass a plain const reference.
re: https://github.com/chaincodelabs/libmultiprocess/pull/83#pullrequestreview-1298380154
I also noticed one new warning is shown now (using clang-tidy 14.0.6)
Following change fixes the warning (EDIT: merged this change already in https://github.com/chaincodelabs/libmultiprocess/pull/84)
--- a/include/mp/proxy-types.h
+++ b/include/mp/proxy-types.h
@@ -159,7 +159,7 @@ auto PassField(Priority<1>, TypeList<>, ServerContext& server_context, const Fn&
auto thread_client = context_arg.getThread();
return JoinPromises(server.m_context.connection->m_threads.getLocalServer(thread_client)
- .then([&server, invoke, req](kj::Maybe<Thread::Server&> perhaps) {
+ .then([&server, invoke, req](const kj::Maybe<Thread::Server&>& perhaps) {
KJ_IF_MAYBE(thread_server, perhaps)
{
const auto& thread = static_cast<ProxyServer<Thread>&>(*thread_server);
Code review ACK ceb3a4b8a0d5d04d7a8573a3dca4f71b4a8b04da, but I think I'd like to rename the cmake option as described https://github.com/chaincodelabs/libmultiprocess/pull/83#discussion_r1106345466. I noticed some other clang-tidy errors still occurred for me with clang-tidy 14.0.6 after this PR, so I separately merged fixes for these in https://github.com/chaincodelabs/libmultiprocess/pull/84
See https://clang.llvm.org/extra/clang-tidy/checks/bugprone/suspicious-semicolon.html
See https://clang.llvm.org/extra/clang-tidy/checks/modernize/return-braced-init-list.html
See https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-emplace.html
See https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-equals-default.html
See https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-nullptr.html
See https://clang.llvm.org/extra/clang-tidy/checks/performance/faster-string-find.html
See https://clang.llvm.org/extra/clang-tidy/checks/performance/inefficient-vector-operation.html
See https://clang.llvm.org/extra/clang-tidy/checks/performance/unnecessary-value-param.html
See https://clang.llvm.org/extra/clang-tidy/checks/readability/make-member-function-const.html
Code review ACK 594466ae975a8370bfed8f6de05bbcf92289dd8f. Changes since last review were changing option name, and updating HeaderFilterRegex, and rebasing
Merged now. Thank you for these nice changes and features!