release/21.x: [clang-format] Fix bugs in annotating arrows and square… · llvm/llvm-project@41e817a (original) (raw)
`@@ -2266,7 +2266,7 @@ bool UnwrappedLineParser::tryToParseLambda() {
`
2266
2266
`if (!tryToParseLambdaIntroducer())
`
2267
2267
`return false;
`
2268
2268
``
2269
``
`-
bool SeenArrow = false;
`
``
2269
`+
FormatToken *Arrow = nullptr;
`
2270
2270
`bool InTemplateParameterList = false;
`
2271
2271
``
2272
2272
`while (FormatTok->isNot(tok::l_brace)) {
`
`@@ -2341,17 +2341,13 @@ bool UnwrappedLineParser::tryToParseLambda() {
`
2341
2341
`case tok::ellipsis:
`
2342
2342
`case tok::kw_true:
`
2343
2343
`case tok::kw_false:
`
2344
``
`-
if (SeenArrow || InTemplateParameterList) {
`
``
2344
`+
if (Arrow || InTemplateParameterList) {
`
2345
2345
`nextToken();
`
2346
2346
`break;
`
2347
2347
` }
`
2348
2348
`return true;
`
2349
2349
`case tok::arrow:
`
2350
``
`-
// This might or might not actually be a lambda arrow (this could be an
`
2351
``
`-
// ObjC method invocation followed by a dereferencing arrow). We might
`
2352
``
`-
// reset this back to TT_Unknown in TokenAnnotator.
`
2353
``
`-
FormatTok->setFinalizedType(TT_LambdaArrow);
`
2354
``
`-
SeenArrow = true;
`
``
2350
`+
Arrow = FormatTok;
`
2355
2351
`nextToken();
`
2356
2352
`break;
`
2357
2353
`case tok::kw_requires: {
`
`@@ -2373,6 +2369,9 @@ bool UnwrappedLineParser::tryToParseLambda() {
`
2373
2369
` FormatTok->setFinalizedType(TT_LambdaLBrace);
`
2374
2370
` LSquare.setFinalizedType(TT_LambdaLSquare);
`
2375
2371
``
``
2372
`+
if (Arrow)
`
``
2373
`+
Arrow->setFinalizedType(TT_LambdaArrow);
`
``
2374
+
2376
2375
` NestedLambdas.push_back(Line->SeenDecltypeAuto);
`
2377
2376
`parseChildBlock();
`
2378
2377
`assert(!NestedLambdas.empty());
`
`@@ -2386,11 +2385,6 @@ bool UnwrappedLineParser::tryToParseLambdaIntroducer() {
`
2386
2385
`const FormatToken *LeftSquare = FormatTok;
`
2387
2386
`nextToken();
`
2388
2387
`if (Previous) {
`
2389
``
`-
if (Previous->Tok.getIdentifierInfo() &&
`
2390
``
`-
!Previous->isOneOf(tok::kw_return, tok::kw_co_await, tok::kw_co_yield,
`
2391
``
`-
tok::kw_co_return)) {
`
2392
``
`-
return false;
`
2393
``
`-
}
`
2394
2388
`if (Previous->closesScope()) {
`
2395
2389
`// Not a potential C-style cast.
`
2396
2390
`if (Previous->isNot(tok::r_paren))
`
`@@ -2400,6 +2394,13 @@ bool UnwrappedLineParser::tryToParseLambdaIntroducer() {
`
2400
2394
`` // and int (*)().
``
2401
2395
`if (!BeforeRParen || !BeforeRParen->isOneOf(tok::greater, tok::r_paren))
`
2402
2396
`return false;
`
``
2397
`+
} else if (Previous->is(tok::star)) {
`
``
2398
`+
Previous = Previous->getPreviousNonComment();
`
``
2399
`+
}
`
``
2400
`+
if (Previous && Previous->Tok.getIdentifierInfo() &&
`
``
2401
`+
!Previous->isOneOf(tok::kw_return, tok::kw_co_await, tok::kw_co_yield,
`
``
2402
`+
tok::kw_co_return)) {
`
``
2403
`+
return false;
`
2403
2404
` }
`
2404
2405
` }
`
2405
2406
`if (LeftSquare->isCppStructuredBinding(IsCpp))
`