diff --git a/lib/checkbool.cpp b/lib/checkbool.cpp index 6f847cdeb..a385d8336 100644 --- a/lib/checkbool.cpp +++ b/lib/checkbool.cpp @@ -57,10 +57,8 @@ void CheckBool::checkIncrementBoolean() const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); for (const Scope * scope : symbolDatabase->functionScopes) { for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { - if (Token::Match(tok, "%var% ++")) { - const Variable *var = tok->variable(); - if (isBool(var)) - incrementBooleanError(tok); + if (astIsBool(tok) && tok->astParent() && tok->astParent()->str() == "++") { + incrementBooleanError(tok); } } } diff --git a/test/testbool.cpp b/test/testbool.cpp index c50066d77..385a984c5 100644 --- a/test/testbool.cpp +++ b/test/testbool.cpp @@ -857,6 +857,16 @@ private: "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n", errout.str()); + check("void f(bool* test){\n" + " (*test)++;\n" + "}"); + ASSERT_EQUALS("[test.cpp:2]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n", errout.str()); + + check("void f(bool* test){\n" + " test[0]++;\n" + "}"); + ASSERT_EQUALS("[test.cpp:2]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n", errout.str()); + check("void f(int test){\n" " test++;\n" "}");