[llvm-branch-commits] [clang] 1b1ddb7 - [clang-format] Fix a misannotation of redundant r_paren as CastRParen (#105921)
Tobias Hieta via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Sep 1 01:07:40 PDT 2024
Author: Owen Pan
Date: 2024-09-01T10:07:28+02:00
New Revision: 1b1ddb767e430a29c35c8b12760b7aa21f508d15
URL: https://github.com/llvm/llvm-project/commit/1b1ddb767e430a29c35c8b12760b7aa21f508d15
DIFF: https://github.com/llvm/llvm-project/commit/1b1ddb767e430a29c35c8b12760b7aa21f508d15.diff
LOG: [clang-format] Fix a misannotation of redundant r_paren as CastRParen (#105921)
Fixes #105880.
(cherry picked from commit 6bc225e0630f28e83290a43c3d9b25b057fc815a)
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 851f79895ac5ac..3b1ddf99888ca8 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2874,6 +2874,8 @@ class AnnotatingParser {
// Search for unexpected tokens.
for (auto *Prev = BeforeRParen; Prev != LParen; Prev = Prev->Previous) {
if (Prev->is(tok::r_paren)) {
+ if (Prev->is(TT_CastRParen))
+ return false;
Prev = Prev->MatchingParen;
if (!Prev)
return false;
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index c20b50d14b80b1..1f15c00573bade 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -741,6 +741,12 @@ TEST_F(TokenAnnotatorTest, UnderstandsCasts) {
EXPECT_TOKEN(Tokens[9], tok::r_paren, TT_CastRParen);
EXPECT_TOKEN(Tokens[10], tok::amp, TT_UnaryOperator);
+ Tokens = annotate("int result = ((int)a) - b;");
+ ASSERT_EQ(Tokens.size(), 13u) << Tokens;
+ EXPECT_TOKEN(Tokens[6], tok::r_paren, TT_CastRParen);
+ EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_Unknown);
+ EXPECT_TOKEN(Tokens[9], tok::minus, TT_BinaryOperator);
+
auto Style = getLLVMStyle();
Style.TypeNames.push_back("Foo");
Tokens = annotate("#define FOO(bar) foo((Foo)&bar)", Style);
More information about the llvm-branch-commits
mailing list