[llvm-branch-commits] [clang] d9806ff - [clang-format] Fix a misannotation of less/greater as angle brackets (#105941)
Tobias Hieta via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Sep 1 01:08:06 PDT 2024
Author: Owen Pan
Date: 2024-09-01T10:07:54+02:00
New Revision: d9806ffe4e4d26de9c01f6b8ac0deae169b1d88d
URL: https://github.com/llvm/llvm-project/commit/d9806ffe4e4d26de9c01f6b8ac0deae169b1d88d
DIFF: https://github.com/llvm/llvm-project/commit/d9806ffe4e4d26de9c01f6b8ac0deae169b1d88d.diff
LOG: [clang-format] Fix a misannotation of less/greater as angle brackets (#105941)
Fixes #105877.
(cherry picked from commit 0916ae49b89db6eb9eee9f6fee4f1a65fd9cdb74)
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 3b1ddf99888ca8..2f6ffb2e508650 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -249,7 +249,7 @@ class AnnotatingParser {
if (Precedence > prec::Conditional && Precedence < prec::Relational)
return false;
}
- if (Prev.is(TT_ConditionalExpr))
+ if (Prev.isOneOf(tok::question, tok::colon) && !Style.isProto())
SeenTernaryOperator = true;
updateParameterCount(Left, CurrentToken);
if (Style.Language == FormatStyle::LK_Proto) {
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 1f15c00573bade..51afe1bf2ff9be 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -614,6 +614,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsNonTemplateAngleBrackets) {
EXPECT_TOKEN(Tokens[2], tok::less, TT_BinaryOperator);
EXPECT_TOKEN(Tokens[8], tok::greater, TT_BinaryOperator);
+ Tokens = annotate("return checklower ? a < b : a > b;");
+ ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+ EXPECT_TOKEN(Tokens[4], tok::less, TT_BinaryOperator);
+ EXPECT_TOKEN(Tokens[8], tok::greater, TT_BinaryOperator);
+
Tokens = annotate("return A < B ^ A > B;");
ASSERT_EQ(Tokens.size(), 10u) << Tokens;
EXPECT_TOKEN(Tokens[2], tok::less, TT_BinaryOperator);
More information about the llvm-branch-commits
mailing list