clang 20.0.0git
DeclTemplate.h
Go to the documentation of this file.
1//===- DeclTemplate.h - Classes for representing C++ templates --*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// Defines the C++ template declaration subclasses.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_DECLTEMPLATE_H
15#define LLVM_CLANG_AST_DECLTEMPLATE_H
16
19#include "clang/AST/Decl.h"
20#include "clang/AST/DeclBase.h"
21#include "clang/AST/DeclCXX.h"
25#include "clang/AST/Type.h"
26#include "clang/Basic/LLVM.h"
29#include "llvm/ADT/ArrayRef.h"
30#include "llvm/ADT/FoldingSet.h"
31#include "llvm/ADT/PointerIntPair.h"
32#include "llvm/ADT/PointerUnion.h"
33#include "llvm/ADT/iterator.h"
34#include "llvm/ADT/iterator_range.h"
35#include "llvm/Support/Casting.h"
36#include "llvm/Support/Compiler.h"
37#include "llvm/Support/TrailingObjects.h"
38#include <cassert>
39#include <cstddef>
40#include <cstdint>
41#include <iterator>
42#include <optional>
43#include <utility>
44
45namespace clang {
46
48class ClassTemplateDecl;
49class ClassTemplatePartialSpecializationDecl;
50class Expr;
51class FunctionTemplateDecl;
52class IdentifierInfo;
53class NonTypeTemplateParmDecl;
54class TemplateDecl;
55class TemplateTemplateParmDecl;
56class TemplateTypeParmDecl;
57class ConceptDecl;
58class UnresolvedSetImpl;
59class VarTemplateDecl;
60class VarTemplatePartialSpecializationDecl;
61
62/// Stores a template parameter of any kind.
64 llvm::PointerUnion<TemplateTypeParmDecl *, NonTypeTemplateParmDecl *,
66
68
69/// Stores a list of template parameters for a TemplateDecl and its
70/// derived classes.
72 : private llvm::TrailingObjects<TemplateParameterList, NamedDecl *,
73 Expr *> {
74 /// The template argument list of the template parameter list.
75 TemplateArgument *InjectedArgs = nullptr;
76
77 /// The location of the 'template' keyword.
78 SourceLocation TemplateLoc;
79
80 /// The locations of the '<' and '>' angle brackets.
81 SourceLocation LAngleLoc, RAngleLoc;
82
83 /// The number of template parameters in this template
84 /// parameter list.
85 unsigned NumParams : 29;
86
87 /// Whether this template parameter list contains an unexpanded parameter
88 /// pack.
89 LLVM_PREFERRED_TYPE(bool)
90 unsigned ContainsUnexpandedParameterPack : 1;
91
92 /// Whether this template parameter list has a requires clause.
93 LLVM_PREFERRED_TYPE(bool)
94 unsigned HasRequiresClause : 1;
95
96 /// Whether any of the template parameters has constrained-parameter
97 /// constraint-expression.
98 LLVM_PREFERRED_TYPE(bool)
99 unsigned HasConstrainedParameters : 1;
100
101protected:
103 SourceLocation LAngleLoc, ArrayRef<NamedDecl *> Params,
104 SourceLocation RAngleLoc, Expr *RequiresClause);
105
106 size_t numTrailingObjects(OverloadToken<NamedDecl *>) const {
107 return NumParams;
108 }
109
110 size_t numTrailingObjects(OverloadToken<Expr *>) const {
111 return HasRequiresClause ? 1 : 0;
112 }
113
114public:
115 template <size_t N, bool HasRequiresClause>
118
120 SourceLocation TemplateLoc,
121 SourceLocation LAngleLoc,
123 SourceLocation RAngleLoc,
124 Expr *RequiresClause);
125
126 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &C) const;
127
128 /// Iterates through the template parameters in this list.
129 using iterator = NamedDecl **;
130
131 /// Iterates through the template parameters in this list.
132 using const_iterator = NamedDecl * const *;
133
134 iterator begin() { return getTrailingObjects<NamedDecl *>(); }
135 const_iterator begin() const { return getTrailingObjects<NamedDecl *>(); }
136 iterator end() { return begin() + NumParams; }
137 const_iterator end() const { return begin() + NumParams; }
138
139 unsigned size() const { return NumParams; }
140 bool empty() const { return NumParams == 0; }
141
144 return llvm::ArrayRef(begin(), size());
145 }
146
147 NamedDecl* getParam(unsigned Idx) {
148 assert(Idx < size() && "Template parameter index out-of-range");
149 return begin()[Idx];
150 }
151 const NamedDecl* getParam(unsigned Idx) const {
152 assert(Idx < size() && "Template parameter index out-of-range");
153 return begin()[Idx];
154 }
155
156 /// Returns the minimum number of arguments needed to form a
157 /// template specialization.
158 ///
159 /// This may be fewer than the number of template parameters, if some of
160 /// the parameters have default arguments or if there is a parameter pack.
161 unsigned getMinRequiredArguments() const;
162
163 /// Get the depth of this template parameter list in the set of
164 /// template parameter lists.
165 ///
166 /// The first template parameter list in a declaration will have depth 0,
167 /// the second template parameter list will have depth 1, etc.
168 unsigned getDepth() const;
169
170 /// Determine whether this template parameter list contains an
171 /// unexpanded parameter pack.
173
174 /// Determine whether this template parameter list contains a parameter pack.
175 bool hasParameterPack() const {
176 for (const NamedDecl *P : asArray())
177 if (P->isParameterPack())
178 return true;
179 return false;
180 }
181
182 /// The constraint-expression of the associated requires-clause.
184 return HasRequiresClause ? getTrailingObjects<Expr *>()[0] : nullptr;
185 }
186
187 /// The constraint-expression of the associated requires-clause.
188 const Expr *getRequiresClause() const {
189 return HasRequiresClause ? getTrailingObjects<Expr *>()[0] : nullptr;
190 }
191
192 /// \brief All associated constraints derived from this template parameter
193 /// list, including the requires clause and any constraints derived from
194 /// constrained-parameters.
195 ///
196 /// The constraints in the resulting list are to be treated as if in a
197 /// conjunction ("and").
199
201
202 /// Get the template argument list of the template parameter list.
204
205 SourceLocation getTemplateLoc() const { return TemplateLoc; }
206 SourceLocation getLAngleLoc() const { return LAngleLoc; }
207 SourceLocation getRAngleLoc() const { return RAngleLoc; }
208
209 SourceRange getSourceRange() const LLVM_READONLY {
210 return SourceRange(TemplateLoc, RAngleLoc);
211 }
212
213 void print(raw_ostream &Out, const ASTContext &Context,
214 bool OmitTemplateKW = false) const;
215 void print(raw_ostream &Out, const ASTContext &Context,
216 const PrintingPolicy &Policy, bool OmitTemplateKW = false) const;
217
219 const TemplateParameterList *TPL,
220 unsigned Idx);
221};
222
223/// Stores a list of template parameters and the associated
224/// requires-clause (if any) for a TemplateDecl and its derived classes.
225/// Suitable for creating on the stack.
226template <size_t N, bool HasRequiresClause>
228 : public TemplateParameterList::FixedSizeStorageOwner {
229 typename TemplateParameterList::FixedSizeStorage<
230 NamedDecl *, Expr *>::with_counts<
231 N, HasRequiresClause ? 1u : 0u
232 >::type storage;
233
234public:
236 SourceLocation TemplateLoc,
237 SourceLocation LAngleLoc,
239 SourceLocation RAngleLoc,
240 Expr *RequiresClause)
241 : FixedSizeStorageOwner(
242 (assert(N == Params.size()),
243 assert(HasRequiresClause == (RequiresClause != nullptr)),
244 new (static_cast<void *>(&storage)) TemplateParameterList(C,
245 TemplateLoc, LAngleLoc, Params, RAngleLoc, RequiresClause))) {}
246};
247
248/// A template argument list.
250 : private llvm::TrailingObjects<TemplateArgumentList, TemplateArgument> {
251 /// The number of template arguments in this template
252 /// argument list.
253 unsigned NumArguments;
254
255 // Constructs an instance with an internal Argument list, containing
256 // a copy of the Args array. (Called by CreateCopy)
258
259public:
261
264
265 /// Create a new template argument list that copies the given set of
266 /// template arguments.
269
270 /// Retrieve the template argument at a given index.
271 const TemplateArgument &get(unsigned Idx) const {
272 assert(Idx < NumArguments && "Invalid template argument index");
273 return data()[Idx];
274 }
275
276 /// Retrieve the template argument at a given index.
277 const TemplateArgument &operator[](unsigned Idx) const { return get(Idx); }
278
279 /// Produce this as an array ref.
281 return llvm::ArrayRef(data(), size());
282 }
283
284 /// Retrieve the number of template arguments in this
285 /// template argument list.
286 unsigned size() const { return NumArguments; }
287
288 /// Retrieve a pointer to the template argument list.
289 const TemplateArgument *data() const {
290 return getTrailingObjects<TemplateArgument>();
291 }
292};
293
294void *allocateDefaultArgStorageChain(const ASTContext &C);
295
296/// Storage for a default argument. This is conceptually either empty, or an
297/// argument value, or a pointer to a previous declaration that had a default
298/// argument.
299///
300/// However, this is complicated by modules: while we require all the default
301/// arguments for a template to be equivalent, there may be more than one, and
302/// we need to track all the originating parameters to determine if the default
303/// argument is visible.
304template<typename ParmDecl, typename ArgType>
306 /// Storage for both the value *and* another parameter from which we inherit
307 /// the default argument. This is used when multiple default arguments for a
308 /// parameter are merged together from different modules.
309 struct Chain {
310 ParmDecl *PrevDeclWithDefaultArg;
311 ArgType Value;
312 };
313 static_assert(sizeof(Chain) == sizeof(void *) * 2,
314 "non-pointer argument type?");
315
316 llvm::PointerUnion<ArgType, ParmDecl*, Chain*> ValueOrInherited;
317
318 static ParmDecl *getParmOwningDefaultArg(ParmDecl *Parm) {
319 const DefaultArgStorage &Storage = Parm->getDefaultArgStorage();
320 if (auto *Prev = Storage.ValueOrInherited.template dyn_cast<ParmDecl *>())
321 Parm = Prev;
322 assert(!isa<ParmDecl *>(Parm->getDefaultArgStorage().ValueOrInherited) &&
323 "should only be one level of indirection");
324 return Parm;
325 }
326
327public:
328 DefaultArgStorage() : ValueOrInherited(ArgType()) {}
329
330 /// Determine whether there is a default argument for this parameter.
331 bool isSet() const { return !ValueOrInherited.isNull(); }
332
333 /// Determine whether the default argument for this parameter was inherited
334 /// from a previous declaration of the same entity.
335 bool isInherited() const { return isa<ParmDecl *>(ValueOrInherited); }
336
337 /// Get the default argument's value. This does not consider whether the
338 /// default argument is visible.
339 ArgType get() const {
340 const DefaultArgStorage *Storage = this;
341 if (const auto *Prev = ValueOrInherited.template dyn_cast<ParmDecl *>())
342 Storage = &Prev->getDefaultArgStorage();
343 if (const auto *C = Storage->ValueOrInherited.template dyn_cast<Chain *>())
344 return C->Value;
345 return cast<ArgType>(Storage->ValueOrInherited);
346 }
347
348 /// Get the parameter from which we inherit the default argument, if any.
349 /// This is the parameter on which the default argument was actually written.
350 const ParmDecl *getInheritedFrom() const {
351 if (const auto *D = ValueOrInherited.template dyn_cast<ParmDecl *>())
352 return D;
353 if (const auto *C = ValueOrInherited.template dyn_cast<Chain *>())
354 return C->PrevDeclWithDefaultArg;
355 return nullptr;
356 }
357
358 /// Set the default argument.
359 void set(ArgType Arg) {
360 assert(!isSet() && "default argument already set");
361 ValueOrInherited = Arg;
362 }
363
364 /// Set that the default argument was inherited from another parameter.
365 void setInherited(const ASTContext &C, ParmDecl *InheritedFrom) {
366 InheritedFrom = getParmOwningDefaultArg(InheritedFrom);
367 if (!isSet())
368 ValueOrInherited = InheritedFrom;
369 else if ([[maybe_unused]] auto *D =
370 ValueOrInherited.template dyn_cast<ParmDecl *>()) {
371 assert(C.isSameDefaultTemplateArgument(D, InheritedFrom));
372 ValueOrInherited =
373 new (allocateDefaultArgStorageChain(C)) Chain{InheritedFrom, get()};
374 } else if (auto *Inherited =
375 ValueOrInherited.template dyn_cast<Chain *>()) {
376 assert(C.isSameDefaultTemplateArgument(Inherited->PrevDeclWithDefaultArg,
377 InheritedFrom));
378 Inherited->PrevDeclWithDefaultArg = InheritedFrom;
379 } else
380 ValueOrInherited = new (allocateDefaultArgStorageChain(C))
381 Chain{InheritedFrom, cast<ArgType>(ValueOrInherited)};
382 }
383
384 /// Remove the default argument, even if it was inherited.
385 void clear() {
386 ValueOrInherited = ArgType();
387 }
388};
389
390//===----------------------------------------------------------------------===//
391// Kinds of Templates
392//===----------------------------------------------------------------------===//
393
394/// \brief 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.
399class TemplateDecl : public NamedDecl {
400 void anchor() override;
401
402protected:
403 // Construct a template decl with name, parameters, and templated element.
406
407 // Construct a template decl with the given name and parameters.
408 // Used when there is no templated element (e.g., for tt-params).
410 TemplateParameterList *Params)
411 : TemplateDecl(DK, DC, L, Name, Params, nullptr) {}
412
413public:
414 friend class ASTDeclReader;
415 friend class ASTDeclWriter;
416
417 /// Get the list of template parameters
419 return TemplateParams;
420 }
421
422 /// \brief Get the total constraint-expression associated with this template,
423 /// including constraint-expressions derived from the requires-clause,
424 /// trailing requires-clause (for functions and methods) and constrained
425 /// template parameters.
427
428 bool hasAssociatedConstraints() const;
429
430 /// Get the underlying, templated declaration.
432
433 // Should a specialization behave like an alias for another type.
434 bool isTypeAlias() const;
435
436 // Implement isa/cast/dyncast/etc.
437 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
438
439 static bool classofKind(Kind K) {
440 return K >= firstTemplate && K <= lastTemplate;
441 }
442
443 SourceRange getSourceRange() const override LLVM_READONLY {
444 return SourceRange(getTemplateParameters()->getTemplateLoc(),
446 }
447
448protected:
451
452public:
454 TemplateParams = TParams;
455 }
456
457 /// Initialize the underlying templated declaration.
458 void init(NamedDecl *NewTemplatedDecl) {
459 if (TemplatedDecl)
460 assert(TemplatedDecl == NewTemplatedDecl && "Inconsistent TemplatedDecl");
461 else
462 TemplatedDecl = NewTemplatedDecl;
463 }
464};
465
466/// Provides information about a function template specialization,
467/// which is a FunctionDecl that has been explicitly specialization or
468/// instantiated from a function template.
470 : public llvm::FoldingSetNode,
471 private llvm::TrailingObjects<FunctionTemplateSpecializationInfo,
472 MemberSpecializationInfo *> {
473 /// The function template specialization that this structure describes and a
474 /// flag indicating if the function is a member specialization.
475 llvm::PointerIntPair<FunctionDecl *, 1, bool> Function;
476
477 /// The function template from which this function template
478 /// specialization was generated.
479 ///
480 /// The two bits contain the top 4 values of TemplateSpecializationKind.
481 llvm::PointerIntPair<FunctionTemplateDecl *, 2> Template;
482
483public:
484 /// The template arguments used to produce the function template
485 /// specialization from the function template.
487
488 /// The template arguments as written in the sources, if provided.
489 /// FIXME: Normally null; tail-allocate this.
491
492 /// The point at which this function template specialization was
493 /// first instantiated.
495
496private:
498 FunctionDecl *FD, FunctionTemplateDecl *Template,
500 const ASTTemplateArgumentListInfo *TemplateArgsAsWritten,
502 : Function(FD, MSInfo ? true : false), Template(Template, TSK - 1),
503 TemplateArguments(TemplateArgs),
504 TemplateArgumentsAsWritten(TemplateArgsAsWritten),
506 if (MSInfo)
507 getTrailingObjects<MemberSpecializationInfo *>()[0] = MSInfo;
508 }
509
510 size_t numTrailingObjects(OverloadToken<MemberSpecializationInfo*>) const {
511 return Function.getInt();
512 }
513
514public:
516
520 const TemplateArgumentListInfo *TemplateArgsAsWritten,
522
523 /// Retrieve the declaration of the function template specialization.
524 FunctionDecl *getFunction() const { return Function.getPointer(); }
525
526 /// Retrieve the template from which this function was specialized.
527 FunctionTemplateDecl *getTemplate() const { return Template.getPointer(); }
528
529 /// Determine what kind of template specialization this is.
531 return (TemplateSpecializationKind)(Template.getInt() + 1);
532 }
533
536 }
537
538 /// True if this declaration is an explicit specialization,
539 /// explicit instantiation declaration, or explicit instantiation
540 /// definition.
544 }
545
546 /// Set the template specialization kind.
548 assert(TSK != TSK_Undeclared &&
549 "Cannot encode TSK_Undeclared for a function template specialization");
550 Template.setInt(TSK - 1);
551 }
552
553 /// Retrieve the first point of instantiation of this function
554 /// template specialization.
555 ///
556 /// The point of instantiation may be an invalid source location if this
557 /// function has yet to be instantiated.
560 }
561
562 /// Set the (first) point of instantiation of this function template
563 /// specialization.
566 }
567
568 /// Get the specialization info if this function template specialization is
569 /// also a member specialization:
570 ///
571 /// \code
572 /// template<typename> struct A {
573 /// template<typename> void f();
574 /// template<> void f<int>();
575 /// };
576 /// \endcode
577 ///
578 /// Here, A<int>::f<int> is a function template specialization that is
579 /// an explicit specialization of A<int>::f, but it's also a member
580 /// specialization (an implicit instantiation in this case) of A::f<int>.
581 /// Further:
582 ///
583 /// \code
584 /// template<> template<> void A<int>::f<int>() {}
585 /// \endcode
586 ///
587 /// ... declares a function template specialization that is an explicit
588 /// specialization of A<int>::f, and is also an explicit member
589 /// specialization of A::f<int>.
590 ///
591 /// Note that the TemplateSpecializationKind of the MemberSpecializationInfo
592 /// need not be the same as that returned by getTemplateSpecializationKind(),
593 /// and represents the relationship between the function and the class-scope
594 /// explicit specialization in the original templated class -- whereas our
595 /// TemplateSpecializationKind represents the relationship between the
596 /// function and the function template, and should always be
597 /// TSK_ExplicitSpecialization whenever we have MemberSpecializationInfo.
599 return numTrailingObjects(OverloadToken<MemberSpecializationInfo *>())
600 ? getTrailingObjects<MemberSpecializationInfo *>()[0]
601 : nullptr;
602 }
603
604 void Profile(llvm::FoldingSetNodeID &ID) {
605 Profile(ID, TemplateArguments->asArray(), getFunction()->getASTContext());
606 }
607
608 static void
609 Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
610 const ASTContext &Context) {
611 ID.AddInteger(TemplateArgs.size());
612 for (const TemplateArgument &TemplateArg : TemplateArgs)
613 TemplateArg.Profile(ID, Context);
614 }
615};
616
617/// Provides information a specialization of a member of a class
618/// template, which may be a member function, static data member,
619/// member class or member enumeration.
621 // The member declaration from which this member was instantiated, and the
622 // manner in which the instantiation occurred (in the lower two bits).
623 llvm::PointerIntPair<NamedDecl *, 2> MemberAndTSK;
624
625 // The point at which this member was first instantiated.
626 SourceLocation PointOfInstantiation;
627
628public:
629 explicit
632 : MemberAndTSK(IF, TSK - 1), PointOfInstantiation(POI) {
633 assert(TSK != TSK_Undeclared &&
634 "Cannot encode undeclared template specializations for members");
635 }
636
637 /// Retrieve the member declaration from which this member was
638 /// instantiated.
639 NamedDecl *getInstantiatedFrom() const { return MemberAndTSK.getPointer(); }
640
641 /// Determine what kind of template specialization this is.
643 return (TemplateSpecializationKind)(MemberAndTSK.getInt() + 1);
644 }
645
648 }
649
650 /// Set the template specialization kind.
652 assert(TSK != TSK_Undeclared &&
653 "Cannot encode undeclared template specializations for members");
654 MemberAndTSK.setInt(TSK - 1);
655 }
656
657 /// Retrieve the first point of instantiation of this member.
658 /// If the point of instantiation is an invalid location, then this member
659 /// has not yet been instantiated.
661 return PointOfInstantiation;
662 }
663
664 /// Set the first point of instantiation.
666 PointOfInstantiation = POI;
667 }
668};
669
670/// Provides information about a dependent function-template
671/// specialization declaration.
672///
673/// This is used for function templates explicit specializations declared
674/// within class templates:
675///
676/// \code
677/// template<typename> struct A {
678/// template<typename> void f();
679/// template<> void f<int>(); // DependentFunctionTemplateSpecializationInfo
680/// };
681/// \endcode
682///
683/// As well as dependent friend declarations naming function template
684/// specializations declared within class templates:
685///
686/// \code
687/// template <class T> void foo(T);
688/// template <class T> class A {
689/// friend void foo<>(T); // DependentFunctionTemplateSpecializationInfo
690/// };
691/// \endcode
693 : private llvm::TrailingObjects<DependentFunctionTemplateSpecializationInfo,
694 FunctionTemplateDecl *> {
695 friend TrailingObjects;
696
697 /// The number of candidates for the primary template.
698 unsigned NumCandidates;
699
701 const UnresolvedSetImpl &Candidates,
702 const ASTTemplateArgumentListInfo *TemplateArgsWritten);
703
704public:
705 /// The template arguments as written in the sources, if provided.
707
709 Create(ASTContext &Context, const UnresolvedSetImpl &Candidates,
710 const TemplateArgumentListInfo *TemplateArgs);
711
712 /// Returns the candidates for the primary function template.
714 return {getTrailingObjects<FunctionTemplateDecl *>(), NumCandidates};
715 }
716};
717
718/// Declaration of a redeclarable template.
720 public Redeclarable<RedeclarableTemplateDecl>
721{
723
724 RedeclarableTemplateDecl *getNextRedeclarationImpl() override {
725 return getNextRedeclaration();
726 }
727
728 RedeclarableTemplateDecl *getPreviousDeclImpl() override {
729 return getPreviousDecl();
730 }
731
732 RedeclarableTemplateDecl *getMostRecentDeclImpl() override {
733 return getMostRecentDecl();
734 }
735
736 void anchor() override;
737
738protected:
739 template <typename EntryType> struct SpecEntryTraits {
740 using DeclType = EntryType;
741
742 static DeclType *getDecl(EntryType *D) {
743 return D;
744 }
745
747 return D->getTemplateArgs().asArray();
748 }
749 };
750
751 template <typename EntryType, typename SETraits = SpecEntryTraits<EntryType>,
752 typename DeclType = typename SETraits::DeclType>
754 : llvm::iterator_adaptor_base<
755 SpecIterator<EntryType, SETraits, DeclType>,
756 typename llvm::FoldingSetVector<EntryType>::iterator,
757 typename std::iterator_traits<typename llvm::FoldingSetVector<
758 EntryType>::iterator>::iterator_category,
759 DeclType *, ptrdiff_t, DeclType *, DeclType *> {
760 SpecIterator() = default;
761 explicit SpecIterator(
762 typename llvm::FoldingSetVector<EntryType>::iterator SetIter)
763 : SpecIterator::iterator_adaptor_base(std::move(SetIter)) {}
764
765 DeclType *operator*() const {
766 return SETraits::getDecl(&*this->I)->getMostRecentDecl();
767 }
768
769 DeclType *operator->() const { return **this; }
770 };
771
772 template <typename EntryType>
773 static SpecIterator<EntryType>
774 makeSpecIterator(llvm::FoldingSetVector<EntryType> &Specs, bool isEnd) {
775 return SpecIterator<EntryType>(isEnd ? Specs.end() : Specs.begin());
776 }
777
778 void loadLazySpecializationsImpl(bool OnlyPartial = false) const;
779
781 TemplateParameterList *TPL = nullptr) const;
782
783 template <class EntryType, typename ...ProfileArguments>
785 findSpecializationImpl(llvm::FoldingSetVector<EntryType> &Specs,
786 void *&InsertPos, ProfileArguments &&...ProfileArgs);
787
788 template <class EntryType, typename... ProfileArguments>
790 findSpecializationLocally(llvm::FoldingSetVector<EntryType> &Specs,
791 void *&InsertPos,
792 ProfileArguments &&...ProfileArgs);
793
794 template <class Derived, class EntryType>
795 void addSpecializationImpl(llvm::FoldingSetVector<EntryType> &Specs,
796 EntryType *Entry, void *InsertPos);
797
798 struct CommonBase {
800
801 /// The template from which this was most
802 /// directly instantiated (or null).
803 ///
804 /// The boolean value indicates whether this template
805 /// was explicitly specialized.
806 llvm::PointerIntPair<RedeclarableTemplateDecl *, 1, bool>
808 };
809
810 /// Pointer to the common data shared by all declarations of this
811 /// template.
812 mutable CommonBase *Common = nullptr;
813
814 /// Retrieves the "common" pointer shared by all (re-)declarations of
815 /// the same template. Calling this routine may implicitly allocate memory
816 /// for the common pointer.
817 CommonBase *getCommonPtr() const;
818
819 virtual CommonBase *newCommon(ASTContext &C) const = 0;
820
821 // Construct a template decl with name, parameters, and templated element.
825 : TemplateDecl(DK, DC, L, Name, Params, Decl), redeclarable_base(C) {}
826
827public:
828 friend class ASTDeclReader;
829 friend class ASTDeclWriter;
830 friend class ASTReader;
831 template <class decl_type> friend class RedeclarableTemplate;
832
833 /// Retrieves the canonical declaration of this template.
835 return getFirstDecl();
836 }
838 return getFirstDecl();
839 }
840
841 /// Determines whether this template was a specialization of a
842 /// member template.
843 ///
844 /// In the following example, the function template \c X<int>::f and the
845 /// member template \c X<int>::Inner are member specializations.
846 ///
847 /// \code
848 /// template<typename T>
849 /// struct X {
850 /// template<typename U> void f(T, U);
851 /// template<typename U> struct Inner;
852 /// };
853 ///
854 /// template<> template<typename T>
855 /// void X<int>::f(int, T);
856 /// template<> template<typename T>
857 /// struct X<int>::Inner { /* ... */ };
858 /// \endcode
860 return getCommonPtr()->InstantiatedFromMember.getInt();
861 }
862
863 /// Note that this member template is a specialization.
865 assert(getCommonPtr()->InstantiatedFromMember.getPointer() &&
866 "Only member templates can be member template specializations");
867 getCommonPtr()->InstantiatedFromMember.setInt(true);
868 }
869
870 /// Retrieve the member template from which this template was
871 /// instantiated, or nullptr if this template was not instantiated from a
872 /// member template.
873 ///
874 /// A template is instantiated from a member template when the member
875 /// template itself is part of a class template (or member thereof). For
876 /// example, given
877 ///
878 /// \code
879 /// template<typename T>
880 /// struct X {
881 /// template<typename U> void f(T, U);
882 /// };
883 ///
884 /// void test(X<int> x) {
885 /// x.f(1, 'a');
886 /// };
887 /// \endcode
888 ///
889 /// \c X<int>::f is a FunctionTemplateDecl that describes the function
890 /// template
891 ///
892 /// \code
893 /// template<typename U> void X<int>::f(int, U);
894 /// \endcode
895 ///
896 /// which was itself created during the instantiation of \c X<int>. Calling
897 /// getInstantiatedFromMemberTemplate() on this FunctionTemplateDecl will
898 /// retrieve the FunctionTemplateDecl for the original template \c f within
899 /// the class template \c X<T>, i.e.,
900 ///
901 /// \code
902 /// template<typename T>
903 /// template<typename U>
904 /// void X<T>::f(T, U);
905 /// \endcode
907 return getCommonPtr()->InstantiatedFromMember.getPointer();
908 }
909
911 assert(!getCommonPtr()->InstantiatedFromMember.getPointer());
912 getCommonPtr()->InstantiatedFromMember.setPointer(TD);
913 }
914
915 /// Retrieve the "injected" template arguments that correspond to the
916 /// template parameters of this template.
917 ///
918 /// Although the C++ standard has no notion of the "injected" template
919 /// arguments for a template, the notion is convenient when
920 /// we need to perform substitutions inside the definition of a template.
922 getInjectedTemplateArgs(const ASTContext &Context) const {
924 }
925
927 using redecl_iterator = redeclarable_base::redecl_iterator;
928
935
936 // Implement isa/cast/dyncast/etc.
937 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
938
939 static bool classofKind(Kind K) {
940 return K >= firstRedeclarableTemplate && K <= lastRedeclarableTemplate;
941 }
942};
943
944template <> struct RedeclarableTemplateDecl::
945SpecEntryTraits<FunctionTemplateSpecializationInfo> {
947
949 return I->getFunction();
950 }
951
954 return I->TemplateArguments->asArray();
955 }
956};
957
958/// Declaration of a template function.
960protected:
961 friend class FunctionDecl;
962
963 /// Data that is common to all of the declarations of a given
964 /// function template.
966 /// The function template specializations for this function
967 /// template, including explicit specializations and instantiations.
968 llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> Specializations;
969
970 Common() = default;
971 };
972
976 : RedeclarableTemplateDecl(FunctionTemplate, C, DC, L, Name, Params,
977 Decl) {}
978
979 CommonBase *newCommon(ASTContext &C) const override;
980
982 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
983 }
984
985 /// Retrieve the set of function template specializations of this
986 /// function template.
987 llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> &
988 getSpecializations() const;
989
990 /// Add a specialization of this function template.
991 ///
992 /// \param InsertPos Insert position in the FoldingSetVector, must have been
993 /// retrieved by an earlier call to findSpecialization().
995 void *InsertPos);
996
997public:
998 friend class ASTDeclReader;
999 friend class ASTDeclWriter;
1000
1001 /// Load any lazily-loaded specializations from the external source.
1002 void LoadLazySpecializations() const;
1003
1004 /// Get the underlying function declaration of the template.
1006 return static_cast<FunctionDecl *>(TemplatedDecl);
1007 }
1008
1009 /// Returns whether this template declaration defines the primary
1010 /// pattern.
1013 }
1014
1015 /// Return the specialization with the provided arguments if it exists,
1016 /// otherwise return the insertion point.
1018 void *&InsertPos);
1019
1021 return cast<FunctionTemplateDecl>(
1023 }
1025 return cast<FunctionTemplateDecl>(
1027 }
1028
1029 /// Retrieve the previous declaration of this function template, or
1030 /// nullptr if no such declaration exists.
1032 return cast_or_null<FunctionTemplateDecl>(
1033 static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
1034 }
1036 return cast_or_null<FunctionTemplateDecl>(
1037 static_cast<const RedeclarableTemplateDecl *>(this)->getPreviousDecl());
1038 }
1039
1041 return cast<FunctionTemplateDecl>(
1042 static_cast<RedeclarableTemplateDecl *>(this)
1043 ->getMostRecentDecl());
1044 }
1046 return const_cast<FunctionTemplateDecl*>(this)->getMostRecentDecl();
1047 }
1048
1050 return cast_or_null<FunctionTemplateDecl>(
1052 }
1053
1055 using spec_range = llvm::iterator_range<spec_iterator>;
1056
1058 return spec_range(spec_begin(), spec_end());
1059 }
1060
1062 return makeSpecIterator(getSpecializations(), false);
1063 }
1064
1066 return makeSpecIterator(getSpecializations(), true);
1067 }
1068
1069 /// Return whether this function template is an abbreviated function template,
1070 /// e.g. `void foo(auto x)` or `template<typename T> void foo(auto x)`
1071 bool isAbbreviated() const {
1072 // Since the invented template parameters generated from 'auto' parameters
1073 // are either appended to the end of the explicit template parameter list or
1074 // form a new template parameter list, we can simply observe the last
1075 // parameter to determine if such a thing happened.
1077 return TPL->getParam(TPL->size() - 1)->isImplicit();
1078 }
1079
1080 /// Merge \p Prev with our RedeclarableTemplateDecl::Common.
1082
1083 /// Create a function template node.
1086 DeclarationName Name,
1087 TemplateParameterList *Params,
1088 NamedDecl *Decl);
1089
1090 /// Create an empty function template node.
1093
1094 // Implement isa/cast/dyncast support
1095 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1096 static bool classofKind(Kind K) { return K == FunctionTemplate; }
1097};
1098
1099//===----------------------------------------------------------------------===//
1100// Kinds of Template Parameters
1101//===----------------------------------------------------------------------===//
1102
1103/// Defines the position of a template parameter within a template
1104/// parameter list.
1105///
1106/// Because template parameter can be listed
1107/// sequentially for out-of-line template members, each template parameter is
1108/// given a Depth - the nesting of template parameter scopes - and a Position -
1109/// the occurrence within the parameter list.
1110/// This class is inheritedly privately by different kinds of template
1111/// parameters and is not part of the Decl hierarchy. Just a facility.
1113protected:
1114 enum { DepthWidth = 20, PositionWidth = 12 };
1115 unsigned Depth : DepthWidth;
1117
1118 static constexpr unsigned MaxDepth = (1U << DepthWidth) - 1;
1119 static constexpr unsigned MaxPosition = (1U << PositionWidth) - 1;
1120
1121 TemplateParmPosition(unsigned D, unsigned P) : Depth(D), Position(P) {
1122 // The input may fill maximum values to show that it is invalid.
1123 // Add one here to convert it to zero.
1124 assert((D + 1) <= MaxDepth &&
1125 "The depth of template parmeter position is more than 2^20!");
1126 assert((P + 1) <= MaxPosition &&
1127 "The position of template parmeter position is more than 2^12!");
1128 }
1129
1130public:
1132
1133 /// Get the nesting depth of the template parameter.
1134 unsigned getDepth() const { return Depth; }
1135 void setDepth(unsigned D) {
1136 assert((D + 1) <= MaxDepth &&
1137 "The depth of template parmeter position is more than 2^20!");
1138 Depth = D;
1139 }
1140
1141 /// Get the position of the template parameter within its parameter list.
1142 unsigned getPosition() const { return Position; }
1143 void setPosition(unsigned P) {
1144 assert((P + 1) <= MaxPosition &&
1145 "The position of template parmeter position is more than 2^12!");
1146 Position = P;
1147 }
1148
1149 /// Get the index of the template parameter within its parameter list.
1150 unsigned getIndex() const { return Position; }
1151};
1152
1153/// Declaration of a template type parameter.
1154///
1155/// For example, "T" in
1156/// \code
1157/// template<typename T> class vector;
1158/// \endcode
1159class TemplateTypeParmDecl final : public TypeDecl,
1160 private llvm::TrailingObjects<TemplateTypeParmDecl, TypeConstraint> {
1161 /// Sema creates these on the stack during auto type deduction.
1162 friend class Sema;
1163 friend TrailingObjects;
1164 friend class ASTDeclReader;
1165
1166 /// Whether this template type parameter was declaration with
1167 /// the 'typename' keyword.
1168 ///
1169 /// If false, it was declared with the 'class' keyword.
1170 bool Typename : 1;
1171
1172 /// Whether this template type parameter has a type-constraint construct.
1173 bool HasTypeConstraint : 1;
1174
1175 /// Whether the type constraint has been initialized. This can be false if the
1176 /// constraint was not initialized yet or if there was an error forming the
1177 /// type constraint.
1178 bool TypeConstraintInitialized : 1;
1179
1180 /// Whether this type template parameter is an "expanded"
1181 /// parameter pack, meaning that its type is a pack expansion and we
1182 /// already know the set of types that expansion expands to.
1183 bool ExpandedParameterPack : 1;
1184
1185 /// The number of type parameters in an expanded parameter pack.
1186 unsigned NumExpanded = 0;
1187
1188 /// The default template argument, if any.
1189 using DefArgStorage =
1191 DefArgStorage DefaultArgument;
1192
1194 SourceLocation IdLoc, IdentifierInfo *Id, bool Typename,
1195 bool HasTypeConstraint,
1196 std::optional<unsigned> NumExpanded)
1197 : TypeDecl(TemplateTypeParm, DC, IdLoc, Id, KeyLoc), Typename(Typename),
1198 HasTypeConstraint(HasTypeConstraint), TypeConstraintInitialized(false),
1199 ExpandedParameterPack(NumExpanded),
1200 NumExpanded(NumExpanded.value_or(0)) {}
1201
1202public:
1203 static TemplateTypeParmDecl *
1204 Create(const ASTContext &C, DeclContext *DC, SourceLocation KeyLoc,
1205 SourceLocation NameLoc, unsigned D, unsigned P, IdentifierInfo *Id,
1206 bool Typename, bool ParameterPack, bool HasTypeConstraint = false,
1207 std::optional<unsigned> NumExpanded = std::nullopt);
1212 bool HasTypeConstraint);
1213
1214 /// Whether this template type parameter was declared with
1215 /// the 'typename' keyword.
1216 ///
1217 /// If not, it was either declared with the 'class' keyword or with a
1218 /// type-constraint (see hasTypeConstraint()).
1220 return Typename && !HasTypeConstraint;
1221 }
1222
1223 const DefArgStorage &getDefaultArgStorage() const { return DefaultArgument; }
1224
1225 /// Determine whether this template parameter has a default
1226 /// argument.
1227 bool hasDefaultArgument() const { return DefaultArgument.isSet(); }
1228
1229 /// Retrieve the default argument, if any.
1231 static const TemplateArgumentLoc NoneLoc;
1232 return DefaultArgument.isSet() ? *DefaultArgument.get() : NoneLoc;
1233 }
1234
1235 /// Retrieves the location of the default argument declaration.
1237
1238 /// Determines whether the default argument was inherited
1239 /// from a previous declaration of this template.
1241 return DefaultArgument.isInherited();
1242 }
1243
1244 /// Set the default argument for this template parameter.
1245 void setDefaultArgument(const ASTContext &C,
1246 const TemplateArgumentLoc &DefArg);
1247
1248 /// Set that this default argument was inherited from another
1249 /// parameter.
1251 TemplateTypeParmDecl *Prev) {
1252 DefaultArgument.setInherited(C, Prev);
1253 }
1254
1255 /// Removes the default argument of this template parameter.
1257 DefaultArgument.clear();
1258 }
1259
1260 /// Set whether this template type parameter was declared with
1261 /// the 'typename' or 'class' keyword.
1262 void setDeclaredWithTypename(bool withTypename) { Typename = withTypename; }
1263
1264 /// Retrieve the depth of the template parameter.
1265 unsigned getDepth() const;
1266
1267 /// Retrieve the index of the template parameter.
1268 unsigned getIndex() const;
1269
1270 /// Returns whether this is a parameter pack.
1271 bool isParameterPack() const;
1272
1273 /// Whether this parameter pack is a pack expansion.
1274 ///
1275 /// A template type template parameter pack can be a pack expansion if its
1276 /// type-constraint contains an unexpanded parameter pack.
1277 bool isPackExpansion() const {
1278 if (!isParameterPack())
1279 return false;
1280 if (const TypeConstraint *TC = getTypeConstraint())
1281 if (TC->hasExplicitTemplateArgs())
1282 for (const auto &ArgLoc : TC->getTemplateArgsAsWritten()->arguments())
1283 if (ArgLoc.getArgument().containsUnexpandedParameterPack())
1284 return true;
1285 return false;
1286 }
1287
1288 /// Whether this parameter is a template type parameter pack that has a known
1289 /// list of different type-constraints at different positions.
1290 ///
1291 /// A parameter pack is an expanded parameter pack when the original
1292 /// parameter pack's type-constraint was itself a pack expansion, and that
1293 /// expansion has already been expanded. For example, given:
1294 ///
1295 /// \code
1296 /// template<typename ...Types>
1297 /// struct X {
1298 /// template<convertible_to<Types> ...Convertibles>
1299 /// struct Y { /* ... */ };
1300 /// };
1301 /// \endcode
1302 ///
1303 /// The parameter pack \c Convertibles has (convertible_to<Types> && ...) as
1304 /// its type-constraint. When \c Types is supplied with template arguments by
1305 /// instantiating \c X, the instantiation of \c Convertibles becomes an
1306 /// expanded parameter pack. For example, instantiating
1307 /// \c X<int, unsigned int> results in \c Convertibles being an expanded
1308 /// parameter pack of size 2 (use getNumExpansionTypes() to get this number).
1309 bool isExpandedParameterPack() const { return ExpandedParameterPack; }
1310
1311 /// Retrieves the number of parameters in an expanded parameter pack.
1312 unsigned getNumExpansionParameters() const {
1313 assert(ExpandedParameterPack && "Not an expansion parameter pack");
1314 return NumExpanded;
1315 }
1316
1317 /// Returns the type constraint associated with this template parameter (if
1318 /// any).
1320 return TypeConstraintInitialized ? getTrailingObjects<TypeConstraint>() :
1321 nullptr;
1322 }
1323
1325 Expr *ImmediatelyDeclaredConstraint);
1326
1327 /// Determine whether this template parameter has a type-constraint.
1328 bool hasTypeConstraint() const {
1329 return HasTypeConstraint;
1330 }
1331
1332 /// \brief Get the associated-constraints of this template parameter.
1333 /// This will either be the immediately-introduced constraint or empty.
1334 ///
1335 /// Use this instead of getTypeConstraint for concepts APIs that
1336 /// accept an ArrayRef of constraint expressions.
1338 if (HasTypeConstraint)
1339 AC.push_back(getTypeConstraint()->getImmediatelyDeclaredConstraint());
1340 }
1341
1342 SourceRange getSourceRange() const override LLVM_READONLY;
1343
1344 // Implement isa/cast/dyncast/etc.
1345 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1346 static bool classofKind(Kind K) { return K == TemplateTypeParm; }
1347};
1348
1349/// NonTypeTemplateParmDecl - Declares a non-type template parameter,
1350/// e.g., "Size" in
1351/// @code
1352/// template<int Size> class array { };
1353/// @endcode
1355 : public DeclaratorDecl,
1356 protected TemplateParmPosition,
1357 private llvm::TrailingObjects<NonTypeTemplateParmDecl,
1358 std::pair<QualType, TypeSourceInfo *>,
1359 Expr *> {
1360 friend class ASTDeclReader;
1361 friend TrailingObjects;
1362
1363 /// The default template argument, if any, and whether or not
1364 /// it was inherited.
1365 using DefArgStorage =
1367 DefArgStorage DefaultArgument;
1368
1369 // FIXME: Collapse this into TemplateParamPosition; or, just move depth/index
1370 // down here to save memory.
1371
1372 /// Whether this non-type template parameter is a parameter pack.
1373 bool ParameterPack;
1374
1375 /// Whether this non-type template parameter is an "expanded"
1376 /// parameter pack, meaning that its type is a pack expansion and we
1377 /// already know the set of types that expansion expands to.
1378 bool ExpandedParameterPack = false;
1379
1380 /// The number of types in an expanded parameter pack.
1381 unsigned NumExpandedTypes = 0;
1382
1383 size_t numTrailingObjects(
1384 OverloadToken<std::pair<QualType, TypeSourceInfo *>>) const {
1385 return NumExpandedTypes;
1386 }
1387
1389 SourceLocation IdLoc, unsigned D, unsigned P,
1390 const IdentifierInfo *Id, QualType T,
1391 bool ParameterPack, TypeSourceInfo *TInfo)
1392 : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc),
1393 TemplateParmPosition(D, P), ParameterPack(ParameterPack) {}
1394
1395 NonTypeTemplateParmDecl(DeclContext *DC, SourceLocation StartLoc,
1396 SourceLocation IdLoc, unsigned D, unsigned P,
1397 const IdentifierInfo *Id, QualType T,
1398 TypeSourceInfo *TInfo,
1399 ArrayRef<QualType> ExpandedTypes,
1400 ArrayRef<TypeSourceInfo *> ExpandedTInfos);
1401
1402public:
1403 static NonTypeTemplateParmDecl *
1404 Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1405 SourceLocation IdLoc, unsigned D, unsigned P, const IdentifierInfo *Id,
1406 QualType T, bool ParameterPack, TypeSourceInfo *TInfo);
1407
1408 static NonTypeTemplateParmDecl *
1409 Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1410 SourceLocation IdLoc, unsigned D, unsigned P, const IdentifierInfo *Id,
1411 QualType T, TypeSourceInfo *TInfo, ArrayRef<QualType> ExpandedTypes,
1412 ArrayRef<TypeSourceInfo *> ExpandedTInfos);
1413
1414 static NonTypeTemplateParmDecl *
1415 CreateDeserialized(ASTContext &C, GlobalDeclID ID, bool HasTypeConstraint);
1416 static NonTypeTemplateParmDecl *CreateDeserialized(ASTContext &C,
1417 GlobalDeclID ID,
1418 unsigned NumExpandedTypes,
1419 bool HasTypeConstraint);
1420
1426
1427 SourceRange getSourceRange() const override LLVM_READONLY;
1428
1429 const DefArgStorage &getDefaultArgStorage() const { return DefaultArgument; }
1430
1431 /// Determine whether this template parameter has a default
1432 /// argument.
1433 bool hasDefaultArgument() const { return DefaultArgument.isSet(); }
1434
1435 /// Retrieve the default argument, if any.
1437 static const TemplateArgumentLoc NoneLoc;
1438 return DefaultArgument.isSet() ? *DefaultArgument.get() : NoneLoc;
1439 }
1440
1441 /// Retrieve the location of the default argument, if any.
1443
1444 /// Determines whether the default argument was inherited
1445 /// from a previous declaration of this template.
1447 return DefaultArgument.isInherited();
1448 }
1449
1450 /// Set the default argument for this template parameter, and
1451 /// whether that default argument was inherited from another
1452 /// declaration.
1453 void setDefaultArgument(const ASTContext &C,
1454 const TemplateArgumentLoc &DefArg);
1457 DefaultArgument.setInherited(C, Parm);
1458 }
1459
1460 /// Removes the default argument of this template parameter.
1461 void removeDefaultArgument() { DefaultArgument.clear(); }
1462
1463 /// Whether this parameter is a non-type template parameter pack.
1464 ///
1465 /// If the parameter is a parameter pack, the type may be a
1466 /// \c PackExpansionType. In the following example, the \c Dims parameter
1467 /// is a parameter pack (whose type is 'unsigned').
1468 ///
1469 /// \code
1470 /// template<typename T, unsigned ...Dims> struct multi_array;
1471 /// \endcode
1472 bool isParameterPack() const { return ParameterPack; }
1473
1474 /// Whether this parameter pack is a pack expansion.
1475 ///
1476 /// A non-type template parameter pack is a pack expansion if its type
1477 /// contains an unexpanded parameter pack. In this case, we will have
1478 /// built a PackExpansionType wrapping the type.
1479 bool isPackExpansion() const {
1480 return ParameterPack && getType()->getAs<PackExpansionType>();
1481 }
1482
1483 /// Whether this parameter is a non-type template parameter pack
1484 /// that has a known list of different types at different positions.
1485 ///
1486 /// A parameter pack is an expanded parameter pack when the original
1487 /// parameter pack's type was itself a pack expansion, and that expansion
1488 /// has already been expanded. For example, given:
1489 ///
1490 /// \code
1491 /// template<typename ...Types>
1492 /// struct X {
1493 /// template<Types ...Values>
1494 /// struct Y { /* ... */ };
1495 /// };
1496 /// \endcode
1497 ///
1498 /// The parameter pack \c Values has a \c PackExpansionType as its type,
1499 /// which expands \c Types. When \c Types is supplied with template arguments
1500 /// by instantiating \c X, the instantiation of \c Values becomes an
1501 /// expanded parameter pack. For example, instantiating
1502 /// \c X<int, unsigned int> results in \c Values being an expanded parameter
1503 /// pack with expansion types \c int and \c unsigned int.
1504 ///
1505 /// The \c getExpansionType() and \c getExpansionTypeSourceInfo() functions
1506 /// return the expansion types.
1507 bool isExpandedParameterPack() const { return ExpandedParameterPack; }
1508
1509 /// Retrieves the number of expansion types in an expanded parameter
1510 /// pack.
1511 unsigned getNumExpansionTypes() const {
1512 assert(ExpandedParameterPack && "Not an expansion parameter pack");
1513 return NumExpandedTypes;
1514 }
1515
1516 /// Retrieve a particular expansion type within an expanded parameter
1517 /// pack.
1518 QualType getExpansionType(unsigned I) const {
1519 assert(I < NumExpandedTypes && "Out-of-range expansion type index");
1520 auto TypesAndInfos =
1521 getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>();
1522 return TypesAndInfos[I].first;
1523 }
1524
1525 /// Retrieve a particular expansion type source info within an
1526 /// expanded parameter pack.
1528 assert(I < NumExpandedTypes && "Out-of-range expansion type index");
1529 auto TypesAndInfos =
1530 getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>();
1531 return TypesAndInfos[I].second;
1532 }
1533
1534 /// Return the constraint introduced by the placeholder type of this non-type
1535 /// template parameter (if any).
1537 return hasPlaceholderTypeConstraint() ? *getTrailingObjects<Expr *>() :
1538 nullptr;
1539 }
1540
1542 *getTrailingObjects<Expr *>() = E;
1543 }
1544
1545 /// Determine whether this non-type template parameter's type has a
1546 /// placeholder with a type-constraint.
1548 auto *AT = getType()->getContainedAutoType();
1549 return AT && AT->isConstrained();
1550 }
1551
1552 /// \brief Get the associated-constraints of this template parameter.
1553 /// This will either be a vector of size 1 containing the immediately-declared
1554 /// constraint introduced by the placeholder type, or an empty vector.
1555 ///
1556 /// Use this instead of getPlaceholderImmediatelyDeclaredConstraint for
1557 /// concepts APIs that accept an ArrayRef of constraint expressions.
1560 AC.push_back(E);
1561 }
1562
1563 // Implement isa/cast/dyncast/etc.
1564 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1565 static bool classofKind(Kind K) { return K == NonTypeTemplateParm; }
1566};
1567
1568/// TemplateTemplateParmDecl - Declares a template template parameter,
1569/// e.g., "T" in
1570/// @code
1571/// template <template <typename> class T> class container { };
1572/// @endcode
1573/// A template template parameter is a TemplateDecl because it defines the
1574/// name of a template and the template parameters allowable for substitution.
1576 : public TemplateDecl,
1577 protected TemplateParmPosition,
1578 private llvm::TrailingObjects<TemplateTemplateParmDecl,
1579 TemplateParameterList *> {
1580 /// The default template argument, if any.
1581 using DefArgStorage =
1583 DefArgStorage DefaultArgument;
1584
1585 /// Whether this template template parameter was declaration with
1586 /// the 'typename' keyword.
1587 ///
1588 /// If false, it was declared with the 'class' keyword.
1589 LLVM_PREFERRED_TYPE(bool)
1590 unsigned Typename : 1;
1591
1592 /// Whether this parameter is a parameter pack.
1593 LLVM_PREFERRED_TYPE(bool)
1594 unsigned ParameterPack : 1;
1595
1596 /// Whether this template template parameter is an "expanded"
1597 /// parameter pack, meaning that it is a pack expansion and we
1598 /// already know the set of template parameters that expansion expands to.
1599 LLVM_PREFERRED_TYPE(bool)
1600 unsigned ExpandedParameterPack : 1;
1601
1602 /// The number of parameters in an expanded parameter pack.
1603 unsigned NumExpandedParams = 0;
1604
1606 unsigned P, bool ParameterPack, IdentifierInfo *Id,
1607 bool Typename, TemplateParameterList *Params)
1608 : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params),
1610 ParameterPack(ParameterPack), ExpandedParameterPack(false) {}
1611
1613 unsigned P, IdentifierInfo *Id, bool Typename,
1614 TemplateParameterList *Params,
1616
1617 void anchor() override;
1618
1619public:
1620 friend class ASTDeclReader;
1621 friend class ASTDeclWriter;
1623
1625 SourceLocation L, unsigned D,
1626 unsigned P, bool ParameterPack,
1627 IdentifierInfo *Id, bool Typename,
1628 TemplateParameterList *Params);
1630 Create(const ASTContext &C, DeclContext *DC, SourceLocation L, unsigned D,
1631 unsigned P, IdentifierInfo *Id, bool Typename,
1632 TemplateParameterList *Params,
1634
1638 CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumExpansions);
1639
1645
1646 /// Whether this template template parameter was declared with
1647 /// the 'typename' keyword.
1648 bool wasDeclaredWithTypename() const { return Typename; }
1649
1650 /// Set whether this template template parameter was declared with
1651 /// the 'typename' or 'class' keyword.
1652 void setDeclaredWithTypename(bool withTypename) { Typename = withTypename; }
1653
1654 /// Whether this template template parameter is a template
1655 /// parameter pack.
1656 ///
1657 /// \code
1658 /// template<template <class T> ...MetaFunctions> struct Apply;
1659 /// \endcode
1660 bool isParameterPack() const { return ParameterPack; }
1661
1662 /// Whether this parameter pack is a pack expansion.
1663 ///
1664 /// A template template parameter pack is a pack expansion if its template
1665 /// parameter list contains an unexpanded parameter pack.
1666 bool isPackExpansion() const {
1667 return ParameterPack &&
1669 }
1670
1671 /// Whether this parameter is a template template parameter pack that
1672 /// has a known list of different template parameter lists at different
1673 /// positions.
1674 ///
1675 /// A parameter pack is an expanded parameter pack when the original parameter
1676 /// pack's template parameter list was itself a pack expansion, and that
1677 /// expansion has already been expanded. For exampe, given:
1678 ///
1679 /// \code
1680 /// template<typename...Types> struct Outer {
1681 /// template<template<Types> class...Templates> struct Inner;
1682 /// };
1683 /// \endcode
1684 ///
1685 /// The parameter pack \c Templates is a pack expansion, which expands the
1686 /// pack \c Types. When \c Types is supplied with template arguments by
1687 /// instantiating \c Outer, the instantiation of \c Templates is an expanded
1688 /// parameter pack.
1689 bool isExpandedParameterPack() const { return ExpandedParameterPack; }
1690
1691 /// Retrieves the number of expansion template parameters in
1692 /// an expanded parameter pack.
1694 assert(ExpandedParameterPack && "Not an expansion parameter pack");
1695 return NumExpandedParams;
1696 }
1697
1698 /// Retrieve a particular expansion type within an expanded parameter
1699 /// pack.
1701 assert(I < NumExpandedParams && "Out-of-range expansion type index");
1702 return getTrailingObjects<TemplateParameterList *>()[I];
1703 }
1704
1705 const DefArgStorage &getDefaultArgStorage() const { return DefaultArgument; }
1706
1707 /// Determine whether this template parameter has a default
1708 /// argument.
1709 bool hasDefaultArgument() const { return DefaultArgument.isSet(); }
1710
1711 /// Retrieve the default argument, if any.
1713 static const TemplateArgumentLoc NoneLoc;
1714 return DefaultArgument.isSet() ? *DefaultArgument.get() : NoneLoc;
1715 }
1716
1717 /// Retrieve the location of the default argument, if any.
1719
1720 /// Determines whether the default argument was inherited
1721 /// from a previous declaration of this template.
1723 return DefaultArgument.isInherited();
1724 }
1725
1726 /// Set the default argument for this template parameter, and
1727 /// whether that default argument was inherited from another
1728 /// declaration.
1729 void setDefaultArgument(const ASTContext &C,
1730 const TemplateArgumentLoc &DefArg);
1733 DefaultArgument.setInherited(C, Prev);
1734 }
1735
1736 /// Removes the default argument of this template parameter.
1737 void removeDefaultArgument() { DefaultArgument.clear(); }
1738
1739 SourceRange getSourceRange() const override LLVM_READONLY {
1743 return SourceRange(getTemplateParameters()->getTemplateLoc(), End);
1744 }
1745
1746 // Implement isa/cast/dyncast/etc.
1747 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1748 static bool classofKind(Kind K) { return K == TemplateTemplateParm; }
1749};
1750
1751/// Represents the builtin template declaration which is used to
1752/// implement __make_integer_seq and other builtin templates. It serves
1753/// no real purpose beyond existing as a place to hold template parameters.
1756
1759
1760 void anchor() override;
1761
1762public:
1763 // Implement isa/cast/dyncast support
1764 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1765 static bool classofKind(Kind K) { return K == BuiltinTemplate; }
1766
1768 DeclarationName Name,
1769 BuiltinTemplateKind BTK) {
1770 return new (C, DC) BuiltinTemplateDecl(C, DC, Name, BTK);
1771 }
1772
1773 SourceRange getSourceRange() const override LLVM_READONLY {
1774 return {};
1775 }
1776
1778};
1779
1780/// Provides information about an explicit instantiation of a variable or class
1781/// template.
1783 /// The template arguments as written..
1785
1786 /// The location of the extern keyword.
1788
1789 /// The location of the template keyword.
1791
1793};
1794
1796 llvm::PointerUnion<const ASTTemplateArgumentListInfo *,
1798
1799/// Represents a class template specialization, which refers to
1800/// a class template with a given set of template arguments.
1801///
1802/// Class template specializations represent both explicit
1803/// specialization of class templates, as in the example below, and
1804/// implicit instantiations of class templates.
1805///
1806/// \code
1807/// template<typename T> class array;
1808///
1809/// template<>
1810/// class array<bool> { }; // class template specialization array<bool>
1811/// \endcode
1813 public llvm::FoldingSetNode {
1814 /// Structure that stores information about a class template
1815 /// specialization that was instantiated from a class template partial
1816 /// specialization.
1817 struct SpecializedPartialSpecialization {
1818 /// The class template partial specialization from which this
1819 /// class template specialization was instantiated.
1820 ClassTemplatePartialSpecializationDecl *PartialSpecialization;
1821
1822 /// The template argument list deduced for the class template
1823 /// partial specialization itself.
1824 const TemplateArgumentList *TemplateArgs;
1825 };
1826
1827 /// The template that this specialization specializes
1828 llvm::PointerUnion<ClassTemplateDecl *, SpecializedPartialSpecialization *>
1829 SpecializedTemplate;
1830
1831 /// Further info for explicit template specialization/instantiation.
1832 /// Does not apply to implicit specializations.
1833 SpecializationOrInstantiationInfo ExplicitInfo = nullptr;
1834
1835 /// The template arguments used to describe this specialization.
1836 const TemplateArgumentList *TemplateArgs;
1837
1838 /// The point where this template was instantiated (if any)
1839 SourceLocation PointOfInstantiation;
1840
1841 /// The kind of specialization this declaration refers to.
1842 LLVM_PREFERRED_TYPE(TemplateSpecializationKind)
1843 unsigned SpecializationKind : 3;
1844
1845protected:
1847 DeclContext *DC, SourceLocation StartLoc,
1848 SourceLocation IdLoc,
1849 ClassTemplateDecl *SpecializedTemplate,
1852
1854
1855public:
1856 friend class ASTDeclReader;
1857 friend class ASTDeclWriter;
1858
1860 Create(ASTContext &Context, TagKind TK, DeclContext *DC,
1861 SourceLocation StartLoc, SourceLocation IdLoc,
1862 ClassTemplateDecl *SpecializedTemplate,
1867
1868 void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy,
1869 bool Qualified) const override;
1870
1871 // FIXME: This is broken. CXXRecordDecl::getMostRecentDecl() returns a
1872 // different "most recent" declaration from this function for the same
1873 // declaration, because we don't override getMostRecentDeclImpl(). But
1874 // it's not clear that we should override that, because the most recent
1875 // declaration as a CXXRecordDecl sometimes is the injected-class-name.
1877 return cast<ClassTemplateSpecializationDecl>(
1879 }
1880
1881 /// Retrieve the template that this specialization specializes.
1883
1884 /// Retrieve the template arguments of the class template
1885 /// specialization.
1887 return *TemplateArgs;
1888 }
1889
1891 TemplateArgs = Args;
1892 }
1893
1894 /// Determine the kind of specialization that this
1895 /// declaration represents.
1897 return static_cast<TemplateSpecializationKind>(SpecializationKind);
1898 }
1899
1902 }
1903
1904 /// Is this an explicit specialization at class scope (within the class that
1905 /// owns the primary template)? For example:
1906 ///
1907 /// \code
1908 /// template<typename T> struct Outer {
1909 /// template<typename U> struct Inner;
1910 /// template<> struct Inner; // class-scope explicit specialization
1911 /// };
1912 /// \endcode
1914 return isExplicitSpecialization() &&
1915 isa<CXXRecordDecl>(getLexicalDeclContext());
1916 }
1917
1918 /// True if this declaration is an explicit specialization,
1919 /// explicit instantiation declaration, or explicit instantiation
1920 /// definition.
1924 }
1925
1927 SpecializedTemplate = Specialized;
1928 }
1929
1931 SpecializationKind = TSK;
1932 }
1933
1934 /// Get the point of instantiation (if any), or null if none.
1936 return PointOfInstantiation;
1937 }
1938
1940 assert(Loc.isValid() && "point of instantiation must be valid!");
1941 PointOfInstantiation = Loc;
1942 }
1943
1944 /// If this class template specialization is an instantiation of
1945 /// a template (rather than an explicit specialization), return the
1946 /// class template or class template partial specialization from which it
1947 /// was instantiated.
1948 llvm::PointerUnion<ClassTemplateDecl *,
1952 return llvm::PointerUnion<ClassTemplateDecl *,
1954
1956 }
1957
1958 /// Retrieve the class template or class template partial
1959 /// specialization which was specialized by this.
1960 llvm::PointerUnion<ClassTemplateDecl *,
1963 if (const auto *PartialSpec =
1964 SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
1965 return PartialSpec->PartialSpecialization;
1966
1967 return cast<ClassTemplateDecl *>(SpecializedTemplate);
1968 }
1969
1970 /// Retrieve the set of template arguments that should be used
1971 /// to instantiate members of the class template or class template partial
1972 /// specialization from which this class template specialization was
1973 /// instantiated.
1974 ///
1975 /// \returns For a class template specialization instantiated from the primary
1976 /// template, this function will return the same template arguments as
1977 /// getTemplateArgs(). For a class template specialization instantiated from
1978 /// a class template partial specialization, this function will return the
1979 /// deduced template arguments for the class template partial specialization
1980 /// itself.
1982 if (const auto *PartialSpec =
1983 SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
1984 return *PartialSpec->TemplateArgs;
1985
1986 return getTemplateArgs();
1987 }
1988
1989 /// Note that this class template specialization is actually an
1990 /// instantiation of the given class template partial specialization whose
1991 /// template arguments have been deduced.
1993 const TemplateArgumentList *TemplateArgs) {
1994 assert(!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) &&
1995 "Already set to a class template partial specialization!");
1996 auto *PS = new (getASTContext()) SpecializedPartialSpecialization();
1997 PS->PartialSpecialization = PartialSpec;
1998 PS->TemplateArgs = TemplateArgs;
1999 SpecializedTemplate = PS;
2000 }
2001
2002 /// Note that this class template specialization is an instantiation
2003 /// of the given class template.
2005 assert(!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) &&
2006 "Previously set to a class template partial specialization!");
2007 SpecializedTemplate = TemplDecl;
2008 }
2009
2010 /// Retrieve the template argument list as written in the sources,
2011 /// if any.
2013 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2014 return Info->TemplateArgsAsWritten;
2015 return cast<const ASTTemplateArgumentListInfo *>(ExplicitInfo);
2016 }
2017
2018 /// Set the template argument list as written in the sources.
2019 void
2021 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2022 Info->TemplateArgsAsWritten = ArgsWritten;
2023 else
2024 ExplicitInfo = ArgsWritten;
2025 }
2026
2027 /// Set the template argument list as written in the sources.
2031 }
2032
2033 /// Gets the location of the extern keyword, if present.
2035 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2036 return Info->ExternKeywordLoc;
2037 return SourceLocation();
2038 }
2039
2040 /// Sets the location of the extern keyword.
2042
2043 /// Gets the location of the template keyword, if present.
2045 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2046 return Info->TemplateKeywordLoc;
2047 return SourceLocation();
2048 }
2049
2050 /// Sets the location of the template keyword.
2052
2053 SourceRange getSourceRange() const override LLVM_READONLY;
2054
2055 void Profile(llvm::FoldingSetNodeID &ID) const {
2056 Profile(ID, TemplateArgs->asArray(), getASTContext());
2057 }
2058
2059 static void
2060 Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
2061 const ASTContext &Context) {
2062 ID.AddInteger(TemplateArgs.size());
2063 for (const TemplateArgument &TemplateArg : TemplateArgs)
2064 TemplateArg.Profile(ID, Context);
2065 }
2066
2067 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2068
2069 static bool classofKind(Kind K) {
2070 return K >= firstClassTemplateSpecialization &&
2071 K <= lastClassTemplateSpecialization;
2072 }
2073};
2074
2077 /// The list of template parameters
2078 TemplateParameterList *TemplateParams = nullptr;
2079
2080 /// The class template partial specialization from which this
2081 /// class template partial specialization was instantiated.
2082 ///
2083 /// The boolean value will be true to indicate that this class template
2084 /// partial specialization was specialized at this level.
2085 llvm::PointerIntPair<ClassTemplatePartialSpecializationDecl *, 1, bool>
2086 InstantiatedFromMember;
2087
2089 ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc,
2091 ClassTemplateDecl *SpecializedTemplate, ArrayRef<TemplateArgument> Args,
2093
2095 : ClassTemplateSpecializationDecl(C, ClassTemplatePartialSpecialization),
2096 InstantiatedFromMember(nullptr, false) {}
2097
2098 void anchor() override;
2099
2100public:
2101 friend class ASTDeclReader;
2102 friend class ASTDeclWriter;
2103
2105 Create(ASTContext &Context, TagKind TK, DeclContext *DC,
2106 SourceLocation StartLoc, SourceLocation IdLoc,
2107 TemplateParameterList *Params, ClassTemplateDecl *SpecializedTemplate,
2108 ArrayRef<TemplateArgument> Args, QualType CanonInjectedType,
2110
2113
2115 return cast<ClassTemplatePartialSpecializationDecl>(
2116 static_cast<ClassTemplateSpecializationDecl *>(
2117 this)->getMostRecentDecl());
2118 }
2119
2120 /// Get the list of template parameters
2122 return TemplateParams;
2123 }
2124
2125 /// Get the template argument list of the template parameter list.
2127 getInjectedTemplateArgs(const ASTContext &Context) const {
2129 }
2130
2131 /// \brief All associated constraints of this partial specialization,
2132 /// including the requires clause and any constraints derived from
2133 /// constrained-parameters.
2134 ///
2135 /// The constraints in the resulting list are to be treated as if in a
2136 /// conjunction ("and").
2138 TemplateParams->getAssociatedConstraints(AC);
2139 }
2140
2142 return TemplateParams->hasAssociatedConstraints();
2143 }
2144
2145 /// Retrieve the member class template partial specialization from
2146 /// which this particular class template partial specialization was
2147 /// instantiated.
2148 ///
2149 /// \code
2150 /// template<typename T>
2151 /// struct Outer {
2152 /// template<typename U> struct Inner;
2153 /// template<typename U> struct Inner<U*> { }; // #1
2154 /// };
2155 ///
2156 /// Outer<float>::Inner<int*> ii;
2157 /// \endcode
2158 ///
2159 /// In this example, the instantiation of \c Outer<float>::Inner<int*> will
2160 /// end up instantiating the partial specialization
2161 /// \c Outer<float>::Inner<U*>, which itself was instantiated from the class
2162 /// template partial specialization \c Outer<T>::Inner<U*>. Given
2163 /// \c Outer<float>::Inner<U*>, this function would return
2164 /// \c Outer<T>::Inner<U*>.
2166 const auto *First =
2167 cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2168 return First->InstantiatedFromMember.getPointer();
2169 }
2173 }
2174
2177 auto *First = cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2178 First->InstantiatedFromMember.setPointer(PartialSpec);
2179 }
2180
2181 /// Determines whether this class template partial specialization
2182 /// template was a specialization of a member partial specialization.
2183 ///
2184 /// In the following example, the member template partial specialization
2185 /// \c X<int>::Inner<T*> is a member specialization.
2186 ///
2187 /// \code
2188 /// template<typename T>
2189 /// struct X {
2190 /// template<typename U> struct Inner;
2191 /// template<typename U> struct Inner<U*>;
2192 /// };
2193 ///
2194 /// template<> template<typename T>
2195 /// struct X<int>::Inner<T*> { /* ... */ };
2196 /// \endcode
2198 const auto *First =
2199 cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2200 return First->InstantiatedFromMember.getInt();
2201 }
2202
2203 /// Note that this member template is a specialization.
2205 auto *First = cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2206 assert(First->InstantiatedFromMember.getPointer() &&
2207 "Only member templates can be member template specializations");
2208 return First->InstantiatedFromMember.setInt(true);
2209 }
2210
2211 /// Retrieves the injected specialization type for this partial
2212 /// specialization. This is not the same as the type-decl-type for
2213 /// this partial specialization, which is an InjectedClassNameType.
2215 assert(getTypeForDecl() && "partial specialization has no type set!");
2216 return cast<InjectedClassNameType>(getTypeForDecl())
2217 ->getInjectedSpecializationType();
2218 }
2219
2220 SourceRange getSourceRange() const override LLVM_READONLY;
2221
2222 void Profile(llvm::FoldingSetNodeID &ID) const {
2224 getASTContext());
2225 }
2226
2227 static void
2228 Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
2229 TemplateParameterList *TPL, const ASTContext &Context);
2230
2231 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2232
2233 static bool classofKind(Kind K) {
2234 return K == ClassTemplatePartialSpecialization;
2235 }
2236};
2237
2238/// Declaration of a class template.
2240protected:
2241 /// Data that is common to all of the declarations of a given
2242 /// class template.
2244 /// The class template specializations for this class
2245 /// template, including explicit specializations and instantiations.
2246 llvm::FoldingSetVector<ClassTemplateSpecializationDecl> Specializations;
2247
2248 /// The class template partial specializations for this class
2249 /// template.
2250 llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>
2252
2253 /// The injected-class-name type for this class template.
2255
2256 Common() = default;
2257 };
2258
2259 /// Retrieve the set of specializations of this class template.
2260 llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
2261 getSpecializations() const;
2262
2263 /// Retrieve the set of partial specializations of this class
2264 /// template.
2265 llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
2267
2270 NamedDecl *Decl)
2271 : RedeclarableTemplateDecl(ClassTemplate, C, DC, L, Name, Params, Decl) {}
2272
2273 CommonBase *newCommon(ASTContext &C) const override;
2274
2276 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
2277 }
2278
2280
2281public:
2282
2283 friend class ASTDeclReader;
2284 friend class ASTDeclWriter;
2286
2287 /// Load any lazily-loaded specializations from the external source.
2288 void LoadLazySpecializations(bool OnlyPartial = false) const;
2289
2290 /// Get the underlying class declarations of the template.
2292 return static_cast<CXXRecordDecl *>(TemplatedDecl);
2293 }
2294
2295 /// Returns whether this template declaration defines the primary
2296 /// class pattern.
2299 }
2300
2301 /// \brief Create a class template node.
2304 DeclarationName Name,
2305 TemplateParameterList *Params,
2306 NamedDecl *Decl);
2307
2308 /// Create an empty class template node.
2310
2311 /// Return the specialization with the provided arguments if it exists,
2312 /// otherwise return the insertion point.
2314 findSpecialization(ArrayRef<TemplateArgument> Args, void *&InsertPos);
2315
2316 /// Insert the specified specialization knowing that it is not already
2317 /// in. InsertPos must be obtained from findSpecialization.
2318 void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos);
2319
2321 return cast<ClassTemplateDecl>(
2323 }
2325 return cast<ClassTemplateDecl>(
2327 }
2328
2329 /// Retrieve the previous declaration of this class template, or
2330 /// nullptr if no such declaration exists.
2332 return cast_or_null<ClassTemplateDecl>(
2333 static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
2334 }
2336 return cast_or_null<ClassTemplateDecl>(
2337 static_cast<const RedeclarableTemplateDecl *>(
2338 this)->getPreviousDecl());
2339 }
2340
2342 return cast<ClassTemplateDecl>(
2343 static_cast<RedeclarableTemplateDecl *>(this)->getMostRecentDecl());
2344 }
2346 return const_cast<ClassTemplateDecl*>(this)->getMostRecentDecl();
2347 }
2348
2350 return cast_or_null<ClassTemplateDecl>(
2352 }
2353
2354 /// Return the partial specialization with the provided arguments if it
2355 /// exists, otherwise return the insertion point.
2358 TemplateParameterList *TPL, void *&InsertPos);
2359
2360 /// Insert the specified partial specialization knowing that it is not
2361 /// already in. InsertPos must be obtained from findPartialSpecialization.
2363 void *InsertPos);
2364
2365 /// Retrieve the partial specializations as an ordered list.
2368
2369 /// Find a class template partial specialization with the given
2370 /// type T.
2371 ///
2372 /// \param T a dependent type that names a specialization of this class
2373 /// template.
2374 ///
2375 /// \returns the class template partial specialization that exactly matches
2376 /// the type \p T, or nullptr if no such partial specialization exists.
2378
2379 /// Find a class template partial specialization which was instantiated
2380 /// from the given member partial specialization.
2381 ///
2382 /// \param D a member class template partial specialization.
2383 ///
2384 /// \returns the class template partial specialization which was instantiated
2385 /// from the given member partial specialization, or nullptr if no such
2386 /// partial specialization exists.
2390
2391 /// Retrieve the template specialization type of the
2392 /// injected-class-name for this class template.
2393 ///
2394 /// The injected-class-name for a class template \c X is \c
2395 /// X<template-args>, where \c template-args is formed from the
2396 /// template arguments that correspond to the template parameters of
2397 /// \c X. For example:
2398 ///
2399 /// \code
2400 /// template<typename T, int N>
2401 /// struct array {
2402 /// typedef array this_type; // "array" is equivalent to "array<T, N>"
2403 /// };
2404 /// \endcode
2406
2408 using spec_range = llvm::iterator_range<spec_iterator>;
2409
2411 return spec_range(spec_begin(), spec_end());
2412 }
2413
2415 return makeSpecIterator(getSpecializations(), false);
2416 }
2417
2419 return makeSpecIterator(getSpecializations(), true);
2420 }
2421
2422 // Implement isa/cast/dyncast support
2423 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2424 static bool classofKind(Kind K) { return K == ClassTemplate; }
2425};
2426
2427/// Declaration of a friend template.
2428///
2429/// For example:
2430/// \code
2431/// template <typename T> class A {
2432/// friend class MyVector<T>; // not a friend template
2433/// template <typename U> friend class B; // not a friend template
2434/// template <typename U> friend class Foo<T>::Nested; // friend template
2435/// };
2436/// \endcode
2437///
2438/// \note This class is not currently in use. All of the above
2439/// will yield a FriendDecl, not a FriendTemplateDecl.
2440class FriendTemplateDecl : public Decl {
2441 virtual void anchor();
2442
2443public:
2444 using FriendUnion = llvm::PointerUnion<NamedDecl *,TypeSourceInfo *>;
2445
2446private:
2447 // The number of template parameters; always non-zero.
2448 unsigned NumParams = 0;
2449
2450 // The parameter list.
2451 TemplateParameterList **Params = nullptr;
2452
2453 // The declaration that's a friend of this class.
2454 FriendUnion Friend;
2455
2456 // Location of the 'friend' specifier.
2457 SourceLocation FriendLoc;
2458
2460 TemplateParameterList **Params, unsigned NumParams,
2461 FriendUnion Friend, SourceLocation FriendLoc)
2462 : Decl(Decl::FriendTemplate, DC, Loc), NumParams(NumParams),
2463 Params(Params), Friend(Friend), FriendLoc(FriendLoc) {}
2464
2465 FriendTemplateDecl(EmptyShell Empty) : Decl(Decl::FriendTemplate, Empty) {}
2466
2467public:
2468 friend class ASTDeclReader;
2469
2470 static FriendTemplateDecl *
2473 SourceLocation FriendLoc);
2474
2476
2477 /// If this friend declaration names a templated type (or
2478 /// a dependent member type of a templated type), return that
2479 /// type; otherwise return null.
2481 return Friend.dyn_cast<TypeSourceInfo*>();
2482 }
2483
2484 /// If this friend declaration names a templated function (or
2485 /// a member function of a templated type), return that type;
2486 /// otherwise return null.
2488 return Friend.dyn_cast<NamedDecl*>();
2489 }
2490
2491 /// Retrieves the location of the 'friend' keyword.
2493 return FriendLoc;
2494 }
2495
2497 assert(i <= NumParams);
2498 return Params[i];
2499 }
2500
2501 unsigned getNumTemplateParameters() const {
2502 return NumParams;
2503 }
2504
2505 // Implement isa/cast/dyncast/etc.
2506 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2507 static bool classofKind(Kind K) { return K == Decl::FriendTemplate; }
2508};
2509
2510/// Declaration of an alias template.
2511///
2512/// For example:
2513/// \code
2514/// template <typename T> using V = std::map<T*, int, MyCompare<T>>;
2515/// \endcode
2517protected:
2519
2522 NamedDecl *Decl)
2523 : RedeclarableTemplateDecl(TypeAliasTemplate, C, DC, L, Name, Params,
2524 Decl) {}
2525
2526 CommonBase *newCommon(ASTContext &C) const override;
2527
2529 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
2530 }
2531
2532public:
2533 friend class ASTDeclReader;
2534 friend class ASTDeclWriter;
2535
2536 /// Get the underlying function declaration of the template.
2538 return static_cast<TypeAliasDecl *>(TemplatedDecl);
2539 }
2540
2541
2543 return cast<TypeAliasTemplateDecl>(
2545 }
2547 return cast<TypeAliasTemplateDecl>(
2549 }
2550
2551 /// Retrieve the previous declaration of this function template, or
2552 /// nullptr if no such declaration exists.
2554 return cast_or_null<TypeAliasTemplateDecl>(
2555 static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
2556 }
2558 return cast_or_null<TypeAliasTemplateDecl>(
2559 static_cast<const RedeclarableTemplateDecl *>(
2560 this)->getPreviousDecl());
2561 }
2562
2564 return cast_or_null<TypeAliasTemplateDecl>(
2566 }
2567
2568 /// Create a function template node.
2571 DeclarationName Name,
2572 TemplateParameterList *Params,
2573 NamedDecl *Decl);
2574
2575 /// Create an empty alias template node.
2578
2579 // Implement isa/cast/dyncast support
2580 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2581 static bool classofKind(Kind K) { return K == TypeAliasTemplate; }
2582};
2583
2584/// Represents a variable template specialization, which refers to
2585/// a variable template with a given set of template arguments.
2586///
2587/// Variable template specializations represent both explicit
2588/// specializations of variable templates, as in the example below, and
2589/// implicit instantiations of variable templates.
2590///
2591/// \code
2592/// template<typename T> constexpr T pi = T(3.1415926535897932385);
2593///
2594/// template<>
2595/// constexpr float pi<float>; // variable template specialization pi<float>
2596/// \endcode
2598 public llvm::FoldingSetNode {
2599
2600 /// Structure that stores information about a variable template
2601 /// specialization that was instantiated from a variable template partial
2602 /// specialization.
2603 struct SpecializedPartialSpecialization {
2604 /// The variable template partial specialization from which this
2605 /// variable template specialization was instantiated.
2606 VarTemplatePartialSpecializationDecl *PartialSpecialization;
2607
2608 /// The template argument list deduced for the variable template
2609 /// partial specialization itself.
2610 const TemplateArgumentList *TemplateArgs;
2611 };
2612
2613 /// The template that this specialization specializes.
2614 llvm::PointerUnion<VarTemplateDecl *, SpecializedPartialSpecialization *>
2615 SpecializedTemplate;
2616
2617 /// Further info for explicit template specialization/instantiation.
2618 /// Does not apply to implicit specializations.
2619 SpecializationOrInstantiationInfo ExplicitInfo = nullptr;
2620
2621 /// The template arguments used to describe this specialization.
2622 const TemplateArgumentList *TemplateArgs;
2623
2624 /// The point where this template was instantiated (if any).
2625 SourceLocation PointOfInstantiation;
2626
2627 /// The kind of specialization this declaration refers to.
2628 LLVM_PREFERRED_TYPE(TemplateSpecializationKind)
2629 unsigned SpecializationKind : 3;
2630
2631 /// Whether this declaration is a complete definition of the
2632 /// variable template specialization. We can't otherwise tell apart
2633 /// an instantiated declaration from an instantiated definition with
2634 /// no initializer.
2635 LLVM_PREFERRED_TYPE(bool)
2636 unsigned IsCompleteDefinition : 1;
2637
2638protected:
2640 SourceLocation StartLoc, SourceLocation IdLoc,
2641 VarTemplateDecl *SpecializedTemplate,
2642 QualType T, TypeSourceInfo *TInfo,
2643 StorageClass S,
2645
2646 explicit VarTemplateSpecializationDecl(Kind DK, ASTContext &Context);
2647
2648public:
2649 friend class ASTDeclReader;
2650 friend class ASTDeclWriter;
2651 friend class VarDecl;
2652
2654 Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
2655 SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
2656 TypeSourceInfo *TInfo, StorageClass S,
2660
2661 void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy,
2662 bool Qualified) const override;
2663
2665 VarDecl *Recent = static_cast<VarDecl *>(this)->getMostRecentDecl();
2666 return cast<VarTemplateSpecializationDecl>(Recent);
2667 }
2668
2669 /// Retrieve the template that this specialization specializes.
2671
2672 /// Retrieve the template arguments of the variable template
2673 /// specialization.
2674 const TemplateArgumentList &getTemplateArgs() const { return *TemplateArgs; }
2675
2676 /// Determine the kind of specialization that this
2677 /// declaration represents.
2679 return static_cast<TemplateSpecializationKind>(SpecializationKind);
2680 }
2681
2684 }
2685
2687 return isExplicitSpecialization() &&
2688 isa<CXXRecordDecl>(getLexicalDeclContext());
2689 }
2690
2691 /// True if this declaration is an explicit specialization,
2692 /// explicit instantiation declaration, or explicit instantiation
2693 /// definition.
2697 }
2698
2700 SpecializationKind = TSK;
2701 }
2702
2703 /// Get the point of instantiation (if any), or null if none.
2705 return PointOfInstantiation;
2706 }
2707
2709 assert(Loc.isValid() && "point of instantiation must be valid!");
2710 PointOfInstantiation = Loc;
2711 }
2712
2713 void setCompleteDefinition() { IsCompleteDefinition = true; }
2714
2715 /// If this variable template specialization is an instantiation of
2716 /// a template (rather than an explicit specialization), return the
2717 /// variable template or variable template partial specialization from which
2718 /// it was instantiated.
2719 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
2722 return llvm::PointerUnion<VarTemplateDecl *,
2724
2726 }
2727
2728 /// Retrieve the variable template or variable template partial
2729 /// specialization which was specialized by this.
2730 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
2732 if (const auto *PartialSpec =
2733 SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
2734 return PartialSpec->PartialSpecialization;
2735
2736 return cast<VarTemplateDecl *>(SpecializedTemplate);
2737 }
2738
2739 /// Retrieve the set of template arguments that should be used
2740 /// to instantiate the initializer of the variable template or variable
2741 /// template partial specialization from which this variable template
2742 /// specialization was instantiated.
2743 ///
2744 /// \returns For a variable template specialization instantiated from the
2745 /// primary template, this function will return the same template arguments
2746 /// as getTemplateArgs(). For a variable template specialization instantiated
2747 /// from a variable template partial specialization, this function will the
2748 /// return deduced template arguments for the variable template partial
2749 /// specialization itself.
2751 if (const auto *PartialSpec =
2752 SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
2753 return *PartialSpec->TemplateArgs;
2754
2755 return getTemplateArgs();
2756 }
2757
2758 /// Note that this variable template specialization is actually an
2759 /// instantiation of the given variable template partial specialization whose
2760 /// template arguments have been deduced.
2762 const TemplateArgumentList *TemplateArgs) {
2763 assert(!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) &&
2764 "Already set to a variable template partial specialization!");
2765 auto *PS = new (getASTContext()) SpecializedPartialSpecialization();
2766 PS->PartialSpecialization = PartialSpec;
2767 PS->TemplateArgs = TemplateArgs;
2768 SpecializedTemplate = PS;
2769 }
2770
2771 /// Note that this variable template specialization is an instantiation
2772 /// of the given variable template.
2774 assert(!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) &&
2775 "Previously set to a variable template partial specialization!");
2776 SpecializedTemplate = TemplDecl;
2777 }
2778
2779 /// Retrieve the template argument list as written in the sources,
2780 /// if any.
2782 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2783 return Info->TemplateArgsAsWritten;
2784 return cast<const ASTTemplateArgumentListInfo *>(ExplicitInfo);
2785 }
2786
2787 /// Set the template argument list as written in the sources.
2788 void
2790 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2791 Info->TemplateArgsAsWritten = ArgsWritten;
2792 else
2793 ExplicitInfo = ArgsWritten;
2794 }
2795
2796 /// Set the template argument list as written in the sources.
2800 }
2801
2802 /// Gets the location of the extern keyword, if present.
2804 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2805 return Info->ExternKeywordLoc;
2806 return SourceLocation();
2807 }
2808
2809 /// Sets the location of the extern keyword.
2811
2812 /// Gets the location of the template keyword, if present.
2814 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2815 return Info->TemplateKeywordLoc;
2816 return SourceLocation();
2817 }
2818
2819 /// Sets the location of the template keyword.
2821
2822 SourceRange getSourceRange() const override LLVM_READONLY;
2823
2824 void Profile(llvm::FoldingSetNodeID &ID) const {
2825 Profile(ID, TemplateArgs->asArray(), getASTContext());
2826 }
2827
2828 static void Profile(llvm::FoldingSetNodeID &ID,
2829 ArrayRef<TemplateArgument> TemplateArgs,
2830 const ASTContext &Context) {
2831 ID.AddInteger(TemplateArgs.size());
2832 for (const TemplateArgument &TemplateArg : TemplateArgs)
2833 TemplateArg.Profile(ID, Context);
2834 }
2835
2836 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2837
2838 static bool classofKind(Kind K) {
2839 return K >= firstVarTemplateSpecialization &&
2840 K <= lastVarTemplateSpecialization;
2841 }
2842};
2843
2846 /// The list of template parameters
2847 TemplateParameterList *TemplateParams = nullptr;
2848
2849 /// The variable template partial specialization from which this
2850 /// variable template partial specialization was instantiated.
2851 ///
2852 /// The boolean value will be true to indicate that this variable template
2853 /// partial specialization was specialized at this level.
2854 llvm::PointerIntPair<VarTemplatePartialSpecializationDecl *, 1, bool>
2855 InstantiatedFromMember;
2856
2858 ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
2860 VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
2862
2864 : VarTemplateSpecializationDecl(VarTemplatePartialSpecialization,
2865 Context),
2866 InstantiatedFromMember(nullptr, false) {}
2867
2868 void anchor() override;
2869
2870public:
2871 friend class ASTDeclReader;
2872 friend class ASTDeclWriter;
2873
2875 Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
2877 VarTemplateDecl *SpecializedTemplate, QualType T,
2878 TypeSourceInfo *TInfo, StorageClass S,
2880
2883
2885 return cast<VarTemplatePartialSpecializationDecl>(
2886 static_cast<VarTemplateSpecializationDecl *>(
2887 this)->getMostRecentDecl());
2888 }
2889
2890 /// Get the list of template parameters
2892 return TemplateParams;
2893 }
2894
2895 /// Get the template argument list of the template parameter list.
2897 getInjectedTemplateArgs(const ASTContext &Context) const {
2899 }
2900
2901 /// \brief All associated constraints of this partial specialization,
2902 /// including the requires clause and any constraints derived from
2903 /// constrained-parameters.
2904 ///
2905 /// The constraints in the resulting list are to be treated as if in a
2906 /// conjunction ("and").
2908 TemplateParams->getAssociatedConstraints(AC);
2909 }
2910
2912 return TemplateParams->hasAssociatedConstraints();
2913 }
2914
2915 /// \brief Retrieve the member variable template partial specialization from
2916 /// which this particular variable template partial specialization was
2917 /// instantiated.
2918 ///
2919 /// \code
2920 /// template<typename T>
2921 /// struct Outer {
2922 /// template<typename U> U Inner;
2923 /// template<typename U> U* Inner<U*> = (U*)(0); // #1
2924 /// };
2925 ///
2926 /// template int* Outer<float>::Inner<int*>;
2927 /// \endcode
2928 ///
2929 /// In this example, the instantiation of \c Outer<float>::Inner<int*> will
2930 /// end up instantiating the partial specialization
2931 /// \c Outer<float>::Inner<U*>, which itself was instantiated from the
2932 /// variable template partial specialization \c Outer<T>::Inner<U*>. Given
2933 /// \c Outer<float>::Inner<U*>, this function would return
2934 /// \c Outer<T>::Inner<U*>.
2936 const auto *First =
2937 cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2938 return First->InstantiatedFromMember.getPointer();
2939 }
2940
2941 void
2943 auto *First = cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2944 First->InstantiatedFromMember.setPointer(PartialSpec);
2945 }
2946
2947 /// Determines whether this variable template partial specialization
2948 /// was a specialization of a member partial specialization.
2949 ///
2950 /// In the following example, the member template partial specialization
2951 /// \c X<int>::Inner<T*> is a member specialization.
2952 ///
2953 /// \code
2954 /// template<typename T>
2955 /// struct X {
2956 /// template<typename U> U Inner;
2957 /// template<typename U> U* Inner<U*> = (U*)(0);
2958 /// };
2959 ///
2960 /// template<> template<typename T>
2961 /// U* X<int>::Inner<T*> = (T*)(0) + 1;
2962 /// \endcode
2964 const auto *First =
2965 cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2966 return First->InstantiatedFromMember.getInt();
2967 }
2968
2969 /// Note that this member template is a specialization.
2971 auto *First = cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2972 assert(First->InstantiatedFromMember.getPointer() &&
2973 "Only member templates can be member template specializations");
2974 return First->InstantiatedFromMember.setInt(true);
2975 }
2976
2977 SourceRange getSourceRange() const override LLVM_READONLY;
2978
2979 void Profile(llvm::FoldingSetNodeID &ID) const {
2981 getASTContext());
2982 }
2983
2984 static void
2985 Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
2986 TemplateParameterList *TPL, const ASTContext &Context);
2987
2988 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2989
2990 static bool classofKind(Kind K) {
2991 return K == VarTemplatePartialSpecialization;
2992 }
2993};
2994
2995/// Declaration of a variable template.
2997protected:
2998 /// Data that is common to all of the declarations of a given
2999 /// variable template.
3001 /// The variable template specializations for this variable
3002 /// template, including explicit specializations and instantiations.
3003 llvm::FoldingSetVector<VarTemplateSpecializationDecl> Specializations;
3004
3005 /// The variable template partial specializations for this variable
3006 /// template.
3007 llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl>
3009
3010 Common() = default;
3011 };
3012
3013 /// Retrieve the set of specializations of this variable template.
3014 llvm::FoldingSetVector<VarTemplateSpecializationDecl> &
3015 getSpecializations() const;
3016
3017 /// Retrieve the set of partial specializations of this class
3018 /// template.
3019 llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &
3021
3024 NamedDecl *Decl)
3025 : RedeclarableTemplateDecl(VarTemplate, C, DC, L, Name, Params, Decl) {}
3026
3027 CommonBase *newCommon(ASTContext &C) const override;
3028
3030 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
3031 }
3032
3033public:
3034 friend class ASTDeclReader;
3035 friend class ASTDeclWriter;
3036
3037 /// Load any lazily-loaded specializations from the external source.
3038 void LoadLazySpecializations(bool OnlyPartial = false) const;
3039
3040 /// Get the underlying variable declarations of the template.
3042 return static_cast<VarDecl *>(TemplatedDecl);
3043 }
3044
3045 /// Returns whether this template declaration defines the primary
3046 /// variable pattern.
3049 }
3050
3052
3053 /// Create a variable template node.
3056 TemplateParameterList *Params,
3057 VarDecl *Decl);
3058
3059 /// Create an empty variable template node.
3061
3062 /// Return the specialization with the provided arguments if it exists,
3063 /// otherwise return the insertion point.
3065 findSpecialization(ArrayRef<TemplateArgument> Args, void *&InsertPos);
3066
3067 /// Insert the specified specialization knowing that it is not already
3068 /// in. InsertPos must be obtained from findSpecialization.
3069 void AddSpecialization(VarTemplateSpecializationDecl *D, void *InsertPos);
3070
3072 return cast<VarTemplateDecl>(RedeclarableTemplateDecl::getCanonicalDecl());
3073 }
3075 return cast<VarTemplateDecl>(RedeclarableTemplateDecl::getCanonicalDecl());
3076 }
3077
3078 /// Retrieve the previous declaration of this variable template, or
3079 /// nullptr if no such declaration exists.
3081 return cast_or_null<VarTemplateDecl>(
3082 static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
3083 }
3085 return cast_or_null<VarTemplateDecl>(
3086 static_cast<const RedeclarableTemplateDecl *>(
3087 this)->getPreviousDecl());
3088 }
3089
3091 return cast<VarTemplateDecl>(
3092 static_cast<RedeclarableTemplateDecl *>(this)->getMostRecentDecl());
3093 }
3095 return const_cast<VarTemplateDecl *>(this)->getMostRecentDecl();
3096 }
3097
3099 return cast_or_null<VarTemplateDecl>(
3101 }
3102
3103 /// Return the partial specialization with the provided arguments if it
3104 /// exists, otherwise return the insertion point.
3107 TemplateParameterList *TPL, void *&InsertPos);
3108
3109 /// Insert the specified partial specialization knowing that it is not
3110 /// already in. InsertPos must be obtained from findPartialSpecialization.
3112 void *InsertPos);
3113
3114 /// Retrieve the partial specializations as an ordered list.
3117
3118 /// Find a variable template partial specialization which was
3119 /// instantiated
3120 /// from the given member partial specialization.
3121 ///
3122 /// \param D a member variable template partial specialization.
3123 ///
3124 /// \returns the variable template partial specialization which was
3125 /// instantiated
3126 /// from the given member partial specialization, or nullptr if no such
3127 /// partial specialization exists.
3130
3132 using spec_range = llvm::iterator_range<spec_iterator>;
3133
3135 return spec_range(spec_begin(), spec_end());
3136 }
3137
3139 return makeSpecIterator(getSpecializations(), false);
3140 }
3141
3143 return makeSpecIterator(getSpecializations(), true);
3144 }
3145
3146 // Implement isa/cast/dyncast support
3147 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3148 static bool classofKind(Kind K) { return K == VarTemplate; }
3149};
3150
3151/// Declaration of a C++20 concept.
3152class ConceptDecl : public TemplateDecl, public Mergeable<ConceptDecl> {
3153protected:
3155
3158 : TemplateDecl(Concept, DC, L, Name, Params),
3160public:
3162 DeclarationName Name,
3163 TemplateParameterList *Params,
3164 Expr *ConstraintExpr = nullptr);
3166
3168 return ConstraintExpr;
3169 }
3170
3171 bool hasDefinition() const { return ConstraintExpr != nullptr; }
3172
3174
3175 SourceRange getSourceRange() const override LLVM_READONLY {
3176 return SourceRange(getTemplateParameters()->getTemplateLoc(),
3178 : SourceLocation());
3179 }
3180
3181 bool isTypeConcept() const {
3182 return isa<TemplateTypeParmDecl>(getTemplateParameters()->getParam(0));
3183 }
3184
3186 return cast<ConceptDecl>(getPrimaryMergedDecl(this));
3187 }
3189 return const_cast<ConceptDecl *>(this)->getCanonicalDecl();
3190 }
3191
3192 // Implement isa/cast/dyncast/etc.
3193 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3194 static bool classofKind(Kind K) { return K == Concept; }
3195
3196 friend class ASTReader;
3197 friend class ASTDeclReader;
3198 friend class ASTDeclWriter;
3199};
3200
3201// An implementation detail of ConceptSpecialicationExpr that holds the template
3202// arguments, so we can later use this to reconstitute the template arguments
3203// during constraint checking.
3205 : public Decl,
3206 private llvm::TrailingObjects<ImplicitConceptSpecializationDecl,
3207 TemplateArgument> {
3208 unsigned NumTemplateArgs;
3209
3211 ArrayRef<TemplateArgument> ConvertedArgs);
3212 ImplicitConceptSpecializationDecl(EmptyShell Empty, unsigned NumTemplateArgs);
3213
3214public:
3217 ArrayRef<TemplateArgument> ConvertedArgs);
3220 unsigned NumTemplateArgs);
3221
3223 return ArrayRef<TemplateArgument>(getTrailingObjects<TemplateArgument>(),
3224 NumTemplateArgs);
3225 }
3227
3228 static bool classofKind(Kind K) { return K == ImplicitConceptSpecialization; }
3229 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3230
3232 friend class ASTDeclReader;
3233};
3234
3235/// A template parameter object.
3236///
3237/// Template parameter objects represent values of class type used as template
3238/// arguments. There is one template parameter object for each such distinct
3239/// value used as a template argument across the program.
3240///
3241/// \code
3242/// struct A { int x, y; };
3243/// template<A> struct S;
3244/// S<A{1, 2}> s1;
3245/// S<A{1, 2}> s2; // same type, argument is same TemplateParamObjectDecl.
3246/// \endcode
3248 public Mergeable<TemplateParamObjectDecl>,
3249 public llvm::FoldingSetNode {
3250private:
3251 /// The value of this template parameter object.
3252 APValue Value;
3253
3255 : ValueDecl(TemplateParamObject, DC, SourceLocation(), DeclarationName(),
3256 T),
3257 Value(V) {}
3258
3260 const APValue &V);
3261 static TemplateParamObjectDecl *CreateDeserialized(ASTContext &C,
3263
3264 /// Only ASTContext::getTemplateParamObjectDecl and deserialization
3265 /// create these.
3266 friend class ASTContext;
3267 friend class ASTReader;
3268 friend class ASTDeclReader;
3269
3270public:
3271 /// Print this template parameter object in a human-readable format.
3272 void printName(llvm::raw_ostream &OS,
3273 const PrintingPolicy &Policy) const override;
3274
3275 /// Print this object as an equivalent expression.
3276 void printAsExpr(llvm::raw_ostream &OS) const;
3277 void printAsExpr(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const;
3278
3279 /// Print this object as an initializer suitable for a variable of the
3280 /// object's type.
3281 void printAsInit(llvm::raw_ostream &OS) const;
3282 void printAsInit(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const;
3283
3284 const APValue &getValue() const { return Value; }
3285
3286 static void Profile(llvm::FoldingSetNodeID &ID, QualType T,
3287 const APValue &V) {
3288 ID.AddPointer(T.getCanonicalType().getAsOpaquePtr());
3289 V.Profile(ID);
3290 }
3291 void Profile(llvm::FoldingSetNodeID &ID) {
3292 Profile(ID, getType(), getValue());
3293 }
3294
3296 return getFirstDecl();
3297 }
3299 return getFirstDecl();
3300 }
3301
3302 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3303 static bool classofKind(Kind K) { return K == TemplateParamObject; }
3304};
3305
3307 if (auto *PD = P.dyn_cast<TemplateTypeParmDecl *>())
3308 return PD;
3309 if (auto *PD = P.dyn_cast<NonTypeTemplateParmDecl *>())
3310 return PD;
3311 return cast<TemplateTemplateParmDecl *>(P);
3312}
3313
3315 auto *TD = dyn_cast<TemplateDecl>(D);
3316 return TD && (isa<ClassTemplateDecl>(TD) ||
3317 isa<ClassTemplatePartialSpecializationDecl>(TD) ||
3318 isa<TypeAliasTemplateDecl>(TD) ||
3319 isa<TemplateTemplateParmDecl>(TD))
3320 ? TD
3321 : nullptr;
3322}
3323
3324/// Check whether the template parameter is a pack expansion, and if so,
3325/// determine the number of parameters produced by that expansion. For instance:
3326///
3327/// \code
3328/// template<typename ...Ts> struct A {
3329/// template<Ts ...NTs, template<Ts> class ...TTs, typename ...Us> struct B;
3330/// };
3331/// \endcode
3332///
3333/// In \c A<int,int>::B, \c NTs and \c TTs have expanded pack size 2, and \c Us
3334/// is not a pack expansion, so returns an empty Optional.
3335inline std::optional<unsigned> getExpandedPackSize(const NamedDecl *Param) {
3336 if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
3337 if (TTP->isExpandedParameterPack())
3338 return TTP->getNumExpansionParameters();
3339 }
3340
3341 if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
3342 if (NTTP->isExpandedParameterPack())
3343 return NTTP->getNumExpansionTypes();
3344 }
3345
3346 if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(Param)) {
3347 if (TTP->isExpandedParameterPack())
3348 return TTP->getNumExpansionTemplateParameters();
3349 }
3350
3351 return std::nullopt;
3352}
3353
3354/// Internal helper used by Subst* nodes to retrieve the parameter list
3355/// for their AssociatedDecl.
3356TemplateParameterList *getReplacedTemplateParameterList(Decl *D);
3357
3358} // namespace clang
3359
3360#endif // LLVM_CLANG_AST_DECLTEMPLATE_H
This file provides AST data structures related to concepts.
Defines the clang::ASTContext interface.
#define V(N, I)
Definition: ASTContext.h:3443
StringRef P
static char ID
Definition: Arena.cpp:183
const Decl * D
Expr * E
enum clang::sema::@1712::IndirectLocalPathEntry::EntryKind Kind
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
uint32_t Id
Definition: SemaARM.cpp:1134
SourceLocation Loc
Definition: SemaObjC.cpp:759
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
C Language Family Type Representation.
__device__ int
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:383
bool isConstrained() const
Definition: Type.h:6575
Represents the builtin template declaration which is used to implement __make_integer_seq and other b...
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
BuiltinTemplateKind getBuiltinTemplateKind() const
static BuiltinTemplateDecl * Create(const ASTContext &C, DeclContext *DC, DeclarationName Name, BuiltinTemplateKind BTK)
static bool classof(const Decl *D)
static bool classofKind(Kind K)
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
CXXRecordDecl * getMostRecentNonInjectedDecl()
Definition: DeclCXX.h:550
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
Definition: DeclCXX.cpp:1999
Declaration of a class template.
void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D, void *InsertPos)
Insert the specified partial specialization knowing that it is not already in.
llvm::FoldingSetVector< ClassTemplateSpecializationDecl > & getSpecializations() const
Retrieve the set of specializations of this class template.
ClassTemplateDecl * getMostRecentDecl()
spec_iterator spec_begin() const
spec_iterator spec_end() const
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
static bool classofKind(Kind K)
llvm::FoldingSetVector< ClassTemplatePartialSpecializationDecl > & getPartialSpecializations() const
Retrieve the set of partial specializations of this class template.
ClassTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, TemplateParameterList *TPL, void *&InsertPos)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
ClassTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
CommonBase * newCommon(ASTContext &C) const override
llvm::iterator_range< spec_iterator > spec_range
static bool classof(const Decl *D)
const ClassTemplateDecl * getMostRecentDecl() const
ClassTemplateDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this template.
ClassTemplatePartialSpecializationDecl * findPartialSpecInstantiatedFromMember(ClassTemplatePartialSpecializationDecl *D)
Find a class template partial specialization which was instantiated from the given member partial spe...
const ClassTemplateDecl * getCanonicalDecl() const
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary class pattern.
ClassTemplateDecl * getPreviousDecl()
Retrieve the previous declaration of this class template, or nullptr if no such declaration exists.
void LoadLazySpecializations(bool OnlyPartial=false) const
Load any lazily-loaded specializations from the external source.
void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
const ClassTemplateDecl * getPreviousDecl() const
ClassTemplateDecl * getInstantiatedFromMemberTemplate() const
void setCommonPtr(Common *C)
spec_range specializations() const
QualType getInjectedClassNameSpecialization()
Retrieve the template specialization type of the injected-class-name for this class template.
Common * getCommonPtr() const
ClassTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
static ClassTemplateDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Create an empty class template node.
ClassTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member class template partial specialization from which this particular class template p...
ClassTemplatePartialSpecializationDecl * getInstantiatedFromMemberTemplate() const
ClassTemplatePartialSpecializationDecl * getMostRecentDecl()
void setInstantiatedFromMember(ClassTemplatePartialSpecializationDecl *PartialSpec)
void getAssociatedConstraints(llvm::SmallVectorImpl< const Expr * > &AC) const
All associated constraints of this partial specialization, including the requires clause and any cons...
void Profile(llvm::FoldingSetNodeID &ID) const
bool isMemberSpecialization() const
Determines whether this class template partial specialization template was a specialization of a memb...
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
ArrayRef< TemplateArgument > getInjectedTemplateArgs(const ASTContext &Context) const
Get the template argument list of the template parameter list.
void setMemberSpecialization()
Note that this member template is a specialization.
QualType getInjectedSpecializationType() const
Retrieves the injected specialization type for this partial specialization.
static ClassTemplatePartialSpecializationDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a class template specialization, which refers to a class template with a given set of temp...
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
bool isClassScopeExplicitSpecialization() const
Is this an explicit specialization at class scope (within the class that owns the primary template)?...
static ClassTemplateSpecializationDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
ClassTemplateSpecializationDecl * getMostRecentDecl()
llvm::PointerUnion< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > getSpecializedTemplateOrPartial() const
Retrieve the class template or class template partial specialization which was specialized by this.
void setTemplateArgs(TemplateArgumentList *Args)
void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const override
Appends a human-readable name for this declaration into the given stream.
void setPointOfInstantiation(SourceLocation Loc)
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
static bool classof(const Decl *D)
void setExternKeywordLoc(SourceLocation Loc)
Sets the location of the extern keyword.
void setSpecializationKind(TemplateSpecializationKind TSK)
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
SourceLocation getExternKeywordLoc() const
Gets the location of the extern keyword, if present.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
static void Profile(llvm::FoldingSetNodeID &ID, ArrayRef< TemplateArgument > TemplateArgs, const ASTContext &Context)
void setInstantiationOf(ClassTemplateDecl *TemplDecl)
Note that this class template specialization is an instantiation of the given class template.
SourceLocation getTemplateKeywordLoc() const
Gets the location of the template keyword, if present.
void setTemplateArgsAsWritten(const TemplateArgumentListInfo &ArgsInfo)
Set the template argument list as written in the sources.
void setTemplateKeywordLoc(SourceLocation Loc)
Sets the location of the template keyword.
const TemplateArgumentList & getTemplateInstantiationArgs() const
Retrieve the set of template arguments that should be used to instantiate members of the class templa...
llvm::PointerUnion< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > getInstantiatedFrom() const
If this class template specialization is an instantiation of a template (rather than an explicit spec...
void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs)
Note that this class template specialization is actually an instantiation of the given class template...
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration,...
void setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten)
Set the template argument list as written in the sources.
void Profile(llvm::FoldingSetNodeID &ID) const
void setSpecializedTemplate(ClassTemplateDecl *Specialized)
Declaration of a C++20 concept.
void setDefinition(Expr *E)
Expr * getConstraintExpr() const
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
ConceptDecl(DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, Expr *ConstraintExpr)
static ConceptDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
bool isTypeConcept() const
ConceptDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
bool hasDefinition() const
static bool classof(const Decl *D)
const ConceptDecl * getCanonicalDecl() const
static bool classofKind(Kind K)
A reference to a concept and its template args, as it appears in the code.
Definition: ASTConcept.h:124
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1435
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:520
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:596
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:89
SourceLocation getLocation() const
Definition: DeclBase.h:442
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition: DeclBase.h:907
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
Definition: DeclBase.h:430
The name of a declaration.
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:735
Storage for a default argument.
Definition: DeclTemplate.h:305
void setInherited(const ASTContext &C, ParmDecl *InheritedFrom)
Set that the default argument was inherited from another parameter.
Definition: DeclTemplate.h:365
bool isSet() const
Determine whether there is a default argument for this parameter.
Definition: DeclTemplate.h:331
ArgType get() const
Get the default argument's value.
Definition: DeclTemplate.h:339
void set(ArgType Arg)
Set the default argument.
Definition: DeclTemplate.h:359
void clear()
Remove the default argument, even if it was inherited.
Definition: DeclTemplate.h:385
const ParmDecl * getInheritedFrom() const
Get the parameter from which we inherit the default argument, if any.
Definition: DeclTemplate.h:350
bool isInherited() const
Determine whether the default argument for this parameter was inherited from a previous declaration o...
Definition: DeclTemplate.h:335
Provides information about a dependent function-template specialization declaration.
Definition: DeclTemplate.h:694
ArrayRef< FunctionTemplateDecl * > getCandidates() const
Returns the candidates for the primary function template.
Definition: DeclTemplate.h:713
const ASTTemplateArgumentListInfo * TemplateArgumentsAsWritten
The template arguments as written in the sources, if provided.
Definition: DeclTemplate.h:706
This represents one expression.
Definition: Expr.h:110
Stores a list of template parameters and the associated requires-clause (if any) for a TemplateDecl a...
Definition: DeclTemplate.h:228
FixedSizeTemplateParameterListStorage(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
Definition: DeclTemplate.h:235
Declaration of a friend template.
static bool classof(const Decl *D)
SourceLocation getFriendLoc() const
Retrieves the location of the 'friend' keyword.
NamedDecl * getFriendDecl() const
If this friend declaration names a templated function (or a member function of a templated type),...
TemplateParameterList * getTemplateParameterList(unsigned i) const
static bool classofKind(Kind K)
unsigned getNumTemplateParameters() const
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
static FriendTemplateDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
TypeSourceInfo * getFriendType() const
If this friend declaration names a templated type (or a dependent member type of a templated type),...
Represents a function declaration or definition.
Definition: Decl.h:1935
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
Definition: Decl.h:2249
Declaration of a template function.
Definition: DeclTemplate.h:959
FunctionTemplateDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this template.
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
spec_iterator spec_end() const
void addSpecialization(FunctionTemplateSpecializationInfo *Info, void *InsertPos)
Add a specialization of this function template.
CommonBase * newCommon(ASTContext &C) const override
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
FunctionTemplateDecl * getInstantiatedFromMemberTemplate() const
Common * getCommonPtr() const
Definition: DeclTemplate.h:981
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary pattern.
const FunctionTemplateDecl * getPreviousDecl() const
bool isAbbreviated() const
Return whether this function template is an abbreviated function template, e.g.
FunctionTemplateDecl * getMostRecentDecl()
FunctionTemplateDecl * getPreviousDecl()
Retrieve the previous declaration of this function template, or nullptr if no such declaration exists...
const FunctionTemplateDecl * getCanonicalDecl() const
static FunctionTemplateDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Create an empty function template node.
spec_range specializations() const
spec_iterator spec_begin() const
FunctionTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Definition: DeclTemplate.h:973
const FunctionTemplateDecl * getMostRecentDecl() const
llvm::iterator_range< spec_iterator > spec_range
static bool classofKind(Kind K)
llvm::FoldingSetVector< FunctionTemplateSpecializationInfo > & getSpecializations() const
Retrieve the set of function template specializations of this function template.
void mergePrevDecl(FunctionTemplateDecl *Prev)
Merge Prev with our RedeclarableTemplateDecl::Common.
void LoadLazySpecializations() const
Load any lazily-loaded specializations from the external source.
static bool classof(const Decl *D)
Provides information about a function template specialization, which is a FunctionDecl that has been ...
Definition: DeclTemplate.h:472
TemplateArgumentList * TemplateArguments
The template arguments used to produce the function template specialization from the function templat...
Definition: DeclTemplate.h:486
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the template specialization kind.
Definition: DeclTemplate.h:547
static void Profile(llvm::FoldingSetNodeID &ID, ArrayRef< TemplateArgument > TemplateArgs, const ASTContext &Context)
Definition: DeclTemplate.h:609
FunctionTemplateDecl * getTemplate() const
Retrieve the template from which this function was specialized.
Definition: DeclTemplate.h:527
MemberSpecializationInfo * getMemberSpecializationInfo() const
Get the specialization info if this function template specialization is also a member specialization:
Definition: DeclTemplate.h:598
const ASTTemplateArgumentListInfo * TemplateArgumentsAsWritten
The template arguments as written in the sources, if provided.
Definition: DeclTemplate.h:490
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this function template specialization.
Definition: DeclTemplate.h:558
void Profile(llvm::FoldingSetNodeID &ID)
Definition: DeclTemplate.h:604
SourceLocation PointOfInstantiation
The point at which this function template specialization was first instantiated.
Definition: DeclTemplate.h:494
FunctionDecl * getFunction() const
Retrieve the declaration of the function template specialization.
Definition: DeclTemplate.h:524
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
Definition: DeclTemplate.h:530
void setPointOfInstantiation(SourceLocation POI)
Set the (first) point of instantiation of this function template specialization.
Definition: DeclTemplate.h:564
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration,...
Definition: DeclTemplate.h:541
One of these records is kept for each identifier that is lexed.
void setTemplateArguments(ArrayRef< TemplateArgument > Converted)
static ImplicitConceptSpecializationDecl * CreateDeserialized(const ASTContext &C, GlobalDeclID ID, unsigned NumTemplateArgs)
ArrayRef< TemplateArgument > getTemplateArguments() const
static bool classof(const Decl *D)
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:620
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the template specialization kind.
Definition: DeclTemplate.h:651
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
Definition: DeclTemplate.h:642
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
Definition: DeclTemplate.h:660
MemberSpecializationInfo(NamedDecl *IF, TemplateSpecializationKind TSK, SourceLocation POI=SourceLocation())
Definition: DeclTemplate.h:630
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
Definition: DeclTemplate.h:665
NamedDecl * getInstantiatedFrom() const
Retrieve the member declaration from which this member was instantiated.
Definition: DeclTemplate.h:639
Provides common interface for the Decls that cannot be redeclared, but can be merged if the same decl...
Definition: Redeclarable.h:313
TemplateParamObjectDecl * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Definition: Redeclarable.h:319
This represents a decl that may have a name.
Definition: Decl.h:253
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
static NonTypeTemplateParmDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, bool HasTypeConstraint)
SourceLocation getDefaultArgumentLoc() const
Retrieve the location of the default argument, if any.
bool isPackExpansion() const
Whether this parameter pack is a pack expansion.
const DefArgStorage & getDefaultArgStorage() const
QualType getExpansionType(unsigned I) const
Retrieve a particular expansion type within an expanded parameter pack.
static bool classofKind(Kind K)
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template.
TypeSourceInfo * getExpansionTypeSourceInfo(unsigned I) const
Retrieve a particular expansion type source info within an expanded parameter pack.
static bool classof(const Decl *D)
unsigned getNumExpansionTypes() const
Retrieves the number of expansion types in an expanded parameter pack.
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
bool isExpandedParameterPack() const
Whether this parameter is a non-type template parameter pack that has a known list of different types...
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
void getAssociatedConstraints(llvm::SmallVectorImpl< const Expr * > &AC) const
Get the associated-constraints of this template parameter.
bool hasPlaceholderTypeConstraint() const
Determine whether this non-type template parameter's type has a placeholder with a type-constraint.
Expr * getPlaceholderTypeConstraint() const
Return the constraint introduced by the placeholder type of this non-type template parameter (if any)...
void setPlaceholderTypeConstraint(Expr *E)
void removeDefaultArgument()
Removes the default argument of this template parameter.
void setInheritedDefaultArgument(const ASTContext &C, NonTypeTemplateParmDecl *Parm)
void setDefaultArgument(const ASTContext &C, const TemplateArgumentLoc &DefArg)
Set the default argument for this template parameter, and whether that default argument was inherited...
Represents a pack expansion of types.
Definition: Type.h:7141
A (possibly-)qualified type.
Definition: Type.h:929
Declaration of a redeclarable template.
Definition: DeclTemplate.h:721
static SpecIterator< EntryType > makeSpecIterator(llvm::FoldingSetVector< EntryType > &Specs, bool isEnd)
Definition: DeclTemplate.h:774
SpecEntryTraits< EntryType >::DeclType * findSpecializationLocally(llvm::FoldingSetVector< EntryType > &Specs, void *&InsertPos, ProfileArguments &&...ProfileArgs)
RedeclarableTemplateDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Definition: DeclTemplate.h:822
redeclarable_base::redecl_iterator redecl_iterator
Definition: DeclTemplate.h:927
void loadLazySpecializationsImpl(bool OnlyPartial=false) const
bool isMemberSpecialization() const
Determines whether this template was a specialization of a member template.
Definition: DeclTemplate.h:859
CommonBase * getCommonPtr() const
Retrieves the "common" pointer shared by all (re-)declarations of the same template.
SpecEntryTraits< EntryType >::DeclType * findSpecializationImpl(llvm::FoldingSetVector< EntryType > &Specs, void *&InsertPos, ProfileArguments &&...ProfileArgs)
const RedeclarableTemplateDecl * getCanonicalDecl() const
Definition: DeclTemplate.h:837
redeclarable_base::redecl_range redecl_range
Definition: DeclTemplate.h:926
CommonBase * Common
Pointer to the common data shared by all declarations of this template.
Definition: DeclTemplate.h:812
static bool classof(const Decl *D)
Definition: DeclTemplate.h:937
RedeclarableTemplateDecl * getInstantiatedFromMemberTemplate() const
Retrieve the member template from which this template was instantiated, or nullptr if this template w...
Definition: DeclTemplate.h:906
static bool classofKind(Kind K)
Definition: DeclTemplate.h:939
virtual CommonBase * newCommon(ASTContext &C) const =0
RedeclarableTemplateDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this template.
Definition: DeclTemplate.h:834
void addSpecializationImpl(llvm::FoldingSetVector< EntryType > &Specs, EntryType *Entry, void *InsertPos)
void setMemberSpecialization()
Note that this member template is a specialization.
Definition: DeclTemplate.h:864
void setInstantiatedFromMemberTemplate(RedeclarableTemplateDecl *TD)
Definition: DeclTemplate.h:910
ArrayRef< TemplateArgument > getInjectedTemplateArgs(const ASTContext &Context) const
Retrieve the "injected" template arguments that correspond to the template parameters of this templat...
Definition: DeclTemplate.h:922
Provides common interface for the Decls that can be redeclared.
Definition: Redeclarable.h:84
RedeclarableTemplateDecl * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Definition: Redeclarable.h:215
RedeclarableTemplateDecl * getNextRedeclaration() const
Definition: Redeclarable.h:187
RedeclarableTemplateDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
Definition: Redeclarable.h:203
llvm::iterator_range< redecl_iterator > redecl_range
Definition: Redeclarable.h:291
RedeclarableTemplateDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
Definition: Redeclarable.h:225
bool isFirstDecl() const
True if this is the first declaration in its redeclaration chain.
Definition: Redeclarable.h:222
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: Redeclarable.h:295
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:463
Encodes a location in the source.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:348
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition: Decl.h:3662
A convenient class for passing around template argument information.
Definition: TemplateBase.h:632
A template argument list.
Definition: DeclTemplate.h:250
TemplateArgumentList(const TemplateArgumentList &)=delete
const TemplateArgument * data() const
Retrieve a pointer to the template argument list.
Definition: DeclTemplate.h:289
const TemplateArgument & operator[](unsigned Idx) const
Retrieve the template argument at a given index.
Definition: DeclTemplate.h:277
static TemplateArgumentList * CreateCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument list that copies the given set of template arguments.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Definition: DeclTemplate.h:286
const TemplateArgument & get(unsigned Idx) const
Retrieve the template argument at a given index.
Definition: DeclTemplate.h:271
TemplateArgumentList & operator=(const TemplateArgumentList &)=delete
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Definition: DeclTemplate.h:280
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:524
SourceRange getSourceRange() const LLVM_READONLY
Represents a template argument.
Definition: TemplateBase.h:61
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:399
NamedDecl * TemplatedDecl
Definition: DeclTemplate.h:449
TemplateParameterList * TemplateParams
Definition: DeclTemplate.h:450
bool isTypeAlias() const
bool hasAssociatedConstraints() const
void init(NamedDecl *NewTemplatedDecl)
Initialize the underlying templated declaration.
Definition: DeclTemplate.h:458
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
Definition: DeclTemplate.h:431
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclTemplate.h:443
TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params)
Definition: DeclTemplate.h:409
void setTemplateParameters(TemplateParameterList *TParams)
Definition: DeclTemplate.h:453
void getAssociatedConstraints(llvm::SmallVectorImpl< const Expr * > &AC) const
Get the total constraint-expression associated with this template, including constraint-expressions d...
static bool classof(const Decl *D)
Definition: DeclTemplate.h:437
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:418
static bool classofKind(Kind K)
Definition: DeclTemplate.h:439
A template parameter object.
TemplateParamObjectDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
void printAsExpr(llvm::raw_ostream &OS) const
Print this object as an equivalent expression.
const TemplateParamObjectDecl * getCanonicalDecl() const
void Profile(llvm::FoldingSetNodeID &ID)
const APValue & getValue() const
static bool classof(const Decl *D)
static void Profile(llvm::FoldingSetNodeID &ID, QualType T, const APValue &V)
void printName(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const override
Print this template parameter object in a human-readable format.
void printAsInit(llvm::raw_ostream &OS) const
Print this object as an initializer suitable for a variable of the object's type.
static bool classofKind(Kind K)
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:73
const_iterator end() const
Definition: DeclTemplate.h:137
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:147
SourceRange getSourceRange() const LLVM_READONLY
Definition: DeclTemplate.h:209
const_iterator begin() const
Definition: DeclTemplate.h:135
ArrayRef< TemplateArgument > getInjectedTemplateArgs(const ASTContext &Context)
Get the template argument list of the template parameter list.
unsigned getDepth() const
Get the depth of this template parameter list in the set of template parameter lists.
const Expr * getRequiresClause() const
The constraint-expression of the associated requires-clause.
Definition: DeclTemplate.h:188
bool hasAssociatedConstraints() const
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to form a template specialization.
size_t numTrailingObjects(OverloadToken< Expr * >) const
Definition: DeclTemplate.h:110
bool hasParameterPack() const
Determine whether this template parameter list contains a parameter pack.
Definition: DeclTemplate.h:175
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
NamedDecl *const * const_iterator
Iterates through the template parameters in this list.
Definition: DeclTemplate.h:132
Expr * getRequiresClause()
The constraint-expression of the associated requires-clause.
Definition: DeclTemplate.h:183
void print(raw_ostream &Out, const ASTContext &Context, const PrintingPolicy &Policy, bool OmitTemplateKW=false) const
SourceLocation getRAngleLoc() const
Definition: DeclTemplate.h:207
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &C) const
const NamedDecl * getParam(unsigned Idx) const
Definition: DeclTemplate.h:151
bool containsUnexpandedParameterPack() const
Determine whether this template parameter list contains an unexpanded parameter pack.
SourceLocation getLAngleLoc() const
Definition: DeclTemplate.h:206
size_t numTrailingObjects(OverloadToken< NamedDecl * >) const
Definition: DeclTemplate.h:106
TemplateParameterList(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
void print(raw_ostream &Out, const ASTContext &Context, bool OmitTemplateKW=false) const
void getAssociatedConstraints(llvm::SmallVectorImpl< const Expr * > &AC) const
All associated constraints derived from this template parameter list, including the requires clause a...
ArrayRef< NamedDecl * > asArray()
Definition: DeclTemplate.h:142
static bool shouldIncludeTypeForArgument(const PrintingPolicy &Policy, const TemplateParameterList *TPL, unsigned Idx)
SourceLocation getTemplateLoc() const
Definition: DeclTemplate.h:205
ArrayRef< const NamedDecl * > asArray() const
Definition: DeclTemplate.h:143
Defines the position of a template parameter within a template parameter list.
static constexpr unsigned MaxPosition
static constexpr unsigned MaxDepth
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
void setPosition(unsigned P)
unsigned getIndex() const
Get the index of the template parameter within its parameter list.
TemplateParmPosition(unsigned D, unsigned P)
unsigned getDepth() const
Get the nesting depth of the template parameter.
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
bool wasDeclaredWithTypename() const
Whether this template template parameter was declared with the 'typename' keyword.
TemplateParameterList * getExpansionTemplateParameters(unsigned I) const
Retrieve a particular expansion type within an expanded parameter pack.
bool isPackExpansion() const
Whether this parameter pack is a pack expansion.
unsigned getNumExpansionTemplateParameters() const
Retrieves the number of expansion template parameters in an expanded parameter pack.
const DefArgStorage & getDefaultArgStorage() const
static bool classof(const Decl *D)
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
void setInheritedDefaultArgument(const ASTContext &C, TemplateTemplateParmDecl *Prev)
static TemplateTemplateParmDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
SourceLocation getDefaultArgumentLoc() const
Retrieve the location of the default argument, if any.
bool isParameterPack() const
Whether this template template parameter is a template parameter pack.
static bool classofKind(Kind K)
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
void setDeclaredWithTypename(bool withTypename)
Set whether this template template parameter was declared with the 'typename' or 'class' keyword.
void setDefaultArgument(const ASTContext &C, const TemplateArgumentLoc &DefArg)
Set the default argument for this template parameter, and whether that default argument was inherited...
bool isExpandedParameterPack() const
Whether this parameter is a template template parameter pack that has a known list of different templ...
void removeDefaultArgument()
Removes the default argument of this template parameter.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
Declaration of a template type parameter.
bool wasDeclaredWithTypename() const
Whether this template type parameter was declared with the 'typename' keyword.
SourceLocation getDefaultArgumentLoc() const
Retrieves the location of the default argument declaration.
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
unsigned getIndex() const
Retrieve the index of the template parameter.
void setInheritedDefaultArgument(const ASTContext &C, TemplateTypeParmDecl *Prev)
Set that this default argument was inherited from another parameter.
static TemplateTypeParmDecl * CreateDeserialized(const ASTContext &C, GlobalDeclID ID)
bool hasTypeConstraint() const
Determine whether this template parameter has a type-constraint.
const TypeConstraint * getTypeConstraint() const
Returns the type constraint associated with this template parameter (if any).
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template.
bool isExpandedParameterPack() const
Whether this parameter is a template type parameter pack that has a known list of different type-cons...
void removeDefaultArgument()
Removes the default argument of this template parameter.
bool isParameterPack() const
Returns whether this is a parameter pack.
unsigned getDepth() const
Retrieve the depth of the template parameter.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
const DefArgStorage & getDefaultArgStorage() const
void setTypeConstraint(ConceptReference *CR, Expr *ImmediatelyDeclaredConstraint)
void setDefaultArgument(const ASTContext &C, const TemplateArgumentLoc &DefArg)
Set the default argument for this template parameter.
unsigned getNumExpansionParameters() const
Retrieves the number of parameters in an expanded parameter pack.
static bool classofKind(Kind K)
static bool classof(const Decl *D)
void getAssociatedConstraints(llvm::SmallVectorImpl< const Expr * > &AC) const
Get the associated-constraints of this template parameter.
void setDeclaredWithTypename(bool withTypename)
Set whether this template type parameter was declared with the 'typename' or 'class' keyword.
bool isPackExpansion() const
Whether this parameter pack is a pack expansion.
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition: Decl.h:3535
Declaration of an alias template.
static bool classof(const Decl *D)
CommonBase * newCommon(ASTContext &C) const override
static TypeAliasTemplateDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Create an empty alias template node.
TypeAliasTemplateDecl * getPreviousDecl()
Retrieve the previous declaration of this function template, or nullptr if no such declaration exists...
const TypeAliasTemplateDecl * getPreviousDecl() const
TypeAliasTemplateDecl * getInstantiatedFromMemberTemplate() const
const TypeAliasTemplateDecl * getCanonicalDecl() const
static bool classofKind(Kind K)
TypeAliasTemplateDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this template.
TypeAliasTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
TypeAliasDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
Definition: ASTConcept.h:227
Represents a declaration of a type.
Definition: Decl.h:3370
const Type * getTypeForDecl() const
Definition: Decl.h:3395
A container of type source information.
Definition: Type.h:7902
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type.
Definition: Type.h:2811
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8731
A set of unresolved declarations.
Definition: UnresolvedSet.h:62
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:671
QualType getType() const
Definition: Decl.h:682
Represents a variable declaration or definition.
Definition: Decl.h:882
DefinitionKind isThisDeclarationADefinition(ASTContext &) const
Check whether this declaration is a definition.
Definition: Decl.cpp:2249
TemplateSpecializationKind getTemplateSpecializationKind() const
If this variable is an instantiation of a variable template or a static data member of a class templa...
Definition: Decl.cpp:2755
Declaration of a variable template.
VarTemplateDecl * getDefinition()
VarDecl * getTemplatedDecl() const
Get the underlying variable declarations of the template.
VarTemplateDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this template.
void AddPartialSpecialization(VarTemplatePartialSpecializationDecl *D, void *InsertPos)
Insert the specified partial specialization knowing that it is not already in.
spec_iterator spec_begin() const
Common * getCommonPtr() const
VarTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, TemplateParameterList *TPL, void *&InsertPos)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
static bool classof(const Decl *D)
const VarTemplateDecl * getPreviousDecl() const
void AddSpecialization(VarTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
VarTemplateDecl * getInstantiatedFromMemberTemplate() const
VarTemplateDecl * getPreviousDecl()
Retrieve the previous declaration of this variable template, or nullptr if no such declaration exists...
CommonBase * newCommon(ASTContext &C) const override
void LoadLazySpecializations(bool OnlyPartial=false) const
Load any lazily-loaded specializations from the external source.
VarTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
const VarTemplateDecl * getCanonicalDecl() const
static VarTemplateDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Create an empty variable template node.
llvm::iterator_range< spec_iterator > spec_range
llvm::FoldingSetVector< VarTemplatePartialSpecializationDecl > & getPartialSpecializations() const
Retrieve the set of partial specializations of this class template.
llvm::FoldingSetVector< VarTemplateSpecializationDecl > & getSpecializations() const
Retrieve the set of specializations of this variable template.
static bool classofKind(Kind K)
const VarTemplateDecl * getMostRecentDecl() const
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary variable pattern.
VarTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
VarTemplatePartialSpecializationDecl * findPartialSpecInstantiatedFromMember(VarTemplatePartialSpecializationDecl *D)
Find a variable template partial specialization which was instantiated from the given member partial ...
spec_iterator spec_end() const
VarTemplateDecl * getMostRecentDecl()
spec_range specializations() const
void setMemberSpecialization()
Note that this member template is a specialization.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
VarTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member variable template partial specialization from which this particular variable temp...
bool isMemberSpecialization() const
Determines whether this variable template partial specialization was a specialization of a member par...
void Profile(llvm::FoldingSetNodeID &ID) const
ArrayRef< TemplateArgument > getInjectedTemplateArgs(const ASTContext &Context) const
Get the template argument list of the template parameter list.
void getAssociatedConstraints(llvm::SmallVectorImpl< const Expr * > &AC) const
All associated constraints of this partial specialization, including the requires clause and any cons...
void setInstantiatedFromMember(VarTemplatePartialSpecializationDecl *PartialSpec)
static VarTemplatePartialSpecializationDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
VarTemplatePartialSpecializationDecl * getMostRecentDecl()
Represents a variable template specialization, which refers to a variable template with a given set o...
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
void setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten)
Set the template argument list as written in the sources.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
void setTemplateKeywordLoc(SourceLocation Loc)
Sets the location of the template keyword.
void setSpecializationKind(TemplateSpecializationKind TSK)
static void Profile(llvm::FoldingSetNodeID &ID, ArrayRef< TemplateArgument > TemplateArgs, const ASTContext &Context)
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
const TemplateArgumentList & getTemplateInstantiationArgs() const
Retrieve the set of template arguments that should be used to instantiate the initializer of the vari...
static bool classof(const Decl *D)
SourceLocation getTemplateKeywordLoc() const
Gets the location of the template keyword, if present.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
void setInstantiationOf(VarTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs)
Note that this variable template specialization is actually an instantiation of the given variable te...
void Profile(llvm::FoldingSetNodeID &ID) const
void setPointOfInstantiation(SourceLocation Loc)
void setTemplateArgsAsWritten(const TemplateArgumentListInfo &ArgsInfo)
Set the template argument list as written in the sources.
llvm::PointerUnion< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > getSpecializedTemplateOrPartial() const
Retrieve the variable template or variable template partial specialization which was specialized by t...
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
void setInstantiationOf(VarTemplateDecl *TemplDecl)
Note that this variable template specialization is an instantiation of the given variable template.
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration,...
llvm::PointerUnion< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > getInstantiatedFrom() const
If this variable template specialization is an instantiation of a template (rather than an explicit s...
SourceLocation getExternKeywordLoc() const
Gets the location of the extern keyword, if present.
static VarTemplateSpecializationDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
void setExternKeywordLoc(SourceLocation Loc)
Sets the location of the extern keyword.
VarTemplateSpecializationDecl * getMostRecentDecl()
void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const override
Appends a human-readable name for this declaration into the given stream.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
The JSON file list parser is used to communicate input to InstallAPI.
bool isTemplateInstantiation(TemplateSpecializationKind Kind)
Determine whether this template specialization kind refers to an instantiation of an entity (as oppos...
Definition: Specifiers.h:212
Decl * getPrimaryMergedDecl(Decl *D)
Get the primary declaration for a declaration from an AST file.
Definition: Decl.cpp:76
NamedDecl * getAsNamedDecl(TemplateParameter P)
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
StorageClass
Storage classes.
Definition: Specifiers.h:248
void * allocateDefaultArgStorageChain(const ASTContext &C)
TemplateDecl * getAsTypeTemplateDecl(Decl *D)
llvm::PointerUnion< const ASTTemplateArgumentListInfo *, ExplicitInstantiationInfo * > SpecializationOrInstantiationInfo
TemplateParameterList * getReplacedTemplateParameterList(Decl *D)
Internal helper used by Subst* nodes to retrieve the parameter list for their AssociatedDecl.
TagTypeKind
The kind of a tag type.
Definition: Type.h:6871
BuiltinTemplateKind
Kinds of BuiltinTemplateDecl.
Definition: Builtins.h:305
llvm::PointerUnion< TemplateTypeParmDecl *, NonTypeTemplateParmDecl *, TemplateTemplateParmDecl * > TemplateParameter
Stores a template parameter of any kind.
Definition: DeclTemplate.h:65
std::optional< unsigned > getExpandedPackSize(const NamedDecl *Param)
Check whether the template parameter is a pack expansion, and if so, determine the number of paramete...
const FunctionProtoType * T
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:188
@ TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp....
Definition: Specifiers.h:198
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...
Definition: Specifiers.h:191
@ Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
bool isTemplateExplicitInstantiationOrSpecialization(TemplateSpecializationKind Kind)
True if this template specialization kind is an explicit specialization, explicit instantiation decla...
Definition: Specifiers.h:219
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
#define true
Definition: stdbool.h:25
#define false
Definition: stdbool.h:26
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:676
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
Data that is common to all of the declarations of a given class template.
llvm::FoldingSetVector< ClassTemplatePartialSpecializationDecl > PartialSpecializations
The class template partial specializations for this class template.
llvm::FoldingSetVector< ClassTemplateSpecializationDecl > Specializations
The class template specializations for this class template, including explicit specializations and in...
QualType InjectedClassNameType
The injected-class-name type for this class template.
A placeholder type used to construct an empty shell of a decl-derived type that will be filled in lat...
Definition: DeclBase.h:102
Provides information about an explicit instantiation of a variable or class template.
SourceLocation ExternKeywordLoc
The location of the extern keyword.
const ASTTemplateArgumentListInfo * TemplateArgsAsWritten
The template arguments as written..
SourceLocation TemplateKeywordLoc
The location of the template keyword.
Data that is common to all of the declarations of a given function template.
Definition: DeclTemplate.h:965
llvm::FoldingSetVector< FunctionTemplateSpecializationInfo > Specializations
The function template specializations for this function template, including explicit specializations ...
Definition: DeclTemplate.h:968
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
llvm::PointerIntPair< RedeclarableTemplateDecl *, 1, bool > InstantiatedFromMember
The template from which this was most directly instantiated (or null).
Definition: DeclTemplate.h:807
static ArrayRef< TemplateArgument > getTemplateArgs(FunctionTemplateSpecializationInfo *I)
Definition: DeclTemplate.h:953
static DeclType * getDecl(FunctionTemplateSpecializationInfo *I)
Definition: DeclTemplate.h:948
static ArrayRef< TemplateArgument > getTemplateArgs(EntryType *D)
Definition: DeclTemplate.h:746
static DeclType * getDecl(EntryType *D)
Definition: DeclTemplate.h:742
SpecIterator(typename llvm::FoldingSetVector< EntryType >::iterator SetIter)
Definition: DeclTemplate.h:761
Data that is common to all of the declarations of a given variable template.
llvm::FoldingSetVector< VarTemplatePartialSpecializationDecl > PartialSpecializations
The variable template partial specializations for this variable template.
llvm::FoldingSetVector< VarTemplateSpecializationDecl > Specializations
The variable template specializations for this variable template, including explicit specializations ...