Skip to content

Commit eaff3a7

Browse files
authored
[clang-format] Fix a bug that misannotates binary operators */&/&& (#110945)
Fixes #110879.
1 parent 876f661 commit eaff3a7

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ class AnnotatingParser {
366366
} else if (OpeningParen.Previous &&
367367
(OpeningParen.Previous->isOneOf(
368368
tok::kw_static_assert, tok::kw_noexcept, tok::kw_explicit,
369-
tok::kw_while, tok::l_paren, tok::comma,
369+
tok::kw_while, tok::l_paren, tok::comma, TT_CastRParen,
370370
TT_BinaryOperator) ||
371371
OpeningParen.Previous->isIf())) {
372372
// static_assert, if and while usually contain expressions.

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,14 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
367367
"}");
368368
ASSERT_EQ(Tokens.size(), 20u) << Tokens;
369369
EXPECT_TOKEN(Tokens[14], tok::star, TT_PointerOrReference);
370+
371+
Tokens = annotate("Thingy kConfig = {\n"
372+
" 1,\n"
373+
" (uint16_t)(kScale * height_pixels),\n"
374+
"};");
375+
ASSERT_EQ(Tokens.size(), 18u) << Tokens;
376+
EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_CastRParen);
377+
EXPECT_TOKEN(Tokens[11], tok::star, TT_BinaryOperator);
370378
}
371379

372380
TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {

0 commit comments

Comments
 (0)