Template.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- SemaTemplate.h - C++ Templates ---------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //===----------------------------------------------------------------------===//
  12. //
  13. // This file provides types used in the semantic analysis of C++ templates.
  14. //
  15. //===----------------------------------------------------------------------===//
  16. #ifndef LLVM_CLANG_SEMA_TEMPLATE_H
  17. #define LLVM_CLANG_SEMA_TEMPLATE_H
  18. #include "clang/AST/DeclTemplate.h"
  19. #include "clang/AST/DeclVisitor.h"
  20. #include "clang/AST/TemplateBase.h"
  21. #include "clang/AST/Type.h"
  22. #include "clang/Basic/LLVM.h"
  23. #include "clang/Sema/Sema.h"
  24. #include "llvm/ADT/ArrayRef.h"
  25. #include "llvm/ADT/DenseMap.h"
  26. #include "llvm/ADT/PointerUnion.h"
  27. #include "llvm/ADT/SmallVector.h"
  28. #include <cassert>
  29. #include <utility>
  30. namespace clang {
  31. class ASTContext;
  32. class BindingDecl;
  33. class CXXMethodDecl;
  34. class Decl;
  35. class DeclaratorDecl;
  36. class DeclContext;
  37. class EnumDecl;
  38. class FunctionDecl;
  39. class NamedDecl;
  40. class ParmVarDecl;
  41. class TagDecl;
  42. class TypedefNameDecl;
  43. class TypeSourceInfo;
  44. class VarDecl;
  45. /// The kind of template substitution being performed.
  46. enum class TemplateSubstitutionKind : char {
  47. /// We are substituting template parameters for template arguments in order
  48. /// to form a template specialization.
  49. Specialization,
  50. /// We are substituting template parameters for (typically) other template
  51. /// parameters in order to rewrite a declaration as a different declaration
  52. /// (for example, when forming a deduction guide from a constructor).
  53. Rewrite,
  54. };
  55. /// Data structure that captures multiple levels of template argument
  56. /// lists for use in template instantiation.
  57. ///
  58. /// Multiple levels of template arguments occur when instantiating the
  59. /// definitions of member templates. For example:
  60. ///
  61. /// \code
  62. /// template<typename T>
  63. /// struct X {
  64. /// template<T Value>
  65. /// struct Y {
  66. /// void f();
  67. /// };
  68. /// };
  69. /// \endcode
  70. ///
  71. /// When instantiating X<int>::Y<17>::f, the multi-level template argument
  72. /// list will contain a template argument list (int) at depth 0 and a
  73. /// template argument list (17) at depth 1.
  74. class MultiLevelTemplateArgumentList {
  75. /// The template argument list at a certain template depth
  76. using ArgList = ArrayRef<TemplateArgument>;
  77. /// The template argument lists, stored from the innermost template
  78. /// argument list (first) to the outermost template argument list (last).
  79. SmallVector<ArgList, 4> TemplateArgumentLists;
  80. /// The number of outer levels of template arguments that are not
  81. /// being substituted.
  82. unsigned NumRetainedOuterLevels = 0;
  83. /// The kind of substitution described by this argument list.
  84. TemplateSubstitutionKind Kind = TemplateSubstitutionKind::Specialization;
  85. public:
  86. /// Construct an empty set of template argument lists.
  87. MultiLevelTemplateArgumentList() = default;
  88. /// Construct a single-level template argument list.
  89. explicit
  90. MultiLevelTemplateArgumentList(const TemplateArgumentList &TemplateArgs) {
  91. addOuterTemplateArguments(&TemplateArgs);
  92. }
  93. void setKind(TemplateSubstitutionKind K) { Kind = K; }
  94. /// Determine the kind of template substitution being performed.
  95. TemplateSubstitutionKind getKind() const { return Kind; }
  96. /// Determine whether we are rewriting template parameters rather than
  97. /// substituting for them. If so, we should not leave references to the
  98. /// original template parameters behind.
  99. bool isRewrite() const {
  100. return Kind == TemplateSubstitutionKind::Rewrite;
  101. }
  102. /// Determine the number of levels in this template argument
  103. /// list.
  104. unsigned getNumLevels() const {
  105. return TemplateArgumentLists.size() + NumRetainedOuterLevels;
  106. }
  107. /// Determine the number of substituted levels in this template
  108. /// argument list.
  109. unsigned getNumSubstitutedLevels() const {
  110. return TemplateArgumentLists.size();
  111. }
  112. unsigned getNumRetainedOuterLevels() const {
  113. return NumRetainedOuterLevels;
  114. }
  115. /// Determine how many of the \p OldDepth outermost template parameter
  116. /// lists would be removed by substituting these arguments.
  117. unsigned getNewDepth(unsigned OldDepth) const {
  118. if (OldDepth < NumRetainedOuterLevels)
  119. return OldDepth;
  120. if (OldDepth < getNumLevels())
  121. return NumRetainedOuterLevels;
  122. return OldDepth - TemplateArgumentLists.size();
  123. }
  124. /// Retrieve the template argument at a given depth and index.
  125. const TemplateArgument &operator()(unsigned Depth, unsigned Index) const {
  126. assert(NumRetainedOuterLevels <= Depth && Depth < getNumLevels());
  127. assert(Index < TemplateArgumentLists[getNumLevels() - Depth - 1].size());
  128. return TemplateArgumentLists[getNumLevels() - Depth - 1][Index];
  129. }
  130. /// Determine whether there is a non-NULL template argument at the
  131. /// given depth and index.
  132. ///
  133. /// There must exist a template argument list at the given depth.
  134. bool hasTemplateArgument(unsigned Depth, unsigned Index) const {
  135. assert(Depth < getNumLevels());
  136. if (Depth < NumRetainedOuterLevels)
  137. return false;
  138. if (Index >= TemplateArgumentLists[getNumLevels() - Depth - 1].size())
  139. return false;
  140. return !(*this)(Depth, Index).isNull();
  141. }
  142. /// Clear out a specific template argument.
  143. void setArgument(unsigned Depth, unsigned Index,
  144. TemplateArgument Arg) {
  145. assert(NumRetainedOuterLevels <= Depth && Depth < getNumLevels());
  146. assert(Index < TemplateArgumentLists[getNumLevels() - Depth - 1].size());
  147. const_cast<TemplateArgument&>(
  148. TemplateArgumentLists[getNumLevels() - Depth - 1][Index])
  149. = Arg;
  150. }
  151. /// Add a new outermost level to the multi-level template argument
  152. /// list.
  153. void addOuterTemplateArguments(const TemplateArgumentList *TemplateArgs) {
  154. addOuterTemplateArguments(ArgList(TemplateArgs->data(),
  155. TemplateArgs->size()));
  156. }
  157. /// Add a new outmost level to the multi-level template argument
  158. /// list.
  159. void addOuterTemplateArguments(ArgList Args) {
  160. assert(!NumRetainedOuterLevels &&
  161. "substituted args outside retained args?");
  162. TemplateArgumentLists.push_back(Args);
  163. }
  164. /// Add an outermost level that we are not substituting. We have no
  165. /// arguments at this level, and do not remove it from the depth of inner
  166. /// template parameters that we instantiate.
  167. void addOuterRetainedLevel() {
  168. ++NumRetainedOuterLevels;
  169. }
  170. void addOuterRetainedLevels(unsigned Num) {
  171. NumRetainedOuterLevels += Num;
  172. }
  173. /// Retrieve the innermost template argument list.
  174. const ArgList &getInnermost() const {
  175. return TemplateArgumentLists.front();
  176. }
  177. };
  178. /// The context in which partial ordering of function templates occurs.
  179. enum TPOC {
  180. /// Partial ordering of function templates for a function call.
  181. TPOC_Call,
  182. /// Partial ordering of function templates for a call to a
  183. /// conversion function.
  184. TPOC_Conversion,
  185. /// Partial ordering of function templates in other contexts, e.g.,
  186. /// taking the address of a function template or matching a function
  187. /// template specialization to a function template.
  188. TPOC_Other
  189. };
  190. // This is lame but unavoidable in a world without forward
  191. // declarations of enums. The alternatives are to either pollute
  192. // Sema.h (by including this file) or sacrifice type safety (by
  193. // making Sema.h declare things as enums).
  194. class TemplatePartialOrderingContext {
  195. TPOC Value;
  196. public:
  197. TemplatePartialOrderingContext(TPOC Value) : Value(Value) {}
  198. operator TPOC() const { return Value; }
  199. };
  200. /// Captures a template argument whose value has been deduced
  201. /// via c++ template argument deduction.
  202. class DeducedTemplateArgument : public TemplateArgument {
  203. /// For a non-type template argument, whether the value was
  204. /// deduced from an array bound.
  205. bool DeducedFromArrayBound = false;
  206. public:
  207. DeducedTemplateArgument() = default;
  208. DeducedTemplateArgument(const TemplateArgument &Arg,
  209. bool DeducedFromArrayBound = false)
  210. : TemplateArgument(Arg), DeducedFromArrayBound(DeducedFromArrayBound) {}
  211. /// Construct an integral non-type template argument that
  212. /// has been deduced, possibly from an array bound.
  213. DeducedTemplateArgument(ASTContext &Ctx,
  214. const llvm::APSInt &Value,
  215. QualType ValueType,
  216. bool DeducedFromArrayBound)
  217. : TemplateArgument(Ctx, Value, ValueType),
  218. DeducedFromArrayBound(DeducedFromArrayBound) {}
  219. /// For a non-type template argument, determine whether the
  220. /// template argument was deduced from an array bound.
  221. bool wasDeducedFromArrayBound() const { return DeducedFromArrayBound; }
  222. /// Specify whether the given non-type template argument
  223. /// was deduced from an array bound.
  224. void setDeducedFromArrayBound(bool Deduced) {
  225. DeducedFromArrayBound = Deduced;
  226. }
  227. };
  228. /// A stack-allocated class that identifies which local
  229. /// variable declaration instantiations are present in this scope.
  230. ///
  231. /// A new instance of this class type will be created whenever we
  232. /// instantiate a new function declaration, which will have its own
  233. /// set of parameter declarations.
  234. class LocalInstantiationScope {
  235. public:
  236. /// A set of declarations.
  237. using DeclArgumentPack = SmallVector<VarDecl *, 4>;
  238. private:
  239. /// Reference to the semantic analysis that is performing
  240. /// this template instantiation.
  241. Sema &SemaRef;
  242. using LocalDeclsMap =
  243. llvm::SmallDenseMap<const Decl *,
  244. llvm::PointerUnion<Decl *, DeclArgumentPack *>, 4>;
  245. /// A mapping from local declarations that occur
  246. /// within a template to their instantiations.
  247. ///
  248. /// This mapping is used during instantiation to keep track of,
  249. /// e.g., function parameter and variable declarations. For example,
  250. /// given:
  251. ///
  252. /// \code
  253. /// template<typename T> T add(T x, T y) { return x + y; }
  254. /// \endcode
  255. ///
  256. /// when we instantiate add<int>, we will introduce a mapping from
  257. /// the ParmVarDecl for 'x' that occurs in the template to the
  258. /// instantiated ParmVarDecl for 'x'.
  259. ///
  260. /// For a parameter pack, the local instantiation scope may contain a
  261. /// set of instantiated parameters. This is stored as a DeclArgumentPack
  262. /// pointer.
  263. LocalDeclsMap LocalDecls;
  264. /// The set of argument packs we've allocated.
  265. SmallVector<DeclArgumentPack *, 1> ArgumentPacks;
  266. /// The outer scope, which contains local variable
  267. /// definitions from some other instantiation (that may not be
  268. /// relevant to this particular scope).
  269. LocalInstantiationScope *Outer;
  270. /// Whether we have already exited this scope.
  271. bool Exited = false;
  272. /// Whether to combine this scope with the outer scope, such that
  273. /// lookup will search our outer scope.
  274. bool CombineWithOuterScope;
  275. /// If non-NULL, the template parameter pack that has been
  276. /// partially substituted per C++0x [temp.arg.explicit]p9.
  277. NamedDecl *PartiallySubstitutedPack = nullptr;
  278. /// If \c PartiallySubstitutedPack is non-null, the set of
  279. /// explicitly-specified template arguments in that pack.
  280. const TemplateArgument *ArgsInPartiallySubstitutedPack;
  281. /// If \c PartiallySubstitutedPack, the number of
  282. /// explicitly-specified template arguments in
  283. /// ArgsInPartiallySubstitutedPack.
  284. unsigned NumArgsInPartiallySubstitutedPack;
  285. public:
  286. LocalInstantiationScope(Sema &SemaRef, bool CombineWithOuterScope = false)
  287. : SemaRef(SemaRef), Outer(SemaRef.CurrentInstantiationScope),
  288. CombineWithOuterScope(CombineWithOuterScope) {
  289. SemaRef.CurrentInstantiationScope = this;
  290. }
  291. LocalInstantiationScope(const LocalInstantiationScope &) = delete;
  292. LocalInstantiationScope &
  293. operator=(const LocalInstantiationScope &) = delete;
  294. ~LocalInstantiationScope() {
  295. Exit();
  296. }
  297. const Sema &getSema() const { return SemaRef; }
  298. /// Exit this local instantiation scope early.
  299. void Exit() {
  300. if (Exited)
  301. return;
  302. for (unsigned I = 0, N = ArgumentPacks.size(); I != N; ++I)
  303. delete ArgumentPacks[I];
  304. SemaRef.CurrentInstantiationScope = Outer;
  305. Exited = true;
  306. }
  307. /// Clone this scope, and all outer scopes, down to the given
  308. /// outermost scope.
  309. LocalInstantiationScope *cloneScopes(LocalInstantiationScope *Outermost) {
  310. if (this == Outermost) return this;
  311. // Save the current scope from SemaRef since the LocalInstantiationScope
  312. // will overwrite it on construction
  313. LocalInstantiationScope *oldScope = SemaRef.CurrentInstantiationScope;
  314. LocalInstantiationScope *newScope =
  315. new LocalInstantiationScope(SemaRef, CombineWithOuterScope);
  316. newScope->Outer = nullptr;
  317. if (Outer)
  318. newScope->Outer = Outer->cloneScopes(Outermost);
  319. newScope->PartiallySubstitutedPack = PartiallySubstitutedPack;
  320. newScope->ArgsInPartiallySubstitutedPack = ArgsInPartiallySubstitutedPack;
  321. newScope->NumArgsInPartiallySubstitutedPack =
  322. NumArgsInPartiallySubstitutedPack;
  323. for (LocalDeclsMap::iterator I = LocalDecls.begin(), E = LocalDecls.end();
  324. I != E; ++I) {
  325. const Decl *D = I->first;
  326. llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored =
  327. newScope->LocalDecls[D];
  328. if (I->second.is<Decl *>()) {
  329. Stored = I->second.get<Decl *>();
  330. } else {
  331. DeclArgumentPack *OldPack = I->second.get<DeclArgumentPack *>();
  332. DeclArgumentPack *NewPack = new DeclArgumentPack(*OldPack);
  333. Stored = NewPack;
  334. newScope->ArgumentPacks.push_back(NewPack);
  335. }
  336. }
  337. // Restore the saved scope to SemaRef
  338. SemaRef.CurrentInstantiationScope = oldScope;
  339. return newScope;
  340. }
  341. /// deletes the given scope, and all otuer scopes, down to the
  342. /// given outermost scope.
  343. static void deleteScopes(LocalInstantiationScope *Scope,
  344. LocalInstantiationScope *Outermost) {
  345. while (Scope && Scope != Outermost) {
  346. LocalInstantiationScope *Out = Scope->Outer;
  347. delete Scope;
  348. Scope = Out;
  349. }
  350. }
  351. /// Find the instantiation of the declaration D within the current
  352. /// instantiation scope.
  353. ///
  354. /// \param D The declaration whose instantiation we are searching for.
  355. ///
  356. /// \returns A pointer to the declaration or argument pack of declarations
  357. /// to which the declaration \c D is instantiated, if found. Otherwise,
  358. /// returns NULL.
  359. llvm::PointerUnion<Decl *, DeclArgumentPack *> *
  360. findInstantiationOf(const Decl *D);
  361. void InstantiatedLocal(const Decl *D, Decl *Inst);
  362. void InstantiatedLocalPackArg(const Decl *D, VarDecl *Inst);
  363. void MakeInstantiatedLocalArgPack(const Decl *D);
  364. /// Note that the given parameter pack has been partially substituted
  365. /// via explicit specification of template arguments
  366. /// (C++0x [temp.arg.explicit]p9).
  367. ///
  368. /// \param Pack The parameter pack, which will always be a template
  369. /// parameter pack.
  370. ///
  371. /// \param ExplicitArgs The explicitly-specified template arguments provided
  372. /// for this parameter pack.
  373. ///
  374. /// \param NumExplicitArgs The number of explicitly-specified template
  375. /// arguments provided for this parameter pack.
  376. void SetPartiallySubstitutedPack(NamedDecl *Pack,
  377. const TemplateArgument *ExplicitArgs,
  378. unsigned NumExplicitArgs);
  379. /// Reset the partially-substituted pack when it is no longer of
  380. /// interest.
  381. void ResetPartiallySubstitutedPack() {
  382. assert(PartiallySubstitutedPack && "No partially-substituted pack");
  383. PartiallySubstitutedPack = nullptr;
  384. ArgsInPartiallySubstitutedPack = nullptr;
  385. NumArgsInPartiallySubstitutedPack = 0;
  386. }
  387. /// Retrieve the partially-substitued template parameter pack.
  388. ///
  389. /// If there is no partially-substituted parameter pack, returns NULL.
  390. NamedDecl *
  391. getPartiallySubstitutedPack(const TemplateArgument **ExplicitArgs = nullptr,
  392. unsigned *NumExplicitArgs = nullptr) const;
  393. /// Determine whether D is a pack expansion created in this scope.
  394. bool isLocalPackExpansion(const Decl *D);
  395. };
  396. class TemplateDeclInstantiator
  397. : public DeclVisitor<TemplateDeclInstantiator, Decl *>
  398. {
  399. Sema &SemaRef;
  400. Sema::ArgumentPackSubstitutionIndexRAII SubstIndex;
  401. DeclContext *Owner;
  402. const MultiLevelTemplateArgumentList &TemplateArgs;
  403. Sema::LateInstantiatedAttrVec* LateAttrs = nullptr;
  404. LocalInstantiationScope *StartingScope = nullptr;
  405. /// A list of out-of-line class template partial
  406. /// specializations that will need to be instantiated after the
  407. /// enclosing class's instantiation is complete.
  408. SmallVector<std::pair<ClassTemplateDecl *,
  409. ClassTemplatePartialSpecializationDecl *>, 4>
  410. OutOfLinePartialSpecs;
  411. /// A list of out-of-line variable template partial
  412. /// specializations that will need to be instantiated after the
  413. /// enclosing variable's instantiation is complete.
  414. /// FIXME: Verify that this is needed.
  415. SmallVector<
  416. std::pair<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>, 4>
  417. OutOfLineVarPartialSpecs;
  418. public:
  419. TemplateDeclInstantiator(Sema &SemaRef, DeclContext *Owner,
  420. const MultiLevelTemplateArgumentList &TemplateArgs)
  421. : SemaRef(SemaRef),
  422. SubstIndex(SemaRef, SemaRef.ArgumentPackSubstitutionIndex),
  423. Owner(Owner), TemplateArgs(TemplateArgs) {}
  424. // Define all the decl visitors using DeclNodes.inc
  425. #define DECL(DERIVED, BASE) \
  426. Decl *Visit ## DERIVED ## Decl(DERIVED ## Decl *D);
  427. #define ABSTRACT_DECL(DECL)
  428. // Decls which never appear inside a class or function.
  429. #define OBJCCONTAINER(DERIVED, BASE)
  430. #define FILESCOPEASM(DERIVED, BASE)
  431. #define IMPORT(DERIVED, BASE)
  432. #define EXPORT(DERIVED, BASE)
  433. #define LINKAGESPEC(DERIVED, BASE)
  434. #define OBJCCOMPATIBLEALIAS(DERIVED, BASE)
  435. #define OBJCMETHOD(DERIVED, BASE)
  436. #define OBJCTYPEPARAM(DERIVED, BASE)
  437. #define OBJCIVAR(DERIVED, BASE)
  438. #define OBJCPROPERTY(DERIVED, BASE)
  439. #define OBJCPROPERTYIMPL(DERIVED, BASE)
  440. #define EMPTY(DERIVED, BASE)
  441. #define LIFETIMEEXTENDEDTEMPORARY(DERIVED, BASE)
  442. // Decls which use special-case instantiation code.
  443. #define BLOCK(DERIVED, BASE)
  444. #define CAPTURED(DERIVED, BASE)
  445. #define IMPLICITPARAM(DERIVED, BASE)
  446. #include "clang/AST/DeclNodes.inc"
  447. enum class RewriteKind { None, RewriteSpaceshipAsEqualEqual };
  448. void adjustForRewrite(RewriteKind RK, FunctionDecl *Orig, QualType &T,
  449. TypeSourceInfo *&TInfo,
  450. DeclarationNameInfo &NameInfo);
  451. // A few supplemental visitor functions.
  452. Decl *VisitCXXMethodDecl(CXXMethodDecl *D,
  453. TemplateParameterList *TemplateParams,
  454. Optional<const ASTTemplateArgumentListInfo *>
  455. ClassScopeSpecializationArgs = llvm::None,
  456. RewriteKind RK = RewriteKind::None);
  457. Decl *VisitFunctionDecl(FunctionDecl *D,
  458. TemplateParameterList *TemplateParams,
  459. RewriteKind RK = RewriteKind::None);
  460. Decl *VisitDecl(Decl *D);
  461. Decl *VisitVarDecl(VarDecl *D, bool InstantiatingVarTemplate,
  462. ArrayRef<BindingDecl *> *Bindings = nullptr);
  463. Decl *VisitBaseUsingDecls(BaseUsingDecl *D, BaseUsingDecl *Inst,
  464. LookupResult *Lookup);
  465. // Enable late instantiation of attributes. Late instantiated attributes
  466. // will be stored in LA.
  467. void enableLateAttributeInstantiation(Sema::LateInstantiatedAttrVec *LA) {
  468. LateAttrs = LA;
  469. StartingScope = SemaRef.CurrentInstantiationScope;
  470. }
  471. // Disable late instantiation of attributes.
  472. void disableLateAttributeInstantiation() {
  473. LateAttrs = nullptr;
  474. StartingScope = nullptr;
  475. }
  476. LocalInstantiationScope *getStartingScope() const { return StartingScope; }
  477. using delayed_partial_spec_iterator = SmallVectorImpl<std::pair<
  478. ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl *>>::iterator;
  479. using delayed_var_partial_spec_iterator = SmallVectorImpl<std::pair<
  480. VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>>::iterator;
  481. /// Return an iterator to the beginning of the set of
  482. /// "delayed" partial specializations, which must be passed to
  483. /// InstantiateClassTemplatePartialSpecialization once the class
  484. /// definition has been completed.
  485. delayed_partial_spec_iterator delayed_partial_spec_begin() {
  486. return OutOfLinePartialSpecs.begin();
  487. }
  488. delayed_var_partial_spec_iterator delayed_var_partial_spec_begin() {
  489. return OutOfLineVarPartialSpecs.begin();
  490. }
  491. /// Return an iterator to the end of the set of
  492. /// "delayed" partial specializations, which must be passed to
  493. /// InstantiateClassTemplatePartialSpecialization once the class
  494. /// definition has been completed.
  495. delayed_partial_spec_iterator delayed_partial_spec_end() {
  496. return OutOfLinePartialSpecs.end();
  497. }
  498. delayed_var_partial_spec_iterator delayed_var_partial_spec_end() {
  499. return OutOfLineVarPartialSpecs.end();
  500. }
  501. // Helper functions for instantiating methods.
  502. TypeSourceInfo *SubstFunctionType(FunctionDecl *D,
  503. SmallVectorImpl<ParmVarDecl *> &Params);
  504. bool InitFunctionInstantiation(FunctionDecl *New, FunctionDecl *Tmpl);
  505. bool InitMethodInstantiation(CXXMethodDecl *New, CXXMethodDecl *Tmpl);
  506. bool SubstDefaultedFunction(FunctionDecl *New, FunctionDecl *Tmpl);
  507. TemplateParameterList *
  508. SubstTemplateParams(TemplateParameterList *List);
  509. bool SubstQualifier(const DeclaratorDecl *OldDecl,
  510. DeclaratorDecl *NewDecl);
  511. bool SubstQualifier(const TagDecl *OldDecl,
  512. TagDecl *NewDecl);
  513. Decl *VisitVarTemplateSpecializationDecl(
  514. VarTemplateDecl *VarTemplate, VarDecl *FromVar,
  515. const TemplateArgumentListInfo &TemplateArgsInfo,
  516. ArrayRef<TemplateArgument> Converted,
  517. VarTemplateSpecializationDecl *PrevDecl = nullptr);
  518. Decl *InstantiateTypedefNameDecl(TypedefNameDecl *D, bool IsTypeAlias);
  519. ClassTemplatePartialSpecializationDecl *
  520. InstantiateClassTemplatePartialSpecialization(
  521. ClassTemplateDecl *ClassTemplate,
  522. ClassTemplatePartialSpecializationDecl *PartialSpec);
  523. VarTemplatePartialSpecializationDecl *
  524. InstantiateVarTemplatePartialSpecialization(
  525. VarTemplateDecl *VarTemplate,
  526. VarTemplatePartialSpecializationDecl *PartialSpec);
  527. void InstantiateEnumDefinition(EnumDecl *Enum, EnumDecl *Pattern);
  528. private:
  529. template<typename T>
  530. Decl *instantiateUnresolvedUsingDecl(T *D,
  531. bool InstantiatingPackElement = false);
  532. };
  533. } // namespace clang
  534. #endif // LLVM_CLANG_SEMA_TEMPLATE_H
  535. #ifdef __GNUC__
  536. #pragma GCC diagnostic pop
  537. #endif