@@ -314,7 +314,7 @@ Response HandleRecordDecl(const CXXRecordDecl *Rec,
314
314
// This is to make sure we pick up the VarTemplateSpecializationDecl that this
315
315
// lambda is defined inside of.
316
316
if (Rec->isLambda ())
317
- if (const Decl *LCD = Rec->getLambdaContextDecl ())
317
+ if (const Decl *LCD = Rec->getLambdaInstantiatingContextDecl ())
318
318
return Response::ChangeDecl (LCD);
319
319
320
320
return Response::UseNextDecl (Rec);
@@ -330,6 +330,14 @@ Response HandleImplicitConceptSpecializationDecl(
330
330
return Response::UseNextDecl (CSD);
331
331
}
332
332
333
+ Response HandleTypeAliasTemplateDecl (const TypeAliasTemplateDecl *TATD,
334
+ bool ForConstraintInstantiation,
335
+ MultiLevelTemplateArgumentList &Result) {
336
+ if (ForConstraintInstantiation)
337
+ Result.addOuterTemplateArguments (std::nullopt);
338
+ return Response::UseNextDecl (TATD);
339
+ }
340
+
333
341
Response HandleGenericDeclContext (const Decl *CurDecl) {
334
342
return Response::UseNextDecl (CurDecl);
335
343
}
@@ -425,6 +433,10 @@ MultiLevelTemplateArgumentList Sema::getTemplateInstantiationArgs(
425
433
if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl)) {
426
434
R = HandleDefaultTempArgIntoTempTempParam (TTP, Result);
427
435
}
436
+ if (const auto *TAD = dyn_cast<TypeAliasTemplateDecl>(CurDecl)) {
437
+ R = HandleTypeAliasTemplateDecl (TAD, ForConstraintInstantiation,
438
+ Result);
439
+ }
428
440
} else {
429
441
R = HandleGenericDeclContext (CurDecl);
430
442
}
@@ -1231,6 +1243,8 @@ namespace {
1231
1243
// Whether to evaluate the C++20 constraints or simply substitute into them.
1232
1244
bool EvaluateConstraints = true ;
1233
1245
1246
+ llvm::DenseMap<Decl *, Decl *> InstantiatedLambdas;
1247
+
1234
1248
public:
1235
1249
typedef TreeTransform<TemplateInstantiator> inherited;
1236
1250
@@ -1353,6 +1367,7 @@ namespace {
1353
1367
auto *NewMD = dyn_cast<CXXMethodDecl>(New);
1354
1368
if (NewMD && isLambdaCallOperator (NewMD)) {
1355
1369
auto *OldMD = dyn_cast<CXXMethodDecl>(Old);
1370
+ InstantiatedLambdas[OldMD] = NewMD;
1356
1371
if (auto *NewTD = NewMD->getDescribedFunctionTemplate ())
1357
1372
NewTD->setInstantiatedFromMemberTemplate (
1358
1373
OldMD->getDescribedFunctionTemplate ());
@@ -1663,6 +1678,13 @@ Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) {
1663
1678
// template parameter.
1664
1679
}
1665
1680
1681
+ if (auto *FTD = dyn_cast<FunctionTemplateDecl>(D))
1682
+ if (auto *Method = dyn_cast<CXXMethodDecl>(FTD->getTemplatedDecl ());
1683
+ Method && isLambdaCallOperator (Method))
1684
+ if (auto Iter = InstantiatedLambdas.find (Method);
1685
+ Iter != InstantiatedLambdas.end ())
1686
+ return Iter->second ;
1687
+
1666
1688
return SemaRef.FindInstantiatedDecl (Loc, cast<NamedDecl>(D), TemplateArgs);
1667
1689
}
1668
1690
0 commit comments