clang-tidy - readability-math-missing-parentheses — Extra Clang Tools 20.1.8 documentation

# Extra Clang Tools 20.1.8 documentation

## clang-tidy - readability-math-missing-parentheses

# readability-math-missing-parentheses

Check for missing parentheses in mathematical expressions that involve operators of different priorities.

Parentheses in mathematical expressions clarify the order of operations, especially with different-priority operators. Lengthy or multiline expressions can obscure this order, leading to coding errors. IDEs can aid clarity by highlighting parentheses. Explicitly using parentheses also clarifies what the developer had in mind when writing the expression. Ensuring their presence reduces ambiguity and errors, promoting clearer and more maintainable code.

Before:

    int x = 1 + 2 * 3 - 4 / 5;

After:

    int x = 1 + (2 * 3) - (4 / 5);