[NFC] Make 1st param to getTemplateInstantiationArgs const correct

The function doesn't modify anything, and took minimal effort to get
const-correct, AND is necessary for a patch I've been working on for
concepts.
This commit is contained in:
Erich Keane 2022-02-28 12:13:16 -08:00
parent b6a6ddf134
commit 96dea20155
3 changed files with 14 additions and 22 deletions

View File

@ -65,8 +65,8 @@ inline bool isGenericLambdaCallOperatorSpecialization(DeclContext *DC) {
} }
inline bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization( inline bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization(
DeclContext *DC) { const DeclContext *DC) {
CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC); const auto *MD = dyn_cast<CXXMethodDecl>(DC);
if (!MD) return false; if (!MD) return false;
const CXXRecordDecl *LambdaClass = MD->getParent(); const CXXRecordDecl *LambdaClass = MD->getParent();
if (LambdaClass && LambdaClass->isGenericLambda()) if (LambdaClass && LambdaClass->isGenericLambda())
@ -75,7 +75,6 @@ inline bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization(
return false; return false;
} }
// This returns the parent DeclContext ensuring that the correct // This returns the parent DeclContext ensuring that the correct
// parent DeclContext is returned for Lambdas // parent DeclContext is returned for Lambdas
inline DeclContext *getLambdaAwareParentOfDeclContext(DeclContext *DC) { inline DeclContext *getLambdaAwareParentOfDeclContext(DeclContext *DC) {

View File

@ -8747,11 +8747,9 @@ public:
// C++ Template Instantiation // C++ Template Instantiation
// //
MultiLevelTemplateArgumentList MultiLevelTemplateArgumentList getTemplateInstantiationArgs(
getTemplateInstantiationArgs(NamedDecl *D, const NamedDecl *D, const TemplateArgumentList *Innermost = nullptr,
const TemplateArgumentList *Innermost = nullptr, bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr);
bool RelativeToPrimary = false,
const FunctionDecl *Pattern = nullptr);
/// A context in which code is being synthesized (where a source location /// A context in which code is being synthesized (where a source location
/// alone is not sufficient to identify the context). This covers template /// alone is not sufficient to identify the context). This covers template

View File

@ -55,26 +55,23 @@ using namespace sema;
/// instantiating the definition of the given declaration, \p D. This is /// instantiating the definition of the given declaration, \p D. This is
/// used to determine the proper set of template instantiation arguments for /// used to determine the proper set of template instantiation arguments for
/// friend function template specializations. /// friend function template specializations.
MultiLevelTemplateArgumentList MultiLevelTemplateArgumentList Sema::getTemplateInstantiationArgs(
Sema::getTemplateInstantiationArgs(NamedDecl *D, const NamedDecl *D, const TemplateArgumentList *Innermost,
const TemplateArgumentList *Innermost, bool RelativeToPrimary, const FunctionDecl *Pattern) {
bool RelativeToPrimary,
const FunctionDecl *Pattern) {
// Accumulate the set of template argument lists in this structure. // Accumulate the set of template argument lists in this structure.
MultiLevelTemplateArgumentList Result; MultiLevelTemplateArgumentList Result;
if (Innermost) if (Innermost)
Result.addOuterTemplateArguments(Innermost); Result.addOuterTemplateArguments(Innermost);
DeclContext *Ctx = dyn_cast<DeclContext>(D); const auto *Ctx = dyn_cast<DeclContext>(D);
if (!Ctx) { if (!Ctx) {
Ctx = D->getDeclContext(); Ctx = D->getDeclContext();
// Add template arguments from a variable template instantiation. For a // Add template arguments from a variable template instantiation. For a
// class-scope explicit specialization, there are no template arguments // class-scope explicit specialization, there are no template arguments
// at this level, but there may be enclosing template arguments. // at this level, but there may be enclosing template arguments.
VarTemplateSpecializationDecl *Spec = const auto *Spec = dyn_cast<VarTemplateSpecializationDecl>(D);
dyn_cast<VarTemplateSpecializationDecl>(D);
if (Spec && !Spec->isClassScopeExplicitSpecialization()) { if (Spec && !Spec->isClassScopeExplicitSpecialization()) {
// We're done when we hit an explicit specialization. // We're done when we hit an explicit specialization.
if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization && if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization &&
@ -107,8 +104,7 @@ Sema::getTemplateInstantiationArgs(NamedDecl *D,
// use empty template parameter lists for all of the outer templates // use empty template parameter lists for all of the outer templates
// to avoid performing any substitutions. // to avoid performing any substitutions.
if (Ctx->isTranslationUnit()) { if (Ctx->isTranslationUnit()) {
if (TemplateTemplateParmDecl *TTP if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
= dyn_cast<TemplateTemplateParmDecl>(D)) {
for (unsigned I = 0, N = TTP->getDepth() + 1; I != N; ++I) for (unsigned I = 0, N = TTP->getDepth() + 1; I != N; ++I)
Result.addOuterTemplateArguments(None); Result.addOuterTemplateArguments(None);
return Result; return Result;
@ -118,8 +114,7 @@ Sema::getTemplateInstantiationArgs(NamedDecl *D,
while (!Ctx->isFileContext()) { while (!Ctx->isFileContext()) {
// Add template arguments from a class template instantiation. // Add template arguments from a class template instantiation.
ClassTemplateSpecializationDecl *Spec const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(Ctx);
= dyn_cast<ClassTemplateSpecializationDecl>(Ctx);
if (Spec && !Spec->isClassScopeExplicitSpecialization()) { if (Spec && !Spec->isClassScopeExplicitSpecialization()) {
// We're done when we hit an explicit specialization. // We're done when we hit an explicit specialization.
if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization && if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization &&
@ -135,7 +130,7 @@ Sema::getTemplateInstantiationArgs(NamedDecl *D,
break; break;
} }
// Add template arguments from a function template specialization. // Add template arguments from a function template specialization.
else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Ctx)) { else if (const auto *Function = dyn_cast<FunctionDecl>(Ctx)) {
if (!RelativeToPrimary && if (!RelativeToPrimary &&
Function->getTemplateSpecializationKindForInstantiation() == Function->getTemplateSpecializationKindForInstantiation() ==
TSK_ExplicitSpecialization) TSK_ExplicitSpecialization)
@ -177,7 +172,7 @@ Sema::getTemplateInstantiationArgs(NamedDecl *D,
RelativeToPrimary = false; RelativeToPrimary = false;
continue; continue;
} }
} else if (CXXRecordDecl *Rec = dyn_cast<CXXRecordDecl>(Ctx)) { } else if (const auto *Rec = dyn_cast<CXXRecordDecl>(Ctx)) {
if (ClassTemplateDecl *ClassTemplate = Rec->getDescribedClassTemplate()) { if (ClassTemplateDecl *ClassTemplate = Rec->getDescribedClassTemplate()) {
assert(Result.getNumSubstitutedLevels() == 0 && assert(Result.getNumSubstitutedLevels() == 0 &&
"Outer template not instantiated?"); "Outer template not instantiated?");