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.
800 uint32_t *LazySpecializations = nullptr;
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.
1091
1092 // Implement isa/cast/dyncast support
1093 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1094 static bool classofKind(Kind K) { return K == FunctionTemplate; }
1095};
1096
1097//===----------------------------------------------------------------------===//
1098// Kinds of Template Parameters
1099//===----------------------------------------------------------------------===//
1100
1101/// Defines the position of a template parameter within a template
1102/// parameter list.
1103///
1104/// Because template parameter can be listed
1105/// sequentially for out-of-line template members, each template parameter is
1106/// given a Depth - the nesting of template parameter scopes - and a Position -
1107/// the occurrence within the parameter list.
1108/// This class is inheritedly privately by different kinds of template
1109/// parameters and is not part of the Decl hierarchy. Just a facility.
1111protected:
1112 enum { DepthWidth = 20, PositionWidth = 12 };
1113 unsigned Depth : DepthWidth;
1115
1116 static constexpr unsigned MaxDepth = (1U << DepthWidth) - 1;
1117 static constexpr unsigned MaxPosition = (1U << PositionWidth) - 1;
1118
1119 TemplateParmPosition(unsigned D, unsigned P) : Depth(D), Position(P) {
1120 // The input may fill maximum values to show that it is invalid.
1121 // Add one here to convert it to zero.
1122 assert((D + 1) <= MaxDepth &&
1123 "The depth of template parmeter position is more than 2^20!");
1124 assert((P + 1) <= MaxPosition &&
1125 "The position of template parmeter position is more than 2^12!");
1126 }
1127
1128public:
1130
1131 /// Get the nesting depth of the template parameter.
1132 unsigned getDepth() const { return Depth; }
1133 void setDepth(unsigned D) {
1134 assert((D + 1) <= MaxDepth &&
1135 "The depth of template parmeter position is more than 2^20!");
1136 Depth = D;
1137 }
1138
1139 /// Get the position of the template parameter within its parameter list.
1140 unsigned getPosition() const { return Position; }
1141 void setPosition(unsigned P) {
1142 assert((P + 1) <= MaxPosition &&
1143 "The position of template parmeter position is more than 2^12!");
1144 Position = P;
1145 }
1146
1147 /// Get the index of the template parameter within its parameter list.
1148 unsigned getIndex() const { return Position; }
1149};
1150
1151/// Declaration of a template type parameter.
1152///
1153/// For example, "T" in
1154/// \code
1155/// template<typename T> class vector;
1156/// \endcode
1157class TemplateTypeParmDecl final : public TypeDecl,
1158 private llvm::TrailingObjects<TemplateTypeParmDecl, TypeConstraint> {
1159 /// Sema creates these on the stack during auto type deduction.
1160 friend class Sema;
1161 friend TrailingObjects;
1162 friend class ASTDeclReader;
1163
1164 /// Whether this template type parameter was declaration with
1165 /// the 'typename' keyword.
1166 ///
1167 /// If false, it was declared with the 'class' keyword.
1168 bool Typename : 1;
1169
1170 /// Whether this template type parameter has a type-constraint construct.
1171 bool HasTypeConstraint : 1;
1172
1173 /// Whether the type constraint has been initialized. This can be false if the
1174 /// constraint was not initialized yet or if there was an error forming the
1175 /// type constraint.
1176 bool TypeConstraintInitialized : 1;
1177
1178 /// Whether this type template parameter is an "expanded"
1179 /// parameter pack, meaning that its type is a pack expansion and we
1180 /// already know the set of types that expansion expands to.
1181 bool ExpandedParameterPack : 1;
1182
1183 /// The number of type parameters in an expanded parameter pack.
1184 unsigned NumExpanded = 0;
1185
1186 /// The default template argument, if any.
1187 using DefArgStorage =
1189 DefArgStorage DefaultArgument;
1190
1192 SourceLocation IdLoc, IdentifierInfo *Id, bool Typename,
1193 bool HasTypeConstraint,
1194 std::optional<unsigned> NumExpanded)
1195 : TypeDecl(TemplateTypeParm, DC, IdLoc, Id, KeyLoc), Typename(Typename),
1196 HasTypeConstraint(HasTypeConstraint), TypeConstraintInitialized(false),
1197 ExpandedParameterPack(NumExpanded),
1198 NumExpanded(NumExpanded.value_or(0)) {}
1199
1200public:
1201 static TemplateTypeParmDecl *
1202 Create(const ASTContext &C, DeclContext *DC, SourceLocation KeyLoc,
1203 SourceLocation NameLoc, unsigned D, unsigned P, IdentifierInfo *Id,
1204 bool Typename, bool ParameterPack, bool HasTypeConstraint = false,
1205 std::optional<unsigned> NumExpanded = std::nullopt);
1207 unsigned ID);
1209 unsigned ID,
1210 bool HasTypeConstraint);
1211
1212 /// Whether this template type parameter was declared with
1213 /// the 'typename' keyword.
1214 ///
1215 /// If not, it was either declared with the 'class' keyword or with a
1216 /// type-constraint (see hasTypeConstraint()).
1218 return Typename && !HasTypeConstraint;
1219 }
1220
1221 const DefArgStorage &getDefaultArgStorage() const { return DefaultArgument; }
1222
1223 /// Determine whether this template parameter has a default
1224 /// argument.
1225 bool hasDefaultArgument() const { return DefaultArgument.isSet(); }
1226
1227 /// Retrieve the default argument, if any.
1229 return DefaultArgument.get()->getType();
1230 }
1231
1232 /// Retrieves the default argument's source information, if any.
1234 return DefaultArgument.get();
1235 }
1236
1237 /// Retrieves the location of the default argument declaration.
1239
1240 /// Determines whether the default argument was inherited
1241 /// from a previous declaration of this template.
1243 return DefaultArgument.isInherited();
1244 }
1245
1246 /// Set the default argument for this template parameter.
1248 DefaultArgument.set(DefArg);
1249 }
1250
1251 /// Set that this default argument was inherited from another
1252 /// parameter.
1254 TemplateTypeParmDecl *Prev) {
1255 DefaultArgument.setInherited(C, Prev);
1256 }
1257
1258 /// Removes the default argument of this template parameter.
1260 DefaultArgument.clear();
1261 }
1262
1263 /// Set whether this template type parameter was declared with
1264 /// the 'typename' or 'class' keyword.
1265 void setDeclaredWithTypename(bool withTypename) { Typename = withTypename; }
1266
1267 /// Retrieve the depth of the template parameter.
1268 unsigned getDepth() const;
1269
1270 /// Retrieve the index of the template parameter.
1271 unsigned getIndex() const;
1272
1273 /// Returns whether this is a parameter pack.
1274 bool isParameterPack() const;
1275
1276 /// Whether this parameter pack is a pack expansion.
1277 ///
1278 /// A template type template parameter pack can be a pack expansion if its
1279 /// type-constraint contains an unexpanded parameter pack.
1280 bool isPackExpansion() const {
1281 if (!isParameterPack())
1282 return false;
1283 if (const TypeConstraint *TC = getTypeConstraint())
1284 if (TC->hasExplicitTemplateArgs())
1285 for (const auto &ArgLoc : TC->getTemplateArgsAsWritten()->arguments())
1286 if (ArgLoc.getArgument().containsUnexpandedParameterPack())
1287 return true;
1288 return false;
1289 }
1290
1291 /// Whether this parameter is a template type parameter pack that has a known
1292 /// list of different type-constraints at different positions.
1293 ///
1294 /// A parameter pack is an expanded parameter pack when the original
1295 /// parameter pack's type-constraint was itself a pack expansion, and that
1296 /// expansion has already been expanded. For example, given:
1297 ///
1298 /// \code
1299 /// template<typename ...Types>
1300 /// struct X {
1301 /// template<convertible_to<Types> ...Convertibles>
1302 /// struct Y { /* ... */ };
1303 /// };
1304 /// \endcode
1305 ///
1306 /// The parameter pack \c Convertibles has (convertible_to<Types> && ...) as
1307 /// its type-constraint. When \c Types is supplied with template arguments by
1308 /// instantiating \c X, the instantiation of \c Convertibles becomes an
1309 /// expanded parameter pack. For example, instantiating
1310 /// \c X<int, unsigned int> results in \c Convertibles being an expanded
1311 /// parameter pack of size 2 (use getNumExpansionTypes() to get this number).
1312 bool isExpandedParameterPack() const { return ExpandedParameterPack; }
1313
1314 /// Retrieves the number of parameters in an expanded parameter pack.
1315 unsigned getNumExpansionParameters() const {
1316 assert(ExpandedParameterPack && "Not an expansion parameter pack");
1317 return NumExpanded;
1318 }
1319
1320 /// Returns the type constraint associated with this template parameter (if
1321 /// any).
1323 return TypeConstraintInitialized ? getTrailingObjects<TypeConstraint>() :
1324 nullptr;
1325 }
1326
1328 Expr *ImmediatelyDeclaredConstraint);
1329
1330 /// Determine whether this template parameter has a type-constraint.
1331 bool hasTypeConstraint() const {
1332 return HasTypeConstraint;
1333 }
1334
1335 /// \brief Get the associated-constraints of this template parameter.
1336 /// This will either be the immediately-introduced constraint or empty.
1337 ///
1338 /// Use this instead of getTypeConstraint for concepts APIs that
1339 /// accept an ArrayRef of constraint expressions.
1341 if (HasTypeConstraint)
1342 AC.push_back(getTypeConstraint()->getImmediatelyDeclaredConstraint());
1343 }
1344
1345 SourceRange getSourceRange() const override LLVM_READONLY;
1346
1347 // Implement isa/cast/dyncast/etc.
1348 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1349 static bool classofKind(Kind K) { return K == TemplateTypeParm; }
1350};
1351
1352/// NonTypeTemplateParmDecl - Declares a non-type template parameter,
1353/// e.g., "Size" in
1354/// @code
1355/// template<int Size> class array { };
1356/// @endcode
1358 : public DeclaratorDecl,
1359 protected TemplateParmPosition,
1360 private llvm::TrailingObjects<NonTypeTemplateParmDecl,
1361 std::pair<QualType, TypeSourceInfo *>,
1362 Expr *> {
1363 friend class ASTDeclReader;
1364 friend TrailingObjects;
1365
1366 /// The default template argument, if any, and whether or not
1367 /// it was inherited.
1369 DefArgStorage DefaultArgument;
1370
1371 // FIXME: Collapse this into TemplateParamPosition; or, just move depth/index
1372 // down here to save memory.
1373
1374 /// Whether this non-type template parameter is a parameter pack.
1375 bool ParameterPack;
1376
1377 /// Whether this non-type template parameter is an "expanded"
1378 /// parameter pack, meaning that its type is a pack expansion and we
1379 /// already know the set of types that expansion expands to.
1380 bool ExpandedParameterPack = false;
1381
1382 /// The number of types in an expanded parameter pack.
1383 unsigned NumExpandedTypes = 0;
1384
1385 size_t numTrailingObjects(
1386 OverloadToken<std::pair<QualType, TypeSourceInfo *>>) const {
1387 return NumExpandedTypes;
1388 }
1389
1391 SourceLocation IdLoc, unsigned D, unsigned P,
1393 bool ParameterPack, TypeSourceInfo *TInfo)
1394 : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc),
1395 TemplateParmPosition(D, P), ParameterPack(ParameterPack) {}
1396
1397 NonTypeTemplateParmDecl(DeclContext *DC, SourceLocation StartLoc,
1398 SourceLocation IdLoc, unsigned D, unsigned P,
1399 IdentifierInfo *Id, QualType T,
1400 TypeSourceInfo *TInfo,
1401 ArrayRef<QualType> ExpandedTypes,
1402 ArrayRef<TypeSourceInfo *> ExpandedTInfos);
1403
1404public:
1405 static NonTypeTemplateParmDecl *
1406 Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1407 SourceLocation IdLoc, unsigned D, unsigned P, IdentifierInfo *Id,
1408 QualType T, bool ParameterPack, TypeSourceInfo *TInfo);
1409
1410 static NonTypeTemplateParmDecl *
1411 Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1412 SourceLocation IdLoc, unsigned D, unsigned P, IdentifierInfo *Id,
1413 QualType T, TypeSourceInfo *TInfo, ArrayRef<QualType> ExpandedTypes,
1414 ArrayRef<TypeSourceInfo *> ExpandedTInfos);
1415
1416 static NonTypeTemplateParmDecl *CreateDeserialized(ASTContext &C,
1417 unsigned ID,
1418 bool HasTypeConstraint);
1419 static NonTypeTemplateParmDecl *CreateDeserialized(ASTContext &C,
1420 unsigned 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 parameter is a parameter pack.
1585 bool ParameterPack;
1586
1587 /// Whether this template template parameter is an "expanded"
1588 /// parameter pack, meaning that it is a pack expansion and we
1589 /// already know the set of template parameters that expansion expands to.
1590 bool ExpandedParameterPack = false;
1591
1592 /// The number of parameters in an expanded parameter pack.
1593 unsigned NumExpandedParams = 0;
1594
1596 unsigned D, unsigned P, bool ParameterPack,
1598 : TemplateDecl(TemplateTemplateParm, DC, L, Id, Params),
1599 TemplateParmPosition(D, P), ParameterPack(ParameterPack) {}
1600
1602 unsigned D, unsigned P,
1605
1606 void anchor() override;
1607
1608public:
1609 friend class ASTDeclReader;
1610 friend class ASTDeclWriter;
1612
1614 SourceLocation L, unsigned D,
1615 unsigned P, bool ParameterPack,
1617 TemplateParameterList *Params);
1619 SourceLocation L, unsigned D,
1620 unsigned P,
1622 TemplateParameterList *Params,
1624
1626 unsigned ID);
1628 unsigned ID,
1629 unsigned NumExpansions);
1630
1636
1637 /// Whether this template template parameter is a template
1638 /// parameter pack.
1639 ///
1640 /// \code
1641 /// template<template <class T> ...MetaFunctions> struct Apply;
1642 /// \endcode
1643 bool isParameterPack() const { return ParameterPack; }
1644
1645 /// Whether this parameter pack is a pack expansion.
1646 ///
1647 /// A template template parameter pack is a pack expansion if its template
1648 /// parameter list contains an unexpanded parameter pack.
1649 bool isPackExpansion() const {
1650 return ParameterPack &&
1652 }
1653
1654 /// Whether this parameter is a template template parameter pack that
1655 /// has a known list of different template parameter lists at different
1656 /// positions.
1657 ///
1658 /// A parameter pack is an expanded parameter pack when the original parameter
1659 /// pack's template parameter list was itself a pack expansion, and that
1660 /// expansion has already been expanded. For exampe, given:
1661 ///
1662 /// \code
1663 /// template<typename...Types> struct Outer {
1664 /// template<template<Types> class...Templates> struct Inner;
1665 /// };
1666 /// \endcode
1667 ///
1668 /// The parameter pack \c Templates is a pack expansion, which expands the
1669 /// pack \c Types. When \c Types is supplied with template arguments by
1670 /// instantiating \c Outer, the instantiation of \c Templates is an expanded
1671 /// parameter pack.
1672 bool isExpandedParameterPack() const { return ExpandedParameterPack; }
1673
1674 /// Retrieves the number of expansion template parameters in
1675 /// an expanded parameter pack.
1677 assert(ExpandedParameterPack && "Not an expansion parameter pack");
1678 return NumExpandedParams;
1679 }
1680
1681 /// Retrieve a particular expansion type within an expanded parameter
1682 /// pack.
1684 assert(I < NumExpandedParams && "Out-of-range expansion type index");
1685 return getTrailingObjects<TemplateParameterList *>()[I];
1686 }
1687
1688 const DefArgStorage &getDefaultArgStorage() const { return DefaultArgument; }
1689
1690 /// Determine whether this template parameter has a default
1691 /// argument.
1692 bool hasDefaultArgument() const { return DefaultArgument.isSet(); }
1693
1694 /// Retrieve the default argument, if any.
1696 static const TemplateArgumentLoc NoneLoc;
1697 return DefaultArgument.isSet() ? *DefaultArgument.get() : NoneLoc;
1698 }
1699
1700 /// Retrieve the location of the default argument, if any.
1702
1703 /// Determines whether the default argument was inherited
1704 /// from a previous declaration of this template.
1706 return DefaultArgument.isInherited();
1707 }
1708
1709 /// Set the default argument for this template parameter, and
1710 /// whether that default argument was inherited from another
1711 /// declaration.
1712 void setDefaultArgument(const ASTContext &C,
1713 const TemplateArgumentLoc &DefArg);
1716 DefaultArgument.setInherited(C, Prev);
1717 }
1718
1719 /// Removes the default argument of this template parameter.
1720 void removeDefaultArgument() { DefaultArgument.clear(); }
1721
1722 SourceRange getSourceRange() const override LLVM_READONLY {
1726 return SourceRange(getTemplateParameters()->getTemplateLoc(), End);
1727 }
1728
1729 // Implement isa/cast/dyncast/etc.
1730 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1731 static bool classofKind(Kind K) { return K == TemplateTemplateParm; }
1732};
1733
1734/// Represents the builtin template declaration which is used to
1735/// implement __make_integer_seq and other builtin templates. It serves
1736/// no real purpose beyond existing as a place to hold template parameters.
1739
1742
1743 void anchor() override;
1744
1745public:
1746 // Implement isa/cast/dyncast support
1747 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1748 static bool classofKind(Kind K) { return K == BuiltinTemplate; }
1749
1751 DeclarationName Name,
1752 BuiltinTemplateKind BTK) {
1753 return new (C, DC) BuiltinTemplateDecl(C, DC, Name, BTK);
1754 }
1755
1756 SourceRange getSourceRange() const override LLVM_READONLY {
1757 return {};
1758 }
1759
1761};
1762
1763/// Represents a class template specialization, which refers to
1764/// a class template with a given set of template arguments.
1765///
1766/// Class template specializations represent both explicit
1767/// specialization of class templates, as in the example below, and
1768/// implicit instantiations of class templates.
1769///
1770/// \code
1771/// template<typename T> class array;
1772///
1773/// template<>
1774/// class array<bool> { }; // class template specialization array<bool>
1775/// \endcode
1777 : public CXXRecordDecl, public llvm::FoldingSetNode {
1778 /// Structure that stores information about a class template
1779 /// specialization that was instantiated from a class template partial
1780 /// specialization.
1781 struct SpecializedPartialSpecialization {
1782 /// The class template partial specialization from which this
1783 /// class template specialization was instantiated.
1784 ClassTemplatePartialSpecializationDecl *PartialSpecialization;
1785
1786 /// The template argument list deduced for the class template
1787 /// partial specialization itself.
1788 const TemplateArgumentList *TemplateArgs;
1789 };
1790
1791 /// The template that this specialization specializes
1792 llvm::PointerUnion<ClassTemplateDecl *, SpecializedPartialSpecialization *>
1793 SpecializedTemplate;
1794
1795 /// Further info for explicit template specialization/instantiation.
1796 struct ExplicitSpecializationInfo {
1797 /// The type-as-written.
1798 TypeSourceInfo *TypeAsWritten = nullptr;
1799
1800 /// The location of the extern keyword.
1801 SourceLocation ExternLoc;
1802
1803 /// The location of the template keyword.
1804 SourceLocation TemplateKeywordLoc;
1805
1806 ExplicitSpecializationInfo() = default;
1807 };
1808
1809 /// Further info for explicit template specialization/instantiation.
1810 /// Does not apply to implicit specializations.
1811 ExplicitSpecializationInfo *ExplicitInfo = nullptr;
1812
1813 /// The template arguments used to describe this specialization.
1814 const TemplateArgumentList *TemplateArgs;
1815
1816 /// The point where this template was instantiated (if any)
1817 SourceLocation PointOfInstantiation;
1818
1819 /// The kind of specialization this declaration refers to.
1820 LLVM_PREFERRED_TYPE(TemplateSpecializationKind)
1821 unsigned SpecializationKind : 3;
1822
1823protected:
1825 DeclContext *DC, SourceLocation StartLoc,
1826 SourceLocation IdLoc,
1827 ClassTemplateDecl *SpecializedTemplate,
1830
1832
1833public:
1834 friend class ASTDeclReader;
1835 friend class ASTDeclWriter;
1836
1838 Create(ASTContext &Context, TagKind TK, DeclContext *DC,
1839 SourceLocation StartLoc, SourceLocation IdLoc,
1840 ClassTemplateDecl *SpecializedTemplate,
1844 CreateDeserialized(ASTContext &C, unsigned ID);
1845
1846 void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy,
1847 bool Qualified) const override;
1848
1849 // FIXME: This is broken. CXXRecordDecl::getMostRecentDecl() returns a
1850 // different "most recent" declaration from this function for the same
1851 // declaration, because we don't override getMostRecentDeclImpl(). But
1852 // it's not clear that we should override that, because the most recent
1853 // declaration as a CXXRecordDecl sometimes is the injected-class-name.
1855 return cast<ClassTemplateSpecializationDecl>(
1857 }
1858
1859 /// Retrieve the template that this specialization specializes.
1861
1862 /// Retrieve the template arguments of the class template
1863 /// specialization.
1865 return *TemplateArgs;
1866 }
1867
1869 TemplateArgs = Args;
1870 }
1871
1872 /// Determine the kind of specialization that this
1873 /// declaration represents.
1875 return static_cast<TemplateSpecializationKind>(SpecializationKind);
1876 }
1877
1880 }
1881
1882 /// Is this an explicit specialization at class scope (within the class that
1883 /// owns the primary template)? For example:
1884 ///
1885 /// \code
1886 /// template<typename T> struct Outer {
1887 /// template<typename U> struct Inner;
1888 /// template<> struct Inner; // class-scope explicit specialization
1889 /// };
1890 /// \endcode
1892 return isExplicitSpecialization() &&
1893 isa<CXXRecordDecl>(getLexicalDeclContext());
1894 }
1895
1896 /// True if this declaration is an explicit specialization,
1897 /// explicit instantiation declaration, or explicit instantiation
1898 /// definition.
1902 }
1903
1905 SpecializedTemplate = Specialized;
1906 }
1907
1909 SpecializationKind = TSK;
1910 }
1911
1912 /// Get the point of instantiation (if any), or null if none.
1914 return PointOfInstantiation;
1915 }
1916
1918 assert(Loc.isValid() && "point of instantiation must be valid!");
1919 PointOfInstantiation = Loc;
1920 }
1921
1922 /// If this class template specialization is an instantiation of
1923 /// a template (rather than an explicit specialization), return the
1924 /// class template or class template partial specialization from which it
1925 /// was instantiated.
1926 llvm::PointerUnion<ClassTemplateDecl *,
1930 return llvm::PointerUnion<ClassTemplateDecl *,
1932
1934 }
1935
1936 /// Retrieve the class template or class template partial
1937 /// specialization which was specialized by this.
1938 llvm::PointerUnion<ClassTemplateDecl *,
1941 if (const auto *PartialSpec =
1942 SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
1943 return PartialSpec->PartialSpecialization;
1944
1945 return SpecializedTemplate.get<ClassTemplateDecl*>();
1946 }
1947
1948 /// Retrieve the set of template arguments that should be used
1949 /// to instantiate members of the class template or class template partial
1950 /// specialization from which this class template specialization was
1951 /// instantiated.
1952 ///
1953 /// \returns For a class template specialization instantiated from the primary
1954 /// template, this function will return the same template arguments as
1955 /// getTemplateArgs(). For a class template specialization instantiated from
1956 /// a class template partial specialization, this function will return the
1957 /// deduced template arguments for the class template partial specialization
1958 /// itself.
1960 if (const auto *PartialSpec =
1961 SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
1962 return *PartialSpec->TemplateArgs;
1963
1964 return getTemplateArgs();
1965 }
1966
1967 /// Note that this class template specialization is actually an
1968 /// instantiation of the given class template partial specialization whose
1969 /// template arguments have been deduced.
1971 const TemplateArgumentList *TemplateArgs) {
1972 assert(!SpecializedTemplate.is<SpecializedPartialSpecialization*>() &&
1973 "Already set to a class template partial specialization!");
1974 auto *PS = new (getASTContext()) SpecializedPartialSpecialization();
1975 PS->PartialSpecialization = PartialSpec;
1976 PS->TemplateArgs = TemplateArgs;
1977 SpecializedTemplate = PS;
1978 }
1979
1980 /// Note that this class template specialization is an instantiation
1981 /// of the given class template.
1983 assert(!SpecializedTemplate.is<SpecializedPartialSpecialization*>() &&
1984 "Previously set to a class template partial specialization!");
1985 SpecializedTemplate = TemplDecl;
1986 }
1987
1988 /// Sets the type of this specialization as it was written by
1989 /// the user. This will be a class template specialization type.
1991 if (!ExplicitInfo)
1992 ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo;
1993 ExplicitInfo->TypeAsWritten = T;
1994 }
1995
1996 /// Gets the type of this specialization as it was written by
1997 /// the user, if it was so written.
1999 return ExplicitInfo ? ExplicitInfo->TypeAsWritten : nullptr;
2000 }
2001
2002 /// Gets the location of the extern keyword, if present.
2004 return ExplicitInfo ? ExplicitInfo->ExternLoc : SourceLocation();
2005 }
2006
2007 /// Sets the location of the extern keyword.
2009 if (!ExplicitInfo)
2010 ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo;
2011 ExplicitInfo->ExternLoc = Loc;
2012 }
2013
2014 /// Sets the location of the template keyword.
2016 if (!ExplicitInfo)
2017 ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo;
2018 ExplicitInfo->TemplateKeywordLoc = Loc;
2019 }
2020
2021 /// Gets the location of the template keyword, if present.
2023 return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation();
2024 }
2025
2026 SourceRange getSourceRange() const override LLVM_READONLY;
2027
2028 void Profile(llvm::FoldingSetNodeID &ID) const {
2029 Profile(ID, TemplateArgs->asArray(), getASTContext());
2030 }
2031
2032 static void
2033 Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
2034 const ASTContext &Context) {
2035 ID.AddInteger(TemplateArgs.size());
2036 for (const TemplateArgument &TemplateArg : TemplateArgs)
2037 TemplateArg.Profile(ID, Context);
2038 }
2039
2040 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2041
2042 static bool classofKind(Kind K) {
2043 return K >= firstClassTemplateSpecialization &&
2044 K <= lastClassTemplateSpecialization;
2045 }
2046};
2047
2050 /// The list of template parameters
2051 TemplateParameterList* TemplateParams = nullptr;
2052
2053 /// The source info for the template arguments as written.
2054 /// FIXME: redundant with TypeAsWritten?
2055 const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr;
2056
2057 /// The class template partial specialization from which this
2058 /// class template partial specialization was instantiated.
2059 ///
2060 /// The boolean value will be true to indicate that this class template
2061 /// partial specialization was specialized at this level.
2062 llvm::PointerIntPair<ClassTemplatePartialSpecializationDecl *, 1, bool>
2063 InstantiatedFromMember;
2064
2066 DeclContext *DC,
2067 SourceLocation StartLoc,
2068 SourceLocation IdLoc,
2069 TemplateParameterList *Params,
2070 ClassTemplateDecl *SpecializedTemplate,
2072 const ASTTemplateArgumentListInfo *ArgsAsWritten,
2074
2076 : ClassTemplateSpecializationDecl(C, ClassTemplatePartialSpecialization),
2077 InstantiatedFromMember(nullptr, false) {}
2078
2079 void anchor() override;
2080
2081public:
2082 friend class ASTDeclReader;
2083 friend class ASTDeclWriter;
2084
2086 Create(ASTContext &Context, TagKind TK, DeclContext *DC,
2087 SourceLocation StartLoc, SourceLocation IdLoc,
2088 TemplateParameterList *Params,
2089 ClassTemplateDecl *SpecializedTemplate,
2091 const TemplateArgumentListInfo &ArgInfos,
2092 QualType CanonInjectedType,
2094
2096 CreateDeserialized(ASTContext &C, unsigned ID);
2097
2099 return cast<ClassTemplatePartialSpecializationDecl>(
2100 static_cast<ClassTemplateSpecializationDecl *>(
2101 this)->getMostRecentDecl());
2102 }
2103
2104 /// Get the list of template parameters
2106 return TemplateParams;
2107 }
2108
2109 /// \brief All associated constraints of this partial specialization,
2110 /// including the requires clause and any constraints derived from
2111 /// constrained-parameters.
2112 ///
2113 /// The constraints in the resulting list are to be treated as if in a
2114 /// conjunction ("and").
2116 TemplateParams->getAssociatedConstraints(AC);
2117 }
2118
2120 return TemplateParams->hasAssociatedConstraints();
2121 }
2122
2123 /// Get the template arguments as written.
2125 return ArgsAsWritten;
2126 }
2127
2128 /// Retrieve the member class template partial specialization from
2129 /// which this particular class template partial specialization was
2130 /// instantiated.
2131 ///
2132 /// \code
2133 /// template<typename T>
2134 /// struct Outer {
2135 /// template<typename U> struct Inner;
2136 /// template<typename U> struct Inner<U*> { }; // #1
2137 /// };
2138 ///
2139 /// Outer<float>::Inner<int*> ii;
2140 /// \endcode
2141 ///
2142 /// In this example, the instantiation of \c Outer<float>::Inner<int*> will
2143 /// end up instantiating the partial specialization
2144 /// \c Outer<float>::Inner<U*>, which itself was instantiated from the class
2145 /// template partial specialization \c Outer<T>::Inner<U*>. Given
2146 /// \c Outer<float>::Inner<U*>, this function would return
2147 /// \c Outer<T>::Inner<U*>.
2149 const auto *First =
2150 cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2151 return First->InstantiatedFromMember.getPointer();
2152 }
2156 }
2157
2160 auto *First = cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2161 First->InstantiatedFromMember.setPointer(PartialSpec);
2162 }
2163
2164 /// Determines whether this class template partial specialization
2165 /// template was a specialization of a member partial specialization.
2166 ///
2167 /// In the following example, the member template partial specialization
2168 /// \c X<int>::Inner<T*> is a member specialization.
2169 ///
2170 /// \code
2171 /// template<typename T>
2172 /// struct X {
2173 /// template<typename U> struct Inner;
2174 /// template<typename U> struct Inner<U*>;
2175 /// };
2176 ///
2177 /// template<> template<typename T>
2178 /// struct X<int>::Inner<T*> { /* ... */ };
2179 /// \endcode
2181 const auto *First =
2182 cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2183 return First->InstantiatedFromMember.getInt();
2184 }
2185
2186 /// Note that this member template is a specialization.
2188 auto *First = cast<ClassTemplatePartialSpecializationDecl>(getFirstDecl());
2189 assert(First->InstantiatedFromMember.getPointer() &&
2190 "Only member templates can be member template specializations");
2191 return First->InstantiatedFromMember.setInt(true);
2192 }
2193
2194 /// Retrieves the injected specialization type for this partial
2195 /// specialization. This is not the same as the type-decl-type for
2196 /// this partial specialization, which is an InjectedClassNameType.
2198 assert(getTypeForDecl() && "partial specialization has no type set!");
2199 return cast<InjectedClassNameType>(getTypeForDecl())
2200 ->getInjectedSpecializationType();
2201 }
2202
2203 void Profile(llvm::FoldingSetNodeID &ID) const {
2205 getASTContext());
2206 }
2207
2208 static void
2209 Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
2210 TemplateParameterList *TPL, const ASTContext &Context);
2211
2212 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2213
2214 static bool classofKind(Kind K) {
2215 return K == ClassTemplatePartialSpecialization;
2216 }
2217};
2218
2219/// Declaration of a class template.
2221protected:
2222 /// Data that is common to all of the declarations of a given
2223 /// class template.
2225 /// The class template specializations for this class
2226 /// template, including explicit specializations and instantiations.
2227 llvm::FoldingSetVector<ClassTemplateSpecializationDecl> Specializations;
2228
2229 /// The class template partial specializations for this class
2230 /// template.
2231 llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>
2233
2234 /// The injected-class-name type for this class template.
2236
2237 Common() = default;
2238 };
2239
2240 /// Retrieve the set of specializations of this class template.
2241 llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
2242 getSpecializations() const;
2243
2244 /// Retrieve the set of partial specializations of this class
2245 /// template.
2246 llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
2248
2251 NamedDecl *Decl)
2252 : RedeclarableTemplateDecl(ClassTemplate, C, DC, L, Name, Params, Decl) {}
2253
2254 CommonBase *newCommon(ASTContext &C) const override;
2255
2257 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
2258 }
2259
2262 }
2263
2264public:
2265
2266 friend class ASTDeclReader;
2267 friend class ASTDeclWriter;
2269
2270 /// Load any lazily-loaded specializations from the external source.
2271 void LoadLazySpecializations() const;
2272
2273 /// Get the underlying class declarations of the template.
2275 return static_cast<CXXRecordDecl *>(TemplatedDecl);
2276 }
2277
2278 /// Returns whether this template declaration defines the primary
2279 /// class pattern.
2282 }
2283
2284 /// \brief Create a class template node.
2287 DeclarationName Name,
2288 TemplateParameterList *Params,
2289 NamedDecl *Decl);
2290
2291 /// Create an empty class template node.
2293
2294 /// Return the specialization with the provided arguments if it exists,
2295 /// otherwise return the insertion point.
2297 findSpecialization(ArrayRef<TemplateArgument> Args, void *&InsertPos);
2298
2299 /// Insert the specified specialization knowing that it is not already
2300 /// in. InsertPos must be obtained from findSpecialization.
2301 void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos);
2302
2304 return cast<ClassTemplateDecl>(
2306 }
2308 return cast<ClassTemplateDecl>(
2310 }
2311
2312 /// Retrieve the previous declaration of this class template, or
2313 /// nullptr if no such declaration exists.
2315 return cast_or_null<ClassTemplateDecl>(
2316 static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
2317 }
2319 return cast_or_null<ClassTemplateDecl>(
2320 static_cast<const RedeclarableTemplateDecl *>(
2321 this)->getPreviousDecl());
2322 }
2323
2325 return cast<ClassTemplateDecl>(
2326 static_cast<RedeclarableTemplateDecl *>(this)->getMostRecentDecl());
2327 }
2329 return const_cast<ClassTemplateDecl*>(this)->getMostRecentDecl();
2330 }
2331
2333 return cast_or_null<ClassTemplateDecl>(
2335 }
2336
2337 /// Return the partial specialization with the provided arguments if it
2338 /// exists, otherwise return the insertion point.
2341 TemplateParameterList *TPL, void *&InsertPos);
2342
2343 /// Insert the specified partial specialization knowing that it is not
2344 /// already in. InsertPos must be obtained from findPartialSpecialization.
2346 void *InsertPos);
2347
2348 /// Retrieve the partial specializations as an ordered list.
2351
2352 /// Find a class template partial specialization with the given
2353 /// type T.
2354 ///
2355 /// \param T a dependent type that names a specialization of this class
2356 /// template.
2357 ///
2358 /// \returns the class template partial specialization that exactly matches
2359 /// the type \p T, or nullptr if no such partial specialization exists.
2361
2362 /// Find a class template partial specialization which was instantiated
2363 /// from the given member partial specialization.
2364 ///
2365 /// \param D a member class template partial specialization.
2366 ///
2367 /// \returns the class template partial specialization which was instantiated
2368 /// from the given member partial specialization, or nullptr if no such
2369 /// partial specialization exists.
2373
2374 /// Retrieve the template specialization type of the
2375 /// injected-class-name for this class template.
2376 ///
2377 /// The injected-class-name for a class template \c X is \c
2378 /// X<template-args>, where \c template-args is formed from the
2379 /// template arguments that correspond to the template parameters of
2380 /// \c X. For example:
2381 ///
2382 /// \code
2383 /// template<typename T, int N>
2384 /// struct array {
2385 /// typedef array this_type; // "array" is equivalent to "array<T, N>"
2386 /// };
2387 /// \endcode
2389
2391 using spec_range = llvm::iterator_range<spec_iterator>;
2392
2394 return spec_range(spec_begin(), spec_end());
2395 }
2396
2398 return makeSpecIterator(getSpecializations(), false);
2399 }
2400
2402 return makeSpecIterator(getSpecializations(), true);
2403 }
2404
2405 // Implement isa/cast/dyncast support
2406 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2407 static bool classofKind(Kind K) { return K == ClassTemplate; }
2408};
2409
2410/// Declaration of a friend template.
2411///
2412/// For example:
2413/// \code
2414/// template <typename T> class A {
2415/// friend class MyVector<T>; // not a friend template
2416/// template <typename U> friend class B; // not a friend template
2417/// template <typename U> friend class Foo<T>::Nested; // friend template
2418/// };
2419/// \endcode
2420///
2421/// \note This class is not currently in use. All of the above
2422/// will yield a FriendDecl, not a FriendTemplateDecl.
2423class FriendTemplateDecl : public Decl {
2424 virtual void anchor();
2425
2426public:
2427 using FriendUnion = llvm::PointerUnion<NamedDecl *,TypeSourceInfo *>;
2428
2429private:
2430 // The number of template parameters; always non-zero.
2431 unsigned NumParams = 0;
2432
2433 // The parameter list.
2434 TemplateParameterList **Params = nullptr;
2435
2436 // The declaration that's a friend of this class.
2437 FriendUnion Friend;
2438
2439 // Location of the 'friend' specifier.
2440 SourceLocation FriendLoc;
2441
2443 TemplateParameterList **Params, unsigned NumParams,
2444 FriendUnion Friend, SourceLocation FriendLoc)
2445 : Decl(Decl::FriendTemplate, DC, Loc), NumParams(NumParams),
2446 Params(Params), Friend(Friend), FriendLoc(FriendLoc) {}
2447
2448 FriendTemplateDecl(EmptyShell Empty) : Decl(Decl::FriendTemplate, Empty) {}
2449
2450public:
2451 friend class ASTDeclReader;
2452
2453 static FriendTemplateDecl *
2454 Create(ASTContext &Context, DeclContext *DC, SourceLocation Loc,
2456 SourceLocation FriendLoc);
2457
2459
2460 /// If this friend declaration names a templated type (or
2461 /// a dependent member type of a templated type), return that
2462 /// type; otherwise return null.
2464 return Friend.dyn_cast<TypeSourceInfo*>();
2465 }
2466
2467 /// If this friend declaration names a templated function (or
2468 /// a member function of a templated type), return that type;
2469 /// otherwise return null.
2471 return Friend.dyn_cast<NamedDecl*>();
2472 }
2473
2474 /// Retrieves the location of the 'friend' keyword.
2476 return FriendLoc;
2477 }
2478
2480 assert(i <= NumParams);
2481 return Params[i];
2482 }
2483
2484 unsigned getNumTemplateParameters() const {
2485 return NumParams;
2486 }
2487
2488 // Implement isa/cast/dyncast/etc.
2489 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2490 static bool classofKind(Kind K) { return K == Decl::FriendTemplate; }
2491};
2492
2493/// Declaration of an alias template.
2494///
2495/// For example:
2496/// \code
2497/// template <typename T> using V = std::map<T*, int, MyCompare<T>>;
2498/// \endcode
2500protected:
2502
2505 NamedDecl *Decl)
2506 : RedeclarableTemplateDecl(TypeAliasTemplate, C, DC, L, Name, Params,
2507 Decl) {}
2508
2509 CommonBase *newCommon(ASTContext &C) const override;
2510
2512 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
2513 }
2514
2515public:
2516 friend class ASTDeclReader;
2517 friend class ASTDeclWriter;
2518
2519 /// Get the underlying function declaration of the template.
2521 return static_cast<TypeAliasDecl *>(TemplatedDecl);
2522 }
2523
2524
2526 return cast<TypeAliasTemplateDecl>(
2528 }
2530 return cast<TypeAliasTemplateDecl>(
2532 }
2533
2534 /// Retrieve the previous declaration of this function template, or
2535 /// nullptr if no such declaration exists.
2537 return cast_or_null<TypeAliasTemplateDecl>(
2538 static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
2539 }
2541 return cast_or_null<TypeAliasTemplateDecl>(
2542 static_cast<const RedeclarableTemplateDecl *>(
2543 this)->getPreviousDecl());
2544 }
2545
2547 return cast_or_null<TypeAliasTemplateDecl>(
2549 }
2550
2551 /// Create a function template node.
2554 DeclarationName Name,
2555 TemplateParameterList *Params,
2556 NamedDecl *Decl);
2557
2558 /// Create an empty alias template node.
2560
2561 // Implement isa/cast/dyncast support
2562 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2563 static bool classofKind(Kind K) { return K == TypeAliasTemplate; }
2564};
2565
2566/// Represents a variable template specialization, which refers to
2567/// a variable template with a given set of template arguments.
2568///
2569/// Variable template specializations represent both explicit
2570/// specializations of variable templates, as in the example below, and
2571/// implicit instantiations of variable templates.
2572///
2573/// \code
2574/// template<typename T> constexpr T pi = T(3.1415926535897932385);
2575///
2576/// template<>
2577/// constexpr float pi<float>; // variable template specialization pi<float>
2578/// \endcode
2580 public llvm::FoldingSetNode {
2581
2582 /// Structure that stores information about a variable template
2583 /// specialization that was instantiated from a variable template partial
2584 /// specialization.
2585 struct SpecializedPartialSpecialization {
2586 /// The variable template partial specialization from which this
2587 /// variable template specialization was instantiated.
2588 VarTemplatePartialSpecializationDecl *PartialSpecialization;
2589
2590 /// The template argument list deduced for the variable template
2591 /// partial specialization itself.
2592 const TemplateArgumentList *TemplateArgs;
2593 };
2594
2595 /// The template that this specialization specializes.
2596 llvm::PointerUnion<VarTemplateDecl *, SpecializedPartialSpecialization *>
2597 SpecializedTemplate;
2598
2599 /// Further info for explicit template specialization/instantiation.
2600 struct ExplicitSpecializationInfo {
2601 /// The type-as-written.
2602 TypeSourceInfo *TypeAsWritten = nullptr;
2603
2604 /// The location of the extern keyword.
2605 SourceLocation ExternLoc;
2606
2607 /// The location of the template keyword.
2608 SourceLocation TemplateKeywordLoc;
2609
2610 ExplicitSpecializationInfo() = default;
2611 };
2612
2613 /// Further info for explicit template specialization/instantiation.
2614 /// Does not apply to implicit specializations.
2615 ExplicitSpecializationInfo *ExplicitInfo = nullptr;
2616
2617 /// The template arguments used to describe this specialization.
2618 const TemplateArgumentList *TemplateArgs;
2619 const ASTTemplateArgumentListInfo *TemplateArgsInfo = nullptr;
2620
2621 /// The point where this template was instantiated (if any).
2622 SourceLocation PointOfInstantiation;
2623
2624 /// The kind of specialization this declaration refers to.
2625 LLVM_PREFERRED_TYPE(TemplateSpecializationKind)
2626 unsigned SpecializationKind : 3;
2627
2628 /// Whether this declaration is a complete definition of the
2629 /// variable template specialization. We can't otherwise tell apart
2630 /// an instantiated declaration from an instantiated definition with
2631 /// no initializer.
2632 LLVM_PREFERRED_TYPE(bool)
2633 unsigned IsCompleteDefinition : 1;
2634
2635protected:
2637 SourceLocation StartLoc, SourceLocation IdLoc,
2638 VarTemplateDecl *SpecializedTemplate,
2639 QualType T, TypeSourceInfo *TInfo,
2640 StorageClass S,
2642
2643 explicit VarTemplateSpecializationDecl(Kind DK, ASTContext &Context);
2644
2645public:
2646 friend class ASTDeclReader;
2647 friend class ASTDeclWriter;
2648 friend class VarDecl;
2649
2651 Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
2652 SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
2653 TypeSourceInfo *TInfo, StorageClass S,
2656 unsigned ID);
2657
2658 void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy,
2659 bool Qualified) const override;
2660
2662 VarDecl *Recent = static_cast<VarDecl *>(this)->getMostRecentDecl();
2663 return cast<VarTemplateSpecializationDecl>(Recent);
2664 }
2665
2666 /// Retrieve the template that this specialization specializes.
2668
2669 /// Retrieve the template arguments of the variable template
2670 /// specialization.
2671 const TemplateArgumentList &getTemplateArgs() const { return *TemplateArgs; }
2672
2673 // TODO: Always set this when creating the new specialization?
2674 void setTemplateArgsInfo(const TemplateArgumentListInfo &ArgsInfo);
2676
2678 return TemplateArgsInfo;
2679 }
2680
2681 /// Determine the kind of specialization that this
2682 /// declaration represents.
2684 return static_cast<TemplateSpecializationKind>(SpecializationKind);
2685 }
2686
2689 }
2690
2692 return isExplicitSpecialization() &&
2693 isa<CXXRecordDecl>(getLexicalDeclContext());
2694 }
2695
2696 /// True if this declaration is an explicit specialization,
2697 /// explicit instantiation declaration, or explicit instantiation
2698 /// definition.
2702 }
2703
2705 SpecializationKind = TSK;
2706 }
2707
2708 /// Get the point of instantiation (if any), or null if none.
2710 return PointOfInstantiation;
2711 }
2712
2714 assert(Loc.isValid() && "point of instantiation must be valid!");
2715 PointOfInstantiation = Loc;
2716 }
2717
2718 void setCompleteDefinition() { IsCompleteDefinition = true; }
2719
2720 /// If this variable template specialization is an instantiation of
2721 /// a template (rather than an explicit specialization), return the
2722 /// variable template or variable template partial specialization from which
2723 /// it was instantiated.
2724 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
2727 return llvm::PointerUnion<VarTemplateDecl *,
2729
2731 }
2732
2733 /// Retrieve the variable template or variable template partial
2734 /// specialization which was specialized by this.
2735 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
2737 if (const auto *PartialSpec =
2738 SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
2739 return PartialSpec->PartialSpecialization;
2740
2741 return SpecializedTemplate.get<VarTemplateDecl *>();
2742 }
2743
2744 /// Retrieve the set of template arguments that should be used
2745 /// to instantiate the initializer of the variable template or variable
2746 /// template partial specialization from which this variable template
2747 /// specialization was instantiated.
2748 ///
2749 /// \returns For a variable template specialization instantiated from the
2750 /// primary template, this function will return the same template arguments
2751 /// as getTemplateArgs(). For a variable template specialization instantiated
2752 /// from a variable template partial specialization, this function will the
2753 /// return deduced template arguments for the variable template partial
2754 /// specialization itself.
2756 if (const auto *PartialSpec =
2757 SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
2758 return *PartialSpec->TemplateArgs;
2759
2760 return getTemplateArgs();
2761 }
2762
2763 /// Note that this variable template specialization is actually an
2764 /// instantiation of the given variable template partial specialization whose
2765 /// template arguments have been deduced.
2767 const TemplateArgumentList *TemplateArgs) {
2768 assert(!SpecializedTemplate.is<SpecializedPartialSpecialization *>() &&
2769 "Already set to a variable template partial specialization!");
2770 auto *PS = new (getASTContext()) SpecializedPartialSpecialization();
2771 PS->PartialSpecialization = PartialSpec;
2772 PS->TemplateArgs = TemplateArgs;
2773 SpecializedTemplate = PS;
2774 }
2775
2776 /// Note that this variable template specialization is an instantiation
2777 /// of the given variable template.
2779 assert(!SpecializedTemplate.is<SpecializedPartialSpecialization *>() &&
2780 "Previously set to a variable template partial specialization!");
2781 SpecializedTemplate = TemplDecl;
2782 }
2783
2784 /// Sets the type of this specialization as it was written by
2785 /// the user.
2787 if (!ExplicitInfo)
2788 ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo;
2789 ExplicitInfo->TypeAsWritten = T;
2790 }
2791
2792 /// Gets the type of this specialization as it was written by
2793 /// the user, if it was so written.
2795 return ExplicitInfo ? ExplicitInfo->TypeAsWritten : nullptr;
2796 }
2797
2798 /// Gets the location of the extern keyword, if present.
2800 return ExplicitInfo ? ExplicitInfo->ExternLoc : SourceLocation();
2801 }
2802
2803 /// Sets the location of the extern keyword.
2805 if (!ExplicitInfo)
2806 ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo;
2807 ExplicitInfo->ExternLoc = Loc;
2808 }
2809
2810 /// Sets the location of the template keyword.
2812 if (!ExplicitInfo)
2813 ExplicitInfo = new (getASTContext()) ExplicitSpecializationInfo;
2814 ExplicitInfo->TemplateKeywordLoc = Loc;
2815 }
2816
2817 /// Gets the location of the template keyword, if present.
2819 return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation();
2820 }
2821
2822 SourceRange getSourceRange() const override LLVM_READONLY;
2823
2824 void Profile(llvm::FoldingSetNodeID &ID) const {
2825 Profile(ID, TemplateArgs->asArray(), getASTContext());
2826 }
2827
2828 static void Profile(llvm::FoldingSetNodeID &ID,
2829 ArrayRef<TemplateArgument> TemplateArgs,
2830 const ASTContext &Context) {
2831 ID.AddInteger(TemplateArgs.size());
2832 for (const TemplateArgument &TemplateArg : TemplateArgs)
2833 TemplateArg.Profile(ID, Context);
2834 }
2835
2836 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2837
2838 static bool classofKind(Kind K) {
2839 return K >= firstVarTemplateSpecialization &&
2840 K <= lastVarTemplateSpecialization;
2841 }
2842};
2843
2846 /// The list of template parameters
2847 TemplateParameterList *TemplateParams = nullptr;
2848
2849 /// The source info for the template arguments as written.
2850 /// FIXME: redundant with TypeAsWritten?
2851 const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr;
2852
2853 /// The variable template partial specialization from which this
2854 /// variable template partial specialization was instantiated.
2855 ///
2856 /// The boolean value will be true to indicate that this variable template
2857 /// partial specialization was specialized at this level.
2858 llvm::PointerIntPair<VarTemplatePartialSpecializationDecl *, 1, bool>
2859 InstantiatedFromMember;
2860
2862 ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
2864 VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
2866 const ASTTemplateArgumentListInfo *ArgInfos);
2867
2869 : VarTemplateSpecializationDecl(VarTemplatePartialSpecialization,
2870 Context),
2871 InstantiatedFromMember(nullptr, false) {}
2872
2873 void anchor() override;
2874
2875public:
2876 friend class ASTDeclReader;
2877 friend class ASTDeclWriter;
2878
2880 Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
2882 VarTemplateDecl *SpecializedTemplate, QualType T,
2884 const TemplateArgumentListInfo &ArgInfos);
2885
2887 unsigned ID);
2888
2890 return cast<VarTemplatePartialSpecializationDecl>(
2891 static_cast<VarTemplateSpecializationDecl *>(
2892 this)->getMostRecentDecl());
2893 }
2894
2895 /// Get the list of template parameters
2897 return TemplateParams;
2898 }
2899
2900 /// Get the template arguments as written.
2902 return ArgsAsWritten;
2903 }
2904
2905 /// \brief All associated constraints of this partial specialization,
2906 /// including the requires clause and any constraints derived from
2907 /// constrained-parameters.
2908 ///
2909 /// The constraints in the resulting list are to be treated as if in a
2910 /// conjunction ("and").
2912 TemplateParams->getAssociatedConstraints(AC);
2913 }
2914
2916 return TemplateParams->hasAssociatedConstraints();
2917 }
2918
2919 /// \brief Retrieve the member variable template partial specialization from
2920 /// which this particular variable template partial specialization was
2921 /// instantiated.
2922 ///
2923 /// \code
2924 /// template<typename T>
2925 /// struct Outer {
2926 /// template<typename U> U Inner;
2927 /// template<typename U> U* Inner<U*> = (U*)(0); // #1
2928 /// };
2929 ///
2930 /// template int* Outer<float>::Inner<int*>;
2931 /// \endcode
2932 ///
2933 /// In this example, the instantiation of \c Outer<float>::Inner<int*> will
2934 /// end up instantiating the partial specialization
2935 /// \c Outer<float>::Inner<U*>, which itself was instantiated from the
2936 /// variable template partial specialization \c Outer<T>::Inner<U*>. Given
2937 /// \c Outer<float>::Inner<U*>, this function would return
2938 /// \c Outer<T>::Inner<U*>.
2940 const auto *First =
2941 cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2942 return First->InstantiatedFromMember.getPointer();
2943 }
2944
2945 void
2947 auto *First = cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2948 First->InstantiatedFromMember.setPointer(PartialSpec);
2949 }
2950
2951 /// Determines whether this variable template partial specialization
2952 /// was a specialization of a member partial specialization.
2953 ///
2954 /// In the following example, the member template partial specialization
2955 /// \c X<int>::Inner<T*> is a member specialization.
2956 ///
2957 /// \code
2958 /// template<typename T>
2959 /// struct X {
2960 /// template<typename U> U Inner;
2961 /// template<typename U> U* Inner<U*> = (U*)(0);
2962 /// };
2963 ///
2964 /// template<> template<typename T>
2965 /// U* X<int>::Inner<T*> = (T*)(0) + 1;
2966 /// \endcode
2968 const auto *First =
2969 cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2970 return First->InstantiatedFromMember.getInt();
2971 }
2972
2973 /// Note that this member template is a specialization.
2975 auto *First = cast<VarTemplatePartialSpecializationDecl>(getFirstDecl());
2976 assert(First->InstantiatedFromMember.getPointer() &&
2977 "Only member templates can be member template specializations");
2978 return First->InstantiatedFromMember.setInt(true);
2979 }
2980
2981 SourceRange getSourceRange() const override LLVM_READONLY;
2982
2983 void Profile(llvm::FoldingSetNodeID &ID) const {
2985 getASTContext());
2986 }
2987
2988 static void
2989 Profile(llvm::FoldingSetNodeID &ID, ArrayRef<TemplateArgument> TemplateArgs,
2990 TemplateParameterList *TPL, const ASTContext &Context);
2991
2992 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2993
2994 static bool classofKind(Kind K) {
2995 return K == VarTemplatePartialSpecialization;
2996 }
2997};
2998
2999/// Declaration of a variable template.
3001protected:
3002 /// Data that is common to all of the declarations of a given
3003 /// variable template.
3005 /// The variable template specializations for this variable
3006 /// template, including explicit specializations and instantiations.
3007 llvm::FoldingSetVector<VarTemplateSpecializationDecl> Specializations;
3008
3009 /// The variable template partial specializations for this variable
3010 /// template.
3011 llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl>
3013
3014 Common() = default;
3015 };
3016
3017 /// Retrieve the set of specializations of this variable template.
3018 llvm::FoldingSetVector<VarTemplateSpecializationDecl> &
3019 getSpecializations() const;
3020
3021 /// Retrieve the set of partial specializations of this class
3022 /// template.
3023 llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &
3025
3028 NamedDecl *Decl)
3029 : RedeclarableTemplateDecl(VarTemplate, C, DC, L, Name, Params, Decl) {}
3030
3031 CommonBase *newCommon(ASTContext &C) const override;
3032
3034 return static_cast<Common *>(RedeclarableTemplateDecl::getCommonPtr());
3035 }
3036
3037public:
3038 friend class ASTDeclReader;
3039 friend class ASTDeclWriter;
3040
3041 /// Load any lazily-loaded specializations from the external source.
3042 void LoadLazySpecializations() const;
3043
3044 /// Get the underlying variable declarations of the template.
3046 return static_cast<VarDecl *>(TemplatedDecl);
3047 }
3048
3049 /// Returns whether this template declaration defines the primary
3050 /// variable pattern.
3053 }
3054
3056
3057 /// Create a variable template node.
3060 TemplateParameterList *Params,
3061 VarDecl *Decl);
3062
3063 /// Create an empty variable template node.
3064 static VarTemplateDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3065
3066 /// Return the specialization with the provided arguments if it exists,
3067 /// otherwise return the insertion point.
3069 findSpecialization(ArrayRef<TemplateArgument> Args, void *&InsertPos);
3070
3071 /// Insert the specified specialization knowing that it is not already
3072 /// in. InsertPos must be obtained from findSpecialization.
3073 void AddSpecialization(VarTemplateSpecializationDecl *D, void *InsertPos);
3074
3076 return cast<VarTemplateDecl>(RedeclarableTemplateDecl::getCanonicalDecl());
3077 }
3079 return cast<VarTemplateDecl>(RedeclarableTemplateDecl::getCanonicalDecl());
3080 }
3081
3082 /// Retrieve the previous declaration of this variable template, or
3083 /// nullptr if no such declaration exists.
3085 return cast_or_null<VarTemplateDecl>(
3086 static_cast<RedeclarableTemplateDecl *>(this)->getPreviousDecl());
3087 }
3089 return cast_or_null<VarTemplateDecl>(
3090 static_cast<const RedeclarableTemplateDecl *>(
3091 this)->getPreviousDecl());
3092 }
3093
3095 return cast<VarTemplateDecl>(
3096 static_cast<RedeclarableTemplateDecl *>(this)->getMostRecentDecl());
3097 }
3099 return const_cast<VarTemplateDecl *>(this)->getMostRecentDecl();
3100 }
3101
3103 return cast_or_null<VarTemplateDecl>(
3105 }
3106
3107 /// Return the partial specialization with the provided arguments if it
3108 /// exists, otherwise return the insertion point.
3111 TemplateParameterList *TPL, void *&InsertPos);
3112
3113 /// Insert the specified partial specialization knowing that it is not
3114 /// already in. InsertPos must be obtained from findPartialSpecialization.
3116 void *InsertPos);
3117
3118 /// Retrieve the partial specializations as an ordered list.
3121
3122 /// Find a variable template partial specialization which was
3123 /// instantiated
3124 /// from the given member partial specialization.
3125 ///
3126 /// \param D a member variable template partial specialization.
3127 ///
3128 /// \returns the variable template partial specialization which was
3129 /// instantiated
3130 /// from the given member partial specialization, or nullptr if no such
3131 /// partial specialization exists.
3134
3136 using spec_range = llvm::iterator_range<spec_iterator>;
3137
3139 return spec_range(spec_begin(), spec_end());
3140 }
3141
3143 return makeSpecIterator(getSpecializations(), false);
3144 }
3145
3147 return makeSpecIterator(getSpecializations(), true);
3148 }
3149
3150 // Implement isa/cast/dyncast support
3151 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3152 static bool classofKind(Kind K) { return K == VarTemplate; }
3153};
3154
3155/// Declaration of a C++20 concept.
3156class ConceptDecl : public TemplateDecl, public Mergeable<ConceptDecl> {
3157protected:
3159
3162 : TemplateDecl(Concept, DC, L, Name, Params),
3164public:
3167 TemplateParameterList *Params,
3169 static ConceptDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3170
3172 return ConstraintExpr;
3173 }
3174
3175 SourceRange getSourceRange() const override LLVM_READONLY {
3176 return SourceRange(getTemplateParameters()->getTemplateLoc(),
3178 }
3179
3180 bool isTypeConcept() const {
3181 return isa<TemplateTypeParmDecl>(getTemplateParameters()->getParam(0));
3182 }
3183
3185 return cast<ConceptDecl>(getPrimaryMergedDecl(this));
3186 }
3188 return const_cast<ConceptDecl *>(this)->getCanonicalDecl();
3189 }
3190
3191 // Implement isa/cast/dyncast/etc.
3192 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3193 static bool classofKind(Kind K) { return K == Concept; }
3194
3195 friend class ASTReader;
3196 friend class ASTDeclReader;
3197 friend class ASTDeclWriter;
3198};
3199
3200// An implementation detail of ConceptSpecialicationExpr that holds the template
3201// arguments, so we can later use this to reconstitute the template arguments
3202// during constraint checking.
3204 : public Decl,
3205 private llvm::TrailingObjects<ImplicitConceptSpecializationDecl,
3206 TemplateArgument> {
3207 unsigned NumTemplateArgs;
3208
3210 ArrayRef<TemplateArgument> ConvertedArgs);
3211 ImplicitConceptSpecializationDecl(EmptyShell Empty, unsigned NumTemplateArgs);
3212
3213public:
3216 ArrayRef<TemplateArgument> ConvertedArgs);
3218 CreateDeserialized(const ASTContext &C, unsigned ID,
3219 unsigned NumTemplateArgs);
3220
3222 return ArrayRef<TemplateArgument>(getTrailingObjects<TemplateArgument>(),
3223 NumTemplateArgs);
3224 }
3226
3227 static bool classofKind(Kind K) { return K == ImplicitConceptSpecialization; }
3228 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3229
3231 friend class ASTDeclReader;
3232};
3233
3234/// A template parameter object.
3235///
3236/// Template parameter objects represent values of class type used as template
3237/// arguments. There is one template parameter object for each such distinct
3238/// value used as a template argument across the program.
3239///
3240/// \code
3241/// struct A { int x, y; };
3242/// template<A> struct S;
3243/// S<A{1, 2}> s1;
3244/// S<A{1, 2}> s2; // same type, argument is same TemplateParamObjectDecl.
3245/// \endcode
3247 public Mergeable<TemplateParamObjectDecl>,
3248 public llvm::FoldingSetNode {
3249private:
3250 /// The value of this template parameter object.
3251 APValue Value;
3252
3254 : ValueDecl(TemplateParamObject, DC, SourceLocation(), DeclarationName(),
3255 T),
3256 Value(V) {}
3257
3259 const APValue &V);
3260 static TemplateParamObjectDecl *CreateDeserialized(ASTContext &C,
3261 unsigned ID);
3262
3263 /// Only ASTContext::getTemplateParamObjectDecl and deserialization
3264 /// create these.
3265 friend class ASTContext;
3266 friend class ASTReader;
3267 friend class ASTDeclReader;
3268
3269public:
3270 /// Print this template parameter object in a human-readable format.
3271 void printName(llvm::raw_ostream &OS,
3272 const PrintingPolicy &Policy) const override;
3273
3274 /// Print this object as an equivalent expression.
3275 void printAsExpr(llvm::raw_ostream &OS) const;
3276 void printAsExpr(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const;
3277
3278 /// Print this object as an initializer suitable for a variable of the
3279 /// object's type.
3280 void printAsInit(llvm::raw_ostream &OS) const;
3281 void printAsInit(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const;
3282
3283 const APValue &getValue() const { return Value; }
3284
3285 static void Profile(llvm::FoldingSetNodeID &ID, QualType T,
3286 const APValue &V) {
3287 ID.AddPointer(T.getCanonicalType().getAsOpaquePtr());
3288 V.Profile(ID);
3289 }
3290 void Profile(llvm::FoldingSetNodeID &ID) {
3291 Profile(ID, getType(), getValue());
3292 }
3293
3295 return getFirstDecl();
3296 }
3298 return getFirstDecl();
3299 }
3300
3301 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3302 static bool classofKind(Kind K) { return K == TemplateParamObject; }
3303};
3304
3306 if (auto *PD = P.dyn_cast<TemplateTypeParmDecl *>())
3307 return PD;
3308 if (auto *PD = P.dyn_cast<NonTypeTemplateParmDecl *>())
3309 return PD;
3310 return P.get<TemplateTemplateParmDecl *>();
3311}
3312
3314 auto *TD = dyn_cast<TemplateDecl>(D);
3315 return TD && (isa<ClassTemplateDecl>(TD) ||
3316 isa<ClassTemplatePartialSpecializationDecl>(TD) ||
3317 isa<TypeAliasTemplateDecl>(TD) ||
3318 isa<TemplateTemplateParmDecl>(TD))
3319 ? TD
3320 : nullptr;
3321}
3322
3323/// Check whether the template parameter is a pack expansion, and if so,
3324/// determine the number of parameters produced by that expansion. For instance:
3325///
3326/// \code
3327/// template<typename ...Ts> struct A {
3328/// template<Ts ...NTs, template<Ts> class ...TTs, typename ...Us> struct B;
3329/// };
3330/// \endcode
3331///
3332/// In \c A<int,int>::B, \c NTs and \c TTs have expanded pack size 2, and \c Us
3333/// is not a pack expansion, so returns an empty Optional.
3334inline std::optional<unsigned> getExpandedPackSize(const NamedDecl *Param) {
3335 if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
3336 if (TTP->isExpandedParameterPack())
3337 return TTP->getNumExpansionParameters();
3338 }
3339
3340 if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
3341 if (NTTP->isExpandedParameterPack())
3342 return NTTP->getNumExpansionTypes();
3343 }
3344
3345 if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(Param)) {
3346 if (TTP->isExpandedParameterPack())
3347 return TTP->getNumExpansionTemplateParameters();
3348 }
3349
3350 return std::nullopt;
3351}
3352
3353/// Internal helper used by Subst* nodes to retrieve the parameter list
3354/// for their AssociatedDecl.
3355TemplateParameterList *getReplacedTemplateParameterList(Decl *D);
3356
3357} // namespace clang
3358
3359#endif // LLVM_CLANG_AST_DECLTEMPLATE_H
This file provides AST data structures related to concepts.
Defines the clang::ASTContext interface.
#define V(N, I)
Definition: ASTContext.h:3259
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.
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:5543
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:1904
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 ClassTemplateDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Create an empty class template node.
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...
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)
bool isMemberSpecialization()
Determines whether this class template partial specialization template was a specialization of a memb...
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
void setMemberSpecialization()
Note that this member template is a specialization.
QualType getInjectedSpecializationType() const
Retrieves the injected specialization type for this partial specialization.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Get the template arguments as written.
static ClassTemplatePartialSpecializationDecl * CreateDeserialized(ASTContext &C, unsigned 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.
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, unsigned ID)
SourceLocation getExternLoc() const
Gets the location of the extern keyword, if present.
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 setTypeAsWritten(TypeSourceInfo *T)
Sets the type of this specialization as it was written by the user.
void setPointOfInstantiation(SourceLocation Loc)
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
TypeSourceInfo * getTypeAsWritten() const
Gets the type of this specialization as it was written by the user, if it was so written.
static bool classof(const Decl *D)
void setSpecializationKind(TemplateSpecializationKind TSK)
void setTemplateKeywordLoc(SourceLocation Loc)
Sets the location of the template keyword.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
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.
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 setExternLoc(SourceLocation Loc)
Sets the location of the extern keyword.
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 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, unsigned 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:1446
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:85
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:598
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:88
SourceLocation getLocation() const
Definition: DeclBase.h:444
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition: DeclBase.h:918
Kind getKind() const
Definition: DeclBase.h:447
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
Definition: DeclBase.h:432
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 FriendTemplateDecl * CreateDeserialized(ASTContext &C, unsigned ID)
static bool classofKind(Kind K)
unsigned getNumTemplateParameters() const
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
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:1959
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
Definition: Decl.h:2258
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
static FunctionTemplateDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Create an empty function template node.
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
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, unsigned 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.
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)
static NonTypeTemplateParmDecl * CreateDeserialized(ASTContext &C, unsigned ID, bool HasTypeConstraint)
Represents a pack expansion of types.
Definition: Type.h:6112
A (possibly-)qualified type.
Definition: Type.h:737
QualType getCanonicalType() const
Definition: Type.h:6954
void * getAsOpaquePtr() const
Definition: Type.h:784
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:426
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
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:3647
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.
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 TemplateTemplateParmDecl * CreateDeserialized(ASTContext &C, unsigned ID)
static bool classof(const Decl *D)
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
void setInheritedDefaultArgument(const ASTContext &C, TemplateTemplateParmDecl *Prev)
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 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.
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...
static TemplateTypeParmDecl * CreateDeserialized(const ASTContext &C, unsigned ID)
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:3521
Declaration of an alias template.
static bool classof(const Decl *D)
CommonBase * newCommon(ASTContext &C) const override
static TypeAliasTemplateDecl * CreateDeserialized(ASTContext &C, unsigned 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:3357
const Type * getTypeForDecl() const
Definition: Decl.h:3381
A container of type source information.
Definition: Type.h:6873
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:6884
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type.
Definition: Type.h:2525
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7657
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
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()
static VarTemplateDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Create an empty variable template node.
spec_range specializations() const
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Get the template arguments as written.
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()
Determines whether this variable template partial specialization was a specialization of a member par...
void Profile(llvm::FoldingSetNodeID &ID) const
static VarTemplatePartialSpecializationDecl * CreateDeserialized(ASTContext &C, unsigned ID)
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)
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 setExternLoc(SourceLocation Loc)
Sets the location of the extern keyword.
void setSpecializationKind(TemplateSpecializationKind TSK)
static void Profile(llvm::FoldingSetNodeID &ID, ArrayRef< TemplateArgument > TemplateArgs, const ASTContext &Context)
void setTemplateArgsInfo(const TemplateArgumentListInfo &ArgsInfo)
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...
SourceLocation getExternLoc() const
Gets the location of the extern keyword, if present.
static bool classof(const Decl *D)
void setTypeAsWritten(TypeSourceInfo *T)
Sets the type of this specialization as it was written by the user.
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)
llvm::PointerUnion< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > getSpecializedTemplateOrPartial() const
Retrieve the variable template or variable template partial specialization which was specialized by t...
void setTemplateKeywordLoc(SourceLocation Loc)
Sets the location of the template keyword.
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...
const ASTTemplateArgumentListInfo * getTemplateArgsInfo() const
TypeSourceInfo * getTypeAsWritten() const
Gets the type of this specialization as it was written by the user, if it was so written.
VarTemplateSpecializationDecl * getMostRecentDecl()
static VarTemplateSpecializationDecl * CreateDeserialized(ASTContext &C, unsigned ID)
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
'copyin' 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)
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:5842
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...
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
YAML serialization mapping.
Definition: Dominators.h:30
Definition: Format.h:5304
#define true
Definition: stdbool.h:21
#define false
Definition: stdbool.h:22
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:676
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:101
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
uint32_t * 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 ...