Skip to content

Commit 53033b2

Browse files
committed
[clang-format] Fix a bug in parsing C-style cast lambda
Fix #135959
1 parent 9bd0c87 commit 53033b2

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2371,7 +2371,8 @@ bool UnwrappedLineParser::tryToParseLambdaIntroducer() {
23712371
if ((Previous && ((Previous->Tok.getIdentifierInfo() &&
23722372
!Previous->isOneOf(tok::kw_return, tok::kw_co_await,
23732373
tok::kw_co_yield, tok::kw_co_return)) ||
2374-
Previous->closesScope())) ||
2374+
(Previous->closesScope() &&
2375+
!Previous->endsSequence(tok::r_paren, tok::greater)))) ||
23752376
LeftSquare->isCppStructuredBinding(IsCpp)) {
23762377
return false;
23772378
}

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,6 +2159,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsLambdas) {
21592159
// FIXME:
21602160
// EXPECT_TOKEN(Tokens[13], tok::l_paren, TT_LambdaDefinitionLParen);
21612161
EXPECT_TOKEN(Tokens[17], tok::l_brace, TT_LambdaLBrace);
2162+
2163+
Tokens = annotate("auto foo{(std::function<int()>)[] { return 0; }};");
2164+
ASSERT_EQ(Tokens.size(), 23u) << Tokens;
2165+
EXPECT_TOKEN(Tokens[13], tok::l_square, TT_LambdaLSquare);
2166+
EXPECT_TOKEN(Tokens[15], tok::l_brace, TT_LambdaLBrace);
21622167
}
21632168

21642169
TEST_F(TokenAnnotatorTest, UnderstandsFunctionAnnotations) {

0 commit comments

Comments
 (0)