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