Fix FP, conversion of char literal '\0' to boolean is not true

This commit is contained in:
Daniel Marjamäki 2018-08-08 19:04:10 +02:00
parent fc7aab220e
commit f2e7071922
2 changed files with 6 additions and 1 deletions

View File

@ -307,7 +307,7 @@ void CheckString::checkIncorrectStringCompare()
}
} else if (Token::Match(tok, "&&|%oror%|( %str%|%char% &&|%oror%|)") && !Token::Match(tok, "( %str%|%char% )")) {
incorrectStringBooleanError(tok->next(), tok->strAt(1));
} else if (Token::Match(tok, "if|while ( %str%|%char% )")) {
} else if (Token::Match(tok, "if|while ( %str%|%char% )") && !tok->tokAt(2)->getValue(0)) {
incorrectStringBooleanError(tok->tokAt(2), tok->strAt(2));
}
}

View File

@ -591,6 +591,11 @@ private:
"[test.cpp:3]: (warning) Conversion of char literal 'b' to bool always evaluates to true.\n"
"[test.cpp:4]: (warning) Conversion of char literal 'c' to bool always evaluates to true.\n"
, errout.str());
check("void f() {\n"
" if('\\0'){}\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void deadStrcmp() {