File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -594,12 +594,14 @@ void CheckCondition::multiCondition2()
594594 if (!Token::simpleMatch (scope.classDef ->linkAt (1 ), " ) {" ))
595595 continue ;
596596
597+ bool functionCall = false ;
597598 bool nonConstFunctionCall = false ;
598599 bool nonlocal = false ; // nonlocal variable used in condition
599600 std::set<int > vars; // variables used in condition
600601 visitAstNodes (condTok,
601602 [&](const Token *cond) {
602603 if (Token::Match (cond, " %name% (" )) {
604+ functionCall = true ;
603605 nonConstFunctionCall = isNonConstFunctionCall (cond, mSettings ->library );
604606 if (nonConstFunctionCall)
605607 return ChildrenToVisit::done;
@@ -755,7 +757,8 @@ void CheckCondition::multiCondition2()
755757 break ;
756758 }
757759 if ((tok->varId () && vars.find (tok->varId ()) != vars.end ()) ||
758- (!tok->varId () && nonlocal)) {
760+ (!tok->varId () && nonlocal) ||
761+ (functionCall && tok->variable () && !tok->variable ()->isLocal ())) {
759762 if (Token::Match (tok, " %name% %assign%|++|--" ))
760763 break ;
761764 if (Token::Match (tok->astParent (), " *|.|[" )) {
Original file line number Diff line number Diff line change @@ -1921,6 +1921,19 @@ class TestCondition : public TestFixture {
19211921 " }\n "
19221922 " }" );
19231923 ASSERT_EQUALS (" " , errout.str ());
1924+
1925+ // #9702
1926+ check (" struct A {\n "
1927+ " void DoTest() {\n "
1928+ " if (!IsSet()) {\n "
1929+ " m_value = true;\n "
1930+ " if (IsSet());\n "
1931+ " }\n "
1932+ " }\n "
1933+ " bool IsSet() const { return m_value; }\n "
1934+ " bool m_value = false;\n "
1935+ " };" );
1936+ ASSERT_EQUALS (" " , errout.str ());
19241937 }
19251938
19261939 void oppositeInnerConditionPointers () {
You can’t perform that action at this time.
0 commit comments