File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -716,7 +716,7 @@ void CheckCondition::multiCondition2()
716716
717717 // Condition..
718718 const Token *cond2 = tok->str () == " if" ? condStartToken->astOperand2 () : condStartToken->astOperand1 ();
719- const bool isReturnVar = (tok->str () == " return" && !Token::Match (cond2, " %cop%" ));
719+ const bool isReturnVar = (tok->str () == " return" && ( !Token::Match (cond2, " %cop%" ) || (cond2 && cond2-> isUnaryOp ( " ! " )) ));
720720
721721 ErrorPath errorPath;
722722
Original file line number Diff line number Diff line change @@ -2129,6 +2129,15 @@ class TestCondition : public TestFixture {
21292129 " bool m_value = false;\n "
21302130 " };" );
21312131 ASSERT_EQUALS (" " , errout_str ());
2132+
2133+ // #12725
2134+ check (" bool f(bool b) {\n "
2135+ " if (b)\n "
2136+ " return !b;\n "
2137+ " b = g();\n "
2138+ " return b;\n "
2139+ " }\n " );
2140+ ASSERT_EQUALS (" [test.cpp:2] -> [test.cpp:3]: (style) Return value '!b' is always false\n " , errout_str ());
21322141 }
21332142
21342143 void oppositeInnerConditionPointers () {
You can’t perform that action at this time.
0 commit comments