V552. A bool type variable is being incremented. Perhaps another variable should be incremented instead.

The analyzer detected a potentially dangerous construct in code where a variable of the bool type is being incremented:

bool bValue = false;
...
bValue++;

First, the C++ language's standard reads:

The use of an operand of type bool with the postfix ++ operator is deprecated.

It means that we should not use such a construct.

Second, it is better to assign the 'true' value explicitly to this variable. This code is clearer:

bValue = true;

Third, it might be that there is a misprint in the code and the programmer actually intended to increment a different variable. For example:

bool bValue = false;
int iValue = 1;
...
if (bValue)
  bValue++;

A wrong variable was used by accident here while it was meant to be this code:

bool bValue = false;
int iValue = 1;
...
if (bValue)
  iValue++;

According to Common Weakness Enumeration, potential errors found by using this diagnostic are classified as CWE-480.

You can look at examples of errors detected by the V552 diagnostic.


Bugs Found

Checked Projects
409
Collected Errors
14 072
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site. Learn More →
Accept