CWARN.BOOLOP.INC

Attempt to increment a Boolean value

The CWARN.BOOLOP.INC checker finds attempts to increment or decrement a Boolean value.

Vulnerability and risk

Using increment or decrement operations with a Boolean true/false value has no effect.

Vulnerable code example

1  #include <iostream>

2  using namespace std;
 
3  void foo() {
4    bool b = true;
5    b++;
6  }
 
7  int main() { 
8    foo();
9    return 0;
10 }

Klocwork flags the attempt to increment Boolean variable 'b' at line 5.