diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 70fa4d9ae33..bc1df36aacc 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -716,7 +716,7 @@ void CheckCondition::multiCondition2() // Condition.. const Token *cond2 = tok->str() == "if" ? condStartToken->astOperand2() : condStartToken->astOperand1(); - const bool isReturnVar = (tok->str() == "return" && !Token::Match(cond2, "%cop%")); + const bool isReturnVar = (tok->str() == "return" && (!Token::Match(cond2, "%cop%") || (cond2 && cond2->isUnaryOp("!")))); ErrorPath errorPath; diff --git a/test/testcondition.cpp b/test/testcondition.cpp index db044308c71..1a535ff0bf0 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -2129,6 +2129,15 @@ class TestCondition : public TestFixture { " bool m_value = false;\n" "};"); ASSERT_EQUALS("", errout_str()); + + // #12725 + check("bool f(bool b) {\n" + " if (b)\n" + " return !b;\n" + " b = g();\n" + " return b;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Return value '!b' is always false\n", errout_str()); } void oppositeInnerConditionPointers() {