Skip to content

Commit

Permalink
Fix FP incorrectStringBooleanError
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Aug 18, 2023
1 parent 5703aed commit 9107acc
Show file tree
Hide file tree
Showing 2 changed files with 8 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 @@ -294,7 +294,7 @@ void CheckString::checkIncorrectStringCompare()
incorrectStringBooleanError(tok->tokAt(2), tok->strAt(2));
} else if (tok->str() == "?" && Token::Match(tok->astOperand1(), "%str%|%char%")) {
incorrectStringBooleanError(tok->astOperand1(), tok->astOperand1()->str());
} else if (Token::Match(tok, "%str%") && isBooleanFuncArg(tok))
} else if (Token::Match(tok, "%str%") && isUsedAsBool(tok) && isBooleanFuncArg(tok))
incorrectStringBooleanError(tok, tok->str());
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/teststring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,13 @@ class TestString : public TestFixture {
" f(\"abc\");\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (warning) Conversion of string literal \"abc\" to bool always evaluates to true.\n", errout.str());

check("void g(bool);\n"
" void f(std::map<std::string, std::vector<int>>&m) {\n"
" if (m.count(\"abc\"))\n"
" g(m[\"abc\"][0] ? true : false);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}

void deadStrcmp() {
Expand Down

0 comments on commit 9107acc

Please sign in to comment.