refactor: make member functions const when applicable #25673

pull aureleoules wants to merge 2 commits into bitcoin:master from aureleoules:2022-07-refactor changing 32 files +72 −70
  1. aureleoules commented at 10:38 AM on July 22, 2022: member

    I have added a clang-tidy check: 'readability-make-member-function-const'.

    Finds non-static member functions that can be made const because the functions don’t use this in a non-const way.

    I believe this makes the code more maintainable.

    I used clang-tidy with --fix-errors and the check readability-make-member-function-const to generate the refactor commit.

  2. fanquake added the label Refactoring on Jul 22, 2022
  3. jonatack commented at 11:00 AM on July 22, 2022: contributor

    Codebase-wide changes like this tend to be a difficult sell. Some initial thoughts.

    Pro:

    Caveat:

    • Const member functions need to be thread safe

    Related:

  4. maflcko commented at 11:05 AM on July 22, 2022: member

    std::move will cast even mutable references, which makes hard-to-find bugs and is thus generally not wanted if the reference was passed to a function. So I don't think replacing forward with move is correct, unless you can provide a reason for the change.

  5. aureleoules force-pushed on Jul 22, 2022
  6. aureleoules commented at 11:56 AM on July 22, 2022: member

    std::move will cast even mutable references, which makes hard-to-find bugs and is thus generally not wanted if the reference was passed to a function. So I don't think replacing forward with move is correct, unless you can provide a reason for the change.

    my mistake, I've dropped the commit

  7. maflcko commented at 11:58 AM on July 22, 2022: member
  8. DrahtBot commented at 1:18 AM on July 23, 2022: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #25722 (refactor: Use util::Result class for wallet loading by ryanofsky)
    • #24313 (Improve display address handling for external signer by Sjors)
    • #22838 (descriptors: Be able to specify change and receiving in a single descriptor string by achow101)

    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.

  9. DrahtBot cross-referenced this on Jul 23, 2022 from issue Severity-based logging, step 2 by jonatack
  10. DrahtBot cross-referenced this on Jul 23, 2022 from issue Severity-based logging -- parent PR by jonatack
  11. DrahtBot cross-referenced this on Jul 23, 2022 from issue test: Cleanup miner_tests by maflcko
  12. DrahtBot cross-referenced this on Jul 23, 2022 from issue Add config option to set max debug log size by tehelsper
  13. DrahtBot cross-referenced this on Jul 23, 2022 from issue refactor address relay time by maflcko
  14. DrahtBot cross-referenced this on Jul 23, 2022 from issue p2p: Prevent block index fingerprinting by sending additional getheaders messages by dergoegge
  15. in src/leveldb/util/env_posix.cc:338 in fe9f78aa21 outdated
     334 | @@ -335,7 +335,7 @@ class PosixWritableFile final : public WritableFile {
     335 |      return status;
     336 |    }
     337 |  
     338 | -  Status WriteUnbuffered(const char* data, size_t size) {
     339 | +  Status WriteUnbuffered(const char* data, size_t size) const {
    


    jonatack commented at 9:47 AM on July 23, 2022:

    You are touching files in https://github.com/bitcoin-core/leveldb-subtree; changes to it need to be made there or upstream and not in bitcoin/bitcoin. See the CI linter failure: "FAIL: subtree directory was touched without subtree merge" (test/lint/git-subtree-check.sh)


    aureleoules commented at 4:34 PM on July 24, 2022:

    Thanks, I was wondering what this meant. I removed these changes.

  16. aureleoules force-pushed on Jul 24, 2022
  17. DrahtBot cross-referenced this on Jul 24, 2022 from issue mempool, refactor: add `MemPoolBypass` by w0xlt
  18. DrahtBot added the label Needs rebase on Jul 27, 2022
  19. DrahtBot cross-referenced this on Jul 27, 2022 from issue indexes: Stop using node internal types and locking cs_main, improve sync logic by ryanofsky
  20. fanquake commented at 12:36 PM on July 27, 2022: member

    I assume this is being done with some automated tooling? If so, could you expand the PR description to describe what you are doing to produce the change?

    Similar to #25707, if you want to make a change like this, we'd likely also want this enforced/linted in some way. Are there any checks you can use in https://releases.llvm.org/14.0.0/tools/clang/tools/extra/docs/clang-tidy/checks/list.html?

  21. jonatack commented at 12:39 PM on July 27, 2022: contributor

    Can tooling ensure these member functions marked as const are all thread-safe?

  22. aureleoules force-pushed on Jul 27, 2022
  23. aureleoules force-pushed on Jul 27, 2022
  24. aureleoules force-pushed on Jul 27, 2022
  25. DrahtBot removed the label Needs rebase on Jul 27, 2022
  26. DrahtBot cross-referenced this on Jul 27, 2022 from issue refactor: Use util::Result class for wallet loading by ryanofsky
  27. DrahtBot cross-referenced this on Jul 27, 2022 from issue refactor: Make const references to avoid unnecessarily copying objects and enable two clang-tidy checks by aureleoules
  28. aureleoules force-pushed on Jul 27, 2022
  29. DrahtBot cross-referenced this on Jul 27, 2022 from issue refactor: make all NodeImpl/ChainImpl/ExternalSignerImpl members public, rm temporaries, simplify by jonatack
  30. DrahtBot cross-referenced this on Jul 28, 2022 from issue Improve display address handling for external signer by Sjors
  31. DrahtBot cross-referenced this on Jul 28, 2022 from issue descriptors: Be able to specify change and receiving in a single descriptor string by achow101
  32. DrahtBot added the label Needs rebase on Aug 1, 2022
  33. aureleoules force-pushed on Aug 1, 2022
  34. aureleoules commented at 1:32 PM on August 1, 2022: member

    I assume this is being done with some automated tooling? If so, could you expand the PR description to describe what you are doing to produce the change?

    Done.

    Also rebased.

  35. DrahtBot removed the label Needs rebase on Aug 1, 2022
  36. aureleoules force-pushed on Aug 2, 2022
  37. DrahtBot cross-referenced this on Aug 4, 2022 from issue p2p: Implement anti-DoS headers sync by sdaftuar
  38. DrahtBot cross-referenced this on Aug 4, 2022 from issue tidy: add modernize-use-using by fanquake
  39. aureleoules force-pushed on Aug 8, 2022
  40. DrahtBot cross-referenced this on Aug 13, 2022 from issue consensus: Remove mainnet checkpoints by sdaftuar
  41. DrahtBot cross-referenced this on Aug 19, 2022 from issue Fix issues when calling std::move(const&) by maflcko
  42. DrahtBot added the label Needs rebase on Aug 19, 2022
  43. aureleoules force-pushed on Aug 22, 2022
  44. aureleoules force-pushed on Aug 22, 2022
  45. DrahtBot removed the label Needs rebase on Aug 22, 2022
  46. DrahtBot added the label Needs rebase on Aug 30, 2022
  47. refactor: make member functions const if applicable 057558626b
  48. tidy: Add readability-make-member-function-const 9112ec7963
  49. aureleoules force-pushed on Sep 5, 2022
  50. DrahtBot removed the label Needs rebase on Sep 5, 2022
  51. DrahtBot cross-referenced this on Sep 9, 2022 from issue mempool clean up: replace update_* structs with lambdas by glozow
  52. DrahtBot commented at 8:37 AM on September 12, 2022: contributor

    <!--cf906140f33d8803c4a75a2196329ecb-->

    🐙 This pull request conflicts with the target branch and needs rebase.

    <sub>Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".</sub>

  53. DrahtBot added the label Needs rebase on Sep 12, 2022
  54. aureleoules closed this on Oct 12, 2022

  55. maflcko commented at 8:12 AM on October 13, 2022: member

    why the close? Seems a risk free CI check to avoid spending time on this during review?

  56. aureleoules commented at 8:58 AM on October 13, 2022: member

    @MarcoFalke I was asked during coredev to close this.

    This kind of code review-heavy codebase-wide refactor is not appropriate in general, especially for a new contributor. Constness can be accidental, and code/logical constness are not the same thing.

  57. aureleoules deleted the branch on Nov 2, 2022
  58. fanquake cross-referenced this on Dec 8, 2022 from issue refactor: make some BlockManager members const by promag
  59. bitcoin locked this on Nov 2, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-20 06:53 UTC