build: Enable `-Wunused` #36167

pull fanquake wants to merge 3 commits into bitcoin:master from fanquake:enable_wunused changing 137 files +461 −438
  1. fanquake commented at 2:32 PM on September 4, 2026: member

    We've had a handful of dead code removal PRs recently:

    Also well as an instance of what was thought to be dead code, but it'd just been forgotten to be used: #36137.

    It could be beneficial to get -Wunused enabled, to catch dead/unused code in CI.

    Enabling some of these flags may also help enforce other stuff, like inline constexpr usage (#35852). i.e:

      /home/runner/work/_temp/src/leveldb/db/dbformat.h:67:29: error: 'leveldb::kMaxSequenceNumber' defined but not used [-Werror=unused-const-variable=]
         67 | static const SequenceNumber kMaxSequenceNumber = ((0x1ull << 56) - 1);
            |                             ^~~~~~~~~~~~~~~~~~
    

    Based on:

  2. DrahtBot commented at 2:32 PM on September 4, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #36326 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36326.svg"></sub> (kernel: Use typed errors for fatal and flush error notifications by arejula27)
    • #36268 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36268.svg"></sub> (refactor: prune unused semi-colons by fanquake)
    • #36154 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36154.svg"></sub> (wallet: fill PSBT_GLOBAL_XPUB by jeanpablojp)
    • #36122 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36122.svg"></sub> (BIP460: CISA for Taproot key path spends by fjahr)
    • #36074 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36074.svg"></sub> (scripted-diff: [test] Add util/check.h includes for assertions by maflcko)
    • #35911 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35911.svg"></sub> (Warn on and add missing [[noreturn]] by fanquake)
    • #35906 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35906.svg"></sub> (First steps towards a stateless, side-effect free validation library by purpleKarrot)
    • #35760 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35760.svg"></sub> (wallet: make corrupted transaction records fail wallet loading instead of forcing a rescan by achow101)
    • #35716 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35716.svg"></sub> (wallet: Replace mapWallet and wtxOrdered with a boost::multi_index by achow101)
    • #35302 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35302.svg"></sub> (Silent Payments: Sending (take 2) by Eunovo)
    • #34520 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34520.svg"></sub> (refactor: Add [[nodiscard]] to functions returning bool+mutable ref by maflcko)
    • #34132 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34132.svg"></sub> (coins,dbwrapper: make point-read and txindex lookup failures fatal by l0rinc)
    • #33324 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/33324.svg"></sub> (blocks: add resumable reobfuscation for existing block files by l0rinc)
    • #33117 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/33117.svg"></sub> (Interfaces: Expose UTXO Snapshot Loading and Add Progress Notifications by D33r-Gee)
    • #30343 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/30343.svg"></sub> (wallet, logging: Replace WalletLogPrintf() with LogInfo() by ryanofsky)
    • #27865 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/27865.svg"></sub> (wallet: Track no-longer-spendable TXOs separately 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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  3. DrahtBot added the label CI failed on Sep 4, 2026
  4. DrahtBot commented at 3:54 PM on September 4, 2026: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Task lint: https://github.com/bitcoin/bitcoin/actions/runs/33884346846/job/101060370925</sub> <sub>LLM reason (✨ experimental): CI failed the subtree lint check because a subtree directory was modified without the required subtree merge (FAIL: subtree directory was touched without subtree merge).</sub>

    <details><summary>Hints</summary>

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

    </details>

  5. fanquake force-pushed on Sep 4, 2026
  6. fanquake force-pushed on Sep 7, 2026
  7. fanquake force-pushed on Sep 9, 2026
  8. fanquake force-pushed on Sep 14, 2026
  9. fanquake force-pushed on Sep 16, 2026
  10. in src/policy/fees/mempool_estimator.h:38 in b8a063d2a5
      37 |  
      38 |  // Constants for mempool sanity checks.
      39 | -constexpr size_t MEMPOOL_HEALTH_WINDOW_BLOCKS = 6;
      40 | -constexpr double MEMPOOL_REPRESENTATION_THRESHOLD = 0.75;
      41 | +inline constexpr size_t MEMPOOL_HEALTH_WINDOW_BLOCKS = 6;
      42 | +inline constexpr double MEMPOOL_REPRESENTATION_THRESHOLD = 0.75;
    


    maflcko commented at 10:46 AM on September 16, 2026:

    Nice, but I think those should:

    • use the C++11 narrowing-check init `double ...{0.75};
    • Maybe be split up into a separate pull from the unused parameter warnings

    Haven't tried this, but what about just a small pull to add:

    try_append_cxx_flags("-Wunused-macros" TARGET warn_interface SKIP_LINK)
    try_append_cxx_flags("-Wunused-const-variable=2" TARGET warn_interface SKIP_LINK)
    try_append_cxx_flags("-Wunused-member-function" TARGET warn_interface SKIP_LINK)
    try_append_cxx_flags("-Wunused-template" TARGET warn_interface SKIP_LINK)
    etc...whatever...
    

    And leave the -Wno-unused-parameter as-is for now?

    Those should catch most of the issues mentioned in OP (except for the unused parameter ones)?


    fanquake commented at 3:15 PM on September 16, 2026:

    Split a portion out into #36275.

  11. sipa referenced this in commit a12f5de1c9 on Sep 16, 2026
  12. fanquake referenced this in commit 53a1914e00 on Sep 16, 2026
  13. DrahtBot added the label Needs rebase on Sep 17, 2026
  14. fanquake referenced this in commit 60bcf13edf on Sep 19, 2026
  15. fanquake force-pushed on Sep 29, 2026
  16. fanquake force-pushed on Sep 29, 2026
  17. fanquake force-pushed on Sep 29, 2026
  18. in src/rpc/blockchain.cpp:299 in aaa1307cc4 outdated
     295 | @@ -296,7 +296,7 @@ static RPCMethod getblockcount()
     296 |                      HelpExampleCli("getblockcount", "")
     297 |              + HelpExampleRpc("getblockcount", "")
     298 |                  },
     299 | -        [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
     300 | +        [](const RPCMethod&, const JSONRPCRequest& request) -> UniValue
    


    maflcko commented at 3:12 PM on September 29, 2026:

    still not sure about enabling the unused-param one. I think we want to use self here more, not remove it. But using it would require touching this line again.

    Maybe some of the other warnings can be enabled #36167 (review)?


    fanquake commented at 4:54 PM on September 29, 2026:

    I think we want to use self here more,

    Are there any PRs currently doing this? I'll split more of this out.


    maflcko commented at 8:06 PM on September 29, 2026:

    maflcko commented at 6:08 PM on November 5, 2026:

    Also, for the context, I wonder if we can pipe it through self and then instead remove the JSONRPCRequest instead of RPCMethod:

    diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp
    index 3852358..6123c38 100644
    --- a/src/rpc/server.cpp
    +++ b/src/rpc/server.cpp
    @@ -170,3 +170,3 @@ static RPCMethod stop()
                     RPCExamples{""},
    -        [](const RPCMethod& self, const JSONRPCRequest& jsonRequest) -> UniValue
    +        [](const RPCMethod& self, const JSONRPCRequest&) -> UniValue
     {
    @@ -174,5 +174,5 @@ static RPCMethod stop()
         // this reply will get back to the client.
    -    CHECK_NONFATAL((CHECK_NONFATAL(EnsureAnyNodeContext(jsonRequest.context).shutdown_request))());
    -    if (jsonRequest.params[0].isNum()) {
    -        UninterruptibleSleep(std::chrono::milliseconds{jsonRequest.params[0].getInt<int>()});
    +    CHECK_NONFATAL((CHECK_NONFATAL(EnsureAnyNodeContext(self.Context()).shutdown_request))());
    +    if (const auto wait{self.MaybeArg<int>("wait")}) {
    +        UninterruptibleSleep(std::chrono::milliseconds{*wait});
         }
    diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp
    index e2cf363..ccad9da 100644
    --- a/src/rpc/util.cpp
    +++ b/src/rpc/util.cpp
    @@ -694,2 +694,7 @@ UniValue RPCMethod::HandleRequest(const JSONRPCRequest& request) const
     
    +const std::any& RPCMethod::Context() const
    +{
    +    return CHECK_NONFATAL(m_req)->context;
    +}
    +
     using CheckFn = void(const RPCArg&);
    diff --git a/src/rpc/util.h b/src/rpc/util.h
    index bf17885..0e2a075 100644
    --- a/src/rpc/util.h
    +++ b/src/rpc/util.h
    @@ -18,2 +18,3 @@
     
    +#include <any>
     #include <cstddef>
    @@ -451,2 +452,5 @@ public:
         UniValue HandleRequest(const JSONRPCRequest& request) const;
    +    /// Return the context for the current RPC method invocation.
    +    /// Like Arg(), this is only available during the method implementation.
    +    const std::any& Context() const;
         /**
    
  19. hebasto referenced this in commit 3b9768a07a on Sep 29, 2026
  20. fanquake force-pushed on Sep 29, 2026
  21. DrahtBot removed the label Needs rebase on Sep 29, 2026
  22. fanquake force-pushed on Oct 1, 2026
  23. hebasto referenced this in commit 69142eacd1 on Oct 2, 2026
  24. DrahtBot added the label Needs rebase on Oct 2, 2026
  25. fanquake force-pushed on Oct 2, 2026
  26. DrahtBot removed the label Needs rebase on Oct 2, 2026
  27. fanquake force-pushed on Oct 6, 2026
  28. fanquake force-pushed on Oct 13, 2026
  29. in CMakeLists.txt:487 in 45b90e51b5
     479 | @@ -480,9 +480,11 @@ else()
     480 |    try_append_cxx_flags("-Wthread-safety-pointer" TARGET warn_interface SKIP_LINK)
     481 |    try_append_cxx_flags("-Wloop-analysis" TARGET warn_interface SKIP_LINK)
     482 |    try_append_cxx_flags("-Wredundant-decls" TARGET warn_interface SKIP_LINK)
     483 | -  try_append_cxx_flags("-Wunused-member-function" TARGET warn_interface SKIP_LINK)
     484 | +  try_append_cxx_flags("-Wunused" TARGET warn_interface SKIP_LINK)
     485 |    try_append_cxx_flags("-Wunused-const-variable" TARGET warn_interface SKIP_LINK)
     486 | +  try_append_cxx_flags("-Wunused-member-function" TARGET warn_interface SKIP_LINK)
     487 |    try_append_cxx_flags("-Wunused-exception-parameter" TARGET warn_interface SKIP_LINK)
     488 | +  try_append_cxx_flags("-Wunused-template" TARGET warn_interface SKIP_LINK)
    


    maflcko commented at 6:39 AM on October 13, 2026:

    can you split this one out? Possibly also -Wunused-macros (if meaningful, etc)?


    fanquake commented at 8:39 AM on October 13, 2026:

    Put them into #36509.

  30. sedited referenced this in commit d3c3871b59 on Oct 21, 2026
  31. DrahtBot added the label Needs rebase on Oct 21, 2026
  32. fanquake force-pushed on Oct 21, 2026
  33. DrahtBot removed the label Needs rebase on Oct 21, 2026
  34. fanquake referenced this in commit 42ad455b00 on Oct 30, 2026
  35. fanquake force-pushed on Oct 30, 2026
  36. fanquake referenced this in commit e267773191 on Nov 2, 2026
  37. ryanofsky referenced this in commit b1816a8d02 on Nov 3, 2026
  38. DrahtBot added the label Needs rebase on Nov 4, 2026
  39. fanquake referenced this in commit 93bd4e1df4 on Nov 5, 2026
  40. fanquake force-pushed on Nov 5, 2026
  41. fanquake renamed this:
    [RFC] Enable `-Wunused`
    build: Enable `-Wunused`
    on Nov 5, 2026
  42. fanquake force-pushed on Nov 5, 2026
  43. DrahtBot removed the label Needs rebase on Nov 5, 2026
  44. DrahtBot added the label Needs rebase on Nov 6, 2026
  45. hebasto referenced this in commit b6ccaaef05 on Nov 6, 2026
  46. [[nomerge]] minisketch: unused changes 5f9e7b2cbc
  47. refactor: fix -Wunused issues 7e7eb3514c
  48. build: add -Wunused e563664025
  49. fanquake force-pushed on Nov 6, 2026
  50. DrahtBot removed the label Needs rebase on Nov 6, 2026

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-11-10 20:51 UTC

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