templates: instantiations in a template class (#280)

This commit is contained in:
Daniel Marjamäki 2009-05-06 21:03:11 +02:00
parent 177aeba0cf
commit 51beadd81c
2 changed files with 32 additions and 11 deletions

View File

@ -483,8 +483,34 @@ void Tokenizer::simplifyTemplates()
std::list<Token *> used;
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (Token::Match(tok, "%var% <") && tok->str() != "template")
// template definition.. skip it
if (Token::simpleMatch(tok, "template <"))
{
unsigned int indentlevel = 0;
for (; tok; tok = tok->next())
{
if (tok->str() == "{")
{
++indentlevel;
}
else if (tok->str() == "}")
{
if (indentlevel <= 1)
break;
--indentlevel;
}
else if (indentlevel == 0 && tok->str() == ";")
{
break;
}
}
if (!tok)
break;
}
else if (Token::Match(tok, "%var% <"))
{
used.push_back(tok);
}
}
if (used.empty())
return;

View File

@ -579,7 +579,7 @@ private:
void template7()
{
// Typedef
// A template class that is not used => no simplification
{
const char code[] = "template <class T>\n"
"class ABC\n"
@ -587,21 +587,16 @@ private:
"public:\n"
" typedef ABC<T> m;\n"
"\n"
"};\n"
"\n"
"int main()\n"
"{}\n";
"};\n";
const std::string expected(" template < class T > "
"class ABC "
"{ "
"public: "
"typedef ABC<T> m ; "
"} ; "
"int main ( )"
" { }");
"typedef ABC < T > m ; "
"} ;");
TODO_ASSERT_EQUALS(expected, sizeof_(code));
ASSERT_EQUALS(expected, sizeof_(code));
}
{