-
Notifications
You must be signed in to change notification settings - Fork 244
Remove unused variables, fields, and captures #7455
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
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.
Pull Request Overview
This PR improves compiler warning coverage by replacing the broad -Wno-unused flag with more targeted -Wno-unused-parameter and -Wno-unused-function flags. This enables detection of genuinely unused variables, fields, and lambda captures while still allowing unused function parameters (required by interface signatures) and unused static header functions.
- Removes unused lambda captures (primarily
[this]where the lambda body doesn't use member variables/functions) - Removes unused local variables and fields identified by the stricter warning settings
- Adds error checking for some previously unchecked
JSWrappedValue::set...return values
Reviewed Changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| cmake/preproject.cmake | Replaces -Wno-unused with more specific -Wno-unused-parameter and -Wno-unused-function to enable better unused code detection |
| src/tasks/ordered_tasks.cpp | Removes unused [this] lambda capture where only the action parameter is used |
| src/quic/quic_session.h | Removes unused written variable that accumulated bytes written but wasn't used |
| src/node/rpc/node_frontend.h | Removes unused [this] captures from multiple lambdas and unused local variables config and service_config |
| src/node/rpc/jwt_management.h | Removes unused issuer_constraints from lambda capture list (still used elsewhere in the function) |
| src/node/quote.cpp | Removes unused digest variable |
| src/node/node_state.h | Removes unused service_config local variable |
| src/node/gov/handlers/proposals.h | Adds error checking for set_bool() return value |
| src/kv/store.h | Removes unused fields size_since_chunk and chunk_threshold |
| src/kv/serialised_entry_format.h | Adds [[maybe_unused]] to max_entry_size constant (used only in assertions) |
| src/js/registry.cpp | Removes unused [this] capture and unused rt variable |
| src/js/extensions/ccf/request.cpp | Adds error checking for multiple set() and set_null() return values when populating JS objects |
| src/js/extensions/ccf/historical.cpp | Removes unused view and seqno variables |
| src/js/extensions/ccf/crypto.cpp | Removes unused exception variable (though this introduces a bug) |
| src/endpoints/authentication/cose_auth.cpp | Removes unused gov_msg_proposal_created_at variable |
| src/crypto/csr.h | Removes unused icrt variable |
| samples/apps/programmability/programmability.cpp | Removes unused [this] lambda capture |
| samples/apps/logging/logging.cpp | Removes many unused [this] lambda captures and unused make_handle lambda function |
| samples/apps/basic/basic.cpp | Removes unused [this] lambda capture |
|
@copilot review this PR again now it has been updated. |
While we're improving
clang-tidycoverage (#7449, #7451) and adding a lot of[[nodiscard]]attributes I realised these aren't having the desired impact. Because we're also compiling with-Wno-unused, and ignoring all sorts of unused things.I've fiddled with a few options, and I think what we actually want is
-Wno-unused-parameter(because you have to implement a signature, but sometimes an argument isn't for you! Removing the name or adding an attribute are both ugly band-aids), and-Wno-unused-function(because we have lots of header-defined static functions used in some compilation units but not others. Would be great to find which are truly globally unused, but that's harder).In practice this mostly finds unused lambda captures (
[this]->[]), a few unused variables and fields (I think missed during refactors or block copy-pastes), and a few unchecked results ofJSWrappedValue::set...calls.I've added check-and-throw blocks so the latter compile, but I think this is ugly; if no-one wants the return values, then we should probably stop returning them entirely, and simply swallow-or-throw within theI've now addedset...call itself.[[nodiscard]]to ALL the set functions, and wrapped all call-points in a newJS_CHECK_OR_THROWmacro