diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index a6d24af60..77f4093cf 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -1498,6 +1498,8 @@ void CheckCondition::alwaysTrueFalse() continue; if (Token::simpleMatch(tok, ":")) continue; + if (Token::Match(tok->astOperand1(), "%name% (") && Token::simpleMatch(tok->astParent(), "return")) + continue; if (tok->isComparisonOp() && isWithoutSideEffects(mTokenizer->isCPP(), tok->astOperand1()) && isSameExpression(mTokenizer->isCPP(), true, diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 08d22e673..188cab433 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -3597,6 +3597,8 @@ void CheckOther::checkKnownArgument() continue; if (isConstVarExpression(tok)) continue; + if (Token::Match(tok->astOperand1(), "%name% (")) + continue; const Token * tok2 = tok; if (isCPPCast(tok2)) tok2 = tok2->astOperand2(); diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 2e5afa951..d34623184 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -4504,6 +4504,20 @@ private: " if (j == 1) {}\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("void h(int);\n" // #11679 + "bool g(int a) { h(a); return false; }\n" + "bool f(int i) {\n" + " return g(i);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + + check("void f(std::string a) {\n" // #11051 + " a = \"x\";\n" + " if (a == \"x\") {}\n" + " return a;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'a==\"x\"' is always true\n", errout.str()); } void alwaysTrueSymbolic() diff --git a/test/testother.cpp b/test/testother.cpp index 1530a3a36..439f1662d 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -10696,6 +10696,15 @@ private: " dostuff(self->maxsize * sizeof(intptr_t));\n" "}"); ASSERT_EQUALS("", errout.str()); + + // #11679 + check("bool g(int);\n" + "void h(int);\n" + "int k(int a) { h(a); return 0; }\n" + "void f(int i) {\n" + " if (g(k(i))) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void knownArgumentHiddenVariableExpression() {