-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[clang-format] Fix a bug in annotating TrailingReturnArrow #69249
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
Merged
Conversation
This file contains hidden or 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
Skip TrailingAnnotation when looking for TrailingReturnArrow. Fixes llvm#69234.
@llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) ChangesSkip TrailingAnnotation when looking for TrailingReturnArrow. Fixes #69234. Full diff: https://github.com/llvm/llvm-project/pull/69249.diff 2 Files Affected:
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 3dd537272e9dad0..9f007125e82c430 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3497,6 +3497,15 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
Tok->setType(TT_TrailingReturnArrow);
break;
}
+ if (Tok->isNot(TT_TrailingAnnotation))
+ continue;
+ const auto *Next = Tok->Next;
+ if (!Next || Next->isNot(tok::l_paren))
+ continue;
+ Tok = Next->MatchingParen;
+ if (Tok)
+ continue;
+ break;
}
}
}
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index e5cc3ed3686b3d3..d386ae9aae4ca61 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1788,6 +1788,10 @@ TEST_F(TokenAnnotatorTest, UnderstandsTrailingReturnArrow) {
ASSERT_EQ(Tokens.size(), 15u) << Tokens;
EXPECT_TOKEN(Tokens[12], tok::arrow, TT_Unknown);
+ Tokens = annotate("void f() FOO(foo->bar);");
+ ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+ EXPECT_TOKEN(Tokens[7], tok::arrow, TT_Unknown);
+
// Mixed
Tokens = annotate("auto f() -> int { auto a = b()->c; }");
ASSERT_EQ(Tokens.size(), 18u) << Tokens;
|
@HazardyKnusperkeks any other concerns? |
HazardyKnusperkeks
approved these changes
Oct 17, 2023
LGTM |
mydeveloperday
approved these changes
Oct 18, 2023
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.
Skip TrailingAnnotation when looking for TrailingReturnArrow.
Fixes #69234.