Templates: better handling of 'X<class Y>' template instantiations. Ticket: #4544

This commit is contained in:
Daniel Marjamäki 2013-04-11 18:58:39 +02:00
parent e03a3946d0
commit e8fbd39efd
2 changed files with 20 additions and 8 deletions

View File

@ -1092,17 +1092,19 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
else if (indentlevel > 0 && Token::Match(tok3, "> [,>]"))
--indentlevel;
templateMatchPattern += tok3->str();
templateMatchPattern += " ";
templateMatchPattern += ' ';
if (indentlevel == 0 && Token::Match(tok3->previous(), "[<,]"))
typesUsedInTemplateInstantiation.push_back(tok3);
// add additional type information
if (tok3->isUnsigned())
typeForNewNameStr += "unsigned";
else if (tok3->isSigned())
typeForNewNameStr += "signed";
if (tok3->isLong())
typeForNewNameStr += "long";
typeForNewNameStr += tok3->str();
if (tok3->str() != "class") {
if (tok3->isUnsigned())
typeForNewNameStr += "unsigned";
else if (tok3->isSigned())
typeForNewNameStr += "signed";
if (tok3->isLong())
typeForNewNameStr += "long";
typeForNewNameStr += tok3->str();
}
}
templateMatchPattern += ">";
const std::string typeForNewName(typeForNewNameStr);

View File

@ -128,6 +128,7 @@ private:
TEST_CASE(template34); // #3706 - namespace => hang
TEST_CASE(template35); // #4074 - A<'x'> a;
TEST_CASE(template36); // #4310 - passing unknown template instantiation as template argument
TEST_CASE(template37); // #4544 - A<class B> a;
TEST_CASE(template_unhandled);
TEST_CASE(template_default_parameter);
TEST_CASE(template_default_type);
@ -2252,6 +2253,15 @@ private:
tok(code));
}
void template37() { // #4544 - A<class B> a;
const char code[] = "class A { };\n"
"template<class T> class B {};\n"
"B<class A> b1;\n"
"B<A> b2;";
ASSERT_EQUALS("class A { } ; B<A> b1 ; B<A> b2 ; class B<A> { }",
tok(code));
}
void template_unhandled() {
// An unhandled template usage should be simplified..
ASSERT_EQUALS("x<int> ( ) ;", tok("x<int>();"));