...
Although this noncompliant code example compiles correctly, it is unlikely that it means what the author of the code intended.:
Code Block | ||||
---|---|---|---|---|
| ||||
int a = 2; int b = 2; int c = 2; /* ... */ if (a < b < c) /* misleading, likely bug */ /* ... */ if (a == b == c) /* misleading, likely bug */ |
...
Treat relational and equality operators as if it were invalid to chain them.:
Code Block | ||||
---|---|---|---|---|
| ||||
if ( (a < b) && (b < c) ) /* clearer, and probably what was intended */ /* ... */ if ( (a == b) && (a == c) ) /* ditto */ |
...
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
| exprprns | Fully implemented. | |||||||
GCC |
|
| Option | ||||||
PRQA QA-C |
| 3392 | Fully implemented. |
Related Guidelines
CERT C++ Secure Coding Standard | EXP17-CPP. Treat relational and equality operators as if they were nonassociative |
Bibliography
[ISO/IEC 9899:2011] | Section 6.5.8, "Relational Operators" |
...