47 lines · plain
1.. title:: clang-tidy - misc-redundant-expression2 3misc-redundant-expression4=========================5 6Detect redundant expressions which are typically errors due to copy-paste.7 8Depending on the operator expressions may be9 10- redundant,11 12- always ``true``,13 14- always ``false``,15 16- always a constant (zero or one).17 18Examples:19 20.. code-block:: c++21 22 ((x+1) | (x+1)) // (x+1) is redundant23 (p->x == p->x) // always true24 (p->x < p->x) // always false25 (speed - speed + 1 == 12) // speed - speed is always zero26 int b = a | 4 | a // identical expr on both sides27 ((x=1) | (x=1)) // expression is identical28 (DEFINE_1 | DEFINE_1) // same macro on the both sides29 ((DEF_1 + DEF_2) | (DEF_1+DEF_2)) // expressions differ in spaces only30 31Floats are handled except in the case that NaNs are checked like so:32 33.. code-block:: c++34 35 int TestFloat(float F) {36 if (F == F) // Identical float values used37 return 1;38 return 0;39 }40 41 int TestFloat(float F) {42 // Testing NaN.43 if (F != F && F == F) // does not warn44 return 1;45 return 0;46 }47