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