|
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"
|
@@ -5245,9 +5246,31 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
|
5245 | 5246 | RebuildTypeSourceInfoForDefaultSpecialMembers();
|
5246 | 5247 | SetDeclDefaulted(Function, PatternDecl->getLocation());
|
5247 | 5248 | } else {
|
| 5249 | + NamedDecl *ND = Function; |
| 5250 | + DeclContext *DC = ND->getLexicalDeclContext(); |
| 5251 | + std::optional<ArrayRef<TemplateArgument>> Innermost; |
| 5252 | + if (auto *Primary = Function->getPrimaryTemplate(); |
| 5253 | + Primary && |
| 5254 | + !isGenericLambdaCallOperatorOrStaticInvokerSpecialization(Function) && |
| 5255 | + Function->getTemplateSpecializationKind() != |
| 5256 | + TSK_ExplicitSpecialization) { |
| 5257 | + auto It = llvm::find_if(Primary->redecls(), |
| 5258 | + [](const RedeclarableTemplateDecl *RTD) { |
| 5259 | + return cast<FunctionTemplateDecl>(RTD) |
| 5260 | + ->isCompatibleWithDefinition(); |
| 5261 | + }); |
| 5262 | + assert(It != Primary->redecls().end() && |
| 5263 | + "Should't get here without a definition"); |
| 5264 | + if (FunctionDecl *Def = cast<FunctionTemplateDecl>(*It) |
| 5265 | + ->getTemplatedDecl() |
| 5266 | + ->getDefinition()) |
| 5267 | + DC = Def->getLexicalDeclContext(); |
| 5268 | + else |
| 5269 | + DC = (*It)->getLexicalDeclContext(); |
| 5270 | + Innermost.emplace(Function->getTemplateSpecializationArgs()->asArray()); |
| 5271 | + } |
5248 | 5272 | MultiLevelTemplateArgumentList TemplateArgs = getTemplateInstantiationArgs(
|
5249 |
| - Function, Function->getLexicalDeclContext(), /*Final=*/false, |
5250 |
| - /*Innermost=*/std::nullopt, false, PatternDecl); |
| 5273 | + Function, DC, /*Final=*/false, Innermost, false, PatternDecl); |
5251 | 5274 |
|
5252 | 5275 | // Substitute into the qualifier; we can get a substitution failure here
|
5253 | 5276 | // through evil use of alias templates.
|
|
0 commit comments