Synopsis: | The test condition in control statements shall be a non-assignment expression |
Language: | C++ |
Severity Level: | 9 |
Category: | Control Flow |
Description: |
The test condition shall not be an assignment expression. This avoids mistaking assignments for comparisons. Example: bool b1 = true; bool b2 = true; int i = 123; if (i != 0) // right: expression is a non-assignment if (i = 123) // wrong: probably, (i == 123) was intended if (b1 = (b1 && b2)) // wrong: even if this might seem convenient in some cases |