Fixed #1357 (problem in stl insert method of set template)
This commit is contained in:
parent
3152816619
commit
7763d25847
|
@ -67,7 +67,20 @@ void CheckStl::iterators()
|
||||||
else if (Token::Match(tok2, "%var% . insert|erase ( %varid% )|,", iteratorId))
|
else if (Token::Match(tok2, "%var% . insert|erase ( %varid% )|,", iteratorId))
|
||||||
{
|
{
|
||||||
if (tok2->varId() != containerId && tok2->tokAt(5)->str() != ".")
|
if (tok2->varId() != containerId && tok2->tokAt(5)->str() != ".")
|
||||||
|
{
|
||||||
|
// skip error message if container is a set..
|
||||||
|
if (tok2->varId() > 0)
|
||||||
|
{
|
||||||
|
const Token *decltok = Token::findmatch(_tokenizer->tokens(), "%varid%", tok2->varId());
|
||||||
|
while (decltok && !Token::Match(decltok, "[;{},(]"))
|
||||||
|
decltok = decltok->previous();
|
||||||
|
if (Token::Match(decltok, "%any% const| std :: set"))
|
||||||
|
continue; // No warning
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show error message, mismatching iterator is used.
|
||||||
iteratorsError(tok2, tok->strAt(2), tok2->str());
|
iteratorsError(tok2, tok->strAt(2), tok2->str());
|
||||||
|
}
|
||||||
else if (tok2->strAt(2) == std::string("erase"))
|
else if (tok2->strAt(2) == std::string("erase"))
|
||||||
validIterator = false;
|
validIterator = false;
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ private:
|
||||||
TEST_CASE(iterator3);
|
TEST_CASE(iterator3);
|
||||||
TEST_CASE(iterator4);
|
TEST_CASE(iterator4);
|
||||||
TEST_CASE(iterator5);
|
TEST_CASE(iterator5);
|
||||||
|
TEST_CASE(iterator6);
|
||||||
|
|
||||||
TEST_CASE(dereference);
|
TEST_CASE(dereference);
|
||||||
TEST_CASE(dereference_member);
|
TEST_CASE(dereference_member);
|
||||||
|
@ -163,6 +164,19 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) mismatching containers\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (error) mismatching containers\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void iterator6()
|
||||||
|
{
|
||||||
|
// Ticket #1357
|
||||||
|
check("void foo(const std::set<int> &ints1)\n"
|
||||||
|
"{\n"
|
||||||
|
" std::set<int> ints2;\n"
|
||||||
|
" std::set<int>::iterator it1 = ints1.begin();\n"
|
||||||
|
" std::set<int>::iterator it2 = ints1.end();\n"
|
||||||
|
" ints2.insert(it1, it2);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
// Dereferencing invalid pointer
|
// Dereferencing invalid pointer
|
||||||
void dereference()
|
void dereference()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue