Fixed #2631 (Tokenizer::simplifyTemplates: template usage 'std::cout << (foo<double>(r));')
This commit is contained in:
parent
8e571c04e4
commit
7496cd412c
|
@ -2684,11 +2684,23 @@ std::list<Token *> Tokenizer::simplifyTemplatesGetTemplateInstantiations()
|
||||||
// template definition.. skip it
|
// template definition.. skip it
|
||||||
if (Token::simpleMatch(tok, "template <"))
|
if (Token::simpleMatch(tok, "template <"))
|
||||||
{
|
{
|
||||||
|
unsigned int level = 0;
|
||||||
|
|
||||||
// Goto the end of the template definition
|
// Goto the end of the template definition
|
||||||
for (; tok; tok = tok->next())
|
for (; tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
|
// skip '<' .. '>'
|
||||||
|
if (tok->str() == "<")
|
||||||
|
++level;
|
||||||
|
else if (tok->str() == ">")
|
||||||
|
{
|
||||||
|
if (level <= 1)
|
||||||
|
break;
|
||||||
|
--level;
|
||||||
|
}
|
||||||
|
|
||||||
// skip inner '(' .. ')' and '{' .. '}'
|
// skip inner '(' .. ')' and '{' .. '}'
|
||||||
if (tok->str() == "{" || tok->str() == "(")
|
else if (tok->str() == "{" || tok->str() == "(")
|
||||||
{
|
{
|
||||||
// skip inner tokens. goto ')' or '}'
|
// skip inner tokens. goto ')' or '}'
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
|
@ -3217,7 +3229,7 @@ void Tokenizer::simplifyTemplates()
|
||||||
//while (!done)
|
//while (!done)
|
||||||
{
|
{
|
||||||
done = true;
|
done = true;
|
||||||
for (std::list<Token *>::const_iterator iter1 = templates.begin(); iter1 != templates.end(); ++iter1)
|
for (std::list<Token *>::reverse_iterator iter1 = templates.rbegin(); iter1 != templates.rend(); ++iter1)
|
||||||
{
|
{
|
||||||
simplifyTemplatesInstantiate(*iter1, used, expandedtemplates);
|
simplifyTemplatesInstantiate(*iter1, used, expandedtemplates);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1714,7 +1714,7 @@ private:
|
||||||
"} ;\n";
|
"} ;\n";
|
||||||
|
|
||||||
// The expected result..
|
// The expected result..
|
||||||
std::string expected("; void f ( ) { A<int> a ; } ; class A<int> { }");
|
std::string expected("; void f ( ) { A<int> a ; } ; class A<int> { } class A<T> { }");
|
||||||
|
|
||||||
ASSERT_EQUALS(expected, sizeof_(code));
|
ASSERT_EQUALS(expected, sizeof_(code));
|
||||||
}
|
}
|
||||||
|
@ -1868,18 +1868,13 @@ private:
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
const std::string wanted("; "
|
const std::string expected("; "
|
||||||
"; "
|
"int main ( ) { b<2> ( ) ; return 0 ; } "
|
||||||
"int main ( ) { b<2> ( ) ; return 0 ; } "
|
"void b<2> ( ) { a<2> ( ) ; } "
|
||||||
"void b<2> ( ) { a<2> ( ) ; } "
|
"void a<i> ( ) { } "
|
||||||
"void a<2> ( ) { }");
|
"void a<2> ( ) { }");
|
||||||
|
|
||||||
const std::string current("; "
|
ASSERT_EQUALS(expected, sizeof_(code));
|
||||||
"int main ( ) { b<2> ( ) ; return 0 ; } "
|
|
||||||
"void b<2> ( ) { a < 2 > ( ) ; }"
|
|
||||||
);
|
|
||||||
|
|
||||||
TODO_ASSERT_EQUALS(wanted, current, sizeof_(code));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void template17()
|
void template17()
|
||||||
|
|
Loading…
Reference in New Issue