-
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 misannotation of redundant r_paren as CastRParen #105921
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) ChangesFixes #105880. Full diff: https://github.com/llvm/llvm-project/pull/105921.diff 2 Files Affected:
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 0d5741ed76f7cb..a4952e7a47becd 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2875,6 +2875,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 99798de43e70ff..834430fa931129 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -747,6 +747,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);
|
rymiel
approved these changes
Aug 24, 2024
/cherry-pick 6bc225e |
llvmbot
pushed a commit
to llvmbot/llvm-project
that referenced
this pull request
Aug 25, 2024
…llvm#105921) Fixes llvm#105880. (cherry picked from commit 6bc225e)
/pull-request #105967 |
tru
pushed a commit
to llvmbot/llvm-project
that referenced
this pull request
Sep 1, 2024
…llvm#105921) Fixes llvm#105880. (cherry picked from commit 6bc225e)
dmpolukhin
pushed a commit
to dmpolukhin/llvm-project
that referenced
this pull request
Sep 2, 2024
qiaojbao
pushed a commit
to GPUOpen-Drivers/llvm-project
that referenced
this pull request
Sep 30, 2024
…4bb5b239f Local branch amd-gfx 4bb4bb5 Merged main:3ef64f7ab5b8651eab500cd944984379fce5f639 into amd-gfx:3b493b7eeddf Remote branch main 6bc225e [clang-format] Fix a misannotation of redundant r_paren as CastRParen (llvm#105921)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #105880.