[clang] eaff3a7 - [clang-format] Fix a bug that misannotates binary operators */&/&& (#110945)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 3 18:57:53 PDT 2024
Author: Owen Pan
Date: 2024-10-03T18:57:50-07:00
New Revision: eaff3a743406ff1636e6328e1ba1bc66318d53cb
URL: https://github.com/llvm/llvm-project/commit/eaff3a743406ff1636e6328e1ba1bc66318d53cb
DIFF: https://github.com/llvm/llvm-project/commit/eaff3a743406ff1636e6328e1ba1bc66318d53cb.diff
LOG: [clang-format] Fix a bug that misannotates binary operators */&/&& (#110945)
Fixes #110879.
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 5398e2dadd485a..e2068e557732af 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -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.
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index de1346b5ddd5a7..a89adfa3f4fdd9 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -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) {
More information about the cfe-commits
mailing list