-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang-format] Fix a regression in annotating star before lambda #170969
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
Conversation
|
@llvm/pr-subscribers-clang-format Author: owenca (owenca) ChangesFixes #170573 Full diff: https://github.com/llvm/llvm-project/pull/170969.diff 2 Files Affected:
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 19c83d3910902..c1a9161b10720 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2395,17 +2395,17 @@ bool UnwrappedLineParser::tryToParseLambdaIntroducer() {
const FormatToken *LeftSquare = FormatTok;
nextToken();
if (Previous) {
+ const auto *PrevPrev = Previous->getPreviousNonComment();
+ if (Previous->is(tok::star) && PrevPrev && PrevPrev->isTypeName(LangOpts))
+ return false;
if (Previous->closesScope()) {
// Not a potential C-style cast.
if (Previous->isNot(tok::r_paren))
return false;
- const auto *BeforeRParen = Previous->getPreviousNonComment();
// Lambdas can be cast to function types only, e.g. `std::function<int()>`
// and `int (*)()`.
- if (!BeforeRParen || BeforeRParen->isNoneOf(tok::greater, tok::r_paren))
+ if (!PrevPrev || PrevPrev->isNoneOf(tok::greater, tok::r_paren))
return false;
- } else if (Previous->is(tok::star)) {
- Previous = Previous->getPreviousNonComment();
}
if (Previous && Previous->Tok.getIdentifierInfo() &&
Previous->isNoneOf(tok::kw_return, tok::kw_co_await, tok::kw_co_yield,
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 008adff1cee2d..1bf243a30bb74 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2322,6 +2322,12 @@ TEST_F(TokenAnnotatorTest, UnderstandsLambdas) {
EXPECT_TOKEN(Tokens[3], tok::l_square, TT_LambdaLSquare);
EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_LambdaDefinitionLParen);
EXPECT_TOKEN(Tokens[10], tok::l_square, TT_ArraySubscriptLSquare);
+
+ Tokens = annotate("foo = bar * [] { return 2; }();");
+ ASSERT_EQ(Tokens.size(), 15u) << Tokens;
+ EXPECT_TOKEN(Tokens[3], tok::star, TT_BinaryOperator);
+ EXPECT_TOKEN(Tokens[4], tok::l_square, TT_LambdaLSquare);
+ EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_LambdaLBrace);
}
TEST_F(TokenAnnotatorTest, UnderstandsFunctionAnnotations) {
|
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/88/builds/18768 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/174/builds/28525 Here is the relevant piece of the build log for the reference |
…re lambda (llvm#170969) Backport 4930e94
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/186/builds/14523 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/110/builds/6671 Here is the relevant piece of the build log for the reference |
Fixes #170573