Author: owenca
Date: 2025-12-25T08:23:23Z
New Revision: 347c6006f42a286ff9170c8b40f53295da2e95c7

URL: 
https://github.com/llvm/llvm-project/commit/347c6006f42a286ff9170c8b40f53295da2e95c7
DIFF: 
https://github.com/llvm/llvm-project/commit/347c6006f42a286ff9170c8b40f53295da2e95c7.diff

LOG: [clang-format] Fix a crash in formatting unbalanced angle brackets 
(#173456)

Fixes #173382

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 1123ae98c02ca..2b554e609fa3a 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 f5f23388453ec..3ee7ce38578aa 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -29053,7 +29053,12 @@ TEST_F(FormatTest, KeywordedFunctionLikeMacros) {
                Style);
 }
 
-TEST_F(FormatTest, UnbalancedAngleBrackets) { verifyFormat("template <"); }
+TEST_F(FormatTest, UnbalancedAngleBrackets) {
+  verifyFormat("template <");
+
+  verifyNoCrash("typename foo<bar>::value, const String &>::type f();",
+                getLLVMStyleWithColumns(50));
+}
 
 } // namespace
 } // namespace test


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to