Skip to content

house-else-if-without-else: an if ... else if chain ends with else - #113

Merged
theAndreas merged 2 commits into
mainfrom
house-if-ends-with-else
Nov 17, 2026
Merged

theAndreas merged 2 commits into
mainfrom
house-if-ends-with-else

Conversation

@theAndreas

Copy link
Copy Markdown
Owner

What

A project's make tidy reports an if … else if chain that ends without else, as MISRA C++:2023 Rule 9.4.1 asks; the new CodingStyle T-24 states the rule, and that an empty else says in a comment why nothing is to do. Misra.md names the check for the rule instead of review.

The check reports the if of the last else if; an if alone, with or without else, passes, and a chain in the branch of another if counts 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 the else does, only the author knows.

Why

The rule complements the default of a switch: the chain says what happens when no condition holds. No check of clang-tidy 23 finds it, as hicpp-multiway-paths-covered is gone, so Misra.md left it to review. On the update, a project fixes each chain it reports by hand.

How it was checked

  • tests/tidy_module.py passes, with the cases of the new check: chains of two and three links, a chain in the branch of another if, 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 tidy passes for the Arduino library, --no-arduino, --firmware and --platformio, and tests/check.sh --targets tidy for the Arduino library, --no-arduino and --firmware: the skeleton has no chain without else.
  • tests/doc_indent.py passes.

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
theAndreas force-pushed the house-if-ends-with-else branch from 4ef5e30 to 08d9822 Compare November 17, 2026 12:13
@theAndreas
theAndreas merged commit 83f2f45 into main Nov 17, 2026
1 check passed
@theAndreas
theAndreas deleted the house-if-ends-with-else branch November 17, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants