-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang-format] Fix a bug in AnnotatingParser::rParenEndsCast() #79549
Conversation
@llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) ChangesFixes #78965. Full diff: https://github.com/llvm/llvm-project/pull/79549.diff 2 Files Affected:
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 25fcceb87864379..df1c5bc19de1e84 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2488,6 +2488,8 @@ class AnnotatingParser {
(Tok.Next->Next->is(tok::numeric_constant) || Line.InPPDirective)) {
return false;
}
+ if (Line.InPPDirective && Tok.Next->is(tok::minus))
+ return false;
// Search for unexpected tokens.
for (FormatToken *Prev = Tok.Previous; Prev != Tok.MatchingParen;
Prev = Prev->Previous) {
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 3dbf504c35ed55e..67678c18963b1f3 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -611,6 +611,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsCasts) {
EXPECT_TOKEN(Tokens[13], tok::r_paren, TT_Unknown);
EXPECT_TOKEN(Tokens[14], tok::star, TT_BinaryOperator);
+ Tokens = annotate("#define foo(i) ((i) - bar)");
+ ASSERT_EQ(Tokens.size(), 14u) << Tokens;
+ EXPECT_TOKEN(Tokens[9], tok::r_paren, TT_Unknown);
+ EXPECT_TOKEN(Tokens[10], tok::minus, TT_BinaryOperator);
+
Tokens = annotate("return (Foo) & 10;");
ASSERT_EQ(Tokens.size(), 8u) << Tokens;
EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_Unknown);
|
@owenca, @HazardyKnusperkeks, I'm sorry I'm not very familiar with LLVM release cycle, but couldn't this be back-ported for version 18.1.0rc2? I see this fix only in |
/cherry-pick f826f55 |
…79549) Fixes llvm#78965. (cherry picked from commit f826f55)
/pull-request #80591 |
…79549) Fixes llvm#78965. (cherry picked from commit f826f55)
…79549) Fixes llvm#78965. (cherry picked from commit f826f55)
…79549) Fixes llvm#78965. (cherry picked from commit f826f55)
…79549) Fixes llvm#78965. (cherry picked from commit f826f55)
…79549) Fixes llvm#78965. (cherry picked from commit f826f55)
…79549) Fixes llvm#78965. (cherry picked from commit f826f55)
Fixes #78965.