[llvm-branch-commits] [clang] [clang-tools-extra] [clang] fix getTemplateInstantiationArgs (PR #199528)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon May 25 06:33:35 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clangd
Author: Matheus Izvekov (mizvekov)
<details>
<summary>Changes</summary>
This implements a new strategy for collecting the template arguments, by relying on the qualifiers and template parameter lists to navigate the template context of out-of-line definitions.
This greatly simplifies the signature of that function, by removing a bunch of workarounds, and simpliffying a couple that weren't removed yet.
Since this now relies on qualifiers and template parameter lists, this patch expends most of its effort making sure these are placed, transformed and propagated to template instantiations.
Also makes the explicit specialization AST nodes stop abusing the template parameter lists by storing it's own template parameter list, creating a dedicated field for them, similar to partial specializations.
---
Patch is 256.34 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/199528.diff
52 Files Affected:
- (modified) clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp (+1-1)
- (modified) clang-tools-extra/clangd/SemanticHighlighting.cpp (+21-18)
- (modified) clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp (+1-1)
- (modified) clang/docs/ReleaseNotes.rst (+3)
- (modified) clang/include/clang/AST/Decl.h (+17-5)
- (modified) clang/include/clang/AST/DeclTemplate.h (+96-95)
- (modified) clang/include/clang/AST/JSONNodeDumper.h (+1)
- (modified) clang/include/clang/AST/RecursiveASTVisitor.h (+8-6)
- (modified) clang/include/clang/ASTMatchers/ASTMatchers.h (+5)
- (modified) clang/include/clang/ASTMatchers/ASTMatchersInternal.h (+2-6)
- (modified) clang/include/clang/Basic/Specifiers.h (+3)
- (modified) clang/include/clang/Sema/Sema.h (+42-101)
- (modified) clang/lib/AST/ASTContext.cpp (+2)
- (modified) clang/lib/AST/ASTDumper.cpp (+1)
- (modified) clang/lib/AST/ASTImporter.cpp (+90-32)
- (modified) clang/lib/AST/Comment.cpp (+6-4)
- (modified) clang/lib/AST/Decl.cpp (+36-9)
- (modified) clang/lib/AST/DeclPrinter.cpp (+1)
- (modified) clang/lib/AST/DeclTemplate.cpp (+62-94)
- (modified) clang/lib/AST/JSONNodeDumper.cpp (+3)
- (modified) clang/lib/AST/TextNodeDumper.cpp (+3)
- (modified) clang/lib/ASTMatchers/Dynamic/Registry.cpp (+1)
- (modified) clang/lib/Analysis/ExprMutationAnalyzer.cpp (+8-5)
- (modified) clang/lib/CodeGen/CGVTables.cpp (+17-15)
- (modified) clang/lib/Index/IndexingContext.cpp (+1)
- (modified) clang/lib/InstallAPI/Visitor.cpp (+5)
- (modified) clang/lib/Parse/ParseDeclCXX.cpp (+8-6)
- (modified) clang/lib/Sema/HLSLExternalSemaSource.cpp (+7-8)
- (modified) clang/lib/Sema/SemaConcept.cpp (+59-129)
- (modified) clang/lib/Sema/SemaDecl.cpp (+27-26)
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+7-4)
- (modified) clang/lib/Sema/SemaExprMember.cpp (+2-3)
- (modified) clang/lib/Sema/SemaOverload.cpp (+4-2)
- (modified) clang/lib/Sema/SemaTemplate.cpp (+149-147)
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+11-32)
- (modified) clang/lib/Sema/SemaTemplateDeductionGuide.cpp (+7-50)
- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+188-423)
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+265-169)
- (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+41-36)
- (modified) clang/lib/Serialization/ASTWriterDecl.cpp (+61-39)
- (modified) clang/lib/StaticAnalyzer/Core/BugSuppression.cpp (+7-71)
- (modified) clang/lib/Tooling/Syntax/BuildTree.cpp (+7-6)
- (modified) clang/test/AST/ast-dump-templates-pattern.cpp (+10-9)
- (modified) clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp (+4-7)
- (modified) clang/test/CXX/temp/temp.constr/temp.constr.decl/p4.cpp (+2-15)
- (modified) clang/test/SemaTemplate/concepts-out-of-line-def.cpp (+2-7)
- (modified) clang/test/SemaTemplate/instantiate-scope.cpp (+4-6)
- (modified) clang/test/Templight/templight-default-func-arg.cpp (+23-10)
- (modified) clang/test/Templight/templight-empty-entries-fix.cpp (+50-38)
- (modified) clang/tools/libclang/CIndex.cpp (+1)
- (modified) clang/unittests/AST/ASTImporterTest.cpp (+4-2)
- (modified) clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp (+2-2)
``````````diff
diff --git a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
index ae063a19d779d..a1a705dd043a0 100644
--- a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -106,7 +106,7 @@ void DefinitionsInHeadersCheck::check(const MatchFinder::MatchResult &Result) {
return;
diag(FD->getLocation(), "mark the definition as 'inline'",
DiagnosticIDs::Note)
- << FixItHint::CreateInsertion(FD->getInnerLocStart(), "inline ");
+ << FixItHint::CreateInsertion(FD->getFunctionLocStart(), "inline ");
} else if (const auto *VD = dyn_cast<VarDecl>(ND)) {
// C++14 variable templates are allowed.
if (VD->getDescribedVarTemplate())
diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index 751ee254d3623..3c33b88d897fc 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -590,28 +590,28 @@ class CollectExtraHighlightings
bool
VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D) {
- if (auto *Args = D->getTemplateArgsAsWritten())
- H.addAngleBracketTokens(Args->getLAngleLoc(), Args->getRAngleLoc());
- return true;
- }
-
- bool VisitClassTemplatePartialSpecializationDecl(
- ClassTemplatePartialSpecializationDecl *D) {
- if (auto *TPL = D->getTemplateParameters())
- H.addAngleBracketTokens(TPL->getLAngleLoc(), TPL->getRAngleLoc());
+ if (const auto *Info = D->getExplicitInstantiationInfo()) {
+ H.addAngleBracketTokens(Info->TemplateArgsAsWritten->getLAngleLoc(),
+ Info->TemplateArgsAsWritten->getRAngleLoc());
+ } else if (const auto *Info = D->getExplicitSpecializationInfo()) {
+ H.addAngleBracketTokens(Info->TemplateParams->getLAngleLoc(),
+ Info->TemplateParams->getRAngleLoc());
+ H.addAngleBracketTokens(Info->TemplateArgsAsWritten->getLAngleLoc(),
+ Info->TemplateArgsAsWritten->getRAngleLoc());
+ }
return true;
}
bool VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D) {
- if (auto *Args = D->getTemplateArgsAsWritten())
- H.addAngleBracketTokens(Args->getLAngleLoc(), Args->getRAngleLoc());
- return true;
- }
-
- bool VisitVarTemplatePartialSpecializationDecl(
- VarTemplatePartialSpecializationDecl *D) {
- if (auto *TPL = D->getTemplateParameters())
- H.addAngleBracketTokens(TPL->getLAngleLoc(), TPL->getRAngleLoc());
+ if (const auto *Info = D->getExplicitInstantiationInfo()) {
+ H.addAngleBracketTokens(Info->TemplateArgsAsWritten->getLAngleLoc(),
+ Info->TemplateArgsAsWritten->getRAngleLoc());
+ } else if (const auto *Info = D->getExplicitSpecializationInfo()) {
+ H.addAngleBracketTokens(Info->TemplateParams->getLAngleLoc(),
+ Info->TemplateParams->getRAngleLoc());
+ H.addAngleBracketTokens(Info->TemplateArgsAsWritten->getLAngleLoc(),
+ Info->TemplateArgsAsWritten->getRAngleLoc());
+ }
return true;
}
@@ -625,6 +625,9 @@ class CollectExtraHighlightings
}
bool VisitFunctionDecl(FunctionDecl *D) {
+ if (const TemplateParameterList *TPL =
+ D->getTemplateSpecializationParameters())
+ H.addAngleBracketTokens(TPL->getLAngleLoc(), TPL->getRAngleLoc());
if (D->isOverloadedOperator()) {
const auto AddOpDeclToken = [&](SourceLocation Loc) {
auto &Token = H.addToken(Loc, HighlightingKind::Operator)
diff --git a/clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp b/clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp
index c9704492bf1cd..5fcb1a24448b8 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp
@@ -364,7 +364,7 @@ addInlineIfInHeader(const FunctionDecl *FD) {
if (!isHeaderFile(FileName, FD->getASTContext().getLangOpts()))
return std::nullopt;
- return tooling::Replacement(SM, FD->getInnerLocStart(), 0, "inline ");
+ return tooling::Replacement(SM, FD->getFunctionLocStart(), 0, "inline ");
}
/// Moves definition of a function/method to its declaration location.
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3c1eacfc05dc8..b6941e80b7750 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -642,7 +642,10 @@ Bug Fixes to C++ Support
- Fixed an alias template CTAD crash.
- Correctly diagnose uses of ``co_await`` / ``co_yield`` in the default argument of nested function declarations. (#GH98923)
- Fixed a crash when diagnosing an invalid static member function with an explicit object parameter (#GH177741)
+- Fixed clang incorrectly rejecting several cases of out-ofline definitions.
- Clang incorrectly instantiated variable specializations outside of the immediate context. (#GH54439)
+- Fixed a bug matching constrained out-of-line definitions of class members.
+- Fixed a crash when instantiating an invalid out-of-line static data member definition in a local class. (#GH176152)
- Fixed a crash when pack expansions are used as arguments for non-pack parameters of built-in templates. (#GH180307)
- Fix a problem where a substitution failure when evaluating a type requirement
could directly make the program ill-formed.
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 01b9ba45be9ad..84fed785eaa03 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -2147,8 +2147,9 @@ class FunctionDecl : public DeclaratorDecl,
ASTContext &C, FunctionTemplateDecl *Template,
TemplateArgumentList *TemplateArgs, void *InsertPos,
TemplateSpecializationKind TSK,
+ const TemplateParameterList *TemplateParams,
const TemplateArgumentListInfo *TemplateArgsAsWritten,
- SourceLocation PointOfInstantiation);
+ SourceLocation PointOfInstantiation, bool AddSpecialization);
/// Specify that this record is an instantiation of the
/// member function FD.
@@ -2245,6 +2246,8 @@ class FunctionDecl : public DeclaratorDecl,
return SourceLocation();
}
+ SourceLocation getFunctionLocStart() const;
+
SourceRange getSourceRange() const override LLVM_READONLY;
// Function definitions.
@@ -3070,6 +3073,9 @@ class FunctionDecl : public DeclaratorDecl,
const ASTTemplateArgumentListInfo*
getTemplateSpecializationArgsAsWritten() const;
+ /// Returns the template parameter list for an explicit specialization.
+ const TemplateParameterList *getTemplateSpecializationParameters() const;
+
/// Specify that this function declaration is actually a function
/// template specialization.
///
@@ -3085,6 +3091,9 @@ class FunctionDecl : public DeclaratorDecl,
///
/// \param TSK the kind of template specialization this is.
///
+ /// \param TemplateParams the template parameters if this is an explicit
+ /// specialization.
+ ///
/// \param TemplateArgsAsWritten location info of template arguments.
///
/// \param PointOfInstantiation point at which the function template
@@ -3093,17 +3102,20 @@ class FunctionDecl : public DeclaratorDecl,
FunctionTemplateDecl *Template, TemplateArgumentList *TemplateArgs,
void *InsertPos,
TemplateSpecializationKind TSK = TSK_ImplicitInstantiation,
+ const TemplateParameterList *TemplateParams = nullptr,
TemplateArgumentListInfo *TemplateArgsAsWritten = nullptr,
- SourceLocation PointOfInstantiation = SourceLocation()) {
- setFunctionTemplateSpecialization(getASTContext(), Template, TemplateArgs,
- InsertPos, TSK, TemplateArgsAsWritten,
- PointOfInstantiation);
+ SourceLocation PointOfInstantiation = SourceLocation(),
+ bool AddSpecialization = true) {
+ setFunctionTemplateSpecialization(
+ getASTContext(), Template, TemplateArgs, InsertPos, TSK, TemplateParams,
+ TemplateArgsAsWritten, PointOfInstantiation, AddSpecialization);
}
/// Specifies that this function declaration is actually a
/// dependent function template specialization.
void setDependentTemplateSpecialization(
ASTContext &Context, const UnresolvedSetImpl &Templates,
+ const TemplateParameterList *TemplateParams,
const TemplateArgumentListInfo *TemplateArgs);
DependentFunctionTemplateSpecializationInfo *
diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h
index 6ca9d67af0710..fbc6540538314 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -73,7 +73,7 @@ class TemplateParameterList final
: private llvm::TrailingObjects<TemplateParameterList, NamedDecl *,
Expr *> {
/// The template argument list of the template parameter list.
- TemplateArgument *InjectedArgs = nullptr;
+ mutable TemplateArgument *InjectedArgs = nullptr;
/// The location of the 'template' keyword.
SourceLocation TemplateLoc;
@@ -200,7 +200,8 @@ class TemplateParameterList final
bool hasAssociatedConstraints() const;
/// Get the template argument list of the template parameter list.
- ArrayRef<TemplateArgument> getInjectedTemplateArgs(const ASTContext &Context);
+ ArrayRef<TemplateArgument>
+ getInjectedTemplateArgs(const ASTContext &Context) const;
SourceLocation getTemplateLoc() const { return TemplateLoc; }
SourceLocation getLAngleLoc() const { return LAngleLoc; }
@@ -475,14 +476,18 @@ class FunctionTemplateSpecializationInfo final
/// The function template from which this function template
/// specialization was generated.
///
- /// The two bits contain the top 4 values of TemplateSpecializationKind.
- llvm::PointerIntPair<FunctionTemplateDecl *, 2> Template;
+ /// The three bits contain the TemplateSpecializationKind.
+ llvm::PointerIntPair<FunctionTemplateDecl *, 3> Template;
public:
/// The template arguments used to produce the function template
/// specialization from the function template.
TemplateArgumentList *TemplateArguments;
+ // The template parameters if this is an explicit specialization.
+ /// FIXME: Normally null; tail-allocate this.
+ const TemplateParameterList *TemplateParameters;
+
/// The template arguments as written in the sources, if provided.
/// FIXME: Normally null; tail-allocate this.
const ASTTemplateArgumentListInfo *TemplateArgumentsAsWritten;
@@ -495,12 +500,14 @@ class FunctionTemplateSpecializationInfo final
FunctionTemplateSpecializationInfo(
FunctionDecl *FD, FunctionTemplateDecl *Template,
TemplateSpecializationKind TSK, TemplateArgumentList *TemplateArgs,
+ const TemplateParameterList *TemplateParameters,
const ASTTemplateArgumentListInfo *TemplateArgsAsWritten,
SourceLocation POI, MemberSpecializationInfo *MSInfo)
: Function(FD, MSInfo ? true : false), Template(Template, TSK - 1),
- TemplateArguments(TemplateArgs),
+ TemplateArguments(TemplateArgs), TemplateParameters(TemplateParameters),
TemplateArgumentsAsWritten(TemplateArgsAsWritten),
PointOfInstantiation(POI) {
+ assert(TemplateParameters == nullptr || TSK == TSK_ExplicitSpecialization);
if (MSInfo)
getTrailingObjects()[0] = MSInfo;
}
@@ -513,6 +520,7 @@ class FunctionTemplateSpecializationInfo final
static FunctionTemplateSpecializationInfo *
Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template,
TemplateSpecializationKind TSK, TemplateArgumentList *TemplateArgs,
+ const TemplateParameterList *TemplateParameters,
const TemplateArgumentListInfo *TemplateArgsAsWritten,
SourceLocation POI, MemberSpecializationInfo *MSInfo);
@@ -613,8 +621,8 @@ class FunctionTemplateSpecializationInfo final
/// member class or member enumeration.
class MemberSpecializationInfo {
// The member declaration from which this member was instantiated, and the
- // manner in which the instantiation occurred (in the lower two bits).
- llvm::PointerIntPair<NamedDecl *, 2> MemberAndTSK;
+ // manner in which the instantiation occurred (in the lower three bits).
+ llvm::PointerIntPair<NamedDecl *, 3> MemberAndTSK;
// The point at which this member was first instantiated.
SourceLocation PointOfInstantiation;
@@ -693,14 +701,19 @@ class DependentFunctionTemplateSpecializationInfo final
DependentFunctionTemplateSpecializationInfo(
const UnresolvedSetImpl &Candidates,
+ const TemplateParameterList *TemplateParams,
const ASTTemplateArgumentListInfo *TemplateArgsWritten);
public:
+ // The template parameters if this is an explicit specialization.
+ const TemplateParameterList *TemplateParameters;
+
/// The template arguments as written in the sources, if provided.
const ASTTemplateArgumentListInfo *TemplateArgumentsAsWritten;
static DependentFunctionTemplateSpecializationInfo *
Create(ASTContext &Context, const UnresolvedSetImpl &Candidates,
+ const TemplateParameterList *TemplateParams,
const TemplateArgumentListInfo *TemplateArgs);
/// Returns the candidates for the primary function template.
@@ -1005,11 +1018,6 @@ class FunctionTemplateDecl : public RedeclarableTemplateDecl {
return getTemplatedDecl()->isThisDeclarationADefinition();
}
- bool isCompatibleWithDefinition() const {
- return getTemplatedDecl()->isInstantiatedFromMemberTemplate() ||
- isThisDeclarationADefinition();
- }
-
// This bit closely tracks 'RedeclarableTemplateDecl::InstantiatedFromMember',
// except this is per declaration, while the redeclarable field is
// per chain. This indicates a template redeclaration which
@@ -1807,8 +1815,18 @@ struct ExplicitInstantiationInfo {
ExplicitInstantiationInfo() = default;
};
+struct ExplicitSpecializationInfo {
+ /// The list of template parameters
+ TemplateParameterList *TemplateParams = nullptr;
+
+ /// The template arguments as written.
+ const ASTTemplateArgumentListInfo *TemplateArgsAsWritten = nullptr;
+
+ ExplicitSpecializationInfo() = default;
+};
+
using SpecializationOrInstantiationInfo =
- llvm::PointerUnion<const ASTTemplateArgumentListInfo *,
+ llvm::PointerUnion<ExplicitSpecializationInfo *,
ExplicitInstantiationInfo *>;
/// Represents a class template specialization, which refers to
@@ -2038,49 +2056,38 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
/// Retrieve the template argument list as written in the sources,
/// if any.
const ASTTemplateArgumentListInfo *getTemplateArgsAsWritten() const {
- if (auto *Info =
- dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo))
+ if (const auto *Info = getExplicitSpecializationInfo())
return Info->TemplateArgsAsWritten;
- return cast<const ASTTemplateArgumentListInfo *>(ExplicitInfo);
- }
-
- /// Set the template argument list as written in the sources.
- void
- setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten) {
- if (auto *Info =
- dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo))
- Info->TemplateArgsAsWritten = ArgsWritten;
- else
- ExplicitInfo = ArgsWritten;
+ if (const auto *Info = getExplicitInstantiationInfo())
+ return Info->TemplateArgsAsWritten;
+ return nullptr;
}
- /// Set the template argument list as written in the sources.
- void setTemplateArgsAsWritten(const TemplateArgumentListInfo &ArgsInfo) {
- setTemplateArgsAsWritten(
- ASTTemplateArgumentListInfo::Create(getASTContext(), ArgsInfo));
+ /// Gets the explicit instantiation info, if present.
+ const ExplicitInstantiationInfo *getExplicitInstantiationInfo() const {
+ return dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo);
}
- /// Gets the location of the extern keyword, if present.
- SourceLocation getExternKeywordLoc() const {
- if (auto *Info =
- dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo))
- return Info->ExternKeywordLoc;
- return SourceLocation();
+ /// Sets the explicit instantiation info.
+ void setExplicitInstantiationInfo(
+ SourceLocation ExternKeywordLoc, SourceLocation TemplateKeywordLoc,
+ const ASTTemplateArgumentListInfo *TemplateArgsAsWritten) {
+ auto *Info = new (getASTContext()) ExplicitInstantiationInfo();
+ Info->ExternKeywordLoc = ExternKeywordLoc;
+ Info->TemplateKeywordLoc = TemplateKeywordLoc;
+ Info->TemplateArgsAsWritten = TemplateArgsAsWritten;
+ ExplicitInfo = Info;
}
- /// Sets the location of the extern keyword.
- void setExternKeywordLoc(SourceLocation Loc);
-
- /// Gets the location of the template keyword, if present.
- SourceLocation getTemplateKeywordLoc() const {
- if (auto *Info =
- dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo))
- return Info->TemplateKeywordLoc;
- return SourceLocation();
+ /// Gets the explicit specialization info, if present.
+ const ExplicitSpecializationInfo *getExplicitSpecializationInfo() const {
+ return dyn_cast_if_present<ExplicitSpecializationInfo *>(ExplicitInfo);
}
- /// Sets the location of the template keyword.
- void setTemplateKeywordLoc(SourceLocation Loc);
+ /// Sets the explicit specialization info.
+ void setExplicitSpecializationInfo(
+ TemplateParameterList *TemplateParams,
+ const ASTTemplateArgumentListInfo *TemplateArgsAsWritten);
SourceRange getSourceRange() const override LLVM_READONLY;
@@ -2105,10 +2112,7 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
};
class ClassTemplatePartialSpecializationDecl
- : public ClassTemplateSpecializationDecl {
- /// The list of template parameters
- TemplateParameterList *TemplateParams = nullptr;
-
+ : public ClassTemplateSpecializationDecl {
/// The class template partial specialization from which this
/// class template partial specialization was instantiated.
///
@@ -2122,6 +2126,7 @@ class ClassTemplatePartialSpecializationDecl
ClassTemplatePartialSpecializationDecl(
ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc,
SourceLocation IdLoc, TemplateParameterList *Params,
+ const ASTTemplateArgumentListInfo *ArgsAsWritten,
ClassTemplateDecl *SpecializedTemplate, ArrayRef<TemplateArgument> Args,
CanQualType CanonInjectedTST,
ClassTemplatePartialSpecializationDecl *PrevDecl);
@@ -2139,7 +2144,9 @@ class ClassTemplatePartialSpecializationDecl
static ClassTemplatePartialSpecializationDecl *
Create(ASTContext &Context, TagKind TK, DeclContext *DC,
SourceLocation StartLoc, SourceLocation IdLoc,
- TemplateParameterList *Params, ClassTemplateDecl *SpecializedTemplate,
+ TemplateParameterList *Params,
+ const ASTTemplateArgumentListInfo *TemplateArgsAsWritten,
+ ClassTemplateDecl *SpecializedTemplate,
ArrayRef<TemplateArgument> Args, CanQualType CanonInjectedTST,
ClassTemplatePartialSpecializationDecl *PrevDecl);
@@ -2154,7 +2161,10 @@ class ClassTemplatePartialSpecializationDecl
/// Get the list of template parameters
TemplateParameterList *getTemplateParameters() const {
- return TemplateParams;
+ auto *ExplicitSpecInfo = getExplicitSpecializationInfo();
+ assert(ExplicitSpecInfo &&
+ "A partial specialization is always an explicit specialization");
+ return ExplicitSpecInfo->TemplateParams;
}
/// \brief All associated constraints of this partial specialization,
@@ -2165,11 +2175,11 @@ class ClassTemplatePartialSpecializationDecl
/// conjunction ("and").
void getAssociatedConstraints(
llvm::SmallVectorImpl<AssociatedConstraint> &AC) const {
- TemplateParams->getAssociatedConstraints(AC);
+ getTemplateParameters()->getAssociatedConstraints(AC);
}
bool hasAssociatedConstraints() const {
- return TemplateParams->hasAssociatedConstraints();
+ return getTemplateParameters()->hasAssociatedConstraints();
}
/...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/199528
More information about the llvm-branch-commits
mailing list