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