ATH-inc-bool (C++ only)
In this section:
Synopsis
Deprecated operation on bool.
Enabled by default
Yes
Severity/Certainty
Medium/High

Full description
An undefined increment or decrement operation is performed on a bool value. In older versions of C++, Boolean values were modeled by a typedef to an integer type, allowing increment and decrement operations. These types are deprecated in Standard C++ and the operations no longer apply to the built-in C++ bool type.
Coding standards
- CWE 480
Use of Incorrect Operator
Code examples
The following code example fails the check and will give a warning:
int main(void)
{
bool x = true;
++x; //this operation is undefined for a bool
}
The following code example passes the check and will not give a warning about this issue:
int main(void)
{
int x = 0;
++x; //OK - x is an int
}