Skip to content

Commit d9806ff

Browse files
owencatru
authored andcommitted
[clang-format] Fix a misannotation of less/greater as angle brackets (#105941)
Fixes #105877. (cherry picked from commit 0916ae4)
1 parent 1b1ddb7 commit d9806ff

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
@@ -249,7 +249,7 @@ class AnnotatingParser {
249249
if (Precedence > prec::Conditional && Precedence < prec::Relational)
250250
return false;
251251
}
252-
if (Prev.is(TT_ConditionalExpr))
252+
if (Prev.isOneOf(tok::question, tok::colon) && !Style.isProto())
253253
SeenTernaryOperator = true;
254254
updateParameterCount(Left, CurrentToken);
255255
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
@@ -614,6 +614,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsNonTemplateAngleBrackets) {
614614
EXPECT_TOKEN(Tokens[2], tok::less, TT_BinaryOperator);
615615
EXPECT_TOKEN(Tokens[8], tok::greater, TT_BinaryOperator);
616616

617+
Tokens = annotate("return checklower ? a < b : a > b;");
618+
ASSERT_EQ(Tokens.size(), 12u) << Tokens;
619+
EXPECT_TOKEN(Tokens[4], tok::less, TT_BinaryOperator);
620+
EXPECT_TOKEN(Tokens[8], tok::greater, TT_BinaryOperator);
621+
617622
Tokens = annotate("return A < B ^ A > B;");
618623
ASSERT_EQ(Tokens.size(), 10u) << Tokens;
619624
EXPECT_TOKEN(Tokens[2], tok::less, TT_BinaryOperator);

0 commit comments

Comments
 (0)