parent
da198e0726
commit
a4a225203c
|
@ -1637,23 +1637,41 @@ void CheckStl::missingComparison()
|
|||
}
|
||||
|
||||
const Token *incrementToken = nullptr;
|
||||
bool bComparedInAdvance = false;
|
||||
|
||||
// Parse loop..
|
||||
for (const Token *tok3 = scope.bodyStart; tok3 != scope.bodyEnd; tok3 = tok3->next()) {
|
||||
if (Token::Match(tok3, "%varid% ++", iteratorId))
|
||||
incrementToken = tok3;
|
||||
else if (Token::Match(tok3->previous(), "++ %varid% !!.", iteratorId))
|
||||
incrementToken = tok3;
|
||||
else if (Token::Match(tok3, "%varid% !=|==", iteratorId))
|
||||
incrementToken = nullptr;
|
||||
else if (tok3->str() == "break" || tok3->str() == "return")
|
||||
incrementToken = nullptr;
|
||||
else if (Token::Match(tok3, "%varid% = %name% . insert ( ++| %varid% ++| ,", iteratorId)) {
|
||||
for (const Token *tok3 = scope.bodyStart; tok3 != scope.bodyEnd; tok3 = tok3->next())
|
||||
{
|
||||
if (tok3->varId() == iteratorId)
|
||||
{
|
||||
if (Token::Match(tok3, "%varid% = %name% . insert ( ++| %varid% ++| ,", iteratorId))
|
||||
{
|
||||
// skip insertion..
|
||||
tok3 = tok3->linkAt(6);
|
||||
if (!tok3)
|
||||
break;
|
||||
}
|
||||
else if (Token::simpleMatch(tok3->astParent(), "++"))
|
||||
{
|
||||
if (!bComparedInAdvance)
|
||||
incrementToken = tok3;
|
||||
else
|
||||
bComparedInAdvance = false;
|
||||
}
|
||||
else if (Token::simpleMatch(tok3->astParent(), "+"))
|
||||
{
|
||||
if (Token::simpleMatch(tok3->astSibling(), "1"))
|
||||
{
|
||||
const Token* tokenGrandParent = tok3->astParent()->astParent();
|
||||
if (Token::Match(tokenGrandParent, "==|!="))
|
||||
bComparedInAdvance = true;
|
||||
}
|
||||
}
|
||||
else if (Token::Match(tok3->astParent(), "==|!="))
|
||||
incrementToken = nullptr;
|
||||
}
|
||||
else if (tok3->str() == "break" || tok3->str() == "return")
|
||||
incrementToken = nullptr;
|
||||
}
|
||||
if (incrementToken)
|
||||
missingComparisonError(incrementToken, tok2->tokAt(16));
|
||||
|
|
|
@ -2986,6 +2986,14 @@ private:
|
|||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
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"
|
||||
" if(it+1 != v.end())\n"
|
||||
" ++it;\n"
|
||||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void missingInnerComparison2() {
|
||||
|
|
Loading…
Reference in New Issue