clang 19.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 location of the 'template' keyword.
75 SourceLocation TemplateLoc;
76
77 /// The locations of the '<' and '>' angle brackets.
78 SourceLocation LAngleLoc, RAngleLoc;
79
80 /// The number of template parameters in this template
81 /// parameter list.
82 unsigned NumParams : 29;
83
84 /// Whether this template parameter list contains an unexpanded parameter
85 /// pack.
86 LLVM_PREFERRED_TYPE(bool)
87 unsigned ContainsUnexpandedParameterPack : 1;
88
89 /// Whether this template parameter list has a requires clause.
90 LLVM_PREFERRED_TYPE(bool)
91 unsigned HasRequiresClause : 1;
92
93 /// Whether any of the template parameters has constrained-parameter
94 /// constraint-expression.
95 LLVM_PREFERRED_TYPE(bool)
96 unsigned HasConstrainedParameters : 1;
97
98protected:
100 SourceLocation LAngleLoc, ArrayRef<NamedDecl *> Params,
101 SourceLocation RAngleLoc, Expr *RequiresClause);
102
103 size_t numTrailingObjects(OverloadToken<NamedDecl *>) const {
104 return NumParams;
105 }
106
107 size_t numTrailingObjects(OverloadToken<Expr *>) const {
108 return HasRequiresClause ? 1 : 0;
109 }
110
111public:
112 template <size_t N, bool HasRequiresClause>
115
117 SourceLocation TemplateLoc,
118 SourceLocation LAngleLoc,
120 SourceLocation RAngleLoc,
121 Expr *RequiresClause);
122
123 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &C) const;
124
125 /// Iterates through the template parameters in this list.
126 using iterator = NamedDecl **;
127
128 /// Iterates through the template parameters in this list.
129 using const_iterator = NamedDecl * const *;
130
131 iterator begin() { return getTrailingObjects<NamedDecl *>(); }
132 const_iterator begin() const { return getTrailingObjects<NamedDecl *>(); }
133 iterator end() { return begin() + NumParams; }
134 const_iterator end() const { return begin() + NumParams; }
135
136 unsigned size() const { return NumParams; }
137 bool empty() const { return NumParams == 0; }
138
141 return llvm::ArrayRef(begin(), size());
142 }
143
144 NamedDecl* getParam(unsigned Idx) {
145 assert(Idx < size() && "Template parameter index out-of-range");
146 return begin()[Idx];
147 }
148 const NamedDecl* getParam(unsigned Idx) const {
149 assert(Idx < size() && "Template parameter index out-of-range");
150 return begin()[Idx];
151 }
152
153 /// Returns the minimum number of arguments needed to form a
154 /// template specialization.
155 ///
156 /// This may be fewer than the number of template parameters, if some of
157 /// the parameters have default arguments or if there is a parameter pack.
158 unsigned getMinRequiredArguments() const;
159
160 /// Get the depth of this template parameter list in the set of
161 /// template parameter lists.
162 ///
163 /// The first template parameter list in a declaration will have depth 0,
164 /// the second template parameter list will have depth 1, etc.
165 unsigned getDepth() const;
166
167 /// Determine whether this template parameter list contains an
168 /// unexpanded parameter pack.
170
171 /// Determine whether this template parameter list contains a parameter pack.
172 bool hasParameterPack() const {
173 for (const NamedDecl *P : asArray())
174 if (P->isParameterPack())
175 return true;
176 return false;
177 }
178
179 /// The constraint-expression of the associated requires-clause.
181 return HasRequiresClause ? getTrailingObjects<Expr *>()[0] : nullptr;
182 }
183
184 /// The constraint-expression of the associated requires-clause.
185 const Expr *getRequiresClause() const {
186 return HasRequiresClause ? getTrailingObjects<Expr *>()[0] : nullptr;
187 }
188
189 /// \brief All associated constraints derived from this template parameter
190 /// list, including the requires clause and any constraints derived from
191 /// constrained-parameters.
192 ///
193 /// The constraints in the resulting list are to be treated as if in a
194 /// conjunction ("and").
196
198
199 SourceLocation getTemplateLoc() const { return TemplateLoc; }
200 SourceLocation getLAngleLoc() const { return LAngleLoc; }
201 SourceLocation getRAngleLoc() const { return RAngleLoc; }
202
203 SourceRange getSourceRange() const LLVM_READONLY {
204 return SourceRange(TemplateLoc, RAngleLoc);
205 }
206
207 void print(raw_ostream &Out, const ASTContext &Context,
208 bool OmitTemplateKW = false) const;
209 void print(raw_ostream &Out, const ASTContext &Context,
210 const PrintingPolicy &Policy, bool OmitTemplateKW = false) const;
211
213 const TemplateParameterList *TPL,
214 unsigned Idx);
215};
216
217/// Stores a list of template parameters and the associated
218/// requires-clause (if any) for a TemplateDecl and its derived classes.
219/// Suitable for creating on the stack.
220template <size_t N, bool HasRequiresClause>
222 : public TemplateParameterList::FixedSizeStorageOwner {
223 typename TemplateParameterList::FixedSizeStorage<
224 NamedDecl *, Expr *>::with_counts<
225 N, HasRequiresClause ? 1u : 0u
226 >::type storage;
227
228public:
230 SourceLocation TemplateLoc,
231 SourceLocation LAngleLoc,
233 SourceLocation RAngleLoc,
234 Expr *RequiresClause)
235 : FixedSizeStorageOwner(
236 (assert(N == Params.size()),
237 assert(HasRequiresClause == (RequiresClause != nullptr)),
238 new (static_cast<void *>(&storage)) TemplateParameterList(C,
239 TemplateLoc, LAngleLoc, Params, RAngleLoc, RequiresClause))) {}
240};
241
242/// A template argument list.
244 : private llvm::TrailingObjects<TemplateArgumentList, TemplateArgument> {
245 /// The number of template arguments in this template
246 /// argument list.
247 unsigned NumArguments;
248
249 // Constructs an instance with an internal Argument list, containing
250 // a copy of the Args array. (Called by CreateCopy)
252
253public:
255
258
259 /// Create a new template argument list that copies the given set of
260 /// template arguments.
263
264 /// Retrieve the template argument at a given index.
265 const TemplateArgument &get(unsigned Idx) const {
266 assert(Idx < NumArguments && "Invalid template argument index");
267 return data()[Idx];
268 }
269
270 /// Retrieve the template argument at a given index.
271 const TemplateArgument &operator[](unsigned Idx) const { return get(Idx); }
272
273 /// Produce this as an array ref.
275 return llvm::ArrayRef(data(), size());
276 }
277
278 /// Retrieve the number of template arguments in this
279 /// template argument list.
280 unsigned size() const { return NumArguments; }
281
282 /// Retrieve a pointer to the template argument list.
283 const TemplateArgument *data() const {
284 return getTrailingObjects<TemplateArgument>();
285 }
286};
287
288void *allocateDefaultArgStorageChain(const ASTContext &C);
289
290/// Storage for a default argument. This is conceptually either empty, or an
291/// argument value, or a pointer to a previous declaration that had a default
292/// argument.
293///
294/// However, this is complicated by modules: while we require all the default
295/// arguments for a template to be equivalent, there may be more than one, and
296/// we need to track all the originating parameters to determine if the default
297/// argument is visible.
298template<typename ParmDecl, typename ArgType>
300 /// Storage for both the value *and* another parameter from which we inherit
301 /// the default argument. This is used when multiple default arguments for a
302 /// parameter are merged together from different modules.
303 struct Chain {
304 ParmDecl *PrevDeclWithDefaultArg;
305 ArgType Value;
306 };
307 static_assert(sizeof(Chain) == sizeof(void *) * 2,
308 "non-pointer argument type?");
309
310 llvm::PointerUnion<ArgType, ParmDecl*, Chain*> ValueOrInherited;
311
312 static ParmDecl *getParmOwningDefaultArg(ParmDecl *Parm) {
313 const DefaultArgStorage &Storage = Parm->getDefaultArgStorage();
314 if (auto *Prev = Storage.ValueOrInherited.template dyn_cast<ParmDecl *>())
315 Parm = Prev;
316 assert(!Parm->getDefaultArgStorage()
317 .ValueOrInherited.template is<ParmDecl *>() &&
318 "should only be one level of indirection");
319 return Parm;
320 }
321
322public:
323 DefaultArgStorage() : ValueOrInherited(ArgType()) {}
324
325 /// Determine whether there is a default argument for this parameter.
326 bool isSet() const { return !ValueOrInherited.isNull(); }
327
328 /// Determine whether the default argument for this parameter was inherited
329 /// from a previous declaration of the same entity.
330 bool isInherited() const { return ValueOrInherited.template is<ParmDecl*>(); }
331
332 /// Get the default argument's value. This does not consider whether the
333 /// default argument is visible.
334 ArgType get() const {
335 const DefaultArgStorage *Storage = this;
336 if (const auto *Prev = ValueOrInherited.template dyn_cast<ParmDecl *>())
337 Storage = &Prev->getDefaultArgStorage();
338 if (const auto *C = Storage->ValueOrInherited.template dyn_cast<Chain *>())
339 return C->Value;
340 return Storage->ValueOrInherited.template get<ArgType>();
341 }
342
343 /// Get the parameter from which we inherit the default argument, if any.
344 /// This is the parameter on which the default argument was actually written.
345 const ParmDecl *getInheritedFrom() const {
346 if (const auto *D = ValueOrInherited.template dyn_cast<ParmDecl *>())
347 return D;
348 if (const auto *C = ValueOrInherited.template dyn_cast<Chain *>())
349 return C->PrevDeclWithDefaultArg;
350 return nullptr;
351 }
352
353 /// Set the default argument.
354 void set(ArgType Arg) {
355 assert(!isSet() && "default argument already set");
356 ValueOrInherited = Arg;
357 }
358
359 /// Set that the default argument was inherited from another parameter.
360 void setInherited(const ASTContext &C, ParmDecl *InheritedFrom) {
361 InheritedFrom = getParmOwningDefaultArg(InheritedFrom);
362 if (!isSet())
363 ValueOrInherited = InheritedFrom;
364 else if ([[maybe_unused]] auto *D =
365 ValueOrInherited.template dyn_cast<ParmDecl *>()) {
366 assert(C.isSameDefaultTemplateArgument(D, InheritedFrom));
367 ValueOrInherited =
368 new (allocateDefaultArgStorageChain(C)) Chain{InheritedFrom, get()};
369 } else if (auto *Inherited =
370 ValueOrInherited.template dyn_cast<Chain *>()) {
371 assert(C.isSameDefaultTemplateArgument(Inherited->PrevDeclWithDefaultArg,
372 InheritedFrom));
373 Inherited->PrevDeclWithDefaultArg = InheritedFrom;
374 } else
375 ValueOrInherited = new (allocateDefaultArgStorageChain(C))
376 Chain{InheritedFrom, ValueOrInherited.template get<ArgType>()};
377 }
378
379 /// Remove the default argument, even if it was inherited.
380 void clear() {
381 ValueOrInherited = ArgType();
382 }
383};
384
385//===----------------------------------------------------------------------===//
386// Kinds of Templates
387//===----------------------------------------------------------------------===//
388
389/// \brief The base class of all kinds of template declarations (e.g.,
390/// class, function, etc.).
391///
392/// The TemplateDecl class stores the list of template parameters and a
393/// reference to the templated scoped declaration: the underlying AST node.
394class TemplateDecl : public NamedDecl {
395 void anchor() override;
396
397protected:
398 // Construct a template decl with name, parameters, and templated element.
401
402 // Construct a template decl with the given name and parameters.
403 // Used when there is no templated element (e.g., for tt-params).
405 TemplateParameterList *Params)
406 : TemplateDecl(DK, DC, L, Name, Params, nullptr) {}
407
408public:
409 friend class ASTDeclReader;
410 friend class ASTDeclWriter;
411
412 /// Get the list of template parameters
414 return TemplateParams;
415 }
416
417 /// \brief Get the total constraint-expression associated with this template,
418 /// including constraint-expressions derived from the requires-clause,
419 /// trailing requires-clause (for functions and methods) and constrained
420 /// template parameters.
422
423 bool hasAssociatedConstraints() const;
424
425 /// Get the underlying, templated declaration.
427
428 // Should a specialization behave like an alias for another type.
429 bool isTypeAlias() const;
430
431 // Implement isa/cast/dyncast/etc.
432 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
433
434 static bool classofKind(Kind K) {
435 return K >= firstTemplate && K <= lastTemplate;
436 }
437
438 SourceRange getSourceRange() const override LLVM_READONLY {
439 return SourceRange(getTemplateParameters()->getTemplateLoc(),
441 }
442
443protected:
446
447public:
449 TemplateParams = TParams;
450 }
451
452 /// Initialize the underlying templated declaration.
453 void init(NamedDecl *NewTemplatedDecl) {
454 if (TemplatedDecl)
455 assert(TemplatedDecl == NewTemplatedDecl && "Inconsistent TemplatedDecl");
456 else
457 TemplatedDecl = NewTemplatedDecl;
458 }
459};
460
461/// Provides information about a function template specialization,
462/// which is a FunctionDecl that has been explicitly specialization or
463/// instantiated from a function template.
465 : public llvm::FoldingSetNode,
466 private llvm::TrailingObjects<FunctionTemplateSpecializationInfo,
467 MemberSpecializationInfo *> {
468 /// The function template specialization that this structure describes and a
469 /// flag indicating if the function is a member specialization.
470 llvm::PointerIntPair<FunctionDecl *, 1, bool> Function;
471
472 /// The function template from which this function template
473 /// specialization was generated.
474 ///
475 /// The two bits contain the top 4 values of TemplateSpecializationKind.
476 llvm::PointerIntPair<FunctionTemplateDecl *, 2> Template;
477
478public:
479 /// The template arguments used to produce the function template
480 /// specialization from the function template.
482
483 /// The template arguments as written in the sources, if provided.
484 /// FIXME: Normally null; tail-allocate this.
486
487 /// The point at which this function template specialization was
488 /// first instantiated.
490
491private:
493 FunctionDecl *FD, FunctionTemplateDecl *Template,
494 TemplateSpecializationKind TSK, const TemplateArgumentList *TemplateArgs,
495 const ASTTemplateArgumentListInfo *TemplateArgsAsWritten,
497 : Function(FD, MSInfo ? true : false), Template(Template, TSK - 1),
498 TemplateArguments(TemplateArgs),
499 TemplateArgumentsAsWritten(TemplateArgsAsWritten),
501 if (MSInfo)
502 getTrailingObjects<MemberSpecializationInfo *>()[0] = MSInfo;
503 }
504
505 size_t numTrailingObjects(OverloadToken<MemberSpecializationInfo*>) const {
506 return Function.getInt();
507 }
508
509public:
511
515 const TemplateArgumentList *TemplateArgs,
516 const TemplateArgumentListInfo *TemplateArgsAsWritten,
518
519 /// Retrieve the declaration of the function template specialization.
520 FunctionDecl *getFunction() const { return Function.getPointer(); }
521
522 /// Retrieve the template from which this function was specialized.
523 FunctionTemplateDecl *getTemplate() const { return Template.getPointer(); }
524
525 /// Determine what kind of template specialization this is.
527 return (TemplateSpecializationKind)(Template.getInt() + 1);
528 }
529
532 }
533
534 /// True if this declaration is an explicit specialization,
535 /// explicit instantiation declaration, or explicit instantiation
536 /// definition.
540 }
541
542 /// Set the template specialization kind.
544 assert(TSK != TSK_Undeclared &&
545 "Cannot encode TSK_Undeclared for a function template specialization");
546 Template.setInt(TSK - 1);
547 }
548
549 /// Retrieve the first point of instantiation of this function
550 /// template specialization.
551 ///
552 /// The point of instantiation may be an invalid source location if this
553 /// function has yet to be instantiated.
556 }
557
558 /// Set the (first) point of instantiation of this function template
559 /// specialization.
562 }
563
564 /// Get the specialization info if this function template specialization is
565 /// also a member specialization:
566 ///
567 /// \code
568 /// template<typename> struct A {
569 /// template<typename> void f();
570 /// template<> void f<int>();
571 /// };
572 /// \endcode
573 ///
574 /// Here, A<int>::f<int> is a function template specialization that is
575 /// an explicit specialization of A<int>::f, but it's also a member
576 /// specialization (an implicit instantiation in this case) of A::f<int>.
577 /// Further:
578 ///
579 /// \code
580 /// template<> template<> void A<int>::f<int>() {}
581 /// \endcode
582 ///
583 /// ... declares a function template specialization that is an explicit
584 /// specialization of A<int>::f, and is also an explicit member
585 /// specialization of A::f<int>.
586 ///
587 /// Note that the TemplateSpecializationKind of the MemberSpecializationInfo
588 /// need not be the same as that returned by getTemplateSpecializationKind(),
589 /// and represents the relationship between the function and the class-scope
590 /// explicit specialization in the original templated class -- whereas our
591 /// TemplateSpecializationKind represents the relationship between the
592 /// function and the function template, and should always be
593 /// TSK_ExplicitSpecialization whenever we have MemberSpecializationInfo.
595 return numTrailingObjects(OverloadToken<MemberSpecializationInfo *>())
596 ? getTrailingObjects<MemberSpecializationInfo *>()[0]
597 : nullptr;
598 }
599
600 void Profile(llvm::FoldingSetNodeID &ID) {
601 Profile(ID, TemplateArguments->asArray(), getFunction()->getASTContext());
602 }
603
604 static void
605 Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
606 const ASTContext &Context) {
607 ID.AddInteger(TemplateArgs.size());
608 for (const TemplateArgument &TemplateArg : TemplateArgs)
609 TemplateArg.Profile(ID, Context);
610 }
611};
612
613/// Provides information a specialization of a member of a class
614/// template, which may be a member function, static data member,
615/// member class or member enumeration.
617 // The member declaration from which this member was instantiated, and the
618 // manner in which the instantiation occurred (in the lower two bits).
619 llvm::PointerIntPair<NamedDecl *, 2> MemberAndTSK;
620
621 // The point at which this member was first instantiated.
622 SourceLocation PointOfInstantiation;
623
624public:
625 explicit
628 : MemberAndTSK(IF, TSK - 1), PointOfInstantiation(POI) {
629 assert(TSK != TSK_Undeclared &&
630 "Cannot encode undeclared template specializations for members");
631 }
632
633 /// Retrieve the member declaration from which this member was
634 /// instantiated.
635 NamedDecl *getInstantiatedFrom() const { return MemberAndTSK.getPointer(); }
636
637 /// Determine what kind of template specialization this is.
639 return (TemplateSpecializationKind)(MemberAndTSK.getInt() + 1);
640 }
641
644 }
645
646 /// Set the template specialization kind.
648 assert(TSK != TSK_Undeclared &&
649 "Cannot encode undeclared template specializations for members");
650 MemberAndTSK.setInt(TSK - 1);
651 }
652
653 /// Retrieve the first point of instantiation of this member.
654 /// If the point of instantiation is an invalid location, then this member
655 /// has not yet been instantiated.
657 return PointOfInstantiation;
658 }
659
660 /// Set the first point of instantiation.
662 PointOfInstantiation = POI;
663 }
664};
665
666/// Provides information about a dependent function-template
667/// specialization declaration.
668///
669/// This is used for function templates explicit specializations declared
670/// within class templates:
671///
672/// \code
673/// template<typename> struct A {
674/// template<typename> void f();
675/// template<> void f<int>(); // DependentFunctionTemplateSpecializationInfo
676/// };
677/// \endcode
678///
679/// As well as dependent friend declarations naming function template
680/// specializations declared within class templates:
681///
682/// \code
683/// template <class T> void foo(T);
684/// template <class T> class A {
685/// friend void foo<>(T); // DependentFunctionTemplateSpecializationInfo
686/// };
687/// \endcode
689 : private llvm::TrailingObjects<DependentFunctionTemplateSpecializationInfo,
690 FunctionTemplateDecl *> {
691 friend TrailingObjects;
692
693 /// The number of candidates for the primary template.
694 unsigned NumCandidates;
695
697 const UnresolvedSetImpl &Candidates,
698 const ASTTemplateArgumentListInfo *TemplateArgsWritten);
699
700public:
701 /// The template arguments as written in the sources, if provided.
703
705 Create(ASTContext &Context, const UnresolvedSetImpl &Candidates,
706 const TemplateArgumentListInfo *TemplateArgs);
707
708 /// Returns the candidates for the primary function template.
710 return {getTrailingObjects<FunctionTemplateDecl *>(), NumCandidates};
711 }
712};
713
714/// Declaration of a redeclarable template.
716 public Redeclarable<RedeclarableTemplateDecl>
717{
719
720 RedeclarableTemplateDecl *getNextRedeclarationImpl() override {
721 return getNextRedeclaration();
722 }
723
724 RedeclarableTemplateDecl *getPreviousDeclImpl() override {
725 return getPreviousDecl();
726 }
727
728 RedeclarableTemplateDecl *getMostRecentDeclImpl() override {
729 return getMostRecentDecl();
730 }
731
732 void anchor() override;
733protected:
734 template <typename EntryType> struct SpecEntryTraits {
735 using DeclType = EntryType;
736
737 static DeclType *getDecl(EntryType *D) {
738 return D;
739 }
740
742 return D->getTemplateArgs().asArray();
743 }
744 };
745
746 template <typename EntryType, typename SETraits = SpecEntryTraits<EntryType>,
747 typename DeclType = typename SETraits::DeclType>
749 : llvm::iterator_adaptor_base<
750 SpecIterator<EntryType, SETraits, DeclType>,
751 typename llvm::FoldingSetVector<EntryType>::iterator,
752 typename std::iterator_traits<typename llvm::FoldingSetVector<
753 EntryType>::iterator>::iterator_category,
754 DeclType *, ptrdiff_t, DeclType *, DeclType *> {
755 SpecIterator() = default;
756 explicit SpecIterator(
757 typename llvm::FoldingSetVector<EntryType>::iterator SetIter)
758 : SpecIterator::iterator_adaptor_base(std::move(SetIter)) {}
759
760 DeclType *operator*() const {
761 return SETraits::getDecl(&*this->I)->getMostRecentDecl();
762 }
763
764 DeclType *operator->() const { return **this; }
765 };
766
767 template <typename EntryType>
768 static SpecIterator<EntryType>
769 makeSpecIterator(llvm::FoldingSetVector<EntryType> &Specs, bool isEnd) {
770 return SpecIterator<EntryType>(isEnd ? Specs.end() : Specs.begin());
771 }
772
773 void loadLazySpecializationsImpl() const;
774
775 template <class EntryType, typename ...ProfileArguments>
777 findSpecializationImpl(llvm::FoldingSetVector<EntryType> &Specs,
778 void *&InsertPos, ProfileArguments &&...ProfileArgs);
779
780 template <class Derived, class EntryType>
781 void addSpecializationImpl(llvm::FoldingSetVector<EntryType> &Specs,
782 EntryType *Entry, void *InsertPos);
783
784 struct CommonBase {
786
787 /// The template from which this was most
788 /// directly instantiated (or null).
789 ///
790 /// The boolean value indicates whether this template
791 /// was explicitly specialized.
792 llvm::PointerIntPair<RedeclarableTemplateDecl*, 1, bool>
794
795 /// If non-null, points to an array of specializations (including
796 /// partial specializations) known only by their external declaration IDs.
797 ///
798 /// The first value in the array is the number of specializations/partial
799 /// specializations that follow.
801
802 /// The set of "injected" template arguments used within this
803 /// template.
804 ///
805 /// This pointer refers to the template arguments (there are as
806 /// many template arguments as template parameters) for the
807 /// template, and is allocated lazily, since most templates do not
808 /// require the use of this information.
810 };
811
812 /// Pointer to the common data shared by all declarations of this
813 /// template.
814 mutable CommonBase *Common = nullptr;
815
816 /// Retrieves the "common" pointer shared by all (re-)declarations of
817 /// the same template. Calling this routine may implicitly allocate memory
818 /// for the common pointer.
819 CommonBase *getCommonPtr() const;
820
821 virtual CommonBase *newCommon(ASTContext &C) const = 0;
822
823 // Construct a template decl with name, parameters, and templated element.
827 : TemplateDecl(DK, DC, L, Name, Params, Decl), redeclarable_base(C) {}
828
829public:
830 friend class ASTDeclReader;
831 friend class ASTDeclWriter;
832 friend class ASTReader;
833 template <class decl_type> friend class RedeclarableTemplate;
834
835 /// Retrieves the canonical declaration of this template.
837 return getFirstDecl();
838 }
840 return getFirstDecl();
841 }
842
843 /// Determines whether this template was a specialization of a
844 /// member template.
845 ///
846 /// In the following example, the function template \c X<int>::f and the
847 /// member template \c X<int>::Inner are member specializations.
848 ///
849 /// \code
850 /// template<typename T>
851 /// struct X {
852 /// template<typename U> void f(T, U);
853 /// template<typename U> struct Inner;
854 /// };
855 ///
856 /// template<> template<typename T>
857 /// void X<int>::f(int, T);
858 /// template<> template<typename T>
859 /// struct X<int>::Inner { /* ... */ };
860 /// \endcode
862 return getCommonPtr()->InstantiatedFromMember.getInt();
863 }
864
865 /// Note that this member template is a specialization.
867 assert(getCommonPtr()->InstantiatedFromMember.getPointer() &&
868 "Only member templates can be member template specializations");
869 getCommonPtr()->InstantiatedFromMember.setInt(true);
870 }
871
872 /// Retrieve the member template from which this template was
873 /// instantiated, or nullptr if this template was not instantiated from a
874 /// member template.
875 ///
876 /// A template is instantiated from a member template when the member
877 /// template itself is part of a class template (or member thereof). For
878 /// example, given
879 ///
880 /// \code
881 /// template<typename T>
882 /// struct X {
883 /// template<typename U> void f(T, U);
884 /// };
885 ///
886 /// void test(X<int> x) {
887 /// x.f(1, 'a');
888 /// };
889 /// \endcode
890 ///
891 /// \c X<int>::f is a FunctionTemplateDecl that describes the function
892 /// template
893 ///
894 /// \code
895 /// template<typename U> void X<int>::f(int, U);
896 /// \endcode
897 ///
898 /// which was itself created during the instantiation of \c X<int>. Calling
899 /// getInstantiatedFromMemberTemplate() on this FunctionTemplateDecl will
900 /// retrieve the FunctionTemplateDecl for the original template \c f within
901 /// the class template \c X<T>, i.e.,
902 ///
903 /// \code
904 /// template<typename T>
905 /// template<typename U>
906 /// void X<T>::f(T, U);
907 /// \endcode
909 return getCommonPtr()->InstantiatedFromMember.getPointer();
910 }
911
913 assert(!getCommonPtr()->InstantiatedFromMember.getPointer());
914 getCommonPtr()->InstantiatedFromMember.setPointer(TD);
915 }
916
917 /// Retrieve the "injected" template arguments that correspond to the
918 /// template parameters of this template.
919 ///
920 /// Although the C++ standard has no notion of the "injected" template
921 /// arguments for a template, the notion is convenient when
922 /// we need to perform substitutions inside the definition of a template.
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 return DefaultArgument.get()->getType();
1231 }
1232
1233 /// Retrieves the default argument's source information, if any.
1235 return DefaultArgument.get();
1236 }
1237
1238 /// Retrieves the location of the default argument declaration.
1240
1241 /// Determines whether the default argument was inherited
1242 /// from a previous declaration of this template.
1244 return DefaultArgument.isInherited();
1245 }
1246
1247 /// Set the default argument for this template parameter.
1249 DefaultArgument.set(DefArg);
1250 }
1251
1252 /// Set that this default argument was inherited from another
1253 /// parameter.
1255 TemplateTypeParmDecl *Prev) {
1256 DefaultArgument.setInherited(C, Prev);
1257 }
1258
1259 /// Removes the default argument of this template parameter.
1261 DefaultArgument.clear();
1262 }
1263
1264 /// Set whether this template type parameter was declared with
1265 /// the 'typename' or 'class' keyword.
1266 void setDeclaredWithTypename(bool withTypename) { Typename = withTypename; }
1267
1268 /// Retrieve the depth of the template parameter.
1269 unsigned getDepth() const;
1270
1271 /// Retrieve the index of the template parameter.
1272 unsigned getIndex() const;
1273
1274 /// Returns whether this is a parameter pack.
1275 bool isParameterPack() const;
1276
1277 /// Whether this parameter pack is a pack expansion.
1278 ///
1279 /// A template type template parameter pack can be a pack expansion if its
1280 /// type-constraint contains an unexpanded parameter pack.
1281 bool isPackExpansion() const {
1282 if (!isParameterPack())
1283 return false;
1284 if (const TypeConstraint *TC = getTypeConstraint())
1285 if (TC->hasExplicitTemplateArgs())
1286 for (const auto &ArgLoc : TC->getTemplateArgsAsWritten()->arguments())
1287 if (ArgLoc.getArgument().containsUnexpandedParameterPack())
1288 return true;
1289 return false;
1290 }
1291
1292 /// Whether this parameter is a template type parameter pack that has a known
1293 /// list of different type-constraints at different positions.
1294 ///
1295 /// A parameter pack is an expanded parameter pack when the original
1296 /// parameter pack's type-constraint was itself a pack expansion, and that
1297 /// expansion has already been expanded. For example, given:
1298 ///
1299 /// \code
1300 /// template<typename ...Types>
1301 /// struct X {
1302 /// template<convertible_to<Types> ...Convertibles>
1303 /// struct Y { /* ... */ };
1304 /// };
1305 /// \endcode
1306 ///
1307 /// The parameter pack \c Convertibles has (convertible_to<Types> && ...) as
1308 /// its type-constraint. When \c Types is supplied with template arguments by
1309 /// instantiating \c X, the instantiation of \c Convertibles becomes an
1310 /// expanded parameter pack. For example, instantiating
1311 /// \c X<int, unsigned int> results in \c Convertibles being an expanded
1312 /// parameter pack of size 2 (use getNumExpansionTypes() to get this number).
1313 bool isExpandedParameterPack() const { return ExpandedParameterPack; }
1314
1315 /// Retrieves the number of parameters in an expanded parameter pack.
1316 unsigned getNumExpansionParameters() const {
1317 assert(ExpandedParameterPack && "Not an expansion parameter pack");
1318 return NumExpanded;
1319 }
1320
1321 /// Returns the type constraint associated with this template parameter (if
1322 /// any).
1324 return TypeConstraintInitialized ? getTrailingObjects<TypeConstraint>() :
1325 nullptr;
1326 }
1327
1329 Expr *ImmediatelyDeclaredConstraint);
1330
1331 /// Determine whether this template parameter has a type-constraint.
1332 bool hasTypeConstraint() const {
1333 return HasTypeConstraint;
1334 }
1335
1336 /// \brief Get the associated-constraints of this template parameter.
1337 /// This will either be the immediately-introduced constraint or empty.
1338 ///
1339 /// Use this instead of getTypeConstraint for concepts APIs that
1340 /// accept an ArrayRef of constraint expressions.
1342 if (HasTypeConstraint)
1343 AC.push_back(getTypeConstraint()->getImmediatelyDeclaredConstraint());
1344 }
1345
1346 SourceRange getSourceRange() const override LLVM_READONLY;
1347
1348 // Implement isa/cast/dyncast/etc.
1349 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1350 static bool classofKind(Kind K) { return K == TemplateTypeParm; }
1351};
1352
1353/// NonTypeTemplateParmDecl - Declares a non-type template parameter,
1354/// e.g., "Size" in
1355/// @code
1356/// template<int Size> class array { };
1357/// @endcode
1359 : public DeclaratorDecl,
1360 protected TemplateParmPosition,
1361 private llvm::TrailingObjects<NonTypeTemplateParmDecl,
1362 std::pair<QualType, TypeSourceInfo *>,
1363 Expr *> {
1364 friend class ASTDeclReader;
1365 friend TrailingObjects;
1366
1367 /// The default template argument, if any, and whether or not
1368 /// it was inherited.
1370 DefArgStorage DefaultArgument;
1371
1372 // FIXME: Collapse this into TemplateParamPosition; or, just move depth/index
1373 // down here to save memory.
1374
1375 /// Whether this non-type template parameter is a parameter pack.
1376 bool ParameterPack;
1377
1378 /// Whether this non-type template parameter is an "expanded"
1379 /// parameter pack, meaning that its type is a pack expansion and we
1380 /// already know the set of types that expansion expands to.
1381 bool ExpandedParameterPack = false;
1382
1383 /// The number of types in an expanded parameter pack.
1384 unsigned NumExpandedTypes = 0;
1385
1386 size_t numTrailingObjects(
1387 OverloadToken<std::pair<QualType, TypeSourceInfo *>>) const {
1388 return NumExpandedTypes;
1389 }
1390
1392 SourceLocation IdLoc, unsigned D, unsigned P,
1393 const IdentifierInfo *Id, QualType T,
1394 bool ParameterPack, TypeSourceInfo *TInfo)
1395 : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc),
1396 TemplateParmPosition(D, P), ParameterPack(ParameterPack) {}
1397
1398 NonTypeTemplateParmDecl(DeclContext *DC, SourceLocation StartLoc,
1399 SourceLocation IdLoc, unsigned D, unsigned P,
1400 const IdentifierInfo *Id, QualType T,
1401 TypeSourceInfo *TInfo,
1402 ArrayRef<QualType> ExpandedTypes,
1403 ArrayRef<TypeSourceInfo *> ExpandedTInfos);
1404
1405public:
1406 static NonTypeTemplateParmDecl *
1407 Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1408 SourceLocation IdLoc, unsigned D, unsigned P, const IdentifierInfo *Id,
1409 QualType T, bool ParameterPack, TypeSourceInfo *TInfo);
1410
1411 static NonTypeTemplateParmDecl *
1412 Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1413 SourceLocation IdLoc, unsigned D, unsigned P, const IdentifierInfo *Id,
1414 QualType T, TypeSourceInfo *TInfo, ArrayRef<QualType> ExpandedTypes,
1415 ArrayRef<TypeSourceInfo *> ExpandedTInfos);
1416
1417 static NonTypeTemplateParmDecl *
1418 CreateDeserialized(ASTContext &C, GlobalDeclID ID, bool HasTypeConstraint);
1419 static NonTypeTemplateParmDecl *CreateDeserialized(ASTContext &C,
1420 GlobalDeclID ID,
1421 unsigned NumExpandedTypes,
1422 bool HasTypeConstraint);
1423
1429
1430 SourceRange getSourceRange() const override LLVM_READONLY;
1431
1432 const DefArgStorage &getDefaultArgStorage() const { return DefaultArgument; }
1433
1434 /// Determine whether this template parameter has a default
1435 /// argument.
1436 bool hasDefaultArgument() const { return DefaultArgument.isSet(); }
1437
1438 /// Retrieve the default argument, if any.
1439 Expr *getDefaultArgument() const { return DefaultArgument.get(); }
1440
1441 /// Retrieve the location of the default argument, if any.
1443
1444 /// Determines whether the default argument was inherited
1445 /// from a previous declaration of this template.
1447 return DefaultArgument.isInherited();
1448 }
1449
1450 /// Set the default argument for this template parameter, and
1451 /// whether that default argument was inherited from another
1452 /// declaration.
1453 void setDefaultArgument(Expr *DefArg) { DefaultArgument.set(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 SpecializedTemplate.get<ClassTemplateDecl*>();
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(!SpecializedTemplate.is<SpecializedPartialSpecialization*>() &&
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(!SpecializedTemplate.is<SpecializedPartialSpecialization*>() &&
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 ExplicitInfo.get<const ASTTemplateArgumentListInfo *>();
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 /// \brief All associated constraints of this partial specialization,
2125 /// including the requires clause and any constraints derived from
2126 /// constrained-parameters.
2127 ///
2128 /// The constraints in the resulting list are to be treated as if in a
2129 /// conjunction ("and").
2131 TemplateParams->getAssociatedConstraints(AC);
2132 }
2133
2135 return TemplateParams->hasAssociatedConstraints();
2136 }
2137
2138 /// Retrieve the member class template partial specialization from
2139 /// which this particular class template partial specialization was
2140 /// instantiated.
2141 ///
2142 /// \code
2143 /// template<typename T>
2144 /// struct Outer {
2145 /// template<typename U> struct Inner;
2146 /// template<typename U> struct Inner<U*> { }; // #1
2147 /// };
2148 ///
2149 /// Outer<float>::Inner<int*> ii;
2150 /// \endcode
2151 ///
2152 /// In this example, the instantiation of \c Outer<float>::Inner<int*> will
2153 /// end up instantiating the partial specialization
2154 /// \c Outer<float>::Inner<U*>, which itself was instantiated from the class
2155 /// template partial specialization \c Outer<T>::Inner<U*>. Given
2156 /// \c Outer<float>::Inner<U*>, this function would return
2157 /// \c Outer<T>::Inner<U*>.
2159 const auto *First =
2160 cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2161 return First->InstantiatedFromMember.getPointer();
2162 }
2166 }
2167
2170 auto *First = cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2171 First->InstantiatedFromMember.setPointer(PartialSpec);
2172 }
2173
2174 /// Determines whether this class template partial specialization
2175 /// template was a specialization of a member partial specialization.
2176 ///
2177 /// In the following example, the member template partial specialization
2178 /// \c X<int>::Inner<T*> is a member specialization.
2179 ///
2180 /// \code
2181 /// template<typename T>
2182 /// struct X {
2183 /// template<typename U> struct Inner;
2184 /// template<typename U> struct Inner<U*>;
2185 /// };
2186 ///
2187 /// template<> template<typename T>
2188 /// struct X<int>::Inner<T*> { /* ... */ };
2189 /// \endcode
2191 const auto *First =
2192 cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2193 return First->InstantiatedFromMember.getInt();
2194 }
2195
2196 /// Note that this member template is a specialization.
2198 auto *First = cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2199 assert(First->InstantiatedFromMember.getPointer() &&
2200 "Only member templates can be member template specializations");
2201 return First->InstantiatedFromMember.setInt(true);
2202 }
2203
2204 /// Retrieves the injected specialization type for this partial
2205 /// specialization. This is not the same as the type-decl-type for
2206 /// this partial specialization, which is an InjectedClassNameType.
2208 assert(getTypeForDecl() && "partial specialization has no type set!");
2209 return cast<InjectedClassNameType>(getTypeForDecl())
2210 ->getInjectedSpecializationType();
2211 }
2212
2213 SourceRange getSourceRange() const override LLVM_READONLY;
2214
2215 void Profile(llvm::FoldingSetNodeID &ID) const {
2217 getASTContext());
2218 }
2219
2220 static void
2221 Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
2222 TemplateParameterList *TPL, const ASTContext &Context);
2223
2224 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2225
2226 static bool classofKind(Kind K) {
2227 return K == ClassTemplatePartialSpecialization;
2228 }
2229};
2230
2231/// Declaration of a class template.
2233protected:
2234 /// Data that is common to all of the declarations of a given
2235 /// class template.
2237 /// The class template specializations for this class
2238 /// template, including explicit specializations and instantiations.
2239 llvm::FoldingSetVector<ClassTemplateSpecializationDecl> Specializations;
2240
2241 /// The class template partial specializations for this class
2242 /// template.
2243 llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>
2245
2246 /// The injected-class-name type for this class template.
2248
2249 Common() = default;
2250 };
2251
2252 /// Retrieve the set of specializations of this class template.
2253 llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
2254 getSpecializations() const;
2255
2256 /// Retrieve the set of partial specializations of this class
2257 /// template.
2258 llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
2260
2263 NamedDecl *Decl)
2264 : RedeclarableTemplateDecl(ClassTemplate, C, DC, L, Name, Params, Decl) {}
2265
2266 CommonBase *newCommon(ASTContext &C) const override;
2267
2269 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
2270 }
2271
2274 }
2275
2276public:
2277
2278 friend class ASTDeclReader;
2279 friend class ASTDeclWriter;
2281
2282 /// Load any lazily-loaded specializations from the external source.
2283 void LoadLazySpecializations() const;
2284
2285 /// Get the underlying class declarations of the template.
2287 return static_cast<CXXRecordDecl *>(TemplatedDecl);
2288 }
2289
2290 /// Returns whether this template declaration defines the primary
2291 /// class pattern.
2294 }
2295
2296 /// \brief Create a class template node.
2299 DeclarationName Name,
2300 TemplateParameterList *Params,
2301 NamedDecl *Decl);
2302
2303 /// Create an empty class template node.
2305
2306 /// Return the specialization with the provided arguments if it exists,
2307 /// otherwise return the insertion point.
2309 findSpecialization(ArrayRef<TemplateArgument> Args, void *&InsertPos);
2310
2311 /// Insert the specified specialization knowing that it is not already
2312 /// in. InsertPos must be obtained from findSpecialization.
2313 void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos);
2314
2316 return cast<ClassTemplateDecl>(
2318 }
2320 return cast<ClassTemplateDecl>(
2322 }
2323
2324 /// Retrieve the previous declaration of this class template, or
2325 /// nullptr if no such declaration exists.
2327 return cast_or_null<ClassTemplateDecl>(
2328 static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
2329 }
2331 return cast_or_null<ClassTemplateDecl>(
2332 static_cast<const RedeclarableTemplateDecl *>(
2333 this)->getPreviousDecl());
2334 }
2335
2337 return cast<ClassTemplateDecl>(
2338 static_cast<RedeclarableTemplateDecl *>(this)->getMostRecentDecl());
2339 }
2341 return const_cast<ClassTemplateDecl*>(this)->getMostRecentDecl();
2342 }
2343
2345 return cast_or_null<ClassTemplateDecl>(
2347 }
2348
2349 /// Return the partial specialization with the provided arguments if it
2350 /// exists, otherwise return the insertion point.
2353 TemplateParameterList *TPL, void *&InsertPos);
2354
2355 /// Insert the specified partial specialization knowing that it is not
2356 /// already in. InsertPos must be obtained from findPartialSpecialization.
2358 void *InsertPos);
2359
2360 /// Retrieve the partial specializations as an ordered list.
2363
2364 /// Find a class template partial specialization with the given
2365 /// type T.
2366 ///
2367 /// \param T a dependent type that names a specialization of this class
2368 /// template.
2369 ///
2370 /// \returns the class template partial specialization that exactly matches
2371 /// the type \p T, or nullptr if no such partial specialization exists.
2373
2374 /// Find a class template partial specialization which was instantiated
2375 /// from the given member partial specialization.
2376 ///
2377 /// \param D a member class template partial specialization.
2378 ///
2379 /// \returns the class template partial specialization which was instantiated
2380 /// from the given member partial specialization, or nullptr if no such
2381 /// partial specialization exists.
2385
2386 /// Retrieve the template specialization type of the
2387 /// injected-class-name for this class template.
2388 ///
2389 /// The injected-class-name for a class template \c X is \c
2390 /// X<template-args>, where \c template-args is formed from the
2391 /// template arguments that correspond to the template parameters of
2392 /// \c X. For example:
2393 ///
2394 /// \code
2395 /// template<typename T, int N>
2396 /// struct array {
2397 /// typedef array this_type; // "array" is equivalent to "array<T, N>"
2398 /// };
2399 /// \endcode
2401
2403 using spec_range = llvm::iterator_range<spec_iterator>;
2404
2406 return spec_range(spec_begin(), spec_end());
2407 }
2408
2410 return makeSpecIterator(getSpecializations(), false);
2411 }
2412
2414 return makeSpecIterator(getSpecializations(), true);
2415 }
2416
2417 // Implement isa/cast/dyncast support
2418 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2419 static bool classofKind(Kind K) { return K == ClassTemplate; }
2420};
2421
2422/// Declaration of a friend template.
2423///
2424/// For example:
2425/// \code
2426/// template <typename T> class A {
2427/// friend class MyVector<T>; // not a friend template
2428/// template <typename U> friend class B; // not a friend template
2429/// template <typename U> friend class Foo<T>::Nested; // friend template
2430/// };
2431/// \endcode
2432///
2433/// \note This class is not currently in use. All of the above
2434/// will yield a FriendDecl, not a FriendTemplateDecl.
2435class FriendTemplateDecl : public Decl {
2436 virtual void anchor();
2437
2438public:
2439 using FriendUnion = llvm::PointerUnion<NamedDecl *,TypeSourceInfo *>;
2440
2441private:
2442 // The number of template parameters; always non-zero.
2443 unsigned NumParams = 0;
2444
2445 // The parameter list.
2446 TemplateParameterList **Params = nullptr;
2447
2448 // The declaration that's a friend of this class.
2449 FriendUnion Friend;
2450
2451 // Location of the 'friend' specifier.
2452 SourceLocation FriendLoc;
2453
2455 TemplateParameterList **Params, unsigned NumParams,
2456 FriendUnion Friend, SourceLocation FriendLoc)
2457 : Decl(Decl::FriendTemplate, DC, Loc), NumParams(NumParams),
2458 Params(Params), Friend(Friend), FriendLoc(FriendLoc) {}
2459
2460 FriendTemplateDecl(EmptyShell Empty) : Decl(Decl::FriendTemplate, Empty) {}
2461
2462public:
2463 friend class ASTDeclReader;
2464
2465 static FriendTemplateDecl *
2468 SourceLocation FriendLoc);
2469
2471
2472 /// If this friend declaration names a templated type (or
2473 /// a dependent member type of a templated type), return that
2474 /// type; otherwise return null.
2476 return Friend.dyn_cast<TypeSourceInfo*>();
2477 }
2478
2479 /// If this friend declaration names a templated function (or
2480 /// a member function of a templated type), return that type;
2481 /// otherwise return null.
2483 return Friend.dyn_cast<NamedDecl*>();
2484 }
2485
2486 /// Retrieves the location of the 'friend' keyword.
2488 return FriendLoc;
2489 }
2490
2492 assert(i <= NumParams);
2493 return Params[i];
2494 }
2495
2496 unsigned getNumTemplateParameters() const {
2497 return NumParams;
2498 }
2499
2500 // Implement isa/cast/dyncast/etc.
2501 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2502 static bool classofKind(Kind K) { return K == Decl::FriendTemplate; }
2503};
2504
2505/// Declaration of an alias template.
2506///
2507/// For example:
2508/// \code
2509/// template <typename T> using V = std::map<T*, int, MyCompare<T>>;
2510/// \endcode
2512protected:
2514
2517 NamedDecl *Decl)
2518 : RedeclarableTemplateDecl(TypeAliasTemplate, C, DC, L, Name, Params,
2519 Decl) {}
2520
2521 CommonBase *newCommon(ASTContext &C) const override;
2522
2524 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
2525 }
2526
2527public:
2528 friend class ASTDeclReader;
2529 friend class ASTDeclWriter;
2530
2531 /// Get the underlying function declaration of the template.
2533 return static_cast<TypeAliasDecl *>(TemplatedDecl);
2534 }
2535
2536
2538 return cast<TypeAliasTemplateDecl>(
2540 }
2542 return cast<TypeAliasTemplateDecl>(
2544 }
2545
2546 /// Retrieve the previous declaration of this function template, or
2547 /// nullptr if no such declaration exists.
2549 return cast_or_null<TypeAliasTemplateDecl>(
2550 static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
2551 }
2553 return cast_or_null<TypeAliasTemplateDecl>(
2554 static_cast<const RedeclarableTemplateDecl *>(
2555 this)->getPreviousDecl());
2556 }
2557
2559 return cast_or_null<TypeAliasTemplateDecl>(
2561 }
2562
2563 /// Create a function template node.
2566 DeclarationName Name,
2567 TemplateParameterList *Params,
2568 NamedDecl *Decl);
2569
2570 /// Create an empty alias template node.
2573
2574 // Implement isa/cast/dyncast support
2575 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2576 static bool classofKind(Kind K) { return K == TypeAliasTemplate; }
2577};
2578
2579/// Represents a variable template specialization, which refers to
2580/// a variable template with a given set of template arguments.
2581///
2582/// Variable template specializations represent both explicit
2583/// specializations of variable templates, as in the example below, and
2584/// implicit instantiations of variable templates.
2585///
2586/// \code
2587/// template<typename T> constexpr T pi = T(3.1415926535897932385);
2588///
2589/// template<>
2590/// constexpr float pi<float>; // variable template specialization pi<float>
2591/// \endcode
2593 public llvm::FoldingSetNode {
2594
2595 /// Structure that stores information about a variable template
2596 /// specialization that was instantiated from a variable template partial
2597 /// specialization.
2598 struct SpecializedPartialSpecialization {
2599 /// The variable template partial specialization from which this
2600 /// variable template specialization was instantiated.
2601 VarTemplatePartialSpecializationDecl *PartialSpecialization;
2602
2603 /// The template argument list deduced for the variable template
2604 /// partial specialization itself.
2605 const TemplateArgumentList *TemplateArgs;
2606 };
2607
2608 /// The template that this specialization specializes.
2609 llvm::PointerUnion<VarTemplateDecl *, SpecializedPartialSpecialization *>
2610 SpecializedTemplate;
2611
2612 /// Further info for explicit template specialization/instantiation.
2613 /// Does not apply to implicit specializations.
2614 SpecializationOrInstantiationInfo ExplicitInfo = nullptr;
2615
2616 /// The template arguments used to describe this specialization.
2617 const TemplateArgumentList *TemplateArgs;
2618
2619 /// The point where this template was instantiated (if any).
2620 SourceLocation PointOfInstantiation;
2621
2622 /// The kind of specialization this declaration refers to.
2623 LLVM_PREFERRED_TYPE(TemplateSpecializationKind)
2624 unsigned SpecializationKind : 3;
2625
2626 /// Whether this declaration is a complete definition of the
2627 /// variable template specialization. We can't otherwise tell apart
2628 /// an instantiated declaration from an instantiated definition with
2629 /// no initializer.
2630 LLVM_PREFERRED_TYPE(bool)
2631 unsigned IsCompleteDefinition : 1;
2632
2633protected:
2635 SourceLocation StartLoc, SourceLocation IdLoc,
2636 VarTemplateDecl *SpecializedTemplate,
2637 QualType T, TypeSourceInfo *TInfo,
2638 StorageClass S,
2640
2641 explicit VarTemplateSpecializationDecl(Kind DK, ASTContext &Context);
2642
2643public:
2644 friend class ASTDeclReader;
2645 friend class ASTDeclWriter;
2646 friend class VarDecl;
2647
2649 Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
2650 SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
2651 TypeSourceInfo *TInfo, StorageClass S,
2655
2656 void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy,
2657 bool Qualified) const override;
2658
2660 VarDecl *Recent = static_cast<VarDecl *>(this)->getMostRecentDecl();
2661 return cast<VarTemplateSpecializationDecl>(Recent);
2662 }
2663
2664 /// Retrieve the template that this specialization specializes.
2666
2667 /// Retrieve the template arguments of the variable template
2668 /// specialization.
2669 const TemplateArgumentList &getTemplateArgs() const { return *TemplateArgs; }
2670
2671 /// Determine the kind of specialization that this
2672 /// declaration represents.
2674 return static_cast<TemplateSpecializationKind>(SpecializationKind);
2675 }
2676
2679 }
2680
2682 return isExplicitSpecialization() &&
2683 isa<CXXRecordDecl>(getLexicalDeclContext());
2684 }
2685
2686 /// True if this declaration is an explicit specialization,
2687 /// explicit instantiation declaration, or explicit instantiation
2688 /// definition.
2692 }
2693
2695 SpecializationKind = TSK;
2696 }
2697
2698 /// Get the point of instantiation (if any), or null if none.
2700 return PointOfInstantiation;
2701 }
2702
2704 assert(Loc.isValid() && "point of instantiation must be valid!");
2705 PointOfInstantiation = Loc;
2706 }
2707
2708 void setCompleteDefinition() { IsCompleteDefinition = true; }
2709
2710 /// If this variable template specialization is an instantiation of
2711 /// a template (rather than an explicit specialization), return the
2712 /// variable template or variable template partial specialization from which
2713 /// it was instantiated.
2714 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
2717 return llvm::PointerUnion<VarTemplateDecl *,
2719
2721 }
2722
2723 /// Retrieve the variable template or variable template partial
2724 /// specialization which was specialized by this.
2725 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
2727 if (const auto *PartialSpec =
2728 SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
2729 return PartialSpec->PartialSpecialization;
2730
2731 return SpecializedTemplate.get<VarTemplateDecl *>();
2732 }
2733
2734 /// Retrieve the set of template arguments that should be used
2735 /// to instantiate the initializer of the variable template or variable
2736 /// template partial specialization from which this variable template
2737 /// specialization was instantiated.
2738 ///
2739 /// \returns For a variable template specialization instantiated from the
2740 /// primary template, this function will return the same template arguments
2741 /// as getTemplateArgs(). For a variable template specialization instantiated
2742 /// from a variable template partial specialization, this function will the
2743 /// return deduced template arguments for the variable template partial
2744 /// specialization itself.
2746 if (const auto *PartialSpec =
2747 SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
2748 return *PartialSpec->TemplateArgs;
2749
2750 return getTemplateArgs();
2751 }
2752
2753 /// Note that this variable template specialization is actually an
2754 /// instantiation of the given variable template partial specialization whose
2755 /// template arguments have been deduced.
2757 const TemplateArgumentList *TemplateArgs) {
2758 assert(!SpecializedTemplate.is<SpecializedPartialSpecialization *>() &&
2759 "Already set to a variable template partial specialization!");
2760 auto *PS = new (getASTContext()) SpecializedPartialSpecialization();
2761 PS->PartialSpecialization = PartialSpec;
2762 PS->TemplateArgs = TemplateArgs;
2763 SpecializedTemplate = PS;
2764 }
2765
2766 /// Note that this variable template specialization is an instantiation
2767 /// of the given variable template.
2769 assert(!SpecializedTemplate.is<SpecializedPartialSpecialization *>() &&
2770 "Previously set to a variable template partial specialization!");
2771 SpecializedTemplate = TemplDecl;
2772 }
2773
2774 /// Retrieve the template argument list as written in the sources,
2775 /// if any.
2777 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2778 return Info->TemplateArgsAsWritten;
2779 return ExplicitInfo.get<const ASTTemplateArgumentListInfo *>();
2780 }
2781
2782 /// Set the template argument list as written in the sources.
2783 void
2785 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2786 Info->TemplateArgsAsWritten = ArgsWritten;
2787 else
2788 ExplicitInfo = ArgsWritten;
2789 }
2790
2791 /// Set the template argument list as written in the sources.
2795 }
2796
2797 /// Gets the location of the extern keyword, if present.
2799 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2800 return Info->ExternKeywordLoc;
2801 return SourceLocation();
2802 }
2803
2804 /// Sets the location of the extern keyword.
2806
2807 /// Gets the location of the template keyword, if present.
2809 if (auto *Info = ExplicitInfo.dyn_cast<ExplicitInstantiationInfo *>())
2810 return Info->TemplateKeywordLoc;
2811 return SourceLocation();
2812 }
2813
2814 /// Sets the location of the template keyword.
2816
2817 SourceRange getSourceRange() const override LLVM_READONLY;
2818
2819 void Profile(llvm::FoldingSetNodeID &ID) const {
2820 Profile(ID, TemplateArgs->asArray(), getASTContext());
2821 }
2822
2823 static void Profile(llvm::FoldingSetNodeID &ID,
2824 ArrayRef<TemplateArgument> TemplateArgs,
2825 const ASTContext &Context) {
2826 ID.AddInteger(TemplateArgs.size());
2827 for (const TemplateArgument &TemplateArg : TemplateArgs)
2828 TemplateArg.Profile(ID, Context);
2829 }
2830
2831 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2832
2833 static bool classofKind(Kind K) {
2834 return K >= firstVarTemplateSpecialization &&
2835 K <= lastVarTemplateSpecialization;
2836 }
2837};
2838
2841 /// The list of template parameters
2842 TemplateParameterList *TemplateParams = nullptr;
2843
2844 /// The variable template partial specialization from which this
2845 /// variable template partial specialization was instantiated.
2846 ///
2847 /// The boolean value will be true to indicate that this variable template
2848 /// partial specialization was specialized at this level.
2849 llvm::PointerIntPair<VarTemplatePartialSpecializationDecl *, 1, bool>
2850 InstantiatedFromMember;
2851
2853 ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
2855 VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
2857
2859 : VarTemplateSpecializationDecl(VarTemplatePartialSpecialization,
2860 Context),
2861 InstantiatedFromMember(nullptr, false) {}
2862
2863 void anchor() override;
2864
2865public:
2866 friend class ASTDeclReader;
2867 friend class ASTDeclWriter;
2868
2870 Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
2872 VarTemplateDecl *SpecializedTemplate, QualType T,
2873 TypeSourceInfo *TInfo, StorageClass S,
2875
2878
2880 return cast<VarTemplatePartialSpecializationDecl>(
2881 static_cast<VarTemplateSpecializationDecl *>(
2882 this)->getMostRecentDecl());
2883 }
2884
2885 /// Get the list of template parameters
2887 return TemplateParams;
2888 }
2889
2890 /// \brief All associated constraints of this partial specialization,
2891 /// including the requires clause and any constraints derived from
2892 /// constrained-parameters.
2893 ///
2894 /// The constraints in the resulting list are to be treated as if in a
2895 /// conjunction ("and").
2897 TemplateParams->getAssociatedConstraints(AC);
2898 }
2899
2901 return TemplateParams->hasAssociatedConstraints();
2902 }
2903
2904 /// \brief Retrieve the member variable template partial specialization from
2905 /// which this particular variable template partial specialization was
2906 /// instantiated.
2907 ///
2908 /// \code
2909 /// template<typename T>
2910 /// struct Outer {
2911 /// template<typename U> U Inner;
2912 /// template<typename U> U* Inner<U*> = (U*)(0); // #1
2913 /// };
2914 ///
2915 /// template int* Outer<float>::Inner<int*>;
2916 /// \endcode
2917 ///
2918 /// In this example, the instantiation of \c Outer<float>::Inner<int*> will
2919 /// end up instantiating the partial specialization
2920 /// \c Outer<float>::Inner<U*>, which itself was instantiated from the
2921 /// variable template partial specialization \c Outer<T>::Inner<U*>. Given
2922 /// \c Outer<float>::Inner<U*>, this function would return
2923 /// \c Outer<T>::Inner<U*>.
2925 const auto *First =
2926 cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2927 return First->InstantiatedFromMember.getPointer();
2928 }
2929
2930 void
2932 auto *First = cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2933 First->InstantiatedFromMember.setPointer(PartialSpec);
2934 }
2935
2936 /// Determines whether this variable template partial specialization
2937 /// was a specialization of a member partial specialization.
2938 ///
2939 /// In the following example, the member template partial specialization
2940 /// \c X<int>::Inner<T*> is a member specialization.
2941 ///
2942 /// \code
2943 /// template<typename T>
2944 /// struct X {
2945 /// template<typename U> U Inner;
2946 /// template<typename U> U* Inner<U*> = (U*)(0);
2947 /// };
2948 ///
2949 /// template<> template<typename T>
2950 /// U* X<int>::Inner<T*> = (T*)(0) + 1;
2951 /// \endcode
2953 const auto *First =
2954 cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2955 return First->InstantiatedFromMember.getInt();
2956 }
2957
2958 /// Note that this member template is a specialization.
2960 auto *First = cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2961 assert(First->InstantiatedFromMember.getPointer() &&
2962 "Only member templates can be member template specializations");
2963 return First->InstantiatedFromMember.setInt(true);
2964 }
2965
2966 SourceRange getSourceRange() const override LLVM_READONLY;
2967
2968 void Profile(llvm::FoldingSetNodeID &ID) const {
2970 getASTContext());
2971 }
2972
2973 static void
2974 Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
2975 TemplateParameterList *TPL, const ASTContext &Context);
2976
2977 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2978
2979 static bool classofKind(Kind K) {
2980 return K == VarTemplatePartialSpecialization;
2981 }
2982};
2983
2984/// Declaration of a variable template.
2986protected:
2987 /// Data that is common to all of the declarations of a given
2988 /// variable template.
2990 /// The variable template specializations for this variable
2991 /// template, including explicit specializations and instantiations.
2992 llvm::FoldingSetVector<VarTemplateSpecializationDecl> Specializations;
2993
2994 /// The variable template partial specializations for this variable
2995 /// template.
2996 llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl>
2998
2999 Common() = default;
3000 };
3001
3002 /// Retrieve the set of specializations of this variable template.
3003 llvm::FoldingSetVector<VarTemplateSpecializationDecl> &
3004 getSpecializations() const;
3005
3006 /// Retrieve the set of partial specializations of this class
3007 /// template.
3008 llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &
3010
3013 NamedDecl *Decl)
3014 : RedeclarableTemplateDecl(VarTemplate, C, DC, L, Name, Params, Decl) {}
3015
3016 CommonBase *newCommon(ASTContext &C) const override;
3017
3019 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
3020 }
3021
3022public:
3023 friend class ASTDeclReader;
3024 friend class ASTDeclWriter;
3025
3026 /// Load any lazily-loaded specializations from the external source.
3027 void LoadLazySpecializations() const;
3028
3029 /// Get the underlying variable declarations of the template.
3031 return static_cast<VarDecl *>(TemplatedDecl);
3032 }
3033
3034 /// Returns whether this template declaration defines the primary
3035 /// variable pattern.
3038 }
3039
3041
3042 /// Create a variable template node.
3045 TemplateParameterList *Params,
3046 VarDecl *Decl);
3047
3048 /// Create an empty variable template node.
3050
3051 /// Return the specialization with the provided arguments if it exists,
3052 /// otherwise return the insertion point.
3054 findSpecialization(ArrayRef<TemplateArgument> Args, void *&InsertPos);
3055
3056 /// Insert the specified specialization knowing that it is not already
3057 /// in. InsertPos must be obtained from findSpecialization.
3058 void AddSpecialization(VarTemplateSpecializationDecl *D, void *InsertPos);
3059
3061 return cast<VarTemplateDecl>(RedeclarableTemplateDecl::getCanonicalDecl());
3062 }
3064 return cast<VarTemplateDecl>(RedeclarableTemplateDecl::getCanonicalDecl());
3065 }
3066
3067 /// Retrieve the previous declaration of this variable template, or
3068 /// nullptr if no such declaration exists.
3070 return cast_or_null<VarTemplateDecl>(
3071 static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
3072 }
3074 return cast_or_null<VarTemplateDecl>(
3075 static_cast<const RedeclarableTemplateDecl *>(
3076 this)->getPreviousDecl());
3077 }
3078
3080 return cast<VarTemplateDecl>(
3081 static_cast<RedeclarableTemplateDecl *>(this)->getMostRecentDecl());
3082 }
3084 return const_cast<VarTemplateDecl *>(this)->getMostRecentDecl();
3085 }
3086
3088 return cast_or_null<VarTemplateDecl>(
3090 }
3091
3092 /// Return the partial specialization with the provided arguments if it
3093 /// exists, otherwise return the insertion point.
3096 TemplateParameterList *TPL, void *&InsertPos);
3097
3098 /// Insert the specified partial specialization knowing that it is not
3099 /// already in. InsertPos must be obtained from findPartialSpecialization.
3101 void *InsertPos);
3102
3103 /// Retrieve the partial specializations as an ordered list.
3106
3107 /// Find a variable template partial specialization which was
3108 /// instantiated
3109 /// from the given member partial specialization.
3110 ///
3111 /// \param D a member variable template partial specialization.
3112 ///
3113 /// \returns the variable template partial specialization which was
3114 /// instantiated
3115 /// from the given member partial specialization, or nullptr if no such
3116 /// partial specialization exists.
3119
3121 using spec_range = llvm::iterator_range<spec_iterator>;
3122
3124 return spec_range(spec_begin(), spec_end());
3125 }
3126
3128 return makeSpecIterator(getSpecializations(), false);
3129 }
3130
3132 return makeSpecIterator(getSpecializations(), true);
3133 }
3134
3135 // Implement isa/cast/dyncast support
3136 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3137 static bool classofKind(Kind K) { return K == VarTemplate; }
3138};
3139
3140/// Declaration of a C++20 concept.
3141class ConceptDecl : public TemplateDecl, public Mergeable<ConceptDecl> {
3142protected:
3144
3147 : TemplateDecl(Concept, DC, L, Name, Params),
3149public:
3152 TemplateParameterList *Params,
3155
3157 return ConstraintExpr;
3158 }
3159
3160 SourceRange getSourceRange() const override LLVM_READONLY {
3161 return SourceRange(getTemplateParameters()->getTemplateLoc(),
3163 }
3164
3165 bool isTypeConcept() const {
3166 return isa<TemplateTypeParmDecl>(getTemplateParameters()->getParam(0));
3167 }
3168
3170 return cast<ConceptDecl>(getPrimaryMergedDecl(this));
3171 }
3173 return const_cast<ConceptDecl *>(this)->getCanonicalDecl();
3174 }
3175
3176 // Implement isa/cast/dyncast/etc.
3177 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3178 static bool classofKind(Kind K) { return K == Concept; }
3179
3180 friend class ASTReader;
3181 friend class ASTDeclReader;
3182 friend class ASTDeclWriter;
3183};
3184
3185// An implementation detail of ConceptSpecialicationExpr that holds the template
3186// arguments, so we can later use this to reconstitute the template arguments
3187// during constraint checking.
3189 : public Decl,
3190 private llvm::TrailingObjects<ImplicitConceptSpecializationDecl,
3191 TemplateArgument> {
3192 unsigned NumTemplateArgs;
3193
3195 ArrayRef<TemplateArgument> ConvertedArgs);
3196 ImplicitConceptSpecializationDecl(EmptyShell Empty, unsigned NumTemplateArgs);
3197
3198public:
3201 ArrayRef<TemplateArgument> ConvertedArgs);
3204 unsigned NumTemplateArgs);
3205
3207 return ArrayRef<TemplateArgument>(getTrailingObjects<TemplateArgument>(),
3208 NumTemplateArgs);
3209 }
3211
3212 static bool classofKind(Kind K) { return K == ImplicitConceptSpecialization; }
3213 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3214
3216 friend class ASTDeclReader;
3217};
3218
3219/// A template parameter object.
3220///
3221/// Template parameter objects represent values of class type used as template
3222/// arguments. There is one template parameter object for each such distinct
3223/// value used as a template argument across the program.
3224///
3225/// \code
3226/// struct A { int x, y; };
3227/// template<A> struct S;
3228/// S<A{1, 2}> s1;
3229/// S<A{1, 2}> s2; // same type, argument is same TemplateParamObjectDecl.
3230/// \endcode
3232 public Mergeable<TemplateParamObjectDecl>,
3233 public llvm::FoldingSetNode {
3234private:
3235 /// The value of this template parameter object.
3236 APValue Value;
3237
3239 : ValueDecl(TemplateParamObject, DC, SourceLocation(), DeclarationName(),
3240 T),
3241 Value(V) {}
3242
3244 const APValue &V);
3245 static TemplateParamObjectDecl *CreateDeserialized(ASTContext &C,
3247
3248 /// Only ASTContext::getTemplateParamObjectDecl and deserialization
3249 /// create these.
3250 friend class ASTContext;
3251 friend class ASTReader;
3252 friend class ASTDeclReader;
3253
3254public:
3255 /// Print this template parameter object in a human-readable format.
3256 void printName(llvm::raw_ostream &OS,
3257 const PrintingPolicy &Policy) const override;
3258
3259 /// Print this object as an equivalent expression.
3260 void printAsExpr(llvm::raw_ostream &OS) const;
3261 void printAsExpr(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const;
3262
3263 /// Print this object as an initializer suitable for a variable of the
3264 /// object's type.
3265 void printAsInit(llvm::raw_ostream &OS) const;
3266 void printAsInit(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const;
3267
3268 const APValue &getValue() const { return Value; }
3269
3270 static void Profile(llvm::FoldingSetNodeID &ID, QualType T,
3271 const APValue &V) {
3272 ID.AddPointer(T.getCanonicalType().getAsOpaquePtr());
3273 V.Profile(ID);
3274 }
3275 void Profile(llvm::FoldingSetNodeID &ID) {
3276 Profile(ID, getType(), getValue());
3277 }
3278
3280 return getFirstDecl();
3281 }
3283 return getFirstDecl();
3284 }
3285
3286 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3287 static bool classofKind(Kind K) { return K == TemplateParamObject; }
3288};
3289
3291 if (auto *PD = P.dyn_cast<TemplateTypeParmDecl *>())
3292 return PD;
3293 if (auto *PD = P.dyn_cast<NonTypeTemplateParmDecl *>())
3294 return PD;
3295 return P.get<TemplateTemplateParmDecl *>();
3296}
3297
3299 auto *TD = dyn_cast<TemplateDecl>(D);
3300 return TD && (isa<ClassTemplateDecl>(TD) ||
3301 isa<ClassTemplatePartialSpecializationDecl>(TD) ||
3302 isa<TypeAliasTemplateDecl>(TD) ||
3303 isa<TemplateTemplateParmDecl>(TD))
3304 ? TD
3305 : nullptr;
3306}
3307
3308/// Check whether the template parameter is a pack expansion, and if so,
3309/// determine the number of parameters produced by that expansion. For instance:
3310///
3311/// \code
3312/// template<typename ...Ts> struct A {
3313/// template<Ts ...NTs, template<Ts> class ...TTs, typename ...Us> struct B;
3314/// };
3315/// \endcode
3316///
3317/// In \c A<int,int>::B, \c NTs and \c TTs have expanded pack size 2, and \c Us
3318/// is not a pack expansion, so returns an empty Optional.
3319inline std::optional<unsigned> getExpandedPackSize(const NamedDecl *Param) {
3320 if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
3321 if (TTP->isExpandedParameterPack())
3322 return TTP->getNumExpansionParameters();
3323 }
3324
3325 if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
3326 if (NTTP->isExpandedParameterPack())
3327 return NTTP->getNumExpansionTypes();
3328 }
3329
3330 if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(Param)) {
3331 if (TTP->isExpandedParameterPack())
3332 return TTP->getNumExpansionTemplateParameters();
3333 }
3334
3335 return std::nullopt;
3336}
3337
3338/// Internal helper used by Subst* nodes to retrieve the parameter list
3339/// for their AssociatedDecl.
3340TemplateParameterList *getReplacedTemplateParameterList(Decl *D);
3341
3342} // namespace clang
3343
3344#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:3285
int Id
Definition: ASTDiff.cpp:190
StringRef P
static char ID
Definition: Arena.cpp:183
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.
SourceLocation Loc
Definition: SemaObjC.cpp:755
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:182
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:366
bool isConstrained() const
Definition: Type.h:6000
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:549
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
Definition: DeclCXX.cpp:1905
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.
void LoadLazySpecializations() const
Load any lazily-loaded specializations from the external source.
ClassTemplateDecl * getPreviousDecl()
Retrieve the previous declaration of this class template, or nullptr if no such declaration exists.
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.
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.
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.
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:128
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1436
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:501
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:599
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:89
SourceLocation getLocation() const
Definition: DeclBase.h:445
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition: DeclBase.h:908
Kind getKind() const
Definition: DeclBase.h:448
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
Definition: DeclBase.h:433
The name of a declaration.
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:770
Storage for a default argument.
Definition: DeclTemplate.h:299
void setInherited(const ASTContext &C, ParmDecl *InheritedFrom)
Set that the default argument was inherited from another parameter.
Definition: DeclTemplate.h:360
bool isSet() const
Determine whether there is a default argument for this parameter.
Definition: DeclTemplate.h:326
ArgType get() const
Get the default argument's value.
Definition: DeclTemplate.h:334
void set(ArgType Arg)
Set the default argument.
Definition: DeclTemplate.h:354
void clear()
Remove the default argument, even if it was inherited.
Definition: DeclTemplate.h:380
const ParmDecl * getInheritedFrom() const
Get the parameter from which we inherit the default argument, if any.
Definition: DeclTemplate.h:345
bool isInherited() const
Determine whether the default argument for this parameter was inherited from a previous declaration o...
Definition: DeclTemplate.h:330
Provides information about a dependent function-template specialization declaration.
Definition: DeclTemplate.h:690
ArrayRef< FunctionTemplateDecl * > getCandidates() const
Returns the candidates for the primary function template.
Definition: DeclTemplate.h:709
const ASTTemplateArgumentListInfo * TemplateArgumentsAsWritten
The template arguments as written in the sources, if provided.
Definition: DeclTemplate.h:702
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:222
FixedSizeTemplateParameterListStorage(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
Definition: DeclTemplate.h:229
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:1971
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
Definition: Decl.h:2284
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:467
const TemplateArgumentList * TemplateArguments
The template arguments used to produce the function template specialization from the function templat...
Definition: DeclTemplate.h:481
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the template specialization kind.
Definition: DeclTemplate.h:543
static void Profile(llvm::FoldingSetNodeID &ID, ArrayRef< TemplateArgument > TemplateArgs, const ASTContext &Context)
Definition: DeclTemplate.h:605
FunctionTemplateDecl * getTemplate() const
Retrieve the template from which this function was specialized.
Definition: DeclTemplate.h:523
MemberSpecializationInfo * getMemberSpecializationInfo() const
Get the specialization info if this function template specialization is also a member specialization:
Definition: DeclTemplate.h:594
const ASTTemplateArgumentListInfo * TemplateArgumentsAsWritten
The template arguments as written in the sources, if provided.
Definition: DeclTemplate.h:485
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this function template specialization.
Definition: DeclTemplate.h:554
void Profile(llvm::FoldingSetNodeID &ID)
Definition: DeclTemplate.h:600
SourceLocation PointOfInstantiation
The point at which this function template specialization was first instantiated.
Definition: DeclTemplate.h:489
FunctionDecl * getFunction() const
Retrieve the declaration of the function template specialization.
Definition: DeclTemplate.h:520
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
Definition: DeclTemplate.h:526
void setPointOfInstantiation(SourceLocation POI)
Set the (first) point of instantiation of this function template specialization.
Definition: DeclTemplate.h:560
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration,...
Definition: DeclTemplate.h:537
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:616
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the template specialization kind.
Definition: DeclTemplate.h:647
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
Definition: DeclTemplate.h:638
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
Definition: DeclTemplate.h:656
MemberSpecializationInfo(NamedDecl *IF, TemplateSpecializationKind TSK, SourceLocation POI=SourceLocation())
Definition: DeclTemplate.h:626
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
Definition: DeclTemplate.h:661
NamedDecl * getInstantiatedFrom() const
Retrieve the member declaration from which this member was instantiated.
Definition: DeclTemplate.h:635
Provides common interface for the Decls that cannot be redeclared, but can be merged if the same decl...
Definition: Redeclarable.h:314
TemplateParamObjectDecl * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Definition: Redeclarable.h:320
This represents a decl that may have a name.
Definition: Decl.h:249
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.
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.
Expr * getDefaultArgument() const
Retrieve the default argument, if any.
void getAssociatedConstraints(llvm::SmallVectorImpl< const Expr * > &AC) const
Get the associated-constraints of this template parameter.
void setDefaultArgument(Expr *DefArg)
Set the default argument for this template parameter, and whether that default argument was inherited...
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)
Represents a pack expansion of types.
Definition: Type.h:6569
A (possibly-)qualified type.
Definition: Type.h:940
Declaration of a redeclarable template.
Definition: DeclTemplate.h:717
static SpecIterator< EntryType > makeSpecIterator(llvm::FoldingSetVector< EntryType > &Specs, bool isEnd)
Definition: DeclTemplate.h:769
RedeclarableTemplateDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Definition: DeclTemplate.h:824
redeclarable_base::redecl_iterator redecl_iterator
Definition: DeclTemplate.h:926
bool isMemberSpecialization() const
Determines whether this template was a specialization of a member template.
Definition: DeclTemplate.h:861
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:839
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:814
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:908
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:836
void addSpecializationImpl(llvm::FoldingSetVector< EntryType > &Specs, EntryType *Entry, void *InsertPos)
void setMemberSpecialization()
Note that this member template is a specialization.
Definition: DeclTemplate.h:866
void setInstantiatedFromMemberTemplate(RedeclarableTemplateDecl *TD)
Definition: DeclTemplate.h:912
ArrayRef< TemplateArgument > getInjectedTemplateArgs()
Retrieve the "injected" template arguments that correspond to the template parameters of this templat...
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:216
RedeclarableTemplateDecl * getNextRedeclaration() const
Definition: Redeclarable.h:189
RedeclarableTemplateDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
Definition: Redeclarable.h:204
llvm::iterator_range< redecl_iterator > redecl_range
Definition: Redeclarable.h:292
RedeclarableTemplateDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
Definition: Redeclarable.h:226
bool isFirstDecl() const
True if this is the first declaration in its redeclaration chain.
Definition: Redeclarable.h:223
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: Redeclarable.h:296
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:449
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:350
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition: Decl.h:3683
A convenient class for passing around template argument information.
Definition: TemplateBase.h:632
A template argument list.
Definition: DeclTemplate.h:244
TemplateArgumentList(const TemplateArgumentList &)=delete
const TemplateArgument * data() const
Retrieve a pointer to the template argument list.
Definition: DeclTemplate.h:283
const TemplateArgument & operator[](unsigned Idx) const
Retrieve the template argument at a given index.
Definition: DeclTemplate.h:271
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:280
const TemplateArgument & get(unsigned Idx) const
Retrieve the template argument at a given index.
Definition: DeclTemplate.h:265
TemplateArgumentList & operator=(const TemplateArgumentList &)=delete
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Definition: DeclTemplate.h:274
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:394
NamedDecl * TemplatedDecl
Definition: DeclTemplate.h:444
TemplateParameterList * TemplateParams
Definition: DeclTemplate.h:445
bool isTypeAlias() const
bool hasAssociatedConstraints() const
void init(NamedDecl *NewTemplatedDecl)
Initialize the underlying templated declaration.
Definition: DeclTemplate.h:453
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
Definition: DeclTemplate.h:426
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclTemplate.h:438
TemplateDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params)
Definition: DeclTemplate.h:404
void setTemplateParameters(TemplateParameterList *TParams)
Definition: DeclTemplate.h:448
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:432
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:413
static bool classofKind(Kind K)
Definition: DeclTemplate.h:434
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:134
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:144
SourceRange getSourceRange() const LLVM_READONLY
Definition: DeclTemplate.h:203
const_iterator begin() const
Definition: DeclTemplate.h:132
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:185
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:107
bool hasParameterPack() const
Determine whether this template parameter list contains a parameter pack.
Definition: DeclTemplate.h:172
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:129
Expr * getRequiresClause()
The constraint-expression of the associated requires-clause.
Definition: DeclTemplate.h:180
void print(raw_ostream &Out, const ASTContext &Context, const PrintingPolicy &Policy, bool OmitTemplateKW=false) const
SourceLocation getRAngleLoc() const
Definition: DeclTemplate.h:201
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &C) const
const NamedDecl * getParam(unsigned Idx) const
Definition: DeclTemplate.h:148
bool containsUnexpandedParameterPack() const
Determine whether this template parameter list contains an unexpanded parameter pack.
SourceLocation getLAngleLoc() const
Definition: DeclTemplate.h:200
size_t numTrailingObjects(OverloadToken< NamedDecl * >) const
Definition: DeclTemplate.h:103
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:139
static bool shouldIncludeTypeForArgument(const PrintingPolicy &Policy, const TemplateParameterList *TPL, unsigned Idx)
SourceLocation getTemplateLoc() const
Definition: DeclTemplate.h:199
ArrayRef< const NamedDecl * > asArray() const
Definition: DeclTemplate.h:140
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.
QualType 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.
TypeSourceInfo * getDefaultArgumentInfo() const
Retrieves the default argument's source information, if any.
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.
void setDefaultArgument(TypeSourceInfo *DefArg)
Set the default argument for 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)
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:3556
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:231
Represents a declaration of a type.
Definition: Decl.h:3391
const Type * getTypeForDecl() const
Definition: Decl.h:3415
A container of type source information.
Definition: Type.h:7330
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:7341
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type.
Definition: Type.h:2758
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8126
A set of unresolved declarations.
Definition: UnresolvedSet.h:61
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:706
QualType getType() const
Definition: Decl.h:717
Represents a variable declaration or definition.
Definition: Decl.h:918
DefinitionKind isThisDeclarationADefinition(ASTContext &) const
Check whether this declaration is a definition.
Definition: Decl.cpp:2257
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:2756
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...
void LoadLazySpecializations() const
Load any lazily-loaded specializations from the external source.
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
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
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.
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
bool isTemplateInstantiation(TemplateSpecializationKind Kind)
Determine whether this template specialization kind refers to an instantiation of an entity (as oppos...
Definition: Specifiers.h:209
Decl * getPrimaryMergedDecl(Decl *D)
Get the primary declaration for a declaration from an AST file.
Definition: Decl.cpp:77
NamedDecl * getAsNamedDecl(TemplateParameter P)
StorageClass
Storage classes.
Definition: Specifiers.h:245
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:6299
BuiltinTemplateKind
Kinds of BuiltinTemplateDecl.
Definition: Builtins.h:302
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:185
@ TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp....
Definition: Specifiers.h:195
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...
Definition: Specifiers.h:188
@ 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:216
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
Definition: Format.h:5428
#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:793
GlobalDeclID * LazySpecializations
If non-null, points to an array of specializations (including partial specializations) known only by ...
Definition: DeclTemplate.h:800
TemplateArgument * InjectedArgs
The set of "injected" template arguments used within this template.
Definition: DeclTemplate.h:809
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:741
static DeclType * getDecl(EntryType *D)
Definition: DeclTemplate.h:737
SpecIterator(typename llvm::FoldingSetVector< EntryType >::iterator SetIter)
Definition: DeclTemplate.h:756
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 ...