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