[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 22:12:01 PST 2025


https://github.com/owenca updated https://github.com/llvm/llvm-project/pull/173456

>From 24bf3d8e19aa1308ef5aa0e21a7ed3bac62c59d4 Mon Sep 17 00:00:00 2001
From: Owen Pan <owenpiano at gmail.com>
Date: Tue, 23 Dec 2025 21:48:31 -0800
Subject: [PATCH] [clang-format] Fix a crash in formatting unbalanced angle
 brackets

Fixes #173382
---
 clang/lib/Format/TokenAnnotator.cpp   | 4 +---
 clang/unittests/Format/FormatTest.cpp | 5 +++++
 2 files changed, 6 insertions(+), 3 deletions(-)

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



More information about the cfe-commits mailing list