1.. title:: clang-tidy - misc-redundant-expression 2 3misc-redundant-expression 4========================= 5 6Detect redundant expressions which are typically errors due to copy-paste. 7 8Depending on the operator expressions may be 9 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 redundant 23 (p->x == p->x) // always true 24 (p->x < p->x) // always false 25 (speed - speed + 1 == 12) // speed - speed is always zero 26 int b = a | 4 | a // identical expr on both sides 27 ((x=1) | (x=1)) // expression is identical 28 29Floats are handled except in the case that NaNs are checked like so: 30 31.. code-block:: c++ 32 33 int TestFloat(float F) { 34 if (F == F) // Identical float values used 35 return 1; 36 return 0; 37 } 38 39 int TestFloat(float F) { 40 // Testing NaN. 41 if (F != F && F == F) // does not warn 42 return 1; 43 return 0; 44 } 45