@@ -6396,7 +6396,7 @@ void Tokenizer::simplifyHeadersAndUnusedTemplates()
63966396
63976397 if (removeUnusedTemplates || (isIncluded && removeUnusedIncludedTemplates)) {
63986398 if (Token::Match (tok, " template < %name%" )) {
6399- const Token *closingBracket = tok->next ()->findClosingBracket ();
6399+ Token *closingBracket = tok->next ()->findClosingBracket ();
64006400 if (Token::Match (closingBracket, " > class|struct %name% [;:{]" ) && keep.find (closingBracket->strAt (2 )) == keep.end ()) {
64016401 const Token *endToken = closingBracket->tokAt (3 );
64026402 if (endToken->str () == " :" ) {
@@ -6410,11 +6410,68 @@ void Tokenizer::simplifyHeadersAndUnusedTemplates()
64106410 Token::eraseTokens (tok, endToken);
64116411 tok->deleteThis ();
64126412 }
6413- } else if (Token::Match (closingBracket, " > %type% %name% (" ) && Token::simpleMatch (closingBracket->linkAt (3 ), " ) {" ) && keep.find (closingBracket->strAt (2 )) == keep.end ()) {
6414- const Token *endToken = closingBracket->linkAt (3 )->linkAt (1 )->next ();
6415- Token::eraseTokens (tok, endToken);
6416- tok->deleteThis ();
6417- goBack = true ;
6413+ } else {
6414+ Token *funcTok = closingBracket->next ();
6415+ while (funcTok) {
6416+ if (Token::Match (funcTok, " __declspec|__attribute__ (" )) {
6417+ funcTok = funcTok->linkAt (1 );
6418+ if (funcTok) {
6419+ funcTok = funcTok->next ();
6420+ }
6421+ continue ;
6422+ }
6423+ if (Token::Match (funcTok, " [ [" )) {
6424+ funcTok = funcTok->link ();
6425+ if (funcTok) {
6426+ funcTok = funcTok->next ();
6427+ }
6428+ continue ;
6429+ }
6430+ if (Token::Match (funcTok, " static|inline|const|%type%|&|&&|*" ) && !Token::Match (funcTok, " %name% (" )) {
6431+ funcTok = funcTok->next ();
6432+ continue ;
6433+ }
6434+ break ;
6435+ }
6436+ if (!Token::Match (funcTok, " %name% (" )) {
6437+ tok = funcTok;
6438+ continue ;
6439+ }
6440+ funcTok = funcTok->linkAt (1 );
6441+ if (funcTok) {
6442+ funcTok = funcTok->next ();
6443+ }
6444+ while (funcTok) {
6445+ if (Token::Match (funcTok, " __declspec|__attribute__|throw|noexcept (" )) {
6446+ funcTok = funcTok->linkAt (1 );
6447+ if (funcTok) {
6448+ funcTok = funcTok->next ();
6449+ }
6450+ continue ;
6451+ }
6452+ if (Token::Match (funcTok, " [ [" )) {
6453+ funcTok = funcTok->link ();
6454+ if (funcTok) {
6455+ funcTok = funcTok->next ();
6456+ }
6457+ continue ;
6458+ }
6459+ if (Token::Match (funcTok, " const|volatile|&|&&" )) {
6460+ funcTok = funcTok->next ();
6461+ continue ;
6462+ }
6463+ break ;
6464+ }
6465+ if (!Token::simpleMatch (funcTok, " {" )) {
6466+ tok = funcTok;
6467+ continue ;
6468+ }
6469+ funcTok = funcTok->link ();
6470+ if (funcTok) {
6471+ Token::eraseTokens (tok, funcTok->next ());
6472+ tok->deleteThis ();
6473+ goBack = true ;
6474+ }
64186475 }
64196476 }
64206477 }
0 commit comments