@@ -1637,23 +1637,41 @@ void CheckStl::missingComparison()
16371637 }
16381638
16391639 const Token *incrementToken = nullptr ;
1640+ bool bComparedInAdvance = false ;
16401641
16411642 // Parse loop..
1642- for (const Token *tok3 = scope.bodyStart ; tok3 != scope.bodyEnd ; tok3 = tok3->next ()) {
1643- if (Token::Match (tok3, " %varid% ++" , iteratorId))
1644- incrementToken = tok3;
1645- else if (Token::Match (tok3->previous (), " ++ %varid% !!." , iteratorId))
1646- incrementToken = tok3;
1647- else if (Token::Match (tok3, " %varid% !=|==" , iteratorId))
1648- incrementToken = nullptr ;
1643+ for (const Token *tok3 = scope.bodyStart ; tok3 != scope.bodyEnd ; tok3 = tok3->next ())
1644+ {
1645+ if (tok3->varId () == iteratorId)
1646+ {
1647+ if (Token::Match (tok3, " %varid% = %name% . insert ( ++| %varid% ++| ," , iteratorId))
1648+ {
1649+ // skip insertion..
1650+ tok3 = tok3->linkAt (6 );
1651+ if (!tok3)
1652+ break ;
1653+ }
1654+ else if (Token::simpleMatch (tok3->astParent (), " ++" ))
1655+ {
1656+ if (!bComparedInAdvance)
1657+ incrementToken = tok3;
1658+ else
1659+ bComparedInAdvance = false ;
1660+ }
1661+ else if (Token::simpleMatch (tok3->astParent (), " +" ))
1662+ {
1663+ if (Token::simpleMatch (tok3->astSibling (), " 1" ))
1664+ {
1665+ const Token* tokenGrandParent = tok3->astParent ()->astParent ();
1666+ if (Token::Match (tokenGrandParent, " ==|!=" ))
1667+ bComparedInAdvance = true ;
1668+ }
1669+ }
1670+ else if (Token::Match (tok3->astParent (), " ==|!=" ))
1671+ incrementToken = nullptr ;
1672+ }
16491673 else if (tok3->str () == " break" || tok3->str () == " return" )
16501674 incrementToken = nullptr ;
1651- else if (Token::Match (tok3, " %varid% = %name% . insert ( ++| %varid% ++| ," , iteratorId)) {
1652- // skip insertion..
1653- tok3 = tok3->linkAt (6 );
1654- if (!tok3)
1655- break ;
1656- }
16571675 }
16581676 if (incrementToken)
16591677 missingComparisonError (incrementToken, tok2->tokAt (16 ));
0 commit comments