-
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] Correctly annotate keyword operator function name #66904
Conversation
@llvm/pr-subscribers-clang-format ChangesFixes #66890. Full diff: https://github.com/llvm/llvm-project/pull/66904.diff 2 Files Affected:
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 138f7e8562dcc39..4a052efdd5f8136 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3294,6 +3294,11 @@ static bool isFunctionDeclarationName(bool IsCpp, const FormatToken &Current,
!Previous->isOneOf(tok::kw_return, tok::kw_co_return)) {
return true;
}
+ if (Previous->is(tok::r_paren) && Previous->is(TT_TypeDeclarationParen)) {
+ assert(Previous->MatchingParen);
+ assert(Previous->MatchingParen->is(TT_TypeDeclarationParen));
+ return true;
+ }
if (!Previous->isOneOf(tok::star, tok::amp, tok::ampamp, TT_TemplateCloser))
return false;
Next = skipOperatorName(Next);
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 22698f6faf3cb1e..567a364432f9228 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -753,6 +753,16 @@ TEST_F(TokenAnnotatorTest, UnderstandsOverloadedOperators) {
EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_OverloadedOperator);
EXPECT_TOKEN(Tokens[9], tok::l_paren, TT_OverloadedOperatorLParen);
EXPECT_TOKEN(Tokens[11], tok::amp, TT_PointerOrReference);
+
+ Tokens = annotate("decltype(auto) operator()(T &x);");
+ ASSERT_EQ(Tokens.size(), 14u) << Tokens;
+ EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_TypeDeclarationParen);
+ EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_TypeDeclarationParen);
+ EXPECT_TOKEN(Tokens[4], tok::kw_operator, TT_FunctionDeclarationName);
+ EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperator);
+ EXPECT_TOKEN(Tokens[6], tok::r_paren, TT_OverloadedOperator);
+ EXPECT_TOKEN(Tokens[7], tok::l_paren, TT_OverloadedOperatorLParen);
+ EXPECT_TOKEN(Tokens[9], tok::amp, TT_PointerOrReference);
}
TEST_F(TokenAnnotatorTest, OverloadedOperatorInTemplate) {
|
…vm#66274) The associated function can be a nullptr if it is an indirect call. This causes a crash in `CheckCallee` which always assumes the callee is a valid pointer. Fix llvm#66904.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry you have to ping. I had some downtime on my mailserver and did not receive github mails for a week.
@HazardyKnusperkeks Np! Really appreciate your prompt reviews of so many clang-format patches! |
wq The Attributor has gained support for indirect calls but it is opt-in. This patch makes AAKernelInfoCallSite able to handle multiple potential callees. [LLVM][OpenMPOpt] Fix a crash when associated function is nullptr (llvm#66274) The associated function can be a nullptr if it is an indirect call. This causes a crash in `CheckCallee` which always assumes the callee is a valid pointer. Fix llvm#66904. Change-Id: Ief6ea28456dc5c01709049153fe7e30f6aa4cb29
Fixes #66890.