From 96dea2015554d1bf1e095ea82bc57d9229bd5fd5 Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Mon, 28 Feb 2022 12:13:16 -0800 Subject: [PATCH] [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. --- clang/include/clang/AST/ASTLambda.h | 5 ++--- clang/include/clang/Sema/Sema.h | 8 +++----- clang/lib/Sema/SemaTemplateInstantiate.cpp | 23 +++++++++-------------- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/clang/include/clang/AST/ASTLambda.h b/clang/include/clang/AST/ASTLambda.h index 6fd82d6..230e0c8 100644 --- a/clang/include/clang/AST/ASTLambda.h +++ b/clang/include/clang/AST/ASTLambda.h @@ -65,8 +65,8 @@ inline bool isGenericLambdaCallOperatorSpecialization(DeclContext *DC) { } inline bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization( - DeclContext *DC) { - CXXMethodDecl *MD = dyn_cast(DC); + const DeclContext *DC) { + const auto *MD = dyn_cast(DC); if (!MD) return false; const CXXRecordDecl *LambdaClass = MD->getParent(); if (LambdaClass && LambdaClass->isGenericLambda()) @@ -75,7 +75,6 @@ inline bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization( return false; } - // This returns the parent DeclContext ensuring that the correct // parent DeclContext is returned for Lambdas inline DeclContext *getLambdaAwareParentOfDeclContext(DeclContext *DC) { diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 9937846..0840f3a 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -8747,11 +8747,9 @@ public: // C++ Template Instantiation // - MultiLevelTemplateArgumentList - getTemplateInstantiationArgs(NamedDecl *D, - const TemplateArgumentList *Innermost = nullptr, - bool RelativeToPrimary = false, - const FunctionDecl *Pattern = nullptr); + MultiLevelTemplateArgumentList getTemplateInstantiationArgs( + const NamedDecl *D, const TemplateArgumentList *Innermost = nullptr, + bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr); /// A context in which code is being synthesized (where a source location /// alone is not sufficient to identify the context). This covers template diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 6de486be..2675665 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -55,26 +55,23 @@ using namespace sema; /// instantiating the definition of the given declaration, \p D. This is /// used to determine the proper set of template instantiation arguments for /// friend function template specializations. -MultiLevelTemplateArgumentList -Sema::getTemplateInstantiationArgs(NamedDecl *D, - const TemplateArgumentList *Innermost, - bool RelativeToPrimary, - const FunctionDecl *Pattern) { +MultiLevelTemplateArgumentList Sema::getTemplateInstantiationArgs( + const NamedDecl *D, const TemplateArgumentList *Innermost, + bool RelativeToPrimary, const FunctionDecl *Pattern) { // Accumulate the set of template argument lists in this structure. MultiLevelTemplateArgumentList Result; if (Innermost) Result.addOuterTemplateArguments(Innermost); - DeclContext *Ctx = dyn_cast(D); + const auto *Ctx = dyn_cast(D); if (!Ctx) { Ctx = D->getDeclContext(); // Add template arguments from a variable template instantiation. For a // class-scope explicit specialization, there are no template arguments // at this level, but there may be enclosing template arguments. - VarTemplateSpecializationDecl *Spec = - dyn_cast(D); + const auto *Spec = dyn_cast(D); if (Spec && !Spec->isClassScopeExplicitSpecialization()) { // We're done when we hit an explicit specialization. if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization && @@ -107,8 +104,7 @@ Sema::getTemplateInstantiationArgs(NamedDecl *D, // use empty template parameter lists for all of the outer templates // to avoid performing any substitutions. if (Ctx->isTranslationUnit()) { - if (TemplateTemplateParmDecl *TTP - = dyn_cast(D)) { + if (const auto *TTP = dyn_cast(D)) { for (unsigned I = 0, N = TTP->getDepth() + 1; I != N; ++I) Result.addOuterTemplateArguments(None); return Result; @@ -118,8 +114,7 @@ Sema::getTemplateInstantiationArgs(NamedDecl *D, while (!Ctx->isFileContext()) { // Add template arguments from a class template instantiation. - ClassTemplateSpecializationDecl *Spec - = dyn_cast(Ctx); + const auto *Spec = dyn_cast(Ctx); if (Spec && !Spec->isClassScopeExplicitSpecialization()) { // We're done when we hit an explicit specialization. if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization && @@ -135,7 +130,7 @@ Sema::getTemplateInstantiationArgs(NamedDecl *D, break; } // Add template arguments from a function template specialization. - else if (FunctionDecl *Function = dyn_cast(Ctx)) { + else if (const auto *Function = dyn_cast(Ctx)) { if (!RelativeToPrimary && Function->getTemplateSpecializationKindForInstantiation() == TSK_ExplicitSpecialization) @@ -177,7 +172,7 @@ Sema::getTemplateInstantiationArgs(NamedDecl *D, RelativeToPrimary = false; continue; } - } else if (CXXRecordDecl *Rec = dyn_cast(Ctx)) { + } else if (const auto *Rec = dyn_cast(Ctx)) { if (ClassTemplateDecl *ClassTemplate = Rec->getDescribedClassTemplate()) { assert(Result.getNumSubstitutedLevels() == 0 && "Outer template not instantiated?"); -- 2.7.4