diff --git a/lib/checkbool.cpp b/lib/checkbool.cpp index 5de0f2209..48167187d 100644 --- a/lib/checkbool.cpp +++ b/lib/checkbool.cpp @@ -333,10 +333,13 @@ void CheckBool::checkAssignBoolToPointer() const Scope * scope = symbolDatabase->functionScopes[i]; for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { if (Token::Match(tok, "%var% = %bool% ;")) { - // Todo: properly check if there is a deref + // check if there is a deref // *x.p = true; // <- don't warn // x.p = true; // <- warn - if (Token::Match(tok->previous(), "[*.)]")) + const Token *prev = tok; + while (Token::Match(prev->tokAt(-2), "%var% .")) + prev = prev->tokAt(-2); + if (Token::Match(prev->previous(), "[*.)]")) continue; // Is variable a pointer? diff --git a/test/testbool.cpp b/test/testbool.cpp index 2213103f6..b3808fb45 100644 --- a/test/testbool.cpp +++ b/test/testbool.cpp @@ -111,7 +111,7 @@ private: " S s = {0};\n" " s.p = true;\n" "}\n"); - TODO_ASSERT_EQUALS("error", "", errout.str()); + ASSERT_EQUALS("[test.cpp:6]: (error) Boolean value assigned to pointer.\n", errout.str()); } void comparisonOfBoolExpressionWithInt1() {