Skip to content

Commit c91f0ab

Browse files
autoantwortclaude
andcommitted
Explain the loop in isTrailingReturnTypeEnd
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 20418f4 commit c91f0ab

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎lib/templatesimplifier.cpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,23 @@ static Token *skipRequires(Token *tok)
6666
// is tok the last token of a trailing return type, as in 'auto f() -> T & requires C<T>'?
6767
static bool isTrailingReturnTypeEnd(const Token *tok)
6868
{
69+
// walk back over the type: names, '::', '&', '&&', '*', template arguments '<..>' and 'decltype(..)'.
70+
// The loop stops at the first token that cannot be part of the type, the token before the type.
6971
while (Token::Match(tok, "%name%|::|&|&&|*|>|)")) {
7072
if (tok->str() == ">") {
73+
// skip the template arguments ('<' and '>' are not linked yet)
7174
tok = tok->findOpeningBracket();
7275
if (!tok)
7376
return false;
7477
} else if (tok->str() == ")") {
78+
// only 'decltype(..)' ends a type with ')', skip it
7579
if (!Token::simpleMatch(tok->link()->previous(), "decltype"))
7680
return false;
7781
tok = tok->link()->previous();
7882
}
7983
tok = tok->previous();
8084
}
85+
// the type must follow '->' (already simplified to '.')
8186
if (!tok || tok->str() != "." || tok->originalName() != "->")
8287
return false;
8388
// a trailing return type follows the parameter list or a specifier, a member access 'p->x' follows an object

0 commit comments

Comments
 (0)