-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Don't make "in" parameters look like "out"/"in-out" parameters: pass by ref to const instead of ref to non-const #20581
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
Conversation
…by ref to const instead of ref to non-const
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
cr ACK 12dcdaa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 12dcdaa, I have reviewed the code and it looks OK, I agree it can be merged.
All findings are made by a cool static analyzer, aren't they?
Yes, To reproduce:
|
Code review ACK 12dcdaa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
…ions as const 31b136e Don't declare de facto const reference variables as non-const (practicalswift) 1c65c07 Don't declare de facto const member functions as non-const (practicalswift) Pull request description: _Meta: This is the second and final part of the `const` refactoring series (part one: #20581). **I promise: no more refactoring PRs from me in a while! :)** I'll now go back to focusing on fuzzing/hardening!_ Changes in this PR: * Don't declare de facto const member functions as non-const * Don't declare de facto const reference variables as non-const Awards for finding candidates for the above changes go to: * `clang-tidy`'s [`readability-make-member-function-const`](https://clang.llvm.org/extra/clang-tidy/checks/readability-make-member-function-const.html) check ([list of `clang-tidy` checks](https://clang.llvm.org/extra/clang-tidy/checks/list.html)) * `cppcheck`'s `constVariable` check ([list of `cppcheck` checks](https://sourceforge.net/p/cppcheck/wiki/ListOfChecks/)) See #18920 for instructions on how to analyse Bitcoin Core using Clang Static Analysis, `clang-tidy` and `cppcheck`. ACKs for top commit: ajtowns: ACK 31b136e jonatack: ACK 31b136e theStack: ACK 31b136e ❄️ Tree-SHA512: f58f8f00744219426874379e9f3e9331132b9b48e954d24f3a85cbb858fdcc98009ed42ef7e7b4619ae8af9fc240a6d8bfc1c438db2e97b0ecd722a80dcfeffe
@@ -505,13 +505,13 @@ class MemPoolAccept | |||
|
|||
// Run the script checks using our policy flags. As this can be slow, we should | |||
// only invoke this on transactions that have otherwise passed policy checks. | |||
bool PolicyScriptChecks(ATMPArgs& args, Workspace& ws, PrecomputedTransactionData& txdata) EXCLUSIVE_LOCKS_REQUIRED(cs_main); | |||
bool PolicyScriptChecks(ATMPArgs& args, const Workspace& ws, PrecomputedTransactionData& txdata) EXCLUSIVE_LOCKS_REQUIRED(cs_main); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Er, would it be alright if I changed the Workspace
here back to non-const? I'd interpret Workspace as an "in-out" parameter used throughout MemPoolAccept::AcceptSingleTransaction
. As I understand it, this PR makes it const
for 2 of the intermediate steps based on some code analysis, but I think it might just be coincidentally unmodified inside those functions 😅 I'd like to be able to update the workspace inside PolicyScriptChecks
/ConsensusScriptChecks
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, just remove the const
again. While the changes here are correct (as in adding a const
will still compile), they probably don't make sense conceptually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@glozow Absolutely! What is const
is not necessarily const over time :)
The C++ const correctness FAQ (isocpp.org) is great reading on the topic!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coolio, thanks 🤗
…by ref to const instead of ref to non-const Summary: This is a backport of [[bitcoin/bitcoin#20581 | core#20581]] Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D11094
…ut" parameters: pass by ref to const instead of ref to non-const
…ut" parameters: pass by ref to const instead of ref to non-const
Don't make "in" parameters look like "out"/"in-out" parameters: pass by ref to const instead of ref to non-const.