Debian Codegraph @

clang-tools-extra/docs/clang-tidy/checks/readability/math-missing-parentheses.rst

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