[clang] [clang-tools-extra] [lldb] Revert "[clang] Reland: fix getTemplateInstantiationArgs (#208285)" (PR #208426)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 9 04:12:42 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-modules
Author: Hans Wennborg (zmodem)
<details>
<summary>Changes</summary>
It caused various breakages; see comments on the PR.
This reverts commit 031b773b01700acf82f5977a5aa6024621b8211c.
---
Patch is 282.62 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/208426.diff
70 Files Affected:
- (modified) clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp (+1-1)
- (modified) clang-tools-extra/clangd/SemanticHighlighting.cpp (+18-21)
- (modified) clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp (+1-1)
- (modified) clang/docs/LibASTMatchersReference.html (-5)
- (modified) clang/docs/ReleaseNotes.md (-1)
- (modified) clang/include/clang/AST/Decl.h (+37-21)
- (modified) clang/include/clang/AST/DeclTemplate.h (+95-96)
- (modified) clang/include/clang/AST/JSONNodeDumper.h (-1)
- (modified) clang/include/clang/AST/RecursiveASTVisitor.h (+2-6)
- (modified) clang/include/clang/ASTMatchers/ASTMatchers.h (-5)
- (modified) clang/include/clang/ASTMatchers/ASTMatchersInternal.h (+6-2)
- (modified) clang/include/clang/Basic/Specifiers.h (-3)
- (modified) clang/include/clang/Sema/Sema.h (+101-42)
- (modified) clang/lib/AST/ASTContext.cpp (-2)
- (modified) clang/lib/AST/ASTDumper.cpp (-1)
- (modified) clang/lib/AST/ASTImporter.cpp (+34-97)
- (modified) clang/lib/AST/Comment.cpp (+4-6)
- (modified) clang/lib/AST/Decl.cpp (+9-36)
- (modified) clang/lib/AST/DeclPrinter.cpp (-1)
- (modified) clang/lib/AST/DeclTemplate.cpp (+94-62)
- (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 (+5-8)
- (modified) clang/lib/CIR/CodeGen/CIRGenVTables.cpp (-2)
- (modified) clang/lib/CodeGen/CGVTables.cpp (+15-17)
- (modified) clang/lib/Index/IndexingContext.cpp (-1)
- (modified) clang/lib/InstallAPI/Visitor.cpp (-5)
- (modified) clang/lib/Parse/ParseDeclCXX.cpp (+6-8)
- (modified) clang/lib/Sema/HLSLExternalSemaSource.cpp (+8-7)
- (modified) clang/lib/Sema/SemaConcept.cpp (+129-59)
- (modified) clang/lib/Sema/SemaDecl.cpp (+40-28)
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+4-7)
- (modified) clang/lib/Sema/SemaExprMember.cpp (+3-2)
- (modified) clang/lib/Sema/SemaOverload.cpp (+2-4)
- (modified) clang/lib/Sema/SemaTemplate.cpp (+146-150)
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+32-11)
- (modified) clang/lib/Sema/SemaTemplateDeductionGuide.cpp (+50-7)
- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+423-188)
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+167-303)
- (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+36-41)
- (modified) clang/lib/Serialization/ASTWriterDecl.cpp (+39-61)
- (modified) clang/lib/StaticAnalyzer/Core/BugSuppression.cpp (+81-10)
- (modified) clang/lib/Tooling/Syntax/BuildTree.cpp (+6-7)
- (modified) clang/test/AST/ast-dump-templates-pattern.cpp (+9-10)
- (modified) clang/test/CXX/basic/basic.link/p11.cpp (+2)
- (modified) clang/test/CXX/drs/cwg18xx.cpp (+2-6)
- (modified) clang/test/CXX/drs/cwg7xx.cpp (+1-2)
- (modified) clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp (+7-4)
- (modified) clang/test/CXX/temp/temp.constr/temp.constr.decl/p4.cpp (+15-2)
- (modified) clang/test/CXX/temp/temp.decls/temp.spec.partial/temp.spec.partial.member/p2.cpp (-1)
- (modified) clang/test/CXX/temp/temp.spec/temp.expl.spec/p7.cpp (+23)
- (modified) clang/test/CodeGenCXX/default-arguments.cpp (-12)
- (modified) clang/test/CodeGenCXX/explicit-instantiation.cpp (-7)
- (removed) clang/test/Modules/GH208100.cpp (-28)
- (modified) clang/test/SemaCXX/GH195416.cpp (-1)
- (modified) clang/test/SemaCXX/constant-expression-cxx14.cpp (-7)
- (modified) clang/test/SemaCXX/deduced-return-type-cxx14.cpp (-26)
- (modified) clang/test/SemaCXX/member-class-11.cpp (+1-19)
- (removed) clang/test/SemaTemplate/GH202358.cpp (-12)
- (modified) clang/test/SemaTemplate/concepts-out-of-line-def.cpp (+7-2)
- (modified) clang/test/SemaTemplate/friend-template.cpp (+24-7)
- (modified) clang/test/SemaTemplate/instantiate-scope.cpp (+6-4)
- (modified) clang/test/Templight/templight-default-func-arg.cpp (+10-23)
- (modified) clang/test/Templight/templight-empty-entries-fix.cpp (+38-50)
- (modified) clang/tools/libclang/CIndex.cpp (-1)
- (modified) clang/unittests/AST/ASTImporterTest.cpp (+2-4)
- (modified) clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp (+2-2)
- (modified) lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp (+8-4)
- (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp (+2-46)
``````````diff
diff --git a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
index a1a705dd043a0..ae063a19d779d 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->getFunctionLocStart(), "inline ");
+ << FixItHint::CreateInsertion(FD->getInnerLocStart(), "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 ffd0ed1b79b79..5d9336fa6e53d 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 (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());
- }
+ 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());
return true;
}
bool VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D) {
- 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());
- }
+ 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());
return true;
}
@@ -625,9 +625,6 @@ 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 5fcb1a24448b8..c9704492bf1cd 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->getFunctionLocStart(), 0, "inline ");
+ return tooling::Replacement(SM, FD->getInnerLocStart(), 0, "inline ");
}
/// Moves definition of a function/method to its declaration location.
diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html
index 675fb4a550ba8..7e0bbbcb18938 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -4301,11 +4301,6 @@ <h2 id="narrowing-matchers">Narrowing Matchers</h2>
</pre></td></tr>
-<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('declaresSameEntityAsNode0')"><a name="declaresSameEntityAsNode0Anchor">declaresSameEntityAsNode</a></td><td>const Decl * Other</td></tr>
-<tr><td colspan="4" class="doc" id="declaresSameEntityAsNode0"><pre>Matches a declaration if it declares the same entity as the node.
-</pre></td></tr>
-
-
<tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>></td><td class="name" onclick="toggle('equalsBoundNode1')"><a name="equalsBoundNode1Anchor">equalsBoundNode</a></td><td>std::string ID</td></tr>
<tr><td colspan="4" class="doc" id="equalsBoundNode1"><pre>Matches if a node equals a previously bound node.
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 61caf2d9ec99e..09a20eda5235d 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -838,7 +838,6 @@ latest release, please see the [Clang Web Site](https://clang.llvm.org) or the
- 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-of-line definitions. (#GH101330)
- Clang incorrectly instantiated variable specializations outside of the immediate context. (#GH54439)
- Fixed a crash when pack expansions are used as arguments for non-pack parameters of built-in templates. (#GH180307)
- Fixed crash instantiating class member specializations.
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 59dbf3b75af30..88c900203630a 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -2131,6 +2131,34 @@ class FunctionDecl : public DeclaratorDecl,
/// the DeclaratorDecl base class.
DeclarationNameLoc DNLoc;
+ /// Specify that this function declaration is actually a function
+ /// template specialization.
+ ///
+ /// \param C the ASTContext.
+ ///
+ /// \param Template the function template that this function template
+ /// specialization specializes.
+ ///
+ /// \param TemplateArgs the template arguments that produced this
+ /// function template specialization from the template.
+ ///
+ /// \param InsertPos If non-NULL, the position in the function template
+ /// specialization set where the function template specialization data will
+ /// be inserted.
+ ///
+ /// \param TSK the kind of template specialization this is.
+ ///
+ /// \param TemplateArgsAsWritten location info of template arguments.
+ ///
+ /// \param PointOfInstantiation point at which the function template
+ /// specialization was first instantiated.
+ 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.
void setInstantiationOfMemberFunction(ASTContext &C, FunctionDecl *FD,
@@ -2226,8 +2254,6 @@ class FunctionDecl : public DeclaratorDecl,
return SourceLocation();
}
- SourceLocation getFunctionLocStart() const;
-
SourceRange getSourceRange() const override LLVM_READONLY;
// Function definitions.
@@ -3057,14 +3083,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.
///
- /// \param C the ASTContext.
- ///
/// \param Template the function template that this function template
/// specialization specializes.
///
@@ -3077,30 +3098,25 @@ 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
/// specialization was first instantiated.
- ///
- /// \param AddSpecialization whether to add this specialization to the
- /// template's specialization set.
- ///
void setFunctionTemplateSpecialization(
- ASTContext &C, FunctionTemplateDecl *Template,
- TemplateArgumentList *TemplateArgs, void *InsertPos,
- TemplateSpecializationKind TSK,
- const TemplateParameterList *TemplateParams,
- const TemplateArgumentListInfo *TemplateArgsAsWritten,
- SourceLocation PointOfInstantiation, bool AddSpecialization);
+ FunctionTemplateDecl *Template, TemplateArgumentList *TemplateArgs,
+ void *InsertPos,
+ TemplateSpecializationKind TSK = TSK_ImplicitInstantiation,
+ TemplateArgumentListInfo *TemplateArgsAsWritten = nullptr,
+ SourceLocation PointOfInstantiation = SourceLocation()) {
+ setFunctionTemplateSpecialization(getASTContext(), Template, TemplateArgs,
+ InsertPos, TSK, TemplateArgsAsWritten,
+ PointOfInstantiation);
+ }
/// 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 672648c3fc03c..4f5a4e1b7b8a6 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.
- mutable TemplateArgument *InjectedArgs = nullptr;
+ TemplateArgument *InjectedArgs = nullptr;
/// The location of the 'template' keyword.
SourceLocation TemplateLoc;
@@ -200,8 +200,7 @@ class TemplateParameterList final
bool hasAssociatedConstraints() const;
/// Get the template argument list of the template parameter list.
- ArrayRef<TemplateArgument>
- getInjectedTemplateArgs(const ASTContext &Context) const;
+ ArrayRef<TemplateArgument> getInjectedTemplateArgs(const ASTContext &Context);
SourceLocation getTemplateLoc() const { return TemplateLoc; }
SourceLocation getLAngleLoc() const { return LAngleLoc; }
@@ -476,18 +475,14 @@ class FunctionTemplateSpecializationInfo final
/// The function template from which this function template
/// specialization was generated.
///
- /// The three bits contain the TemplateSpecializationKind.
- llvm::PointerIntPair<FunctionTemplateDecl *, 3> Template;
+ /// The two bits contain the top 4 values of TemplateSpecializationKind.
+ llvm::PointerIntPair<FunctionTemplateDecl *, 2> 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;
@@ -500,14 +495,12 @@ 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), TemplateParameters(TemplateParameters),
+ TemplateArguments(TemplateArgs),
TemplateArgumentsAsWritten(TemplateArgsAsWritten),
PointOfInstantiation(POI) {
- assert(TemplateParameters == nullptr || TSK == TSK_ExplicitSpecialization);
if (MSInfo)
getTrailingObjects()[0] = MSInfo;
}
@@ -520,7 +513,6 @@ 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);
@@ -621,8 +613,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 three bits).
- llvm::PointerIntPair<NamedDecl *, 3> MemberAndTSK;
+ // manner in which the instantiation occurred (in the lower two bits).
+ llvm::PointerIntPair<NamedDecl *, 2> MemberAndTSK;
// The point at which this member was first instantiated.
SourceLocation PointOfInstantiation;
@@ -701,19 +693,14 @@ 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.
@@ -1018,6 +1005,11 @@ 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
@@ -1815,18 +1807,8 @@ 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<ExplicitSpecializationInfo *,
+ llvm::PointerUnion<const ASTTemplateArgumentListInfo *,
ExplicitInstantiationInfo *>;
/// Represents a class template specialization, which refers to
@@ -2056,38 +2038,49 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
/// Retrieve the template argument list as written in the sources,
/// if any.
const ASTTemplateArgumentListInfo *getTemplateArgsAsWritten() const {
- if (const auto *Info = getExplicitSpecializationInfo())
+ if (auto *Info =
+ dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo))
return Info->TemplateArgsAsWritten;
- if (const auto *Info = getExplicitInstantiationInfo())
- return Info->TemplateArgsAsWritten;
- return nullptr;
+ 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;
}
- /// Gets the explicit instantiation info, if present.
- const ExplicitInstantiationInfo *getExplicitInstantiationInfo() const {
- return dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo);
+ /// Set the template argument list as written in the sources.
+ void setTemplateArgsAsWritten(const TemplateArgumentListInfo &ArgsInfo) {
+ setTemplateArgsAsWritten(
+ ASTTemplateArgumentListInfo::Create(getASTContext(), ArgsInfo));
}
- /// 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;
+ /// 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();
}
- /// Gets the explicit specialization info, if present.
- const ExplicitSpecializationInfo *getExplicitSpecializationInfo() const {
- return dyn_cast_if_present<ExplicitSpecializationInfo *>(ExplicitInfo);
+ /// 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();
}
- /// Sets the explicit specialization info.
- void setExplicitSpecializationInfo(
- TemplateParameterList *TemplateParams,
- const ASTTemplateArgumentListInfo *TemplateArgsAsWritten);
+ /// Sets the location of the template keyword.
+ void setTemplateKeywordLoc(SourceLocation Loc);
SourceRange getSourceRange() const override LLVM_READONLY;
@@ -2112,7 +2105,10 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
};
class ClassTemplatePartialSpecializationDecl
- : public ClassTemplateSpecializationDecl {
+ : public ClassTemplateSpecializationDecl {
+ /// The list of template parameters
+ TemplateParameterList *TemplateParams = nullptr;
+
/// The class template partial specialization from which this
/// class template partial specialization was instantia...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/208426
More information about the cfe-commits
mailing list