CheckBool: Fixed false negative when assigning bool to pointer '; s.p = true; '
This commit is contained in:
parent
b577b12660
commit
5c072993e3
|
@ -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?
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue