[clang] [clang-format] Handle templates in qualified typenames (PR #143194)
Shafik Yaghmour via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 8 13:44:47 PST 2026
================
@@ -3669,12 +3718,11 @@ static FormatToken *getFunctionName(const AnnotatedLine &Line,
}
// Skip to the unqualified part of the name.
- while (Tok->startsSequence(tok::identifier, tok::coloncolon)) {
- assert(Tok->Next);
- Tok = Tok->Next->Next;
- if (!Tok)
- return nullptr;
- }
+ while (FormatToken *Next = skipNameQualifier(Tok))
+ Tok = Next;
+
+ if (!Tok)
+ return nullptr;
----------------
shafik wrote:
I don't see how `Tok` can ever be a `nullptr` here.
`Tok` is first set by
`FormatToken *Tok = Line.getFirstNonComment()`
If this could yield a `nullptr` than the first unchecked dereference would be wrong.
The next time `Tok` is set is at:
`while (auto *Next = skipNameQualifier(Tok))`
Other assignments to `Tok` have explicit `nullptr` checks.
but this can't be a `nullptr` b/c the condition would be `false`
We have various continues and breaks but the for loop unconditionally checks `Tok` so those can't yield a `nullptr` either.
https://github.com/llvm/llvm-project/pull/143194
More information about the cfe-commits
mailing list