clang 8.0.0

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