push_back: updated the checking of push_back (#263)
This commit is contained in:
parent
49430afabe
commit
ebd15cec0f
|
@ -232,7 +232,10 @@ void CheckStl::pushback()
|
||||||
break;
|
break;
|
||||||
if (Token::Match(tok, "> :: iterator|const_iterator %var% =|;"))
|
if (Token::Match(tok, "> :: iterator|const_iterator %var% =|;"))
|
||||||
{
|
{
|
||||||
const std::string iteratorname(tok->strAt(3));
|
const unsigned int iteratorid(tok->tokAt(3)->varId());
|
||||||
|
if (iteratorid == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
std::string vectorname;
|
std::string vectorname;
|
||||||
int indent = 0;
|
int indent = 0;
|
||||||
bool invalidIterator = false;
|
bool invalidIterator = false;
|
||||||
|
@ -249,7 +252,7 @@ void CheckStl::pushback()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assigning iterator..
|
// Assigning iterator..
|
||||||
if (Token::Match(tok2, (iteratorname + " = %var% . begin ( )").c_str()))
|
if (Token::Match(tok2, "%varid% = %var% . begin ( )", iteratorid))
|
||||||
{
|
{
|
||||||
vectorname = tok2->strAt(2);
|
vectorname = tok2->strAt(2);
|
||||||
invalidIterator = false;
|
invalidIterator = false;
|
||||||
|
@ -262,10 +265,10 @@ void CheckStl::pushback()
|
||||||
// Using invalid iterator..
|
// Using invalid iterator..
|
||||||
if (invalidIterator)
|
if (invalidIterator)
|
||||||
{
|
{
|
||||||
if (Token::Match(tok2, ("++|--|*|+|-|(|, " + iteratorname).c_str()))
|
if (Token::Match(tok2, "++|--|*|+|-|(|, %varid%", iteratorid))
|
||||||
pushbackError(tok2, iteratorname);
|
pushbackError(tok2, tok2->strAt(1));
|
||||||
if (Token::Match(tok2, (iteratorname + " ++|--|+|-").c_str()))
|
if (Token::Match(tok2, "%varid% ++|--|+|-", iteratorid))
|
||||||
pushbackError(tok2, iteratorname);
|
pushbackError(tok2, tok2->str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,7 @@ private:
|
||||||
Tokenizer tokenizer;
|
Tokenizer tokenizer;
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
tokenizer.tokenize(istr, "test.cpp");
|
||||||
|
tokenizer.setVarId();
|
||||||
|
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
@ -260,7 +261,7 @@ private:
|
||||||
" *it = 456;\n"
|
" *it = 456;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
TODO_ASSERT_EQUALS("", errout.str()); // Ticket #262
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void pushback3()
|
void pushback3()
|
||||||
|
|
Loading…
Reference in New Issue