clang  16.0.0git
Template.h
Go to the documentation of this file.
1 //===- SemaTemplate.h - C++ Templates ---------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //===----------------------------------------------------------------------===//
7 //
8 // This file provides types used in the semantic analysis of C++ templates.
9 //
10 //===----------------------------------------------------------------------===//
11 
12 #ifndef LLVM_CLANG_SEMA_TEMPLATE_H
13 #define LLVM_CLANG_SEMA_TEMPLATE_H
14 
15 #include "clang/AST/DeclTemplate.h"
16 #include "clang/AST/DeclVisitor.h"
17 #include "clang/AST/TemplateBase.h"
18 #include "clang/AST/Type.h"
19 #include "clang/Basic/LLVM.h"
20 #include "clang/Sema/Sema.h"
21 #include "llvm/ADT/ArrayRef.h"
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/ADT/PointerUnion.h"
24 #include "llvm/ADT/SmallVector.h"
25 #include <cassert>
26 #include <utility>
27 
28 namespace clang {
29 
30 class ASTContext;
31 class BindingDecl;
32 class CXXMethodDecl;
33 class Decl;
34 class DeclaratorDecl;
35 class DeclContext;
36 class EnumDecl;
37 class FunctionDecl;
38 class NamedDecl;
39 class ParmVarDecl;
40 class TagDecl;
41 class TypedefNameDecl;
42 class TypeSourceInfo;
43 class VarDecl;
44 
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.
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 
56  /// Data structure that captures multiple levels of template argument
57  /// lists for use in template instantiation.
58  ///
59  /// Multiple levels of template arguments occur when instantiating the
60  /// definitions of member templates. For example:
61  ///
62  /// \code
63  /// template<typename T>
64  /// struct X {
65  /// template<T Value>
66  /// struct Y {
67  /// void f();
68  /// };
69  /// };
70  /// \endcode
71  ///
72  /// When instantiating X<int>::Y<17>::f, the multi-level template argument
73  /// list will contain a template argument list (int) at depth 0 and a
74  /// template argument list (17) at depth 1.
76  /// The template argument list at a certain template depth
78  using ArgListsIterator = SmallVector<ArgList, 4>::iterator;
79  using ConstArgListsIterator = SmallVector<ArgList, 4>::const_iterator;
80 
81  /// The template argument lists, stored from the innermost template
82  /// argument list (first) to the outermost template argument list (last).
83  SmallVector<ArgList, 4> TemplateArgumentLists;
84 
85  /// The number of outer levels of template arguments that are not
86  /// being substituted.
87  unsigned NumRetainedOuterLevels = 0;
88 
89  /// The kind of substitution described by this argument list.
91 
92  public:
93  /// Construct an empty set of template argument lists.
95 
96  /// Construct a single-level template argument list.
97  explicit
99  addOuterTemplateArguments(&TemplateArgs);
100  }
101 
102  void setKind(TemplateSubstitutionKind K) { Kind = K; }
103 
104  /// Determine the kind of template substitution being performed.
105  TemplateSubstitutionKind getKind() const { return Kind; }
106 
107  /// Determine whether we are rewriting template parameters rather than
108  /// substituting for them. If so, we should not leave references to the
109  /// original template parameters behind.
110  bool isRewrite() const {
111  return Kind == TemplateSubstitutionKind::Rewrite;
112  }
113 
114  /// Determine the number of levels in this template argument
115  /// list.
116  unsigned getNumLevels() const {
117  return TemplateArgumentLists.size() + NumRetainedOuterLevels;
118  }
119 
120  /// Determine the number of substituted levels in this template
121  /// argument list.
122  unsigned getNumSubstitutedLevels() const {
123  return TemplateArgumentLists.size();
124  }
125 
126  // Determine the number of substituted args at 'Depth'.
127  unsigned getNumSubsitutedArgs(unsigned Depth) const {
128  assert(NumRetainedOuterLevels <= Depth && Depth < getNumLevels());
129  return TemplateArgumentLists[getNumLevels() - Depth - 1].size();
130  }
131 
132  unsigned getNumRetainedOuterLevels() const {
133  return NumRetainedOuterLevels;
134  }
135 
136  /// Determine how many of the \p OldDepth outermost template parameter
137  /// lists would be removed by substituting these arguments.
138  unsigned getNewDepth(unsigned OldDepth) const {
139  if (OldDepth < NumRetainedOuterLevels)
140  return OldDepth;
141  if (OldDepth < getNumLevels())
142  return NumRetainedOuterLevels;
143  return OldDepth - TemplateArgumentLists.size();
144  }
145 
146  /// Retrieve the template argument at a given depth and index.
147  const TemplateArgument &operator()(unsigned Depth, unsigned Index) const {
148  assert(NumRetainedOuterLevels <= Depth && Depth < getNumLevels());
149  assert(Index < TemplateArgumentLists[getNumLevels() - Depth - 1].size());
150  return TemplateArgumentLists[getNumLevels() - Depth - 1][Index];
151  }
152 
153  /// Determine whether there is a non-NULL template argument at the
154  /// given depth and index.
155  ///
156  /// There must exist a template argument list at the given depth.
157  bool hasTemplateArgument(unsigned Depth, unsigned Index) const {
158  assert(Depth < getNumLevels());
159 
160  if (Depth < NumRetainedOuterLevels)
161  return false;
162 
163  if (Index >= TemplateArgumentLists[getNumLevels() - Depth - 1].size())
164  return false;
165 
166  return !(*this)(Depth, Index).isNull();
167  }
168 
170  for (ArgList List : TemplateArgumentLists)
171  for (const TemplateArgument &TA : List)
172  if (TA.isInstantiationDependent())
173  return true;
174  return false;
175  }
176 
177  /// Clear out a specific template argument.
178  void setArgument(unsigned Depth, unsigned Index,
179  TemplateArgument Arg) {
180  assert(NumRetainedOuterLevels <= Depth && Depth < getNumLevels());
181  assert(Index < TemplateArgumentLists[getNumLevels() - Depth - 1].size());
182  const_cast<TemplateArgument&>(
183  TemplateArgumentLists[getNumLevels() - Depth - 1][Index])
184  = Arg;
185  }
186 
187  /// Add a new outermost level to the multi-level template argument
188  /// list.
190  addOuterTemplateArguments(ArgList(TemplateArgs->data(),
191  TemplateArgs->size()));
192  }
193 
194  /// Add a new outmost level to the multi-level template argument
195  /// list.
197  assert(!NumRetainedOuterLevels &&
198  "substituted args outside retained args?");
199  TemplateArgumentLists.push_back(Args);
200  }
201 
202  /// Replaces the current 'innermost' level with the provided argument list.
203  /// This is useful for type deduction cases where we need to get the entire
204  /// list from the AST, but then add the deduced innermost list.
206  assert(TemplateArgumentLists.size() > 0 && "Replacing in an empty list?");
207  TemplateArgumentLists[0] = Args;
208  }
209 
210  /// Add an outermost level that we are not substituting. We have no
211  /// arguments at this level, and do not remove it from the depth of inner
212  /// template parameters that we instantiate.
214  ++NumRetainedOuterLevels;
215  }
216  void addOuterRetainedLevels(unsigned Num) {
217  NumRetainedOuterLevels += Num;
218  }
219 
220  /// Retrieve the innermost template argument list.
221  const ArgList &getInnermost() const {
222  return TemplateArgumentLists.front();
223  }
224  /// Retrieve the outermost template argument list.
225  const ArgList &getOutermost() const {
226  return TemplateArgumentLists.back();
227  }
228  ArgListsIterator begin() { return TemplateArgumentLists.begin(); }
229  ConstArgListsIterator begin() const {
230  return TemplateArgumentLists.begin();
231  }
232  ArgListsIterator end() { return TemplateArgumentLists.end(); }
233  ConstArgListsIterator end() const { return TemplateArgumentLists.end(); }
234  };
235 
236  /// The context in which partial ordering of function templates occurs.
237  enum TPOC {
238  /// Partial ordering of function templates for a function call.
240 
241  /// Partial ordering of function templates for a call to a
242  /// conversion function.
244 
245  /// Partial ordering of function templates in other contexts, e.g.,
246  /// taking the address of a function template or matching a function
247  /// template specialization to a function template.
249  };
250 
251  // This is lame but unavoidable in a world without forward
252  // declarations of enums. The alternatives are to either pollute
253  // Sema.h (by including this file) or sacrifice type safety (by
254  // making Sema.h declare things as enums).
256  TPOC Value;
257 
258  public:
260 
261  operator TPOC() const { return Value; }
262  };
263 
264  /// Captures a template argument whose value has been deduced
265  /// via c++ template argument deduction.
267  /// For a non-type template argument, whether the value was
268  /// deduced from an array bound.
269  bool DeducedFromArrayBound = false;
270 
271  public:
272  DeducedTemplateArgument() = default;
273 
275  bool DeducedFromArrayBound = false)
276  : TemplateArgument(Arg), DeducedFromArrayBound(DeducedFromArrayBound) {}
277 
278  /// Construct an integral non-type template argument that
279  /// has been deduced, possibly from an array bound.
281  const llvm::APSInt &Value,
282  QualType ValueType,
283  bool DeducedFromArrayBound)
284  : TemplateArgument(Ctx, Value, ValueType),
285  DeducedFromArrayBound(DeducedFromArrayBound) {}
286 
287  /// For a non-type template argument, determine whether the
288  /// template argument was deduced from an array bound.
289  bool wasDeducedFromArrayBound() const { return DeducedFromArrayBound; }
290 
291  /// Specify whether the given non-type template argument
292  /// was deduced from an array bound.
293  void setDeducedFromArrayBound(bool Deduced) {
294  DeducedFromArrayBound = Deduced;
295  }
296  };
297 
298  /// A stack-allocated class that identifies which local
299  /// variable declaration instantiations are present in this scope.
300  ///
301  /// A new instance of this class type will be created whenever we
302  /// instantiate a new function declaration, which will have its own
303  /// set of parameter declarations.
305  public:
306  /// A set of declarations.
308 
309  private:
310  /// Reference to the semantic analysis that is performing
311  /// this template instantiation.
312  Sema &SemaRef;
313 
314  using LocalDeclsMap =
315  llvm::SmallDenseMap<const Decl *,
316  llvm::PointerUnion<Decl *, DeclArgumentPack *>, 4>;
317 
318  /// A mapping from local declarations that occur
319  /// within a template to their instantiations.
320  ///
321  /// This mapping is used during instantiation to keep track of,
322  /// e.g., function parameter and variable declarations. For example,
323  /// given:
324  ///
325  /// \code
326  /// template<typename T> T add(T x, T y) { return x + y; }
327  /// \endcode
328  ///
329  /// when we instantiate add<int>, we will introduce a mapping from
330  /// the ParmVarDecl for 'x' that occurs in the template to the
331  /// instantiated ParmVarDecl for 'x'.
332  ///
333  /// For a parameter pack, the local instantiation scope may contain a
334  /// set of instantiated parameters. This is stored as a DeclArgumentPack
335  /// pointer.
336  LocalDeclsMap LocalDecls;
337 
338  /// The set of argument packs we've allocated.
340 
341  /// The outer scope, which contains local variable
342  /// definitions from some other instantiation (that may not be
343  /// relevant to this particular scope).
345 
346  /// Whether we have already exited this scope.
347  bool Exited = false;
348 
349  /// Whether to combine this scope with the outer scope, such that
350  /// lookup will search our outer scope.
351  bool CombineWithOuterScope;
352 
353  /// If non-NULL, the template parameter pack that has been
354  /// partially substituted per C++0x [temp.arg.explicit]p9.
355  NamedDecl *PartiallySubstitutedPack = nullptr;
356 
357  /// If \c PartiallySubstitutedPack is non-null, the set of
358  /// explicitly-specified template arguments in that pack.
359  const TemplateArgument *ArgsInPartiallySubstitutedPack;
360 
361  /// If \c PartiallySubstitutedPack, the number of
362  /// explicitly-specified template arguments in
363  /// ArgsInPartiallySubstitutedPack.
364  unsigned NumArgsInPartiallySubstitutedPack;
365 
366  public:
367  LocalInstantiationScope(Sema &SemaRef, bool CombineWithOuterScope = false)
368  : SemaRef(SemaRef), Outer(SemaRef.CurrentInstantiationScope),
369  CombineWithOuterScope(CombineWithOuterScope) {
370  SemaRef.CurrentInstantiationScope = this;
371  }
372 
375  operator=(const LocalInstantiationScope &) = delete;
376 
378  Exit();
379  }
380 
381  const Sema &getSema() const { return SemaRef; }
382 
383  /// Exit this local instantiation scope early.
384  void Exit() {
385  if (Exited)
386  return;
387 
388  for (unsigned I = 0, N = ArgumentPacks.size(); I != N; ++I)
389  delete ArgumentPacks[I];
390 
391  SemaRef.CurrentInstantiationScope = Outer;
392  Exited = true;
393  }
394 
395  /// Clone this scope, and all outer scopes, down to the given
396  /// outermost scope.
398  if (this == Outermost) return this;
399 
400  // Save the current scope from SemaRef since the LocalInstantiationScope
401  // will overwrite it on construction
403 
404  LocalInstantiationScope *newScope =
405  new LocalInstantiationScope(SemaRef, CombineWithOuterScope);
406 
407  newScope->Outer = nullptr;
408  if (Outer)
409  newScope->Outer = Outer->cloneScopes(Outermost);
410 
411  newScope->PartiallySubstitutedPack = PartiallySubstitutedPack;
412  newScope->ArgsInPartiallySubstitutedPack = ArgsInPartiallySubstitutedPack;
413  newScope->NumArgsInPartiallySubstitutedPack =
414  NumArgsInPartiallySubstitutedPack;
415 
416  for (LocalDeclsMap::iterator I = LocalDecls.begin(), E = LocalDecls.end();
417  I != E; ++I) {
418  const Decl *D = I->first;
419  llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored =
420  newScope->LocalDecls[D];
421  if (I->second.is<Decl *>()) {
422  Stored = I->second.get<Decl *>();
423  } else {
424  DeclArgumentPack *OldPack = I->second.get<DeclArgumentPack *>();
425  DeclArgumentPack *NewPack = new DeclArgumentPack(*OldPack);
426  Stored = NewPack;
427  newScope->ArgumentPacks.push_back(NewPack);
428  }
429  }
430  // Restore the saved scope to SemaRef
431  SemaRef.CurrentInstantiationScope = oldScope;
432  return newScope;
433  }
434 
435  /// deletes the given scope, and all outer scopes, down to the
436  /// given outermost scope.
438  LocalInstantiationScope *Outermost) {
439  while (Scope && Scope != Outermost) {
440  LocalInstantiationScope *Out = Scope->Outer;
441  delete Scope;
442  Scope = Out;
443  }
444  }
445 
446  /// Find the instantiation of the declaration D within the current
447  /// instantiation scope.
448  ///
449  /// \param D The declaration whose instantiation we are searching for.
450  ///
451  /// \returns A pointer to the declaration or argument pack of declarations
452  /// to which the declaration \c D is instantiated, if found. Otherwise,
453  /// returns NULL.
454  llvm::PointerUnion<Decl *, DeclArgumentPack *> *
455  findInstantiationOf(const Decl *D);
456 
457  void InstantiatedLocal(const Decl *D, Decl *Inst);
458  void InstantiatedLocalPackArg(const Decl *D, VarDecl *Inst);
459  void MakeInstantiatedLocalArgPack(const Decl *D);
460 
461  /// Note that the given parameter pack has been partially substituted
462  /// via explicit specification of template arguments
463  /// (C++0x [temp.arg.explicit]p9).
464  ///
465  /// \param Pack The parameter pack, which will always be a template
466  /// parameter pack.
467  ///
468  /// \param ExplicitArgs The explicitly-specified template arguments provided
469  /// for this parameter pack.
470  ///
471  /// \param NumExplicitArgs The number of explicitly-specified template
472  /// arguments provided for this parameter pack.
474  const TemplateArgument *ExplicitArgs,
475  unsigned NumExplicitArgs);
476 
477  /// Reset the partially-substituted pack when it is no longer of
478  /// interest.
480  assert(PartiallySubstitutedPack && "No partially-substituted pack");
481  PartiallySubstitutedPack = nullptr;
482  ArgsInPartiallySubstitutedPack = nullptr;
483  NumArgsInPartiallySubstitutedPack = 0;
484  }
485 
486  /// Retrieve the partially-substitued template parameter pack.
487  ///
488  /// If there is no partially-substituted parameter pack, returns NULL.
489  NamedDecl *
490  getPartiallySubstitutedPack(const TemplateArgument **ExplicitArgs = nullptr,
491  unsigned *NumExplicitArgs = nullptr) const;
492 
493  /// Determine whether D is a pack expansion created in this scope.
494  bool isLocalPackExpansion(const Decl *D);
495  };
496 
498  : public DeclVisitor<TemplateDeclInstantiator, Decl *>
499  {
500  Sema &SemaRef;
502  DeclContext *Owner;
503  const MultiLevelTemplateArgumentList &TemplateArgs;
504  Sema::LateInstantiatedAttrVec* LateAttrs = nullptr;
505  LocalInstantiationScope *StartingScope = nullptr;
506  bool EvaluateConstraints = true;
507 
508  /// A list of out-of-line class template partial
509  /// specializations that will need to be instantiated after the
510  /// enclosing class's instantiation is complete.
511  SmallVector<std::pair<ClassTemplateDecl *,
513  OutOfLinePartialSpecs;
514 
515  /// A list of out-of-line variable template partial
516  /// specializations that will need to be instantiated after the
517  /// enclosing variable's instantiation is complete.
518  /// FIXME: Verify that this is needed.
519  SmallVector<
520  std::pair<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>, 4>
521  OutOfLineVarPartialSpecs;
522 
523  public:
525  const MultiLevelTemplateArgumentList &TemplateArgs)
526  : SemaRef(SemaRef),
527  SubstIndex(SemaRef, SemaRef.ArgumentPackSubstitutionIndex),
528  Owner(Owner), TemplateArgs(TemplateArgs) {}
529 
530  void setEvaluateConstraints(bool B) {
531  EvaluateConstraints = B;
532  }
534  return EvaluateConstraints;
535  }
536 
537 // Define all the decl visitors using DeclNodes.inc
538 #define DECL(DERIVED, BASE) \
539  Decl *Visit ## DERIVED ## Decl(DERIVED ## Decl *D);
540 #define ABSTRACT_DECL(DECL)
541 
542 // Decls which never appear inside a class or function.
543 #define OBJCCONTAINER(DERIVED, BASE)
544 #define FILESCOPEASM(DERIVED, BASE)
545 #define IMPORT(DERIVED, BASE)
546 #define EXPORT(DERIVED, BASE)
547 #define LINKAGESPEC(DERIVED, BASE)
548 #define OBJCCOMPATIBLEALIAS(DERIVED, BASE)
549 #define OBJCMETHOD(DERIVED, BASE)
550 #define OBJCTYPEPARAM(DERIVED, BASE)
551 #define OBJCIVAR(DERIVED, BASE)
552 #define OBJCPROPERTY(DERIVED, BASE)
553 #define OBJCPROPERTYIMPL(DERIVED, BASE)
554 #define EMPTY(DERIVED, BASE)
555 #define LIFETIMEEXTENDEDTEMPORARY(DERIVED, BASE)
556 
557  // Decls which use special-case instantiation code.
558 #define BLOCK(DERIVED, BASE)
559 #define CAPTURED(DERIVED, BASE)
560 #define IMPLICITPARAM(DERIVED, BASE)
561 
562 #include "clang/AST/DeclNodes.inc"
563 
565 
567  TypeSourceInfo *&TInfo,
568  DeclarationNameInfo &NameInfo);
569 
570  // A few supplemental visitor functions.
572  TemplateParameterList *TemplateParams,
574  ClassScopeSpecializationArgs = llvm::None,
577  TemplateParameterList *TemplateParams,
579  Decl *VisitDecl(Decl *D);
580  Decl *VisitVarDecl(VarDecl *D, bool InstantiatingVarTemplate,
581  ArrayRef<BindingDecl *> *Bindings = nullptr);
583  LookupResult *Lookup);
584 
585  // Enable late instantiation of attributes. Late instantiated attributes
586  // will be stored in LA.
588  LateAttrs = LA;
589  StartingScope = SemaRef.CurrentInstantiationScope;
590  }
591 
592  // Disable late instantiation of attributes.
594  LateAttrs = nullptr;
595  StartingScope = nullptr;
596  }
597 
598  LocalInstantiationScope *getStartingScope() const { return StartingScope; }
599 
602 
605 
606  /// Return an iterator to the beginning of the set of
607  /// "delayed" partial specializations, which must be passed to
608  /// InstantiateClassTemplatePartialSpecialization once the class
609  /// definition has been completed.
611  return OutOfLinePartialSpecs.begin();
612  }
613 
615  return OutOfLineVarPartialSpecs.begin();
616  }
617 
618  /// Return an iterator to the end of the set of
619  /// "delayed" partial specializations, which must be passed to
620  /// InstantiateClassTemplatePartialSpecialization once the class
621  /// definition has been completed.
623  return OutOfLinePartialSpecs.end();
624  }
625 
627  return OutOfLineVarPartialSpecs.end();
628  }
629 
630  // Helper functions for instantiating methods.
635 
637 
640 
641  bool SubstQualifier(const DeclaratorDecl *OldDecl,
642  DeclaratorDecl *NewDecl);
643  bool SubstQualifier(const TagDecl *OldDecl,
644  TagDecl *NewDecl);
645 
647  VarTemplateDecl *VarTemplate, VarDecl *FromVar,
648  const TemplateArgumentListInfo &TemplateArgsInfo,
649  ArrayRef<TemplateArgument> Converted,
650  VarTemplateSpecializationDecl *PrevDecl = nullptr);
651 
652  Decl *InstantiateTypedefNameDecl(TypedefNameDecl *D, bool IsTypeAlias);
655  ClassTemplateDecl *ClassTemplate,
659  VarTemplateDecl *VarTemplate,
661  void InstantiateEnumDefinition(EnumDecl *Enum, EnumDecl *Pattern);
662 
663  private:
664  template<typename T>
665  Decl *instantiateUnresolvedUsingDecl(T *D,
666  bool InstantiatingPackElement = false);
667  };
668 
669 } // namespace clang
670 
671 #endif // LLVM_CLANG_SEMA_TEMPLATE_H
clang::MultiLevelTemplateArgumentList::setArgument
void setArgument(unsigned Depth, unsigned Index, TemplateArgument Arg)
Clear out a specific template argument.
Definition: Template.h:178
clang::MultiLevelTemplateArgumentList::begin
ArgListsIterator begin()
Definition: Template.h:228
clang::TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl
Decl * VisitVarTemplateSpecializationDecl(VarTemplateDecl *VarTemplate, VarDecl *FromVar, const TemplateArgumentListInfo &TemplateArgsInfo, ArrayRef< TemplateArgument > Converted, VarTemplateSpecializationDecl *PrevDecl=nullptr)
Definition: SemaTemplateInstantiateDecl.cpp:3852
clang::TemplateDeclInstantiator::delayed_var_partial_spec_begin
delayed_var_partial_spec_iterator delayed_var_partial_spec_begin()
Definition: Template.h:614
clang::MultiLevelTemplateArgumentList::addOuterTemplateArguments
void addOuterTemplateArguments(ArgList Args)
Add a new outmost level to the multi-level template argument list.
Definition: Template.h:196
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1389
clang::TPOC_Conversion
@ TPOC_Conversion
Partial ordering of function templates for a call to a conversion function.
Definition: Template.h:243
llvm::SmallVector
Definition: LLVM.h:38
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:247
clang::TemplateDeclInstantiator::RewriteKind::None
@ None
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:737
clang::MultiLevelTemplateArgumentList::getKind
TemplateSubstitutionKind getKind() const
Determine the kind of template substitution being performed.
Definition: Template.h:105
clang::TemplateDeclInstantiator::SubstTemplateParams
TemplateParameterList * SubstTemplateParams(TemplateParameterList *List)
Instantiates a nested template parameter list in the current instantiation context.
Definition: SemaTemplateInstantiateDecl.cpp:4063
clang::TemplateSubstitutionKind::Rewrite
@ Rewrite
We are substituting template parameters for (typically) other template parameters in order to rewrite...
clang::LookupResult
Represents the results of name lookup.
Definition: Lookup.h:46
clang::TemplateDeclInstantiator::delayed_var_partial_spec_iterator
SmallVectorImpl< std::pair< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > >::iterator delayed_var_partial_spec_iterator
Definition: Template.h:604
clang::DeducedTemplateArgument::DeducedTemplateArgument
DeducedTemplateArgument(const TemplateArgument &Arg, bool DeducedFromArrayBound=false)
Definition: Template.h:274
clang::TemplateDeclInstantiator::RewriteKind::RewriteSpaceshipAsEqualEqual
@ RewriteSpaceshipAsEqualEqual
clang::TemplateSubstitutionKind::Specialization
@ Specialization
We are substituting template parameters for template arguments in order to form a template specializa...
clang::DeducedTemplateArgument::DeducedTemplateArgument
DeducedTemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value, QualType ValueType, bool DeducedFromArrayBound)
Construct an integral non-type template argument that has been deduced, possibly from an array bound.
Definition: Template.h:280
clang::TemplateDeclInstantiator::delayed_partial_spec_end
delayed_partial_spec_iterator delayed_partial_spec_end()
Return an iterator to the end of the set of "delayed" partial specializations, which must be passed t...
Definition: Template.h:622
clang::MultiLevelTemplateArgumentList::end
ArgListsIterator end()
Definition: Template.h:232
llvm::Optional
Definition: LLVM.h:40
clang::DeducedTemplateArgument
Captures a template argument whose value has been deduced via c++ template argument deduction.
Definition: Template.h:266
clang::LocalInstantiationScope::deleteScopes
static void deleteScopes(LocalInstantiationScope *Scope, LocalInstantiationScope *Outermost)
deletes the given scope, and all outer scopes, down to the given outermost scope.
Definition: Template.h:437
clang::MultiLevelTemplateArgumentList::getOutermost
const ArgList & getOutermost() const
Retrieve the outermost template argument list.
Definition: Template.h:225
clang::ClassTemplatePartialSpecializationDecl
Definition: DeclTemplate.h:2104
clang::TemplateDeclInstantiator::disableLateAttributeInstantiation
void disableLateAttributeInstantiation()
Definition: Template.h:593
clang::VarTemplateSpecializationDecl
Represents a variable template specialization, which refers to a variable template with a given set o...
Definition: DeclTemplate.h:2693
clang::TPOC_Other
@ TPOC_Other
Partial ordering of function templates in other contexts, e.g., taking the address of a function temp...
Definition: Template.h:248
clang::EnumDecl
Represents an enum.
Definition: Decl.h:3676
clang::TemplateArgumentList::data
const TemplateArgument * data() const
Retrieve a pointer to the template argument list.
Definition: DeclTemplate.h:301
clang::MultiLevelTemplateArgumentList::MultiLevelTemplateArgumentList
MultiLevelTemplateArgumentList(const TemplateArgumentList &TemplateArgs)
Construct a single-level template argument list.
Definition: Template.h:98
clang::CodeGen::AlignmentSource::Decl
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
APSInt
llvm::APSInt APSInt
Definition: ByteCodeEmitter.cpp:19
TemplateBase.h
DeclTemplate.h
clang::TemplateDeclInstantiator::SubstDefaultedFunction
bool SubstDefaultedFunction(FunctionDecl *New, FunctionDecl *Tmpl)
Definition: SemaTemplateInstantiateDecl.cpp:4713
clang::TemplateArgumentListInfo
A convenient class for passing around template argument information.
Definition: TemplateBase.h:563
clang::Sema::ArgumentPackSubstitutionIndexRAII
RAII object used to change the argument pack substitution index within a Sema object.
Definition: Sema.h:9302
clang::TemplateDeclInstantiator::getEvaluateConstraints
bool getEvaluateConstraints()
Definition: Template.h:533
clang::Scope
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
clang::TemplateDeclInstantiator::adjustForRewrite
void adjustForRewrite(RewriteKind RK, FunctionDecl *Orig, QualType &T, TypeSourceInfo *&TInfo, DeclarationNameInfo &NameInfo)
Definition: SemaTemplateInstantiateDecl.cpp:3987
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:209
clang::TemplateDeclInstantiator
Definition: Template.h:497
clang::TemplateDeclInstantiator::RewriteKind
RewriteKind
Definition: Template.h:564
clang::LocalInstantiationScope::Exit
void Exit()
Exit this local instantiation scope early.
Definition: Template.h:384
Depth
int Depth
Definition: ASTDiff.cpp:191
clang::DeducedTemplateArgument::setDeducedFromArrayBound
void setDeducedFromArrayBound(bool Deduced)
Specify whether the given non-type template argument was deduced from an array bound.
Definition: Template.h:293
clang::TemplateArgument
Represents a template argument.
Definition: TemplateBase.h:61
clang::MultiLevelTemplateArgumentList
Data structure that captures multiple levels of template argument lists for use in template instantia...
Definition: Template.h:75
Type.h
clang::TemplateDeclInstantiator::VisitFunctionDecl
Decl * VisitFunctionDecl(FunctionDecl *D, TemplateParameterList *TemplateParams, RewriteKind RK=RewriteKind::None)
Normal class members are of more specific types and therefore don't make it here.
Definition: SemaTemplateInstantiateDecl.cpp:2008
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:879
clang::TagDecl
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3396
clang::TemplateParameterList
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:70
clang::TemplateDeclInstantiator::setEvaluateConstraints
void setEvaluateConstraints(bool B)
Definition: Template.h:530
clang::MultiLevelTemplateArgumentList::getNumLevels
unsigned getNumLevels() const
Determine the number of levels in this template argument list.
Definition: Template.h:116
clang::DeducedTemplateArgument::wasDeducedFromArrayBound
bool wasDeducedFromArrayBound() const
For a non-type template argument, determine whether the template argument was deduced from an array b...
Definition: Template.h:289
clang::TemplateDeclInstantiator::VisitBaseUsingDecls
Decl * VisitBaseUsingDecls(BaseUsingDecl *D, BaseUsingDecl *Inst, LookupResult *Lookup)
Definition: SemaTemplateInstantiateDecl.cpp:3169
clang::LocalInstantiationScope::DeclArgumentPack
SmallVector< VarDecl *, 4 > DeclArgumentPack
A set of declarations.
Definition: Template.h:307
Sema.h
clang::MultiLevelTemplateArgumentList::getNumRetainedOuterLevels
unsigned getNumRetainedOuterLevels() const
Definition: Template.h:132
clang::LocalInstantiationScope::~LocalInstantiationScope
~LocalInstantiationScope()
Definition: Template.h:377
clang::TemplateDeclInstantiator::InstantiateTypedefNameDecl
Decl * InstantiateTypedefNameDecl(TypedefNameDecl *D, bool IsTypeAlias)
Definition: SemaTemplateInstantiateDecl.cpp:939
clang::MultiLevelTemplateArgumentList::isAnyArgInstantiationDependent
bool isAnyArgInstantiationDependent() const
Definition: Template.h:169
clang::TemplateDeclInstantiator::delayed_var_partial_spec_end
delayed_var_partial_spec_iterator delayed_var_partial_spec_end()
Definition: Template.h:626
clang::TemplateDeclInstantiator::delayed_partial_spec_begin
delayed_partial_spec_iterator delayed_partial_spec_begin()
Return an iterator to the beginning of the set of "delayed" partial specializations,...
Definition: Template.h:610
clang::TemplateDeclInstantiator::VisitCXXMethodDecl
Decl * VisitCXXMethodDecl(CXXMethodDecl *D, TemplateParameterList *TemplateParams, Optional< const ASTTemplateArgumentListInfo * > ClassScopeSpecializationArgs=llvm::None, RewriteKind RK=RewriteKind::None)
Definition: SemaTemplateInstantiateDecl.cpp:2368
clang::RISCV::TA
@ TA
Definition: RISCVVIntrinsicUtils.h:96
clang::TemplateDeclInstantiator::SubstQualifier
bool SubstQualifier(const DeclaratorDecl *OldDecl, DeclaratorDecl *NewDecl)
Definition: SemaTemplateInstantiateDecl.cpp:72
clang::LocalInstantiationScope::getPartiallySubstitutedPack
NamedDecl * getPartiallySubstitutedPack(const TemplateArgument **ExplicitArgs=nullptr, unsigned *NumExplicitArgs=nullptr) const
Retrieve the partially-substitued template parameter pack.
Definition: SemaTemplateInstantiate.cpp:4025
clang::LocalInstantiationScope::cloneScopes
LocalInstantiationScope * cloneScopes(LocalInstantiationScope *Outermost)
Clone this scope, and all outer scopes, down to the given outermost scope.
Definition: Template.h:397
clang::MultiLevelTemplateArgumentList::hasTemplateArgument
bool hasTemplateArgument(unsigned Depth, unsigned Index) const
Determine whether there is a non-NULL template argument at the given depth and index.
Definition: Template.h:157
clang::ClassTemplateDecl
Declaration of a class template.
Definition: DeclTemplate.h:2276
clang::MultiLevelTemplateArgumentList::end
ConstArgListsIterator end() const
Definition: Template.h:233
clang::LocalInstantiationScope::getSema
const Sema & getSema() const
Definition: Template.h:381
clang::TemplateSubstitutionKind
TemplateSubstitutionKind
The kind of template substitution being performed.
Definition: Template.h:46
clang::VarTemplatePartialSpecializationDecl
Definition: DeclTemplate.h:2955
clang::TemplateDeclInstantiator::InstantiateEnumDefinition
void InstantiateEnumDefinition(EnumDecl *Enum, EnumDecl *Pattern)
Definition: SemaTemplateInstantiateDecl.cpp:1495
clang::LocalInstantiationScope::operator=
LocalInstantiationScope & operator=(const LocalInstantiationScope &)=delete
clang::MultiLevelTemplateArgumentList::getNumSubsitutedArgs
unsigned getNumSubsitutedArgs(unsigned Depth) const
Definition: Template.h:127
llvm::ArrayRef
Definition: LLVM.h:34
DeclVisitor.h
Value
Value
Definition: UninitializedValues.cpp:102
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
clang::DeclaratorDecl
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:731
clang::MultiLevelTemplateArgumentList::getInnermost
const ArgList & getInnermost() const
Retrieve the innermost template argument list.
Definition: Template.h:221
clang::TemplatePartialOrderingContext
Definition: Template.h:255
clang::Sema
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:358
LLVM.h
clang::TemplateDeclInstantiator::VisitDecl
Decl * VisitDecl(Decl *D)
Definition: SemaTemplateInstantiateDecl.cpp:3970
clang::TemplateArgumentList
A template argument list.
Definition: DeclTemplate.h:238
clang::TemplateDeclInstantiator::InitMethodInstantiation
bool InitMethodInstantiation(CXXMethodDecl *New, CXXMethodDecl *Tmpl)
Initializes common fields of an instantiated method declaration (New) from the corresponding fields o...
Definition: SemaTemplateInstantiateDecl.cpp:4697
clang::Sema::CurrentInstantiationScope
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
Definition: Sema.h:9615
clang::TemplateDeclInstantiator::InitFunctionInstantiation
bool InitFunctionInstantiation(FunctionDecl *New, FunctionDecl *Tmpl)
Initializes the common fields of an instantiation function declaration (New) from the corresponding f...
Definition: SemaTemplateInstantiateDecl.cpp:4607
clang::DeducedTemplateArgument::DeducedTemplateArgument
DeducedTemplateArgument()=default
clang::MultiLevelTemplateArgumentList::getNewDepth
unsigned getNewDepth(unsigned OldDepth) const
Determine how many of the OldDepth outermost template parameter lists would be removed by substitutin...
Definition: Template.h:138
clang::MultiLevelTemplateArgumentList::addOuterRetainedLevels
void addOuterRetainedLevels(unsigned Num)
Definition: Template.h:216
clang::MultiLevelTemplateArgumentList::setKind
void setKind(TemplateSubstitutionKind K)
Definition: Template.h:102
clang::LocalInstantiationScope::SetPartiallySubstitutedPack
void SetPartiallySubstitutedPack(NamedDecl *Pack, const TemplateArgument *ExplicitArgs, unsigned NumExplicitArgs)
Note that the given parameter pack has been partially substituted via explicit specification of templ...
Definition: SemaTemplateInstantiate.cpp:4012
clang::MultiLevelTemplateArgumentList::begin
ConstArgListsIterator begin() const
Definition: Template.h:229
clang::MultiLevelTemplateArgumentList::getNumSubstitutedLevels
unsigned getNumSubstitutedLevels() const
Determine the number of substituted levels in this template argument list.
Definition: Template.h:122
clang
Definition: CalledOnceCheck.h:17
clang::TPOC
TPOC
The context in which partial ordering of function templates occurs.
Definition: Template.h:237
clang::MultiLevelTemplateArgumentList::operator()
const TemplateArgument & operator()(unsigned Depth, unsigned Index) const
Retrieve the template argument at a given depth and index.
Definition: Template.h:147
clang::TemplateDeclInstantiator::TemplateDeclInstantiator
TemplateDeclInstantiator(Sema &SemaRef, DeclContext *Owner, const MultiLevelTemplateArgumentList &TemplateArgs)
Definition: Template.h:524
clang::LocalInstantiationScope::LocalInstantiationScope
LocalInstantiationScope(Sema &SemaRef, bool CombineWithOuterScope=false)
Definition: Template.h:367
clang::DeclVisitor
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:66
clang::TPOC_Call
@ TPOC_Call
Partial ordering of function templates for a function call.
Definition: Template.h:239
clang::TypeSourceInfo
A container of type source information.
Definition: Type.h:6646
clang::TemplateDeclInstantiator::InstantiateVarTemplatePartialSpecialization
VarTemplatePartialSpecializationDecl * InstantiateVarTemplatePartialSpecialization(VarTemplateDecl *VarTemplate, VarTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a variable template partial specialization.
Definition: SemaTemplateInstantiateDecl.cpp:4236
clang::LocalInstantiationScope
A stack-allocated class that identifies which local variable declaration instantiations are present i...
Definition: Template.h:304
clang::LocalInstantiationScope::ResetPartiallySubstitutedPack
void ResetPartiallySubstitutedPack()
Reset the partially-substituted pack when it is no longer of interest.
Definition: Template.h:479
clang::LocalInstantiationScope::InstantiatedLocalPackArg
void InstantiatedLocalPackArg(const Decl *D, VarDecl *Inst)
Definition: SemaTemplateInstantiate.cpp:3982
clang::TypedefNameDecl
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3248
clang::TemplateDeclInstantiator::delayed_partial_spec_iterator
SmallVectorImpl< std::pair< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > >::iterator delayed_partial_spec_iterator
Definition: Template.h:601
clang::TemplatePartialOrderingContext::TemplatePartialOrderingContext
TemplatePartialOrderingContext(TPOC Value)
Definition: Template.h:259
clang::TemplateDeclInstantiator::InstantiateClassTemplatePartialSpecialization
ClassTemplatePartialSpecializationDecl * InstantiateClassTemplatePartialSpecialization(ClassTemplateDecl *ClassTemplate, ClassTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a class template partial specialization.
Definition: SemaTemplateInstantiateDecl.cpp:4109
clang::MultiLevelTemplateArgumentList::replaceInnermostTemplateArguments
void replaceInnermostTemplateArguments(ArgList Args)
Replaces the current 'innermost' level with the provided argument list.
Definition: Template.h:205
clang::TemplateDeclInstantiator::SubstFunctionType
TypeSourceInfo * SubstFunctionType(FunctionDecl *D, SmallVectorImpl< ParmVarDecl * > &Params)
Definition: SemaTemplateInstantiateDecl.cpp:4362
clang::MultiLevelTemplateArgumentList::MultiLevelTemplateArgumentList
MultiLevelTemplateArgumentList()=default
Construct an empty set of template argument lists.
clang::MultiLevelTemplateArgumentList::isRewrite
bool isRewrite() const
Determine whether we are rewriting template parameters rather than substituting for them.
Definition: Template.h:110
clang::TemplateDeclInstantiator::getStartingScope
LocalInstantiationScope * getStartingScope() const
Definition: Template.h:598
llvm::SmallVectorImpl
Definition: Randstruct.h:18
clang::VarTemplateDecl
Declaration of a variable template.
Definition: DeclTemplate.h:3109
clang::BaseUsingDecl
Represents a C++ declaration that introduces decls from somewhere else.
Definition: DeclCXX.h:3319
clang::MultiLevelTemplateArgumentList::addOuterRetainedLevel
void addOuterRetainedLevel()
Add an outermost level that we are not substituting.
Definition: Template.h:213
clang::DeclarationNameInfo
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
Definition: DeclarationName.h:767
clang::LocalInstantiationScope::isLocalPackExpansion
bool isLocalPackExpansion(const Decl *D)
Determine whether D is a pack expansion created in this scope.
Definition: SemaTemplateInstantiate.cpp:4005
clang::TemplateArgumentList::size
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Definition: DeclTemplate.h:298
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1877
clang::LocalInstantiationScope::MakeInstantiatedLocalArgPack
void MakeInstantiatedLocalArgPack(const Decl *D)
Definition: SemaTemplateInstantiate.cpp:3989
clang::LocalInstantiationScope::findInstantiationOf
llvm::PointerUnion< Decl *, DeclArgumentPack * > * findInstantiationOf(const Decl *D)
Find the instantiation of the declaration D within the current instantiation scope.
Definition: SemaTemplateInstantiate.cpp:3907
clang::CXXMethodDecl
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1983
clang::TemplateDeclInstantiator::VisitVarDecl
Decl * VisitVarDecl(VarDecl *D, bool InstantiatingVarTemplate, ArrayRef< BindingDecl * > *Bindings=nullptr)
Definition: SemaTemplateInstantiateDecl.cpp:1101
clang::MultiLevelTemplateArgumentList::addOuterTemplateArguments
void addOuterTemplateArguments(const TemplateArgumentList *TemplateArgs)
Add a new outermost level to the multi-level template argument list.
Definition: Template.h:189
clang::TemplateDeclInstantiator::enableLateAttributeInstantiation
void enableLateAttributeInstantiation(Sema::LateInstantiatedAttrVec *LA)
Definition: Template.h:587
clang::LocalInstantiationScope::InstantiatedLocal
void InstantiatedLocal(const Decl *D, Decl *Inst)
Definition: SemaTemplateInstantiate.cpp:3961