29 lines · plain
1.. title:: clang-tidy - readability-math-missing-parentheses2 3readability-math-missing-parentheses4====================================5 6Check for missing parentheses in mathematical expressions that involve7operators of different priorities.8 9Parentheses in mathematical expressions clarify the order10of operations, especially with different-priority operators. Lengthy or11multiline expressions can obscure this order, leading to coding errors.12IDEs can aid clarity by highlighting parentheses. Explicitly using parentheses13also clarifies what the developer had in mind when writing the expression.14Ensuring their presence reduces ambiguity and errors, promoting clearer and15more maintainable code.16 17Before:18 19.. code-block:: c++20 21 int x = 1 + 2 * 3 - 4 / 5;22 23 24After:25 26.. code-block:: c++27 28 int x = 1 + (2 * 3) - (4 / 5);29