clang 19.0.0git
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"
15#include "clang/AST/ASTLambda.h"
18#include "clang/AST/Attr.h"
20#include "clang/AST/DeclBase.h"
23#include "clang/AST/Expr.h"
24#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ODRHash.h"
28#include "clang/AST/Type.h"
29#include "clang/AST/TypeLoc.h"
33#include "clang/Basic/LLVM.h"
40#include "llvm/ADT/SmallPtrSet.h"
41#include "llvm/ADT/SmallVector.h"
42#include "llvm/ADT/iterator_range.h"
43#include "llvm/Support/Casting.h"
44#include "llvm/Support/ErrorHandling.h"
45#include "llvm/Support/Format.h"
46#include "llvm/Support/raw_ostream.h"
47#include <algorithm>
48#include <cassert>
49#include <cstddef>
50#include <cstdint>
51
52using namespace clang;
53
54//===----------------------------------------------------------------------===//
55// Decl Allocation/Deallocation Method Implementations
56//===----------------------------------------------------------------------===//
57
58void AccessSpecDecl::anchor() {}
59
61 GlobalDeclID ID) {
62 return new (C, ID) AccessSpecDecl(EmptyShell());
63}
64
65void LazyASTUnresolvedSet::getFromExternalSource(ASTContext &C) const {
66 ExternalASTSource *Source = C.getExternalSource();
67 assert(Impl.Decls.isLazy() && "getFromExternalSource for non-lazy set");
68 assert(Source && "getFromExternalSource with no external source");
69
70 for (ASTUnresolvedSet::iterator I = Impl.begin(); I != Impl.end(); ++I)
71 I.setDecl(
72 cast<NamedDecl>(Source->GetExternalDecl(GlobalDeclID(I.getDeclID()))));
73 Impl.Decls.setLazy(false);
74}
75
76CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D)
77 : UserDeclaredConstructor(false), UserDeclaredSpecialMembers(0),
78 Aggregate(true), PlainOldData(true), Empty(true), Polymorphic(false),
79 Abstract(false), IsStandardLayout(true), IsCXX11StandardLayout(true),
80 HasBasesWithFields(false), HasBasesWithNonStaticDataMembers(false),
81 HasPrivateFields(false), HasProtectedFields(false),
82 HasPublicFields(false), HasMutableFields(false), HasVariantMembers(false),
83 HasOnlyCMembers(true), HasInitMethod(false), HasInClassInitializer(false),
84 HasUninitializedReferenceMember(false), HasUninitializedFields(false),
85 HasInheritedConstructor(false), HasInheritedDefaultConstructor(false),
86 HasInheritedAssignment(false),
87 NeedOverloadResolutionForCopyConstructor(false),
88 NeedOverloadResolutionForMoveConstructor(false),
89 NeedOverloadResolutionForCopyAssignment(false),
90 NeedOverloadResolutionForMoveAssignment(false),
91 NeedOverloadResolutionForDestructor(false),
92 DefaultedCopyConstructorIsDeleted(false),
93 DefaultedMoveConstructorIsDeleted(false),
94 DefaultedCopyAssignmentIsDeleted(false),
95 DefaultedMoveAssignmentIsDeleted(false),
96 DefaultedDestructorIsDeleted(false), HasTrivialSpecialMembers(SMF_All),
97 HasTrivialSpecialMembersForCall(SMF_All),
98 DeclaredNonTrivialSpecialMembers(0),
99 DeclaredNonTrivialSpecialMembersForCall(0), HasIrrelevantDestructor(true),
100 HasConstexprNonCopyMoveConstructor(false),
101 HasDefaultedDefaultConstructor(false),
102 DefaultedDefaultConstructorIsConstexpr(true),
103 HasConstexprDefaultConstructor(false),
104 DefaultedDestructorIsConstexpr(true),
105 HasNonLiteralTypeFieldsOrBases(false), StructuralIfLiteral(true),
106 UserProvidedDefaultConstructor(false), DeclaredSpecialMembers(0),
107 ImplicitCopyConstructorCanHaveConstParamForVBase(true),
108 ImplicitCopyConstructorCanHaveConstParamForNonVBase(true),
109 ImplicitCopyAssignmentHasConstParam(true),
110 HasDeclaredCopyConstructorWithConstParam(false),
111 HasDeclaredCopyAssignmentWithConstParam(false),
112 IsAnyDestructorNoReturn(false), IsLambda(false),
113 IsParsingBaseSpecifiers(false), ComputedVisibleConversions(false),
114 HasODRHash(false), Definition(D) {}
115
116CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getBasesSlowCase() const {
117 return Bases.get(Definition->getASTContext().getExternalSource());
118}
119
120CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getVBasesSlowCase() const {
121 return VBases.get(Definition->getASTContext().getExternalSource());
122}
123
125 DeclContext *DC, SourceLocation StartLoc,
127 CXXRecordDecl *PrevDecl)
128 : RecordDecl(K, TK, C, DC, StartLoc, IdLoc, Id, PrevDecl),
129 DefinitionData(PrevDecl ? PrevDecl->DefinitionData
130 : nullptr) {}
131
133 DeclContext *DC, SourceLocation StartLoc,
135 CXXRecordDecl *PrevDecl,
136 bool DelayTypeCreation) {
137 auto *R = new (C, DC) CXXRecordDecl(CXXRecord, TK, C, DC, StartLoc, IdLoc, Id,
138 PrevDecl);
139 R->setMayHaveOutOfDateDef(C.getLangOpts().Modules);
140
141 // FIXME: DelayTypeCreation seems like such a hack
142 if (!DelayTypeCreation)
143 C.getTypeDeclType(R, PrevDecl);
144 return R;
145}
146
150 unsigned DependencyKind, bool IsGeneric,
151 LambdaCaptureDefault CaptureDefault) {
152 auto *R = new (C, DC) CXXRecordDecl(CXXRecord, TagTypeKind::Class, C, DC, Loc,
153 Loc, nullptr, nullptr);
154 R->setBeingDefined(true);
155 R->DefinitionData = new (C) struct LambdaDefinitionData(
156 R, Info, DependencyKind, IsGeneric, CaptureDefault);
157 R->setMayHaveOutOfDateDef(false);
158 R->setImplicit(true);
159
160 C.getTypeDeclType(R, /*PrevDecl=*/nullptr);
161 return R;
162}
163
165 GlobalDeclID ID) {
166 auto *R = new (C, ID)
167 CXXRecordDecl(CXXRecord, TagTypeKind::Struct, C, nullptr,
168 SourceLocation(), SourceLocation(), nullptr, nullptr);
169 R->setMayHaveOutOfDateDef(false);
170 return R;
171}
172
173/// Determine whether a class has a repeated base class. This is intended for
174/// use when determining if a class is standard-layout, so makes no attempt to
175/// handle virtual bases.
176static bool hasRepeatedBaseClass(const CXXRecordDecl *StartRD) {
178 SmallVector<const CXXRecordDecl*, 8> WorkList = {StartRD};
179 while (!WorkList.empty()) {
180 const CXXRecordDecl *RD = WorkList.pop_back_val();
181 if (RD->getTypeForDecl()->isDependentType())
182 continue;
183 for (const CXXBaseSpecifier &BaseSpec : RD->bases()) {
184 if (const CXXRecordDecl *B = BaseSpec.getType()->getAsCXXRecordDecl()) {
185 if (!SeenBaseTypes.insert(B).second)
186 return true;
187 WorkList.push_back(B);
188 }
189 }
190 }
191 return false;
192}
193
194void
196 unsigned NumBases) {
198
199 if (!data().Bases.isOffset() && data().NumBases > 0)
200 C.Deallocate(data().getBases());
201
202 if (NumBases) {
203 if (!C.getLangOpts().CPlusPlus17) {
204 // C++ [dcl.init.aggr]p1:
205 // An aggregate is [...] a class with [...] no base classes [...].
206 data().Aggregate = false;
207 }
208
209 // C++ [class]p4:
210 // A POD-struct is an aggregate class...
211 data().PlainOldData = false;
212 }
213
214 // The set of seen virtual base types.
216
217 // The virtual bases of this class.
219
220 data().Bases = new(C) CXXBaseSpecifier [NumBases];
221 data().NumBases = NumBases;
222 for (unsigned i = 0; i < NumBases; ++i) {
223 data().getBases()[i] = *Bases[i];
224 // Keep track of inherited vbases for this base class.
225 const CXXBaseSpecifier *Base = Bases[i];
226 QualType BaseType = Base->getType();
227 // Skip dependent types; we can't do any checking on them now.
228 if (BaseType->isDependentType())
229 continue;
230 auto *BaseClassDecl =
231 cast<CXXRecordDecl>(BaseType->castAs<RecordType>()->getDecl());
232
233 // C++2a [class]p7:
234 // A standard-layout class is a class that:
235 // [...]
236 // -- has all non-static data members and bit-fields in the class and
237 // its base classes first declared in the same class
238 if (BaseClassDecl->data().HasBasesWithFields ||
239 !BaseClassDecl->field_empty()) {
240 if (data().HasBasesWithFields)
241 // Two bases have members or bit-fields: not standard-layout.
242 data().IsStandardLayout = false;
243 data().HasBasesWithFields = true;
244 }
245
246 // C++11 [class]p7:
247 // A standard-layout class is a class that:
248 // -- [...] has [...] at most one base class with non-static data
249 // members
250 if (BaseClassDecl->data().HasBasesWithNonStaticDataMembers ||
251 BaseClassDecl->hasDirectFields()) {
252 if (data().HasBasesWithNonStaticDataMembers)
253 data().IsCXX11StandardLayout = false;
254 data().HasBasesWithNonStaticDataMembers = true;
255 }
256
257 if (!BaseClassDecl->isEmpty()) {
258 // C++14 [meta.unary.prop]p4:
259 // T is a class type [...] with [...] no base class B for which
260 // is_empty<B>::value is false.
261 data().Empty = false;
262 }
263
264 // C++1z [dcl.init.agg]p1:
265 // An aggregate is a class with [...] no private or protected base classes
266 if (Base->getAccessSpecifier() != AS_public) {
267 data().Aggregate = false;
268
269 // C++20 [temp.param]p7:
270 // A structural type is [...] a literal class type with [...] all base
271 // classes [...] public
272 data().StructuralIfLiteral = false;
273 }
274
275 // C++ [class.virtual]p1:
276 // A class that declares or inherits a virtual function is called a
277 // polymorphic class.
278 if (BaseClassDecl->isPolymorphic()) {
279 data().Polymorphic = true;
280
281 // An aggregate is a class with [...] no virtual functions.
282 data().Aggregate = false;
283 }
284
285 // C++0x [class]p7:
286 // A standard-layout class is a class that: [...]
287 // -- has no non-standard-layout base classes
288 if (!BaseClassDecl->isStandardLayout())
289 data().IsStandardLayout = false;
290 if (!BaseClassDecl->isCXX11StandardLayout())
291 data().IsCXX11StandardLayout = false;
292
293 // Record if this base is the first non-literal field or base.
294 if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C))
295 data().HasNonLiteralTypeFieldsOrBases = true;
296
297 // Now go through all virtual bases of this base and add them.
298 for (const auto &VBase : BaseClassDecl->vbases()) {
299 // Add this base if it's not already in the list.
300 if (SeenVBaseTypes.insert(C.getCanonicalType(VBase.getType())).second) {
301 VBases.push_back(&VBase);
302
303 // C++11 [class.copy]p8:
304 // The implicitly-declared copy constructor for a class X will have
305 // the form 'X::X(const X&)' if each [...] virtual base class B of X
306 // has a copy constructor whose first parameter is of type
307 // 'const B&' or 'const volatile B&' [...]
308 if (CXXRecordDecl *VBaseDecl = VBase.getType()->getAsCXXRecordDecl())
309 if (!VBaseDecl->hasCopyConstructorWithConstParam())
310 data().ImplicitCopyConstructorCanHaveConstParamForVBase = false;
311
312 // C++1z [dcl.init.agg]p1:
313 // An aggregate is a class with [...] no virtual base classes
314 data().Aggregate = false;
315 }
316 }
317
318 if (Base->isVirtual()) {
319 // Add this base if it's not already in the list.
320 if (SeenVBaseTypes.insert(C.getCanonicalType(BaseType)).second)
321 VBases.push_back(Base);
322
323 // C++14 [meta.unary.prop] is_empty:
324 // T is a class type, but not a union type, with ... no virtual base
325 // classes
326 data().Empty = false;
327
328 // C++1z [dcl.init.agg]p1:
329 // An aggregate is a class with [...] no virtual base classes
330 data().Aggregate = false;
331
332 // C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25:
333 // A [default constructor, copy/move constructor, or copy/move assignment
334 // operator for a class X] is trivial [...] if:
335 // -- class X has [...] no virtual base classes
336 data().HasTrivialSpecialMembers &= SMF_Destructor;
337 data().HasTrivialSpecialMembersForCall &= SMF_Destructor;
338
339 // C++0x [class]p7:
340 // A standard-layout class is a class that: [...]
341 // -- has [...] no virtual base classes
342 data().IsStandardLayout = false;
343 data().IsCXX11StandardLayout = false;
344
345 // C++20 [dcl.constexpr]p3:
346 // In the definition of a constexpr function [...]
347 // -- if the function is a constructor or destructor,
348 // its class shall not have any virtual base classes
349 data().DefaultedDefaultConstructorIsConstexpr = false;
350 data().DefaultedDestructorIsConstexpr = false;
351
352 // C++1z [class.copy]p8:
353 // The implicitly-declared copy constructor for a class X will have
354 // the form 'X::X(const X&)' if each potentially constructed subobject
355 // has a copy constructor whose first parameter is of type
356 // 'const B&' or 'const volatile B&' [...]
357 if (!BaseClassDecl->hasCopyConstructorWithConstParam())
358 data().ImplicitCopyConstructorCanHaveConstParamForVBase = false;
359 } else {
360 // C++ [class.ctor]p5:
361 // A default constructor is trivial [...] if:
362 // -- all the direct base classes of its class have trivial default
363 // constructors.
364 if (!BaseClassDecl->hasTrivialDefaultConstructor())
365 data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor;
366
367 // C++0x [class.copy]p13:
368 // A copy/move constructor for class X is trivial if [...]
369 // [...]
370 // -- the constructor selected to copy/move each direct base class
371 // subobject is trivial, and
372 if (!BaseClassDecl->hasTrivialCopyConstructor())
373 data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor;
374
375 if (!BaseClassDecl->hasTrivialCopyConstructorForCall())
376 data().HasTrivialSpecialMembersForCall &= ~SMF_CopyConstructor;
377
378 // If the base class doesn't have a simple move constructor, we'll eagerly
379 // declare it and perform overload resolution to determine which function
380 // it actually calls. If it does have a simple move constructor, this
381 // check is correct.
382 if (!BaseClassDecl->hasTrivialMoveConstructor())
383 data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor;
384
385 if (!BaseClassDecl->hasTrivialMoveConstructorForCall())
386 data().HasTrivialSpecialMembersForCall &= ~SMF_MoveConstructor;
387
388 // C++0x [class.copy]p27:
389 // A copy/move assignment operator for class X is trivial if [...]
390 // [...]
391 // -- the assignment operator selected to copy/move each direct base
392 // class subobject is trivial, and
393 if (!BaseClassDecl->hasTrivialCopyAssignment())
394 data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment;
395 // If the base class doesn't have a simple move assignment, we'll eagerly
396 // declare it and perform overload resolution to determine which function
397 // it actually calls. If it does have a simple move assignment, this
398 // check is correct.
399 if (!BaseClassDecl->hasTrivialMoveAssignment())
400 data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment;
401
402 // C++11 [class.ctor]p6:
403 // If that user-written default constructor would satisfy the
404 // requirements of a constexpr constructor/function(C++23), the
405 // implicitly-defined default constructor is constexpr.
406 if (!BaseClassDecl->hasConstexprDefaultConstructor())
407 data().DefaultedDefaultConstructorIsConstexpr =
408 C.getLangOpts().CPlusPlus23;
409
410 // C++1z [class.copy]p8:
411 // The implicitly-declared copy constructor for a class X will have
412 // the form 'X::X(const X&)' if each potentially constructed subobject
413 // has a copy constructor whose first parameter is of type
414 // 'const B&' or 'const volatile B&' [...]
415 if (!BaseClassDecl->hasCopyConstructorWithConstParam())
416 data().ImplicitCopyConstructorCanHaveConstParamForNonVBase = false;
417 }
418
419 // C++ [class.ctor]p3:
420 // A destructor is trivial if all the direct base classes of its class
421 // have trivial destructors.
422 if (!BaseClassDecl->hasTrivialDestructor())
423 data().HasTrivialSpecialMembers &= ~SMF_Destructor;
424
425 if (!BaseClassDecl->hasTrivialDestructorForCall())
426 data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor;
427
428 if (!BaseClassDecl->hasIrrelevantDestructor())
429 data().HasIrrelevantDestructor = false;
430
431 if (BaseClassDecl->isAnyDestructorNoReturn())
432 data().IsAnyDestructorNoReturn = true;
433
434 // C++11 [class.copy]p18:
435 // The implicitly-declared copy assignment operator for a class X will
436 // have the form 'X& X::operator=(const X&)' if each direct base class B
437 // of X has a copy assignment operator whose parameter is of type 'const
438 // B&', 'const volatile B&', or 'B' [...]
439 if (!BaseClassDecl->hasCopyAssignmentWithConstParam())
440 data().ImplicitCopyAssignmentHasConstParam = false;
441
442 // A class has an Objective-C object member if... or any of its bases
443 // has an Objective-C object member.
444 if (BaseClassDecl->hasObjectMember())
445 setHasObjectMember(true);
446
447 if (BaseClassDecl->hasVolatileMember())
449
450 if (BaseClassDecl->getArgPassingRestrictions() ==
453
454 // Keep track of the presence of mutable fields.
455 if (BaseClassDecl->hasMutableFields())
456 data().HasMutableFields = true;
457
458 if (BaseClassDecl->hasUninitializedReferenceMember())
459 data().HasUninitializedReferenceMember = true;
460
461 if (!BaseClassDecl->allowConstDefaultInit())
462 data().HasUninitializedFields = true;
463
464 addedClassSubobject(BaseClassDecl);
465 }
466
467 // C++2a [class]p7:
468 // A class S is a standard-layout class if it:
469 // -- has at most one base class subobject of any given type
470 //
471 // Note that we only need to check this for classes with more than one base
472 // class. If there's only one base class, and it's standard layout, then
473 // we know there are no repeated base classes.
474 if (data().IsStandardLayout && NumBases > 1 && hasRepeatedBaseClass(this))
475 data().IsStandardLayout = false;
476
477 if (VBases.empty()) {
478 data().IsParsingBaseSpecifiers = false;
479 return;
480 }
481
482 // Create base specifier for any direct or indirect virtual bases.
483 data().VBases = new (C) CXXBaseSpecifier[VBases.size()];
484 data().NumVBases = VBases.size();
485 for (int I = 0, E = VBases.size(); I != E; ++I) {
486 QualType Type = VBases[I]->getType();
487 if (!Type->isDependentType())
488 addedClassSubobject(Type->getAsCXXRecordDecl());
489 data().getVBases()[I] = *VBases[I];
490 }
491
492 data().IsParsingBaseSpecifiers = false;
493}
494
496 assert(hasDefinition() && "ODRHash only for records with definitions");
497
498 // Previously calculated hash is stored in DefinitionData.
499 if (DefinitionData->HasODRHash)
500 return DefinitionData->ODRHash;
501
502 // Only calculate hash on first call of getODRHash per record.
503 ODRHash Hash;
505 DefinitionData->HasODRHash = true;
506 DefinitionData->ODRHash = Hash.CalculateHash();
507
508 return DefinitionData->ODRHash;
509}
510
511void CXXRecordDecl::addedClassSubobject(CXXRecordDecl *Subobj) {
512 // C++11 [class.copy]p11:
513 // A defaulted copy/move constructor for a class X is defined as
514 // deleted if X has:
515 // -- a direct or virtual base class B that cannot be copied/moved [...]
516 // -- a non-static data member of class type M (or array thereof)
517 // that cannot be copied or moved [...]
518 if (!Subobj->hasSimpleCopyConstructor())
519 data().NeedOverloadResolutionForCopyConstructor = true;
520 if (!Subobj->hasSimpleMoveConstructor())
521 data().NeedOverloadResolutionForMoveConstructor = true;
522
523 // C++11 [class.copy]p23:
524 // A defaulted copy/move assignment operator for a class X is defined as
525 // deleted if X has:
526 // -- a direct or virtual base class B that cannot be copied/moved [...]
527 // -- a non-static data member of class type M (or array thereof)
528 // that cannot be copied or moved [...]
529 if (!Subobj->hasSimpleCopyAssignment())
530 data().NeedOverloadResolutionForCopyAssignment = true;
531 if (!Subobj->hasSimpleMoveAssignment())
532 data().NeedOverloadResolutionForMoveAssignment = true;
533
534 // C++11 [class.ctor]p5, C++11 [class.copy]p11, C++11 [class.dtor]p5:
535 // A defaulted [ctor or dtor] for a class X is defined as
536 // deleted if X has:
537 // -- any direct or virtual base class [...] has a type with a destructor
538 // that is deleted or inaccessible from the defaulted [ctor or dtor].
539 // -- any non-static data member has a type with a destructor
540 // that is deleted or inaccessible from the defaulted [ctor or dtor].
541 if (!Subobj->hasSimpleDestructor()) {
542 data().NeedOverloadResolutionForCopyConstructor = true;
543 data().NeedOverloadResolutionForMoveConstructor = true;
544 data().NeedOverloadResolutionForDestructor = true;
545 }
546
547 // C++2a [dcl.constexpr]p4:
548 // The definition of a constexpr destructor [shall] satisfy the
549 // following requirement:
550 // -- for every subobject of class type or (possibly multi-dimensional)
551 // array thereof, that class type shall have a constexpr destructor
552 if (!Subobj->hasConstexprDestructor())
553 data().DefaultedDestructorIsConstexpr =
554 getASTContext().getLangOpts().CPlusPlus23;
555
556 // C++20 [temp.param]p7:
557 // A structural type is [...] a literal class type [for which] the types
558 // of all base classes and non-static data members are structural types or
559 // (possibly multi-dimensional) array thereof
560 if (!Subobj->data().StructuralIfLiteral)
561 data().StructuralIfLiteral = false;
562}
563
565 auto *Dtor = getDestructor();
566 return Dtor ? Dtor->isConstexpr() : defaultedDestructorIsConstexpr();
567}
568
570 if (!isDependentContext())
571 return false;
572
573 return !forallBases([](const CXXRecordDecl *) { return true; });
574}
575
577 // C++0x [class]p5:
578 // A trivially copyable class is a class that:
579 // -- has no non-trivial copy constructors,
580 if (hasNonTrivialCopyConstructor()) return false;
581 // -- has no non-trivial move constructors,
582 if (hasNonTrivialMoveConstructor()) return false;
583 // -- has no non-trivial copy assignment operators,
584 if (hasNonTrivialCopyAssignment()) return false;
585 // -- has no non-trivial move assignment operators, and
586 if (hasNonTrivialMoveAssignment()) return false;
587 // -- has a trivial destructor.
588 if (!hasTrivialDestructor()) return false;
589
590 return true;
591}
592
594
595 // A trivially copy constructible class is a class that:
596 // -- has no non-trivial copy constructors,
598 return false;
599 // -- has a trivial destructor.
601 return false;
602
603 return true;
604}
605
606void CXXRecordDecl::markedVirtualFunctionPure() {
607 // C++ [class.abstract]p2:
608 // A class is abstract if it has at least one pure virtual function.
609 data().Abstract = true;
610}
611
612bool CXXRecordDecl::hasSubobjectAtOffsetZeroOfEmptyBaseType(
613 ASTContext &Ctx, const CXXRecordDecl *XFirst) {
614 if (!getNumBases())
615 return false;
616
620
621 // Visit a type that we have determined is an element of M(S).
622 auto Visit = [&](const CXXRecordDecl *RD) -> bool {
623 RD = RD->getCanonicalDecl();
624
625 // C++2a [class]p8:
626 // A class S is a standard-layout class if it [...] has no element of the
627 // set M(S) of types as a base class.
628 //
629 // If we find a subobject of an empty type, it might also be a base class,
630 // so we'll need to walk the base classes to check.
631 if (!RD->data().HasBasesWithFields) {
632 // Walk the bases the first time, stopping if we find the type. Build a
633 // set of them so we don't need to walk them again.
634 if (Bases.empty()) {
635 bool RDIsBase = !forallBases([&](const CXXRecordDecl *Base) -> bool {
636 Base = Base->getCanonicalDecl();
637 if (RD == Base)
638 return false;
639 Bases.insert(Base);
640 return true;
641 });
642 if (RDIsBase)
643 return true;
644 } else {
645 if (Bases.count(RD))
646 return true;
647 }
648 }
649
650 if (M.insert(RD).second)
651 WorkList.push_back(RD);
652 return false;
653 };
654
655 if (Visit(XFirst))
656 return true;
657
658 while (!WorkList.empty()) {
659 const CXXRecordDecl *X = WorkList.pop_back_val();
660
661 // FIXME: We don't check the bases of X. That matches the standard, but
662 // that sure looks like a wording bug.
663
664 // -- If X is a non-union class type with a non-static data member
665 // [recurse to each field] that is either of zero size or is the
666 // first non-static data member of X
667 // -- If X is a union type, [recurse to union members]
668 bool IsFirstField = true;
669 for (auto *FD : X->fields()) {
670 // FIXME: Should we really care about the type of the first non-static
671 // data member of a non-union if there are preceding unnamed bit-fields?
672 if (FD->isUnnamedBitField())
673 continue;
674
675 if (!IsFirstField && !FD->isZeroSize(Ctx))
676 continue;
677
678 // -- If X is n array type, [visit the element type]
679 QualType T = Ctx.getBaseElementType(FD->getType());
680 if (auto *RD = T->getAsCXXRecordDecl())
681 if (Visit(RD))
682 return true;
683
684 if (!X->isUnion())
685 IsFirstField = false;
686 }
687 }
688
689 return false;
690}
691
693 assert(isLambda() && "not a lambda");
694
695 // C++2a [expr.prim.lambda.capture]p11:
696 // The closure type associated with a lambda-expression has no default
697 // constructor if the lambda-expression has a lambda-capture and a
698 // defaulted default constructor otherwise. It has a deleted copy
699 // assignment operator if the lambda-expression has a lambda-capture and
700 // defaulted copy and move assignment operators otherwise.
701 //
702 // C++17 [expr.prim.lambda]p21:
703 // The closure type associated with a lambda-expression has no default
704 // constructor and a deleted copy assignment operator.
705 if (!isCapturelessLambda())
706 return false;
707 return getASTContext().getLangOpts().CPlusPlus20;
708}
709
710void CXXRecordDecl::addedMember(Decl *D) {
711 if (!D->isImplicit() && !isa<FieldDecl>(D) && !isa<IndirectFieldDecl>(D) &&
712 (!isa<TagDecl>(D) ||
713 cast<TagDecl>(D)->getTagKind() == TagTypeKind::Class ||
714 cast<TagDecl>(D)->getTagKind() == TagTypeKind::Interface))
715 data().HasOnlyCMembers = false;
716
717 // Ignore friends and invalid declarations.
718 if (D->getFriendObjectKind() || D->isInvalidDecl())
719 return;
720
721 auto *FunTmpl = dyn_cast<FunctionTemplateDecl>(D);
722 if (FunTmpl)
723 D = FunTmpl->getTemplatedDecl();
724
725 // FIXME: Pass NamedDecl* to addedMember?
726 Decl *DUnderlying = D;
727 if (auto *ND = dyn_cast<NamedDecl>(DUnderlying)) {
728 DUnderlying = ND->getUnderlyingDecl();
729 if (auto *UnderlyingFunTmpl = dyn_cast<FunctionTemplateDecl>(DUnderlying))
730 DUnderlying = UnderlyingFunTmpl->getTemplatedDecl();
731 }
732
733 if (const auto *Method = dyn_cast<CXXMethodDecl>(D)) {
734 if (Method->isVirtual()) {
735 // C++ [dcl.init.aggr]p1:
736 // An aggregate is an array or a class with [...] no virtual functions.
737 data().Aggregate = false;
738
739 // C++ [class]p4:
740 // A POD-struct is an aggregate class...
741 data().PlainOldData = false;
742
743 // C++14 [meta.unary.prop]p4:
744 // T is a class type [...] with [...] no virtual member functions...
745 data().Empty = false;
746
747 // C++ [class.virtual]p1:
748 // A class that declares or inherits a virtual function is called a
749 // polymorphic class.
750 data().Polymorphic = true;
751
752 // C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25:
753 // A [default constructor, copy/move constructor, or copy/move
754 // assignment operator for a class X] is trivial [...] if:
755 // -- class X has no virtual functions [...]
756 data().HasTrivialSpecialMembers &= SMF_Destructor;
757 data().HasTrivialSpecialMembersForCall &= SMF_Destructor;
758
759 // C++0x [class]p7:
760 // A standard-layout class is a class that: [...]
761 // -- has no virtual functions
762 data().IsStandardLayout = false;
763 data().IsCXX11StandardLayout = false;
764 }
765 }
766
767 // Notify the listener if an implicit member was added after the definition
768 // was completed.
769 if (!isBeingDefined() && D->isImplicit())
771 L->AddedCXXImplicitMember(data().Definition, D);
772
773 // The kind of special member this declaration is, if any.
774 unsigned SMKind = 0;
775
776 // Handle constructors.
777 if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(D)) {
778 if (Constructor->isInheritingConstructor()) {
779 // Ignore constructor shadow declarations. They are lazily created and
780 // so shouldn't affect any properties of the class.
781 } else {
782 if (!Constructor->isImplicit()) {
783 // Note that we have a user-declared constructor.
784 data().UserDeclaredConstructor = true;
785
786 const TargetInfo &TI = getASTContext().getTargetInfo();
787 if ((!Constructor->isDeleted() && !Constructor->isDefaulted()) ||
789 // C++ [class]p4:
790 // A POD-struct is an aggregate class [...]
791 // Since the POD bit is meant to be C++03 POD-ness, clear it even if
792 // the type is technically an aggregate in C++0x since it wouldn't be
793 // in 03.
794 data().PlainOldData = false;
795 }
796 }
797
798 if (Constructor->isDefaultConstructor()) {
799 SMKind |= SMF_DefaultConstructor;
800
801 if (Constructor->isUserProvided())
802 data().UserProvidedDefaultConstructor = true;
803 if (Constructor->isConstexpr())
804 data().HasConstexprDefaultConstructor = true;
805 if (Constructor->isDefaulted())
806 data().HasDefaultedDefaultConstructor = true;
807 }
808
809 if (!FunTmpl) {
810 unsigned Quals;
811 if (Constructor->isCopyConstructor(Quals)) {
812 SMKind |= SMF_CopyConstructor;
813
814 if (Quals & Qualifiers::Const)
815 data().HasDeclaredCopyConstructorWithConstParam = true;
816 } else if (Constructor->isMoveConstructor())
817 SMKind |= SMF_MoveConstructor;
818 }
819
820 // C++11 [dcl.init.aggr]p1: DR1518
821 // An aggregate is an array or a class with no user-provided [or]
822 // explicit [...] constructors
823 // C++20 [dcl.init.aggr]p1:
824 // An aggregate is an array or a class with no user-declared [...]
825 // constructors
827 ? !Constructor->isImplicit()
828 : (Constructor->isUserProvided() || Constructor->isExplicit()))
829 data().Aggregate = false;
830 }
831 }
832
833 // Handle constructors, including those inherited from base classes.
834 if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(DUnderlying)) {
835 // Record if we see any constexpr constructors which are neither copy
836 // nor move constructors.
837 // C++1z [basic.types]p10:
838 // [...] has at least one constexpr constructor or constructor template
839 // (possibly inherited from a base class) that is not a copy or move
840 // constructor [...]
841 if (Constructor->isConstexpr() && !Constructor->isCopyOrMoveConstructor())
842 data().HasConstexprNonCopyMoveConstructor = true;
843 if (!isa<CXXConstructorDecl>(D) && Constructor->isDefaultConstructor())
844 data().HasInheritedDefaultConstructor = true;
845 }
846
847 // Handle member functions.
848 if (const auto *Method = dyn_cast<CXXMethodDecl>(D)) {
849 if (isa<CXXDestructorDecl>(D))
850 SMKind |= SMF_Destructor;
851
852 if (Method->isCopyAssignmentOperator()) {
853 SMKind |= SMF_CopyAssignment;
854
855 const auto *ParamTy =
856 Method->getNonObjectParameter(0)->getType()->getAs<ReferenceType>();
857 if (!ParamTy || ParamTy->getPointeeType().isConstQualified())
858 data().HasDeclaredCopyAssignmentWithConstParam = true;
859 }
860
861 if (Method->isMoveAssignmentOperator())
862 SMKind |= SMF_MoveAssignment;
863
864 // Keep the list of conversion functions up-to-date.
865 if (auto *Conversion = dyn_cast<CXXConversionDecl>(D)) {
866 // FIXME: We use the 'unsafe' accessor for the access specifier here,
867 // because Sema may not have set it yet. That's really just a misdesign
868 // in Sema. However, LLDB *will* have set the access specifier correctly,
869 // and adds declarations after the class is technically completed,
870 // so completeDefinition()'s overriding of the access specifiers doesn't
871 // work.
872 AccessSpecifier AS = Conversion->getAccessUnsafe();
873
874 if (Conversion->getPrimaryTemplate()) {
875 // We don't record specializations.
876 } else {
877 ASTContext &Ctx = getASTContext();
878 ASTUnresolvedSet &Conversions = data().Conversions.get(Ctx);
879 NamedDecl *Primary =
880 FunTmpl ? cast<NamedDecl>(FunTmpl) : cast<NamedDecl>(Conversion);
881 if (Primary->getPreviousDecl())
882 Conversions.replace(cast<NamedDecl>(Primary->getPreviousDecl()),
883 Primary, AS);
884 else
885 Conversions.addDecl(Ctx, Primary, AS);
886 }
887 }
888
889 if (SMKind) {
890 // If this is the first declaration of a special member, we no longer have
891 // an implicit trivial special member.
892 data().HasTrivialSpecialMembers &=
893 data().DeclaredSpecialMembers | ~SMKind;
894 data().HasTrivialSpecialMembersForCall &=
895 data().DeclaredSpecialMembers | ~SMKind;
896
897 // Note when we have declared a declared special member, and suppress the
898 // implicit declaration of this special member.
899 data().DeclaredSpecialMembers |= SMKind;
900 if (!Method->isImplicit()) {
901 data().UserDeclaredSpecialMembers |= SMKind;
902
903 const TargetInfo &TI = getASTContext().getTargetInfo();
904 if ((!Method->isDeleted() && !Method->isDefaulted() &&
905 SMKind != SMF_MoveAssignment) ||
907 // C++03 [class]p4:
908 // A POD-struct is an aggregate class that has [...] no user-defined
909 // copy assignment operator and no user-defined destructor.
910 //
911 // Since the POD bit is meant to be C++03 POD-ness, and in C++03,
912 // aggregates could not have any constructors, clear it even for an
913 // explicitly defaulted or deleted constructor.
914 // type is technically an aggregate in C++0x since it wouldn't be in
915 // 03.
916 //
917 // Also, a user-declared move assignment operator makes a class
918 // non-POD. This is an extension in C++03.
919 data().PlainOldData = false;
920 }
921 }
922 // When instantiating a class, we delay updating the destructor and
923 // triviality properties of the class until selecting a destructor and
924 // computing the eligibility of its special member functions. This is
925 // because there might be function constraints that we need to evaluate
926 // and compare later in the instantiation.
927 if (!Method->isIneligibleOrNotSelected()) {
929 }
930 }
931
932 return;
933 }
934
935 // Handle non-static data members.
936 if (const auto *Field = dyn_cast<FieldDecl>(D)) {
937 ASTContext &Context = getASTContext();
938
939 // C++2a [class]p7:
940 // A standard-layout class is a class that:
941 // [...]
942 // -- has all non-static data members and bit-fields in the class and
943 // its base classes first declared in the same class
944 if (data().HasBasesWithFields)
945 data().IsStandardLayout = false;
946
947 // C++ [class.bit]p2:
948 // A declaration for a bit-field that omits the identifier declares an
949 // unnamed bit-field. Unnamed bit-fields are not members and cannot be
950 // initialized.
951 if (Field->isUnnamedBitField()) {
952 // C++ [meta.unary.prop]p4: [LWG2358]
953 // T is a class type [...] with [...] no unnamed bit-fields of non-zero
954 // length
955 if (data().Empty && !Field->isZeroLengthBitField(Context) &&
956 Context.getLangOpts().getClangABICompat() >
958 data().Empty = false;
959 return;
960 }
961
962 // C++11 [class]p7:
963 // A standard-layout class is a class that:
964 // -- either has no non-static data members in the most derived class
965 // [...] or has no base classes with non-static data members
966 if (data().HasBasesWithNonStaticDataMembers)
967 data().IsCXX11StandardLayout = false;
968
969 // C++ [dcl.init.aggr]p1:
970 // An aggregate is an array or a class (clause 9) with [...] no
971 // private or protected non-static data members (clause 11).
972 //
973 // A POD must be an aggregate.
974 if (D->getAccess() == AS_private || D->getAccess() == AS_protected) {
975 data().Aggregate = false;
976 data().PlainOldData = false;
977
978 // C++20 [temp.param]p7:
979 // A structural type is [...] a literal class type [for which] all
980 // non-static data members are public
981 data().StructuralIfLiteral = false;
982 }
983
984 // Track whether this is the first field. We use this when checking
985 // whether the class is standard-layout below.
986 bool IsFirstField = !data().HasPrivateFields &&
987 !data().HasProtectedFields && !data().HasPublicFields;
988
989 // C++0x [class]p7:
990 // A standard-layout class is a class that:
991 // [...]
992 // -- has the same access control for all non-static data members,
993 switch (D->getAccess()) {
994 case AS_private: data().HasPrivateFields = true; break;
995 case AS_protected: data().HasProtectedFields = true; break;
996 case AS_public: data().HasPublicFields = true; break;
997 case AS_none: llvm_unreachable("Invalid access specifier");
998 };
999 if ((data().HasPrivateFields + data().HasProtectedFields +
1000 data().HasPublicFields) > 1) {
1001 data().IsStandardLayout = false;
1002 data().IsCXX11StandardLayout = false;
1003 }
1004
1005 // Keep track of the presence of mutable fields.
1006 if (Field->isMutable()) {
1007 data().HasMutableFields = true;
1008
1009 // C++20 [temp.param]p7:
1010 // A structural type is [...] a literal class type [for which] all
1011 // non-static data members are public
1012 data().StructuralIfLiteral = false;
1013 }
1014
1015 // C++11 [class.union]p8, DR1460:
1016 // If X is a union, a non-static data member of X that is not an anonymous
1017 // union is a variant member of X.
1018 if (isUnion() && !Field->isAnonymousStructOrUnion())
1019 data().HasVariantMembers = true;
1020
1021 // C++0x [class]p9:
1022 // A POD struct is a class that is both a trivial class and a
1023 // standard-layout class, and has no non-static data members of type
1024 // non-POD struct, non-POD union (or array of such types).
1025 //
1026 // Automatic Reference Counting: the presence of a member of Objective-C pointer type
1027 // that does not explicitly have no lifetime makes the class a non-POD.
1028 QualType T = Context.getBaseElementType(Field->getType());
1029 if (T->isObjCRetainableType() || T.isObjCGCStrong()) {
1030 if (T.hasNonTrivialObjCLifetime()) {
1031 // Objective-C Automatic Reference Counting:
1032 // If a class has a non-static data member of Objective-C pointer
1033 // type (or array thereof), it is a non-POD type and its
1034 // default constructor (if any), copy constructor, move constructor,
1035 // copy assignment operator, move assignment operator, and destructor are
1036 // non-trivial.
1037 setHasObjectMember(true);
1038 struct DefinitionData &Data = data();
1039 Data.PlainOldData = false;
1040 Data.HasTrivialSpecialMembers = 0;
1041
1042 // __strong or __weak fields do not make special functions non-trivial
1043 // for the purpose of calls.
1044 Qualifiers::ObjCLifetime LT = T.getQualifiers().getObjCLifetime();
1046 data().HasTrivialSpecialMembersForCall = 0;
1047
1048 // Structs with __weak fields should never be passed directly.
1049 if (LT == Qualifiers::OCL_Weak)
1051
1052 Data.HasIrrelevantDestructor = false;
1053
1054 if (isUnion()) {
1055 data().DefaultedCopyConstructorIsDeleted = true;
1056 data().DefaultedMoveConstructorIsDeleted = true;
1057 data().DefaultedCopyAssignmentIsDeleted = true;
1058 data().DefaultedMoveAssignmentIsDeleted = true;
1059 data().DefaultedDestructorIsDeleted = true;
1060 data().NeedOverloadResolutionForCopyConstructor = true;
1061 data().NeedOverloadResolutionForMoveConstructor = true;
1062 data().NeedOverloadResolutionForCopyAssignment = true;
1063 data().NeedOverloadResolutionForMoveAssignment = true;
1064 data().NeedOverloadResolutionForDestructor = true;
1065 }
1066 } else if (!Context.getLangOpts().ObjCAutoRefCount) {
1067 setHasObjectMember(true);
1068 }
1069 } else if (!T.isCXX98PODType(Context))
1070 data().PlainOldData = false;
1071
1072 if (T->isReferenceType()) {
1073 if (!Field->hasInClassInitializer())
1074 data().HasUninitializedReferenceMember = true;
1075
1076 // C++0x [class]p7:
1077 // A standard-layout class is a class that:
1078 // -- has no non-static data members of type [...] reference,
1079 data().IsStandardLayout = false;
1080 data().IsCXX11StandardLayout = false;
1081
1082 // C++1z [class.copy.ctor]p10:
1083 // A defaulted copy constructor for a class X is defined as deleted if X has:
1084 // -- a non-static data member of rvalue reference type
1085 if (T->isRValueReferenceType())
1086 data().DefaultedCopyConstructorIsDeleted = true;
1087 }
1088
1089 if (!Field->hasInClassInitializer() && !Field->isMutable()) {
1090 if (CXXRecordDecl *FieldType = T->getAsCXXRecordDecl()) {
1091 if (FieldType->hasDefinition() && !FieldType->allowConstDefaultInit())
1092 data().HasUninitializedFields = true;
1093 } else {
1094 data().HasUninitializedFields = true;
1095 }
1096 }
1097
1098 // Record if this field is the first non-literal or volatile field or base.
1099 if (!T->isLiteralType(Context) || T.isVolatileQualified())
1100 data().HasNonLiteralTypeFieldsOrBases = true;
1101
1102 if (Field->hasInClassInitializer() ||
1103 (Field->isAnonymousStructOrUnion() &&
1104 Field->getType()->getAsCXXRecordDecl()->hasInClassInitializer())) {
1105 data().HasInClassInitializer = true;
1106
1107 // C++11 [class]p5:
1108 // A default constructor is trivial if [...] no non-static data member
1109 // of its class has a brace-or-equal-initializer.
1110 data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor;
1111
1112 // C++11 [dcl.init.aggr]p1:
1113 // An aggregate is a [...] class with [...] no
1114 // brace-or-equal-initializers for non-static data members.
1115 //
1116 // This rule was removed in C++14.
1118 data().Aggregate = false;
1119
1120 // C++11 [class]p10:
1121 // A POD struct is [...] a trivial class.
1122 data().PlainOldData = false;
1123 }
1124
1125 // C++11 [class.copy]p23:
1126 // A defaulted copy/move assignment operator for a class X is defined
1127 // as deleted if X has:
1128 // -- a non-static data member of reference type
1129 if (T->isReferenceType()) {
1130 data().DefaultedCopyAssignmentIsDeleted = true;
1131 data().DefaultedMoveAssignmentIsDeleted = true;
1132 }
1133
1134 // Bitfields of length 0 are also zero-sized, but we already bailed out for
1135 // those because they are always unnamed.
1136 bool IsZeroSize = Field->isZeroSize(Context);
1137
1138 if (const auto *RecordTy = T->getAs<RecordType>()) {
1139 auto *FieldRec = cast<CXXRecordDecl>(RecordTy->getDecl());
1140 if (FieldRec->getDefinition()) {
1141 addedClassSubobject(FieldRec);
1142
1143 // We may need to perform overload resolution to determine whether a
1144 // field can be moved if it's const or volatile qualified.
1145 if (T.getCVRQualifiers() & (Qualifiers::Const | Qualifiers::Volatile)) {
1146 // We need to care about 'const' for the copy constructor because an
1147 // implicit copy constructor might be declared with a non-const
1148 // parameter.
1149 data().NeedOverloadResolutionForCopyConstructor = true;
1150 data().NeedOverloadResolutionForMoveConstructor = true;
1151 data().NeedOverloadResolutionForCopyAssignment = true;
1152 data().NeedOverloadResolutionForMoveAssignment = true;
1153 }
1154
1155 // C++11 [class.ctor]p5, C++11 [class.copy]p11:
1156 // A defaulted [special member] for a class X is defined as
1157 // deleted if:
1158 // -- X is a union-like class that has a variant member with a
1159 // non-trivial [corresponding special member]
1160 if (isUnion()) {
1161 if (FieldRec->hasNonTrivialCopyConstructor())
1162 data().DefaultedCopyConstructorIsDeleted = true;
1163 if (FieldRec->hasNonTrivialMoveConstructor())
1164 data().DefaultedMoveConstructorIsDeleted = true;
1165 if (FieldRec->hasNonTrivialCopyAssignment())
1166 data().DefaultedCopyAssignmentIsDeleted = true;
1167 if (FieldRec->hasNonTrivialMoveAssignment())
1168 data().DefaultedMoveAssignmentIsDeleted = true;
1169 if (FieldRec->hasNonTrivialDestructor())
1170 data().DefaultedDestructorIsDeleted = true;
1171 }
1172
1173 // For an anonymous union member, our overload resolution will perform
1174 // overload resolution for its members.
1175 if (Field->isAnonymousStructOrUnion()) {
1176 data().NeedOverloadResolutionForCopyConstructor |=
1177 FieldRec->data().NeedOverloadResolutionForCopyConstructor;
1178 data().NeedOverloadResolutionForMoveConstructor |=
1179 FieldRec->data().NeedOverloadResolutionForMoveConstructor;
1180 data().NeedOverloadResolutionForCopyAssignment |=
1181 FieldRec->data().NeedOverloadResolutionForCopyAssignment;
1182 data().NeedOverloadResolutionForMoveAssignment |=
1183 FieldRec->data().NeedOverloadResolutionForMoveAssignment;
1184 data().NeedOverloadResolutionForDestructor |=
1185 FieldRec->data().NeedOverloadResolutionForDestructor;
1186 }
1187
1188 // C++0x [class.ctor]p5:
1189 // A default constructor is trivial [...] if:
1190 // -- for all the non-static data members of its class that are of
1191 // class type (or array thereof), each such class has a trivial
1192 // default constructor.
1193 if (!FieldRec->hasTrivialDefaultConstructor())
1194 data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor;
1195
1196 // C++0x [class.copy]p13:
1197 // A copy/move constructor for class X is trivial if [...]
1198 // [...]
1199 // -- for each non-static data member of X that is of class type (or
1200 // an array thereof), the constructor selected to copy/move that
1201 // member is trivial;
1202 if (!FieldRec->hasTrivialCopyConstructor())
1203 data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor;
1204
1205 if (!FieldRec->hasTrivialCopyConstructorForCall())
1206 data().HasTrivialSpecialMembersForCall &= ~SMF_CopyConstructor;
1207
1208 // If the field doesn't have a simple move constructor, we'll eagerly
1209 // declare the move constructor for this class and we'll decide whether
1210 // it's trivial then.
1211 if (!FieldRec->hasTrivialMoveConstructor())
1212 data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor;
1213
1214 if (!FieldRec->hasTrivialMoveConstructorForCall())
1215 data().HasTrivialSpecialMembersForCall &= ~SMF_MoveConstructor;
1216
1217 // C++0x [class.copy]p27:
1218 // A copy/move assignment operator for class X is trivial if [...]
1219 // [...]
1220 // -- for each non-static data member of X that is of class type (or
1221 // an array thereof), the assignment operator selected to
1222 // copy/move that member is trivial;
1223 if (!FieldRec->hasTrivialCopyAssignment())
1224 data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment;
1225 // If the field doesn't have a simple move assignment, we'll eagerly
1226 // declare the move assignment for this class and we'll decide whether
1227 // it's trivial then.
1228 if (!FieldRec->hasTrivialMoveAssignment())
1229 data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment;
1230
1231 if (!FieldRec->hasTrivialDestructor())
1232 data().HasTrivialSpecialMembers &= ~SMF_Destructor;
1233 if (!FieldRec->hasTrivialDestructorForCall())
1234 data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor;
1235 if (!FieldRec->hasIrrelevantDestructor())
1236 data().HasIrrelevantDestructor = false;
1237 if (FieldRec->isAnyDestructorNoReturn())
1238 data().IsAnyDestructorNoReturn = true;
1239 if (FieldRec->hasObjectMember())
1240 setHasObjectMember(true);
1241 if (FieldRec->hasVolatileMember())
1243 if (FieldRec->getArgPassingRestrictions() ==
1246
1247 // C++0x [class]p7:
1248 // A standard-layout class is a class that:
1249 // -- has no non-static data members of type non-standard-layout
1250 // class (or array of such types) [...]
1251 if (!FieldRec->isStandardLayout())
1252 data().IsStandardLayout = false;
1253 if (!FieldRec->isCXX11StandardLayout())
1254 data().IsCXX11StandardLayout = false;
1255
1256 // C++2a [class]p7:
1257 // A standard-layout class is a class that:
1258 // [...]
1259 // -- has no element of the set M(S) of types as a base class.
1260 if (data().IsStandardLayout &&
1261 (isUnion() || IsFirstField || IsZeroSize) &&
1262 hasSubobjectAtOffsetZeroOfEmptyBaseType(Context, FieldRec))
1263 data().IsStandardLayout = false;
1264
1265 // C++11 [class]p7:
1266 // A standard-layout class is a class that:
1267 // -- has no base classes of the same type as the first non-static
1268 // data member
1269 if (data().IsCXX11StandardLayout && IsFirstField) {
1270 // FIXME: We should check all base classes here, not just direct
1271 // base classes.
1272 for (const auto &BI : bases()) {
1273 if (Context.hasSameUnqualifiedType(BI.getType(), T)) {
1274 data().IsCXX11StandardLayout = false;
1275 break;
1276 }
1277 }
1278 }
1279
1280 // Keep track of the presence of mutable fields.
1281 if (FieldRec->hasMutableFields())
1282 data().HasMutableFields = true;
1283
1284 if (Field->isMutable()) {
1285 // Our copy constructor/assignment might call something other than
1286 // the subobject's copy constructor/assignment if it's mutable and of
1287 // class type.
1288 data().NeedOverloadResolutionForCopyConstructor = true;
1289 data().NeedOverloadResolutionForCopyAssignment = true;
1290 }
1291
1292 // C++11 [class.copy]p13:
1293 // If the implicitly-defined constructor would satisfy the
1294 // requirements of a constexpr constructor, the implicitly-defined
1295 // constructor is constexpr.
1296 // C++11 [dcl.constexpr]p4:
1297 // -- every constructor involved in initializing non-static data
1298 // members [...] shall be a constexpr constructor
1299 if (!Field->hasInClassInitializer() &&
1300 !FieldRec->hasConstexprDefaultConstructor() && !isUnion())
1301 // The standard requires any in-class initializer to be a constant
1302 // expression. We consider this to be a defect.
1303 data().DefaultedDefaultConstructorIsConstexpr =
1304 Context.getLangOpts().CPlusPlus23;
1305
1306 // C++11 [class.copy]p8:
1307 // The implicitly-declared copy constructor for a class X will have
1308 // the form 'X::X(const X&)' if each potentially constructed subobject
1309 // of a class type M (or array thereof) has a copy constructor whose
1310 // first parameter is of type 'const M&' or 'const volatile M&'.
1311 if (!FieldRec->hasCopyConstructorWithConstParam())
1312 data().ImplicitCopyConstructorCanHaveConstParamForNonVBase = false;
1313
1314 // C++11 [class.copy]p18:
1315 // The implicitly-declared copy assignment oeprator for a class X will
1316 // have the form 'X& X::operator=(const X&)' if [...] for all the
1317 // non-static data members of X that are of a class type M (or array
1318 // thereof), each such class type has a copy assignment operator whose
1319 // parameter is of type 'const M&', 'const volatile M&' or 'M'.
1320 if (!FieldRec->hasCopyAssignmentWithConstParam())
1321 data().ImplicitCopyAssignmentHasConstParam = false;
1322
1323 if (FieldRec->hasUninitializedReferenceMember() &&
1324 !Field->hasInClassInitializer())
1325 data().HasUninitializedReferenceMember = true;
1326
1327 // C++11 [class.union]p8, DR1460:
1328 // a non-static data member of an anonymous union that is a member of
1329 // X is also a variant member of X.
1330 if (FieldRec->hasVariantMembers() &&
1331 Field->isAnonymousStructOrUnion())
1332 data().HasVariantMembers = true;
1333 }
1334 } else {
1335 // Base element type of field is a non-class type.
1336 if (!T->isLiteralType(Context) ||
1337 (!Field->hasInClassInitializer() && !isUnion() &&
1338 !Context.getLangOpts().CPlusPlus20))
1339 data().DefaultedDefaultConstructorIsConstexpr = false;
1340
1341 // C++11 [class.copy]p23:
1342 // A defaulted copy/move assignment operator for a class X is defined
1343 // as deleted if X has:
1344 // -- a non-static data member of const non-class type (or array
1345 // thereof)
1346 if (T.isConstQualified()) {
1347 data().DefaultedCopyAssignmentIsDeleted = true;
1348 data().DefaultedMoveAssignmentIsDeleted = true;
1349 }
1350
1351 // C++20 [temp.param]p7:
1352 // A structural type is [...] a literal class type [for which] the
1353 // types of all non-static data members are structural types or
1354 // (possibly multidimensional) array thereof
1355 // We deal with class types elsewhere.
1356 if (!T->isStructuralType())
1357 data().StructuralIfLiteral = false;
1358 }
1359
1360 // C++14 [meta.unary.prop]p4:
1361 // T is a class type [...] with [...] no non-static data members other
1362 // than subobjects of zero size
1363 if (data().Empty && !IsZeroSize)
1364 data().Empty = false;
1365 }
1366
1367 // Handle using declarations of conversion functions.
1368 if (auto *Shadow = dyn_cast<UsingShadowDecl>(D)) {
1369 if (Shadow->getDeclName().getNameKind()
1371 ASTContext &Ctx = getASTContext();
1372 data().Conversions.get(Ctx).addDecl(Ctx, Shadow, Shadow->getAccess());
1373 }
1374 }
1375
1376 if (const auto *Using = dyn_cast<UsingDecl>(D)) {
1377 if (Using->getDeclName().getNameKind() ==
1379 data().HasInheritedConstructor = true;
1380 // C++1z [dcl.init.aggr]p1:
1381 // An aggregate is [...] a class [...] with no inherited constructors
1382 data().Aggregate = false;
1383 }
1384
1385 if (Using->getDeclName().getCXXOverloadedOperator() == OO_Equal)
1386 data().HasInheritedAssignment = true;
1387 }
1388}
1389
1391 const LangOptions &LangOpts = getLangOpts();
1392 if (!(LangOpts.CPlusPlus20 ? hasConstexprDestructor()
1394 return false;
1395
1397 // CWG2598
1398 // is an aggregate union type that has either no variant
1399 // members or at least one variant member of non-volatile literal type,
1400 if (!isUnion())
1401 return false;
1402 bool HasAtLeastOneLiteralMember =
1403 fields().empty() || any_of(fields(), [this](const FieldDecl *D) {
1404 return !D->getType().isVolatileQualified() &&
1406 });
1407 if (!HasAtLeastOneLiteralMember)
1408 return false;
1409 }
1410
1411 return isAggregate() || (isLambda() && LangOpts.CPlusPlus17) ||
1413}
1414
1416 DD->setIneligibleOrNotSelected(false);
1417 addedEligibleSpecialMemberFunction(DD, SMF_Destructor);
1418}
1419
1421 unsigned SMKind) {
1422 // FIXME: We shouldn't change DeclaredNonTrivialSpecialMembers if `MD` is
1423 // a function template, but this needs CWG attention before we break ABI.
1424 // See https://github.com/llvm/llvm-project/issues/59206
1425
1426 if (const auto *DD = dyn_cast<CXXDestructorDecl>(MD)) {
1427 if (DD->isUserProvided())
1428 data().HasIrrelevantDestructor = false;
1429 // If the destructor is explicitly defaulted and not trivial or not public
1430 // or if the destructor is deleted, we clear HasIrrelevantDestructor in
1431 // finishedDefaultedOrDeletedMember.
1432
1433 // C++11 [class.dtor]p5:
1434 // A destructor is trivial if [...] the destructor is not virtual.
1435 if (DD->isVirtual()) {
1436 data().HasTrivialSpecialMembers &= ~SMF_Destructor;
1437 data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor;
1438 }
1439
1440 if (DD->isNoReturn())
1441 data().IsAnyDestructorNoReturn = true;
1442 }
1443
1444 if (!MD->isImplicit() && !MD->isUserProvided()) {
1445 // This method is user-declared but not user-provided. We can't work
1446 // out whether it's trivial yet (not until we get to the end of the
1447 // class). We'll handle this method in
1448 // finishedDefaultedOrDeletedMember.
1449 } else if (MD->isTrivial()) {
1450 data().HasTrivialSpecialMembers |= SMKind;
1451 data().HasTrivialSpecialMembersForCall |= SMKind;
1452 } else if (MD->isTrivialForCall()) {
1453 data().HasTrivialSpecialMembersForCall |= SMKind;
1454 data().DeclaredNonTrivialSpecialMembers |= SMKind;
1455 } else {
1456 data().DeclaredNonTrivialSpecialMembers |= SMKind;
1457 // If this is a user-provided function, do not set
1458 // DeclaredNonTrivialSpecialMembersForCall here since we don't know
1459 // yet whether the method would be considered non-trivial for the
1460 // purpose of calls (attribute "trivial_abi" can be dropped from the
1461 // class later, which can change the special method's triviality).
1462 if (!MD->isUserProvided())
1463 data().DeclaredNonTrivialSpecialMembersForCall |= SMKind;
1464 }
1465}
1466
1468 assert(!D->isImplicit() && !D->isUserProvided());
1469
1470 // The kind of special member this declaration is, if any.
1471 unsigned SMKind = 0;
1472
1473 if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(D)) {
1474 if (Constructor->isDefaultConstructor()) {
1475 SMKind |= SMF_DefaultConstructor;
1476 if (Constructor->isConstexpr())
1477 data().HasConstexprDefaultConstructor = true;
1478 }
1479 if (Constructor->isCopyConstructor())
1480 SMKind |= SMF_CopyConstructor;
1481 else if (Constructor->isMoveConstructor())
1482 SMKind |= SMF_MoveConstructor;
1483 else if (Constructor->isConstexpr())
1484 // We may now know that the constructor is constexpr.
1485 data().HasConstexprNonCopyMoveConstructor = true;
1486 } else if (isa<CXXDestructorDecl>(D)) {
1487 SMKind |= SMF_Destructor;
1488 if (!D->isTrivial() || D->getAccess() != AS_public || D->isDeleted())
1489 data().HasIrrelevantDestructor = false;
1490 } else if (D->isCopyAssignmentOperator())
1491 SMKind |= SMF_CopyAssignment;
1492 else if (D->isMoveAssignmentOperator())
1493 SMKind |= SMF_MoveAssignment;
1494
1495 // Update which trivial / non-trivial special members we have.
1496 // addedMember will have skipped this step for this member.
1497 if (!D->isIneligibleOrNotSelected()) {
1498 if (D->isTrivial())
1499 data().HasTrivialSpecialMembers |= SMKind;
1500 else
1501 data().DeclaredNonTrivialSpecialMembers |= SMKind;
1502 }
1503}
1504
1505void CXXRecordDecl::LambdaDefinitionData::AddCaptureList(ASTContext &Ctx,
1506 Capture *CaptureList) {
1507 Captures.push_back(CaptureList);
1508 if (Captures.size() == 2) {
1509 // The TinyPtrVector member now needs destruction.
1510 Ctx.addDestruction(&Captures);
1511 }
1512}
1513
1515 ArrayRef<LambdaCapture> Captures) {
1516 CXXRecordDecl::LambdaDefinitionData &Data = getLambdaData();
1517
1518 // Copy captures.
1519 Data.NumCaptures = Captures.size();
1520 Data.NumExplicitCaptures = 0;
1521 auto *ToCapture = (LambdaCapture *)Context.Allocate(sizeof(LambdaCapture) *
1522 Captures.size());
1523 Data.AddCaptureList(Context, ToCapture);
1524 for (unsigned I = 0, N = Captures.size(); I != N; ++I) {
1525 if (Captures[I].isExplicit())
1526 ++Data.NumExplicitCaptures;
1527
1528 new (ToCapture) LambdaCapture(Captures[I]);
1529 ToCapture++;
1530 }
1531
1533 Data.DefaultedCopyAssignmentIsDeleted = true;
1534}
1535
1537 unsigned SMKind = 0;
1538
1539 if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(D)) {
1540 if (Constructor->isCopyConstructor())
1541 SMKind = SMF_CopyConstructor;
1542 else if (Constructor->isMoveConstructor())
1543 SMKind = SMF_MoveConstructor;
1544 } else if (isa<CXXDestructorDecl>(D))
1545 SMKind = SMF_Destructor;
1546
1547 if (D->isTrivialForCall())
1548 data().HasTrivialSpecialMembersForCall |= SMKind;
1549 else
1550 data().DeclaredNonTrivialSpecialMembersForCall |= SMKind;
1551}
1552
1554 if (getTagKind() == TagTypeKind::Class ||
1556 !TemplateOrInstantiation.isNull())
1557 return false;
1558 if (!hasDefinition())
1559 return true;
1560
1561 return isPOD() && data().HasOnlyCMembers;
1562}
1563
1565 if (!isLambda()) return false;
1566 return getLambdaData().IsGenericLambda;
1567}
1568
1569#ifndef NDEBUG
1571 return llvm::all_of(R, [&](NamedDecl *D) {
1572 return D->isInvalidDecl() || declaresSameEntity(D, R.front());
1573 });
1574}
1575#endif
1576
1578 if (!RD.isLambda()) return nullptr;
1579 DeclarationName Name =
1581 DeclContext::lookup_result Calls = RD.lookup(Name);
1582
1583 assert(!Calls.empty() && "Missing lambda call operator!");
1584 assert(allLookupResultsAreTheSame(Calls) &&
1585 "More than one lambda call operator!");
1586 return Calls.front();
1587}
1588
1590 NamedDecl *CallOp = getLambdaCallOperatorHelper(*this);
1591 return dyn_cast_or_null<FunctionTemplateDecl>(CallOp);
1592}
1593
1595 NamedDecl *CallOp = getLambdaCallOperatorHelper(*this);
1596
1597 if (CallOp == nullptr)
1598 return nullptr;
1599
1600 if (const auto *CallOpTmpl = dyn_cast<FunctionTemplateDecl>(CallOp))
1601 return cast<CXXMethodDecl>(CallOpTmpl->getTemplatedDecl());
1602
1603 return cast<CXXMethodDecl>(CallOp);
1604}
1605
1608 CallingConv CC = CallOp->getType()->castAs<FunctionType>()->getCallConv();
1609 return getLambdaStaticInvoker(CC);
1610}
1611
1614 assert(RD.isLambda() && "Must be a lambda");
1615 DeclarationName Name =
1617 return RD.lookup(Name);
1618}
1619
1621 if (const auto *InvokerTemplate = dyn_cast<FunctionTemplateDecl>(ND))
1622 return cast<CXXMethodDecl>(InvokerTemplate->getTemplatedDecl());
1623 return cast<CXXMethodDecl>(ND);
1624}
1625
1627 if (!isLambda())
1628 return nullptr;
1630
1631 for (NamedDecl *ND : Invoker) {
1632 const auto *FTy =
1633 cast<ValueDecl>(ND->getAsFunction())->getType()->castAs<FunctionType>();
1634 if (FTy->getCallConv() == CC)
1635 return getInvokerAsMethod(ND);
1636 }
1637
1638 return nullptr;
1639}
1640
1642 llvm::DenseMap<const ValueDecl *, FieldDecl *> &Captures,
1643 FieldDecl *&ThisCapture) const {
1644 Captures.clear();
1645 ThisCapture = nullptr;
1646
1647 LambdaDefinitionData &Lambda = getLambdaData();
1648 for (const LambdaCapture *List : Lambda.Captures) {
1650 for (const LambdaCapture *C = List, *CEnd = C + Lambda.NumCaptures;
1651 C != CEnd; ++C, ++Field) {
1652 if (C->capturesThis())
1653 ThisCapture = *Field;
1654 else if (C->capturesVariable())
1655 Captures[C->getCapturedVar()] = *Field;
1656 }
1657 assert(Field == field_end());
1658 }
1659}
1660
1663 if (!isGenericLambda()) return nullptr;
1666 return Tmpl->getTemplateParameters();
1667 return nullptr;
1668}
1669
1673 if (!List)
1674 return {};
1675
1676 assert(std::is_partitioned(List->begin(), List->end(),
1677 [](const NamedDecl *D) { return !D->isImplicit(); })
1678 && "Explicit template params should be ordered before implicit ones");
1679
1680 const auto ExplicitEnd = llvm::partition_point(
1681 *List, [](const NamedDecl *D) { return !D->isImplicit(); });
1682 return llvm::ArrayRef(List->begin(), ExplicitEnd);
1683}
1684
1686 assert(isLambda() && "Not a lambda closure type!");
1688 return getLambdaData().ContextDecl.get(Source);
1689}
1690
1692 assert(isLambda() && "Not a lambda closure type!");
1693 getLambdaData().ManglingNumber = Numbering.ManglingNumber;
1694 if (Numbering.DeviceManglingNumber)
1695 getASTContext().DeviceLambdaManglingNumbers[this] =
1696 Numbering.DeviceManglingNumber;
1697 getLambdaData().IndexInContext = Numbering.IndexInContext;
1698 getLambdaData().ContextDecl = Numbering.ContextDecl;
1699 getLambdaData().HasKnownInternalLinkage = Numbering.HasKnownInternalLinkage;
1700}
1701
1703 assert(isLambda() && "Not a lambda closure type!");
1704 return getASTContext().DeviceLambdaManglingNumbers.lookup(this);
1705}
1706
1708 QualType T =
1709 cast<CXXConversionDecl>(Conv->getUnderlyingDecl()->getAsFunction())
1710 ->getConversionType();
1711 return Context.getCanonicalType(T);
1712}
1713
1714/// Collect the visible conversions of a base class.
1715///
1716/// \param Record a base class of the class we're considering
1717/// \param InVirtual whether this base class is a virtual base (or a base
1718/// of a virtual base)
1719/// \param Access the access along the inheritance path to this base
1720/// \param ParentHiddenTypes the conversions provided by the inheritors
1721/// of this base
1722/// \param Output the set to which to add conversions from non-virtual bases
1723/// \param VOutput the set to which to add conversions from virtual bases
1724/// \param HiddenVBaseCs the set of conversions which were hidden in a
1725/// virtual base along some inheritance path
1727 ASTContext &Context, const CXXRecordDecl *Record, bool InVirtual,
1728 AccessSpecifier Access,
1729 const llvm::SmallPtrSet<CanQualType, 8> &ParentHiddenTypes,
1730 ASTUnresolvedSet &Output, UnresolvedSetImpl &VOutput,
1731 llvm::SmallPtrSet<NamedDecl *, 8> &HiddenVBaseCs) {
1732 // The set of types which have conversions in this class or its
1733 // subclasses. As an optimization, we don't copy the derived set
1734 // unless it might change.
1735 const llvm::SmallPtrSet<CanQualType, 8> *HiddenTypes = &ParentHiddenTypes;
1736 llvm::SmallPtrSet<CanQualType, 8> HiddenTypesBuffer;
1737
1738 // Collect the direct conversions and figure out which conversions
1739 // will be hidden in the subclasses.
1740 CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin();
1741 CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end();
1742 if (ConvI != ConvE) {
1743 HiddenTypesBuffer = ParentHiddenTypes;
1744 HiddenTypes = &HiddenTypesBuffer;
1745
1746 for (CXXRecordDecl::conversion_iterator I = ConvI; I != ConvE; ++I) {
1747 CanQualType ConvType(GetConversionType(Context, I.getDecl()));
1748 bool Hidden = ParentHiddenTypes.count(ConvType);
1749 if (!Hidden)
1750 HiddenTypesBuffer.insert(ConvType);
1751
1752 // If this conversion is hidden and we're in a virtual base,
1753 // remember that it's hidden along some inheritance path.
1754 if (Hidden && InVirtual)
1755 HiddenVBaseCs.insert(cast<NamedDecl>(I.getDecl()->getCanonicalDecl()));
1756
1757 // If this conversion isn't hidden, add it to the appropriate output.
1758 else if (!Hidden) {
1759 AccessSpecifier IAccess
1760 = CXXRecordDecl::MergeAccess(Access, I.getAccess());
1761
1762 if (InVirtual)
1763 VOutput.addDecl(I.getDecl(), IAccess);
1764 else
1765 Output.addDecl(Context, I.getDecl(), IAccess);
1766 }
1767 }
1768 }
1769
1770 // Collect information recursively from any base classes.
1771 for (const auto &I : Record->bases()) {
1772 const auto *RT = I.getType()->getAs<RecordType>();
1773 if (!RT) continue;
1774
1775 AccessSpecifier BaseAccess
1776 = CXXRecordDecl::MergeAccess(Access, I.getAccessSpecifier());
1777 bool BaseInVirtual = InVirtual || I.isVirtual();
1778
1779 auto *Base = cast<CXXRecordDecl>(RT->getDecl());
1780 CollectVisibleConversions(Context, Base, BaseInVirtual, BaseAccess,
1781 *HiddenTypes, Output, VOutput, HiddenVBaseCs);
1782 }
1783}
1784
1785/// Collect the visible conversions of a class.
1786///
1787/// This would be extremely straightforward if it weren't for virtual
1788/// bases. It might be worth special-casing that, really.
1790 const CXXRecordDecl *Record,
1791 ASTUnresolvedSet &Output) {
1792 // The collection of all conversions in virtual bases that we've
1793 // found. These will be added to the output as long as they don't
1794 // appear in the hidden-conversions set.
1795 UnresolvedSet<8> VBaseCs;
1796
1797 // The set of conversions in virtual bases that we've determined to
1798 // be hidden.
1800
1801 // The set of types hidden by classes derived from this one.
1803
1804 // Go ahead and collect the direct conversions and add them to the
1805 // hidden-types set.
1806 CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin();
1807 CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end();
1808 Output.append(Context, ConvI, ConvE);
1809 for (; ConvI != ConvE; ++ConvI)
1810 HiddenTypes.insert(GetConversionType(Context, ConvI.getDecl()));
1811
1812 // Recursively collect conversions from base classes.
1813 for (const auto &I : Record->bases()) {
1814 const auto *RT = I.getType()->getAs<RecordType>();
1815 if (!RT) continue;
1816
1817 CollectVisibleConversions(Context, cast<CXXRecordDecl>(RT->getDecl()),
1818 I.isVirtual(), I.getAccessSpecifier(),
1819 HiddenTypes, Output, VBaseCs, HiddenVBaseCs);
1820 }
1821
1822 // Add any unhidden conversions provided by virtual bases.
1823 for (UnresolvedSetIterator I = VBaseCs.begin(), E = VBaseCs.end();
1824 I != E; ++I) {
1825 if (!HiddenVBaseCs.count(cast<NamedDecl>(I.getDecl()->getCanonicalDecl())))
1826 Output.addDecl(Context, I.getDecl(), I.getAccess());
1827 }
1828}
1829
1830/// getVisibleConversionFunctions - get all conversion functions visible
1831/// in current class; including conversion function templates.
1832llvm::iterator_range<CXXRecordDecl::conversion_iterator>
1834 ASTContext &Ctx = getASTContext();
1835
1837 if (bases_begin() == bases_end()) {
1838 // If root class, all conversions are visible.
1839 Set = &data().Conversions.get(Ctx);
1840 } else {
1841 Set = &data().VisibleConversions.get(Ctx);
1842 // If visible conversion list is not evaluated, evaluate it.
1843 if (!data().ComputedVisibleConversions) {
1844 CollectVisibleConversions(Ctx, this, *Set);
1845 data().ComputedVisibleConversions = true;
1846 }
1847 }
1848 return llvm::make_range(Set->begin(), Set->end());
1849}
1850
1852 // This operation is O(N) but extremely rare. Sema only uses it to
1853 // remove UsingShadowDecls in a class that were followed by a direct
1854 // declaration, e.g.:
1855 // class A : B {
1856 // using B::operator int;
1857 // operator int();
1858 // };
1859 // This is uncommon by itself and even more uncommon in conjunction
1860 // with sufficiently large numbers of directly-declared conversions
1861 // that asymptotic behavior matters.
1862
1863 ASTUnresolvedSet &Convs = data().Conversions.get(getASTContext());
1864 for (unsigned I = 0, E = Convs.size(); I != E; ++I) {
1865 if (Convs[I].getDecl() == ConvDecl) {
1866 Convs.erase(I);
1867 assert(!llvm::is_contained(Convs, ConvDecl) &&
1868 "conversion was found multiple times in unresolved set");
1869 return;
1870 }
1871 }
1872
1873 llvm_unreachable("conversion not found in set!");
1874}
1875
1878 return cast<CXXRecordDecl>(MSInfo->getInstantiatedFrom());
1879
1880 return nullptr;
1881}
1882
1884 return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>();
1885}
1886
1887void
1890 assert(TemplateOrInstantiation.isNull() &&
1891 "Previous template or instantiation?");
1892 assert(!isa<ClassTemplatePartialSpecializationDecl>(this));
1893 TemplateOrInstantiation
1894 = new (getASTContext()) MemberSpecializationInfo(RD, TSK);
1895}
1896
1898 return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl *>();
1899}
1900
1902 TemplateOrInstantiation = Template;
1903}
1904
1906 if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(this))
1907 return Spec->getSpecializationKind();
1908
1910 return MSInfo->getTemplateSpecializationKind();
1911
1912 return TSK_Undeclared;
1913}
1914
1915void
1917 if (auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(this)) {
1918 Spec->setSpecializationKind(TSK);
1919 return;
1920 }
1921
1923 MSInfo->setTemplateSpecializationKind(TSK);
1924 return;
1925 }
1926
1927 llvm_unreachable("Not a class template or member class specialization");
1928}
1929
1931 auto GetDefinitionOrSelf =
1932 [](const CXXRecordDecl *D) -> const CXXRecordDecl * {
1933 if (auto *Def = D->getDefinition())
1934 return Def;
1935 return D;
1936 };
1937
1938 // If it's a class template specialization, find the template or partial
1939 // specialization from which it was instantiated.
1940 if (auto *TD = dyn_cast<ClassTemplateSpecializationDecl>(this)) {
1941 auto From = TD->getInstantiatedFrom();
1942 if (auto *CTD = From.dyn_cast<ClassTemplateDecl *>()) {
1943 while (auto *NewCTD = CTD->getInstantiatedFromMemberTemplate()) {
1944 if (NewCTD->isMemberSpecialization())
1945 break;
1946 CTD = NewCTD;
1947 }
1948 return GetDefinitionOrSelf(CTD->getTemplatedDecl());
1949 }
1950 if (auto *CTPSD =
1951 From.dyn_cast<ClassTemplatePartialSpecializationDecl *>()) {
1952 while (auto *NewCTPSD = CTPSD->getInstantiatedFromMember()) {
1953 if (NewCTPSD->isMemberSpecialization())
1954 break;
1955 CTPSD = NewCTPSD;
1956 }
1957 return GetDefinitionOrSelf(CTPSD);
1958 }
1959 }
1960
1962 if (isTemplateInstantiation(MSInfo->getTemplateSpecializationKind())) {
1963 const CXXRecordDecl *RD = this;
1964 while (auto *NewRD = RD->getInstantiatedFromMemberClass())
1965 RD = NewRD;
1966 return GetDefinitionOrSelf(RD);
1967 }
1968 }
1969
1971 "couldn't find pattern for class template instantiation");
1972 return nullptr;
1973}
1974
1976 ASTContext &Context = getASTContext();
1977 QualType ClassType = Context.getTypeDeclType(this);
1978
1979 DeclarationName Name
1981 Context.getCanonicalType(ClassType));
1982
1984
1985 // If a destructor was marked as not selected, we skip it. We don't always
1986 // have a selected destructor: dependent types, unnamed structs.
1987 for (auto *Decl : R) {
1988 auto* DD = dyn_cast<CXXDestructorDecl>(Decl);
1989 if (DD && !DD->isIneligibleOrNotSelected())
1990 return DD;
1991 }
1992 return nullptr;
1993}
1994
1996 while (!DC->isTranslationUnit()) {
1997 if (DC->isNamespace())
1998 return true;
1999 DC = DC->getParent();
2000 }
2001 return false;
2002}
2003
2005 assert(hasDefinition() && "checking for interface-like without a definition");
2006 // All __interfaces are inheritently interface-like.
2007 if (isInterface())
2008 return true;
2009
2010 // Interface-like types cannot have a user declared constructor, destructor,
2011 // friends, VBases, conversion functions, or fields. Additionally, lambdas
2012 // cannot be interface types.
2015 getNumVBases() > 0 || conversion_end() - conversion_begin() > 0)
2016 return false;
2017
2018 // No interface-like type can have a method with a definition.
2019 for (const auto *const Method : methods())
2020 if (Method->isDefined() && !Method->isImplicit())
2021 return false;
2022
2023 // Check "Special" types.
2024 const auto *Uuid = getAttr<UuidAttr>();
2025 // MS SDK declares IUnknown/IDispatch both in the root of a TU, or in an
2026 // extern C++ block directly in the TU. These are only valid if in one
2027 // of these two situations.
2028 if (Uuid && isStruct() && !getDeclContext()->isExternCContext() &&
2030 ((getName() == "IUnknown" &&
2031 Uuid->getGuid() == "00000000-0000-0000-C000-000000000046") ||
2032 (getName() == "IDispatch" &&
2033 Uuid->getGuid() == "00020400-0000-0000-C000-000000000046"))) {
2034 if (getNumBases() > 0)
2035 return false;
2036 return true;
2037 }
2038
2039 // FIXME: Any access specifiers is supposed to make this no longer interface
2040 // like.
2041
2042 // If this isn't a 'special' type, it must have a single interface-like base.
2043 if (getNumBases() != 1)
2044 return false;
2045
2046 const auto BaseSpec = *bases_begin();
2047 if (BaseSpec.isVirtual() || BaseSpec.getAccessSpecifier() != AS_public)
2048 return false;
2049 const auto *Base = BaseSpec.getType()->getAsCXXRecordDecl();
2050 if (Base->isInterface() || !Base->isInterfaceLike())
2051 return false;
2052 return true;
2053}
2054
2056 completeDefinition(nullptr);
2057}
2058
2061
2062 // If the class may be abstract (but hasn't been marked as such), check for
2063 // any pure final overriders.
2064 if (mayBeAbstract()) {
2065 CXXFinalOverriderMap MyFinalOverriders;
2066 if (!FinalOverriders) {
2067 getFinalOverriders(MyFinalOverriders);
2068 FinalOverriders = &MyFinalOverriders;
2069 }
2070
2071 bool Done = false;
2072 for (CXXFinalOverriderMap::iterator M = FinalOverriders->begin(),
2073 MEnd = FinalOverriders->end();
2074 M != MEnd && !Done; ++M) {
2075 for (OverridingMethods::iterator SO = M->second.begin(),
2076 SOEnd = M->second.end();
2077 SO != SOEnd && !Done; ++SO) {
2078 assert(SO->second.size() > 0 &&
2079 "All virtual functions have overriding virtual functions");
2080
2081 // C++ [class.abstract]p4:
2082 // A class is abstract if it contains or inherits at least one
2083 // pure virtual function for which the final overrider is pure
2084 // virtual.
2085 if (SO->second.front().Method->isPureVirtual()) {
2086 data().Abstract = true;
2087 Done = true;
2088 break;
2089 }
2090 }
2091 }
2092 }
2093
2094 // Set access bits correctly on the directly-declared conversions.
2096 I != E; ++I)
2097 I.setAccess((*I)->getAccess());
2098}
2099
2101 if (data().Abstract || isInvalidDecl() || !data().Polymorphic ||
2103 return false;
2104
2105 for (const auto &B : bases()) {
2106 const auto *BaseDecl =
2107 cast<CXXRecordDecl>(B.getType()->castAs<RecordType>()->getDecl());
2108 if (BaseDecl->isAbstract())
2109 return true;
2110 }
2111
2112 return false;
2113}
2114
2116 auto *Def = getDefinition();
2117 if (!Def)
2118 return false;
2119 if (Def->hasAttr<FinalAttr>())
2120 return true;
2121 if (const auto *Dtor = Def->getDestructor())
2122 if (Dtor->hasAttr<FinalAttr>())
2123 return true;
2124 return false;
2125}
2126
2127void CXXDeductionGuideDecl::anchor() {}
2128
2130 if ((getKind() != Other.getKind() ||
2133 Other.getKind() == ExplicitSpecKind::Unresolved) {
2134 ODRHash SelfHash, OtherHash;
2135 SelfHash.AddStmt(getExpr());
2136 OtherHash.AddStmt(Other.getExpr());
2137 return SelfHash.CalculateHash() == OtherHash.CalculateHash();
2138 } else
2139 return false;
2140 }
2141 return true;
2142}
2143
2145 switch (Function->getDeclKind()) {
2146 case Decl::Kind::CXXConstructor:
2147 return cast<CXXConstructorDecl>(Function)->getExplicitSpecifier();
2148 case Decl::Kind::CXXConversion:
2149 return cast<CXXConversionDecl>(Function)->getExplicitSpecifier();
2150 case Decl::Kind::CXXDeductionGuide:
2151 return cast<CXXDeductionGuideDecl>(Function)->getExplicitSpecifier();
2152 default:
2153 return {};
2154 }
2155}
2156
2158 ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
2159 ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T,
2160 TypeSourceInfo *TInfo, SourceLocation EndLocation, CXXConstructorDecl *Ctor,
2161 DeductionCandidate Kind) {
2162 return new (C, DC) CXXDeductionGuideDecl(C, DC, StartLoc, ES, NameInfo, T,
2163 TInfo, EndLocation, Ctor, Kind);
2164}
2165
2168 return new (C, ID) CXXDeductionGuideDecl(
2170 QualType(), nullptr, SourceLocation(), nullptr,
2172}
2173
2175 ASTContext &C, DeclContext *DC, SourceLocation StartLoc) {
2176 return new (C, DC) RequiresExprBodyDecl(C, DC, StartLoc);
2177}
2178
2181 return new (C, ID) RequiresExprBodyDecl(C, nullptr, SourceLocation());
2182}
2183
2184void CXXMethodDecl::anchor() {}
2185
2187 const CXXMethodDecl *MD = getCanonicalDecl();
2188
2189 if (MD->getStorageClass() == SC_Static)
2190 return true;
2191
2193 return isStaticOverloadedOperator(OOK);
2194}
2195
2196static bool recursivelyOverrides(const CXXMethodDecl *DerivedMD,
2197 const CXXMethodDecl *BaseMD) {
2198 for (const CXXMethodDecl *MD : DerivedMD->overridden_methods()) {
2199 if (MD->getCanonicalDecl() == BaseMD->getCanonicalDecl())
2200 return true;
2201 if (recursivelyOverrides(MD, BaseMD))
2202 return true;
2203 }
2204 return false;
2205}
2206
2209 bool MayBeBase) {
2210 if (this->getParent()->getCanonicalDecl() == RD->getCanonicalDecl())
2211 return this;
2212
2213 // Lookup doesn't work for destructors, so handle them separately.
2214 if (isa<CXXDestructorDecl>(this)) {
2215 CXXMethodDecl *MD = RD->getDestructor();
2216 if (MD) {
2217 if (recursivelyOverrides(MD, this))
2218 return MD;
2219 if (MayBeBase && recursivelyOverrides(this, MD))
2220 return MD;
2221 }
2222 return nullptr;
2223 }
2224
2225 for (auto *ND : RD->lookup(getDeclName())) {
2226 auto *MD = dyn_cast<CXXMethodDecl>(ND);
2227 if (!MD)
2228 continue;
2229 if (recursivelyOverrides(MD, this))
2230 return MD;
2231 if (MayBeBase && recursivelyOverrides(this, MD))
2232 return MD;
2233 }
2234
2235 return nullptr;
2236}
2237
2240 bool MayBeBase) {
2241 if (auto *MD = getCorrespondingMethodDeclaredInClass(RD, MayBeBase))
2242 return MD;
2243
2245 auto AddFinalOverrider = [&](CXXMethodDecl *D) {
2246 // If this function is overridden by a candidate final overrider, it is not
2247 // a final overrider.
2248 for (CXXMethodDecl *OtherD : FinalOverriders) {
2249 if (declaresSameEntity(D, OtherD) || recursivelyOverrides(OtherD, D))
2250 return;
2251 }
2252
2253 // Other candidate final overriders might be overridden by this function.
2254 llvm::erase_if(FinalOverriders, [&](CXXMethodDecl *OtherD) {
2255 return recursivelyOverrides(D, OtherD);
2256 });
2257
2258 FinalOverriders.push_back(D);
2259 };
2260
2261 for (const auto &I : RD->bases()) {
2262 const RecordType *RT = I.getType()->getAs<RecordType>();
2263 if (!RT)
2264 continue;
2265 const auto *Base = cast<CXXRecordDecl>(RT->getDecl());
2266 if (CXXMethodDecl *D = this->getCorrespondingMethodInClass(Base))
2267 AddFinalOverrider(D);
2268 }
2269
2270 return FinalOverriders.size() == 1 ? FinalOverriders.front() : nullptr;
2271}
2272
2275 const DeclarationNameInfo &NameInfo, QualType T,
2276 TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin,
2277 bool isInline, ConstexprSpecKind ConstexprKind,
2278 SourceLocation EndLocation,
2279 Expr *TrailingRequiresClause) {
2280 return new (C, RD) CXXMethodDecl(
2281 CXXMethod, C, RD, StartLoc, NameInfo, T, TInfo, SC, UsesFPIntrin,
2282 isInline, ConstexprKind, EndLocation, TrailingRequiresClause);
2283}
2284
2286 GlobalDeclID ID) {
2287 return new (C, ID) CXXMethodDecl(
2288 CXXMethod, C, nullptr, SourceLocation(), DeclarationNameInfo(),
2289 QualType(), nullptr, SC_None, false, false,
2291}
2292
2294 bool IsAppleKext) {
2295 assert(isVirtual() && "this method is expected to be virtual");
2296
2297 // When building with -fapple-kext, all calls must go through the vtable since
2298 // the kernel linker can do runtime patching of vtables.
2299 if (IsAppleKext)
2300 return nullptr;
2301
2302 // If the member function is marked 'final', we know that it can't be
2303 // overridden and can therefore devirtualize it unless it's pure virtual.
2304 if (hasAttr<FinalAttr>())
2305 return isPureVirtual() ? nullptr : this;
2306
2307 // If Base is unknown, we cannot devirtualize.
2308 if (!Base)
2309 return nullptr;
2310
2311 // If the base expression (after skipping derived-to-base conversions) is a
2312 // class prvalue, then we can devirtualize.
2313 Base = Base->getBestDynamicClassTypeExpr();
2314 if (Base->isPRValue() && Base->getType()->isRecordType())
2315 return this;
2316
2317 // If we don't even know what we would call, we can't devirtualize.
2318 const CXXRecordDecl *BestDynamicDecl = Base->getBestDynamicClassType();
2319 if (!BestDynamicDecl)
2320 return nullptr;
2321
2322 // There may be a method corresponding to MD in a derived class.
2323 CXXMethodDecl *DevirtualizedMethod =
2324 getCorrespondingMethodInClass(BestDynamicDecl);
2325
2326 // If there final overrider in the dynamic type is ambiguous, we can't
2327 // devirtualize this call.
2328 if (!DevirtualizedMethod)
2329 return nullptr;
2330
2331 // If that method is pure virtual, we can't devirtualize. If this code is
2332 // reached, the result would be UB, not a direct call to the derived class
2333 // function, and we can't assume the derived class function is defined.
2334 if (DevirtualizedMethod->isPureVirtual())
2335 return nullptr;
2336
2337 // If that method is marked final, we can devirtualize it.
2338 if (DevirtualizedMethod->hasAttr<FinalAttr>())
2339 return DevirtualizedMethod;
2340
2341 // Similarly, if the class itself or its destructor is marked 'final',
2342 // the class can't be derived from and we can therefore devirtualize the
2343 // member function call.
2344 if (BestDynamicDecl->isEffectivelyFinal())
2345 return DevirtualizedMethod;
2346
2347 if (const auto *DRE = dyn_cast<DeclRefExpr>(Base)) {
2348 if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl()))
2349 if (VD->getType()->isRecordType())
2350 // This is a record decl. We know the type and can devirtualize it.
2351 return DevirtualizedMethod;
2352
2353 return nullptr;
2354 }
2355
2356 // We can devirtualize calls on an object accessed by a class member access
2357 // expression, since by C++11 [basic.life]p6 we know that it can't refer to
2358 // a derived class object constructed in the same location.
2359 if (const auto *ME = dyn_cast<MemberExpr>(Base)) {
2360 const ValueDecl *VD = ME->getMemberDecl();
2361 return VD->getType()->isRecordType() ? DevirtualizedMethod : nullptr;
2362 }
2363
2364 // Likewise for calls on an object accessed by a (non-reference) pointer to
2365 // member access.
2366 if (auto *BO = dyn_cast<BinaryOperator>(Base)) {
2367 if (BO->isPtrMemOp()) {
2368 auto *MPT = BO->getRHS()->getType()->castAs<MemberPointerType>();
2369 if (MPT->getPointeeType()->isRecordType())
2370 return DevirtualizedMethod;
2371 }
2372 }
2373
2374 // We can't devirtualize the call.
2375 return nullptr;
2376}
2377
2379 SmallVectorImpl<const FunctionDecl *> &PreventedBy) const {
2380 assert(PreventedBy.empty() && "PreventedBy is expected to be empty");
2381 if (getOverloadedOperator() != OO_Delete &&
2382 getOverloadedOperator() != OO_Array_Delete)
2383 return false;
2384
2385 // C++ [basic.stc.dynamic.deallocation]p2:
2386 // A template instance is never a usual deallocation function,
2387 // regardless of its signature.
2388 if (getPrimaryTemplate())
2389 return false;
2390
2391 // C++ [basic.stc.dynamic.deallocation]p2:
2392 // If a class T has a member deallocation function named operator delete
2393 // with exactly one parameter, then that function is a usual (non-placement)
2394 // deallocation function. [...]
2395 if (getNumParams() == 1)
2396 return true;
2397 unsigned UsualParams = 1;
2398
2399 // C++ P0722:
2400 // A destroying operator delete is a usual deallocation function if
2401 // removing the std::destroying_delete_t parameter and changing the
2402 // first parameter type from T* to void* results in the signature of
2403 // a usual deallocation function.
2405 ++UsualParams;
2406
2407 // C++ <=14 [basic.stc.dynamic.deallocation]p2:
2408 // [...] If class T does not declare such an operator delete but does
2409 // declare a member deallocation function named operator delete with
2410 // exactly two parameters, the second of which has type std::size_t (18.1),
2411 // then this function is a usual deallocation function.
2412 //
2413 // C++17 says a usual deallocation function is one with the signature
2414 // (void* [, size_t] [, std::align_val_t] [, ...])
2415 // and all such functions are usual deallocation functions. It's not clear
2416 // that allowing varargs functions was intentional.
2417 ASTContext &Context = getASTContext();
2418 if (UsualParams < getNumParams() &&
2419 Context.hasSameUnqualifiedType(getParamDecl(UsualParams)->getType(),
2420 Context.getSizeType()))
2421 ++UsualParams;
2422
2423 if (UsualParams < getNumParams() &&
2424 getParamDecl(UsualParams)->getType()->isAlignValT())
2425 ++UsualParams;
2426
2427 if (UsualParams != getNumParams())
2428 return false;
2429
2430 // In C++17 onwards, all potential usual deallocation functions are actual
2431 // usual deallocation functions. Honor this behavior when post-C++14
2432 // deallocation functions are offered as extensions too.
2433 // FIXME(EricWF): Destroying Delete should be a language option. How do we
2434 // handle when destroying delete is used prior to C++17?
2435 if (Context.getLangOpts().CPlusPlus17 ||
2436 Context.getLangOpts().AlignedAllocation ||
2438 return true;
2439
2440 // This function is a usual deallocation function if there are no
2441 // single-parameter deallocation functions of the same kind.
2443 bool Result = true;
2444 for (const auto *D : R) {
2445 if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
2446 if (FD->getNumParams() == 1) {
2447 PreventedBy.push_back(FD);
2448 Result = false;
2449 }
2450 }
2451 }
2452 return Result;
2453}
2454
2456 // C++2b [dcl.fct]p6:
2457 // An explicit object member function is a non-static member
2458 // function with an explicit object parameter
2460}
2461
2464}
2465
2467 // C++0x [class.copy]p17:
2468 // A user-declared copy assignment operator X::operator= is a non-static
2469 // non-template member function of class X with exactly one parameter of
2470 // type X, X&, const X&, volatile X& or const volatile X&.
2471 if (/*operator=*/getOverloadedOperator() != OO_Equal ||
2472 /*non-static*/ isStatic() ||
2473
2474 /*non-template*/ getPrimaryTemplate() || getDescribedFunctionTemplate() ||
2475 getNumExplicitParams() != 1)
2476 return false;
2477
2478 QualType ParamType = getNonObjectParameter(0)->getType();
2479 if (const auto *Ref = ParamType->getAs<LValueReferenceType>())
2480 ParamType = Ref->getPointeeType();
2481
2482 ASTContext &Context = getASTContext();
2483 QualType ClassType
2484 = Context.getCanonicalType(Context.getTypeDeclType(getParent()));
2485 return Context.hasSameUnqualifiedType(ClassType, ParamType);
2486}
2487
2489 // C++0x [class.copy]p19:
2490 // A user-declared move assignment operator X::operator= is a non-static
2491 // non-template member function of class X with exactly one parameter of type
2492 // X&&, const X&&, volatile X&&, or const volatile X&&.
2493 if (getOverloadedOperator() != OO_Equal || isStatic() ||
2495 getNumExplicitParams() != 1)
2496 return false;
2497
2498 QualType ParamType = getNonObjectParameter(0)->getType();
2499 if (!ParamType->isRValueReferenceType())
2500 return false;
2501 ParamType = ParamType->getPointeeType();
2502
2503 ASTContext &Context = getASTContext();
2504 QualType ClassType
2505 = Context.getCanonicalType(Context.getTypeDeclType(getParent()));
2506 return Context.hasSameUnqualifiedType(ClassType, ParamType);
2507}
2508
2510 assert(MD->isCanonicalDecl() && "Method is not canonical!");
2511 assert(!MD->getParent()->isDependentContext() &&
2512 "Can't add an overridden method to a class template!");
2513 assert(MD->isVirtual() && "Method is not virtual!");
2514
2516}
2517
2519 if (isa<CXXConstructorDecl>(this)) return nullptr;
2521}
2522
2524 if (isa<CXXConstructorDecl>(this)) return nullptr;
2526}
2527
2529 if (isa<CXXConstructorDecl>(this)) return 0;
2531}
2532
2535 if (isa<CXXConstructorDecl>(this))
2536 return overridden_method_range(nullptr, nullptr);
2537 return getASTContext().overridden_methods(this);
2538}
2539
2541 const CXXRecordDecl *Decl) {
2542 QualType ClassTy = C.getTypeDeclType(Decl);
2543 return C.getQualifiedType(ClassTy, FPT->getMethodQuals());
2544}
2545
2547 const CXXRecordDecl *Decl) {
2549 QualType ObjectTy = ::getThisObjectType(C, FPT, Decl);
2550
2551 // Unlike 'const' and 'volatile', a '__restrict' qualifier must be
2552 // attached to the pointer type, not the pointee.
2553 bool Restrict = FPT->getMethodQuals().hasRestrict();
2554 if (Restrict)
2555 ObjectTy.removeLocalRestrict();
2556
2557 ObjectTy = C.getLangOpts().HLSL ? C.getLValueReferenceType(ObjectTy)
2558 : C.getPointerType(ObjectTy);
2559
2560 if (Restrict)
2561 ObjectTy.addRestrict();
2562 return ObjectTy;
2563}
2564
2566 // C++ 9.3.2p1: The type of this in a member function of a class X is X*.
2567 // If the member function is declared const, the type of this is const X*,
2568 // if the member function is declared volatile, the type of this is
2569 // volatile X*, and if the member function is declared const volatile,
2570 // the type of this is const volatile X*.
2571 assert(isInstance() && "No 'this' for static methods!");
2572 return CXXMethodDecl::getThisType(getType()->castAs<FunctionProtoType>(),
2573 getParent());
2574}
2575
2578 return parameters()[0]->getType();
2579
2585 return C.getRValueReferenceType(Type);
2586 return C.getLValueReferenceType(Type);
2587}
2588
2590 // If this function is a template instantiation, look at the template from
2591 // which it was instantiated.
2593 if (!CheckFn)
2594 CheckFn = this;
2595
2596 const FunctionDecl *fn;
2597 return CheckFn->isDefined(fn) && !fn->isOutOfLine() &&
2599}
2600
2602 const CXXRecordDecl *P = getParent();
2603 return P->isLambda() && getDeclName().isIdentifier() &&
2605}
2606
2608 TypeSourceInfo *TInfo, bool IsVirtual,
2611 SourceLocation EllipsisLoc)
2612 : Initializee(TInfo), Init(Init), MemberOrEllipsisLocation(EllipsisLoc),
2613 LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(IsVirtual),
2614 IsWritten(false), SourceOrder(0) {}
2615
2617 SourceLocation MemberLoc,
2620 : Initializee(Member), Init(Init), MemberOrEllipsisLocation(MemberLoc),
2621 LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
2622 IsWritten(false), SourceOrder(0) {}
2623
2626 SourceLocation MemberLoc,
2629 : Initializee(Member), Init(Init), MemberOrEllipsisLocation(MemberLoc),
2630 LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
2631 IsWritten(false), SourceOrder(0) {}
2632
2634 TypeSourceInfo *TInfo,
2637 : Initializee(TInfo), Init(Init), LParenLoc(L), RParenLoc(R),
2638 IsDelegating(true), IsVirtual(false), IsWritten(false), SourceOrder(0) {}
2639
2640int64_t CXXCtorInitializer::getID(const ASTContext &Context) const {
2641 return Context.getAllocator()
2642 .identifyKnownAlignedObject<CXXCtorInitializer>(this);
2643}
2644
2646 if (isBaseInitializer())
2647 return Initializee.get<TypeSourceInfo*>()->getTypeLoc();
2648 else
2649 return {};
2650}
2651
2653 if (isBaseInitializer())
2654 return Initializee.get<TypeSourceInfo*>()->getType().getTypePtr();
2655 else
2656 return nullptr;
2657}
2658
2661 return getAnyMember()->getLocation();
2662
2664 return getMemberLocation();
2665
2666 if (const auto *TSInfo = Initializee.get<TypeSourceInfo *>())
2667 return TSInfo->getTypeLoc().getBeginLoc();
2668
2669 return {};
2670}
2671
2674 FieldDecl *D = getAnyMember();
2675 if (Expr *I = D->getInClassInitializer())
2676 return I->getSourceRange();
2677 return {};
2678 }
2679
2681}
2682
2683CXXConstructorDecl::CXXConstructorDecl(
2684 ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2685 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2686 ExplicitSpecifier ES, bool UsesFPIntrin, bool isInline,
2687 bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind,
2688 InheritedConstructor Inherited, Expr *TrailingRequiresClause)
2689 : CXXMethodDecl(CXXConstructor, C, RD, StartLoc, NameInfo, T, TInfo,
2690 SC_None, UsesFPIntrin, isInline, ConstexprKind,
2691 SourceLocation(), TrailingRequiresClause) {
2692 setNumCtorInitializers(0);
2693 setInheritingConstructor(static_cast<bool>(Inherited));
2694 setImplicit(isImplicitlyDeclared);
2695 CXXConstructorDeclBits.HasTrailingExplicitSpecifier = ES.getExpr() ? 1 : 0;
2696 if (Inherited)
2697 *getTrailingObjects<InheritedConstructor>() = Inherited;
2698 setExplicitSpecifier(ES);
2699}
2700
2701void CXXConstructorDecl::anchor() {}
2702
2705 uint64_t AllocKind) {
2706 bool hasTrailingExplicit = static_cast<bool>(AllocKind & TAKHasTailExplicit);
2708 static_cast<bool>(AllocKind & TAKInheritsConstructor);
2709 unsigned Extra =
2710 additionalSizeToAlloc<InheritedConstructor, ExplicitSpecifier>(
2711 isInheritingConstructor, hasTrailingExplicit);
2712 auto *Result = new (C, ID, Extra) CXXConstructorDecl(
2713 C, nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr,
2714 ExplicitSpecifier(), false, false, false, ConstexprSpecKind::Unspecified,
2715 InheritedConstructor(), nullptr);
2716 Result->setInheritingConstructor(isInheritingConstructor);
2717 Result->CXXConstructorDeclBits.HasTrailingExplicitSpecifier =
2718 hasTrailingExplicit;
2719 Result->setExplicitSpecifier(ExplicitSpecifier());
2720 return Result;
2721}
2722
2724 ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2725 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2726 ExplicitSpecifier ES, bool UsesFPIntrin, bool isInline,
2727 bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind,
2728 InheritedConstructor Inherited, Expr *TrailingRequiresClause) {
2729 assert(NameInfo.getName().getNameKind()
2731 "Name must refer to a constructor");
2732 unsigned Extra =
2733 additionalSizeToAlloc<InheritedConstructor, ExplicitSpecifier>(
2734 Inherited ? 1 : 0, ES.getExpr() ? 1 : 0);
2735 return new (C, RD, Extra) CXXConstructorDecl(
2736 C, RD, StartLoc, NameInfo, T, TInfo, ES, UsesFPIntrin, isInline,
2737 isImplicitlyDeclared, ConstexprKind, Inherited, TrailingRequiresClause);
2738}
2739
2741 return CtorInitializers.get(getASTContext().getExternalSource());
2742}
2743
2745 assert(isDelegatingConstructor() && "Not a delegating constructor!");
2746 Expr *E = (*init_begin())->getInit()->IgnoreImplicit();
2747 if (const auto *Construct = dyn_cast<CXXConstructExpr>(E))
2748 return Construct->getConstructor();
2749
2750 return nullptr;
2751}
2752
2754 // C++ [class.default.ctor]p1:
2755 // A default constructor for a class X is a constructor of class X for
2756 // which each parameter that is not a function parameter pack has a default
2757 // argument (including the case of a constructor with no parameters)
2758 return getMinRequiredArguments() == 0;
2759}
2760
2761bool
2762CXXConstructorDecl::isCopyConstructor(unsigned &TypeQuals) const {
2763 return isCopyOrMoveConstructor(TypeQuals) &&
2765}
2766
2767bool CXXConstructorDecl::isMoveConstructor(unsigned &TypeQuals) const {
2768 return isCopyOrMoveConstructor(TypeQuals) &&
2770}
2771
2772/// Determine whether this is a copy or move constructor.
2773bool CXXConstructorDecl::isCopyOrMoveConstructor(unsigned &TypeQuals) const {
2774 // C++ [class.copy]p2:
2775 // A non-template constructor for class X is a copy constructor
2776 // if its first parameter is of type X&, const X&, volatile X& or
2777 // const volatile X&, and either there are no other parameters
2778 // or else all other parameters have default arguments (8.3.6).
2779 // C++0x [class.copy]p3:
2780 // A non-template constructor for class X is a move constructor if its
2781 // first parameter is of type X&&, const X&&, volatile X&&, or
2782 // const volatile X&&, and either there are no other parameters or else
2783 // all other parameters have default arguments.
2784 if (!hasOneParamOrDefaultArgs() || getPrimaryTemplate() != nullptr ||
2785 getDescribedFunctionTemplate() != nullptr)
2786 return false;
2787
2788 const ParmVarDecl *Param = getParamDecl(0);
2789
2790 // Do we have a reference type?
2791 const auto *ParamRefType = Param->getType()->getAs<ReferenceType>();
2792 if (!ParamRefType)
2793 return false;
2794
2795 // Is it a reference to our class type?
2796 ASTContext &Context = getASTContext();
2797
2798 CanQualType PointeeType
2799 = Context.getCanonicalType(ParamRefType->getPointeeType());
2800 CanQualType ClassTy
2801 = Context.getCanonicalType(Context.getTagDeclType(getParent()));
2802 if (PointeeType.getUnqualifiedType() != ClassTy)
2803 return false;
2804
2805 // FIXME: other qualifiers?
2806
2807 // We have a copy or move constructor.
2808 TypeQuals = PointeeType.getCVRQualifiers();
2809 return true;
2810}
2811
2812bool CXXConstructorDecl::isConvertingConstructor(bool AllowExplicit) const {
2813 // C++ [class.conv.ctor]p1:
2814 // A constructor declared without the function-specifier explicit
2815 // that can be called with a single parameter specifies a
2816 // conversion from the type of its first parameter to the type of
2817 // its class. Such a constructor is called a converting
2818 // constructor.
2819 if (isExplicit() && !AllowExplicit)
2820 return false;
2821
2822 // FIXME: This has nothing to do with the definition of converting
2823 // constructor, but is convenient for how we use this function in overload
2824 // resolution.
2825 return getNumParams() == 0
2827 : getMinRequiredArguments() <= 1;
2828}
2829
2832 return false;
2833
2834 const ParmVarDecl *Param = getParamDecl(0);
2835
2836 ASTContext &Context = getASTContext();
2837 CanQualType ParamType = Context.getCanonicalType(Param->getType());
2838
2839 // Is it the same as our class type?
2840 CanQualType ClassTy
2841 = Context.getCanonicalType(Context.getTagDeclType(getParent()));
2842 if (ParamType.getUnqualifiedType() != ClassTy)
2843 return false;
2844
2845 return true;
2846}
2847
2848void CXXDestructorDecl::anchor() {}
2849
2851 GlobalDeclID ID) {
2852 return new (C, ID) CXXDestructorDecl(
2853 C, nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr,
2854 false, false, false, ConstexprSpecKind::Unspecified, nullptr);
2855}
2856
2858 ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2859 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2860 bool UsesFPIntrin, bool isInline, bool isImplicitlyDeclared,
2861 ConstexprSpecKind ConstexprKind, Expr *TrailingRequiresClause) {
2862 assert(NameInfo.getName().getNameKind()
2864 "Name must refer to a destructor");
2865 return new (C, RD) CXXDestructorDecl(
2866 C, RD, StartLoc, NameInfo, T, TInfo, UsesFPIntrin, isInline,
2867 isImplicitlyDeclared, ConstexprKind, TrailingRequiresClause);
2868}
2869
2871 auto *First = cast<CXXDestructorDecl>(getFirstDecl());
2872 if (OD && !First->OperatorDelete) {
2873 First->OperatorDelete = OD;
2874 First->OperatorDeleteThisArg = ThisArg;
2875 if (auto *L = getASTMutationListener())
2876 L->ResolvedOperatorDelete(First, OD, ThisArg);
2877 }
2878}
2879
2880void CXXConversionDecl::anchor() {}
2881
2883 GlobalDeclID ID) {
2884 return new (C, ID) CXXConversionDecl(
2885 C, nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr,
2887 SourceLocation(), nullptr);
2888}
2889
2891 ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2892 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2893 bool UsesFPIntrin, bool isInline, ExplicitSpecifier ES,
2894 ConstexprSpecKind ConstexprKind, SourceLocation EndLocation,
2895 Expr *TrailingRequiresClause) {
2896 assert(NameInfo.getName().getNameKind()
2898 "Name must refer to a conversion function");
2899 return new (C, RD) CXXConversionDecl(
2900 C, RD, StartLoc, NameInfo, T, TInfo, UsesFPIntrin, isInline, ES,
2901 ConstexprKind, EndLocation, TrailingRequiresClause);
2902}
2903
2905 return isImplicit() && getParent()->isLambda() &&
2907}
2908
2909LinkageSpecDecl::LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
2910 SourceLocation LangLoc,
2911 LinkageSpecLanguageIDs lang, bool HasBraces)
2912 : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
2913 ExternLoc(ExternLoc), RBraceLoc(SourceLocation()) {
2914 setLanguage(lang);
2915 LinkageSpecDeclBits.HasBraces = HasBraces;
2916}
2917
2918void LinkageSpecDecl::anchor() {}
2919
2921 SourceLocation ExternLoc,
2922 SourceLocation LangLoc,
2924 bool HasBraces) {
2925 return new (C, DC) LinkageSpecDecl(DC, ExternLoc, LangLoc, Lang, HasBraces);
2926}
2927
2929 GlobalDeclID ID) {
2930 return new (C, ID)
2933}
2934
2935void UsingDirectiveDecl::anchor() {}
2936
2939 SourceLocation NamespaceLoc,
2940 NestedNameSpecifierLoc QualifierLoc,
2941 SourceLocation IdentLoc,
2942 NamedDecl *Used,
2943 DeclContext *CommonAncestor) {
2944 if (auto *NS = dyn_cast_or_null<NamespaceDecl>(Used))
2945 Used = NS->getOriginalNamespace();
2946 return new (C, DC) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierLoc,
2947 IdentLoc, Used, CommonAncestor);
2948}
2949
2951 GlobalDeclID ID) {
2952 return new (C, ID) UsingDirectiveDecl(nullptr, SourceLocation(),
2955 SourceLocation(), nullptr, nullptr);
2956}
2957
2959 if (auto *NA = dyn_cast_or_null<NamespaceAliasDecl>(NominatedNamespace))
2960 return NA->getNamespace();
2961 return cast_or_null<NamespaceDecl>(NominatedNamespace);
2962}
2963
2964NamespaceDecl::NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline,
2965 SourceLocation StartLoc, SourceLocation IdLoc,
2966 IdentifierInfo *Id, NamespaceDecl *PrevDecl,
2967 bool Nested)
2968 : NamedDecl(Namespace, DC, IdLoc, Id), DeclContext(Namespace),
2969 redeclarable_base(C), LocStart(StartLoc) {
2970 unsigned Flags = 0;
2971 if (Inline)
2972 Flags |= F_Inline;
2973 if (Nested)
2974 Flags |= F_Nested;
2975 AnonOrFirstNamespaceAndFlags = {nullptr, Flags};
2976 setPreviousDecl(PrevDecl);
2977
2978 if (PrevDecl)
2979 AnonOrFirstNamespaceAndFlags.setPointer(PrevDecl->getOriginalNamespace());
2980}
2981
2983 bool Inline, SourceLocation StartLoc,
2985 NamespaceDecl *PrevDecl, bool Nested) {
2986 return new (C, DC)
2987 NamespaceDecl(C, DC, Inline, StartLoc, IdLoc, Id, PrevDecl, Nested);
2988}
2989
2991 GlobalDeclID ID) {
2992 return new (C, ID) NamespaceDecl(C, nullptr, false, SourceLocation(),
2993 SourceLocation(), nullptr, nullptr, false);
2994}
2995
2997 if (isFirstDecl())
2998 return this;
2999
3000 return AnonOrFirstNamespaceAndFlags.getPointer();
3001}
3002
3004 if (isFirstDecl())
3005 return this;
3006
3007 return AnonOrFirstNamespaceAndFlags.getPointer();
3008}
3009
3011
3012NamespaceDecl *NamespaceDecl::getNextRedeclarationImpl() {
3013 return getNextRedeclaration();
3014}
3015
3016NamespaceDecl *NamespaceDecl::getPreviousDeclImpl() {
3017 return getPreviousDecl();
3018}
3019
3020NamespaceDecl *NamespaceDecl::getMostRecentDeclImpl() {
3021 return getMostRecentDecl();
3022}
3023
3024void NamespaceAliasDecl::anchor() {}
3025
3026NamespaceAliasDecl *NamespaceAliasDecl::getNextRedeclarationImpl() {
3027 return getNextRedeclaration();
3028}
3029
3030NamespaceAliasDecl *NamespaceAliasDecl::getPreviousDeclImpl() {
3031 return getPreviousDecl();
3032}
3033
3034NamespaceAliasDecl *NamespaceAliasDecl::getMostRecentDeclImpl() {
3035 return getMostRecentDecl();
3036}
3037
3039 SourceLocation UsingLoc,
3040 SourceLocation AliasLoc,
3041 IdentifierInfo *Alias,
3042 NestedNameSpecifierLoc QualifierLoc,
3043 SourceLocation IdentLoc,
3044 NamedDecl *Namespace) {
3045 // FIXME: Preserve the aliased namespace as written.
3046 if (auto *NS = dyn_cast_or_null<NamespaceDecl>(Namespace))
3047 Namespace = NS->getOriginalNamespace();
3048 return new (C, DC) NamespaceAliasDecl(C, DC, UsingLoc, AliasLoc, Alias,
3049 QualifierLoc, IdentLoc, Namespace);
3050}
3051
3053 GlobalDeclID ID) {
3054 return new (C, ID) NamespaceAliasDecl(C, nullptr, SourceLocation(),
3055 SourceLocation(), nullptr,
3057 SourceLocation(), nullptr);
3058}
3059
3060void LifetimeExtendedTemporaryDecl::anchor() {}
3061
3062/// Retrieve the storage duration for the materialized temporary.
3064 const ValueDecl *ExtendingDecl = getExtendingDecl();
3065 if (!ExtendingDecl)
3066 return SD_FullExpression;
3067 // FIXME: This is not necessarily correct for a temporary materialized
3068 // within a default initializer.
3069 if (isa<FieldDecl>(ExtendingDecl))
3070 return SD_Automatic;
3071 // FIXME: This only works because storage class specifiers are not allowed
3072 // on decomposition declarations.
3073 if (isa<BindingDecl>(ExtendingDecl))
3074 return ExtendingDecl->getDeclContext()->isFunctionOrMethod() ? SD_Automatic
3075 : SD_Static;
3076 return cast<VarDecl>(ExtendingDecl)->getStorageDuration();
3077}
3078
3080 assert(getStorageDuration() == SD_Static &&
3081 "don't need to cache the computed value for this temporary");
3082 if (MayCreate && !Value) {
3083 Value = (new (getASTContext()) APValue);
3085 }
3086 assert(Value && "may not be null");
3087 return Value;
3088}
3089
3090void UsingShadowDecl::anchor() {}
3091
3094 BaseUsingDecl *Introducer, NamedDecl *Target)
3095 : NamedDecl(K, DC, Loc, Name), redeclarable_base(C),
3096 UsingOrNextShadow(Introducer) {
3097 if (Target) {
3098 assert(!isa<UsingShadowDecl>(Target));
3100 }
3101 setImplicit();
3102}
3103
3105 : NamedDecl(K, nullptr, SourceLocation(), DeclarationName()),
3107
3109 GlobalDeclID ID) {
3110 return new (C, ID) UsingShadowDecl(UsingShadow, C, EmptyShell());
3111}
3112
3114 const UsingShadowDecl *Shadow = this;
3115 while (const auto *NextShadow =
3116 dyn_cast<UsingShadowDecl>(Shadow->UsingOrNextShadow))
3117 Shadow = NextShadow;
3118 return cast<BaseUsingDecl>(Shadow->UsingOrNextShadow);
3119}
3120
3121void ConstructorUsingShadowDecl::anchor() {}
3122
3126 NamedDecl *Target, bool IsVirtual) {
3127 return new (C, DC) ConstructorUsingShadowDecl(C, DC, Loc, Using, Target,
3128 IsVirtual);
3129}
3130
3133 return new (C, ID) ConstructorUsingShadowDecl(C, EmptyShell());
3134}
3135
3138}
3139
3140void BaseUsingDecl::anchor() {}
3141
3143 assert(!llvm::is_contained(shadows(), S) && "declaration already in set");
3144 assert(S->getIntroducer() == this);
3145
3146 if (FirstUsingShadow.getPointer())
3147 S->UsingOrNextShadow = FirstUsingShadow.getPointer();
3148 FirstUsingShadow.setPointer(S);
3149}
3150
3152 assert(llvm::is_contained(shadows(), S) && "declaration not in set");
3153 assert(S->getIntroducer() == this);
3154
3155 // Remove S from the shadow decl chain. This is O(n) but hopefully rare.
3156
3157 if (FirstUsingShadow.getPointer() == S) {
3158 FirstUsingShadow.setPointer(
3159 dyn_cast<UsingShadowDecl>(S->UsingOrNextShadow));
3160 S->UsingOrNextShadow = this;
3161 return;
3162 }
3163
3164 UsingShadowDecl *Prev = FirstUsingShadow.getPointer();
3165 while (Prev->UsingOrNextShadow != S)
3166 Prev = cast<UsingShadowDecl>(Prev->UsingOrNextShadow);
3167 Prev->UsingOrNextShadow = S->UsingOrNextShadow;
3168 S->UsingOrNextShadow = this;
3169}
3170
3171void UsingDecl::anchor() {}
3172
3174 NestedNameSpecifierLoc QualifierLoc,
3175 const DeclarationNameInfo &NameInfo,
3176 bool HasTypename) {
3177 return new (C, DC) UsingDecl(DC, UL, QualifierLoc, NameInfo, HasTypename);
3178}
3179
3181 return new (C, ID) UsingDecl(nullptr, SourceLocation(),
3183 false);
3184}
3185
3188 ? getQualifierLoc().getBeginLoc() : UsingLocation;
3190}
3191
3192void UsingEnumDecl::anchor() {}
3193
3195 SourceLocation UL,
3196 SourceLocation EL,
3197 SourceLocation NL,
3199 assert(isa<EnumDecl>(EnumType->getType()->getAsTagDecl()));
3200 return new (C, DC)
3201 UsingEnumDecl(DC, EnumType->getType()->getAsTagDecl()->getDeclName(), UL, EL, NL, EnumType);
3202}
3203
3205 GlobalDeclID ID) {
3206 return new (C, ID)
3208 SourceLocation(), SourceLocation(), nullptr);
3209}
3210
3212 return SourceRange(UsingLocation, EnumType->getTypeLoc().getEndLoc());
3213}
3214
3215void UsingPackDecl::anchor() {}
3216
3218 NamedDecl *InstantiatedFrom,
3219 ArrayRef<NamedDecl *> UsingDecls) {
3220 size_t Extra = additionalSizeToAlloc<NamedDecl *>(UsingDecls.size());
3221 return new (C, DC, Extra) UsingPackDecl(DC, InstantiatedFrom, UsingDecls);
3222}
3223
3225 unsigned NumExpansions) {
3226 size_t Extra = additionalSizeToAlloc<NamedDecl *>(NumExpansions);
3227 auto *Result =
3228 new (C, ID, Extra) UsingPackDecl(nullptr, nullptr, std::nullopt);
3229 Result->NumExpansions = NumExpansions;
3230 auto *Trail = Result->getTrailingObjects<NamedDecl *>();
3231 for (unsigned I = 0; I != NumExpansions; ++I)
3232 new (Trail + I) NamedDecl*(nullptr);
3233 return Result;
3234}
3235
3236void UnresolvedUsingValueDecl::anchor() {}
3237
3240 SourceLocation UsingLoc,
3241 NestedNameSpecifierLoc QualifierLoc,
3242 const DeclarationNameInfo &NameInfo,
3243 SourceLocation EllipsisLoc) {
3244 return new (C, DC) UnresolvedUsingValueDecl(DC, C.DependentTy, UsingLoc,
3245 QualifierLoc, NameInfo,
3246 EllipsisLoc);
3247}
3248
3251 return new (C, ID) UnresolvedUsingValueDecl(nullptr, QualType(),
3255 SourceLocation());
3256}
3257
3260 ? getQualifierLoc().getBeginLoc() : UsingLocation;
3262}
3263
3264void UnresolvedUsingTypenameDecl::anchor() {}
3265
3268 SourceLocation UsingLoc,
3269 SourceLocation TypenameLoc,
3270 NestedNameSpecifierLoc QualifierLoc,
3271 SourceLocation TargetNameLoc,
3272 DeclarationName TargetName,
3273 SourceLocation EllipsisLoc) {
3274 return new (C, DC) UnresolvedUsingTypenameDecl(
3275 DC, UsingLoc, TypenameLoc, QualifierLoc, TargetNameLoc,
3276 TargetName.getAsIdentifierInfo(), EllipsisLoc);
3277}
3278
3281 GlobalDeclID ID) {
3282 return new (C, ID) UnresolvedUsingTypenameDecl(
3284 SourceLocation(), nullptr, SourceLocation());
3285}
3286
3290 return new (Ctx, DC) UnresolvedUsingIfExistsDecl(DC, Loc, Name);
3291}
3292
3295 GlobalDeclID ID) {
3296 return new (Ctx, ID)
3298}
3299
3300UnresolvedUsingIfExistsDecl::UnresolvedUsingIfExistsDecl(DeclContext *DC,
3302 DeclarationName Name)
3303 : NamedDecl(Decl::UnresolvedUsingIfExists, DC, Loc, Name) {}
3304
3305void UnresolvedUsingIfExistsDecl::anchor() {}
3306
3307void StaticAssertDecl::anchor() {}
3308
3310 SourceLocation StaticAssertLoc,
3311 Expr *AssertExpr, Expr *Message,
3312 SourceLocation RParenLoc,
3313 bool Failed) {
3314 return new (C, DC) StaticAssertDecl(DC, StaticAssertLoc, AssertExpr, Message,
3315 RParenLoc, Failed);
3316}
3317
3319 GlobalDeclID ID) {
3320 return new (C, ID) StaticAssertDecl(nullptr, SourceLocation(), nullptr,
3321 nullptr, SourceLocation(), false);
3322}
3323
3325 assert((isa<VarDecl, BindingDecl>(this)) &&
3326 "expected a VarDecl or a BindingDecl");
3327 if (auto *Var = llvm::dyn_cast<VarDecl>(this))
3328 return Var;
3329 if (auto *BD = llvm::dyn_cast<BindingDecl>(this))
3330 return llvm::dyn_cast<VarDecl>(BD->getDecomposedDecl());
3331 return nullptr;
3332}
3333
3334void BindingDecl::anchor() {}
3335
3338 return new (C, DC) BindingDecl(DC, IdLoc, Id);
3339}
3340
3342 return new (C, ID) BindingDecl(nullptr, SourceLocation(), nullptr);
3343}
3344
3346 Expr *B = getBinding();
3347 if (!B)
3348 return nullptr;
3349 auto *DRE = dyn_cast<DeclRefExpr>(B->IgnoreImplicit());
3350 if (!DRE)
3351 return nullptr;
3352
3353 auto *VD = cast<VarDecl>(DRE->getDecl());
3354 assert(VD->isImplicit() && "holding var for binding decl not implicit");
3355 return VD;
3356}
3357
3358void DecompositionDecl::anchor() {}
3359
3361 SourceLocation StartLoc,
3362 SourceLocation LSquareLoc,
3363 QualType T, TypeSourceInfo *TInfo,
3364 StorageClass SC,
3366 size_t Extra = additionalSizeToAlloc<BindingDecl *>(Bindings.size());
3367 return new (C, DC, Extra)
3368 DecompositionDecl(C, DC, StartLoc, LSquareLoc, T, TInfo, SC, Bindings);
3369}
3370
3373 unsigned NumBindings) {
3374 size_t Extra = additionalSizeToAlloc<BindingDecl *>(NumBindings);
3375 auto *Result = new (C, ID, Extra)
3377 QualType(), nullptr, StorageClass(), std::nullopt);
3378 // Set up and clean out the bindings array.
3379 Result->NumBindings = NumBindings;
3380 auto *Trail = Result->getTrailingObjects<BindingDecl *>();
3381 for (unsigned I = 0; I != NumBindings; ++I)
3382 new (Trail + I) BindingDecl*(nullptr);
3383 return Result;
3384}
3385
3386void DecompositionDecl::printName(llvm::raw_ostream &OS,
3387 const PrintingPolicy &Policy) const {
3388 OS << '[';
3389 bool Comma = false;
3390 for (const auto *B : bindings()) {
3391 if (Comma)
3392 OS << ", ";
3393 B->printName(OS, Policy);
3394 Comma = true;
3395 }
3396 OS << ']';
3397}
3398
3399void MSPropertyDecl::anchor() {}
3400
3403 QualType T, TypeSourceInfo *TInfo,
3404 SourceLocation StartL,
3405 IdentifierInfo *Getter,
3406 IdentifierInfo *Setter) {
3407 return new (C, DC) MSPropertyDecl(DC, L, N, T, TInfo, StartL, Getter, Setter);
3408}
3409
3411 GlobalDeclID ID) {
3412 return new (C, ID) MSPropertyDecl(nullptr, SourceLocation(),
3413 DeclarationName(), QualType(), nullptr,
3414 SourceLocation(), nullptr, nullptr);
3415}
3416
3417void MSGuidDecl::anchor() {}
3418
3419MSGuidDecl::MSGuidDecl(DeclContext *DC, QualType T, Parts P)
3420 : ValueDecl(Decl::MSGuid, DC, SourceLocation(), DeclarationName(), T),
3421 PartVal(P) {}
3422
3423MSGuidDecl *MSGuidDecl::Create(const ASTContext &C, QualType T, Parts P) {
3424 DeclContext *DC = C.getTranslationUnitDecl();
3425 return new (C, DC) MSGuidDecl(DC, T, P);
3426}
3427
3428MSGuidDecl *MSGuidDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) {
3429 return new (C, ID) MSGuidDecl(nullptr, QualType(), Parts());
3430}
3431
3432void MSGuidDecl::printName(llvm::raw_ostream &OS,
3433 const PrintingPolicy &) const {
3434 OS << llvm::format("GUID{%08" PRIx32 "-%04" PRIx16 "-%04" PRIx16 "-",
3435 PartVal.Part1, PartVal.Part2, PartVal.Part3);
3436 unsigned I = 0;
3437 for (uint8_t Byte : PartVal.Part4And5) {
3438 OS << llvm::format("%02" PRIx8, Byte);
3439 if (++I == 2)
3440 OS << '-';
3441 }
3442 OS << '}';
3443}
3444
3445/// Determine if T is a valid 'struct _GUID' of the shape that we expect.
3447 // FIXME: We only need to check this once, not once each time we compute a
3448 // GUID APValue.
3449 using MatcherRef = llvm::function_ref<bool(QualType)>;
3450
3451 auto IsInt = [&Ctx](unsigned N) {
3452 return [&Ctx, N](QualType T) {
3454 Ctx.getIntWidth(T) == N;
3455 };
3456 };
3457
3458 auto IsArray = [&Ctx](MatcherRef Elem, unsigned N) {
3459 return [&Ctx, Elem, N](QualType T) {
3460 const ConstantArrayType *CAT = Ctx.getAsConstantArrayType(T);
3461 return CAT && CAT->getSize() == N && Elem(CAT->getElementType());
3462 };
3463 };
3464
3465 auto IsStruct = [](std::initializer_list<MatcherRef> Fields) {
3466 return [Fields](QualType T) {
3467 const RecordDecl *RD = T->getAsRecordDecl();
3468 if (!RD || RD->isUnion())
3469 return false;
3470 RD = RD->getDefinition();
3471 if (!RD)
3472 return false;
3473 if (auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
3474 if (CXXRD->getNumBases())
3475 return false;
3476 auto MatcherIt = Fields.begin();
3477 for (const FieldDecl *FD : RD->fields()) {
3478 if (FD->isUnnamedBitField())
3479 continue;
3480 if (FD->isBitField() || MatcherIt == Fields.end() ||
3481 !(*MatcherIt)(FD->getType()))
3482 return false;
3483 ++MatcherIt;
3484 }
3485 return MatcherIt == Fields.end();
3486 };
3487 };
3488
3489 // We expect an {i32, i16, i16, [8 x i8]}.
3490 return IsStruct({IsInt(32), IsInt(16), IsInt(16), IsArray(IsInt(8), 8)})(T);
3491}
3492
3494 if (APVal.isAbsent() && isValidStructGUID(getASTContext(), getType())) {
3495 using llvm::APInt;
3496 using llvm::APSInt;
3497 APVal = APValue(APValue::UninitStruct(), 0, 4);
3498 APVal.getStructField(0) = APValue(APSInt(APInt(32, PartVal.Part1), true));
3499 APVal.getStructField(1) = APValue(APSInt(APInt(16, PartVal.Part2), true));
3500 APVal.getStructField(2) = APValue(APSInt(APInt(16, PartVal.Part3), true));
3501 APValue &Arr = APVal.getStructField(3) =
3503 for (unsigned I = 0; I != 8; ++I) {
3504 Arr.getArrayInitializedElt(I) =
3505 APValue(APSInt(APInt(8, PartVal.Part4And5[I]), true));
3506 }
3507 // Register this APValue to be destroyed if necessary. (Note that the
3508 // MSGuidDecl destructor is never run.)
3509 getASTContext().addDestruction(&APVal);
3510 }
3511
3512 return APVal;
3513}
3514
3515void UnnamedGlobalConstantDecl::anchor() {}
3516
3517UnnamedGlobalConstantDecl::UnnamedGlobalConstantDecl(const ASTContext &C,
3518 DeclContext *DC,
3519 QualType Ty,
3520 const APValue &Val)
3521 : ValueDecl(Decl::UnnamedGlobalConstant, DC, SourceLocation(),
3522 DeclarationName(), Ty),
3523 Value(Val) {
3524 // Cleanup the embedded APValue if required (note that our destructor is never
3525 // run)
3526 if (Value.needsCleanup())
3527 C.addDestruction(&Value);
3528}
3529
3531UnnamedGlobalConstantDecl::Create(const ASTContext &C, QualType T,
3532 const APValue &Value) {
3533 DeclContext *DC = C.getTranslationUnitDecl();
3534 return new (C, DC) UnnamedGlobalConstantDecl(C, DC, T, Value);
3535}
3536
3538UnnamedGlobalConstantDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) {
3539 return new (C, ID)
3541}
3542
3543void UnnamedGlobalConstantDecl::printName(llvm::raw_ostream &OS,
3544 const PrintingPolicy &) const {
3545 OS << "unnamed-global-constant";
3546}
3547
3548static const char *getAccessName(AccessSpecifier AS) {
3549 switch (AS) {
3550 case AS_none:
3551 llvm_unreachable("Invalid access specifier!");
3552 case AS_public:
3553 return "public";
3554 case AS_private:
3555 return "private";
3556 case AS_protected:
3557 return "protected";
3558 }
3559 llvm_unreachable("Invalid access specifier!");
3560}
3561
3563 AccessSpecifier AS) {
3564 return DB << getAccessName(AS);
3565}
Defines the clang::ASTContext interface.
ASTImporterLookupTable & LT
This file provides some common utility functions for processing Lambda related AST Constructs.
StringRef P
static char ID
Definition: Arena.cpp:183
Defines the Diagnostic-related interfaces.
llvm::APSInt APSInt
static void CollectVisibleConversions(ASTContext &Context, const 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:1726
static const char * getAccessName(AccessSpecifier AS)
Definition: DeclCXX.cpp:3548
static bool recursivelyOverrides(const CXXMethodDecl *DerivedMD, const CXXMethodDecl *BaseMD)
Definition: DeclCXX.cpp:2196
static bool isValidStructGUID(ASTContext &Ctx, QualType T)
Determine if T is a valid 'struct _GUID' of the shape that we expect.
Definition: DeclCXX.cpp:3446
static DeclContext::lookup_result getLambdaStaticInvokers(const CXXRecordDecl &RD)
Definition: DeclCXX.cpp:1613
static NamedDecl * getLambdaCallOperatorHelper(const CXXRecordDecl &RD)
Definition: DeclCXX.cpp:1577
static QualType getThisObjectType(ASTContext &C, const FunctionProtoType *FPT, const CXXRecordDecl *Decl)
Definition: DeclCXX.cpp:2540
static bool allLookupResultsAreTheSame(const DeclContext::lookup_result &R)
Definition: DeclCXX.cpp:1570
static bool isDeclContextInNamespace(const DeclContext *DC)
Definition: DeclCXX.cpp:1995
static bool hasRepeatedBaseClass(const CXXRecordDecl *StartRD)
Determine whether a class has a repeated base class.
Definition: DeclCXX.cpp:176
static CanQualType GetConversionType(ASTContext &Context, NamedDecl *Conv)
Definition: DeclCXX.cpp:1707
static CXXMethodDecl * getInvokerAsMethod(NamedDecl *ND)
Definition: DeclCXX.cpp:1620
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
#define X(type, name)
Definition: Value.h:143
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the LambdaCapture class.
Defines the clang::LangOptions interface.
llvm::MachO::Target Target
Definition: MachO.h:50
llvm::MachO::Record Record
Definition: MachO.h:31
This file contains the declaration of the ODRHash class, which calculates a hash based on AST nodes,...
Defines an enumeration for C++ overloaded operators.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
uint32_t Id
Definition: SemaARM.cpp:1091
SourceLocation Loc
Definition: SemaObjC.cpp:758
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
SourceLocation Begin
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
APValue & getArrayInitializedElt(unsigned I)
Definition: APValue.h:510
APValue & getStructField(unsigned i)
Definition: APValue.h:551
bool isAbsent() const
Definition: APValue.h:397
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:185
const ConstantArrayType * getAsConstantArrayType(QualType T) const
Definition: ASTContext.h:2777
unsigned getIntWidth(QualType T) const
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl.
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:651
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2584
overridden_method_range overridden_methods(const CXXMethodDecl *Method) const
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:1600
IdentifierTable & Idents
Definition: ASTContext.h:647
const LangOptions & getLangOpts() const
Definition: ASTContext.h:778
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
overridden_cxx_method_iterator overridden_methods_end(const CXXMethodDecl *Method) const
llvm::BumpPtrAllocator & getAllocator() const
Definition: ASTContext.h:717
void addOverriddenMethod(const CXXMethodDecl *Method, const CXXMethodDecl *Overridden)
Note that the given C++ Method overrides the given Overridden method.
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
Definition: ASTContext.h:2627
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:721
unsigned overridden_methods_size(const CXXMethodDecl *Method) const
overridden_cxx_method_iterator overridden_methods_begin(const CXXMethodDecl *Method) const
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:760
void addDestruction(T *Ptr) const
If T isn't trivially destructible, calls AddDeallocation to register it for destruction.
Definition: ASTContext.h:3121
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
Definition: ASTContext.h:1198
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
An UnresolvedSet-like class which uses the ASTContext's allocator.
void append(ASTContext &C, iterator I, iterator E)
bool replace(const NamedDecl *Old, NamedDecl *New, AccessSpecifier AS)
Replaces the given declaration with the new one, once.
void addDecl(ASTContext &C, NamedDecl *D, AccessSpecifier AS)
void erase(unsigned I)
Represents an access specifier followed by colon ':'.
Definition: DeclCXX.h:86
static AccessSpecDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: DeclCXX.cpp:60
QualType getElementType() const
Definition: Type.h:3546
Represents a C++ declaration that introduces decls from somewhere else.
Definition: DeclCXX.h:3417
void addShadowDecl(UsingShadowDecl *S)
Definition: DeclCXX.cpp:3142
shadow_range shadows() const
Definition: DeclCXX.h:3483
void removeShadowDecl(UsingShadowDecl *S)
Definition: DeclCXX.cpp:3151
A binding in a decomposition declaration.
Definition: DeclCXX.h:4107
VarDecl * getHoldingVar() const
Get the variable (if any) that holds the value of evaluating the binding.
Definition: DeclCXX.cpp:3345
Expr * getBinding() const
Get the expression to which this declaration is bound.
Definition: DeclCXX.h:4131
static BindingDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: DeclCXX.cpp:3341
static BindingDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id)
Definition: DeclCXX.cpp:3336
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2535
bool isExplicit() const
Return true if the declaration is already resolved to be explicit.
Definition: DeclCXX.h:2614
init_iterator init_begin()
Retrieve an iterator to the first initializer.
Definition: DeclCXX.h:2631
CXXConstructorDecl * getTargetConstructor() const
When this constructor delegates to another, retrieve the target.
Definition: DeclCXX.cpp:2744
static CXXConstructorDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, uint64_t AllocKind)
Definition: DeclCXX.cpp:2703
bool isDefaultConstructor() const
Whether this constructor is a default constructor (C++ [class.ctor]p5), which can be used to default-...
Definition: DeclCXX.cpp:2753
bool isDelegatingConstructor() const
Determine whether this constructor is a delegating constructor.
Definition: DeclCXX.h:2687
bool isSpecializationCopyingObject() const
Determine whether this is a member template specialization that would copy the object to itself.
Definition: DeclCXX.cpp:2830
bool isMoveConstructor() const
Determine whether this constructor is a move constructor (C++11 [class.copy]p3), which can be used to...
Definition: DeclCXX.h:2732
bool isCopyOrMoveConstructor() const
Determine whether this a copy or move constructor.
Definition: DeclCXX.h:2744
static CXXConstructorDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, ExplicitSpecifier ES, bool UsesFPIntrin, bool isInline, bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, InheritedConstructor Inherited=InheritedConstructor(), Expr *TrailingRequiresClause=nullptr)
Definition: DeclCXX.cpp:2723
bool isInheritingConstructor() const
Determine whether this is an implicit constructor synthesized to model a call to a constructor inheri...
Definition: DeclCXX.h:2761
CXXCtorInitializer *const * init_const_iterator
Iterates through the member/base initializer list.
Definition: DeclCXX.h:2620
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:2812
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:2718
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2862
bool isLambdaToBlockPointerConversion() const
Determine whether this conversion function is a conversion from a lambda closure type to a block poin...
Definition: DeclCXX.cpp:2904
static CXXConversionDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, bool UsesFPIntrin, bool isInline, ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, Expr *TrailingRequiresClause=nullptr)
Definition: DeclCXX.cpp:2890
QualType getConversionType() const
Returns the type that this conversion function is converting to.
Definition: DeclCXX.h:2902
static CXXConversionDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: DeclCXX.cpp:2882
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2300
SourceLocation getRParenLoc() const
Definition: DeclCXX.h:2499
SourceRange getSourceRange() const LLVM_READONLY
Determine the source range covering the entire initializer.
Definition: DeclCXX.cpp:2672
SourceLocation getSourceLocation() const
Determine the source location of the initializer.
Definition: DeclCXX.cpp:2659
bool isAnyMemberInitializer() const
Definition: DeclCXX.h:2380
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition: DeclCXX.h:2372
int64_t getID(const ASTContext &Context) const
Definition: DeclCXX.cpp:2640
bool isInClassMemberInitializer() const
Determine whether this initializer is an implicit initializer generated for a field with an initializ...
Definition: DeclCXX.h:2394
const Type * getBaseClass() const
If this is a base class initializer, returns the type of the base class.
Definition: DeclCXX.cpp:2652
SourceLocation getMemberLocation() const
Definition: DeclCXX.h:2460
FieldDecl * getAnyMember() const
Definition: DeclCXX.h:2446
TypeLoc getBaseClassLoc() const
If this is a base class initializer, returns the type of the base class with location information.
Definition: DeclCXX.cpp:2645
CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual, SourceLocation L, Expr *Init, SourceLocation R, SourceLocation EllipsisLoc)
Creates a new base-class initializer.
Definition: DeclCXX.cpp:2607
Represents a C++ deduction guide declaration.
Definition: DeclCXX.h:1952
static CXXDeductionGuideDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, SourceLocation EndLocation, CXXConstructorDecl *Ctor=nullptr, DeductionCandidate Kind=DeductionCandidate::Normal)
Definition: DeclCXX.cpp:2157
static CXXDeductionGuideDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: DeclCXX.cpp:2167
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2799
static CXXDestructorDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, bool UsesFPIntrin, bool isInline, bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, Expr *TrailingRequiresClause=nullptr)
Definition: DeclCXX.cpp:2857
static CXXDestructorDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: DeclCXX.cpp:2850
void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg)
Definition: DeclCXX.cpp:2870
A mapping from each virtual member function to its set of final overriders.
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2060
bool isExplicitObjectMemberFunction() const
[C++2b][dcl.fct]/p7 An explicit object member function is a non-static member function with an explic...
Definition: DeclCXX.cpp:2455
CXXMethodDecl * getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD, bool MayBeBase=false)
Find if RD declares a function that overrides this function, and if so, return it.
Definition: DeclCXX.cpp:2208
bool isImplicitObjectMemberFunction() const
[C++2b][dcl.fct]/p7 An implicit object member function is a non-static member function without an exp...
Definition: DeclCXX.cpp:2462
void addOverriddenMethod(const CXXMethodDecl *MD)
Definition: DeclCXX.cpp:2509
bool hasInlineBody() const
Definition: DeclCXX.cpp:2589
bool isVirtual() const
Definition: DeclCXX.h:2115
bool isUsualDeallocationFunction(SmallVectorImpl< const FunctionDecl * > &PreventedBy) const
Determine whether this is a usual deallocation function (C++ [basic.stc.dynamic.deallocation]p2),...
Definition: DeclCXX.cpp:2378
unsigned getNumExplicitParams() const
Definition: DeclCXX.h:2214
overridden_method_range overridden_methods() const
Definition: DeclCXX.cpp:2534
unsigned size_overridden_methods() const
Definition: DeclCXX.cpp:2528
const CXXMethodDecl *const * method_iterator
Definition: DeclCXX.h:2173
QualType getFunctionObjectParameterReferenceType() const
Return the type of the object pointed by this.
Definition: DeclCXX.cpp:2576
method_iterator begin_overridden_methods() const
Definition: DeclCXX.cpp:2518
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Definition: DeclCXX.h:2186
QualType getThisType() const
Return the type of the this pointer.
Definition: DeclCXX.cpp:2565
bool isInstance() const
Definition: DeclCXX.h:2087
bool isMoveAssignmentOperator() const
Determine whether this is a move assignment operator.
Definition: DeclCXX.cpp:2488
static CXXMethodDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin, bool isInline, ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, Expr *TrailingRequiresClause=nullptr)
Definition: DeclCXX.cpp:2274
CXXMethodDecl * getDevirtualizedMethod(const Expr *Base, bool IsAppleKext)
If it's possible to devirtualize a call to this method, return the called function.
Definition: DeclCXX.cpp:2293
static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK)
Returns true if the given operator is implicitly static in a record context.
Definition: DeclCXX.h:2102
CXXMethodDecl * getCorrespondingMethodInClass(const CXXRecordDecl *RD, bool MayBeBase=false)
Find the method in RD that corresponds to this one.
Definition: DeclCXX.cpp:2239
llvm::iterator_range< llvm::TinyPtrVector< const CXXMethodDecl * >::const_iterator > overridden_method_range
Definition: DeclCXX.h:2180
bool isStatic() const
Definition: DeclCXX.cpp:2186
bool isCopyAssignmentOperator() const
Determine whether this is a copy-assignment operator, regardless of whether it was declared implicitl...
Definition: DeclCXX.cpp:2466
static CXXMethodDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: DeclCXX.cpp:2285
method_iterator end_overridden_methods() const
Definition: DeclCXX.cpp:2523
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:2156
bool isLambdaStaticInvoker() const
Determine whether this is a lambda closure type's static member function that is used for the result ...
Definition: DeclCXX.cpp:2601
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
Decl * getLambdaContextDecl() const
Retrieve the declaration that provides additional context for a lambda, when the normal declaration c...
Definition: DeclCXX.cpp:1685
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:2100
bool isTriviallyCopyable() const
Determine whether this class is considered trivially copyable per (C++11 [class]p6).
Definition: DeclCXX.cpp:576
bool hasNonTrivialCopyAssignment() const
Determine whether this class has a non-trivial copy assignment operator (C++ [class....
Definition: DeclCXX.h:1335
TemplateParameterList * getGenericLambdaTemplateParameterList() const
Retrieve the generic lambda's template parameter list.
Definition: DeclCXX.cpp:1662
bool isEffectivelyFinal() const
Determine whether it's impossible for a class to be derived from this class.
Definition: DeclCXX.cpp:2115
bool hasSimpleMoveConstructor() const
true if we know for sure that this class has a single, accessible, unambiguous move constructor that ...
Definition: DeclCXX.h:741
bool isAggregate() const
Determine whether this class is an aggregate (C++ [dcl.init.aggr]), which is a class with no user-dec...
Definition: DeclCXX.h:1147
bool hasTrivialDefaultConstructor() const
Determine whether this class has a trivial default constructor (C++11 [class.ctor]p5).
Definition: DeclCXX.h:1241
void setBases(CXXBaseSpecifier const *const *Bases, unsigned NumBases)
Sets the base classes of this struct or class.
Definition: DeclCXX.cpp:195
bool isGenericLambda() const
Determine whether this class describes a generic lambda function object (i.e.
Definition: DeclCXX.cpp:1564
base_class_iterator bases_end()
Definition: DeclCXX.h:628
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
Definition: DeclCXX.h:1367
bool hasUserDeclaredDestructor() const
Determine whether this class has a user-declared destructor.
Definition: DeclCXX.h:1005
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:1876
void completeDefinition() override
Indicates that the definition of this class is now complete.
Definition: DeclCXX.cpp:2055
bool isLiteral() const
Determine whether this class is a literal type.
Definition: DeclCXX.cpp:1390
bool defaultedDestructorIsConstexpr() const
Determine whether a defaulted default constructor for this class would be constexpr.
Definition: DeclCXX.h:1357
void setCaptures(ASTContext &Context, ArrayRef< LambdaCapture > Captures)
Set the captures for this lambda closure type.
Definition: DeclCXX.cpp:1514
unsigned getDeviceLambdaManglingNumber() const
Retrieve the device side mangling number.
Definition: DeclCXX.cpp:1702
base_class_range bases()
Definition: DeclCXX.h:619
bool hasAnyDependentBases() const
Determine whether this class has any dependent base classes which are not the current instantiation.
Definition: DeclCXX.cpp:569
void setTrivialForCallFlags(CXXMethodDecl *MD)
Definition: DeclCXX.cpp:1536
bool isLambda() const
Determine whether this class describes a lambda function object.
Definition: DeclCXX.h:1022
void addedSelectedDestructor(CXXDestructorDecl *DD)
Notify the class that this destructor is now selected.
Definition: DeclCXX.cpp:1415
bool hasFriends() const
Determines whether this record has any friends.
Definition: DeclCXX.h:702
method_range methods() const
Definition: DeclCXX.h:661
CXXRecordDecl * getDefinition() const
Definition: DeclCXX.h:564
static AccessSpecifier MergeAccess(AccessSpecifier PathAccess, AccessSpecifier DeclAccess)
Calculates the access of a decl that is reached along a path.
Definition: DeclCXX.h:1723
void getCaptureFields(llvm::DenseMap< const ValueDecl *, 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:1641
bool hasConstexprNonCopyMoveConstructor() const
Determine whether this class has at least one constexpr constructor other than the copy or move const...
Definition: DeclCXX.h:1256
static CXXRecordDecl * CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, unsigned DependencyKind, bool IsGeneric, LambdaCaptureDefault CaptureDefault)
Definition: DeclCXX.cpp:148
llvm::iterator_range< conversion_iterator > getVisibleConversionFunctions() const
Get all conversion functions visible in current class, including conversion function templates.
Definition: DeclCXX.cpp:1833
bool hasConstexprDestructor() const
Determine whether this class has a constexpr destructor.
Definition: DeclCXX.cpp:564
unsigned getNumBases() const
Retrieves the number of base classes of this class.
Definition: DeclCXX.h:613
bool hasNonLiteralTypeFieldsOrBases() const
Determine whether this class has a non-literal or/ volatile type non-static data member or base class...
Definition: DeclCXX.h:1409
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:132
bool isTriviallyCopyConstructible() const
Determine whether this class is considered trivially copyable per.
Definition: DeclCXX.cpp:593
bool isCapturelessLambda() const
Definition: DeclCXX.h:1068
const CXXRecordDecl * getTemplateInstantiationPattern() const
Retrieve the record declaration from which this record could be instantiated.
Definition: DeclCXX.cpp:1930
bool lambdaIsDefaultConstructibleAndAssignable() const
Determine whether this lambda should have an implicit default constructor and copy and move assignmen...
Definition: DeclCXX.cpp:692
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
Definition: DeclCXX.cpp:1905
base_class_iterator bases_begin()
Definition: DeclCXX.h:626
FunctionTemplateDecl * getDependentLambdaCallOperator() const
Retrieve the dependent lambda call operator of the closure type if this is a templated closure type.
Definition: DeclCXX.cpp:1589
void addedEligibleSpecialMemberFunction(const CXXMethodDecl *MD, unsigned SMKind)
Notify the class that an eligible SMF has been added.
Definition: DeclCXX.cpp:1420
conversion_iterator conversion_end() const
Definition: DeclCXX.h:1129
void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD)
Indicates that the declaration of a defaulted or deleted special member function is now complete.
Definition: DeclCXX.cpp:1467
CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, CXXRecordDecl *PrevDecl)
Definition: DeclCXX.cpp:124
bool isCLike() const
True if this class is C-like, without C++-specific features, e.g.
Definition: DeclCXX.cpp:1553
void setInstantiationOfMemberClass(CXXRecordDecl *RD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member class RD.
Definition: DeclCXX.cpp:1888
static CXXRecordDecl * CreateDeserialized(const ASTContext &C, GlobalDeclID ID)
Definition: DeclCXX.cpp:164
bool hasSimpleMoveAssignment() const
true if we know for sure that this class has a single, accessible, unambiguous move assignment operat...
Definition: DeclCXX.h:755
bool hasNonTrivialMoveConstructor() const
Determine whether this class has a non-trivial move constructor (C++11 [class.copy]p12)
Definition: DeclCXX.h:1314
bool hasUserDeclaredConstructor() const
Determine whether this class has any user-declared constructors.
Definition: DeclCXX.h:791
unsigned getODRHash() const
Definition: DeclCXX.cpp:495
bool hasDefinition() const
Definition: DeclCXX.h:571
ArrayRef< NamedDecl * > getLambdaExplicitTemplateParameters() const
Retrieve the lambda template parameters that were specified explicitly.
Definition: DeclCXX.cpp:1671
ClassTemplateDecl * getDescribedClassTemplate() const
Retrieves the class template that is described by this class declaration.
Definition: DeclCXX.cpp:1897
bool isPOD() const
Whether this class is a POD-type (C++ [class]p4)
Definition: DeclCXX.h:1175
void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const
Retrieve the final overriders for each virtual member function in the class hierarchy where this clas...
void removeConversion(const NamedDecl *Old)
Removes a conversion function from this class.
Definition: DeclCXX.cpp:1851
bool hasSimpleCopyConstructor() const
true if we know for sure that this class has a single, accessible, unambiguous copy constructor that ...
Definition: DeclCXX.h:734
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
Definition: DeclCXX.cpp:1975
bool hasNonTrivialMoveAssignment() const
Determine whether this class has a non-trivial move assignment operator (C++11 [class....
Definition: DeclCXX.h:1349
CXXMethodDecl * getLambdaStaticInvoker() const
Retrieve the lambda static invoker, the address of which is returned by the conversion operator,...
Definition: DeclCXX.cpp:1606
bool hasSimpleDestructor() const
true if we know for sure that this class has an accessible destructor that is not deleted.
Definition: DeclCXX.h:762
void setDescribedClassTemplate(ClassTemplateDecl *Template)
Definition: DeclCXX.cpp:1901
bool isInterfaceLike() const
Definition: DeclCXX.cpp:2004
void setLambdaNumbering(LambdaNumbering Numbering)
Set the mangling numbers and context declaration for a lambda class.
Definition: DeclCXX.cpp:1691
bool forallBases(ForallBasesCallback BaseMatches) const
Determines if the given callback holds for all the direct or indirect base classes of this type.
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization,...
Definition: DeclCXX.cpp:1883
bool hasNonTrivialCopyConstructor() const
Determine whether this class has a non-trivial copy constructor (C++ [class.copy]p6,...
Definition: DeclCXX.h:1289
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
Definition: DeclCXX.cpp:1594
bool hasSimpleCopyAssignment() const
true if we know for sure that this class has a single, accessible, unambiguous copy assignment operat...
Definition: DeclCXX.h:748
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:523
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition: DeclCXX.cpp:1916
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
Definition: DeclCXX.h:634
conversion_iterator conversion_begin() const
Definition: DeclCXX.h:1125
unsigned getCVRQualifiers() const
Retrieve the const/volatile/restrict qualifiers.
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
Declaration of a class template.
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:3572
llvm::APInt getSize() const
Return the constant array size as an APInt.
Definition: Type.h:3628
Represents a shadow constructor declaration introduced into a class by a C++11 using-declaration that...
Definition: DeclCXX.h:3598
static ConstructorUsingShadowDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: DeclCXX.cpp:3132
UsingDecl * getIntroducer() const
Override the UsingShadowDecl's getIntroducer, returning the UsingDecl that introduced this.
Definition: DeclCXX.h:3655
static ConstructorUsingShadowDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation Loc, UsingDecl *Using, NamedDecl *Target, bool IsVirtual)
Definition: DeclCXX.cpp:3124
CXXRecordDecl * getNominatedBaseClass() const
Get the base class that was named in the using declaration.
Definition: DeclCXX.cpp:3136
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1365
reference front() const
Definition: DeclBase.h:1388
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
Definition: DeclBase.h:2342
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1432
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2062
ASTContext & getParentASTContext() const
Definition: DeclBase.h:2091
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1304
bool isNamespace() const
Definition: DeclBase.h:2151
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1824
bool isTranslationUnit() const
Definition: DeclBase.h:2138
bool isFunctionOrMethod() const
Definition: DeclBase.h:2114
bool isExternCContext() const
Determines whether this context or some of its ancestors is a linkage specification context that spec...
Definition: DeclBase.cpp:1355
LinkageSpecDeclBitfields LinkageSpecDeclBits
Definition: DeclBase.h:2003
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
Definition: DeclBase.h:1047
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:441
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Definition: DeclBase.h:1212
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:523
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:599
ASTMutationListener * getASTMutationListener() const
Definition: DeclBase.cpp:533
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:89
bool isCanonicalDecl() const
Whether this particular Decl is a canonical one.
Definition: DeclBase.h:970
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
Definition: DeclBase.cpp:249
bool isInvalidDecl() const
Definition: DeclBase.h:594
SourceLocation getLocation() const
Definition: DeclBase.h:445
void setImplicit(bool I=true)
Definition: DeclBase.h:600
DeclContext * getDeclContext()
Definition: DeclBase.h:454
AccessSpecifier getAccess() const
Definition: DeclBase.h:513
bool hasAttr() const
Definition: DeclBase.h:583
const LangOptions & getLangOpts() const LLVM_READONLY
Helper to get the language options from the ASTContext.
Definition: DeclBase.cpp:529
DeclarationName getCXXDestructorName(CanQualType Ty)
Returns the name of a C++ destructor for the given Type.
DeclarationName getCXXOperatorName(OverloadedOperatorKind Op)
Get the name of the overloadable C++ operator corresponding to Op.
The name of a declaration.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
NameKind getNameKind() const
Determine what kind of name this is.
bool isIdentifier() const
Predicate functions for querying what type of name this is.
A decomposition declaration.
Definition: DeclCXX.h:4166
void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override
Pretty-print the unqualified name of this declaration.
Definition: DeclCXX.cpp:3386
ArrayRef< BindingDecl * > bindings() const
Definition: DeclCXX.h:4198
static DecompositionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation LSquareLoc, QualType T, TypeSourceInfo *TInfo, StorageClass S, ArrayRef< BindingDecl * > Bindings)
Definition: DeclCXX.cpp:3360
static DecompositionDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumBindings)
Definition: DeclCXX.cpp:3371
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:5591
Store information needed for an explicit specifier.
Definition: DeclCXX.h:1897
ExplicitSpecKind getKind() const
Definition: DeclCXX.h:1905
const Expr * getExpr() const
Definition: DeclCXX.h:1906
static ExplicitSpecifier getFromDecl(FunctionDecl *Function)
Definition: DeclCXX.cpp:2144
bool isEquivalent(const ExplicitSpecifier Other) const
Check for equivalence of explicit specifiers.
Definition: DeclCXX.cpp:2129
This represents one expression.
Definition: Expr.h:110
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3047
Abstract interface for external sources of AST nodes.
virtual Decl * GetExternalDecl(GlobalDeclID ID)
Resolve a declaration ID into a declaration, potentially building a new declaration.
Represents a member of a struct/union/class.
Definition: Decl.h:3059
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition: Decl.cpp:4565
Represents a function declaration or definition.
Definition: Decl.h:1971
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:2708
bool isTrivialForCall() const
Definition: Decl.h:2344
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to call this function.
Definition: Decl.cpp:3708
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:4037
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
Definition: Decl.cpp:3469
bool hasCXXExplicitFunctionObjectParameter() const
Definition: Decl.cpp:3726
bool UsesFPIntrin() const
Determine whether the function was declared in source context that requires constrained FP intrinsics...
Definition: Decl.h:2820
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2685
FunctionDecl * getTemplateInstantiationPattern(bool ForDefinition=true) const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
Definition: Decl.cpp:4108
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition: Decl.h:2341
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
Definition: Decl.cpp:4157
const ParmVarDecl * getNonObjectParameter(unsigned I) const
Definition: Decl.h:2734
bool isVariadic() const
Whether this function is variadic.
Definition: Decl.cpp:3084
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition: Decl.h:2297
bool isDeleted() const
Whether this function has been deleted.
Definition: Decl.h:2504
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:2799
bool isOutOfLine() const override
Determine whether this is or was instantiated from an out-of-line definition of a member function.
Definition: Decl.cpp:4367
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
Definition: Decl.h:2324
bool isIneligibleOrNotSelected() const
Definition: Decl.h:2382
void setIneligibleOrNotSelected(bool II)
Definition: Decl.h:2385
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any.
Definition: Decl.cpp:3974
bool isUserProvided() const
True if this method is user-declared and was not deleted or defaulted on its first declaration.
Definition: Decl.h:2374
bool hasOneParamOrDefaultArgs() const
Determine whether this function has a single parameter, or multiple parameters where all but the firs...
Definition: Decl.cpp:3740
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3687
bool isDefined(const FunctionDecl *&Definition, bool CheckForPendingFriendDefinition=false) const
Returns true if the function has a definition that does not need to be instantiated.
Definition: Decl.cpp:3198
bool willHaveBody() const
True if this function will eventually have a body, once it's fully parsed.
Definition: Decl.h:2597
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4672
Qualifiers getMethodQuals() const
Definition: Type.h:5046
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
Definition: Type.h:5054
Declaration of a template function.
Definition: DeclTemplate.h:957
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:4272
One of these records is kept for each identifier that is lexed.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
Represents a field injected from an anonymous union/struct into the parent scope.
Definition: Decl.h:3343
Description of a constructor that was inherited from a base class.
Definition: DeclCXX.h:2506
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3440
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:25
@ Ver6
Attempt to be ABI-compatible with code generated by Clang 6.0.x (SVN r321711).
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:461
APValue * getOrCreateValue(bool MayCreate) const
Get the storage for the constant value of a materialized temporary of static storage duration.
Definition: DeclCXX.cpp:3079
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
Definition: DeclCXX.cpp:3063
Represents a linkage specification.
Definition: DeclCXX.h:2934
static LinkageSpecDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation ExternLoc, SourceLocation LangLoc, LinkageSpecLanguageIDs Lang, bool HasBraces)
Definition: DeclCXX.cpp:2920
static LinkageSpecDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: DeclCXX.cpp:2928
A global _GUID constant.
Definition: DeclCXX.h:4289
APValue & getAsAPValue() const
Get the value of this MSGuidDecl as an APValue.
Definition: DeclCXX.cpp:3493
MSGuidDeclParts Parts
Definition: DeclCXX.h:4291
void printName(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const override
Print this UUID in a human-readable format.
Definition: DeclCXX.cpp:3432
An instance of this class represents the declaration of a property member.
Definition: DeclCXX.h:4235
static MSPropertyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName N, QualType T, TypeSourceInfo *TInfo, SourceLocation StartL, IdentifierInfo *Getter, IdentifierInfo *Setter)
Definition: DeclCXX.cpp:3401
static MSPropertyDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: DeclCXX.cpp:3410
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:3476
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:615
This represents a decl that may have a name.
Definition: Decl.h:249
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition: Decl.h:462
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:276
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:315
NamedDecl * getMostRecentDecl()
Definition: Decl.h:476
Represents a C++ namespace alias.
Definition: DeclCXX.h:3120
static NamespaceAliasDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: DeclCXX.cpp:3052
static NamespaceAliasDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation NamespaceLoc, SourceLocation AliasLoc, IdentifierInfo *Alias, NestedNameSpecifierLoc QualifierLoc, SourceLocation IdentLoc, NamedDecl *Namespace)
Definition: DeclCXX.cpp:3038
Represent a C++ namespace.
Definition: Decl.h:547
bool isOriginalNamespace() const
Return true if this declaration is an original (first) declaration of the namespace.
Definition: DeclCXX.cpp:3010
NamespaceDecl * getOriginalNamespace()
Get the original (first) namespace declaration.
Definition: DeclCXX.cpp:2996
static NamespaceDecl * Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl, bool Nested)
Definition: DeclCXX.cpp:2982
static NamespaceDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: DeclCXX.cpp:2990
A C++ nested-name-specifier augmented with source location information.
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier.
void AddStmt(const Stmt *S)
Definition: ODRHash.cpp:24
void AddCXXRecordDecl(const CXXRecordDecl *Record)
Definition: ODRHash.cpp:568
unsigned CalculateHash()
Definition: ODRHash.cpp:225
MapType::iterator iterator
Represents a parameter to a function.
Definition: Decl.h:1761
A (possibly-)qualified type.
Definition: Type.h:940
void addRestrict()
Add the restrict qualifier to this QualType.
Definition: Type.h:1181
void removeLocalRestrict()
Definition: Type.h:7487
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
Definition: Type.h:347
@ OCL_Weak
Reading or writing from this object requires a barrier call.
Definition: Type.h:350
bool hasRestrict() const
Definition: Type.h:463
Represents a struct/union/class.
Definition: Decl.h:4170
void setArgPassingRestrictions(RecordArgPassingKind Kind)
Definition: Decl.h:4308
field_iterator field_end() const
Definition: Decl.h:4379
field_range fields() const
Definition: Decl.h:4376
void setHasObjectMember(bool val)
Definition: Decl.h:4231
void setHasVolatileMember(bool val)
Definition: Decl.h:4235
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition: Decl.cpp:5076
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition: Decl.h:4361
bool field_empty() const
Definition: Decl.h:4384
field_iterator field_begin() const
Definition: Decl.cpp:5064
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5565
RecordDecl * getDecl() const
Definition: Type.h:5575
FunctionDecl * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Definition: Redeclarable.h:216
NamespaceDecl * getNextRedeclaration() const
Definition: Redeclarable.h:189
NamespaceDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
Definition: Redeclarable.h:204
bool isFirstDecl() const
True if this is the first declaration in its redeclaration chain.
Definition: Redeclarable.h:223
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3396
Represents the body of a requires-expression.
Definition: DeclCXX.h:2029
static RequiresExprBodyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc)
Definition: DeclCXX.cpp:2174
static RequiresExprBodyDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: DeclCXX.cpp:2180
Encodes a location in the source.
A trivial tuple used to represent a source range.
Represents a C++11 static_assert declaration.
Definition: DeclCXX.h:4058
static StaticAssertDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StaticAssertLoc, Expr *AssertExpr, Expr *Message, SourceLocation RParenLoc, bool Failed)
Definition: DeclCXX.cpp:3309
static StaticAssertDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: DeclCXX.cpp:3318
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
Definition: Diagnostic.h:1115
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition: Decl.h:3709
void setMayHaveOutOfDateDef(bool V=true)
Indicates whether it is possible for declarations of this kind to have an out-of-date definition.
Definition: Decl.h:3647
bool isStruct() const
Definition: Decl.h:3789
bool isUnion() const
Definition: Decl.h:3792
void setBeingDefined(bool V=true)
True if this decl is currently being defined.
Definition: Decl.h:3641
bool isInterface() const
Definition: Decl.h:3790
TagKind getTagKind() const
Definition: Decl.h:3781
Exposes information about the current target.
Definition: TargetInfo.h:218
virtual bool areDefaultedSMFStillPOD(const LangOptions &) const
Controls whether explicitly defaulted (= default) special member functions disqualify something from ...
Definition: TargetInfo.cpp:600
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:73
const Type * getTypeForDecl() const
Definition: Decl.h:3416
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:59
A container of type source information.
Definition: Type.h:7346
The base class of the type hierarchy.
Definition: Type.h:1827
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1881
bool isBlockPointerType() const
Definition: Type.h:7636
bool isLiteralType(const ASTContext &Ctx) const
Return true if this is a literal type (C++11 [basic.types]p10)
Definition: Type.cpp:2948
bool isUnsignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is unsigned or an enumeration types whose underlying ...
Definition: Type.cpp:2216
bool isRValueReferenceType() const
Definition: Type.h:7648
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:8213
bool isReferenceType() const
Definition: Type.h:7640
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:705
bool isLValueReferenceType() const
Definition: Type.h:7644
bool isStructuralType() const
Determine if this type is a structural type, per C++20 [temp.param]p7.
Definition: Type.cpp:3013
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2669
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8146
bool isRecordType() const
Definition: Type.h:7722
bool isObjCRetainableType() const
Definition: Type.cpp:4933
TagDecl * getAsTagDecl() const
Retrieves the TagDecl that this type refers to, either because the type is a TagType or because it is...
Definition: Type.cpp:1889
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition: Type.cpp:1885
An artificial decl, representing a global anonymous constant value which is uniquified by value withi...
Definition: DeclCXX.h:4346
void printName(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const override
Print this in a human-readable format.
Definition: DeclCXX.cpp:3543
A set of unresolved declarations.
Definition: UnresolvedSet.h:62
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:92
The iterator over UnresolvedSets.
Definition: UnresolvedSet.h:35
NamedDecl * getDecl() const
Definition: UnresolvedSet.h:51
A set of unresolved declarations.
This node is generated when a using-declaration that was annotated with attribute((using_if_exists)) ...
Definition: DeclCXX.h:4040
static UnresolvedUsingIfExistsDecl * CreateDeserialized(ASTContext &Ctx, GlobalDeclID ID)
Definition: DeclCXX.cpp:3294
static UnresolvedUsingIfExistsDecl * Create(ASTContext &Ctx, DeclContext *DC, SourceLocation Loc, DeclarationName Name)
Definition: DeclCXX.cpp:3288
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3959
static UnresolvedUsingTypenameDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TargetNameLoc, DeclarationName TargetName, SourceLocation EllipsisLoc)
Definition: DeclCXX.cpp:3267
static UnresolvedUsingTypenameDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: DeclCXX.cpp:3280
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3862
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no 'using').
Definition: DeclCXX.h:3899
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition: DeclCXX.h:3903
DeclarationNameInfo getNameInfo() const
Definition: DeclCXX.h:3910
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclCXX.cpp:3258
static UnresolvedUsingValueDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, SourceLocation EllipsisLoc)
Definition: DeclCXX.cpp:3239
static UnresolvedUsingValueDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: DeclCXX.cpp:3250
Represents a C++ using-declaration.
Definition: DeclCXX.h:3512
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no 'using').
Definition: DeclCXX.h:3558
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclCXX.cpp:3186
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition: DeclCXX.h:3546
static UsingDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: DeclCXX.cpp:3180
DeclarationNameInfo getNameInfo() const
Definition: DeclCXX.h:3553
static UsingDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingL, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword)
Definition: DeclCXX.cpp:3173
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Definition: DeclCXX.h:3549
Represents C++ using-directive.
Definition: DeclCXX.h:3015
static UsingDirectiveDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: DeclCXX.cpp:2950
static UsingDirectiveDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, SourceLocation NamespaceLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation IdentLoc, NamedDecl *Nominated, DeclContext *CommonAncestor)
Definition: DeclCXX.cpp:2937
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
Definition: DeclCXX.cpp:2958
Represents a C++ using-enum-declaration.
Definition: DeclCXX.h:3713
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclCXX.cpp:3211
static UsingEnumDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: DeclCXX.cpp:3204
static UsingEnumDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingL, SourceLocation EnumL, SourceLocation NameL, TypeSourceInfo *EnumType)
Definition: DeclCXX.cpp:3194
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition: DeclCXX.h:3794
static UsingPackDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumExpansions)
Definition: DeclCXX.cpp:3224
static UsingPackDecl * Create(ASTContext &C, DeclContext *DC, NamedDecl *InstantiatedFrom, ArrayRef< NamedDecl * > UsingDecls)
Definition: DeclCXX.cpp:3217
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3320
void setTargetDecl(NamedDecl *ND)
Sets the underlying declaration which has been brought into the local scope.
Definition: DeclCXX.h:3388
UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC, SourceLocation Loc, DeclarationName Name, BaseUsingDecl *Introducer, NamedDecl *Target)
Definition: DeclCXX.cpp:3092
static UsingShadowDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: DeclCXX.cpp:3108
BaseUsingDecl * getIntroducer() const
Gets the (written or instantiated) using declaration that introduced this declaration.
Definition: DeclCXX.cpp:3113
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:706
QualType getType() const
Definition: Decl.h:717
VarDecl * getPotentiallyDecomposedVarDecl()
Definition: DeclCXX.cpp:3324
Represents a variable declaration or definition.
Definition: Decl.h:918
Defines the clang::TargetInfo interface.
The JSON file list parser is used to communicate input to InstallAPI.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:21
bool isTemplateInstantiation(TemplateSpecializationKind Kind)
Determine whether this template specialization kind refers to an instantiation of an entity (as oppos...
Definition: Specifiers.h:209
@ CPlusPlus20
Definition: LangStandard.h:59
@ CPlusPlus14
Definition: LangStandard.h:57
ConstexprSpecKind
Define the kind of constexpr specifier.
Definition: Specifiers.h:35
LinkageSpecLanguageIDs
Represents the language in a linkage specification.
Definition: DeclCXX.h:2926
RefQualifierKind
The kind of C++11 ref-qualifier associated with a function type.
Definition: Type.h:1774
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
Definition: Type.h:1782
StorageClass
Storage classes.
Definition: Specifiers.h:245
@ SC_Static
Definition: Specifiers.h:249
@ SC_None
Definition: Specifiers.h:247
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)
Insertion operator for diagnostics.
StorageDuration
The storage duration for an object (per C++ [basic.stc]).
Definition: Specifiers.h:324
@ SD_Static
Static storage duration.
Definition: Specifiers.h:328
@ SD_FullExpression
Full-expression storage duration (for temporaries).
Definition: Specifiers.h:325
@ SD_Automatic
Automatic storage duration (most local variables).
Definition: Specifiers.h:326
@ Result
The result type of a method or function.
TagTypeKind
The kind of a tag type.
Definition: Type.h:6315
@ Interface
The "__interface" keyword.
@ Struct
The "struct" keyword.
@ Class
The "class" keyword.
@ CanNeverPassInRegs
The argument of this type cannot be passed directly in registers.
LambdaCaptureDefault
The default, if any, capture method for a lambda expression.
Definition: Lambda.h:22
StringRef getLambdaStaticInvokerName()
Definition: ASTLambda.h:22
const FunctionProtoType * T
DeductionCandidate
Only used by CXXDeductionGuideDecl.
Definition: DeclBase.h:1404
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition: DeclBase.h:1271
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:185
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...
Definition: Specifiers.h:188
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:275
U cast(CodeGen::Address addr)
Definition: Address.h:291
@ Other
Other implicit parameter.
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:120
@ AS_public
Definition: Specifiers.h:121
@ AS_protected
Definition: Specifiers.h:122
@ AS_none
Definition: Specifiers.h:124
@ AS_private
Definition: Specifiers.h:123
#define true
Definition: stdbool.h:25
#define false
Definition: stdbool.h:26
#define bool
Definition: stdbool.h:24
Information about how a lambda is numbered within its context.
Definition: DeclCXX.h:1798
A placeholder type used to construct an empty shell of a decl-derived type that will be filled in lat...
Definition: DeclBase.h:102
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
DeclarationName getName() const
getName - Returns the embedded declaration name.
T * get(ExternalASTSource *Source) const
Retrieve the pointer to the AST node that this lazy pointer points to.
uint16_t Part2
...-89ab-...
Definition: DeclCXX.h:4268
uint32_t Part1
{01234567-...
Definition: DeclCXX.h:4266
uint16_t Part3
...-cdef-...
Definition: DeclCXX.h:4270
uint8_t Part4And5[8]
...-0123-456789abcdef}
Definition: DeclCXX.h:4272
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57