@@ -969,6 +969,21 @@ static bool isPrefixUnary(const Token* tok, bool cpp)
969969 return tok->strAt (-1 ) == " )" && iscast (tok->linkAt (-1 ), cpp);
970970}
971971
972+ template <class T , REQUIRES (" T must be a Token class" , std::is_convertible<T*, const Token*> )>
973+ static T* skipTrailingReturnType (T* tok)
974+ {
975+ if (!Token::simpleMatch (tok, " ." ))
976+ return tok;
977+ tok = tok->next ();
978+ while (Token::Match (tok, " %type%|%name%|::|&|&&|*|<|(" )) {
979+ if (tok->link ())
980+ tok = tok->link ()->next ();
981+ else
982+ tok = tok->next ();
983+ }
984+ return tok;
985+ }
986+
972987/* *
973988 * @throws InternalError thrown if unexpected tokens are encountered
974989 */
@@ -1063,15 +1078,7 @@ static void compilePrecedence2(Token *&tok, AST_state& state)
10631078 }
10641079 } else {
10651080 Token* curlyBracket = squareBracket->link ()->next ();
1066- if (Token::simpleMatch (curlyBracket, " ." )) { // trailing return type
1067- curlyBracket = curlyBracket->next ();
1068- while (Token::Match (curlyBracket, " %type%|%name%|::|&|&&|*|<|(" )) {
1069- if (curlyBracket->link ())
1070- curlyBracket = curlyBracket->link ()->next ();
1071- else
1072- curlyBracket = curlyBracket->next ();
1073- }
1074- }
1081+ curlyBracket = skipTrailingReturnType (curlyBracket);
10751082 if (!Token::simpleMatch (curlyBracket, " {" ))
10761083 throw InternalError (tok, " Syntax error in lambda" , InternalError::AST );
10771084 squareBracket->astOperand1 (curlyBracket);
@@ -1518,15 +1525,7 @@ const Token* findLambdaEndTokenWithoutAST(const Token* tok) {
15181525 tok = tok->link ()->next ();
15191526 if (Token::simpleMatch (tok, " mutable" ))
15201527 tok = tok->next ();
1521- if (Token::Match (tok, " .|->" )) { // trailing return type
1522- tok = tok->next ();
1523- while (Token::Match (tok, " %type%|%name%|::|&|&&|*|<|(" )) {
1524- if (tok->link ())
1525- tok = tok->link ()->next ();
1526- else
1527- tok = tok->next ();
1528- }
1529- }
1528+ tok = skipTrailingReturnType (tok);
15301529 if (!(Token::simpleMatch (tok, " {" ) && tok->link ()))
15311530 return nullptr ;
15321531 return tok->link ()->next ();
0 commit comments