clang 20.0.0git
DeclTemplate.h
Go to the documentation of this file.
1//===- DeclTemplate.h - Classes for representing C++ templates --*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// Defines the C++ template declaration subclasses.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_DECLTEMPLATE_H
15#define LLVM_CLANG_AST_DECLTEMPLATE_H
16
19#include "clang/AST/Decl.h"
20#include "clang/AST/DeclBase.h"
21#include "clang/AST/DeclCXX.h"
25#include "clang/AST/Type.h"
26#include "clang/Basic/LLVM.h"
29#include "llvm/ADT/ArrayRef.h"
30#include "llvm/ADT/FoldingSet.h"
31#include "llvm/ADT/PointerIntPair.h"
32#include "llvm/ADT/PointerUnion.h"
33#include "llvm/ADT/iterator.h"
34#include "llvm/ADT/iterator_range.h"
35#include "llvm/Support/Casting.h"
36#include "llvm/Support/Compiler.h"
37#include "llvm/Support/TrailingObjects.h"
38#include <cassert>
39#include <cstddef>
40#include <cstdint>
41#include <iterator>
42#include <optional>
43#include <utility>
44
45namespace clang {
46
48class ClassTemplateDecl;
49class ClassTemplatePartialSpecializationDecl;
50class Expr;
51class FunctionTemplateDecl;
52class IdentifierInfo;
53class NonTypeTemplateParmDecl;
54class TemplateDecl;
55class TemplateTemplateParmDecl;
56class TemplateTypeParmDecl;
57class ConceptDecl;
58class UnresolvedSetImpl;
59class VarTemplateDecl;
60class VarTemplatePartialSpecializationDecl;
61
62/// Stores a template parameter of any kind.
64 llvm::PointerUnion<TemplateTypeParmDecl *, NonTypeTemplateParmDecl *,
66
68
69/// Stores a list of template parameters for a TemplateDecl and its
70/// derived classes.
72 : private llvm::TrailingObjects<TemplateParameterList, NamedDecl *,
73 Expr *> {
74 /// The template argument list of the template parameter list.
75 TemplateArgument *InjectedArgs = nullptr;
76
77 /// The location of the 'template' keyword.
78 SourceLocation TemplateLoc;
79
80 /// The locations of the '<' and '>' angle brackets.
81 SourceLocation LAngleLoc, RAngleLoc;
82
83 /// The number of template parameters in this template
84 /// parameter list.
85 unsigned NumParams : 29;
86
87 /// Whether this template parameter list contains an unexpanded parameter
88 /// pack.
89 LLVM_PREFERRED_TYPE(bool)
90 unsigned ContainsUnexpandedParameterPack : 1;
91
92 /// Whether this template parameter list has a requires clause.
93 LLVM_PREFERRED_TYPE(bool)
94 unsigned HasRequiresClause : 1;
95
96 /// Whether any of the template parameters has constrained-parameter
97 /// constraint-expression.
98 LLVM_PREFERRED_TYPE(bool)
99 unsigned HasConstrainedParameters : 1;
100
101protected:
103 SourceLocation LAngleLoc, ArrayRef<NamedDecl *> Params,
104 SourceLocation RAngleLoc, Expr *RequiresClause);
105
106 size_t numTrailingObjects(OverloadToken<NamedDecl *>) const {
107 return NumParams;
108 }
109
110 size_t numTrailingObjects(OverloadToken<Expr *>) const {
111 return HasRequiresClause ? 1 : 0;
112 }
113
114public:
115 template <size_t N, bool HasRequiresClause>
118
120 SourceLocation TemplateLoc,
121 SourceLocation LAngleLoc,
123 SourceLocation RAngleLoc,
124 Expr *RequiresClause);
125
126 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &C) const;
127
128 /// Iterates through the template parameters in this list.
129 using iterator = NamedDecl **;
130
131 /// Iterates through the template parameters in this list.
132 using const_iterator = NamedDecl * const *;
133
134 iterator begin() { return getTrailingObjects<NamedDecl *>(); }
135 const_iterator begin() const { return getTrailingObjects<NamedDecl *>(); }
136 iterator end() { return begin() + NumParams; }
137 const_iterator end() const { return begin() + NumParams; }
138
139 unsigned size() const { return NumParams; }
140 bool empty() const { return NumParams == 0; }
141
144 return llvm::ArrayRef(begin(), size());
145 }
146
147 NamedDecl* getParam(unsigned Idx) {
148 assert(Idx < size() && "Template parameter index out-of-range");
149 return begin()[Idx];
150 }
151 const NamedDecl* getParam(unsigned Idx) const {
152 assert(Idx < size() && "Template parameter index out-of-range");
153 return begin()[Idx];
154 }
155
156 /// Returns the minimum number of arguments needed to form a
157 /// template specialization.
158 ///
159 /// This may be fewer than the number of template parameters, if some of
160 /// the parameters have default arguments or if there is a parameter pack.
161 unsigned getMinRequiredArguments() const;
162
163 /// Get the depth of this template parameter list in the set of
164 /// template parameter lists.
165 ///
166 /// The first template parameter list in a declaration will have depth 0,
167 /// the second template parameter list will have depth 1, etc.
168 unsigned getDepth() const;
169
170 /// Determine whether this template parameter list contains an
171 /// unexpanded parameter pack.
173
174 /// Determine whether this template parameter list contains a parameter pack.
175 bool hasParameterPack() const {
176 for (const NamedDecl *P : asArray())
177 if (P->isParameterPack())
178 return true;
179 return false;
180 }
181
182 /// The constraint-expression of the associated requires-clause.
184 return HasRequiresClause ? getTrailingObjects<Expr *>()[0] : nullptr;
185 }
186
187 /// The constraint-expression of the associated requires-clause.
188 const Expr *getRequiresClause() const {
189 return HasRequiresClause ? getTrailingObjects<Expr *>()[0] : nullptr;
190 }
191
192 /// \brief All associated constraints derived from this template parameter
193 /// list, including the requires clause and any constraints derived from
194 /// constrained-parameters.
195 ///
196 /// The constraints in the resulting list are to be treated as if in a
197 /// conjunction ("and").
199
201
202 /// Get the template argument list of the template parameter list.
204
205 SourceLocation getTemplateLoc() const { return TemplateLoc; }
206 SourceLocation getLAngleLoc() const { return LAngleLoc; }
207 SourceLocation getRAngleLoc() const { return RAngleLoc; }
208
209 SourceRange getSourceRange() const LLVM_READONLY {
210 return SourceRange(TemplateLoc, RAngleLoc);
211 }
212
213 void print(raw_ostream &Out, const ASTContext &Context,
214 bool OmitTemplateKW = false) const;
215 void print(raw_ostream &Out, const ASTContext &Context,
216 const PrintingPolicy &Policy, bool OmitTemplateKW = false) const;
217
219 const TemplateParameterList *TPL,
220 unsigned Idx);
221};
222
223/// Stores a list of template parameters and the associated
224/// requires-clause (if any) for a TemplateDecl and its derived classes.
225/// Suitable for creating on the stack.
226template <size_t N, bool HasRequiresClause>
228 : public TemplateParameterList::FixedSizeStorageOwner {
229 typename TemplateParameterList::FixedSizeStorage<
230 NamedDecl *, Expr *>::with_counts<
231 N, HasRequiresClause ? 1u : 0u
232 >::type storage;
233
234public:
236 SourceLocation TemplateLoc,
237 SourceLocation LAngleLoc,
239 SourceLocation RAngleLoc,
240 Expr *RequiresClause)
241 : FixedSizeStorageOwner(
242 (assert(N == Params.size()),
243 assert(HasRequiresClause == (RequiresClause != nullptr)),
244 new (static_cast<void *>(&storage)) TemplateParameterList(C,
245 TemplateLoc, LAngleLoc, Params, RAngleLoc, RequiresClause))) {}
246};
247
248/// A template argument list.
250 : private llvm::TrailingObjects<TemplateArgumentList, TemplateArgument> {
251 /// The number of template arguments in this template
252 /// argument list.
253 unsigned NumArguments;
254
255 // Constructs an instance with an internal Argument list, containing
256 // a copy of the Args array. (Called by CreateCopy)
258
259public:
261
264
265 /// Create a new template argument list that copies the given set of
266 /// template arguments.
269
270 /// Retrieve the template argument at a given index.
271 const TemplateArgument &get(unsigned Idx) const {
272 assert(Idx < NumArguments && "Invalid template argument index");
273 return data()[Idx];
274 }
275
276 /// Retrieve the template argument at a given index.
277 const TemplateArgument &operator[](unsigned Idx) const { return get(Idx); }
278
279 /// Produce this as an array ref.
281 return llvm::ArrayRef(data(), size());
282 }
283
284 /// Retrieve the number of template arguments in this
285 /// template argument list.
286 unsigned size() const { return NumArguments; }
287
288 /// Retrieve a pointer to the template argument list.
289 const TemplateArgument *data() const {
290 return getTrailingObjects<TemplateArgument>();
291 }
292};
293
294void *allocateDefaultArgStorageChain(const ASTContext &C);
295
296/// Storage for a default argument. This is conceptually either empty, or an
297/// argument value, or a pointer to a previous declaration that had a default
298/// argument.
299///
300/// However, this is complicated by modules: while we require all the default
301/// arguments for a template to be equivalent, there may be more than one, and
302/// we need to track all the originating parameters to determine if the default
303/// argument is visible.
304template<typename ParmDecl, typename ArgType>
306 /// Storage for both the value *and* another parameter from which we inherit
307 /// the default argument. This is used when multiple default arguments for a
308 /// parameter are merged together from different modules.
309 struct Chain {
310 ParmDecl *PrevDeclWithDefaultArg;
311 ArgType Value;
312 };
313 static_assert(sizeof(Chain) == sizeof(void *) * 2,
314 "non-pointer argument type?");
315
316 llvm::PointerUnion<ArgType, ParmDecl*, Chain*> ValueOrInherited;
317
318 static ParmDecl *getParmOwningDefaultArg(ParmDecl *Parm) {
319 const DefaultArgStorage &Storage = Parm->getDefaultArgStorage();
320 if (auto *Prev = Storage.ValueOrInherited.template dyn_cast<ParmDecl *>())
321 Parm = Prev;
322 assert(!isa<ParmDecl *>(Parm->getDefaultArgStorage().ValueOrInherited) &&
323 "should only be one level of indirection");
324 return Parm;
325 }
326
327public:
328 DefaultArgStorage() : ValueOrInherited(ArgType()) {}
329
330 /// Determine whether there is a default argument for this parameter.
331 bool isSet() const { return !ValueOrInherited.isNull(); }
332
333 /// Determine whether the default argument for this parameter was inherited
334 /// from a previous declaration of the same entity.
335 bool isInherited() const { return isa<ParmDecl *>(ValueOrInherited); }
336
337 /// Get the default argument's value. This does not consider whether the
338 /// default argument is visible.
339 ArgType get() const {
340 const DefaultArgStorage *Storage = this;
341 if (const auto *Prev = ValueOrInherited.template dyn_cast<ParmDecl *>())
342 Storage = &Prev->getDefaultArgStorage();
343 if (const auto *C = Storage->ValueOrInherited.template dyn_cast<Chain *>())
344 return C->Value;
345 return cast<ArgType>(Storage->ValueOrInherited);
346 }
347
348 /// Get the parameter from which we inherit the default argument, if any.
349 /// This is the parameter on which the default argument was actually written.
350 const ParmDecl *getInheritedFrom() const {
351 if (const auto *D = ValueOrInherited.template dyn_cast<ParmDecl *>())
352 return D;
353 if (const auto *C = ValueOrInherited.template dyn_cast<Chain *>())
354 return C->PrevDeclWithDefaultArg;
355 return nullptr;
356 }
357
358 /// Set the default argument.
359 void set(ArgType Arg) {
360 assert(!isSet() && "default argument already set");
361 ValueOrInherited = Arg;
362 }
363
364 /// Set that the default argument was inherited from another parameter.
365 void setInherited(const ASTContext &C, ParmDecl *InheritedFrom) {
366 InheritedFrom = getParmOwningDefaultArg(InheritedFrom);
367 if (!isSet())
368 ValueOrInherited = InheritedFrom;
369 else if ([[maybe_unused]] auto *D =
370 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 = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2022 Info->TemplateArgsAsWritten = ArgsWritten;
2023 else
2024 ExplicitInfo = ArgsWritten;
2025 }
2026
2027 /// Set the template argument list as written in the sources.
2031 }
2032
2033 /// Gets the location of the extern keyword, if present.
2035 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2036 return Info->ExternKeywordLoc;
2037 return SourceLocation();
2038 }
2039
2040 /// Sets the location of the extern keyword.
2042
2043 /// Gets the location of the template keyword, if present.
2045 if (auto *Info =
2046 dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo))
2047 return Info->TemplateKeywordLoc;
2048 return SourceLocation();
2049 }
2050
2051 /// Sets the location of the template keyword.
2053
2054 SourceRange getSourceRange() const override LLVM_READONLY;
2055
2056 void Profile(llvm::FoldingSetNodeID &ID) const {
2057 Profile(ID, TemplateArgs->asArray(), getASTContext());
2058 }
2059
2060 static void
2061 Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
2062 const ASTContext &Context) {
2063 ID.AddInteger(TemplateArgs.size());
2064 for (const TemplateArgument &TemplateArg : TemplateArgs)
2065 TemplateArg.Profile(ID, Context);
2066 }
2067
2068 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2069
2070 static bool classofKind(Kind K) {
2071 return K >= firstClassTemplateSpecialization &&
2072 K <= lastClassTemplateSpecialization;
2073 }
2074};
2075
2078 /// The list of template parameters
2079 TemplateParameterList *TemplateParams = nullptr;
2080
2081 /// The class template partial specialization from which this
2082 /// class template partial specialization was instantiated.
2083 ///
2084 /// The boolean value will be true to indicate that this class template
2085 /// partial specialization was specialized at this level.
2086 llvm::PointerIntPair<ClassTemplatePartialSpecializationDecl *, 1, bool>
2087 InstantiatedFromMember;
2088
2090 ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc,
2092 ClassTemplateDecl *SpecializedTemplate, ArrayRef<TemplateArgument> Args,
2094
2096 : ClassTemplateSpecializationDecl(C, ClassTemplatePartialSpecialization),
2097 InstantiatedFromMember(nullptr, false) {}
2098
2099 void anchor() override;
2100
2101public:
2102 friend class ASTDeclReader;
2103 friend class ASTDeclWriter;
2104
2106 Create(ASTContext &Context, TagKind TK, DeclContext *DC,
2107 SourceLocation StartLoc, SourceLocation IdLoc,
2108 TemplateParameterList *Params, ClassTemplateDecl *SpecializedTemplate,
2109 ArrayRef<TemplateArgument> Args, QualType CanonInjectedType,
2111
2114
2116 return cast<ClassTemplatePartialSpecializationDecl>(
2117 static_cast<ClassTemplateSpecializationDecl *>(
2118 this)->getMostRecentDecl());
2119 }
2120
2121 /// Get the list of template parameters
2123 return TemplateParams;
2124 }
2125
2126 /// Get the template argument list of the template parameter list.
2128 getInjectedTemplateArgs(const ASTContext &Context) const {
2130 }
2131
2132 /// \brief All associated constraints of this partial specialization,
2133 /// including the requires clause and any constraints derived from
2134 /// constrained-parameters.
2135 ///
2136 /// The constraints in the resulting list are to be treated as if in a
2137 /// conjunction ("and").
2139 TemplateParams->getAssociatedConstraints(AC);
2140 }
2141
2143 return TemplateParams->hasAssociatedConstraints();
2144 }
2145
2146 /// Retrieve the member class template partial specialization from
2147 /// which this particular class template partial specialization was
2148 /// instantiated.
2149 ///
2150 /// \code
2151 /// template<typename T>
2152 /// struct Outer {
2153 /// template<typename U> struct Inner;
2154 /// template<typename U> struct Inner<U*> { }; // #1
2155 /// };
2156 ///
2157 /// Outer<float>::Inner<int*> ii;
2158 /// \endcode
2159 ///
2160 /// In this example, the instantiation of \c Outer<float>::Inner<int*> will
2161 /// end up instantiating the partial specialization
2162 /// \c Outer<float>::Inner<U*>, which itself was instantiated from the class
2163 /// template partial specialization \c Outer<T>::Inner<U*>. Given
2164 /// \c Outer<float>::Inner<U*>, this function would return
2165 /// \c Outer<T>::Inner<U*>.
2167 const auto *First =
2168 cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2169 return First->InstantiatedFromMember.getPointer();
2170 }
2174 }
2175
2178 auto *First = cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2179 First->InstantiatedFromMember.setPointer(PartialSpec);
2180 }
2181
2182 /// Determines whether this class template partial specialization
2183 /// template was a specialization of a member partial specialization.
2184 ///
2185 /// In the following example, the member template partial specialization
2186 /// \c X<int>::Inner<T*> is a member specialization.
2187 ///
2188 /// \code
2189 /// template<typename T>
2190 /// struct X {
2191 /// template<typename U> struct Inner;
2192 /// template<typename U> struct Inner<U*>;
2193 /// };
2194 ///
2195 /// template<> template<typename T>
2196 /// struct X<int>::Inner<T*> { /* ... */ };
2197 /// \endcode
2199 const auto *First =
2200 cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2201 return First->InstantiatedFromMember.getInt();
2202 }
2203
2204 /// Note that this member template is a specialization.
2206 auto *First = cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2207 assert(First->InstantiatedFromMember.getPointer() &&
2208 "Only member templates can be member template specializations");
2209 return First->InstantiatedFromMember.setInt(true);
2210 }
2211
2212 /// Retrieves the injected specialization type for this partial
2213 /// specialization. This is not the same as the type-decl-type for
2214 /// this partial specialization, which is an InjectedClassNameType.
2216 assert(getTypeForDecl() && "partial specialization has no type set!");
2217 return cast<InjectedClassNameType>(getTypeForDecl())
2218 ->getInjectedSpecializationType();
2219 }
2220
2221 SourceRange getSourceRange() const override LLVM_READONLY;
2222
2223 void Profile(llvm::FoldingSetNodeID &ID) const {
2225 getASTContext());
2226 }
2227
2228 static void
2229 Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
2230 TemplateParameterList *TPL, const ASTContext &Context);
2231
2232 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2233
2234 static bool classofKind(Kind K) {
2235 return K == ClassTemplatePartialSpecialization;
2236 }
2237};
2238
2239/// Declaration of a class template.
2241protected:
2242 /// Data that is common to all of the declarations of a given
2243 /// class template.
2245 /// The class template specializations for this class
2246 /// template, including explicit specializations and instantiations.
2247 llvm::FoldingSetVector<ClassTemplateSpecializationDecl> Specializations;
2248
2249 /// The class template partial specializations for this class
2250 /// template.
2251 llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>
2253
2254 /// The injected-class-name type for this class template.
2256
2257 Common() = default;
2258 };
2259
2260 /// Retrieve the set of specializations of this class template.
2261 llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
2262 getSpecializations() const;
2263
2264 /// Retrieve the set of partial specializations of this class
2265 /// template.
2266 llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
2268
2271 NamedDecl *Decl)
2272 : RedeclarableTemplateDecl(ClassTemplate, C, DC, L, Name, Params, Decl) {}
2273
2274 CommonBase *newCommon(ASTContext &C) const override;
2275
2277 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
2278 }
2279
2281
2282public:
2283
2284 friend class ASTDeclReader;
2285 friend class ASTDeclWriter;
2287
2288 /// Load any lazily-loaded specializations from the external source.
2289 void LoadLazySpecializations(bool OnlyPartial = false) const;
2290
2291 /// Get the underlying class declarations of the template.
2293 return static_cast<CXXRecordDecl *>(TemplatedDecl);
2294 }
2295
2296 /// Returns whether this template declaration defines the primary
2297 /// class pattern.
2300 }
2301
2302 /// \brief Create a class template node.
2305 DeclarationName Name,
2306 TemplateParameterList *Params,
2307 NamedDecl *Decl);
2308
2309 /// Create an empty class template node.
2311
2312 /// Return the specialization with the provided arguments if it exists,
2313 /// otherwise return the insertion point.
2315 findSpecialization(ArrayRef<TemplateArgument> Args, void *&InsertPos);
2316
2317 /// Insert the specified specialization knowing that it is not already
2318 /// in. InsertPos must be obtained from findSpecialization.
2319 void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos);
2320
2322 return cast<ClassTemplateDecl>(
2324 }
2326 return cast<ClassTemplateDecl>(
2328 }
2329
2330 /// Retrieve the previous declaration of this class template, or
2331 /// nullptr if no such declaration exists.
2333 return cast_or_null<ClassTemplateDecl>(
2334 static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
2335 }
2337 return cast_or_null<ClassTemplateDecl>(
2338 static_cast<const RedeclarableTemplateDecl *>(
2339 this)->getPreviousDecl());
2340 }
2341
2343 return cast<ClassTemplateDecl>(
2344 static_cast<RedeclarableTemplateDecl *>(this)->getMostRecentDecl());
2345 }
2347 return const_cast<ClassTemplateDecl*>(this)->getMostRecentDecl();
2348 }
2349
2351 return cast_or_null<ClassTemplateDecl>(
2353 }
2354
2355 /// Return the partial specialization with the provided arguments if it
2356 /// exists, otherwise return the insertion point.
2359 TemplateParameterList *TPL, void *&InsertPos);
2360
2361 /// Insert the specified partial specialization knowing that it is not
2362 /// already in. InsertPos must be obtained from findPartialSpecialization.
2364 void *InsertPos);
2365
2366 /// Retrieve the partial specializations as an ordered list.
2369
2370 /// Find a class template partial specialization with the given
2371 /// type T.
2372 ///
2373 /// \param T a dependent type that names a specialization of this class
2374 /// template.
2375 ///
2376 /// \returns the class template partial specialization that exactly matches
2377 /// the type \p T, or nullptr if no such partial specialization exists.
2379
2380 /// Find a class template partial specialization which was instantiated
2381 /// from the given member partial specialization.
2382 ///
2383 /// \param D a member class template partial specialization.
2384 ///
2385 /// \returns the class template partial specialization which was instantiated
2386 /// from the given member partial specialization, or nullptr if no such
2387 /// partial specialization exists.
2391
2392 /// Retrieve the template specialization type of the
2393 /// injected-class-name for this class template.
2394 ///
2395 /// The injected-class-name for a class template \c X is \c
2396 /// X<template-args>, where \c template-args is formed from the
2397 /// template arguments that correspond to the template parameters of
2398 /// \c X. For example:
2399 ///
2400 /// \code
2401 /// template<typename T, int N>
2402 /// struct array {
2403 /// typedef array this_type; // "array" is equivalent to "array<T, N>"
2404 /// };
2405 /// \endcode
2407
2409 using spec_range = llvm::iterator_range<spec_iterator>;
2410
2412 return spec_range(spec_begin(), spec_end());
2413 }
2414
2416 return makeSpecIterator(getSpecializations(), false);
2417 }
2418
2420 return makeSpecIterator(getSpecializations(), true);
2421 }
2422
2423 // Implement isa/cast/dyncast support
2424 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2425 static bool classofKind(Kind K) { return K == ClassTemplate; }
2426};
2427
2428/// Declaration of a friend template.
2429///
2430/// For example:
2431/// \code
2432/// template <typename T> class A {
2433/// friend class MyVector<T>; // not a friend template
2434/// template <typename U> friend class B; // not a friend template
2435/// template <typename U> friend class Foo<T>::Nested; // friend template
2436/// };
2437/// \endcode
2438///
2439/// \note This class is not currently in use. All of the above
2440/// will yield a FriendDecl, not a FriendTemplateDecl.
2441class FriendTemplateDecl : public Decl {
2442 virtual void anchor();
2443
2444public:
2445 using FriendUnion = llvm::PointerUnion<NamedDecl *,TypeSourceInfo *>;
2446
2447private:
2448 // The number of template parameters; always non-zero.
2449 unsigned NumParams = 0;
2450
2451 // The parameter list.
2452 TemplateParameterList **Params = nullptr;
2453
2454 // The declaration that's a friend of this class.
2455 FriendUnion Friend;
2456
2457 // Location of the 'friend' specifier.
2458 SourceLocation FriendLoc;
2459
2461 TemplateParameterList **Params, unsigned NumParams,
2462 FriendUnion Friend, SourceLocation FriendLoc)
2463 : Decl(Decl::FriendTemplate, DC, Loc), NumParams(NumParams),
2464 Params(Params), Friend(Friend), FriendLoc(FriendLoc) {}
2465
2466 FriendTemplateDecl(EmptyShell Empty) : Decl(Decl::FriendTemplate, Empty) {}
2467
2468public:
2469 friend class ASTDeclReader;
2470
2471 static FriendTemplateDecl *
2474 SourceLocation FriendLoc);
2475
2477
2478 /// If this friend declaration names a templated type (or
2479 /// a dependent member type of a templated type), return that
2480 /// type; otherwise return null.
2482 return Friend.dyn_cast<TypeSourceInfo*>();
2483 }
2484
2485 /// If this friend declaration names a templated function (or
2486 /// a member function of a templated type), return that type;
2487 /// otherwise return null.
2489 return Friend.dyn_cast<NamedDecl*>();
2490 }
2491
2492 /// Retrieves the location of the 'friend' keyword.
2494 return FriendLoc;
2495 }
2496
2498 assert(i <= NumParams);
2499 return Params[i];
2500 }
2501
2502 unsigned getNumTemplateParameters() const {
2503 return NumParams;
2504 }
2505
2506 // Implement isa/cast/dyncast/etc.
2507 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2508 static bool classofKind(Kind K) { return K == Decl::FriendTemplate; }
2509};
2510
2511/// Declaration of an alias template.
2512///
2513/// For example:
2514/// \code
2515/// template <typename T> using V = std::map<T*, int, MyCompare<T>>;
2516/// \endcode
2518protected:
2520
2523 NamedDecl *Decl)
2524 : RedeclarableTemplateDecl(TypeAliasTemplate, C, DC, L, Name, Params,
2525 Decl) {}
2526
2527 CommonBase *newCommon(ASTContext &C) const override;
2528
2530 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
2531 }
2532
2533public:
2534 friend class ASTDeclReader;
2535 friend class ASTDeclWriter;
2536
2537 /// Get the underlying function declaration of the template.
2539 return static_cast<TypeAliasDecl *>(TemplatedDecl);
2540 }
2541
2542
2544 return cast<TypeAliasTemplateDecl>(
2546 }
2548 return cast<TypeAliasTemplateDecl>(
2550 }
2551
2552 /// Retrieve the previous declaration of this function template, or
2553 /// nullptr if no such declaration exists.
2555 return cast_or_null<TypeAliasTemplateDecl>(
2556 static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
2557 }
2559 return cast_or_null<TypeAliasTemplateDecl>(
2560 static_cast<const RedeclarableTemplateDecl *>(
2561 this)->getPreviousDecl());
2562 }
2563
2565 return cast_or_null<TypeAliasTemplateDecl>(
2567 }
2568
2569 /// Create a function template node.
2572 DeclarationName Name,
2573 TemplateParameterList *Params,
2574 NamedDecl *Decl);
2575
2576 /// Create an empty alias template node.
2579
2580 // Implement isa/cast/dyncast support
2581 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2582 static bool classofKind(Kind K) { return K == TypeAliasTemplate; }
2583};
2584
2585/// Represents a variable template specialization, which refers to
2586/// a variable template with a given set of template arguments.
2587///
2588/// Variable template specializations represent both explicit
2589/// specializations of variable templates, as in the example below, and
2590/// implicit instantiations of variable templates.
2591///
2592/// \code
2593/// template<typename T> constexpr T pi = T(3.1415926535897932385);
2594///
2595/// template<>
2596/// constexpr float pi<float>; // variable template specialization pi<float>
2597/// \endcode
2599 public llvm::FoldingSetNode {
2600
2601 /// Structure that stores information about a variable template
2602 /// specialization that was instantiated from a variable template partial
2603 /// specialization.
2604 struct SpecializedPartialSpecialization {
2605 /// The variable template partial specialization from which this
2606 /// variable template specialization was instantiated.
2607 VarTemplatePartialSpecializationDecl *PartialSpecialization;
2608
2609 /// The template argument list deduced for the variable template
2610 /// partial specialization itself.
2611 const TemplateArgumentList *TemplateArgs;
2612 };
2613
2614 /// The template that this specialization specializes.
2615 llvm::PointerUnion<VarTemplateDecl *, SpecializedPartialSpecialization *>
2616 SpecializedTemplate;
2617
2618 /// Further info for explicit template specialization/instantiation.
2619 /// Does not apply to implicit specializations.
2620 SpecializationOrInstantiationInfo ExplicitInfo = nullptr;
2621
2622 /// The template arguments used to describe this specialization.
2623 const TemplateArgumentList *TemplateArgs;
2624
2625 /// The point where this template was instantiated (if any).
2626 SourceLocation PointOfInstantiation;
2627
2628 /// The kind of specialization this declaration refers to.
2629 LLVM_PREFERRED_TYPE(TemplateSpecializationKind)
2630 unsigned SpecializationKind : 3;
2631
2632 /// Whether this declaration is a complete definition of the
2633 /// variable template specialization. We can't otherwise tell apart
2634 /// an instantiated declaration from an instantiated definition with
2635 /// no initializer.
2636 LLVM_PREFERRED_TYPE(bool)
2637 unsigned IsCompleteDefinition : 1;
2638
2639protected:
2641 SourceLocation StartLoc, SourceLocation IdLoc,
2642 VarTemplateDecl *SpecializedTemplate,
2643 QualType T, TypeSourceInfo *TInfo,
2644 StorageClass S,
2646
2647 explicit VarTemplateSpecializationDecl(Kind DK, ASTContext &Context);
2648
2649public:
2650 friend class ASTDeclReader;
2651 friend class ASTDeclWriter;
2652 friend class VarDecl;
2653
2655 Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
2656 SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
2657 TypeSourceInfo *TInfo, StorageClass S,
2661
2662 void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy,
2663 bool Qualified) const override;
2664
2666 VarDecl *Recent = static_cast<VarDecl *>(this)->getMostRecentDecl();
2667 return cast<VarTemplateSpecializationDecl>(Recent);
2668 }
2669
2670 /// Retrieve the template that this specialization specializes.
2672
2673 /// Retrieve the template arguments of the variable template
2674 /// specialization.
2675 const TemplateArgumentList &getTemplateArgs() const { return *TemplateArgs; }
2676
2677 /// Determine the kind of specialization that this
2678 /// declaration represents.
2680 return static_cast<TemplateSpecializationKind>(SpecializationKind);
2681 }
2682
2685 }
2686
2688 return isExplicitSpecialization() &&
2689 isa<CXXRecordDecl>(getLexicalDeclContext());
2690 }
2691
2692 /// True if this declaration is an explicit specialization,
2693 /// explicit instantiation declaration, or explicit instantiation
2694 /// definition.
2698 }
2699
2701 SpecializationKind = TSK;
2702 }
2703
2704 /// Get the point of instantiation (if any), or null if none.
2706 return PointOfInstantiation;
2707 }
2708
2710 assert(Loc.isValid() && "point of instantiation must be valid!");
2711 PointOfInstantiation = Loc;
2712 }
2713
2714 void setCompleteDefinition() { IsCompleteDefinition = true; }
2715
2716 /// If this variable template specialization is an instantiation of
2717 /// a template (rather than an explicit specialization), return the
2718 /// variable template or variable template partial specialization from which
2719 /// it was instantiated.
2720 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
2723 return llvm::PointerUnion<VarTemplateDecl *,
2725
2727 }
2728
2729 /// Retrieve the variable template or variable template partial
2730 /// specialization which was specialized by this.
2731 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
2733 if (const auto *PartialSpec =
2734 SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
2735 return PartialSpec->PartialSpecialization;
2736
2737 return cast<VarTemplateDecl *>(SpecializedTemplate);
2738 }
2739
2740 /// Retrieve the set of template arguments that should be used
2741 /// to instantiate the initializer of the variable template or variable
2742 /// template partial specialization from which this variable template
2743 /// specialization was instantiated.
2744 ///
2745 /// \returns For a variable template specialization instantiated from the
2746 /// primary template, this function will return the same template arguments
2747 /// as getTemplateArgs(). For a variable template specialization instantiated
2748 /// from a variable template partial specialization, this function will the
2749 /// return deduced template arguments for the variable template partial
2750 /// specialization itself.
2752 if (const auto *PartialSpec =
2753 SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
2754 return *PartialSpec->TemplateArgs;
2755
2756 return getTemplateArgs();
2757 }
2758
2759 /// Note that this variable template specialization is actually an
2760 /// instantiation of the given variable template partial specialization whose
2761 /// template arguments have been deduced.
2763 const TemplateArgumentList *TemplateArgs) {
2764 assert(!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) &&
2765 "Already set to a variable template partial specialization!");
2766 auto *PS = new (getASTContext()) SpecializedPartialSpecialization();
2767 PS->PartialSpecialization = PartialSpec;
2768 PS->TemplateArgs = TemplateArgs;
2769 SpecializedTemplate = PS;
2770 }
2771
2772 /// Note that this variable template specialization is an instantiation
2773 /// of the given variable template.
2775 assert(!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) &&
2776 "Previously set to a variable template partial specialization!");
2777 SpecializedTemplate = TemplDecl;
2778 }
2779
2780 /// Retrieve the template argument list as written in the sources,
2781 /// if any.
2783 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2784 return Info->TemplateArgsAsWritten;
2785 return cast<const ASTTemplateArgumentListInfo *>(ExplicitInfo);
2786 }
2787
2788 /// Set the template argument list as written in the sources.
2789 void
2791 if (auto *Info =
2792 dyn_cast_if_present<ExplicitInstantiationInfo *>(ExplicitInfo))
2793 Info->TemplateArgsAsWritten = ArgsWritten;
2794 else
2795 ExplicitInfo = ArgsWritten;
2796 }
2797
2798 /// Set the template argument list as written in the sources.
2802 }
2803
2804 /// Gets the location of the extern keyword, if present.
2806 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2807 return Info->ExternKeywordLoc;
2808 return SourceLocation();
2809 }
2810
2811 /// Sets the location of the extern keyword.
2813
2814 /// Gets the location of the template keyword, if present.
2816 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2817 return Info->TemplateKeywordLoc;
2818 return SourceLocation();
2819 }
2820
2821 /// Sets the location of the template keyword.
2823
2824 SourceRange getSourceRange() const override LLVM_READONLY;
2825
2826 void Profile(llvm::FoldingSetNodeID &ID) const {
2827 Profile(ID, TemplateArgs->asArray(), getASTContext());
2828 }
2829
2830 static void Profile(llvm::FoldingSetNodeID &ID,
2831 ArrayRef<TemplateArgument> TemplateArgs,
2832 const ASTContext &Context) {
2833 ID.AddInteger(TemplateArgs.size());
2834 for (const TemplateArgument &TemplateArg : TemplateArgs)
2835 TemplateArg.Profile(ID, Context);
2836 }
2837
2838 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2839
2840 static bool classofKind(Kind K) {
2841 return K >= firstVarTemplateSpecialization &&
2842 K <= lastVarTemplateSpecialization;
2843 }
2844};
2845
2848 /// The list of template parameters
2849 TemplateParameterList *TemplateParams = nullptr;
2850
2851 /// The variable template partial specialization from which this
2852 /// variable template partial specialization was instantiated.
2853 ///
2854 /// The boolean value will be true to indicate that this variable template
2855 /// partial specialization was specialized at this level.
2856 llvm::PointerIntPair<VarTemplatePartialSpecializationDecl *, 1, bool>
2857 InstantiatedFromMember;
2858
2860 ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
2862 VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
2864
2866 : VarTemplateSpecializationDecl(VarTemplatePartialSpecialization,
2867 Context),
2868 InstantiatedFromMember(nullptr, false) {}
2869
2870 void anchor() override;
2871
2872public:
2873 friend class ASTDeclReader;
2874 friend class ASTDeclWriter;
2875
2877 Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
2879 VarTemplateDecl *SpecializedTemplate, QualType T,
2880 TypeSourceInfo *TInfo, StorageClass S,
2882
2885
2887 return cast<VarTemplatePartialSpecializationDecl>(
2888 static_cast<VarTemplateSpecializationDecl *>(
2889 this)->getMostRecentDecl());
2890 }
2891
2892 /// Get the list of template parameters
2894 return TemplateParams;
2895 }
2896
2897 /// Get the template argument list of the template parameter list.
2899 getInjectedTemplateArgs(const ASTContext &Context) const {
2901 }
2902
2903 /// \brief All associated constraints of this partial specialization,
2904 /// including the requires clause and any constraints derived from
2905 /// constrained-parameters.
2906 ///
2907 /// The constraints in the resulting list are to be treated as if in a
2908 /// conjunction ("and").
2910 TemplateParams->getAssociatedConstraints(AC);
2911 }
2912
2914 return TemplateParams->hasAssociatedConstraints();
2915 }
2916
2917 /// \brief Retrieve the member variable template partial specialization from
2918 /// which this particular variable template partial specialization was
2919 /// instantiated.
2920 ///
2921 /// \code
2922 /// template<typename T>
2923 /// struct Outer {
2924 /// template<typename U> U Inner;
2925 /// template<typename U> U* Inner<U*> = (U*)(0); // #1
2926 /// };
2927 ///
2928 /// template int* Outer<float>::Inner<int*>;
2929 /// \endcode
2930 ///
2931 /// In this example, the instantiation of \c Outer<float>::Inner<int*> will
2932 /// end up instantiating the partial specialization
2933 /// \c Outer<float>::Inner<U*>, which itself was instantiated from the
2934 /// variable template partial specialization \c Outer<T>::Inner<U*>. Given
2935 /// \c Outer<float>::Inner<U*>, this function would return
2936 /// \c Outer<T>::Inner<U*>.
2938 const auto *First =
2939 cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2940 return First->InstantiatedFromMember.getPointer();
2941 }
2942
2943 void
2945 auto *First = cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2946 First->InstantiatedFromMember.setPointer(PartialSpec);
2947 }
2948
2949 /// Determines whether this variable template partial specialization
2950 /// was a specialization of a member partial specialization.
2951 ///
2952 /// In the following example, the member template partial specialization
2953 /// \c X<int>::Inner<T*> is a member specialization.
2954 ///
2955 /// \code
2956 /// template<typename T>
2957 /// struct X {
2958 /// template<typename U> U Inner;
2959 /// template<typename U> U* Inner<U*> = (U*)(0);
2960 /// };
2961 ///
2962 /// template<> template<typename T>
2963 /// U* X<int>::Inner<T*> = (T*)(0) + 1;
2964 /// \endcode
2966 const auto *First =
2967 cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2968 return First->InstantiatedFromMember.getInt();
2969 }
2970
2971 /// Note that this member template is a specialization.
2973 auto *First = cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2974 assert(First->InstantiatedFromMember.getPointer() &&
2975 "Only member templates can be member template specializations");
2976 return First->InstantiatedFromMember.setInt(true);
2977 }
2978
2979 SourceRange getSourceRange() const override LLVM_READONLY;
2980
2981 void Profile(llvm::FoldingSetNodeID &ID) const {
2983 getASTContext());
2984 }
2985
2986 static void
2987 Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
2988 TemplateParameterList *TPL, const ASTContext &Context);
2989
2990 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2991
2992 static bool classofKind(Kind K) {
2993 return K == VarTemplatePartialSpecialization;
2994 }
2995};
2996
2997/// Declaration of a variable template.
2999protected:
3000 /// Data that is common to all of the declarations of a given
3001 /// variable template.
3003 /// The variable template specializations for this variable
3004 /// template, including explicit specializations and instantiations.
3005 llvm::FoldingSetVector<VarTemplateSpecializationDecl> Specializations;
3006
3007 /// The variable template partial specializations for this variable
3008 /// template.
3009 llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl>
3011
3012 Common() = default;
3013 };
3014
3015 /// Retrieve the set of specializations of this variable template.
3016 llvm::FoldingSetVector<VarTemplateSpecializationDecl> &
3017 getSpecializations() const;
3018
3019 /// Retrieve the set of partial specializations of this class
3020 /// template.
3021 llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &
3023
3026 NamedDecl *Decl)
3027 : RedeclarableTemplateDecl(VarTemplate, C, DC, L, Name, Params, Decl) {}
3028
3029 CommonBase *newCommon(ASTContext &C) const override;
3030
3032 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
3033 }
3034
3035public:
3036 friend class ASTDeclReader;
3037 friend class ASTDeclWriter;
3038
3039 /// Load any lazily-loaded specializations from the external source.
3040 void LoadLazySpecializations(bool OnlyPartial = false) const;
3041
3042 /// Get the underlying variable declarations of the template.
3044 return static_cast<VarDecl *>(TemplatedDecl);
3045 }
3046
3047 /// Returns whether this template declaration defines the primary
3048 /// variable pattern.
3051 }
3052
3054
3055 /// Create a variable template node.
3058 TemplateParameterList *Params,
3059 VarDecl *Decl);
3060
3061 /// Create an empty variable template node.
3063
3064 /// Return the specialization with the provided arguments if it exists,
3065 /// otherwise return the insertion point.
3067 findSpecialization(ArrayRef<TemplateArgument> Args, void *&InsertPos);
3068
3069 /// Insert the specified specialization knowing that it is not already
3070 /// in. InsertPos must be obtained from findSpecialization.
3071 void AddSpecialization(VarTemplateSpecializationDecl *D, void *InsertPos);
3072
3074 return cast<VarTemplateDecl>(RedeclarableTemplateDecl::getCanonicalDecl());
3075 }
3077 return cast<VarTemplateDecl>(RedeclarableTemplateDecl::getCanonicalDecl());
3078 }
3079
3080 /// Retrieve the previous declaration of this variable template, or
3081 /// nullptr if no such declaration exists.
3083 return cast_or_null<VarTemplateDecl>(
3084 static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
3085 }
3087 return cast_or_null<VarTemplateDecl>(
3088 static_cast<const RedeclarableTemplateDecl *>(
3089 this)->getPreviousDecl());
3090 }
3091
3093 return cast<VarTemplateDecl>(
3094 static_cast<RedeclarableTemplateDecl *>(this)->getMostRecentDecl());
3095 }
3097 return const_cast<VarTemplateDecl *>(this)->getMostRecentDecl();
3098 }
3099
3101 return cast_or_null<VarTemplateDecl>(
3103 }
3104
3105 /// Return the partial specialization with the provided arguments if it
3106 /// exists, otherwise return the insertion point.
3109 TemplateParameterList *TPL, void *&InsertPos);
3110
3111 /// Insert the specified partial specialization knowing that it is not
3112 /// already in. InsertPos must be obtained from findPartialSpecialization.
3114 void *InsertPos);
3115
3116 /// Retrieve the partial specializations as an ordered list.
3119
3120 /// Find a variable template partial specialization which was
3121 /// instantiated
3122 /// from the given member partial specialization.
3123 ///
3124 /// \param D a member variable template partial specialization.
3125 ///
3126 /// \returns the variable template partial specialization which was
3127 /// instantiated
3128 /// from the given member partial specialization, or nullptr if no such
3129 /// partial specialization exists.
3132
3134 using spec_range = llvm::iterator_range<spec_iterator>;
3135
3137 return spec_range(spec_begin(), spec_end());
3138 }
3139
3141 return makeSpecIterator(getSpecializations(), false);
3142 }
3143
3145 return makeSpecIterator(getSpecializations(), true);
3146 }
3147
3148 // Implement isa/cast/dyncast support
3149 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3150 static bool classofKind(Kind K) { return K == VarTemplate; }
3151};
3152
3153/// Declaration of a C++20 concept.
3154class ConceptDecl : public TemplateDecl, public Mergeable<ConceptDecl> {
3155protected:
3157
3160 : TemplateDecl(Concept, DC, L, Name, Params),
3162public:
3164 DeclarationName Name,
3165 TemplateParameterList *Params,
3166 Expr *ConstraintExpr = nullptr);
3168
3170 return ConstraintExpr;
3171 }
3172
3173 bool hasDefinition() const { return ConstraintExpr != nullptr; }
3174
3176
3177 SourceRange getSourceRange() const override LLVM_READONLY {
3178 return SourceRange(getTemplateParameters()->getTemplateLoc(),
3180 : SourceLocation());
3181 }
3182
3183 bool isTypeConcept() const {
3184 return isa<TemplateTypeParmDecl>(getTemplateParameters()->getParam(0));
3185 }
3186
3188 return cast<ConceptDecl>(getPrimaryMergedDecl(this));
3189 }
3191 return const_cast<ConceptDecl *>(this)->getCanonicalDecl();
3192 }
3193
3194 // Implement isa/cast/dyncast/etc.
3195 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3196 static bool classofKind(Kind K) { return K == Concept; }
3197
3198 friend class ASTReader;
3199 friend class ASTDeclReader;
3200 friend class ASTDeclWriter;
3201};
3202
3203// An implementation detail of ConceptSpecialicationExpr that holds the template
3204// arguments, so we can later use this to reconstitute the template arguments
3205// during constraint checking.
3207 : public Decl,
3208 private llvm::TrailingObjects<ImplicitConceptSpecializationDecl,
3209 TemplateArgument> {
3210 unsigned NumTemplateArgs;
3211
3213 ArrayRef<TemplateArgument> ConvertedArgs);
3214 ImplicitConceptSpecializationDecl(EmptyShell Empty, unsigned NumTemplateArgs);
3215
3216public:
3219 ArrayRef<TemplateArgument> ConvertedArgs);
3222 unsigned NumTemplateArgs);
3223
3225 return ArrayRef<TemplateArgument>(getTrailingObjects<TemplateArgument>(),
3226 NumTemplateArgs);
3227 }
3229
3230 static bool classofKind(Kind K) { return K == ImplicitConceptSpecialization; }
3231 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3232
3234 friend class ASTDeclReader;
3235};
3236
3237/// A template parameter object.
3238///
3239/// Template parameter objects represent values of class type used as template
3240/// arguments. There is one template parameter object for each such distinct
3241/// value used as a template argument across the program.
3242///
3243/// \code
3244/// struct A { int x, y; };
3245/// template<A> struct S;
3246/// S<A{1, 2}> s1;
3247/// S<A{1, 2}> s2; // same type, argument is same TemplateParamObjectDecl.
3248/// \endcode
3250 public Mergeable<TemplateParamObjectDecl>,
3251 public llvm::FoldingSetNode {
3252private:
3253 /// The value of this template parameter object.
3254 APValue Value;
3255
3257 : ValueDecl(TemplateParamObject, DC, SourceLocation(), DeclarationName(),
3258 T),
3259 Value(V) {}
3260
3262 const APValue &V);
3263 static TemplateParamObjectDecl *CreateDeserialized(ASTContext &C,
3265
3266 /// Only ASTContext::getTemplateParamObjectDecl and deserialization
3267 /// create these.
3268 friend class ASTContext;
3269 friend class ASTReader;
3270 friend class ASTDeclReader;
3271
3272public:
3273 /// Print this template parameter object in a human-readable format.
3274 void printName(llvm::raw_ostream &OS,
3275 const PrintingPolicy &Policy) const override;
3276
3277 /// Print this object as an equivalent expression.
3278 void printAsExpr(llvm::raw_ostream &OS) const;
3279 void printAsExpr(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const;
3280
3281 /// Print this object as an initializer suitable for a variable of the
3282 /// object's type.
3283 void printAsInit(llvm::raw_ostream &OS) const;
3284 void printAsInit(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const;
3285
3286 const APValue &getValue() const { return Value; }
3287
3288 static void Profile(llvm::FoldingSetNodeID &ID, QualType T,
3289 const APValue &V) {
3290 ID.AddPointer(T.getCanonicalType().getAsOpaquePtr());
3291 V.Profile(ID);
3292 }
3293 void Profile(llvm::FoldingSetNodeID &ID) {
3294 Profile(ID, getType(), getValue());
3295 }
3296
3298 return getFirstDecl();
3299 }
3301 return getFirstDecl();
3302 }
3303
3304 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3305 static bool classofKind(Kind K) { return K == TemplateParamObject; }
3306};
3307
3309 if (auto *PD = P.dyn_cast<TemplateTypeParmDecl *>())
3310 return PD;
3311 if (auto *PD = P.dyn_cast<NonTypeTemplateParmDecl *>())
3312 return PD;
3313 return cast<TemplateTemplateParmDecl *>(P);
3314}
3315
3317 auto *TD = dyn_cast<TemplateDecl>(D);
3318 return TD && (isa<ClassTemplateDecl>(TD) ||
3319 isa<ClassTemplatePartialSpecializationDecl>(TD) ||
3320 isa<TypeAliasTemplateDecl>(TD) ||
3321 isa<TemplateTemplateParmDecl>(TD))
3322 ? TD
3323 : nullptr;
3324}
3325
3326/// Check whether the template parameter is a pack expansion, and if so,
3327/// determine the number of parameters produced by that expansion. For instance:
3328///
3329/// \code
3330/// template<typename ...Ts> struct A {
3331/// template<Ts ...NTs, template<Ts> class ...TTs, typename ...Us> struct B;
3332/// };
3333/// \endcode
3334///
3335/// In \c A<int,int>::B, \c NTs and \c TTs have expanded pack size 2, and \c Us
3336/// is not a pack expansion, so returns an empty Optional.
3337inline std::optional<unsigned> getExpandedPackSize(const NamedDecl *Param) {
3338 if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
3339 if (TTP->isExpandedParameterPack())
3340 return TTP->getNumExpansionParameters();
3341 }
3342
3343 if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
3344 if (NTTP->isExpandedParameterPack())
3345 return NTTP->getNumExpansionTypes();
3346 }
3347
3348 if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(Param)) {
3349 if (TTP->isExpandedParameterPack())
3350 return TTP->getNumExpansionTemplateParameters();
3351 }
3352
3353 return std::nullopt;
3354}
3355
3356/// Internal helper used by Subst* nodes to retrieve the parameter list
3357/// for their AssociatedDecl.
3358TemplateParameterList *getReplacedTemplateParameterList(Decl *D);
3359
3360} // namespace clang
3361
3362#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
const Decl * D
enum clang::sema::@1727::IndirectLocalPathEntry::EntryKind Kind
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:1134
SourceLocation Loc
Definition: SemaObjC.cpp:759
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
C Language Family Type Representation.
__device__ int
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:384
bool isConstrained() const
Definition: Type.h:6580
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:1439
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:735
Storage for a default argument.
Definition: DeclTemplate.h:305
void setInherited(const ASTContext &C, ParmDecl *InheritedFrom)
Set that the default argument was inherited from another parameter.
Definition: DeclTemplate.h:365
bool isSet() const
Determine whether there is a default argument for this parameter.
Definition: DeclTemplate.h:331
ArgType get() const
Get the default argument's value.
Definition: DeclTemplate.h:339
void set(ArgType Arg)
Set the default argument.
Definition: DeclTemplate.h:359
void clear()
Remove the default argument, even if it was inherited.
Definition: DeclTemplate.h: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:7146
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:464
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:7907
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type.
Definition: Type.h:2811
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8736
A set of unresolved declarations.
Definition: UnresolvedSet.h:62
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:671
QualType getType() const
Definition: Decl.h:682
Represents a variable declaration or definition.
Definition: Decl.h:882
DefinitionKind isThisDeclarationADefinition(ASTContext &) const
Check whether this declaration is a definition.
Definition: Decl.cpp:2249
TemplateSpecializationKind getTemplateSpecializationKind() const
If this variable is an instantiation of a variable template or a static data member of a class templa...
Definition: Decl.cpp:2755
Declaration of a variable template.
VarTemplateDecl * getDefinition()
VarDecl * getTemplatedDecl() const
Get the underlying variable declarations of the template.
VarTemplateDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this template.
void AddPartialSpecialization(VarTemplatePartialSpecializationDecl *D, void *InsertPos)
Insert the specified partial specialization knowing that it is not already in.
spec_iterator spec_begin() const
Common * getCommonPtr() const
VarTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, TemplateParameterList *TPL, void *&InsertPos)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
static bool classof(const Decl *D)
const VarTemplateDecl * getPreviousDecl() const
void AddSpecialization(VarTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
VarTemplateDecl * getInstantiatedFromMemberTemplate() const
VarTemplateDecl * getPreviousDecl()
Retrieve the previous declaration of this variable template, or nullptr if no such declaration exists...
CommonBase * newCommon(ASTContext &C) const override
void LoadLazySpecializations(bool OnlyPartial=false) const
Load any lazily-loaded specializations from the external source.
VarTemplateDecl(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
const VarTemplateDecl * getCanonicalDecl() const
static VarTemplateDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Create an empty variable template node.
llvm::iterator_range< spec_iterator > spec_range
llvm::FoldingSetVector< VarTemplatePartialSpecializationDecl > & getPartialSpecializations() const
Retrieve the set of partial specializations of this class template.
llvm::FoldingSetVector< VarTemplateSpecializationDecl > & getSpecializations() const
Retrieve the set of specializations of this variable template.
static bool classofKind(Kind K)
const VarTemplateDecl * getMostRecentDecl() const
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary variable pattern.
VarTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
VarTemplatePartialSpecializationDecl * findPartialSpecInstantiatedFromMember(VarTemplatePartialSpecializationDecl *D)
Find a variable template partial specialization which was instantiated from the given member partial ...
spec_iterator spec_end() const
VarTemplateDecl * getMostRecentDecl()
spec_range specializations() const
void setMemberSpecialization()
Note that this member template is a specialization.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
VarTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member variable template partial specialization from which this particular variable temp...
bool isMemberSpecialization() const
Determines whether this variable template partial specialization was a specialization of a member par...
void Profile(llvm::FoldingSetNodeID &ID) const
ArrayRef< TemplateArgument > getInjectedTemplateArgs(const ASTContext &Context) const
Get the template argument list of the template parameter list.
void getAssociatedConstraints(llvm::SmallVectorImpl< const Expr * > &AC) const
All associated constraints of this partial specialization, including the requires clause and any cons...
void setInstantiatedFromMember(VarTemplatePartialSpecializationDecl *PartialSpec)
static VarTemplatePartialSpecializationDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
VarTemplatePartialSpecializationDecl * getMostRecentDecl()
Represents a variable template specialization, which refers to a variable template with a given set o...
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
void setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten)
Set the template argument list as written in the sources.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
void setTemplateKeywordLoc(SourceLocation Loc)
Sets the location of the template keyword.
void setSpecializationKind(TemplateSpecializationKind TSK)
static void Profile(llvm::FoldingSetNodeID &ID, ArrayRef< TemplateArgument > TemplateArgs, const ASTContext &Context)
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
const TemplateArgumentList & getTemplateInstantiationArgs() const
Retrieve the set of template arguments that should be used to instantiate the initializer of the vari...
static bool classof(const Decl *D)
SourceLocation getTemplateKeywordLoc() const
Gets the location of the template keyword, if present.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
void setInstantiationOf(VarTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs)
Note that this variable template specialization is actually an instantiation of the given variable te...
void Profile(llvm::FoldingSetNodeID &ID) const
void setPointOfInstantiation(SourceLocation Loc)
void setTemplateArgsAsWritten(const TemplateArgumentListInfo &ArgsInfo)
Set the template argument list as written in the sources.
llvm::PointerUnion< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > getSpecializedTemplateOrPartial() const
Retrieve the variable template or variable template partial specialization which was specialized by t...
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
void setInstantiationOf(VarTemplateDecl *TemplDecl)
Note that this variable template specialization is an instantiation of the given variable template.
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration,...
llvm::PointerUnion< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > getInstantiatedFrom() const
If this variable template specialization is an instantiation of a template (rather than an explicit s...
SourceLocation getExternKeywordLoc() const
Gets the location of the extern keyword, if present.
static VarTemplateSpecializationDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
void setExternKeywordLoc(SourceLocation Loc)
Sets the location of the extern keyword.
VarTemplateSpecializationDecl * getMostRecentDecl()
void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const override
Appends a human-readable name for this declaration into the given stream.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
The JSON file list parser is used to communicate input to InstallAPI.
bool isTemplateInstantiation(TemplateSpecializationKind Kind)
Determine whether this template specialization kind refers to an instantiation of an entity (as oppos...
Definition: Specifiers.h:212
Decl * getPrimaryMergedDecl(Decl *D)
Get the primary declaration for a declaration from an AST file.
Definition: Decl.cpp:76
NamedDecl * getAsNamedDecl(TemplateParameter P)
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
StorageClass
Storage classes.
Definition: Specifiers.h:248
void * allocateDefaultArgStorageChain(const ASTContext &C)
TemplateDecl * getAsTypeTemplateDecl(Decl *D)
llvm::PointerUnion< const ASTTemplateArgumentListInfo *, ExplicitInstantiationInfo * > SpecializationOrInstantiationInfo
TemplateParameterList * getReplacedTemplateParameterList(Decl *D)
Internal helper used by Subst* nodes to retrieve the parameter list for their AssociatedDecl.
TagTypeKind
The kind of a tag type.
Definition: Type.h:6876
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 ...