refactor: Enforce readability-avoid-const-params-in-decls #31650

pull maflcko wants to merge 2 commits into bitcoin:master from maflcko:2501-less-wrong-const changing 52 files +105 −103
  1. maflcko commented at 8:41 pm on January 13, 2025: member

    Top level const in declarations is problematic for many reasons:

    • It is often a typo, where one wanted to denote a const reference. For example bool PSBTInputSignedAndVerified(const PartiallySignedTransaction psbt, ... is missing the &. This will create a redundant copy of the value.
    • In constructors it prevents move construction.
    • It can incorrectly imply some data is const, like in an imaginary example std::span<int> Shuffle(const std::span<int>);, where the ints are not const.
    • The compiler ignores the const from the declaration in the implementation.
    • It isn’t used consistently anyway, not even on the same line.

    Fix all issues by:

    • Using a const reference to avoid a copy, where read-only of the value is intended. This is only done for values that may be expensive to copy.
    • Using move-construction to avoid a copy
    • Applying readability-avoid-const-params-in-decls via clang-tidy
  2. DrahtBot commented at 8:41 pm on January 13, 2025: contributor

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

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31650.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK hebasto

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #bitcoin-core/gui/841 (Decouple WalletModel from RPCExecutor by furszy)
    • #31519 (refactor: Use std::span over Span by maflcko)
    • #29680 (wallet: fix unrelated parent conflict doesn’t cause child tx to be marked as conflict by Eunovo)
    • #28710 (Remove the legacy wallet and BDB dependency 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.

  3. DrahtBot renamed this:
    refactor: Enforce readability-avoid-const-params-in-decls
    refactor: Enforce readability-avoid-const-params-in-decls
    on Jan 13, 2025
  4. DrahtBot added the label Refactoring on Jan 13, 2025
  5. hebasto commented at 9:01 am on January 14, 2025: member
    Concept ACK.
  6. maflcko force-pushed on Jan 14, 2025
  7. DrahtBot added the label Needs rebase on Jan 16, 2025
  8. refactor: Avoid copies by using const references or by move-construction fafcd0090f
  9. refactor: Enforce readability-avoid-const-params-in-decls fa89b4beab
  10. maflcko force-pushed on Jan 20, 2025
  11. DrahtBot removed the label Needs rebase on Jan 20, 2025
  12. maflcko commented at 10:52 am on January 20, 2025: member
    rebased to drop hunk which was already merged via one of the conflicting pulls

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: 2025-01-21 03:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me