Skip to content

Commit 1119f0a

Browse files
committed
[Clang][NFCI] Slightly refactor getTemplateInstantiationArgs()
1 parent 3364284 commit 1119f0a

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13033,11 +13033,14 @@ class Sema final : public SemaBase {
1303313033
/// instantiation arguments.
1303413034
///
1303513035
/// \param DC In the event we don't HAVE a declaration yet, we instead provide
13036-
/// the decl context where it will be created. In this case, the `Innermost`
13037-
/// should likely be provided. If ND is non-null, this is ignored.
13036+
/// the decl context where it will be created. In this case, the \p
13037+
/// Innermost should likely be provided. If \p ND is non-null and \p
13038+
/// Innermost is NULL, this is ignored.
1303813039
///
1303913040
/// \param Innermost if non-NULL, specifies a template argument list for the
13040-
/// template declaration passed as ND.
13041+
/// template declaration passed as \p ND. The next declaration context would
13042+
/// be switched to \p DC if present; otherwise, it would be the semantic
13043+
/// declaration context of \p ND.
1304113044
///
1304213045
/// \param RelativeToPrimary true if we should get the template
1304313046
/// arguments relative to the primary template, even when we're
@@ -13053,6 +13056,9 @@ class Sema final : public SemaBase {
1305313056
/// ForConstraintInstantiation indicates we should continue looking when
1305413057
/// encountering a lambda generic call operator, and continue looking for
1305513058
/// arguments on an enclosing class template.
13059+
///
13060+
/// \param SkipForSpecialization when specified, any template specializations
13061+
/// in a traversal would be ignored.
1305613062
MultiLevelTemplateArgumentList getTemplateInstantiationArgs(
1305713063
const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false,
1305813064
std::optional<ArrayRef<TemplateArgument>> Innermost = std::nullopt,

clang/lib/Sema/SemaConcept.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ substituteParameterMappings(Sema &S, NormalizedConstraint &N,
14821482
static bool substituteParameterMappings(Sema &S, NormalizedConstraint &N,
14831483
const ConceptSpecializationExpr *CSE) {
14841484
MultiLevelTemplateArgumentList MLTAL = S.getTemplateInstantiationArgs(
1485-
CSE->getNamedConcept(), CSE->getNamedConcept()->getLexicalDeclContext(),
1485+
CSE->getNamedConcept(), CSE->getNamedConcept()->getDeclContext(),
14861486
/*Final=*/true, CSE->getTemplateArguments(),
14871487
/*RelativeToPrimary=*/true,
14881488
/*Pattern=*/nullptr,

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5582,7 +5582,7 @@ bool Sema::CheckTemplateArgumentList(
55825582
CXXThisScopeRAII(*this, RD, ThisQuals, RD != nullptr);
55835583

55845584
MultiLevelTemplateArgumentList MLTAL = getTemplateInstantiationArgs(
5585-
Template, NewContext, /*Final=*/true, SugaredConverted,
5585+
Template, Template->getDeclContext(), /*Final=*/true, SugaredConverted,
55865586
/*RelativeToPrimary=*/true,
55875587
/*Pattern=*/nullptr,
55885588
/*ForConceptInstantiation=*/true);

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ MultiLevelTemplateArgumentList Sema::getTemplateInstantiationArgs(
491491
// has a depth of 0.
492492
if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl))
493493
HandleDefaultTempArgIntoTempTempParam(TTP, Result);
494-
CurDecl = Response::UseNextDecl(CurDecl).NextDecl;
494+
CurDecl = DC ? Decl::castFromDeclContext(DC)
495+
: Response::UseNextDecl(CurDecl).NextDecl;
495496
}
496497

497498
while (!CurDecl->isFileContextDecl()) {
@@ -3242,15 +3243,13 @@ bool Sema::SubstDefaultArgument(
32423243
/*ForDefinition*/ false);
32433244
if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
32443245
return true;
3245-
const FunctionTemplateDecl *PrimaryTemplate = FD->getPrimaryTemplate();
3246-
if (PrimaryTemplate && PrimaryTemplate->isOutOfLine()) {
3247-
TemplateArgumentList *CurrentTemplateArgumentList =
3248-
TemplateArgumentList::CreateCopy(getASTContext(),
3249-
TemplateArgs.getInnermost());
3246+
// FIXME: Investigate if we shall validate every FunctionTemplateDecl
3247+
// along the getInstantiatedFromMemberTemplate() chain.
3248+
if (auto *PrimaryTemplate = FD->getPrimaryTemplate();
3249+
PrimaryTemplate && PrimaryTemplate->isOutOfLine())
32503250
NewTemplateArgs = getTemplateInstantiationArgs(
32513251
FD, FD->getDeclContext(), /*Final=*/false,
3252-
CurrentTemplateArgumentList->asArray(), /*RelativeToPrimary=*/true);
3253-
}
3252+
TemplateArgs.getInnermost(), /*RelativeToPrimary=*/true);
32543253
}
32553254

32563255
runWithSufficientStackSpace(Loc, [&] {

0 commit comments

Comments
 (0)