diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 82fcb2ecf3e..82b8a71946d 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2246,7 +2246,7 @@ T* getTokenArgumentFunctionImpl(T* tok, int& argn) parent = parent->astParent(); // passing variable to subfunction? - if (Token::Match(parent, "[*[(,{]")) + if (Token::Match(parent, "[*[(,{]") || Token::Match(parent, "%oror%|&&")) ; else if (Token::simpleMatch(parent, ":")) { while (Token::Match(parent, "[?:]")) diff --git a/lib/checkstring.cpp b/lib/checkstring.cpp index 6b230b1d979..34388ab1d2f 100644 --- a/lib/checkstring.cpp +++ b/lib/checkstring.cpp @@ -255,9 +255,13 @@ void CheckString::strPlusCharError(const Token *tok) static bool isMacroUsage(const Token* tok) { if (const Token* parent = tok->astParent()) { + while (parent && parent->isCast()) + parent = parent->astParent(); + if (!parent) + return false; if (parent->isExpandedMacro()) return true; - if (parent->isUnaryOp("!")) { + if (parent->isUnaryOp("!") || parent->isComparisonOp()) { int argn{}; const Token* ftok = getTokenArgumentFunction(parent, argn); if (ftok && !ftok->function()) diff --git a/test/teststring.cpp b/test/teststring.cpp index e94f969034d..0ef10600797 100644 --- a/test/teststring.cpp +++ b/test/teststring.cpp @@ -799,6 +799,12 @@ class TestString : public TestFixture { " return false;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("void f(const int* p, const int* q) {\n" + " assert((p != NULL && q != NULL) || !\"abc\");\n" + " ASSERT((void*)(\"def\") == 0);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void deadStrcmp() {