clang 21.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 dyn_cast<ParmDecl *>(ValueOrInherited)) {
371 assert(C.isSameDefaultTemplateArgument(D, InheritedFrom));
372 ValueOrInherited =
373 new (allocateDefaultArgStorageChain(C)) Chain{InheritedFrom, get()};
374 } else if (auto *Inherited = dyn_cast<Chain *>(ValueOrInherited)) {
375 assert(C.isSameDefaultTemplateArgument(Inherited->PrevDeclWithDefaultArg,
376 InheritedFrom));
377 Inherited->PrevDeclWithDefaultArg = InheritedFrom;
378 } else
379 ValueOrInherited = new (allocateDefaultArgStorageChain(C))
380 Chain{InheritedFrom, cast<ArgType>(ValueOrInherited)};
381 }
382
383 /// Remove the default argument, even if it was inherited.
384 void clear() {
385 ValueOrInherited = ArgType();
386 }
387};
388
389//===----------------------------------------------------------------------===//
390// Kinds of Templates
391//===----------------------------------------------------------------------===//
392
393/// \brief The base class of all kinds of template declarations (e.g.,
394/// class, function, etc.).
395///
396/// The TemplateDecl class stores the list of template parameters and a
397/// reference to the templated scoped declaration: the underlying AST node.
398class TemplateDecl : public NamedDecl {
399 void anchor() override;
400
401protected:
402 // Construct a template decl with name, parameters, and templated element.
405
406 // Construct a template decl with the given name and parameters.
407 // Used when there is no templated element (e.g., for tt-params).
409 TemplateParameterList *Params)
410 : TemplateDecl(DK, DC, L, Name, Params, nullptr) {}
411
412public:
413 friend class ASTDeclReader;
414 friend class ASTDeclWriter;
415
416 /// Get the list of template parameters
418 return TemplateParams;
419 }
420
421 /// \brief Get the total constraint-expression associated with this template,
422 /// including constraint-expressions derived from the requires-clause,
423 /// trailing requires-clause (for functions and methods) and constrained
424 /// template parameters.
426
427 bool hasAssociatedConstraints() const;
428
429 /// Get the underlying, templated declaration.
431
432 // Should a specialization behave like an alias for another type.
433 bool isTypeAlias() const;
434
435 // Implement isa/cast/dyncast/etc.
436 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
437
438 static bool classofKind(Kind K) {
439 return K >= firstTemplate && K <= lastTemplate;
440 }
441
442 SourceRange getSourceRange() const override LLVM_READONLY {
443 return SourceRange(getTemplateParameters()->getTemplateLoc(),
445 }
446
447protected:
450
451public:
453 TemplateParams = TParams;
454 }
455
456 /// Initialize the underlying templated declaration.
457 void init(NamedDecl *NewTemplatedDecl) {
458 if (TemplatedDecl)
459 assert(TemplatedDecl == NewTemplatedDecl && "Inconsistent TemplatedDecl");
460 else
461 TemplatedDecl = NewTemplatedDecl;
462 }
463};
464
465/// Provides information about a function template specialization,
466/// which is a FunctionDecl that has been explicitly specialization or
467/// instantiated from a function template.
469 : public llvm::FoldingSetNode,
470 private llvm::TrailingObjects<FunctionTemplateSpecializationInfo,
471 MemberSpecializationInfo *> {
472 /// The function template specialization that this structure describes and a
473 /// flag indicating if the function is a member specialization.
474 llvm::PointerIntPair<FunctionDecl *, 1, bool> Function;
475
476 /// The function template from which this function template
477 /// specialization was generated.
478 ///
479 /// The two bits contain the top 4 values of TemplateSpecializationKind.
480 llvm::PointerIntPair<FunctionTemplateDecl *, 2> Template;
481
482public:
483 /// The template arguments used to produce the function template
484 /// specialization from the function template.
486
487 /// The template arguments as written in the sources, if provided.
488 /// FIXME: Normally null; tail-allocate this.
490
491 /// The point at which this function template specialization was
492 /// first instantiated.
494
495private:
497 FunctionDecl *FD, FunctionTemplateDecl *Template,
499 const ASTTemplateArgumentListInfo *TemplateArgsAsWritten,
501 : Function(FD, MSInfo ? true : false), Template(Template, TSK - 1),
502 TemplateArguments(TemplateArgs),
503 TemplateArgumentsAsWritten(TemplateArgsAsWritten),
505 if (MSInfo)
506 getTrailingObjects<MemberSpecializationInfo *>()[0] = MSInfo;
507 }
508
509 size_t numTrailingObjects(OverloadToken<MemberSpecializationInfo*>) const {
510 return Function.getInt();
511 }
512
513public:
515
519 const TemplateArgumentListInfo *TemplateArgsAsWritten,
521
522 /// Retrieve the declaration of the function template specialization.
523 FunctionDecl *getFunction() const { return Function.getPointer(); }
524
525 /// Retrieve the template from which this function was specialized.
526 FunctionTemplateDecl *getTemplate() const { return Template.getPointer(); }
527
528 /// Determine what kind of template specialization this is.
530 return (TemplateSpecializationKind)(Template.getInt() + 1);
531 }
532
535 }
536
537 /// True if this declaration is an explicit specialization,
538 /// explicit instantiation declaration, or explicit instantiation
539 /// definition.
543 }
544
545 /// Set the template specialization kind.
547 assert(TSK != TSK_Undeclared &&
548 "Cannot encode TSK_Undeclared for a function template specialization");
549 Template.setInt(TSK - 1);
550 }
551
552 /// Retrieve the first point of instantiation of this function
553 /// template specialization.
554 ///
555 /// The point of instantiation may be an invalid source location if this
556 /// function has yet to be instantiated.
559 }
560
561 /// Set the (first) point of instantiation of this function template
562 /// specialization.
565 }
566
567 /// Get the specialization info if this function template specialization is
568 /// also a member specialization:
569 ///
570 /// \code
571 /// template<typename> struct A {
572 /// template<typename> void f();
573 /// template<> void f<int>();
574 /// };
575 /// \endcode
576 ///
577 /// Here, A<int>::f<int> is a function template specialization that is
578 /// an explicit specialization of A<int>::f, but it's also a member
579 /// specialization (an implicit instantiation in this case) of A::f<int>.
580 /// Further:
581 ///
582 /// \code
583 /// template<> template<> void A<int>::f<int>() {}
584 /// \endcode
585 ///
586 /// ... declares a function template specialization that is an explicit
587 /// specialization of A<int>::f, and is also an explicit member
588 /// specialization of A::f<int>.
589 ///
590 /// Note that the TemplateSpecializationKind of the MemberSpecializationInfo
591 /// need not be the same as that returned by getTemplateSpecializationKind(),
592 /// and represents the relationship between the function and the class-scope
593 /// explicit specialization in the original templated class -- whereas our
594 /// TemplateSpecializationKind represents the relationship between the
595 /// function and the function template, and should always be
596 /// TSK_ExplicitSpecialization whenever we have MemberSpecializationInfo.
598 return numTrailingObjects(OverloadToken<MemberSpecializationInfo *>())
599 ? getTrailingObjects<MemberSpecializationInfo *>()[0]
600 : nullptr;
601 }
602
603 void Profile(llvm::FoldingSetNodeID &ID) {
604 Profile(ID, TemplateArguments->asArray(), getFunction()->getASTContext());
605 }
606
607 static void
608 Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
609 const ASTContext &Context) {
610 ID.AddInteger(TemplateArgs.size());
611 for (const TemplateArgument &TemplateArg : TemplateArgs)
612 TemplateArg.Profile(ID, Context);
613 }
614};
615
616/// Provides information a specialization of a member of a class
617/// template, which may be a member function, static data member,
618/// member class or member enumeration.
620 // The member declaration from which this member was instantiated, and the
621 // manner in which the instantiation occurred (in the lower two bits).
622 llvm::PointerIntPair<NamedDecl *, 2> MemberAndTSK;
623
624 // The point at which this member was first instantiated.
625 SourceLocation PointOfInstantiation;
626
627public:
628 explicit
631 : MemberAndTSK(IF, TSK - 1), PointOfInstantiation(POI) {
632 assert(TSK != TSK_Undeclared &&
633 "Cannot encode undeclared template specializations for members");
634 }
635
636 /// Retrieve the member declaration from which this member was
637 /// instantiated.
638 NamedDecl *getInstantiatedFrom() const { return MemberAndTSK.getPointer(); }
639
640 /// Determine what kind of template specialization this is.
642 return (TemplateSpecializationKind)(MemberAndTSK.getInt() + 1);
643 }
644
647 }
648
649 /// Set the template specialization kind.
651 assert(TSK != TSK_Undeclared &&
652 "Cannot encode undeclared template specializations for members");
653 MemberAndTSK.setInt(TSK - 1);
654 }
655
656 /// Retrieve the first point of instantiation of this member.
657 /// If the point of instantiation is an invalid location, then this member
658 /// has not yet been instantiated.
660 return PointOfInstantiation;
661 }
662
663 /// Set the first point of instantiation.
665 PointOfInstantiation = POI;
666 }
667};
668
669/// Provides information about a dependent function-template
670/// specialization declaration.
671///
672/// This is used for function templates explicit specializations declared
673/// within class templates:
674///
675/// \code
676/// template<typename> struct A {
677/// template<typename> void f();
678/// template<> void f<int>(); // DependentFunctionTemplateSpecializationInfo
679/// };
680/// \endcode
681///
682/// As well as dependent friend declarations naming function template
683/// specializations declared within class templates:
684///
685/// \code
686/// template <class T> void foo(T);
687/// template <class T> class A {
688/// friend void foo<>(T); // DependentFunctionTemplateSpecializationInfo
689/// };
690/// \endcode
692 : private llvm::TrailingObjects<DependentFunctionTemplateSpecializationInfo,
693 FunctionTemplateDecl *> {
694 friend TrailingObjects;
695
696 /// The number of candidates for the primary template.
697 unsigned NumCandidates;
698
700 const UnresolvedSetImpl &Candidates,
701 const ASTTemplateArgumentListInfo *TemplateArgsWritten);
702
703public:
704 /// The template arguments as written in the sources, if provided.
706
708 Create(ASTContext &Context, const UnresolvedSetImpl &Candidates,
709 const TemplateArgumentListInfo *TemplateArgs);
710
711 /// Returns the candidates for the primary function template.
713 return {getTrailingObjects<FunctionTemplateDecl *>(), NumCandidates};
714 }
715};
716
717/// Declaration of a redeclarable template.
719 public Redeclarable<RedeclarableTemplateDecl>
720{
722
723 RedeclarableTemplateDecl *getNextRedeclarationImpl() override {
724 return getNextRedeclaration();
725 }
726
727 RedeclarableTemplateDecl *getPreviousDeclImpl() override {
728 return getPreviousDecl();
729 }
730
731 RedeclarableTemplateDecl *getMostRecentDeclImpl() override {
732 return getMostRecentDecl();
733 }
734
735 void anchor() override;
736
737protected:
738 template <typename EntryType> struct SpecEntryTraits {
739 using DeclType = EntryType;
740
741 static DeclType *getDecl(EntryType *D) {
742 return D;
743 }
744
746 return D->getTemplateArgs().asArray();
747 }
748 };
749
750 template <typename EntryType, typename SETraits = SpecEntryTraits<EntryType>,
751 typename DeclType = typename SETraits::DeclType>
753 : llvm::iterator_adaptor_base<
754 SpecIterator<EntryType, SETraits, DeclType>,
755 typename llvm::FoldingSetVector<EntryType>::iterator,
756 typename std::iterator_traits<typename llvm::FoldingSetVector<
757 EntryType>::iterator>::iterator_category,
758 DeclType *, ptrdiff_t, DeclType *, DeclType *> {
759 SpecIterator() = default;
760 explicit SpecIterator(
761 typename llvm::FoldingSetVector<EntryType>::iterator SetIter)
762 : SpecIterator::iterator_adaptor_base(std::move(SetIter)) {}
763
764 DeclType *operator*() const {
765 return SETraits::getDecl(&*this->I)->getMostRecentDecl();
766 }
767
768 DeclType *operator->() const { return **this; }
769 };
770
771 template <typename EntryType>
772 static SpecIterator<EntryType>
773 makeSpecIterator(llvm::FoldingSetVector<EntryType> &Specs, bool isEnd) {
774 return SpecIterator<EntryType>(isEnd ? Specs.end() : Specs.begin());
775 }
776
777 void loadLazySpecializationsImpl(bool OnlyPartial = false) const;
778
780 TemplateParameterList *TPL = nullptr) const;
781
782 template <class EntryType, typename ...ProfileArguments>
784 findSpecializationImpl(llvm::FoldingSetVector<EntryType> &Specs,
785 void *&InsertPos, ProfileArguments &&...ProfileArgs);
786
787 template <class EntryType, typename... ProfileArguments>
789 findSpecializationLocally(llvm::FoldingSetVector<EntryType> &Specs,
790 void *&InsertPos,
791 ProfileArguments &&...ProfileArgs);
792
793 template <class Derived, class EntryType>
794 void addSpecializationImpl(llvm::FoldingSetVector<EntryType> &Specs,
795 EntryType *Entry, void *InsertPos);
796
797 struct CommonBase {
799
800 /// The template from which this was most
801 /// directly instantiated (or null).
802 ///
803 /// The boolean value indicates whether this template
804 /// was explicitly specialized.
805 llvm::PointerIntPair<RedeclarableTemplateDecl *, 1, bool>
807 };
808
809 /// Pointer to the common data shared by all declarations of this
810 /// template.
811 mutable CommonBase *Common = nullptr;
812
813 /// Retrieves the "common" pointer shared by all (re-)declarations of
814 /// the same template. Calling this routine may implicitly allocate memory
815 /// for the common pointer.
816 CommonBase *getCommonPtr() const;
817
818 virtual CommonBase *newCommon(ASTContext &C) const = 0;
819
820 // Construct a template decl with name, parameters, and templated element.
824 : TemplateDecl(DK, DC, L, Name, Params, Decl), redeclarable_base(C) {}
825
826public:
827 friend class ASTDeclReader;
828 friend class ASTDeclWriter;
829 friend class ASTReader;
830 template <class decl_type> friend class RedeclarableTemplate;
831
832 /// Retrieves the canonical declaration of this template.
834 return getFirstDecl();
835 }
837 return getFirstDecl();
838 }
839
840 /// Determines whether this template was a specialization of a
841 /// member template.
842 ///
843 /// In the following example, the function template \c X<int>::f and the
844 /// member template \c X<int>::Inner are member specializations.
845 ///
846 /// \code
847 /// template<typename T>
848 /// struct X {
849 /// template<typename U> void f(T, U);
850 /// template<typename U> struct Inner;
851 /// };
852 ///
853 /// template<> template<typename T>
854 /// void X<int>::f(int, T);
855 /// template<> template<typename T>
856 /// struct X<int>::Inner { /* ... */ };
857 /// \endcode
859 return getCommonPtr()->InstantiatedFromMember.getInt();
860 }
861
862 /// Note that this member template is a specialization.
864 assert(getCommonPtr()->InstantiatedFromMember.getPointer() &&
865 "Only member templates can be member template specializations");
866 getCommonPtr()->InstantiatedFromMember.setInt(true);
867 }
868
869 /// Retrieve the member template from which this template was
870 /// instantiated, or nullptr if this template was not instantiated from a
871 /// member template.
872 ///
873 /// A template is instantiated from a member template when the member
874 /// template itself is part of a class template (or member thereof). For
875 /// example, given
876 ///
877 /// \code
878 /// template<typename T>
879 /// struct X {
880 /// template<typename U> void f(T, U);
881 /// };
882 ///
883 /// void test(X<int> x) {
884 /// x.f(1, 'a');
885 /// };
886 /// \endcode
887 ///
888 /// \c X<int>::f is a FunctionTemplateDecl that describes the function
889 /// template
890 ///
891 /// \code
892 /// template<typename U> void X<int>::f(int, U);
893 /// \endcode
894 ///
895 /// which was itself created during the instantiation of \c X<int>. Calling
896 /// getInstantiatedFromMemberTemplate() on this FunctionTemplateDecl will
897 /// retrieve the FunctionTemplateDecl for the original template \c f within
898 /// the class template \c X<T>, i.e.,
899 ///
900 /// \code
901 /// template<typename T>
902 /// template<typename U>
903 /// void X<T>::f(T, U);
904 /// \endcode
906 return getCommonPtr()->InstantiatedFromMember.getPointer();
907 }
908
910 assert(!getCommonPtr()->InstantiatedFromMember.getPointer());
911 getCommonPtr()->InstantiatedFromMember.setPointer(TD);
912 }
913
914 /// Retrieve the "injected" template arguments that correspond to the
915 /// template parameters of this template.
916 ///
917 /// Although the C++ standard has no notion of the "injected" template
918 /// arguments for a template, the notion is convenient when
919 /// we need to perform substitutions inside the definition of a template.
921 getInjectedTemplateArgs(const ASTContext &Context) const {
923 }
924
926 using redecl_iterator = redeclarable_base::redecl_iterator;
927
934
935 // Implement isa/cast/dyncast/etc.
936 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
937
938 static bool classofKind(Kind K) {
939 return K >= firstRedeclarableTemplate && K <= lastRedeclarableTemplate;
940 }
941};
942
943template <> struct RedeclarableTemplateDecl::
944SpecEntryTraits<FunctionTemplateSpecializationInfo> {
946
948 return I->getFunction();
949 }
950
953 return I->TemplateArguments->asArray();
954 }
955};
956
957/// Declaration of a template function.
959protected:
960 friend class FunctionDecl;
961
962 /// Data that is common to all of the declarations of a given
963 /// function template.
965 /// The function template specializations for this function
966 /// template, including explicit specializations and instantiations.
967 llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> Specializations;
968
969 Common() = default;
970 };
971
975 : RedeclarableTemplateDecl(FunctionTemplate, C, DC, L, Name, Params,
976 Decl) {}
977
978 CommonBase *newCommon(ASTContext &C) const override;
979
981 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
982 }
983
984 /// Retrieve the set of function template specializations of this
985 /// function template.
986 llvm::FoldingSetVector<FunctionTemplateSpecializationInfo> &
987 getSpecializations() const;
988
989 /// Add a specialization of this function template.
990 ///
991 /// \param InsertPos Insert position in the FoldingSetVector, must have been
992 /// retrieved by an earlier call to findSpecialization().
994 void *InsertPos);
995
996public:
997 friend class ASTDeclReader;
998 friend class ASTDeclWriter;
999
1000 /// Load any lazily-loaded specializations from the external source.
1001 void LoadLazySpecializations() const;
1002
1003 /// Get the underlying function declaration of the template.
1005 return static_cast<FunctionDecl *>(TemplatedDecl);
1006 }
1007
1008 /// Returns whether this template declaration defines the primary
1009 /// pattern.
1012 }
1013
1014 /// Return the specialization with the provided arguments if it exists,
1015 /// otherwise return the insertion point.
1017 void *&InsertPos);
1018
1020 return cast<FunctionTemplateDecl>(
1022 }
1024 return cast<FunctionTemplateDecl>(
1026 }
1027
1028 /// Retrieve the previous declaration of this function template, or
1029 /// nullptr if no such declaration exists.
1031 return cast_or_null<FunctionTemplateDecl>(
1032 static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
1033 }
1035 return cast_or_null<FunctionTemplateDecl>(
1036 static_cast<const RedeclarableTemplateDecl *>(this)->getPreviousDecl());
1037 }
1038
1040 return cast<FunctionTemplateDecl>(
1041 static_cast<RedeclarableTemplateDecl *>(this)
1042 ->getMostRecentDecl());
1043 }
1045 return const_cast<FunctionTemplateDecl*>(this)->getMostRecentDecl();
1046 }
1047
1049 return cast_or_null<FunctionTemplateDecl>(
1051 }
1052
1054 using spec_range = llvm::iterator_range<spec_iterator>;
1055
1057 return spec_range(spec_begin(), spec_end());
1058 }
1059
1061 return makeSpecIterator(getSpecializations(), false);
1062 }
1063
1065 return makeSpecIterator(getSpecializations(), true);
1066 }
1067
1068 /// Return whether this function template is an abbreviated function template,
1069 /// e.g. `void foo(auto x)` or `template<typename T> void foo(auto x)`
1070 bool isAbbreviated() const {
1071 // Since the invented template parameters generated from 'auto' parameters
1072 // are either appended to the end of the explicit template parameter list or
1073 // form a new template parameter list, we can simply observe the last
1074 // parameter to determine if such a thing happened.
1076 return TPL->getParam(TPL->size() - 1)->isImplicit();
1077 }
1078
1079 /// Merge \p Prev with our RedeclarableTemplateDecl::Common.
1081
1082 /// Create a function template node.
1085 DeclarationName Name,
1086 TemplateParameterList *Params,
1087 NamedDecl *Decl);
1088
1089 /// Create an empty function template node.
1092
1093 // Implement isa/cast/dyncast support
1094 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1095 static bool classofKind(Kind K) { return K == FunctionTemplate; }
1096};
1097
1098//===----------------------------------------------------------------------===//
1099// Kinds of Template Parameters
1100//===----------------------------------------------------------------------===//
1101
1102/// Defines the position of a template parameter within a template
1103/// parameter list.
1104///
1105/// Because template parameter can be listed
1106/// sequentially for out-of-line template members, each template parameter is
1107/// given a Depth - the nesting of template parameter scopes - and a Position -
1108/// the occurrence within the parameter list.
1109/// This class is inheritedly privately by different kinds of template
1110/// parameters and is not part of the Decl hierarchy. Just a facility.
1112protected:
1113 enum { DepthWidth = 20, PositionWidth = 12 };
1114 unsigned Depth : DepthWidth;
1116
1117 static constexpr unsigned MaxDepth = (1U << DepthWidth) - 1;
1118 static constexpr unsigned MaxPosition = (1U << PositionWidth) - 1;
1119
1120 TemplateParmPosition(unsigned D, unsigned P) : Depth(D), Position(P) {
1121 // The input may fill maximum values to show that it is invalid.
1122 // Add one here to convert it to zero.
1123 assert((D + 1) <= MaxDepth &&
1124 "The depth of template parmeter position is more than 2^20!");
1125 assert((P + 1) <= MaxPosition &&
1126 "The position of template parmeter position is more than 2^12!");
1127 }
1128
1129public:
1131
1132 /// Get the nesting depth of the template parameter.
1133 unsigned getDepth() const { return Depth; }
1134 void setDepth(unsigned D) {
1135 assert((D + 1) <= MaxDepth &&
1136 "The depth of template parmeter position is more than 2^20!");
1137 Depth = D;
1138 }
1139
1140 /// Get the position of the template parameter within its parameter list.
1141 unsigned getPosition() const { return Position; }
1142 void setPosition(unsigned P) {
1143 assert((P + 1) <= MaxPosition &&
1144 "The position of template parmeter position is more than 2^12!");
1145 Position = P;
1146 }
1147
1148 /// Get the index of the template parameter within its parameter list.
1149 unsigned getIndex() const { return Position; }
1150};
1151
1152/// Declaration of a template type parameter.
1153///
1154/// For example, "T" in
1155/// \code
1156/// template<typename T> class vector;
1157/// \endcode
1158class TemplateTypeParmDecl final : public TypeDecl,
1159 private llvm::TrailingObjects<TemplateTypeParmDecl, TypeConstraint> {
1160 /// Sema creates these on the stack during auto type deduction.
1161 friend class Sema;
1162 friend TrailingObjects;
1163 friend class ASTDeclReader;
1164
1165 /// Whether this template type parameter was declaration with
1166 /// the 'typename' keyword.
1167 ///
1168 /// If false, it was declared with the 'class' keyword.
1169 bool Typename : 1;
1170
1171 /// Whether this template type parameter has a type-constraint construct.
1172 bool HasTypeConstraint : 1;
1173
1174 /// Whether the type constraint has been initialized. This can be false if the
1175 /// constraint was not initialized yet or if there was an error forming the
1176 /// type constraint.
1177 bool TypeConstraintInitialized : 1;
1178
1179 /// Whether this type template parameter is an "expanded"
1180 /// parameter pack, meaning that its type is a pack expansion and we
1181 /// already know the set of types that expansion expands to.
1182 bool ExpandedParameterPack : 1;
1183
1184 /// The number of type parameters in an expanded parameter pack.
1185 unsigned NumExpanded = 0;
1186
1187 /// The default template argument, if any.
1188 using DefArgStorage =
1190 DefArgStorage DefaultArgument;
1191
1193 SourceLocation IdLoc, IdentifierInfo *Id, bool Typename,
1194 bool HasTypeConstraint,
1195 std::optional<unsigned> NumExpanded)
1196 : TypeDecl(TemplateTypeParm, DC, IdLoc, Id, KeyLoc), Typename(Typename),
1197 HasTypeConstraint(HasTypeConstraint), TypeConstraintInitialized(false),
1198 ExpandedParameterPack(NumExpanded),
1199 NumExpanded(NumExpanded.value_or(0)) {}
1200
1201public:
1202 static TemplateTypeParmDecl *
1203 Create(const ASTContext &C, DeclContext *DC, SourceLocation KeyLoc,
1204 SourceLocation NameLoc, unsigned D, unsigned P, IdentifierInfo *Id,
1205 bool Typename, bool ParameterPack, bool HasTypeConstraint = false,
1206 std::optional<unsigned> NumExpanded = std::nullopt);
1211 bool HasTypeConstraint);
1212
1213 /// Whether this template type parameter was declared with
1214 /// the 'typename' keyword.
1215 ///
1216 /// If not, it was either declared with the 'class' keyword or with a
1217 /// type-constraint (see hasTypeConstraint()).
1219 return Typename && !HasTypeConstraint;
1220 }
1221
1222 const DefArgStorage &getDefaultArgStorage() const { return DefaultArgument; }
1223
1224 /// Determine whether this template parameter has a default
1225 /// argument.
1226 bool hasDefaultArgument() const { return DefaultArgument.isSet(); }
1227
1228 /// Retrieve the default argument, if any.
1230 static const TemplateArgumentLoc NoneLoc;
1231 return DefaultArgument.isSet() ? *DefaultArgument.get() : NoneLoc;
1232 }
1233
1234 /// Retrieves the location of the default argument declaration.
1236
1237 /// Determines whether the default argument was inherited
1238 /// from a previous declaration of this template.
1240 return DefaultArgument.isInherited();
1241 }
1242
1243 /// Set the default argument for this template parameter.
1244 void setDefaultArgument(const ASTContext &C,
1245 const TemplateArgumentLoc &DefArg);
1246
1247 /// Set that this default argument was inherited from another
1248 /// parameter.
1250 TemplateTypeParmDecl *Prev) {
1251 DefaultArgument.setInherited(C, Prev);
1252 }
1253
1254 /// Removes the default argument of this template parameter.
1256 DefaultArgument.clear();
1257 }
1258
1259 /// Set whether this template type parameter was declared with
1260 /// the 'typename' or 'class' keyword.
1261 void setDeclaredWithTypename(bool withTypename) { Typename = withTypename; }
1262
1263 /// Retrieve the depth of the template parameter.
1264 unsigned getDepth() const;
1265
1266 /// Retrieve the index of the template parameter.
1267 unsigned getIndex() const;
1268
1269 /// Returns whether this is a parameter pack.
1270 bool isParameterPack() const;
1271
1272 /// Whether this parameter pack is a pack expansion.
1273 ///
1274 /// A template type template parameter pack can be a pack expansion if its
1275 /// type-constraint contains an unexpanded parameter pack.
1276 bool isPackExpansion() const {
1277 if (!isParameterPack())
1278 return false;
1279 if (const TypeConstraint *TC = getTypeConstraint())
1280 if (TC->hasExplicitTemplateArgs())
1281 for (const auto &ArgLoc : TC->getTemplateArgsAsWritten()->arguments())
1282 if (ArgLoc.getArgument().containsUnexpandedParameterPack())
1283 return true;
1284 return false;
1285 }
1286
1287 /// Whether this parameter is a template type parameter pack that has a known
1288 /// list of different type-constraints at different positions.
1289 ///
1290 /// A parameter pack is an expanded parameter pack when the original
1291 /// parameter pack's type-constraint was itself a pack expansion, and that
1292 /// expansion has already been expanded. For example, given:
1293 ///
1294 /// \code
1295 /// template<typename ...Types>
1296 /// struct X {
1297 /// template<convertible_to<Types> ...Convertibles>
1298 /// struct Y { /* ... */ };
1299 /// };
1300 /// \endcode
1301 ///
1302 /// The parameter pack \c Convertibles has (convertible_to<Types> && ...) as
1303 /// its type-constraint. When \c Types is supplied with template arguments by
1304 /// instantiating \c X, the instantiation of \c Convertibles becomes an
1305 /// expanded parameter pack. For example, instantiating
1306 /// \c X<int, unsigned int> results in \c Convertibles being an expanded
1307 /// parameter pack of size 2 (use getNumExpansionTypes() to get this number).
1308 bool isExpandedParameterPack() const { return ExpandedParameterPack; }
1309
1310 /// Retrieves the number of parameters in an expanded parameter pack.
1311 unsigned getNumExpansionParameters() const {
1312 assert(ExpandedParameterPack && "Not an expansion parameter pack");
1313 return NumExpanded;
1314 }
1315
1316 /// Returns the type constraint associated with this template parameter (if
1317 /// any).
1319 return TypeConstraintInitialized ? getTrailingObjects<TypeConstraint>() :
1320 nullptr;
1321 }
1322
1324 Expr *ImmediatelyDeclaredConstraint);
1325
1326 /// Determine whether this template parameter has a type-constraint.
1327 bool hasTypeConstraint() const {
1328 return HasTypeConstraint;
1329 }
1330
1331 /// \brief Get the associated-constraints of this template parameter.
1332 /// This will either be the immediately-introduced constraint or empty.
1333 ///
1334 /// Use this instead of getTypeConstraint for concepts APIs that
1335 /// accept an ArrayRef of constraint expressions.
1337 if (HasTypeConstraint)
1338 AC.push_back(getTypeConstraint()->getImmediatelyDeclaredConstraint());
1339 }
1340
1341 SourceRange getSourceRange() const override LLVM_READONLY;
1342
1343 // Implement isa/cast/dyncast/etc.
1344 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1345 static bool classofKind(Kind K) { return K == TemplateTypeParm; }
1346};
1347
1348/// NonTypeTemplateParmDecl - Declares a non-type template parameter,
1349/// e.g., "Size" in
1350/// @code
1351/// template<int Size> class array { };
1352/// @endcode
1354 : public DeclaratorDecl,
1355 protected TemplateParmPosition,
1356 private llvm::TrailingObjects<NonTypeTemplateParmDecl,
1357 std::pair<QualType, TypeSourceInfo *>,
1358 Expr *> {
1359 friend class ASTDeclReader;
1360 friend TrailingObjects;
1361
1362 /// The default template argument, if any, and whether or not
1363 /// it was inherited.
1364 using DefArgStorage =
1366 DefArgStorage DefaultArgument;
1367
1368 // FIXME: Collapse this into TemplateParamPosition; or, just move depth/index
1369 // down here to save memory.
1370
1371 /// Whether this non-type template parameter is a parameter pack.
1372 bool ParameterPack;
1373
1374 /// Whether this non-type template parameter is an "expanded"
1375 /// parameter pack, meaning that its type is a pack expansion and we
1376 /// already know the set of types that expansion expands to.
1377 bool ExpandedParameterPack = false;
1378
1379 /// The number of types in an expanded parameter pack.
1380 unsigned NumExpandedTypes = 0;
1381
1382 size_t numTrailingObjects(
1383 OverloadToken<std::pair<QualType, TypeSourceInfo *>>) const {
1384 return NumExpandedTypes;
1385 }
1386
1388 SourceLocation IdLoc, unsigned D, unsigned P,
1389 const IdentifierInfo *Id, QualType T,
1390 bool ParameterPack, TypeSourceInfo *TInfo)
1391 : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc),
1392 TemplateParmPosition(D, P), ParameterPack(ParameterPack) {}
1393
1394 NonTypeTemplateParmDecl(DeclContext *DC, SourceLocation StartLoc,
1395 SourceLocation IdLoc, unsigned D, unsigned P,
1396 const IdentifierInfo *Id, QualType T,
1397 TypeSourceInfo *TInfo,
1398 ArrayRef<QualType> ExpandedTypes,
1399 ArrayRef<TypeSourceInfo *> ExpandedTInfos);
1400
1401public:
1402 static NonTypeTemplateParmDecl *
1403 Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1404 SourceLocation IdLoc, unsigned D, unsigned P, const IdentifierInfo *Id,
1405 QualType T, bool ParameterPack, TypeSourceInfo *TInfo);
1406
1407 static NonTypeTemplateParmDecl *
1408 Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1409 SourceLocation IdLoc, unsigned D, unsigned P, const IdentifierInfo *Id,
1410 QualType T, TypeSourceInfo *TInfo, ArrayRef<QualType> ExpandedTypes,
1411 ArrayRef<TypeSourceInfo *> ExpandedTInfos);
1412
1413 static NonTypeTemplateParmDecl *
1414 CreateDeserialized(ASTContext &C, GlobalDeclID ID, bool HasTypeConstraint);
1415 static NonTypeTemplateParmDecl *CreateDeserialized(ASTContext &C,
1416 GlobalDeclID ID,
1417 unsigned NumExpandedTypes,
1418 bool HasTypeConstraint);
1419
1425
1426 SourceRange getSourceRange() const override LLVM_READONLY;
1427
1428 const DefArgStorage &getDefaultArgStorage() const { return DefaultArgument; }
1429
1430 /// Determine whether this template parameter has a default
1431 /// argument.
1432 bool hasDefaultArgument() const { return DefaultArgument.isSet(); }
1433
1434 /// Retrieve the default argument, if any.
1436 static const TemplateArgumentLoc NoneLoc;
1437 return DefaultArgument.isSet() ? *DefaultArgument.get() : NoneLoc;
1438 }
1439
1440 /// Retrieve the location of the default argument, if any.
1442
1443 /// Determines whether the default argument was inherited
1444 /// from a previous declaration of this template.
1446 return DefaultArgument.isInherited();
1447 }
1448
1449 /// Set the default argument for this template parameter, and
1450 /// whether that default argument was inherited from another
1451 /// declaration.
1452 void setDefaultArgument(const ASTContext &C,
1453 const TemplateArgumentLoc &DefArg);
1456 DefaultArgument.setInherited(C, Parm);
1457 }
1458
1459 /// Removes the default argument of this template parameter.
1460 void removeDefaultArgument() { DefaultArgument.clear(); }
1461
1462 /// Whether this parameter is a non-type template parameter pack.
1463 ///
1464 /// If the parameter is a parameter pack, the type may be a
1465 /// \c PackExpansionType. In the following example, the \c Dims parameter
1466 /// is a parameter pack (whose type is 'unsigned').
1467 ///
1468 /// \code
1469 /// template<typename T, unsigned ...Dims> struct multi_array;
1470 /// \endcode
1471 bool isParameterPack() const { return ParameterPack; }
1472
1473 /// Whether this parameter pack is a pack expansion.
1474 ///
1475 /// A non-type template parameter pack is a pack expansion if its type
1476 /// contains an unexpanded parameter pack. In this case, we will have
1477 /// built a PackExpansionType wrapping the type.
1478 bool isPackExpansion() const {
1479 return ParameterPack && getType()->getAs<PackExpansionType>();
1480 }
1481
1482 /// Whether this parameter is a non-type template parameter pack
1483 /// that has a known list of different types at different positions.
1484 ///
1485 /// A parameter pack is an expanded parameter pack when the original
1486 /// parameter pack's type was itself a pack expansion, and that expansion
1487 /// has already been expanded. For example, given:
1488 ///
1489 /// \code
1490 /// template<typename ...Types>
1491 /// struct X {
1492 /// template<Types ...Values>
1493 /// struct Y { /* ... */ };
1494 /// };
1495 /// \endcode
1496 ///
1497 /// The parameter pack \c Values has a \c PackExpansionType as its type,
1498 /// which expands \c Types. When \c Types is supplied with template arguments
1499 /// by instantiating \c X, the instantiation of \c Values becomes an
1500 /// expanded parameter pack. For example, instantiating
1501 /// \c X<int, unsigned int> results in \c Values being an expanded parameter
1502 /// pack with expansion types \c int and \c unsigned int.
1503 ///
1504 /// The \c getExpansionType() and \c getExpansionTypeSourceInfo() functions
1505 /// return the expansion types.
1506 bool isExpandedParameterPack() const { return ExpandedParameterPack; }
1507
1508 /// Retrieves the number of expansion types in an expanded parameter
1509 /// pack.
1510 unsigned getNumExpansionTypes() const {
1511 assert(ExpandedParameterPack && "Not an expansion parameter pack");
1512 return NumExpandedTypes;
1513 }
1514
1515 /// Retrieve a particular expansion type within an expanded parameter
1516 /// pack.
1517 QualType getExpansionType(unsigned I) const {
1518 assert(I < NumExpandedTypes && "Out-of-range expansion type index");
1519 auto TypesAndInfos =
1520 getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>();
1521 return TypesAndInfos[I].first;
1522 }
1523
1524 /// Retrieve a particular expansion type source info within an
1525 /// expanded parameter pack.
1527 assert(I < NumExpandedTypes && "Out-of-range expansion type index");
1528 auto TypesAndInfos =
1529 getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>();
1530 return TypesAndInfos[I].second;
1531 }
1532
1533 /// Return the constraint introduced by the placeholder type of this non-type
1534 /// template parameter (if any).
1536 return hasPlaceholderTypeConstraint() ? *getTrailingObjects<Expr *>() :
1537 nullptr;
1538 }
1539
1541 *getTrailingObjects<Expr *>() = E;
1542 }
1543
1544 /// Determine whether this non-type template parameter's type has a
1545 /// placeholder with a type-constraint.
1547 auto *AT = getType()->getContainedAutoType();
1548 return AT && AT->isConstrained();
1549 }
1550
1551 /// \brief Get the associated-constraints of this template parameter.
1552 /// This will either be a vector of size 1 containing the immediately-declared
1553 /// constraint introduced by the placeholder type, or an empty vector.
1554 ///
1555 /// Use this instead of getPlaceholderImmediatelyDeclaredConstraint for
1556 /// concepts APIs that accept an ArrayRef of constraint expressions.
1559 AC.push_back(E);
1560 }
1561
1562 // Implement isa/cast/dyncast/etc.
1563 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1564 static bool classofKind(Kind K) { return K == NonTypeTemplateParm; }
1565};
1566
1567/// TemplateTemplateParmDecl - Declares a template template parameter,
1568/// e.g., "T" in
1569/// @code
1570/// template <template <typename> class T> class container { };
1571/// @endcode
1572/// A template template parameter is a TemplateDecl because it defines the
1573/// name of a template and the template parameters allowable for substitution.
1575 : public TemplateDecl,
1576 protected TemplateParmPosition,
1577 private llvm::TrailingObjects<TemplateTemplateParmDecl,
1578 TemplateParameterList *> {
1579 /// The default template argument, if any.
1580 using DefArgStorage =
1582 DefArgStorage DefaultArgument;
1583
1584 /// Whether this template template parameter was declaration with
1585 /// the 'typename' keyword.
1586 ///
1587 /// If false, it was declared with the 'class' keyword.
1588 LLVM_PREFERRED_TYPE(bool)
1589 unsigned Typename : 1;
1590
1591 /// Whether this parameter is a parameter pack.
1592 LLVM_PREFERRED_TYPE(bool)
1593 unsigned ParameterPack : 1;
1594
1595 /// Whether this template template parameter is an "expanded"
1596 /// parameter pack, meaning that it is a pack expansion and we
1597 /// already know the set of template parameters that expansion expands to.
1598 LLVM_PREFERRED_TYPE(bool)
1599 unsigned ExpandedParameterPack : 1;
1600
1601 /// The number of parameters in an expanded parameter pack.
1602 unsigned NumExpandedParams = 0;
1603
1605 unsigned P, bool ParameterPack, IdentifierInfo *Id,
1606 bool Typename, TemplateParameterList *Params)
1607 : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params),
1609 ParameterPack(ParameterPack), ExpandedParameterPack(false) {}
1610
1612 unsigned P, IdentifierInfo *Id, bool Typename,
1613 TemplateParameterList *Params,
1615
1616 void anchor() override;
1617
1618public:
1619 friend class ASTDeclReader;
1620 friend class ASTDeclWriter;
1622
1624 SourceLocation L, unsigned D,
1625 unsigned P, bool ParameterPack,
1626 IdentifierInfo *Id, bool Typename,
1627 TemplateParameterList *Params);
1629 Create(const ASTContext &C, DeclContext *DC, SourceLocation L, unsigned D,
1630 unsigned P, IdentifierInfo *Id, bool Typename,
1631 TemplateParameterList *Params,
1633
1637 CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumExpansions);
1638
1644
1645 /// Whether this template template parameter was declared with
1646 /// the 'typename' keyword.
1647 bool wasDeclaredWithTypename() const { return Typename; }
1648
1649 /// Set whether this template template parameter was declared with
1650 /// the 'typename' or 'class' keyword.
1651 void setDeclaredWithTypename(bool withTypename) { Typename = withTypename; }
1652
1653 /// Whether this template template parameter is a template
1654 /// parameter pack.
1655 ///
1656 /// \code
1657 /// template<template <class T> ...MetaFunctions> struct Apply;
1658 /// \endcode
1659 bool isParameterPack() const { return ParameterPack; }
1660
1661 /// Whether this parameter pack is a pack expansion.
1662 ///
1663 /// A template template parameter pack is a pack expansion if its template
1664 /// parameter list contains an unexpanded parameter pack.
1665 bool isPackExpansion() const {
1666 return ParameterPack &&
1668 }
1669
1670 /// Whether this parameter is a template template parameter pack that
1671 /// has a known list of different template parameter lists at different
1672 /// positions.
1673 ///
1674 /// A parameter pack is an expanded parameter pack when the original parameter
1675 /// pack's template parameter list was itself a pack expansion, and that
1676 /// expansion has already been expanded. For exampe, given:
1677 ///
1678 /// \code
1679 /// template<typename...Types> struct Outer {
1680 /// template<template<Types> class...Templates> struct Inner;
1681 /// };
1682 /// \endcode
1683 ///
1684 /// The parameter pack \c Templates is a pack expansion, which expands the
1685 /// pack \c Types. When \c Types is supplied with template arguments by
1686 /// instantiating \c Outer, the instantiation of \c Templates is an expanded
1687 /// parameter pack.
1688 bool isExpandedParameterPack() const { return ExpandedParameterPack; }
1689
1690 /// Retrieves the number of expansion template parameters in
1691 /// an expanded parameter pack.
1693 assert(ExpandedParameterPack && "Not an expansion parameter pack");
1694 return NumExpandedParams;
1695 }
1696
1697 /// Retrieve a particular expansion type within an expanded parameter
1698 /// pack.
1700 assert(I < NumExpandedParams && "Out-of-range expansion type index");
1701 return getTrailingObjects<TemplateParameterList *>()[I];
1702 }
1703
1704 const DefArgStorage &getDefaultArgStorage() const { return DefaultArgument; }
1705
1706 /// Determine whether this template parameter has a default
1707 /// argument.
1708 bool hasDefaultArgument() const { return DefaultArgument.isSet(); }
1709
1710 /// Retrieve the default argument, if any.
1712 static const TemplateArgumentLoc NoneLoc;
1713 return DefaultArgument.isSet() ? *DefaultArgument.get() : NoneLoc;
1714 }
1715
1716 /// Retrieve the location of the default argument, if any.
1718
1719 /// Determines whether the default argument was inherited
1720 /// from a previous declaration of this template.
1722 return DefaultArgument.isInherited();
1723 }
1724
1725 /// Set the default argument for this template parameter, and
1726 /// whether that default argument was inherited from another
1727 /// declaration.
1728 void setDefaultArgument(const ASTContext &C,
1729 const TemplateArgumentLoc &DefArg);
1732 DefaultArgument.setInherited(C, Prev);
1733 }
1734
1735 /// Removes the default argument of this template parameter.
1736 void removeDefaultArgument() { DefaultArgument.clear(); }
1737
1738 SourceRange getSourceRange() const override LLVM_READONLY {
1742 return SourceRange(getTemplateParameters()->getTemplateLoc(), End);
1743 }
1744
1745 // Implement isa/cast/dyncast/etc.
1746 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1747 static bool classofKind(Kind K) { return K == TemplateTemplateParm; }
1748};
1749
1750/// Represents the builtin template declaration which is used to
1751/// implement __make_integer_seq and other builtin templates. It serves
1752/// no real purpose beyond existing as a place to hold template parameters.
1755
1758
1759 void anchor() override;
1760
1761public:
1762 // Implement isa/cast/dyncast support
1763 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1764 static bool classofKind(Kind K) { return K == BuiltinTemplate; }
1765
1767 DeclarationName Name,
1768 BuiltinTemplateKind BTK) {
1769 return new (C, DC) BuiltinTemplateDecl(C, DC, Name, BTK);
1770 }
1771
1772 SourceRange getSourceRange() const override LLVM_READONLY {
1773 return {};
1774 }
1775
1777};
1778
1779/// Provides information about an explicit instantiation of a variable or class
1780/// template.
1782 /// The template arguments as written..
1784
1785 /// The location of the extern keyword.
1787
1788 /// The location of the template keyword.
1790
1792};
1793
1795 llvm::PointerUnion<const ASTTemplateArgumentListInfo *,
1797
1798/// Represents a class template specialization, which refers to
1799/// a class template with a given set of template arguments.
1800///
1801/// Class template specializations represent both explicit
1802/// specialization of class templates, as in the example below, and
1803/// implicit instantiations of class templates.
1804///
1805/// \code
1806/// template<typename T> class array;
1807///
1808/// template<>
1809/// class array<bool> { }; // class template specialization array<bool>
1810/// \endcode
1812 public llvm::FoldingSetNode {
1813 /// Structure that stores information about a class template
1814 /// specialization that was instantiated from a class template partial
1815 /// specialization.
1816 struct SpecializedPartialSpecialization {
1817 /// The class template partial specialization from which this
1818 /// class template specialization was instantiated.
1819 ClassTemplatePartialSpecializationDecl *PartialSpecialization;
1820
1821 /// The template argument list deduced for the class template
1822 /// partial specialization itself.
1823 const TemplateArgumentList *TemplateArgs;
1824 };
1825
1826 /// The template that this specialization specializes
1827 llvm::PointerUnion<ClassTemplateDecl *, SpecializedPartialSpecialization *>
1828 SpecializedTemplate;
1829
1830 /// Further info for explicit template specialization/instantiation.
1831 /// Does not apply to implicit specializations.
1832 SpecializationOrInstantiationInfo ExplicitInfo = nullptr;
1833
1834 /// The template arguments used to describe this specialization.
1835 const TemplateArgumentList *TemplateArgs;
1836
1837 /// The point where this template was instantiated (if any)
1838 SourceLocation PointOfInstantiation;
1839
1840 /// The kind of specialization this declaration refers to.
1841 LLVM_PREFERRED_TYPE(TemplateSpecializationKind)
1842 unsigned SpecializationKind : 3;
1843
1844protected:
1846 DeclContext *DC, SourceLocation StartLoc,
1847 SourceLocation IdLoc,
1848 ClassTemplateDecl *SpecializedTemplate,
1851
1853
1854public:
1855 friend class ASTDeclReader;
1856 friend class ASTDeclWriter;
1857
1859 Create(ASTContext &Context, TagKind TK, DeclContext *DC,
1860 SourceLocation StartLoc, SourceLocation IdLoc,
1861 ClassTemplateDecl *SpecializedTemplate,
1866
1867 void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy,
1868 bool Qualified) const override;
1869
1870 // FIXME: This is broken. CXXRecordDecl::getMostRecentDecl() returns a
1871 // different "most recent" declaration from this function for the same
1872 // declaration, because we don't override getMostRecentDeclImpl(). But
1873 // it's not clear that we should override that, because the most recent
1874 // declaration as a CXXRecordDecl sometimes is the injected-class-name.
1876 return cast<ClassTemplateSpecializationDecl>(
1878 }
1879
1880 /// Retrieve the template that this specialization specializes.
1882
1883 /// Retrieve the template arguments of the class template
1884 /// specialization.
1886 return *TemplateArgs;
1887 }
1888
1890 TemplateArgs = Args;
1891 }
1892
1893 /// Determine the kind of specialization that this
1894 /// declaration represents.
1896 return static_cast<TemplateSpecializationKind>(SpecializationKind);
1897 }
1898
1901 }
1902
1903 /// Is this an explicit specialization at class scope (within the class that
1904 /// owns the primary template)? For example:
1905 ///
1906 /// \code
1907 /// template<typename T> struct Outer {
1908 /// template<typename U> struct Inner;
1909 /// template<> struct Inner; // class-scope explicit specialization
1910 /// };
1911 /// \endcode
1913 return isExplicitSpecialization() &&
1914 isa<CXXRecordDecl>(getLexicalDeclContext());
1915 }
1916
1917 /// True if this declaration is an explicit specialization,
1918 /// explicit instantiation declaration, or explicit instantiation
1919 /// definition.
1923 }
1924
1926 SpecializedTemplate = Specialized;
1927 }
1928
1930 SpecializationKind = TSK;
1931 }
1932
1933 /// Get the point of instantiation (if any), or null if none.
1935 return PointOfInstantiation;
1936 }
1937
1939 assert(Loc.isValid() && "point of instantiation must be valid!");
1940 PointOfInstantiation = Loc;
1941 }
1942
1943 /// If this class template specialization is an instantiation of
1944 /// a template (rather than an explicit specialization), return the
1945 /// class template or class template partial specialization from which it
1946 /// was instantiated.
1947 llvm::PointerUnion<ClassTemplateDecl *,
1951 return llvm::PointerUnion<ClassTemplateDecl *,
1953
1955 }
1956
1957 /// Retrieve the class template or class template partial
1958 /// specialization which was specialized by this.
1959 llvm::PointerUnion<ClassTemplateDecl *,
1962 if (const auto *PartialSpec =
1963 SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
1964 return PartialSpec->PartialSpecialization;
1965
1966 return cast<ClassTemplateDecl *>(SpecializedTemplate);
1967 }
1968
1969 /// Retrieve the set of template arguments that should be used
1970 /// to instantiate members of the class template or class template partial
1971 /// specialization from which this class template specialization was
1972 /// instantiated.
1973 ///
1974 /// \returns For a class template specialization instantiated from the primary
1975 /// template, this function will return the same template arguments as
1976 /// getTemplateArgs(). For a class template specialization instantiated from
1977 /// a class template partial specialization, this function will return the
1978 /// deduced template arguments for the class template partial specialization
1979 /// itself.
1981 if (const auto *PartialSpec =
1982 SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
1983 return *PartialSpec->TemplateArgs;
1984
1985 return getTemplateArgs();
1986 }
1987
1988 /// Note that this class template specialization is actually an
1989 /// instantiation of the given class template partial specialization whose
1990 /// template arguments have been deduced.
1992 const TemplateArgumentList *TemplateArgs) {
1993 assert(!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) &&
1994 "Already set to a class template partial specialization!");
1995 auto *PS = new (getASTContext()) SpecializedPartialSpecialization();
1996 PS->PartialSpecialization = PartialSpec;
1997 PS->TemplateArgs = TemplateArgs;
1998 SpecializedTemplate = PS;
1999 }
2000
2001 /// Note that this class template specialization is an instantiation
2002 /// of the given class template.
2004 assert(!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) &&
2005 "Previously set to a class template partial specialization!");
2006 SpecializedTemplate = TemplDecl;
2007 }
2008
2009 /// Retrieve the template argument list as written in the sources,
2010 /// if any.
2012 if (auto *Info =
2013 dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo))
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 =
2022 dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo))
2023 Info->TemplateArgsAsWritten = ArgsWritten;
2024 else
2025 ExplicitInfo = ArgsWritten;
2026 }
2027
2028 /// Set the template argument list as written in the sources.
2032 }
2033
2034 /// Gets the location of the extern keyword, if present.
2036 if (auto *Info =
2037 dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo))
2038 return Info->ExternKeywordLoc;
2039 return SourceLocation();
2040 }
2041
2042 /// Sets the location of the extern keyword.
2044
2045 /// Gets the location of the template keyword, if present.
2047 if (auto *Info =
2048 dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo))
2049 return Info->TemplateKeywordLoc;
2050 return SourceLocation();
2051 }
2052
2053 /// Sets the location of the template keyword.
2055
2056 SourceRange getSourceRange() const override LLVM_READONLY;
2057
2058 void Profile(llvm::FoldingSetNodeID &ID) const {
2059 Profile(ID, TemplateArgs->asArray(), getASTContext());
2060 }
2061
2062 static void
2063 Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
2064 const ASTContext &Context) {
2065 ID.AddInteger(TemplateArgs.size());
2066 for (const TemplateArgument &TemplateArg : TemplateArgs)
2067 TemplateArg.Profile(ID, Context);
2068 }
2069
2070 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2071
2072 static bool classofKind(Kind K) {
2073 return K >= firstClassTemplateSpecialization &&
2074 K <= lastClassTemplateSpecialization;
2075 }
2076};
2077
2080 /// The list of template parameters
2081 TemplateParameterList *TemplateParams = nullptr;
2082
2083 /// The class template partial specialization from which this
2084 /// class template partial specialization was instantiated.
2085 ///
2086 /// The boolean value will be true to indicate that this class template
2087 /// partial specialization was specialized at this level.
2088 llvm::PointerIntPair<ClassTemplatePartialSpecializationDecl *, 1, bool>
2089 InstantiatedFromMember;
2090
2092 ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc,
2094 ClassTemplateDecl *SpecializedTemplate, ArrayRef<TemplateArgument> Args,
2096
2098 : ClassTemplateSpecializationDecl(C, ClassTemplatePartialSpecialization),
2099 InstantiatedFromMember(nullptr, false) {}
2100
2101 void anchor() override;
2102
2103public:
2104 friend class ASTDeclReader;
2105 friend class ASTDeclWriter;
2106
2108 Create(ASTContext &Context, TagKind TK, DeclContext *DC,
2109 SourceLocation StartLoc, SourceLocation IdLoc,
2110 TemplateParameterList *Params, ClassTemplateDecl *SpecializedTemplate,
2111 ArrayRef<TemplateArgument> Args, QualType CanonInjectedType,
2113
2116
2118 return cast<ClassTemplatePartialSpecializationDecl>(
2119 static_cast<ClassTemplateSpecializationDecl *>(
2120 this)->getMostRecentDecl());
2121 }
2122
2123 /// Get the list of template parameters
2125 return TemplateParams;
2126 }
2127
2128 /// Get the template argument list of the template parameter list.
2130 getInjectedTemplateArgs(const ASTContext &Context) const {
2132 }
2133
2134 /// \brief All associated constraints of this partial specialization,
2135 /// including the requires clause and any constraints derived from
2136 /// constrained-parameters.
2137 ///
2138 /// The constraints in the resulting list are to be treated as if in a
2139 /// conjunction ("and").
2141 TemplateParams->getAssociatedConstraints(AC);
2142 }
2143
2145 return TemplateParams->hasAssociatedConstraints();
2146 }
2147
2148 /// Retrieve the member class template partial specialization from
2149 /// which this particular class template partial specialization was
2150 /// instantiated.
2151 ///
2152 /// \code
2153 /// template<typename T>
2154 /// struct Outer {
2155 /// template<typename U> struct Inner;
2156 /// template<typename U> struct Inner<U*> { }; // #1
2157 /// };
2158 ///
2159 /// Outer<float>::Inner<int*> ii;
2160 /// \endcode
2161 ///
2162 /// In this example, the instantiation of \c Outer<float>::Inner<int*> will
2163 /// end up instantiating the partial specialization
2164 /// \c Outer<float>::Inner<U*>, which itself was instantiated from the class
2165 /// template partial specialization \c Outer<T>::Inner<U*>. Given
2166 /// \c Outer<float>::Inner<U*>, this function would return
2167 /// \c Outer<T>::Inner<U*>.
2169 const auto *First =
2170 cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2171 return First->InstantiatedFromMember.getPointer();
2172 }
2176 }
2177
2180 auto *First = cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2181 First->InstantiatedFromMember.setPointer(PartialSpec);
2182 }
2183
2184 /// Determines whether this class template partial specialization
2185 /// template was a specialization of a member partial specialization.
2186 ///
2187 /// In the following example, the member template partial specialization
2188 /// \c X<int>::Inner<T*> is a member specialization.
2189 ///
2190 /// \code
2191 /// template<typename T>
2192 /// struct X {
2193 /// template<typename U> struct Inner;
2194 /// template<typename U> struct Inner<U*>;
2195 /// };
2196 ///
2197 /// template<> template<typename T>
2198 /// struct X<int>::Inner<T*> { /* ... */ };
2199 /// \endcode
2201 const auto *First =
2202 cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2203 return First->InstantiatedFromMember.getInt();
2204 }
2205
2206 /// Note that this member template is a specialization.
2208 auto *First = cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2209 assert(First->InstantiatedFromMember.getPointer() &&
2210 "Only member templates can be member template specializations");
2211 return First->InstantiatedFromMember.setInt(true);
2212 }
2213
2214 /// Retrieves the injected specialization type for this partial
2215 /// specialization. This is not the same as the type-decl-type for
2216 /// this partial specialization, which is an InjectedClassNameType.
2218 assert(getTypeForDecl() && "partial specialization has no type set!");
2219 return cast<InjectedClassNameType>(getTypeForDecl())
2220 ->getInjectedSpecializationType();
2221 }
2222
2223 SourceRange getSourceRange() const override LLVM_READONLY;
2224
2225 void Profile(llvm::FoldingSetNodeID &ID) const {
2227 getASTContext());
2228 }
2229
2230 static void
2231 Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
2232 TemplateParameterList *TPL, const ASTContext &Context);
2233
2234 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2235
2236 static bool classofKind(Kind K) {
2237 return K == ClassTemplatePartialSpecialization;
2238 }
2239};
2240
2241/// Declaration of a class template.
2243protected:
2244 /// Data that is common to all of the declarations of a given
2245 /// class template.
2247 /// The class template specializations for this class
2248 /// template, including explicit specializations and instantiations.
2249 llvm::FoldingSetVector<ClassTemplateSpecializationDecl> Specializations;
2250
2251 /// The class template partial specializations for this class
2252 /// template.
2253 llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>
2255
2256 /// The injected-class-name type for this class template.
2258
2259 Common() = default;
2260 };
2261
2262 /// Retrieve the set of specializations of this class template.
2263 llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
2264 getSpecializations() const;
2265
2266 /// Retrieve the set of partial specializations of this class
2267 /// template.
2268 llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
2270
2273 NamedDecl *Decl)
2274 : RedeclarableTemplateDecl(ClassTemplate, C, DC, L, Name, Params, Decl) {}
2275
2276 CommonBase *newCommon(ASTContext &C) const override;
2277
2279 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
2280 }
2281
2283
2284public:
2285
2286 friend class ASTDeclReader;
2287 friend class ASTDeclWriter;
2289
2290 /// Load any lazily-loaded specializations from the external source.
2291 void LoadLazySpecializations(bool OnlyPartial = false) const;
2292
2293 /// Get the underlying class declarations of the template.
2295 return static_cast<CXXRecordDecl *>(TemplatedDecl);
2296 }
2297
2298 /// Returns whether this template declaration defines the primary
2299 /// class pattern.
2302 }
2303
2304 /// \brief Create a class template node.
2307 DeclarationName Name,
2308 TemplateParameterList *Params,
2309 NamedDecl *Decl);
2310
2311 /// Create an empty class template node.
2313
2314 /// Return the specialization with the provided arguments if it exists,
2315 /// otherwise return the insertion point.
2317 findSpecialization(ArrayRef<TemplateArgument> Args, void *&InsertPos);
2318
2319 /// Insert the specified specialization knowing that it is not already
2320 /// in. InsertPos must be obtained from findSpecialization.
2321 void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos);
2322
2324 return cast<ClassTemplateDecl>(
2326 }
2328 return cast<ClassTemplateDecl>(
2330 }
2331
2332 /// Retrieve the previous declaration of this class template, or
2333 /// nullptr if no such declaration exists.
2335 return cast_or_null<ClassTemplateDecl>(
2336 static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
2337 }
2339 return cast_or_null<ClassTemplateDecl>(
2340 static_cast<const RedeclarableTemplateDecl *>(
2341 this)->getPreviousDecl());
2342 }
2343
2345 return cast<ClassTemplateDecl>(
2346 static_cast<RedeclarableTemplateDecl *>(this)->getMostRecentDecl());
2347 }
2349 return const_cast<ClassTemplateDecl*>(this)->getMostRecentDecl();
2350 }
2351
2353 return cast_or_null<ClassTemplateDecl>(
2355 }
2356
2357 /// Return the partial specialization with the provided arguments if it
2358 /// exists, otherwise return the insertion point.
2361 TemplateParameterList *TPL, void *&InsertPos);
2362
2363 /// Insert the specified partial specialization knowing that it is not
2364 /// already in. InsertPos must be obtained from findPartialSpecialization.
2366 void *InsertPos);
2367
2368 /// Retrieve the partial specializations as an ordered list.
2371
2372 /// Find a class template partial specialization with the given
2373 /// type T.
2374 ///
2375 /// \param T a dependent type that names a specialization of this class
2376 /// template.
2377 ///
2378 /// \returns the class template partial specialization that exactly matches
2379 /// the type \p T, or nullptr if no such partial specialization exists.
2381
2382 /// Find a class template partial specialization which was instantiated
2383 /// from the given member partial specialization.
2384 ///
2385 /// \param D a member class template partial specialization.
2386 ///
2387 /// \returns the class template partial specialization which was instantiated
2388 /// from the given member partial specialization, or nullptr if no such
2389 /// partial specialization exists.
2393
2394 /// Retrieve the template specialization type of the
2395 /// injected-class-name for this class template.
2396 ///
2397 /// The injected-class-name for a class template \c X is \c
2398 /// X<template-args>, where \c template-args is formed from the
2399 /// template arguments that correspond to the template parameters of
2400 /// \c X. For example:
2401 ///
2402 /// \code
2403 /// template<typename T, int N>
2404 /// struct array {
2405 /// typedef array this_type; // "array" is equivalent to "array<T, N>"
2406 /// };
2407 /// \endcode
2409
2411 using spec_range = llvm::iterator_range<spec_iterator>;
2412
2414 return spec_range(spec_begin(), spec_end());
2415 }
2416
2418 return makeSpecIterator(getSpecializations(), false);
2419 }
2420
2422 return makeSpecIterator(getSpecializations(), true);
2423 }
2424
2425 // Implement isa/cast/dyncast support
2426 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2427 static bool classofKind(Kind K) { return K == ClassTemplate; }
2428};
2429
2430/// Declaration of a friend template.
2431///
2432/// For example:
2433/// \code
2434/// template <typename T> class A {
2435/// friend class MyVector<T>; // not a friend template
2436/// template <typename U> friend class B; // not a friend template
2437/// template <typename U> friend class Foo<T>::Nested; // friend template
2438/// };
2439/// \endcode
2440///
2441/// \note This class is not currently in use. All of the above
2442/// will yield a FriendDecl, not a FriendTemplateDecl.
2443class FriendTemplateDecl : public Decl {
2444 virtual void anchor();
2445
2446public:
2447 using FriendUnion = llvm::PointerUnion<NamedDecl *,TypeSourceInfo *>;
2448
2449private:
2450 // The number of template parameters; always non-zero.
2451 unsigned NumParams = 0;
2452
2453 // The parameter list.
2454 TemplateParameterList **Params = nullptr;
2455
2456 // The declaration that's a friend of this class.
2457 FriendUnion Friend;
2458
2459 // Location of the 'friend' specifier.
2460 SourceLocation FriendLoc;
2461
2463 TemplateParameterList **Params, unsigned NumParams,
2464 FriendUnion Friend, SourceLocation FriendLoc)
2465 : Decl(Decl::FriendTemplate, DC, Loc), NumParams(NumParams),
2466 Params(Params), Friend(Friend), FriendLoc(FriendLoc) {}
2467
2468 FriendTemplateDecl(EmptyShell Empty) : Decl(Decl::FriendTemplate, Empty) {}
2469
2470public:
2471 friend class ASTDeclReader;
2472
2473 static FriendTemplateDecl *
2476 SourceLocation FriendLoc);
2477
2479
2480 /// If this friend declaration names a templated type (or
2481 /// a dependent member type of a templated type), return that
2482 /// type; otherwise return null.
2484 return Friend.dyn_cast<TypeSourceInfo*>();
2485 }
2486
2487 /// If this friend declaration names a templated function (or
2488 /// a member function of a templated type), return that type;
2489 /// otherwise return null.
2491 return Friend.dyn_cast<NamedDecl*>();
2492 }
2493
2494 /// Retrieves the location of the 'friend' keyword.
2496 return FriendLoc;
2497 }
2498
2500 assert(i <= NumParams);
2501 return Params[i];
2502 }
2503
2504 unsigned getNumTemplateParameters() const {
2505 return NumParams;
2506 }
2507
2508 // Implement isa/cast/dyncast/etc.
2509 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2510 static bool classofKind(Kind K) { return K == Decl::FriendTemplate; }
2511};
2512
2513/// Declaration of an alias template.
2514///
2515/// For example:
2516/// \code
2517/// template <typename T> using V = std::map<T*, int, MyCompare<T>>;
2518/// \endcode
2520protected:
2522
2525 NamedDecl *Decl)
2526 : RedeclarableTemplateDecl(TypeAliasTemplate, C, DC, L, Name, Params,
2527 Decl) {}
2528
2529 CommonBase *newCommon(ASTContext &C) const override;
2530
2532 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
2533 }
2534
2535public:
2536 friend class ASTDeclReader;
2537 friend class ASTDeclWriter;
2538
2539 /// Get the underlying function declaration of the template.
2541 return static_cast<TypeAliasDecl *>(TemplatedDecl);
2542 }
2543
2544
2546 return cast<TypeAliasTemplateDecl>(
2548 }
2550 return cast<TypeAliasTemplateDecl>(
2552 }
2553
2554 /// Retrieve the previous declaration of this function template, or
2555 /// nullptr if no such declaration exists.
2557 return cast_or_null<TypeAliasTemplateDecl>(
2558 static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
2559 }
2561 return cast_or_null<TypeAliasTemplateDecl>(
2562 static_cast<const RedeclarableTemplateDecl *>(
2563 this)->getPreviousDecl());
2564 }
2565
2567 return cast_or_null<TypeAliasTemplateDecl>(
2569 }
2570
2571 /// Create a function template node.
2574 DeclarationName Name,
2575 TemplateParameterList *Params,
2576 NamedDecl *Decl);
2577
2578 /// Create an empty alias template node.
2581
2582 // Implement isa/cast/dyncast support
2583 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2584 static bool classofKind(Kind K) { return K == TypeAliasTemplate; }
2585};
2586
2587/// Represents a variable template specialization, which refers to
2588/// a variable template with a given set of template arguments.
2589///
2590/// Variable template specializations represent both explicit
2591/// specializations of variable templates, as in the example below, and
2592/// implicit instantiations of variable templates.
2593///
2594/// \code
2595/// template<typename T> constexpr T pi = T(3.1415926535897932385);
2596///
2597/// template<>
2598/// constexpr float pi<float>; // variable template specialization pi<float>
2599/// \endcode
2601 public llvm::FoldingSetNode {
2602
2603 /// Structure that stores information about a variable template
2604 /// specialization that was instantiated from a variable template partial
2605 /// specialization.
2606 struct SpecializedPartialSpecialization {
2607 /// The variable template partial specialization from which this
2608 /// variable template specialization was instantiated.
2609 VarTemplatePartialSpecializationDecl *PartialSpecialization;
2610
2611 /// The template argument list deduced for the variable template
2612 /// partial specialization itself.
2613 const TemplateArgumentList *TemplateArgs;
2614 };
2615
2616 /// The template that this specialization specializes.
2617 llvm::PointerUnion<VarTemplateDecl *, SpecializedPartialSpecialization *>
2618 SpecializedTemplate;
2619
2620 /// Further info for explicit template specialization/instantiation.
2621 /// Does not apply to implicit specializations.
2622 SpecializationOrInstantiationInfo ExplicitInfo = nullptr;
2623
2624 /// The template arguments used to describe this specialization.
2625 const TemplateArgumentList *TemplateArgs;
2626
2627 /// The point where this template was instantiated (if any).
2628 SourceLocation PointOfInstantiation;
2629
2630 /// The kind of specialization this declaration refers to.
2631 LLVM_PREFERRED_TYPE(TemplateSpecializationKind)
2632 unsigned SpecializationKind : 3;
2633
2634 /// Whether this declaration is a complete definition of the
2635 /// variable template specialization. We can't otherwise tell apart
2636 /// an instantiated declaration from an instantiated definition with
2637 /// no initializer.
2638 LLVM_PREFERRED_TYPE(bool)
2639 unsigned IsCompleteDefinition : 1;
2640
2641protected:
2643 SourceLocation StartLoc, SourceLocation IdLoc,
2644 VarTemplateDecl *SpecializedTemplate,
2645 QualType T, TypeSourceInfo *TInfo,
2646 StorageClass S,
2648
2649 explicit VarTemplateSpecializationDecl(Kind DK, ASTContext &Context);
2650
2651public:
2652 friend class ASTDeclReader;
2653 friend class ASTDeclWriter;
2654 friend class VarDecl;
2655
2657 Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
2658 SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
2659 TypeSourceInfo *TInfo, StorageClass S,
2663
2664 void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy,
2665 bool Qualified) const override;
2666
2668 VarDecl *Recent = static_cast<VarDecl *>(this)->getMostRecentDecl();
2669 return cast<VarTemplateSpecializationDecl>(Recent);
2670 }
2671
2672 /// Retrieve the template that this specialization specializes.
2674
2675 /// Retrieve the template arguments of the variable template
2676 /// specialization.
2677 const TemplateArgumentList &getTemplateArgs() const { return *TemplateArgs; }
2678
2679 /// Determine the kind of specialization that this
2680 /// declaration represents.
2682 return static_cast<TemplateSpecializationKind>(SpecializationKind);
2683 }
2684
2687 }
2688
2690 return isExplicitSpecialization() &&
2691 isa<CXXRecordDecl>(getLexicalDeclContext());
2692 }
2693
2694 /// True if this declaration is an explicit specialization,
2695 /// explicit instantiation declaration, or explicit instantiation
2696 /// definition.
2700 }
2701
2703 SpecializationKind = TSK;
2704 }
2705
2706 /// Get the point of instantiation (if any), or null if none.
2708 return PointOfInstantiation;
2709 }
2710
2712 assert(Loc.isValid() && "point of instantiation must be valid!");
2713 PointOfInstantiation = Loc;
2714 }
2715
2716 void setCompleteDefinition() { IsCompleteDefinition = true; }
2717
2718 /// If this variable template specialization is an instantiation of
2719 /// a template (rather than an explicit specialization), return the
2720 /// variable template or variable template partial specialization from which
2721 /// it was instantiated.
2722 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
2725 return llvm::PointerUnion<VarTemplateDecl *,
2727
2729 }
2730
2731 /// Retrieve the variable template or variable template partial
2732 /// specialization which was specialized by this.
2733 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
2735 if (const auto *PartialSpec =
2736 SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
2737 return PartialSpec->PartialSpecialization;
2738
2739 return cast<VarTemplateDecl *>(SpecializedTemplate);
2740 }
2741
2742 /// Retrieve the set of template arguments that should be used
2743 /// to instantiate the initializer of the variable template or variable
2744 /// template partial specialization from which this variable template
2745 /// specialization was instantiated.
2746 ///
2747 /// \returns For a variable template specialization instantiated from the
2748 /// primary template, this function will return the same template arguments
2749 /// as getTemplateArgs(). For a variable template specialization instantiated
2750 /// from a variable template partial specialization, this function will the
2751 /// return deduced template arguments for the variable template partial
2752 /// specialization itself.
2754 if (const auto *PartialSpec =
2755 SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
2756 return *PartialSpec->TemplateArgs;
2757
2758 return getTemplateArgs();
2759 }
2760
2761 /// Note that this variable template specialization is actually an
2762 /// instantiation of the given variable template partial specialization whose
2763 /// template arguments have been deduced.
2765 const TemplateArgumentList *TemplateArgs) {
2766 assert(!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) &&
2767 "Already set to a variable template partial specialization!");
2768 auto *PS = new (getASTContext()) SpecializedPartialSpecialization();
2769 PS->PartialSpecialization = PartialSpec;
2770 PS->TemplateArgs = TemplateArgs;
2771 SpecializedTemplate = PS;
2772 }
2773
2774 /// Note that this variable template specialization is an instantiation
2775 /// of the given variable template.
2777 assert(!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) &&
2778 "Previously set to a variable template partial specialization!");
2779 SpecializedTemplate = TemplDecl;
2780 }
2781
2782 /// Retrieve the template argument list as written in the sources,
2783 /// if any.
2785 if (auto *Info =
2786 dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo))
2787 return Info->TemplateArgsAsWritten;
2788 return cast<const ASTTemplateArgumentListInfo *>(ExplicitInfo);
2789 }
2790
2791 /// Set the template argument list as written in the sources.
2792 void
2794 if (auto *Info =
2795 dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo))
2796 Info->TemplateArgsAsWritten = ArgsWritten;
2797 else
2798 ExplicitInfo = ArgsWritten;
2799 }
2800
2801 /// Set the template argument list as written in the sources.
2805 }
2806
2807 /// Gets the location of the extern keyword, if present.
2809 if (auto *Info =
2810 dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo))
2811 return Info->ExternKeywordLoc;
2812 return SourceLocation();
2813 }
2814
2815 /// Sets the location of the extern keyword.
2817
2818 /// Gets the location of the template keyword, if present.
2820 if (auto *Info =
2821 dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo))
2822 return Info->TemplateKeywordLoc;
2823 return SourceLocation();
2824 }
2825
2826 /// Sets the location of the template keyword.
2828
2829 SourceRange getSourceRange() const override LLVM_READONLY;
2830
2831 void Profile(llvm::FoldingSetNodeID &ID) const {
2832 Profile(ID, TemplateArgs->asArray(), getASTContext());
2833 }
2834
2835 static void Profile(llvm::FoldingSetNodeID &ID,
2836 ArrayRef<TemplateArgument> TemplateArgs,
2837 const ASTContext &Context) {
2838 ID.AddInteger(TemplateArgs.size());
2839 for (const TemplateArgument &TemplateArg : TemplateArgs)
2840 TemplateArg.Profile(ID, Context);
2841 }
2842
2843 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2844
2845 static bool classofKind(Kind K) {
2846 return K >= firstVarTemplateSpecialization &&
2847 K <= lastVarTemplateSpecialization;
2848 }
2849};
2850
2853 /// The list of template parameters
2854 TemplateParameterList *TemplateParams = nullptr;
2855
2856 /// The variable template partial specialization from which this
2857 /// variable template partial specialization was instantiated.
2858 ///
2859 /// The boolean value will be true to indicate that this variable template
2860 /// partial specialization was specialized at this level.
2861 llvm::PointerIntPair<VarTemplatePartialSpecializationDecl *, 1, bool>
2862 InstantiatedFromMember;
2863
2865 ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
2867 VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
2869
2871 : VarTemplateSpecializationDecl(VarTemplatePartialSpecialization,
2872 Context),
2873 InstantiatedFromMember(nullptr, false) {}
2874
2875 void anchor() override;
2876
2877public:
2878 friend class ASTDeclReader;
2879 friend class ASTDeclWriter;
2880
2882 Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
2884 VarTemplateDecl *SpecializedTemplate, QualType T,
2885 TypeSourceInfo *TInfo, StorageClass S,
2887
2890
2892 return cast<VarTemplatePartialSpecializationDecl>(
2893 static_cast<VarTemplateSpecializationDecl *>(
2894 this)->getMostRecentDecl());
2895 }
2896
2897 /// Get the list of template parameters
2899 return TemplateParams;
2900 }
2901
2902 /// Get the template argument list of the template parameter list.
2904 getInjectedTemplateArgs(const ASTContext &Context) const {
2906 }
2907
2908 /// \brief All associated constraints of this partial specialization,
2909 /// including the requires clause and any constraints derived from
2910 /// constrained-parameters.
2911 ///
2912 /// The constraints in the resulting list are to be treated as if in a
2913 /// conjunction ("and").
2915 TemplateParams->getAssociatedConstraints(AC);
2916 }
2917
2919 return TemplateParams->hasAssociatedConstraints();
2920 }
2921
2922 /// \brief Retrieve the member variable template partial specialization from
2923 /// which this particular variable template partial specialization was
2924 /// instantiated.
2925 ///
2926 /// \code
2927 /// template<typename T>
2928 /// struct Outer {
2929 /// template<typename U> U Inner;
2930 /// template<typename U> U* Inner<U*> = (U*)(0); // #1
2931 /// };
2932 ///
2933 /// template int* Outer<float>::Inner<int*>;
2934 /// \endcode
2935 ///
2936 /// In this example, the instantiation of \c Outer<float>::Inner<int*> will
2937 /// end up instantiating the partial specialization
2938 /// \c Outer<float>::Inner<U*>, which itself was instantiated from the
2939 /// variable template partial specialization \c Outer<T>::Inner<U*>. Given
2940 /// \c Outer<float>::Inner<U*>, this function would return
2941 /// \c Outer<T>::Inner<U*>.
2943 const auto *First =
2944 cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2945 return First->InstantiatedFromMember.getPointer();
2946 }
2947
2948 void
2950 auto *First = cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2951 First->InstantiatedFromMember.setPointer(PartialSpec);
2952 }
2953
2954 /// Determines whether this variable template partial specialization
2955 /// was a specialization of a member partial specialization.
2956 ///
2957 /// In the following example, the member template partial specialization
2958 /// \c X<int>::Inner<T*> is a member specialization.
2959 ///
2960 /// \code
2961 /// template<typename T>
2962 /// struct X {
2963 /// template<typename U> U Inner;
2964 /// template<typename U> U* Inner<U*> = (U*)(0);
2965 /// };
2966 ///
2967 /// template<> template<typename T>
2968 /// U* X<int>::Inner<T*> = (T*)(0) + 1;
2969 /// \endcode
2971 const auto *First =
2972 cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2973 return First->InstantiatedFromMember.getInt();
2974 }
2975
2976 /// Note that this member template is a specialization.
2978 auto *First = cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2979 assert(First->InstantiatedFromMember.getPointer() &&
2980 "Only member templates can be member template specializations");
2981 return First->InstantiatedFromMember.setInt(true);
2982 }
2983
2984 SourceRange getSourceRange() const override LLVM_READONLY;
2985
2986 void Profile(llvm::FoldingSetNodeID &ID) const {
2988 getASTContext());
2989 }
2990
2991 static void
2992 Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
2993 TemplateParameterList *TPL, const ASTContext &Context);
2994
2995 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2996
2997 static bool classofKind(Kind K) {
2998 return K == VarTemplatePartialSpecialization;
2999 }
3000};
3001
3002/// Declaration of a variable template.
3004protected:
3005 /// Data that is common to all of the declarations of a given
3006 /// variable template.
3008 /// The variable template specializations for this variable
3009 /// template, including explicit specializations and instantiations.
3010 llvm::FoldingSetVector<VarTemplateSpecializationDecl> Specializations;
3011
3012 /// The variable template partial specializations for this variable
3013 /// template.
3014 llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl>
3016
3017 Common() = default;
3018 };
3019
3020 /// Retrieve the set of specializations of this variable template.
3021 llvm::FoldingSetVector<VarTemplateSpecializationDecl> &
3022 getSpecializations() const;
3023
3024 /// Retrieve the set of partial specializations of this class
3025 /// template.
3026 llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &
3028
3031 NamedDecl *Decl)
3032 : RedeclarableTemplateDecl(VarTemplate, C, DC, L, Name, Params, Decl) {}
3033
3034 CommonBase *newCommon(ASTContext &C) const override;
3035
3037 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
3038 }
3039
3040public:
3041 friend class ASTDeclReader;
3042 friend class ASTDeclWriter;
3043
3044 /// Load any lazily-loaded specializations from the external source.
3045 void LoadLazySpecializations(bool OnlyPartial = false) const;
3046
3047 /// Get the underlying variable declarations of the template.
3049 return static_cast<VarDecl *>(TemplatedDecl);
3050 }
3051
3052 /// Returns whether this template declaration defines the primary
3053 /// variable pattern.
3056 }
3057
3059
3060 /// Create a variable template node.
3063 TemplateParameterList *Params,
3064 VarDecl *Decl);
3065
3066 /// Create an empty variable template node.
3068
3069 /// Return the specialization with the provided arguments if it exists,
3070 /// otherwise return the insertion point.
3072 findSpecialization(ArrayRef<TemplateArgument> Args, void *&InsertPos);
3073
3074 /// Insert the specified specialization knowing that it is not already
3075 /// in. InsertPos must be obtained from findSpecialization.
3076 void AddSpecialization(VarTemplateSpecializationDecl *D, void *InsertPos);
3077
3079 return cast<VarTemplateDecl>(RedeclarableTemplateDecl::getCanonicalDecl());
3080 }
3082 return cast<VarTemplateDecl>(RedeclarableTemplateDecl::getCanonicalDecl());
3083 }
3084
3085 /// Retrieve the previous declaration of this variable template, or
3086 /// nullptr if no such declaration exists.
3088 return cast_or_null<VarTemplateDecl>(
3089 static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
3090 }
3092 return cast_or_null<VarTemplateDecl>(
3093 static_cast<const RedeclarableTemplateDecl *>(
3094 this)->getPreviousDecl());
3095 }
3096
3098 return cast<VarTemplateDecl>(
3099 static_cast<RedeclarableTemplateDecl *>(this)->getMostRecentDecl());
3100 }
3102 return const_cast<VarTemplateDecl *>(this)->getMostRecentDecl();
3103 }
3104
3106 return cast_or_null<VarTemplateDecl>(
3108 }
3109
3110 /// Return the partial specialization with the provided arguments if it
3111 /// exists, otherwise return the insertion point.
3114 TemplateParameterList *TPL, void *&InsertPos);
3115
3116 /// Insert the specified partial specialization knowing that it is not
3117 /// already in. InsertPos must be obtained from findPartialSpecialization.
3119 void *InsertPos);
3120
3121 /// Retrieve the partial specializations as an ordered list.
3124
3125 /// Find a variable template partial specialization which was
3126 /// instantiated
3127 /// from the given member partial specialization.
3128 ///
3129 /// \param D a member variable template partial specialization.
3130 ///
3131 /// \returns the variable template partial specialization which was
3132 /// instantiated
3133 /// from the given member partial specialization, or nullptr if no such
3134 /// partial specialization exists.
3137
3139 using spec_range = llvm::iterator_range<spec_iterator>;
3140
3142 return spec_range(spec_begin(), spec_end());
3143 }
3144
3146 return makeSpecIterator(getSpecializations(), false);
3147 }
3148
3150 return makeSpecIterator(getSpecializations(), true);
3151 }
3152
3153 // Implement isa/cast/dyncast support
3154 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3155 static bool classofKind(Kind K) { return K == VarTemplate; }
3156};
3157
3158/// Declaration of a C++20 concept.
3159class ConceptDecl : public TemplateDecl, public Mergeable<ConceptDecl> {
3160protected:
3162
3165 : TemplateDecl(Concept, DC, L, Name, Params),
3167public:
3169 DeclarationName Name,
3170 TemplateParameterList *Params,
3171 Expr *ConstraintExpr = nullptr);
3173
3175 return ConstraintExpr;
3176 }
3177
3178 bool hasDefinition() const { return ConstraintExpr != nullptr; }
3179
3181
3182 SourceRange getSourceRange() const override LLVM_READONLY {
3183 return SourceRange(getTemplateParameters()->getTemplateLoc(),
3185 : SourceLocation());
3186 }
3187
3188 bool isTypeConcept() const {
3189 return isa<TemplateTypeParmDecl>(getTemplateParameters()->getParam(0));
3190 }
3191
3193 return cast<ConceptDecl>(getPrimaryMergedDecl(this));
3194 }
3196 return const_cast<ConceptDecl *>(this)->getCanonicalDecl();
3197 }
3198
3199 // Implement isa/cast/dyncast/etc.
3200 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3201 static bool classofKind(Kind K) { return K == Concept; }
3202
3203 friend class ASTReader;
3204 friend class ASTDeclReader;
3205 friend class ASTDeclWriter;
3206};
3207
3208// An implementation detail of ConceptSpecialicationExpr that holds the template
3209// arguments, so we can later use this to reconstitute the template arguments
3210// during constraint checking.
3212 : public Decl,
3213 private llvm::TrailingObjects<ImplicitConceptSpecializationDecl,
3214 TemplateArgument> {
3215 unsigned NumTemplateArgs;
3216
3218 ArrayRef<TemplateArgument> ConvertedArgs);
3219 ImplicitConceptSpecializationDecl(EmptyShell Empty, unsigned NumTemplateArgs);
3220
3221public:
3224 ArrayRef<TemplateArgument> ConvertedArgs);
3227 unsigned NumTemplateArgs);
3228
3230 return ArrayRef<TemplateArgument>(getTrailingObjects<TemplateArgument>(),
3231 NumTemplateArgs);
3232 }
3234
3235 static bool classofKind(Kind K) { return K == ImplicitConceptSpecialization; }
3236 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3237
3239 friend class ASTDeclReader;
3240};
3241
3242/// A template parameter object.
3243///
3244/// Template parameter objects represent values of class type used as template
3245/// arguments. There is one template parameter object for each such distinct
3246/// value used as a template argument across the program.
3247///
3248/// \code
3249/// struct A { int x, y; };
3250/// template<A> struct S;
3251/// S<A{1, 2}> s1;
3252/// S<A{1, 2}> s2; // same type, argument is same TemplateParamObjectDecl.
3253/// \endcode
3255 public Mergeable<TemplateParamObjectDecl>,
3256 public llvm::FoldingSetNode {
3257private:
3258 /// The value of this template parameter object.
3259 APValue Value;
3260
3262 : ValueDecl(TemplateParamObject, DC, SourceLocation(), DeclarationName(),
3263 T),
3264 Value(V) {}
3265
3267 const APValue &V);
3268 static TemplateParamObjectDecl *CreateDeserialized(ASTContext &C,
3270
3271 /// Only ASTContext::getTemplateParamObjectDecl and deserialization
3272 /// create these.
3273 friend class ASTContext;
3274 friend class ASTReader;
3275 friend class ASTDeclReader;
3276
3277public:
3278 /// Print this template parameter object in a human-readable format.
3279 void printName(llvm::raw_ostream &OS,
3280 const PrintingPolicy &Policy) const override;
3281
3282 /// Print this object as an equivalent expression.
3283 void printAsExpr(llvm::raw_ostream &OS) const;
3284 void printAsExpr(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const;
3285
3286 /// Print this object as an initializer suitable for a variable of the
3287 /// object's type.
3288 void printAsInit(llvm::raw_ostream &OS) const;
3289 void printAsInit(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const;
3290
3291 const APValue &getValue() const { return Value; }
3292
3293 static void Profile(llvm::FoldingSetNodeID &ID, QualType T,
3294 const APValue &V) {
3295 ID.AddPointer(T.getCanonicalType().getAsOpaquePtr());
3296 V.Profile(ID);
3297 }
3298 void Profile(llvm::FoldingSetNodeID &ID) {
3299 Profile(ID, getType(), getValue());
3300 }
3301
3303 return getFirstDecl();
3304 }
3306 return getFirstDecl();
3307 }
3308
3309 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3310 static bool classofKind(Kind K) { return K == TemplateParamObject; }
3311};
3312
3314 if (auto *PD = P.dyn_cast<TemplateTypeParmDecl *>())
3315 return PD;
3316 if (auto *PD = P.dyn_cast<NonTypeTemplateParmDecl *>())
3317 return PD;
3318 return cast<TemplateTemplateParmDecl *>(P);
3319}
3320
3322 auto *TD = dyn_cast<TemplateDecl>(D);
3323 return TD && (isa<ClassTemplateDecl>(TD) ||
3324 isa<ClassTemplatePartialSpecializationDecl>(TD) ||
3325 isa<TypeAliasTemplateDecl>(TD) ||
3326 isa<TemplateTemplateParmDecl>(TD))
3327 ? TD
3328 : nullptr;
3329}
3330
3331/// Check whether the template parameter is a pack expansion, and if so,
3332/// determine the number of parameters produced by that expansion. For instance:
3333///
3334/// \code
3335/// template<typename ...Ts> struct A {
3336/// template<Ts ...NTs, template<Ts> class ...TTs, typename ...Us> struct B;
3337/// };
3338/// \endcode
3339///
3340/// In \c A<int,int>::B, \c NTs and \c TTs have expanded pack size 2, and \c Us
3341/// is not a pack expansion, so returns an empty Optional.
3342inline std::optional<unsigned> getExpandedPackSize(const NamedDecl *Param) {
3343 if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
3344 if (TTP->isExpandedParameterPack())
3345 return TTP->getNumExpansionParameters();
3346 }
3347
3348 if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
3349 if (NTTP->isExpandedParameterPack())
3350 return NTTP->getNumExpansionTypes();
3351 }
3352
3353 if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(Param)) {
3354 if (TTP->isExpandedParameterPack())
3355 return TTP->getNumExpansionTemplateParameters();
3356 }
3357
3358 return std::nullopt;
3359}
3360
3361/// Internal helper used by Subst* nodes to retrieve the parameter list
3362/// for their AssociatedDecl.
3363TemplateParameterList *getReplacedTemplateParameterList(Decl *D);
3364
3365} // namespace clang
3366
3367#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:3460
StringRef P
static char ID
Definition: Arena.cpp:183
enum clang::sema::@1704::IndirectLocalPathEntry::EntryKind Kind
const Decl * D
Expr * E
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:1125
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:384
bool isConstrained() const
Definition: Type.h:6581
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:2012
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:1442
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:528
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:911
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:739
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:384
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:693
ArrayRef< FunctionTemplateDecl * > getCandidates() const
Returns the candidates for the primary function template.
Definition: DeclTemplate.h:712
const ASTTemplateArgumentListInfo * TemplateArgumentsAsWritten
The template arguments as written in the sources, if provided.
Definition: DeclTemplate.h:705
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:958
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:980
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:972
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:471
TemplateArgumentList * TemplateArguments
The template arguments used to produce the function template specialization from the function templat...
Definition: DeclTemplate.h:485
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the template specialization kind.
Definition: DeclTemplate.h:546
static void Profile(llvm::FoldingSetNodeID &ID, ArrayRef< TemplateArgument > TemplateArgs, const ASTContext &Context)
Definition: DeclTemplate.h:608
FunctionTemplateDecl * getTemplate() const
Retrieve the template from which this function was specialized.
Definition: DeclTemplate.h:526
MemberSpecializationInfo * getMemberSpecializationInfo() const
Get the specialization info if this function template specialization is also a member specialization:
Definition: DeclTemplate.h:597
const ASTTemplateArgumentListInfo * TemplateArgumentsAsWritten
The template arguments as written in the sources, if provided.
Definition: DeclTemplate.h:489
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this function template specialization.
Definition: DeclTemplate.h:557
void Profile(llvm::FoldingSetNodeID &ID)
Definition: DeclTemplate.h:603
SourceLocation PointOfInstantiation
The point at which this function template specialization was first instantiated.
Definition: DeclTemplate.h:493
FunctionDecl * getFunction() const
Retrieve the declaration of the function template specialization.
Definition: DeclTemplate.h:523
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
Definition: DeclTemplate.h:529
void setPointOfInstantiation(SourceLocation POI)
Set the (first) point of instantiation of this function template specialization.
Definition: DeclTemplate.h:563
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration,...
Definition: DeclTemplate.h:540
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:619
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the template specialization kind.
Definition: DeclTemplate.h:650
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
Definition: DeclTemplate.h:641
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
Definition: DeclTemplate.h:659
MemberSpecializationInfo(NamedDecl *IF, TemplateSpecializationKind TSK, SourceLocation POI=SourceLocation())
Definition: DeclTemplate.h:629
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
Definition: DeclTemplate.h:664
NamedDecl * getInstantiatedFrom() const
Retrieve the member declaration from which this member was instantiated.
Definition: DeclTemplate.h:638
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:7147
A (possibly-)qualified type.
Definition: Type.h:929
Declaration of a redeclarable template.
Definition: DeclTemplate.h:720
static SpecIterator< EntryType > makeSpecIterator(llvm::FoldingSetVector< EntryType > &Specs, bool isEnd)
Definition: DeclTemplate.h:773
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:821
redeclarable_base::redecl_iterator redecl_iterator
Definition: DeclTemplate.h:926
void loadLazySpecializationsImpl(bool OnlyPartial=false) const
bool isMemberSpecialization() const
Determines whether this template was a specialization of a member template.
Definition: DeclTemplate.h:858
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:836
redeclarable_base::redecl_range redecl_range
Definition: DeclTemplate.h:925
CommonBase * Common
Pointer to the common data shared by all declarations of this template.
Definition: DeclTemplate.h:811
static bool classof(const Decl *D)
Definition: DeclTemplate.h:936
RedeclarableTemplateDecl * getInstantiatedFromMemberTemplate() const
Retrieve the member template from which this template was instantiated, or nullptr if this template w...
Definition: DeclTemplate.h:905
static bool classofKind(Kind K)
Definition: DeclTemplate.h:938
virtual CommonBase * newCommon(ASTContext &C) const =0
RedeclarableTemplateDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this template.
Definition: DeclTemplate.h:833
void addSpecializationImpl(llvm::FoldingSetVector< EntryType > &Specs, EntryType *Entry, void *InsertPos)
void setMemberSpecialization()
Note that this member template is a specialization.
Definition: DeclTemplate.h:863
void setInstantiatedFromMemberTemplate(RedeclarableTemplateDecl *TD)
Definition: DeclTemplate.h:909
ArrayRef< TemplateArgument > getInjectedTemplateArgs(const ASTContext &Context) const
Retrieve the "injected" template arguments that correspond to the template parameters of this templat...
Definition: DeclTemplate.h:921
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:466
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:358
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition: Decl.h:3676
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:398
NamedDecl * TemplatedDecl
Definition: DeclTemplate.h:448
TemplateParameterList * TemplateParams
Definition: DeclTemplate.h:449
bool isTypeAlias() const
bool hasAssociatedConstraints() const
void init(NamedDecl *NewTemplatedDecl)
Initialize the underlying templated declaration.
Definition: DeclTemplate.h:457
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
Definition: DeclTemplate.h:430
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclTemplate.h:442
TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params)
Definition: DeclTemplate.h:408
void setTemplateParameters(TemplateParameterList *TParams)
Definition: DeclTemplate.h:452
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:436
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:417
static bool classofKind(Kind K)
Definition: DeclTemplate.h:438
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:3549
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:3384
const Type * getTypeForDecl() const
Definition: Decl.h:3409
A container of type source information.
Definition: Type.h:7908
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type.
Definition: Type.h:2812
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8741
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:886
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:2751
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:6877
BuiltinTemplateKind
Kinds of BuiltinTemplateDecl.
Definition: Builtins.h:308
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:964
llvm::FoldingSetVector< FunctionTemplateSpecializationInfo > Specializations
The function template specializations for this function template, including explicit specializations ...
Definition: DeclTemplate.h:967
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:806
static ArrayRef< TemplateArgument > getTemplateArgs(FunctionTemplateSpecializationInfo *I)
Definition: DeclTemplate.h:952
static DeclType * getDecl(FunctionTemplateSpecializationInfo *I)
Definition: DeclTemplate.h:947
static ArrayRef< TemplateArgument > getTemplateArgs(EntryType *D)
Definition: DeclTemplate.h:745
static DeclType * getDecl(EntryType *D)
Definition: DeclTemplate.h:741
SpecIterator(typename llvm::FoldingSetVector< EntryType >::iterator SetIter)
Definition: DeclTemplate.h:760
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 ...