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; std::list<Token *> used;
for (Token *tok = _tokens; tok; tok = tok->next()) 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); used.push_back(tok);
}
} }
if (used.empty()) if (used.empty())
return; return;

View File

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