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