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