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