|
12 | 12 | #include "TreeTransform.h" |
13 | 13 | #include "clang/AST/ASTConsumer.h" |
14 | 14 | #include "clang/AST/ASTContext.h" |
| 15 | +#include "clang/AST/ASTLambda.h" |
15 | 16 | #include "clang/AST/ASTMutationListener.h" |
16 | 17 | #include "clang/AST/DeclTemplate.h" |
17 | 18 | #include "clang/AST/DependentDiagnostic.h" |
@@ -5276,9 +5277,31 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, |
5276 | 5277 | RebuildTypeSourceInfoForDefaultSpecialMembers(); |
5277 | 5278 | SetDeclDefaulted(Function, PatternDecl->getLocation()); |
5278 | 5279 | } else { |
| 5280 | + NamedDecl *ND = Function; |
| 5281 | + DeclContext *DC = ND->getLexicalDeclContext(); |
| 5282 | + std::optional<ArrayRef<TemplateArgument>> Innermost; |
| 5283 | + if (auto *Primary = Function->getPrimaryTemplate(); |
| 5284 | + Primary && |
| 5285 | + !isGenericLambdaCallOperatorOrStaticInvokerSpecialization(Function) && |
| 5286 | + Function->getTemplateSpecializationKind() != |
| 5287 | + TSK_ExplicitSpecialization) { |
| 5288 | + auto It = llvm::find_if(Primary->redecls(), |
| 5289 | + [](const RedeclarableTemplateDecl *RTD) { |
| 5290 | + return cast<FunctionTemplateDecl>(RTD) |
| 5291 | + ->isCompatibleWithDefinition(); |
| 5292 | + }); |
| 5293 | + assert(It != Primary->redecls().end() && |
| 5294 | + "Should't get here without a definition"); |
| 5295 | + if (FunctionDecl *Def = cast<FunctionTemplateDecl>(*It) |
| 5296 | + ->getTemplatedDecl() |
| 5297 | + ->getDefinition()) |
| 5298 | + DC = Def->getLexicalDeclContext(); |
| 5299 | + else |
| 5300 | + DC = (*It)->getLexicalDeclContext(); |
| 5301 | + Innermost.emplace(Function->getTemplateSpecializationArgs()->asArray()); |
| 5302 | + } |
5279 | 5303 | MultiLevelTemplateArgumentList TemplateArgs = getTemplateInstantiationArgs( |
5280 | | - Function, Function->getLexicalDeclContext(), /*Final=*/false, |
5281 | | - /*Innermost=*/std::nullopt, false, PatternDecl); |
| 5304 | + Function, DC, /*Final=*/false, Innermost, false, PatternDecl); |
5282 | 5305 |
|
5283 | 5306 | // Substitute into the qualifier; we can get a substitution failure here |
5284 | 5307 | // through evil use of alias templates. |
|
0 commit comments