Repository navigation
house-operator-precedence: parentheses that make the precedence explicit (MISRA 8.0.1) - #109
Merged
Merged
Conversation
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.
Merged
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.
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) : candsizeof(value). CodingStyle gets the rule as T-23.Until now
Misra.mdnamedreadability-math-missing-parenthesesand-Wparenthesesfor the rule. Those hold arithmetic and bits mixed, and&&in||, so a comparison in&&or||, the operands of?:and the operand ofsizeofpassed every check. The new checkhouse-operator-precedencefollows 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-parenthesesis turned off, as it covers a part of the same rule and would report one place twice. The expression of an#ifis out of reach of clang-tidy and stays with review.Breaking for a project on update:
make tidyreports 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.mdon 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.shin full for the Arduino library, the CMake library and the firmware;lint tidyfor PlatformIO, andtidywith--targetsfor the Arduino library and the firmware. The skeleton'sclamp, its fuzzers and SelfCheck take their parentheses.