|
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,26 @@ 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 | + DC = (*It)->getLexicalDeclContext(); |
| 5265 | + Innermost.emplace(Function->getTemplateSpecializationArgs()->asArray()); |
| 5266 | + } |
5248 | 5267 | MultiLevelTemplateArgumentList TemplateArgs = getTemplateInstantiationArgs( |
5249 | | - Function, Function->getLexicalDeclContext(), /*Final=*/false, |
5250 | | - /*Innermost=*/std::nullopt, false, PatternDecl); |
| 5268 | + Function, DC, /*Final=*/false, Innermost, false, PatternDecl); |
5251 | 5269 |
|
5252 | 5270 | // Substitute into the qualifier; we can get a substitution failure here |
5253 | 5271 | // through evil use of alias templates. |
|
0 commit comments