Skip to content

house-operator-precedence: parentheses that make the precedence explicit (MISRA 8.0.1) - #109

Merged
theAndreas merged 3 commits into
mainfrom
house-operator-precedence
Nov 17, 2026
Merged

theAndreas merged 3 commits into
mainfrom
house-operator-precedence

Conversation

@theAndreas

Copy link
Copy Markdown
Owner

A project made from the template now checks MISRA C++:2023 Rule 8.0.1 in full: an operand that is itself an operation of higher precedence stands in parentheses, as (a == b) && ready, (x + 1) < limit, ready ? (a + b) : c and sizeof(value). CodingStyle gets the rule as T-23.

Until now Misra.md named readability-math-missing-parentheses and -Wparentheses for the rule. Those hold arithmetic and bits mixed, and && in ||, so a comparison in && or ||, the operands of ?: and the operand of sizeof passed every check. The new check house-operator-precedence follows the ranks of the rule, for built-in and overloaded operators alike, and every report carries a fix-it that adds the parentheses. readability-math-missing-parentheses is turned off, as it covers a part of the same rule and would report one place twice. The expression of an #if is out of reach of clang-tidy and stays with review.

Breaking for a project on update: make tidy reports every operand that lacks its parentheses. The CHANGELOG says how to apply the fix-its at once.

Also in this PR: ROADMAP I-4 and the note of Misra.md on the rows marked Review name PVS-Studio and Cppcheck Premium as examples of a commercial checker.

Checked:

  • tests/tidy_module.py: every case of the new check, reported and passing, built-in and overloaded, ?:, sizeof, a macro argument and body, a template; the fix-its applied compile and leave nothing to report. The other modules' cases still pass.
  • tests/check.sh in full for the Arduino library, the CMake library and the firmware; lint tidy for PlatformIO, and tidy with --targets for the Arduino library and the firmware. The skeleton's clamp, its fuzzers and SelfCheck take their parentheses.

MISRA C++:2023 Rule 8.0.1 asks for parentheses around an operand that is
itself an operation of higher precedence, and Misra.md named
readability-math-missing-parentheses and -Wparentheses for it. Those hold
arithmetic and bits mixed, and && in ||; a comparison in && or ||, the
operands of ?: and the operand of sizeof passed every check.

The new check holds the rule by its ranks, for built-in and overloaded
operators, with a fix-it that puts the operand in parentheses. It reports
in a template once, as written, and in the argument of a macro, but not
in a macro's body, which every expansion shares; the expression of an #if
is out of reach of clang-tidy and stays with review.

CodingStyle gets the rule as T-23, and the example of T-18 puts its
comparisons in parentheses. readability-math-missing-parentheses is off,
as a part of the new check that would report one place twice. The
skeleton's clamp, fuzzers and SelfCheck take their parentheses, and so
does a case of house-operator-form.
I-4 and the note of Misra.md on the rows marked Review name PVS-Studio
and Cppcheck Premium as examples of a commercial checker for MISRA
C++:2023, with no order and no preference among them.
@theAndreas
theAndreas merged commit ecf81fb into main Nov 17, 2026
1 check passed
@theAndreas
theAndreas deleted the house-operator-precedence branch November 17, 2026 10:39
@theAndreas theAndreas mentioned this pull request Nov 17, 2026
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