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