Fixed #9060 (TemplateSimplifier::templateParameters : var <...>)
This commit is contained in:
parent
0efddc4010
commit
fbc769266c
|
@ -320,6 +320,8 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
|
||||||
return 0;
|
return 0;
|
||||||
if (tok->str() != "<")
|
if (tok->str() != "<")
|
||||||
return 0;
|
return 0;
|
||||||
|
if (Token::Match(tok->previous(), "%var% <"))
|
||||||
|
return 0;
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
||||||
unsigned int level = 0;
|
unsigned int level = 0;
|
||||||
|
@ -412,11 +414,11 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
|
||||||
// ,/>
|
// ,/>
|
||||||
while (Token::Match(tok, ">|>>")) {
|
while (Token::Match(tok, ">|>>")) {
|
||||||
if (level == 0)
|
if (level == 0)
|
||||||
return ((tok->str() == ">") ? numberOfParameters : 0);
|
return tok->str() == ">" && !Token::Match(tok->next(), "%num%") ? numberOfParameters : 0;
|
||||||
--level;
|
--level;
|
||||||
if (tok->str() == ">>") {
|
if (tok->str() == ">>") {
|
||||||
if (level == 0)
|
if (level == 0)
|
||||||
return numberOfParameters;
|
return !Token::Match(tok->next(), "%num%") ? numberOfParameters : 0;
|
||||||
--level;
|
--level;
|
||||||
}
|
}
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
|
@ -3016,6 +3016,11 @@ private:
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, "test.cpp", "");
|
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());
|
return TemplateSimplifier::templateParameters(tokenizer.tokens()->next());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3041,6 +3046,8 @@ private:
|
||||||
ASSERT_EQUALS(1U, templateParameters("X<i == 0> x;"));
|
ASSERT_EQUALS(1U, templateParameters("X<i == 0> x;"));
|
||||||
ASSERT_EQUALS(2U, templateParameters("X<int, 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(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
|
// Helper function to unit test TemplateSimplifier::getTemplateNamePosition
|
||||||
|
|
Loading…
Reference in New Issue