Skip to content

Commit

Permalink
[clang-format] Fix a bug that misannotates binary operators */&/&& (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
owenca authored Oct 4, 2024
1 parent 876f661 commit eaff3a7
Show file tree
Hide file tree
Showing 2 changed files with 9 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 @@ -366,7 +366,7 @@ class AnnotatingParser {
} else if (OpeningParen.Previous &&
(OpeningParen.Previous->isOneOf(
tok::kw_static_assert, tok::kw_noexcept, tok::kw_explicit,
tok::kw_while, tok::l_paren, tok::comma,
tok::kw_while, tok::l_paren, tok::comma, TT_CastRParen,
TT_BinaryOperator) ||
OpeningParen.Previous->isIf())) {
// static_assert, if and while usually contain expressions.
Expand Down
8 changes: 8 additions & 0 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,14 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
"}");
ASSERT_EQ(Tokens.size(), 20u) << Tokens;
EXPECT_TOKEN(Tokens[14], tok::star, TT_PointerOrReference);

Tokens = annotate("Thingy kConfig = {\n"
" 1,\n"
" (uint16_t)(kScale * height_pixels),\n"
"};");
ASSERT_EQ(Tokens.size(), 18u) << Tokens;
EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_CastRParen);
EXPECT_TOKEN(Tokens[11], tok::star, TT_BinaryOperator);
}

TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {
Expand Down

0 comments on commit eaff3a7

Please sign in to comment.