Permalink
Browse files

Templates: better handling of 'X<class Y>' template instantiations. T…

…icket: #4544
  • Loading branch information...
1 parent e03a394 commit e8fbd39efda8e183d5e2ce26ce2a5f3c8482ef3c @danmar committed Apr 11, 2013
Showing with 20 additions and 8 deletions.
  1. +10 −8 lib/templatesimplifier.cpp
  2. +10 −0 test/testsimplifytokens.cpp
@@ -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);
@@ -128,6 +128,7 @@ class TestSimplifyTokens : public TestFixture {
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 @@ class TestSimplifyTokens : public TestFixture {
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>();"));

0 comments on commit e8fbd39

Please sign in to comment.