Skip to content

Commit

Permalink
[clang-format] Fix a misannotation of less/greater as angle brackets (l…
Browse files Browse the repository at this point in the history
  • Loading branch information
owenca committed Aug 25, 2024
1 parent 6bc225e commit 0916ae4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,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) {
Expand Down
5 changes: 5 additions & 0 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,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);
Expand Down

0 comments on commit 0916ae4

Please sign in to comment.