@@ -6546,7 +6546,7 @@ void Tokenizer::simplifyHeadersAndUnusedTemplates()
65466546
65476547 if (removeUnusedTemplates || (isIncluded && removeUnusedIncludedTemplates)) {
65486548 if (Token::Match (tok, " template < %name%" )) {
6549- const Token *closingBracket = tok->next ()->findClosingBracket ();
6549+ Token *closingBracket = tok->next ()->findClosingBracket ();
65506550 if (Token::Match (closingBracket, " > class|struct %name% [;:{]" ) && keep.find (closingBracket->strAt (2 )) == keep.end ()) {
65516551 const Token *endToken = closingBracket->tokAt (3 );
65526552 if (endToken->str () == " :" ) {
@@ -6560,11 +6560,68 @@ void Tokenizer::simplifyHeadersAndUnusedTemplates()
65606560 Token::eraseTokens (tok, endToken);
65616561 tok->deleteThis ();
65626562 }
6563- } else if (Token::Match (closingBracket, " > %type% %name% (" ) && Token::simpleMatch (closingBracket->linkAt (3 ), " ) {" ) && keep.find (closingBracket->strAt (2 )) == keep.end ()) {
6564- const Token *endToken = closingBracket->linkAt (3 )->linkAt (1 )->next ();
6565- Token::eraseTokens (tok, endToken);
6566- tok->deleteThis ();
6567- goBack = true ;
6563+ } else {
6564+ Token *funcTok = closingBracket->next ();
6565+ while (funcTok) {
6566+ if (Token::Match (funcTok, " __declspec|__attribute__ (" )) {
6567+ funcTok = funcTok->linkAt (1 );
6568+ if (funcTok) {
6569+ funcTok = funcTok->next ();
6570+ }
6571+ continue ;
6572+ }
6573+ if (Token::Match (funcTok, " [ [" )) {
6574+ funcTok = funcTok->link ();
6575+ if (funcTok) {
6576+ funcTok = funcTok->next ();
6577+ }
6578+ continue ;
6579+ }
6580+ if (Token::Match (funcTok, " static|inline|const|%type%|&|&&|*" ) && !Token::Match (funcTok, " %name% (" )) {
6581+ funcTok = funcTok->next ();
6582+ continue ;
6583+ }
6584+ break ;
6585+ }
6586+ if (!Token::Match (funcTok, " %name% (" )) {
6587+ tok = funcTok;
6588+ continue ;
6589+ }
6590+ funcTok = funcTok->linkAt (1 );
6591+ if (funcTok) {
6592+ funcTok = funcTok->next ();
6593+ }
6594+ while (funcTok) {
6595+ if (Token::Match (funcTok, " __declspec|__attribute__|throw|noexcept (" )) {
6596+ funcTok = funcTok->linkAt (1 );
6597+ if (funcTok) {
6598+ funcTok = funcTok->next ();
6599+ }
6600+ continue ;
6601+ }
6602+ if (Token::Match (funcTok, " [ [" )) {
6603+ funcTok = funcTok->link ();
6604+ if (funcTok) {
6605+ funcTok = funcTok->next ();
6606+ }
6607+ continue ;
6608+ }
6609+ if (Token::Match (funcTok, " const|volatile|&|&&" )) {
6610+ funcTok = funcTok->next ();
6611+ continue ;
6612+ }
6613+ break ;
6614+ }
6615+ if (!Token::simpleMatch (funcTok, " {" )) {
6616+ tok = funcTok;
6617+ continue ;
6618+ }
6619+ funcTok = funcTok->link ();
6620+ if (funcTok) {
6621+ Token::eraseTokens (tok, funcTok->next ());
6622+ tok->deleteThis ();
6623+ goBack = true ;
6624+ }
65686625 }
65696626 }
65706627 }
0 commit comments