Repository navigation
house-else-if-without-else: an if ... else if chain ends with else - #113
Merged
Merged
Conversation
MISRA C++:2023 Rule 9.4.1 asks for an else at the end of every chain of else if, as 9.4.2 asks for a default in a switch. Misra.md left it to review, as hicpp-multiway-paths-covered, which checked it, is gone in clang-tidy 23. The new check reports the if of the last else if of a chain without else; once in a template, not in the body of a macro. It has no fix-it, as only the author knows what the else does. CodingStyle T-24 states the rule, and that an empty else says in a comment why nothing is to do. ROADMAP C-15 records the check, and C-3 drops it from its candidates.
theAndreas
force-pushed
the
house-if-ends-with-else
branch
from
November 17, 2026 12:13
4ef5e30 to
08d9822
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A project's
make tidyreports anif … else ifchain that ends withoutelse, as MISRA C++:2023 Rule 9.4.1 asks; the new CodingStyle T-24 states the rule, and that an emptyelsesays in a comment why nothing is to do.Misra.mdnames the check for the rule instead of review.The check reports the
ifof the lastelse if; anifalone, with or withoutelse, passes, and a chain in the branch of anotherifcounts as a chain of its own. In a template it reports once, as written, and not in the body of a macro. It has no fix-it: what theelsedoes, only the author knows.Why
The rule complements the
defaultof aswitch: the chain says what happens when no condition holds. No check of clang-tidy 23 finds it, ashicpp-multiway-paths-coveredis gone, soMisra.mdleft it to review. On the update, a project fixes each chain it reports by hand.How it was checked
tests/tidy_module.pypasses, with the cases of the new check: chains of two and three links, a chain in the branch of anotherif, a template instantiated twice, and what passes. A marker moved to a line the check must not report makes it fail.tests/check.sh lint tidypasses for the Arduino library,--no-arduino,--firmwareand--platformio, andtests/check.sh --targets tidyfor the Arduino library,--no-arduinoand--firmware: the skeleton has no chain withoutelse.tests/doc_indent.pypasses.