Robert Reif: Fixed #1163 (post increment test broken for complex template types)
This commit is contained in:
parent
160f795710
commit
71b328d703
|
@ -1426,21 +1426,60 @@ void Tokenizer::setVarId()
|
|||
// Skip template arguments..
|
||||
if (Token::Match(tok, "%type% <"))
|
||||
{
|
||||
int level = 1;
|
||||
bool again;
|
||||
Token *tok2 = tok->tokAt(2);
|
||||
|
||||
do // Look for start of templates or template arguments
|
||||
{
|
||||
again = false;
|
||||
|
||||
while (Token::Match(tok2, "%var% ::"))
|
||||
tok2 = tok2->tokAt(2);
|
||||
|
||||
if (Token::Match(tok2, "%type% <"))
|
||||
{
|
||||
level++;
|
||||
tok2 = tok2->tokAt(2);
|
||||
again = true;
|
||||
}
|
||||
else if (Token::Match(tok2, "%type% ,"))
|
||||
{
|
||||
tok2 = tok2->tokAt(2);
|
||||
again = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (tok2 && (tok2->isName() || tok2->isNumber() || tok2->str() == "*" || tok2->str() == ","))
|
||||
tok2 = tok2->next();
|
||||
}
|
||||
}
|
||||
while (again);
|
||||
|
||||
if (Token::Match(tok2, "> %var%"))
|
||||
do // Look for end of templates
|
||||
{
|
||||
again = false;
|
||||
|
||||
if (level == 1 && Token::Match(tok2, "> %var%"))
|
||||
tok = tok2;
|
||||
else if (Token::Match(tok2, "> ::|*|& %var%"))
|
||||
else if (level > 1 && tok2->str() == ">")
|
||||
{
|
||||
level--;
|
||||
if (level == 0)
|
||||
tok = tok2;
|
||||
else
|
||||
{
|
||||
tok2 = tok2->tokAt(1);
|
||||
again = true;
|
||||
}
|
||||
}
|
||||
else if (level == 1 && Token::Match(tok2, "> ::|*|& %var%"))
|
||||
tok = tok2->next();
|
||||
else
|
||||
continue; // Not code that I understand / not a variable declaration
|
||||
}
|
||||
while (again);
|
||||
}
|
||||
|
||||
// Determine name of declared variable..
|
||||
const char *varname = 0;
|
||||
|
|
|
@ -1550,6 +1550,22 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Decrementing variable 'it' is preferred to Post-Decrementing\n"
|
||||
"[test.cpp:6]: (possible style) Pre-Decrementing variable 'it' is preferred to Post-Decrementing\n", errout.str());
|
||||
|
||||
checkpostIncrementDecrement("void f1()\n"
|
||||
"{\n"
|
||||
" std::list<std::vector<int> >::iterator it;\n"
|
||||
" for (it = ab.begin(); it != ab.end(); it++)\n"
|
||||
" ;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str());
|
||||
|
||||
checkpostIncrementDecrement("void f1()\n"
|
||||
"{\n"
|
||||
" std::map<int, std::vector<int> >::iterator it;\n"
|
||||
" for (it = ab.begin(); it != ab.end(); it++)\n"
|
||||
" ;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (possible style) Pre-Incrementing variable 'it' is preferred to Post-Incrementing\n", errout.str());
|
||||
}
|
||||
|
||||
void postIncrementDecrementClass()
|
||||
|
|
Loading…
Reference in New Issue