-
Notifications
You must be signed in to change notification settings - Fork 27
refactor: fix warnings from clang-tidy-20 and bitcoin-tidy #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Concept ACK. |
Reported by Sjors Provoost <[email protected]> bitcoin/bitcoin#31802 (comment) /ci_container_base/include/mp/proxy-io.h:252:16: error: forwarding reference passed to std::move(), which may unexpectedly cause lvalues to be moved; use std::forward() instead [bugprone-move-forwarding-reference,-warnings-as-errors] /ci_container_base/include/mp/proxy-io.h:336:18: error: forwarding reference passed to std::move(), which may unexpectedly cause lvalues to be moved; use std::forward() instead [bugprone-move-forwarding-reference,-warnings-as-errors] /ci_container_base/include/mp/util.h:186:12: error: forwarding reference passed to std::move(), which may unexpectedly cause lvalues to be moved; use std::forward() instead [bugprone-move-forwarding-reference,-warnings-as-errors] https://cirrus-ci.com/task/6187773452877824?logs=ci#L4712
/ci_container_base/include/mp/type-interface.h:47:75: error: forwarding reference passed to std::move(), which may unexpectedly cause lvalues to be moved; use std::forward() instead [bugprone-move-forwarding-reference,-warnings-as-errors] https://cirrus-ci.com/task/6187773452877824?logs=ci#L4712 Error was caused by mp/type-interface.h CustomBuildField field using std::move instead of std::forward. This commit: - Adds std::forward and std::move several places to preserve lvalue/rvalue status. - Defines a FunctionTraits::Fwd<...>(...) helper which does same thing as std::forward except it takes parameter number instead of a parameter type so generated code doesn't need as verbose as std::forward calls would be. - Changes C++ code generator to pass arguments as `M0::Fwd<1>(arg1)` instead of `arg1` in generated code. This change can be verified by diffing a generated file like build/src/ipc/capnp/mining.capnp.proxy-client.c++ in the bitcoin build before and after this change. Unlike the previous commit which resolved bugprone-move-forwarding-reference errors by just switching std::move to std::forward, this commit required more changes because just switching from std::move to std::forward in the type-interface.h CustomBuildField function would lead to another error in the CustomMakeProxyServer function there which is expecting an rvalue, not an lvalue. That error could have alternately been fixed by changing CustomMakeProxyServer to accept lvalues and copy the shared_ptr. But this would be slightly less efficient and it is better to resolve the problem at the root and just use perfect forwarding everywhere, all the way up the call stack. This required the changes to the code generator and clientInvoke described above.
/ci_container_base/include/mp/proxy-io.h:637:1: error: Variable with non-trivial destructor cannot be thread_local. [bitcoin-nontrivial-threadlocal,-warnings-as-errors] https://cirrus-ci.com/task/6187773452877824?logs=ci#L4720
I added the latest version of this to bitcoin/bitcoin#31802, the tidy job is still happy. Some background for the first two commits: https://clang.llvm.org/extra/clang-tidy/checks/bugprone/move-forwarding-reference.html With that in mind the first commit seems fine, the second one e922bb8 is a bit over my head due to the changes in I don't have an informed opinion on the last commit a5bff37 that suppresses |
Thanks @Sjors. Now that this git repo is a subtree and a bitcoin-core project, I would like to (1) stop my previous practice of merging PRs like this that do not have any ACKs and (2) try to encourage more review to happen earlier in the upstream PR's in this repository rather than later in the downstream PRs in the bitcoin repository. So would you feel comfortable reviewing more and maybe giving an ACK along the lines of...
... or however you might actually review it? I am happy to answer any questions that could help clarify things. The second commit should be the only complicated one here, and I can break it down. It is:
Maybe I should add some of these explanations in code comments or commit messages too. Would welcome any feedback. |
This might help more people understand the code. |
ACK 57a65b8 I studied the second commit more, along with some of I wrote:
The original |
Warnings are described in commit messages and were reported by Sjors in bitcoin/bitcoin#31802 (comment)