Clang Project

clang_source_code/include/clang/AST/DeclTemplate.h
1//===- DeclTemplate.h - Classes for representing 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//
9/// \file
10/// Defines the C++ template declaration subclasses.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_DECLTEMPLATE_H
15#define LLVM_CLANG_AST_DECLTEMPLATE_H
16
17#include "clang/AST/Decl.h"
18#include "clang/AST/DeclBase.h"
19#include "clang/AST/DeclCXX.h"
20#include "clang/AST/DeclarationName.h"
21#include "clang/AST/Redeclarable.h"
22#include "clang/AST/TemplateBase.h"
23#include "clang/AST/Type.h"
24#include "clang/Basic/LLVM.h"
25#include "clang/Basic/SourceLocation.h"
26#include "clang/Basic/Specifiers.h"
27#include "llvm/ADT/ArrayRef.h"
28#include "llvm/ADT/FoldingSet.h"
29#include "llvm/ADT/PointerIntPair.h"
30#include "llvm/ADT/PointerUnion.h"
31#include "llvm/ADT/iterator.h"
32#include "llvm/ADT/iterator_range.h"
33#include "llvm/Support/Casting.h"
34#include "llvm/Support/Compiler.h"
35#include "llvm/Support/TrailingObjects.h"
36#include <cassert>
37#include <cstddef>
38#include <cstdint>
39#include <iterator>
40#include <utility>
41
42namespace clang {
43
44enum BuiltinTemplateKind : int;
45class ClassTemplateDecl;
46class ClassTemplatePartialSpecializationDecl;
47class Expr;
48class FunctionTemplateDecl;
49class IdentifierInfo;
50class NonTypeTemplateParmDecl;
51class TemplateDecl;
52class TemplateTemplateParmDecl;
53class TemplateTypeParmDecl;
54class UnresolvedSetImpl;
55class VarTemplateDecl;
56class VarTemplatePartialSpecializationDecl;
57
58/// Stores a template parameter of any kind.
59using TemplateParameter =
60    llvm::PointerUnion3<TemplateTypeParmDecl *, NonTypeTemplateParmDecl *,
61                        TemplateTemplateParmDecl *>;
62
63NamedDecl *getAsNamedDecl(TemplateParameter P);
64
65/// Stores a list of template parameters for a TemplateDecl and its
66/// derived classes.
67class TemplateParameterList final
68    : private llvm::TrailingObjects<TemplateParameterList, NamedDecl *,
69                                    Expr *> {
70  /// The location of the 'template' keyword.
71  SourceLocation TemplateLoc;
72
73  /// The locations of the '<' and '>' angle brackets.
74  SourceLocation LAngleLocRAngleLoc;
75
76  /// The number of template parameters in this template
77  /// parameter list.
78  unsigned NumParams : 30;
79
80  /// Whether this template parameter list contains an unexpanded parameter
81  /// pack.
82  unsigned ContainsUnexpandedParameterPack : 1;
83
84  /// Whether this template parameter list has an associated requires-clause
85  unsigned HasRequiresClause : 1;
86
87protected:
88  TemplateParameterList(SourceLocation TemplateLocSourceLocation LAngleLoc,
89                        ArrayRef<NamedDecl *> ParamsSourceLocation RAngleLoc,
90                        Expr *RequiresClause);
91
92  size_t numTrailingObjects(OverloadToken<NamedDecl *>) const {
93    return NumParams;
94  }
95
96  size_t numTrailingObjects(OverloadToken<Expr *>) const {
97    return HasRequiresClause;
98  }
99
100public:
101  template <size_t N, bool HasRequiresClause>
102  friend class FixedSizeTemplateParameterListStorage;
103  friend TrailingObjects;
104
105  static TemplateParameterList *Create(const ASTContext &C,
106                                       SourceLocation TemplateLoc,
107                                       SourceLocation LAngleLoc,
108                                       ArrayRef<NamedDecl *> Params,
109                                       SourceLocation RAngleLoc,
110                                       Expr *RequiresClause);
111
112  /// Iterates through the template parameters in this list.
113  using iterator = NamedDecl **;
114
115  /// Iterates through the template parameters in this list.
116  using const_iterator = NamedDecl * const *;
117
118  iterator begin() { return getTrailingObjects<NamedDecl *>(); }
119  const_iterator begin() const { return getTrailingObjects<NamedDecl *>(); }
120  iterator end() { return begin() + NumParams; }
121  const_iterator end() const { return begin() + NumParams; }
122
123  unsigned size() const { return NumParams; }
124
125  ArrayRef<NamedDecl*> asArray() {
126    return llvm::makeArrayRef(begin(), end());
127  }
128  ArrayRef<const NamedDecl*> asArray() const {
129    return llvm::makeArrayRef(begin(), size());
130  }
131
132  NamedDeclgetParam(unsigned Idx) {
133     (0) . __assert_fail ("Idx < size() && \"Template parameter index out-of-range\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 133, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Idx < size() && "Template parameter index out-of-range");
134    return begin()[Idx];
135  }
136  const NamedDeclgetParam(unsigned Idxconst {
137     (0) . __assert_fail ("Idx < size() && \"Template parameter index out-of-range\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 137, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Idx < size() && "Template parameter index out-of-range");
138    return begin()[Idx];
139  }
140
141  /// Returns the minimum number of arguments needed to form a
142  /// template specialization.
143  ///
144  /// This may be fewer than the number of template parameters, if some of
145  /// the parameters have default arguments or if there is a parameter pack.
146  unsigned getMinRequiredArguments() const;
147
148  /// Get the depth of this template parameter list in the set of
149  /// template parameter lists.
150  ///
151  /// The first template parameter list in a declaration will have depth 0,
152  /// the second template parameter list will have depth 1, etc.
153  unsigned getDepth() const;
154
155  /// Determine whether this template parameter list contains an
156  /// unexpanded parameter pack.
157  bool containsUnexpandedParameterPack() const {
158    return ContainsUnexpandedParameterPack;
159  }
160
161  /// The constraint-expression of the associated requires-clause.
162  Expr *getRequiresClause() {
163    return HasRequiresClause ? *getTrailingObjects<Expr *>() : nullptr;
164  }
165
166  /// The constraint-expression of the associated requires-clause.
167  const Expr *getRequiresClause() const {
168    return HasRequiresClause ? *getTrailingObjects<Expr *>() : nullptr;
169  }
170
171  SourceLocation getTemplateLoc() const { return TemplateLoc; }
172  SourceLocation getLAngleLoc() const { return LAngleLoc; }
173  SourceLocation getRAngleLoc() const { return RAngleLoc; }
174
175  SourceRange getSourceRange() const LLVM_READONLY {
176    return SourceRange(TemplateLoc, RAngleLoc);
177  }
178
179public:
180  // FIXME: workaround for MSVC 2013; remove when no longer needed
181  using FixedSizeStorageOwner = TrailingObjects::FixedSizeStorageOwner;
182};
183
184/// Stores a list of template parameters and the associated
185/// requires-clause (if any) for a TemplateDecl and its derived classes.
186/// Suitable for creating on the stack.
187template <size_t N, bool HasRequiresClause>
188class FixedSizeTemplateParameterListStorage
189    : public TemplateParameterList::FixedSizeStorageOwner {
190  typename TemplateParameterList::FixedSizeStorage<
191      NamedDecl *, Expr *>::with_counts<
192      N, HasRequiresClause ? 1u : 0u
193      >::type storage;
194
195public:
196  FixedSizeTemplateParameterListStorage(SourceLocation TemplateLoc,
197                                        SourceLocation LAngleLoc,
198                                        ArrayRef<NamedDecl *> Params,
199                                        SourceLocation RAngleLoc,
200                                        Expr *RequiresClause)
201      : FixedSizeStorageOwner(
202            (assert(N == Params.size()),
203             (RequiresClause)", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 203, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(HasRequiresClause == static_cast<bool>(RequiresClause)),
204             new (static_cast<void *>(&storage)) TemplateParameterList(
205                 TemplateLoc, LAngleLoc, Params, RAngleLoc, RequiresClause))) {}
206};
207
208/// A template argument list.
209class TemplateArgumentList final
210    : private llvm::TrailingObjects<TemplateArgumentList, TemplateArgument> {
211  /// The template argument list.
212  const TemplateArgument *Arguments;
213
214  /// The number of template arguments in this template
215  /// argument list.
216  unsigned NumArguments;
217
218  // Constructs an instance with an internal Argument list, containing
219  // a copy of the Args array. (Called by CreateCopy)
220  TemplateArgumentList(ArrayRef<TemplateArgumentArgs);
221
222public:
223  friend TrailingObjects;
224
225  TemplateArgumentList(const TemplateArgumentList &) = delete;
226  TemplateArgumentList &operator=(const TemplateArgumentList &) = delete;
227
228  /// Type used to indicate that the template argument list itself is a
229  /// stack object. It does not own its template arguments.
230  enum OnStackType { OnStack };
231
232  /// Create a new template argument list that copies the given set of
233  /// template arguments.
234  static TemplateArgumentList *CreateCopy(ASTContext &Context,
235                                          ArrayRef<TemplateArgumentArgs);
236
237  /// Construct a new, temporary template argument list on the stack.
238  ///
239  /// The template argument list does not own the template arguments
240  /// provided.
241  explicit TemplateArgumentList(OnStackTypeArrayRef<TemplateArgumentArgs)
242      : Arguments(Args.data()), NumArguments(Args.size()) {}
243
244  /// Produces a shallow copy of the given template argument list.
245  ///
246  /// This operation assumes that the input argument list outlives it.
247  /// This takes the list as a pointer to avoid looking like a copy
248  /// constructor, since this really really isn't safe to use that
249  /// way.
250  explicit TemplateArgumentList(const TemplateArgumentList *Other)
251      : Arguments(Other->data()), NumArguments(Other->size()) {}
252
253  /// Retrieve the template argument at a given index.
254  const TemplateArgument &get(unsigned Idxconst {
255     (0) . __assert_fail ("Idx < NumArguments && \"Invalid template argument index\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 255, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Idx < NumArguments && "Invalid template argument index");
256    return data()[Idx];
257  }
258
259  /// Retrieve the template argument at a given index.
260  const TemplateArgument &operator[](unsigned Idxconst { return get(Idx); }
261
262  /// Produce this as an array ref.
263  ArrayRef<TemplateArgumentasArray() const {
264    return llvm::makeArrayRef(data(), size());
265  }
266
267  /// Retrieve the number of template arguments in this
268  /// template argument list.
269  unsigned size() const { return NumArguments; }
270
271  /// Retrieve a pointer to the template argument list.
272  const TemplateArgument *data() const { return Arguments; }
273};
274
275void *allocateDefaultArgStorageChain(const ASTContext &C);
276
277/// Storage for a default argument. This is conceptually either empty, or an
278/// argument value, or a pointer to a previous declaration that had a default
279/// argument.
280///
281/// However, this is complicated by modules: while we require all the default
282/// arguments for a template to be equivalent, there may be more than one, and
283/// we need to track all the originating parameters to determine if the default
284/// argument is visible.
285template<typename ParmDecl, typename ArgType>
286class DefaultArgStorage {
287  /// Storage for both the value *and* another parameter from which we inherit
288  /// the default argument. This is used when multiple default arguments for a
289  /// parameter are merged together from different modules.
290  struct Chain {
291    ParmDecl *PrevDeclWithDefaultArg;
292    ArgType Value;
293  };
294  static_assert(sizeof(Chain) == sizeof(void *) * 2,
295                "non-pointer argument type?");
296
297  llvm::PointerUnion3<ArgType, ParmDecl*, Chain*> ValueOrInherited;
298
299  static ParmDecl *getParmOwningDefaultArg(ParmDecl *Parm) {
300    const DefaultArgStorage &Storage = Parm->getDefaultArgStorage();
301    if (auto *Prev = Storage.ValueOrInherited.template dyn_cast<ParmDecl *>())
302      Parm = Prev;
303     (0) . __assert_fail ("!Parm->getDefaultArgStorage() .ValueOrInherited.template is() && \"should only be one level of indirection\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 305, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!Parm->getDefaultArgStorage()
304 (0) . __assert_fail ("!Parm->getDefaultArgStorage() .ValueOrInherited.template is() && \"should only be one level of indirection\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 305, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">                .ValueOrInherited.template is<ParmDecl *>() &&
305 (0) . __assert_fail ("!Parm->getDefaultArgStorage() .ValueOrInherited.template is() && \"should only be one level of indirection\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 305, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">           "should only be one level of indirection");
306    return Parm;
307  }
308
309public:
310  DefaultArgStorage() : ValueOrInherited(ArgType()) {}
311
312  /// Determine whether there is a default argument for this parameter.
313  bool isSet() const { return !ValueOrInherited.isNull(); }
314
315  /// Determine whether the default argument for this parameter was inherited
316  /// from a previous declaration of the same entity.
317  bool isInherited() const { return ValueOrInherited.template is<ParmDecl*>(); }
318
319  /// Get the default argument's value. This does not consider whether the
320  /// default argument is visible.
321  ArgType get() const {
322    const DefaultArgStorage *Storage = this;
323    if (const auto *Prev = ValueOrInherited.template dyn_cast<ParmDecl *>())
324      Storage = &Prev->getDefaultArgStorage();
325    if (const auto *C = Storage->ValueOrInherited.template dyn_cast<Chain *>())
326      return C->Value;
327    return Storage->ValueOrInherited.template get<ArgType>();
328  }
329
330  /// Get the parameter from which we inherit the default argument, if any.
331  /// This is the parameter on which the default argument was actually written.
332  const ParmDecl *getInheritedFrom() const {
333    if (const auto *D = ValueOrInherited.template dyn_cast<ParmDecl *>())
334      return D;
335    if (const auto *C = ValueOrInherited.template dyn_cast<Chain *>())
336      return C->PrevDeclWithDefaultArg;
337    return nullptr;
338  }
339
340  /// Set the default argument.
341  void set(ArgType Arg) {
342     (0) . __assert_fail ("!isSet() && \"default argument already set\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 342, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!isSet() && "default argument already set");
343    ValueOrInherited = Arg;
344  }
345
346  /// Set that the default argument was inherited from another parameter.
347  void setInherited(const ASTContext &C, ParmDecl *InheritedFrom) {
348     (0) . __assert_fail ("!isInherited() && \"default argument already inherited\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 348, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!isInherited() && "default argument already inherited");
349    InheritedFrom = getParmOwningDefaultArg(InheritedFrom);
350    if (!isSet())
351      ValueOrInherited = InheritedFrom;
352    else
353      ValueOrInherited = new (allocateDefaultArgStorageChain(C))
354          Chain{InheritedFrom, ValueOrInherited.template get<ArgType>()};
355  }
356
357  /// Remove the default argument, even if it was inherited.
358  void clear() {
359    ValueOrInherited = ArgType();
360  }
361};
362
363//===----------------------------------------------------------------------===//
364// Kinds of Templates
365//===----------------------------------------------------------------------===//
366
367/// Stores the template parameter list and associated constraints for
368/// \c TemplateDecl objects that track associated constraints.
369class ConstrainedTemplateDeclInfo {
370  friend TemplateDecl;
371
372public:
373  ConstrainedTemplateDeclInfo() = default;
374
375  TemplateParameterList *getTemplateParameters() const {
376    return TemplateParams;
377  }
378
379  Expr *getAssociatedConstraints() const { return AssociatedConstraints; }
380
381protected:
382  void setTemplateParameters(TemplateParameterList *TParams) {
383    TemplateParams = TParams;
384  }
385
386  void setAssociatedConstraints(Expr *AC) { AssociatedConstraints = AC; }
387
388  TemplateParameterList *TemplateParams = nullptr;
389  Expr *AssociatedConstraints = nullptr;
390};
391
392
393/// The base class of all kinds of template declarations (e.g.,
394/// class, function, etc.).
395///
396/// The TemplateDecl class stores the list of template parameters and a
397/// reference to the templated scoped declaration: the underlying AST node.
398class TemplateDecl : public NamedDecl {
399  void anchor() override;
400
401protected:
402  // Construct a template decl with the given name and parameters.
403  // Used when there is no templated element (e.g., for tt-params).
404  TemplateDecl(ConstrainedTemplateDeclInfo *CTDIKind DKDeclContext *DC,
405               SourceLocation LDeclarationName Name,
406               TemplateParameterList *Params)
407      : NamedDecl(DKDCLName), TemplatedDecl(nullptr),
408        TemplateParams(CTDI) {
409    this->setTemplateParameters(Params);
410  }
411
412  TemplateDecl(Kind DKDeclContext *DCSourceLocation LDeclarationName Name,
413               TemplateParameterList *Params)
414      : TemplateDecl(nullptrDKDCLNameParams) {}
415
416  // Construct a template decl with name, parameters, and templated element.
417  TemplateDecl(ConstrainedTemplateDeclInfo *CTDIKind DKDeclContext *DC,
418               SourceLocation LDeclarationName Name,
419               TemplateParameterList *ParamsNamedDecl *Decl)
420      : NamedDecl(DKDCLName), TemplatedDecl(Decl),
421        TemplateParams(CTDI) {
422    this->setTemplateParameters(Params);
423  }
424
425  TemplateDecl(Kind DKDeclContext *DCSourceLocation LDeclarationName Name,
426               TemplateParameterList *ParamsNamedDecl *Decl)
427      : TemplateDecl(nullptrDKDCLNameParamsDecl) {}
428
429public:
430  /// Get the list of template parameters
431  TemplateParameterList *getTemplateParameters() const {
432    const auto *const CTDI =
433        TemplateParams.dyn_cast<ConstrainedTemplateDeclInfo *>();
434    return CTDI ? CTDI->getTemplateParameters()
435                : TemplateParams.get<TemplateParameterList *>();
436  }
437
438  /// Get the constraint-expression from the associated requires-clause (if any)
439  const Expr *getRequiresClause() const {
440    const TemplateParameterList *const TP = getTemplateParameters();
441    return TP ? TP->getRequiresClause() : nullptr;
442  }
443
444  Expr *getAssociatedConstraints() const {
445    const auto *const C = cast<TemplateDecl>(getCanonicalDecl());
446    const auto *const CTDI =
447        C->TemplateParams.dyn_cast<ConstrainedTemplateDeclInfo *>();
448    return CTDI ? CTDI->getAssociatedConstraints() : nullptr;
449  }
450
451  /// Get the underlying, templated declaration.
452  NamedDecl *getTemplatedDecl() const { return TemplatedDecl; }
453
454  // Implement isa/cast/dyncast/etc.
455  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
456
457  static bool classofKind(Kind K) {
458    return K >= firstTemplate && K <= lastTemplate;
459  }
460
461  SourceRange getSourceRange() const override LLVM_READONLY {
462    return SourceRange(getTemplateParameters()->getTemplateLoc(),
463                       TemplatedDecl->getSourceRange().getEnd());
464  }
465
466protected:
467  NamedDecl *TemplatedDecl;
468
469  /// The template parameter list and optional requires-clause
470  /// associated with this declaration; alternatively, a
471  /// \c ConstrainedTemplateDeclInfo if the associated constraints of the
472  /// template are being tracked by this particular declaration.
473  llvm::PointerUnion<TemplateParameterList *,
474                     ConstrainedTemplateDeclInfo *>
475      TemplateParams;
476
477  void setTemplateParameters(TemplateParameterList *TParams) {
478    if (auto *const CTDI =
479            TemplateParams.dyn_cast<ConstrainedTemplateDeclInfo *>()) {
480      CTDI->setTemplateParameters(TParams);
481    } else {
482      TemplateParams = TParams;
483    }
484  }
485
486  void setAssociatedConstraints(Expr *AC) {
487     (0) . __assert_fail ("isCanonicalDecl() && \"Attaching associated constraints to non-canonical Decl\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 488, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(isCanonicalDecl() &&
488 (0) . __assert_fail ("isCanonicalDecl() && \"Attaching associated constraints to non-canonical Decl\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 488, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">           "Attaching associated constraints to non-canonical Decl");
489    TemplateParams.get<ConstrainedTemplateDeclInfo *>()
490        ->setAssociatedConstraints(AC);
491  }
492
493public:
494  /// Initialize the underlying templated declaration and
495  /// template parameters.
496  void init(NamedDecl *templatedDeclTemplateParameterListtemplateParams) {
497     (0) . __assert_fail ("!TemplatedDecl && \"TemplatedDecl already set!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 497, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!TemplatedDecl && "TemplatedDecl already set!");
498     (0) . __assert_fail ("!TemplateParams && \"TemplateParams already set!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 498, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!TemplateParams && "TemplateParams already set!");
499    TemplatedDecl = templatedDecl;
500    TemplateParams = templateParams;
501  }
502};
503
504/// Provides information about a function template specialization,
505/// which is a FunctionDecl that has been explicitly specialization or
506/// instantiated from a function template.
507class FunctionTemplateSpecializationInfo : public llvm::FoldingSetNode {
508  FunctionTemplateSpecializationInfo(FunctionDecl *FD,
509                                     FunctionTemplateDecl *Template,
510                                     TemplateSpecializationKind TSK,
511                                     const TemplateArgumentList *TemplateArgs,
512                       const ASTTemplateArgumentListInfo *TemplateArgsAsWritten,
513                                     SourceLocation POI)
514      : Function(FD), Template(Template, TSK - 1),
515        TemplateArguments(TemplateArgs),
516        TemplateArgumentsAsWritten(TemplateArgsAsWritten),
517        PointOfInstantiation(POI) {}
518
519public:
520  static FunctionTemplateSpecializationInfo *
521  Create(ASTContext &CFunctionDecl *FDFunctionTemplateDecl *Template,
522         TemplateSpecializationKind TSK,
523         const TemplateArgumentList *TemplateArgs,
524         const TemplateArgumentListInfo *TemplateArgsAsWritten,
525         SourceLocation POI);
526
527  /// The function template specialization that this structure
528  /// describes.
529  FunctionDecl *Function;
530
531  /// The function template from which this function template
532  /// specialization was generated.
533  ///
534  /// The two bits contain the top 4 values of TemplateSpecializationKind.
535  llvm::PointerIntPair<FunctionTemplateDecl *, 2Template;
536
537  /// The template arguments used to produce the function template
538  /// specialization from the function template.
539  const TemplateArgumentList *TemplateArguments;
540
541  /// The template arguments as written in the sources, if provided.
542  const ASTTemplateArgumentListInfo *TemplateArgumentsAsWritten;
543
544  /// The point at which this function template specialization was
545  /// first instantiated.
546  SourceLocation PointOfInstantiation;
547
548  /// Retrieve the template from which this function was specialized.
549  FunctionTemplateDecl *getTemplate() const { return Template.getPointer(); }
550
551  /// Determine what kind of template specialization this is.
552  TemplateSpecializationKind getTemplateSpecializationKind() const {
553    return (TemplateSpecializationKind)(Template.getInt() + 1);
554  }
555
556  bool isExplicitSpecialization() const {
557    return getTemplateSpecializationKind() == TSK_ExplicitSpecialization;
558  }
559
560  /// True if this declaration is an explicit specialization,
561  /// explicit instantiation declaration, or explicit instantiation
562  /// definition.
563  bool isExplicitInstantiationOrSpecialization() const {
564    return isTemplateExplicitInstantiationOrSpecialization(
565        getTemplateSpecializationKind());
566  }
567
568  /// Set the template specialization kind.
569  void setTemplateSpecializationKind(TemplateSpecializationKind TSK) {
570     (0) . __assert_fail ("TSK != TSK_Undeclared && \"Cannot encode TSK_Undeclared for a function template specialization\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 571, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(TSK != TSK_Undeclared &&
571 (0) . __assert_fail ("TSK != TSK_Undeclared && \"Cannot encode TSK_Undeclared for a function template specialization\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 571, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">         "Cannot encode TSK_Undeclared for a function template specialization");
572    Template.setInt(TSK - 1);
573  }
574
575  /// Retrieve the first point of instantiation of this function
576  /// template specialization.
577  ///
578  /// The point of instantiation may be an invalid source location if this
579  /// function has yet to be instantiated.
580  SourceLocation getPointOfInstantiation() const {
581    return PointOfInstantiation;
582  }
583
584  /// Set the (first) point of instantiation of this function template
585  /// specialization.
586  void setPointOfInstantiation(SourceLocation POI) {
587    PointOfInstantiation = POI;
588  }
589
590  void Profile(llvm::FoldingSetNodeID &ID) {
591    Profile(IDTemplateArguments->asArray(),
592            Function->getASTContext());
593  }
594
595  static void
596  Profile(llvm::FoldingSetNodeID &IDArrayRef<TemplateArgumentTemplateArgs,
597          ASTContext &Context) {
598    ID.AddInteger(TemplateArgs.size());
599    for (const TemplateArgument &TemplateArg : TemplateArgs)
600      TemplateArg.Profile(ID, Context);
601  }
602};
603
604/// Provides information a specialization of a member of a class
605/// template, which may be a member function, static data member,
606/// member class or member enumeration.
607class MemberSpecializationInfo {
608  // The member declaration from which this member was instantiated, and the
609  // manner in which the instantiation occurred (in the lower two bits).
610  llvm::PointerIntPair<NamedDecl *, 2MemberAndTSK;
611
612  // The point at which this member was first instantiated.
613  SourceLocation PointOfInstantiation;
614
615public:
616  explicit
617  MemberSpecializationInfo(NamedDecl *IFTemplateSpecializationKind TSK,
618                           SourceLocation POI = SourceLocation())
619      : MemberAndTSK(IF, TSK - 1), PointOfInstantiation(POI) {
620     (0) . __assert_fail ("TSK != TSK_Undeclared && \"Cannot encode undeclared template specializations for members\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 621, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(TSK != TSK_Undeclared &&
621 (0) . __assert_fail ("TSK != TSK_Undeclared && \"Cannot encode undeclared template specializations for members\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 621, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">           "Cannot encode undeclared template specializations for members");
622  }
623
624  /// Retrieve the member declaration from which this member was
625  /// instantiated.
626  NamedDecl *getInstantiatedFrom() const { return MemberAndTSK.getPointer(); }
627
628  /// Determine what kind of template specialization this is.
629  TemplateSpecializationKind getTemplateSpecializationKind() const {
630    return (TemplateSpecializationKind)(MemberAndTSK.getInt() + 1);
631  }
632
633  bool isExplicitSpecialization() const {
634    return getTemplateSpecializationKind() == TSK_ExplicitSpecialization;
635  }
636
637  /// Set the template specialization kind.
638  void setTemplateSpecializationKind(TemplateSpecializationKind TSK) {
639     (0) . __assert_fail ("TSK != TSK_Undeclared && \"Cannot encode undeclared template specializations for members\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 640, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(TSK != TSK_Undeclared &&
640 (0) . __assert_fail ("TSK != TSK_Undeclared && \"Cannot encode undeclared template specializations for members\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 640, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">           "Cannot encode undeclared template specializations for members");
641    MemberAndTSK.setInt(TSK - 1);
642  }
643
644  /// Retrieve the first point of instantiation of this member.
645  /// If the point of instantiation is an invalid location, then this member
646  /// has not yet been instantiated.
647  SourceLocation getPointOfInstantiation() const {
648    return PointOfInstantiation;
649  }
650
651  /// Set the first point of instantiation.
652  void setPointOfInstantiation(SourceLocation POI) {
653    PointOfInstantiation = POI;
654  }
655};
656
657/// Provides information about a dependent function-template
658/// specialization declaration.
659///
660/// Since explicit function template specialization and instantiation
661/// declarations can only appear in namespace scope, and you can only
662/// specialize a member of a fully-specialized class, the only way to
663/// get one of these is in a friend declaration like the following:
664///
665/// \code
666///   template \<class T> void foo(T);
667///   template \<class T> class A {
668///     friend void foo<>(T);
669///   };
670/// \endcode
671class DependentFunctionTemplateSpecializationInfo final
672    : private llvm::TrailingObjects<DependentFunctionTemplateSpecializationInfo,
673                                    TemplateArgumentLoc,
674                                    FunctionTemplateDecl *> {
675  /// The number of potential template candidates.
676  unsigned NumTemplates;
677
678  /// The number of template arguments.
679  unsigned NumArgs;
680
681  /// The locations of the left and right angle brackets.
682  SourceRange AngleLocs;
683
684  size_t numTrailingObjects(OverloadToken<TemplateArgumentLoc>) const {
685    return NumArgs;
686  }
687  size_t numTrailingObjects(OverloadToken<FunctionTemplateDecl *>) const {
688    return NumTemplates;
689  }
690
691  DependentFunctionTemplateSpecializationInfo(
692                                 const UnresolvedSetImpl &Templates,
693                                 const TemplateArgumentListInfo &TemplateArgs);
694
695public:
696  friend TrailingObjects;
697
698  static DependentFunctionTemplateSpecializationInfo *
699  Create(ASTContext &Contextconst UnresolvedSetImpl &Templates,
700         const TemplateArgumentListInfo &TemplateArgs);
701
702  /// Returns the number of function templates that this might
703  /// be a specialization of.
704  unsigned getNumTemplates() const { return NumTemplates; }
705
706  /// Returns the i'th template candidate.
707  FunctionTemplateDecl *getTemplate(unsigned Iconst {
708     (0) . __assert_fail ("I < getNumTemplates() && \"template index out of range\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 708, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(I < getNumTemplates() && "template index out of range");
709    return getTrailingObjects<FunctionTemplateDecl *>()[I];
710  }
711
712  /// Returns the explicit template arguments that were given.
713  const TemplateArgumentLoc *getTemplateArgs() const {
714    return getTrailingObjects<TemplateArgumentLoc>();
715  }
716
717  /// Returns the number of explicit template arguments that were given.
718  unsigned getNumTemplateArgs() const { return NumArgs; }
719
720  /// Returns the nth template argument.
721  const TemplateArgumentLoc &getTemplateArg(unsigned Iconst {
722     (0) . __assert_fail ("I < getNumTemplateArgs() && \"template arg index out of range\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 722, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(I < getNumTemplateArgs() && "template arg index out of range");
723    return getTemplateArgs()[I];
724  }
725
726  SourceLocation getLAngleLoc() const {
727    return AngleLocs.getBegin();
728  }
729
730  SourceLocation getRAngleLoc() const {
731    return AngleLocs.getEnd();
732  }
733};
734
735/// Declaration of a redeclarable template.
736class RedeclarableTemplateDecl : public TemplateDecl,
737                                 public Redeclarable<RedeclarableTemplateDecl>
738{
739  using redeclarable_base = Redeclarable<RedeclarableTemplateDecl>;
740
741  RedeclarableTemplateDecl *getNextRedeclarationImpl() override {
742    return getNextRedeclaration();
743  }
744
745  RedeclarableTemplateDecl *getPreviousDeclImpl() override {
746    return getPreviousDecl();
747  }
748
749  RedeclarableTemplateDecl *getMostRecentDeclImpl() override {
750    return getMostRecentDecl();
751  }
752
753  void anchor() override;
754protected:
755  template <typename EntryType> struct SpecEntryTraits {
756    using DeclType = EntryType;
757
758    static DeclType *getDecl(EntryType *D) {
759      return D;
760    }
761
762    static ArrayRef<TemplateArgumentgetTemplateArgs(EntryType *D) {
763      return D->getTemplateArgs().asArray();
764    }
765  };
766
767  template <typename EntryType, typename SETraits = SpecEntryTraits<EntryType>,
768            typename DeclType = typename SETraits::DeclType>
769  struct SpecIterator
770      : llvm::iterator_adaptor_base<
771            SpecIterator<EntryType, SETraits, DeclType>,
772            typename llvm::FoldingSetVector<EntryType>::iterator,
773            typename std::iterator_traits<typename llvm::FoldingSetVector<
774                EntryType>::iterator>::iterator_category,
775            DeclType *, ptrdiff_t, DeclType *, DeclType *> {
776    SpecIterator() = default;
777    explicit SpecIterator(
778        typename llvm::FoldingSetVector<EntryType>::iterator SetIter)
779        : SpecIterator::iterator_adaptor_base(std::move(SetIter)) {}
780
781    DeclType *operator*() const {
782      return SETraits::getDecl(&*this->I)->getMostRecentDecl();
783    }
784
785    DeclType *operator->() const { return **this; }
786  };
787
788  template <typename EntryType>
789  static SpecIterator<EntryType>
790  makeSpecIterator(llvm::FoldingSetVector<EntryType> &Specsbool isEnd) {
791    return SpecIterator<EntryType>(isEnd ? Specs.end() : Specs.begin());
792  }
793
794  void loadLazySpecializationsImpl() const;
795
796  template <class EntryType> typename SpecEntryTraits<EntryType>::DeclType*
797  findSpecializationImpl(llvm::FoldingSetVector<EntryType> &Specs,
798                         ArrayRef<TemplateArgumentArgsvoid *&InsertPos);
799
800  template <class Derived, class EntryType>
801  void addSpecializationImpl(llvm::FoldingSetVector<EntryType> &Specs,
802                             EntryType *Entryvoid *InsertPos);
803
804  struct CommonBase {
805    CommonBase() : InstantiatedFromMember(nullptrfalse) {}
806
807    /// The template from which this was most
808    /// directly instantiated (or null).
809    ///
810    /// The boolean value indicates whether this template
811    /// was explicitly specialized.
812    llvm::PointerIntPair<RedeclarableTemplateDecl*, 1bool>
813      InstantiatedFromMember;
814
815    /// If non-null, points to an array of specializations (including
816    /// partial specializations) known only by their external declaration IDs.
817    ///
818    /// The first value in the array is the number of specializations/partial
819    /// specializations that follow.
820    uint32_t *LazySpecializations = nullptr;
821  };
822
823  /// Pointer to the common data shared by all declarations of this
824  /// template.
825  mutable CommonBase *Common = nullptr;
826
827  /// Retrieves the "common" pointer shared by all (re-)declarations of
828  /// the same template. Calling this routine may implicitly allocate memory
829  /// for the common pointer.
830  CommonBase *getCommonPtr() const;
831
832  virtual CommonBase *newCommon(ASTContext &Cconst = 0;
833
834  // Construct a template decl with name, parameters, and templated element.
835  RedeclarableTemplateDecl(ConstrainedTemplateDeclInfo *CTDIKind DK,
836                           ASTContext &CDeclContext *DCSourceLocation L,
837                           DeclarationName NameTemplateParameterList *Params,
838                           NamedDecl *Decl)
839      : TemplateDecl(CTDIDKDCLNameParamsDecl), redeclarable_base(C)
840        {}
841
842  RedeclarableTemplateDecl(Kind DKASTContext &CDeclContext *DC,
843                           SourceLocation LDeclarationName Name,
844                           TemplateParameterList *ParamsNamedDecl *Decl)
845      : RedeclarableTemplateDecl(nullptrDKCDCLNameParamsDecl) {}
846
847public:
848  friend class ASTDeclReader;
849  friend class ASTDeclWriter;
850  friend class ASTReader;
851  template <class decl_type> friend class RedeclarableTemplate;
852
853  /// Retrieves the canonical declaration of this template.
854  RedeclarableTemplateDecl *getCanonicalDecl() override {
855    return getFirstDecl();
856  }
857  const RedeclarableTemplateDecl *getCanonicalDecl() const {
858    return getFirstDecl();
859  }
860
861  /// Determines whether this template was a specialization of a
862  /// member template.
863  ///
864  /// In the following example, the function template \c X<int>::f and the
865  /// member template \c X<int>::Inner are member specializations.
866  ///
867  /// \code
868  /// template<typename T>
869  /// struct X {
870  ///   template<typename U> void f(T, U);
871  ///   template<typename U> struct Inner;
872  /// };
873  ///
874  /// template<> template<typename T>
875  /// void X<int>::f(int, T);
876  /// template<> template<typename T>
877  /// struct X<int>::Inner { /* ... */ };
878  /// \endcode
879  bool isMemberSpecialization() const {
880    return getCommonPtr()->InstantiatedFromMember.getInt();
881  }
882
883  /// Note that this member template is a specialization.
884  void setMemberSpecialization() {
885     (0) . __assert_fail ("getCommonPtr()->InstantiatedFromMember.getPointer() && \"Only member templates can be member template specializations\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 886, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getCommonPtr()->InstantiatedFromMember.getPointer() &&
886 (0) . __assert_fail ("getCommonPtr()->InstantiatedFromMember.getPointer() && \"Only member templates can be member template specializations\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 886, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">           "Only member templates can be member template specializations");
887    getCommonPtr()->InstantiatedFromMember.setInt(true);
888  }
889
890  /// Retrieve the member template from which this template was
891  /// instantiated, or nullptr if this template was not instantiated from a
892  /// member template.
893  ///
894  /// A template is instantiated from a member template when the member
895  /// template itself is part of a class template (or member thereof). For
896  /// example, given
897  ///
898  /// \code
899  /// template<typename T>
900  /// struct X {
901  ///   template<typename U> void f(T, U);
902  /// };
903  ///
904  /// void test(X<int> x) {
905  ///   x.f(1, 'a');
906  /// };
907  /// \endcode
908  ///
909  /// \c X<int>::f is a FunctionTemplateDecl that describes the function
910  /// template
911  ///
912  /// \code
913  /// template<typename U> void X<int>::f(int, U);
914  /// \endcode
915  ///
916  /// which was itself created during the instantiation of \c X<int>. Calling
917  /// getInstantiatedFromMemberTemplate() on this FunctionTemplateDecl will
918  /// retrieve the FunctionTemplateDecl for the original template \c f within
919  /// the class template \c X<T>, i.e.,
920  ///
921  /// \code
922  /// template<typename T>
923  /// template<typename U>
924  /// void X<T>::f(T, U);
925  /// \endcode
926  RedeclarableTemplateDecl *getInstantiatedFromMemberTemplate() const {
927    return getCommonPtr()->InstantiatedFromMember.getPointer();
928  }
929
930  void setInstantiatedFromMemberTemplate(RedeclarableTemplateDecl *TD) {
931    InstantiatedFromMember.getPointer()", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 931, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!getCommonPtr()->InstantiatedFromMember.getPointer());
932    getCommonPtr()->InstantiatedFromMember.setPointer(TD);
933  }
934
935  using redecl_range = redeclarable_base::redecl_range;
936  using redecl_iterator = redeclarable_base::redecl_iterator;
937
938  using redeclarable_base::redecls_begin;
939  using redeclarable_base::redecls_end;
940  using redeclarable_base::redecls;
941  using redeclarable_base::getPreviousDecl;
942  using redeclarable_base::getMostRecentDecl;
943  using redeclarable_base::isFirstDecl;
944
945  // Implement isa/cast/dyncast/etc.
946  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
947
948  static bool classofKind(Kind K) {
949    return K >= firstRedeclarableTemplate && K <= lastRedeclarableTemplate;
950  }
951};
952
953template <> struct RedeclarableTemplateDecl::
954SpecEntryTraits<FunctionTemplateSpecializationInfo> {
955  using DeclType = FunctionDecl;
956
957  static DeclType *getDecl(FunctionTemplateSpecializationInfo *I) {
958    return I->Function;
959  }
960
961  static ArrayRef<TemplateArgument>
962  getTemplateArgs(FunctionTemplateSpecializationInfo *I) {
963    return I->TemplateArguments->asArray();
964  }
965};
966
967/// Declaration of a template function.
968class FunctionTemplateDecl : public RedeclarableTemplateDecl {
969protected:
970  friend class FunctionDecl;
971
972  /// Data that is common to all of the declarations of a given
973  /// function template.
974  struct Common : CommonBase {
975    /// The function template specializations for this function
976    /// template, including explicit specializations and instantiations.
977    llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> Specializations;
978
979    /// The set of "injected" template arguments used within this
980    /// function template.
981    ///
982    /// This pointer refers to the template arguments (there are as
983    /// many template arguments as template parameaters) for the function
984    /// template, and is allocated lazily, since most function templates do not
985    /// require the use of this information.
986    TemplateArgument *InjectedArgs = nullptr;
987
988    Common() = default;
989  };
990
991  FunctionTemplateDecl(ASTContext &CDeclContext *DCSourceLocation L,
992                       DeclarationName NameTemplateParameterList *Params,
993                       NamedDecl *Decl)
994      : RedeclarableTemplateDecl(FunctionTemplate, C, DC, L, Name, Params,
995                                 Decl) {}
996
997  CommonBase *newCommon(ASTContext &Cconst override;
998
999  Common *getCommonPtr() const {
1000    return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
1001  }
1002
1003  /// Retrieve the set of function template specializations of this
1004  /// function template.
1005  llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> &
1006  getSpecializations() const;
1007
1008  /// Add a specialization of this function template.
1009  ///
1010  /// \param InsertPos Insert position in the FoldingSetVector, must have been
1011  ///        retrieved by an earlier call to findSpecialization().
1012  void addSpecialization(FunctionTemplateSpecializationInfoInfo,
1013                         void *InsertPos);
1014
1015public:
1016  friend class ASTDeclReader;
1017  friend class ASTDeclWriter;
1018
1019  /// Load any lazily-loaded specializations from the external source.
1020  void LoadLazySpecializations() const;
1021
1022  /// Get the underlying function declaration of the template.
1023  FunctionDecl *getTemplatedDecl() const {
1024    return static_cast<FunctionDecl *>(TemplatedDecl);
1025  }
1026
1027  /// Returns whether this template declaration defines the primary
1028  /// pattern.
1029  bool isThisDeclarationADefinition() const {
1030    return getTemplatedDecl()->isThisDeclarationADefinition();
1031  }
1032
1033  /// Return the specialization with the provided arguments if it exists,
1034  /// otherwise return the insertion point.
1035  FunctionDecl *findSpecialization(ArrayRef<TemplateArgumentArgs,
1036                                   void *&InsertPos);
1037
1038  FunctionTemplateDecl *getCanonicalDecl() override {
1039    return cast<FunctionTemplateDecl>(
1040             RedeclarableTemplateDecl::getCanonicalDecl());
1041  }
1042  const FunctionTemplateDecl *getCanonicalDecl() const {
1043    return cast<FunctionTemplateDecl>(
1044             RedeclarableTemplateDecl::getCanonicalDecl());
1045  }
1046
1047  /// Retrieve the previous declaration of this function template, or
1048  /// nullptr if no such declaration exists.
1049  FunctionTemplateDecl *getPreviousDecl() {
1050    return cast_or_null<FunctionTemplateDecl>(
1051             static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
1052  }
1053  const FunctionTemplateDecl *getPreviousDecl() const {
1054    return cast_or_null<FunctionTemplateDecl>(
1055       static_cast<const RedeclarableTemplateDecl *>(this)->getPreviousDecl());
1056  }
1057
1058  FunctionTemplateDecl *getMostRecentDecl() {
1059    return cast<FunctionTemplateDecl>(
1060        static_cast<RedeclarableTemplateDecl *>(this)
1061            ->getMostRecentDecl());
1062  }
1063  const FunctionTemplateDecl *getMostRecentDecl() const {
1064    return const_cast<FunctionTemplateDecl*>(this)->getMostRecentDecl();
1065  }
1066
1067  FunctionTemplateDecl *getInstantiatedFromMemberTemplate() const {
1068    return cast_or_null<FunctionTemplateDecl>(
1069             RedeclarableTemplateDecl::getInstantiatedFromMemberTemplate());
1070  }
1071
1072  using spec_iterator = SpecIterator<FunctionTemplateSpecializationInfo>;
1073  using spec_range = llvm::iterator_range<spec_iterator>;
1074
1075  spec_range specializations() const {
1076    return spec_range(spec_begin(), spec_end());
1077  }
1078
1079  spec_iterator spec_begin() const {
1080    return makeSpecIterator(getSpecializations(), false);
1081  }
1082
1083  spec_iterator spec_end() const {
1084    return makeSpecIterator(getSpecializations(), true);
1085  }
1086
1087  /// Retrieve the "injected" template arguments that correspond to the
1088  /// template parameters of this function template.
1089  ///
1090  /// Although the C++ standard has no notion of the "injected" template
1091  /// arguments for a function template, the notion is convenient when
1092  /// we need to perform substitutions inside the definition of a function
1093  /// template.
1094  ArrayRef<TemplateArgumentgetInjectedTemplateArgs();
1095
1096  /// Merge \p Prev with our RedeclarableTemplateDecl::Common.
1097  void mergePrevDecl(FunctionTemplateDecl *Prev);
1098
1099  /// Create a function template node.
1100  static FunctionTemplateDecl *Create(ASTContext &CDeclContext *DC,
1101                                      SourceLocation L,
1102                                      DeclarationName Name,
1103                                      TemplateParameterList *Params,
1104                                      NamedDecl *Decl);
1105
1106  /// Create an empty function template node.
1107  static FunctionTemplateDecl *CreateDeserialized(ASTContext &Cunsigned ID);
1108
1109  // Implement isa/cast/dyncast support
1110  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1111  static bool classofKind(Kind K) { return K == FunctionTemplate; }
1112};
1113
1114//===----------------------------------------------------------------------===//
1115// Kinds of Template Parameters
1116//===----------------------------------------------------------------------===//
1117
1118/// Defines the position of a template parameter within a template
1119/// parameter list.
1120///
1121/// Because template parameter can be listed
1122/// sequentially for out-of-line template members, each template parameter is
1123/// given a Depth - the nesting of template parameter scopes - and a Position -
1124/// the occurrence within the parameter list.
1125/// This class is inheritedly privately by different kinds of template
1126/// parameters and is not part of the Decl hierarchy. Just a facility.
1127class TemplateParmPosition {
1128protected:
1129  // FIXME: These probably don't need to be ints. int:5 for depth, int:8 for
1130  // position? Maybe?
1131  unsigned Depth;
1132  unsigned Position;
1133
1134  TemplateParmPosition(unsigned Dunsigned P) : Depth(D), Position(P) {}
1135
1136public:
1137  TemplateParmPosition() = delete;
1138
1139  /// Get the nesting depth of the template parameter.
1140  unsigned getDepth() const { return Depth; }
1141  void setDepth(unsigned D) { Depth = D; }
1142
1143  /// Get the position of the template parameter within its parameter list.
1144  unsigned getPosition() const { return Position; }
1145  void setPosition(unsigned P) { Position = P; }
1146
1147  /// Get the index of the template parameter within its parameter list.
1148  unsigned getIndex() const { return Position; }
1149};
1150
1151/// Declaration of a template type parameter.
1152///
1153/// For example, "T" in
1154/// \code
1155/// template<typename T> class vector;
1156/// \endcode
1157class TemplateTypeParmDecl : public TypeDecl {
1158  /// Sema creates these on the stack during auto type deduction.
1159  friend class Sema;
1160
1161  /// Whether this template type parameter was declaration with
1162  /// the 'typename' keyword.
1163  ///
1164  /// If false, it was declared with the 'class' keyword.
1165  bool Typename : 1;
1166
1167  /// The default template argument, if any.
1168  using DefArgStorage =
1169      DefaultArgStorage<TemplateTypeParmDeclTypeSourceInfo *>;
1170  DefArgStorage DefaultArgument;
1171
1172  TemplateTypeParmDecl(DeclContext *DCSourceLocation KeyLoc,
1173                       SourceLocation IdLocIdentifierInfo *Id,
1174                       bool Typename)
1175      : TypeDecl(TemplateTypeParm, DC, IdLoc, Id, KeyLoc), Typename(Typename) {}
1176
1177public:
1178  static TemplateTypeParmDecl *Create(const ASTContext &CDeclContext *DC,
1179                                      SourceLocation KeyLoc,
1180                                      SourceLocation NameLoc,
1181                                      unsigned Dunsigned P,
1182                                      IdentifierInfo *Idbool Typename,
1183                                      bool ParameterPack);
1184  static TemplateTypeParmDecl *CreateDeserialized(const ASTContext &C,
1185                                                  unsigned ID);
1186
1187  /// Whether this template type parameter was declared with
1188  /// the 'typename' keyword.
1189  ///
1190  /// If not, it was declared with the 'class' keyword.
1191  bool wasDeclaredWithTypename() const { return Typename; }
1192
1193  const DefArgStorage &getDefaultArgStorage() const { return DefaultArgument; }
1194
1195  /// Determine whether this template parameter has a default
1196  /// argument.
1197  bool hasDefaultArgument() const { return DefaultArgument.isSet(); }
1198
1199  /// Retrieve the default argument, if any.
1200  QualType getDefaultArgument() const {
1201    return DefaultArgument.get()->getType();
1202  }
1203
1204  /// Retrieves the default argument's source information, if any.
1205  TypeSourceInfo *getDefaultArgumentInfo() const {
1206    return DefaultArgument.get();
1207  }
1208
1209  /// Retrieves the location of the default argument declaration.
1210  SourceLocation getDefaultArgumentLoc() const;
1211
1212  /// Determines whether the default argument was inherited
1213  /// from a previous declaration of this template.
1214  bool defaultArgumentWasInherited() const {
1215    return DefaultArgument.isInherited();
1216  }
1217
1218  /// Set the default argument for this template parameter.
1219  void setDefaultArgument(TypeSourceInfo *DefArg) {
1220    DefaultArgument.set(DefArg);
1221  }
1222
1223  /// Set that this default argument was inherited from another
1224  /// parameter.
1225  void setInheritedDefaultArgument(const ASTContext &C,
1226                                   TemplateTypeParmDecl *Prev) {
1227    DefaultArgument.setInherited(C, Prev);
1228  }
1229
1230  /// Removes the default argument of this template parameter.
1231  void removeDefaultArgument() {
1232    DefaultArgument.clear();
1233  }
1234
1235  /// Set whether this template type parameter was declared with
1236  /// the 'typename' or 'class' keyword.
1237  void setDeclaredWithTypename(bool withTypename) { Typename = withTypename; }
1238
1239  /// Retrieve the depth of the template parameter.
1240  unsigned getDepth() const;
1241
1242  /// Retrieve the index of the template parameter.
1243  unsigned getIndex() const;
1244
1245  /// Returns whether this is a parameter pack.
1246  bool isParameterPack() const;
1247
1248  SourceRange getSourceRange() const override LLVM_READONLY;
1249
1250  // Implement isa/cast/dyncast/etc.
1251  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1252  static bool classofKind(Kind K) { return K == TemplateTypeParm; }
1253};
1254
1255/// NonTypeTemplateParmDecl - Declares a non-type template parameter,
1256/// e.g., "Size" in
1257/// @code
1258/// template<int Size> class array { };
1259/// @endcode
1260class NonTypeTemplateParmDecl final
1261    : public DeclaratorDecl,
1262      protected TemplateParmPosition,
1263      private llvm::TrailingObjects<NonTypeTemplateParmDecl,
1264                                    std::pair<QualType, TypeSourceInfo *>> {
1265  friend class ASTDeclReader;
1266  friend TrailingObjects;
1267
1268  /// The default template argument, if any, and whether or not
1269  /// it was inherited.
1270  using DefArgStorage = DefaultArgStorage<NonTypeTemplateParmDeclExpr *>;
1271  DefArgStorage DefaultArgument;
1272
1273  // FIXME: Collapse this into TemplateParamPosition; or, just move depth/index
1274  // down here to save memory.
1275
1276  /// Whether this non-type template parameter is a parameter pack.
1277  bool ParameterPack;
1278
1279  /// Whether this non-type template parameter is an "expanded"
1280  /// parameter pack, meaning that its type is a pack expansion and we
1281  /// already know the set of types that expansion expands to.
1282  bool ExpandedParameterPack = false;
1283
1284  /// The number of types in an expanded parameter pack.
1285  unsigned NumExpandedTypes = 0;
1286
1287  size_t numTrailingObjects(
1288      OverloadToken<std::pair<QualType, TypeSourceInfo *>>) const {
1289    return NumExpandedTypes;
1290  }
1291
1292  NonTypeTemplateParmDecl(DeclContext *DCSourceLocation StartLoc,
1293                          SourceLocation IdLocunsigned Dunsigned P,
1294                          IdentifierInfo *IdQualType T,
1295                          bool ParameterPackTypeSourceInfo *TInfo)
1296      : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc),
1297        TemplateParmPosition(DP), ParameterPack(ParameterPack) {}
1298
1299  NonTypeTemplateParmDecl(DeclContext *DCSourceLocation StartLoc,
1300                          SourceLocation IdLocunsigned Dunsigned P,
1301                          IdentifierInfo *IdQualType T,
1302                          TypeSourceInfo *TInfo,
1303                          ArrayRef<QualTypeExpandedTypes,
1304                          ArrayRef<TypeSourceInfo *> ExpandedTInfos);
1305
1306public:
1307  static NonTypeTemplateParmDecl *
1308  Create(const ASTContext &CDeclContext *DCSourceLocation StartLoc,
1309         SourceLocation IdLocunsigned Dunsigned PIdentifierInfo *Id,
1310         QualType Tbool ParameterPackTypeSourceInfo *TInfo);
1311
1312  static NonTypeTemplateParmDecl *
1313  Create(const ASTContext &CDeclContext *DCSourceLocation StartLoc,
1314         SourceLocation IdLocunsigned Dunsigned PIdentifierInfo *Id,
1315         QualType TTypeSourceInfo *TInfoArrayRef<QualTypeExpandedTypes,
1316         ArrayRef<TypeSourceInfo *> ExpandedTInfos);
1317
1318  static NonTypeTemplateParmDecl *CreateDeserialized(ASTContext &C,
1319                                                     unsigned ID);
1320  static NonTypeTemplateParmDecl *CreateDeserialized(ASTContext &C,
1321                                                     unsigned ID,
1322                                                     unsigned NumExpandedTypes);
1323
1324  using TemplateParmPosition::getDepth;
1325  using TemplateParmPosition::setDepth;
1326  using TemplateParmPosition::getPosition;
1327  using TemplateParmPosition::setPosition;
1328  using TemplateParmPosition::getIndex;
1329
1330  SourceRange getSourceRange() const override LLVM_READONLY;
1331
1332  const DefArgStorage &getDefaultArgStorage() const { return DefaultArgument; }
1333
1334  /// Determine whether this template parameter has a default
1335  /// argument.
1336  bool hasDefaultArgument() const { return DefaultArgument.isSet(); }
1337
1338  /// Retrieve the default argument, if any.
1339  Expr *getDefaultArgument() const { return DefaultArgument.get(); }
1340
1341  /// Retrieve the location of the default argument, if any.
1342  SourceLocation getDefaultArgumentLoc() const;
1343
1344  /// Determines whether the default argument was inherited
1345  /// from a previous declaration of this template.
1346  bool defaultArgumentWasInherited() const {
1347    return DefaultArgument.isInherited();
1348  }
1349
1350  /// Set the default argument for this template parameter, and
1351  /// whether that default argument was inherited from another
1352  /// declaration.
1353  void setDefaultArgument(Expr *DefArg) { DefaultArgument.set(DefArg); }
1354  void setInheritedDefaultArgument(const ASTContext &C,
1355                                   NonTypeTemplateParmDecl *Parm) {
1356    DefaultArgument.setInherited(C, Parm);
1357  }
1358
1359  /// Removes the default argument of this template parameter.
1360  void removeDefaultArgument() { DefaultArgument.clear(); }
1361
1362  /// Whether this parameter is a non-type template parameter pack.
1363  ///
1364  /// If the parameter is a parameter pack, the type may be a
1365  /// \c PackExpansionType. In the following example, the \c Dims parameter
1366  /// is a parameter pack (whose type is 'unsigned').
1367  ///
1368  /// \code
1369  /// template<typename T, unsigned ...Dims> struct multi_array;
1370  /// \endcode
1371  bool isParameterPack() const { return ParameterPack; }
1372
1373  /// Whether this parameter pack is a pack expansion.
1374  ///
1375  /// A non-type template parameter pack is a pack expansion if its type
1376  /// contains an unexpanded parameter pack. In this case, we will have
1377  /// built a PackExpansionType wrapping the type.
1378  bool isPackExpansion() const {
1379    return ParameterPack && getType()->getAs<PackExpansionType>();
1380  }
1381
1382  /// Whether this parameter is a non-type template parameter pack
1383  /// that has a known list of different types at different positions.
1384  ///
1385  /// A parameter pack is an expanded parameter pack when the original
1386  /// parameter pack's type was itself a pack expansion, and that expansion
1387  /// has already been expanded. For example, given:
1388  ///
1389  /// \code
1390  /// template<typename ...Types>
1391  /// struct X {
1392  ///   template<Types ...Values>
1393  ///   struct Y { /* ... */ };
1394  /// };
1395  /// \endcode
1396  ///
1397  /// The parameter pack \c Values has a \c PackExpansionType as its type,
1398  /// which expands \c Types. When \c Types is supplied with template arguments
1399  /// by instantiating \c X, the instantiation of \c Values becomes an
1400  /// expanded parameter pack. For example, instantiating
1401  /// \c X<int, unsigned int> results in \c Values being an expanded parameter
1402  /// pack with expansion types \c int and \c unsigned int.
1403  ///
1404  /// The \c getExpansionType() and \c getExpansionTypeSourceInfo() functions
1405  /// return the expansion types.
1406  bool isExpandedParameterPack() const { return ExpandedParameterPack; }
1407
1408  /// Retrieves the number of expansion types in an expanded parameter
1409  /// pack.
1410  unsigned getNumExpansionTypes() const {
1411     (0) . __assert_fail ("ExpandedParameterPack && \"Not an expansion parameter pack\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 1411, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(ExpandedParameterPack && "Not an expansion parameter pack");
1412    return NumExpandedTypes;
1413  }
1414
1415  /// Retrieve a particular expansion type within an expanded parameter
1416  /// pack.
1417  QualType getExpansionType(unsigned Iconst {
1418     (0) . __assert_fail ("I < NumExpandedTypes && \"Out-of-range expansion type index\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 1418, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(I < NumExpandedTypes && "Out-of-range expansion type index");
1419    auto TypesAndInfos =
1420        getTrailingObjects<std::pair<QualTypeTypeSourceInfo *>>();
1421    return TypesAndInfos[I].first;
1422  }
1423
1424  /// Retrieve a particular expansion type source info within an
1425  /// expanded parameter pack.
1426  TypeSourceInfo *getExpansionTypeSourceInfo(unsigned Iconst {
1427     (0) . __assert_fail ("I < NumExpandedTypes && \"Out-of-range expansion type index\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 1427, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(I < NumExpandedTypes && "Out-of-range expansion type index");
1428    auto TypesAndInfos =
1429        getTrailingObjects<std::pair<QualTypeTypeSourceInfo *>>();
1430    return TypesAndInfos[I].second;
1431  }
1432
1433  // Implement isa/cast/dyncast/etc.
1434  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1435  static bool classofKind(Kind K) { return K == NonTypeTemplateParm; }
1436};
1437
1438/// TemplateTemplateParmDecl - Declares a template template parameter,
1439/// e.g., "T" in
1440/// @code
1441/// template <template <typename> class T> class container { };
1442/// @endcode
1443/// A template template parameter is a TemplateDecl because it defines the
1444/// name of a template and the template parameters allowable for substitution.
1445class TemplateTemplateParmDecl final
1446    : public TemplateDecl,
1447      protected TemplateParmPosition,
1448      private llvm::TrailingObjects<TemplateTemplateParmDecl,
1449                                    TemplateParameterList *> {
1450  /// The default template argument, if any.
1451  using DefArgStorage =
1452      DefaultArgStorage<TemplateTemplateParmDeclTemplateArgumentLoc *>;
1453  DefArgStorage DefaultArgument;
1454
1455  /// Whether this parameter is a parameter pack.
1456  bool ParameterPack;
1457
1458  /// Whether this template template parameter is an "expanded"
1459  /// parameter pack, meaning that it is a pack expansion and we
1460  /// already know the set of template parameters that expansion expands to.
1461  bool ExpandedParameterPack = false;
1462
1463  /// The number of parameters in an expanded parameter pack.
1464  unsigned NumExpandedParams = 0;
1465
1466  TemplateTemplateParmDecl(DeclContext *DCSourceLocation L,
1467                           unsigned Dunsigned Pbool ParameterPack,
1468                           IdentifierInfo *IdTemplateParameterList *Params)
1469      : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params),
1470        TemplateParmPosition(DP), ParameterPack(ParameterPack) {}
1471
1472  TemplateTemplateParmDecl(DeclContext *DCSourceLocation L,
1473                           unsigned Dunsigned P,
1474                           IdentifierInfo *IdTemplateParameterList *Params,
1475                           ArrayRef<TemplateParameterList *> Expansions);
1476
1477  void anchor() override;
1478
1479public:
1480  friend class ASTDeclReader;
1481  friend class ASTDeclWriter;
1482  friend TrailingObjects;
1483
1484  static TemplateTemplateParmDecl *Create(const ASTContext &CDeclContext *DC,
1485                                          SourceLocation Lunsigned D,
1486                                          unsigned Pbool ParameterPack,
1487                                          IdentifierInfo *Id,
1488                                          TemplateParameterList *Params);
1489  static TemplateTemplateParmDecl *Create(const ASTContext &CDeclContext *DC,
1490                                          SourceLocation Lunsigned D,
1491                                          unsigned P,
1492                                          IdentifierInfo *Id,
1493                                          TemplateParameterList *Params,
1494                                 ArrayRef<TemplateParameterList *> Expansions);
1495
1496  static TemplateTemplateParmDecl *CreateDeserialized(ASTContext &C,
1497                                                      unsigned ID);
1498  static TemplateTemplateParmDecl *CreateDeserialized(ASTContext &C,
1499                                                      unsigned ID,
1500                                                      unsigned NumExpansions);
1501
1502  using TemplateParmPosition::getDepth;
1503  using TemplateParmPosition::setDepth;
1504  using TemplateParmPosition::getPosition;
1505  using TemplateParmPosition::setPosition;
1506  using TemplateParmPosition::getIndex;
1507
1508  /// Whether this template template parameter is a template
1509  /// parameter pack.
1510  ///
1511  /// \code
1512  /// template<template <class T> ...MetaFunctions> struct Apply;
1513  /// \endcode
1514  bool isParameterPack() const { return ParameterPack; }
1515
1516  /// Whether this parameter pack is a pack expansion.
1517  ///
1518  /// A template template parameter pack is a pack expansion if its template
1519  /// parameter list contains an unexpanded parameter pack.
1520  bool isPackExpansion() const {
1521    return ParameterPack &&
1522           getTemplateParameters()->containsUnexpandedParameterPack();
1523  }
1524
1525  /// Whether this parameter is a template template parameter pack that
1526  /// has a known list of different template parameter lists at different
1527  /// positions.
1528  ///
1529  /// A parameter pack is an expanded parameter pack when the original parameter
1530  /// pack's template parameter list was itself a pack expansion, and that
1531  /// expansion has already been expanded. For exampe, given:
1532  ///
1533  /// \code
1534  /// template<typename...Types> struct Outer {
1535  ///   template<template<Types> class...Templates> struct Inner;
1536  /// };
1537  /// \endcode
1538  ///
1539  /// The parameter pack \c Templates is a pack expansion, which expands the
1540  /// pack \c Types. When \c Types is supplied with template arguments by
1541  /// instantiating \c Outer, the instantiation of \c Templates is an expanded
1542  /// parameter pack.
1543  bool isExpandedParameterPack() const { return ExpandedParameterPack; }
1544
1545  /// Retrieves the number of expansion template parameters in
1546  /// an expanded parameter pack.
1547  unsigned getNumExpansionTemplateParameters() const {
1548     (0) . __assert_fail ("ExpandedParameterPack && \"Not an expansion parameter pack\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 1548, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(ExpandedParameterPack && "Not an expansion parameter pack");
1549    return NumExpandedParams;
1550  }
1551
1552  /// Retrieve a particular expansion type within an expanded parameter
1553  /// pack.
1554  TemplateParameterList *getExpansionTemplateParameters(unsigned Iconst {
1555     (0) . __assert_fail ("I < NumExpandedParams && \"Out-of-range expansion type index\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 1555, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(I < NumExpandedParams && "Out-of-range expansion type index");
1556    return getTrailingObjects<TemplateParameterList *>()[I];
1557  }
1558
1559  const DefArgStorage &getDefaultArgStorage() const { return DefaultArgument; }
1560
1561  /// Determine whether this template parameter has a default
1562  /// argument.
1563  bool hasDefaultArgument() const { return DefaultArgument.isSet(); }
1564
1565  /// Retrieve the default argument, if any.
1566  const TemplateArgumentLoc &getDefaultArgument() const {
1567    static const TemplateArgumentLoc None;
1568    return DefaultArgument.isSet() ? *DefaultArgument.get() : None;
1569  }
1570
1571  /// Retrieve the location of the default argument, if any.
1572  SourceLocation getDefaultArgumentLoc() const;
1573
1574  /// Determines whether the default argument was inherited
1575  /// from a previous declaration of this template.
1576  bool defaultArgumentWasInherited() const {
1577    return DefaultArgument.isInherited();
1578  }
1579
1580  /// Set the default argument for this template parameter, and
1581  /// whether that default argument was inherited from another
1582  /// declaration.
1583  void setDefaultArgument(const ASTContext &C,
1584                          const TemplateArgumentLoc &DefArg);
1585  void setInheritedDefaultArgument(const ASTContext &C,
1586                                   TemplateTemplateParmDecl *Prev) {
1587    DefaultArgument.setInherited(C, Prev);
1588  }
1589
1590  /// Removes the default argument of this template parameter.
1591  void removeDefaultArgument() { DefaultArgument.clear(); }
1592
1593  SourceRange getSourceRange() const override LLVM_READONLY {
1594    SourceLocation End = getLocation();
1595    if (hasDefaultArgument() && !defaultArgumentWasInherited())
1596      End = getDefaultArgument().getSourceRange().getEnd();
1597    return SourceRange(getTemplateParameters()->getTemplateLoc(), End);
1598  }
1599
1600  // Implement isa/cast/dyncast/etc.
1601  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1602  static bool classofKind(Kind K) { return K == TemplateTemplateParm; }
1603};
1604
1605/// Represents the builtin template declaration which is used to
1606/// implement __make_integer_seq and other builtin templates.  It serves
1607/// no real purpose beyond existing as a place to hold template parameters.
1608class BuiltinTemplateDecl : public TemplateDecl {
1609  BuiltinTemplateKind BTK;
1610
1611  BuiltinTemplateDecl(const ASTContext &CDeclContext *DC,
1612                      DeclarationName NameBuiltinTemplateKind BTK);
1613
1614  void anchor() override;
1615
1616public:
1617  // Implement isa/cast/dyncast support
1618  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1619  static bool classofKind(Kind K) { return K == BuiltinTemplate; }
1620
1621  static BuiltinTemplateDecl *Create(const ASTContext &CDeclContext *DC,
1622                                     DeclarationName Name,
1623                                     BuiltinTemplateKind BTK) {
1624    return new (CDCBuiltinTemplateDecl(CDCNameBTK);
1625  }
1626
1627  SourceRange getSourceRange() const override LLVM_READONLY {
1628    return {};
1629  }
1630
1631  BuiltinTemplateKind getBuiltinTemplateKind() const { return BTK; }
1632};
1633
1634/// Represents a class template specialization, which refers to
1635/// a class template with a given set of template arguments.
1636///
1637/// Class template specializations represent both explicit
1638/// specialization of class templates, as in the example below, and
1639/// implicit instantiations of class templates.
1640///
1641/// \code
1642/// template<typename T> class array;
1643///
1644/// template<>
1645/// class array<bool> { }; // class template specialization array<bool>
1646/// \endcode
1647class ClassTemplateSpecializationDecl
1648  : public CXXRecordDeclpublic llvm::FoldingSetNode {
1649  /// Structure that stores information about a class template
1650  /// specialization that was instantiated from a class template partial
1651  /// specialization.
1652  struct SpecializedPartialSpecialization {
1653    /// The class template partial specialization from which this
1654    /// class template specialization was instantiated.
1655    ClassTemplatePartialSpecializationDecl *PartialSpecialization;
1656
1657    /// The template argument list deduced for the class template
1658    /// partial specialization itself.
1659    const TemplateArgumentList *TemplateArgs;
1660  };
1661
1662  /// The template that this specialization specializes
1663  llvm::PointerUnion<ClassTemplateDecl *, SpecializedPartialSpecialization *>
1664    SpecializedTemplate;
1665
1666  /// Further info for explicit template specialization/instantiation.
1667  struct ExplicitSpecializationInfo {
1668    /// The type-as-written.
1669    TypeSourceInfo *TypeAsWritten = nullptr;
1670
1671    /// The location of the extern keyword.
1672    SourceLocation ExternLoc;
1673
1674    /// The location of the template keyword.
1675    SourceLocation TemplateKeywordLoc;
1676
1677    ExplicitSpecializationInfo() = default;
1678  };
1679
1680  /// Further info for explicit template specialization/instantiation.
1681  /// Does not apply to implicit specializations.
1682  ExplicitSpecializationInfo *ExplicitInfo = nullptr;
1683
1684  /// The template arguments used to describe this specialization.
1685  const TemplateArgumentList *TemplateArgs;
1686
1687  /// The point where this template was instantiated (if any)
1688  SourceLocation PointOfInstantiation;
1689
1690  /// The kind of specialization this declaration refers to.
1691  /// Really a value of type TemplateSpecializationKind.
1692  unsigned SpecializationKind : 3;
1693
1694protected:
1695  ClassTemplateSpecializationDecl(ASTContext &ContextKind DKTagKind TK,
1696                                  DeclContext *DCSourceLocation StartLoc,
1697                                  SourceLocation IdLoc,
1698                                  ClassTemplateDecl *SpecializedTemplate,
1699                                  ArrayRef<TemplateArgumentArgs,
1700                                  ClassTemplateSpecializationDecl *PrevDecl);
1701
1702  explicit ClassTemplateSpecializationDecl(ASTContext &CKind DK);
1703
1704public:
1705  friend class ASTDeclReader;
1706  friend class ASTDeclWriter;
1707
1708  static ClassTemplateSpecializationDecl *
1709  Create(ASTContext &ContextTagKind TKDeclContext *DC,
1710         SourceLocation StartLocSourceLocation IdLoc,
1711         ClassTemplateDecl *SpecializedTemplate,
1712         ArrayRef<TemplateArgumentArgs,
1713         ClassTemplateSpecializationDecl *PrevDecl);
1714  static ClassTemplateSpecializationDecl *
1715  CreateDeserialized(ASTContext &Cunsigned ID);
1716
1717  void getNameForDiagnostic(raw_ostream &OSconst PrintingPolicy &Policy,
1718                            bool Qualifiedconst override;
1719
1720  // FIXME: This is broken. CXXRecordDecl::getMostRecentDecl() returns a
1721  // different "most recent" declaration from this function for the same
1722  // declaration, because we don't override getMostRecentDeclImpl(). But
1723  // it's not clear that we should override that, because the most recent
1724  // declaration as a CXXRecordDecl sometimes is the injected-class-name.
1725  ClassTemplateSpecializationDecl *getMostRecentDecl() {
1726    return cast<ClassTemplateSpecializationDecl>(
1727        getMostRecentNonInjectedDecl());
1728  }
1729
1730  /// Retrieve the template that this specialization specializes.
1731  ClassTemplateDecl *getSpecializedTemplate() const;
1732
1733  /// Retrieve the template arguments of the class template
1734  /// specialization.
1735  const TemplateArgumentList &getTemplateArgs() const {
1736    return *TemplateArgs;
1737  }
1738
1739  /// Determine the kind of specialization that this
1740  /// declaration represents.
1741  TemplateSpecializationKind getSpecializationKind() const {
1742    return static_cast<TemplateSpecializationKind>(SpecializationKind);
1743  }
1744
1745  bool isExplicitSpecialization() const {
1746    return getSpecializationKind() == TSK_ExplicitSpecialization;
1747  }
1748
1749  /// True if this declaration is an explicit specialization,
1750  /// explicit instantiation declaration, or explicit instantiation
1751  /// definition.
1752  bool isExplicitInstantiationOrSpecialization() const {
1753    return isTemplateExplicitInstantiationOrSpecialization(
1754        getTemplateSpecializationKind());
1755  }
1756
1757  void setSpecializationKind(TemplateSpecializationKind TSK) {
1758    SpecializationKind = TSK;
1759  }
1760
1761  /// Get the point of instantiation (if any), or null if none.
1762  SourceLocation getPointOfInstantiation() const {
1763    return PointOfInstantiation;
1764  }
1765
1766  void setPointOfInstantiation(SourceLocation Loc) {
1767     (0) . __assert_fail ("Loc.isValid() && \"point of instantiation must be valid!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 1767, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Loc.isValid() && "point of instantiation must be valid!");
1768    PointOfInstantiation = Loc;
1769  }
1770
1771  /// If this class template specialization is an instantiation of
1772  /// a template (rather than an explicit specialization), return the
1773  /// class template or class template partial specialization from which it
1774  /// was instantiated.
1775  llvm::PointerUnion<ClassTemplateDecl *,
1776                     ClassTemplatePartialSpecializationDecl *>
1777  getInstantiatedFrom() const {
1778    if (!isTemplateInstantiation(getSpecializationKind()))
1779      return llvm::PointerUnion<ClassTemplateDecl *,
1780                                ClassTemplatePartialSpecializationDecl *>();
1781
1782    return getSpecializedTemplateOrPartial();
1783  }
1784
1785  /// Retrieve the class template or class template partial
1786  /// specialization which was specialized by this.
1787  llvm::PointerUnion<ClassTemplateDecl *,
1788                     ClassTemplatePartialSpecializationDecl *>
1789  getSpecializedTemplateOrPartial() const {
1790    if (const auto *PartialSpec =
1791            SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
1792      return PartialSpec->PartialSpecialization;
1793
1794    return SpecializedTemplate.get<ClassTemplateDecl*>();
1795  }
1796
1797  /// Retrieve the set of template arguments that should be used
1798  /// to instantiate members of the class template or class template partial
1799  /// specialization from which this class template specialization was
1800  /// instantiated.
1801  ///
1802  /// \returns For a class template specialization instantiated from the primary
1803  /// template, this function will return the same template arguments as
1804  /// getTemplateArgs(). For a class template specialization instantiated from
1805  /// a class template partial specialization, this function will return the
1806  /// deduced template arguments for the class template partial specialization
1807  /// itself.
1808  const TemplateArgumentList &getTemplateInstantiationArgs() const {
1809    if (const auto *PartialSpec =
1810            SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
1811      return *PartialSpec->TemplateArgs;
1812
1813    return getTemplateArgs();
1814  }
1815
1816  /// Note that this class template specialization is actually an
1817  /// instantiation of the given class template partial specialization whose
1818  /// template arguments have been deduced.
1819  void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec,
1820                          const TemplateArgumentList *TemplateArgs) {
1821     (0) . __assert_fail ("!SpecializedTemplate.is() && \"Already set to a class template partial specialization!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 1822, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!SpecializedTemplate.is<SpecializedPartialSpecialization*>() &&
1822 (0) . __assert_fail ("!SpecializedTemplate.is() && \"Already set to a class template partial specialization!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 1822, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">           "Already set to a class template partial specialization!");
1823    auto *PS = new (getASTContext()) SpecializedPartialSpecialization();
1824    PS->PartialSpecialization = PartialSpec;
1825    PS->TemplateArgs = TemplateArgs;
1826    SpecializedTemplate = PS;
1827  }
1828
1829  /// Note that this class template specialization is an instantiation
1830  /// of the given class template.
1831  void setInstantiationOf(ClassTemplateDecl *TemplDecl) {
1832     (0) . __assert_fail ("!SpecializedTemplate.is() && \"Previously set to a class template partial specialization!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 1833, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!SpecializedTemplate.is<SpecializedPartialSpecialization*>() &&
1833 (0) . __assert_fail ("!SpecializedTemplate.is() && \"Previously set to a class template partial specialization!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 1833, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">           "Previously set to a class template partial specialization!");
1834    SpecializedTemplate = TemplDecl;
1835  }
1836
1837  /// Sets the type of this specialization as it was written by
1838  /// the user. This will be a class template specialization type.
1839  void setTypeAsWritten(TypeSourceInfo *T) {
1840    if (!ExplicitInfo)
1841      ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo;
1842    ExplicitInfo->TypeAsWritten = T;
1843  }
1844
1845  /// Gets the type of this specialization as it was written by
1846  /// the user, if it was so written.
1847  TypeSourceInfo *getTypeAsWritten() const {
1848    return ExplicitInfo ? ExplicitInfo->TypeAsWritten : nullptr;
1849  }
1850
1851  /// Gets the location of the extern keyword, if present.
1852  SourceLocation getExternLoc() const {
1853    return ExplicitInfo ? ExplicitInfo->ExternLoc : SourceLocation();
1854  }
1855
1856  /// Sets the location of the extern keyword.
1857  void setExternLoc(SourceLocation Loc) {
1858    if (!ExplicitInfo)
1859      ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo;
1860    ExplicitInfo->ExternLoc = Loc;
1861  }
1862
1863  /// Sets the location of the template keyword.
1864  void setTemplateKeywordLoc(SourceLocation Loc) {
1865    if (!ExplicitInfo)
1866      ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo;
1867    ExplicitInfo->TemplateKeywordLoc = Loc;
1868  }
1869
1870  /// Gets the location of the template keyword, if present.
1871  SourceLocation getTemplateKeywordLoc() const {
1872    return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation();
1873  }
1874
1875  SourceRange getSourceRange() const override LLVM_READONLY;
1876
1877  void Profile(llvm::FoldingSetNodeID &IDconst {
1878    Profile(IDTemplateArgs->asArray(), getASTContext());
1879  }
1880
1881  static void
1882  Profile(llvm::FoldingSetNodeID &IDArrayRef<TemplateArgumentTemplateArgs,
1883          ASTContext &Context) {
1884    ID.AddInteger(TemplateArgs.size());
1885    for (const TemplateArgument &TemplateArg : TemplateArgs)
1886      TemplateArg.Profile(ID, Context);
1887  }
1888
1889  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1890
1891  static bool classofKind(Kind K) {
1892    return K >= firstClassTemplateSpecialization &&
1893           K <= lastClassTemplateSpecialization;
1894  }
1895};
1896
1897class ClassTemplatePartialSpecializationDecl
1898  : public ClassTemplateSpecializationDecl {
1899  /// The list of template parameters
1900  TemplateParameterListTemplateParams = nullptr;
1901
1902  /// The source info for the template arguments as written.
1903  /// FIXME: redundant with TypeAsWritten?
1904  const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr;
1905
1906  /// The class template partial specialization from which this
1907  /// class template partial specialization was instantiated.
1908  ///
1909  /// The boolean value will be true to indicate that this class template
1910  /// partial specialization was specialized at this level.
1911  llvm::PointerIntPair<ClassTemplatePartialSpecializationDecl *, 1bool>
1912      InstantiatedFromMember;
1913
1914  ClassTemplatePartialSpecializationDecl(ASTContext &ContextTagKind TK,
1915                                         DeclContext *DC,
1916                                         SourceLocation StartLoc,
1917                                         SourceLocation IdLoc,
1918                                         TemplateParameterList *Params,
1919                                         ClassTemplateDecl *SpecializedTemplate,
1920                                         ArrayRef<TemplateArgumentArgs,
1921                               const ASTTemplateArgumentListInfo *ArgsAsWritten,
1922                               ClassTemplatePartialSpecializationDecl *PrevDecl);
1923
1924  ClassTemplatePartialSpecializationDecl(ASTContext &C)
1925    : ClassTemplateSpecializationDecl(C, ClassTemplatePartialSpecialization),
1926      InstantiatedFromMember(nullptrfalse) {}
1927
1928  void anchor() override;
1929
1930public:
1931  friend class ASTDeclReader;
1932  friend class ASTDeclWriter;
1933
1934  static ClassTemplatePartialSpecializationDecl *
1935  Create(ASTContext &ContextTagKind TKDeclContext *DC,
1936         SourceLocation StartLocSourceLocation IdLoc,
1937         TemplateParameterList *Params,
1938         ClassTemplateDecl *SpecializedTemplate,
1939         ArrayRef<TemplateArgumentArgs,
1940         const TemplateArgumentListInfo &ArgInfos,
1941         QualType CanonInjectedType,
1942         ClassTemplatePartialSpecializationDecl *PrevDecl);
1943
1944  static ClassTemplatePartialSpecializationDecl *
1945  CreateDeserialized(ASTContext &Cunsigned ID);
1946
1947  ClassTemplatePartialSpecializationDecl *getMostRecentDecl() {
1948    return cast<ClassTemplatePartialSpecializationDecl>(
1949             static_cast<ClassTemplateSpecializationDecl *>(
1950               this)->getMostRecentDecl());
1951  }
1952
1953  /// Get the list of template parameters
1954  TemplateParameterList *getTemplateParameters() const {
1955    return TemplateParams;
1956  }
1957
1958  /// Get the template arguments as written.
1959  const ASTTemplateArgumentListInfo *getTemplateArgsAsWritten() const {
1960    return ArgsAsWritten;
1961  }
1962
1963  /// Retrieve the member class template partial specialization from
1964  /// which this particular class template partial specialization was
1965  /// instantiated.
1966  ///
1967  /// \code
1968  /// template<typename T>
1969  /// struct Outer {
1970  ///   template<typename U> struct Inner;
1971  ///   template<typename U> struct Inner<U*> { }; // #1
1972  /// };
1973  ///
1974  /// Outer<float>::Inner<int*> ii;
1975  /// \endcode
1976  ///
1977  /// In this example, the instantiation of \c Outer<float>::Inner<int*> will
1978  /// end up instantiating the partial specialization
1979  /// \c Outer<float>::Inner<U*>, which itself was instantiated from the class
1980  /// template partial specialization \c Outer<T>::Inner<U*>. Given
1981  /// \c Outer<float>::Inner<U*>, this function would return
1982  /// \c Outer<T>::Inner<U*>.
1983  ClassTemplatePartialSpecializationDecl *getInstantiatedFromMember() const {
1984    const auto *First =
1985        cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
1986    return First->InstantiatedFromMember.getPointer();
1987  }
1988  ClassTemplatePartialSpecializationDecl *
1989  getInstantiatedFromMemberTemplate() const {
1990    return getInstantiatedFromMember();
1991  }
1992
1993  void setInstantiatedFromMember(
1994                          ClassTemplatePartialSpecializationDecl *PartialSpec) {
1995    auto *First = cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
1996    First->InstantiatedFromMember.setPointer(PartialSpec);
1997  }
1998
1999  /// Determines whether this class template partial specialization
2000  /// template was a specialization of a member partial specialization.
2001  ///
2002  /// In the following example, the member template partial specialization
2003  /// \c X<int>::Inner<T*> is a member specialization.
2004  ///
2005  /// \code
2006  /// template<typename T>
2007  /// struct X {
2008  ///   template<typename U> struct Inner;
2009  ///   template<typename U> struct Inner<U*>;
2010  /// };
2011  ///
2012  /// template<> template<typename T>
2013  /// struct X<int>::Inner<T*> { /* ... */ };
2014  /// \endcode
2015  bool isMemberSpecialization() {
2016    const auto *First =
2017        cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2018    return First->InstantiatedFromMember.getInt();
2019  }
2020
2021  /// Note that this member template is a specialization.
2022  void setMemberSpecialization() {
2023    auto *First = cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2024     (0) . __assert_fail ("First->InstantiatedFromMember.getPointer() && \"Only member templates can be member template specializations\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 2025, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(First->InstantiatedFromMember.getPointer() &&
2025 (0) . __assert_fail ("First->InstantiatedFromMember.getPointer() && \"Only member templates can be member template specializations\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 2025, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">           "Only member templates can be member template specializations");
2026    return First->InstantiatedFromMember.setInt(true);
2027  }
2028
2029  /// Retrieves the injected specialization type for this partial
2030  /// specialization.  This is not the same as the type-decl-type for
2031  /// this partial specialization, which is an InjectedClassNameType.
2032  QualType getInjectedSpecializationType() const {
2033     (0) . __assert_fail ("getTypeForDecl() && \"partial specialization has no type set!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 2033, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getTypeForDecl() && "partial specialization has no type set!");
2034    return cast<InjectedClassNameType>(getTypeForDecl())
2035             ->getInjectedSpecializationType();
2036  }
2037
2038  // FIXME: Add Profile support!
2039
2040  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2041
2042  static bool classofKind(Kind K) {
2043    return K == ClassTemplatePartialSpecialization;
2044  }
2045};
2046
2047/// Declaration of a class template.
2048class ClassTemplateDecl : public RedeclarableTemplateDecl {
2049protected:
2050  /// Data that is common to all of the declarations of a given
2051  /// class template.
2052  struct Common : CommonBase {
2053    /// The class template specializations for this class
2054    /// template, including explicit specializations and instantiations.
2055    llvm::FoldingSetVector<ClassTemplateSpecializationDecl> Specializations;
2056
2057    /// The class template partial specializations for this class
2058    /// template.
2059    llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>
2060      PartialSpecializations;
2061
2062    /// The injected-class-name type for this class template.
2063    QualType InjectedClassNameType;
2064
2065    Common() = default;
2066  };
2067
2068  /// Retrieve the set of specializations of this class template.
2069  llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
2070  getSpecializations() const;
2071
2072  /// Retrieve the set of partial specializations of this class
2073  /// template.
2074  llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
2075  getPartialSpecializations();
2076
2077  ClassTemplateDecl(ConstrainedTemplateDeclInfo *CTDIASTContext &C,
2078                    DeclContext *DCSourceLocation LDeclarationName Name,
2079                    TemplateParameterList *ParamsNamedDecl *Decl)
2080      : RedeclarableTemplateDecl(CTDI, ClassTemplate, C, DC, L, Name, Params,
2081                                 Decl) {}
2082
2083  ClassTemplateDecl(ASTContext &CDeclContext *DCSourceLocation L,
2084                    DeclarationName NameTemplateParameterList *Params,
2085                    NamedDecl *Decl)
2086      : ClassTemplateDecl(nullptrCDCLNameParamsDecl) {}
2087
2088  CommonBase *newCommon(ASTContext &Cconst override;
2089
2090  Common *getCommonPtr() const {
2091    return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
2092  }
2093
2094public:
2095  friend class ASTDeclReader;
2096  friend class ASTDeclWriter;
2097
2098  /// Load any lazily-loaded specializations from the external source.
2099  void LoadLazySpecializations() const;
2100
2101  /// Get the underlying class declarations of the template.
2102  CXXRecordDecl *getTemplatedDecl() const {
2103    return static_cast<CXXRecordDecl *>(TemplatedDecl);
2104  }
2105
2106  /// Returns whether this template declaration defines the primary
2107  /// class pattern.
2108  bool isThisDeclarationADefinition() const {
2109    return getTemplatedDecl()->isThisDeclarationADefinition();
2110  }
2111
2112  // FIXME: remove default argument for AssociatedConstraints
2113  /// Create a class template node.
2114  static ClassTemplateDecl *Create(ASTContext &CDeclContext *DC,
2115                                   SourceLocation L,
2116                                   DeclarationName Name,
2117                                   TemplateParameterList *Params,
2118                                   NamedDecl *Decl,
2119                                   Expr *AssociatedConstraints = nullptr);
2120
2121  /// Create an empty class template node.
2122  static ClassTemplateDecl *CreateDeserialized(ASTContext &Cunsigned ID);
2123
2124  /// Return the specialization with the provided arguments if it exists,
2125  /// otherwise return the insertion point.
2126  ClassTemplateSpecializationDecl *
2127  findSpecialization(ArrayRef<TemplateArgumentArgsvoid *&InsertPos);
2128
2129  /// Insert the specified specialization knowing that it is not already
2130  /// in. InsertPos must be obtained from findSpecialization.
2131  void AddSpecialization(ClassTemplateSpecializationDecl *Dvoid *InsertPos);
2132
2133  ClassTemplateDecl *getCanonicalDecl() override {
2134    return cast<ClassTemplateDecl>(
2135             RedeclarableTemplateDecl::getCanonicalDecl());
2136  }
2137  const ClassTemplateDecl *getCanonicalDecl() const {
2138    return cast<ClassTemplateDecl>(
2139             RedeclarableTemplateDecl::getCanonicalDecl());
2140  }
2141
2142  /// Retrieve the previous declaration of this class template, or
2143  /// nullptr if no such declaration exists.
2144  ClassTemplateDecl *getPreviousDecl() {
2145    return cast_or_null<ClassTemplateDecl>(
2146             static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
2147  }
2148  const ClassTemplateDecl *getPreviousDecl() const {
2149    return cast_or_null<ClassTemplateDecl>(
2150             static_cast<const RedeclarableTemplateDecl *>(
2151               this)->getPreviousDecl());
2152  }
2153
2154  ClassTemplateDecl *getMostRecentDecl() {
2155    return cast<ClassTemplateDecl>(
2156        static_cast<RedeclarableTemplateDecl *>(this)->getMostRecentDecl());
2157  }
2158  const ClassTemplateDecl *getMostRecentDecl() const {
2159    return const_cast<ClassTemplateDecl*>(this)->getMostRecentDecl();
2160  }
2161
2162  ClassTemplateDecl *getInstantiatedFromMemberTemplate() const {
2163    return cast_or_null<ClassTemplateDecl>(
2164             RedeclarableTemplateDecl::getInstantiatedFromMemberTemplate());
2165  }
2166
2167  /// Return the partial specialization with the provided arguments if it
2168  /// exists, otherwise return the insertion point.
2169  ClassTemplatePartialSpecializationDecl *
2170  findPartialSpecialization(ArrayRef<TemplateArgumentArgsvoid *&InsertPos);
2171
2172  /// Insert the specified partial specialization knowing that it is not
2173  /// already in. InsertPos must be obtained from findPartialSpecialization.
2174  void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D,
2175                                void *InsertPos);
2176
2177  /// Retrieve the partial specializations as an ordered list.
2178  void getPartialSpecializations(
2179          SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS);
2180
2181  /// Find a class template partial specialization with the given
2182  /// type T.
2183  ///
2184  /// \param T a dependent type that names a specialization of this class
2185  /// template.
2186  ///
2187  /// \returns the class template partial specialization that exactly matches
2188  /// the type \p T, or nullptr if no such partial specialization exists.
2189  ClassTemplatePartialSpecializationDecl *findPartialSpecialization(QualType T);
2190
2191  /// Find a class template partial specialization which was instantiated
2192  /// from the given member partial specialization.
2193  ///
2194  /// \param D a member class template partial specialization.
2195  ///
2196  /// \returns the class template partial specialization which was instantiated
2197  /// from the given member partial specialization, or nullptr if no such
2198  /// partial specialization exists.
2199  ClassTemplatePartialSpecializationDecl *
2200  findPartialSpecInstantiatedFromMember(
2201                                     ClassTemplatePartialSpecializationDecl *D);
2202
2203  /// Retrieve the template specialization type of the
2204  /// injected-class-name for this class template.
2205  ///
2206  /// The injected-class-name for a class template \c X is \c
2207  /// X<template-args>, where \c template-args is formed from the
2208  /// template arguments that correspond to the template parameters of
2209  /// \c X. For example:
2210  ///
2211  /// \code
2212  /// template<typename T, int N>
2213  /// struct array {
2214  ///   typedef array this_type; // "array" is equivalent to "array<T, N>"
2215  /// };
2216  /// \endcode
2217  QualType getInjectedClassNameSpecialization();
2218
2219  using spec_iterator = SpecIterator<ClassTemplateSpecializationDecl>;
2220  using spec_range = llvm::iterator_range<spec_iterator>;
2221
2222  spec_range specializations() const {
2223    return spec_range(spec_begin(), spec_end());
2224  }
2225
2226  spec_iterator spec_begin() const {
2227    return makeSpecIterator(getSpecializations(), false);
2228  }
2229
2230  spec_iterator spec_end() const {
2231    return makeSpecIterator(getSpecializations(), true);
2232  }
2233
2234  // Implement isa/cast/dyncast support
2235  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2236  static bool classofKind(Kind K) { return K == ClassTemplate; }
2237};
2238
2239/// Declaration of a friend template.
2240///
2241/// For example:
2242/// \code
2243/// template \<typename T> class A {
2244///   friend class MyVector<T>; // not a friend template
2245///   template \<typename U> friend class B; // not a friend template
2246///   template \<typename U> friend class Foo<T>::Nested; // friend template
2247/// };
2248/// \endcode
2249///
2250/// \note This class is not currently in use.  All of the above
2251/// will yield a FriendDecl, not a FriendTemplateDecl.
2252class FriendTemplateDecl : public Decl {
2253  virtual void anchor();
2254
2255public:
2256  using FriendUnion = llvm::PointerUnion<NamedDecl *,TypeSourceInfo *>;
2257
2258private:
2259  // The number of template parameters;  always non-zero.
2260  unsigned NumParams = 0;
2261
2262  // The parameter list.
2263  TemplateParameterList **Params = nullptr;
2264
2265  // The declaration that's a friend of this class.
2266  FriendUnion Friend;
2267
2268  // Location of the 'friend' specifier.
2269  SourceLocation FriendLoc;
2270
2271  FriendTemplateDecl(DeclContext *DCSourceLocation Loc,
2272                     MutableArrayRef<TemplateParameterList *> Params,
2273                     FriendUnion FriendSourceLocation FriendLoc)
2274      : Decl(Decl::FriendTemplate, DC, Loc), NumParams(Params.size()),
2275        Params(Params.data()), Friend(Friend), FriendLoc(FriendLoc) {}
2276
2277  FriendTemplateDecl(EmptyShell Empty) : Decl(Decl::FriendTemplate, Empty) {}
2278
2279public:
2280  friend class ASTDeclReader;
2281
2282  static FriendTemplateDecl *
2283  Create(ASTContext &ContextDeclContext *DCSourceLocation Loc,
2284         MutableArrayRef<TemplateParameterList *> Params, FriendUnion Friend,
2285         SourceLocation FriendLoc);
2286
2287  static FriendTemplateDecl *CreateDeserialized(ASTContext &Cunsigned ID);
2288
2289  /// If this friend declaration names a templated type (or
2290  /// a dependent member type of a templated type), return that
2291  /// type;  otherwise return null.
2292  TypeSourceInfo *getFriendType() const {
2293    return Friend.dyn_cast<TypeSourceInfo*>();
2294  }
2295
2296  /// If this friend declaration names a templated function (or
2297  /// a member function of a templated type), return that type;
2298  /// otherwise return null.
2299  NamedDecl *getFriendDecl() const {
2300    return Friend.dyn_cast<NamedDecl*>();
2301  }
2302
2303  /// Retrieves the location of the 'friend' keyword.
2304  SourceLocation getFriendLoc() const {
2305    return FriendLoc;
2306  }
2307
2308  TemplateParameterList *getTemplateParameterList(unsigned iconst {
2309    assert(i <= NumParams);
2310    return Params[i];
2311  }
2312
2313  unsigned getNumTemplateParameters() const {
2314    return NumParams;
2315  }
2316
2317  // Implement isa/cast/dyncast/etc.
2318  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2319  static bool classofKind(Kind K) { return K == Decl::FriendTemplate; }
2320};
2321
2322/// Declaration of an alias template.
2323///
2324/// For example:
2325/// \code
2326/// template \<typename T> using V = std::map<T*, int, MyCompare<T>>;
2327/// \endcode
2328class TypeAliasTemplateDecl : public RedeclarableTemplateDecl {
2329protected:
2330  using Common = CommonBase;
2331
2332  TypeAliasTemplateDecl(ASTContext &CDeclContext *DCSourceLocation L,
2333                        DeclarationName NameTemplateParameterList *Params,
2334                        NamedDecl *Decl)
2335      : RedeclarableTemplateDecl(TypeAliasTemplate, C, DC, L, Name, Params,
2336                                 Decl) {}
2337
2338  CommonBase *newCommon(ASTContext &Cconst override;
2339
2340  Common *getCommonPtr() {
2341    return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
2342  }
2343
2344public:
2345  friend class ASTDeclReader;
2346  friend class ASTDeclWriter;
2347
2348  /// Get the underlying function declaration of the template.
2349  TypeAliasDecl *getTemplatedDecl() const {
2350    return static_cast<TypeAliasDecl *>(TemplatedDecl);
2351  }
2352
2353
2354  TypeAliasTemplateDecl *getCanonicalDecl() override {
2355    return cast<TypeAliasTemplateDecl>(
2356             RedeclarableTemplateDecl::getCanonicalDecl());
2357  }
2358  const TypeAliasTemplateDecl *getCanonicalDecl() const {
2359    return cast<TypeAliasTemplateDecl>(
2360             RedeclarableTemplateDecl::getCanonicalDecl());
2361  }
2362
2363  /// Retrieve the previous declaration of this function template, or
2364  /// nullptr if no such declaration exists.
2365  TypeAliasTemplateDecl *getPreviousDecl() {
2366    return cast_or_null<TypeAliasTemplateDecl>(
2367             static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
2368  }
2369  const TypeAliasTemplateDecl *getPreviousDecl() const {
2370    return cast_or_null<TypeAliasTemplateDecl>(
2371             static_cast<const RedeclarableTemplateDecl *>(
2372               this)->getPreviousDecl());
2373  }
2374
2375  TypeAliasTemplateDecl *getInstantiatedFromMemberTemplate() const {
2376    return cast_or_null<TypeAliasTemplateDecl>(
2377             RedeclarableTemplateDecl::getInstantiatedFromMemberTemplate());
2378  }
2379
2380  /// Create a function template node.
2381  static TypeAliasTemplateDecl *Create(ASTContext &CDeclContext *DC,
2382                                       SourceLocation L,
2383                                       DeclarationName Name,
2384                                       TemplateParameterList *Params,
2385                                       NamedDecl *Decl);
2386
2387  /// Create an empty alias template node.
2388  static TypeAliasTemplateDecl *CreateDeserialized(ASTContext &Cunsigned ID);
2389
2390  // Implement isa/cast/dyncast support
2391  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2392  static bool classofKind(Kind K) { return K == TypeAliasTemplate; }
2393};
2394
2395/// Declaration of a function specialization at template class scope.
2396///
2397/// This is a non-standard extension needed to support MSVC.
2398///
2399/// For example:
2400/// \code
2401/// template <class T>
2402/// class A {
2403///    template <class U> void foo(U a) { }
2404///    template<> void foo(int a) { }
2405/// }
2406/// \endcode
2407///
2408/// "template<> foo(int a)" will be saved in Specialization as a normal
2409/// CXXMethodDecl. Then during an instantiation of class A, it will be
2410/// transformed into an actual function specialization.
2411class ClassScopeFunctionSpecializationDecl : public Decl {
2412  CXXMethodDecl *Specialization;
2413  bool HasExplicitTemplateArgs;
2414  TemplateArgumentListInfo TemplateArgs;
2415
2416  ClassScopeFunctionSpecializationDecl(DeclContext *DCSourceLocation Loc,
2417                                       CXXMethodDecl *FDbool Args,
2418                                       TemplateArgumentListInfo TemplArgs)
2419      : Decl(Decl::ClassScopeFunctionSpecialization, DC, Loc),
2420        Specialization(FD), HasExplicitTemplateArgs(Args),
2421        TemplateArgs(std::move(TemplArgs)) {}
2422
2423  ClassScopeFunctionSpecializationDecl(EmptyShell Empty)
2424      : Decl(Decl::ClassScopeFunctionSpecialization, Empty) {}
2425
2426  virtual void anchor();
2427
2428public:
2429  friend class ASTDeclReader;
2430  friend class ASTDeclWriter;
2431
2432  CXXMethodDecl *getSpecialization() const { return Specialization; }
2433  bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
2434  const TemplateArgumentListInfotemplateArgs() const { return TemplateArgs; }
2435
2436  static ClassScopeFunctionSpecializationDecl *Create(ASTContext &C,
2437                                                      DeclContext *DC,
2438                                                      SourceLocation Loc,
2439                                                      CXXMethodDecl *FD,
2440                                                   bool HasExplicitTemplateArgs,
2441                                        TemplateArgumentListInfo TemplateArgs) {
2442    return new (CDCClassScopeFunctionSpecializationDecl(
2443        DCLocFDHasExplicitTemplateArgsstd::move(TemplateArgs));
2444  }
2445
2446  static ClassScopeFunctionSpecializationDecl *
2447  CreateDeserialized(ASTContext &Contextunsigned ID);
2448
2449  // Implement isa/cast/dyncast/etc.
2450  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2451
2452  static bool classofKind(Kind K) {
2453    return K == Decl::ClassScopeFunctionSpecialization;
2454  }
2455};
2456
2457/// Implementation of inline functions that require the template declarations
2458inline AnyFunctionDecl::AnyFunctionDecl(FunctionTemplateDecl *FTD)
2459    : Function(FTD) {}
2460
2461/// Represents a variable template specialization, which refers to
2462/// a variable template with a given set of template arguments.
2463///
2464/// Variable template specializations represent both explicit
2465/// specializations of variable templates, as in the example below, and
2466/// implicit instantiations of variable templates.
2467///
2468/// \code
2469/// template<typename T> constexpr T pi = T(3.1415926535897932385);
2470///
2471/// template<>
2472/// constexpr float pi<float>; // variable template specialization pi<float>
2473/// \endcode
2474class VarTemplateSpecializationDecl : public VarDecl,
2475                                      public llvm::FoldingSetNode {
2476
2477  /// Structure that stores information about a variable template
2478  /// specialization that was instantiated from a variable template partial
2479  /// specialization.
2480  struct SpecializedPartialSpecialization {
2481    /// The variable template partial specialization from which this
2482    /// variable template specialization was instantiated.
2483    VarTemplatePartialSpecializationDecl *PartialSpecialization;
2484
2485    /// The template argument list deduced for the variable template
2486    /// partial specialization itself.
2487    const TemplateArgumentList *TemplateArgs;
2488  };
2489
2490  /// The template that this specialization specializes.
2491  llvm::PointerUnion<VarTemplateDecl *, SpecializedPartialSpecialization *>
2492  SpecializedTemplate;
2493
2494  /// Further info for explicit template specialization/instantiation.
2495  struct ExplicitSpecializationInfo {
2496    /// The type-as-written.
2497    TypeSourceInfo *TypeAsWritten = nullptr;
2498
2499    /// The location of the extern keyword.
2500    SourceLocation ExternLoc;
2501
2502    /// The location of the template keyword.
2503    SourceLocation TemplateKeywordLoc;
2504
2505    ExplicitSpecializationInfo() = default;
2506  };
2507
2508  /// Further info for explicit template specialization/instantiation.
2509  /// Does not apply to implicit specializations.
2510  ExplicitSpecializationInfo *ExplicitInfo = nullptr;
2511
2512  /// The template arguments used to describe this specialization.
2513  const TemplateArgumentList *TemplateArgs;
2514  TemplateArgumentListInfo TemplateArgsInfo;
2515
2516  /// The point where this template was instantiated (if any).
2517  SourceLocation PointOfInstantiation;
2518
2519  /// The kind of specialization this declaration refers to.
2520  /// Really a value of type TemplateSpecializationKind.
2521  unsigned SpecializationKind : 3;
2522
2523  /// Whether this declaration is a complete definition of the
2524  /// variable template specialization. We can't otherwise tell apart
2525  /// an instantiated declaration from an instantiated definition with
2526  /// no initializer.
2527  unsigned IsCompleteDefinition : 1;
2528
2529protected:
2530  VarTemplateSpecializationDecl(Kind DKASTContext &ContextDeclContext *DC,
2531                                SourceLocation StartLocSourceLocation IdLoc,
2532                                VarTemplateDecl *SpecializedTemplate,
2533                                QualType TTypeSourceInfo *TInfo,
2534                                StorageClass S,
2535                                ArrayRef<TemplateArgumentArgs);
2536
2537  explicit VarTemplateSpecializationDecl(Kind DKASTContext &Context);
2538
2539public:
2540  friend class ASTDeclReader;
2541  friend class ASTDeclWriter;
2542  friend class VarDecl;
2543
2544  static VarTemplateSpecializationDecl *
2545  Create(ASTContext &ContextDeclContext *DCSourceLocation StartLoc,
2546         SourceLocation IdLocVarTemplateDecl *SpecializedTemplateQualType T,
2547         TypeSourceInfo *TInfoStorageClass S,
2548         ArrayRef<TemplateArgumentArgs);
2549  static VarTemplateSpecializationDecl *CreateDeserialized(ASTContext &C,
2550                                                           unsigned ID);
2551
2552  void getNameForDiagnostic(raw_ostream &OSconst PrintingPolicy &Policy,
2553                            bool Qualifiedconst override;
2554
2555  VarTemplateSpecializationDecl *getMostRecentDecl() {
2556    VarDecl *Recent = static_cast<VarDecl *>(this)->getMostRecentDecl();
2557    return cast<VarTemplateSpecializationDecl>(Recent);
2558  }
2559
2560  /// Retrieve the template that this specialization specializes.
2561  VarTemplateDecl *getSpecializedTemplate() const;
2562
2563  /// Retrieve the template arguments of the variable template
2564  /// specialization.
2565  const TemplateArgumentList &getTemplateArgs() const { return *TemplateArgs; }
2566
2567  // TODO: Always set this when creating the new specialization?
2568  void setTemplateArgsInfo(const TemplateArgumentListInfo &ArgsInfo);
2569
2570  const TemplateArgumentListInfo &getTemplateArgsInfo() const {
2571    return TemplateArgsInfo;
2572  }
2573
2574  /// Determine the kind of specialization that this
2575  /// declaration represents.
2576  TemplateSpecializationKind getSpecializationKind() const {
2577    return static_cast<TemplateSpecializationKind>(SpecializationKind);
2578  }
2579
2580  bool isExplicitSpecialization() const {
2581    return getSpecializationKind() == TSK_ExplicitSpecialization;
2582  }
2583
2584  /// True if this declaration is an explicit specialization,
2585  /// explicit instantiation declaration, or explicit instantiation
2586  /// definition.
2587  bool isExplicitInstantiationOrSpecialization() const {
2588    return isTemplateExplicitInstantiationOrSpecialization(
2589        getTemplateSpecializationKind());
2590  }
2591
2592  void setSpecializationKind(TemplateSpecializationKind TSK) {
2593    SpecializationKind = TSK;
2594  }
2595
2596  /// Get the point of instantiation (if any), or null if none.
2597  SourceLocation getPointOfInstantiation() const {
2598    return PointOfInstantiation;
2599  }
2600
2601  void setPointOfInstantiation(SourceLocation Loc) {
2602     (0) . __assert_fail ("Loc.isValid() && \"point of instantiation must be valid!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 2602, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Loc.isValid() && "point of instantiation must be valid!");
2603    PointOfInstantiation = Loc;
2604  }
2605
2606  void setCompleteDefinition() { IsCompleteDefinition = true; }
2607
2608  /// If this variable template specialization is an instantiation of
2609  /// a template (rather than an explicit specialization), return the
2610  /// variable template or variable template partial specialization from which
2611  /// it was instantiated.
2612  llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
2613  getInstantiatedFrom() const {
2614    if (!isTemplateInstantiation(getSpecializationKind()))
2615      return llvm::PointerUnion<VarTemplateDecl *,
2616                                VarTemplatePartialSpecializationDecl *>();
2617
2618    return getSpecializedTemplateOrPartial();
2619  }
2620
2621  /// Retrieve the variable template or variable template partial
2622  /// specialization which was specialized by this.
2623  llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
2624  getSpecializedTemplateOrPartial() const {
2625    if (const auto *PartialSpec =
2626            SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
2627      return PartialSpec->PartialSpecialization;
2628
2629    return SpecializedTemplate.get<VarTemplateDecl *>();
2630  }
2631
2632  /// Retrieve the set of template arguments that should be used
2633  /// to instantiate the initializer of the variable template or variable
2634  /// template partial specialization from which this variable template
2635  /// specialization was instantiated.
2636  ///
2637  /// \returns For a variable template specialization instantiated from the
2638  /// primary template, this function will return the same template arguments
2639  /// as getTemplateArgs(). For a variable template specialization instantiated
2640  /// from a variable template partial specialization, this function will the
2641  /// return deduced template arguments for the variable template partial
2642  /// specialization itself.
2643  const TemplateArgumentList &getTemplateInstantiationArgs() const {
2644    if (const auto *PartialSpec =
2645            SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
2646      return *PartialSpec->TemplateArgs;
2647
2648    return getTemplateArgs();
2649  }
2650
2651  /// Note that this variable template specialization is actually an
2652  /// instantiation of the given variable template partial specialization whose
2653  /// template arguments have been deduced.
2654  void setInstantiationOf(VarTemplatePartialSpecializationDecl *PartialSpec,
2655                          const TemplateArgumentList *TemplateArgs) {
2656     (0) . __assert_fail ("!SpecializedTemplate.is() && \"Already set to a variable template partial specialization!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 2657, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!SpecializedTemplate.is<SpecializedPartialSpecialization *>() &&
2657 (0) . __assert_fail ("!SpecializedTemplate.is() && \"Already set to a variable template partial specialization!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 2657, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">           "Already set to a variable template partial specialization!");
2658    auto *PS = new (getASTContext()) SpecializedPartialSpecialization();
2659    PS->PartialSpecialization = PartialSpec;
2660    PS->TemplateArgs = TemplateArgs;
2661    SpecializedTemplate = PS;
2662  }
2663
2664  /// Note that this variable template specialization is an instantiation
2665  /// of the given variable template.
2666  void setInstantiationOf(VarTemplateDecl *TemplDecl) {
2667     (0) . __assert_fail ("!SpecializedTemplate.is() && \"Previously set to a variable template partial specialization!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 2668, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!SpecializedTemplate.is<SpecializedPartialSpecialization *>() &&
2668 (0) . __assert_fail ("!SpecializedTemplate.is() && \"Previously set to a variable template partial specialization!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 2668, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">           "Previously set to a variable template partial specialization!");
2669    SpecializedTemplate = TemplDecl;
2670  }
2671
2672  /// Sets the type of this specialization as it was written by
2673  /// the user.
2674  void setTypeAsWritten(TypeSourceInfo *T) {
2675    if (!ExplicitInfo)
2676      ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo;
2677    ExplicitInfo->TypeAsWritten = T;
2678  }
2679
2680  /// Gets the type of this specialization as it was written by
2681  /// the user, if it was so written.
2682  TypeSourceInfo *getTypeAsWritten() const {
2683    return ExplicitInfo ? ExplicitInfo->TypeAsWritten : nullptr;
2684  }
2685
2686  /// Gets the location of the extern keyword, if present.
2687  SourceLocation getExternLoc() const {
2688    return ExplicitInfo ? ExplicitInfo->ExternLoc : SourceLocation();
2689  }
2690
2691  /// Sets the location of the extern keyword.
2692  void setExternLoc(SourceLocation Loc) {
2693    if (!ExplicitInfo)
2694      ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo;
2695    ExplicitInfo->ExternLoc = Loc;
2696  }
2697
2698  /// Sets the location of the template keyword.
2699  void setTemplateKeywordLoc(SourceLocation Loc) {
2700    if (!ExplicitInfo)
2701      ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo;
2702    ExplicitInfo->TemplateKeywordLoc = Loc;
2703  }
2704
2705  /// Gets the location of the template keyword, if present.
2706  SourceLocation getTemplateKeywordLoc() const {
2707    return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation();
2708  }
2709
2710  void Profile(llvm::FoldingSetNodeID &IDconst {
2711    Profile(IDTemplateArgs->asArray(), getASTContext());
2712  }
2713
2714  static void Profile(llvm::FoldingSetNodeID &ID,
2715                      ArrayRef<TemplateArgumentTemplateArgs,
2716                      ASTContext &Context) {
2717    ID.AddInteger(TemplateArgs.size());
2718    for (const TemplateArgument &TemplateArg : TemplateArgs)
2719      TemplateArg.Profile(ID, Context);
2720  }
2721
2722  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2723
2724  static bool classofKind(Kind K) {
2725    return K >= firstVarTemplateSpecialization &&
2726           K <= lastVarTemplateSpecialization;
2727  }
2728};
2729
2730class VarTemplatePartialSpecializationDecl
2731    : public VarTemplateSpecializationDecl {
2732  /// The list of template parameters
2733  TemplateParameterList *TemplateParams = nullptr;
2734
2735  /// The source info for the template arguments as written.
2736  /// FIXME: redundant with TypeAsWritten?
2737  const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr;
2738
2739  /// The variable template partial specialization from which this
2740  /// variable template partial specialization was instantiated.
2741  ///
2742  /// The boolean value will be true to indicate that this variable template
2743  /// partial specialization was specialized at this level.
2744  llvm::PointerIntPair<VarTemplatePartialSpecializationDecl *, 1bool>
2745  InstantiatedFromMember;
2746
2747  VarTemplatePartialSpecializationDecl(
2748      ASTContext &ContextDeclContext *DCSourceLocation StartLoc,
2749      SourceLocation IdLocTemplateParameterList *Params,
2750      VarTemplateDecl *SpecializedTemplateQualType TTypeSourceInfo *TInfo,
2751      StorageClass SArrayRef<TemplateArgumentArgs,
2752      const ASTTemplateArgumentListInfo *ArgInfos);
2753
2754  VarTemplatePartialSpecializationDecl(ASTContext &Context)
2755      : VarTemplateSpecializationDecl(VarTemplatePartialSpecialization,
2756                                      Context),
2757        InstantiatedFromMember(nullptrfalse) {}
2758
2759  void anchor() override;
2760
2761public:
2762  friend class ASTDeclReader;
2763  friend class ASTDeclWriter;
2764
2765  static VarTemplatePartialSpecializationDecl *
2766  Create(ASTContext &ContextDeclContext *DCSourceLocation StartLoc,
2767         SourceLocation IdLocTemplateParameterList *Params,
2768         VarTemplateDecl *SpecializedTemplateQualType T,
2769         TypeSourceInfo *TInfoStorageClass SArrayRef<TemplateArgumentArgs,
2770         const TemplateArgumentListInfo &ArgInfos);
2771
2772  static VarTemplatePartialSpecializationDecl *CreateDeserialized(ASTContext &C,
2773                                                                  unsigned ID);
2774
2775  VarTemplatePartialSpecializationDecl *getMostRecentDecl() {
2776    return cast<VarTemplatePartialSpecializationDecl>(
2777             static_cast<VarTemplateSpecializationDecl *>(
2778               this)->getMostRecentDecl());
2779  }
2780
2781  /// Get the list of template parameters
2782  TemplateParameterList *getTemplateParameters() const {
2783    return TemplateParams;
2784  }
2785
2786  /// Get the template arguments as written.
2787  const ASTTemplateArgumentListInfo *getTemplateArgsAsWritten() const {
2788    return ArgsAsWritten;
2789  }
2790
2791  /// Retrieve the member variable template partial specialization from
2792  /// which this particular variable template partial specialization was
2793  /// instantiated.
2794  ///
2795  /// \code
2796  /// template<typename T>
2797  /// struct Outer {
2798  ///   template<typename U> U Inner;
2799  ///   template<typename U> U* Inner<U*> = (U*)(0); // #1
2800  /// };
2801  ///
2802  /// template int* Outer<float>::Inner<int*>;
2803  /// \endcode
2804  ///
2805  /// In this example, the instantiation of \c Outer<float>::Inner<int*> will
2806  /// end up instantiating the partial specialization
2807  /// \c Outer<float>::Inner<U*>, which itself was instantiated from the
2808  /// variable template partial specialization \c Outer<T>::Inner<U*>. Given
2809  /// \c Outer<float>::Inner<U*>, this function would return
2810  /// \c Outer<T>::Inner<U*>.
2811  VarTemplatePartialSpecializationDecl *getInstantiatedFromMember() const {
2812    const auto *First =
2813        cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2814    return First->InstantiatedFromMember.getPointer();
2815  }
2816
2817  void
2818  setInstantiatedFromMember(VarTemplatePartialSpecializationDecl *PartialSpec) {
2819    auto *First = cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2820    First->InstantiatedFromMember.setPointer(PartialSpec);
2821  }
2822
2823  /// Determines whether this variable template partial specialization
2824  /// was a specialization of a member partial specialization.
2825  ///
2826  /// In the following example, the member template partial specialization
2827  /// \c X<int>::Inner<T*> is a member specialization.
2828  ///
2829  /// \code
2830  /// template<typename T>
2831  /// struct X {
2832  ///   template<typename U> U Inner;
2833  ///   template<typename U> U* Inner<U*> = (U*)(0);
2834  /// };
2835  ///
2836  /// template<> template<typename T>
2837  /// U* X<int>::Inner<T*> = (T*)(0) + 1;
2838  /// \endcode
2839  bool isMemberSpecialization() {
2840    const auto *First =
2841        cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2842    return First->InstantiatedFromMember.getInt();
2843  }
2844
2845  /// Note that this member template is a specialization.
2846  void setMemberSpecialization() {
2847    auto *First = cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2848     (0) . __assert_fail ("First->InstantiatedFromMember.getPointer() && \"Only member templates can be member template specializations\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 2849, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(First->InstantiatedFromMember.getPointer() &&
2849 (0) . __assert_fail ("First->InstantiatedFromMember.getPointer() && \"Only member templates can be member template specializations\"", "/home/seafit/code_projects/clang_source/clang/include/clang/AST/DeclTemplate.h", 2849, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">           "Only member templates can be member template specializations");
2850    return First->InstantiatedFromMember.setInt(true);
2851  }
2852
2853  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2854
2855  static bool classofKind(Kind K) {
2856    return K == VarTemplatePartialSpecialization;
2857  }
2858};
2859
2860/// Declaration of a variable template.
2861class VarTemplateDecl : public RedeclarableTemplateDecl {
2862protected:
2863  /// Data that is common to all of the declarations of a given
2864  /// variable template.
2865  struct Common : CommonBase {
2866    /// The variable template specializations for this variable
2867    /// template, including explicit specializations and instantiations.
2868    llvm::FoldingSetVector<VarTemplateSpecializationDecl> Specializations;
2869
2870    /// The variable template partial specializations for this variable
2871    /// template.
2872    llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl>
2873    PartialSpecializations;
2874
2875    Common() = default;
2876  };
2877
2878  /// Retrieve the set of specializations of this variable template.
2879  llvm::FoldingSetVector<VarTemplateSpecializationDecl> &
2880  getSpecializations() const;
2881
2882  /// Retrieve the set of partial specializations of this class
2883  /// template.
2884  llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &
2885  getPartialSpecializations();
2886
2887  VarTemplateDecl(ASTContext &CDeclContext *DCSourceLocation L,
2888                  DeclarationName NameTemplateParameterList *Params,
2889                  NamedDecl *Decl)
2890      : RedeclarableTemplateDecl(VarTemplate, C, DC, L, Name, Params, Decl) {}
2891
2892  CommonBase *newCommon(ASTContext &Cconst override;
2893
2894  Common *getCommonPtr() const {
2895    return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
2896  }
2897
2898public:
2899  friend class ASTDeclReader;
2900  friend class ASTDeclWriter;
2901
2902  /// Load any lazily-loaded specializations from the external source.
2903  void LoadLazySpecializations() const;
2904
2905  /// Get the underlying variable declarations of the template.
2906  VarDecl *getTemplatedDecl() const {
2907    return static_cast<VarDecl *>(TemplatedDecl);
2908  }
2909
2910  /// Returns whether this template declaration defines the primary
2911  /// variable pattern.
2912  bool isThisDeclarationADefinition() const {
2913    return getTemplatedDecl()->isThisDeclarationADefinition();
2914  }
2915
2916  VarTemplateDecl *getDefinition();
2917
2918  /// Create a variable template node.
2919  static VarTemplateDecl *Create(ASTContext &CDeclContext *DC,
2920                                 SourceLocation LDeclarationName Name,
2921                                 TemplateParameterList *Params,
2922                                 VarDecl *Decl);
2923
2924  /// Create an empty variable template node.
2925  static VarTemplateDecl *CreateDeserialized(ASTContext &Cunsigned ID);
2926
2927  /// Return the specialization with the provided arguments if it exists,
2928  /// otherwise return the insertion point.
2929  VarTemplateSpecializationDecl *
2930  findSpecialization(ArrayRef<TemplateArgumentArgsvoid *&InsertPos);
2931
2932  /// Insert the specified specialization knowing that it is not already
2933  /// in. InsertPos must be obtained from findSpecialization.
2934  void AddSpecialization(VarTemplateSpecializationDecl *Dvoid *InsertPos);
2935
2936  VarTemplateDecl *getCanonicalDecl() override {
2937    return cast<VarTemplateDecl>(RedeclarableTemplateDecl::getCanonicalDecl());
2938  }
2939  const VarTemplateDecl *getCanonicalDecl() const {
2940    return cast<VarTemplateDecl>(RedeclarableTemplateDecl::getCanonicalDecl());
2941  }
2942
2943  /// Retrieve the previous declaration of this variable template, or
2944  /// nullptr if no such declaration exists.
2945  VarTemplateDecl *getPreviousDecl() {
2946    return cast_or_null<VarTemplateDecl>(
2947        static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
2948  }
2949  const VarTemplateDecl *getPreviousDecl() const {
2950    return cast_or_null<VarTemplateDecl>(
2951            static_cast<const RedeclarableTemplateDecl *>(
2952              this)->getPreviousDecl());
2953  }
2954
2955  VarTemplateDecl *getMostRecentDecl() {
2956    return cast<VarTemplateDecl>(
2957        static_cast<RedeclarableTemplateDecl *>(this)->getMostRecentDecl());
2958  }
2959  const VarTemplateDecl *getMostRecentDecl() const {
2960    return const_cast<VarTemplateDecl *>(this)->getMostRecentDecl();
2961  }
2962
2963  VarTemplateDecl *getInstantiatedFromMemberTemplate() const {
2964    return cast_or_null<VarTemplateDecl>(
2965        RedeclarableTemplateDecl::getInstantiatedFromMemberTemplate());
2966  }
2967
2968  /// Return the partial specialization with the provided arguments if it
2969  /// exists, otherwise return the insertion point.
2970  VarTemplatePartialSpecializationDecl *
2971  findPartialSpecialization(ArrayRef<TemplateArgumentArgsvoid *&InsertPos);
2972
2973  /// Insert the specified partial specialization knowing that it is not
2974  /// already in. InsertPos must be obtained from findPartialSpecialization.
2975  void AddPartialSpecialization(VarTemplatePartialSpecializationDecl *D,
2976                                void *InsertPos);
2977
2978  /// Retrieve the partial specializations as an ordered list.
2979  void getPartialSpecializations(
2980      SmallVectorImpl<VarTemplatePartialSpecializationDecl *> &PS);
2981
2982  /// Find a variable template partial specialization which was
2983  /// instantiated
2984  /// from the given member partial specialization.
2985  ///
2986  /// \param D a member variable template partial specialization.
2987  ///
2988  /// \returns the variable template partial specialization which was
2989  /// instantiated
2990  /// from the given member partial specialization, or nullptr if no such
2991  /// partial specialization exists.
2992  VarTemplatePartialSpecializationDecl *findPartialSpecInstantiatedFromMember(
2993      VarTemplatePartialSpecializationDecl *D);
2994
2995  using spec_iterator = SpecIterator<VarTemplateSpecializationDecl>;
2996  using spec_range = llvm::iterator_range<spec_iterator>;
2997
2998  spec_range specializations() const {
2999    return spec_range(spec_begin(), spec_end());
3000  }
3001
3002  spec_iterator spec_begin() const {
3003    return makeSpecIterator(getSpecializations(), false);
3004  }
3005
3006  spec_iterator spec_end() const {
3007    return makeSpecIterator(getSpecializations(), true);
3008  }
3009
3010  // Implement isa/cast/dyncast support
3011  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3012  static bool classofKind(Kind K) { return K == VarTemplate; }
3013};
3014
3015inline NamedDecl *getAsNamedDecl(TemplateParameter P) {
3016  if (auto *PD = P.dyn_cast<TemplateTypeParmDecl *>())
3017    return PD;
3018  if (auto *PD = P.dyn_cast<NonTypeTemplateParmDecl *>())
3019    return PD;
3020  return P.get<TemplateTemplateParmDecl *>();
3021}
3022
3023inline TemplateDecl *getAsTypeTemplateDecl(Decl *D) {
3024  auto *TD = dyn_cast<TemplateDecl>(D);
3025  return TD && (isa<ClassTemplateDecl>(TD) ||
3026                isa<ClassTemplatePartialSpecializationDecl>(TD) ||
3027                isa<TypeAliasTemplateDecl>(TD) ||
3028                isa<TemplateTemplateParmDecl>(TD))
3029             ? TD
3030             : nullptr;
3031}
3032
3033// namespace clang
3034
3035#endif // LLVM_CLANG_AST_DECLTEMPLATE_H
3036
clang::TemplateParameterList::TemplateLoc
clang::TemplateParameterList::LAngleLoc
clang::TemplateParameterList::RAngleLoc
clang::TemplateParameterList::NumParams
clang::TemplateParameterList::ContainsUnexpandedParameterPack
clang::TemplateParameterList::HasRequiresClause
clang::TemplateParameterList::numTrailingObjects
clang::TemplateParameterList::Create
clang::TemplateParameterList::begin
clang::TemplateParameterList::begin
clang::TemplateParameterList::end
clang::TemplateParameterList::end
clang::TemplateParameterList::size
clang::TemplateParameterList::asArray
clang::TemplateParameterList::asArray
clang::TemplateParameterList::getParam
clang::TemplateParameterList::getParam
clang::TemplateParameterList::getMinRequiredArguments
clang::TemplateParameterList::getDepth
clang::TemplateParameterList::containsUnexpandedParameterPack
clang::TemplateParameterList::getRequiresClause
clang::TemplateParameterList::getRequiresClause
clang::TemplateParameterList::getTemplateLoc
clang::TemplateParameterList::getLAngleLoc
clang::TemplateParameterList::getRAngleLoc
clang::TemplateParameterList::getSourceRange
clang::TemplateArgumentList::Arguments
clang::TemplateArgumentList::NumArguments
clang::TemplateArgumentList::OnStackType
clang::TemplateArgumentList::CreateCopy
clang::TemplateArgumentList::get
clang::TemplateArgumentList::asArray
clang::TemplateArgumentList::size
clang::TemplateArgumentList::data
clang::DefaultArgStorage::Chain
clang::DefaultArgStorage::Chain::PrevDeclWithDefaultArg
clang::DefaultArgStorage::Chain::Value
clang::DefaultArgStorage::ValueOrInherited
clang::DefaultArgStorage::getParmOwningDefaultArg
clang::DefaultArgStorage::isSet
clang::DefaultArgStorage::isInherited
clang::DefaultArgStorage::get
clang::DefaultArgStorage::getInheritedFrom
clang::DefaultArgStorage::set
clang::DefaultArgStorage::setInherited
clang::DefaultArgStorage::clear
clang::ConstrainedTemplateDeclInfo::getTemplateParameters
clang::ConstrainedTemplateDeclInfo::getAssociatedConstraints
clang::ConstrainedTemplateDeclInfo::setTemplateParameters
clang::ConstrainedTemplateDeclInfo::setAssociatedConstraints
clang::ConstrainedTemplateDeclInfo::TemplateParams
clang::ConstrainedTemplateDeclInfo::AssociatedConstraints
clang::TemplateDecl::anchor
clang::TemplateDecl::getTemplateParameters
clang::TemplateDecl::getRequiresClause
clang::TemplateDecl::getAssociatedConstraints
clang::TemplateDecl::getTemplatedDecl
clang::TemplateDecl::classof
clang::TemplateDecl::classofKind
clang::TemplateDecl::getSourceRange
clang::TemplateDecl::TemplateParams
clang::TemplateDecl::setTemplateParameters
clang::TemplateDecl::setAssociatedConstraints
clang::TemplateDecl::init
clang::FunctionTemplateSpecializationInfo::Create
clang::FunctionTemplateSpecializationInfo::Function
clang::FunctionTemplateSpecializationInfo::Template
clang::FunctionTemplateSpecializationInfo::TemplateArguments
clang::FunctionTemplateSpecializationInfo::TemplateArgumentsAsWritten
clang::FunctionTemplateSpecializationInfo::PointOfInstantiation
clang::FunctionTemplateSpecializationInfo::getTemplate
clang::FunctionTemplateSpecializationInfo::getTemplateSpecializationKind
clang::FunctionTemplateSpecializationInfo::isExplicitSpecialization
clang::FunctionTemplateSpecializationInfo::isExplicitInstantiationOrSpecialization
clang::FunctionTemplateSpecializationInfo::setTemplateSpecializationKind
clang::FunctionTemplateSpecializationInfo::getPointOfInstantiation
clang::FunctionTemplateSpecializationInfo::setPointOfInstantiation
clang::FunctionTemplateSpecializationInfo::Profile
clang::FunctionTemplateSpecializationInfo::Profile
clang::MemberSpecializationInfo::MemberAndTSK
clang::MemberSpecializationInfo::PointOfInstantiation
clang::MemberSpecializationInfo::getInstantiatedFrom
clang::MemberSpecializationInfo::getTemplateSpecializationKind
clang::MemberSpecializationInfo::isExplicitSpecialization
clang::MemberSpecializationInfo::setTemplateSpecializationKind
clang::MemberSpecializationInfo::getPointOfInstantiation
clang::MemberSpecializationInfo::setPointOfInstantiation
clang::DependentFunctionTemplateSpecializationInfo::NumTemplates
clang::DependentFunctionTemplateSpecializationInfo::NumArgs
clang::DependentFunctionTemplateSpecializationInfo::AngleLocs
clang::DependentFunctionTemplateSpecializationInfo::numTrailingObjects
clang::DependentFunctionTemplateSpecializationInfo::Create
clang::DependentFunctionTemplateSpecializationInfo::getNumTemplates
clang::DependentFunctionTemplateSpecializationInfo::getTemplate
clang::DependentFunctionTemplateSpecializationInfo::getTemplateArgs
clang::DependentFunctionTemplateSpecializationInfo::getNumTemplateArgs
clang::DependentFunctionTemplateSpecializationInfo::getTemplateArg
clang::DependentFunctionTemplateSpecializationInfo::getLAngleLoc
clang::DependentFunctionTemplateSpecializationInfo::getRAngleLoc
clang::RedeclarableTemplateDecl::getNextRedeclarationImpl
clang::RedeclarableTemplateDecl::getPreviousDeclImpl
clang::RedeclarableTemplateDecl::getMostRecentDeclImpl
clang::RedeclarableTemplateDecl::anchor
clang::RedeclarableTemplateDecl::SpecEntryTraits
clang::RedeclarableTemplateDecl::SpecEntryTraits::getDecl
clang::RedeclarableTemplateDecl::SpecEntryTraits::getTemplateArgs
clang::RedeclarableTemplateDecl::SpecIterator
clang::RedeclarableTemplateDecl::makeSpecIterator
clang::RedeclarableTemplateDecl::loadLazySpecializationsImpl
clang::RedeclarableTemplateDecl::findSpecializationImpl
clang::RedeclarableTemplateDecl::addSpecializationImpl
clang::RedeclarableTemplateDecl::CommonBase
clang::RedeclarableTemplateDecl::CommonBase::InstantiatedFromMember
clang::RedeclarableTemplateDecl::CommonBase::LazySpecializations
clang::RedeclarableTemplateDecl::Common
clang::RedeclarableTemplateDecl::getCommonPtr
clang::RedeclarableTemplateDecl::newCommon
clang::RedeclarableTemplateDecl::getCanonicalDecl
clang::RedeclarableTemplateDecl::getCanonicalDecl
clang::RedeclarableTemplateDecl::isMemberSpecialization
clang::RedeclarableTemplateDecl::setMemberSpecialization
clang::RedeclarableTemplateDecl::getInstantiatedFromMemberTemplate
clang::RedeclarableTemplateDecl::setInstantiatedFromMemberTemplate
clang::RedeclarableTemplateDecl::classof
clang::RedeclarableTemplateDecl::classofKind
clang::RedeclarableTemplateDecl::SpecEntryTraits::getDecl
clang::RedeclarableTemplateDecl::SpecEntryTraits::getTemplateArgs
clang::FunctionTemplateDecl::Common
clang::FunctionTemplateDecl::Common::Specializations
clang::FunctionTemplateDecl::Common::InjectedArgs
clang::FunctionTemplateDecl::newCommon
clang::FunctionTemplateDecl::getCommonPtr
clang::FunctionTemplateDecl::getSpecializations
clang::FunctionTemplateDecl::addSpecialization
clang::FunctionTemplateDecl::LoadLazySpecializations
clang::FunctionTemplateDecl::getTemplatedDecl
clang::FunctionTemplateDecl::isThisDeclarationADefinition
clang::FunctionTemplateDecl::findSpecialization
clang::FunctionTemplateDecl::getCanonicalDecl
clang::FunctionTemplateDecl::getCanonicalDecl
clang::FunctionTemplateDecl::getPreviousDecl
clang::FunctionTemplateDecl::getPreviousDecl
clang::FunctionTemplateDecl::getMostRecentDecl
clang::FunctionTemplateDecl::getMostRecentDecl
clang::FunctionTemplateDecl::getInstantiatedFromMemberTemplate
clang::FunctionTemplateDecl::specializations
clang::FunctionTemplateDecl::spec_begin
clang::FunctionTemplateDecl::spec_end
clang::FunctionTemplateDecl::getInjectedTemplateArgs
clang::FunctionTemplateDecl::mergePrevDecl
clang::FunctionTemplateDecl::Create
clang::FunctionTemplateDecl::CreateDeserialized
clang::FunctionTemplateDecl::classof
clang::FunctionTemplateDecl::classofKind
clang::TemplateParmPosition::Depth
clang::TemplateParmPosition::Position
clang::TemplateParmPosition::getDepth
clang::TemplateParmPosition::setDepth
clang::TemplateParmPosition::getPosition
clang::TemplateParmPosition::setPosition
clang::TemplateParmPosition::getIndex
clang::TemplateTypeParmDecl::Typename
clang::TemplateTypeParmDecl::DefaultArgument
clang::TemplateTypeParmDecl::Create
clang::TemplateTypeParmDecl::CreateDeserialized
clang::TemplateTypeParmDecl::wasDeclaredWithTypename
clang::TemplateTypeParmDecl::getDefaultArgStorage
clang::TemplateTypeParmDecl::hasDefaultArgument
clang::TemplateTypeParmDecl::getDefaultArgument
clang::TemplateTypeParmDecl::getDefaultArgumentInfo
clang::TemplateTypeParmDecl::getDefaultArgumentLoc
clang::TemplateTypeParmDecl::defaultArgumentWasInherited
clang::TemplateTypeParmDecl::setDefaultArgument
clang::TemplateTypeParmDecl::setInheritedDefaultArgument
clang::TemplateTypeParmDecl::removeDefaultArgument
clang::TemplateTypeParmDecl::setDeclaredWithTypename
clang::TemplateTypeParmDecl::getDepth
clang::TemplateTypeParmDecl::getIndex
clang::TemplateTypeParmDecl::isParameterPack
clang::TemplateTypeParmDecl::getSourceRange
clang::TemplateTypeParmDecl::classof
clang::TemplateTypeParmDecl::classofKind
clang::NonTypeTemplateParmDecl::DefaultArgument
clang::NonTypeTemplateParmDecl::ParameterPack
clang::NonTypeTemplateParmDecl::ExpandedParameterPack
clang::NonTypeTemplateParmDecl::NumExpandedTypes
clang::NonTypeTemplateParmDecl::numTrailingObjects
clang::NonTypeTemplateParmDecl::Create
clang::NonTypeTemplateParmDecl::Create
clang::NonTypeTemplateParmDecl::CreateDeserialized
clang::NonTypeTemplateParmDecl::CreateDeserialized
clang::NonTypeTemplateParmDecl::getSourceRange
clang::NonTypeTemplateParmDecl::getDefaultArgStorage
clang::NonTypeTemplateParmDecl::hasDefaultArgument
clang::NonTypeTemplateParmDecl::getDefaultArgument
clang::NonTypeTemplateParmDecl::getDefaultArgumentLoc
clang::NonTypeTemplateParmDecl::defaultArgumentWasInherited
clang::NonTypeTemplateParmDecl::setDefaultArgument
clang::NonTypeTemplateParmDecl::setInheritedDefaultArgument
clang::NonTypeTemplateParmDecl::removeDefaultArgument
clang::NonTypeTemplateParmDecl::isParameterPack
clang::NonTypeTemplateParmDecl::isPackExpansion
clang::NonTypeTemplateParmDecl::isExpandedParameterPack
clang::NonTypeTemplateParmDecl::getNumExpansionTypes
clang::NonTypeTemplateParmDecl::getExpansionType
clang::NonTypeTemplateParmDecl::getExpansionTypeSourceInfo
clang::NonTypeTemplateParmDecl::classof
clang::NonTypeTemplateParmDecl::classofKind
clang::TemplateTemplateParmDecl::DefaultArgument
clang::TemplateTemplateParmDecl::ParameterPack
clang::TemplateTemplateParmDecl::ExpandedParameterPack
clang::TemplateTemplateParmDecl::NumExpandedParams
clang::TemplateTemplateParmDecl::anchor
clang::TemplateTemplateParmDecl::Create
clang::TemplateTemplateParmDecl::Create
clang::TemplateTemplateParmDecl::CreateDeserialized
clang::TemplateTemplateParmDecl::CreateDeserialized
clang::TemplateTemplateParmDecl::isParameterPack
clang::TemplateTemplateParmDecl::isPackExpansion
clang::TemplateTemplateParmDecl::isExpandedParameterPack
clang::TemplateTemplateParmDecl::getNumExpansionTemplateParameters
clang::TemplateTemplateParmDecl::getExpansionTemplateParameters
clang::TemplateTemplateParmDecl::getDefaultArgStorage
clang::TemplateTemplateParmDecl::hasDefaultArgument
clang::TemplateTemplateParmDecl::getDefaultArgument
clang::TemplateTemplateParmDecl::getDefaultArgumentLoc
clang::TemplateTemplateParmDecl::defaultArgumentWasInherited
clang::TemplateTemplateParmDecl::setDefaultArgument
clang::TemplateTemplateParmDecl::setInheritedDefaultArgument
clang::TemplateTemplateParmDecl::removeDefaultArgument
clang::TemplateTemplateParmDecl::getSourceRange
clang::BuiltinTemplateDecl::BTK
clang::BuiltinTemplateDecl::anchor
clang::BuiltinTemplateDecl::classof
clang::BuiltinTemplateDecl::classofKind
clang::BuiltinTemplateDecl::Create
clang::BuiltinTemplateDecl::getSourceRange
clang::ClassTemplateSpecializationDecl::SpecializedPartialSpecialization
clang::ClassTemplateSpecializationDecl::SpecializedPartialSpecialization::PartialSpecialization
clang::ClassTemplateSpecializationDecl::SpecializedPartialSpecialization::TemplateArgs
clang::ClassTemplateSpecializationDecl::SpecializedTemplate
clang::ClassTemplateSpecializationDecl::ExplicitSpecializationInfo
clang::ClassTemplateSpecializationDecl::ExplicitSpecializationInfo::TypeAsWritten
clang::ClassTemplateSpecializationDecl::ExplicitSpecializationInfo::ExternLoc
clang::ClassTemplateSpecializationDecl::ExplicitSpecializationInfo::TemplateKeywordLoc
clang::ClassTemplateSpecializationDecl::ExplicitInfo
clang::ClassTemplateSpecializationDecl::TemplateArgs
clang::ClassTemplateSpecializationDecl::PointOfInstantiation
clang::ClassTemplateSpecializationDecl::SpecializationKind
clang::ClassTemplateSpecializationDecl::Create
clang::ClassTemplateSpecializationDecl::CreateDeserialized
clang::ClassTemplateSpecializationDecl::getNameForDiagnostic
clang::ClassTemplateSpecializationDecl::getMostRecentDecl
clang::ClassTemplateSpecializationDecl::getSpecializedTemplate
clang::ClassTemplateSpecializationDecl::getTemplateArgs
clang::ClassTemplateSpecializationDecl::getSpecializationKind
clang::ClassTemplateSpecializationDecl::isExplicitSpecialization
clang::ClassTemplateSpecializationDecl::isExplicitInstantiationOrSpecialization
clang::ClassTemplateSpecializationDecl::setSpecializationKind
clang::ClassTemplateSpecializationDecl::getPointOfInstantiation
clang::ClassTemplateSpecializationDecl::setPointOfInstantiation
clang::ClassTemplateSpecializationDecl::getInstantiatedFrom
clang::ClassTemplateSpecializationDecl::getSpecializedTemplateOrPartial
clang::ClassTemplateSpecializationDecl::getTemplateInstantiationArgs
clang::ClassTemplateSpecializationDecl::setInstantiationOf
clang::ClassTemplateSpecializationDecl::setInstantiationOf
clang::ClassTemplateSpecializationDecl::setTypeAsWritten
clang::ClassTemplateSpecializationDecl::getTypeAsWritten
clang::ClassTemplateSpecializationDecl::getExternLoc
clang::ClassTemplateSpecializationDecl::setExternLoc
clang::ClassTemplateSpecializationDecl::setTemplateKeywordLoc
clang::ClassTemplateSpecializationDecl::getTemplateKeywordLoc
clang::ClassTemplateSpecializationDecl::getSourceRange
clang::ClassTemplateSpecializationDecl::Profile
clang::ClassTemplateSpecializationDecl::Profile
clang::ClassTemplateSpecializationDecl::classof
clang::ClassTemplateSpecializationDecl::classofKind
clang::ClassTemplatePartialSpecializationDecl::TemplateParams
clang::ClassTemplatePartialSpecializationDecl::ArgsAsWritten
clang::ClassTemplatePartialSpecializationDecl::InstantiatedFromMember
clang::ClassTemplatePartialSpecializationDecl::anchor
clang::ClassTemplatePartialSpecializationDecl::Create
clang::ClassTemplatePartialSpecializationDecl::CreateDeserialized
clang::ClassTemplatePartialSpecializationDecl::getMostRecentDecl
clang::ClassTemplatePartialSpecializationDecl::getTemplateParameters
clang::ClassTemplatePartialSpecializationDecl::getTemplateArgsAsWritten
clang::ClassTemplatePartialSpecializationDecl::getInstantiatedFromMember
clang::ClassTemplatePartialSpecializationDecl::getInstantiatedFromMemberTemplate
clang::ClassTemplatePartialSpecializationDecl::setInstantiatedFromMember
clang::ClassTemplatePartialSpecializationDecl::isMemberSpecialization
clang::ClassTemplatePartialSpecializationDecl::setMemberSpecialization
clang::ClassTemplatePartialSpecializationDecl::getInjectedSpecializationType
clang::ClassTemplatePartialSpecializationDecl::classof
clang::ClassTemplatePartialSpecializationDecl::classofKind
clang::ClassTemplateDecl::Common
clang::ClassTemplateDecl::Common::Specializations
clang::ClassTemplateDecl::Common::PartialSpecializations
clang::ClassTemplateDecl::Common::InjectedClassNameType
clang::ClassTemplateDecl::getSpecializations
clang::ClassTemplateDecl::getPartialSpecializations
clang::ClassTemplateDecl::newCommon
clang::ClassTemplateDecl::getCommonPtr
clang::ClassTemplateDecl::LoadLazySpecializations
clang::ClassTemplateDecl::getTemplatedDecl
clang::ClassTemplateDecl::isThisDeclarationADefinition
clang::ClassTemplateDecl::Create
clang::ClassTemplateDecl::CreateDeserialized
clang::ClassTemplateDecl::findSpecialization
clang::ClassTemplateDecl::AddSpecialization
clang::ClassTemplateDecl::getCanonicalDecl
clang::ClassTemplateDecl::getCanonicalDecl
clang::ClassTemplateDecl::getPreviousDecl
clang::ClassTemplateDecl::getPreviousDecl
clang::ClassTemplateDecl::getMostRecentDecl
clang::ClassTemplateDecl::getMostRecentDecl
clang::ClassTemplateDecl::getInstantiatedFromMemberTemplate
clang::ClassTemplateDecl::findPartialSpecialization
clang::ClassTemplateDecl::AddPartialSpecialization
clang::ClassTemplateDecl::getPartialSpecializations
clang::ClassTemplateDecl::findPartialSpecialization
clang::ClassTemplateDecl::findPartialSpecInstantiatedFromMember
clang::ClassTemplateDecl::getInjectedClassNameSpecialization
clang::ClassTemplateDecl::specializations
clang::ClassTemplateDecl::spec_begin
clang::ClassTemplateDecl::spec_end
clang::ClassTemplateDecl::classof
clang::ClassTemplateDecl::classofKind
clang::FriendTemplateDecl::anchor
clang::FriendTemplateDecl::NumParams
clang::FriendTemplateDecl::Params
clang::FriendTemplateDecl::Friend
clang::FriendTemplateDecl::FriendLoc
clang::FriendTemplateDecl::Create
clang::FriendTemplateDecl::CreateDeserialized
clang::FriendTemplateDecl::getFriendType
clang::FriendTemplateDecl::getFriendDecl
clang::FriendTemplateDecl::getFriendLoc
clang::FriendTemplateDecl::getTemplateParameterList
clang::FriendTemplateDecl::getNumTemplateParameters
clang::FriendTemplateDecl::classof
clang::FriendTemplateDecl::classofKind
clang::TypeAliasTemplateDecl::newCommon
clang::TypeAliasTemplateDecl::getCommonPtr
clang::TypeAliasTemplateDecl::getTemplatedDecl
clang::TypeAliasTemplateDecl::getCanonicalDecl
clang::TypeAliasTemplateDecl::getCanonicalDecl
clang::TypeAliasTemplateDecl::getPreviousDecl
clang::TypeAliasTemplateDecl::getPreviousDecl
clang::TypeAliasTemplateDecl::getInstantiatedFromMemberTemplate
clang::TypeAliasTemplateDecl::Create
clang::TypeAliasTemplateDecl::CreateDeserialized
clang::TypeAliasTemplateDecl::classof
clang::TypeAliasTemplateDecl::classofKind
clang::ClassScopeFunctionSpecializationDecl::Specialization
clang::ClassScopeFunctionSpecializationDecl::HasExplicitTemplateArgs
clang::ClassScopeFunctionSpecializationDecl::TemplateArgs
clang::ClassScopeFunctionSpecializationDecl::anchor
clang::ClassScopeFunctionSpecializationDecl::getSpecialization
clang::ClassScopeFunctionSpecializationDecl::hasExplicitTemplateArgs
clang::ClassScopeFunctionSpecializationDecl::templateArgs
clang::ClassScopeFunctionSpecializationDecl::Create
clang::ClassScopeFunctionSpecializationDecl::CreateDeserialized
clang::ClassScopeFunctionSpecializationDecl::classof
clang::ClassScopeFunctionSpecializationDecl::classofKind
clang::VarTemplateSpecializationDecl::SpecializedPartialSpecialization
clang::VarTemplateSpecializationDecl::SpecializedPartialSpecialization::PartialSpecialization
clang::VarTemplateSpecializationDecl::SpecializedPartialSpecialization::TemplateArgs
clang::VarTemplateSpecializationDecl::SpecializedTemplate
clang::VarTemplateSpecializationDecl::ExplicitSpecializationInfo
clang::VarTemplateSpecializationDecl::ExplicitSpecializationInfo::TypeAsWritten
clang::VarTemplateSpecializationDecl::ExplicitSpecializationInfo::ExternLoc
clang::VarTemplateSpecializationDecl::ExplicitSpecializationInfo::TemplateKeywordLoc
clang::VarTemplateSpecializationDecl::ExplicitInfo
clang::VarTemplateSpecializationDecl::TemplateArgs
clang::VarTemplateSpecializationDecl::TemplateArgsInfo
clang::VarTemplateSpecializationDecl::PointOfInstantiation
clang::VarTemplateSpecializationDecl::SpecializationKind
clang::VarTemplateSpecializationDecl::IsCompleteDefinition
clang::VarTemplateSpecializationDecl::Create
clang::VarTemplateSpecializationDecl::CreateDeserialized
clang::VarTemplateSpecializationDecl::getNameForDiagnostic
clang::VarTemplateSpecializationDecl::getMostRecentDecl
clang::VarTemplateSpecializationDecl::getSpecializedTemplate
clang::VarTemplateSpecializationDecl::getTemplateArgs
clang::VarTemplateSpecializationDecl::setTemplateArgsInfo
clang::VarTemplateSpecializationDecl::getTemplateArgsInfo
clang::VarTemplateSpecializationDecl::getSpecializationKind
clang::VarTemplateSpecializationDecl::isExplicitSpecialization
clang::VarTemplateSpecializationDecl::isExplicitInstantiationOrSpecialization
clang::VarTemplateSpecializationDecl::setSpecializationKind
clang::VarTemplateSpecializationDecl::getPointOfInstantiation
clang::VarTemplateSpecializationDecl::setPointOfInstantiation
clang::VarTemplateSpecializationDecl::setCompleteDefinition
clang::VarTemplateSpecializationDecl::getInstantiatedFrom
clang::VarTemplateSpecializationDecl::getSpecializedTemplateOrPartial
clang::VarTemplateSpecializationDecl::getTemplateInstantiationArgs
clang::VarTemplateSpecializationDecl::setInstantiationOf
clang::VarTemplateSpecializationDecl::setInstantiationOf
clang::VarTemplateSpecializationDecl::setTypeAsWritten
clang::VarTemplateSpecializationDecl::getTypeAsWritten
clang::VarTemplateSpecializationDecl::getExternLoc
clang::VarTemplateSpecializationDecl::setExternLoc
clang::VarTemplateSpecializationDecl::setTemplateKeywordLoc
clang::VarTemplateSpecializationDecl::getTemplateKeywordLoc
clang::VarTemplateSpecializationDecl::Profile
clang::VarTemplateSpecializationDecl::Profile
clang::VarTemplateSpecializationDecl::classof
clang::VarTemplateSpecializationDecl::classofKind
clang::VarTemplatePartialSpecializationDecl::TemplateParams
clang::VarTemplatePartialSpecializationDecl::ArgsAsWritten
clang::VarTemplatePartialSpecializationDecl::InstantiatedFromMember
clang::VarTemplatePartialSpecializationDecl::anchor
clang::VarTemplatePartialSpecializationDecl::Create
clang::VarTemplatePartialSpecializationDecl::CreateDeserialized
clang::VarTemplatePartialSpecializationDecl::getMostRecentDecl
clang::VarTemplatePartialSpecializationDecl::getTemplateParameters
clang::VarTemplatePartialSpecializationDecl::getTemplateArgsAsWritten
clang::VarTemplatePartialSpecializationDecl::getInstantiatedFromMember
clang::VarTemplatePartialSpecializationDecl::setInstantiatedFromMember
clang::VarTemplatePartialSpecializationDecl::isMemberSpecialization
clang::VarTemplatePartialSpecializationDecl::setMemberSpecialization
clang::VarTemplatePartialSpecializationDecl::classof
clang::VarTemplatePartialSpecializationDecl::classofKind
clang::VarTemplateDecl::Common
clang::VarTemplateDecl::Common::Specializations
clang::VarTemplateDecl::Common::PartialSpecializations
clang::VarTemplateDecl::getSpecializations
clang::VarTemplateDecl::getPartialSpecializations
clang::VarTemplateDecl::newCommon
clang::VarTemplateDecl::getCommonPtr
clang::VarTemplateDecl::LoadLazySpecializations
clang::VarTemplateDecl::getTemplatedDecl
clang::VarTemplateDecl::isThisDeclarationADefinition
clang::VarTemplateDecl::getDefinition
clang::VarTemplateDecl::Create
clang::VarTemplateDecl::CreateDeserialized
clang::VarTemplateDecl::findSpecialization
clang::VarTemplateDecl::AddSpecialization
clang::VarTemplateDecl::getCanonicalDecl
clang::VarTemplateDecl::getCanonicalDecl
clang::VarTemplateDecl::getPreviousDecl
clang::VarTemplateDecl::getPreviousDecl
clang::VarTemplateDecl::getMostRecentDecl
clang::VarTemplateDecl::getMostRecentDecl
clang::VarTemplateDecl::getInstantiatedFromMemberTemplate
clang::VarTemplateDecl::findPartialSpecialization
clang::VarTemplateDecl::AddPartialSpecialization
clang::VarTemplateDecl::getPartialSpecializations
clang::VarTemplateDecl::findPartialSpecInstantiatedFromMember
clang::VarTemplateDecl::specializations
clang::VarTemplateDecl::spec_begin
clang::VarTemplateDecl::spec_end
clang::VarTemplateDecl::classof
clang::VarTemplateDecl::classofKind