Skip to content

Commit 0b5c62b

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

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎lib/templatesimplifier.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,27 @@ 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+
// It is if the tokens from tok backwards form a type that starts right after a '->', and that
70+
// '->' comes after the parameter list (or a specifier following it). A '->' after an object,
71+
// as in 'p->x', is a member access instead.
72+
73+
// walk back over the type: names, '::', '&', '&&', '*', template arguments '<..>' and 'decltype(..)'.
74+
// The loop stops at the first token that cannot be part of the type, the token before the type.
6975
while (Token::Match(tok, "%name%|::|&|&&|*|>|)")) {
7076
if (tok->str() == ">") {
77+
// skip the template arguments ('<' and '>' are not linked yet)
7178
tok = tok->findOpeningBracket();
7279
if (!tok)
7380
return false;
7481
} else if (tok->str() == ")") {
82+
// only 'decltype(..)' ends a type with ')', skip it
7583
if (!Token::simpleMatch(tok->link()->previous(), "decltype"))
7684
return false;
7785
tok = tok->link()->previous();
7886
}
7987
tok = tok->previous();
8088
}
89+
// the type must follow '->' (already simplified to '.')
8190
if (!tok || tok->str() != "." || tok->originalName() != "->")
8291
return false;
8392
// a trailing return type follows the parameter list or a specifier, a member access 'p->x' follows an object

0 commit comments

Comments
 (0)