[clang] [clang-format] Fix a crash in formatting unbalanced angle brackets (PR #173456)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 23 21:53:57 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: owenca (owenca)
<details>
<summary>Changes</summary>
Fixes #<!-- -->173382
---
Full diff: https://github.com/llvm/llvm-project/pull/173456.diff
2 Files Affected:
- (modified) clang/lib/Format/TokenAnnotator.cpp (+1-3)
- (modified) clang/unittests/Format/FormatTest.cpp (+5)
``````````diff
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index f6341ff0305a9..d11e9d23e56aa 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3037,10 +3037,8 @@ class AnnotatingParser {
auto *NextToken = Tok.getNextNonComment();
if (!NextToken)
return TT_PointerOrReference;
- if (NextToken->is(tok::greater)) {
- NextToken->setFinalizedType(TT_TemplateCloser);
+ if (NextToken->is(tok::greater))
return TT_PointerOrReference;
- }
if (InTemplateArgument && NextToken->is(tok::kw_noexcept))
return TT_BinaryOperator;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 5cdac66d1dcbd..c8724f898bf9d 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -29053,6 +29053,11 @@ TEST_F(FormatTest, KeywordedFunctionLikeMacros) {
Style);
}
+TEST_F(FormatTest, UnbalancedAngleBrackets) {
+ verifyNoCrash("typename foo<bar>::value, const String &>::type f();",
+ getLLVMStyleWithColumns(50));
+}
+
} // namespace
} // namespace test
} // namespace format
``````````
</details>
https://github.com/llvm/llvm-project/pull/173456
More information about the cfe-commits
mailing list