Made missing comparison in loop check more generic (#3048)
This commit is contained in:
parent
65395aeaa1
commit
b97387db66
|
@ -1732,8 +1732,6 @@ void CheckStl::missingComparison()
|
||||||
}
|
}
|
||||||
|
|
||||||
const Token *incrementToken = nullptr;
|
const Token *incrementToken = nullptr;
|
||||||
bool bComparedInAdvance = false;
|
|
||||||
|
|
||||||
// Parse loop..
|
// Parse loop..
|
||||||
for (const Token *tok3 = scope.bodyStart; tok3 != scope.bodyEnd; tok3 = tok3->next()) {
|
for (const Token *tok3 = scope.bodyStart; tok3 != scope.bodyEnd; tok3 = tok3->next()) {
|
||||||
if (tok3->varId() == iteratorId) {
|
if (tok3->varId() == iteratorId) {
|
||||||
|
@ -1742,16 +1740,13 @@ void CheckStl::missingComparison()
|
||||||
tok3 = tok3->linkAt(6);
|
tok3 = tok3->linkAt(6);
|
||||||
if (!tok3)
|
if (!tok3)
|
||||||
break;
|
break;
|
||||||
} else if (Token::simpleMatch(tok3->astParent(), "++")) {
|
} else if (Token::simpleMatch(tok3->astParent(), "++"))
|
||||||
if (!bComparedInAdvance)
|
|
||||||
incrementToken = tok3;
|
incrementToken = tok3;
|
||||||
else
|
else if (Token::simpleMatch(tok3->astParent(), "+")) {
|
||||||
bComparedInAdvance = false;
|
if (Token::Match(tok3->astSibling(), "%num%")) {
|
||||||
} else if (Token::simpleMatch(tok3->astParent(), "+")) {
|
|
||||||
if (Token::simpleMatch(tok3->astSibling(), "1")) {
|
|
||||||
const Token* tokenGrandParent = tok3->astParent()->astParent();
|
const Token* tokenGrandParent = tok3->astParent()->astParent();
|
||||||
if (Token::Match(tokenGrandParent, "==|!="))
|
if (Token::Match(tokenGrandParent, "==|!="))
|
||||||
bComparedInAdvance = true;
|
break;
|
||||||
}
|
}
|
||||||
} else if (Token::Match(tok3->astParent(), "==|!="))
|
} else if (Token::Match(tok3->astParent(), "==|!="))
|
||||||
incrementToken = nullptr;
|
incrementToken = nullptr;
|
||||||
|
|
|
@ -3004,8 +3004,11 @@ private:
|
||||||
|
|
||||||
check("void f(const std::vector<std::string> &v) {\n"
|
check("void f(const std::vector<std::string> &v) {\n"
|
||||||
" for(std::vector<std::string>::const_iterator it = v.begin(); it != v.end(); ++it) {\n"
|
" for(std::vector<std::string>::const_iterator it = v.begin(); it != v.end(); ++it) {\n"
|
||||||
" if(it+1 != v.end())\n"
|
" if(it+2 != v.end())\n"
|
||||||
|
" {\n"
|
||||||
" ++it;\n"
|
" ++it;\n"
|
||||||
|
" ++it;\n"
|
||||||
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
Loading…
Reference in New Issue