Fixed #9060 (TemplateSimplifier::templateParameters : var <...>)

This commit is contained in:
Daniel Marjamäki 2019-03-31 16:29:28 +02:00
parent 0efddc4010
commit fbc769266c
2 changed files with 11 additions and 2 deletions

View File

@ -320,6 +320,8 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
return 0;
if (tok->str() != "<")
return 0;
if (Token::Match(tok->previous(), "%var% <"))
return 0;
tok = tok->next();
unsigned int level = 0;
@ -412,11 +414,11 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
// ,/>
while (Token::Match(tok, ">|>>")) {
if (level == 0)
return ((tok->str() == ">") ? numberOfParameters : 0);
return tok->str() == ">" && !Token::Match(tok->next(), "%num%") ? numberOfParameters : 0;
--level;
if (tok->str() == ">>") {
if (level == 0)
return numberOfParameters;
return !Token::Match(tok->next(), "%num%") ? numberOfParameters : 0;
--level;
}
tok = tok->next();

View File

@ -3016,6 +3016,11 @@ private:
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp", "");
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
if (tok->str() == "var1")
(const_cast<Token *>(tok))->varId(1);
}
return TemplateSimplifier::templateParameters(tokenizer.tokens()->next());
}
@ -3041,6 +3046,8 @@ private:
ASSERT_EQUALS(1U, templateParameters("X<i == 0> x;"));
ASSERT_EQUALS(2U, templateParameters("X<int, i>=0> x;"));
ASSERT_EQUALS(3U, templateParameters("X<int, i>=0, i - 2> x;"));
ASSERT_EQUALS(0U, templateParameters("var1<1> x;"));
ASSERT_EQUALS(0U, templateParameters("X<1>2;"));
}
// Helper function to unit test TemplateSimplifier::getTemplateNamePosition