diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 823d2a85f..5199f5aac 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2671,11 +2671,16 @@ static void removeTemplates(Token *tok) if (!tok2) break; } - if (tok2->str() == ";") { + else if (tok2->str() == ";") { Token::eraseTokens(tok, tok2->next()); tok->str(";"); break; } + else if (Token::Match(tok2, ">|>> class %var% [,)]")) { + Token::eraseTokens(tok,tok2->next()); + tok->deleteThis(); + break; + } } } } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index c14bef598..8c41ad6fd 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -117,6 +117,7 @@ private: TEST_CASE(template24); // #2648 - using sizeof in template parameter TEST_CASE(template25); // #2648 - another test for sizeof template parameter TEST_CASE(template26); // #2721 - passing 'char[2]' as template parameter + TEST_CASE(template27); // #3350 - removing unused template in macro call TEST_CASE(template_unhandled); TEST_CASE(template_default_parameter); TEST_CASE(template_default_type); @@ -2095,6 +2096,12 @@ private: ASSERT_EQUALS("; C<2> a ; class C<2> : public A < char [ 2 ] > { }", sizeof_(code)); } + void template27() { + // #3350 - template inside macro call + const char code[] = "X(template class Fred);"; + ASSERT_EQUALS("X ( class Fred ) ;", sizeof_(code)); + } + void template_unhandled() { // An unhandled template usage should be simplified.. ASSERT_EQUALS("; x ( ) ;", sizeof_(";x();"));