https://github.com/Endilll created https://github.com/llvm/llvm-project/pull/92500
This patch remove const-qualification from pointee type of `FunctionTemplateSpecializationInfo::TemplateArguments`, because it's (eventually) used to initialize `MultiLevelTemplateArgumentList`, which can actually mutate the arguments via https://github.com/llvm/llvm-project/blob/f42f57b52dd279e6ae19270d063aeb8d59e3f11c/clang/include/clang/Sema/Template.h#L197-L204 Mutation seems to be required to correctly handle packs: https://github.com/llvm/llvm-project/blob/9144553207052a868efc5a8ce61a0afbb0eaf236/clang/lib/Sema/SemaTemplateInstantiate.cpp#L1440-L1469 >From a8a6e0dae0ac0903f6cc759ff2680320ab96d2dc Mon Sep 17 00:00:00 2001 From: Vlad Serebrennikov <serebrennikov.vladis...@gmail.com> Date: Fri, 17 May 2024 09:09:29 +0300 Subject: [PATCH] [clang][NFC] Remove const-qualification from `FunctionTemplateSpecializationInfo::TemplateArguments` --- clang/include/clang/AST/Decl.h | 25 ++++++++++++------------- clang/include/clang/AST/DeclTemplate.h | 7 +++---- clang/lib/AST/Decl.cpp | 14 ++++++-------- clang/lib/AST/DeclTemplate.cpp | 2 +- clang/lib/Sema/SemaTemplate.cpp | 2 +- 5 files changed, 23 insertions(+), 27 deletions(-) diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index de8b923645f8d..5e485ccb85a13 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -2096,13 +2096,12 @@ class FunctionDecl : public DeclaratorDecl, /// /// \param PointOfInstantiation point at which the function template /// specialization was first instantiated. - void setFunctionTemplateSpecialization(ASTContext &C, - FunctionTemplateDecl *Template, - const TemplateArgumentList *TemplateArgs, - void *InsertPos, - TemplateSpecializationKind TSK, - const TemplateArgumentListInfo *TemplateArgsAsWritten, - SourceLocation PointOfInstantiation); + void setFunctionTemplateSpecialization( + ASTContext &C, FunctionTemplateDecl *Template, + TemplateArgumentList *TemplateArgs, void *InsertPos, + TemplateSpecializationKind TSK, + const TemplateArgumentListInfo *TemplateArgsAsWritten, + SourceLocation PointOfInstantiation); /// Specify that this record is an instantiation of the /// member function FD. @@ -2981,12 +2980,12 @@ class FunctionDecl : public DeclaratorDecl, /// /// \param PointOfInstantiation point at which the function template /// specialization was first instantiated. - void setFunctionTemplateSpecialization(FunctionTemplateDecl *Template, - const TemplateArgumentList *TemplateArgs, - void *InsertPos, - TemplateSpecializationKind TSK = TSK_ImplicitInstantiation, - const TemplateArgumentListInfo *TemplateArgsAsWritten = nullptr, - SourceLocation PointOfInstantiation = SourceLocation()) { + void setFunctionTemplateSpecialization( + FunctionTemplateDecl *Template, TemplateArgumentList *TemplateArgs, + void *InsertPos, + TemplateSpecializationKind TSK = TSK_ImplicitInstantiation, + TemplateArgumentListInfo *TemplateArgsAsWritten = nullptr, + SourceLocation PointOfInstantiation = SourceLocation()) { setFunctionTemplateSpecialization(getASTContext(), Template, TemplateArgs, InsertPos, TSK, TemplateArgsAsWritten, PointOfInstantiation); diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index 268aeacf2f20f..f3d6a321ecf10 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -478,7 +478,7 @@ class FunctionTemplateSpecializationInfo final public: /// The template arguments used to produce the function template /// specialization from the function template. - const TemplateArgumentList *TemplateArguments; + TemplateArgumentList *TemplateArguments; /// The template arguments as written in the sources, if provided. /// FIXME: Normally null; tail-allocate this. @@ -491,7 +491,7 @@ class FunctionTemplateSpecializationInfo final private: FunctionTemplateSpecializationInfo( FunctionDecl *FD, FunctionTemplateDecl *Template, - TemplateSpecializationKind TSK, const TemplateArgumentList *TemplateArgs, + TemplateSpecializationKind TSK, TemplateArgumentList *TemplateArgs, const ASTTemplateArgumentListInfo *TemplateArgsAsWritten, SourceLocation POI, MemberSpecializationInfo *MSInfo) : Function(FD, MSInfo ? true : false), Template(Template, TSK - 1), @@ -511,8 +511,7 @@ class FunctionTemplateSpecializationInfo final static FunctionTemplateSpecializationInfo * Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template, - TemplateSpecializationKind TSK, - const TemplateArgumentList *TemplateArgs, + TemplateSpecializationKind TSK, TemplateArgumentList *TemplateArgs, const TemplateArgumentListInfo *TemplateArgsAsWritten, SourceLocation POI, MemberSpecializationInfo *MSInfo); diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index ec851c9371e10..41fbfe281ef65 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -4199,14 +4199,12 @@ FunctionDecl::getTemplateSpecializationArgsAsWritten() const { return nullptr; } -void -FunctionDecl::setFunctionTemplateSpecialization(ASTContext &C, - FunctionTemplateDecl *Template, - const TemplateArgumentList *TemplateArgs, - void *InsertPos, - TemplateSpecializationKind TSK, - const TemplateArgumentListInfo *TemplateArgsAsWritten, - SourceLocation PointOfInstantiation) { +void FunctionDecl::setFunctionTemplateSpecialization( + ASTContext &C, FunctionTemplateDecl *Template, + TemplateArgumentList *TemplateArgs, void *InsertPos, + TemplateSpecializationKind TSK, + const TemplateArgumentListInfo *TemplateArgsAsWritten, + SourceLocation PointOfInstantiation) { assert((TemplateOrSpecialization.isNull() || TemplateOrSpecialization.is<MemberSpecializationInfo *>()) && "Member function is already a specialization"); diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index d22ecc3c032e7..26765a5da1dc6 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -884,7 +884,7 @@ TemplateArgumentList::CreateCopy(ASTContext &Context, FunctionTemplateSpecializationInfo *FunctionTemplateSpecializationInfo::Create( ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template, - TemplateSpecializationKind TSK, const TemplateArgumentList *TemplateArgs, + TemplateSpecializationKind TSK, TemplateArgumentList *TemplateArgs, const TemplateArgumentListInfo *TemplateArgsAsWritten, SourceLocation POI, MemberSpecializationInfo *MSInfo) { const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr; diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 1b3f1e8bf80f4..ce09193721239 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -10494,7 +10494,7 @@ bool Sema::CheckFunctionTemplateSpecialization( // specialization, with the template arguments from the previous // specialization. // Take copies of (semantic and syntactic) template argument lists. - const TemplateArgumentList *TemplArgs = TemplateArgumentList::CreateCopy( + TemplateArgumentList *TemplArgs = TemplateArgumentList::CreateCopy( Context, Specialization->getTemplateSpecializationArgs()->asArray()); FD->setFunctionTemplateSpecialization( Specialization->getPrimaryTemplate(), TemplArgs, /*InsertPos=*/nullptr, _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits