[clang] 0812f41 - [clang-format] Don't crash on incomplete template declaration (#173433)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 24 05:32:30 PST 2025
Author: Björn Schäpers
Date: 2025-12-24T13:32:25Z
New Revision: 0812f41cd68d63d10a4c3a02271b0ea8276dbe57
URL: https://github.com/llvm/llvm-project/commit/0812f41cd68d63d10a4c3a02271b0ea8276dbe57
DIFF: https://github.com/llvm/llvm-project/commit/0812f41cd68d63d10a4c3a02271b0ea8276dbe57.diff
LOG: [clang-format] Don't crash on incomplete template declaration (#173433)
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index f6341ff0305a9..1123ae98c02ca 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3711,7 +3711,7 @@ static FormatToken *getFunctionName(const AnnotatedLine &Line,
if (Tok->is(TT_AttributeLSquare)) {
Tok = Tok->MatchingParen;
if (!Tok)
- break;
+ return nullptr;
continue;
}
@@ -3743,6 +3743,8 @@ static FormatToken *getFunctionName(const AnnotatedLine &Line,
return nullptr;
Tok = Tok->MatchingParen;
+ if (!Tok)
+ return nullptr;
continue;
}
@@ -3751,7 +3753,7 @@ static FormatToken *getFunctionName(const AnnotatedLine &Line,
if (Tok->is(tok::coloncolon)) {
Tok = Tok->Next;
if (!Tok)
- break;
+ return nullptr;
}
// Skip to the unqualified part of the name.
@@ -3765,12 +3767,12 @@ static FormatToken *getFunctionName(const AnnotatedLine &Line,
if (Tok->is(tok::tilde)) {
Tok = Tok->Next;
if (!Tok)
- break;
+ return nullptr;
}
// Make sure the name is not already annotated, e.g. as NamespaceMacro.
if (Tok->isNot(tok::identifier) || Tok->isNot(TT_Unknown))
- break;
+ return nullptr;
Name = Tok;
}
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 5cdac66d1dcbd..f5f23388453ec 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -29053,6 +29053,8 @@ TEST_F(FormatTest, KeywordedFunctionLikeMacros) {
Style);
}
+TEST_F(FormatTest, UnbalancedAngleBrackets) { verifyFormat("template <"); }
+
} // namespace
} // namespace test
} // namespace format
More information about the cfe-commits
mailing list