Skip to content

Commit 0916ae4

Browse files
authored
[clang-format] Fix a misannotation of less/greater as angle brackets (#105941)
Fixes #105877.
1 parent 6bc225e commit 0916ae4

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class AnnotatingParser {
250250
if (Precedence > prec::Conditional && Precedence < prec::Relational)
251251
return false;
252252
}
253-
if (Prev.is(TT_ConditionalExpr))
253+
if (Prev.isOneOf(tok::question, tok::colon) && !Style.isProto())
254254
SeenTernaryOperator = true;
255255
updateParameterCount(Left, CurrentToken);
256256
if (Style.Language == FormatStyle::LK_Proto) {

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsNonTemplateAngleBrackets) {
620620
EXPECT_TOKEN(Tokens[2], tok::less, TT_BinaryOperator);
621621
EXPECT_TOKEN(Tokens[8], tok::greater, TT_BinaryOperator);
622622

623+
Tokens = annotate("return checklower ? a < b : a > b;");
624+
ASSERT_EQ(Tokens.size(), 12u) << Tokens;
625+
EXPECT_TOKEN(Tokens[4], tok::less, TT_BinaryOperator);
626+
EXPECT_TOKEN(Tokens[8], tok::greater, TT_BinaryOperator);
627+
623628
Tokens = annotate("return A < B ^ A > B;");
624629
ASSERT_EQ(Tokens.size(), 10u) << Tokens;
625630
EXPECT_TOKEN(Tokens[2], tok::less, TT_BinaryOperator);

0 commit comments

Comments
 (0)