xref: /llvm-project/clang/include/clang/AST/TemplateName.h (revision fa6580470547411667b866362941db0b02e25578)
1 //===- TemplateName.h - C++ Template Name Representation --------*- 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 //  This file defines the TemplateName interface and subclasses.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_AST_TEMPLATENAME_H
14 #define LLVM_CLANG_AST_TEMPLATENAME_H
15 
16 #include "clang/AST/DependenceFlags.h"
17 #include "clang/AST/NestedNameSpecifier.h"
18 #include "clang/Basic/LLVM.h"
19 #include "llvm/ADT/FoldingSet.h"
20 #include "llvm/ADT/PointerIntPair.h"
21 #include "llvm/ADT/PointerUnion.h"
22 #include "llvm/Support/PointerLikeTypeTraits.h"
23 #include <cassert>
24 #include <optional>
25 
26 namespace clang {
27 
28 class ASTContext;
29 class Decl;
30 class DependentTemplateName;
31 class IdentifierInfo;
32 class NamedDecl;
33 class NestedNameSpecifier;
34 enum OverloadedOperatorKind : int;
35 class OverloadedTemplateStorage;
36 class AssumedTemplateStorage;
37 class DeducedTemplateStorage;
38 struct PrintingPolicy;
39 class QualifiedTemplateName;
40 class SubstTemplateTemplateParmPackStorage;
41 class SubstTemplateTemplateParmStorage;
42 class TemplateArgument;
43 class TemplateDecl;
44 class TemplateTemplateParmDecl;
45 class UsingShadowDecl;
46 
47 /// Implementation class used to describe either a set of overloaded
48 /// template names or an already-substituted template template parameter pack.
49 class UncommonTemplateNameStorage {
50 protected:
51   enum Kind {
52     Overloaded,
53     Assumed, // defined in DeclarationName.h
54     Deduced,
55     SubstTemplateTemplateParm,
56     SubstTemplateTemplateParmPack
57   };
58 
59   struct BitsTag {
60     LLVM_PREFERRED_TYPE(Kind)
61     unsigned Kind : 3;
62 
63     // The template parameter index.
64     unsigned Index : 14;
65 
66     /// The pack index, or the number of stored templates
67     /// or template arguments, depending on which subclass we have.
68     unsigned Data : 15;
69   };
70 
71   union {
72     struct BitsTag Bits;
73     void *PointerAlignment;
74   };
75 
76   UncommonTemplateNameStorage(Kind Kind, unsigned Index, unsigned Data) {
77     Bits.Kind = Kind;
78     Bits.Index = Index;
79     Bits.Data = Data;
80   }
81 
82 public:
83   OverloadedTemplateStorage *getAsOverloadedStorage()  {
84     return Bits.Kind == Overloaded
85              ? reinterpret_cast<OverloadedTemplateStorage *>(this)
86              : nullptr;
87   }
88 
89   AssumedTemplateStorage *getAsAssumedTemplateName()  {
90     return Bits.Kind == Assumed
91              ? reinterpret_cast<AssumedTemplateStorage *>(this)
92              : nullptr;
93   }
94 
95   DeducedTemplateStorage *getAsDeducedTemplateName() {
96     return Bits.Kind == Deduced
97                ? reinterpret_cast<DeducedTemplateStorage *>(this)
98                : nullptr;
99   }
100 
101   SubstTemplateTemplateParmStorage *getAsSubstTemplateTemplateParm() {
102     return Bits.Kind == SubstTemplateTemplateParm
103              ? reinterpret_cast<SubstTemplateTemplateParmStorage *>(this)
104              : nullptr;
105   }
106 
107   SubstTemplateTemplateParmPackStorage *getAsSubstTemplateTemplateParmPack() {
108     return Bits.Kind == SubstTemplateTemplateParmPack
109              ? reinterpret_cast<SubstTemplateTemplateParmPackStorage *>(this)
110              : nullptr;
111   }
112 };
113 
114 /// A structure for storing the information associated with an
115 /// overloaded template name.
116 class OverloadedTemplateStorage : public UncommonTemplateNameStorage {
117   friend class ASTContext;
118 
119   OverloadedTemplateStorage(unsigned size)
120       : UncommonTemplateNameStorage(Overloaded, 0, size) {}
121 
122   NamedDecl **getStorage() {
123     return reinterpret_cast<NamedDecl **>(this + 1);
124   }
125   NamedDecl * const *getStorage() const {
126     return reinterpret_cast<NamedDecl *const *>(this + 1);
127   }
128 
129 public:
130   unsigned size() const { return Bits.Data; }
131 
132   using iterator = NamedDecl *const *;
133 
134   iterator begin() const { return getStorage(); }
135   iterator end() const { return getStorage() + Bits.Data; }
136 
137   llvm::ArrayRef<NamedDecl*> decls() const {
138     return llvm::ArrayRef(begin(), end());
139   }
140 };
141 
142 /// A structure for storing an already-substituted template template
143 /// parameter pack.
144 ///
145 /// This kind of template names occurs when the parameter pack has been
146 /// provided with a template template argument pack in a context where its
147 /// enclosing pack expansion could not be fully expanded.
148 class SubstTemplateTemplateParmPackStorage : public UncommonTemplateNameStorage,
149                                              public llvm::FoldingSetNode {
150   const TemplateArgument *Arguments;
151   llvm::PointerIntPair<Decl *, 1, bool> AssociatedDeclAndFinal;
152 
153 public:
154   SubstTemplateTemplateParmPackStorage(ArrayRef<TemplateArgument> ArgPack,
155                                        Decl *AssociatedDecl, unsigned Index,
156                                        bool Final);
157 
158   /// A template-like entity which owns the whole pattern being substituted.
159   /// This will own a set of template parameters.
160   Decl *getAssociatedDecl() const;
161 
162   /// Returns the index of the replaced parameter in the associated declaration.
163   /// This should match the result of `getParameterPack()->getIndex()`.
164   unsigned getIndex() const { return Bits.Index; }
165 
166   // When true the substitution will be 'Final' (subst node won't be placed).
167   bool getFinal() const;
168 
169   /// Retrieve the template template parameter pack being substituted.
170   TemplateTemplateParmDecl *getParameterPack() const;
171 
172   /// Retrieve the template template argument pack with which this
173   /// parameter was substituted.
174   TemplateArgument getArgumentPack() const;
175 
176   void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context);
177 
178   static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
179                       const TemplateArgument &ArgPack, Decl *AssociatedDecl,
180                       unsigned Index, bool Final);
181 };
182 
183 struct DefaultArguments {
184   // The position in the template parameter list
185   // the first argument corresponds to.
186   unsigned StartPos;
187   ArrayRef<TemplateArgument> Args;
188 
189   operator bool() const { return !Args.empty(); }
190 };
191 
192 /// Represents a C++ template name within the type system.
193 ///
194 /// A C++ template name refers to a template within the C++ type
195 /// system. In most cases, a template name is simply a reference to a
196 /// class template, e.g.
197 ///
198 /// \code
199 /// template<typename T> class X { };
200 ///
201 /// X<int> xi;
202 /// \endcode
203 ///
204 /// Here, the 'X' in \c X<int> is a template name that refers to the
205 /// declaration of the class template X, above. Template names can
206 /// also refer to function templates, C++0x template aliases, etc.
207 ///
208 /// Some template names are dependent. For example, consider:
209 ///
210 /// \code
211 /// template<typename MetaFun, typename T1, typename T2> struct apply2 {
212 ///   typedef typename MetaFun::template apply<T1, T2>::type type;
213 /// };
214 /// \endcode
215 ///
216 /// Here, "apply" is treated as a template name within the typename
217 /// specifier in the typedef. "apply" is a nested template, and can
218 /// only be understood in the context of a template instantiation,
219 /// hence is represented as a dependent template name.
220 class TemplateName {
221   // NameDecl is either a TemplateDecl or a UsingShadowDecl depending on the
222   // NameKind.
223   // !! There is no free low bits in 32-bit builds to discriminate more than 4
224   // pointer types in PointerUnion.
225   using StorageType =
226       llvm::PointerUnion<Decl *, UncommonTemplateNameStorage *,
227                          QualifiedTemplateName *, DependentTemplateName *>;
228 
229   StorageType Storage;
230 
231   explicit TemplateName(void *Ptr);
232 
233 public:
234   // Kind of name that is actually stored.
235   enum NameKind {
236     /// A single template declaration.
237     Template,
238 
239     /// A set of overloaded template declarations.
240     OverloadedTemplate,
241 
242     /// An unqualified-id that has been assumed to name a function template
243     /// that will be found by ADL.
244     AssumedTemplate,
245 
246     /// A qualified template name, where the qualification is kept
247     /// to describe the source code as written.
248     QualifiedTemplate,
249 
250     /// A dependent template name that has not been resolved to a
251     /// template (or set of templates).
252     DependentTemplate,
253 
254     /// A template template parameter that has been substituted
255     /// for some other template name.
256     SubstTemplateTemplateParm,
257 
258     /// A template template parameter pack that has been substituted for
259     /// a template template argument pack, but has not yet been expanded into
260     /// individual arguments.
261     SubstTemplateTemplateParmPack,
262 
263     /// A template name that refers to a template declaration found through a
264     /// specific using shadow declaration.
265     UsingTemplate,
266 
267     /// A template name that refers to another TemplateName with deduced default
268     /// arguments.
269     DeducedTemplate,
270   };
271 
272   TemplateName() = default;
273   explicit TemplateName(TemplateDecl *Template);
274   explicit TemplateName(OverloadedTemplateStorage *Storage);
275   explicit TemplateName(AssumedTemplateStorage *Storage);
276   explicit TemplateName(SubstTemplateTemplateParmStorage *Storage);
277   explicit TemplateName(SubstTemplateTemplateParmPackStorage *Storage);
278   explicit TemplateName(QualifiedTemplateName *Qual);
279   explicit TemplateName(DependentTemplateName *Dep);
280   explicit TemplateName(UsingShadowDecl *Using);
281   explicit TemplateName(DeducedTemplateStorage *Deduced);
282 
283   /// Determine whether this template name is NULL.
284   bool isNull() const;
285 
286   // Get the kind of name that is actually stored.
287   NameKind getKind() const;
288 
289   /// Retrieve the underlying template declaration that
290   /// this template name refers to, if known.
291   ///
292   /// \returns The template declaration that this template name refers
293   /// to, if any. If the template name does not refer to a specific
294   /// declaration because it is a dependent name, or if it refers to a
295   /// set of function templates, returns NULL.
296   TemplateDecl *getAsTemplateDecl(bool IgnoreDeduced = false) const;
297 
298   /// Retrieves the underlying template declaration that
299   /// this template name refers to, along with the
300   /// deduced default arguments, if any.
301   std::pair<TemplateDecl *, DefaultArguments>
302   getTemplateDeclAndDefaultArgs() const;
303 
304   /// Retrieve the underlying, overloaded function template
305   /// declarations that this template name refers to, if known.
306   ///
307   /// \returns The set of overloaded function templates that this template
308   /// name refers to, if known. If the template name does not refer to a
309   /// specific set of function templates because it is a dependent name or
310   /// refers to a single template, returns NULL.
311   OverloadedTemplateStorage *getAsOverloadedTemplate() const;
312 
313   /// Retrieve information on a name that has been assumed to be a
314   /// template-name in order to permit a call via ADL.
315   AssumedTemplateStorage *getAsAssumedTemplateName() const;
316 
317   /// Retrieve the substituted template template parameter, if
318   /// known.
319   ///
320   /// \returns The storage for the substituted template template parameter,
321   /// if known. Otherwise, returns NULL.
322   SubstTemplateTemplateParmStorage *getAsSubstTemplateTemplateParm() const;
323 
324   /// Retrieve the substituted template template parameter pack, if
325   /// known.
326   ///
327   /// \returns The storage for the substituted template template parameter pack,
328   /// if known. Otherwise, returns NULL.
329   SubstTemplateTemplateParmPackStorage *
330   getAsSubstTemplateTemplateParmPack() const;
331 
332   /// Retrieve the underlying qualified template name
333   /// structure, if any.
334   QualifiedTemplateName *getAsQualifiedTemplateName() const;
335 
336   /// Retrieve the underlying dependent template name
337   /// structure, if any.
338   DependentTemplateName *getAsDependentTemplateName() const;
339 
340   /// Retrieve the using shadow declaration through which the underlying
341   /// template declaration is introduced, if any.
342   UsingShadowDecl *getAsUsingShadowDecl() const;
343 
344   /// Retrieve the deduced template info, if any.
345   DeducedTemplateStorage *getAsDeducedTemplateName() const;
346 
347   std::optional<TemplateName> desugar(bool IgnoreDeduced) const;
348 
349   TemplateName getUnderlying() const;
350 
351   TemplateNameDependence getDependence() const;
352 
353   /// Determines whether this is a dependent template name.
354   bool isDependent() const;
355 
356   /// Determines whether this is a template name that somehow
357   /// depends on a template parameter.
358   bool isInstantiationDependent() const;
359 
360   /// Determines whether this template name contains an
361   /// unexpanded parameter pack (for C++0x variadic templates).
362   bool containsUnexpandedParameterPack() const;
363 
364   enum class Qualified { None, AsWritten };
365   /// Print the template name.
366   ///
367   /// \param OS the output stream to which the template name will be
368   /// printed.
369   ///
370   /// \param Qual print the (Qualified::None) simple name,
371   /// (Qualified::AsWritten) any written (possibly partial) qualifier, or
372   /// (Qualified::Fully) the fully qualified name.
373   void print(raw_ostream &OS, const PrintingPolicy &Policy,
374              Qualified Qual = Qualified::AsWritten) const;
375 
376   /// Debugging aid that dumps the template name.
377   void dump(raw_ostream &OS, const ASTContext &Context) const;
378 
379   /// Debugging aid that dumps the template name to standard
380   /// error.
381   void dump() const;
382 
383   void Profile(llvm::FoldingSetNodeID &ID) {
384     ID.AddPointer(Storage.getOpaqueValue());
385   }
386 
387   /// Retrieve the template name as a void pointer.
388   void *getAsVoidPointer() const { return Storage.getOpaqueValue(); }
389 
390   /// Build a template name from a void pointer.
391   static TemplateName getFromVoidPointer(void *Ptr) {
392     return TemplateName(Ptr);
393   }
394 
395   /// Structural equality.
396   bool operator==(TemplateName Other) const { return Storage == Other.Storage; }
397   bool operator!=(TemplateName Other) const { return !operator==(Other); }
398 };
399 
400 /// Insertion operator for diagnostics.  This allows sending TemplateName's
401 /// into a diagnostic with <<.
402 const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
403                                       TemplateName N);
404 
405 /// A structure for storing the information associated with a
406 /// substituted template template parameter.
407 class SubstTemplateTemplateParmStorage
408   : public UncommonTemplateNameStorage, public llvm::FoldingSetNode {
409   friend class ASTContext;
410 
411   TemplateName Replacement;
412   Decl *AssociatedDecl;
413 
414   SubstTemplateTemplateParmStorage(TemplateName Replacement,
415                                    Decl *AssociatedDecl, unsigned Index,
416                                    std::optional<unsigned> PackIndex)
417       : UncommonTemplateNameStorage(SubstTemplateTemplateParm, Index,
418                                     PackIndex ? *PackIndex + 1 : 0),
419         Replacement(Replacement), AssociatedDecl(AssociatedDecl) {
420     assert(AssociatedDecl != nullptr);
421   }
422 
423 public:
424   /// A template-like entity which owns the whole pattern being substituted.
425   /// This will own a set of template parameters.
426   Decl *getAssociatedDecl() const { return AssociatedDecl; }
427 
428   /// Returns the index of the replaced parameter in the associated declaration.
429   /// This should match the result of `getParameter()->getIndex()`.
430   unsigned getIndex() const { return Bits.Index; }
431 
432   std::optional<unsigned> getPackIndex() const {
433     if (Bits.Data == 0)
434       return std::nullopt;
435     return Bits.Data - 1;
436   }
437 
438   TemplateTemplateParmDecl *getParameter() const;
439   TemplateName getReplacement() const { return Replacement; }
440 
441   void Profile(llvm::FoldingSetNodeID &ID);
442 
443   static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Replacement,
444                       Decl *AssociatedDecl, unsigned Index,
445                       std::optional<unsigned> PackIndex);
446 };
447 
448 class DeducedTemplateStorage : public UncommonTemplateNameStorage,
449                                public llvm::FoldingSetNode {
450   friend class ASTContext;
451 
452   TemplateName Underlying;
453 
454   DeducedTemplateStorage(TemplateName Underlying,
455                          const DefaultArguments &DefArgs);
456 
457 public:
458   TemplateName getUnderlying() const { return Underlying; }
459 
460   DefaultArguments getDefaultArguments() const {
461     return {/*StartPos=*/Bits.Index,
462             /*Args=*/{reinterpret_cast<const TemplateArgument *>(this + 1),
463                       Bits.Data}};
464   }
465 
466   void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) const;
467 
468   static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
469                       TemplateName Underlying, const DefaultArguments &DefArgs);
470 };
471 
472 inline TemplateName TemplateName::getUnderlying() const {
473   if (SubstTemplateTemplateParmStorage *subst
474         = getAsSubstTemplateTemplateParm())
475     return subst->getReplacement().getUnderlying();
476   return *this;
477 }
478 
479 /// Represents a template name as written in source code.
480 ///
481 /// This kind of template name may refer to a template name that was
482 /// preceded by a nested name specifier, e.g., \c std::vector. Here,
483 /// the nested name specifier is "std::" and the template name is the
484 /// declaration for "vector". It may also have been written with the
485 /// 'template' keyword. The QualifiedTemplateName class is only
486 /// used to provide "sugar" for template names, so that they can
487 /// be differentiated from canonical template names. and has no
488 /// semantic meaning. In this manner, it is to TemplateName what
489 /// ElaboratedType is to Type, providing extra syntactic sugar
490 /// for downstream clients.
491 class QualifiedTemplateName : public llvm::FoldingSetNode {
492   friend class ASTContext;
493 
494   /// The nested name specifier that qualifies the template name.
495   ///
496   /// The bit is used to indicate whether the "template" keyword was
497   /// present before the template name itself. Note that the
498   /// "template" keyword is always redundant in this case (otherwise,
499   /// the template name would be a dependent name and we would express
500   /// this name with DependentTemplateName).
501   llvm::PointerIntPair<NestedNameSpecifier *, 1> Qualifier;
502 
503   /// The underlying template name, it is either
504   ///  1) a Template -- a template declaration that this qualified name refers
505   ///     to.
506   ///  2) or a UsingTemplate -- a template declaration introduced by a
507   ///     using-shadow declaration.
508   TemplateName UnderlyingTemplate;
509 
510   QualifiedTemplateName(NestedNameSpecifier *NNS, bool TemplateKeyword,
511                         TemplateName Template)
512       : Qualifier(NNS, TemplateKeyword ? 1 : 0), UnderlyingTemplate(Template) {
513     assert(UnderlyingTemplate.getKind() == TemplateName::Template ||
514            UnderlyingTemplate.getKind() == TemplateName::UsingTemplate);
515   }
516 
517 public:
518   /// Return the nested name specifier that qualifies this name.
519   NestedNameSpecifier *getQualifier() const { return Qualifier.getPointer(); }
520 
521   /// Whether the template name was prefixed by the "template"
522   /// keyword.
523   bool hasTemplateKeyword() const { return Qualifier.getInt(); }
524 
525   /// Return the underlying template name.
526   TemplateName getUnderlyingTemplate() const { return UnderlyingTemplate; }
527 
528   void Profile(llvm::FoldingSetNodeID &ID) {
529     Profile(ID, getQualifier(), hasTemplateKeyword(), UnderlyingTemplate);
530   }
531 
532   static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS,
533                       bool TemplateKeyword, TemplateName TN) {
534     ID.AddPointer(NNS);
535     ID.AddBoolean(TemplateKeyword);
536     ID.AddPointer(TN.getAsVoidPointer());
537   }
538 };
539 
540 /// Represents a dependent template name that cannot be
541 /// resolved prior to template instantiation.
542 ///
543 /// This kind of template name refers to a dependent template name,
544 /// including its nested name specifier (if any). For example,
545 /// DependentTemplateName can refer to "MetaFun::template apply",
546 /// where "MetaFun::" is the nested name specifier and "apply" is the
547 /// template name referenced. The "template" keyword is implied.
548 class DependentTemplateName : public llvm::FoldingSetNode {
549   friend class ASTContext;
550 
551   /// The nested name specifier that qualifies the template
552   /// name.
553   ///
554   /// The bit stored in this qualifier describes whether the \c Name field
555   /// is interpreted as an IdentifierInfo pointer (when clear) or as an
556   /// overloaded operator kind (when set).
557   llvm::PointerIntPair<NestedNameSpecifier *, 1, bool> Qualifier;
558 
559   /// The dependent template name.
560   union {
561     /// The identifier template name.
562     ///
563     /// Only valid when the bit on \c Qualifier is clear.
564     const IdentifierInfo *Identifier;
565 
566     /// The overloaded operator name.
567     ///
568     /// Only valid when the bit on \c Qualifier is set.
569     OverloadedOperatorKind Operator;
570   };
571 
572   /// The canonical template name to which this dependent
573   /// template name refers.
574   ///
575   /// The canonical template name for a dependent template name is
576   /// another dependent template name whose nested name specifier is
577   /// canonical.
578   TemplateName CanonicalTemplateName;
579 
580   DependentTemplateName(NestedNameSpecifier *Qualifier,
581                         const IdentifierInfo *Identifier)
582       : Qualifier(Qualifier, false), Identifier(Identifier),
583         CanonicalTemplateName(this) {}
584 
585   DependentTemplateName(NestedNameSpecifier *Qualifier,
586                         const IdentifierInfo *Identifier,
587                         TemplateName Canon)
588       : Qualifier(Qualifier, false), Identifier(Identifier),
589         CanonicalTemplateName(Canon) {}
590 
591   DependentTemplateName(NestedNameSpecifier *Qualifier,
592                         OverloadedOperatorKind Operator)
593       : Qualifier(Qualifier, true), Operator(Operator),
594         CanonicalTemplateName(this) {}
595 
596   DependentTemplateName(NestedNameSpecifier *Qualifier,
597                         OverloadedOperatorKind Operator,
598                         TemplateName Canon)
599        : Qualifier(Qualifier, true), Operator(Operator),
600          CanonicalTemplateName(Canon) {}
601 
602 public:
603   /// Return the nested name specifier that qualifies this name.
604   NestedNameSpecifier *getQualifier() const { return Qualifier.getPointer(); }
605 
606   /// Determine whether this template name refers to an identifier.
607   bool isIdentifier() const { return !Qualifier.getInt(); }
608 
609   /// Returns the identifier to which this template name refers.
610   const IdentifierInfo *getIdentifier() const {
611     assert(isIdentifier() && "Template name isn't an identifier?");
612     return Identifier;
613   }
614 
615   /// Determine whether this template name refers to an overloaded
616   /// operator.
617   bool isOverloadedOperator() const { return Qualifier.getInt(); }
618 
619   /// Return the overloaded operator to which this template name refers.
620   OverloadedOperatorKind getOperator() const {
621     assert(isOverloadedOperator() &&
622            "Template name isn't an overloaded operator?");
623     return Operator;
624   }
625 
626   void Profile(llvm::FoldingSetNodeID &ID) {
627     if (isIdentifier())
628       Profile(ID, getQualifier(), getIdentifier());
629     else
630       Profile(ID, getQualifier(), getOperator());
631   }
632 
633   static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS,
634                       const IdentifierInfo *Identifier) {
635     ID.AddPointer(NNS);
636     ID.AddBoolean(false);
637     ID.AddPointer(Identifier);
638   }
639 
640   static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS,
641                       OverloadedOperatorKind Operator) {
642     ID.AddPointer(NNS);
643     ID.AddBoolean(true);
644     ID.AddInteger(Operator);
645   }
646 };
647 
648 } // namespace clang.
649 
650 namespace llvm {
651 
652 /// The clang::TemplateName class is effectively a pointer.
653 template<>
654 struct PointerLikeTypeTraits<clang::TemplateName> {
655   static inline void *getAsVoidPointer(clang::TemplateName TN) {
656     return TN.getAsVoidPointer();
657   }
658 
659   static inline clang::TemplateName getFromVoidPointer(void *Ptr) {
660     return clang::TemplateName::getFromVoidPointer(Ptr);
661   }
662 
663   // No bits are available!
664   static constexpr int NumLowBitsAvailable = 0;
665 };
666 
667 } // namespace llvm.
668 
669 #endif // LLVM_CLANG_AST_TEMPLATENAME_H
670