Skip to content

Commit fc2f551

Browse files
Fix #13067 FP incorrectStringBooleanError for macro argument (cppcheck-opensource#6770)
1 parent c2f4c5c commit fc2f551

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/checkstring.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ void CheckString::strPlusCharError(const Token *tok)
254254
static bool isMacroUsage(const Token* tok)
255255
{
256256
if (const Token* parent = tok->astParent()) {
257-
while (parent && parent->isCast())
257+
while (parent && (parent->isCast() || parent->str() == "&&"))
258258
parent = parent->astParent();
259259
if (!parent)
260260
return false;

test/teststring.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,12 @@ class TestString : public TestFixture {
802802
" }\n"
803803
"};\n");
804804
ASSERT_EQUALS("[test.cpp:4]: (warning) Conversion of string literal \"test.C\" to bool always evaluates to true.\n", errout_str());
805+
806+
check("#define MACRO(C) if(!(C)) { error(__FILE__, __LINE__, __FUNCTION__, #C); return; }\n" // #13067
807+
"void f() {\n"
808+
" MACRO(false && \"abc\");\n"
809+
"}\n");
810+
ASSERT_EQUALS("", errout_str());
805811
}
806812

807813
void deadStrcmp() {

0 commit comments

Comments
 (0)