@@ -435,12 +435,8 @@ std::set<std::string> TemplateSimplifier::expandSpecialized(Token *tokens)
435435 s = ostr.str ();
436436 }
437437
438- // save search pattern..
439- const std::string pattern (s + " >" );
440-
441438 // remove spaces to create new name
442- s.erase (std::remove (s.begin (), s.end (), ' ' ), s.end ());
443- const std::string name (s + " >" );
439+ const std::string name (s + " >" );
444440 expandedtemplates.insert (name);
445441
446442 // Rename template..
@@ -452,7 +448,7 @@ std::set<std::string> TemplateSimplifier::expandSpecialized(Token *tokens)
452448 tok->deleteThis ();
453449
454450 // Use this special template in the code..
455- while (nullptr != (tok2 = const_cast <Token *>(Token::findsimplematch (tok2, pattern .c_str ())))) {
451+ while (nullptr != (tok2 = const_cast <Token *>(Token::findsimplematch (tok2, name .c_str ())))) {
456452 Token::eraseTokens (tok2, Token::findsimplematch (tok2, " <" )->findClosingBracket ()->next ());
457453 tok2->str (name);
458454 }
@@ -1264,7 +1260,7 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
12641260 // New type..
12651261 std::vector<const Token *> typesUsedInTemplateInstantiation;
12661262 std::string typeForNewName;
1267- std::string templateMatchPattern (name + " < " ) ;
1263+ std::string typeForPatternMatch ;
12681264 unsigned int indentlevel = 0 ;
12691265 for (const Token *tok3 = tok2->tokAt (2 ); tok3 && (indentlevel > 0 || tok3->str () != " >" ); tok3 = tok3->next ()) {
12701266 // #2648 - unhandled parentheses => bail out
@@ -1281,13 +1277,14 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
12811277 ++indentlevel;
12821278 else if (indentlevel > 0 && Token::Match (tok3, " > [,>]" ))
12831279 --indentlevel;
1284- bool constconst = tok3->str () == " const" && tok3->strAt (1 ) == " const" ;
1285- if (!constconst) {
1286- templateMatchPattern += tok3->str ();
1287- templateMatchPattern += ' ' ;
1288- }
12891280 if (indentlevel == 0 && Token::Match (tok3->previous (), " [<,]" ))
12901281 typesUsedInTemplateInstantiation.push_back (tok3);
1282+ const bool constconst = tok3->str () == " const" && tok3->strAt (1 ) == " const" ;
1283+ if (!constconst) {
1284+ if (!typeForPatternMatch.empty ())
1285+ typeForPatternMatch += ' ' ;
1286+ typeForPatternMatch += tok3->str ();
1287+ }
12911288 // add additional type information
12921289 if (!constconst && tok3->str () != " class" ) {
12931290 if (tok3->isUnsigned ())
@@ -1296,10 +1293,12 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
12961293 typeForNewName += " signed" ;
12971294 if (tok3->isLong ())
12981295 typeForNewName += " long" ;
1296+ if (!typeForNewName.empty ())
1297+ typeForNewName += ' ' ;
12991298 typeForNewName += tok3->str ();
13001299 }
13011300 }
1302- templateMatchPattern += " > " ;
1301+ std::string templateMatchPattern (name + " < " + typeForPatternMatch + " > " ) ;
13031302
13041303 if (typeForNewName.empty () || typeParametersInDeclaration.size () != typesUsedInTemplateInstantiation.size ()) {
13051304 if (printDebug && errorlogger) {
@@ -1313,7 +1312,7 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
13131312 }
13141313
13151314 // New classname/funcname..
1316- const std::string newName (name + " < " + typeForNewName + " >" );
1315+ const std::string newName (name + " < " + typeForNewName + " >" );
13171316
13181317 if (expandedtemplates.find (newName) == expandedtemplates.end ()) {
13191318 expandedtemplates.insert (newName);
0 commit comments