Skip to content

Commit

Permalink
Fix #13067 FP incorrectStringBooleanError for macro argument (#6770)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Sep 7, 2024
1 parent c2f4c5c commit fc2f551
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/checkstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ void CheckString::strPlusCharError(const Token *tok)
static bool isMacroUsage(const Token* tok)
{
if (const Token* parent = tok->astParent()) {
while (parent && parent->isCast())
while (parent && (parent->isCast() || parent->str() == "&&"))
parent = parent->astParent();
if (!parent)
return false;
Expand Down
6 changes: 6 additions & 0 deletions test/teststring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,12 @@ class TestString : public TestFixture {
" }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:4]: (warning) Conversion of string literal \"test.C\" to bool always evaluates to true.\n", errout_str());

check("#define MACRO(C) if(!(C)) { error(__FILE__, __LINE__, __FUNCTION__, #C); return; }\n" // #13067
"void f() {\n"
" MACRO(false && \"abc\");\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void deadStrcmp() {
Expand Down

0 comments on commit fc2f551

Please sign in to comment.