Use -Wswitch for TxoutType where possible#20211
Conversation
|
Concept ACK: From the standard: "Flowing off the end of a function is equivalent to a return with no value; this results in undefined behavior in a value-returning function." (C++11, [stmt.return]) |
|
Concept ACK |
1 similar comment
|
Concept ACK |
|
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. |
There was a problem hiding this comment.
Ack fa650ca
We do switch (dest.which()) { in a few places as well. This seems pretty similar, and I'm wondering if this should be refactored as well? (Probably in a different PR though?)
In #20286 I added TxoutType& typeRet to ExtractDestination here, and I was wondering if this would allow us to make these switch (dest.which()) { statements more readable by doing it on TxoutType as done in this PR. Thoughts, and once #20286 is merged, is this something that should be done?
What do you suggest? |
|
Well once we have (would require #20286): bool ExtractDestination(const CScript& scriptPubKey, TxoutType& typeRet, CTxDestination& addressRet);Could we do something like: TxoutType type;
CTxDestination dest;
ExtractDestination(m_script, type, dest);
switch (type) {
case TxoutType::PUBKEYHASH:
case TxoutType::SCRIPTHASH: return OutputType::LEGACY;
case TxoutType::WITNESS_V0_SCRIPTHASH:
case TxoutType::WITNESS_V0_KEYHASH:
case TxoutType::WITNESS_V1_TAPROOT:
case TxoutType::WITNESS_UNKNOWN: return OutputType::BECH32;
case TxoutType::PUBKEY:
case TxoutType::MULTISIG:
case TxoutType::NONSTANDARD:
case TxoutType::NULL_DATA: return nullopt; // no default case, so the compiler can warn about missing cases
}
assert(false);Note: I messed around with this, and probably made some mistakes here, but didn't see any unit tests or functional tests fail. So maybe some test coverage is needed here as well? |
Let's discuss this in the other pull then |
|
cr ACK fa650ca: patch looks correct and |
fa650ca Use -Wswitch for TxoutType where possible (MarcoFalke) fa59e0b test: Add missing script_standard_Solver_success cases (MarcoFalke) Pull request description: This removes unused `default:` cases for all `switch` statements on `TxoutType` and adds the cases (`MULTISIG`, `NULL_DATA`, `NONSTANDARD`) to `ExtractDestination` for clarity. Also, the compiler is now able to use `-Wswitch`. ACKs for top commit: practicalswift: cr ACK fa650ca: patch looks correct and `assert(false);` is better than UB :) hebasto: ACK fa650ca, I have reviewed the code and it looks OK, I agree it can be merged. Tree-SHA512: 282458b6523bd8923a0c0f5c423d1db2dce2a2d1b1d1dae455415c6fc995bb41ce82c1f9b0a1c0dcc6d874d171e04c30eca585f147582f52c7048c140358630a
This removes unused
default:cases for allswitchstatements onTxoutTypeand adds the cases (MULTISIG,NULL_DATA,NONSTANDARD) toExtractDestinationfor clarity.Also, the compiler is now able to use
-Wswitch.