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 = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2013 return Info->TemplateArgsAsWritten;
2014 return cast<const ASTTemplateArgumentListInfo *>(ExplicitInfo);
2015 }
2016
2017 /// Set the template argument list as written in the sources.
2018 void
2020 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2021 Info->TemplateArgsAsWritten = ArgsWritten;
2022 else
2023 ExplicitInfo = ArgsWritten;
2024 }
2025
2026 /// Set the template argument list as written in the sources.
2030 }
2031
2032 /// Gets the location of the extern keyword, if present.
2034 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2035 return Info->ExternKeywordLoc;
2036 return SourceLocation();
2037 }
2038
2039 /// Sets the location of the extern keyword.
2041
2042 /// Gets the location of the template keyword, if present.
2044 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2045 return Info->TemplateKeywordLoc;
2046 return SourceLocation();
2047 }
2048
2049 /// Sets the location of the template keyword.
2051
2052 SourceRange getSourceRange() const override LLVM_READONLY;
2053
2054 void Profile(llvm::FoldingSetNodeID &ID) const {
2055 Profile(ID, TemplateArgs->asArray(), getASTContext());
2056 }
2057
2058 static void
2059 Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
2060 const ASTContext &Context) {
2061 ID.AddInteger(TemplateArgs.size());
2062 for (const TemplateArgument &TemplateArg : TemplateArgs)
2063 TemplateArg.Profile(ID, Context);
2064 }
2065
2066 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2067
2068 static bool classofKind(Kind K) {
2069 return K >= firstClassTemplateSpecialization &&
2070 K <= lastClassTemplateSpecialization;
2071 }
2072};
2073
2076 /// The list of template parameters
2077 TemplateParameterList *TemplateParams = nullptr;
2078
2079 /// The class template partial specialization from which this
2080 /// class template partial specialization was instantiated.
2081 ///
2082 /// The boolean value will be true to indicate that this class template
2083 /// partial specialization was specialized at this level.
2084 llvm::PointerIntPair<ClassTemplatePartialSpecializationDecl *, 1, bool>
2085 InstantiatedFromMember;
2086
2088 ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc,
2090 ClassTemplateDecl *SpecializedTemplate, ArrayRef<TemplateArgument> Args,
2092
2094 : ClassTemplateSpecializationDecl(C, ClassTemplatePartialSpecialization),
2095 InstantiatedFromMember(nullptr, false) {}
2096
2097 void anchor() override;
2098
2099public:
2100 friend class ASTDeclReader;
2101 friend class ASTDeclWriter;
2102
2104 Create(ASTContext &Context, TagKind TK, DeclContext *DC,
2105 SourceLocation StartLoc, SourceLocation IdLoc,
2106 TemplateParameterList *Params, ClassTemplateDecl *SpecializedTemplate,
2107 ArrayRef<TemplateArgument> Args, QualType CanonInjectedType,
2109
2112
2114 return cast<ClassTemplatePartialSpecializationDecl>(
2115 static_cast<ClassTemplateSpecializationDecl *>(
2116 this)->getMostRecentDecl());
2117 }
2118
2119 /// Get the list of template parameters
2121 return TemplateParams;
2122 }
2123
2124 /// Get the template argument list of the template parameter list.
2126 getInjectedTemplateArgs(const ASTContext &Context) const {
2128 }
2129
2130 /// \brief All associated constraints of this partial specialization,
2131 /// including the requires clause and any constraints derived from
2132 /// constrained-parameters.
2133 ///
2134 /// The constraints in the resulting list are to be treated as if in a
2135 /// conjunction ("and").
2137 TemplateParams->getAssociatedConstraints(AC);
2138 }
2139
2141 return TemplateParams->hasAssociatedConstraints();
2142 }
2143
2144 /// Retrieve the member class template partial specialization from
2145 /// which this particular class template partial specialization was
2146 /// instantiated.
2147 ///
2148 /// \code
2149 /// template<typename T>
2150 /// struct Outer {
2151 /// template<typename U> struct Inner;
2152 /// template<typename U> struct Inner<U*> { }; // #1
2153 /// };
2154 ///
2155 /// Outer<float>::Inner<int*> ii;
2156 /// \endcode
2157 ///
2158 /// In this example, the instantiation of \c Outer<float>::Inner<int*> will
2159 /// end up instantiating the partial specialization
2160 /// \c Outer<float>::Inner<U*>, which itself was instantiated from the class
2161 /// template partial specialization \c Outer<T>::Inner<U*>. Given
2162 /// \c Outer<float>::Inner<U*>, this function would return
2163 /// \c Outer<T>::Inner<U*>.
2165 const auto *First =
2166 cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2167 return First->InstantiatedFromMember.getPointer();
2168 }
2172 }
2173
2176 auto *First = cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2177 First->InstantiatedFromMember.setPointer(PartialSpec);
2178 }
2179
2180 /// Determines whether this class template partial specialization
2181 /// template was a specialization of a member partial specialization.
2182 ///
2183 /// In the following example, the member template partial specialization
2184 /// \c X<int>::Inner<T*> is a member specialization.
2185 ///
2186 /// \code
2187 /// template<typename T>
2188 /// struct X {
2189 /// template<typename U> struct Inner;
2190 /// template<typename U> struct Inner<U*>;
2191 /// };
2192 ///
2193 /// template<> template<typename T>
2194 /// struct X<int>::Inner<T*> { /* ... */ };
2195 /// \endcode
2197 const auto *First =
2198 cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2199 return First->InstantiatedFromMember.getInt();
2200 }
2201
2202 /// Note that this member template is a specialization.
2204 auto *First = cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2205 assert(First->InstantiatedFromMember.getPointer() &&
2206 "Only member templates can be member template specializations");
2207 return First->InstantiatedFromMember.setInt(true);
2208 }
2209
2210 /// Retrieves the injected specialization type for this partial
2211 /// specialization. This is not the same as the type-decl-type for
2212 /// this partial specialization, which is an InjectedClassNameType.
2214 assert(getTypeForDecl() && "partial specialization has no type set!");
2215 return cast<InjectedClassNameType>(getTypeForDecl())
2216 ->getInjectedSpecializationType();
2217 }
2218
2219 SourceRange getSourceRange() const override LLVM_READONLY;
2220
2221 void Profile(llvm::FoldingSetNodeID &ID) const {
2223 getASTContext());
2224 }
2225
2226 static void
2227 Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
2228 TemplateParameterList *TPL, const ASTContext &Context);
2229
2230 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2231
2232 static bool classofKind(Kind K) {
2233 return K == ClassTemplatePartialSpecialization;
2234 }
2235};
2236
2237/// Declaration of a class template.
2239protected:
2240 /// Data that is common to all of the declarations of a given
2241 /// class template.
2243 /// The class template specializations for this class
2244 /// template, including explicit specializations and instantiations.
2245 llvm::FoldingSetVector<ClassTemplateSpecializationDecl> Specializations;
2246
2247 /// The class template partial specializations for this class
2248 /// template.
2249 llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>
2251
2252 /// The injected-class-name type for this class template.
2254
2255 Common() = default;
2256 };
2257
2258 /// Retrieve the set of specializations of this class template.
2259 llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
2260 getSpecializations() const;
2261
2262 /// Retrieve the set of partial specializations of this class
2263 /// template.
2264 llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
2266
2269 NamedDecl *Decl)
2270 : RedeclarableTemplateDecl(ClassTemplate, C, DC, L, Name, Params, Decl) {}
2271
2272 CommonBase *newCommon(ASTContext &C) const override;
2273
2275 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
2276 }
2277
2279
2280public:
2281
2282 friend class ASTDeclReader;
2283 friend class ASTDeclWriter;
2285
2286 /// Load any lazily-loaded specializations from the external source.
2287 void LoadLazySpecializations(bool OnlyPartial = false) const;
2288
2289 /// Get the underlying class declarations of the template.
2291 return static_cast<CXXRecordDecl *>(TemplatedDecl);
2292 }
2293
2294 /// Returns whether this template declaration defines the primary
2295 /// class pattern.
2298 }
2299
2300 /// \brief Create a class template node.
2303 DeclarationName Name,
2304 TemplateParameterList *Params,
2305 NamedDecl *Decl);
2306
2307 /// Create an empty class template node.
2309
2310 /// Return the specialization with the provided arguments if it exists,
2311 /// otherwise return the insertion point.
2313 findSpecialization(ArrayRef<TemplateArgument> Args, void *&InsertPos);
2314
2315 /// Insert the specified specialization knowing that it is not already
2316 /// in. InsertPos must be obtained from findSpecialization.
2317 void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos);
2318
2320 return cast<ClassTemplateDecl>(
2322 }
2324 return cast<ClassTemplateDecl>(
2326 }
2327
2328 /// Retrieve the previous declaration of this class template, or
2329 /// nullptr if no such declaration exists.
2331 return cast_or_null<ClassTemplateDecl>(
2332 static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
2333 }
2335 return cast_or_null<ClassTemplateDecl>(
2336 static_cast<const RedeclarableTemplateDecl *>(
2337 this)->getPreviousDecl());
2338 }
2339
2341 return cast<ClassTemplateDecl>(
2342 static_cast<RedeclarableTemplateDecl *>(this)->getMostRecentDecl());
2343 }
2345 return const_cast<ClassTemplateDecl*>(this)->getMostRecentDecl();
2346 }
2347
2349 return cast_or_null<ClassTemplateDecl>(
2351 }
2352
2353 /// Return the partial specialization with the provided arguments if it
2354 /// exists, otherwise return the insertion point.
2357 TemplateParameterList *TPL, void *&InsertPos);
2358
2359 /// Insert the specified partial specialization knowing that it is not
2360 /// already in. InsertPos must be obtained from findPartialSpecialization.
2362 void *InsertPos);
2363
2364 /// Retrieve the partial specializations as an ordered list.
2367
2368 /// Find a class template partial specialization with the given
2369 /// type T.
2370 ///
2371 /// \param T a dependent type that names a specialization of this class
2372 /// template.
2373 ///
2374 /// \returns the class template partial specialization that exactly matches
2375 /// the type \p T, or nullptr if no such partial specialization exists.
2377
2378 /// Find a class template partial specialization which was instantiated
2379 /// from the given member partial specialization.
2380 ///
2381 /// \param D a member class template partial specialization.
2382 ///
2383 /// \returns the class template partial specialization which was instantiated
2384 /// from the given member partial specialization, or nullptr if no such
2385 /// partial specialization exists.
2389
2390 /// Retrieve the template specialization type of the
2391 /// injected-class-name for this class template.
2392 ///
2393 /// The injected-class-name for a class template \c X is \c
2394 /// X<template-args>, where \c template-args is formed from the
2395 /// template arguments that correspond to the template parameters of
2396 /// \c X. For example:
2397 ///
2398 /// \code
2399 /// template<typename T, int N>
2400 /// struct array {
2401 /// typedef array this_type; // "array" is equivalent to "array<T, N>"
2402 /// };
2403 /// \endcode
2405
2407 using spec_range = llvm::iterator_range<spec_iterator>;
2408
2410 return spec_range(spec_begin(), spec_end());
2411 }
2412
2414 return makeSpecIterator(getSpecializations(), false);
2415 }
2416
2418 return makeSpecIterator(getSpecializations(), true);
2419 }
2420
2421 // Implement isa/cast/dyncast support
2422 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2423 static bool classofKind(Kind K) { return K == ClassTemplate; }
2424};
2425
2426/// Declaration of a friend template.
2427///
2428/// For example:
2429/// \code
2430/// template <typename T> class A {
2431/// friend class MyVector<T>; // not a friend template
2432/// template <typename U> friend class B; // not a friend template
2433/// template <typename U> friend class Foo<T>::Nested; // friend template
2434/// };
2435/// \endcode
2436///
2437/// \note This class is not currently in use. All of the above
2438/// will yield a FriendDecl, not a FriendTemplateDecl.
2439class FriendTemplateDecl : public Decl {
2440 virtual void anchor();
2441
2442public:
2443 using FriendUnion = llvm::PointerUnion<NamedDecl *,TypeSourceInfo *>;
2444
2445private:
2446 // The number of template parameters; always non-zero.
2447 unsigned NumParams = 0;
2448
2449 // The parameter list.
2450 TemplateParameterList **Params = nullptr;
2451
2452 // The declaration that's a friend of this class.
2453 FriendUnion Friend;
2454
2455 // Location of the 'friend' specifier.
2456 SourceLocation FriendLoc;
2457
2459 TemplateParameterList **Params, unsigned NumParams,
2460 FriendUnion Friend, SourceLocation FriendLoc)
2461 : Decl(Decl::FriendTemplate, DC, Loc), NumParams(NumParams),
2462 Params(Params), Friend(Friend), FriendLoc(FriendLoc) {}
2463
2464 FriendTemplateDecl(EmptyShell Empty) : Decl(Decl::FriendTemplate, Empty) {}
2465
2466public:
2467 friend class ASTDeclReader;
2468
2469 static FriendTemplateDecl *
2472 SourceLocation FriendLoc);
2473
2475
2476 /// If this friend declaration names a templated type (or
2477 /// a dependent member type of a templated type), return that
2478 /// type; otherwise return null.
2480 return Friend.dyn_cast<TypeSourceInfo*>();
2481 }
2482
2483 /// If this friend declaration names a templated function (or
2484 /// a member function of a templated type), return that type;
2485 /// otherwise return null.
2487 return Friend.dyn_cast<NamedDecl*>();
2488 }
2489
2490 /// Retrieves the location of the 'friend' keyword.
2492 return FriendLoc;
2493 }
2494
2496 assert(i <= NumParams);
2497 return Params[i];
2498 }
2499
2500 unsigned getNumTemplateParameters() const {
2501 return NumParams;
2502 }
2503
2504 // Implement isa/cast/dyncast/etc.
2505 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2506 static bool classofKind(Kind K) { return K == Decl::FriendTemplate; }
2507};
2508
2509/// Declaration of an alias template.
2510///
2511/// For example:
2512/// \code
2513/// template <typename T> using V = std::map<T*, int, MyCompare<T>>;
2514/// \endcode
2516protected:
2518
2521 NamedDecl *Decl)
2522 : RedeclarableTemplateDecl(TypeAliasTemplate, C, DC, L, Name, Params,
2523 Decl) {}
2524
2525 CommonBase *newCommon(ASTContext &C) const override;
2526
2528 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
2529 }
2530
2531public:
2532 friend class ASTDeclReader;
2533 friend class ASTDeclWriter;
2534
2535 /// Get the underlying function declaration of the template.
2537 return static_cast<TypeAliasDecl *>(TemplatedDecl);
2538 }
2539
2540
2542 return cast<TypeAliasTemplateDecl>(
2544 }
2546 return cast<TypeAliasTemplateDecl>(
2548 }
2549
2550 /// Retrieve the previous declaration of this function template, or
2551 /// nullptr if no such declaration exists.
2553 return cast_or_null<TypeAliasTemplateDecl>(
2554 static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
2555 }
2557 return cast_or_null<TypeAliasTemplateDecl>(
2558 static_cast<const RedeclarableTemplateDecl *>(
2559 this)->getPreviousDecl());
2560 }
2561
2563 return cast_or_null<TypeAliasTemplateDecl>(
2565 }
2566
2567 /// Create a function template node.
2570 DeclarationName Name,
2571 TemplateParameterList *Params,
2572 NamedDecl *Decl);
2573
2574 /// Create an empty alias template node.
2577
2578 // Implement isa/cast/dyncast support
2579 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2580 static bool classofKind(Kind K) { return K == TypeAliasTemplate; }
2581};
2582
2583/// Represents a variable template specialization, which refers to
2584/// a variable template with a given set of template arguments.
2585///
2586/// Variable template specializations represent both explicit
2587/// specializations of variable templates, as in the example below, and
2588/// implicit instantiations of variable templates.
2589///
2590/// \code
2591/// template<typename T> constexpr T pi = T(3.1415926535897932385);
2592///
2593/// template<>
2594/// constexpr float pi<float>; // variable template specialization pi<float>
2595/// \endcode
2597 public llvm::FoldingSetNode {
2598
2599 /// Structure that stores information about a variable template
2600 /// specialization that was instantiated from a variable template partial
2601 /// specialization.
2602 struct SpecializedPartialSpecialization {
2603 /// The variable template partial specialization from which this
2604 /// variable template specialization was instantiated.
2605 VarTemplatePartialSpecializationDecl *PartialSpecialization;
2606
2607 /// The template argument list deduced for the variable template
2608 /// partial specialization itself.
2609 const TemplateArgumentList *TemplateArgs;
2610 };
2611
2612 /// The template that this specialization specializes.
2613 llvm::PointerUnion<VarTemplateDecl *, SpecializedPartialSpecialization *>
2614 SpecializedTemplate;
2615
2616 /// Further info for explicit template specialization/instantiation.
2617 /// Does not apply to implicit specializations.
2618 SpecializationOrInstantiationInfo ExplicitInfo = nullptr;
2619
2620 /// The template arguments used to describe this specialization.
2621 const TemplateArgumentList *TemplateArgs;
2622
2623 /// The point where this template was instantiated (if any).
2624 SourceLocation PointOfInstantiation;
2625
2626 /// The kind of specialization this declaration refers to.
2627 LLVM_PREFERRED_TYPE(TemplateSpecializationKind)
2628 unsigned SpecializationKind : 3;
2629
2630 /// Whether this declaration is a complete definition of the
2631 /// variable template specialization. We can't otherwise tell apart
2632 /// an instantiated declaration from an instantiated definition with
2633 /// no initializer.
2634 LLVM_PREFERRED_TYPE(bool)
2635 unsigned IsCompleteDefinition : 1;
2636
2637protected:
2639 SourceLocation StartLoc, SourceLocation IdLoc,
2640 VarTemplateDecl *SpecializedTemplate,
2641 QualType T, TypeSourceInfo *TInfo,
2642 StorageClass S,
2644
2645 explicit VarTemplateSpecializationDecl(Kind DK, ASTContext &Context);
2646
2647public:
2648 friend class ASTDeclReader;
2649 friend class ASTDeclWriter;
2650 friend class VarDecl;
2651
2653 Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
2654 SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
2655 TypeSourceInfo *TInfo, StorageClass S,
2659
2660 void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy,
2661 bool Qualified) const override;
2662
2664 VarDecl *Recent = static_cast<VarDecl *>(this)->getMostRecentDecl();
2665 return cast<VarTemplateSpecializationDecl>(Recent);
2666 }
2667
2668 /// Retrieve the template that this specialization specializes.
2670
2671 /// Retrieve the template arguments of the variable template
2672 /// specialization.
2673 const TemplateArgumentList &getTemplateArgs() const { return *TemplateArgs; }
2674
2675 /// Determine the kind of specialization that this
2676 /// declaration represents.
2678 return static_cast<TemplateSpecializationKind>(SpecializationKind);
2679 }
2680
2683 }
2684
2686 return isExplicitSpecialization() &&
2687 isa<CXXRecordDecl>(getLexicalDeclContext());
2688 }
2689
2690 /// True if this declaration is an explicit specialization,
2691 /// explicit instantiation declaration, or explicit instantiation
2692 /// definition.
2696 }
2697
2699 SpecializationKind = TSK;
2700 }
2701
2702 /// Get the point of instantiation (if any), or null if none.
2704 return PointOfInstantiation;
2705 }
2706
2708 assert(Loc.isValid() && "point of instantiation must be valid!");
2709 PointOfInstantiation = Loc;
2710 }
2711
2712 void setCompleteDefinition() { IsCompleteDefinition = true; }
2713
2714 /// If this variable template specialization is an instantiation of
2715 /// a template (rather than an explicit specialization), return the
2716 /// variable template or variable template partial specialization from which
2717 /// it was instantiated.
2718 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
2721 return llvm::PointerUnion<VarTemplateDecl *,
2723
2725 }
2726
2727 /// Retrieve the variable template or variable template partial
2728 /// specialization which was specialized by this.
2729 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
2731 if (const auto *PartialSpec =
2732 SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
2733 return PartialSpec->PartialSpecialization;
2734
2735 return cast<VarTemplateDecl *>(SpecializedTemplate);
2736 }
2737
2738 /// Retrieve the set of template arguments that should be used
2739 /// to instantiate the initializer of the variable template or variable
2740 /// template partial specialization from which this variable template
2741 /// specialization was instantiated.
2742 ///
2743 /// \returns For a variable template specialization instantiated from the
2744 /// primary template, this function will return the same template arguments
2745 /// as getTemplateArgs(). For a variable template specialization instantiated
2746 /// from a variable template partial specialization, this function will the
2747 /// return deduced template arguments for the variable template partial
2748 /// specialization itself.
2750 if (const auto *PartialSpec =
2751 SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
2752 return *PartialSpec->TemplateArgs;
2753
2754 return getTemplateArgs();
2755 }
2756
2757 /// Note that this variable template specialization is actually an
2758 /// instantiation of the given variable template partial specialization whose
2759 /// template arguments have been deduced.
2761 const TemplateArgumentList *TemplateArgs) {
2762 assert(!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) &&
2763 "Already set to a variable template partial specialization!");
2764 auto *PS = new (getASTContext()) SpecializedPartialSpecialization();
2765 PS->PartialSpecialization = PartialSpec;
2766 PS->TemplateArgs = TemplateArgs;
2767 SpecializedTemplate = PS;
2768 }
2769
2770 /// Note that this variable template specialization is an instantiation
2771 /// of the given variable template.
2773 assert(!isa<SpecializedPartialSpecialization *>(SpecializedTemplate) &&
2774 "Previously set to a variable template partial specialization!");
2775 SpecializedTemplate = TemplDecl;
2776 }
2777
2778 /// Retrieve the template argument list as written in the sources,
2779 /// if any.
2781 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2782 return Info->TemplateArgsAsWritten;
2783 return cast<const ASTTemplateArgumentListInfo *>(ExplicitInfo);
2784 }
2785
2786 /// Set the template argument list as written in the sources.
2787 void
2789 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2790 Info->TemplateArgsAsWritten = ArgsWritten;
2791 else
2792 ExplicitInfo = ArgsWritten;
2793 }
2794
2795 /// Set the template argument list as written in the sources.
2799 }
2800
2801 /// Gets the location of the extern keyword, if present.
2803 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2804 return Info->ExternKeywordLoc;
2805 return SourceLocation();
2806 }
2807
2808 /// Sets the location of the extern keyword.
2810
2811 /// Gets the location of the template keyword, if present.
2813 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2814 return Info->TemplateKeywordLoc;
2815 return SourceLocation();
2816 }
2817
2818 /// Sets the location of the template keyword.
2820
2821 SourceRange getSourceRange() const override LLVM_READONLY;
2822
2823 void Profile(llvm::FoldingSetNodeID &ID) const {
2824 Profile(ID, TemplateArgs->asArray(), getASTContext());
2825 }
2826
2827 static void Profile(llvm::FoldingSetNodeID &ID,
2828 ArrayRef<TemplateArgument> TemplateArgs,
2829 const ASTContext &Context) {
2830 ID.AddInteger(TemplateArgs.size());
2831 for (const TemplateArgument &TemplateArg : TemplateArgs)
2832 TemplateArg.Profile(ID, Context);
2833 }
2834
2835 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2836
2837 static bool classofKind(Kind K) {
2838 return K >= firstVarTemplateSpecialization &&
2839 K <= lastVarTemplateSpecialization;
2840 }
2841};
2842
2845 /// The list of template parameters
2846 TemplateParameterList *TemplateParams = nullptr;
2847
2848 /// The variable template partial specialization from which this
2849 /// variable template partial specialization was instantiated.
2850 ///
2851 /// The boolean value will be true to indicate that this variable template
2852 /// partial specialization was specialized at this level.
2853 llvm::PointerIntPair<VarTemplatePartialSpecializationDecl *, 1, bool>
2854 InstantiatedFromMember;
2855
2857 ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
2859 VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
2861
2863 : VarTemplateSpecializationDecl(VarTemplatePartialSpecialization,
2864 Context),
2865 InstantiatedFromMember(nullptr, false) {}
2866
2867 void anchor() override;
2868
2869public:
2870 friend class ASTDeclReader;
2871 friend class ASTDeclWriter;
2872
2874 Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
2876 VarTemplateDecl *SpecializedTemplate, QualType T,
2877 TypeSourceInfo *TInfo, StorageClass S,
2879
2882
2884 return cast<VarTemplatePartialSpecializationDecl>(
2885 static_cast<VarTemplateSpecializationDecl *>(
2886 this)->getMostRecentDecl());
2887 }
2888
2889 /// Get the list of template parameters
2891 return TemplateParams;
2892 }
2893
2894 /// Get the template argument list of the template parameter list.
2896 getInjectedTemplateArgs(const ASTContext &Context) const {
2898 }
2899
2900 /// \brief All associated constraints of this partial specialization,
2901 /// including the requires clause and any constraints derived from
2902 /// constrained-parameters.
2903 ///
2904 /// The constraints in the resulting list are to be treated as if in a
2905 /// conjunction ("and").
2907 TemplateParams->getAssociatedConstraints(AC);
2908 }
2909
2911 return TemplateParams->hasAssociatedConstraints();
2912 }
2913
2914 /// \brief Retrieve the member variable template partial specialization from
2915 /// which this particular variable template partial specialization was
2916 /// instantiated.
2917 ///
2918 /// \code
2919 /// template<typename T>
2920 /// struct Outer {
2921 /// template<typename U> U Inner;
2922 /// template<typename U> U* Inner<U*> = (U*)(0); // #1
2923 /// };
2924 ///
2925 /// template int* Outer<float>::Inner<int*>;
2926 /// \endcode
2927 ///
2928 /// In this example, the instantiation of \c Outer<float>::Inner<int*> will
2929 /// end up instantiating the partial specialization
2930 /// \c Outer<float>::Inner<U*>, which itself was instantiated from the
2931 /// variable template partial specialization \c Outer<T>::Inner<U*>. Given
2932 /// \c Outer<float>::Inner<U*>, this function would return
2933 /// \c Outer<T>::Inner<U*>.
2935 const auto *First =
2936 cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2937 return First->InstantiatedFromMember.getPointer();
2938 }
2939
2940 void
2942 auto *First = cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2943 First->InstantiatedFromMember.setPointer(PartialSpec);
2944 }
2945
2946 /// Determines whether this variable template partial specialization
2947 /// was a specialization of a member partial specialization.
2948 ///
2949 /// In the following example, the member template partial specialization
2950 /// \c X<int>::Inner<T*> is a member specialization.
2951 ///
2952 /// \code
2953 /// template<typename T>
2954 /// struct X {
2955 /// template<typename U> U Inner;
2956 /// template<typename U> U* Inner<U*> = (U*)(0);
2957 /// };
2958 ///
2959 /// template<> template<typename T>
2960 /// U* X<int>::Inner<T*> = (T*)(0) + 1;
2961 /// \endcode
2963 const auto *First =
2964 cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2965 return First->InstantiatedFromMember.getInt();
2966 }
2967
2968 /// Note that this member template is a specialization.
2970 auto *First = cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2971 assert(First->InstantiatedFromMember.getPointer() &&
2972 "Only member templates can be member template specializations");
2973 return First->InstantiatedFromMember.setInt(true);
2974 }
2975
2976 SourceRange getSourceRange() const override LLVM_READONLY;
2977
2978 void Profile(llvm::FoldingSetNodeID &ID) const {
2980 getASTContext());
2981 }
2982
2983 static void
2984 Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
2985 TemplateParameterList *TPL, const ASTContext &Context);
2986
2987 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2988
2989 static bool classofKind(Kind K) {
2990 return K == VarTemplatePartialSpecialization;
2991 }
2992};
2993
2994/// Declaration of a variable template.
2996protected:
2997 /// Data that is common to all of the declarations of a given
2998 /// variable template.
3000 /// The variable template specializations for this variable
3001 /// template, including explicit specializations and instantiations.
3002 llvm::FoldingSetVector<VarTemplateSpecializationDecl> Specializations;
3003
3004 /// The variable template partial specializations for this variable
3005 /// template.
3006 llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl>
3008
3009 Common() = default;
3010 };
3011
3012 /// Retrieve the set of specializations of this variable template.
3013 llvm::FoldingSetVector<VarTemplateSpecializationDecl> &
3014 getSpecializations() const;
3015
3016 /// Retrieve the set of partial specializations of this class
3017 /// template.
3018 llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &
3020
3023 NamedDecl *Decl)
3024 : RedeclarableTemplateDecl(VarTemplate, C, DC, L, Name, Params, Decl) {}
3025
3026 CommonBase *newCommon(ASTContext &C) const override;
3027
3029 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
3030 }
3031
3032public:
3033 friend class ASTDeclReader;
3034 friend class ASTDeclWriter;
3035
3036 /// Load any lazily-loaded specializations from the external source.
3037 void LoadLazySpecializations(bool OnlyPartial = false) const;
3038
3039 /// Get the underlying variable declarations of the template.
3041 return static_cast<VarDecl *>(TemplatedDecl);
3042 }
3043
3044 /// Returns whether this template declaration defines the primary
3045 /// variable pattern.
3048 }
3049
3051
3052 /// Create a variable template node.
3055 TemplateParameterList *Params,
3056 VarDecl *Decl);
3057
3058 /// Create an empty variable template node.
3060
3061 /// Return the specialization with the provided arguments if it exists,
3062 /// otherwise return the insertion point.
3064 findSpecialization(ArrayRef<TemplateArgument> Args, void *&InsertPos);
3065
3066 /// Insert the specified specialization knowing that it is not already
3067 /// in. InsertPos must be obtained from findSpecialization.
3068 void AddSpecialization(VarTemplateSpecializationDecl *D, void *InsertPos);
3069
3071 return cast<VarTemplateDecl>(RedeclarableTemplateDecl::getCanonicalDecl());
3072 }
3074 return cast<VarTemplateDecl>(RedeclarableTemplateDecl::getCanonicalDecl());
3075 }
3076
3077 /// Retrieve the previous declaration of this variable template, or
3078 /// nullptr if no such declaration exists.
3080 return cast_or_null<VarTemplateDecl>(
3081 static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
3082 }
3084 return cast_or_null<VarTemplateDecl>(
3085 static_cast<const RedeclarableTemplateDecl *>(
3086 this)->getPreviousDecl());
3087 }
3088
3090 return cast<VarTemplateDecl>(
3091 static_cast<RedeclarableTemplateDecl *>(this)->getMostRecentDecl());
3092 }
3094 return const_cast<VarTemplateDecl *>(this)->getMostRecentDecl();
3095 }
3096
3098 return cast_or_null<VarTemplateDecl>(
3100 }
3101
3102 /// Return the partial specialization with the provided arguments if it
3103 /// exists, otherwise return the insertion point.
3106 TemplateParameterList *TPL, void *&InsertPos);
3107
3108 /// Insert the specified partial specialization knowing that it is not
3109 /// already in. InsertPos must be obtained from findPartialSpecialization.
3111 void *InsertPos);
3112
3113 /// Retrieve the partial specializations as an ordered list.
3116
3117 /// Find a variable template partial specialization which was
3118 /// instantiated
3119 /// from the given member partial specialization.
3120 ///
3121 /// \param D a member variable template partial specialization.
3122 ///
3123 /// \returns the variable template partial specialization which was
3124 /// instantiated
3125 /// from the given member partial specialization, or nullptr if no such
3126 /// partial specialization exists.
3129
3131 using spec_range = llvm::iterator_range<spec_iterator>;
3132
3134 return spec_range(spec_begin(), spec_end());
3135 }
3136
3138 return makeSpecIterator(getSpecializations(), false);
3139 }
3140
3142 return makeSpecIterator(getSpecializations(), true);
3143 }
3144
3145 // Implement isa/cast/dyncast support
3146 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3147 static bool classofKind(Kind K) { return K == VarTemplate; }
3148};
3149
3150/// Declaration of a C++20 concept.
3151class ConceptDecl : public TemplateDecl, public Mergeable<ConceptDecl> {
3152protected:
3154
3157 : TemplateDecl(Concept, DC, L, Name, Params),
3159public:
3161 DeclarationName Name,
3162 TemplateParameterList *Params,
3163 Expr *ConstraintExpr = nullptr);
3165
3167 return ConstraintExpr;
3168 }
3169
3170 bool hasDefinition() const { return ConstraintExpr != nullptr; }
3171
3173
3174 SourceRange getSourceRange() const override LLVM_READONLY {
3175 return SourceRange(getTemplateParameters()->getTemplateLoc(),
3177 : SourceLocation());
3178 }
3179
3180 bool isTypeConcept() const {
3181 return isa<TemplateTypeParmDecl>(getTemplateParameters()->getParam(0));
3182 }
3183
3185 return cast<ConceptDecl>(getPrimaryMergedDecl(this));
3186 }
3188 return const_cast<ConceptDecl *>(this)->getCanonicalDecl();
3189 }
3190
3191 // Implement isa/cast/dyncast/etc.
3192 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3193 static bool classofKind(Kind K) { return K == Concept; }
3194
3195 friend class ASTReader;
3196 friend class ASTDeclReader;
3197 friend class ASTDeclWriter;
3198};
3199
3200// An implementation detail of ConceptSpecialicationExpr that holds the template
3201// arguments, so we can later use this to reconstitute the template arguments
3202// during constraint checking.
3204 : public Decl,
3205 private llvm::TrailingObjects<ImplicitConceptSpecializationDecl,
3206 TemplateArgument> {
3207 unsigned NumTemplateArgs;
3208
3210 ArrayRef<TemplateArgument> ConvertedArgs);
3211 ImplicitConceptSpecializationDecl(EmptyShell Empty, unsigned NumTemplateArgs);
3212
3213public:
3216 ArrayRef<TemplateArgument> ConvertedArgs);
3219 unsigned NumTemplateArgs);
3220
3222 return ArrayRef<TemplateArgument>(getTrailingObjects<TemplateArgument>(),
3223 NumTemplateArgs);
3224 }
3226
3227 static bool classofKind(Kind K) { return K == ImplicitConceptSpecialization; }
3228 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3229
3231 friend class ASTDeclReader;
3232};
3233
3234/// A template parameter object.
3235///
3236/// Template parameter objects represent values of class type used as template
3237/// arguments. There is one template parameter object for each such distinct
3238/// value used as a template argument across the program.
3239///
3240/// \code
3241/// struct A { int x, y; };
3242/// template<A> struct S;
3243/// S<A{1, 2}> s1;
3244/// S<A{1, 2}> s2; // same type, argument is same TemplateParamObjectDecl.
3245/// \endcode
3247 public Mergeable<TemplateParamObjectDecl>,
3248 public llvm::FoldingSetNode {
3249private:
3250 /// The value of this template parameter object.
3251 APValue Value;
3252
3254 : ValueDecl(TemplateParamObject, DC, SourceLocation(), DeclarationName(),
3255 T),
3256 Value(V) {}
3257
3259 const APValue &V);
3260 static TemplateParamObjectDecl *CreateDeserialized(ASTContext &C,
3262
3263 /// Only ASTContext::getTemplateParamObjectDecl and deserialization
3264 /// create these.
3265 friend class ASTContext;
3266 friend class ASTReader;
3267 friend class ASTDeclReader;
3268
3269public:
3270 /// Print this template parameter object in a human-readable format.
3271 void printName(llvm::raw_ostream &OS,
3272 const PrintingPolicy &Policy) const override;
3273
3274 /// Print this object as an equivalent expression.
3275 void printAsExpr(llvm::raw_ostream &OS) const;
3276 void printAsExpr(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const;
3277
3278 /// Print this object as an initializer suitable for a variable of the
3279 /// object's type.
3280 void printAsInit(llvm::raw_ostream &OS) const;
3281 void printAsInit(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const;
3282
3283 const APValue &getValue() const { return Value; }
3284
3285 static void Profile(llvm::FoldingSetNodeID &ID, QualType T,
3286 const APValue &V) {
3287 ID.AddPointer(T.getCanonicalType().getAsOpaquePtr());
3288 V.Profile(ID);
3289 }
3290 void Profile(llvm::FoldingSetNodeID &ID) {
3291 Profile(ID, getType(), getValue());
3292 }
3293
3295 return getFirstDecl();
3296 }
3298 return getFirstDecl();
3299 }
3300
3301 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3302 static bool classofKind(Kind K) { return K == TemplateParamObject; }
3303};
3304
3306 if (auto *PD = P.dyn_cast<TemplateTypeParmDecl *>())
3307 return PD;
3308 if (auto *PD = P.dyn_cast<NonTypeTemplateParmDecl *>())
3309 return PD;
3310 return cast<TemplateTemplateParmDecl *>(P);
3311}
3312
3314 auto *TD = dyn_cast<TemplateDecl>(D);
3315 return TD && (isa<ClassTemplateDecl>(TD) ||
3316 isa<ClassTemplatePartialSpecializationDecl>(TD) ||
3317 isa<TypeAliasTemplateDecl>(TD) ||
3318 isa<TemplateTemplateParmDecl>(TD))
3319 ? TD
3320 : nullptr;
3321}
3322
3323/// Check whether the template parameter is a pack expansion, and if so,
3324/// determine the number of parameters produced by that expansion. For instance:
3325///
3326/// \code
3327/// template<typename ...Ts> struct A {
3328/// template<Ts ...NTs, template<Ts> class ...TTs, typename ...Us> struct B;
3329/// };
3330/// \endcode
3331///
3332/// In \c A<int,int>::B, \c NTs and \c TTs have expanded pack size 2, and \c Us
3333/// is not a pack expansion, so returns an empty Optional.
3334inline std::optional<unsigned> getExpandedPackSize(const NamedDecl *Param) {
3335 if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
3336 if (TTP->isExpandedParameterPack())
3337 return TTP->getNumExpansionParameters();
3338 }
3339
3340 if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
3341 if (NTTP->isExpandedParameterPack())
3342 return NTTP->getNumExpansionTypes();
3343 }
3344
3345 if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(Param)) {
3346 if (TTP->isExpandedParameterPack())
3347 return TTP->getNumExpansionTemplateParameters();
3348 }
3349
3350 return std::nullopt;
3351}
3352
3353/// Internal helper used by Subst* nodes to retrieve the parameter list
3354/// for their AssociatedDecl.
3355TemplateParameterList *getReplacedTemplateParameterList(Decl *D);
3356
3357} // namespace clang
3358
3359#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::@1726::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:2011
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:357
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 ...