Fix false negatives in checkIncrementBoolean (#2210)
Detect incrementing boolean expressions involving pointer dereferences, array element accesses, etc.
This commit is contained in:
parent
0fadae78d3
commit
ca5f2562fc
|
@ -57,9 +57,7 @@ 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))
|
||||
if (astIsBool(tok) && tok->astParent() && tok->astParent()->str() == "++") {
|
||||
incrementBooleanError(tok);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
"}");
|
||||
|
|
Loading…
Reference in New Issue