Fixed #2451 (False positive when incrementing map value via iterator)
This commit is contained in:
parent
708a75e363
commit
00b49a51da
|
@ -962,11 +962,11 @@ void CheckStl::missingComparison()
|
||||||
break;
|
break;
|
||||||
--indentlevel;
|
--indentlevel;
|
||||||
}
|
}
|
||||||
else if (tok3->varId() == iteratorId && Token::simpleMatch(tok3->next(), "++"))
|
else if (Token::Match(tok3, "%varid% ++", iteratorId))
|
||||||
incrementToken = tok3;
|
incrementToken = tok3;
|
||||||
else if (tok3->str() == "++" && tok3->next() && tok3->next()->varId() == iteratorId)
|
else if (Token::Match(tok3->previous(), "++ %varid% !!.", iteratorId))
|
||||||
incrementToken = tok3;
|
incrementToken = tok3;
|
||||||
else if (tok3->varId() == iteratorId && Token::Match(tok3->next(), "!=|=="))
|
else if (Token::Match(tok3, "%varid% !=|==", iteratorId))
|
||||||
incrementToken = 0;
|
incrementToken = 0;
|
||||||
else if (tok3->str() == "break" || tok3->str() == "return")
|
else if (tok3->str() == "break" || tok3->str() == "return")
|
||||||
incrementToken = 0;
|
incrementToken = 0;
|
||||||
|
|
|
@ -1080,6 +1080,13 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (warning) Missing bounds check for extra iterator increment in loop.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (warning) Missing bounds check for extra iterator increment in loop.\n", errout.str());
|
||||||
|
|
||||||
|
check("void f(std::map<int,int> &ints) {\n"
|
||||||
|
" for (std::map<int,int>::iterator it = ints.begin(); it != ints.end(); ++it) {\n"
|
||||||
|
" ++it->second;\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void missingInnerComparison2()
|
void missingInnerComparison2()
|
||||||
|
|
Loading…
Reference in New Issue