Home | History | Annotate | Line # | Download | only in AST
DeclCXX.cpp revision 1.1
      1  1.1  joerg //===- DeclCXX.cpp - C++ Declaration AST Node Implementation --------------===//
      2  1.1  joerg //
      3  1.1  joerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
      4  1.1  joerg // See https://llvm.org/LICENSE.txt for license information.
      5  1.1  joerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
      6  1.1  joerg //
      7  1.1  joerg //===----------------------------------------------------------------------===//
      8  1.1  joerg //
      9  1.1  joerg // This file implements the C++ related Decl classes.
     10  1.1  joerg //
     11  1.1  joerg //===----------------------------------------------------------------------===//
     12  1.1  joerg 
     13  1.1  joerg #include "clang/AST/DeclCXX.h"
     14  1.1  joerg #include "clang/AST/ASTContext.h"
     15  1.1  joerg #include "clang/AST/ASTLambda.h"
     16  1.1  joerg #include "clang/AST/ASTMutationListener.h"
     17  1.1  joerg #include "clang/AST/ASTUnresolvedSet.h"
     18  1.1  joerg #include "clang/AST/CXXInheritance.h"
     19  1.1  joerg #include "clang/AST/DeclBase.h"
     20  1.1  joerg #include "clang/AST/DeclTemplate.h"
     21  1.1  joerg #include "clang/AST/DeclarationName.h"
     22  1.1  joerg #include "clang/AST/Expr.h"
     23  1.1  joerg #include "clang/AST/ExprCXX.h"
     24  1.1  joerg #include "clang/AST/LambdaCapture.h"
     25  1.1  joerg #include "clang/AST/NestedNameSpecifier.h"
     26  1.1  joerg #include "clang/AST/ODRHash.h"
     27  1.1  joerg #include "clang/AST/Type.h"
     28  1.1  joerg #include "clang/AST/TypeLoc.h"
     29  1.1  joerg #include "clang/AST/UnresolvedSet.h"
     30  1.1  joerg #include "clang/Basic/Diagnostic.h"
     31  1.1  joerg #include "clang/Basic/IdentifierTable.h"
     32  1.1  joerg #include "clang/Basic/LLVM.h"
     33  1.1  joerg #include "clang/Basic/LangOptions.h"
     34  1.1  joerg #include "clang/Basic/OperatorKinds.h"
     35  1.1  joerg #include "clang/Basic/PartialDiagnostic.h"
     36  1.1  joerg #include "clang/Basic/SourceLocation.h"
     37  1.1  joerg #include "clang/Basic/Specifiers.h"
     38  1.1  joerg #include "llvm/ADT/None.h"
     39  1.1  joerg #include "llvm/ADT/SmallPtrSet.h"
     40  1.1  joerg #include "llvm/ADT/SmallVector.h"
     41  1.1  joerg #include "llvm/ADT/iterator_range.h"
     42  1.1  joerg #include "llvm/Support/Casting.h"
     43  1.1  joerg #include "llvm/Support/ErrorHandling.h"
     44  1.1  joerg #include "llvm/Support/raw_ostream.h"
     45  1.1  joerg #include <algorithm>
     46  1.1  joerg #include <cassert>
     47  1.1  joerg #include <cstddef>
     48  1.1  joerg #include <cstdint>
     49  1.1  joerg 
     50  1.1  joerg using namespace clang;
     51  1.1  joerg 
     52  1.1  joerg //===----------------------------------------------------------------------===//
     53  1.1  joerg // Decl Allocation/Deallocation Method Implementations
     54  1.1  joerg //===----------------------------------------------------------------------===//
     55  1.1  joerg 
     56  1.1  joerg void AccessSpecDecl::anchor() {}
     57  1.1  joerg 
     58  1.1  joerg AccessSpecDecl *AccessSpecDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
     59  1.1  joerg   return new (C, ID) AccessSpecDecl(EmptyShell());
     60  1.1  joerg }
     61  1.1  joerg 
     62  1.1  joerg void LazyASTUnresolvedSet::getFromExternalSource(ASTContext &C) const {
     63  1.1  joerg   ExternalASTSource *Source = C.getExternalSource();
     64  1.1  joerg   assert(Impl.Decls.isLazy() && "getFromExternalSource for non-lazy set");
     65  1.1  joerg   assert(Source && "getFromExternalSource with no external source");
     66  1.1  joerg 
     67  1.1  joerg   for (ASTUnresolvedSet::iterator I = Impl.begin(); I != Impl.end(); ++I)
     68  1.1  joerg     I.setDecl(cast<NamedDecl>(Source->GetExternalDecl(
     69  1.1  joerg         reinterpret_cast<uintptr_t>(I.getDecl()) >> 2)));
     70  1.1  joerg   Impl.Decls.setLazy(false);
     71  1.1  joerg }
     72  1.1  joerg 
     73  1.1  joerg CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D)
     74  1.1  joerg     : UserDeclaredConstructor(false), UserDeclaredSpecialMembers(0),
     75  1.1  joerg       Aggregate(true), PlainOldData(true), Empty(true), Polymorphic(false),
     76  1.1  joerg       Abstract(false), IsStandardLayout(true), IsCXX11StandardLayout(true),
     77  1.1  joerg       HasBasesWithFields(false), HasBasesWithNonStaticDataMembers(false),
     78  1.1  joerg       HasPrivateFields(false), HasProtectedFields(false),
     79  1.1  joerg       HasPublicFields(false), HasMutableFields(false), HasVariantMembers(false),
     80  1.1  joerg       HasOnlyCMembers(true), HasInClassInitializer(false),
     81  1.1  joerg       HasUninitializedReferenceMember(false), HasUninitializedFields(false),
     82  1.1  joerg       HasInheritedConstructor(false), HasInheritedAssignment(false),
     83  1.1  joerg       NeedOverloadResolutionForCopyConstructor(false),
     84  1.1  joerg       NeedOverloadResolutionForMoveConstructor(false),
     85  1.1  joerg       NeedOverloadResolutionForMoveAssignment(false),
     86  1.1  joerg       NeedOverloadResolutionForDestructor(false),
     87  1.1  joerg       DefaultedCopyConstructorIsDeleted(false),
     88  1.1  joerg       DefaultedMoveConstructorIsDeleted(false),
     89  1.1  joerg       DefaultedMoveAssignmentIsDeleted(false),
     90  1.1  joerg       DefaultedDestructorIsDeleted(false), HasTrivialSpecialMembers(SMF_All),
     91  1.1  joerg       HasTrivialSpecialMembersForCall(SMF_All),
     92  1.1  joerg       DeclaredNonTrivialSpecialMembers(0),
     93  1.1  joerg       DeclaredNonTrivialSpecialMembersForCall(0), HasIrrelevantDestructor(true),
     94  1.1  joerg       HasConstexprNonCopyMoveConstructor(false),
     95  1.1  joerg       HasDefaultedDefaultConstructor(false),
     96  1.1  joerg       DefaultedDefaultConstructorIsConstexpr(true),
     97  1.1  joerg       HasConstexprDefaultConstructor(false),
     98  1.1  joerg       DefaultedDestructorIsConstexpr(true),
     99  1.1  joerg       HasNonLiteralTypeFieldsOrBases(false),
    100  1.1  joerg       UserProvidedDefaultConstructor(false), DeclaredSpecialMembers(0),
    101  1.1  joerg       ImplicitCopyConstructorCanHaveConstParamForVBase(true),
    102  1.1  joerg       ImplicitCopyConstructorCanHaveConstParamForNonVBase(true),
    103  1.1  joerg       ImplicitCopyAssignmentHasConstParam(true),
    104  1.1  joerg       HasDeclaredCopyConstructorWithConstParam(false),
    105  1.1  joerg       HasDeclaredCopyAssignmentWithConstParam(false), IsLambda(false),
    106  1.1  joerg       IsParsingBaseSpecifiers(false), ComputedVisibleConversions(false),
    107  1.1  joerg       HasODRHash(false), Definition(D) {}
    108  1.1  joerg 
    109  1.1  joerg CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getBasesSlowCase() const {
    110  1.1  joerg   return Bases.get(Definition->getASTContext().getExternalSource());
    111  1.1  joerg }
    112  1.1  joerg 
    113  1.1  joerg CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getVBasesSlowCase() const {
    114  1.1  joerg   return VBases.get(Definition->getASTContext().getExternalSource());
    115  1.1  joerg }
    116  1.1  joerg 
    117  1.1  joerg CXXRecordDecl::CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C,
    118  1.1  joerg                              DeclContext *DC, SourceLocation StartLoc,
    119  1.1  joerg                              SourceLocation IdLoc, IdentifierInfo *Id,
    120  1.1  joerg                              CXXRecordDecl *PrevDecl)
    121  1.1  joerg     : RecordDecl(K, TK, C, DC, StartLoc, IdLoc, Id, PrevDecl),
    122  1.1  joerg       DefinitionData(PrevDecl ? PrevDecl->DefinitionData
    123  1.1  joerg                               : nullptr) {}
    124  1.1  joerg 
    125  1.1  joerg CXXRecordDecl *CXXRecordDecl::Create(const ASTContext &C, TagKind TK,
    126  1.1  joerg                                      DeclContext *DC, SourceLocation StartLoc,
    127  1.1  joerg                                      SourceLocation IdLoc, IdentifierInfo *Id,
    128  1.1  joerg                                      CXXRecordDecl *PrevDecl,
    129  1.1  joerg                                      bool DelayTypeCreation) {
    130  1.1  joerg   auto *R = new (C, DC) CXXRecordDecl(CXXRecord, TK, C, DC, StartLoc, IdLoc, Id,
    131  1.1  joerg                                       PrevDecl);
    132  1.1  joerg   R->setMayHaveOutOfDateDef(C.getLangOpts().Modules);
    133  1.1  joerg 
    134  1.1  joerg   // FIXME: DelayTypeCreation seems like such a hack
    135  1.1  joerg   if (!DelayTypeCreation)
    136  1.1  joerg     C.getTypeDeclType(R, PrevDecl);
    137  1.1  joerg   return R;
    138  1.1  joerg }
    139  1.1  joerg 
    140  1.1  joerg CXXRecordDecl *
    141  1.1  joerg CXXRecordDecl::CreateLambda(const ASTContext &C, DeclContext *DC,
    142  1.1  joerg                             TypeSourceInfo *Info, SourceLocation Loc,
    143  1.1  joerg                             bool Dependent, bool IsGeneric,
    144  1.1  joerg                             LambdaCaptureDefault CaptureDefault) {
    145  1.1  joerg   auto *R = new (C, DC) CXXRecordDecl(CXXRecord, TTK_Class, C, DC, Loc, Loc,
    146  1.1  joerg                                       nullptr, nullptr);
    147  1.1  joerg   R->setBeingDefined(true);
    148  1.1  joerg   R->DefinitionData =
    149  1.1  joerg       new (C) struct LambdaDefinitionData(R, Info, Dependent, IsGeneric,
    150  1.1  joerg                                           CaptureDefault);
    151  1.1  joerg   R->setMayHaveOutOfDateDef(false);
    152  1.1  joerg   R->setImplicit(true);
    153  1.1  joerg   C.getTypeDeclType(R, /*PrevDecl=*/nullptr);
    154  1.1  joerg   return R;
    155  1.1  joerg }
    156  1.1  joerg 
    157  1.1  joerg CXXRecordDecl *
    158  1.1  joerg CXXRecordDecl::CreateDeserialized(const ASTContext &C, unsigned ID) {
    159  1.1  joerg   auto *R = new (C, ID) CXXRecordDecl(
    160  1.1  joerg       CXXRecord, TTK_Struct, C, nullptr, SourceLocation(), SourceLocation(),
    161  1.1  joerg       nullptr, nullptr);
    162  1.1  joerg   R->setMayHaveOutOfDateDef(false);
    163  1.1  joerg   return R;
    164  1.1  joerg }
    165  1.1  joerg 
    166  1.1  joerg /// Determine whether a class has a repeated base class. This is intended for
    167  1.1  joerg /// use when determining if a class is standard-layout, so makes no attempt to
    168  1.1  joerg /// handle virtual bases.
    169  1.1  joerg static bool hasRepeatedBaseClass(const CXXRecordDecl *StartRD) {
    170  1.1  joerg   llvm::SmallPtrSet<const CXXRecordDecl*, 8> SeenBaseTypes;
    171  1.1  joerg   SmallVector<const CXXRecordDecl*, 8> WorkList = {StartRD};
    172  1.1  joerg   while (!WorkList.empty()) {
    173  1.1  joerg     const CXXRecordDecl *RD = WorkList.pop_back_val();
    174  1.1  joerg     for (const CXXBaseSpecifier &BaseSpec : RD->bases()) {
    175  1.1  joerg       if (const CXXRecordDecl *B = BaseSpec.getType()->getAsCXXRecordDecl()) {
    176  1.1  joerg         if (!SeenBaseTypes.insert(B).second)
    177  1.1  joerg           return true;
    178  1.1  joerg         WorkList.push_back(B);
    179  1.1  joerg       }
    180  1.1  joerg     }
    181  1.1  joerg   }
    182  1.1  joerg   return false;
    183  1.1  joerg }
    184  1.1  joerg 
    185  1.1  joerg void
    186  1.1  joerg CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases,
    187  1.1  joerg                         unsigned NumBases) {
    188  1.1  joerg   ASTContext &C = getASTContext();
    189  1.1  joerg 
    190  1.1  joerg   if (!data().Bases.isOffset() && data().NumBases > 0)
    191  1.1  joerg     C.Deallocate(data().getBases());
    192  1.1  joerg 
    193  1.1  joerg   if (NumBases) {
    194  1.1  joerg     if (!C.getLangOpts().CPlusPlus17) {
    195  1.1  joerg       // C++ [dcl.init.aggr]p1:
    196  1.1  joerg       //   An aggregate is [...] a class with [...] no base classes [...].
    197  1.1  joerg       data().Aggregate = false;
    198  1.1  joerg     }
    199  1.1  joerg 
    200  1.1  joerg     // C++ [class]p4:
    201  1.1  joerg     //   A POD-struct is an aggregate class...
    202  1.1  joerg     data().PlainOldData = false;
    203  1.1  joerg   }
    204  1.1  joerg 
    205  1.1  joerg   // The set of seen virtual base types.
    206  1.1  joerg   llvm::SmallPtrSet<CanQualType, 8> SeenVBaseTypes;
    207  1.1  joerg 
    208  1.1  joerg   // The virtual bases of this class.
    209  1.1  joerg   SmallVector<const CXXBaseSpecifier *, 8> VBases;
    210  1.1  joerg 
    211  1.1  joerg   data().Bases = new(C) CXXBaseSpecifier [NumBases];
    212  1.1  joerg   data().NumBases = NumBases;
    213  1.1  joerg   for (unsigned i = 0; i < NumBases; ++i) {
    214  1.1  joerg     data().getBases()[i] = *Bases[i];
    215  1.1  joerg     // Keep track of inherited vbases for this base class.
    216  1.1  joerg     const CXXBaseSpecifier *Base = Bases[i];
    217  1.1  joerg     QualType BaseType = Base->getType();
    218  1.1  joerg     // Skip dependent types; we can't do any checking on them now.
    219  1.1  joerg     if (BaseType->isDependentType())
    220  1.1  joerg       continue;
    221  1.1  joerg     auto *BaseClassDecl =
    222  1.1  joerg         cast<CXXRecordDecl>(BaseType->castAs<RecordType>()->getDecl());
    223  1.1  joerg 
    224  1.1  joerg     // C++2a [class]p7:
    225  1.1  joerg     //   A standard-layout class is a class that:
    226  1.1  joerg     //    [...]
    227  1.1  joerg     //    -- has all non-static data members and bit-fields in the class and
    228  1.1  joerg     //       its base classes first declared in the same class
    229  1.1  joerg     if (BaseClassDecl->data().HasBasesWithFields ||
    230  1.1  joerg         !BaseClassDecl->field_empty()) {
    231  1.1  joerg       if (data().HasBasesWithFields)
    232  1.1  joerg         // Two bases have members or bit-fields: not standard-layout.
    233  1.1  joerg         data().IsStandardLayout = false;
    234  1.1  joerg       data().HasBasesWithFields = true;
    235  1.1  joerg     }
    236  1.1  joerg 
    237  1.1  joerg     // C++11 [class]p7:
    238  1.1  joerg     //   A standard-layout class is a class that:
    239  1.1  joerg     //     -- [...] has [...] at most one base class with non-static data
    240  1.1  joerg     //        members
    241  1.1  joerg     if (BaseClassDecl->data().HasBasesWithNonStaticDataMembers ||
    242  1.1  joerg         BaseClassDecl->hasDirectFields()) {
    243  1.1  joerg       if (data().HasBasesWithNonStaticDataMembers)
    244  1.1  joerg         data().IsCXX11StandardLayout = false;
    245  1.1  joerg       data().HasBasesWithNonStaticDataMembers = true;
    246  1.1  joerg     }
    247  1.1  joerg 
    248  1.1  joerg     if (!BaseClassDecl->isEmpty()) {
    249  1.1  joerg       // C++14 [meta.unary.prop]p4:
    250  1.1  joerg       //   T is a class type [...] with [...] no base class B for which
    251  1.1  joerg       //   is_empty<B>::value is false.
    252  1.1  joerg       data().Empty = false;
    253  1.1  joerg     }
    254  1.1  joerg 
    255  1.1  joerg     // C++1z [dcl.init.agg]p1:
    256  1.1  joerg     //   An aggregate is a class with [...] no private or protected base classes
    257  1.1  joerg     if (Base->getAccessSpecifier() != AS_public)
    258  1.1  joerg       data().Aggregate = false;
    259  1.1  joerg 
    260  1.1  joerg     // C++ [class.virtual]p1:
    261  1.1  joerg     //   A class that declares or inherits a virtual function is called a
    262  1.1  joerg     //   polymorphic class.
    263  1.1  joerg     if (BaseClassDecl->isPolymorphic()) {
    264  1.1  joerg       data().Polymorphic = true;
    265  1.1  joerg 
    266  1.1  joerg       //   An aggregate is a class with [...] no virtual functions.
    267  1.1  joerg       data().Aggregate = false;
    268  1.1  joerg     }
    269  1.1  joerg 
    270  1.1  joerg     // C++0x [class]p7:
    271  1.1  joerg     //   A standard-layout class is a class that: [...]
    272  1.1  joerg     //    -- has no non-standard-layout base classes
    273  1.1  joerg     if (!BaseClassDecl->isStandardLayout())
    274  1.1  joerg       data().IsStandardLayout = false;
    275  1.1  joerg     if (!BaseClassDecl->isCXX11StandardLayout())
    276  1.1  joerg       data().IsCXX11StandardLayout = false;
    277  1.1  joerg 
    278  1.1  joerg     // Record if this base is the first non-literal field or base.
    279  1.1  joerg     if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C))
    280  1.1  joerg       data().HasNonLiteralTypeFieldsOrBases = true;
    281  1.1  joerg 
    282  1.1  joerg     // Now go through all virtual bases of this base and add them.
    283  1.1  joerg     for (const auto &VBase : BaseClassDecl->vbases()) {
    284  1.1  joerg       // Add this base if it's not already in the list.
    285  1.1  joerg       if (SeenVBaseTypes.insert(C.getCanonicalType(VBase.getType())).second) {
    286  1.1  joerg         VBases.push_back(&VBase);
    287  1.1  joerg 
    288  1.1  joerg         // C++11 [class.copy]p8:
    289  1.1  joerg         //   The implicitly-declared copy constructor for a class X will have
    290  1.1  joerg         //   the form 'X::X(const X&)' if each [...] virtual base class B of X
    291  1.1  joerg         //   has a copy constructor whose first parameter is of type
    292  1.1  joerg         //   'const B&' or 'const volatile B&' [...]
    293  1.1  joerg         if (CXXRecordDecl *VBaseDecl = VBase.getType()->getAsCXXRecordDecl())
    294  1.1  joerg           if (!VBaseDecl->hasCopyConstructorWithConstParam())
    295  1.1  joerg             data().ImplicitCopyConstructorCanHaveConstParamForVBase = false;
    296  1.1  joerg 
    297  1.1  joerg         // C++1z [dcl.init.agg]p1:
    298  1.1  joerg         //   An aggregate is a class with [...] no virtual base classes
    299  1.1  joerg         data().Aggregate = false;
    300  1.1  joerg       }
    301  1.1  joerg     }
    302  1.1  joerg 
    303  1.1  joerg     if (Base->isVirtual()) {
    304  1.1  joerg       // Add this base if it's not already in the list.
    305  1.1  joerg       if (SeenVBaseTypes.insert(C.getCanonicalType(BaseType)).second)
    306  1.1  joerg         VBases.push_back(Base);
    307  1.1  joerg 
    308  1.1  joerg       // C++14 [meta.unary.prop] is_empty:
    309  1.1  joerg       //   T is a class type, but not a union type, with ... no virtual base
    310  1.1  joerg       //   classes
    311  1.1  joerg       data().Empty = false;
    312  1.1  joerg 
    313  1.1  joerg       // C++1z [dcl.init.agg]p1:
    314  1.1  joerg       //   An aggregate is a class with [...] no virtual base classes
    315  1.1  joerg       data().Aggregate = false;
    316  1.1  joerg 
    317  1.1  joerg       // C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25:
    318  1.1  joerg       //   A [default constructor, copy/move constructor, or copy/move assignment
    319  1.1  joerg       //   operator for a class X] is trivial [...] if:
    320  1.1  joerg       //    -- class X has [...] no virtual base classes
    321  1.1  joerg       data().HasTrivialSpecialMembers &= SMF_Destructor;
    322  1.1  joerg       data().HasTrivialSpecialMembersForCall &= SMF_Destructor;
    323  1.1  joerg 
    324  1.1  joerg       // C++0x [class]p7:
    325  1.1  joerg       //   A standard-layout class is a class that: [...]
    326  1.1  joerg       //    -- has [...] no virtual base classes
    327  1.1  joerg       data().IsStandardLayout = false;
    328  1.1  joerg       data().IsCXX11StandardLayout = false;
    329  1.1  joerg 
    330  1.1  joerg       // C++20 [dcl.constexpr]p3:
    331  1.1  joerg       //   In the definition of a constexpr function [...]
    332  1.1  joerg       //    -- if the function is a constructor or destructor,
    333  1.1  joerg       //       its class shall not have any virtual base classes
    334  1.1  joerg       data().DefaultedDefaultConstructorIsConstexpr = false;
    335  1.1  joerg       data().DefaultedDestructorIsConstexpr = false;
    336  1.1  joerg 
    337  1.1  joerg       // C++1z [class.copy]p8:
    338  1.1  joerg       //   The implicitly-declared copy constructor for a class X will have
    339  1.1  joerg       //   the form 'X::X(const X&)' if each potentially constructed subobject
    340  1.1  joerg       //   has a copy constructor whose first parameter is of type
    341  1.1  joerg       //   'const B&' or 'const volatile B&' [...]
    342  1.1  joerg       if (!BaseClassDecl->hasCopyConstructorWithConstParam())
    343  1.1  joerg         data().ImplicitCopyConstructorCanHaveConstParamForVBase = false;
    344  1.1  joerg     } else {
    345  1.1  joerg       // C++ [class.ctor]p5:
    346  1.1  joerg       //   A default constructor is trivial [...] if:
    347  1.1  joerg       //    -- all the direct base classes of its class have trivial default
    348  1.1  joerg       //       constructors.
    349  1.1  joerg       if (!BaseClassDecl->hasTrivialDefaultConstructor())
    350  1.1  joerg         data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor;
    351  1.1  joerg 
    352  1.1  joerg       // C++0x [class.copy]p13:
    353  1.1  joerg       //   A copy/move constructor for class X is trivial if [...]
    354  1.1  joerg       //    [...]
    355  1.1  joerg       //    -- the constructor selected to copy/move each direct base class
    356  1.1  joerg       //       subobject is trivial, and
    357  1.1  joerg       if (!BaseClassDecl->hasTrivialCopyConstructor())
    358  1.1  joerg         data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor;
    359  1.1  joerg 
    360  1.1  joerg       if (!BaseClassDecl->hasTrivialCopyConstructorForCall())
    361  1.1  joerg         data().HasTrivialSpecialMembersForCall &= ~SMF_CopyConstructor;
    362  1.1  joerg 
    363  1.1  joerg       // If the base class doesn't have a simple move constructor, we'll eagerly
    364  1.1  joerg       // declare it and perform overload resolution to determine which function
    365  1.1  joerg       // it actually calls. If it does have a simple move constructor, this
    366  1.1  joerg       // check is correct.
    367  1.1  joerg       if (!BaseClassDecl->hasTrivialMoveConstructor())
    368  1.1  joerg         data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor;
    369  1.1  joerg 
    370  1.1  joerg       if (!BaseClassDecl->hasTrivialMoveConstructorForCall())
    371  1.1  joerg         data().HasTrivialSpecialMembersForCall &= ~SMF_MoveConstructor;
    372  1.1  joerg 
    373  1.1  joerg       // C++0x [class.copy]p27:
    374  1.1  joerg       //   A copy/move assignment operator for class X is trivial if [...]
    375  1.1  joerg       //    [...]
    376  1.1  joerg       //    -- the assignment operator selected to copy/move each direct base
    377  1.1  joerg       //       class subobject is trivial, and
    378  1.1  joerg       if (!BaseClassDecl->hasTrivialCopyAssignment())
    379  1.1  joerg         data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment;
    380  1.1  joerg       // If the base class doesn't have a simple move assignment, we'll eagerly
    381  1.1  joerg       // declare it and perform overload resolution to determine which function
    382  1.1  joerg       // it actually calls. If it does have a simple move assignment, this
    383  1.1  joerg       // check is correct.
    384  1.1  joerg       if (!BaseClassDecl->hasTrivialMoveAssignment())
    385  1.1  joerg         data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment;
    386  1.1  joerg 
    387  1.1  joerg       // C++11 [class.ctor]p6:
    388  1.1  joerg       //   If that user-written default constructor would satisfy the
    389  1.1  joerg       //   requirements of a constexpr constructor, the implicitly-defined
    390  1.1  joerg       //   default constructor is constexpr.
    391  1.1  joerg       if (!BaseClassDecl->hasConstexprDefaultConstructor())
    392  1.1  joerg         data().DefaultedDefaultConstructorIsConstexpr = false;
    393  1.1  joerg 
    394  1.1  joerg       // C++1z [class.copy]p8:
    395  1.1  joerg       //   The implicitly-declared copy constructor for a class X will have
    396  1.1  joerg       //   the form 'X::X(const X&)' if each potentially constructed subobject
    397  1.1  joerg       //   has a copy constructor whose first parameter is of type
    398  1.1  joerg       //   'const B&' or 'const volatile B&' [...]
    399  1.1  joerg       if (!BaseClassDecl->hasCopyConstructorWithConstParam())
    400  1.1  joerg         data().ImplicitCopyConstructorCanHaveConstParamForNonVBase = false;
    401  1.1  joerg     }
    402  1.1  joerg 
    403  1.1  joerg     // C++ [class.ctor]p3:
    404  1.1  joerg     //   A destructor is trivial if all the direct base classes of its class
    405  1.1  joerg     //   have trivial destructors.
    406  1.1  joerg     if (!BaseClassDecl->hasTrivialDestructor())
    407  1.1  joerg       data().HasTrivialSpecialMembers &= ~SMF_Destructor;
    408  1.1  joerg 
    409  1.1  joerg     if (!BaseClassDecl->hasTrivialDestructorForCall())
    410  1.1  joerg       data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor;
    411  1.1  joerg 
    412  1.1  joerg     if (!BaseClassDecl->hasIrrelevantDestructor())
    413  1.1  joerg       data().HasIrrelevantDestructor = false;
    414  1.1  joerg 
    415  1.1  joerg     // C++11 [class.copy]p18:
    416  1.1  joerg     //   The implicitly-declared copy assignment oeprator for a class X will
    417  1.1  joerg     //   have the form 'X& X::operator=(const X&)' if each direct base class B
    418  1.1  joerg     //   of X has a copy assignment operator whose parameter is of type 'const
    419  1.1  joerg     //   B&', 'const volatile B&', or 'B' [...]
    420  1.1  joerg     if (!BaseClassDecl->hasCopyAssignmentWithConstParam())
    421  1.1  joerg       data().ImplicitCopyAssignmentHasConstParam = false;
    422  1.1  joerg 
    423  1.1  joerg     // A class has an Objective-C object member if... or any of its bases
    424  1.1  joerg     // has an Objective-C object member.
    425  1.1  joerg     if (BaseClassDecl->hasObjectMember())
    426  1.1  joerg       setHasObjectMember(true);
    427  1.1  joerg 
    428  1.1  joerg     if (BaseClassDecl->hasVolatileMember())
    429  1.1  joerg       setHasVolatileMember(true);
    430  1.1  joerg 
    431  1.1  joerg     if (BaseClassDecl->getArgPassingRestrictions() ==
    432  1.1  joerg         RecordDecl::APK_CanNeverPassInRegs)
    433  1.1  joerg       setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs);
    434  1.1  joerg 
    435  1.1  joerg     // Keep track of the presence of mutable fields.
    436  1.1  joerg     if (BaseClassDecl->hasMutableFields()) {
    437  1.1  joerg       data().HasMutableFields = true;
    438  1.1  joerg       data().NeedOverloadResolutionForCopyConstructor = true;
    439  1.1  joerg     }
    440  1.1  joerg 
    441  1.1  joerg     if (BaseClassDecl->hasUninitializedReferenceMember())
    442  1.1  joerg       data().HasUninitializedReferenceMember = true;
    443  1.1  joerg 
    444  1.1  joerg     if (!BaseClassDecl->allowConstDefaultInit())
    445  1.1  joerg       data().HasUninitializedFields = true;
    446  1.1  joerg 
    447  1.1  joerg     addedClassSubobject(BaseClassDecl);
    448  1.1  joerg   }
    449  1.1  joerg 
    450  1.1  joerg   // C++2a [class]p7:
    451  1.1  joerg   //   A class S is a standard-layout class if it:
    452  1.1  joerg   //     -- has at most one base class subobject of any given type
    453  1.1  joerg   //
    454  1.1  joerg   // Note that we only need to check this for classes with more than one base
    455  1.1  joerg   // class. If there's only one base class, and it's standard layout, then
    456  1.1  joerg   // we know there are no repeated base classes.
    457  1.1  joerg   if (data().IsStandardLayout && NumBases > 1 && hasRepeatedBaseClass(this))
    458  1.1  joerg     data().IsStandardLayout = false;
    459  1.1  joerg 
    460  1.1  joerg   if (VBases.empty()) {
    461  1.1  joerg     data().IsParsingBaseSpecifiers = false;
    462  1.1  joerg     return;
    463  1.1  joerg   }
    464  1.1  joerg 
    465  1.1  joerg   // Create base specifier for any direct or indirect virtual bases.
    466  1.1  joerg   data().VBases = new (C) CXXBaseSpecifier[VBases.size()];
    467  1.1  joerg   data().NumVBases = VBases.size();
    468  1.1  joerg   for (int I = 0, E = VBases.size(); I != E; ++I) {
    469  1.1  joerg     QualType Type = VBases[I]->getType();
    470  1.1  joerg     if (!Type->isDependentType())
    471  1.1  joerg       addedClassSubobject(Type->getAsCXXRecordDecl());
    472  1.1  joerg     data().getVBases()[I] = *VBases[I];
    473  1.1  joerg   }
    474  1.1  joerg 
    475  1.1  joerg   data().IsParsingBaseSpecifiers = false;
    476  1.1  joerg }
    477  1.1  joerg 
    478  1.1  joerg unsigned CXXRecordDecl::getODRHash() const {
    479  1.1  joerg   assert(hasDefinition() && "ODRHash only for records with definitions");
    480  1.1  joerg 
    481  1.1  joerg   // Previously calculated hash is stored in DefinitionData.
    482  1.1  joerg   if (DefinitionData->HasODRHash)
    483  1.1  joerg     return DefinitionData->ODRHash;
    484  1.1  joerg 
    485  1.1  joerg   // Only calculate hash on first call of getODRHash per record.
    486  1.1  joerg   ODRHash Hash;
    487  1.1  joerg   Hash.AddCXXRecordDecl(getDefinition());
    488  1.1  joerg   DefinitionData->HasODRHash = true;
    489  1.1  joerg   DefinitionData->ODRHash = Hash.CalculateHash();
    490  1.1  joerg 
    491  1.1  joerg   return DefinitionData->ODRHash;
    492  1.1  joerg }
    493  1.1  joerg 
    494  1.1  joerg void CXXRecordDecl::addedClassSubobject(CXXRecordDecl *Subobj) {
    495  1.1  joerg   // C++11 [class.copy]p11:
    496  1.1  joerg   //   A defaulted copy/move constructor for a class X is defined as
    497  1.1  joerg   //   deleted if X has:
    498  1.1  joerg   //    -- a direct or virtual base class B that cannot be copied/moved [...]
    499  1.1  joerg   //    -- a non-static data member of class type M (or array thereof)
    500  1.1  joerg   //       that cannot be copied or moved [...]
    501  1.1  joerg   if (!Subobj->hasSimpleCopyConstructor())
    502  1.1  joerg     data().NeedOverloadResolutionForCopyConstructor = true;
    503  1.1  joerg   if (!Subobj->hasSimpleMoveConstructor())
    504  1.1  joerg     data().NeedOverloadResolutionForMoveConstructor = true;
    505  1.1  joerg 
    506  1.1  joerg   // C++11 [class.copy]p23:
    507  1.1  joerg   //   A defaulted copy/move assignment operator for a class X is defined as
    508  1.1  joerg   //   deleted if X has:
    509  1.1  joerg   //    -- a direct or virtual base class B that cannot be copied/moved [...]
    510  1.1  joerg   //    -- a non-static data member of class type M (or array thereof)
    511  1.1  joerg   //        that cannot be copied or moved [...]
    512  1.1  joerg   if (!Subobj->hasSimpleMoveAssignment())
    513  1.1  joerg     data().NeedOverloadResolutionForMoveAssignment = true;
    514  1.1  joerg 
    515  1.1  joerg   // C++11 [class.ctor]p5, C++11 [class.copy]p11, C++11 [class.dtor]p5:
    516  1.1  joerg   //   A defaulted [ctor or dtor] for a class X is defined as
    517  1.1  joerg   //   deleted if X has:
    518  1.1  joerg   //    -- any direct or virtual base class [...] has a type with a destructor
    519  1.1  joerg   //       that is deleted or inaccessible from the defaulted [ctor or dtor].
    520  1.1  joerg   //    -- any non-static data member has a type with a destructor
    521  1.1  joerg   //       that is deleted or inaccessible from the defaulted [ctor or dtor].
    522  1.1  joerg   if (!Subobj->hasSimpleDestructor()) {
    523  1.1  joerg     data().NeedOverloadResolutionForCopyConstructor = true;
    524  1.1  joerg     data().NeedOverloadResolutionForMoveConstructor = true;
    525  1.1  joerg     data().NeedOverloadResolutionForDestructor = true;
    526  1.1  joerg   }
    527  1.1  joerg 
    528  1.1  joerg   // C++2a [dcl.constexpr]p4:
    529  1.1  joerg   //   The definition of a constexpr destructor [shall] satisfy the
    530  1.1  joerg   //   following requirement:
    531  1.1  joerg   //   -- for every subobject of class type or (possibly multi-dimensional)
    532  1.1  joerg   //      array thereof, that class type shall have a constexpr destructor
    533  1.1  joerg   if (!Subobj->hasConstexprDestructor())
    534  1.1  joerg     data().DefaultedDestructorIsConstexpr = false;
    535  1.1  joerg }
    536  1.1  joerg 
    537  1.1  joerg bool CXXRecordDecl::hasConstexprDestructor() const {
    538  1.1  joerg   auto *Dtor = getDestructor();
    539  1.1  joerg   return Dtor ? Dtor->isConstexpr() : defaultedDestructorIsConstexpr();
    540  1.1  joerg }
    541  1.1  joerg 
    542  1.1  joerg bool CXXRecordDecl::hasAnyDependentBases() const {
    543  1.1  joerg   if (!isDependentContext())
    544  1.1  joerg     return false;
    545  1.1  joerg 
    546  1.1  joerg   return !forallBases([](const CXXRecordDecl *) { return true; });
    547  1.1  joerg }
    548  1.1  joerg 
    549  1.1  joerg bool CXXRecordDecl::isTriviallyCopyable() const {
    550  1.1  joerg   // C++0x [class]p5:
    551  1.1  joerg   //   A trivially copyable class is a class that:
    552  1.1  joerg   //   -- has no non-trivial copy constructors,
    553  1.1  joerg   if (hasNonTrivialCopyConstructor()) return false;
    554  1.1  joerg   //   -- has no non-trivial move constructors,
    555  1.1  joerg   if (hasNonTrivialMoveConstructor()) return false;
    556  1.1  joerg   //   -- has no non-trivial copy assignment operators,
    557  1.1  joerg   if (hasNonTrivialCopyAssignment()) return false;
    558  1.1  joerg   //   -- has no non-trivial move assignment operators, and
    559  1.1  joerg   if (hasNonTrivialMoveAssignment()) return false;
    560  1.1  joerg   //   -- has a trivial destructor.
    561  1.1  joerg   if (!hasTrivialDestructor()) return false;
    562  1.1  joerg 
    563  1.1  joerg   return true;
    564  1.1  joerg }
    565  1.1  joerg 
    566  1.1  joerg void CXXRecordDecl::markedVirtualFunctionPure() {
    567  1.1  joerg   // C++ [class.abstract]p2:
    568  1.1  joerg   //   A class is abstract if it has at least one pure virtual function.
    569  1.1  joerg   data().Abstract = true;
    570  1.1  joerg }
    571  1.1  joerg 
    572  1.1  joerg bool CXXRecordDecl::hasSubobjectAtOffsetZeroOfEmptyBaseType(
    573  1.1  joerg     ASTContext &Ctx, const CXXRecordDecl *XFirst) {
    574  1.1  joerg   if (!getNumBases())
    575  1.1  joerg     return false;
    576  1.1  joerg 
    577  1.1  joerg   llvm::SmallPtrSet<const CXXRecordDecl*, 8> Bases;
    578  1.1  joerg   llvm::SmallPtrSet<const CXXRecordDecl*, 8> M;
    579  1.1  joerg   SmallVector<const CXXRecordDecl*, 8> WorkList;
    580  1.1  joerg 
    581  1.1  joerg   // Visit a type that we have determined is an element of M(S).
    582  1.1  joerg   auto Visit = [&](const CXXRecordDecl *RD) -> bool {
    583  1.1  joerg     RD = RD->getCanonicalDecl();
    584  1.1  joerg 
    585  1.1  joerg     // C++2a [class]p8:
    586  1.1  joerg     //   A class S is a standard-layout class if it [...] has no element of the
    587  1.1  joerg     //   set M(S) of types as a base class.
    588  1.1  joerg     //
    589  1.1  joerg     // If we find a subobject of an empty type, it might also be a base class,
    590  1.1  joerg     // so we'll need to walk the base classes to check.
    591  1.1  joerg     if (!RD->data().HasBasesWithFields) {
    592  1.1  joerg       // Walk the bases the first time, stopping if we find the type. Build a
    593  1.1  joerg       // set of them so we don't need to walk them again.
    594  1.1  joerg       if (Bases.empty()) {
    595  1.1  joerg         bool RDIsBase = !forallBases([&](const CXXRecordDecl *Base) -> bool {
    596  1.1  joerg           Base = Base->getCanonicalDecl();
    597  1.1  joerg           if (RD == Base)
    598  1.1  joerg             return false;
    599  1.1  joerg           Bases.insert(Base);
    600  1.1  joerg           return true;
    601  1.1  joerg         });
    602  1.1  joerg         if (RDIsBase)
    603  1.1  joerg           return true;
    604  1.1  joerg       } else {
    605  1.1  joerg         if (Bases.count(RD))
    606  1.1  joerg           return true;
    607  1.1  joerg       }
    608  1.1  joerg     }
    609  1.1  joerg 
    610  1.1  joerg     if (M.insert(RD).second)
    611  1.1  joerg       WorkList.push_back(RD);
    612  1.1  joerg     return false;
    613  1.1  joerg   };
    614  1.1  joerg 
    615  1.1  joerg   if (Visit(XFirst))
    616  1.1  joerg     return true;
    617  1.1  joerg 
    618  1.1  joerg   while (!WorkList.empty()) {
    619  1.1  joerg     const CXXRecordDecl *X = WorkList.pop_back_val();
    620  1.1  joerg 
    621  1.1  joerg     // FIXME: We don't check the bases of X. That matches the standard, but
    622  1.1  joerg     // that sure looks like a wording bug.
    623  1.1  joerg 
    624  1.1  joerg     //   -- If X is a non-union class type with a non-static data member
    625  1.1  joerg     //      [recurse to each field] that is either of zero size or is the
    626  1.1  joerg     //      first non-static data member of X
    627  1.1  joerg     //   -- If X is a union type, [recurse to union members]
    628  1.1  joerg     bool IsFirstField = true;
    629  1.1  joerg     for (auto *FD : X->fields()) {
    630  1.1  joerg       // FIXME: Should we really care about the type of the first non-static
    631  1.1  joerg       // data member of a non-union if there are preceding unnamed bit-fields?
    632  1.1  joerg       if (FD->isUnnamedBitfield())
    633  1.1  joerg         continue;
    634  1.1  joerg 
    635  1.1  joerg       if (!IsFirstField && !FD->isZeroSize(Ctx))
    636  1.1  joerg         continue;
    637  1.1  joerg 
    638  1.1  joerg       //   -- If X is n array type, [visit the element type]
    639  1.1  joerg       QualType T = Ctx.getBaseElementType(FD->getType());
    640  1.1  joerg       if (auto *RD = T->getAsCXXRecordDecl())
    641  1.1  joerg         if (Visit(RD))
    642  1.1  joerg           return true;
    643  1.1  joerg 
    644  1.1  joerg       if (!X->isUnion())
    645  1.1  joerg         IsFirstField = false;
    646  1.1  joerg     }
    647  1.1  joerg   }
    648  1.1  joerg 
    649  1.1  joerg   return false;
    650  1.1  joerg }
    651  1.1  joerg 
    652  1.1  joerg bool CXXRecordDecl::lambdaIsDefaultConstructibleAndAssignable() const {
    653  1.1  joerg   assert(isLambda() && "not a lambda");
    654  1.1  joerg 
    655  1.1  joerg   // C++2a [expr.prim.lambda.capture]p11:
    656  1.1  joerg   //   The closure type associated with a lambda-expression has no default
    657  1.1  joerg   //   constructor if the lambda-expression has a lambda-capture and a
    658  1.1  joerg   //   defaulted default constructor otherwise. It has a deleted copy
    659  1.1  joerg   //   assignment operator if the lambda-expression has a lambda-capture and
    660  1.1  joerg   //   defaulted copy and move assignment operators otherwise.
    661  1.1  joerg   //
    662  1.1  joerg   // C++17 [expr.prim.lambda]p21:
    663  1.1  joerg   //   The closure type associated with a lambda-expression has no default
    664  1.1  joerg   //   constructor and a deleted copy assignment operator.
    665  1.1  joerg   if (getLambdaCaptureDefault() != LCD_None ||
    666  1.1  joerg       getLambdaData().NumCaptures != 0)
    667  1.1  joerg     return false;
    668  1.1  joerg   return getASTContext().getLangOpts().CPlusPlus2a;
    669  1.1  joerg }
    670  1.1  joerg 
    671  1.1  joerg void CXXRecordDecl::addedMember(Decl *D) {
    672  1.1  joerg   if (!D->isImplicit() &&
    673  1.1  joerg       !isa<FieldDecl>(D) &&
    674  1.1  joerg       !isa<IndirectFieldDecl>(D) &&
    675  1.1  joerg       (!isa<TagDecl>(D) || cast<TagDecl>(D)->getTagKind() == TTK_Class ||
    676  1.1  joerg         cast<TagDecl>(D)->getTagKind() == TTK_Interface))
    677  1.1  joerg     data().HasOnlyCMembers = false;
    678  1.1  joerg 
    679  1.1  joerg   // Ignore friends and invalid declarations.
    680  1.1  joerg   if (D->getFriendObjectKind() || D->isInvalidDecl())
    681  1.1  joerg     return;
    682  1.1  joerg 
    683  1.1  joerg   auto *FunTmpl = dyn_cast<FunctionTemplateDecl>(D);
    684  1.1  joerg   if (FunTmpl)
    685  1.1  joerg     D = FunTmpl->getTemplatedDecl();
    686  1.1  joerg 
    687  1.1  joerg   // FIXME: Pass NamedDecl* to addedMember?
    688  1.1  joerg   Decl *DUnderlying = D;
    689  1.1  joerg   if (auto *ND = dyn_cast<NamedDecl>(DUnderlying)) {
    690  1.1  joerg     DUnderlying = ND->getUnderlyingDecl();
    691  1.1  joerg     if (auto *UnderlyingFunTmpl = dyn_cast<FunctionTemplateDecl>(DUnderlying))
    692  1.1  joerg       DUnderlying = UnderlyingFunTmpl->getTemplatedDecl();
    693  1.1  joerg   }
    694  1.1  joerg 
    695  1.1  joerg   if (const auto *Method = dyn_cast<CXXMethodDecl>(D)) {
    696  1.1  joerg     if (Method->isVirtual()) {
    697  1.1  joerg       // C++ [dcl.init.aggr]p1:
    698  1.1  joerg       //   An aggregate is an array or a class with [...] no virtual functions.
    699  1.1  joerg       data().Aggregate = false;
    700  1.1  joerg 
    701  1.1  joerg       // C++ [class]p4:
    702  1.1  joerg       //   A POD-struct is an aggregate class...
    703  1.1  joerg       data().PlainOldData = false;
    704  1.1  joerg 
    705  1.1  joerg       // C++14 [meta.unary.prop]p4:
    706  1.1  joerg       //   T is a class type [...] with [...] no virtual member functions...
    707  1.1  joerg       data().Empty = false;
    708  1.1  joerg 
    709  1.1  joerg       // C++ [class.virtual]p1:
    710  1.1  joerg       //   A class that declares or inherits a virtual function is called a
    711  1.1  joerg       //   polymorphic class.
    712  1.1  joerg       data().Polymorphic = true;
    713  1.1  joerg 
    714  1.1  joerg       // C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25:
    715  1.1  joerg       //   A [default constructor, copy/move constructor, or copy/move
    716  1.1  joerg       //   assignment operator for a class X] is trivial [...] if:
    717  1.1  joerg       //    -- class X has no virtual functions [...]
    718  1.1  joerg       data().HasTrivialSpecialMembers &= SMF_Destructor;
    719  1.1  joerg       data().HasTrivialSpecialMembersForCall &= SMF_Destructor;
    720  1.1  joerg 
    721  1.1  joerg       // C++0x [class]p7:
    722  1.1  joerg       //   A standard-layout class is a class that: [...]
    723  1.1  joerg       //    -- has no virtual functions
    724  1.1  joerg       data().IsStandardLayout = false;
    725  1.1  joerg       data().IsCXX11StandardLayout = false;
    726  1.1  joerg     }
    727  1.1  joerg   }
    728  1.1  joerg 
    729  1.1  joerg   // Notify the listener if an implicit member was added after the definition
    730  1.1  joerg   // was completed.
    731  1.1  joerg   if (!isBeingDefined() && D->isImplicit())
    732  1.1  joerg     if (ASTMutationListener *L = getASTMutationListener())
    733  1.1  joerg       L->AddedCXXImplicitMember(data().Definition, D);
    734  1.1  joerg 
    735  1.1  joerg   // The kind of special member this declaration is, if any.
    736  1.1  joerg   unsigned SMKind = 0;
    737  1.1  joerg 
    738  1.1  joerg   // Handle constructors.
    739  1.1  joerg   if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(D)) {
    740  1.1  joerg     if (!Constructor->isImplicit()) {
    741  1.1  joerg       // Note that we have a user-declared constructor.
    742  1.1  joerg       data().UserDeclaredConstructor = true;
    743  1.1  joerg 
    744  1.1  joerg       // C++ [class]p4:
    745  1.1  joerg       //   A POD-struct is an aggregate class [...]
    746  1.1  joerg       // Since the POD bit is meant to be C++03 POD-ness, clear it even if the
    747  1.1  joerg       // type is technically an aggregate in C++0x since it wouldn't be in 03.
    748  1.1  joerg       data().PlainOldData = false;
    749  1.1  joerg     }
    750  1.1  joerg 
    751  1.1  joerg     if (Constructor->isDefaultConstructor()) {
    752  1.1  joerg       SMKind |= SMF_DefaultConstructor;
    753  1.1  joerg 
    754  1.1  joerg       if (Constructor->isUserProvided())
    755  1.1  joerg         data().UserProvidedDefaultConstructor = true;
    756  1.1  joerg       if (Constructor->isConstexpr())
    757  1.1  joerg         data().HasConstexprDefaultConstructor = true;
    758  1.1  joerg       if (Constructor->isDefaulted())
    759  1.1  joerg         data().HasDefaultedDefaultConstructor = true;
    760  1.1  joerg     }
    761  1.1  joerg 
    762  1.1  joerg     if (!FunTmpl) {
    763  1.1  joerg       unsigned Quals;
    764  1.1  joerg       if (Constructor->isCopyConstructor(Quals)) {
    765  1.1  joerg         SMKind |= SMF_CopyConstructor;
    766  1.1  joerg 
    767  1.1  joerg         if (Quals & Qualifiers::Const)
    768  1.1  joerg           data().HasDeclaredCopyConstructorWithConstParam = true;
    769  1.1  joerg       } else if (Constructor->isMoveConstructor())
    770  1.1  joerg         SMKind |= SMF_MoveConstructor;
    771  1.1  joerg     }
    772  1.1  joerg 
    773  1.1  joerg     // C++11 [dcl.init.aggr]p1: DR1518
    774  1.1  joerg     //   An aggregate is an array or a class with no user-provided [or]
    775  1.1  joerg     //   explicit [...] constructors
    776  1.1  joerg     // C++20 [dcl.init.aggr]p1:
    777  1.1  joerg     //   An aggregate is an array or a class with no user-declared [...]
    778  1.1  joerg     //   constructors
    779  1.1  joerg     if (getASTContext().getLangOpts().CPlusPlus2a
    780  1.1  joerg             ? !Constructor->isImplicit()
    781  1.1  joerg             : (Constructor->isUserProvided() || Constructor->isExplicit()))
    782  1.1  joerg       data().Aggregate = false;
    783  1.1  joerg   }
    784  1.1  joerg 
    785  1.1  joerg   // Handle constructors, including those inherited from base classes.
    786  1.1  joerg   if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(DUnderlying)) {
    787  1.1  joerg     // Record if we see any constexpr constructors which are neither copy
    788  1.1  joerg     // nor move constructors.
    789  1.1  joerg     // C++1z [basic.types]p10:
    790  1.1  joerg     //   [...] has at least one constexpr constructor or constructor template
    791  1.1  joerg     //   (possibly inherited from a base class) that is not a copy or move
    792  1.1  joerg     //   constructor [...]
    793  1.1  joerg     if (Constructor->isConstexpr() && !Constructor->isCopyOrMoveConstructor())
    794  1.1  joerg       data().HasConstexprNonCopyMoveConstructor = true;
    795  1.1  joerg   }
    796  1.1  joerg 
    797  1.1  joerg   // Handle destructors.
    798  1.1  joerg   if (const auto *DD = dyn_cast<CXXDestructorDecl>(D)) {
    799  1.1  joerg     SMKind |= SMF_Destructor;
    800  1.1  joerg 
    801  1.1  joerg     if (DD->isUserProvided())
    802  1.1  joerg       data().HasIrrelevantDestructor = false;
    803  1.1  joerg     // If the destructor is explicitly defaulted and not trivial or not public
    804  1.1  joerg     // or if the destructor is deleted, we clear HasIrrelevantDestructor in
    805  1.1  joerg     // finishedDefaultedOrDeletedMember.
    806  1.1  joerg 
    807  1.1  joerg     // C++11 [class.dtor]p5:
    808  1.1  joerg     //   A destructor is trivial if [...] the destructor is not virtual.
    809  1.1  joerg     if (DD->isVirtual()) {
    810  1.1  joerg       data().HasTrivialSpecialMembers &= ~SMF_Destructor;
    811  1.1  joerg       data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor;
    812  1.1  joerg     }
    813  1.1  joerg   }
    814  1.1  joerg 
    815  1.1  joerg   // Handle member functions.
    816  1.1  joerg   if (const auto *Method = dyn_cast<CXXMethodDecl>(D)) {
    817  1.1  joerg     if (Method->isCopyAssignmentOperator()) {
    818  1.1  joerg       SMKind |= SMF_CopyAssignment;
    819  1.1  joerg 
    820  1.1  joerg       const auto *ParamTy =
    821  1.1  joerg           Method->getParamDecl(0)->getType()->getAs<ReferenceType>();
    822  1.1  joerg       if (!ParamTy || ParamTy->getPointeeType().isConstQualified())
    823  1.1  joerg         data().HasDeclaredCopyAssignmentWithConstParam = true;
    824  1.1  joerg     }
    825  1.1  joerg 
    826  1.1  joerg     if (Method->isMoveAssignmentOperator())
    827  1.1  joerg       SMKind |= SMF_MoveAssignment;
    828  1.1  joerg 
    829  1.1  joerg     // Keep the list of conversion functions up-to-date.
    830  1.1  joerg     if (auto *Conversion = dyn_cast<CXXConversionDecl>(D)) {
    831  1.1  joerg       // FIXME: We use the 'unsafe' accessor for the access specifier here,
    832  1.1  joerg       // because Sema may not have set it yet. That's really just a misdesign
    833  1.1  joerg       // in Sema. However, LLDB *will* have set the access specifier correctly,
    834  1.1  joerg       // and adds declarations after the class is technically completed,
    835  1.1  joerg       // so completeDefinition()'s overriding of the access specifiers doesn't
    836  1.1  joerg       // work.
    837  1.1  joerg       AccessSpecifier AS = Conversion->getAccessUnsafe();
    838  1.1  joerg 
    839  1.1  joerg       if (Conversion->getPrimaryTemplate()) {
    840  1.1  joerg         // We don't record specializations.
    841  1.1  joerg       } else {
    842  1.1  joerg         ASTContext &Ctx = getASTContext();
    843  1.1  joerg         ASTUnresolvedSet &Conversions = data().Conversions.get(Ctx);
    844  1.1  joerg         NamedDecl *Primary =
    845  1.1  joerg             FunTmpl ? cast<NamedDecl>(FunTmpl) : cast<NamedDecl>(Conversion);
    846  1.1  joerg         if (Primary->getPreviousDecl())
    847  1.1  joerg           Conversions.replace(cast<NamedDecl>(Primary->getPreviousDecl()),
    848  1.1  joerg                               Primary, AS);
    849  1.1  joerg         else
    850  1.1  joerg           Conversions.addDecl(Ctx, Primary, AS);
    851  1.1  joerg       }
    852  1.1  joerg     }
    853  1.1  joerg 
    854  1.1  joerg     if (SMKind) {
    855  1.1  joerg       // If this is the first declaration of a special member, we no longer have
    856  1.1  joerg       // an implicit trivial special member.
    857  1.1  joerg       data().HasTrivialSpecialMembers &=
    858  1.1  joerg           data().DeclaredSpecialMembers | ~SMKind;
    859  1.1  joerg       data().HasTrivialSpecialMembersForCall &=
    860  1.1  joerg           data().DeclaredSpecialMembers | ~SMKind;
    861  1.1  joerg 
    862  1.1  joerg       if (!Method->isImplicit() && !Method->isUserProvided()) {
    863  1.1  joerg         // This method is user-declared but not user-provided. We can't work out
    864  1.1  joerg         // whether it's trivial yet (not until we get to the end of the class).
    865  1.1  joerg         // We'll handle this method in finishedDefaultedOrDeletedMember.
    866  1.1  joerg       } else if (Method->isTrivial()) {
    867  1.1  joerg         data().HasTrivialSpecialMembers |= SMKind;
    868  1.1  joerg         data().HasTrivialSpecialMembersForCall |= SMKind;
    869  1.1  joerg       } else if (Method->isTrivialForCall()) {
    870  1.1  joerg         data().HasTrivialSpecialMembersForCall |= SMKind;
    871  1.1  joerg         data().DeclaredNonTrivialSpecialMembers |= SMKind;
    872  1.1  joerg       } else {
    873  1.1  joerg         data().DeclaredNonTrivialSpecialMembers |= SMKind;
    874  1.1  joerg         // If this is a user-provided function, do not set
    875  1.1  joerg         // DeclaredNonTrivialSpecialMembersForCall here since we don't know
    876  1.1  joerg         // yet whether the method would be considered non-trivial for the
    877  1.1  joerg         // purpose of calls (attribute "trivial_abi" can be dropped from the
    878  1.1  joerg         // class later, which can change the special method's triviality).
    879  1.1  joerg         if (!Method->isUserProvided())
    880  1.1  joerg           data().DeclaredNonTrivialSpecialMembersForCall |= SMKind;
    881  1.1  joerg       }
    882  1.1  joerg 
    883  1.1  joerg       // Note when we have declared a declared special member, and suppress the
    884  1.1  joerg       // implicit declaration of this special member.
    885  1.1  joerg       data().DeclaredSpecialMembers |= SMKind;
    886  1.1  joerg 
    887  1.1  joerg       if (!Method->isImplicit()) {
    888  1.1  joerg         data().UserDeclaredSpecialMembers |= SMKind;
    889  1.1  joerg 
    890  1.1  joerg         // C++03 [class]p4:
    891  1.1  joerg         //   A POD-struct is an aggregate class that has [...] no user-defined
    892  1.1  joerg         //   copy assignment operator and no user-defined destructor.
    893  1.1  joerg         //
    894  1.1  joerg         // Since the POD bit is meant to be C++03 POD-ness, and in C++03,
    895  1.1  joerg         // aggregates could not have any constructors, clear it even for an
    896  1.1  joerg         // explicitly defaulted or deleted constructor.
    897  1.1  joerg         // type is technically an aggregate in C++0x since it wouldn't be in 03.
    898  1.1  joerg         //
    899  1.1  joerg         // Also, a user-declared move assignment operator makes a class non-POD.
    900  1.1  joerg         // This is an extension in C++03.
    901  1.1  joerg         data().PlainOldData = false;
    902  1.1  joerg       }
    903  1.1  joerg     }
    904  1.1  joerg 
    905  1.1  joerg     return;
    906  1.1  joerg   }
    907  1.1  joerg 
    908  1.1  joerg   // Handle non-static data members.
    909  1.1  joerg   if (const auto *Field = dyn_cast<FieldDecl>(D)) {
    910  1.1  joerg     ASTContext &Context = getASTContext();
    911  1.1  joerg 
    912  1.1  joerg     // C++2a [class]p7:
    913  1.1  joerg     //   A standard-layout class is a class that:
    914  1.1  joerg     //    [...]
    915  1.1  joerg     //    -- has all non-static data members and bit-fields in the class and
    916  1.1  joerg     //       its base classes first declared in the same class
    917  1.1  joerg     if (data().HasBasesWithFields)
    918  1.1  joerg       data().IsStandardLayout = false;
    919  1.1  joerg 
    920  1.1  joerg     // C++ [class.bit]p2:
    921  1.1  joerg     //   A declaration for a bit-field that omits the identifier declares an
    922  1.1  joerg     //   unnamed bit-field. Unnamed bit-fields are not members and cannot be
    923  1.1  joerg     //   initialized.
    924  1.1  joerg     if (Field->isUnnamedBitfield()) {
    925  1.1  joerg       // C++ [meta.unary.prop]p4: [LWG2358]
    926  1.1  joerg       //   T is a class type [...] with [...] no unnamed bit-fields of non-zero
    927  1.1  joerg       //   length
    928  1.1  joerg       if (data().Empty && !Field->isZeroLengthBitField(Context) &&
    929  1.1  joerg           Context.getLangOpts().getClangABICompat() >
    930  1.1  joerg               LangOptions::ClangABI::Ver6)
    931  1.1  joerg         data().Empty = false;
    932  1.1  joerg       return;
    933  1.1  joerg     }
    934  1.1  joerg 
    935  1.1  joerg     // C++11 [class]p7:
    936  1.1  joerg     //   A standard-layout class is a class that:
    937  1.1  joerg     //    -- either has no non-static data members in the most derived class
    938  1.1  joerg     //       [...] or has no base classes with non-static data members
    939  1.1  joerg     if (data().HasBasesWithNonStaticDataMembers)
    940  1.1  joerg       data().IsCXX11StandardLayout = false;
    941  1.1  joerg 
    942  1.1  joerg     // C++ [dcl.init.aggr]p1:
    943  1.1  joerg     //   An aggregate is an array or a class (clause 9) with [...] no
    944  1.1  joerg     //   private or protected non-static data members (clause 11).
    945  1.1  joerg     //
    946  1.1  joerg     // A POD must be an aggregate.
    947  1.1  joerg     if (D->getAccess() == AS_private || D->getAccess() == AS_protected) {
    948  1.1  joerg       data().Aggregate = false;
    949  1.1  joerg       data().PlainOldData = false;
    950  1.1  joerg     }
    951  1.1  joerg 
    952  1.1  joerg     // Track whether this is the first field. We use this when checking
    953  1.1  joerg     // whether the class is standard-layout below.
    954  1.1  joerg     bool IsFirstField = !data().HasPrivateFields &&
    955  1.1  joerg                         !data().HasProtectedFields && !data().HasPublicFields;
    956  1.1  joerg 
    957  1.1  joerg     // C++0x [class]p7:
    958  1.1  joerg     //   A standard-layout class is a class that:
    959  1.1  joerg     //    [...]
    960  1.1  joerg     //    -- has the same access control for all non-static data members,
    961  1.1  joerg     switch (D->getAccess()) {
    962  1.1  joerg     case AS_private:    data().HasPrivateFields = true;   break;
    963  1.1  joerg     case AS_protected:  data().HasProtectedFields = true; break;
    964  1.1  joerg     case AS_public:     data().HasPublicFields = true;    break;
    965  1.1  joerg     case AS_none:       llvm_unreachable("Invalid access specifier");
    966  1.1  joerg     };
    967  1.1  joerg     if ((data().HasPrivateFields + data().HasProtectedFields +
    968  1.1  joerg          data().HasPublicFields) > 1) {
    969  1.1  joerg       data().IsStandardLayout = false;
    970  1.1  joerg       data().IsCXX11StandardLayout = false;
    971  1.1  joerg     }
    972  1.1  joerg 
    973  1.1  joerg     // Keep track of the presence of mutable fields.
    974  1.1  joerg     if (Field->isMutable()) {
    975  1.1  joerg       data().HasMutableFields = true;
    976  1.1  joerg       data().NeedOverloadResolutionForCopyConstructor = true;
    977  1.1  joerg     }
    978  1.1  joerg 
    979  1.1  joerg     // C++11 [class.union]p8, DR1460:
    980  1.1  joerg     //   If X is a union, a non-static data member of X that is not an anonymous
    981  1.1  joerg     //   union is a variant member of X.
    982  1.1  joerg     if (isUnion() && !Field->isAnonymousStructOrUnion())
    983  1.1  joerg       data().HasVariantMembers = true;
    984  1.1  joerg 
    985  1.1  joerg     // C++0x [class]p9:
    986  1.1  joerg     //   A POD struct is a class that is both a trivial class and a
    987  1.1  joerg     //   standard-layout class, and has no non-static data members of type
    988  1.1  joerg     //   non-POD struct, non-POD union (or array of such types).
    989  1.1  joerg     //
    990  1.1  joerg     // Automatic Reference Counting: the presence of a member of Objective-C pointer type
    991  1.1  joerg     // that does not explicitly have no lifetime makes the class a non-POD.
    992  1.1  joerg     QualType T = Context.getBaseElementType(Field->getType());
    993  1.1  joerg     if (T->isObjCRetainableType() || T.isObjCGCStrong()) {
    994  1.1  joerg       if (T.hasNonTrivialObjCLifetime()) {
    995  1.1  joerg         // Objective-C Automatic Reference Counting:
    996  1.1  joerg         //   If a class has a non-static data member of Objective-C pointer
    997  1.1  joerg         //   type (or array thereof), it is a non-POD type and its
    998  1.1  joerg         //   default constructor (if any), copy constructor, move constructor,
    999  1.1  joerg         //   copy assignment operator, move assignment operator, and destructor are
   1000  1.1  joerg         //   non-trivial.
   1001  1.1  joerg         setHasObjectMember(true);
   1002  1.1  joerg         struct DefinitionData &Data = data();
   1003  1.1  joerg         Data.PlainOldData = false;
   1004  1.1  joerg         Data.HasTrivialSpecialMembers = 0;
   1005  1.1  joerg 
   1006  1.1  joerg         // __strong or __weak fields do not make special functions non-trivial
   1007  1.1  joerg         // for the purpose of calls.
   1008  1.1  joerg         Qualifiers::ObjCLifetime LT = T.getQualifiers().getObjCLifetime();
   1009  1.1  joerg         if (LT != Qualifiers::OCL_Strong && LT != Qualifiers::OCL_Weak)
   1010  1.1  joerg           data().HasTrivialSpecialMembersForCall = 0;
   1011  1.1  joerg 
   1012  1.1  joerg         // Structs with __weak fields should never be passed directly.
   1013  1.1  joerg         if (LT == Qualifiers::OCL_Weak)
   1014  1.1  joerg           setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs);
   1015  1.1  joerg 
   1016  1.1  joerg         Data.HasIrrelevantDestructor = false;
   1017  1.1  joerg 
   1018  1.1  joerg         if (isUnion()) {
   1019  1.1  joerg           data().DefaultedCopyConstructorIsDeleted = true;
   1020  1.1  joerg           data().DefaultedMoveConstructorIsDeleted = true;
   1021  1.1  joerg           data().DefaultedMoveAssignmentIsDeleted = true;
   1022  1.1  joerg           data().DefaultedDestructorIsDeleted = true;
   1023  1.1  joerg           data().NeedOverloadResolutionForCopyConstructor = true;
   1024  1.1  joerg           data().NeedOverloadResolutionForMoveConstructor = true;
   1025  1.1  joerg           data().NeedOverloadResolutionForMoveAssignment = true;
   1026  1.1  joerg           data().NeedOverloadResolutionForDestructor = true;
   1027  1.1  joerg         }
   1028  1.1  joerg       } else if (!Context.getLangOpts().ObjCAutoRefCount) {
   1029  1.1  joerg         setHasObjectMember(true);
   1030  1.1  joerg       }
   1031  1.1  joerg     } else if (!T.isCXX98PODType(Context))
   1032  1.1  joerg       data().PlainOldData = false;
   1033  1.1  joerg 
   1034  1.1  joerg     if (T->isReferenceType()) {
   1035  1.1  joerg       if (!Field->hasInClassInitializer())
   1036  1.1  joerg         data().HasUninitializedReferenceMember = true;
   1037  1.1  joerg 
   1038  1.1  joerg       // C++0x [class]p7:
   1039  1.1  joerg       //   A standard-layout class is a class that:
   1040  1.1  joerg       //    -- has no non-static data members of type [...] reference,
   1041  1.1  joerg       data().IsStandardLayout = false;
   1042  1.1  joerg       data().IsCXX11StandardLayout = false;
   1043  1.1  joerg 
   1044  1.1  joerg       // C++1z [class.copy.ctor]p10:
   1045  1.1  joerg       //   A defaulted copy constructor for a class X is defined as deleted if X has:
   1046  1.1  joerg       //    -- a non-static data member of rvalue reference type
   1047  1.1  joerg       if (T->isRValueReferenceType())
   1048  1.1  joerg         data().DefaultedCopyConstructorIsDeleted = true;
   1049  1.1  joerg     }
   1050  1.1  joerg 
   1051  1.1  joerg     if (!Field->hasInClassInitializer() && !Field->isMutable()) {
   1052  1.1  joerg       if (CXXRecordDecl *FieldType = T->getAsCXXRecordDecl()) {
   1053  1.1  joerg         if (FieldType->hasDefinition() && !FieldType->allowConstDefaultInit())
   1054  1.1  joerg           data().HasUninitializedFields = true;
   1055  1.1  joerg       } else {
   1056  1.1  joerg         data().HasUninitializedFields = true;
   1057  1.1  joerg       }
   1058  1.1  joerg     }
   1059  1.1  joerg 
   1060  1.1  joerg     // Record if this field is the first non-literal or volatile field or base.
   1061  1.1  joerg     if (!T->isLiteralType(Context) || T.isVolatileQualified())
   1062  1.1  joerg       data().HasNonLiteralTypeFieldsOrBases = true;
   1063  1.1  joerg 
   1064  1.1  joerg     if (Field->hasInClassInitializer() ||
   1065  1.1  joerg         (Field->isAnonymousStructOrUnion() &&
   1066  1.1  joerg          Field->getType()->getAsCXXRecordDecl()->hasInClassInitializer())) {
   1067  1.1  joerg       data().HasInClassInitializer = true;
   1068  1.1  joerg 
   1069  1.1  joerg       // C++11 [class]p5:
   1070  1.1  joerg       //   A default constructor is trivial if [...] no non-static data member
   1071  1.1  joerg       //   of its class has a brace-or-equal-initializer.
   1072  1.1  joerg       data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor;
   1073  1.1  joerg 
   1074  1.1  joerg       // C++11 [dcl.init.aggr]p1:
   1075  1.1  joerg       //   An aggregate is a [...] class with [...] no
   1076  1.1  joerg       //   brace-or-equal-initializers for non-static data members.
   1077  1.1  joerg       //
   1078  1.1  joerg       // This rule was removed in C++14.
   1079  1.1  joerg       if (!getASTContext().getLangOpts().CPlusPlus14)
   1080  1.1  joerg         data().Aggregate = false;
   1081  1.1  joerg 
   1082  1.1  joerg       // C++11 [class]p10:
   1083  1.1  joerg       //   A POD struct is [...] a trivial class.
   1084  1.1  joerg       data().PlainOldData = false;
   1085  1.1  joerg     }
   1086  1.1  joerg 
   1087  1.1  joerg     // C++11 [class.copy]p23:
   1088  1.1  joerg     //   A defaulted copy/move assignment operator for a class X is defined
   1089  1.1  joerg     //   as deleted if X has:
   1090  1.1  joerg     //    -- a non-static data member of reference type
   1091  1.1  joerg     if (T->isReferenceType())
   1092  1.1  joerg       data().DefaultedMoveAssignmentIsDeleted = true;
   1093  1.1  joerg 
   1094  1.1  joerg     // Bitfields of length 0 are also zero-sized, but we already bailed out for
   1095  1.1  joerg     // those because they are always unnamed.
   1096  1.1  joerg     bool IsZeroSize = Field->isZeroSize(Context);
   1097  1.1  joerg 
   1098  1.1  joerg     if (const auto *RecordTy = T->getAs<RecordType>()) {
   1099  1.1  joerg       auto *FieldRec = cast<CXXRecordDecl>(RecordTy->getDecl());
   1100  1.1  joerg       if (FieldRec->getDefinition()) {
   1101  1.1  joerg         addedClassSubobject(FieldRec);
   1102  1.1  joerg 
   1103  1.1  joerg         // We may need to perform overload resolution to determine whether a
   1104  1.1  joerg         // field can be moved if it's const or volatile qualified.
   1105  1.1  joerg         if (T.getCVRQualifiers() & (Qualifiers::Const | Qualifiers::Volatile)) {
   1106  1.1  joerg           // We need to care about 'const' for the copy constructor because an
   1107  1.1  joerg           // implicit copy constructor might be declared with a non-const
   1108  1.1  joerg           // parameter.
   1109  1.1  joerg           data().NeedOverloadResolutionForCopyConstructor = true;
   1110  1.1  joerg           data().NeedOverloadResolutionForMoveConstructor = true;
   1111  1.1  joerg           data().NeedOverloadResolutionForMoveAssignment = true;
   1112  1.1  joerg         }
   1113  1.1  joerg 
   1114  1.1  joerg         // C++11 [class.ctor]p5, C++11 [class.copy]p11:
   1115  1.1  joerg         //   A defaulted [special member] for a class X is defined as
   1116  1.1  joerg         //   deleted if:
   1117  1.1  joerg         //    -- X is a union-like class that has a variant member with a
   1118  1.1  joerg         //       non-trivial [corresponding special member]
   1119  1.1  joerg         if (isUnion()) {
   1120  1.1  joerg           if (FieldRec->hasNonTrivialCopyConstructor())
   1121  1.1  joerg             data().DefaultedCopyConstructorIsDeleted = true;
   1122  1.1  joerg           if (FieldRec->hasNonTrivialMoveConstructor())
   1123  1.1  joerg             data().DefaultedMoveConstructorIsDeleted = true;
   1124  1.1  joerg           if (FieldRec->hasNonTrivialMoveAssignment())
   1125  1.1  joerg             data().DefaultedMoveAssignmentIsDeleted = true;
   1126  1.1  joerg           if (FieldRec->hasNonTrivialDestructor())
   1127  1.1  joerg             data().DefaultedDestructorIsDeleted = true;
   1128  1.1  joerg         }
   1129  1.1  joerg 
   1130  1.1  joerg         // For an anonymous union member, our overload resolution will perform
   1131  1.1  joerg         // overload resolution for its members.
   1132  1.1  joerg         if (Field->isAnonymousStructOrUnion()) {
   1133  1.1  joerg           data().NeedOverloadResolutionForCopyConstructor |=
   1134  1.1  joerg               FieldRec->data().NeedOverloadResolutionForCopyConstructor;
   1135  1.1  joerg           data().NeedOverloadResolutionForMoveConstructor |=
   1136  1.1  joerg               FieldRec->data().NeedOverloadResolutionForMoveConstructor;
   1137  1.1  joerg           data().NeedOverloadResolutionForMoveAssignment |=
   1138  1.1  joerg               FieldRec->data().NeedOverloadResolutionForMoveAssignment;
   1139  1.1  joerg           data().NeedOverloadResolutionForDestructor |=
   1140  1.1  joerg               FieldRec->data().NeedOverloadResolutionForDestructor;
   1141  1.1  joerg         }
   1142  1.1  joerg 
   1143  1.1  joerg         // C++0x [class.ctor]p5:
   1144  1.1  joerg         //   A default constructor is trivial [...] if:
   1145  1.1  joerg         //    -- for all the non-static data members of its class that are of
   1146  1.1  joerg         //       class type (or array thereof), each such class has a trivial
   1147  1.1  joerg         //       default constructor.
   1148  1.1  joerg         if (!FieldRec->hasTrivialDefaultConstructor())
   1149  1.1  joerg           data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor;
   1150  1.1  joerg 
   1151  1.1  joerg         // C++0x [class.copy]p13:
   1152  1.1  joerg         //   A copy/move constructor for class X is trivial if [...]
   1153  1.1  joerg         //    [...]
   1154  1.1  joerg         //    -- for each non-static data member of X that is of class type (or
   1155  1.1  joerg         //       an array thereof), the constructor selected to copy/move that
   1156  1.1  joerg         //       member is trivial;
   1157  1.1  joerg         if (!FieldRec->hasTrivialCopyConstructor())
   1158  1.1  joerg           data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor;
   1159  1.1  joerg 
   1160  1.1  joerg         if (!FieldRec->hasTrivialCopyConstructorForCall())
   1161  1.1  joerg           data().HasTrivialSpecialMembersForCall &= ~SMF_CopyConstructor;
   1162  1.1  joerg 
   1163  1.1  joerg         // If the field doesn't have a simple move constructor, we'll eagerly
   1164  1.1  joerg         // declare the move constructor for this class and we'll decide whether
   1165  1.1  joerg         // it's trivial then.
   1166  1.1  joerg         if (!FieldRec->hasTrivialMoveConstructor())
   1167  1.1  joerg           data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor;
   1168  1.1  joerg 
   1169  1.1  joerg         if (!FieldRec->hasTrivialMoveConstructorForCall())
   1170  1.1  joerg           data().HasTrivialSpecialMembersForCall &= ~SMF_MoveConstructor;
   1171  1.1  joerg 
   1172  1.1  joerg         // C++0x [class.copy]p27:
   1173  1.1  joerg         //   A copy/move assignment operator for class X is trivial if [...]
   1174  1.1  joerg         //    [...]
   1175  1.1  joerg         //    -- for each non-static data member of X that is of class type (or
   1176  1.1  joerg         //       an array thereof), the assignment operator selected to
   1177  1.1  joerg         //       copy/move that member is trivial;
   1178  1.1  joerg         if (!FieldRec->hasTrivialCopyAssignment())
   1179  1.1  joerg           data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment;
   1180  1.1  joerg         // If the field doesn't have a simple move assignment, we'll eagerly
   1181  1.1  joerg         // declare the move assignment for this class and we'll decide whether
   1182  1.1  joerg         // it's trivial then.
   1183  1.1  joerg         if (!FieldRec->hasTrivialMoveAssignment())
   1184  1.1  joerg           data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment;
   1185  1.1  joerg 
   1186  1.1  joerg         if (!FieldRec->hasTrivialDestructor())
   1187  1.1  joerg           data().HasTrivialSpecialMembers &= ~SMF_Destructor;
   1188  1.1  joerg         if (!FieldRec->hasTrivialDestructorForCall())
   1189  1.1  joerg           data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor;
   1190  1.1  joerg         if (!FieldRec->hasIrrelevantDestructor())
   1191  1.1  joerg           data().HasIrrelevantDestructor = false;
   1192  1.1  joerg         if (FieldRec->hasObjectMember())
   1193  1.1  joerg           setHasObjectMember(true);
   1194  1.1  joerg         if (FieldRec->hasVolatileMember())
   1195  1.1  joerg           setHasVolatileMember(true);
   1196  1.1  joerg         if (FieldRec->getArgPassingRestrictions() ==
   1197  1.1  joerg             RecordDecl::APK_CanNeverPassInRegs)
   1198  1.1  joerg           setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs);
   1199  1.1  joerg 
   1200  1.1  joerg         // C++0x [class]p7:
   1201  1.1  joerg         //   A standard-layout class is a class that:
   1202  1.1  joerg         //    -- has no non-static data members of type non-standard-layout
   1203  1.1  joerg         //       class (or array of such types) [...]
   1204  1.1  joerg         if (!FieldRec->isStandardLayout())
   1205  1.1  joerg           data().IsStandardLayout = false;
   1206  1.1  joerg         if (!FieldRec->isCXX11StandardLayout())
   1207  1.1  joerg           data().IsCXX11StandardLayout = false;
   1208  1.1  joerg 
   1209  1.1  joerg         // C++2a [class]p7:
   1210  1.1  joerg         //   A standard-layout class is a class that:
   1211  1.1  joerg         //    [...]
   1212  1.1  joerg         //    -- has no element of the set M(S) of types as a base class.
   1213  1.1  joerg         if (data().IsStandardLayout &&
   1214  1.1  joerg             (isUnion() || IsFirstField || IsZeroSize) &&
   1215  1.1  joerg             hasSubobjectAtOffsetZeroOfEmptyBaseType(Context, FieldRec))
   1216  1.1  joerg           data().IsStandardLayout = false;
   1217  1.1  joerg 
   1218  1.1  joerg         // C++11 [class]p7:
   1219  1.1  joerg         //   A standard-layout class is a class that:
   1220  1.1  joerg         //    -- has no base classes of the same type as the first non-static
   1221  1.1  joerg         //       data member
   1222  1.1  joerg         if (data().IsCXX11StandardLayout && IsFirstField) {
   1223  1.1  joerg           // FIXME: We should check all base classes here, not just direct
   1224  1.1  joerg           // base classes.
   1225  1.1  joerg           for (const auto &BI : bases()) {
   1226  1.1  joerg             if (Context.hasSameUnqualifiedType(BI.getType(), T)) {
   1227  1.1  joerg               data().IsCXX11StandardLayout = false;
   1228  1.1  joerg               break;
   1229  1.1  joerg             }
   1230  1.1  joerg           }
   1231  1.1  joerg         }
   1232  1.1  joerg 
   1233  1.1  joerg         // Keep track of the presence of mutable fields.
   1234  1.1  joerg         if (FieldRec->hasMutableFields()) {
   1235  1.1  joerg           data().HasMutableFields = true;
   1236  1.1  joerg           data().NeedOverloadResolutionForCopyConstructor = true;
   1237  1.1  joerg         }
   1238  1.1  joerg 
   1239  1.1  joerg         // C++11 [class.copy]p13:
   1240  1.1  joerg         //   If the implicitly-defined constructor would satisfy the
   1241  1.1  joerg         //   requirements of a constexpr constructor, the implicitly-defined
   1242  1.1  joerg         //   constructor is constexpr.
   1243  1.1  joerg         // C++11 [dcl.constexpr]p4:
   1244  1.1  joerg         //    -- every constructor involved in initializing non-static data
   1245  1.1  joerg         //       members [...] shall be a constexpr constructor
   1246  1.1  joerg         if (!Field->hasInClassInitializer() &&
   1247  1.1  joerg             !FieldRec->hasConstexprDefaultConstructor() && !isUnion())
   1248  1.1  joerg           // The standard requires any in-class initializer to be a constant
   1249  1.1  joerg           // expression. We consider this to be a defect.
   1250  1.1  joerg           data().DefaultedDefaultConstructorIsConstexpr = false;
   1251  1.1  joerg 
   1252  1.1  joerg         // C++11 [class.copy]p8:
   1253  1.1  joerg         //   The implicitly-declared copy constructor for a class X will have
   1254  1.1  joerg         //   the form 'X::X(const X&)' if each potentially constructed subobject
   1255  1.1  joerg         //   of a class type M (or array thereof) has a copy constructor whose
   1256  1.1  joerg         //   first parameter is of type 'const M&' or 'const volatile M&'.
   1257  1.1  joerg         if (!FieldRec->hasCopyConstructorWithConstParam())
   1258  1.1  joerg           data().ImplicitCopyConstructorCanHaveConstParamForNonVBase = false;
   1259  1.1  joerg 
   1260  1.1  joerg         // C++11 [class.copy]p18:
   1261  1.1  joerg         //   The implicitly-declared copy assignment oeprator for a class X will
   1262  1.1  joerg         //   have the form 'X& X::operator=(const X&)' if [...] for all the
   1263  1.1  joerg         //   non-static data members of X that are of a class type M (or array
   1264  1.1  joerg         //   thereof), each such class type has a copy assignment operator whose
   1265  1.1  joerg         //   parameter is of type 'const M&', 'const volatile M&' or 'M'.
   1266  1.1  joerg         if (!FieldRec->hasCopyAssignmentWithConstParam())
   1267  1.1  joerg           data().ImplicitCopyAssignmentHasConstParam = false;
   1268  1.1  joerg 
   1269  1.1  joerg         if (FieldRec->hasUninitializedReferenceMember() &&
   1270  1.1  joerg             !Field->hasInClassInitializer())
   1271  1.1  joerg           data().HasUninitializedReferenceMember = true;
   1272  1.1  joerg 
   1273  1.1  joerg         // C++11 [class.union]p8, DR1460:
   1274  1.1  joerg         //   a non-static data member of an anonymous union that is a member of
   1275  1.1  joerg         //   X is also a variant member of X.
   1276  1.1  joerg         if (FieldRec->hasVariantMembers() &&
   1277  1.1  joerg             Field->isAnonymousStructOrUnion())
   1278  1.1  joerg           data().HasVariantMembers = true;
   1279  1.1  joerg       }
   1280  1.1  joerg     } else {
   1281  1.1  joerg       // Base element type of field is a non-class type.
   1282  1.1  joerg       if (!T->isLiteralType(Context) ||
   1283  1.1  joerg           (!Field->hasInClassInitializer() && !isUnion() &&
   1284  1.1  joerg            !Context.getLangOpts().CPlusPlus2a))
   1285  1.1  joerg         data().DefaultedDefaultConstructorIsConstexpr = false;
   1286  1.1  joerg 
   1287  1.1  joerg       // C++11 [class.copy]p23:
   1288  1.1  joerg       //   A defaulted copy/move assignment operator for a class X is defined
   1289  1.1  joerg       //   as deleted if X has:
   1290  1.1  joerg       //    -- a non-static data member of const non-class type (or array
   1291  1.1  joerg       //       thereof)
   1292  1.1  joerg       if (T.isConstQualified())
   1293  1.1  joerg         data().DefaultedMoveAssignmentIsDeleted = true;
   1294  1.1  joerg     }
   1295  1.1  joerg 
   1296  1.1  joerg     // C++14 [meta.unary.prop]p4:
   1297  1.1  joerg     //   T is a class type [...] with [...] no non-static data members other
   1298  1.1  joerg     //   than subobjects of zero size
   1299  1.1  joerg     if (data().Empty && !IsZeroSize)
   1300  1.1  joerg       data().Empty = false;
   1301  1.1  joerg   }
   1302  1.1  joerg 
   1303  1.1  joerg   // Handle using declarations of conversion functions.
   1304  1.1  joerg   if (auto *Shadow = dyn_cast<UsingShadowDecl>(D)) {
   1305  1.1  joerg     if (Shadow->getDeclName().getNameKind()
   1306  1.1  joerg           == DeclarationName::CXXConversionFunctionName) {
   1307  1.1  joerg       ASTContext &Ctx = getASTContext();
   1308  1.1  joerg       data().Conversions.get(Ctx).addDecl(Ctx, Shadow, Shadow->getAccess());
   1309  1.1  joerg     }
   1310  1.1  joerg   }
   1311  1.1  joerg 
   1312  1.1  joerg   if (const auto *Using = dyn_cast<UsingDecl>(D)) {
   1313  1.1  joerg     if (Using->getDeclName().getNameKind() ==
   1314  1.1  joerg         DeclarationName::CXXConstructorName) {
   1315  1.1  joerg       data().HasInheritedConstructor = true;
   1316  1.1  joerg       // C++1z [dcl.init.aggr]p1:
   1317  1.1  joerg       //  An aggregate is [...] a class [...] with no inherited constructors
   1318  1.1  joerg       data().Aggregate = false;
   1319  1.1  joerg     }
   1320  1.1  joerg 
   1321  1.1  joerg     if (Using->getDeclName().getCXXOverloadedOperator() == OO_Equal)
   1322  1.1  joerg       data().HasInheritedAssignment = true;
   1323  1.1  joerg   }
   1324  1.1  joerg }
   1325  1.1  joerg 
   1326  1.1  joerg void CXXRecordDecl::finishedDefaultedOrDeletedMember(CXXMethodDecl *D) {
   1327  1.1  joerg   assert(!D->isImplicit() && !D->isUserProvided());
   1328  1.1  joerg 
   1329  1.1  joerg   // The kind of special member this declaration is, if any.
   1330  1.1  joerg   unsigned SMKind = 0;
   1331  1.1  joerg 
   1332  1.1  joerg   if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(D)) {
   1333  1.1  joerg     if (Constructor->isDefaultConstructor()) {
   1334  1.1  joerg       SMKind |= SMF_DefaultConstructor;
   1335  1.1  joerg       if (Constructor->isConstexpr())
   1336  1.1  joerg         data().HasConstexprDefaultConstructor = true;
   1337  1.1  joerg     }
   1338  1.1  joerg     if (Constructor->isCopyConstructor())
   1339  1.1  joerg       SMKind |= SMF_CopyConstructor;
   1340  1.1  joerg     else if (Constructor->isMoveConstructor())
   1341  1.1  joerg       SMKind |= SMF_MoveConstructor;
   1342  1.1  joerg     else if (Constructor->isConstexpr())
   1343  1.1  joerg       // We may now know that the constructor is constexpr.
   1344  1.1  joerg       data().HasConstexprNonCopyMoveConstructor = true;
   1345  1.1  joerg   } else if (isa<CXXDestructorDecl>(D)) {
   1346  1.1  joerg     SMKind |= SMF_Destructor;
   1347  1.1  joerg     if (!D->isTrivial() || D->getAccess() != AS_public || D->isDeleted())
   1348  1.1  joerg       data().HasIrrelevantDestructor = false;
   1349  1.1  joerg   } else if (D->isCopyAssignmentOperator())
   1350  1.1  joerg     SMKind |= SMF_CopyAssignment;
   1351  1.1  joerg   else if (D->isMoveAssignmentOperator())
   1352  1.1  joerg     SMKind |= SMF_MoveAssignment;
   1353  1.1  joerg 
   1354  1.1  joerg   // Update which trivial / non-trivial special members we have.
   1355  1.1  joerg   // addedMember will have skipped this step for this member.
   1356  1.1  joerg   if (D->isTrivial())
   1357  1.1  joerg     data().HasTrivialSpecialMembers |= SMKind;
   1358  1.1  joerg   else
   1359  1.1  joerg     data().DeclaredNonTrivialSpecialMembers |= SMKind;
   1360  1.1  joerg }
   1361  1.1  joerg 
   1362  1.1  joerg void CXXRecordDecl::setTrivialForCallFlags(CXXMethodDecl *D) {
   1363  1.1  joerg   unsigned SMKind = 0;
   1364  1.1  joerg 
   1365  1.1  joerg   if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(D)) {
   1366  1.1  joerg     if (Constructor->isCopyConstructor())
   1367  1.1  joerg       SMKind = SMF_CopyConstructor;
   1368  1.1  joerg     else if (Constructor->isMoveConstructor())
   1369  1.1  joerg       SMKind = SMF_MoveConstructor;
   1370  1.1  joerg   } else if (isa<CXXDestructorDecl>(D))
   1371  1.1  joerg     SMKind = SMF_Destructor;
   1372  1.1  joerg 
   1373  1.1  joerg   if (D->isTrivialForCall())
   1374  1.1  joerg     data().HasTrivialSpecialMembersForCall |= SMKind;
   1375  1.1  joerg   else
   1376  1.1  joerg     data().DeclaredNonTrivialSpecialMembersForCall |= SMKind;
   1377  1.1  joerg }
   1378  1.1  joerg 
   1379  1.1  joerg bool CXXRecordDecl::isCLike() const {
   1380  1.1  joerg   if (getTagKind() == TTK_Class || getTagKind() == TTK_Interface ||
   1381  1.1  joerg       !TemplateOrInstantiation.isNull())
   1382  1.1  joerg     return false;
   1383  1.1  joerg   if (!hasDefinition())
   1384  1.1  joerg     return true;
   1385  1.1  joerg 
   1386  1.1  joerg   return isPOD() && data().HasOnlyCMembers;
   1387  1.1  joerg }
   1388  1.1  joerg 
   1389  1.1  joerg bool CXXRecordDecl::isGenericLambda() const {
   1390  1.1  joerg   if (!isLambda()) return false;
   1391  1.1  joerg   return getLambdaData().IsGenericLambda;
   1392  1.1  joerg }
   1393  1.1  joerg 
   1394  1.1  joerg #ifndef NDEBUG
   1395  1.1  joerg static bool allLookupResultsAreTheSame(const DeclContext::lookup_result &R) {
   1396  1.1  joerg   for (auto *D : R)
   1397  1.1  joerg     if (!declaresSameEntity(D, R.front()))
   1398  1.1  joerg       return false;
   1399  1.1  joerg   return true;
   1400  1.1  joerg }
   1401  1.1  joerg #endif
   1402  1.1  joerg 
   1403  1.1  joerg static NamedDecl* getLambdaCallOperatorHelper(const CXXRecordDecl &RD) {
   1404  1.1  joerg   if (!RD.isLambda()) return nullptr;
   1405  1.1  joerg   DeclarationName Name =
   1406  1.1  joerg     RD.getASTContext().DeclarationNames.getCXXOperatorName(OO_Call);
   1407  1.1  joerg   DeclContext::lookup_result Calls = RD.lookup(Name);
   1408  1.1  joerg 
   1409  1.1  joerg   assert(!Calls.empty() && "Missing lambda call operator!");
   1410  1.1  joerg   assert(allLookupResultsAreTheSame(Calls) &&
   1411  1.1  joerg          "More than one lambda call operator!");
   1412  1.1  joerg   return Calls.front();
   1413  1.1  joerg }
   1414  1.1  joerg 
   1415  1.1  joerg FunctionTemplateDecl* CXXRecordDecl::getDependentLambdaCallOperator() const {
   1416  1.1  joerg   NamedDecl *CallOp = getLambdaCallOperatorHelper(*this);
   1417  1.1  joerg   return  dyn_cast_or_null<FunctionTemplateDecl>(CallOp);
   1418  1.1  joerg }
   1419  1.1  joerg 
   1420  1.1  joerg CXXMethodDecl *CXXRecordDecl::getLambdaCallOperator() const {
   1421  1.1  joerg   NamedDecl *CallOp = getLambdaCallOperatorHelper(*this);
   1422  1.1  joerg 
   1423  1.1  joerg   if (CallOp == nullptr)
   1424  1.1  joerg     return nullptr;
   1425  1.1  joerg 
   1426  1.1  joerg   if (const auto *CallOpTmpl = dyn_cast<FunctionTemplateDecl>(CallOp))
   1427  1.1  joerg     return cast<CXXMethodDecl>(CallOpTmpl->getTemplatedDecl());
   1428  1.1  joerg 
   1429  1.1  joerg   return cast<CXXMethodDecl>(CallOp);
   1430  1.1  joerg }
   1431  1.1  joerg 
   1432  1.1  joerg CXXMethodDecl* CXXRecordDecl::getLambdaStaticInvoker() const {
   1433  1.1  joerg   if (!isLambda()) return nullptr;
   1434  1.1  joerg   DeclarationName Name =
   1435  1.1  joerg     &getASTContext().Idents.get(getLambdaStaticInvokerName());
   1436  1.1  joerg   DeclContext::lookup_result Invoker = lookup(Name);
   1437  1.1  joerg   if (Invoker.empty()) return nullptr;
   1438  1.1  joerg   assert(allLookupResultsAreTheSame(Invoker) &&
   1439  1.1  joerg          "More than one static invoker operator!");
   1440  1.1  joerg   NamedDecl *InvokerFun = Invoker.front();
   1441  1.1  joerg   if (const auto *InvokerTemplate = dyn_cast<FunctionTemplateDecl>(InvokerFun))
   1442  1.1  joerg     return cast<CXXMethodDecl>(InvokerTemplate->getTemplatedDecl());
   1443  1.1  joerg 
   1444  1.1  joerg   return cast<CXXMethodDecl>(InvokerFun);
   1445  1.1  joerg }
   1446  1.1  joerg 
   1447  1.1  joerg void CXXRecordDecl::getCaptureFields(
   1448  1.1  joerg        llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures,
   1449  1.1  joerg        FieldDecl *&ThisCapture) const {
   1450  1.1  joerg   Captures.clear();
   1451  1.1  joerg   ThisCapture = nullptr;
   1452  1.1  joerg 
   1453  1.1  joerg   LambdaDefinitionData &Lambda = getLambdaData();
   1454  1.1  joerg   RecordDecl::field_iterator Field = field_begin();
   1455  1.1  joerg   for (const LambdaCapture *C = Lambda.Captures, *CEnd = C + Lambda.NumCaptures;
   1456  1.1  joerg        C != CEnd; ++C, ++Field) {
   1457  1.1  joerg     if (C->capturesThis())
   1458  1.1  joerg       ThisCapture = *Field;
   1459  1.1  joerg     else if (C->capturesVariable())
   1460  1.1  joerg       Captures[C->getCapturedVar()] = *Field;
   1461  1.1  joerg   }
   1462  1.1  joerg   assert(Field == field_end());
   1463  1.1  joerg }
   1464  1.1  joerg 
   1465  1.1  joerg TemplateParameterList *
   1466  1.1  joerg CXXRecordDecl::getGenericLambdaTemplateParameterList() const {
   1467  1.1  joerg   if (!isGenericLambda()) return nullptr;
   1468  1.1  joerg   CXXMethodDecl *CallOp = getLambdaCallOperator();
   1469  1.1  joerg   if (FunctionTemplateDecl *Tmpl = CallOp->getDescribedFunctionTemplate())
   1470  1.1  joerg     return Tmpl->getTemplateParameters();
   1471  1.1  joerg   return nullptr;
   1472  1.1  joerg }
   1473  1.1  joerg 
   1474  1.1  joerg ArrayRef<NamedDecl *>
   1475  1.1  joerg CXXRecordDecl::getLambdaExplicitTemplateParameters() const {
   1476  1.1  joerg   TemplateParameterList *List = getGenericLambdaTemplateParameterList();
   1477  1.1  joerg   if (!List)
   1478  1.1  joerg     return {};
   1479  1.1  joerg 
   1480  1.1  joerg   assert(std::is_partitioned(List->begin(), List->end(),
   1481  1.1  joerg                              [](const NamedDecl *D) { return !D->isImplicit(); })
   1482  1.1  joerg          && "Explicit template params should be ordered before implicit ones");
   1483  1.1  joerg 
   1484  1.1  joerg   const auto ExplicitEnd = llvm::partition_point(
   1485  1.1  joerg       *List, [](const NamedDecl *D) { return !D->isImplicit(); });
   1486  1.1  joerg   return llvm::makeArrayRef(List->begin(), ExplicitEnd);
   1487  1.1  joerg }
   1488  1.1  joerg 
   1489  1.1  joerg Decl *CXXRecordDecl::getLambdaContextDecl() const {
   1490  1.1  joerg   assert(isLambda() && "Not a lambda closure type!");
   1491  1.1  joerg   ExternalASTSource *Source = getParentASTContext().getExternalSource();
   1492  1.1  joerg   return getLambdaData().ContextDecl.get(Source);
   1493  1.1  joerg }
   1494  1.1  joerg 
   1495  1.1  joerg static CanQualType GetConversionType(ASTContext &Context, NamedDecl *Conv) {
   1496  1.1  joerg   QualType T =
   1497  1.1  joerg       cast<CXXConversionDecl>(Conv->getUnderlyingDecl()->getAsFunction())
   1498  1.1  joerg           ->getConversionType();
   1499  1.1  joerg   return Context.getCanonicalType(T);
   1500  1.1  joerg }
   1501  1.1  joerg 
   1502  1.1  joerg /// Collect the visible conversions of a base class.
   1503  1.1  joerg ///
   1504  1.1  joerg /// \param Record a base class of the class we're considering
   1505  1.1  joerg /// \param InVirtual whether this base class is a virtual base (or a base
   1506  1.1  joerg ///   of a virtual base)
   1507  1.1  joerg /// \param Access the access along the inheritance path to this base
   1508  1.1  joerg /// \param ParentHiddenTypes the conversions provided by the inheritors
   1509  1.1  joerg ///   of this base
   1510  1.1  joerg /// \param Output the set to which to add conversions from non-virtual bases
   1511  1.1  joerg /// \param VOutput the set to which to add conversions from virtual bases
   1512  1.1  joerg /// \param HiddenVBaseCs the set of conversions which were hidden in a
   1513  1.1  joerg ///   virtual base along some inheritance path
   1514  1.1  joerg static void CollectVisibleConversions(ASTContext &Context,
   1515  1.1  joerg                                       CXXRecordDecl *Record,
   1516  1.1  joerg                                       bool InVirtual,
   1517  1.1  joerg                                       AccessSpecifier Access,
   1518  1.1  joerg                   const llvm::SmallPtrSet<CanQualType, 8> &ParentHiddenTypes,
   1519  1.1  joerg                                       ASTUnresolvedSet &Output,
   1520  1.1  joerg                                       UnresolvedSetImpl &VOutput,
   1521  1.1  joerg                            llvm::SmallPtrSet<NamedDecl*, 8> &HiddenVBaseCs) {
   1522  1.1  joerg   // The set of types which have conversions in this class or its
   1523  1.1  joerg   // subclasses.  As an optimization, we don't copy the derived set
   1524  1.1  joerg   // unless it might change.
   1525  1.1  joerg   const llvm::SmallPtrSet<CanQualType, 8> *HiddenTypes = &ParentHiddenTypes;
   1526  1.1  joerg   llvm::SmallPtrSet<CanQualType, 8> HiddenTypesBuffer;
   1527  1.1  joerg 
   1528  1.1  joerg   // Collect the direct conversions and figure out which conversions
   1529  1.1  joerg   // will be hidden in the subclasses.
   1530  1.1  joerg   CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin();
   1531  1.1  joerg   CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end();
   1532  1.1  joerg   if (ConvI != ConvE) {
   1533  1.1  joerg     HiddenTypesBuffer = ParentHiddenTypes;
   1534  1.1  joerg     HiddenTypes = &HiddenTypesBuffer;
   1535  1.1  joerg 
   1536  1.1  joerg     for (CXXRecordDecl::conversion_iterator I = ConvI; I != ConvE; ++I) {
   1537  1.1  joerg       CanQualType ConvType(GetConversionType(Context, I.getDecl()));
   1538  1.1  joerg       bool Hidden = ParentHiddenTypes.count(ConvType);
   1539  1.1  joerg       if (!Hidden)
   1540  1.1  joerg         HiddenTypesBuffer.insert(ConvType);
   1541  1.1  joerg 
   1542  1.1  joerg       // If this conversion is hidden and we're in a virtual base,
   1543  1.1  joerg       // remember that it's hidden along some inheritance path.
   1544  1.1  joerg       if (Hidden && InVirtual)
   1545  1.1  joerg         HiddenVBaseCs.insert(cast<NamedDecl>(I.getDecl()->getCanonicalDecl()));
   1546  1.1  joerg 
   1547  1.1  joerg       // If this conversion isn't hidden, add it to the appropriate output.
   1548  1.1  joerg       else if (!Hidden) {
   1549  1.1  joerg         AccessSpecifier IAccess
   1550  1.1  joerg           = CXXRecordDecl::MergeAccess(Access, I.getAccess());
   1551  1.1  joerg 
   1552  1.1  joerg         if (InVirtual)
   1553  1.1  joerg           VOutput.addDecl(I.getDecl(), IAccess);
   1554  1.1  joerg         else
   1555  1.1  joerg           Output.addDecl(Context, I.getDecl(), IAccess);
   1556  1.1  joerg       }
   1557  1.1  joerg     }
   1558  1.1  joerg   }
   1559  1.1  joerg 
   1560  1.1  joerg   // Collect information recursively from any base classes.
   1561  1.1  joerg   for (const auto &I : Record->bases()) {
   1562  1.1  joerg     const RecordType *RT = I.getType()->getAs<RecordType>();
   1563  1.1  joerg     if (!RT) continue;
   1564  1.1  joerg 
   1565  1.1  joerg     AccessSpecifier BaseAccess
   1566  1.1  joerg       = CXXRecordDecl::MergeAccess(Access, I.getAccessSpecifier());
   1567  1.1  joerg     bool BaseInVirtual = InVirtual || I.isVirtual();
   1568  1.1  joerg 
   1569  1.1  joerg     auto *Base = cast<CXXRecordDecl>(RT->getDecl());
   1570  1.1  joerg     CollectVisibleConversions(Context, Base, BaseInVirtual, BaseAccess,
   1571  1.1  joerg                               *HiddenTypes, Output, VOutput, HiddenVBaseCs);
   1572  1.1  joerg   }
   1573  1.1  joerg }
   1574  1.1  joerg 
   1575  1.1  joerg /// Collect the visible conversions of a class.
   1576  1.1  joerg ///
   1577  1.1  joerg /// This would be extremely straightforward if it weren't for virtual
   1578  1.1  joerg /// bases.  It might be worth special-casing that, really.
   1579  1.1  joerg static void CollectVisibleConversions(ASTContext &Context,
   1580  1.1  joerg                                       CXXRecordDecl *Record,
   1581  1.1  joerg                                       ASTUnresolvedSet &Output) {
   1582  1.1  joerg   // The collection of all conversions in virtual bases that we've
   1583  1.1  joerg   // found.  These will be added to the output as long as they don't
   1584  1.1  joerg   // appear in the hidden-conversions set.
   1585  1.1  joerg   UnresolvedSet<8> VBaseCs;
   1586  1.1  joerg 
   1587  1.1  joerg   // The set of conversions in virtual bases that we've determined to
   1588  1.1  joerg   // be hidden.
   1589  1.1  joerg   llvm::SmallPtrSet<NamedDecl*, 8> HiddenVBaseCs;
   1590  1.1  joerg 
   1591  1.1  joerg   // The set of types hidden by classes derived from this one.
   1592  1.1  joerg   llvm::SmallPtrSet<CanQualType, 8> HiddenTypes;
   1593  1.1  joerg 
   1594  1.1  joerg   // Go ahead and collect the direct conversions and add them to the
   1595  1.1  joerg   // hidden-types set.
   1596  1.1  joerg   CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin();
   1597  1.1  joerg   CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end();
   1598  1.1  joerg   Output.append(Context, ConvI, ConvE);
   1599  1.1  joerg   for (; ConvI != ConvE; ++ConvI)
   1600  1.1  joerg     HiddenTypes.insert(GetConversionType(Context, ConvI.getDecl()));
   1601  1.1  joerg 
   1602  1.1  joerg   // Recursively collect conversions from base classes.
   1603  1.1  joerg   for (const auto &I : Record->bases()) {
   1604  1.1  joerg     const RecordType *RT = I.getType()->getAs<RecordType>();
   1605  1.1  joerg     if (!RT) continue;
   1606  1.1  joerg 
   1607  1.1  joerg     CollectVisibleConversions(Context, cast<CXXRecordDecl>(RT->getDecl()),
   1608  1.1  joerg                               I.isVirtual(), I.getAccessSpecifier(),
   1609  1.1  joerg                               HiddenTypes, Output, VBaseCs, HiddenVBaseCs);
   1610  1.1  joerg   }
   1611  1.1  joerg 
   1612  1.1  joerg   // Add any unhidden conversions provided by virtual bases.
   1613  1.1  joerg   for (UnresolvedSetIterator I = VBaseCs.begin(), E = VBaseCs.end();
   1614  1.1  joerg          I != E; ++I) {
   1615  1.1  joerg     if (!HiddenVBaseCs.count(cast<NamedDecl>(I.getDecl()->getCanonicalDecl())))
   1616  1.1  joerg       Output.addDecl(Context, I.getDecl(), I.getAccess());
   1617  1.1  joerg   }
   1618  1.1  joerg }
   1619  1.1  joerg 
   1620  1.1  joerg /// getVisibleConversionFunctions - get all conversion functions visible
   1621  1.1  joerg /// in current class; including conversion function templates.
   1622  1.1  joerg llvm::iterator_range<CXXRecordDecl::conversion_iterator>
   1623  1.1  joerg CXXRecordDecl::getVisibleConversionFunctions() {
   1624  1.1  joerg   ASTContext &Ctx = getASTContext();
   1625  1.1  joerg 
   1626  1.1  joerg   ASTUnresolvedSet *Set;
   1627  1.1  joerg   if (bases_begin() == bases_end()) {
   1628  1.1  joerg     // If root class, all conversions are visible.
   1629  1.1  joerg     Set = &data().Conversions.get(Ctx);
   1630  1.1  joerg   } else {
   1631  1.1  joerg     Set = &data().VisibleConversions.get(Ctx);
   1632  1.1  joerg     // If visible conversion list is not evaluated, evaluate it.
   1633  1.1  joerg     if (!data().ComputedVisibleConversions) {
   1634  1.1  joerg       CollectVisibleConversions(Ctx, this, *Set);
   1635  1.1  joerg       data().ComputedVisibleConversions = true;
   1636  1.1  joerg     }
   1637  1.1  joerg   }
   1638  1.1  joerg   return llvm::make_range(Set->begin(), Set->end());
   1639  1.1  joerg }
   1640  1.1  joerg 
   1641  1.1  joerg void CXXRecordDecl::removeConversion(const NamedDecl *ConvDecl) {
   1642  1.1  joerg   // This operation is O(N) but extremely rare.  Sema only uses it to
   1643  1.1  joerg   // remove UsingShadowDecls in a class that were followed by a direct
   1644  1.1  joerg   // declaration, e.g.:
   1645  1.1  joerg   //   class A : B {
   1646  1.1  joerg   //     using B::operator int;
   1647  1.1  joerg   //     operator int();
   1648  1.1  joerg   //   };
   1649  1.1  joerg   // This is uncommon by itself and even more uncommon in conjunction
   1650  1.1  joerg   // with sufficiently large numbers of directly-declared conversions
   1651  1.1  joerg   // that asymptotic behavior matters.
   1652  1.1  joerg 
   1653  1.1  joerg   ASTUnresolvedSet &Convs = data().Conversions.get(getASTContext());
   1654  1.1  joerg   for (unsigned I = 0, E = Convs.size(); I != E; ++I) {
   1655  1.1  joerg     if (Convs[I].getDecl() == ConvDecl) {
   1656  1.1  joerg       Convs.erase(I);
   1657  1.1  joerg       assert(llvm::find(Convs, ConvDecl) == Convs.end() &&
   1658  1.1  joerg              "conversion was found multiple times in unresolved set");
   1659  1.1  joerg       return;
   1660  1.1  joerg     }
   1661  1.1  joerg   }
   1662  1.1  joerg 
   1663  1.1  joerg   llvm_unreachable("conversion not found in set!");
   1664  1.1  joerg }
   1665  1.1  joerg 
   1666  1.1  joerg CXXRecordDecl *CXXRecordDecl::getInstantiatedFromMemberClass() const {
   1667  1.1  joerg   if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo())
   1668  1.1  joerg     return cast<CXXRecordDecl>(MSInfo->getInstantiatedFrom());
   1669  1.1  joerg 
   1670  1.1  joerg   return nullptr;
   1671  1.1  joerg }
   1672  1.1  joerg 
   1673  1.1  joerg MemberSpecializationInfo *CXXRecordDecl::getMemberSpecializationInfo() const {
   1674  1.1  joerg   return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>();
   1675  1.1  joerg }
   1676  1.1  joerg 
   1677  1.1  joerg void
   1678  1.1  joerg CXXRecordDecl::setInstantiationOfMemberClass(CXXRecordDecl *RD,
   1679  1.1  joerg                                              TemplateSpecializationKind TSK) {
   1680  1.1  joerg   assert(TemplateOrInstantiation.isNull() &&
   1681  1.1  joerg          "Previous template or instantiation?");
   1682  1.1  joerg   assert(!isa<ClassTemplatePartialSpecializationDecl>(this));
   1683  1.1  joerg   TemplateOrInstantiation
   1684  1.1  joerg     = new (getASTContext()) MemberSpecializationInfo(RD, TSK);
   1685  1.1  joerg }
   1686  1.1  joerg 
   1687  1.1  joerg ClassTemplateDecl *CXXRecordDecl::getDescribedClassTemplate() const {
   1688  1.1  joerg   return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl *>();
   1689  1.1  joerg }
   1690  1.1  joerg 
   1691  1.1  joerg void CXXRecordDecl::setDescribedClassTemplate(ClassTemplateDecl *Template) {
   1692  1.1  joerg   TemplateOrInstantiation = Template;
   1693  1.1  joerg }
   1694  1.1  joerg 
   1695  1.1  joerg TemplateSpecializationKind CXXRecordDecl::getTemplateSpecializationKind() const{
   1696  1.1  joerg   if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(this))
   1697  1.1  joerg     return Spec->getSpecializationKind();
   1698  1.1  joerg 
   1699  1.1  joerg   if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo())
   1700  1.1  joerg     return MSInfo->getTemplateSpecializationKind();
   1701  1.1  joerg 
   1702  1.1  joerg   return TSK_Undeclared;
   1703  1.1  joerg }
   1704  1.1  joerg 
   1705  1.1  joerg void
   1706  1.1  joerg CXXRecordDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK) {
   1707  1.1  joerg   if (auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(this)) {
   1708  1.1  joerg     Spec->setSpecializationKind(TSK);
   1709  1.1  joerg     return;
   1710  1.1  joerg   }
   1711  1.1  joerg 
   1712  1.1  joerg   if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) {
   1713  1.1  joerg     MSInfo->setTemplateSpecializationKind(TSK);
   1714  1.1  joerg     return;
   1715  1.1  joerg   }
   1716  1.1  joerg 
   1717  1.1  joerg   llvm_unreachable("Not a class template or member class specialization");
   1718  1.1  joerg }
   1719  1.1  joerg 
   1720  1.1  joerg const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const {
   1721  1.1  joerg   auto GetDefinitionOrSelf =
   1722  1.1  joerg       [](const CXXRecordDecl *D) -> const CXXRecordDecl * {
   1723  1.1  joerg     if (auto *Def = D->getDefinition())
   1724  1.1  joerg       return Def;
   1725  1.1  joerg     return D;
   1726  1.1  joerg   };
   1727  1.1  joerg 
   1728  1.1  joerg   // If it's a class template specialization, find the template or partial
   1729  1.1  joerg   // specialization from which it was instantiated.
   1730  1.1  joerg   if (auto *TD = dyn_cast<ClassTemplateSpecializationDecl>(this)) {
   1731  1.1  joerg     auto From = TD->getInstantiatedFrom();
   1732  1.1  joerg     if (auto *CTD = From.dyn_cast<ClassTemplateDecl *>()) {
   1733  1.1  joerg       while (auto *NewCTD = CTD->getInstantiatedFromMemberTemplate()) {
   1734  1.1  joerg         if (NewCTD->isMemberSpecialization())
   1735  1.1  joerg           break;
   1736  1.1  joerg         CTD = NewCTD;
   1737  1.1  joerg       }
   1738  1.1  joerg       return GetDefinitionOrSelf(CTD->getTemplatedDecl());
   1739  1.1  joerg     }
   1740  1.1  joerg     if (auto *CTPSD =
   1741  1.1  joerg             From.dyn_cast<ClassTemplatePartialSpecializationDecl *>()) {
   1742  1.1  joerg       while (auto *NewCTPSD = CTPSD->getInstantiatedFromMember()) {
   1743  1.1  joerg         if (NewCTPSD->isMemberSpecialization())
   1744  1.1  joerg           break;
   1745  1.1  joerg         CTPSD = NewCTPSD;
   1746  1.1  joerg       }
   1747  1.1  joerg       return GetDefinitionOrSelf(CTPSD);
   1748  1.1  joerg     }
   1749  1.1  joerg   }
   1750  1.1  joerg 
   1751  1.1  joerg   if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) {
   1752  1.1  joerg     if (isTemplateInstantiation(MSInfo->getTemplateSpecializationKind())) {
   1753  1.1  joerg       const CXXRecordDecl *RD = this;
   1754  1.1  joerg       while (auto *NewRD = RD->getInstantiatedFromMemberClass())
   1755  1.1  joerg         RD = NewRD;
   1756  1.1  joerg       return GetDefinitionOrSelf(RD);
   1757  1.1  joerg     }
   1758  1.1  joerg   }
   1759  1.1  joerg 
   1760  1.1  joerg   assert(!isTemplateInstantiation(this->getTemplateSpecializationKind()) &&
   1761  1.1  joerg          "couldn't find pattern for class template instantiation");
   1762  1.1  joerg   return nullptr;
   1763  1.1  joerg }
   1764  1.1  joerg 
   1765  1.1  joerg CXXDestructorDecl *CXXRecordDecl::getDestructor() const {
   1766  1.1  joerg   ASTContext &Context = getASTContext();
   1767  1.1  joerg   QualType ClassType = Context.getTypeDeclType(this);
   1768  1.1  joerg 
   1769  1.1  joerg   DeclarationName Name
   1770  1.1  joerg     = Context.DeclarationNames.getCXXDestructorName(
   1771  1.1  joerg                                           Context.getCanonicalType(ClassType));
   1772  1.1  joerg 
   1773  1.1  joerg   DeclContext::lookup_result R = lookup(Name);
   1774  1.1  joerg 
   1775  1.1  joerg   return R.empty() ? nullptr : dyn_cast<CXXDestructorDecl>(R.front());
   1776  1.1  joerg }
   1777  1.1  joerg 
   1778  1.1  joerg bool CXXRecordDecl::isAnyDestructorNoReturn() const {
   1779  1.1  joerg   // Destructor is noreturn.
   1780  1.1  joerg   if (const CXXDestructorDecl *Destructor = getDestructor())
   1781  1.1  joerg     if (Destructor->isNoReturn())
   1782  1.1  joerg       return true;
   1783  1.1  joerg 
   1784  1.1  joerg   // Check base classes destructor for noreturn.
   1785  1.1  joerg   for (const auto &Base : bases())
   1786  1.1  joerg     if (const CXXRecordDecl *RD = Base.getType()->getAsCXXRecordDecl())
   1787  1.1  joerg       if (RD->isAnyDestructorNoReturn())
   1788  1.1  joerg         return true;
   1789  1.1  joerg 
   1790  1.1  joerg   // Check fields for noreturn.
   1791  1.1  joerg   for (const auto *Field : fields())
   1792  1.1  joerg     if (const CXXRecordDecl *RD =
   1793  1.1  joerg             Field->getType()->getBaseElementTypeUnsafe()->getAsCXXRecordDecl())
   1794  1.1  joerg       if (RD->isAnyDestructorNoReturn())
   1795  1.1  joerg         return true;
   1796  1.1  joerg 
   1797  1.1  joerg   // All destructors are not noreturn.
   1798  1.1  joerg   return false;
   1799  1.1  joerg }
   1800  1.1  joerg 
   1801  1.1  joerg static bool isDeclContextInNamespace(const DeclContext *DC) {
   1802  1.1  joerg   while (!DC->isTranslationUnit()) {
   1803  1.1  joerg     if (DC->isNamespace())
   1804  1.1  joerg       return true;
   1805  1.1  joerg     DC = DC->getParent();
   1806  1.1  joerg   }
   1807  1.1  joerg   return false;
   1808  1.1  joerg }
   1809  1.1  joerg 
   1810  1.1  joerg bool CXXRecordDecl::isInterfaceLike() const {
   1811  1.1  joerg   assert(hasDefinition() && "checking for interface-like without a definition");
   1812  1.1  joerg   // All __interfaces are inheritently interface-like.
   1813  1.1  joerg   if (isInterface())
   1814  1.1  joerg     return true;
   1815  1.1  joerg 
   1816  1.1  joerg   // Interface-like types cannot have a user declared constructor, destructor,
   1817  1.1  joerg   // friends, VBases, conversion functions, or fields.  Additionally, lambdas
   1818  1.1  joerg   // cannot be interface types.
   1819  1.1  joerg   if (isLambda() || hasUserDeclaredConstructor() ||
   1820  1.1  joerg       hasUserDeclaredDestructor() || !field_empty() || hasFriends() ||
   1821  1.1  joerg       getNumVBases() > 0 || conversion_end() - conversion_begin() > 0)
   1822  1.1  joerg     return false;
   1823  1.1  joerg 
   1824  1.1  joerg   // No interface-like type can have a method with a definition.
   1825  1.1  joerg   for (const auto *const Method : methods())
   1826  1.1  joerg     if (Method->isDefined() && !Method->isImplicit())
   1827  1.1  joerg       return false;
   1828  1.1  joerg 
   1829  1.1  joerg   // Check "Special" types.
   1830  1.1  joerg   const auto *Uuid = getAttr<UuidAttr>();
   1831  1.1  joerg   // MS SDK declares IUnknown/IDispatch both in the root of a TU, or in an
   1832  1.1  joerg   // extern C++ block directly in the TU.  These are only valid if in one
   1833  1.1  joerg   // of these two situations.
   1834  1.1  joerg   if (Uuid && isStruct() && !getDeclContext()->isExternCContext() &&
   1835  1.1  joerg       !isDeclContextInNamespace(getDeclContext()) &&
   1836  1.1  joerg       ((getName() == "IUnknown" &&
   1837  1.1  joerg         Uuid->getGuid() == "00000000-0000-0000-C000-000000000046") ||
   1838  1.1  joerg        (getName() == "IDispatch" &&
   1839  1.1  joerg         Uuid->getGuid() == "00020400-0000-0000-C000-000000000046"))) {
   1840  1.1  joerg     if (getNumBases() > 0)
   1841  1.1  joerg       return false;
   1842  1.1  joerg     return true;
   1843  1.1  joerg   }
   1844  1.1  joerg 
   1845  1.1  joerg   // FIXME: Any access specifiers is supposed to make this no longer interface
   1846  1.1  joerg   // like.
   1847  1.1  joerg 
   1848  1.1  joerg   // If this isn't a 'special' type, it must have a single interface-like base.
   1849  1.1  joerg   if (getNumBases() != 1)
   1850  1.1  joerg     return false;
   1851  1.1  joerg 
   1852  1.1  joerg   const auto BaseSpec = *bases_begin();
   1853  1.1  joerg   if (BaseSpec.isVirtual() || BaseSpec.getAccessSpecifier() != AS_public)
   1854  1.1  joerg     return false;
   1855  1.1  joerg   const auto *Base = BaseSpec.getType()->getAsCXXRecordDecl();
   1856  1.1  joerg   if (Base->isInterface() || !Base->isInterfaceLike())
   1857  1.1  joerg     return false;
   1858  1.1  joerg   return true;
   1859  1.1  joerg }
   1860  1.1  joerg 
   1861  1.1  joerg void CXXRecordDecl::completeDefinition() {
   1862  1.1  joerg   completeDefinition(nullptr);
   1863  1.1  joerg }
   1864  1.1  joerg 
   1865  1.1  joerg void CXXRecordDecl::completeDefinition(CXXFinalOverriderMap *FinalOverriders) {
   1866  1.1  joerg   RecordDecl::completeDefinition();
   1867  1.1  joerg 
   1868  1.1  joerg   // If the class may be abstract (but hasn't been marked as such), check for
   1869  1.1  joerg   // any pure final overriders.
   1870  1.1  joerg   if (mayBeAbstract()) {
   1871  1.1  joerg     CXXFinalOverriderMap MyFinalOverriders;
   1872  1.1  joerg     if (!FinalOverriders) {
   1873  1.1  joerg       getFinalOverriders(MyFinalOverriders);
   1874  1.1  joerg       FinalOverriders = &MyFinalOverriders;
   1875  1.1  joerg     }
   1876  1.1  joerg 
   1877  1.1  joerg     bool Done = false;
   1878  1.1  joerg     for (CXXFinalOverriderMap::iterator M = FinalOverriders->begin(),
   1879  1.1  joerg                                      MEnd = FinalOverriders->end();
   1880  1.1  joerg          M != MEnd && !Done; ++M) {
   1881  1.1  joerg       for (OverridingMethods::iterator SO = M->second.begin(),
   1882  1.1  joerg                                     SOEnd = M->second.end();
   1883  1.1  joerg            SO != SOEnd && !Done; ++SO) {
   1884  1.1  joerg         assert(SO->second.size() > 0 &&
   1885  1.1  joerg                "All virtual functions have overriding virtual functions");
   1886  1.1  joerg 
   1887  1.1  joerg         // C++ [class.abstract]p4:
   1888  1.1  joerg         //   A class is abstract if it contains or inherits at least one
   1889  1.1  joerg         //   pure virtual function for which the final overrider is pure
   1890  1.1  joerg         //   virtual.
   1891  1.1  joerg         if (SO->second.front().Method->isPure()) {
   1892  1.1  joerg           data().Abstract = true;
   1893  1.1  joerg           Done = true;
   1894  1.1  joerg           break;
   1895  1.1  joerg         }
   1896  1.1  joerg       }
   1897  1.1  joerg     }
   1898  1.1  joerg   }
   1899  1.1  joerg 
   1900  1.1  joerg   // Set access bits correctly on the directly-declared conversions.
   1901  1.1  joerg   for (conversion_iterator I = conversion_begin(), E = conversion_end();
   1902  1.1  joerg        I != E; ++I)
   1903  1.1  joerg     I.setAccess((*I)->getAccess());
   1904  1.1  joerg }
   1905  1.1  joerg 
   1906  1.1  joerg bool CXXRecordDecl::mayBeAbstract() const {
   1907  1.1  joerg   if (data().Abstract || isInvalidDecl() || !data().Polymorphic ||
   1908  1.1  joerg       isDependentContext())
   1909  1.1  joerg     return false;
   1910  1.1  joerg 
   1911  1.1  joerg   for (const auto &B : bases()) {
   1912  1.1  joerg     const auto *BaseDecl =
   1913  1.1  joerg         cast<CXXRecordDecl>(B.getType()->castAs<RecordType>()->getDecl());
   1914  1.1  joerg     if (BaseDecl->isAbstract())
   1915  1.1  joerg       return true;
   1916  1.1  joerg   }
   1917  1.1  joerg 
   1918  1.1  joerg   return false;
   1919  1.1  joerg }
   1920  1.1  joerg 
   1921  1.1  joerg void CXXDeductionGuideDecl::anchor() {}
   1922  1.1  joerg 
   1923  1.1  joerg bool ExplicitSpecifier::isEquivalent(const ExplicitSpecifier Other) const {
   1924  1.1  joerg   if ((getKind() != Other.getKind() ||
   1925  1.1  joerg        getKind() == ExplicitSpecKind::Unresolved)) {
   1926  1.1  joerg     if (getKind() == ExplicitSpecKind::Unresolved &&
   1927  1.1  joerg         Other.getKind() == ExplicitSpecKind::Unresolved) {
   1928  1.1  joerg       ODRHash SelfHash, OtherHash;
   1929  1.1  joerg       SelfHash.AddStmt(getExpr());
   1930  1.1  joerg       OtherHash.AddStmt(Other.getExpr());
   1931  1.1  joerg       return SelfHash.CalculateHash() == OtherHash.CalculateHash();
   1932  1.1  joerg     } else
   1933  1.1  joerg       return false;
   1934  1.1  joerg   }
   1935  1.1  joerg   return true;
   1936  1.1  joerg }
   1937  1.1  joerg 
   1938  1.1  joerg ExplicitSpecifier ExplicitSpecifier::getFromDecl(FunctionDecl *Function) {
   1939  1.1  joerg   switch (Function->getDeclKind()) {
   1940  1.1  joerg   case Decl::Kind::CXXConstructor:
   1941  1.1  joerg     return cast<CXXConstructorDecl>(Function)->getExplicitSpecifier();
   1942  1.1  joerg   case Decl::Kind::CXXConversion:
   1943  1.1  joerg     return cast<CXXConversionDecl>(Function)->getExplicitSpecifier();
   1944  1.1  joerg   case Decl::Kind::CXXDeductionGuide:
   1945  1.1  joerg     return cast<CXXDeductionGuideDecl>(Function)->getExplicitSpecifier();
   1946  1.1  joerg   default:
   1947  1.1  joerg     return {};
   1948  1.1  joerg   }
   1949  1.1  joerg }
   1950  1.1  joerg 
   1951  1.1  joerg CXXDeductionGuideDecl *CXXDeductionGuideDecl::Create(
   1952  1.1  joerg     ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
   1953  1.1  joerg     ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T,
   1954  1.1  joerg     TypeSourceInfo *TInfo, SourceLocation EndLocation) {
   1955  1.1  joerg   return new (C, DC) CXXDeductionGuideDecl(C, DC, StartLoc, ES, NameInfo, T,
   1956  1.1  joerg                                            TInfo, EndLocation);
   1957  1.1  joerg }
   1958  1.1  joerg 
   1959  1.1  joerg CXXDeductionGuideDecl *CXXDeductionGuideDecl::CreateDeserialized(ASTContext &C,
   1960  1.1  joerg                                                                  unsigned ID) {
   1961  1.1  joerg   return new (C, ID) CXXDeductionGuideDecl(
   1962  1.1  joerg       C, nullptr, SourceLocation(), ExplicitSpecifier(), DeclarationNameInfo(),
   1963  1.1  joerg       QualType(), nullptr, SourceLocation());
   1964  1.1  joerg }
   1965  1.1  joerg 
   1966  1.1  joerg void CXXMethodDecl::anchor() {}
   1967  1.1  joerg 
   1968  1.1  joerg bool CXXMethodDecl::isStatic() const {
   1969  1.1  joerg   const CXXMethodDecl *MD = getCanonicalDecl();
   1970  1.1  joerg 
   1971  1.1  joerg   if (MD->getStorageClass() == SC_Static)
   1972  1.1  joerg     return true;
   1973  1.1  joerg 
   1974  1.1  joerg   OverloadedOperatorKind OOK = getDeclName().getCXXOverloadedOperator();
   1975  1.1  joerg   return isStaticOverloadedOperator(OOK);
   1976  1.1  joerg }
   1977  1.1  joerg 
   1978  1.1  joerg static bool recursivelyOverrides(const CXXMethodDecl *DerivedMD,
   1979  1.1  joerg                                  const CXXMethodDecl *BaseMD) {
   1980  1.1  joerg   for (const CXXMethodDecl *MD : DerivedMD->overridden_methods()) {
   1981  1.1  joerg     if (MD->getCanonicalDecl() == BaseMD->getCanonicalDecl())
   1982  1.1  joerg       return true;
   1983  1.1  joerg     if (recursivelyOverrides(MD, BaseMD))
   1984  1.1  joerg       return true;
   1985  1.1  joerg   }
   1986  1.1  joerg   return false;
   1987  1.1  joerg }
   1988  1.1  joerg 
   1989  1.1  joerg CXXMethodDecl *
   1990  1.1  joerg CXXMethodDecl::getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD,
   1991  1.1  joerg                                                      bool MayBeBase) {
   1992  1.1  joerg   if (this->getParent()->getCanonicalDecl() == RD->getCanonicalDecl())
   1993  1.1  joerg     return this;
   1994  1.1  joerg 
   1995  1.1  joerg   // Lookup doesn't work for destructors, so handle them separately.
   1996  1.1  joerg   if (isa<CXXDestructorDecl>(this)) {
   1997  1.1  joerg     CXXMethodDecl *MD = RD->getDestructor();
   1998  1.1  joerg     if (MD) {
   1999  1.1  joerg       if (recursivelyOverrides(MD, this))
   2000  1.1  joerg         return MD;
   2001  1.1  joerg       if (MayBeBase && recursivelyOverrides(this, MD))
   2002  1.1  joerg         return MD;
   2003  1.1  joerg     }
   2004  1.1  joerg     return nullptr;
   2005  1.1  joerg   }
   2006  1.1  joerg 
   2007  1.1  joerg   for (auto *ND : RD->lookup(getDeclName())) {
   2008  1.1  joerg     auto *MD = dyn_cast<CXXMethodDecl>(ND);
   2009  1.1  joerg     if (!MD)
   2010  1.1  joerg       continue;
   2011  1.1  joerg     if (recursivelyOverrides(MD, this))
   2012  1.1  joerg       return MD;
   2013  1.1  joerg     if (MayBeBase && recursivelyOverrides(this, MD))
   2014  1.1  joerg       return MD;
   2015  1.1  joerg   }
   2016  1.1  joerg 
   2017  1.1  joerg   return nullptr;
   2018  1.1  joerg }
   2019  1.1  joerg 
   2020  1.1  joerg CXXMethodDecl *
   2021  1.1  joerg CXXMethodDecl::getCorrespondingMethodInClass(const CXXRecordDecl *RD,
   2022  1.1  joerg                                              bool MayBeBase) {
   2023  1.1  joerg   if (auto *MD = getCorrespondingMethodDeclaredInClass(RD, MayBeBase))
   2024  1.1  joerg     return MD;
   2025  1.1  joerg 
   2026  1.1  joerg   for (const auto &I : RD->bases()) {
   2027  1.1  joerg     const RecordType *RT = I.getType()->getAs<RecordType>();
   2028  1.1  joerg     if (!RT)
   2029  1.1  joerg       continue;
   2030  1.1  joerg     const auto *Base = cast<CXXRecordDecl>(RT->getDecl());
   2031  1.1  joerg     CXXMethodDecl *T = this->getCorrespondingMethodInClass(Base);
   2032  1.1  joerg     if (T)
   2033  1.1  joerg       return T;
   2034  1.1  joerg   }
   2035  1.1  joerg 
   2036  1.1  joerg   return nullptr;
   2037  1.1  joerg }
   2038  1.1  joerg 
   2039  1.1  joerg CXXMethodDecl *CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD,
   2040  1.1  joerg                                      SourceLocation StartLoc,
   2041  1.1  joerg                                      const DeclarationNameInfo &NameInfo,
   2042  1.1  joerg                                      QualType T, TypeSourceInfo *TInfo,
   2043  1.1  joerg                                      StorageClass SC, bool isInline,
   2044  1.1  joerg                                      ConstexprSpecKind ConstexprKind,
   2045  1.1  joerg                                      SourceLocation EndLocation) {
   2046  1.1  joerg   return new (C, RD)
   2047  1.1  joerg       CXXMethodDecl(CXXMethod, C, RD, StartLoc, NameInfo, T, TInfo, SC,
   2048  1.1  joerg                     isInline, ConstexprKind, EndLocation);
   2049  1.1  joerg }
   2050  1.1  joerg 
   2051  1.1  joerg CXXMethodDecl *CXXMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
   2052  1.1  joerg   return new (C, ID) CXXMethodDecl(
   2053  1.1  joerg       CXXMethod, C, nullptr, SourceLocation(), DeclarationNameInfo(),
   2054  1.1  joerg       QualType(), nullptr, SC_None, false, CSK_unspecified, SourceLocation());
   2055  1.1  joerg }
   2056  1.1  joerg 
   2057  1.1  joerg CXXMethodDecl *CXXMethodDecl::getDevirtualizedMethod(const Expr *Base,
   2058  1.1  joerg                                                      bool IsAppleKext) {
   2059  1.1  joerg   assert(isVirtual() && "this method is expected to be virtual");
   2060  1.1  joerg 
   2061  1.1  joerg   // When building with -fapple-kext, all calls must go through the vtable since
   2062  1.1  joerg   // the kernel linker can do runtime patching of vtables.
   2063  1.1  joerg   if (IsAppleKext)
   2064  1.1  joerg     return nullptr;
   2065  1.1  joerg 
   2066  1.1  joerg   // If the member function is marked 'final', we know that it can't be
   2067  1.1  joerg   // overridden and can therefore devirtualize it unless it's pure virtual.
   2068  1.1  joerg   if (hasAttr<FinalAttr>())
   2069  1.1  joerg     return isPure() ? nullptr : this;
   2070  1.1  joerg 
   2071  1.1  joerg   // If Base is unknown, we cannot devirtualize.
   2072  1.1  joerg   if (!Base)
   2073  1.1  joerg     return nullptr;
   2074  1.1  joerg 
   2075  1.1  joerg   // If the base expression (after skipping derived-to-base conversions) is a
   2076  1.1  joerg   // class prvalue, then we can devirtualize.
   2077  1.1  joerg   Base = Base->getBestDynamicClassTypeExpr();
   2078  1.1  joerg   if (Base->isRValue() && Base->getType()->isRecordType())
   2079  1.1  joerg     return this;
   2080  1.1  joerg 
   2081  1.1  joerg   // If we don't even know what we would call, we can't devirtualize.
   2082  1.1  joerg   const CXXRecordDecl *BestDynamicDecl = Base->getBestDynamicClassType();
   2083  1.1  joerg   if (!BestDynamicDecl)
   2084  1.1  joerg     return nullptr;
   2085  1.1  joerg 
   2086  1.1  joerg   // There may be a method corresponding to MD in a derived class.
   2087  1.1  joerg   CXXMethodDecl *DevirtualizedMethod =
   2088  1.1  joerg       getCorrespondingMethodInClass(BestDynamicDecl);
   2089  1.1  joerg 
   2090  1.1  joerg   // If that method is pure virtual, we can't devirtualize. If this code is
   2091  1.1  joerg   // reached, the result would be UB, not a direct call to the derived class
   2092  1.1  joerg   // function, and we can't assume the derived class function is defined.
   2093  1.1  joerg   if (DevirtualizedMethod->isPure())
   2094  1.1  joerg     return nullptr;
   2095  1.1  joerg 
   2096  1.1  joerg   // If that method is marked final, we can devirtualize it.
   2097  1.1  joerg   if (DevirtualizedMethod->hasAttr<FinalAttr>())
   2098  1.1  joerg     return DevirtualizedMethod;
   2099  1.1  joerg 
   2100  1.1  joerg   // Similarly, if the class itself or its destructor is marked 'final',
   2101  1.1  joerg   // the class can't be derived from and we can therefore devirtualize the
   2102  1.1  joerg   // member function call.
   2103  1.1  joerg   if (BestDynamicDecl->hasAttr<FinalAttr>())
   2104  1.1  joerg     return DevirtualizedMethod;
   2105  1.1  joerg   if (const auto *dtor = BestDynamicDecl->getDestructor()) {
   2106  1.1  joerg     if (dtor->hasAttr<FinalAttr>())
   2107  1.1  joerg       return DevirtualizedMethod;
   2108  1.1  joerg   }
   2109  1.1  joerg 
   2110  1.1  joerg   if (const auto *DRE = dyn_cast<DeclRefExpr>(Base)) {
   2111  1.1  joerg     if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl()))
   2112  1.1  joerg       if (VD->getType()->isRecordType())
   2113  1.1  joerg         // This is a record decl. We know the type and can devirtualize it.
   2114  1.1  joerg         return DevirtualizedMethod;
   2115  1.1  joerg 
   2116  1.1  joerg     return nullptr;
   2117  1.1  joerg   }
   2118  1.1  joerg 
   2119  1.1  joerg   // We can devirtualize calls on an object accessed by a class member access
   2120  1.1  joerg   // expression, since by C++11 [basic.life]p6 we know that it can't refer to
   2121  1.1  joerg   // a derived class object constructed in the same location.
   2122  1.1  joerg   if (const auto *ME = dyn_cast<MemberExpr>(Base)) {
   2123  1.1  joerg     const ValueDecl *VD = ME->getMemberDecl();
   2124  1.1  joerg     return VD->getType()->isRecordType() ? DevirtualizedMethod : nullptr;
   2125  1.1  joerg   }
   2126  1.1  joerg 
   2127  1.1  joerg   // Likewise for calls on an object accessed by a (non-reference) pointer to
   2128  1.1  joerg   // member access.
   2129  1.1  joerg   if (auto *BO = dyn_cast<BinaryOperator>(Base)) {
   2130  1.1  joerg     if (BO->isPtrMemOp()) {
   2131  1.1  joerg       auto *MPT = BO->getRHS()->getType()->castAs<MemberPointerType>();
   2132  1.1  joerg       if (MPT->getPointeeType()->isRecordType())
   2133  1.1  joerg         return DevirtualizedMethod;
   2134  1.1  joerg     }
   2135  1.1  joerg   }
   2136  1.1  joerg 
   2137  1.1  joerg   // We can't devirtualize the call.
   2138  1.1  joerg   return nullptr;
   2139  1.1  joerg }
   2140  1.1  joerg 
   2141  1.1  joerg bool CXXMethodDecl::isUsualDeallocationFunction(
   2142  1.1  joerg     SmallVectorImpl<const FunctionDecl *> &PreventedBy) const {
   2143  1.1  joerg   assert(PreventedBy.empty() && "PreventedBy is expected to be empty");
   2144  1.1  joerg   if (getOverloadedOperator() != OO_Delete &&
   2145  1.1  joerg       getOverloadedOperator() != OO_Array_Delete)
   2146  1.1  joerg     return false;
   2147  1.1  joerg 
   2148  1.1  joerg   // C++ [basic.stc.dynamic.deallocation]p2:
   2149  1.1  joerg   //   A template instance is never a usual deallocation function,
   2150  1.1  joerg   //   regardless of its signature.
   2151  1.1  joerg   if (getPrimaryTemplate())
   2152  1.1  joerg     return false;
   2153  1.1  joerg 
   2154  1.1  joerg   // C++ [basic.stc.dynamic.deallocation]p2:
   2155  1.1  joerg   //   If a class T has a member deallocation function named operator delete
   2156  1.1  joerg   //   with exactly one parameter, then that function is a usual (non-placement)
   2157  1.1  joerg   //   deallocation function. [...]
   2158  1.1  joerg   if (getNumParams() == 1)
   2159  1.1  joerg     return true;
   2160  1.1  joerg   unsigned UsualParams = 1;
   2161  1.1  joerg 
   2162  1.1  joerg   // C++ P0722:
   2163  1.1  joerg   //   A destroying operator delete is a usual deallocation function if
   2164  1.1  joerg   //   removing the std::destroying_delete_t parameter and changing the
   2165  1.1  joerg   //   first parameter type from T* to void* results in the signature of
   2166  1.1  joerg   //   a usual deallocation function.
   2167  1.1  joerg   if (isDestroyingOperatorDelete())
   2168  1.1  joerg     ++UsualParams;
   2169  1.1  joerg 
   2170  1.1  joerg   // C++ <=14 [basic.stc.dynamic.deallocation]p2:
   2171  1.1  joerg   //   [...] If class T does not declare such an operator delete but does
   2172  1.1  joerg   //   declare a member deallocation function named operator delete with
   2173  1.1  joerg   //   exactly two parameters, the second of which has type std::size_t (18.1),
   2174  1.1  joerg   //   then this function is a usual deallocation function.
   2175  1.1  joerg   //
   2176  1.1  joerg   // C++17 says a usual deallocation function is one with the signature
   2177  1.1  joerg   //   (void* [, size_t] [, std::align_val_t] [, ...])
   2178  1.1  joerg   // and all such functions are usual deallocation functions. It's not clear
   2179  1.1  joerg   // that allowing varargs functions was intentional.
   2180  1.1  joerg   ASTContext &Context = getASTContext();
   2181  1.1  joerg   if (UsualParams < getNumParams() &&
   2182  1.1  joerg       Context.hasSameUnqualifiedType(getParamDecl(UsualParams)->getType(),
   2183  1.1  joerg                                      Context.getSizeType()))
   2184  1.1  joerg     ++UsualParams;
   2185  1.1  joerg 
   2186  1.1  joerg   if (UsualParams < getNumParams() &&
   2187  1.1  joerg       getParamDecl(UsualParams)->getType()->isAlignValT())
   2188  1.1  joerg     ++UsualParams;
   2189  1.1  joerg 
   2190  1.1  joerg   if (UsualParams != getNumParams())
   2191  1.1  joerg     return false;
   2192  1.1  joerg 
   2193  1.1  joerg   // In C++17 onwards, all potential usual deallocation functions are actual
   2194  1.1  joerg   // usual deallocation functions. Honor this behavior when post-C++14
   2195  1.1  joerg   // deallocation functions are offered as extensions too.
   2196  1.1  joerg   // FIXME(EricWF): Destrying Delete should be a language option. How do we
   2197  1.1  joerg   // handle when destroying delete is used prior to C++17?
   2198  1.1  joerg   if (Context.getLangOpts().CPlusPlus17 ||
   2199  1.1  joerg       Context.getLangOpts().AlignedAllocation ||
   2200  1.1  joerg       isDestroyingOperatorDelete())
   2201  1.1  joerg     return true;
   2202  1.1  joerg 
   2203  1.1  joerg   // This function is a usual deallocation function if there are no
   2204  1.1  joerg   // single-parameter deallocation functions of the same kind.
   2205  1.1  joerg   DeclContext::lookup_result R = getDeclContext()->lookup(getDeclName());
   2206  1.1  joerg   bool Result = true;
   2207  1.1  joerg   for (const auto *D : R) {
   2208  1.1  joerg     if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
   2209  1.1  joerg       if (FD->getNumParams() == 1) {
   2210  1.1  joerg         PreventedBy.push_back(FD);
   2211  1.1  joerg         Result = false;
   2212  1.1  joerg       }
   2213  1.1  joerg     }
   2214  1.1  joerg   }
   2215  1.1  joerg   return Result;
   2216  1.1  joerg }
   2217  1.1  joerg 
   2218  1.1  joerg bool CXXMethodDecl::isCopyAssignmentOperator() const {
   2219  1.1  joerg   // C++0x [class.copy]p17:
   2220  1.1  joerg   //  A user-declared copy assignment operator X::operator= is a non-static
   2221  1.1  joerg   //  non-template member function of class X with exactly one parameter of
   2222  1.1  joerg   //  type X, X&, const X&, volatile X& or const volatile X&.
   2223  1.1  joerg   if (/*operator=*/getOverloadedOperator() != OO_Equal ||
   2224  1.1  joerg       /*non-static*/ isStatic() ||
   2225  1.1  joerg       /*non-template*/getPrimaryTemplate() || getDescribedFunctionTemplate() ||
   2226  1.1  joerg       getNumParams() != 1)
   2227  1.1  joerg     return false;
   2228  1.1  joerg 
   2229  1.1  joerg   QualType ParamType = getParamDecl(0)->getType();
   2230  1.1  joerg   if (const auto *Ref = ParamType->getAs<LValueReferenceType>())
   2231  1.1  joerg     ParamType = Ref->getPointeeType();
   2232  1.1  joerg 
   2233  1.1  joerg   ASTContext &Context = getASTContext();
   2234  1.1  joerg   QualType ClassType
   2235  1.1  joerg     = Context.getCanonicalType(Context.getTypeDeclType(getParent()));
   2236  1.1  joerg   return Context.hasSameUnqualifiedType(ClassType, ParamType);
   2237  1.1  joerg }
   2238  1.1  joerg 
   2239  1.1  joerg bool CXXMethodDecl::isMoveAssignmentOperator() const {
   2240  1.1  joerg   // C++0x [class.copy]p19:
   2241  1.1  joerg   //  A user-declared move assignment operator X::operator= is a non-static
   2242  1.1  joerg   //  non-template member function of class X with exactly one parameter of type
   2243  1.1  joerg   //  X&&, const X&&, volatile X&&, or const volatile X&&.
   2244  1.1  joerg   if (getOverloadedOperator() != OO_Equal || isStatic() ||
   2245  1.1  joerg       getPrimaryTemplate() || getDescribedFunctionTemplate() ||
   2246  1.1  joerg       getNumParams() != 1)
   2247  1.1  joerg     return false;
   2248  1.1  joerg 
   2249  1.1  joerg   QualType ParamType = getParamDecl(0)->getType();
   2250  1.1  joerg   if (!isa<RValueReferenceType>(ParamType))
   2251  1.1  joerg     return false;
   2252  1.1  joerg   ParamType = ParamType->getPointeeType();
   2253  1.1  joerg 
   2254  1.1  joerg   ASTContext &Context = getASTContext();
   2255  1.1  joerg   QualType ClassType
   2256  1.1  joerg     = Context.getCanonicalType(Context.getTypeDeclType(getParent()));
   2257  1.1  joerg   return Context.hasSameUnqualifiedType(ClassType, ParamType);
   2258  1.1  joerg }
   2259  1.1  joerg 
   2260  1.1  joerg void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) {
   2261  1.1  joerg   assert(MD->isCanonicalDecl() && "Method is not canonical!");
   2262  1.1  joerg   assert(!MD->getParent()->isDependentContext() &&
   2263  1.1  joerg          "Can't add an overridden method to a class template!");
   2264  1.1  joerg   assert(MD->isVirtual() && "Method is not virtual!");
   2265  1.1  joerg 
   2266  1.1  joerg   getASTContext().addOverriddenMethod(this, MD);
   2267  1.1  joerg }
   2268  1.1  joerg 
   2269  1.1  joerg CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const {
   2270  1.1  joerg   if (isa<CXXConstructorDecl>(this)) return nullptr;
   2271  1.1  joerg   return getASTContext().overridden_methods_begin(this);
   2272  1.1  joerg }
   2273  1.1  joerg 
   2274  1.1  joerg CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const {
   2275  1.1  joerg   if (isa<CXXConstructorDecl>(this)) return nullptr;
   2276  1.1  joerg   return getASTContext().overridden_methods_end(this);
   2277  1.1  joerg }
   2278  1.1  joerg 
   2279  1.1  joerg unsigned CXXMethodDecl::size_overridden_methods() const {
   2280  1.1  joerg   if (isa<CXXConstructorDecl>(this)) return 0;
   2281  1.1  joerg   return getASTContext().overridden_methods_size(this);
   2282  1.1  joerg }
   2283  1.1  joerg 
   2284  1.1  joerg CXXMethodDecl::overridden_method_range
   2285  1.1  joerg CXXMethodDecl::overridden_methods() const {
   2286  1.1  joerg   if (isa<CXXConstructorDecl>(this))
   2287  1.1  joerg     return overridden_method_range(nullptr, nullptr);
   2288  1.1  joerg   return getASTContext().overridden_methods(this);
   2289  1.1  joerg }
   2290  1.1  joerg 
   2291  1.1  joerg static QualType getThisObjectType(ASTContext &C, const FunctionProtoType *FPT,
   2292  1.1  joerg                                   const CXXRecordDecl *Decl) {
   2293  1.1  joerg   QualType ClassTy = C.getTypeDeclType(Decl);
   2294  1.1  joerg   return C.getQualifiedType(ClassTy, FPT->getMethodQuals());
   2295  1.1  joerg }
   2296  1.1  joerg 
   2297  1.1  joerg QualType CXXMethodDecl::getThisType(const FunctionProtoType *FPT,
   2298  1.1  joerg                                     const CXXRecordDecl *Decl) {
   2299  1.1  joerg   ASTContext &C = Decl->getASTContext();
   2300  1.1  joerg   QualType ObjectTy = ::getThisObjectType(C, FPT, Decl);
   2301  1.1  joerg   return C.getPointerType(ObjectTy);
   2302  1.1  joerg }
   2303  1.1  joerg 
   2304  1.1  joerg QualType CXXMethodDecl::getThisObjectType(const FunctionProtoType *FPT,
   2305  1.1  joerg                                           const CXXRecordDecl *Decl) {
   2306  1.1  joerg   ASTContext &C = Decl->getASTContext();
   2307  1.1  joerg   return ::getThisObjectType(C, FPT, Decl);
   2308  1.1  joerg }
   2309  1.1  joerg 
   2310  1.1  joerg QualType CXXMethodDecl::getThisType() const {
   2311  1.1  joerg   // C++ 9.3.2p1: The type of this in a member function of a class X is X*.
   2312  1.1  joerg   // If the member function is declared const, the type of this is const X*,
   2313  1.1  joerg   // if the member function is declared volatile, the type of this is
   2314  1.1  joerg   // volatile X*, and if the member function is declared const volatile,
   2315  1.1  joerg   // the type of this is const volatile X*.
   2316  1.1  joerg   assert(isInstance() && "No 'this' for static methods!");
   2317  1.1  joerg 
   2318  1.1  joerg   return CXXMethodDecl::getThisType(getType()->getAs<FunctionProtoType>(),
   2319  1.1  joerg                                     getParent());
   2320  1.1  joerg }
   2321  1.1  joerg 
   2322  1.1  joerg QualType CXXMethodDecl::getThisObjectType() const {
   2323  1.1  joerg   // Ditto getThisType.
   2324  1.1  joerg   assert(isInstance() && "No 'this' for static methods!");
   2325  1.1  joerg 
   2326  1.1  joerg   return CXXMethodDecl::getThisObjectType(getType()->getAs<FunctionProtoType>(),
   2327  1.1  joerg                                           getParent());
   2328  1.1  joerg }
   2329  1.1  joerg 
   2330  1.1  joerg bool CXXMethodDecl::hasInlineBody() const {
   2331  1.1  joerg   // If this function is a template instantiation, look at the template from
   2332  1.1  joerg   // which it was instantiated.
   2333  1.1  joerg   const FunctionDecl *CheckFn = getTemplateInstantiationPattern();
   2334  1.1  joerg   if (!CheckFn)
   2335  1.1  joerg     CheckFn = this;
   2336  1.1  joerg 
   2337  1.1  joerg   const FunctionDecl *fn;
   2338  1.1  joerg   return CheckFn->isDefined(fn) && !fn->isOutOfLine() &&
   2339  1.1  joerg          (fn->doesThisDeclarationHaveABody() || fn->willHaveBody());
   2340  1.1  joerg }
   2341  1.1  joerg 
   2342  1.1  joerg bool CXXMethodDecl::isLambdaStaticInvoker() const {
   2343  1.1  joerg   const CXXRecordDecl *P = getParent();
   2344  1.1  joerg   if (P->isLambda()) {
   2345  1.1  joerg     if (const CXXMethodDecl *StaticInvoker = P->getLambdaStaticInvoker()) {
   2346  1.1  joerg       if (StaticInvoker == this) return true;
   2347  1.1  joerg       if (P->isGenericLambda() && this->isFunctionTemplateSpecialization())
   2348  1.1  joerg         return StaticInvoker == this->getPrimaryTemplate()->getTemplatedDecl();
   2349  1.1  joerg     }
   2350  1.1  joerg   }
   2351  1.1  joerg   return false;
   2352  1.1  joerg }
   2353  1.1  joerg 
   2354  1.1  joerg CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context,
   2355  1.1  joerg                                        TypeSourceInfo *TInfo, bool IsVirtual,
   2356  1.1  joerg                                        SourceLocation L, Expr *Init,
   2357  1.1  joerg                                        SourceLocation R,
   2358  1.1  joerg                                        SourceLocation EllipsisLoc)
   2359  1.1  joerg     : Initializee(TInfo), MemberOrEllipsisLocation(EllipsisLoc), Init(Init),
   2360  1.1  joerg       LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(IsVirtual),
   2361  1.1  joerg       IsWritten(false), SourceOrder(0) {}
   2362  1.1  joerg 
   2363  1.1  joerg CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context,
   2364  1.1  joerg                                        FieldDecl *Member,
   2365  1.1  joerg                                        SourceLocation MemberLoc,
   2366  1.1  joerg                                        SourceLocation L, Expr *Init,
   2367  1.1  joerg                                        SourceLocation R)
   2368  1.1  joerg     : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init),
   2369  1.1  joerg       LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
   2370  1.1  joerg       IsWritten(false), SourceOrder(0) {}
   2371  1.1  joerg 
   2372  1.1  joerg CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context,
   2373  1.1  joerg                                        IndirectFieldDecl *Member,
   2374  1.1  joerg                                        SourceLocation MemberLoc,
   2375  1.1  joerg                                        SourceLocation L, Expr *Init,
   2376  1.1  joerg                                        SourceLocation R)
   2377  1.1  joerg     : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init),
   2378  1.1  joerg       LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
   2379  1.1  joerg       IsWritten(false), SourceOrder(0) {}
   2380  1.1  joerg 
   2381  1.1  joerg CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context,
   2382  1.1  joerg                                        TypeSourceInfo *TInfo,
   2383  1.1  joerg                                        SourceLocation L, Expr *Init,
   2384  1.1  joerg                                        SourceLocation R)
   2385  1.1  joerg     : Initializee(TInfo), Init(Init), LParenLoc(L), RParenLoc(R),
   2386  1.1  joerg       IsDelegating(true), IsVirtual(false), IsWritten(false), SourceOrder(0) {}
   2387  1.1  joerg 
   2388  1.1  joerg int64_t CXXCtorInitializer::getID(const ASTContext &Context) const {
   2389  1.1  joerg   return Context.getAllocator()
   2390  1.1  joerg                 .identifyKnownAlignedObject<CXXCtorInitializer>(this);
   2391  1.1  joerg }
   2392  1.1  joerg 
   2393  1.1  joerg TypeLoc CXXCtorInitializer::getBaseClassLoc() const {
   2394  1.1  joerg   if (isBaseInitializer())
   2395  1.1  joerg     return Initializee.get<TypeSourceInfo*>()->getTypeLoc();
   2396  1.1  joerg   else
   2397  1.1  joerg     return {};
   2398  1.1  joerg }
   2399  1.1  joerg 
   2400  1.1  joerg const Type *CXXCtorInitializer::getBaseClass() const {
   2401  1.1  joerg   if (isBaseInitializer())
   2402  1.1  joerg     return Initializee.get<TypeSourceInfo*>()->getType().getTypePtr();
   2403  1.1  joerg   else
   2404  1.1  joerg     return nullptr;
   2405  1.1  joerg }
   2406  1.1  joerg 
   2407  1.1  joerg SourceLocation CXXCtorInitializer::getSourceLocation() const {
   2408  1.1  joerg   if (isInClassMemberInitializer())
   2409  1.1  joerg     return getAnyMember()->getLocation();
   2410  1.1  joerg 
   2411  1.1  joerg   if (isAnyMemberInitializer())
   2412  1.1  joerg     return getMemberLocation();
   2413  1.1  joerg 
   2414  1.1  joerg   if (const auto *TSInfo = Initializee.get<TypeSourceInfo *>())
   2415  1.1  joerg     return TSInfo->getTypeLoc().getLocalSourceRange().getBegin();
   2416  1.1  joerg 
   2417  1.1  joerg   return {};
   2418  1.1  joerg }
   2419  1.1  joerg 
   2420  1.1  joerg SourceRange CXXCtorInitializer::getSourceRange() const {
   2421  1.1  joerg   if (isInClassMemberInitializer()) {
   2422  1.1  joerg     FieldDecl *D = getAnyMember();
   2423  1.1  joerg     if (Expr *I = D->getInClassInitializer())
   2424  1.1  joerg       return I->getSourceRange();
   2425  1.1  joerg     return {};
   2426  1.1  joerg   }
   2427  1.1  joerg 
   2428  1.1  joerg   return SourceRange(getSourceLocation(), getRParenLoc());
   2429  1.1  joerg }
   2430  1.1  joerg 
   2431  1.1  joerg CXXConstructorDecl::CXXConstructorDecl(
   2432  1.1  joerg     ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
   2433  1.1  joerg     const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
   2434  1.1  joerg     ExplicitSpecifier ES, bool isInline, bool isImplicitlyDeclared,
   2435  1.1  joerg     ConstexprSpecKind ConstexprKind, InheritedConstructor Inherited)
   2436  1.1  joerg     : CXXMethodDecl(CXXConstructor, C, RD, StartLoc, NameInfo, T, TInfo,
   2437  1.1  joerg                     SC_None, isInline, ConstexprKind, SourceLocation()) {
   2438  1.1  joerg   setNumCtorInitializers(0);
   2439  1.1  joerg   setInheritingConstructor(static_cast<bool>(Inherited));
   2440  1.1  joerg   setImplicit(isImplicitlyDeclared);
   2441  1.1  joerg   CXXConstructorDeclBits.HasTrailingExplicitSpecifier = ES.getExpr() ? 1 : 0;
   2442  1.1  joerg   if (Inherited)
   2443  1.1  joerg     *getTrailingObjects<InheritedConstructor>() = Inherited;
   2444  1.1  joerg   setExplicitSpecifier(ES);
   2445  1.1  joerg }
   2446  1.1  joerg 
   2447  1.1  joerg void CXXConstructorDecl::anchor() {}
   2448  1.1  joerg 
   2449  1.1  joerg CXXConstructorDecl *CXXConstructorDecl::CreateDeserialized(ASTContext &C,
   2450  1.1  joerg                                                            unsigned ID,
   2451  1.1  joerg                                                            uint64_t AllocKind) {
   2452  1.1  joerg   bool hasTraillingExplicit = static_cast<bool>(AllocKind & TAKHasTailExplicit);
   2453  1.1  joerg   bool isInheritingConstructor =
   2454  1.1  joerg       static_cast<bool>(AllocKind & TAKInheritsConstructor);
   2455  1.1  joerg   unsigned Extra =
   2456  1.1  joerg       additionalSizeToAlloc<InheritedConstructor, ExplicitSpecifier>(
   2457  1.1  joerg           isInheritingConstructor, hasTraillingExplicit);
   2458  1.1  joerg   auto *Result = new (C, ID, Extra)
   2459  1.1  joerg       CXXConstructorDecl(C, nullptr, SourceLocation(), DeclarationNameInfo(),
   2460  1.1  joerg                          QualType(), nullptr, ExplicitSpecifier(), false, false,
   2461  1.1  joerg                          CSK_unspecified, InheritedConstructor());
   2462  1.1  joerg   Result->setInheritingConstructor(isInheritingConstructor);
   2463  1.1  joerg   Result->CXXConstructorDeclBits.HasTrailingExplicitSpecifier =
   2464  1.1  joerg       hasTraillingExplicit;
   2465  1.1  joerg   Result->setExplicitSpecifier(ExplicitSpecifier());
   2466  1.1  joerg   return Result;
   2467  1.1  joerg }
   2468  1.1  joerg 
   2469  1.1  joerg CXXConstructorDecl *CXXConstructorDecl::Create(
   2470  1.1  joerg     ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
   2471  1.1  joerg     const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
   2472  1.1  joerg     ExplicitSpecifier ES, bool isInline, bool isImplicitlyDeclared,
   2473  1.1  joerg     ConstexprSpecKind ConstexprKind, InheritedConstructor Inherited) {
   2474  1.1  joerg   assert(NameInfo.getName().getNameKind()
   2475  1.1  joerg          == DeclarationName::CXXConstructorName &&
   2476  1.1  joerg          "Name must refer to a constructor");
   2477  1.1  joerg   unsigned Extra =
   2478  1.1  joerg       additionalSizeToAlloc<InheritedConstructor, ExplicitSpecifier>(
   2479  1.1  joerg           Inherited ? 1 : 0, ES.getExpr() ? 1 : 0);
   2480  1.1  joerg   return new (C, RD, Extra)
   2481  1.1  joerg       CXXConstructorDecl(C, RD, StartLoc, NameInfo, T, TInfo, ES, isInline,
   2482  1.1  joerg                          isImplicitlyDeclared, ConstexprKind, Inherited);
   2483  1.1  joerg }
   2484  1.1  joerg 
   2485  1.1  joerg CXXConstructorDecl::init_const_iterator CXXConstructorDecl::init_begin() const {
   2486  1.1  joerg   return CtorInitializers.get(getASTContext().getExternalSource());
   2487  1.1  joerg }
   2488  1.1  joerg 
   2489  1.1  joerg CXXConstructorDecl *CXXConstructorDecl::getTargetConstructor() const {
   2490  1.1  joerg   assert(isDelegatingConstructor() && "Not a delegating constructor!");
   2491  1.1  joerg   Expr *E = (*init_begin())->getInit()->IgnoreImplicit();
   2492  1.1  joerg   if (const auto *Construct = dyn_cast<CXXConstructExpr>(E))
   2493  1.1  joerg     return Construct->getConstructor();
   2494  1.1  joerg 
   2495  1.1  joerg   return nullptr;
   2496  1.1  joerg }
   2497  1.1  joerg 
   2498  1.1  joerg bool CXXConstructorDecl::isDefaultConstructor() const {
   2499  1.1  joerg   // C++ [class.ctor]p5:
   2500  1.1  joerg   //   A default constructor for a class X is a constructor of class
   2501  1.1  joerg   //   X that can be called without an argument.
   2502  1.1  joerg   return (getNumParams() == 0) ||
   2503  1.1  joerg          (getNumParams() > 0 && getParamDecl(0)->hasDefaultArg());
   2504  1.1  joerg }
   2505  1.1  joerg 
   2506  1.1  joerg bool
   2507  1.1  joerg CXXConstructorDecl::isCopyConstructor(unsigned &TypeQuals) const {
   2508  1.1  joerg   return isCopyOrMoveConstructor(TypeQuals) &&
   2509  1.1  joerg          getParamDecl(0)->getType()->isLValueReferenceType();
   2510  1.1  joerg }
   2511  1.1  joerg 
   2512  1.1  joerg bool CXXConstructorDecl::isMoveConstructor(unsigned &TypeQuals) const {
   2513  1.1  joerg   return isCopyOrMoveConstructor(TypeQuals) &&
   2514  1.1  joerg     getParamDecl(0)->getType()->isRValueReferenceType();
   2515  1.1  joerg }
   2516  1.1  joerg 
   2517  1.1  joerg /// Determine whether this is a copy or move constructor.
   2518  1.1  joerg bool CXXConstructorDecl::isCopyOrMoveConstructor(unsigned &TypeQuals) const {
   2519  1.1  joerg   // C++ [class.copy]p2:
   2520  1.1  joerg   //   A non-template constructor for class X is a copy constructor
   2521  1.1  joerg   //   if its first parameter is of type X&, const X&, volatile X& or
   2522  1.1  joerg   //   const volatile X&, and either there are no other parameters
   2523  1.1  joerg   //   or else all other parameters have default arguments (8.3.6).
   2524  1.1  joerg   // C++0x [class.copy]p3:
   2525  1.1  joerg   //   A non-template constructor for class X is a move constructor if its
   2526  1.1  joerg   //   first parameter is of type X&&, const X&&, volatile X&&, or
   2527  1.1  joerg   //   const volatile X&&, and either there are no other parameters or else
   2528  1.1  joerg   //   all other parameters have default arguments.
   2529  1.1  joerg   if ((getNumParams() < 1) ||
   2530  1.1  joerg       (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) ||
   2531  1.1  joerg       (getPrimaryTemplate() != nullptr) ||
   2532  1.1  joerg       (getDescribedFunctionTemplate() != nullptr))
   2533  1.1  joerg     return false;
   2534  1.1  joerg 
   2535  1.1  joerg   const ParmVarDecl *Param = getParamDecl(0);
   2536  1.1  joerg 
   2537  1.1  joerg   // Do we have a reference type?
   2538  1.1  joerg   const auto *ParamRefType = Param->getType()->getAs<ReferenceType>();
   2539  1.1  joerg   if (!ParamRefType)
   2540  1.1  joerg     return false;
   2541  1.1  joerg 
   2542  1.1  joerg   // Is it a reference to our class type?
   2543  1.1  joerg   ASTContext &Context = getASTContext();
   2544  1.1  joerg 
   2545  1.1  joerg   CanQualType PointeeType
   2546  1.1  joerg     = Context.getCanonicalType(ParamRefType->getPointeeType());
   2547  1.1  joerg   CanQualType ClassTy
   2548  1.1  joerg     = Context.getCanonicalType(Context.getTagDeclType(getParent()));
   2549  1.1  joerg   if (PointeeType.getUnqualifiedType() != ClassTy)
   2550  1.1  joerg     return false;
   2551  1.1  joerg 
   2552  1.1  joerg   // FIXME: other qualifiers?
   2553  1.1  joerg 
   2554  1.1  joerg   // We have a copy or move constructor.
   2555  1.1  joerg   TypeQuals = PointeeType.getCVRQualifiers();
   2556  1.1  joerg   return true;
   2557  1.1  joerg }
   2558  1.1  joerg 
   2559  1.1  joerg bool CXXConstructorDecl::isConvertingConstructor(bool AllowExplicit) const {
   2560  1.1  joerg   // C++ [class.conv.ctor]p1:
   2561  1.1  joerg   //   A constructor declared without the function-specifier explicit
   2562  1.1  joerg   //   that can be called with a single parameter specifies a
   2563  1.1  joerg   //   conversion from the type of its first parameter to the type of
   2564  1.1  joerg   //   its class. Such a constructor is called a converting
   2565  1.1  joerg   //   constructor.
   2566  1.1  joerg   if (isExplicit() && !AllowExplicit)
   2567  1.1  joerg     return false;
   2568  1.1  joerg 
   2569  1.1  joerg   return (getNumParams() == 0 &&
   2570  1.1  joerg           getType()->castAs<FunctionProtoType>()->isVariadic()) ||
   2571  1.1  joerg          (getNumParams() == 1) ||
   2572  1.1  joerg          (getNumParams() > 1 &&
   2573  1.1  joerg           (getParamDecl(1)->hasDefaultArg() ||
   2574  1.1  joerg            getParamDecl(1)->isParameterPack()));
   2575  1.1  joerg }
   2576  1.1  joerg 
   2577  1.1  joerg bool CXXConstructorDecl::isSpecializationCopyingObject() const {
   2578  1.1  joerg   if ((getNumParams() < 1) ||
   2579  1.1  joerg       (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) ||
   2580  1.1  joerg       (getDescribedFunctionTemplate() != nullptr))
   2581  1.1  joerg     return false;
   2582  1.1  joerg 
   2583  1.1  joerg   const ParmVarDecl *Param = getParamDecl(0);
   2584  1.1  joerg 
   2585  1.1  joerg   ASTContext &Context = getASTContext();
   2586  1.1  joerg   CanQualType ParamType = Context.getCanonicalType(Param->getType());
   2587  1.1  joerg 
   2588  1.1  joerg   // Is it the same as our class type?
   2589  1.1  joerg   CanQualType ClassTy
   2590  1.1  joerg     = Context.getCanonicalType(Context.getTagDeclType(getParent()));
   2591  1.1  joerg   if (ParamType.getUnqualifiedType() != ClassTy)
   2592  1.1  joerg     return false;
   2593  1.1  joerg 
   2594  1.1  joerg   return true;
   2595  1.1  joerg }
   2596  1.1  joerg 
   2597  1.1  joerg void CXXDestructorDecl::anchor() {}
   2598  1.1  joerg 
   2599  1.1  joerg CXXDestructorDecl *
   2600  1.1  joerg CXXDestructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
   2601  1.1  joerg   return new (C, ID)
   2602  1.1  joerg       CXXDestructorDecl(C, nullptr, SourceLocation(), DeclarationNameInfo(),
   2603  1.1  joerg                         QualType(), nullptr, false, false, CSK_unspecified);
   2604  1.1  joerg }
   2605  1.1  joerg 
   2606  1.1  joerg CXXDestructorDecl *CXXDestructorDecl::Create(
   2607  1.1  joerg     ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
   2608  1.1  joerg     const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
   2609  1.1  joerg     bool isInline, bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind) {
   2610  1.1  joerg   assert(NameInfo.getName().getNameKind()
   2611  1.1  joerg          == DeclarationName::CXXDestructorName &&
   2612  1.1  joerg          "Name must refer to a destructor");
   2613  1.1  joerg   return new (C, RD)
   2614  1.1  joerg       CXXDestructorDecl(C, RD, StartLoc, NameInfo, T, TInfo, isInline,
   2615  1.1  joerg                         isImplicitlyDeclared, ConstexprKind);
   2616  1.1  joerg }
   2617  1.1  joerg 
   2618  1.1  joerg void CXXDestructorDecl::setOperatorDelete(FunctionDecl *OD, Expr *ThisArg) {
   2619  1.1  joerg   auto *First = cast<CXXDestructorDecl>(getFirstDecl());
   2620  1.1  joerg   if (OD && !First->OperatorDelete) {
   2621  1.1  joerg     First->OperatorDelete = OD;
   2622  1.1  joerg     First->OperatorDeleteThisArg = ThisArg;
   2623  1.1  joerg     if (auto *L = getASTMutationListener())
   2624  1.1  joerg       L->ResolvedOperatorDelete(First, OD, ThisArg);
   2625  1.1  joerg   }
   2626  1.1  joerg }
   2627  1.1  joerg 
   2628  1.1  joerg void CXXConversionDecl::anchor() {}
   2629  1.1  joerg 
   2630  1.1  joerg CXXConversionDecl *
   2631  1.1  joerg CXXConversionDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
   2632  1.1  joerg   return new (C, ID) CXXConversionDecl(
   2633  1.1  joerg       C, nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr,
   2634  1.1  joerg       false, ExplicitSpecifier(), CSK_unspecified, SourceLocation());
   2635  1.1  joerg }
   2636  1.1  joerg 
   2637  1.1  joerg CXXConversionDecl *CXXConversionDecl::Create(
   2638  1.1  joerg     ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
   2639  1.1  joerg     const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
   2640  1.1  joerg     bool isInline, ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind,
   2641  1.1  joerg     SourceLocation EndLocation) {
   2642  1.1  joerg   assert(NameInfo.getName().getNameKind()
   2643  1.1  joerg          == DeclarationName::CXXConversionFunctionName &&
   2644  1.1  joerg          "Name must refer to a conversion function");
   2645  1.1  joerg   return new (C, RD)
   2646  1.1  joerg       CXXConversionDecl(C, RD, StartLoc, NameInfo, T, TInfo, isInline, ES,
   2647  1.1  joerg                         ConstexprKind, EndLocation);
   2648  1.1  joerg }
   2649  1.1  joerg 
   2650  1.1  joerg bool CXXConversionDecl::isLambdaToBlockPointerConversion() const {
   2651  1.1  joerg   return isImplicit() && getParent()->isLambda() &&
   2652  1.1  joerg          getConversionType()->isBlockPointerType();
   2653  1.1  joerg }
   2654  1.1  joerg 
   2655  1.1  joerg LinkageSpecDecl::LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
   2656  1.1  joerg                                  SourceLocation LangLoc, LanguageIDs lang,
   2657  1.1  joerg                                  bool HasBraces)
   2658  1.1  joerg     : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
   2659  1.1  joerg       ExternLoc(ExternLoc), RBraceLoc(SourceLocation()) {
   2660  1.1  joerg   setLanguage(lang);
   2661  1.1  joerg   LinkageSpecDeclBits.HasBraces = HasBraces;
   2662  1.1  joerg }
   2663  1.1  joerg 
   2664  1.1  joerg void LinkageSpecDecl::anchor() {}
   2665  1.1  joerg 
   2666  1.1  joerg LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C,
   2667  1.1  joerg                                          DeclContext *DC,
   2668  1.1  joerg                                          SourceLocation ExternLoc,
   2669  1.1  joerg                                          SourceLocation LangLoc,
   2670  1.1  joerg                                          LanguageIDs Lang,
   2671  1.1  joerg                                          bool HasBraces) {
   2672  1.1  joerg   return new (C, DC) LinkageSpecDecl(DC, ExternLoc, LangLoc, Lang, HasBraces);
   2673  1.1  joerg }
   2674  1.1  joerg 
   2675  1.1  joerg LinkageSpecDecl *LinkageSpecDecl::CreateDeserialized(ASTContext &C,
   2676  1.1  joerg                                                      unsigned ID) {
   2677  1.1  joerg   return new (C, ID) LinkageSpecDecl(nullptr, SourceLocation(),
   2678  1.1  joerg                                      SourceLocation(), lang_c, false);
   2679  1.1  joerg }
   2680  1.1  joerg 
   2681  1.1  joerg void UsingDirectiveDecl::anchor() {}
   2682  1.1  joerg 
   2683  1.1  joerg UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC,
   2684  1.1  joerg                                                SourceLocation L,
   2685  1.1  joerg                                                SourceLocation NamespaceLoc,
   2686  1.1  joerg                                            NestedNameSpecifierLoc QualifierLoc,
   2687  1.1  joerg                                                SourceLocation IdentLoc,
   2688  1.1  joerg                                                NamedDecl *Used,
   2689  1.1  joerg                                                DeclContext *CommonAncestor) {
   2690  1.1  joerg   if (auto *NS = dyn_cast_or_null<NamespaceDecl>(Used))
   2691  1.1  joerg     Used = NS->getOriginalNamespace();
   2692  1.1  joerg   return new (C, DC) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierLoc,
   2693  1.1  joerg                                         IdentLoc, Used, CommonAncestor);
   2694  1.1  joerg }
   2695  1.1  joerg 
   2696  1.1  joerg UsingDirectiveDecl *UsingDirectiveDecl::CreateDeserialized(ASTContext &C,
   2697  1.1  joerg                                                            unsigned ID) {
   2698  1.1  joerg   return new (C, ID) UsingDirectiveDecl(nullptr, SourceLocation(),
   2699  1.1  joerg                                         SourceLocation(),
   2700  1.1  joerg                                         NestedNameSpecifierLoc(),
   2701  1.1  joerg                                         SourceLocation(), nullptr, nullptr);
   2702  1.1  joerg }
   2703  1.1  joerg 
   2704  1.1  joerg NamespaceDecl *UsingDirectiveDecl::getNominatedNamespace() {
   2705  1.1  joerg   if (auto *NA = dyn_cast_or_null<NamespaceAliasDecl>(NominatedNamespace))
   2706  1.1  joerg     return NA->getNamespace();
   2707  1.1  joerg   return cast_or_null<NamespaceDecl>(NominatedNamespace);
   2708  1.1  joerg }
   2709  1.1  joerg 
   2710  1.1  joerg NamespaceDecl::NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline,
   2711  1.1  joerg                              SourceLocation StartLoc, SourceLocation IdLoc,
   2712  1.1  joerg                              IdentifierInfo *Id, NamespaceDecl *PrevDecl)
   2713  1.1  joerg     : NamedDecl(Namespace, DC, IdLoc, Id), DeclContext(Namespace),
   2714  1.1  joerg       redeclarable_base(C), LocStart(StartLoc),
   2715  1.1  joerg       AnonOrFirstNamespaceAndInline(nullptr, Inline) {
   2716  1.1  joerg   setPreviousDecl(PrevDecl);
   2717  1.1  joerg 
   2718  1.1  joerg   if (PrevDecl)
   2719  1.1  joerg     AnonOrFirstNamespaceAndInline.setPointer(PrevDecl->getOriginalNamespace());
   2720  1.1  joerg }
   2721  1.1  joerg 
   2722  1.1  joerg NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC,
   2723  1.1  joerg                                      bool Inline, SourceLocation StartLoc,
   2724  1.1  joerg                                      SourceLocation IdLoc, IdentifierInfo *Id,
   2725  1.1  joerg                                      NamespaceDecl *PrevDecl) {
   2726  1.1  joerg   return new (C, DC) NamespaceDecl(C, DC, Inline, StartLoc, IdLoc, Id,
   2727  1.1  joerg                                    PrevDecl);
   2728  1.1  joerg }
   2729  1.1  joerg 
   2730  1.1  joerg NamespaceDecl *NamespaceDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
   2731  1.1  joerg   return new (C, ID) NamespaceDecl(C, nullptr, false, SourceLocation(),
   2732  1.1  joerg                                    SourceLocation(), nullptr, nullptr);
   2733  1.1  joerg }
   2734  1.1  joerg 
   2735  1.1  joerg NamespaceDecl *NamespaceDecl::getOriginalNamespace() {
   2736  1.1  joerg   if (isFirstDecl())
   2737  1.1  joerg     return this;
   2738  1.1  joerg 
   2739  1.1  joerg   return AnonOrFirstNamespaceAndInline.getPointer();
   2740  1.1  joerg }
   2741  1.1  joerg 
   2742  1.1  joerg const NamespaceDecl *NamespaceDecl::getOriginalNamespace() const {
   2743  1.1  joerg   if (isFirstDecl())
   2744  1.1  joerg     return this;
   2745  1.1  joerg 
   2746  1.1  joerg   return AnonOrFirstNamespaceAndInline.getPointer();
   2747  1.1  joerg }
   2748  1.1  joerg 
   2749  1.1  joerg bool NamespaceDecl::isOriginalNamespace() const { return isFirstDecl(); }
   2750  1.1  joerg 
   2751  1.1  joerg NamespaceDecl *NamespaceDecl::getNextRedeclarationImpl() {
   2752  1.1  joerg   return getNextRedeclaration();
   2753  1.1  joerg }
   2754  1.1  joerg 
   2755  1.1  joerg NamespaceDecl *NamespaceDecl::getPreviousDeclImpl() {
   2756  1.1  joerg   return getPreviousDecl();
   2757  1.1  joerg }
   2758  1.1  joerg 
   2759  1.1  joerg NamespaceDecl *NamespaceDecl::getMostRecentDeclImpl() {
   2760  1.1  joerg   return getMostRecentDecl();
   2761  1.1  joerg }
   2762  1.1  joerg 
   2763  1.1  joerg void NamespaceAliasDecl::anchor() {}
   2764  1.1  joerg 
   2765  1.1  joerg NamespaceAliasDecl *NamespaceAliasDecl::getNextRedeclarationImpl() {
   2766  1.1  joerg   return getNextRedeclaration();
   2767  1.1  joerg }
   2768  1.1  joerg 
   2769  1.1  joerg NamespaceAliasDecl *NamespaceAliasDecl::getPreviousDeclImpl() {
   2770  1.1  joerg   return getPreviousDecl();
   2771  1.1  joerg }
   2772  1.1  joerg 
   2773  1.1  joerg NamespaceAliasDecl *NamespaceAliasDecl::getMostRecentDeclImpl() {
   2774  1.1  joerg   return getMostRecentDecl();
   2775  1.1  joerg }
   2776  1.1  joerg 
   2777  1.1  joerg NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC,
   2778  1.1  joerg                                                SourceLocation UsingLoc,
   2779  1.1  joerg                                                SourceLocation AliasLoc,
   2780  1.1  joerg                                                IdentifierInfo *Alias,
   2781  1.1  joerg                                            NestedNameSpecifierLoc QualifierLoc,
   2782  1.1  joerg                                                SourceLocation IdentLoc,
   2783  1.1  joerg                                                NamedDecl *Namespace) {
   2784  1.1  joerg   // FIXME: Preserve the aliased namespace as written.
   2785  1.1  joerg   if (auto *NS = dyn_cast_or_null<NamespaceDecl>(Namespace))
   2786  1.1  joerg     Namespace = NS->getOriginalNamespace();
   2787  1.1  joerg   return new (C, DC) NamespaceAliasDecl(C, DC, UsingLoc, AliasLoc, Alias,
   2788  1.1  joerg                                         QualifierLoc, IdentLoc, Namespace);
   2789  1.1  joerg }
   2790  1.1  joerg 
   2791  1.1  joerg NamespaceAliasDecl *
   2792  1.1  joerg NamespaceAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
   2793  1.1  joerg   return new (C, ID) NamespaceAliasDecl(C, nullptr, SourceLocation(),
   2794  1.1  joerg                                         SourceLocation(), nullptr,
   2795  1.1  joerg                                         NestedNameSpecifierLoc(),
   2796  1.1  joerg                                         SourceLocation(), nullptr);
   2797  1.1  joerg }
   2798  1.1  joerg 
   2799  1.1  joerg void UsingShadowDecl::anchor() {}
   2800  1.1  joerg 
   2801  1.1  joerg UsingShadowDecl::UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC,
   2802  1.1  joerg                                  SourceLocation Loc, UsingDecl *Using,
   2803  1.1  joerg                                  NamedDecl *Target)
   2804  1.1  joerg     : NamedDecl(K, DC, Loc, Using ? Using->getDeclName() : DeclarationName()),
   2805  1.1  joerg       redeclarable_base(C), UsingOrNextShadow(cast<NamedDecl>(Using)) {
   2806  1.1  joerg   if (Target)
   2807  1.1  joerg     setTargetDecl(Target);
   2808  1.1  joerg   setImplicit();
   2809  1.1  joerg }
   2810  1.1  joerg 
   2811  1.1  joerg UsingShadowDecl::UsingShadowDecl(Kind K, ASTContext &C, EmptyShell Empty)
   2812  1.1  joerg     : NamedDecl(K, nullptr, SourceLocation(), DeclarationName()),
   2813  1.1  joerg       redeclarable_base(C) {}
   2814  1.1  joerg 
   2815  1.1  joerg UsingShadowDecl *
   2816  1.1  joerg UsingShadowDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
   2817  1.1  joerg   return new (C, ID) UsingShadowDecl(UsingShadow, C, EmptyShell());
   2818  1.1  joerg }
   2819  1.1  joerg 
   2820  1.1  joerg UsingDecl *UsingShadowDecl::getUsingDecl() const {
   2821  1.1  joerg   const UsingShadowDecl *Shadow = this;
   2822  1.1  joerg   while (const auto *NextShadow =
   2823  1.1  joerg              dyn_cast<UsingShadowDecl>(Shadow->UsingOrNextShadow))
   2824  1.1  joerg     Shadow = NextShadow;
   2825  1.1  joerg   return cast<UsingDecl>(Shadow->UsingOrNextShadow);
   2826  1.1  joerg }
   2827  1.1  joerg 
   2828  1.1  joerg void ConstructorUsingShadowDecl::anchor() {}
   2829  1.1  joerg 
   2830  1.1  joerg ConstructorUsingShadowDecl *
   2831  1.1  joerg ConstructorUsingShadowDecl::Create(ASTContext &C, DeclContext *DC,
   2832  1.1  joerg                                    SourceLocation Loc, UsingDecl *Using,
   2833  1.1  joerg                                    NamedDecl *Target, bool IsVirtual) {
   2834  1.1  joerg   return new (C, DC) ConstructorUsingShadowDecl(C, DC, Loc, Using, Target,
   2835  1.1  joerg                                                 IsVirtual);
   2836  1.1  joerg }
   2837  1.1  joerg 
   2838  1.1  joerg ConstructorUsingShadowDecl *
   2839  1.1  joerg ConstructorUsingShadowDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
   2840  1.1  joerg   return new (C, ID) ConstructorUsingShadowDecl(C, EmptyShell());
   2841  1.1  joerg }
   2842  1.1  joerg 
   2843  1.1  joerg CXXRecordDecl *ConstructorUsingShadowDecl::getNominatedBaseClass() const {
   2844  1.1  joerg   return getUsingDecl()->getQualifier()->getAsRecordDecl();
   2845  1.1  joerg }
   2846  1.1  joerg 
   2847  1.1  joerg void UsingDecl::anchor() {}
   2848  1.1  joerg 
   2849  1.1  joerg void UsingDecl::addShadowDecl(UsingShadowDecl *S) {
   2850  1.1  joerg   assert(std::find(shadow_begin(), shadow_end(), S) == shadow_end() &&
   2851  1.1  joerg          "declaration already in set");
   2852  1.1  joerg   assert(S->getUsingDecl() == this);
   2853  1.1  joerg 
   2854  1.1  joerg   if (FirstUsingShadow.getPointer())
   2855  1.1  joerg     S->UsingOrNextShadow = FirstUsingShadow.getPointer();
   2856  1.1  joerg   FirstUsingShadow.setPointer(S);
   2857  1.1  joerg }
   2858  1.1  joerg 
   2859  1.1  joerg void UsingDecl::removeShadowDecl(UsingShadowDecl *S) {
   2860  1.1  joerg   assert(std::find(shadow_begin(), shadow_end(), S) != shadow_end() &&
   2861  1.1  joerg          "declaration not in set");
   2862  1.1  joerg   assert(S->getUsingDecl() == this);
   2863  1.1  joerg 
   2864  1.1  joerg   // Remove S from the shadow decl chain. This is O(n) but hopefully rare.
   2865  1.1  joerg 
   2866  1.1  joerg   if (FirstUsingShadow.getPointer() == S) {
   2867  1.1  joerg     FirstUsingShadow.setPointer(
   2868  1.1  joerg       dyn_cast<UsingShadowDecl>(S->UsingOrNextShadow));
   2869  1.1  joerg     S->UsingOrNextShadow = this;
   2870  1.1  joerg     return;
   2871  1.1  joerg   }
   2872  1.1  joerg 
   2873  1.1  joerg   UsingShadowDecl *Prev = FirstUsingShadow.getPointer();
   2874  1.1  joerg   while (Prev->UsingOrNextShadow != S)
   2875  1.1  joerg     Prev = cast<UsingShadowDecl>(Prev->UsingOrNextShadow);
   2876  1.1  joerg   Prev->UsingOrNextShadow = S->UsingOrNextShadow;
   2877  1.1  joerg   S->UsingOrNextShadow = this;
   2878  1.1  joerg }
   2879  1.1  joerg 
   2880  1.1  joerg UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation UL,
   2881  1.1  joerg                              NestedNameSpecifierLoc QualifierLoc,
   2882  1.1  joerg                              const DeclarationNameInfo &NameInfo,
   2883  1.1  joerg                              bool HasTypename) {
   2884  1.1  joerg   return new (C, DC) UsingDecl(DC, UL, QualifierLoc, NameInfo, HasTypename);
   2885  1.1  joerg }
   2886  1.1  joerg 
   2887  1.1  joerg UsingDecl *UsingDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
   2888  1.1  joerg   return new (C, ID) UsingDecl(nullptr, SourceLocation(),
   2889  1.1  joerg                                NestedNameSpecifierLoc(), DeclarationNameInfo(),
   2890  1.1  joerg                                false);
   2891  1.1  joerg }
   2892  1.1  joerg 
   2893  1.1  joerg SourceRange UsingDecl::getSourceRange() const {
   2894  1.1  joerg   SourceLocation Begin = isAccessDeclaration()
   2895  1.1  joerg     ? getQualifierLoc().getBeginLoc() : UsingLocation;
   2896  1.1  joerg   return SourceRange(Begin, getNameInfo().getEndLoc());
   2897  1.1  joerg }
   2898  1.1  joerg 
   2899  1.1  joerg void UsingPackDecl::anchor() {}
   2900  1.1  joerg 
   2901  1.1  joerg UsingPackDecl *UsingPackDecl::Create(ASTContext &C, DeclContext *DC,
   2902  1.1  joerg                                      NamedDecl *InstantiatedFrom,
   2903  1.1  joerg                                      ArrayRef<NamedDecl *> UsingDecls) {
   2904  1.1  joerg   size_t Extra = additionalSizeToAlloc<NamedDecl *>(UsingDecls.size());
   2905  1.1  joerg   return new (C, DC, Extra) UsingPackDecl(DC, InstantiatedFrom, UsingDecls);
   2906  1.1  joerg }
   2907  1.1  joerg 
   2908  1.1  joerg UsingPackDecl *UsingPackDecl::CreateDeserialized(ASTContext &C, unsigned ID,
   2909  1.1  joerg                                                  unsigned NumExpansions) {
   2910  1.1  joerg   size_t Extra = additionalSizeToAlloc<NamedDecl *>(NumExpansions);
   2911  1.1  joerg   auto *Result = new (C, ID, Extra) UsingPackDecl(nullptr, nullptr, None);
   2912  1.1  joerg   Result->NumExpansions = NumExpansions;
   2913  1.1  joerg   auto *Trail = Result->getTrailingObjects<NamedDecl *>();
   2914  1.1  joerg   for (unsigned I = 0; I != NumExpansions; ++I)
   2915  1.1  joerg     new (Trail + I) NamedDecl*(nullptr);
   2916  1.1  joerg   return Result;
   2917  1.1  joerg }
   2918  1.1  joerg 
   2919  1.1  joerg void UnresolvedUsingValueDecl::anchor() {}
   2920  1.1  joerg 
   2921  1.1  joerg UnresolvedUsingValueDecl *
   2922  1.1  joerg UnresolvedUsingValueDecl::Create(ASTContext &C, DeclContext *DC,
   2923  1.1  joerg                                  SourceLocation UsingLoc,
   2924  1.1  joerg                                  NestedNameSpecifierLoc QualifierLoc,
   2925  1.1  joerg                                  const DeclarationNameInfo &NameInfo,
   2926  1.1  joerg                                  SourceLocation EllipsisLoc) {
   2927  1.1  joerg   return new (C, DC) UnresolvedUsingValueDecl(DC, C.DependentTy, UsingLoc,
   2928  1.1  joerg                                               QualifierLoc, NameInfo,
   2929  1.1  joerg                                               EllipsisLoc);
   2930  1.1  joerg }
   2931  1.1  joerg 
   2932  1.1  joerg UnresolvedUsingValueDecl *
   2933  1.1  joerg UnresolvedUsingValueDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
   2934  1.1  joerg   return new (C, ID) UnresolvedUsingValueDecl(nullptr, QualType(),
   2935  1.1  joerg                                               SourceLocation(),
   2936  1.1  joerg                                               NestedNameSpecifierLoc(),
   2937  1.1  joerg                                               DeclarationNameInfo(),
   2938  1.1  joerg                                               SourceLocation());
   2939  1.1  joerg }
   2940  1.1  joerg 
   2941  1.1  joerg SourceRange UnresolvedUsingValueDecl::getSourceRange() const {
   2942  1.1  joerg   SourceLocation Begin = isAccessDeclaration()
   2943  1.1  joerg     ? getQualifierLoc().getBeginLoc() : UsingLocation;
   2944  1.1  joerg   return SourceRange(Begin, getNameInfo().getEndLoc());
   2945  1.1  joerg }
   2946  1.1  joerg 
   2947  1.1  joerg void UnresolvedUsingTypenameDecl::anchor() {}
   2948  1.1  joerg 
   2949  1.1  joerg UnresolvedUsingTypenameDecl *
   2950  1.1  joerg UnresolvedUsingTypenameDecl::Create(ASTContext &C, DeclContext *DC,
   2951  1.1  joerg                                     SourceLocation UsingLoc,
   2952  1.1  joerg                                     SourceLocation TypenameLoc,
   2953  1.1  joerg                                     NestedNameSpecifierLoc QualifierLoc,
   2954  1.1  joerg                                     SourceLocation TargetNameLoc,
   2955  1.1  joerg                                     DeclarationName TargetName,
   2956  1.1  joerg                                     SourceLocation EllipsisLoc) {
   2957  1.1  joerg   return new (C, DC) UnresolvedUsingTypenameDecl(
   2958  1.1  joerg       DC, UsingLoc, TypenameLoc, QualifierLoc, TargetNameLoc,
   2959  1.1  joerg       TargetName.getAsIdentifierInfo(), EllipsisLoc);
   2960  1.1  joerg }
   2961  1.1  joerg 
   2962  1.1  joerg UnresolvedUsingTypenameDecl *
   2963  1.1  joerg UnresolvedUsingTypenameDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
   2964  1.1  joerg   return new (C, ID) UnresolvedUsingTypenameDecl(
   2965  1.1  joerg       nullptr, SourceLocation(), SourceLocation(), NestedNameSpecifierLoc(),
   2966  1.1  joerg       SourceLocation(), nullptr, SourceLocation());
   2967  1.1  joerg }
   2968  1.1  joerg 
   2969  1.1  joerg void StaticAssertDecl::anchor() {}
   2970  1.1  joerg 
   2971  1.1  joerg StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC,
   2972  1.1  joerg                                            SourceLocation StaticAssertLoc,
   2973  1.1  joerg                                            Expr *AssertExpr,
   2974  1.1  joerg                                            StringLiteral *Message,
   2975  1.1  joerg                                            SourceLocation RParenLoc,
   2976  1.1  joerg                                            bool Failed) {
   2977  1.1  joerg   return new (C, DC) StaticAssertDecl(DC, StaticAssertLoc, AssertExpr, Message,
   2978  1.1  joerg                                       RParenLoc, Failed);
   2979  1.1  joerg }
   2980  1.1  joerg 
   2981  1.1  joerg StaticAssertDecl *StaticAssertDecl::CreateDeserialized(ASTContext &C,
   2982  1.1  joerg                                                        unsigned ID) {
   2983  1.1  joerg   return new (C, ID) StaticAssertDecl(nullptr, SourceLocation(), nullptr,
   2984  1.1  joerg                                       nullptr, SourceLocation(), false);
   2985  1.1  joerg }
   2986  1.1  joerg 
   2987  1.1  joerg void BindingDecl::anchor() {}
   2988  1.1  joerg 
   2989  1.1  joerg BindingDecl *BindingDecl::Create(ASTContext &C, DeclContext *DC,
   2990  1.1  joerg                                  SourceLocation IdLoc, IdentifierInfo *Id) {
   2991  1.1  joerg   return new (C, DC) BindingDecl(DC, IdLoc, Id);
   2992  1.1  joerg }
   2993  1.1  joerg 
   2994  1.1  joerg BindingDecl *BindingDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
   2995  1.1  joerg   return new (C, ID) BindingDecl(nullptr, SourceLocation(), nullptr);
   2996  1.1  joerg }
   2997  1.1  joerg 
   2998  1.1  joerg ValueDecl *BindingDecl::getDecomposedDecl() const {
   2999  1.1  joerg   ExternalASTSource *Source =
   3000  1.1  joerg       Decomp.isOffset() ? getASTContext().getExternalSource() : nullptr;
   3001  1.1  joerg   return cast_or_null<ValueDecl>(Decomp.get(Source));
   3002  1.1  joerg }
   3003  1.1  joerg 
   3004  1.1  joerg VarDecl *BindingDecl::getHoldingVar() const {
   3005  1.1  joerg   Expr *B = getBinding();
   3006  1.1  joerg   if (!B)
   3007  1.1  joerg     return nullptr;
   3008  1.1  joerg   auto *DRE = dyn_cast<DeclRefExpr>(B->IgnoreImplicit());
   3009  1.1  joerg   if (!DRE)
   3010  1.1  joerg     return nullptr;
   3011  1.1  joerg 
   3012  1.1  joerg   auto *VD = dyn_cast<VarDecl>(DRE->getDecl());
   3013  1.1  joerg   assert(VD->isImplicit() && "holding var for binding decl not implicit");
   3014  1.1  joerg   return VD;
   3015  1.1  joerg }
   3016  1.1  joerg 
   3017  1.1  joerg void DecompositionDecl::anchor() {}
   3018  1.1  joerg 
   3019  1.1  joerg DecompositionDecl *DecompositionDecl::Create(ASTContext &C, DeclContext *DC,
   3020  1.1  joerg                                              SourceLocation StartLoc,
   3021  1.1  joerg                                              SourceLocation LSquareLoc,
   3022  1.1  joerg                                              QualType T, TypeSourceInfo *TInfo,
   3023  1.1  joerg                                              StorageClass SC,
   3024  1.1  joerg                                              ArrayRef<BindingDecl *> Bindings) {
   3025  1.1  joerg   size_t Extra = additionalSizeToAlloc<BindingDecl *>(Bindings.size());
   3026  1.1  joerg   return new (C, DC, Extra)
   3027  1.1  joerg       DecompositionDecl(C, DC, StartLoc, LSquareLoc, T, TInfo, SC, Bindings);
   3028  1.1  joerg }
   3029  1.1  joerg 
   3030  1.1  joerg DecompositionDecl *DecompositionDecl::CreateDeserialized(ASTContext &C,
   3031  1.1  joerg                                                          unsigned ID,
   3032  1.1  joerg                                                          unsigned NumBindings) {
   3033  1.1  joerg   size_t Extra = additionalSizeToAlloc<BindingDecl *>(NumBindings);
   3034  1.1  joerg   auto *Result = new (C, ID, Extra)
   3035  1.1  joerg       DecompositionDecl(C, nullptr, SourceLocation(), SourceLocation(),
   3036  1.1  joerg                         QualType(), nullptr, StorageClass(), None);
   3037  1.1  joerg   // Set up and clean out the bindings array.
   3038  1.1  joerg   Result->NumBindings = NumBindings;
   3039  1.1  joerg   auto *Trail = Result->getTrailingObjects<BindingDecl *>();
   3040  1.1  joerg   for (unsigned I = 0; I != NumBindings; ++I)
   3041  1.1  joerg     new (Trail + I) BindingDecl*(nullptr);
   3042  1.1  joerg   return Result;
   3043  1.1  joerg }
   3044  1.1  joerg 
   3045  1.1  joerg void DecompositionDecl::printName(llvm::raw_ostream &os) const {
   3046  1.1  joerg   os << '[';
   3047  1.1  joerg   bool Comma = false;
   3048  1.1  joerg   for (const auto *B : bindings()) {
   3049  1.1  joerg     if (Comma)
   3050  1.1  joerg       os << ", ";
   3051  1.1  joerg     B->printName(os);
   3052  1.1  joerg     Comma = true;
   3053  1.1  joerg   }
   3054  1.1  joerg   os << ']';
   3055  1.1  joerg }
   3056  1.1  joerg 
   3057  1.1  joerg void MSPropertyDecl::anchor() {}
   3058  1.1  joerg 
   3059  1.1  joerg MSPropertyDecl *MSPropertyDecl::Create(ASTContext &C, DeclContext *DC,
   3060  1.1  joerg                                        SourceLocation L, DeclarationName N,
   3061  1.1  joerg                                        QualType T, TypeSourceInfo *TInfo,
   3062  1.1  joerg                                        SourceLocation StartL,
   3063  1.1  joerg                                        IdentifierInfo *Getter,
   3064  1.1  joerg                                        IdentifierInfo *Setter) {
   3065  1.1  joerg   return new (C, DC) MSPropertyDecl(DC, L, N, T, TInfo, StartL, Getter, Setter);
   3066  1.1  joerg }
   3067  1.1  joerg 
   3068  1.1  joerg MSPropertyDecl *MSPropertyDecl::CreateDeserialized(ASTContext &C,
   3069  1.1  joerg                                                    unsigned ID) {
   3070  1.1  joerg   return new (C, ID) MSPropertyDecl(nullptr, SourceLocation(),
   3071  1.1  joerg                                     DeclarationName(), QualType(), nullptr,
   3072  1.1  joerg                                     SourceLocation(), nullptr, nullptr);
   3073  1.1  joerg }
   3074  1.1  joerg 
   3075  1.1  joerg static const char *getAccessName(AccessSpecifier AS) {
   3076  1.1  joerg   switch (AS) {
   3077  1.1  joerg     case AS_none:
   3078  1.1  joerg       llvm_unreachable("Invalid access specifier!");
   3079  1.1  joerg     case AS_public:
   3080  1.1  joerg       return "public";
   3081  1.1  joerg     case AS_private:
   3082  1.1  joerg       return "private";
   3083  1.1  joerg     case AS_protected:
   3084  1.1  joerg       return "protected";
   3085  1.1  joerg   }
   3086  1.1  joerg   llvm_unreachable("Invalid access specifier!");
   3087  1.1  joerg }
   3088  1.1  joerg 
   3089  1.1  joerg const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB,
   3090  1.1  joerg                                            AccessSpecifier AS) {
   3091  1.1  joerg   return DB << getAccessName(AS);
   3092  1.1  joerg }
   3093  1.1  joerg 
   3094  1.1  joerg const PartialDiagnostic &clang::operator<<(const PartialDiagnostic &DB,
   3095  1.1  joerg                                            AccessSpecifier AS) {
   3096  1.1  joerg   return DB << getAccessName(AS);
   3097  1.1  joerg }
   3098