]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/AST/DeclCXX.h
Import Intel Processor Trace decoder library from
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / AST / DeclCXX.h
1 //===- DeclCXX.h - Classes for representing C++ declarations --*- C++ -*-=====//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// \file
11 /// \brief Defines the C++ Decl subclasses, other than those for templates
12 /// (found in DeclTemplate.h) and friends (in DeclFriend.h).
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_CLANG_AST_DECLCXX_H
17 #define LLVM_CLANG_AST_DECLCXX_H
18
19 #include "clang/AST/ASTContext.h"
20 #include "clang/AST/ASTUnresolvedSet.h"
21 #include "clang/AST/Attr.h"
22 #include "clang/AST/Decl.h"
23 #include "clang/AST/DeclarationName.h"
24 #include "clang/AST/Expr.h"
25 #include "clang/AST/ExternalASTSource.h"
26 #include "clang/AST/LambdaCapture.h"
27 #include "clang/AST/NestedNameSpecifier.h"
28 #include "clang/AST/Redeclarable.h"
29 #include "clang/AST/Stmt.h"
30 #include "clang/AST/Type.h"
31 #include "clang/AST/TypeLoc.h"
32 #include "clang/AST/UnresolvedSet.h"
33 #include "clang/Basic/LLVM.h"
34 #include "clang/Basic/Lambda.h"
35 #include "clang/Basic/LangOptions.h"
36 #include "clang/Basic/OperatorKinds.h"
37 #include "clang/Basic/SourceLocation.h"
38 #include "clang/Basic/Specifiers.h"
39 #include "llvm/ADT/ArrayRef.h"
40 #include "llvm/ADT/DenseMap.h"
41 #include "llvm/ADT/PointerIntPair.h"
42 #include "llvm/ADT/PointerUnion.h"
43 #include "llvm/ADT/STLExtras.h"
44 #include "llvm/ADT/iterator_range.h"
45 #include "llvm/Support/Casting.h"
46 #include "llvm/Support/Compiler.h"
47 #include "llvm/Support/PointerLikeTypeTraits.h"
48 #include "llvm/Support/TrailingObjects.h"
49 #include <cassert>
50 #include <cstddef>
51 #include <iterator>
52 #include <memory>
53 #include <vector>
54
55 namespace clang {
56
57 class ClassTemplateDecl;
58 class ConstructorUsingShadowDecl;
59 class CXXBasePath;
60 class CXXBasePaths;
61 class CXXConstructorDecl;
62 class CXXDestructorDecl;
63 class CXXFinalOverriderMap;
64 class CXXIndirectPrimaryBaseSet;
65 class CXXMethodDecl;
66 class DiagnosticBuilder;
67 class FriendDecl;
68 class FunctionTemplateDecl;
69 class IdentifierInfo;
70 class MemberSpecializationInfo;
71 class TemplateDecl;
72 class TemplateParameterList;
73 class UsingDecl;
74
75 /// \brief Represents any kind of function declaration, whether it is a
76 /// concrete function or a function template.
77 class AnyFunctionDecl {
78   NamedDecl *Function;
79
80   AnyFunctionDecl(NamedDecl *ND) : Function(ND) {}
81
82 public:
83   AnyFunctionDecl(FunctionDecl *FD) : Function(FD) {}
84   AnyFunctionDecl(FunctionTemplateDecl *FTD);
85
86   /// \brief Implicily converts any function or function template into a
87   /// named declaration.
88   operator NamedDecl *() const { return Function; }
89
90   /// \brief Retrieve the underlying function or function template.
91   NamedDecl *get() const { return Function; }
92
93   static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
94     return AnyFunctionDecl(ND);
95   }
96 };
97
98 } // namespace clang
99
100 namespace llvm {
101
102   // Provide PointerLikeTypeTraits for non-cvr pointers.
103   template<>
104   struct PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
105     static void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
106       return F.get();
107     }
108
109     static ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
110       return ::clang::AnyFunctionDecl::getFromNamedDecl(
111                                       static_cast< ::clang::NamedDecl*>(P));
112     }
113
114     enum { NumLowBitsAvailable = 2 };
115   };
116
117 } // namespace llvm
118
119 namespace clang {
120
121 /// \brief Represents an access specifier followed by colon ':'.
122 ///
123 /// An objects of this class represents sugar for the syntactic occurrence
124 /// of an access specifier followed by a colon in the list of member
125 /// specifiers of a C++ class definition.
126 ///
127 /// Note that they do not represent other uses of access specifiers,
128 /// such as those occurring in a list of base specifiers.
129 /// Also note that this class has nothing to do with so-called
130 /// "access declarations" (C++98 11.3 [class.access.dcl]).
131 class AccessSpecDecl : public Decl {
132   /// \brief The location of the ':'.
133   SourceLocation ColonLoc;
134
135   AccessSpecDecl(AccessSpecifier AS, DeclContext *DC,
136                  SourceLocation ASLoc, SourceLocation ColonLoc)
137     : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) {
138     setAccess(AS);
139   }
140
141   AccessSpecDecl(EmptyShell Empty) : Decl(AccessSpec, Empty) {}
142
143   virtual void anchor();
144
145 public:
146   /// \brief The location of the access specifier.
147   SourceLocation getAccessSpecifierLoc() const { return getLocation(); }
148
149   /// \brief Sets the location of the access specifier.
150   void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); }
151
152   /// \brief The location of the colon following the access specifier.
153   SourceLocation getColonLoc() const { return ColonLoc; }
154
155   /// \brief Sets the location of the colon.
156   void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; }
157
158   SourceRange getSourceRange() const override LLVM_READONLY {
159     return SourceRange(getAccessSpecifierLoc(), getColonLoc());
160   }
161
162   static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS,
163                                 DeclContext *DC, SourceLocation ASLoc,
164                                 SourceLocation ColonLoc) {
165     return new (C, DC) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
166   }
167
168   static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
169
170   // Implement isa/cast/dyncast/etc.
171   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
172   static bool classofKind(Kind K) { return K == AccessSpec; }
173 };
174
175 /// \brief Represents a base class of a C++ class.
176 ///
177 /// Each CXXBaseSpecifier represents a single, direct base class (or
178 /// struct) of a C++ class (or struct). It specifies the type of that
179 /// base class, whether it is a virtual or non-virtual base, and what
180 /// level of access (public, protected, private) is used for the
181 /// derivation. For example:
182 ///
183 /// \code
184 ///   class A { };
185 ///   class B { };
186 ///   class C : public virtual A, protected B { };
187 /// \endcode
188 ///
189 /// In this code, C will have two CXXBaseSpecifiers, one for "public
190 /// virtual A" and the other for "protected B".
191 class CXXBaseSpecifier {
192   /// \brief The source code range that covers the full base
193   /// specifier, including the "virtual" (if present) and access
194   /// specifier (if present).
195   SourceRange Range;
196
197   /// \brief The source location of the ellipsis, if this is a pack
198   /// expansion.
199   SourceLocation EllipsisLoc;
200
201   /// \brief Whether this is a virtual base class or not.
202   unsigned Virtual : 1;
203
204   /// \brief Whether this is the base of a class (true) or of a struct (false).
205   ///
206   /// This determines the mapping from the access specifier as written in the
207   /// source code to the access specifier used for semantic analysis.
208   unsigned BaseOfClass : 1;
209
210   /// \brief Access specifier as written in the source code (may be AS_none).
211   ///
212   /// The actual type of data stored here is an AccessSpecifier, but we use
213   /// "unsigned" here to work around a VC++ bug.
214   unsigned Access : 2;
215
216   /// \brief Whether the class contains a using declaration
217   /// to inherit the named class's constructors.
218   unsigned InheritConstructors : 1;
219
220   /// \brief The type of the base class.
221   ///
222   /// This will be a class or struct (or a typedef of such). The source code
223   /// range does not include the \c virtual or the access specifier.
224   TypeSourceInfo *BaseTypeInfo;
225
226 public:
227   CXXBaseSpecifier() = default;
228   CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A,
229                    TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
230     : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC),
231       Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) {}
232
233   /// \brief Retrieves the source range that contains the entire base specifier.
234   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
235   SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
236   SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
237
238   /// \brief Get the location at which the base class type was written.
239   SourceLocation getBaseTypeLoc() const LLVM_READONLY {
240     return BaseTypeInfo->getTypeLoc().getLocStart();
241   }
242
243   /// \brief Determines whether the base class is a virtual base class (or not).
244   bool isVirtual() const { return Virtual; }
245
246   /// \brief Determine whether this base class is a base of a class declared
247   /// with the 'class' keyword (vs. one declared with the 'struct' keyword).
248   bool isBaseOfClass() const { return BaseOfClass; }
249
250   /// \brief Determine whether this base specifier is a pack expansion.
251   bool isPackExpansion() const { return EllipsisLoc.isValid(); }
252
253   /// \brief Determine whether this base class's constructors get inherited.
254   bool getInheritConstructors() const { return InheritConstructors; }
255
256   /// \brief Set that this base class's constructors should be inherited.
257   void setInheritConstructors(bool Inherit = true) {
258     InheritConstructors = Inherit;
259   }
260
261   /// \brief For a pack expansion, determine the location of the ellipsis.
262   SourceLocation getEllipsisLoc() const {
263     return EllipsisLoc;
264   }
265
266   /// \brief Returns the access specifier for this base specifier. 
267   ///
268   /// This is the actual base specifier as used for semantic analysis, so
269   /// the result can never be AS_none. To retrieve the access specifier as
270   /// written in the source code, use getAccessSpecifierAsWritten().
271   AccessSpecifier getAccessSpecifier() const {
272     if ((AccessSpecifier)Access == AS_none)
273       return BaseOfClass? AS_private : AS_public;
274     else
275       return (AccessSpecifier)Access;
276   }
277
278   /// \brief Retrieves the access specifier as written in the source code
279   /// (which may mean that no access specifier was explicitly written).
280   ///
281   /// Use getAccessSpecifier() to retrieve the access specifier for use in
282   /// semantic analysis.
283   AccessSpecifier getAccessSpecifierAsWritten() const {
284     return (AccessSpecifier)Access;
285   }
286
287   /// \brief Retrieves the type of the base class.
288   ///
289   /// This type will always be an unqualified class type.
290   QualType getType() const {
291     return BaseTypeInfo->getType().getUnqualifiedType();
292   }
293
294   /// \brief Retrieves the type and source location of the base class.
295   TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; }
296 };
297
298 /// \brief Represents a C++ struct/union/class.
299 class CXXRecordDecl : public RecordDecl {
300   friend class ASTDeclReader;
301   friend class ASTDeclWriter;
302   friend class ASTNodeImporter;
303   friend class ASTReader;
304   friend class ASTRecordWriter;
305   friend class ASTWriter;
306   friend class DeclContext;
307   friend class LambdaExpr;
308
309   friend void FunctionDecl::setPure(bool);
310   friend void TagDecl::startDefinition();
311
312   /// Values used in DefinitionData fields to represent special members.
313   enum SpecialMemberFlags {
314     SMF_DefaultConstructor = 0x1,
315     SMF_CopyConstructor = 0x2,
316     SMF_MoveConstructor = 0x4,
317     SMF_CopyAssignment = 0x8,
318     SMF_MoveAssignment = 0x10,
319     SMF_Destructor = 0x20,
320     SMF_All = 0x3f
321   };
322
323   struct DefinitionData {
324     /// \brief True if this class has any user-declared constructors.
325     unsigned UserDeclaredConstructor : 1;
326
327     /// \brief The user-declared special members which this class has.
328     unsigned UserDeclaredSpecialMembers : 6;
329
330     /// \brief True when this class is an aggregate.
331     unsigned Aggregate : 1;
332
333     /// \brief True when this class is a POD-type.
334     unsigned PlainOldData : 1;
335
336     /// true when this class is empty for traits purposes,
337     /// i.e. has no data members other than 0-width bit-fields, has no
338     /// virtual function/base, and doesn't inherit from a non-empty
339     /// class. Doesn't take union-ness into account.
340     unsigned Empty : 1;
341
342     /// \brief True when this class is polymorphic, i.e., has at
343     /// least one virtual member or derives from a polymorphic class.
344     unsigned Polymorphic : 1;
345
346     /// \brief True when this class is abstract, i.e., has at least
347     /// one pure virtual function, (that can come from a base class).
348     unsigned Abstract : 1;
349
350     /// \brief True when this class has standard layout.
351     ///
352     /// C++11 [class]p7.  A standard-layout class is a class that:
353     /// * has no non-static data members of type non-standard-layout class (or
354     ///   array of such types) or reference,
355     /// * has no virtual functions (10.3) and no virtual base classes (10.1),
356     /// * has the same access control (Clause 11) for all non-static data
357     ///   members
358     /// * has no non-standard-layout base classes,
359     /// * either has no non-static data members in the most derived class and at
360     ///   most one base class with non-static data members, or has no base
361     ///   classes with non-static data members, and
362     /// * has no base classes of the same type as the first non-static data
363     ///   member.
364     unsigned IsStandardLayout : 1;
365
366     /// \brief True when there are no non-empty base classes.
367     ///
368     /// This is a helper bit of state used to implement IsStandardLayout more
369     /// efficiently.
370     unsigned HasNoNonEmptyBases : 1;
371
372     /// \brief True when there are private non-static data members.
373     unsigned HasPrivateFields : 1;
374
375     /// \brief True when there are protected non-static data members.
376     unsigned HasProtectedFields : 1;
377
378     /// \brief True when there are private non-static data members.
379     unsigned HasPublicFields : 1;
380
381     /// \brief True if this class (or any subobject) has mutable fields.
382     unsigned HasMutableFields : 1;
383
384     /// \brief True if this class (or any nested anonymous struct or union)
385     /// has variant members.
386     unsigned HasVariantMembers : 1;
387
388     /// \brief True if there no non-field members declared by the user.
389     unsigned HasOnlyCMembers : 1;
390
391     /// \brief True if any field has an in-class initializer, including those
392     /// within anonymous unions or structs.
393     unsigned HasInClassInitializer : 1;
394
395     /// \brief True if any field is of reference type, and does not have an
396     /// in-class initializer.
397     ///
398     /// In this case, value-initialization of this class is illegal in C++98
399     /// even if the class has a trivial default constructor.
400     unsigned HasUninitializedReferenceMember : 1;
401
402     /// \brief True if any non-mutable field whose type doesn't have a user-
403     /// provided default ctor also doesn't have an in-class initializer.
404     unsigned HasUninitializedFields : 1;
405
406     /// \brief True if there are any member using-declarations that inherit
407     /// constructors from a base class.
408     unsigned HasInheritedConstructor : 1;
409
410     /// \brief True if there are any member using-declarations named
411     /// 'operator='.
412     unsigned HasInheritedAssignment : 1;
413
414     /// \brief These flags are \c true if a defaulted corresponding special
415     /// member can't be fully analyzed without performing overload resolution.
416     /// @{
417     unsigned NeedOverloadResolutionForCopyConstructor : 1;
418     unsigned NeedOverloadResolutionForMoveConstructor : 1;
419     unsigned NeedOverloadResolutionForMoveAssignment : 1;
420     unsigned NeedOverloadResolutionForDestructor : 1;
421     /// @}
422
423     /// \brief These flags are \c true if an implicit defaulted corresponding
424     /// special member would be defined as deleted.
425     /// @{
426     unsigned DefaultedCopyConstructorIsDeleted : 1;
427     unsigned DefaultedMoveConstructorIsDeleted : 1;
428     unsigned DefaultedMoveAssignmentIsDeleted : 1;
429     unsigned DefaultedDestructorIsDeleted : 1;
430     /// @}
431
432     /// \brief The trivial special members which this class has, per
433     /// C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25,
434     /// C++11 [class.dtor]p5, or would have if the member were not suppressed.
435     ///
436     /// This excludes any user-declared but not user-provided special members
437     /// which have been declared but not yet defined.
438     unsigned HasTrivialSpecialMembers : 6;
439
440     /// \brief The declared special members of this class which are known to be
441     /// non-trivial.
442     ///
443     /// This excludes any user-declared but not user-provided special members
444     /// which have been declared but not yet defined, and any implicit special
445     /// members which have not yet been declared.
446     unsigned DeclaredNonTrivialSpecialMembers : 6;
447
448     /// \brief True when this class has a destructor with no semantic effect.
449     unsigned HasIrrelevantDestructor : 1;
450
451     /// \brief True when this class has at least one user-declared constexpr
452     /// constructor which is neither the copy nor move constructor.
453     unsigned HasConstexprNonCopyMoveConstructor : 1;
454
455     /// \brief True if this class has a (possibly implicit) defaulted default
456     /// constructor.
457     unsigned HasDefaultedDefaultConstructor : 1;
458
459     /// \brief True if this class can be passed in a non-address-preserving
460     /// fashion (such as in registers) according to the C++ language rules.
461     /// This does not imply anything about how the ABI in use will actually
462     /// pass an object of this class.
463     unsigned CanPassInRegisters : 1;
464
465     /// \brief True if a defaulted default constructor for this class would
466     /// be constexpr.
467     unsigned DefaultedDefaultConstructorIsConstexpr : 1;
468
469     /// \brief True if this class has a constexpr default constructor.
470     ///
471     /// This is true for either a user-declared constexpr default constructor
472     /// or an implicitly declared constexpr default constructor.
473     unsigned HasConstexprDefaultConstructor : 1;
474
475     /// \brief True when this class contains at least one non-static data
476     /// member or base class of non-literal or volatile type.
477     unsigned HasNonLiteralTypeFieldsOrBases : 1;
478
479     /// \brief True when visible conversion functions are already computed
480     /// and are available.
481     unsigned ComputedVisibleConversions : 1;
482
483     /// \brief Whether we have a C++11 user-provided default constructor (not
484     /// explicitly deleted or defaulted).
485     unsigned UserProvidedDefaultConstructor : 1;
486
487     /// \brief The special members which have been declared for this class,
488     /// either by the user or implicitly.
489     unsigned DeclaredSpecialMembers : 6;
490
491     /// \brief Whether an implicit copy constructor could have a const-qualified
492     /// parameter, for initializing virtual bases and for other subobjects.
493     unsigned ImplicitCopyConstructorCanHaveConstParamForVBase : 1;
494     unsigned ImplicitCopyConstructorCanHaveConstParamForNonVBase : 1;
495
496     /// \brief Whether an implicit copy assignment operator would have a
497     /// const-qualified parameter.
498     unsigned ImplicitCopyAssignmentHasConstParam : 1;
499
500     /// \brief Whether any declared copy constructor has a const-qualified
501     /// parameter.
502     unsigned HasDeclaredCopyConstructorWithConstParam : 1;
503
504     /// \brief Whether any declared copy assignment operator has either a
505     /// const-qualified reference parameter or a non-reference parameter.
506     unsigned HasDeclaredCopyAssignmentWithConstParam : 1;
507
508     /// \brief Whether this class describes a C++ lambda.
509     unsigned IsLambda : 1;
510
511     /// \brief Whether we are currently parsing base specifiers.
512     unsigned IsParsingBaseSpecifiers : 1;
513
514     unsigned HasODRHash : 1;
515
516     /// \brief A hash of parts of the class to help in ODR checking.
517     unsigned ODRHash = 0;
518
519     /// \brief The number of base class specifiers in Bases.
520     unsigned NumBases = 0;
521
522     /// \brief The number of virtual base class specifiers in VBases.
523     unsigned NumVBases = 0;
524
525     /// \brief Base classes of this class.
526     ///
527     /// FIXME: This is wasted space for a union.
528     LazyCXXBaseSpecifiersPtr Bases;
529
530     /// \brief direct and indirect virtual base classes of this class.
531     LazyCXXBaseSpecifiersPtr VBases;
532
533     /// \brief The conversion functions of this C++ class (but not its
534     /// inherited conversion functions).
535     ///
536     /// Each of the entries in this overload set is a CXXConversionDecl.
537     LazyASTUnresolvedSet Conversions;
538
539     /// \brief The conversion functions of this C++ class and all those
540     /// inherited conversion functions that are visible in this class.
541     ///
542     /// Each of the entries in this overload set is a CXXConversionDecl or a
543     /// FunctionTemplateDecl.
544     LazyASTUnresolvedSet VisibleConversions;
545
546     /// \brief The declaration which defines this record.
547     CXXRecordDecl *Definition;
548
549     /// \brief The first friend declaration in this class, or null if there
550     /// aren't any. 
551     ///
552     /// This is actually currently stored in reverse order.
553     LazyDeclPtr FirstFriend;
554
555     DefinitionData(CXXRecordDecl *D);
556
557     /// \brief Retrieve the set of direct base classes.
558     CXXBaseSpecifier *getBases() const {
559       if (!Bases.isOffset())
560         return Bases.get(nullptr);
561       return getBasesSlowCase();
562     }
563
564     /// \brief Retrieve the set of virtual base classes.
565     CXXBaseSpecifier *getVBases() const {
566       if (!VBases.isOffset())
567         return VBases.get(nullptr);
568       return getVBasesSlowCase();
569     }
570
571     ArrayRef<CXXBaseSpecifier> bases() const {
572       return llvm::makeArrayRef(getBases(), NumBases);
573     }
574
575     ArrayRef<CXXBaseSpecifier> vbases() const {
576       return llvm::makeArrayRef(getVBases(), NumVBases);
577     }
578
579   private:
580     CXXBaseSpecifier *getBasesSlowCase() const;
581     CXXBaseSpecifier *getVBasesSlowCase() const;
582   };
583
584   struct DefinitionData *DefinitionData;
585
586   /// \brief Describes a C++ closure type (generated by a lambda expression).
587   struct LambdaDefinitionData : public DefinitionData {
588     using Capture = LambdaCapture;
589
590     /// \brief Whether this lambda is known to be dependent, even if its
591     /// context isn't dependent.
592     /// 
593     /// A lambda with a non-dependent context can be dependent if it occurs
594     /// within the default argument of a function template, because the
595     /// lambda will have been created with the enclosing context as its
596     /// declaration context, rather than function. This is an unfortunate
597     /// artifact of having to parse the default arguments before. 
598     unsigned Dependent : 1;
599     
600     /// \brief Whether this lambda is a generic lambda.
601     unsigned IsGenericLambda : 1;
602
603     /// \brief The Default Capture.
604     unsigned CaptureDefault : 2;
605
606     /// \brief The number of captures in this lambda is limited 2^NumCaptures.
607     unsigned NumCaptures : 15;
608
609     /// \brief The number of explicit captures in this lambda.
610     unsigned NumExplicitCaptures : 13;
611
612     /// \brief The number used to indicate this lambda expression for name 
613     /// mangling in the Itanium C++ ABI.
614     unsigned ManglingNumber = 0;
615     
616     /// \brief The declaration that provides context for this lambda, if the
617     /// actual DeclContext does not suffice. This is used for lambdas that
618     /// occur within default arguments of function parameters within the class
619     /// or within a data member initializer.
620     LazyDeclPtr ContextDecl;
621     
622     /// \brief The list of captures, both explicit and implicit, for this 
623     /// lambda.
624     Capture *Captures = nullptr;
625
626     /// \brief The type of the call method.
627     TypeSourceInfo *MethodTyInfo;
628
629     LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info, 
630                          bool Dependent, bool IsGeneric, 
631                          LambdaCaptureDefault CaptureDefault) 
632       : DefinitionData(D), Dependent(Dependent), IsGenericLambda(IsGeneric), 
633         CaptureDefault(CaptureDefault), NumCaptures(0), NumExplicitCaptures(0), 
634         MethodTyInfo(Info) {
635       IsLambda = true;
636
637       // C++1z [expr.prim.lambda]p4:
638       //   This class type is not an aggregate type.
639       Aggregate = false;
640       PlainOldData = false;
641     }
642   };
643
644   struct DefinitionData *dataPtr() const {
645     // Complete the redecl chain (if necessary).
646     getMostRecentDecl();
647     return DefinitionData;
648   }
649
650   struct DefinitionData &data() const {
651     auto *DD = dataPtr();
652     assert(DD && "queried property of class with no definition");
653     return *DD;
654   }
655
656   struct LambdaDefinitionData &getLambdaData() const {
657     // No update required: a merged definition cannot change any lambda
658     // properties.
659     auto *DD = DefinitionData;
660     assert(DD && DD->IsLambda && "queried lambda property of non-lambda class");
661     return static_cast<LambdaDefinitionData&>(*DD);
662   }
663
664   /// \brief The template or declaration that this declaration
665   /// describes or was instantiated from, respectively.
666   ///
667   /// For non-templates, this value will be null. For record
668   /// declarations that describe a class template, this will be a
669   /// pointer to a ClassTemplateDecl. For member
670   /// classes of class template specializations, this will be the
671   /// MemberSpecializationInfo referring to the member class that was
672   /// instantiated or specialized.
673   llvm::PointerUnion<ClassTemplateDecl *, MemberSpecializationInfo *>
674       TemplateOrInstantiation;
675
676   /// \brief Called from setBases and addedMember to notify the class that a
677   /// direct or virtual base class or a member of class type has been added.
678   void addedClassSubobject(CXXRecordDecl *Base);
679
680   /// \brief Notify the class that member has been added.
681   ///
682   /// This routine helps maintain information about the class based on which
683   /// members have been added. It will be invoked by DeclContext::addDecl()
684   /// whenever a member is added to this record.
685   void addedMember(Decl *D);
686
687   void markedVirtualFunctionPure();
688
689   /// \brief Get the head of our list of friend declarations, possibly
690   /// deserializing the friends from an external AST source.
691   FriendDecl *getFirstFriend() const;
692
693 protected:
694   CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, DeclContext *DC,
695                 SourceLocation StartLoc, SourceLocation IdLoc,
696                 IdentifierInfo *Id, CXXRecordDecl *PrevDecl);
697
698 public:
699   /// \brief Iterator that traverses the base classes of a class.
700   using base_class_iterator = CXXBaseSpecifier *;
701
702   /// \brief Iterator that traverses the base classes of a class.
703   using base_class_const_iterator = const CXXBaseSpecifier *;
704
705   CXXRecordDecl *getCanonicalDecl() override {
706     return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
707   }
708
709   const CXXRecordDecl *getCanonicalDecl() const {
710     return const_cast<CXXRecordDecl*>(this)->getCanonicalDecl();
711   }
712
713   CXXRecordDecl *getPreviousDecl() {
714     return cast_or_null<CXXRecordDecl>(
715             static_cast<RecordDecl *>(this)->getPreviousDecl());
716   }
717
718   const CXXRecordDecl *getPreviousDecl() const {
719     return const_cast<CXXRecordDecl*>(this)->getPreviousDecl();
720   }
721
722   CXXRecordDecl *getMostRecentDecl() {
723     return cast<CXXRecordDecl>(
724             static_cast<RecordDecl *>(this)->getMostRecentDecl());
725   }
726
727   const CXXRecordDecl *getMostRecentDecl() const {
728     return const_cast<CXXRecordDecl*>(this)->getMostRecentDecl();
729   }
730
731   CXXRecordDecl *getDefinition() const {
732     // We only need an update if we don't already know which
733     // declaration is the definition.
734     auto *DD = DefinitionData ? DefinitionData : dataPtr();
735     return DD ? DD->Definition : nullptr;
736   }
737
738   bool hasDefinition() const { return DefinitionData || dataPtr(); }
739
740   static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
741                                SourceLocation StartLoc, SourceLocation IdLoc,
742                                IdentifierInfo *Id,
743                                CXXRecordDecl *PrevDecl = nullptr,
744                                bool DelayTypeCreation = false);
745   static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC,
746                                      TypeSourceInfo *Info, SourceLocation Loc,
747                                      bool DependentLambda, bool IsGeneric,
748                                      LambdaCaptureDefault CaptureDefault);
749   static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
750
751   bool isDynamicClass() const {
752     return data().Polymorphic || data().NumVBases != 0;
753   }
754
755   void setIsParsingBaseSpecifiers() { data().IsParsingBaseSpecifiers = true; }
756
757   bool isParsingBaseSpecifiers() const {
758     return data().IsParsingBaseSpecifiers;
759   }
760
761   unsigned getODRHash() const;
762
763   /// \brief Sets the base classes of this struct or class.
764   void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
765
766   /// \brief Retrieves the number of base classes of this class.
767   unsigned getNumBases() const { return data().NumBases; }
768
769   using base_class_range = llvm::iterator_range<base_class_iterator>;
770   using base_class_const_range =
771       llvm::iterator_range<base_class_const_iterator>;
772
773   base_class_range bases() {
774     return base_class_range(bases_begin(), bases_end());
775   }
776   base_class_const_range bases() const {
777     return base_class_const_range(bases_begin(), bases_end());
778   }
779
780   base_class_iterator bases_begin() { return data().getBases(); }
781   base_class_const_iterator bases_begin() const { return data().getBases(); }
782   base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
783   base_class_const_iterator bases_end() const {
784     return bases_begin() + data().NumBases;
785   }
786
787   /// \brief Retrieves the number of virtual base classes of this class.
788   unsigned getNumVBases() const { return data().NumVBases; }
789
790   base_class_range vbases() {
791     return base_class_range(vbases_begin(), vbases_end());
792   }
793   base_class_const_range vbases() const {
794     return base_class_const_range(vbases_begin(), vbases_end());
795   }
796
797   base_class_iterator vbases_begin() { return data().getVBases(); }
798   base_class_const_iterator vbases_begin() const { return data().getVBases(); }
799   base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
800   base_class_const_iterator vbases_end() const {
801     return vbases_begin() + data().NumVBases;
802   }
803
804   /// \brief Determine whether this class has any dependent base classes which
805   /// are not the current instantiation.
806   bool hasAnyDependentBases() const;
807
808   /// Iterator access to method members.  The method iterator visits
809   /// all method members of the class, including non-instance methods,
810   /// special methods, etc.
811   using method_iterator = specific_decl_iterator<CXXMethodDecl>;
812   using method_range =
813       llvm::iterator_range<specific_decl_iterator<CXXMethodDecl>>;
814
815   method_range methods() const {
816     return method_range(method_begin(), method_end());
817   }
818
819   /// \brief Method begin iterator.  Iterates in the order the methods
820   /// were declared.
821   method_iterator method_begin() const {
822     return method_iterator(decls_begin());
823   }
824
825   /// \brief Method past-the-end iterator.
826   method_iterator method_end() const {
827     return method_iterator(decls_end());
828   }
829
830   /// Iterator access to constructor members.
831   using ctor_iterator = specific_decl_iterator<CXXConstructorDecl>;
832   using ctor_range =
833       llvm::iterator_range<specific_decl_iterator<CXXConstructorDecl>>;
834
835   ctor_range ctors() const { return ctor_range(ctor_begin(), ctor_end()); }
836
837   ctor_iterator ctor_begin() const {
838     return ctor_iterator(decls_begin());
839   }
840
841   ctor_iterator ctor_end() const {
842     return ctor_iterator(decls_end());
843   }
844
845   /// An iterator over friend declarations.  All of these are defined
846   /// in DeclFriend.h.
847   class friend_iterator;
848   using friend_range = llvm::iterator_range<friend_iterator>;
849
850   friend_range friends() const;
851   friend_iterator friend_begin() const;
852   friend_iterator friend_end() const;
853   void pushFriendDecl(FriendDecl *FD);
854
855   /// Determines whether this record has any friends.
856   bool hasFriends() const {
857     return data().FirstFriend.isValid();
858   }
859
860   /// \brief \c true if a defaulted copy constructor for this class would be
861   /// deleted.
862   bool defaultedCopyConstructorIsDeleted() const {
863     assert((!needsOverloadResolutionForCopyConstructor() ||
864             (data().DeclaredSpecialMembers & SMF_CopyConstructor)) &&
865            "this property has not yet been computed by Sema");
866     return data().DefaultedCopyConstructorIsDeleted;
867   }
868
869   /// \brief \c true if a defaulted move constructor for this class would be
870   /// deleted.
871   bool defaultedMoveConstructorIsDeleted() const {
872     assert((!needsOverloadResolutionForMoveConstructor() ||
873             (data().DeclaredSpecialMembers & SMF_MoveConstructor)) &&
874            "this property has not yet been computed by Sema");
875     return data().DefaultedMoveConstructorIsDeleted;
876   }
877
878   /// \brief \c true if a defaulted destructor for this class would be deleted.
879   bool defaultedDestructorIsDeleted() const {
880     assert((!needsOverloadResolutionForDestructor() ||
881             (data().DeclaredSpecialMembers & SMF_Destructor)) &&
882            "this property has not yet been computed by Sema");
883     return data().DefaultedDestructorIsDeleted;
884   }
885
886   /// \brief \c true if we know for sure that this class has a single,
887   /// accessible, unambiguous copy constructor that is not deleted.
888   bool hasSimpleCopyConstructor() const {
889     return !hasUserDeclaredCopyConstructor() &&
890            !data().DefaultedCopyConstructorIsDeleted;
891   }
892
893   /// \brief \c true if we know for sure that this class has a single,
894   /// accessible, unambiguous move constructor that is not deleted.
895   bool hasSimpleMoveConstructor() const {
896     return !hasUserDeclaredMoveConstructor() && hasMoveConstructor() &&
897            !data().DefaultedMoveConstructorIsDeleted;
898   }
899
900   /// \brief \c true if we know for sure that this class has a single,
901   /// accessible, unambiguous move assignment operator that is not deleted.
902   bool hasSimpleMoveAssignment() const {
903     return !hasUserDeclaredMoveAssignment() && hasMoveAssignment() &&
904            !data().DefaultedMoveAssignmentIsDeleted;
905   }
906
907   /// \brief \c true if we know for sure that this class has an accessible
908   /// destructor that is not deleted.
909   bool hasSimpleDestructor() const {
910     return !hasUserDeclaredDestructor() &&
911            !data().DefaultedDestructorIsDeleted;
912   }
913
914   /// \brief Determine whether this class has any default constructors.
915   bool hasDefaultConstructor() const {
916     return (data().DeclaredSpecialMembers & SMF_DefaultConstructor) ||
917            needsImplicitDefaultConstructor();
918   }
919
920   /// \brief Determine if we need to declare a default constructor for
921   /// this class.
922   ///
923   /// This value is used for lazy creation of default constructors.
924   bool needsImplicitDefaultConstructor() const {
925     return !data().UserDeclaredConstructor &&
926            !(data().DeclaredSpecialMembers & SMF_DefaultConstructor) &&
927            // C++14 [expr.prim.lambda]p20:
928            //   The closure type associated with a lambda-expression has no
929            //   default constructor.
930            !isLambda();
931   }
932
933   /// \brief Determine whether this class has any user-declared constructors.
934   ///
935   /// When true, a default constructor will not be implicitly declared.
936   bool hasUserDeclaredConstructor() const {
937     return data().UserDeclaredConstructor;
938   }
939
940   /// \brief Whether this class has a user-provided default constructor
941   /// per C++11.
942   bool hasUserProvidedDefaultConstructor() const {
943     return data().UserProvidedDefaultConstructor;
944   }
945
946   /// \brief Determine whether this class has a user-declared copy constructor.
947   ///
948   /// When false, a copy constructor will be implicitly declared.
949   bool hasUserDeclaredCopyConstructor() const {
950     return data().UserDeclaredSpecialMembers & SMF_CopyConstructor;
951   }
952
953   /// \brief Determine whether this class needs an implicit copy
954   /// constructor to be lazily declared.
955   bool needsImplicitCopyConstructor() const {
956     return !(data().DeclaredSpecialMembers & SMF_CopyConstructor);
957   }
958
959   /// \brief Determine whether we need to eagerly declare a defaulted copy
960   /// constructor for this class.
961   bool needsOverloadResolutionForCopyConstructor() const {
962     // C++17 [class.copy.ctor]p6:
963     //   If the class definition declares a move constructor or move assignment
964     //   operator, the implicitly declared copy constructor is defined as
965     //   deleted.
966     // In MSVC mode, sometimes a declared move assignment does not delete an
967     // implicit copy constructor, so defer this choice to Sema.
968     if (data().UserDeclaredSpecialMembers &
969         (SMF_MoveConstructor | SMF_MoveAssignment))
970       return true;
971     return data().NeedOverloadResolutionForCopyConstructor;
972   }
973
974   /// \brief Determine whether an implicit copy constructor for this type
975   /// would have a parameter with a const-qualified reference type.
976   bool implicitCopyConstructorHasConstParam() const {
977     return data().ImplicitCopyConstructorCanHaveConstParamForNonVBase &&
978            (isAbstract() ||
979             data().ImplicitCopyConstructorCanHaveConstParamForVBase);
980   }
981
982   /// \brief Determine whether this class has a copy constructor with
983   /// a parameter type which is a reference to a const-qualified type.
984   bool hasCopyConstructorWithConstParam() const {
985     return data().HasDeclaredCopyConstructorWithConstParam ||
986            (needsImplicitCopyConstructor() &&
987             implicitCopyConstructorHasConstParam());
988   }
989
990   /// \brief Whether this class has a user-declared move constructor or
991   /// assignment operator.
992   ///
993   /// When false, a move constructor and assignment operator may be
994   /// implicitly declared.
995   bool hasUserDeclaredMoveOperation() const {
996     return data().UserDeclaredSpecialMembers &
997              (SMF_MoveConstructor | SMF_MoveAssignment);
998   }
999
1000   /// \brief Determine whether this class has had a move constructor
1001   /// declared by the user.
1002   bool hasUserDeclaredMoveConstructor() const {
1003     return data().UserDeclaredSpecialMembers & SMF_MoveConstructor;
1004   }
1005
1006   /// \brief Determine whether this class has a move constructor.
1007   bool hasMoveConstructor() const {
1008     return (data().DeclaredSpecialMembers & SMF_MoveConstructor) ||
1009            needsImplicitMoveConstructor();
1010   }
1011
1012   /// \brief Set that we attempted to declare an implicit copy
1013   /// constructor, but overload resolution failed so we deleted it.
1014   void setImplicitCopyConstructorIsDeleted() {
1015     assert((data().DefaultedCopyConstructorIsDeleted ||
1016             needsOverloadResolutionForCopyConstructor()) &&
1017            "Copy constructor should not be deleted");
1018     data().DefaultedCopyConstructorIsDeleted = true;
1019   }
1020
1021   /// \brief Set that we attempted to declare an implicit move
1022   /// constructor, but overload resolution failed so we deleted it.
1023   void setImplicitMoveConstructorIsDeleted() {
1024     assert((data().DefaultedMoveConstructorIsDeleted ||
1025             needsOverloadResolutionForMoveConstructor()) &&
1026            "move constructor should not be deleted");
1027     data().DefaultedMoveConstructorIsDeleted = true;
1028   }
1029
1030   /// \brief Set that we attempted to declare an implicit destructor,
1031   /// but overload resolution failed so we deleted it.
1032   void setImplicitDestructorIsDeleted() {
1033     assert((data().DefaultedDestructorIsDeleted ||
1034             needsOverloadResolutionForDestructor()) &&
1035            "destructor should not be deleted");
1036     data().DefaultedDestructorIsDeleted = true;
1037   }
1038
1039   /// \brief Determine whether this class should get an implicit move
1040   /// constructor or if any existing special member function inhibits this.
1041   bool needsImplicitMoveConstructor() const {
1042     return !(data().DeclaredSpecialMembers & SMF_MoveConstructor) &&
1043            !hasUserDeclaredCopyConstructor() &&
1044            !hasUserDeclaredCopyAssignment() &&
1045            !hasUserDeclaredMoveAssignment() &&
1046            !hasUserDeclaredDestructor();
1047   }
1048
1049   /// \brief Determine whether we need to eagerly declare a defaulted move
1050   /// constructor for this class.
1051   bool needsOverloadResolutionForMoveConstructor() const {
1052     return data().NeedOverloadResolutionForMoveConstructor;
1053   }
1054
1055   /// \brief Determine whether this class has a user-declared copy assignment
1056   /// operator.
1057   ///
1058   /// When false, a copy assigment operator will be implicitly declared.
1059   bool hasUserDeclaredCopyAssignment() const {
1060     return data().UserDeclaredSpecialMembers & SMF_CopyAssignment;
1061   }
1062
1063   /// \brief Determine whether this class needs an implicit copy
1064   /// assignment operator to be lazily declared.
1065   bool needsImplicitCopyAssignment() const {
1066     return !(data().DeclaredSpecialMembers & SMF_CopyAssignment);
1067   }
1068
1069   /// \brief Determine whether we need to eagerly declare a defaulted copy
1070   /// assignment operator for this class.
1071   bool needsOverloadResolutionForCopyAssignment() const {
1072     return data().HasMutableFields;
1073   }
1074
1075   /// \brief Determine whether an implicit copy assignment operator for this
1076   /// type would have a parameter with a const-qualified reference type.
1077   bool implicitCopyAssignmentHasConstParam() const {
1078     return data().ImplicitCopyAssignmentHasConstParam;
1079   }
1080
1081   /// \brief Determine whether this class has a copy assignment operator with
1082   /// a parameter type which is a reference to a const-qualified type or is not
1083   /// a reference.
1084   bool hasCopyAssignmentWithConstParam() const {
1085     return data().HasDeclaredCopyAssignmentWithConstParam ||
1086            (needsImplicitCopyAssignment() &&
1087             implicitCopyAssignmentHasConstParam());
1088   }
1089
1090   /// \brief Determine whether this class has had a move assignment
1091   /// declared by the user.
1092   bool hasUserDeclaredMoveAssignment() const {
1093     return data().UserDeclaredSpecialMembers & SMF_MoveAssignment;
1094   }
1095
1096   /// \brief Determine whether this class has a move assignment operator.
1097   bool hasMoveAssignment() const {
1098     return (data().DeclaredSpecialMembers & SMF_MoveAssignment) ||
1099            needsImplicitMoveAssignment();
1100   }
1101
1102   /// \brief Set that we attempted to declare an implicit move assignment
1103   /// operator, but overload resolution failed so we deleted it.
1104   void setImplicitMoveAssignmentIsDeleted() {
1105     assert((data().DefaultedMoveAssignmentIsDeleted ||
1106             needsOverloadResolutionForMoveAssignment()) &&
1107            "move assignment should not be deleted");
1108     data().DefaultedMoveAssignmentIsDeleted = true;
1109   }
1110
1111   /// \brief Determine whether this class should get an implicit move
1112   /// assignment operator or if any existing special member function inhibits
1113   /// this.
1114   bool needsImplicitMoveAssignment() const {
1115     return !(data().DeclaredSpecialMembers & SMF_MoveAssignment) &&
1116            !hasUserDeclaredCopyConstructor() &&
1117            !hasUserDeclaredCopyAssignment() &&
1118            !hasUserDeclaredMoveConstructor() &&
1119            !hasUserDeclaredDestructor() &&
1120            // C++1z [expr.prim.lambda]p21: "the closure type has a deleted copy
1121            // assignment operator". The intent is that this counts as a user
1122            // declared copy assignment, but we do not model it that way.
1123            !isLambda();
1124   }
1125
1126   /// \brief Determine whether we need to eagerly declare a move assignment
1127   /// operator for this class.
1128   bool needsOverloadResolutionForMoveAssignment() const {
1129     return data().NeedOverloadResolutionForMoveAssignment;
1130   }
1131
1132   /// \brief Determine whether this class has a user-declared destructor.
1133   ///
1134   /// When false, a destructor will be implicitly declared.
1135   bool hasUserDeclaredDestructor() const {
1136     return data().UserDeclaredSpecialMembers & SMF_Destructor;
1137   }
1138
1139   /// \brief Determine whether this class needs an implicit destructor to
1140   /// be lazily declared.
1141   bool needsImplicitDestructor() const {
1142     return !(data().DeclaredSpecialMembers & SMF_Destructor);
1143   }
1144
1145   /// \brief Determine whether we need to eagerly declare a destructor for this
1146   /// class.
1147   bool needsOverloadResolutionForDestructor() const {
1148     return data().NeedOverloadResolutionForDestructor;
1149   }
1150
1151   /// \brief Determine whether this class describes a lambda function object.
1152   bool isLambda() const {
1153     // An update record can't turn a non-lambda into a lambda.
1154     auto *DD = DefinitionData;
1155     return DD && DD->IsLambda;
1156   }
1157
1158   /// \brief Determine whether this class describes a generic 
1159   /// lambda function object (i.e. function call operator is
1160   /// a template). 
1161   bool isGenericLambda() const; 
1162
1163   /// \brief Retrieve the lambda call operator of the closure type
1164   /// if this is a closure type.
1165   CXXMethodDecl *getLambdaCallOperator() const; 
1166
1167   /// \brief Retrieve the lambda static invoker, the address of which
1168   /// is returned by the conversion operator, and the body of which
1169   /// is forwarded to the lambda call operator. 
1170   CXXMethodDecl *getLambdaStaticInvoker() const; 
1171
1172   /// \brief Retrieve the generic lambda's template parameter list.
1173   /// Returns null if the class does not represent a lambda or a generic 
1174   /// lambda.
1175   TemplateParameterList *getGenericLambdaTemplateParameterList() const;
1176
1177   LambdaCaptureDefault getLambdaCaptureDefault() const {
1178     assert(isLambda());
1179     return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault);
1180   }
1181
1182   /// \brief For a closure type, retrieve the mapping from captured
1183   /// variables and \c this to the non-static data members that store the
1184   /// values or references of the captures.
1185   ///
1186   /// \param Captures Will be populated with the mapping from captured
1187   /// variables to the corresponding fields.
1188   ///
1189   /// \param ThisCapture Will be set to the field declaration for the
1190   /// \c this capture.
1191   ///
1192   /// \note No entries will be added for init-captures, as they do not capture
1193   /// variables.
1194   void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures,
1195                         FieldDecl *&ThisCapture) const;
1196
1197   using capture_const_iterator = const LambdaCapture *;
1198   using capture_const_range = llvm::iterator_range<capture_const_iterator>;
1199
1200   capture_const_range captures() const {
1201     return capture_const_range(captures_begin(), captures_end());
1202   }
1203
1204   capture_const_iterator captures_begin() const {
1205     return isLambda() ? getLambdaData().Captures : nullptr;
1206   }
1207
1208   capture_const_iterator captures_end() const {
1209     return isLambda() ? captures_begin() + getLambdaData().NumCaptures
1210                       : nullptr;
1211   }
1212
1213   using conversion_iterator = UnresolvedSetIterator;
1214
1215   conversion_iterator conversion_begin() const {
1216     return data().Conversions.get(getASTContext()).begin();
1217   }
1218
1219   conversion_iterator conversion_end() const {
1220     return data().Conversions.get(getASTContext()).end();
1221   }
1222
1223   /// Removes a conversion function from this class.  The conversion
1224   /// function must currently be a member of this class.  Furthermore,
1225   /// this class must currently be in the process of being defined.
1226   void removeConversion(const NamedDecl *Old);
1227
1228   /// \brief Get all conversion functions visible in current class,
1229   /// including conversion function templates.
1230   llvm::iterator_range<conversion_iterator> getVisibleConversionFunctions();
1231
1232   /// Determine whether this class is an aggregate (C++ [dcl.init.aggr]),
1233   /// which is a class with no user-declared constructors, no private
1234   /// or protected non-static data members, no base classes, and no virtual
1235   /// functions (C++ [dcl.init.aggr]p1).
1236   bool isAggregate() const { return data().Aggregate; }
1237
1238   /// \brief Whether this class has any in-class initializers
1239   /// for non-static data members (including those in anonymous unions or
1240   /// structs).
1241   bool hasInClassInitializer() const { return data().HasInClassInitializer; }
1242
1243   /// \brief Whether this class or any of its subobjects has any members of
1244   /// reference type which would make value-initialization ill-formed.
1245   ///
1246   /// Per C++03 [dcl.init]p5:
1247   ///  - if T is a non-union class type without a user-declared constructor,
1248   ///    then every non-static data member and base-class component of T is
1249   ///    value-initialized [...] A program that calls for [...]
1250   ///    value-initialization of an entity of reference type is ill-formed.
1251   bool hasUninitializedReferenceMember() const {
1252     return !isUnion() && !hasUserDeclaredConstructor() &&
1253            data().HasUninitializedReferenceMember;
1254   }
1255
1256   /// \brief Whether this class is a POD-type (C++ [class]p4)
1257   ///
1258   /// For purposes of this function a class is POD if it is an aggregate
1259   /// that has no non-static non-POD data members, no reference data
1260   /// members, no user-defined copy assignment operator and no
1261   /// user-defined destructor.
1262   ///
1263   /// Note that this is the C++ TR1 definition of POD.
1264   bool isPOD() const { return data().PlainOldData; }
1265
1266   /// \brief True if this class is C-like, without C++-specific features, e.g.
1267   /// it contains only public fields, no bases, tag kind is not 'class', etc.
1268   bool isCLike() const;
1269
1270   /// \brief Determine whether this is an empty class in the sense of
1271   /// (C++11 [meta.unary.prop]).
1272   ///
1273   /// The CXXRecordDecl is a class type, but not a union type,
1274   /// with no non-static data members other than bit-fields of length 0,
1275   /// no virtual member functions, no virtual base classes,
1276   /// and no base class B for which is_empty<B>::value is false.
1277   ///
1278   /// \note This does NOT include a check for union-ness.
1279   bool isEmpty() const { return data().Empty; }
1280
1281   /// \brief Determine whether this class has direct non-static data members.
1282   bool hasDirectFields() const {
1283     auto &D = data();
1284     return D.HasPublicFields || D.HasProtectedFields || D.HasPrivateFields;
1285   }
1286
1287   /// Whether this class is polymorphic (C++ [class.virtual]),
1288   /// which means that the class contains or inherits a virtual function.
1289   bool isPolymorphic() const { return data().Polymorphic; }
1290
1291   /// \brief Determine whether this class has a pure virtual function.
1292   ///
1293   /// The class is is abstract per (C++ [class.abstract]p2) if it declares
1294   /// a pure virtual function or inherits a pure virtual function that is
1295   /// not overridden.
1296   bool isAbstract() const { return data().Abstract; }
1297
1298   /// \brief Determine whether this class has standard layout per 
1299   /// (C++ [class]p7)
1300   bool isStandardLayout() const { return data().IsStandardLayout; }
1301
1302   /// \brief Determine whether this class, or any of its class subobjects,
1303   /// contains a mutable field.
1304   bool hasMutableFields() const { return data().HasMutableFields; }
1305
1306   /// \brief Determine whether this class has any variant members.
1307   bool hasVariantMembers() const { return data().HasVariantMembers; }
1308
1309   /// \brief Determine whether this class has a trivial default constructor
1310   /// (C++11 [class.ctor]p5).
1311   bool hasTrivialDefaultConstructor() const {
1312     return hasDefaultConstructor() &&
1313            (data().HasTrivialSpecialMembers & SMF_DefaultConstructor);
1314   }
1315
1316   /// \brief Determine whether this class has a non-trivial default constructor
1317   /// (C++11 [class.ctor]p5).
1318   bool hasNonTrivialDefaultConstructor() const {
1319     return (data().DeclaredNonTrivialSpecialMembers & SMF_DefaultConstructor) ||
1320            (needsImplicitDefaultConstructor() &&
1321             !(data().HasTrivialSpecialMembers & SMF_DefaultConstructor));
1322   }
1323
1324   /// \brief Determine whether this class has at least one constexpr constructor
1325   /// other than the copy or move constructors.
1326   bool hasConstexprNonCopyMoveConstructor() const {
1327     return data().HasConstexprNonCopyMoveConstructor ||
1328            (needsImplicitDefaultConstructor() &&
1329             defaultedDefaultConstructorIsConstexpr());
1330   }
1331
1332   /// \brief Determine whether a defaulted default constructor for this class
1333   /// would be constexpr.
1334   bool defaultedDefaultConstructorIsConstexpr() const {
1335     return data().DefaultedDefaultConstructorIsConstexpr &&
1336            (!isUnion() || hasInClassInitializer() || !hasVariantMembers());
1337   }
1338
1339   /// \brief Determine whether this class has a constexpr default constructor.
1340   bool hasConstexprDefaultConstructor() const {
1341     return data().HasConstexprDefaultConstructor ||
1342            (needsImplicitDefaultConstructor() &&
1343             defaultedDefaultConstructorIsConstexpr());
1344   }
1345
1346   /// \brief Determine whether this class has a trivial copy constructor
1347   /// (C++ [class.copy]p6, C++11 [class.copy]p12)
1348   bool hasTrivialCopyConstructor() const {
1349     return data().HasTrivialSpecialMembers & SMF_CopyConstructor;
1350   }
1351
1352   /// \brief Determine whether this class has a non-trivial copy constructor
1353   /// (C++ [class.copy]p6, C++11 [class.copy]p12)
1354   bool hasNonTrivialCopyConstructor() const {
1355     return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor ||
1356            !hasTrivialCopyConstructor();
1357   }
1358
1359   /// \brief Determine whether this class has a trivial move constructor
1360   /// (C++11 [class.copy]p12)
1361   bool hasTrivialMoveConstructor() const {
1362     return hasMoveConstructor() &&
1363            (data().HasTrivialSpecialMembers & SMF_MoveConstructor);
1364   }
1365
1366   /// \brief Determine whether this class has a non-trivial move constructor
1367   /// (C++11 [class.copy]p12)
1368   bool hasNonTrivialMoveConstructor() const {
1369     return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveConstructor) ||
1370            (needsImplicitMoveConstructor() &&
1371             !(data().HasTrivialSpecialMembers & SMF_MoveConstructor));
1372   }
1373
1374   /// \brief Determine whether this class has a trivial copy assignment operator
1375   /// (C++ [class.copy]p11, C++11 [class.copy]p25)
1376   bool hasTrivialCopyAssignment() const {
1377     return data().HasTrivialSpecialMembers & SMF_CopyAssignment;
1378   }
1379
1380   /// \brief Determine whether this class has a non-trivial copy assignment
1381   /// operator (C++ [class.copy]p11, C++11 [class.copy]p25)
1382   bool hasNonTrivialCopyAssignment() const {
1383     return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment ||
1384            !hasTrivialCopyAssignment();
1385   }
1386
1387   /// \brief Determine whether this class has a trivial move assignment operator
1388   /// (C++11 [class.copy]p25)
1389   bool hasTrivialMoveAssignment() const {
1390     return hasMoveAssignment() &&
1391            (data().HasTrivialSpecialMembers & SMF_MoveAssignment);
1392   }
1393
1394   /// \brief Determine whether this class has a non-trivial move assignment
1395   /// operator (C++11 [class.copy]p25)
1396   bool hasNonTrivialMoveAssignment() const {
1397     return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveAssignment) ||
1398            (needsImplicitMoveAssignment() &&
1399             !(data().HasTrivialSpecialMembers & SMF_MoveAssignment));
1400   }
1401
1402   /// \brief Determine whether this class has a trivial destructor
1403   /// (C++ [class.dtor]p3)
1404   bool hasTrivialDestructor() const {
1405     return data().HasTrivialSpecialMembers & SMF_Destructor;
1406   }
1407
1408   /// \brief Determine whether this class has a non-trivial destructor
1409   /// (C++ [class.dtor]p3)
1410   bool hasNonTrivialDestructor() const {
1411     return !(data().HasTrivialSpecialMembers & SMF_Destructor);
1412   }
1413
1414   /// \brief Determine whether declaring a const variable with this type is ok
1415   /// per core issue 253.
1416   bool allowConstDefaultInit() const {
1417     return !data().HasUninitializedFields ||
1418            !(data().HasDefaultedDefaultConstructor ||
1419              needsImplicitDefaultConstructor());
1420   }
1421
1422   /// \brief Determine whether this class has a destructor which has no
1423   /// semantic effect.
1424   ///
1425   /// Any such destructor will be trivial, public, defaulted and not deleted,
1426   /// and will call only irrelevant destructors.
1427   bool hasIrrelevantDestructor() const {
1428     return data().HasIrrelevantDestructor;
1429   }
1430
1431   /// \brief Determine whether this class has at least one trivial, non-deleted
1432   /// copy or move constructor.
1433   bool canPassInRegisters() const {
1434     return data().CanPassInRegisters;
1435   }
1436
1437   /// \brief Set that we can pass this RecordDecl in registers.
1438   // FIXME: This should be set as part of completeDefinition.
1439   void setCanPassInRegisters(bool CanPass) {
1440     data().CanPassInRegisters = CanPass;
1441   }
1442
1443   /// \brief Determine whether this class has a non-literal or/ volatile type
1444   /// non-static data member or base class.
1445   bool hasNonLiteralTypeFieldsOrBases() const {
1446     return data().HasNonLiteralTypeFieldsOrBases;
1447   }
1448
1449   /// \brief Determine whether this class has a using-declaration that names
1450   /// a user-declared base class constructor.
1451   bool hasInheritedConstructor() const {
1452     return data().HasInheritedConstructor;
1453   }
1454
1455   /// \brief Determine whether this class has a using-declaration that names
1456   /// a base class assignment operator.
1457   bool hasInheritedAssignment() const {
1458     return data().HasInheritedAssignment;
1459   }
1460
1461   /// \brief Determine whether this class is considered trivially copyable per
1462   /// (C++11 [class]p6).
1463   bool isTriviallyCopyable() const;
1464
1465   /// \brief Determine whether this class is considered trivial.
1466   ///
1467   /// C++11 [class]p6:
1468   ///    "A trivial class is a class that has a trivial default constructor and
1469   ///    is trivially copiable."
1470   bool isTrivial() const {
1471     return isTriviallyCopyable() && hasTrivialDefaultConstructor();
1472   }
1473
1474   /// \brief Determine whether this class is a literal type.
1475   ///
1476   /// C++11 [basic.types]p10:
1477   ///   A class type that has all the following properties:
1478   ///     - it has a trivial destructor
1479   ///     - every constructor call and full-expression in the
1480   ///       brace-or-equal-intializers for non-static data members (if any) is
1481   ///       a constant expression.
1482   ///     - it is an aggregate type or has at least one constexpr constructor
1483   ///       or constructor template that is not a copy or move constructor, and
1484   ///     - all of its non-static data members and base classes are of literal
1485   ///       types
1486   ///
1487   /// We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by
1488   /// treating types with trivial default constructors as literal types.
1489   ///
1490   /// Only in C++17 and beyond, are lambdas literal types.
1491   bool isLiteral() const {
1492     return hasTrivialDestructor() &&
1493            (!isLambda() || getASTContext().getLangOpts().CPlusPlus17) &&
1494            !hasNonLiteralTypeFieldsOrBases() &&
1495            (isAggregate() || isLambda() ||
1496             hasConstexprNonCopyMoveConstructor() ||
1497             hasTrivialDefaultConstructor());
1498   }
1499
1500   /// \brief If this record is an instantiation of a member class,
1501   /// retrieves the member class from which it was instantiated.
1502   ///
1503   /// This routine will return non-null for (non-templated) member
1504   /// classes of class templates. For example, given:
1505   ///
1506   /// \code
1507   /// template<typename T>
1508   /// struct X {
1509   ///   struct A { };
1510   /// };
1511   /// \endcode
1512   ///
1513   /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
1514   /// whose parent is the class template specialization X<int>. For
1515   /// this declaration, getInstantiatedFromMemberClass() will return
1516   /// the CXXRecordDecl X<T>::A. When a complete definition of
1517   /// X<int>::A is required, it will be instantiated from the
1518   /// declaration returned by getInstantiatedFromMemberClass().
1519   CXXRecordDecl *getInstantiatedFromMemberClass() const;
1520
1521   /// \brief If this class is an instantiation of a member class of a
1522   /// class template specialization, retrieves the member specialization
1523   /// information.
1524   MemberSpecializationInfo *getMemberSpecializationInfo() const;
1525
1526   /// \brief Specify that this record is an instantiation of the
1527   /// member class \p RD.
1528   void setInstantiationOfMemberClass(CXXRecordDecl *RD,
1529                                      TemplateSpecializationKind TSK);
1530
1531   /// \brief Retrieves the class template that is described by this
1532   /// class declaration.
1533   ///
1534   /// Every class template is represented as a ClassTemplateDecl and a
1535   /// CXXRecordDecl. The former contains template properties (such as
1536   /// the template parameter lists) while the latter contains the
1537   /// actual description of the template's
1538   /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
1539   /// CXXRecordDecl that from a ClassTemplateDecl, while
1540   /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
1541   /// a CXXRecordDecl.
1542   ClassTemplateDecl *getDescribedClassTemplate() const;
1543
1544   void setDescribedClassTemplate(ClassTemplateDecl *Template);
1545
1546   /// \brief Determine whether this particular class is a specialization or
1547   /// instantiation of a class template or member class of a class template,
1548   /// and how it was instantiated or specialized.
1549   TemplateSpecializationKind getTemplateSpecializationKind() const;
1550
1551   /// \brief Set the kind of specialization or template instantiation this is.
1552   void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
1553
1554   /// \brief Retrieve the record declaration from which this record could be
1555   /// instantiated. Returns null if this class is not a template instantiation.
1556   const CXXRecordDecl *getTemplateInstantiationPattern() const;
1557
1558   CXXRecordDecl *getTemplateInstantiationPattern() {
1559     return const_cast<CXXRecordDecl *>(const_cast<const CXXRecordDecl *>(this)
1560                                            ->getTemplateInstantiationPattern());
1561   }
1562
1563   /// \brief Returns the destructor decl for this class.
1564   CXXDestructorDecl *getDestructor() const;
1565
1566   /// \brief Returns true if the class destructor, or any implicitly invoked
1567   /// destructors are marked noreturn.
1568   bool isAnyDestructorNoReturn() const;
1569
1570   /// \brief If the class is a local class [class.local], returns
1571   /// the enclosing function declaration.
1572   const FunctionDecl *isLocalClass() const {
1573     if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
1574       return RD->isLocalClass();
1575
1576     return dyn_cast<FunctionDecl>(getDeclContext());
1577   }
1578
1579   FunctionDecl *isLocalClass() {
1580     return const_cast<FunctionDecl*>(
1581         const_cast<const CXXRecordDecl*>(this)->isLocalClass());
1582   }
1583
1584   /// \brief Determine whether this dependent class is a current instantiation,
1585   /// when viewed from within the given context.
1586   bool isCurrentInstantiation(const DeclContext *CurContext) const;
1587
1588   /// \brief Determine whether this class is derived from the class \p Base.
1589   ///
1590   /// This routine only determines whether this class is derived from \p Base,
1591   /// but does not account for factors that may make a Derived -> Base class
1592   /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1593   /// base class subobjects.
1594   ///
1595   /// \param Base the base class we are searching for.
1596   ///
1597   /// \returns true if this class is derived from Base, false otherwise.
1598   bool isDerivedFrom(const CXXRecordDecl *Base) const;
1599
1600   /// \brief Determine whether this class is derived from the type \p Base.
1601   ///
1602   /// This routine only determines whether this class is derived from \p Base,
1603   /// but does not account for factors that may make a Derived -> Base class
1604   /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1605   /// base class subobjects.
1606   ///
1607   /// \param Base the base class we are searching for.
1608   ///
1609   /// \param Paths will contain the paths taken from the current class to the
1610   /// given \p Base class.
1611   ///
1612   /// \returns true if this class is derived from \p Base, false otherwise.
1613   ///
1614   /// \todo add a separate parameter to configure IsDerivedFrom, rather than
1615   /// tangling input and output in \p Paths
1616   bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const;
1617
1618   /// \brief Determine whether this class is virtually derived from
1619   /// the class \p Base.
1620   ///
1621   /// This routine only determines whether this class is virtually
1622   /// derived from \p Base, but does not account for factors that may
1623   /// make a Derived -> Base class ill-formed, such as
1624   /// private/protected inheritance or multiple, ambiguous base class
1625   /// subobjects.
1626   ///
1627   /// \param Base the base class we are searching for.
1628   ///
1629   /// \returns true if this class is virtually derived from Base,
1630   /// false otherwise.
1631   bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const;
1632
1633   /// \brief Determine whether this class is provably not derived from
1634   /// the type \p Base.
1635   bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
1636
1637   /// \brief Function type used by forallBases() as a callback.
1638   ///
1639   /// \param BaseDefinition the definition of the base class
1640   ///
1641   /// \returns true if this base matched the search criteria
1642   using ForallBasesCallback =
1643       llvm::function_ref<bool(const CXXRecordDecl *BaseDefinition)>;
1644
1645   /// \brief Determines if the given callback holds for all the direct
1646   /// or indirect base classes of this type.
1647   ///
1648   /// The class itself does not count as a base class.  This routine
1649   /// returns false if the class has non-computable base classes.
1650   ///
1651   /// \param BaseMatches Callback invoked for each (direct or indirect) base
1652   /// class of this type, or if \p AllowShortCircuit is true then until a call
1653   /// returns false.
1654   ///
1655   /// \param AllowShortCircuit if false, forces the callback to be called
1656   /// for every base class, even if a dependent or non-matching base was
1657   /// found.
1658   bool forallBases(ForallBasesCallback BaseMatches,
1659                    bool AllowShortCircuit = true) const;
1660
1661   /// \brief Function type used by lookupInBases() to determine whether a
1662   /// specific base class subobject matches the lookup criteria.
1663   ///
1664   /// \param Specifier the base-class specifier that describes the inheritance
1665   /// from the base class we are trying to match.
1666   ///
1667   /// \param Path the current path, from the most-derived class down to the
1668   /// base named by the \p Specifier.
1669   ///
1670   /// \returns true if this base matched the search criteria, false otherwise.
1671   using BaseMatchesCallback =
1672       llvm::function_ref<bool(const CXXBaseSpecifier *Specifier,
1673                               CXXBasePath &Path)>;
1674
1675   /// \brief Look for entities within the base classes of this C++ class,
1676   /// transitively searching all base class subobjects.
1677   ///
1678   /// This routine uses the callback function \p BaseMatches to find base
1679   /// classes meeting some search criteria, walking all base class subobjects
1680   /// and populating the given \p Paths structure with the paths through the
1681   /// inheritance hierarchy that resulted in a match. On a successful search,
1682   /// the \p Paths structure can be queried to retrieve the matching paths and
1683   /// to determine if there were any ambiguities.
1684   ///
1685   /// \param BaseMatches callback function used to determine whether a given
1686   /// base matches the user-defined search criteria.
1687   ///
1688   /// \param Paths used to record the paths from this class to its base class
1689   /// subobjects that match the search criteria.
1690   ///
1691   /// \param LookupInDependent can be set to true to extend the search to
1692   /// dependent base classes.
1693   ///
1694   /// \returns true if there exists any path from this class to a base class
1695   /// subobject that matches the search criteria.
1696   bool lookupInBases(BaseMatchesCallback BaseMatches, CXXBasePaths &Paths,
1697                      bool LookupInDependent = false) const;
1698
1699   /// \brief Base-class lookup callback that determines whether the given
1700   /// base class specifier refers to a specific class declaration.
1701   ///
1702   /// This callback can be used with \c lookupInBases() to determine whether
1703   /// a given derived class has is a base class subobject of a particular type.
1704   /// The base record pointer should refer to the canonical CXXRecordDecl of the
1705   /// base class that we are searching for.
1706   static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
1707                             CXXBasePath &Path, const CXXRecordDecl *BaseRecord);
1708
1709   /// \brief Base-class lookup callback that determines whether the
1710   /// given base class specifier refers to a specific class
1711   /// declaration and describes virtual derivation.
1712   ///
1713   /// This callback can be used with \c lookupInBases() to determine
1714   /// whether a given derived class has is a virtual base class
1715   /// subobject of a particular type.  The base record pointer should
1716   /// refer to the canonical CXXRecordDecl of the base class that we
1717   /// are searching for.
1718   static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
1719                                    CXXBasePath &Path,
1720                                    const CXXRecordDecl *BaseRecord);
1721
1722   /// \brief Base-class lookup callback that determines whether there exists
1723   /// a tag with the given name.
1724   ///
1725   /// This callback can be used with \c lookupInBases() to find tag members
1726   /// of the given name within a C++ class hierarchy.
1727   static bool FindTagMember(const CXXBaseSpecifier *Specifier,
1728                             CXXBasePath &Path, DeclarationName Name);
1729
1730   /// \brief Base-class lookup callback that determines whether there exists
1731   /// a member with the given name.
1732   ///
1733   /// This callback can be used with \c lookupInBases() to find members
1734   /// of the given name within a C++ class hierarchy.
1735   static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
1736                                  CXXBasePath &Path, DeclarationName Name);
1737
1738   /// \brief Base-class lookup callback that determines whether there exists
1739   /// a member with the given name.
1740   ///
1741   /// This callback can be used with \c lookupInBases() to find members
1742   /// of the given name within a C++ class hierarchy, including dependent
1743   /// classes.
1744   static bool
1745   FindOrdinaryMemberInDependentClasses(const CXXBaseSpecifier *Specifier,
1746                                        CXXBasePath &Path, DeclarationName Name);
1747
1748   /// \brief Base-class lookup callback that determines whether there exists
1749   /// an OpenMP declare reduction member with the given name.
1750   ///
1751   /// This callback can be used with \c lookupInBases() to find members
1752   /// of the given name within a C++ class hierarchy.
1753   static bool FindOMPReductionMember(const CXXBaseSpecifier *Specifier,
1754                                      CXXBasePath &Path, DeclarationName Name);
1755
1756   /// \brief Base-class lookup callback that determines whether there exists
1757   /// a member with the given name that can be used in a nested-name-specifier.
1758   ///
1759   /// This callback can be used with \c lookupInBases() to find members of
1760   /// the given name within a C++ class hierarchy that can occur within
1761   /// nested-name-specifiers.
1762   static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
1763                                             CXXBasePath &Path,
1764                                             DeclarationName Name);
1765
1766   /// \brief Retrieve the final overriders for each virtual member
1767   /// function in the class hierarchy where this class is the
1768   /// most-derived class in the class hierarchy.
1769   void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
1770
1771   /// \brief Get the indirect primary bases for this class.
1772   void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const;
1773
1774   /// Performs an imprecise lookup of a dependent name in this class.
1775   ///
1776   /// This function does not follow strict semantic rules and should be used
1777   /// only when lookup rules can be relaxed, e.g. indexing.
1778   std::vector<const NamedDecl *>
1779   lookupDependentName(const DeclarationName &Name,
1780                       llvm::function_ref<bool(const NamedDecl *ND)> Filter);
1781
1782   /// Renders and displays an inheritance diagram
1783   /// for this C++ class and all of its base classes (transitively) using
1784   /// GraphViz.
1785   void viewInheritance(ASTContext& Context) const;
1786
1787   /// \brief Calculates the access of a decl that is reached
1788   /// along a path.
1789   static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
1790                                      AccessSpecifier DeclAccess) {
1791     assert(DeclAccess != AS_none);
1792     if (DeclAccess == AS_private) return AS_none;
1793     return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
1794   }
1795
1796   /// \brief Indicates that the declaration of a defaulted or deleted special
1797   /// member function is now complete.
1798   void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD);
1799
1800   /// \brief Indicates that the definition of this class is now complete.
1801   void completeDefinition() override;
1802
1803   /// \brief Indicates that the definition of this class is now complete,
1804   /// and provides a final overrider map to help determine
1805   ///
1806   /// \param FinalOverriders The final overrider map for this class, which can
1807   /// be provided as an optimization for abstract-class checking. If NULL,
1808   /// final overriders will be computed if they are needed to complete the
1809   /// definition.
1810   void completeDefinition(CXXFinalOverriderMap *FinalOverriders);
1811
1812   /// \brief Determine whether this class may end up being abstract, even though
1813   /// it is not yet known to be abstract.
1814   ///
1815   /// \returns true if this class is not known to be abstract but has any
1816   /// base classes that are abstract. In this case, \c completeDefinition()
1817   /// will need to compute final overriders to determine whether the class is
1818   /// actually abstract.
1819   bool mayBeAbstract() const;
1820
1821   /// \brief If this is the closure type of a lambda expression, retrieve the
1822   /// number to be used for name mangling in the Itanium C++ ABI.
1823   ///
1824   /// Zero indicates that this closure type has internal linkage, so the 
1825   /// mangling number does not matter, while a non-zero value indicates which
1826   /// lambda expression this is in this particular context.
1827   unsigned getLambdaManglingNumber() const {
1828     assert(isLambda() && "Not a lambda closure type!");
1829     return getLambdaData().ManglingNumber;
1830   }
1831   
1832   /// \brief Retrieve the declaration that provides additional context for a 
1833   /// lambda, when the normal declaration context is not specific enough.
1834   ///
1835   /// Certain contexts (default arguments of in-class function parameters and 
1836   /// the initializers of data members) have separate name mangling rules for
1837   /// lambdas within the Itanium C++ ABI. For these cases, this routine provides
1838   /// the declaration in which the lambda occurs, e.g., the function parameter 
1839   /// or the non-static data member. Otherwise, it returns NULL to imply that
1840   /// the declaration context suffices.
1841   Decl *getLambdaContextDecl() const;
1842   
1843   /// \brief Set the mangling number and context declaration for a lambda
1844   /// class.
1845   void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl) {
1846     getLambdaData().ManglingNumber = ManglingNumber;
1847     getLambdaData().ContextDecl = ContextDecl;
1848   }
1849
1850   /// \brief Returns the inheritance model used for this record.
1851   MSInheritanceAttr::Spelling getMSInheritanceModel() const;
1852
1853   /// \brief Calculate what the inheritance model would be for this class.
1854   MSInheritanceAttr::Spelling calculateInheritanceModel() const;
1855
1856   /// In the Microsoft C++ ABI, use zero for the field offset of a null data
1857   /// member pointer if we can guarantee that zero is not a valid field offset,
1858   /// or if the member pointer has multiple fields.  Polymorphic classes have a
1859   /// vfptr at offset zero, so we can use zero for null.  If there are multiple
1860   /// fields, we can use zero even if it is a valid field offset because
1861   /// null-ness testing will check the other fields.
1862   bool nullFieldOffsetIsZero() const {
1863     return !MSInheritanceAttr::hasOnlyOneField(/*IsMemberFunction=*/false,
1864                                                getMSInheritanceModel()) ||
1865            (hasDefinition() && isPolymorphic());
1866   }
1867
1868   /// \brief Controls when vtordisps will be emitted if this record is used as a
1869   /// virtual base.
1870   MSVtorDispAttr::Mode getMSVtorDispMode() const;
1871
1872   /// \brief Determine whether this lambda expression was known to be dependent
1873   /// at the time it was created, even if its context does not appear to be
1874   /// dependent.
1875   ///
1876   /// This flag is a workaround for an issue with parsing, where default
1877   /// arguments are parsed before their enclosing function declarations have
1878   /// been created. This means that any lambda expressions within those
1879   /// default arguments will have as their DeclContext the context enclosing
1880   /// the function declaration, which may be non-dependent even when the
1881   /// function declaration itself is dependent. This flag indicates when we
1882   /// know that the lambda is dependent despite that.
1883   bool isDependentLambda() const {
1884     return isLambda() && getLambdaData().Dependent;
1885   }
1886
1887   TypeSourceInfo *getLambdaTypeInfo() const {
1888     return getLambdaData().MethodTyInfo;
1889   }
1890
1891   // \brief Determine whether this type is an Interface Like type for
1892   // __interface inheritence purposes.
1893   bool isInterfaceLike() const;
1894
1895   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1896   static bool classofKind(Kind K) {
1897     return K >= firstCXXRecord && K <= lastCXXRecord;
1898   }
1899 };
1900
1901 /// \brief Represents a C++ deduction guide declaration.
1902 ///
1903 /// \code
1904 /// template<typename T> struct A { A(); A(T); };
1905 /// A() -> A<int>;
1906 /// \endcode
1907 ///
1908 /// In this example, there will be an explicit deduction guide from the
1909 /// second line, and implicit deduction guide templates synthesized from
1910 /// the constructors of \c A.
1911 class CXXDeductionGuideDecl : public FunctionDecl {
1912   void anchor() override;
1913
1914 private:
1915   CXXDeductionGuideDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1916                         bool IsExplicit, const DeclarationNameInfo &NameInfo,
1917                         QualType T, TypeSourceInfo *TInfo,
1918                         SourceLocation EndLocation)
1919       : FunctionDecl(CXXDeductionGuide, C, DC, StartLoc, NameInfo, T, TInfo,
1920                      SC_None, false, false) {
1921     if (EndLocation.isValid())
1922       setRangeEnd(EndLocation);
1923     IsExplicitSpecified = IsExplicit;
1924   }
1925
1926 public:
1927   friend class ASTDeclReader;
1928   friend class ASTDeclWriter;
1929
1930   static CXXDeductionGuideDecl *Create(ASTContext &C, DeclContext *DC,
1931                                        SourceLocation StartLoc, bool IsExplicit,
1932                                        const DeclarationNameInfo &NameInfo,
1933                                        QualType T, TypeSourceInfo *TInfo,
1934                                        SourceLocation EndLocation);
1935
1936   static CXXDeductionGuideDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1937
1938   /// Whether this deduction guide is explicit.
1939   bool isExplicit() const { return IsExplicitSpecified; }
1940
1941   /// Whether this deduction guide was declared with the 'explicit' specifier.
1942   bool isExplicitSpecified() const { return IsExplicitSpecified; }
1943
1944   /// Get the template for which this guide performs deduction.
1945   TemplateDecl *getDeducedTemplate() const {
1946     return getDeclName().getCXXDeductionGuideTemplate();
1947   }
1948
1949   void setIsCopyDeductionCandidate() {
1950     IsCopyDeductionCandidate = true;
1951   }
1952
1953   bool isCopyDeductionCandidate() const { return IsCopyDeductionCandidate; }
1954
1955   // Implement isa/cast/dyncast/etc.
1956   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1957   static bool classofKind(Kind K) { return K == CXXDeductionGuide; }
1958 };
1959
1960 /// \brief Represents a static or instance method of a struct/union/class.
1961 ///
1962 /// In the terminology of the C++ Standard, these are the (static and
1963 /// non-static) member functions, whether virtual or not.
1964 class CXXMethodDecl : public FunctionDecl {
1965   void anchor() override;
1966
1967 protected:
1968   CXXMethodDecl(Kind DK, ASTContext &C, CXXRecordDecl *RD,
1969                 SourceLocation StartLoc, const DeclarationNameInfo &NameInfo,
1970                 QualType T, TypeSourceInfo *TInfo,
1971                 StorageClass SC, bool isInline,
1972                 bool isConstexpr, SourceLocation EndLocation)
1973     : FunctionDecl(DK, C, RD, StartLoc, NameInfo, T, TInfo,
1974                    SC, isInline, isConstexpr) {
1975     if (EndLocation.isValid())
1976       setRangeEnd(EndLocation);
1977   }
1978
1979 public:
1980   static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1981                                SourceLocation StartLoc,
1982                                const DeclarationNameInfo &NameInfo,
1983                                QualType T, TypeSourceInfo *TInfo,
1984                                StorageClass SC,
1985                                bool isInline,
1986                                bool isConstexpr,
1987                                SourceLocation EndLocation);
1988
1989   static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1990
1991   bool isStatic() const;
1992   bool isInstance() const { return !isStatic(); }
1993
1994   /// Returns true if the given operator is implicitly static in a record
1995   /// context.
1996   static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK) {
1997     // [class.free]p1:
1998     // Any allocation function for a class T is a static member
1999     // (even if not explicitly declared static).
2000     // [class.free]p6 Any deallocation function for a class X is a static member
2001     // (even if not explicitly declared static).
2002     return OOK == OO_New || OOK == OO_Array_New || OOK == OO_Delete ||
2003            OOK == OO_Array_Delete;
2004   }
2005
2006   bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); }
2007   bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); }
2008
2009   bool isVirtual() const {
2010     CXXMethodDecl *CD =
2011       cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
2012
2013     // Member function is virtual if it is marked explicitly so, or if it is
2014     // declared in __interface -- then it is automatically pure virtual.
2015     if (CD->isVirtualAsWritten() || CD->isPure())
2016       return true;
2017
2018     return CD->size_overridden_methods() != 0;
2019   }
2020
2021   /// If it's possible to devirtualize a call to this method, return the called
2022   /// function. Otherwise, return null.
2023
2024   /// \param Base The object on which this virtual function is called.
2025   /// \param IsAppleKext True if we are compiling for Apple kext.
2026   CXXMethodDecl *getDevirtualizedMethod(const Expr *Base, bool IsAppleKext);
2027
2028   const CXXMethodDecl *getDevirtualizedMethod(const Expr *Base,
2029                                               bool IsAppleKext) const {
2030     return const_cast<CXXMethodDecl *>(this)->getDevirtualizedMethod(
2031         Base, IsAppleKext);
2032   }
2033
2034   /// \brief Determine whether this is a usual deallocation function
2035   /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded
2036   /// delete or delete[] operator with a particular signature.
2037   bool isUsualDeallocationFunction() const;
2038
2039   /// \brief Determine whether this is a copy-assignment operator, regardless
2040   /// of whether it was declared implicitly or explicitly.
2041   bool isCopyAssignmentOperator() const;
2042
2043   /// \brief Determine whether this is a move assignment operator.
2044   bool isMoveAssignmentOperator() const;
2045
2046   CXXMethodDecl *getCanonicalDecl() override {
2047     return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
2048   }
2049   const CXXMethodDecl *getCanonicalDecl() const {
2050     return const_cast<CXXMethodDecl*>(this)->getCanonicalDecl();
2051   }
2052
2053   CXXMethodDecl *getMostRecentDecl() {
2054     return cast<CXXMethodDecl>(
2055             static_cast<FunctionDecl *>(this)->getMostRecentDecl());
2056   }
2057   const CXXMethodDecl *getMostRecentDecl() const {
2058     return const_cast<CXXMethodDecl*>(this)->getMostRecentDecl();
2059   }
2060
2061   /// True if this method is user-declared and was not
2062   /// deleted or defaulted on its first declaration.
2063   bool isUserProvided() const {
2064     auto *DeclAsWritten = this;
2065     if (auto *Pattern = getTemplateInstantiationPattern())
2066       DeclAsWritten = cast<CXXMethodDecl>(Pattern);
2067     return !(DeclAsWritten->isDeleted() ||
2068              DeclAsWritten->getCanonicalDecl()->isDefaulted());
2069   }
2070
2071   void addOverriddenMethod(const CXXMethodDecl *MD);
2072
2073   using method_iterator = const CXXMethodDecl *const *;
2074
2075   method_iterator begin_overridden_methods() const;
2076   method_iterator end_overridden_methods() const;
2077   unsigned size_overridden_methods() const;
2078
2079   using overridden_method_range= ASTContext::overridden_method_range;
2080
2081   overridden_method_range overridden_methods() const;
2082
2083   /// Returns the parent of this method declaration, which
2084   /// is the class in which this method is defined.
2085   const CXXRecordDecl *getParent() const {
2086     return cast<CXXRecordDecl>(FunctionDecl::getParent());
2087   }
2088
2089   /// Returns the parent of this method declaration, which
2090   /// is the class in which this method is defined.
2091   CXXRecordDecl *getParent() {
2092     return const_cast<CXXRecordDecl *>(
2093              cast<CXXRecordDecl>(FunctionDecl::getParent()));
2094   }
2095
2096   /// \brief Returns the type of the \c this pointer.
2097   ///
2098   /// Should only be called for instance (i.e., non-static) methods. Note
2099   /// that for the call operator of a lambda closure type, this returns the
2100   /// desugared 'this' type (a pointer to the closure type), not the captured
2101   /// 'this' type.
2102   QualType getThisType(ASTContext &C) const;
2103
2104   unsigned getTypeQualifiers() const {
2105     return getType()->getAs<FunctionProtoType>()->getTypeQuals();
2106   }
2107
2108   /// \brief Retrieve the ref-qualifier associated with this method.
2109   ///
2110   /// In the following example, \c f() has an lvalue ref-qualifier, \c g()
2111   /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier.
2112   /// @code
2113   /// struct X {
2114   ///   void f() &;
2115   ///   void g() &&;
2116   ///   void h();
2117   /// };
2118   /// @endcode
2119   RefQualifierKind getRefQualifier() const {
2120     return getType()->getAs<FunctionProtoType>()->getRefQualifier();
2121   }
2122
2123   bool hasInlineBody() const;
2124
2125   /// \brief Determine whether this is a lambda closure type's static member
2126   /// function that is used for the result of the lambda's conversion to
2127   /// function pointer (for a lambda with no captures).
2128   ///
2129   /// The function itself, if used, will have a placeholder body that will be
2130   /// supplied by IR generation to either forward to the function call operator
2131   /// or clone the function call operator.
2132   bool isLambdaStaticInvoker() const;
2133
2134   /// \brief Find the method in \p RD that corresponds to this one.
2135   ///
2136   /// Find if \p RD or one of the classes it inherits from override this method.
2137   /// If so, return it. \p RD is assumed to be a subclass of the class defining
2138   /// this method (or be the class itself), unless \p MayBeBase is set to true.
2139   CXXMethodDecl *
2140   getCorrespondingMethodInClass(const CXXRecordDecl *RD,
2141                                 bool MayBeBase = false);
2142
2143   const CXXMethodDecl *
2144   getCorrespondingMethodInClass(const CXXRecordDecl *RD,
2145                                 bool MayBeBase = false) const {
2146     return const_cast<CXXMethodDecl *>(this)
2147               ->getCorrespondingMethodInClass(RD, MayBeBase);
2148   }
2149
2150   // Implement isa/cast/dyncast/etc.
2151   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2152   static bool classofKind(Kind K) {
2153     return K >= firstCXXMethod && K <= lastCXXMethod;
2154   }
2155 };
2156
2157 /// \brief Represents a C++ base or member initializer.
2158 ///
2159 /// This is part of a constructor initializer that
2160 /// initializes one non-static member variable or one base class. For
2161 /// example, in the following, both 'A(a)' and 'f(3.14159)' are member
2162 /// initializers:
2163 ///
2164 /// \code
2165 /// class A { };
2166 /// class B : public A {
2167 ///   float f;
2168 /// public:
2169 ///   B(A& a) : A(a), f(3.14159) { }
2170 /// };
2171 /// \endcode
2172 class CXXCtorInitializer final {
2173   /// \brief Either the base class name/delegating constructor type (stored as
2174   /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field
2175   /// (IndirectFieldDecl*) being initialized.
2176   llvm::PointerUnion3<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *>
2177     Initializee;
2178
2179   /// \brief The source location for the field name or, for a base initializer
2180   /// pack expansion, the location of the ellipsis.
2181   ///
2182   /// In the case of a delegating
2183   /// constructor, it will still include the type's source location as the
2184   /// Initializee points to the CXXConstructorDecl (to allow loop detection).
2185   SourceLocation MemberOrEllipsisLocation;
2186
2187   /// \brief The argument used to initialize the base or member, which may
2188   /// end up constructing an object (when multiple arguments are involved).
2189   Stmt *Init;
2190
2191   /// \brief Location of the left paren of the ctor-initializer.
2192   SourceLocation LParenLoc;
2193
2194   /// \brief Location of the right paren of the ctor-initializer.
2195   SourceLocation RParenLoc;
2196
2197   /// \brief If the initializee is a type, whether that type makes this
2198   /// a delegating initialization.
2199   unsigned IsDelegating : 1;
2200
2201   /// \brief If the initializer is a base initializer, this keeps track
2202   /// of whether the base is virtual or not.
2203   unsigned IsVirtual : 1;
2204
2205   /// \brief Whether or not the initializer is explicitly written
2206   /// in the sources.
2207   unsigned IsWritten : 1;
2208
2209   /// If IsWritten is true, then this number keeps track of the textual order
2210   /// of this initializer in the original sources, counting from 0.
2211   unsigned SourceOrder : 13;
2212
2213 public:
2214   /// \brief Creates a new base-class initializer.
2215   explicit
2216   CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual,
2217                      SourceLocation L, Expr *Init, SourceLocation R,
2218                      SourceLocation EllipsisLoc);
2219
2220   /// \brief Creates a new member initializer.
2221   explicit
2222   CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
2223                      SourceLocation MemberLoc, SourceLocation L, Expr *Init,
2224                      SourceLocation R);
2225
2226   /// \brief Creates a new anonymous field initializer.
2227   explicit
2228   CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member,
2229                      SourceLocation MemberLoc, SourceLocation L, Expr *Init,
2230                      SourceLocation R);
2231
2232   /// \brief Creates a new delegating initializer.
2233   explicit
2234   CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo,
2235                      SourceLocation L, Expr *Init, SourceLocation R);
2236
2237   /// \brief Determine whether this initializer is initializing a base class.
2238   bool isBaseInitializer() const {
2239     return Initializee.is<TypeSourceInfo*>() && !IsDelegating;
2240   }
2241
2242   /// \brief Determine whether this initializer is initializing a non-static
2243   /// data member.
2244   bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); }
2245
2246   bool isAnyMemberInitializer() const {
2247     return isMemberInitializer() || isIndirectMemberInitializer();
2248   }
2249
2250   bool isIndirectMemberInitializer() const {
2251     return Initializee.is<IndirectFieldDecl*>();
2252   }
2253
2254   /// \brief Determine whether this initializer is an implicit initializer
2255   /// generated for a field with an initializer defined on the member
2256   /// declaration.
2257   ///
2258   /// In-class member initializers (also known as "non-static data member
2259   /// initializations", NSDMIs) were introduced in C++11.
2260   bool isInClassMemberInitializer() const {
2261     return Init->getStmtClass() == Stmt::CXXDefaultInitExprClass;
2262   }
2263
2264   /// \brief Determine whether this initializer is creating a delegating
2265   /// constructor.
2266   bool isDelegatingInitializer() const {
2267     return Initializee.is<TypeSourceInfo*>() && IsDelegating;
2268   }
2269
2270   /// \brief Determine whether this initializer is a pack expansion.
2271   bool isPackExpansion() const {
2272     return isBaseInitializer() && MemberOrEllipsisLocation.isValid();
2273   }
2274
2275   // \brief For a pack expansion, returns the location of the ellipsis.
2276   SourceLocation getEllipsisLoc() const {
2277     assert(isPackExpansion() && "Initializer is not a pack expansion");
2278     return MemberOrEllipsisLocation;
2279   }
2280
2281   /// If this is a base class initializer, returns the type of the
2282   /// base class with location information. Otherwise, returns an NULL
2283   /// type location.
2284   TypeLoc getBaseClassLoc() const;
2285
2286   /// If this is a base class initializer, returns the type of the base class.
2287   /// Otherwise, returns null.
2288   const Type *getBaseClass() const;
2289
2290   /// Returns whether the base is virtual or not.
2291   bool isBaseVirtual() const {
2292     assert(isBaseInitializer() && "Must call this on base initializer!");
2293
2294     return IsVirtual;
2295   }
2296
2297   /// \brief Returns the declarator information for a base class or delegating
2298   /// initializer.
2299   TypeSourceInfo *getTypeSourceInfo() const {
2300     return Initializee.dyn_cast<TypeSourceInfo *>();
2301   }
2302
2303   /// \brief If this is a member initializer, returns the declaration of the
2304   /// non-static data member being initialized. Otherwise, returns null.
2305   FieldDecl *getMember() const {
2306     if (isMemberInitializer())
2307       return Initializee.get<FieldDecl*>();
2308     return nullptr;
2309   }
2310
2311   FieldDecl *getAnyMember() const {
2312     if (isMemberInitializer())
2313       return Initializee.get<FieldDecl*>();
2314     if (isIndirectMemberInitializer())
2315       return Initializee.get<IndirectFieldDecl*>()->getAnonField();
2316     return nullptr;
2317   }
2318
2319   IndirectFieldDecl *getIndirectMember() const {
2320     if (isIndirectMemberInitializer())
2321       return Initializee.get<IndirectFieldDecl*>();
2322     return nullptr;
2323   }
2324
2325   SourceLocation getMemberLocation() const {
2326     return MemberOrEllipsisLocation;
2327   }
2328
2329   /// \brief Determine the source location of the initializer.
2330   SourceLocation getSourceLocation() const;
2331
2332   /// \brief Determine the source range covering the entire initializer.
2333   SourceRange getSourceRange() const LLVM_READONLY;
2334
2335   /// \brief Determine whether this initializer is explicitly written
2336   /// in the source code.
2337   bool isWritten() const { return IsWritten; }
2338
2339   /// \brief Return the source position of the initializer, counting from 0.
2340   /// If the initializer was implicit, -1 is returned.
2341   int getSourceOrder() const {
2342     return IsWritten ? static_cast<int>(SourceOrder) : -1;
2343   }
2344
2345   /// \brief Set the source order of this initializer.
2346   ///
2347   /// This can only be called once for each initializer; it cannot be called
2348   /// on an initializer having a positive number of (implicit) array indices.
2349   ///
2350   /// This assumes that the initializer was written in the source code, and
2351   /// ensures that isWritten() returns true.
2352   void setSourceOrder(int Pos) {
2353     assert(!IsWritten &&
2354            "setSourceOrder() used on implicit initializer");
2355     assert(SourceOrder == 0 &&
2356            "calling twice setSourceOrder() on the same initializer");
2357     assert(Pos >= 0 &&
2358            "setSourceOrder() used to make an initializer implicit");
2359     IsWritten = true;
2360     SourceOrder = static_cast<unsigned>(Pos);
2361   }
2362
2363   SourceLocation getLParenLoc() const { return LParenLoc; }
2364   SourceLocation getRParenLoc() const { return RParenLoc; }
2365
2366   /// \brief Get the initializer.
2367   Expr *getInit() const { return static_cast<Expr*>(Init); }
2368 };
2369
2370 /// Description of a constructor that was inherited from a base class.
2371 class InheritedConstructor {
2372   ConstructorUsingShadowDecl *Shadow = nullptr;
2373   CXXConstructorDecl *BaseCtor = nullptr;
2374
2375 public:
2376   InheritedConstructor() = default;
2377   InheritedConstructor(ConstructorUsingShadowDecl *Shadow,
2378                        CXXConstructorDecl *BaseCtor)
2379       : Shadow(Shadow), BaseCtor(BaseCtor) {}
2380
2381   explicit operator bool() const { return Shadow; }
2382
2383   ConstructorUsingShadowDecl *getShadowDecl() const { return Shadow; }
2384   CXXConstructorDecl *getConstructor() const { return BaseCtor; }
2385 };
2386
2387 /// \brief Represents a C++ constructor within a class.
2388 ///
2389 /// For example:
2390 ///
2391 /// \code
2392 /// class X {
2393 /// public:
2394 ///   explicit X(int); // represented by a CXXConstructorDecl.
2395 /// };
2396 /// \endcode
2397 class CXXConstructorDecl final
2398     : public CXXMethodDecl,
2399       private llvm::TrailingObjects<CXXConstructorDecl, InheritedConstructor> {
2400   /// \name Support for base and member initializers.
2401   /// \{
2402   /// \brief The arguments used to initialize the base or member.
2403   LazyCXXCtorInitializersPtr CtorInitializers;
2404   unsigned NumCtorInitializers : 31;
2405   /// \}
2406
2407   /// \brief Whether this constructor declaration is an implicitly-declared
2408   /// inheriting constructor.
2409   unsigned IsInheritingConstructor : 1;
2410
2411   CXXConstructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2412                      const DeclarationNameInfo &NameInfo,
2413                      QualType T, TypeSourceInfo *TInfo,
2414                      bool isExplicitSpecified, bool isInline,
2415                      bool isImplicitlyDeclared, bool isConstexpr,
2416                      InheritedConstructor Inherited)
2417     : CXXMethodDecl(CXXConstructor, C, RD, StartLoc, NameInfo, T, TInfo,
2418                     SC_None, isInline, isConstexpr, SourceLocation()),
2419       NumCtorInitializers(0), IsInheritingConstructor((bool)Inherited) {
2420     setImplicit(isImplicitlyDeclared);
2421     if (Inherited)
2422       *getTrailingObjects<InheritedConstructor>() = Inherited;
2423     IsExplicitSpecified = isExplicitSpecified;
2424   }
2425
2426   void anchor() override;
2427
2428 public:
2429   friend class ASTDeclReader;
2430   friend class ASTDeclWriter;
2431   friend TrailingObjects;
2432
2433   static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID,
2434                                                 bool InheritsConstructor);
2435   static CXXConstructorDecl *
2436   Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2437          const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2438          bool isExplicit, bool isInline, bool isImplicitlyDeclared,
2439          bool isConstexpr,
2440          InheritedConstructor Inherited = InheritedConstructor());
2441
2442   /// \brief Iterates through the member/base initializer list.
2443   using init_iterator = CXXCtorInitializer **;
2444
2445   /// \brief Iterates through the member/base initializer list.
2446   using init_const_iterator = CXXCtorInitializer *const *;
2447
2448   using init_range = llvm::iterator_range<init_iterator>;
2449   using init_const_range = llvm::iterator_range<init_const_iterator>;
2450
2451   init_range inits() { return init_range(init_begin(), init_end()); }
2452   init_const_range inits() const {
2453     return init_const_range(init_begin(), init_end());
2454   }
2455
2456   /// \brief Retrieve an iterator to the first initializer.
2457   init_iterator init_begin() {
2458     const auto *ConstThis = this;
2459     return const_cast<init_iterator>(ConstThis->init_begin());
2460   }
2461
2462   /// \brief Retrieve an iterator to the first initializer.
2463   init_const_iterator init_begin() const;
2464
2465   /// \brief Retrieve an iterator past the last initializer.
2466   init_iterator       init_end()       {
2467     return init_begin() + NumCtorInitializers;
2468   }
2469
2470   /// \brief Retrieve an iterator past the last initializer.
2471   init_const_iterator init_end() const {
2472     return init_begin() + NumCtorInitializers;
2473   }
2474
2475   using init_reverse_iterator = std::reverse_iterator<init_iterator>;
2476   using init_const_reverse_iterator =
2477       std::reverse_iterator<init_const_iterator>;
2478
2479   init_reverse_iterator init_rbegin() {
2480     return init_reverse_iterator(init_end());
2481   }
2482   init_const_reverse_iterator init_rbegin() const {
2483     return init_const_reverse_iterator(init_end());
2484   }
2485
2486   init_reverse_iterator init_rend() {
2487     return init_reverse_iterator(init_begin());
2488   }
2489   init_const_reverse_iterator init_rend() const {
2490     return init_const_reverse_iterator(init_begin());
2491   }
2492
2493   /// \brief Determine the number of arguments used to initialize the member
2494   /// or base.
2495   unsigned getNumCtorInitializers() const {
2496       return NumCtorInitializers;
2497   }
2498
2499   void setNumCtorInitializers(unsigned numCtorInitializers) {
2500     NumCtorInitializers = numCtorInitializers;
2501   }
2502
2503   void setCtorInitializers(CXXCtorInitializer **Initializers) {
2504     CtorInitializers = Initializers;
2505   }
2506
2507   /// Whether this function is marked as explicit explicitly.
2508   bool isExplicitSpecified() const { return IsExplicitSpecified; }
2509
2510   /// Whether this function is explicit.
2511   bool isExplicit() const {
2512     return getCanonicalDecl()->isExplicitSpecified();
2513   }
2514
2515   /// \brief Determine whether this constructor is a delegating constructor.
2516   bool isDelegatingConstructor() const {
2517     return (getNumCtorInitializers() == 1) &&
2518            init_begin()[0]->isDelegatingInitializer();
2519   }
2520
2521   /// \brief When this constructor delegates to another, retrieve the target.
2522   CXXConstructorDecl *getTargetConstructor() const;
2523
2524   /// Whether this constructor is a default
2525   /// constructor (C++ [class.ctor]p5), which can be used to
2526   /// default-initialize a class of this type.
2527   bool isDefaultConstructor() const;
2528
2529   /// \brief Whether this constructor is a copy constructor (C++ [class.copy]p2,
2530   /// which can be used to copy the class.
2531   ///
2532   /// \p TypeQuals will be set to the qualifiers on the
2533   /// argument type. For example, \p TypeQuals would be set to \c
2534   /// Qualifiers::Const for the following copy constructor:
2535   ///
2536   /// \code
2537   /// class X {
2538   /// public:
2539   ///   X(const X&);
2540   /// };
2541   /// \endcode
2542   bool isCopyConstructor(unsigned &TypeQuals) const;
2543
2544   /// Whether this constructor is a copy
2545   /// constructor (C++ [class.copy]p2, which can be used to copy the
2546   /// class.
2547   bool isCopyConstructor() const {
2548     unsigned TypeQuals = 0;
2549     return isCopyConstructor(TypeQuals);
2550   }
2551
2552   /// \brief Determine whether this constructor is a move constructor
2553   /// (C++11 [class.copy]p3), which can be used to move values of the class.
2554   ///
2555   /// \param TypeQuals If this constructor is a move constructor, will be set
2556   /// to the type qualifiers on the referent of the first parameter's type.
2557   bool isMoveConstructor(unsigned &TypeQuals) const;
2558
2559   /// \brief Determine whether this constructor is a move constructor
2560   /// (C++11 [class.copy]p3), which can be used to move values of the class.
2561   bool isMoveConstructor() const {
2562     unsigned TypeQuals = 0;
2563     return isMoveConstructor(TypeQuals);
2564   }
2565
2566   /// \brief Determine whether this is a copy or move constructor.
2567   ///
2568   /// \param TypeQuals Will be set to the type qualifiers on the reference
2569   /// parameter, if in fact this is a copy or move constructor.
2570   bool isCopyOrMoveConstructor(unsigned &TypeQuals) const;
2571
2572   /// \brief Determine whether this a copy or move constructor.
2573   bool isCopyOrMoveConstructor() const {
2574     unsigned Quals;
2575     return isCopyOrMoveConstructor(Quals);
2576   }
2577
2578   /// Whether this constructor is a
2579   /// converting constructor (C++ [class.conv.ctor]), which can be
2580   /// used for user-defined conversions.
2581   bool isConvertingConstructor(bool AllowExplicit) const;
2582
2583   /// \brief Determine whether this is a member template specialization that
2584   /// would copy the object to itself. Such constructors are never used to copy
2585   /// an object.
2586   bool isSpecializationCopyingObject() const;
2587
2588   /// \brief Determine whether this is an implicit constructor synthesized to
2589   /// model a call to a constructor inherited from a base class.
2590   bool isInheritingConstructor() const { return IsInheritingConstructor; }
2591
2592   /// \brief Get the constructor that this inheriting constructor is based on.
2593   InheritedConstructor getInheritedConstructor() const {
2594     return IsInheritingConstructor ? *getTrailingObjects<InheritedConstructor>()
2595                                    : InheritedConstructor();
2596   }
2597
2598   CXXConstructorDecl *getCanonicalDecl() override {
2599     return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
2600   }
2601   const CXXConstructorDecl *getCanonicalDecl() const {
2602     return const_cast<CXXConstructorDecl*>(this)->getCanonicalDecl();
2603   }
2604
2605   // Implement isa/cast/dyncast/etc.
2606   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2607   static bool classofKind(Kind K) { return K == CXXConstructor; }
2608 };
2609
2610 /// \brief Represents a C++ destructor within a class.
2611 ///
2612 /// For example:
2613 ///
2614 /// \code
2615 /// class X {
2616 /// public:
2617 ///   ~X(); // represented by a CXXDestructorDecl.
2618 /// };
2619 /// \endcode
2620 class CXXDestructorDecl : public CXXMethodDecl {
2621   friend class ASTDeclReader;
2622   friend class ASTDeclWriter;
2623
2624   // FIXME: Don't allocate storage for these except in the first declaration
2625   // of a virtual destructor.
2626   FunctionDecl *OperatorDelete = nullptr;
2627   Expr *OperatorDeleteThisArg = nullptr;
2628
2629   CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2630                     const DeclarationNameInfo &NameInfo,
2631                     QualType T, TypeSourceInfo *TInfo,
2632                     bool isInline, bool isImplicitlyDeclared)
2633     : CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo,
2634                     SC_None, isInline, /*isConstexpr=*/false, SourceLocation())
2635   {
2636     setImplicit(isImplicitlyDeclared);
2637   }
2638
2639   void anchor() override;
2640
2641 public:
2642   static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2643                                    SourceLocation StartLoc,
2644                                    const DeclarationNameInfo &NameInfo,
2645                                    QualType T, TypeSourceInfo* TInfo,
2646                                    bool isInline,
2647                                    bool isImplicitlyDeclared);
2648   static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID);
2649
2650   void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg);
2651
2652   const FunctionDecl *getOperatorDelete() const {
2653     return getCanonicalDecl()->OperatorDelete;
2654   }
2655
2656   Expr *getOperatorDeleteThisArg() const {
2657     return getCanonicalDecl()->OperatorDeleteThisArg;
2658   }
2659
2660   CXXDestructorDecl *getCanonicalDecl() override {
2661     return cast<CXXDestructorDecl>(FunctionDecl::getCanonicalDecl());
2662   }
2663   const CXXDestructorDecl *getCanonicalDecl() const {
2664     return const_cast<CXXDestructorDecl*>(this)->getCanonicalDecl();
2665   }
2666
2667   // Implement isa/cast/dyncast/etc.
2668   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2669   static bool classofKind(Kind K) { return K == CXXDestructor; }
2670 };
2671
2672 /// \brief Represents a C++ conversion function within a class.
2673 ///
2674 /// For example:
2675 ///
2676 /// \code
2677 /// class X {
2678 /// public:
2679 ///   operator bool();
2680 /// };
2681 /// \endcode
2682 class CXXConversionDecl : public CXXMethodDecl {
2683   CXXConversionDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2684                     const DeclarationNameInfo &NameInfo, QualType T,
2685                     TypeSourceInfo *TInfo, bool isInline,
2686                     bool isExplicitSpecified, bool isConstexpr,
2687                     SourceLocation EndLocation)
2688       : CXXMethodDecl(CXXConversion, C, RD, StartLoc, NameInfo, T, TInfo,
2689                       SC_None, isInline, isConstexpr, EndLocation) {
2690     IsExplicitSpecified = isExplicitSpecified;
2691   }
2692
2693   void anchor() override;
2694
2695 public:
2696   friend class ASTDeclReader;
2697   friend class ASTDeclWriter;
2698
2699   static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2700                                    SourceLocation StartLoc,
2701                                    const DeclarationNameInfo &NameInfo,
2702                                    QualType T, TypeSourceInfo *TInfo,
2703                                    bool isInline, bool isExplicit,
2704                                    bool isConstexpr,
2705                                    SourceLocation EndLocation);
2706   static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2707
2708   /// Whether this function is marked as explicit explicitly.
2709   bool isExplicitSpecified() const { return IsExplicitSpecified; }
2710
2711   /// Whether this function is explicit.
2712   bool isExplicit() const {
2713     return getCanonicalDecl()->isExplicitSpecified();
2714   }
2715
2716   /// \brief Returns the type that this conversion function is converting to.
2717   QualType getConversionType() const {
2718     return getType()->getAs<FunctionType>()->getReturnType();
2719   }
2720
2721   /// \brief Determine whether this conversion function is a conversion from
2722   /// a lambda closure type to a block pointer.
2723   bool isLambdaToBlockPointerConversion() const;
2724   
2725   CXXConversionDecl *getCanonicalDecl() override {
2726     return cast<CXXConversionDecl>(FunctionDecl::getCanonicalDecl());
2727   }
2728   const CXXConversionDecl *getCanonicalDecl() const {
2729     return const_cast<CXXConversionDecl*>(this)->getCanonicalDecl();
2730   }
2731
2732   // Implement isa/cast/dyncast/etc.
2733   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2734   static bool classofKind(Kind K) { return K == CXXConversion; }
2735 };
2736
2737 /// \brief Represents a linkage specification. 
2738 ///
2739 /// For example:
2740 /// \code
2741 ///   extern "C" void foo();
2742 /// \endcode
2743 class LinkageSpecDecl : public Decl, public DeclContext {
2744   virtual void anchor();
2745
2746 public:
2747   /// \brief Represents the language in a linkage specification.
2748   ///
2749   /// The values are part of the serialization ABI for
2750   /// ASTs and cannot be changed without altering that ABI.  To help
2751   /// ensure a stable ABI for this, we choose the DW_LANG_ encodings
2752   /// from the dwarf standard.
2753   enum LanguageIDs {
2754     lang_c = /* DW_LANG_C */ 0x0002,
2755     lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
2756   };
2757
2758 private:
2759   /// \brief The language for this linkage specification.
2760   unsigned Language : 3;
2761
2762   /// \brief True if this linkage spec has braces.
2763   ///
2764   /// This is needed so that hasBraces() returns the correct result while the
2765   /// linkage spec body is being parsed.  Once RBraceLoc has been set this is
2766   /// not used, so it doesn't need to be serialized.
2767   unsigned HasBraces : 1;
2768
2769   /// \brief The source location for the extern keyword.
2770   SourceLocation ExternLoc;
2771
2772   /// \brief The source location for the right brace (if valid).
2773   SourceLocation RBraceLoc;
2774
2775   LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
2776                   SourceLocation LangLoc, LanguageIDs lang, bool HasBraces)
2777       : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
2778         Language(lang), HasBraces(HasBraces), ExternLoc(ExternLoc),
2779         RBraceLoc(SourceLocation()) {}
2780
2781 public:
2782   static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
2783                                  SourceLocation ExternLoc,
2784                                  SourceLocation LangLoc, LanguageIDs Lang,
2785                                  bool HasBraces);
2786   static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2787   
2788   /// \brief Return the language specified by this linkage specification.
2789   LanguageIDs getLanguage() const { return LanguageIDs(Language); }
2790
2791   /// \brief Set the language specified by this linkage specification.
2792   void setLanguage(LanguageIDs L) { Language = L; }
2793
2794   /// \brief Determines whether this linkage specification had braces in
2795   /// its syntactic form.
2796   bool hasBraces() const {
2797     assert(!RBraceLoc.isValid() || HasBraces);
2798     return HasBraces;
2799   }
2800
2801   SourceLocation getExternLoc() const { return ExternLoc; }
2802   SourceLocation getRBraceLoc() const { return RBraceLoc; }
2803   void setExternLoc(SourceLocation L) { ExternLoc = L; }
2804   void setRBraceLoc(SourceLocation L) {
2805     RBraceLoc = L;
2806     HasBraces = RBraceLoc.isValid();
2807   }
2808
2809   SourceLocation getLocEnd() const LLVM_READONLY {
2810     if (hasBraces())
2811       return getRBraceLoc();
2812     // No braces: get the end location of the (only) declaration in context
2813     // (if present).
2814     return decls_empty() ? getLocation() : decls_begin()->getLocEnd();
2815   }
2816
2817   SourceRange getSourceRange() const override LLVM_READONLY {
2818     return SourceRange(ExternLoc, getLocEnd());
2819   }
2820
2821   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2822   static bool classofKind(Kind K) { return K == LinkageSpec; }
2823
2824   static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
2825     return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
2826   }
2827
2828   static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
2829     return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
2830   }
2831 };
2832
2833 /// \brief Represents C++ using-directive.
2834 ///
2835 /// For example:
2836 /// \code
2837 ///    using namespace std;
2838 /// \endcode
2839 ///
2840 /// \note UsingDirectiveDecl should be Decl not NamedDecl, but we provide
2841 /// artificial names for all using-directives in order to store
2842 /// them in DeclContext effectively.
2843 class UsingDirectiveDecl : public NamedDecl {
2844   /// \brief The location of the \c using keyword.
2845   SourceLocation UsingLoc;
2846
2847   /// \brief The location of the \c namespace keyword.
2848   SourceLocation NamespaceLoc;
2849
2850   /// \brief The nested-name-specifier that precedes the namespace.
2851   NestedNameSpecifierLoc QualifierLoc;
2852
2853   /// \brief The namespace nominated by this using-directive.
2854   NamedDecl *NominatedNamespace;
2855
2856   /// Enclosing context containing both using-directive and nominated
2857   /// namespace.
2858   DeclContext *CommonAncestor;
2859
2860   UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
2861                      SourceLocation NamespcLoc,
2862                      NestedNameSpecifierLoc QualifierLoc,
2863                      SourceLocation IdentLoc,
2864                      NamedDecl *Nominated,
2865                      DeclContext *CommonAncestor)
2866       : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
2867         NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
2868         NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) {}
2869
2870   /// \brief Returns special DeclarationName used by using-directives.
2871   ///
2872   /// This is only used by DeclContext for storing UsingDirectiveDecls in
2873   /// its lookup structure.
2874   static DeclarationName getName() {
2875     return DeclarationName::getUsingDirectiveName();
2876   }
2877
2878   void anchor() override;
2879
2880 public:
2881   friend class ASTDeclReader;
2882
2883   // Friend for getUsingDirectiveName.
2884   friend class DeclContext;
2885
2886   /// \brief Retrieve the nested-name-specifier that qualifies the
2887   /// name of the namespace, with source-location information.
2888   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2889
2890   /// \brief Retrieve the nested-name-specifier that qualifies the
2891   /// name of the namespace.
2892   NestedNameSpecifier *getQualifier() const {
2893     return QualifierLoc.getNestedNameSpecifier();
2894   }
2895
2896   NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
2897   const NamedDecl *getNominatedNamespaceAsWritten() const {
2898     return NominatedNamespace;
2899   }
2900
2901   /// \brief Returns the namespace nominated by this using-directive.
2902   NamespaceDecl *getNominatedNamespace();
2903
2904   const NamespaceDecl *getNominatedNamespace() const {
2905     return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
2906   }
2907
2908   /// \brief Returns the common ancestor context of this using-directive and
2909   /// its nominated namespace.
2910   DeclContext *getCommonAncestor() { return CommonAncestor; }
2911   const DeclContext *getCommonAncestor() const { return CommonAncestor; }
2912
2913   /// \brief Return the location of the \c using keyword.
2914   SourceLocation getUsingLoc() const { return UsingLoc; }
2915
2916   // FIXME: Could omit 'Key' in name.
2917   /// \brief Returns the location of the \c namespace keyword.
2918   SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
2919
2920   /// \brief Returns the location of this using declaration's identifier.
2921   SourceLocation getIdentLocation() const { return getLocation(); }
2922
2923   static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
2924                                     SourceLocation UsingLoc,
2925                                     SourceLocation NamespaceLoc,
2926                                     NestedNameSpecifierLoc QualifierLoc,
2927                                     SourceLocation IdentLoc,
2928                                     NamedDecl *Nominated,
2929                                     DeclContext *CommonAncestor);
2930   static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2931
2932   SourceRange getSourceRange() const override LLVM_READONLY {
2933     return SourceRange(UsingLoc, getLocation());
2934   }
2935
2936   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2937   static bool classofKind(Kind K) { return K == UsingDirective; }
2938 };
2939
2940 /// \brief Represents a C++ namespace alias.
2941 ///
2942 /// For example:
2943 ///
2944 /// \code
2945 /// namespace Foo = Bar;
2946 /// \endcode
2947 class NamespaceAliasDecl : public NamedDecl,
2948                            public Redeclarable<NamespaceAliasDecl> {
2949   friend class ASTDeclReader;
2950
2951   /// \brief The location of the \c namespace keyword.
2952   SourceLocation NamespaceLoc;
2953
2954   /// \brief The location of the namespace's identifier.
2955   ///
2956   /// This is accessed by TargetNameLoc.
2957   SourceLocation IdentLoc;
2958
2959   /// \brief The nested-name-specifier that precedes the namespace.
2960   NestedNameSpecifierLoc QualifierLoc;
2961
2962   /// \brief The Decl that this alias points to, either a NamespaceDecl or
2963   /// a NamespaceAliasDecl.
2964   NamedDecl *Namespace;
2965
2966   NamespaceAliasDecl(ASTContext &C, DeclContext *DC,
2967                      SourceLocation NamespaceLoc, SourceLocation AliasLoc,
2968                      IdentifierInfo *Alias, NestedNameSpecifierLoc QualifierLoc,
2969                      SourceLocation IdentLoc, NamedDecl *Namespace)
2970       : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias), redeclarable_base(C),
2971         NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc),
2972         QualifierLoc(QualifierLoc), Namespace(Namespace) {}
2973
2974   void anchor() override;
2975
2976   using redeclarable_base = Redeclarable<NamespaceAliasDecl>;
2977
2978   NamespaceAliasDecl *getNextRedeclarationImpl() override;
2979   NamespaceAliasDecl *getPreviousDeclImpl() override;
2980   NamespaceAliasDecl *getMostRecentDeclImpl() override;
2981
2982 public:
2983   static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
2984                                     SourceLocation NamespaceLoc,
2985                                     SourceLocation AliasLoc,
2986                                     IdentifierInfo *Alias,
2987                                     NestedNameSpecifierLoc QualifierLoc,
2988                                     SourceLocation IdentLoc,
2989                                     NamedDecl *Namespace);
2990
2991   static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2992
2993   using redecl_range = redeclarable_base::redecl_range;
2994   using redecl_iterator = redeclarable_base::redecl_iterator;
2995
2996   using redeclarable_base::redecls_begin;
2997   using redeclarable_base::redecls_end;
2998   using redeclarable_base::redecls;
2999   using redeclarable_base::getPreviousDecl;
3000   using redeclarable_base::getMostRecentDecl;
3001
3002   NamespaceAliasDecl *getCanonicalDecl() override {
3003     return getFirstDecl();
3004   }
3005   const NamespaceAliasDecl *getCanonicalDecl() const {
3006     return getFirstDecl();
3007   }
3008
3009   /// \brief Retrieve the nested-name-specifier that qualifies the
3010   /// name of the namespace, with source-location information.
3011   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3012
3013   /// \brief Retrieve the nested-name-specifier that qualifies the
3014   /// name of the namespace.
3015   NestedNameSpecifier *getQualifier() const {
3016     return QualifierLoc.getNestedNameSpecifier();
3017   }
3018
3019   /// \brief Retrieve the namespace declaration aliased by this directive.
3020   NamespaceDecl *getNamespace() {
3021     if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
3022       return AD->getNamespace();
3023
3024     return cast<NamespaceDecl>(Namespace);
3025   }
3026
3027   const NamespaceDecl *getNamespace() const {
3028     return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
3029   }
3030
3031   /// Returns the location of the alias name, i.e. 'foo' in
3032   /// "namespace foo = ns::bar;".
3033   SourceLocation getAliasLoc() const { return getLocation(); }
3034
3035   /// Returns the location of the \c namespace keyword.
3036   SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
3037
3038   /// Returns the location of the identifier in the named namespace.
3039   SourceLocation getTargetNameLoc() const { return IdentLoc; }
3040
3041   /// \brief Retrieve the namespace that this alias refers to, which
3042   /// may either be a NamespaceDecl or a NamespaceAliasDecl.
3043   NamedDecl *getAliasedNamespace() const { return Namespace; }
3044
3045   SourceRange getSourceRange() const override LLVM_READONLY {
3046     return SourceRange(NamespaceLoc, IdentLoc);
3047   }
3048
3049   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3050   static bool classofKind(Kind K) { return K == NamespaceAlias; }
3051 };
3052
3053 /// \brief Represents a shadow declaration introduced into a scope by a
3054 /// (resolved) using declaration.
3055 ///
3056 /// For example,
3057 /// \code
3058 /// namespace A {
3059 ///   void foo();
3060 /// }
3061 /// namespace B {
3062 ///   using A::foo; // <- a UsingDecl
3063 ///                 // Also creates a UsingShadowDecl for A::foo() in B
3064 /// }
3065 /// \endcode
3066 class UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> {
3067   friend class UsingDecl;
3068
3069   /// The referenced declaration.
3070   NamedDecl *Underlying = nullptr;
3071
3072   /// \brief The using declaration which introduced this decl or the next using
3073   /// shadow declaration contained in the aforementioned using declaration.
3074   NamedDecl *UsingOrNextShadow = nullptr;
3075
3076   void anchor() override;
3077
3078   using redeclarable_base = Redeclarable<UsingShadowDecl>;
3079
3080   UsingShadowDecl *getNextRedeclarationImpl() override {
3081     return getNextRedeclaration();
3082   }
3083
3084   UsingShadowDecl *getPreviousDeclImpl() override {
3085     return getPreviousDecl();
3086   }
3087
3088   UsingShadowDecl *getMostRecentDeclImpl() override {
3089     return getMostRecentDecl();
3090   }
3091
3092 protected:
3093   UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC, SourceLocation Loc,
3094                   UsingDecl *Using, NamedDecl *Target);
3095   UsingShadowDecl(Kind K, ASTContext &C, EmptyShell);
3096
3097 public:
3098   friend class ASTDeclReader;
3099   friend class ASTDeclWriter;
3100
3101   static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
3102                                  SourceLocation Loc, UsingDecl *Using,
3103                                  NamedDecl *Target) {
3104     return new (C, DC) UsingShadowDecl(UsingShadow, C, DC, Loc, Using, Target);
3105   }
3106
3107   static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3108
3109   using redecl_range = redeclarable_base::redecl_range;
3110   using redecl_iterator = redeclarable_base::redecl_iterator;
3111
3112   using redeclarable_base::redecls_begin;
3113   using redeclarable_base::redecls_end;
3114   using redeclarable_base::redecls;
3115   using redeclarable_base::getPreviousDecl;
3116   using redeclarable_base::getMostRecentDecl;
3117   using redeclarable_base::isFirstDecl;
3118
3119   UsingShadowDecl *getCanonicalDecl() override {
3120     return getFirstDecl();
3121   }
3122   const UsingShadowDecl *getCanonicalDecl() const {
3123     return getFirstDecl();
3124   }
3125
3126   /// \brief Gets the underlying declaration which has been brought into the
3127   /// local scope.
3128   NamedDecl *getTargetDecl() const { return Underlying; }
3129
3130   /// \brief Sets the underlying declaration which has been brought into the
3131   /// local scope.
3132   void setTargetDecl(NamedDecl* ND) {
3133     assert(ND && "Target decl is null!");
3134     Underlying = ND;
3135     IdentifierNamespace = ND->getIdentifierNamespace();
3136   }
3137
3138   /// \brief Gets the using declaration to which this declaration is tied.
3139   UsingDecl *getUsingDecl() const;
3140
3141   /// \brief The next using shadow declaration contained in the shadow decl
3142   /// chain of the using declaration which introduced this decl.
3143   UsingShadowDecl *getNextUsingShadowDecl() const {
3144     return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow);
3145   }
3146
3147   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3148   static bool classofKind(Kind K) {
3149     return K == Decl::UsingShadow || K == Decl::ConstructorUsingShadow;
3150   }
3151 };
3152
3153 /// \brief Represents a shadow constructor declaration introduced into a
3154 /// class by a C++11 using-declaration that names a constructor.
3155 ///
3156 /// For example:
3157 /// \code
3158 /// struct Base { Base(int); };
3159 /// struct Derived {
3160 ///    using Base::Base; // creates a UsingDecl and a ConstructorUsingShadowDecl
3161 /// };
3162 /// \endcode
3163 class ConstructorUsingShadowDecl final : public UsingShadowDecl {
3164   /// \brief If this constructor using declaration inherted the constructor
3165   /// from an indirect base class, this is the ConstructorUsingShadowDecl
3166   /// in the named direct base class from which the declaration was inherited.
3167   ConstructorUsingShadowDecl *NominatedBaseClassShadowDecl = nullptr;
3168
3169   /// \brief If this constructor using declaration inherted the constructor
3170   /// from an indirect base class, this is the ConstructorUsingShadowDecl
3171   /// that will be used to construct the unique direct or virtual base class
3172   /// that receives the constructor arguments.
3173   ConstructorUsingShadowDecl *ConstructedBaseClassShadowDecl = nullptr;
3174
3175   /// \brief \c true if the constructor ultimately named by this using shadow
3176   /// declaration is within a virtual base class subobject of the class that
3177   /// contains this declaration.
3178   unsigned IsVirtual : 1;
3179
3180   ConstructorUsingShadowDecl(ASTContext &C, DeclContext *DC, SourceLocation Loc,
3181                              UsingDecl *Using, NamedDecl *Target,
3182                              bool TargetInVirtualBase)
3183       : UsingShadowDecl(ConstructorUsingShadow, C, DC, Loc, Using,
3184                         Target->getUnderlyingDecl()),
3185         NominatedBaseClassShadowDecl(
3186             dyn_cast<ConstructorUsingShadowDecl>(Target)),
3187         ConstructedBaseClassShadowDecl(NominatedBaseClassShadowDecl),
3188         IsVirtual(TargetInVirtualBase) {
3189     // If we found a constructor that chains to a constructor for a virtual
3190     // base, we should directly call that virtual base constructor instead.
3191     // FIXME: This logic belongs in Sema.
3192     if (NominatedBaseClassShadowDecl &&
3193         NominatedBaseClassShadowDecl->constructsVirtualBase()) {
3194       ConstructedBaseClassShadowDecl =
3195           NominatedBaseClassShadowDecl->ConstructedBaseClassShadowDecl;
3196       IsVirtual = true;
3197     }
3198   }
3199
3200   ConstructorUsingShadowDecl(ASTContext &C, EmptyShell Empty)
3201       : UsingShadowDecl(ConstructorUsingShadow, C, Empty), IsVirtual(false) {}
3202
3203   void anchor() override;
3204
3205 public:
3206   friend class ASTDeclReader;
3207   friend class ASTDeclWriter;
3208
3209   static ConstructorUsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
3210                                             SourceLocation Loc,
3211                                             UsingDecl *Using, NamedDecl *Target,
3212                                             bool IsVirtual);
3213   static ConstructorUsingShadowDecl *CreateDeserialized(ASTContext &C,
3214                                                         unsigned ID);
3215
3216   /// Returns the parent of this using shadow declaration, which
3217   /// is the class in which this is declared.
3218   //@{
3219   const CXXRecordDecl *getParent() const {
3220     return cast<CXXRecordDecl>(getDeclContext());
3221   }
3222   CXXRecordDecl *getParent() {
3223     return cast<CXXRecordDecl>(getDeclContext());
3224   }
3225   //@}
3226
3227   /// \brief Get the inheriting constructor declaration for the direct base
3228   /// class from which this using shadow declaration was inherited, if there is
3229   /// one. This can be different for each redeclaration of the same shadow decl.
3230   ConstructorUsingShadowDecl *getNominatedBaseClassShadowDecl() const {
3231     return NominatedBaseClassShadowDecl;
3232   }
3233
3234   /// \brief Get the inheriting constructor declaration for the base class
3235   /// for which we don't have an explicit initializer, if there is one.
3236   ConstructorUsingShadowDecl *getConstructedBaseClassShadowDecl() const {
3237     return ConstructedBaseClassShadowDecl;
3238   }
3239
3240   /// \brief Get the base class that was named in the using declaration. This
3241   /// can be different for each redeclaration of this same shadow decl.
3242   CXXRecordDecl *getNominatedBaseClass() const;
3243
3244   /// \brief Get the base class whose constructor or constructor shadow
3245   /// declaration is passed the constructor arguments.
3246   CXXRecordDecl *getConstructedBaseClass() const {
3247     return cast<CXXRecordDecl>((ConstructedBaseClassShadowDecl
3248                                     ? ConstructedBaseClassShadowDecl
3249                                     : getTargetDecl())
3250                                    ->getDeclContext());
3251   }
3252
3253   /// \brief Returns \c true if the constructed base class is a virtual base
3254   /// class subobject of this declaration's class.
3255   bool constructsVirtualBase() const {
3256     return IsVirtual;
3257   }
3258
3259   /// \brief Get the constructor or constructor template in the derived class
3260   /// correspnding to this using shadow declaration, if it has been implicitly
3261   /// declared already.
3262   CXXConstructorDecl *getConstructor() const;
3263   void setConstructor(NamedDecl *Ctor);
3264
3265   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3266   static bool classofKind(Kind K) { return K == ConstructorUsingShadow; }
3267 };
3268
3269 /// \brief Represents a C++ using-declaration.
3270 ///
3271 /// For example:
3272 /// \code
3273 ///    using someNameSpace::someIdentifier;
3274 /// \endcode
3275 class UsingDecl : public NamedDecl, public Mergeable<UsingDecl> {
3276   /// \brief The source location of the 'using' keyword itself.
3277   SourceLocation UsingLocation;
3278
3279   /// \brief The nested-name-specifier that precedes the name.
3280   NestedNameSpecifierLoc QualifierLoc;
3281
3282   /// \brief Provides source/type location info for the declaration name
3283   /// embedded in the ValueDecl base class.
3284   DeclarationNameLoc DNLoc;
3285
3286   /// \brief The first shadow declaration of the shadow decl chain associated
3287   /// with this using declaration.
3288   ///
3289   /// The bool member of the pair store whether this decl has the \c typename
3290   /// keyword.
3291   llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow;
3292
3293   UsingDecl(DeclContext *DC, SourceLocation UL,
3294             NestedNameSpecifierLoc QualifierLoc,
3295             const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword)
3296     : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()),
3297       UsingLocation(UL), QualifierLoc(QualifierLoc),
3298       DNLoc(NameInfo.getInfo()), FirstUsingShadow(nullptr, HasTypenameKeyword) {
3299   }
3300
3301   void anchor() override;
3302
3303 public:
3304   friend class ASTDeclReader;
3305   friend class ASTDeclWriter;
3306
3307   /// \brief Return the source location of the 'using' keyword.
3308   SourceLocation getUsingLoc() const { return UsingLocation; }
3309
3310   /// \brief Set the source location of the 'using' keyword.
3311   void setUsingLoc(SourceLocation L) { UsingLocation = L; }
3312
3313   /// \brief Retrieve the nested-name-specifier that qualifies the name,
3314   /// with source-location information.
3315   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3316
3317   /// \brief Retrieve the nested-name-specifier that qualifies the name.
3318   NestedNameSpecifier *getQualifier() const {
3319     return QualifierLoc.getNestedNameSpecifier();
3320   }
3321
3322   DeclarationNameInfo getNameInfo() const {
3323     return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
3324   }
3325
3326   /// \brief Return true if it is a C++03 access declaration (no 'using').
3327   bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
3328
3329   /// \brief Return true if the using declaration has 'typename'.
3330   bool hasTypename() const { return FirstUsingShadow.getInt(); }
3331
3332   /// \brief Sets whether the using declaration has 'typename'.
3333   void setTypename(bool TN) { FirstUsingShadow.setInt(TN); }
3334
3335   /// \brief Iterates through the using shadow declarations associated with
3336   /// this using declaration.
3337   class shadow_iterator {
3338     /// \brief The current using shadow declaration.
3339     UsingShadowDecl *Current = nullptr;
3340
3341   public:
3342     using value_type = UsingShadowDecl *;
3343     using reference = UsingShadowDecl *;
3344     using pointer = UsingShadowDecl *;
3345     using iterator_category = std::forward_iterator_tag;
3346     using difference_type = std::ptrdiff_t;
3347
3348     shadow_iterator() = default;
3349     explicit shadow_iterator(UsingShadowDecl *C) : Current(C) {}
3350
3351     reference operator*() const { return Current; }
3352     pointer operator->() const { return Current; }
3353
3354     shadow_iterator& operator++() {
3355       Current = Current->getNextUsingShadowDecl();
3356       return *this;
3357     }
3358
3359     shadow_iterator operator++(int) {
3360       shadow_iterator tmp(*this);
3361       ++(*this);
3362       return tmp;
3363     }
3364
3365     friend bool operator==(shadow_iterator x, shadow_iterator y) {
3366       return x.Current == y.Current;
3367     }
3368     friend bool operator!=(shadow_iterator x, shadow_iterator y) {
3369       return x.Current != y.Current;
3370     }
3371   };
3372
3373   using shadow_range = llvm::iterator_range<shadow_iterator>;
3374
3375   shadow_range shadows() const {
3376     return shadow_range(shadow_begin(), shadow_end());
3377   }
3378
3379   shadow_iterator shadow_begin() const {
3380     return shadow_iterator(FirstUsingShadow.getPointer());
3381   }
3382
3383   shadow_iterator shadow_end() const { return shadow_iterator(); }
3384
3385   /// \brief Return the number of shadowed declarations associated with this
3386   /// using declaration.
3387   unsigned shadow_size() const {
3388     return std::distance(shadow_begin(), shadow_end());
3389   }
3390
3391   void addShadowDecl(UsingShadowDecl *S);
3392   void removeShadowDecl(UsingShadowDecl *S);
3393
3394   static UsingDecl *Create(ASTContext &C, DeclContext *DC,
3395                            SourceLocation UsingL,
3396                            NestedNameSpecifierLoc QualifierLoc,
3397                            const DeclarationNameInfo &NameInfo,
3398                            bool HasTypenameKeyword);
3399
3400   static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3401
3402   SourceRange getSourceRange() const override LLVM_READONLY;
3403
3404   /// Retrieves the canonical declaration of this declaration.
3405   UsingDecl *getCanonicalDecl() override { return getFirstDecl(); }
3406   const UsingDecl *getCanonicalDecl() const { return getFirstDecl(); }
3407
3408   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3409   static bool classofKind(Kind K) { return K == Using; }
3410 };
3411
3412 /// Represents a pack of using declarations that a single
3413 /// using-declarator pack-expanded into.
3414 ///
3415 /// \code
3416 /// template<typename ...T> struct X : T... {
3417 ///   using T::operator()...;
3418 ///   using T::operator T...;
3419 /// };
3420 /// \endcode
3421 ///
3422 /// In the second case above, the UsingPackDecl will have the name
3423 /// 'operator T' (which contains an unexpanded pack), but the individual
3424 /// UsingDecls and UsingShadowDecls will have more reasonable names.
3425 class UsingPackDecl final
3426     : public NamedDecl, public Mergeable<UsingPackDecl>,
3427       private llvm::TrailingObjects<UsingPackDecl, NamedDecl *> {
3428   /// The UnresolvedUsingValueDecl or UnresolvedUsingTypenameDecl from
3429   /// which this waas instantiated.
3430   NamedDecl *InstantiatedFrom;
3431
3432   /// The number of using-declarations created by this pack expansion.
3433   unsigned NumExpansions;
3434
3435   UsingPackDecl(DeclContext *DC, NamedDecl *InstantiatedFrom,
3436                 ArrayRef<NamedDecl *> UsingDecls)
3437       : NamedDecl(UsingPack, DC,
3438                   InstantiatedFrom ? InstantiatedFrom->getLocation()
3439                                    : SourceLocation(),
3440                   InstantiatedFrom ? InstantiatedFrom->getDeclName()
3441                                    : DeclarationName()),
3442         InstantiatedFrom(InstantiatedFrom), NumExpansions(UsingDecls.size()) {
3443     std::uninitialized_copy(UsingDecls.begin(), UsingDecls.end(),
3444                             getTrailingObjects<NamedDecl *>());
3445   }
3446
3447   void anchor() override;
3448
3449 public:
3450   friend class ASTDeclReader;
3451   friend class ASTDeclWriter;
3452   friend TrailingObjects;
3453
3454   /// Get the using declaration from which this was instantiated. This will
3455   /// always be an UnresolvedUsingValueDecl or an UnresolvedUsingTypenameDecl
3456   /// that is a pack expansion.
3457   NamedDecl *getInstantiatedFromUsingDecl() const { return InstantiatedFrom; }
3458
3459   /// Get the set of using declarations that this pack expanded into. Note that
3460   /// some of these may still be unresolved.
3461   ArrayRef<NamedDecl *> expansions() const {
3462     return llvm::makeArrayRef(getTrailingObjects<NamedDecl *>(), NumExpansions);
3463   }
3464
3465   static UsingPackDecl *Create(ASTContext &C, DeclContext *DC,
3466                                NamedDecl *InstantiatedFrom,
3467                                ArrayRef<NamedDecl *> UsingDecls);
3468
3469   static UsingPackDecl *CreateDeserialized(ASTContext &C, unsigned ID,
3470                                            unsigned NumExpansions);
3471
3472   SourceRange getSourceRange() const override LLVM_READONLY {
3473     return InstantiatedFrom->getSourceRange();
3474   }
3475
3476   UsingPackDecl *getCanonicalDecl() override { return getFirstDecl(); }
3477   const UsingPackDecl *getCanonicalDecl() const { return getFirstDecl(); }
3478
3479   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3480   static bool classofKind(Kind K) { return K == UsingPack; }
3481 };
3482
3483 /// \brief Represents a dependent using declaration which was not marked with
3484 /// \c typename.
3485 ///
3486 /// Unlike non-dependent using declarations, these *only* bring through
3487 /// non-types; otherwise they would break two-phase lookup.
3488 ///
3489 /// \code
3490 /// template \<class T> class A : public Base<T> {
3491 ///   using Base<T>::foo;
3492 /// };
3493 /// \endcode
3494 class UnresolvedUsingValueDecl : public ValueDecl,
3495                                  public Mergeable<UnresolvedUsingValueDecl> {
3496   /// \brief The source location of the 'using' keyword
3497   SourceLocation UsingLocation;
3498
3499   /// \brief If this is a pack expansion, the location of the '...'.
3500   SourceLocation EllipsisLoc;
3501
3502   /// \brief The nested-name-specifier that precedes the name.
3503   NestedNameSpecifierLoc QualifierLoc;
3504
3505   /// \brief Provides source/type location info for the declaration name
3506   /// embedded in the ValueDecl base class.
3507   DeclarationNameLoc DNLoc;
3508
3509   UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
3510                            SourceLocation UsingLoc,
3511                            NestedNameSpecifierLoc QualifierLoc,
3512                            const DeclarationNameInfo &NameInfo,
3513                            SourceLocation EllipsisLoc)
3514       : ValueDecl(UnresolvedUsingValue, DC,
3515                   NameInfo.getLoc(), NameInfo.getName(), Ty),
3516         UsingLocation(UsingLoc), EllipsisLoc(EllipsisLoc),
3517         QualifierLoc(QualifierLoc), DNLoc(NameInfo.getInfo()) {}
3518
3519   void anchor() override;
3520
3521 public:
3522   friend class ASTDeclReader;
3523   friend class ASTDeclWriter;
3524
3525   /// \brief Returns the source location of the 'using' keyword.
3526   SourceLocation getUsingLoc() const { return UsingLocation; }
3527
3528   /// \brief Set the source location of the 'using' keyword.
3529   void setUsingLoc(SourceLocation L) { UsingLocation = L; }
3530
3531   /// \brief Return true if it is a C++03 access declaration (no 'using').
3532   bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
3533
3534   /// \brief Retrieve the nested-name-specifier that qualifies the name,
3535   /// with source-location information.
3536   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3537
3538   /// \brief Retrieve the nested-name-specifier that qualifies the name.
3539   NestedNameSpecifier *getQualifier() const {
3540     return QualifierLoc.getNestedNameSpecifier();
3541   }
3542
3543   DeclarationNameInfo getNameInfo() const {
3544     return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
3545   }
3546
3547   /// \brief Determine whether this is a pack expansion.
3548   bool isPackExpansion() const {
3549     return EllipsisLoc.isValid();
3550   }
3551
3552   /// \brief Get the location of the ellipsis if this is a pack expansion.
3553   SourceLocation getEllipsisLoc() const {
3554     return EllipsisLoc;
3555   }
3556
3557   static UnresolvedUsingValueDecl *
3558     Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
3559            NestedNameSpecifierLoc QualifierLoc,
3560            const DeclarationNameInfo &NameInfo, SourceLocation EllipsisLoc);
3561
3562   static UnresolvedUsingValueDecl *
3563   CreateDeserialized(ASTContext &C, unsigned ID);
3564
3565   SourceRange getSourceRange() const override LLVM_READONLY;
3566
3567   /// Retrieves the canonical declaration of this declaration.
3568   UnresolvedUsingValueDecl *getCanonicalDecl() override {
3569     return getFirstDecl();
3570   }
3571   const UnresolvedUsingValueDecl *getCanonicalDecl() const {
3572     return getFirstDecl();
3573   }
3574
3575   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3576   static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
3577 };
3578
3579 /// \brief Represents a dependent using declaration which was marked with
3580 /// \c typename.
3581 ///
3582 /// \code
3583 /// template \<class T> class A : public Base<T> {
3584 ///   using typename Base<T>::foo;
3585 /// };
3586 /// \endcode
3587 ///
3588 /// The type associated with an unresolved using typename decl is
3589 /// currently always a typename type.
3590 class UnresolvedUsingTypenameDecl
3591     : public TypeDecl,
3592       public Mergeable<UnresolvedUsingTypenameDecl> {
3593   friend class ASTDeclReader;
3594
3595   /// \brief The source location of the 'typename' keyword
3596   SourceLocation TypenameLocation;
3597
3598   /// \brief If this is a pack expansion, the location of the '...'.
3599   SourceLocation EllipsisLoc;
3600
3601   /// \brief The nested-name-specifier that precedes the name.
3602   NestedNameSpecifierLoc QualifierLoc;
3603
3604   UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
3605                               SourceLocation TypenameLoc,
3606                               NestedNameSpecifierLoc QualifierLoc,
3607                               SourceLocation TargetNameLoc,
3608                               IdentifierInfo *TargetName,
3609                               SourceLocation EllipsisLoc)
3610     : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName,
3611                UsingLoc),
3612       TypenameLocation(TypenameLoc), EllipsisLoc(EllipsisLoc),
3613       QualifierLoc(QualifierLoc) {}
3614
3615   void anchor() override;
3616
3617 public:
3618   /// \brief Returns the source location of the 'using' keyword.
3619   SourceLocation getUsingLoc() const { return getLocStart(); }
3620
3621   /// \brief Returns the source location of the 'typename' keyword.
3622   SourceLocation getTypenameLoc() const { return TypenameLocation; }
3623
3624   /// \brief Retrieve the nested-name-specifier that qualifies the name,
3625   /// with source-location information.
3626   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3627
3628   /// \brief Retrieve the nested-name-specifier that qualifies the name.
3629   NestedNameSpecifier *getQualifier() const {
3630     return QualifierLoc.getNestedNameSpecifier();
3631   }
3632
3633   DeclarationNameInfo getNameInfo() const {
3634     return DeclarationNameInfo(getDeclName(), getLocation());
3635   }
3636
3637   /// \brief Determine whether this is a pack expansion.
3638   bool isPackExpansion() const {
3639     return EllipsisLoc.isValid();
3640   }
3641
3642   /// \brief Get the location of the ellipsis if this is a pack expansion.
3643   SourceLocation getEllipsisLoc() const {
3644     return EllipsisLoc;
3645   }
3646
3647   static UnresolvedUsingTypenameDecl *
3648     Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
3649            SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc,
3650            SourceLocation TargetNameLoc, DeclarationName TargetName,
3651            SourceLocation EllipsisLoc);
3652
3653   static UnresolvedUsingTypenameDecl *
3654   CreateDeserialized(ASTContext &C, unsigned ID);
3655
3656   /// Retrieves the canonical declaration of this declaration.
3657   UnresolvedUsingTypenameDecl *getCanonicalDecl() override {
3658     return getFirstDecl();
3659   }
3660   const UnresolvedUsingTypenameDecl *getCanonicalDecl() const {
3661     return getFirstDecl();
3662   }
3663
3664   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3665   static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; }
3666 };
3667
3668 /// \brief Represents a C++11 static_assert declaration.
3669 class StaticAssertDecl : public Decl {
3670   llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed;
3671   StringLiteral *Message;
3672   SourceLocation RParenLoc;
3673
3674   StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc,
3675                    Expr *AssertExpr, StringLiteral *Message,
3676                    SourceLocation RParenLoc, bool Failed)
3677       : Decl(StaticAssert, DC, StaticAssertLoc),
3678         AssertExprAndFailed(AssertExpr, Failed), Message(Message),
3679         RParenLoc(RParenLoc) {}
3680
3681   virtual void anchor();
3682
3683 public:
3684   friend class ASTDeclReader;
3685
3686   static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
3687                                   SourceLocation StaticAssertLoc,
3688                                   Expr *AssertExpr, StringLiteral *Message,
3689                                   SourceLocation RParenLoc, bool Failed);
3690   static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3691   
3692   Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); }
3693   const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); }
3694
3695   StringLiteral *getMessage() { return Message; }
3696   const StringLiteral *getMessage() const { return Message; }
3697
3698   bool isFailed() const { return AssertExprAndFailed.getInt(); }
3699
3700   SourceLocation getRParenLoc() const { return RParenLoc; }
3701
3702   SourceRange getSourceRange() const override LLVM_READONLY {
3703     return SourceRange(getLocation(), getRParenLoc());
3704   }
3705
3706   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3707   static bool classofKind(Kind K) { return K == StaticAssert; }
3708 };
3709
3710 /// A binding in a decomposition declaration. For instance, given:
3711 ///
3712 ///   int n[3];
3713 ///   auto &[a, b, c] = n;
3714 ///
3715 /// a, b, and c are BindingDecls, whose bindings are the expressions
3716 /// x[0], x[1], and x[2] respectively, where x is the implicit
3717 /// DecompositionDecl of type 'int (&)[3]'.
3718 class BindingDecl : public ValueDecl {
3719   /// The binding represented by this declaration. References to this
3720   /// declaration are effectively equivalent to this expression (except
3721   /// that it is only evaluated once at the point of declaration of the
3722   /// binding).
3723   Expr *Binding = nullptr;
3724
3725   BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id)
3726       : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()) {}
3727
3728   void anchor() override;
3729
3730 public:
3731   friend class ASTDeclReader;
3732
3733   static BindingDecl *Create(ASTContext &C, DeclContext *DC,
3734                              SourceLocation IdLoc, IdentifierInfo *Id);
3735   static BindingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3736
3737   /// Get the expression to which this declaration is bound. This may be null
3738   /// in two different cases: while parsing the initializer for the
3739   /// decomposition declaration, and when the initializer is type-dependent.
3740   Expr *getBinding() const { return Binding; }
3741
3742   /// Get the variable (if any) that holds the value of evaluating the binding.
3743   /// Only present for user-defined bindings for tuple-like types.
3744   VarDecl *getHoldingVar() const;
3745
3746   /// Set the binding for this BindingDecl, along with its declared type (which
3747   /// should be a possibly-cv-qualified form of the type of the binding, or a
3748   /// reference to such a type).
3749   void setBinding(QualType DeclaredType, Expr *Binding) {
3750     setType(DeclaredType);
3751     this->Binding = Binding;
3752   }
3753
3754   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3755   static bool classofKind(Kind K) { return K == Decl::Binding; }
3756 };
3757
3758 /// A decomposition declaration. For instance, given:
3759 ///
3760 ///   int n[3];
3761 ///   auto &[a, b, c] = n;
3762 ///
3763 /// the second line declares a DecompositionDecl of type 'int (&)[3]', and
3764 /// three BindingDecls (named a, b, and c). An instance of this class is always
3765 /// unnamed, but behaves in almost all other respects like a VarDecl.
3766 class DecompositionDecl final
3767     : public VarDecl,
3768       private llvm::TrailingObjects<DecompositionDecl, BindingDecl *> {
3769   /// The number of BindingDecl*s following this object.
3770   unsigned NumBindings;
3771
3772   DecompositionDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3773                     SourceLocation LSquareLoc, QualType T,
3774                     TypeSourceInfo *TInfo, StorageClass SC,
3775                     ArrayRef<BindingDecl *> Bindings)
3776       : VarDecl(Decomposition, C, DC, StartLoc, LSquareLoc, nullptr, T, TInfo,
3777                 SC),
3778         NumBindings(Bindings.size()) {
3779     std::uninitialized_copy(Bindings.begin(), Bindings.end(),
3780                             getTrailingObjects<BindingDecl *>());
3781   }
3782
3783   void anchor() override;
3784
3785 public:
3786   friend class ASTDeclReader;
3787   friend TrailingObjects;
3788
3789   static DecompositionDecl *Create(ASTContext &C, DeclContext *DC,
3790                                    SourceLocation StartLoc,
3791                                    SourceLocation LSquareLoc,
3792                                    QualType T, TypeSourceInfo *TInfo,
3793                                    StorageClass S,
3794                                    ArrayRef<BindingDecl *> Bindings);
3795   static DecompositionDecl *CreateDeserialized(ASTContext &C, unsigned ID,
3796                                                unsigned NumBindings);
3797
3798   ArrayRef<BindingDecl *> bindings() const {
3799     return llvm::makeArrayRef(getTrailingObjects<BindingDecl *>(), NumBindings);
3800   }
3801
3802   void printName(raw_ostream &os) const override;
3803
3804   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3805   static bool classofKind(Kind K) { return K == Decomposition; }
3806 };
3807
3808 /// An instance of this class represents the declaration of a property
3809 /// member.  This is a Microsoft extension to C++, first introduced in
3810 /// Visual Studio .NET 2003 as a parallel to similar features in C#
3811 /// and Managed C++.
3812 ///
3813 /// A property must always be a non-static class member.
3814 ///
3815 /// A property member superficially resembles a non-static data
3816 /// member, except preceded by a property attribute:
3817 ///   __declspec(property(get=GetX, put=PutX)) int x;
3818 /// Either (but not both) of the 'get' and 'put' names may be omitted.
3819 ///
3820 /// A reference to a property is always an lvalue.  If the lvalue
3821 /// undergoes lvalue-to-rvalue conversion, then a getter name is
3822 /// required, and that member is called with no arguments.
3823 /// If the lvalue is assigned into, then a setter name is required,
3824 /// and that member is called with one argument, the value assigned.
3825 /// Both operations are potentially overloaded.  Compound assignments
3826 /// are permitted, as are the increment and decrement operators.
3827 ///
3828 /// The getter and putter methods are permitted to be overloaded,
3829 /// although their return and parameter types are subject to certain
3830 /// restrictions according to the type of the property.
3831 ///
3832 /// A property declared using an incomplete array type may
3833 /// additionally be subscripted, adding extra parameters to the getter
3834 /// and putter methods.
3835 class MSPropertyDecl : public DeclaratorDecl {
3836   IdentifierInfo *GetterId, *SetterId;
3837
3838   MSPropertyDecl(DeclContext *DC, SourceLocation L, DeclarationName N,
3839                  QualType T, TypeSourceInfo *TInfo, SourceLocation StartL,
3840                  IdentifierInfo *Getter, IdentifierInfo *Setter)
3841       : DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL),
3842         GetterId(Getter), SetterId(Setter) {}
3843
3844 public:
3845   friend class ASTDeclReader;
3846
3847   static MSPropertyDecl *Create(ASTContext &C, DeclContext *DC,
3848                                 SourceLocation L, DeclarationName N, QualType T,
3849                                 TypeSourceInfo *TInfo, SourceLocation StartL,
3850                                 IdentifierInfo *Getter, IdentifierInfo *Setter);
3851   static MSPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3852
3853   static bool classof(const Decl *D) { return D->getKind() == MSProperty; }
3854
3855   bool hasGetter() const { return GetterId != nullptr; }
3856   IdentifierInfo* getGetterId() const { return GetterId; }
3857   bool hasSetter() const { return SetterId != nullptr; }
3858   IdentifierInfo* getSetterId() const { return SetterId; }
3859 };
3860
3861 /// Insertion operator for diagnostics.  This allows sending an AccessSpecifier
3862 /// into a diagnostic with <<.
3863 const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
3864                                     AccessSpecifier AS);
3865
3866 const PartialDiagnostic &operator<<(const PartialDiagnostic &DB,
3867                                     AccessSpecifier AS);
3868
3869 } // namespace clang
3870
3871 #endif // LLVM_CLANG_AST_DECLCXX_H