TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C++ Coding Standard

Rule:  CFL#011Checked automatically with code checker

Synopsis:The test condition in control statements shall be a non-assignment expression
Severity Level:9
Category:Control Flow


The test condition shall not be an assignment expression. This avoids mistaking assignments for comparisons.


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