clang 23.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"
34#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), IsHLSLIntangible(false), IsPFPType(false),
113 IsLambda(false), IsParsingBaseSpecifiers(false),
114 ComputedVisibleConversions(false), 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 return new (C, DC)
137 CXXRecordDecl(CXXRecord, TK, C, DC, StartLoc, IdLoc, Id, PrevDecl);
138}
139
143 unsigned DependencyKind, bool IsGeneric,
144 LambdaCaptureDefault CaptureDefault) {
145 auto *R = new (C, DC) CXXRecordDecl(CXXRecord, TagTypeKind::Class, C, DC, Loc,
146 Loc, nullptr, nullptr);
147 R->setBeingDefined(true);
148 R->DefinitionData = new (C) struct LambdaDefinitionData(
149 R, Info, DependencyKind, IsGeneric, CaptureDefault);
150 R->setImplicit(true);
151 return R;
152}
153
155 GlobalDeclID ID) {
156 auto *R = new (C, ID)
157 CXXRecordDecl(CXXRecord, TagTypeKind::Struct, C, nullptr,
158 SourceLocation(), SourceLocation(), nullptr, nullptr);
159 return R;
160}
161
162/// Determine whether a class has a repeated base class. This is intended for
163/// use when determining if a class is standard-layout, so makes no attempt to
164/// handle virtual bases.
165static bool hasRepeatedBaseClass(const CXXRecordDecl *StartRD) {
167 SmallVector<const CXXRecordDecl*, 8> WorkList = {StartRD};
168 while (!WorkList.empty()) {
169 const CXXRecordDecl *RD = WorkList.pop_back_val();
170 if (RD->isDependentType())
171 continue;
172 for (const CXXBaseSpecifier &BaseSpec : RD->bases()) {
173 if (const CXXRecordDecl *B = BaseSpec.getType()->getAsCXXRecordDecl()) {
174 if (!SeenBaseTypes.insert(B).second)
175 return true;
176 WorkList.push_back(B);
177 }
178 }
179 }
180 return false;
181}
182
183void
185 unsigned NumBases) {
187
188 if (!data().Bases.isOffset() && data().NumBases > 0)
189 C.Deallocate(data().getBases());
190
191 if (NumBases) {
192 if (!C.getLangOpts().CPlusPlus17) {
193 // C++ [dcl.init.aggr]p1:
194 // An aggregate is [...] a class with [...] no base classes [...].
195 data().Aggregate = false;
196 }
197
198 // C++ [class]p4:
199 // A POD-struct is an aggregate class...
200 data().PlainOldData = false;
201 }
202
203 // The set of seen virtual base types.
205
206 // The virtual bases of this class.
208
209 data().Bases = new(C) CXXBaseSpecifier [NumBases];
210 data().NumBases = NumBases;
211 for (unsigned i = 0; i < NumBases; ++i) {
212 data().getBases()[i] = *Bases[i];
213 // Keep track of inherited vbases for this base class.
214 const CXXBaseSpecifier *Base = Bases[i];
215 QualType BaseType = Base->getType();
216 // Skip dependent types; we can't do any checking on them now.
217 if (BaseType->isDependentType())
218 continue;
219 auto *BaseClassDecl = BaseType->castAsCXXRecordDecl();
220
221 // C++2a [class]p7:
222 // A standard-layout class is a class that:
223 // [...]
224 // -- has all non-static data members and bit-fields in the class and
225 // its base classes first declared in the same class
226 if (BaseClassDecl->data().HasBasesWithFields ||
227 !BaseClassDecl->field_empty()) {
228 if (data().HasBasesWithFields)
229 // Two bases have members or bit-fields: not standard-layout.
230 data().IsStandardLayout = false;
231 data().HasBasesWithFields = true;
232 }
233
234 // C++11 [class]p7:
235 // A standard-layout class is a class that:
236 // -- [...] has [...] at most one base class with non-static data
237 // members
238 if (BaseClassDecl->data().HasBasesWithNonStaticDataMembers ||
239 BaseClassDecl->hasDirectFields()) {
240 if (data().HasBasesWithNonStaticDataMembers)
241 data().IsCXX11StandardLayout = false;
242 data().HasBasesWithNonStaticDataMembers = true;
243 }
244
245 if (!BaseClassDecl->isEmpty()) {
246 // C++14 [meta.unary.prop]p4:
247 // T is a class type [...] with [...] no base class B for which
248 // is_empty<B>::value is false.
249 data().Empty = false;
250 }
251
252 // C++1z [dcl.init.agg]p1:
253 // An aggregate is a class with [...] no private or protected base classes
254 if (Base->getAccessSpecifier() != AS_public) {
255 data().Aggregate = false;
256
257 // C++20 [temp.param]p7:
258 // A structural type is [...] a literal class type with [...] all base
259 // classes [...] public
260 data().StructuralIfLiteral = false;
261 }
262
263 // C++ [class.virtual]p1:
264 // A class that declares or inherits a virtual function is called a
265 // polymorphic class.
266 if (BaseClassDecl->isPolymorphic()) {
267 data().Polymorphic = true;
268
269 // An aggregate is a class with [...] no virtual functions.
270 data().Aggregate = false;
271 }
272
273 // C++0x [class]p7:
274 // A standard-layout class is a class that: [...]
275 // -- has no non-standard-layout base classes
276 if (!BaseClassDecl->isStandardLayout())
277 data().IsStandardLayout = false;
278 if (!BaseClassDecl->isCXX11StandardLayout())
279 data().IsCXX11StandardLayout = false;
280
281 // Record if this base is the first non-literal field or base.
282 if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C))
283 data().HasNonLiteralTypeFieldsOrBases = true;
284
285 // Now go through all virtual bases of this base and add them.
286 for (const auto &VBase : BaseClassDecl->vbases()) {
287 // Add this base if it's not already in the list.
288 if (SeenVBaseTypes.insert(C.getCanonicalType(VBase.getType())).second) {
289 VBases.push_back(&VBase);
290
291 // C++11 [class.copy]p8:
292 // The implicitly-declared copy constructor for a class X will have
293 // the form 'X::X(const X&)' if each [...] virtual base class B of X
294 // has a copy constructor whose first parameter is of type
295 // 'const B&' or 'const volatile B&' [...]
296 if (CXXRecordDecl *VBaseDecl = VBase.getType()->getAsCXXRecordDecl())
297 if (!VBaseDecl->hasCopyConstructorWithConstParam())
298 data().ImplicitCopyConstructorCanHaveConstParamForVBase = false;
299
300 // C++1z [dcl.init.agg]p1:
301 // An aggregate is a class with [...] no virtual base classes
302 data().Aggregate = false;
303 }
304 }
305
306 if (Base->isVirtual()) {
307 // Add this base if it's not already in the list.
308 if (SeenVBaseTypes.insert(C.getCanonicalType(BaseType)).second)
309 VBases.push_back(Base);
310
311 // C++14 [meta.unary.prop] is_empty:
312 // T is a class type, but not a union type, with ... no virtual base
313 // classes
314 data().Empty = false;
315
316 // C++1z [dcl.init.agg]p1:
317 // An aggregate is a class with [...] no virtual base classes
318 data().Aggregate = false;
319
320 // C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25:
321 // A [default constructor, copy/move constructor, or copy/move assignment
322 // operator for a class X] is trivial [...] if:
323 // -- class X has [...] no virtual base classes
324 data().HasTrivialSpecialMembers &= SMF_Destructor;
325 data().HasTrivialSpecialMembersForCall &= SMF_Destructor;
326
327 // C++0x [class]p7:
328 // A standard-layout class is a class that: [...]
329 // -- has [...] no virtual base classes
330 data().IsStandardLayout = false;
331 data().IsCXX11StandardLayout = false;
332
333 // C++20 [dcl.constexpr]p3:
334 // In the definition of a constexpr function [...]
335 // -- if the function is a constructor or destructor,
336 // its class shall not have any virtual base classes
337 data().DefaultedDefaultConstructorIsConstexpr = false;
338 data().DefaultedDestructorIsConstexpr = false;
339
340 // C++1z [class.copy]p8:
341 // The implicitly-declared copy constructor for a class X will have
342 // the form 'X::X(const X&)' if each potentially constructed subobject
343 // has a copy constructor whose first parameter is of type
344 // 'const B&' or 'const volatile B&' [...]
345 if (!BaseClassDecl->hasCopyConstructorWithConstParam())
346 data().ImplicitCopyConstructorCanHaveConstParamForVBase = false;
347 } else {
348 // C++ [class.ctor]p5:
349 // A default constructor is trivial [...] if:
350 // -- all the direct base classes of its class have trivial default
351 // constructors.
352 if (!BaseClassDecl->hasTrivialDefaultConstructor())
353 data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor;
354
355 // C++0x [class.copy]p13:
356 // A copy/move constructor for class X is trivial if [...]
357 // [...]
358 // -- the constructor selected to copy/move each direct base class
359 // subobject is trivial, and
360 if (!BaseClassDecl->hasTrivialCopyConstructor())
361 data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor;
362
363 if (!BaseClassDecl->hasTrivialCopyConstructorForCall())
364 data().HasTrivialSpecialMembersForCall &= ~SMF_CopyConstructor;
365
366 // If the base class doesn't have a simple move constructor, we'll eagerly
367 // declare it and perform overload resolution to determine which function
368 // it actually calls. If it does have a simple move constructor, this
369 // check is correct.
370 if (!BaseClassDecl->hasTrivialMoveConstructor())
371 data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor;
372
373 if (!BaseClassDecl->hasTrivialMoveConstructorForCall())
374 data().HasTrivialSpecialMembersForCall &= ~SMF_MoveConstructor;
375
376 // C++0x [class.copy]p27:
377 // A copy/move assignment operator for class X is trivial if [...]
378 // [...]
379 // -- the assignment operator selected to copy/move each direct base
380 // class subobject is trivial, and
381 if (!BaseClassDecl->hasTrivialCopyAssignment())
382 data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment;
383 // If the base class doesn't have a simple move assignment, we'll eagerly
384 // declare it and perform overload resolution to determine which function
385 // it actually calls. If it does have a simple move assignment, this
386 // check is correct.
387 if (!BaseClassDecl->hasTrivialMoveAssignment())
388 data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment;
389
390 // C++11 [class.ctor]p6:
391 // If that user-written default constructor would satisfy the
392 // requirements of a constexpr constructor/function(C++23), the
393 // implicitly-defined default constructor is constexpr.
394 if (!BaseClassDecl->hasConstexprDefaultConstructor())
395 data().DefaultedDefaultConstructorIsConstexpr =
396 C.getLangOpts().CPlusPlus23;
397
398 // C++1z [class.copy]p8:
399 // The implicitly-declared copy constructor for a class X will have
400 // the form 'X::X(const X&)' if each potentially constructed subobject
401 // has a copy constructor whose first parameter is of type
402 // 'const B&' or 'const volatile B&' [...]
403 if (!BaseClassDecl->hasCopyConstructorWithConstParam())
404 data().ImplicitCopyConstructorCanHaveConstParamForNonVBase = false;
405 }
406
407 // C++ [class.ctor]p3:
408 // A destructor is trivial if all the direct base classes of its class
409 // have trivial destructors.
410 if (!BaseClassDecl->hasTrivialDestructor())
411 data().HasTrivialSpecialMembers &= ~SMF_Destructor;
412
413 if (!BaseClassDecl->hasTrivialDestructorForCall())
414 data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor;
415
416 if (!BaseClassDecl->hasIrrelevantDestructor())
417 data().HasIrrelevantDestructor = false;
418
419 if (BaseClassDecl->isAnyDestructorNoReturn())
420 data().IsAnyDestructorNoReturn = true;
421
422 if (BaseClassDecl->isHLSLIntangible())
423 data().IsHLSLIntangible = true;
424
425 // C++11 [class.copy]p18:
426 // The implicitly-declared copy assignment operator for a class X will
427 // have the form 'X& X::operator=(const X&)' if each direct base class B
428 // of X has a copy assignment operator whose parameter is of type 'const
429 // B&', 'const volatile B&', or 'B' [...]
430 if (!BaseClassDecl->hasCopyAssignmentWithConstParam())
431 data().ImplicitCopyAssignmentHasConstParam = false;
432
433 // A class has an Objective-C object member if... or any of its bases
434 // has an Objective-C object member.
435 if (BaseClassDecl->hasObjectMember())
436 setHasObjectMember(true);
437
438 if (BaseClassDecl->hasVolatileMember())
440
441 if (BaseClassDecl->getArgPassingRestrictions() ==
444
445 // Keep track of the presence of mutable fields.
446 if (BaseClassDecl->hasMutableFields())
447 data().HasMutableFields = true;
448
449 if (BaseClassDecl->hasUninitializedExplicitInitFields() &&
450 BaseClassDecl->isAggregate())
452
453 if (BaseClassDecl->hasUninitializedReferenceMember())
454 data().HasUninitializedReferenceMember = true;
455
456 if (!BaseClassDecl->allowConstDefaultInit())
457 data().HasUninitializedFields = true;
458
459 if (BaseClassDecl->isPFPType())
460 data().IsPFPType = true;
461
462 addedClassSubobject(BaseClassDecl);
463 }
464
465 // C++2a [class]p7:
466 // A class S is a standard-layout class if it:
467 // -- has at most one base class subobject of any given type
468 //
469 // Note that we only need to check this for classes with more than one base
470 // class. If there's only one base class, and it's standard layout, then
471 // we know there are no repeated base classes.
472 if (data().IsStandardLayout && NumBases > 1 && hasRepeatedBaseClass(this))
473 data().IsStandardLayout = false;
474
475 if (VBases.empty()) {
476 data().IsParsingBaseSpecifiers = false;
477 return;
478 }
479
480 // Create base specifier for any direct or indirect virtual bases.
481 data().VBases = new (C) CXXBaseSpecifier[VBases.size()];
482 data().NumVBases = VBases.size();
483 for (int I = 0, E = VBases.size(); I != E; ++I) {
484 QualType Type = VBases[I]->getType();
485 if (!Type->isDependentType())
486 addedClassSubobject(Type->getAsCXXRecordDecl());
487 data().getVBases()[I] = *VBases[I];
488 }
489
490 data().IsParsingBaseSpecifiers = false;
491}
492
494 assert(hasDefinition() && "ODRHash only for records with definitions");
495
496 // Previously calculated hash is stored in DefinitionData.
497 if (DefinitionData->HasODRHash)
498 return DefinitionData->ODRHash;
499
500 // Only calculate hash on first call of getODRHash per record.
501 ODRHash Hash;
503 DefinitionData->HasODRHash = true;
504 DefinitionData->ODRHash = Hash.CalculateHash();
505
506 return DefinitionData->ODRHash;
507}
508
509void CXXRecordDecl::addedClassSubobject(CXXRecordDecl *Subobj) {
510 // C++11 [class.copy]p11:
511 // A defaulted copy/move constructor for a class X is defined as
512 // deleted if X has:
513 // -- a direct or virtual base class B that cannot be copied/moved [...]
514 // -- a non-static data member of class type M (or array thereof)
515 // that cannot be copied or moved [...]
516 if (!Subobj->hasSimpleCopyConstructor())
517 data().NeedOverloadResolutionForCopyConstructor = true;
518 if (!Subobj->hasSimpleMoveConstructor())
519 data().NeedOverloadResolutionForMoveConstructor = true;
520
521 // C++11 [class.copy]p23:
522 // A defaulted copy/move assignment operator for a class X is defined as
523 // deleted if X has:
524 // -- a direct or virtual base class B that cannot be copied/moved [...]
525 // -- a non-static data member of class type M (or array thereof)
526 // that cannot be copied or moved [...]
527 if (!Subobj->hasSimpleCopyAssignment())
528 data().NeedOverloadResolutionForCopyAssignment = true;
529 if (!Subobj->hasSimpleMoveAssignment())
530 data().NeedOverloadResolutionForMoveAssignment = true;
531
532 // C++11 [class.ctor]p5, C++11 [class.copy]p11, C++11 [class.dtor]p5:
533 // A defaulted [ctor or dtor] for a class X is defined as
534 // deleted if X has:
535 // -- any direct or virtual base class [...] has a type with a destructor
536 // that is deleted or inaccessible from the defaulted [ctor or dtor].
537 // -- any non-static data member has a type with a destructor
538 // that is deleted or inaccessible from the defaulted [ctor or dtor].
539 if (!Subobj->hasSimpleDestructor()) {
540 data().NeedOverloadResolutionForCopyConstructor = true;
541 data().NeedOverloadResolutionForMoveConstructor = true;
542 data().NeedOverloadResolutionForDestructor = true;
543 }
544
545 // C++20 [dcl.constexpr]p5:
546 // The definition of a constexpr destructor whose function-body is not
547 // = delete shall additionally satisfy the following requirement:
548 // -- for every subobject of class type or (possibly multi-dimensional)
549 // array thereof, that class type shall have a constexpr destructor
550 if (!Subobj->hasConstexprDestructor())
551 data().DefaultedDestructorIsConstexpr =
552 getASTContext().getLangOpts().CPlusPlus23;
553
554 // C++20 [temp.param]p7:
555 // A structural type is [...] a literal class type [for which] the types
556 // of all base classes and non-static data members are structural types or
557 // (possibly multi-dimensional) array thereof
558 if (!Subobj->data().StructuralIfLiteral)
559 data().StructuralIfLiteral = false;
560}
561
563 assert(
565 "getStandardLayoutBaseWithFields called on a non-standard-layout type");
566#ifdef EXPENSIVE_CHECKS
567 {
568 unsigned NumberOfBasesWithFields = 0;
569 if (!field_empty())
570 ++NumberOfBasesWithFields;
572 forallBases([&](const CXXRecordDecl *Base) -> bool {
573 if (!Base->field_empty())
574 ++NumberOfBasesWithFields;
575 assert(
576 UniqueBases.insert(Base->getCanonicalDecl()).second &&
577 "Standard layout struct has multiple base classes of the same type");
578 return true;
579 });
580 assert(NumberOfBasesWithFields <= 1 &&
581 "Standard layout struct has fields declared in more than one class");
582 }
583#endif
584 if (!field_empty())
585 return this;
586 const CXXRecordDecl *Result = this;
587 forallBases([&](const CXXRecordDecl *Base) -> bool {
588 if (!Base->field_empty()) {
589 // This is the base where the fields are declared; return early
590 Result = Base;
591 return false;
592 }
593 return true;
594 });
595 return Result;
596}
597
599 auto *Dtor = getDestructor();
600 return Dtor ? Dtor->isConstexpr() : defaultedDestructorIsConstexpr();
601}
602
604 if (!isDependentContext())
605 return false;
606
607 return !forallBases([](const CXXRecordDecl *) { return true; });
608}
609
611 // C++0x [class]p5:
612 // A trivially copyable class is a class that:
613 // -- has no non-trivial copy constructors,
614 if (hasNonTrivialCopyConstructor()) return false;
615 // -- has no non-trivial move constructors,
616 if (hasNonTrivialMoveConstructor()) return false;
617 // -- has no non-trivial copy assignment operators,
618 if (hasNonTrivialCopyAssignment()) return false;
619 // -- has no non-trivial move assignment operators, and
620 if (hasNonTrivialMoveAssignment()) return false;
621 // -- has a trivial destructor.
622 if (!hasTrivialDestructor()) return false;
623
624 return true;
625}
626
628
629 // A trivially copy constructible class is a class that:
630 // -- has no non-trivial copy constructors,
632 return false;
633 // -- has a trivial destructor.
635 return false;
636
637 return true;
638}
639
640void CXXRecordDecl::markedVirtualFunctionPure() {
641 // C++ [class.abstract]p2:
642 // A class is abstract if it has at least one pure virtual function.
643 data().Abstract = true;
644}
645
646bool CXXRecordDecl::hasSubobjectAtOffsetZeroOfEmptyBaseType(
647 ASTContext &Ctx, const CXXRecordDecl *XFirst) {
648 if (!getNumBases())
649 return false;
650
654
655 // Visit a type that we have determined is an element of M(S).
656 auto Visit = [&](const CXXRecordDecl *RD) -> bool {
657 RD = RD->getCanonicalDecl();
658
659 // C++2a [class]p8:
660 // A class S is a standard-layout class if it [...] has no element of the
661 // set M(S) of types as a base class.
662 //
663 // If we find a subobject of an empty type, it might also be a base class,
664 // so we'll need to walk the base classes to check.
665 if (!RD->data().HasBasesWithFields) {
666 // Walk the bases the first time, stopping if we find the type. Build a
667 // set of them so we don't need to walk them again.
668 if (Bases.empty()) {
669 bool RDIsBase = !forallBases([&](const CXXRecordDecl *Base) -> bool {
670 Base = Base->getCanonicalDecl();
671 if (RD == Base)
672 return false;
673 Bases.insert(Base);
674 return true;
675 });
676 if (RDIsBase)
677 return true;
678 } else {
679 if (Bases.count(RD))
680 return true;
681 }
682 }
683
684 if (M.insert(RD).second)
685 WorkList.push_back(RD);
686 return false;
687 };
688
689 if (Visit(XFirst))
690 return true;
691
692 while (!WorkList.empty()) {
693 const CXXRecordDecl *X = WorkList.pop_back_val();
694
695 // FIXME: We don't check the bases of X. That matches the standard, but
696 // that sure looks like a wording bug.
697
698 // -- If X is a non-union class type with a non-static data member
699 // [recurse to each field] that is either of zero size or is the
700 // first non-static data member of X
701 // -- If X is a union type, [recurse to union members]
702 bool IsFirstField = true;
703 for (auto *FD : X->fields()) {
704 // FIXME: Should we really care about the type of the first non-static
705 // data member of a non-union if there are preceding unnamed bit-fields?
706 if (FD->isUnnamedBitField())
707 continue;
708
709 if (!IsFirstField && !FD->isZeroSize(Ctx))
710 continue;
711
712 if (FD->isInvalidDecl())
713 continue;
714
715 // -- If X is n array type, [visit the element type]
716 QualType T = Ctx.getBaseElementType(FD->getType());
717 if (auto *RD = T->getAsCXXRecordDecl())
718 if (Visit(RD))
719 return true;
720
721 if (!X->isUnion())
722 IsFirstField = false;
723 }
724 }
725
726 return false;
727}
728
730 assert(isLambda() && "not a lambda");
731
732 // C++2a [expr.prim.lambda.capture]p11:
733 // The closure type associated with a lambda-expression has no default
734 // constructor if the lambda-expression has a lambda-capture and a
735 // defaulted default constructor otherwise. It has a deleted copy
736 // assignment operator if the lambda-expression has a lambda-capture and
737 // defaulted copy and move assignment operators otherwise.
738 //
739 // C++17 [expr.prim.lambda]p21:
740 // The closure type associated with a lambda-expression has no default
741 // constructor and a deleted copy assignment operator.
742 if (!isCapturelessLambda())
743 return false;
744 return getASTContext().getLangOpts().CPlusPlus20;
745}
746
747void CXXRecordDecl::addedMember(Decl *D) {
748 if (!D->isImplicit() && !isa<FieldDecl>(D) && !isa<IndirectFieldDecl>(D) &&
749 (!isa<TagDecl>(D) ||
750 cast<TagDecl>(D)->getTagKind() == TagTypeKind::Class ||
751 cast<TagDecl>(D)->getTagKind() == TagTypeKind::Interface))
752 data().HasOnlyCMembers = false;
753
754 // Ignore friends and invalid declarations.
755 if (D->getFriendObjectKind() || D->isInvalidDecl())
756 return;
757
758 auto *FunTmpl = dyn_cast<FunctionTemplateDecl>(D);
759 if (FunTmpl)
760 D = FunTmpl->getTemplatedDecl();
761
762 // FIXME: Pass NamedDecl* to addedMember?
763 Decl *DUnderlying = D;
764 if (auto *ND = dyn_cast<NamedDecl>(DUnderlying)) {
765 DUnderlying = ND->getUnderlyingDecl();
766 if (auto *UnderlyingFunTmpl = dyn_cast<FunctionTemplateDecl>(DUnderlying))
767 DUnderlying = UnderlyingFunTmpl->getTemplatedDecl();
768 }
769
770 if (const auto *Method = dyn_cast<CXXMethodDecl>(D)) {
771 if (Method->isVirtual()) {
772 // C++ [dcl.init.aggr]p1:
773 // An aggregate is an array or a class with [...] no virtual functions.
774 data().Aggregate = false;
775
776 // C++ [class]p4:
777 // A POD-struct is an aggregate class...
778 data().PlainOldData = false;
779
780 // C++14 [meta.unary.prop]p4:
781 // T is a class type [...] with [...] no virtual member functions...
782 data().Empty = false;
783
784 // C++ [class.virtual]p1:
785 // A class that declares or inherits a virtual function is called a
786 // polymorphic class.
787 data().Polymorphic = true;
788
789 // C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25:
790 // A [default constructor, copy/move constructor, or copy/move
791 // assignment operator for a class X] is trivial [...] if:
792 // -- class X has no virtual functions [...]
793 data().HasTrivialSpecialMembers &= SMF_Destructor;
794 data().HasTrivialSpecialMembersForCall &= SMF_Destructor;
795
796 // C++0x [class]p7:
797 // A standard-layout class is a class that: [...]
798 // -- has no virtual functions
799 data().IsStandardLayout = false;
800 data().IsCXX11StandardLayout = false;
801 }
802 }
803
804 // Notify the listener if an implicit member was added after the definition
805 // was completed.
806 if (!isBeingDefined() && D->isImplicit())
807 if (ASTMutationListener *L = getASTMutationListener())
808 L->AddedCXXImplicitMember(data().Definition, D);
809
810 // The kind of special member this declaration is, if any.
811 unsigned SMKind = 0;
812
813 // Handle constructors.
814 if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(D)) {
815 if (Constructor->isInheritingConstructor()) {
816 // Ignore constructor shadow declarations. They are lazily created and
817 // so shouldn't affect any properties of the class.
818 } else {
819 if (!Constructor->isImplicit()) {
820 // Note that we have a user-declared constructor.
821 data().UserDeclaredConstructor = true;
822
823 const TargetInfo &TI = getASTContext().getTargetInfo();
824 if ((!Constructor->isDeleted() && !Constructor->isDefaulted()) ||
826 // C++ [class]p4:
827 // A POD-struct is an aggregate class [...]
828 // Since the POD bit is meant to be C++03 POD-ness, clear it even if
829 // the type is technically an aggregate in C++0x since it wouldn't be
830 // in 03.
831 data().PlainOldData = false;
832 }
833 }
834
835 if (Constructor->isDefaultConstructor()) {
836 SMKind |= SMF_DefaultConstructor;
837
838 if (Constructor->isUserProvided())
839 data().UserProvidedDefaultConstructor = true;
840 if (Constructor->isConstexpr())
841 data().HasConstexprDefaultConstructor = true;
842 if (Constructor->isDefaulted())
843 data().HasDefaultedDefaultConstructor = true;
844 }
845
846 if (!FunTmpl) {
847 unsigned Quals;
848 if (Constructor->isCopyConstructor(Quals)) {
849 SMKind |= SMF_CopyConstructor;
850
851 if (Quals & Qualifiers::Const)
852 data().HasDeclaredCopyConstructorWithConstParam = true;
853 } else if (Constructor->isMoveConstructor())
854 SMKind |= SMF_MoveConstructor;
855 }
856
857 // C++11 [dcl.init.aggr]p1: DR1518
858 // An aggregate is an array or a class with no user-provided [or]
859 // explicit [...] constructors
860 // C++20 [dcl.init.aggr]p1:
861 // An aggregate is an array or a class with no user-declared [...]
862 // constructors
864 ? !Constructor->isImplicit()
865 : (Constructor->isUserProvided() || Constructor->isExplicit()))
866 data().Aggregate = false;
867 }
868 }
869
870 // Handle constructors, including those inherited from base classes.
871 if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(DUnderlying)) {
872 // Record if we see any constexpr constructors which are neither copy
873 // nor move constructors.
874 // C++1z [basic.types]p10:
875 // [...] has at least one constexpr constructor or constructor template
876 // (possibly inherited from a base class) that is not a copy or move
877 // constructor [...]
878 if (Constructor->isConstexpr() && !Constructor->isCopyOrMoveConstructor())
879 data().HasConstexprNonCopyMoveConstructor = true;
880 if (!isa<CXXConstructorDecl>(D) && Constructor->isDefaultConstructor())
881 data().HasInheritedDefaultConstructor = true;
882 }
883
884 // Handle member functions.
885 if (const auto *Method = dyn_cast<CXXMethodDecl>(D)) {
887 SMKind |= SMF_Destructor;
888
889 if (Method->isCopyAssignmentOperator()) {
890 SMKind |= SMF_CopyAssignment;
891
892 const auto *ParamTy =
893 Method->getNonObjectParameter(0)->getType()->getAs<ReferenceType>();
894 if (!ParamTy || ParamTy->getPointeeType().isConstQualified())
895 data().HasDeclaredCopyAssignmentWithConstParam = true;
896 }
897
898 if (Method->isMoveAssignmentOperator())
899 SMKind |= SMF_MoveAssignment;
900
901 // Keep the list of conversion functions up-to-date.
902 if (auto *Conversion = dyn_cast<CXXConversionDecl>(D)) {
903 // FIXME: We use the 'unsafe' accessor for the access specifier here,
904 // because Sema may not have set it yet. That's really just a misdesign
905 // in Sema. However, LLDB *will* have set the access specifier correctly,
906 // and adds declarations after the class is technically completed,
907 // so completeDefinition()'s overriding of the access specifiers doesn't
908 // work.
909 AccessSpecifier AS = Conversion->getAccessUnsafe();
910
911 if (Conversion->getPrimaryTemplate()) {
912 // We don't record specializations.
913 } else {
914 ASTContext &Ctx = getASTContext();
915 ASTUnresolvedSet &Conversions = data().Conversions.get(Ctx);
916 NamedDecl *Primary =
917 FunTmpl ? cast<NamedDecl>(FunTmpl) : cast<NamedDecl>(Conversion);
918 if (Primary->getPreviousDecl())
919 Conversions.replace(cast<NamedDecl>(Primary->getPreviousDecl()),
920 Primary, AS);
921 else
922 Conversions.addDecl(Ctx, Primary, AS);
923 }
924 }
925
926 if (SMKind) {
927 // If this is the first declaration of a special member, we no longer have
928 // an implicit trivial special member.
929 data().HasTrivialSpecialMembers &=
930 data().DeclaredSpecialMembers | ~SMKind;
931 data().HasTrivialSpecialMembersForCall &=
932 data().DeclaredSpecialMembers | ~SMKind;
933
934 // Note when we have declared a declared special member, and suppress the
935 // implicit declaration of this special member.
936 data().DeclaredSpecialMembers |= SMKind;
937 if (!Method->isImplicit()) {
938 data().UserDeclaredSpecialMembers |= SMKind;
939
940 const TargetInfo &TI = getASTContext().getTargetInfo();
941 if ((!Method->isDeleted() && !Method->isDefaulted() &&
942 SMKind != SMF_MoveAssignment) ||
944 // C++03 [class]p4:
945 // A POD-struct is an aggregate class that has [...] no user-defined
946 // copy assignment operator and no user-defined destructor.
947 //
948 // Since the POD bit is meant to be C++03 POD-ness, and in C++03,
949 // aggregates could not have any constructors, clear it even for an
950 // explicitly defaulted or deleted constructor.
951 // type is technically an aggregate in C++0x since it wouldn't be in
952 // 03.
953 //
954 // Also, a user-declared move assignment operator makes a class
955 // non-POD. This is an extension in C++03.
956 data().PlainOldData = false;
957 }
958 }
959 // When instantiating a class, we delay updating the destructor and
960 // triviality properties of the class until selecting a destructor and
961 // computing the eligibility of its special member functions. This is
962 // because there might be function constraints that we need to evaluate
963 // and compare later in the instantiation.
964 if (!Method->isIneligibleOrNotSelected()) {
966 }
967 }
968
969 return;
970 }
971
972 // Handle non-static data members.
973 if (const auto *Field = dyn_cast<FieldDecl>(D)) {
974 ASTContext &Context = getASTContext();
975
976 // C++2a [class]p7:
977 // A standard-layout class is a class that:
978 // [...]
979 // -- has all non-static data members and bit-fields in the class and
980 // its base classes first declared in the same class
981 if (data().HasBasesWithFields)
982 data().IsStandardLayout = false;
983
984 // C++ [class.bit]p2:
985 // A declaration for a bit-field that omits the identifier declares an
986 // unnamed bit-field. Unnamed bit-fields are not members and cannot be
987 // initialized.
988 if (Field->isUnnamedBitField()) {
989 // C++ [meta.unary.prop]p4: [LWG2358]
990 // T is a class type [...] with [...] no unnamed bit-fields of non-zero
991 // length
992 if (data().Empty && !Field->isZeroLengthBitField() &&
993 Context.getLangOpts().getClangABICompat() >
994 LangOptions::ClangABI::Ver6)
995 data().Empty = false;
996 return;
997 }
998
999 // C++11 [class]p7:
1000 // A standard-layout class is a class that:
1001 // -- either has no non-static data members in the most derived class
1002 // [...] or has no base classes with non-static data members
1003 if (data().HasBasesWithNonStaticDataMembers)
1004 data().IsCXX11StandardLayout = false;
1005
1006 // C++ [dcl.init.aggr]p1:
1007 // An aggregate is an array or a class (clause 9) with [...] no
1008 // private or protected non-static data members (clause 11).
1009 //
1010 // A POD must be an aggregate.
1011 if (D->getAccess() == AS_private || D->getAccess() == AS_protected) {
1012 data().Aggregate = false;
1013 data().PlainOldData = false;
1014
1015 // C++20 [temp.param]p7:
1016 // A structural type is [...] a literal class type [for which] all
1017 // non-static data members are public
1018 data().StructuralIfLiteral = false;
1019 }
1020
1021 // Track whether this is the first field. We use this when checking
1022 // whether the class is standard-layout below.
1023 bool IsFirstField = !data().HasPrivateFields &&
1024 !data().HasProtectedFields && !data().HasPublicFields;
1025
1026 // C++0x [class]p7:
1027 // A standard-layout class is a class that:
1028 // [...]
1029 // -- has the same access control for all non-static data members,
1030 switch (D->getAccess()) {
1031 case AS_private: data().HasPrivateFields = true; break;
1032 case AS_protected: data().HasProtectedFields = true; break;
1033 case AS_public: data().HasPublicFields = true; break;
1034 case AS_none: llvm_unreachable("Invalid access specifier");
1035 };
1036 if ((data().HasPrivateFields + data().HasProtectedFields +
1037 data().HasPublicFields) > 1) {
1038 data().IsStandardLayout = false;
1039 data().IsCXX11StandardLayout = false;
1040 }
1041
1042 // Keep track of the presence of mutable fields.
1043 if (Field->isMutable()) {
1044 data().HasMutableFields = true;
1045
1046 // C++20 [temp.param]p7:
1047 // A structural type is [...] a literal class type [for which] all
1048 // non-static data members are public
1049 data().StructuralIfLiteral = false;
1050 }
1051
1052 // C++11 [class.union]p8, DR1460:
1053 // If X is a union, a non-static data member of X that is not an anonymous
1054 // union is a variant member of X.
1055 if (isUnion() && !Field->isAnonymousStructOrUnion())
1056 data().HasVariantMembers = true;
1057
1058 if (isUnion() && IsFirstField)
1059 data().HasUninitializedFields = true;
1060
1061 // C++0x [class]p9:
1062 // A POD struct is a class that is both a trivial class and a
1063 // standard-layout class, and has no non-static data members of type
1064 // non-POD struct, non-POD union (or array of such types).
1065 //
1066 // Automatic Reference Counting: the presence of a member of Objective-C pointer type
1067 // that does not explicitly have no lifetime makes the class a non-POD.
1068 QualType T = Context.getBaseElementType(Field->getType());
1069 if (T->isObjCRetainableType() || T.isObjCGCStrong()) {
1070 if (T.hasNonTrivialObjCLifetime()) {
1071 // Objective-C Automatic Reference Counting:
1072 // If a class has a non-static data member of Objective-C pointer
1073 // type (or array thereof), it is a non-POD type and its
1074 // default constructor (if any), copy constructor, move constructor,
1075 // copy assignment operator, move assignment operator, and destructor are
1076 // non-trivial.
1077 setHasObjectMember(true);
1078 struct DefinitionData &Data = data();
1079 Data.PlainOldData = false;
1080 Data.HasTrivialSpecialMembers = 0;
1081
1082 // __strong or __weak fields do not make special functions non-trivial
1083 // for the purpose of calls.
1086 data().HasTrivialSpecialMembersForCall = 0;
1087
1088 // Structs with __weak fields should never be passed directly.
1089 if (LT == Qualifiers::OCL_Weak)
1091
1092 Data.HasIrrelevantDestructor = false;
1093
1094 if (isUnion()) {
1095 data().DefaultedCopyConstructorIsDeleted = true;
1096 data().DefaultedMoveConstructorIsDeleted = true;
1097 data().DefaultedCopyAssignmentIsDeleted = true;
1098 data().DefaultedMoveAssignmentIsDeleted = true;
1099 data().DefaultedDestructorIsDeleted = true;
1100 data().NeedOverloadResolutionForCopyConstructor = true;
1101 data().NeedOverloadResolutionForMoveConstructor = true;
1102 data().NeedOverloadResolutionForCopyAssignment = true;
1103 data().NeedOverloadResolutionForMoveAssignment = true;
1104 data().NeedOverloadResolutionForDestructor = true;
1105 }
1106 } else if (!Context.getLangOpts().ObjCAutoRefCount) {
1107 setHasObjectMember(true);
1108 }
1109 } else if (!T.isCXX98PODType(Context))
1110 data().PlainOldData = false;
1111
1112 // If a class has an address-discriminated signed pointer member, it is a
1113 // non-POD type and its copy constructor, move constructor, copy assignment
1114 // operator, move assignment operator are non-trivial.
1115 if (PointerAuthQualifier Q = T.getPointerAuth()) {
1116 if (Q.isAddressDiscriminated()) {
1117 struct DefinitionData &Data = data();
1118 Data.PlainOldData = false;
1119 Data.HasTrivialSpecialMembers &=
1120 ~(SMF_CopyConstructor | SMF_MoveConstructor | SMF_CopyAssignment |
1121 SMF_MoveAssignment);
1123
1124 // Copy/move constructors/assignment operators of a union are deleted by
1125 // default if it has an address-discriminated ptrauth field.
1126 if (isUnion()) {
1127 data().DefaultedCopyConstructorIsDeleted = true;
1128 data().DefaultedMoveConstructorIsDeleted = true;
1129 data().DefaultedCopyAssignmentIsDeleted = true;
1130 data().DefaultedMoveAssignmentIsDeleted = true;
1131 data().NeedOverloadResolutionForCopyConstructor = true;
1132 data().NeedOverloadResolutionForMoveConstructor = true;
1133 data().NeedOverloadResolutionForCopyAssignment = true;
1134 data().NeedOverloadResolutionForMoveAssignment = true;
1135 }
1136 }
1137 }
1138
1139 if (Field->hasAttr<ExplicitInitAttr>())
1141
1142 if (T->isReferenceType()) {
1143 if (!Field->hasInClassInitializer())
1144 data().HasUninitializedReferenceMember = true;
1145
1146 // C++0x [class]p7:
1147 // A standard-layout class is a class that:
1148 // -- has no non-static data members of type [...] reference,
1149 data().IsStandardLayout = false;
1150 data().IsCXX11StandardLayout = false;
1151
1152 // C++1z [class.copy.ctor]p10:
1153 // A defaulted copy constructor for a class X is defined as deleted if X has:
1154 // -- a non-static data member of rvalue reference type
1155 if (T->isRValueReferenceType())
1156 data().DefaultedCopyConstructorIsDeleted = true;
1157 }
1158
1159 if (isUnion() && !Field->isMutable()) {
1160 if (Field->hasInClassInitializer())
1161 data().HasUninitializedFields = false;
1162 } else if (!Field->hasInClassInitializer() && !Field->isMutable()) {
1163 if (CXXRecordDecl *FieldType = T->getAsCXXRecordDecl()) {
1164 if (FieldType->hasDefinition() && !FieldType->allowConstDefaultInit())
1165 data().HasUninitializedFields = true;
1166 } else {
1167 data().HasUninitializedFields = true;
1168 }
1169 }
1170
1171 // Record if this field is the first non-literal or volatile field or base.
1172 if (!T->isLiteralType(Context) || T.isVolatileQualified())
1173 data().HasNonLiteralTypeFieldsOrBases = true;
1174
1175 if (Field->hasInClassInitializer() ||
1176 (Field->isAnonymousStructOrUnion() &&
1177 Field->getType()->getAsCXXRecordDecl()->hasInClassInitializer())) {
1178 data().HasInClassInitializer = true;
1179
1180 // C++11 [class]p5:
1181 // A default constructor is trivial if [...] no non-static data member
1182 // of its class has a brace-or-equal-initializer.
1183 data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor;
1184
1185 // C++11 [dcl.init.aggr]p1:
1186 // An aggregate is a [...] class with [...] no
1187 // brace-or-equal-initializers for non-static data members.
1188 //
1189 // This rule was removed in C++14.
1191 data().Aggregate = false;
1192
1193 // C++11 [class]p10:
1194 // A POD struct is [...] a trivial class.
1195 data().PlainOldData = false;
1196 }
1197
1198 // C++11 [class.copy]p23:
1199 // A defaulted copy/move assignment operator for a class X is defined
1200 // as deleted if X has:
1201 // -- a non-static data member of reference type
1202 if (T->isReferenceType()) {
1203 data().DefaultedCopyAssignmentIsDeleted = true;
1204 data().DefaultedMoveAssignmentIsDeleted = true;
1205 }
1206
1207 // Bitfields of length 0 are also zero-sized, but we already bailed out for
1208 // those because they are always unnamed.
1209 bool IsZeroSize = Field->isZeroSize(Context);
1210
1211 if (auto *FieldRec = T->getAsCXXRecordDecl()) {
1212 if (FieldRec->isBeingDefined() || FieldRec->isCompleteDefinition()) {
1213 addedClassSubobject(FieldRec);
1214
1215 // We may need to perform overload resolution to determine whether a
1216 // field can be moved if it's const or volatile qualified.
1218 // We need to care about 'const' for the copy constructor because an
1219 // implicit copy constructor might be declared with a non-const
1220 // parameter.
1221 data().NeedOverloadResolutionForCopyConstructor = true;
1222 data().NeedOverloadResolutionForMoveConstructor = true;
1223 data().NeedOverloadResolutionForCopyAssignment = true;
1224 data().NeedOverloadResolutionForMoveAssignment = true;
1225 }
1226
1227 // C++11 [class.ctor]p5, C++11 [class.copy]p11:
1228 // A defaulted [special member] for a class X is defined as
1229 // deleted if:
1230 // -- X is a union-like class that has a variant member with a
1231 // non-trivial [corresponding special member]
1232 if (isUnion()) {
1233 if (FieldRec->hasNonTrivialCopyConstructor())
1234 data().DefaultedCopyConstructorIsDeleted = true;
1235 if (FieldRec->hasNonTrivialMoveConstructor())
1236 data().DefaultedMoveConstructorIsDeleted = true;
1237 if (FieldRec->hasNonTrivialCopyAssignment())
1238 data().DefaultedCopyAssignmentIsDeleted = true;
1239 if (FieldRec->hasNonTrivialMoveAssignment())
1240 data().DefaultedMoveAssignmentIsDeleted = true;
1241 if (FieldRec->hasNonTrivialDestructor()) {
1242 data().DefaultedDestructorIsDeleted = true;
1243 // C++20 [dcl.constexpr]p5:
1244 // The definition of a constexpr destructor whose function-body is
1245 // not = delete shall additionally satisfy...
1246 data().DefaultedDestructorIsConstexpr = true;
1247 }
1248 }
1249
1250 // For an anonymous union member, our overload resolution will perform
1251 // overload resolution for its members.
1252 if (Field->isAnonymousStructOrUnion()) {
1253 data().NeedOverloadResolutionForCopyConstructor |=
1254 FieldRec->data().NeedOverloadResolutionForCopyConstructor;
1255 data().NeedOverloadResolutionForMoveConstructor |=
1256 FieldRec->data().NeedOverloadResolutionForMoveConstructor;
1257 data().NeedOverloadResolutionForCopyAssignment |=
1258 FieldRec->data().NeedOverloadResolutionForCopyAssignment;
1259 data().NeedOverloadResolutionForMoveAssignment |=
1260 FieldRec->data().NeedOverloadResolutionForMoveAssignment;
1261 data().NeedOverloadResolutionForDestructor |=
1262 FieldRec->data().NeedOverloadResolutionForDestructor;
1263 }
1264
1265 // C++0x [class.ctor]p5:
1266 // A default constructor is trivial [...] if:
1267 // -- for all the non-static data members of its class that are of
1268 // class type (or array thereof), each such class has a trivial
1269 // default constructor.
1270 if (!FieldRec->hasTrivialDefaultConstructor())
1271 data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor;
1272
1273 // C++0x [class.copy]p13:
1274 // A copy/move constructor for class X is trivial if [...]
1275 // [...]
1276 // -- for each non-static data member of X that is of class type (or
1277 // an array thereof), the constructor selected to copy/move that
1278 // member is trivial;
1279 if (!FieldRec->hasTrivialCopyConstructor())
1280 data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor;
1281
1282 if (!FieldRec->hasTrivialCopyConstructorForCall())
1283 data().HasTrivialSpecialMembersForCall &= ~SMF_CopyConstructor;
1284
1285 // If the field doesn't have a simple move constructor, we'll eagerly
1286 // declare the move constructor for this class and we'll decide whether
1287 // it's trivial then.
1288 if (!FieldRec->hasTrivialMoveConstructor())
1289 data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor;
1290
1291 if (!FieldRec->hasTrivialMoveConstructorForCall())
1292 data().HasTrivialSpecialMembersForCall &= ~SMF_MoveConstructor;
1293
1294 // C++0x [class.copy]p27:
1295 // A copy/move assignment operator for class X is trivial if [...]
1296 // [...]
1297 // -- for each non-static data member of X that is of class type (or
1298 // an array thereof), the assignment operator selected to
1299 // copy/move that member is trivial;
1300 if (!FieldRec->hasTrivialCopyAssignment())
1301 data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment;
1302 // If the field doesn't have a simple move assignment, we'll eagerly
1303 // declare the move assignment for this class and we'll decide whether
1304 // it's trivial then.
1305 if (!FieldRec->hasTrivialMoveAssignment())
1306 data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment;
1307
1308 if (!FieldRec->hasTrivialDestructor())
1309 data().HasTrivialSpecialMembers &= ~SMF_Destructor;
1310 if (!FieldRec->hasTrivialDestructorForCall())
1311 data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor;
1312 if (!FieldRec->hasIrrelevantDestructor())
1313 data().HasIrrelevantDestructor = false;
1314 if (FieldRec->isAnyDestructorNoReturn())
1315 data().IsAnyDestructorNoReturn = true;
1316 if (FieldRec->hasObjectMember())
1317 setHasObjectMember(true);
1318 if (FieldRec->hasVolatileMember())
1320 if (FieldRec->getArgPassingRestrictions() ==
1323
1324 // C++0x [class]p7:
1325 // A standard-layout class is a class that:
1326 // -- has no non-static data members of type non-standard-layout
1327 // class (or array of such types) [...]
1328 if (!FieldRec->isStandardLayout())
1329 data().IsStandardLayout = false;
1330 if (!FieldRec->isCXX11StandardLayout())
1331 data().IsCXX11StandardLayout = false;
1332
1333 // C++2a [class]p7:
1334 // A standard-layout class is a class that:
1335 // [...]
1336 // -- has no element of the set M(S) of types as a base class.
1337 if (data().IsStandardLayout &&
1338 (isUnion() || IsFirstField || IsZeroSize) &&
1339 hasSubobjectAtOffsetZeroOfEmptyBaseType(Context, FieldRec))
1340 data().IsStandardLayout = false;
1341
1342 // C++11 [class]p7:
1343 // A standard-layout class is a class that:
1344 // -- has no base classes of the same type as the first non-static
1345 // data member
1346 if (data().IsCXX11StandardLayout && IsFirstField) {
1347 // FIXME: We should check all base classes here, not just direct
1348 // base classes.
1349 for (const auto &BI : bases()) {
1350 if (Context.hasSameUnqualifiedType(BI.getType(), T)) {
1351 data().IsCXX11StandardLayout = false;
1352 break;
1353 }
1354 }
1355 }
1356
1357 // Keep track of the presence of mutable fields.
1358 if (FieldRec->hasMutableFields())
1359 data().HasMutableFields = true;
1360
1361 if (Field->isMutable()) {
1362 // Our copy constructor/assignment might call something other than
1363 // the subobject's copy constructor/assignment if it's mutable and of
1364 // class type.
1365 data().NeedOverloadResolutionForCopyConstructor = true;
1366 data().NeedOverloadResolutionForCopyAssignment = true;
1367 }
1368
1369 // C++11 [class.copy]p13:
1370 // If the implicitly-defined constructor would satisfy the
1371 // requirements of a constexpr constructor, the implicitly-defined
1372 // constructor is constexpr.
1373 // C++11 [dcl.constexpr]p4:
1374 // -- every constructor involved in initializing non-static data
1375 // members [...] shall be a constexpr constructor
1376 if (!Field->hasInClassInitializer() &&
1377 !FieldRec->hasConstexprDefaultConstructor() && !isUnion())
1378 // The standard requires any in-class initializer to be a constant
1379 // expression. We consider this to be a defect.
1380 data().DefaultedDefaultConstructorIsConstexpr =
1381 Context.getLangOpts().CPlusPlus23;
1382
1383 // C++11 [class.copy]p8:
1384 // The implicitly-declared copy constructor for a class X will have
1385 // the form 'X::X(const X&)' if each potentially constructed subobject
1386 // of a class type M (or array thereof) has a copy constructor whose
1387 // first parameter is of type 'const M&' or 'const volatile M&'.
1388 if (!FieldRec->hasCopyConstructorWithConstParam())
1389 data().ImplicitCopyConstructorCanHaveConstParamForNonVBase = false;
1390
1391 // C++11 [class.copy]p18:
1392 // The implicitly-declared copy assignment oeprator for a class X will
1393 // have the form 'X& X::operator=(const X&)' if [...] for all the
1394 // non-static data members of X that are of a class type M (or array
1395 // thereof), each such class type has a copy assignment operator whose
1396 // parameter is of type 'const M&', 'const volatile M&' or 'M'.
1397 if (!FieldRec->hasCopyAssignmentWithConstParam())
1398 data().ImplicitCopyAssignmentHasConstParam = false;
1399
1400 if (FieldRec->hasUninitializedExplicitInitFields() &&
1401 FieldRec->isAggregate())
1403
1404 if (FieldRec->hasUninitializedReferenceMember() &&
1405 !Field->hasInClassInitializer())
1406 data().HasUninitializedReferenceMember = true;
1407
1408 // C++11 [class.union]p8, DR1460:
1409 // a non-static data member of an anonymous union that is a member of
1410 // X is also a variant member of X.
1411 if (FieldRec->hasVariantMembers() &&
1412 Field->isAnonymousStructOrUnion())
1413 data().HasVariantMembers = true;
1414
1415 if (FieldRec->isPFPType())
1416 data().IsPFPType = true;
1417 }
1418 } else {
1419 // Base element type of field is a non-class type.
1420 if (!T->isLiteralType(Context) ||
1421 (!Field->hasInClassInitializer() && !isUnion() &&
1422 !Context.getLangOpts().CPlusPlus20))
1423 data().DefaultedDefaultConstructorIsConstexpr = false;
1424
1425 // C++11 [class.copy]p23:
1426 // A defaulted copy/move assignment operator for a class X is defined
1427 // as deleted if X has:
1428 // -- a non-static data member of const non-class type (or array
1429 // thereof)
1430 if (T.isConstQualified()) {
1431 data().DefaultedCopyAssignmentIsDeleted = true;
1432 data().DefaultedMoveAssignmentIsDeleted = true;
1433 }
1434
1435 // C++20 [temp.param]p7:
1436 // A structural type is [...] a literal class type [for which] the
1437 // types of all non-static data members are structural types or
1438 // (possibly multidimensional) array thereof
1439 // We deal with class types elsewhere.
1440 if (!T->isStructuralType())
1441 data().StructuralIfLiteral = false;
1442 }
1443
1444 // If this type contains any address discriminated values we should
1445 // have already indicated that the only special member functions that
1446 // can possibly be trivial are the default constructor and destructor.
1448 data().HasTrivialSpecialMembers &=
1449 SMF_DefaultConstructor | SMF_Destructor;
1450
1451 // C++14 [meta.unary.prop]p4:
1452 // T is a class type [...] with [...] no non-static data members other
1453 // than subobjects of zero size
1454 if (data().Empty && !IsZeroSize)
1455 data().Empty = false;
1456
1457 if (getLangOpts().HLSL) {
1458 const Type *Ty = Field->getType()->getUnqualifiedDesugaredType();
1459 while (isa<ConstantArrayType>(Ty))
1461
1462 Ty = Ty->getUnqualifiedDesugaredType();
1463 if (const RecordType *RT = dyn_cast<RecordType>(Ty))
1464 data().IsHLSLIntangible |= RT->getAsCXXRecordDecl()->isHLSLIntangible();
1465 else
1466 data().IsHLSLIntangible |= (Ty->isHLSLAttributedResourceType() ||
1468 }
1469 }
1470
1471 // Handle using declarations of conversion functions.
1472 if (auto *Shadow = dyn_cast<UsingShadowDecl>(D)) {
1473 if (Shadow->getDeclName().getNameKind()
1475 ASTContext &Ctx = getASTContext();
1476 data().Conversions.get(Ctx).addDecl(Ctx, Shadow, Shadow->getAccess());
1477 }
1478 }
1479
1480 if (const auto *Using = dyn_cast<UsingDecl>(D)) {
1481 if (Using->getDeclName().getNameKind() ==
1483 data().HasInheritedConstructor = true;
1484 // C++1z [dcl.init.aggr]p1:
1485 // An aggregate is [...] a class [...] with no inherited constructors
1486 data().Aggregate = false;
1487 }
1488
1489 if (Using->getDeclName().getCXXOverloadedOperator() == OO_Equal)
1490 data().HasInheritedAssignment = true;
1491 }
1492
1493 // HLSL: All user-defined data types are aggregates and use aggregate
1494 // initialization, meanwhile most, but not all built-in types behave like
1495 // aggregates. Resource types, and some other HLSL types that wrap handles
1496 // don't behave like aggregates. We can identify these as different because we
1497 // implicitly define "special" member functions, which aren't spellable in
1498 // HLSL. This all _needs_ to change in the future. There are two
1499 // relevant HLSL feature proposals that will depend on this changing:
1500 // * 0005-strict-initializer-lists.md
1501 // * https://github.com/microsoft/hlsl-specs/pull/325
1502 if (getLangOpts().HLSL)
1503 data().Aggregate = data().UserDeclaredSpecialMembers == 0;
1504}
1505
1507 const LangOptions &LangOpts = getLangOpts();
1508 if (!(LangOpts.CPlusPlus20 ? hasConstexprDestructor()
1510 return false;
1511
1513 // CWG2598
1514 // is an aggregate union type that has either no variant
1515 // members or at least one variant member of non-volatile literal type,
1516 if (!isUnion())
1517 return false;
1518 bool HasAtLeastOneLiteralMember =
1519 fields().empty() || any_of(fields(), [this](const FieldDecl *D) {
1520 return !D->getType().isVolatileQualified() &&
1522 });
1523 if (!HasAtLeastOneLiteralMember)
1524 return false;
1525 }
1526
1527 return isAggregate() || (isLambda() && LangOpts.CPlusPlus17) ||
1529}
1530
1535
1537 unsigned SMKind) {
1538 // FIXME: We shouldn't change DeclaredNonTrivialSpecialMembers if `MD` is
1539 // a function template, but this needs CWG attention before we break ABI.
1540 // See https://github.com/llvm/llvm-project/issues/59206
1541
1542 if (const auto *DD = dyn_cast<CXXDestructorDecl>(MD)) {
1543 if (DD->isUserProvided())
1544 data().HasIrrelevantDestructor = false;
1545 // If the destructor is explicitly defaulted and not trivial or not public
1546 // or if the destructor is deleted, we clear HasIrrelevantDestructor in
1547 // finishedDefaultedOrDeletedMember.
1548
1549 // C++11 [class.dtor]p5:
1550 // A destructor is trivial if [...] the destructor is not virtual.
1551 if (DD->isVirtual()) {
1552 data().HasTrivialSpecialMembers &= ~SMF_Destructor;
1553 data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor;
1554 }
1555
1556 if (DD->isNoReturn())
1557 data().IsAnyDestructorNoReturn = true;
1558 }
1559 if (!MD->isImplicit() && !MD->isUserProvided()) {
1560 // This method is user-declared but not user-provided. We can't work
1561 // out whether it's trivial yet (not until we get to the end of the
1562 // class). We'll handle this method in
1563 // finishedDefaultedOrDeletedMember.
1564 } else if (MD->isTrivial()) {
1565 data().HasTrivialSpecialMembers |= SMKind;
1566 data().HasTrivialSpecialMembersForCall |= SMKind;
1567 } else if (MD->isTrivialForCall()) {
1568 data().HasTrivialSpecialMembersForCall |= SMKind;
1569 data().DeclaredNonTrivialSpecialMembers |= SMKind;
1570 } else {
1571 data().DeclaredNonTrivialSpecialMembers |= SMKind;
1572 // If this is a user-provided function, do not set
1573 // DeclaredNonTrivialSpecialMembersForCall here since we don't know
1574 // yet whether the method would be considered non-trivial for the
1575 // purpose of calls (attribute "trivial_abi" can be dropped from the
1576 // class later, which can change the special method's triviality).
1577 if (!MD->isUserProvided())
1578 data().DeclaredNonTrivialSpecialMembersForCall |= SMKind;
1579 }
1580}
1581
1583 assert(!D->isImplicit() && !D->isUserProvided());
1584
1585 // The kind of special member this declaration is, if any.
1586 unsigned SMKind = 0;
1587
1588 if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(D)) {
1589 if (Constructor->isDefaultConstructor()) {
1590 SMKind |= SMF_DefaultConstructor;
1591 if (Constructor->isConstexpr())
1592 data().HasConstexprDefaultConstructor = true;
1593 }
1594 if (Constructor->isCopyConstructor())
1595 SMKind |= SMF_CopyConstructor;
1596 else if (Constructor->isMoveConstructor())
1597 SMKind |= SMF_MoveConstructor;
1598 else if (Constructor->isConstexpr())
1599 // We may now know that the constructor is constexpr.
1600 data().HasConstexprNonCopyMoveConstructor = true;
1601 } else if (isa<CXXDestructorDecl>(D)) {
1602 SMKind |= SMF_Destructor;
1603 if (!D->isTrivial() || D->getAccess() != AS_public || D->isDeleted())
1604 data().HasIrrelevantDestructor = false;
1605 } else if (D->isCopyAssignmentOperator())
1606 SMKind |= SMF_CopyAssignment;
1607 else if (D->isMoveAssignmentOperator())
1608 SMKind |= SMF_MoveAssignment;
1609
1610 // Update which trivial / non-trivial special members we have.
1611 // addedMember will have skipped this step for this member.
1612 if (!D->isIneligibleOrNotSelected()) {
1613 if (D->isTrivial())
1614 data().HasTrivialSpecialMembers |= SMKind;
1615 else
1616 data().DeclaredNonTrivialSpecialMembers |= SMKind;
1617 }
1618}
1619
1620void CXXRecordDecl::LambdaDefinitionData::AddCaptureList(ASTContext &Ctx,
1621 Capture *CaptureList) {
1622 Captures.push_back(CaptureList);
1623 if (Captures.size() == 2) {
1624 // The TinyPtrVector member now needs destruction.
1625 Ctx.addDestruction(&Captures);
1626 }
1627}
1628
1630 ArrayRef<LambdaCapture> Captures) {
1631 CXXRecordDecl::LambdaDefinitionData &Data = getLambdaData();
1632
1633 // Copy captures.
1634 Data.NumCaptures = Captures.size();
1635 Data.NumExplicitCaptures = 0;
1636 auto *ToCapture = (LambdaCapture *)Context.Allocate(sizeof(LambdaCapture) *
1637 Captures.size());
1638 Data.AddCaptureList(Context, ToCapture);
1639 for (const LambdaCapture &C : Captures) {
1640 if (C.isExplicit())
1641 ++Data.NumExplicitCaptures;
1642
1643 new (ToCapture) LambdaCapture(C);
1644 ToCapture++;
1645 }
1646
1648 Data.DefaultedCopyAssignmentIsDeleted = true;
1649}
1650
1652 unsigned SMKind = 0;
1653
1654 if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(D)) {
1655 if (Constructor->isCopyConstructor())
1656 SMKind = SMF_CopyConstructor;
1657 else if (Constructor->isMoveConstructor())
1658 SMKind = SMF_MoveConstructor;
1659 } else if (isa<CXXDestructorDecl>(D))
1660 SMKind = SMF_Destructor;
1661
1662 if (D->isTrivialForCall())
1663 data().HasTrivialSpecialMembersForCall |= SMKind;
1664 else
1665 data().DeclaredNonTrivialSpecialMembersForCall |= SMKind;
1666}
1667
1669 if (getTagKind() == TagTypeKind::Class ||
1671 !TemplateOrInstantiation.isNull())
1672 return false;
1673 if (!hasDefinition())
1674 return true;
1675
1676 return isPOD() && data().HasOnlyCMembers;
1677}
1678
1680 if (!isLambda()) return false;
1681 return getLambdaData().IsGenericLambda;
1682}
1683
1684#ifndef NDEBUG
1686 return llvm::all_of(R, [&](NamedDecl *D) {
1687 return D->isInvalidDecl() || declaresSameEntity(D, R.front());
1688 });
1689}
1690#endif
1691
1693 if (!RD.isLambda()) return nullptr;
1694 DeclarationName Name =
1696
1697 DeclContext::lookup_result Calls = RD.lookup(Name);
1698
1699 // This can happen while building the lambda.
1700 if (Calls.empty())
1701 return nullptr;
1702
1703 assert(allLookupResultsAreTheSame(Calls) &&
1704 "More than one lambda call operator!");
1705
1706 // FIXME: If we have multiple call operators, we might be in a situation
1707 // where we merged this lambda with one from another module; in that
1708 // case, return our method (instead of that of the other lambda).
1709 //
1710 // This avoids situations where, given two modules A and B, if we
1711 // try to instantiate A's call operator in a function in B, anything
1712 // in the call operator that relies on local decls in the surrounding
1713 // function will crash because it tries to find A's decls, but we only
1714 // instantiated B's:
1715 //
1716 // template <typename>
1717 // void f() {
1718 // using T = int; // We only instantiate B's version of this.
1719 // auto L = [](T) { }; // But A's call operator would want A's here.
1720 // }
1721 //
1722 // Walk the call operator’s redecl chain to find the one that belongs
1723 // to this module.
1724 //
1725 // TODO: We need to fix this properly (see
1726 // https://github.com/llvm/llvm-project/issues/90154).
1727 Module *M = RD.getOwningModule();
1728 for (Decl *D : Calls.front()->redecls()) {
1729 auto *MD = cast<NamedDecl>(D);
1730 if (MD->getOwningModule() == M)
1731 return MD;
1732 }
1733
1734 llvm_unreachable("Couldn't find our call operator!");
1735}
1736
1738 NamedDecl *CallOp = getLambdaCallOperatorHelper(*this);
1739 return dyn_cast_or_null<FunctionTemplateDecl>(CallOp);
1740}
1741
1743 NamedDecl *CallOp = getLambdaCallOperatorHelper(*this);
1744
1745 if (CallOp == nullptr)
1746 return nullptr;
1747
1748 if (const auto *CallOpTmpl = dyn_cast<FunctionTemplateDecl>(CallOp))
1749 return cast<CXXMethodDecl>(CallOpTmpl->getTemplatedDecl());
1750
1751 return cast<CXXMethodDecl>(CallOp);
1752}
1753
1756 assert(CallOp && "null call operator");
1757 CallingConv CC = CallOp->getType()->castAs<FunctionType>()->getCallConv();
1758 return getLambdaStaticInvoker(CC);
1759}
1760
1763 assert(RD.isLambda() && "Must be a lambda");
1764 DeclarationName Name =
1766 return RD.lookup(Name);
1767}
1768
1770 if (const auto *InvokerTemplate = dyn_cast<FunctionTemplateDecl>(ND))
1771 return cast<CXXMethodDecl>(InvokerTemplate->getTemplatedDecl());
1772 return cast<CXXMethodDecl>(ND);
1773}
1774
1776 if (!isLambda())
1777 return nullptr;
1779
1780 for (NamedDecl *ND : Invoker) {
1781 const auto *FTy =
1782 cast<ValueDecl>(ND->getAsFunction())->getType()->castAs<FunctionType>();
1783 if (FTy->getCallConv() == CC)
1784 return getInvokerAsMethod(ND);
1785 }
1786
1787 return nullptr;
1788}
1789
1791 llvm::DenseMap<const ValueDecl *, FieldDecl *> &Captures,
1792 FieldDecl *&ThisCapture) const {
1793 Captures.clear();
1794 ThisCapture = nullptr;
1795
1796 LambdaDefinitionData &Lambda = getLambdaData();
1797 for (const LambdaCapture *List : Lambda.Captures) {
1799 for (const LambdaCapture *C = List, *CEnd = C + Lambda.NumCaptures;
1800 C != CEnd; ++C, ++Field) {
1801 if (C->capturesThis())
1802 ThisCapture = *Field;
1803 else if (C->capturesVariable())
1804 Captures[C->getCapturedVar()] = *Field;
1805 }
1806 assert(Field == field_end());
1807 }
1808}
1809
1812 if (!isGenericLambda()) return nullptr;
1814 if (FunctionTemplateDecl *Tmpl = CallOp->getDescribedFunctionTemplate())
1815 return Tmpl->getTemplateParameters();
1816 return nullptr;
1817}
1818
1822 if (!List)
1823 return {};
1824
1825 assert(std::is_partitioned(List->begin(), List->end(),
1826 [](const NamedDecl *D) { return !D->isImplicit(); })
1827 && "Explicit template params should be ordered before implicit ones");
1828
1829 const auto ExplicitEnd = llvm::partition_point(
1830 *List, [](const NamedDecl *D) { return !D->isImplicit(); });
1831 return ArrayRef(List->begin(), ExplicitEnd);
1832}
1833
1835 assert(isLambda() && "Not a lambda closure type!");
1837 return getLambdaData().ContextDecl.get(Source);
1838}
1839
1841 assert(isLambda() && "Not a lambda closure type!");
1842 getLambdaData().ContextDecl = ContextDecl;
1843}
1844
1846 assert(isLambda() && "Not a lambda closure type!");
1847 getLambdaData().ManglingNumber = Numbering.ManglingNumber;
1848 if (Numbering.DeviceManglingNumber)
1849 getASTContext().DeviceLambdaManglingNumbers[this] =
1850 Numbering.DeviceManglingNumber;
1851 getLambdaData().IndexInContext = Numbering.IndexInContext;
1852 getLambdaData().HasKnownInternalLinkage = Numbering.HasKnownInternalLinkage;
1853}
1854
1856 assert(isLambda() && "Not a lambda closure type!");
1857 return getASTContext().DeviceLambdaManglingNumbers.lookup(this);
1858}
1859
1861 QualType T =
1863 ->getConversionType();
1864 return Context.getCanonicalType(T);
1865}
1866
1867/// Collect the visible conversions of a base class.
1868///
1869/// \param Record a base class of the class we're considering
1870/// \param InVirtual whether this base class is a virtual base (or a base
1871/// of a virtual base)
1872/// \param Access the access along the inheritance path to this base
1873/// \param ParentHiddenTypes the conversions provided by the inheritors
1874/// of this base
1875/// \param Output the set to which to add conversions from non-virtual bases
1876/// \param VOutput the set to which to add conversions from virtual bases
1877/// \param HiddenVBaseCs the set of conversions which were hidden in a
1878/// virtual base along some inheritance path
1880 ASTContext &Context, const CXXRecordDecl *Record, bool InVirtual,
1882 const llvm::SmallPtrSet<CanQualType, 8> &ParentHiddenTypes,
1883 ASTUnresolvedSet &Output, UnresolvedSetImpl &VOutput,
1884 llvm::SmallPtrSet<NamedDecl *, 8> &HiddenVBaseCs) {
1885 // The set of types which have conversions in this class or its
1886 // subclasses. As an optimization, we don't copy the derived set
1887 // unless it might change.
1888 const llvm::SmallPtrSet<CanQualType, 8> *HiddenTypes = &ParentHiddenTypes;
1889 llvm::SmallPtrSet<CanQualType, 8> HiddenTypesBuffer;
1890
1891 // Collect the direct conversions and figure out which conversions
1892 // will be hidden in the subclasses.
1893 CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin();
1894 CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end();
1895 if (ConvI != ConvE) {
1896 HiddenTypesBuffer = ParentHiddenTypes;
1897 HiddenTypes = &HiddenTypesBuffer;
1898
1899 for (CXXRecordDecl::conversion_iterator I = ConvI; I != ConvE; ++I) {
1900 CanQualType ConvType(GetConversionType(Context, I.getDecl()));
1901 bool Hidden = ParentHiddenTypes.count(ConvType);
1902 if (!Hidden)
1903 HiddenTypesBuffer.insert(ConvType);
1904
1905 // If this conversion is hidden and we're in a virtual base,
1906 // remember that it's hidden along some inheritance path.
1907 if (Hidden && InVirtual)
1908 HiddenVBaseCs.insert(cast<NamedDecl>(I.getDecl()->getCanonicalDecl()));
1909
1910 // If this conversion isn't hidden, add it to the appropriate output.
1911 else if (!Hidden) {
1912 AccessSpecifier IAccess
1913 = CXXRecordDecl::MergeAccess(Access, I.getAccess());
1914
1915 if (InVirtual)
1916 VOutput.addDecl(I.getDecl(), IAccess);
1917 else
1918 Output.addDecl(Context, I.getDecl(), IAccess);
1919 }
1920 }
1921 }
1922
1923 // Collect information recursively from any base classes.
1924 for (const auto &I : Record->bases()) {
1925 const auto *Base = I.getType()->getAsCXXRecordDecl();
1926 if (!Base)
1927 continue;
1928
1929 AccessSpecifier BaseAccess
1930 = CXXRecordDecl::MergeAccess(Access, I.getAccessSpecifier());
1931 bool BaseInVirtual = InVirtual || I.isVirtual();
1932
1933 CollectVisibleConversions(Context, Base, BaseInVirtual, BaseAccess,
1934 *HiddenTypes, Output, VOutput, HiddenVBaseCs);
1935 }
1936}
1937
1938/// Collect the visible conversions of a class.
1939///
1940/// This would be extremely straightforward if it weren't for virtual
1941/// bases. It might be worth special-casing that, really.
1943 const CXXRecordDecl *Record,
1944 ASTUnresolvedSet &Output) {
1945 // The collection of all conversions in virtual bases that we've
1946 // found. These will be added to the output as long as they don't
1947 // appear in the hidden-conversions set.
1948 UnresolvedSet<8> VBaseCs;
1949
1950 // The set of conversions in virtual bases that we've determined to
1951 // be hidden.
1953
1954 // The set of types hidden by classes derived from this one.
1956
1957 // Go ahead and collect the direct conversions and add them to the
1958 // hidden-types set.
1959 CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin();
1960 CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end();
1961 Output.append(Context, ConvI, ConvE);
1962 for (; ConvI != ConvE; ++ConvI)
1963 HiddenTypes.insert(GetConversionType(Context, ConvI.getDecl()));
1964
1965 // Recursively collect conversions from base classes.
1966 for (const auto &I : Record->bases()) {
1967 const auto *Base = I.getType()->getAsCXXRecordDecl();
1968 if (!Base)
1969 continue;
1970
1971 CollectVisibleConversions(Context, Base, I.isVirtual(),
1972 I.getAccessSpecifier(), HiddenTypes, Output,
1973 VBaseCs, HiddenVBaseCs);
1974 }
1975
1976 // Add any unhidden conversions provided by virtual bases.
1977 for (UnresolvedSetIterator I = VBaseCs.begin(), E = VBaseCs.end();
1978 I != E; ++I) {
1979 if (!HiddenVBaseCs.count(cast<NamedDecl>(I.getDecl()->getCanonicalDecl())))
1980 Output.addDecl(Context, I.getDecl(), I.getAccess());
1981 }
1982}
1983
1984/// getVisibleConversionFunctions - get all conversion functions visible
1985/// in current class; including conversion function templates.
1986llvm::iterator_range<CXXRecordDecl::conversion_iterator>
1988 ASTContext &Ctx = getASTContext();
1989
1991 if (bases().empty()) {
1992 // If root class, all conversions are visible.
1993 Set = &data().Conversions.get(Ctx);
1994 } else {
1995 Set = &data().VisibleConversions.get(Ctx);
1996 // If visible conversion list is not evaluated, evaluate it.
1997 if (!data().ComputedVisibleConversions) {
1998 CollectVisibleConversions(Ctx, this, *Set);
1999 data().ComputedVisibleConversions = true;
2000 }
2001 }
2002 return llvm::make_range(Set->begin(), Set->end());
2003}
2004
2006 // This operation is O(N) but extremely rare. Sema only uses it to
2007 // remove UsingShadowDecls in a class that were followed by a direct
2008 // declaration, e.g.:
2009 // class A : B {
2010 // using B::operator int;
2011 // operator int();
2012 // };
2013 // This is uncommon by itself and even more uncommon in conjunction
2014 // with sufficiently large numbers of directly-declared conversions
2015 // that asymptotic behavior matters.
2016
2017 ASTUnresolvedSet &Convs = data().Conversions.get(getASTContext());
2018 for (unsigned I = 0, E = Convs.size(); I != E; ++I) {
2019 if (Convs[I].getDecl() == ConvDecl) {
2020 Convs.erase(I);
2021 assert(!llvm::is_contained(Convs, ConvDecl) &&
2022 "conversion was found multiple times in unresolved set");
2023 return;
2024 }
2025 }
2026
2027 llvm_unreachable("conversion not found in set!");
2028}
2029
2032 return cast<CXXRecordDecl>(MSInfo->getInstantiatedFrom());
2033
2034 return nullptr;
2035}
2036
2038 return dyn_cast_if_present<MemberSpecializationInfo *>(
2039 TemplateOrInstantiation);
2040}
2041
2042void
2045 assert(TemplateOrInstantiation.isNull() &&
2046 "Previous template or instantiation?");
2048 TemplateOrInstantiation
2049 = new (getASTContext()) MemberSpecializationInfo(RD, TSK);
2050}
2051
2053 return dyn_cast_if_present<ClassTemplateDecl *>(TemplateOrInstantiation);
2054}
2055
2059
2061 if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(this))
2062 return Spec->getSpecializationKind();
2063
2065 return MSInfo->getTemplateSpecializationKind();
2066
2067 return TSK_Undeclared;
2068}
2069
2070void
2072 if (auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(this)) {
2073 Spec->setSpecializationKind(TSK);
2074 return;
2075 }
2076
2078 MSInfo->setTemplateSpecializationKind(TSK);
2079 return;
2080 }
2081
2082 llvm_unreachable("Not a class template or member class specialization");
2083}
2084
2086 // If it's a class template specialization, find the template or partial
2087 // specialization from which it was instantiated.
2088 if (auto *TD = dyn_cast<ClassTemplateSpecializationDecl>(this)) {
2089 auto From = TD->getInstantiatedFrom();
2090 if (auto *CTD = dyn_cast_if_present<ClassTemplateDecl *>(From)) {
2091 while (auto *NewCTD = CTD->getInstantiatedFromMemberTemplate()) {
2092 if (NewCTD->isMemberSpecialization())
2093 break;
2094 CTD = NewCTD;
2095 }
2096 return CTD->getTemplatedDecl();
2097 }
2098 if (auto *CTPSD =
2099 dyn_cast_if_present<ClassTemplatePartialSpecializationDecl *>(
2100 From)) {
2101 while (auto *NewCTPSD = CTPSD->getInstantiatedFromMember()) {
2102 if (NewCTPSD->isMemberSpecialization())
2103 break;
2104 CTPSD = NewCTPSD;
2105 }
2106 return CTPSD;
2107 }
2108 }
2109
2111 if (isTemplateInstantiation(MSInfo->getTemplateSpecializationKind())) {
2112 const CXXRecordDecl *RD = this;
2113 while (auto *NewRD = RD->getInstantiatedFromMemberClass())
2114 RD = NewRD;
2115 return RD;
2116 }
2117 }
2118
2120 "couldn't find pattern for class template instantiation");
2121 return nullptr;
2122}
2123
2125 ASTContext &Context = getASTContext();
2126 CanQualType ClassType = Context.getCanonicalTagType(this);
2127
2128 DeclarationName Name =
2129 Context.DeclarationNames.getCXXDestructorName(ClassType);
2130
2132
2133 // If a destructor was marked as not selected, we skip it. We don't always
2134 // have a selected destructor: dependent types, unnamed structs.
2135 for (auto *Decl : R) {
2136 auto* DD = dyn_cast<CXXDestructorDecl>(Decl);
2137 if (DD && !DD->isIneligibleOrNotSelected())
2138 return DD;
2139 }
2140 return nullptr;
2141}
2142
2144 if (const CXXDestructorDecl *D = getDestructor())
2145 return D->isDeleted();
2146 return false;
2147}
2148
2150 if (!isImplicit() || !getDeclName())
2151 return false;
2152
2153 if (const auto *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
2154 return RD->getDeclName() == getDeclName();
2155
2156 return false;
2157}
2158
2160 switch (getDeclKind()) {
2161 case Decl::ClassTemplatePartialSpecialization:
2162 return true;
2163 case Decl::ClassTemplateSpecialization:
2164 return false;
2165 case Decl::CXXRecord:
2166 return getDescribedClassTemplate() != nullptr;
2167 default:
2168 llvm_unreachable("unexpected decl kind");
2169 }
2170}
2171
2173 const ASTContext &Ctx) const {
2174 if (auto *RD = dyn_cast<ClassTemplatePartialSpecializationDecl>(this))
2175 return RD->getCanonicalInjectedSpecializationType(Ctx);
2178 return TD->getCanonicalInjectedSpecializationType(Ctx);
2179 return CanQualType();
2180}
2181
2183 while (!DC->isTranslationUnit()) {
2184 if (DC->isNamespace())
2185 return true;
2186 DC = DC->getParent();
2187 }
2188 return false;
2189}
2190
2192 assert(hasDefinition() && "checking for interface-like without a definition");
2193 // All __interfaces are inheritently interface-like.
2194 if (isInterface())
2195 return true;
2196
2197 // Interface-like types cannot have a user declared constructor, destructor,
2198 // friends, VBases, conversion functions, or fields. Additionally, lambdas
2199 // cannot be interface types.
2202 getNumVBases() > 0 || conversion_end() - conversion_begin() > 0)
2203 return false;
2204
2205 // No interface-like type can have a method with a definition.
2206 for (const auto *const Method : methods())
2207 if (Method->isDefined() && !Method->isImplicit())
2208 return false;
2209
2210 // Check "Special" types.
2211 const auto *Uuid = getAttr<UuidAttr>();
2212 // MS SDK declares IUnknown/IDispatch both in the root of a TU, or in an
2213 // extern C++ block directly in the TU. These are only valid if in one
2214 // of these two situations.
2215 if (Uuid && isStruct() && !getDeclContext()->isExternCContext() &&
2217 ((getName() == "IUnknown" &&
2218 Uuid->getGuid() == "00000000-0000-0000-C000-000000000046") ||
2219 (getName() == "IDispatch" &&
2220 Uuid->getGuid() == "00020400-0000-0000-C000-000000000046"))) {
2221 if (getNumBases() > 0)
2222 return false;
2223 return true;
2224 }
2225
2226 // FIXME: Any access specifiers is supposed to make this no longer interface
2227 // like.
2228
2229 // If this isn't a 'special' type, it must have a single interface-like base.
2230 if (getNumBases() != 1)
2231 return false;
2232
2233 const auto BaseSpec = *bases_begin();
2234 if (BaseSpec.isVirtual() || BaseSpec.getAccessSpecifier() != AS_public)
2235 return false;
2236 const auto *Base = BaseSpec.getType()->getAsCXXRecordDecl();
2237 if (Base->isInterface() || !Base->isInterfaceLike())
2238 return false;
2239 return true;
2240}
2241
2245
2247 const CXXRecordDecl &RD, const CXXFinalOverriderMap *FinalOverriders) {
2248 if (!FinalOverriders) {
2249 CXXFinalOverriderMap MyFinalOverriders;
2250 RD.getFinalOverriders(MyFinalOverriders);
2251 return hasPureVirtualFinalOverrider(RD, &MyFinalOverriders);
2252 }
2253
2254 for (const CXXFinalOverriderMap::value_type &
2255 OverridingMethodsEntry : *FinalOverriders) {
2256 for (const auto &[_, SubobjOverrides] : OverridingMethodsEntry.second) {
2257 assert(SubobjOverrides.size() > 0 &&
2258 "All virtual functions have overriding virtual functions");
2259
2260 if (SubobjOverrides.front().Method->isPureVirtual())
2261 return true;
2262 }
2263 }
2264 return false;
2265}
2266
2269
2270 // If the class may be abstract (but hasn't been marked as such), check for
2271 // any pure final overriders.
2272 //
2273 // C++ [class.abstract]p4:
2274 // A class is abstract if it contains or inherits at least one
2275 // pure virtual function for which the final overrider is pure
2276 // virtual.
2277 if (mayBeAbstract() && hasPureVirtualFinalOverrider(*this, FinalOverriders))
2278 markAbstract();
2279
2280 // Set access bits correctly on the directly-declared conversions.
2282 I != E; ++I)
2283 I.setAccess((*I)->getAccess());
2284
2285 ASTContext &Context = getASTContext();
2286
2288 !Context.getLangOpts().CPlusPlus20) {
2289 // Diagnose any aggregate behavior changes in C++20
2290 for (const FieldDecl *FD : fields()) {
2291 if (const auto *AT = FD->getAttr<ExplicitInitAttr>())
2292 Context.getDiagnostics().Report(
2293 AT->getLocation(),
2294 diag::warn_cxx20_compat_requires_explicit_init_non_aggregate)
2295 << AT << FD << Context.getCanonicalTagType(this);
2296 }
2297 }
2298
2300 // Diagnose any fields that required explicit initialization in a
2301 // non-aggregate type. (Note that the fields may not be directly in this
2302 // type, but in a subobject. In such cases we don't emit diagnoses here.)
2303 for (const FieldDecl *FD : fields()) {
2304 if (const auto *AT = FD->getAttr<ExplicitInitAttr>())
2305 Context.getDiagnostics().Report(AT->getLocation(),
2306 diag::warn_attribute_needs_aggregate)
2307 << AT << Context.getCanonicalTagType(this);
2308 }
2310 }
2311
2312 if (getLangOpts().PointerFieldProtectionABI && !isStandardLayout()) {
2313 data().IsPFPType = true;
2315 data().IsPFPType = true;
2316 data().IsStandardLayout = false;
2317 data().IsCXX11StandardLayout = false;
2318 }
2319}
2320
2322 if (data().Abstract || isInvalidDecl() || !data().Polymorphic ||
2324 return false;
2325
2326 for (const auto &B : bases()) {
2327 const auto *BaseDecl = cast<CXXRecordDecl>(
2328 B.getType()->castAsCanonical<RecordType>()->getDecl());
2329 if (BaseDecl->isAbstract())
2330 return true;
2331 }
2332
2333 return false;
2334}
2335
2337 auto *Def = getDefinition();
2338 if (!Def)
2339 return false;
2340 if (Def->hasAttr<FinalAttr>())
2341 return true;
2342 if (const auto *Dtor = Def->getDestructor())
2343 if (Dtor->hasAttr<FinalAttr>())
2344 return true;
2345 return false;
2346}
2347
2348void CXXDeductionGuideDecl::anchor() {}
2349
2351 if ((getKind() != Other.getKind() ||
2354 Other.getKind() == ExplicitSpecKind::Unresolved) {
2355 ODRHash SelfHash, OtherHash;
2356 SelfHash.AddStmt(getExpr());
2357 OtherHash.AddStmt(Other.getExpr());
2358 return SelfHash.CalculateHash() == OtherHash.CalculateHash();
2359 } else
2360 return false;
2361 }
2362 return true;
2363}
2364
2366 switch (Function->getDeclKind()) {
2367 case Decl::Kind::CXXConstructor:
2368 return cast<CXXConstructorDecl>(Function)->getExplicitSpecifier();
2369 case Decl::Kind::CXXConversion:
2370 return cast<CXXConversionDecl>(Function)->getExplicitSpecifier();
2371 case Decl::Kind::CXXDeductionGuide:
2372 return cast<CXXDeductionGuideDecl>(Function)->getExplicitSpecifier();
2373 default:
2374 return {};
2375 }
2376}
2377
2378CXXDeductionGuideDecl *CXXDeductionGuideDecl::Create(
2379 ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
2380 ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T,
2381 TypeSourceInfo *TInfo, SourceLocation EndLocation, CXXConstructorDecl *Ctor,
2382 DeductionCandidate Kind, const AssociatedConstraint &TrailingRequiresClause,
2383 const CXXDeductionGuideDecl *GeneratedFrom,
2384 SourceDeductionGuideKind SourceKind) {
2385 return new (C, DC) CXXDeductionGuideDecl(
2386 C, DC, StartLoc, ES, NameInfo, T, TInfo, EndLocation, Ctor, Kind,
2387 TrailingRequiresClause, GeneratedFrom, SourceKind);
2388}
2389
2392 return new (C, ID) CXXDeductionGuideDecl(
2393 C, /*DC=*/nullptr, SourceLocation(), ExplicitSpecifier(),
2394 DeclarationNameInfo(), QualType(), /*TInfo=*/nullptr, SourceLocation(),
2395 /*Ctor=*/nullptr, DeductionCandidate::Normal,
2396 /*TrailingRequiresClause=*/{},
2397 /*GeneratedFrom=*/nullptr, SourceDeductionGuideKind::None);
2398}
2399
2400RequiresExprBodyDecl *RequiresExprBodyDecl::Create(
2401 ASTContext &C, DeclContext *DC, SourceLocation StartLoc) {
2402 return new (C, DC) RequiresExprBodyDecl(C, DC, StartLoc);
2403}
2404
2407 return new (C, ID) RequiresExprBodyDecl(C, nullptr, SourceLocation());
2408}
2409
2410void CXXMethodDecl::anchor() {}
2411
2413 const CXXMethodDecl *MD = getCanonicalDecl();
2414
2415 if (MD->getStorageClass() == SC_Static)
2416 return true;
2417
2419 return isStaticOverloadedOperator(OOK);
2420}
2421
2422static bool recursivelyOverrides(const CXXMethodDecl *DerivedMD,
2423 const CXXMethodDecl *BaseMD) {
2424 for (const CXXMethodDecl *MD : DerivedMD->overridden_methods()) {
2425 if (MD->getCanonicalDecl() == BaseMD->getCanonicalDecl())
2426 return true;
2427 if (recursivelyOverrides(MD, BaseMD))
2428 return true;
2429 }
2430 return false;
2431}
2432
2433CXXMethodDecl *
2435 bool MayBeBase) {
2436 if (this->getParent()->getCanonicalDecl() == RD->getCanonicalDecl())
2437 return this;
2438
2439 // Lookup doesn't work for destructors, so handle them separately.
2440 if (isa<CXXDestructorDecl>(this)) {
2441 CXXMethodDecl *MD = RD->getDestructor();
2442 if (MD) {
2443 if (recursivelyOverrides(MD, this))
2444 return MD;
2445 if (MayBeBase && recursivelyOverrides(this, MD))
2446 return MD;
2447 }
2448 return nullptr;
2449 }
2450
2451 for (auto *ND : RD->lookup(getDeclName())) {
2452 auto *MD = dyn_cast<CXXMethodDecl>(ND);
2453 if (!MD)
2454 continue;
2455 if (recursivelyOverrides(MD, this))
2456 return MD;
2457 if (MayBeBase && recursivelyOverrides(this, MD))
2458 return MD;
2459 }
2460
2461 return nullptr;
2462}
2463
2466 bool MayBeBase) {
2467 if (auto *MD = getCorrespondingMethodDeclaredInClass(RD, MayBeBase))
2468 return MD;
2469
2471 auto AddFinalOverrider = [&](CXXMethodDecl *D) {
2472 // If this function is overridden by a candidate final overrider, it is not
2473 // a final overrider.
2474 for (CXXMethodDecl *OtherD : FinalOverriders) {
2475 if (declaresSameEntity(D, OtherD) || recursivelyOverrides(OtherD, D))
2476 return;
2477 }
2478
2479 // Other candidate final overriders might be overridden by this function.
2480 llvm::erase_if(FinalOverriders, [&](CXXMethodDecl *OtherD) {
2481 return recursivelyOverrides(D, OtherD);
2482 });
2483
2484 FinalOverriders.push_back(D);
2485 };
2486
2487 for (const auto &I : RD->bases()) {
2488 const auto *Base = I.getType()->getAsCXXRecordDecl();
2489 if (!Base)
2490 continue;
2492 AddFinalOverrider(D);
2493 }
2494
2495 return FinalOverriders.size() == 1 ? FinalOverriders.front() : nullptr;
2496}
2497
2500 const DeclarationNameInfo &NameInfo, QualType T,
2501 TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin,
2502 bool isInline, ConstexprSpecKind ConstexprKind,
2503 SourceLocation EndLocation,
2504 const AssociatedConstraint &TrailingRequiresClause) {
2505 return new (C, RD) CXXMethodDecl(
2506 CXXMethod, C, RD, StartLoc, NameInfo, T, TInfo, SC, UsesFPIntrin,
2507 isInline, ConstexprKind, EndLocation, TrailingRequiresClause);
2508}
2509
2511 GlobalDeclID ID) {
2512 return new (C, ID)
2513 CXXMethodDecl(CXXMethod, C, nullptr, SourceLocation(),
2514 DeclarationNameInfo(), QualType(), nullptr, SC_None, false,
2516 /*TrailingRequiresClause=*/{});
2517}
2518
2520 bool IsAppleKext) {
2521 assert(isVirtual() && "this method is expected to be virtual");
2522
2523 // When building with -fapple-kext, all calls must go through the vtable since
2524 // the kernel linker can do runtime patching of vtables.
2525 if (IsAppleKext)
2526 return nullptr;
2527
2528 // If the member function is marked 'final', we know that it can't be
2529 // overridden and can therefore devirtualize it unless it's pure virtual.
2530 if (hasAttr<FinalAttr>())
2531 return isPureVirtual() ? nullptr : this;
2532
2533 // If Base is unknown, we cannot devirtualize.
2534 if (!Base)
2535 return nullptr;
2536
2537 // If the base expression (after skipping derived-to-base conversions) is a
2538 // class prvalue, then we can devirtualize.
2539 Base = Base->getBestDynamicClassTypeExpr();
2540 if (Base->isPRValue() && Base->getType()->isRecordType())
2541 return this;
2542
2543 // If we don't even know what we would call, we can't devirtualize.
2544 const CXXRecordDecl *BestDynamicDecl = Base->getBestDynamicClassType();
2545 if (!BestDynamicDecl)
2546 return nullptr;
2547
2548 // There may be a method corresponding to MD in a derived class.
2549 CXXMethodDecl *DevirtualizedMethod =
2550 getCorrespondingMethodInClass(BestDynamicDecl);
2551
2552 // If there final overrider in the dynamic type is ambiguous, we can't
2553 // devirtualize this call.
2554 if (!DevirtualizedMethod)
2555 return nullptr;
2556
2557 // If that method is pure virtual, we can't devirtualize. If this code is
2558 // reached, the result would be UB, not a direct call to the derived class
2559 // function, and we can't assume the derived class function is defined.
2560 if (DevirtualizedMethod->isPureVirtual())
2561 return nullptr;
2562
2563 // If that method is marked final, we can devirtualize it.
2564 if (DevirtualizedMethod->hasAttr<FinalAttr>())
2565 return DevirtualizedMethod;
2566
2567 // Similarly, if the class itself or its destructor is marked 'final',
2568 // the class can't be derived from and we can therefore devirtualize the
2569 // member function call.
2570 if (BestDynamicDecl->isEffectivelyFinal())
2571 return DevirtualizedMethod;
2572
2573 if (const auto *DRE = dyn_cast<DeclRefExpr>(Base)) {
2574 if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl()))
2575 if (VD->getType()->isRecordType())
2576 // This is a record decl. We know the type and can devirtualize it.
2577 return DevirtualizedMethod;
2578
2579 return nullptr;
2580 }
2581
2582 // We can devirtualize calls on an object accessed by a class member access
2583 // expression, since by C++11 [basic.life]p6 we know that it can't refer to
2584 // a derived class object constructed in the same location.
2585 if (const auto *ME = dyn_cast<MemberExpr>(Base)) {
2586 const ValueDecl *VD = ME->getMemberDecl();
2587 return VD->getType()->isRecordType() ? DevirtualizedMethod : nullptr;
2588 }
2589
2590 // Likewise for calls on an object accessed by a (non-reference) pointer to
2591 // member access.
2592 if (auto *BO = dyn_cast<BinaryOperator>(Base)) {
2593 if (BO->isPtrMemOp()) {
2594 auto *MPT = BO->getRHS()->getType()->castAs<MemberPointerType>();
2595 if (MPT->getPointeeType()->isRecordType())
2596 return DevirtualizedMethod;
2597 }
2598 }
2599
2600 // We can't devirtualize the call.
2601 return nullptr;
2602}
2603
2605 SmallVectorImpl<const FunctionDecl *> &PreventedBy) const {
2606 assert(PreventedBy.empty() && "PreventedBy is expected to be empty");
2607 if (!getDeclName().isAnyOperatorDelete())
2608 return false;
2609
2611 // A variadic type aware allocation function is not a usual deallocation
2612 // function
2613 if (isVariadic())
2614 return false;
2615
2616 // Type aware deallocation functions are only usual if they only accept the
2617 // mandatory arguments
2619 return false;
2620
2621 FunctionTemplateDecl *PrimaryTemplate = getPrimaryTemplate();
2622 if (!PrimaryTemplate)
2623 return true;
2624
2625 // A template instance is is only a usual deallocation function if it has a
2626 // type-identity parameter, the type-identity parameter is a dependent type
2627 // (i.e. the type-identity parameter is of type std::type_identity<U> where
2628 // U shall be a dependent type), and the type-identity parameter is the only
2629 // dependent parameter, and there are no template packs in the parameter
2630 // list.
2631 FunctionDecl *SpecializedDecl = PrimaryTemplate->getTemplatedDecl();
2632 if (!SpecializedDecl->getParamDecl(0)->getType()->isDependentType())
2633 return false;
2634 for (unsigned Idx = 1; Idx < getNumParams(); ++Idx) {
2635 if (SpecializedDecl->getParamDecl(Idx)->getType()->isDependentType())
2636 return false;
2637 }
2638 return true;
2639 }
2640
2641 // C++ [basic.stc.dynamic.deallocation]p2:
2642 // A template instance is never a usual deallocation function,
2643 // regardless of its signature.
2644 // Post-P2719 adoption:
2645 // A template instance is is only a usual deallocation function if it has a
2646 // type-identity parameter
2647 if (getPrimaryTemplate())
2648 return false;
2649
2650 // C++ [basic.stc.dynamic.deallocation]p2:
2651 // If a class T has a member deallocation function named operator delete
2652 // with exactly one parameter, then that function is a usual (non-placement)
2653 // deallocation function. [...]
2654 if (getNumParams() == 1)
2655 return true;
2656 unsigned UsualParams = 1;
2657
2658 // C++ P0722:
2659 // A destroying operator delete is a usual deallocation function if
2660 // removing the std::destroying_delete_t parameter and changing the
2661 // first parameter type from T* to void* results in the signature of
2662 // a usual deallocation function.
2664 ++UsualParams;
2665
2666 // C++ <=14 [basic.stc.dynamic.deallocation]p2:
2667 // [...] If class T does not declare such an operator delete but does
2668 // declare a member deallocation function named operator delete with
2669 // exactly two parameters, the second of which has type std::size_t (18.1),
2670 // then this function is a usual deallocation function.
2671 //
2672 // C++17 says a usual deallocation function is one with the signature
2673 // (void* [, size_t] [, std::align_val_t] [, ...])
2674 // and all such functions are usual deallocation functions. It's not clear
2675 // that allowing varargs functions was intentional.
2676 ASTContext &Context = getASTContext();
2677 if (UsualParams < getNumParams() &&
2678 Context.hasSameUnqualifiedType(getParamDecl(UsualParams)->getType(),
2679 Context.getSizeType()))
2680 ++UsualParams;
2681
2682 if (UsualParams < getNumParams() &&
2683 getParamDecl(UsualParams)->getType()->isAlignValT())
2684 ++UsualParams;
2685
2686 if (UsualParams != getNumParams())
2687 return false;
2688
2689 // In C++17 onwards, all potential usual deallocation functions are actual
2690 // usual deallocation functions. Honor this behavior when post-C++14
2691 // deallocation functions are offered as extensions too.
2692 // FIXME(EricWF): Destroying Delete should be a language option. How do we
2693 // handle when destroying delete is used prior to C++17?
2694 if (Context.getLangOpts().CPlusPlus17 ||
2695 Context.getLangOpts().AlignedAllocation ||
2697 return true;
2698
2699 // This function is a usual deallocation function if there are no
2700 // single-parameter deallocation functions of the same kind.
2702 bool Result = true;
2703 for (const auto *D : R) {
2704 if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
2705 if (FD->getNumParams() == 1) {
2706 PreventedBy.push_back(FD);
2707 Result = false;
2708 }
2709 }
2710 }
2711 return Result;
2712}
2713
2715 // C++2b [dcl.fct]p6:
2716 // An explicit object member function is a non-static member
2717 // function with an explicit object parameter
2719}
2720
2724
2726 // C++0x [class.copy]p17:
2727 // A user-declared copy assignment operator X::operator= is a non-static
2728 // non-template member function of class X with exactly one parameter of
2729 // type X, X&, const X&, volatile X& or const volatile X&.
2730 if (/*operator=*/getOverloadedOperator() != OO_Equal ||
2731 /*non-static*/ isStatic() ||
2732
2733 /*non-template*/ getPrimaryTemplate() || getDescribedFunctionTemplate() ||
2734 getNumExplicitParams() != 1)
2735 return false;
2736
2737 QualType ParamType = getNonObjectParameter(0)->getType();
2738 if (const auto *Ref = ParamType->getAs<LValueReferenceType>())
2739 ParamType = Ref->getPointeeType();
2740
2741 ASTContext &Context = getASTContext();
2742 CanQualType ClassType = Context.getCanonicalTagType(getParent());
2743 return Context.hasSameUnqualifiedType(ClassType, ParamType);
2744}
2745
2747 // C++0x [class.copy]p19:
2748 // A user-declared move assignment operator X::operator= is a non-static
2749 // non-template member function of class X with exactly one parameter of type
2750 // X&&, const X&&, volatile X&&, or const volatile X&&.
2751 if (getOverloadedOperator() != OO_Equal || isStatic() ||
2753 getNumExplicitParams() != 1)
2754 return false;
2755
2756 QualType ParamType = getNonObjectParameter(0)->getType();
2757 if (!ParamType->isRValueReferenceType())
2758 return false;
2759 ParamType = ParamType->getPointeeType();
2760
2761 ASTContext &Context = getASTContext();
2762 CanQualType ClassType = Context.getCanonicalTagType(getParent());
2763 return Context.hasSameUnqualifiedType(ClassType, ParamType);
2764}
2765
2767 if (const auto *Ctor = dyn_cast<CXXConstructorDecl>(this))
2768 return Ctor->isCopyOrMoveConstructor();
2769 return false;
2770}
2771
2776
2778 const ASTContext &Ctx) const {
2780 return false;
2781
2782 // Non-trivially-copyable fields with pointer field protection need to be
2783 // copied one by one.
2784 const CXXRecordDecl *Parent = getParent();
2785 if (!Ctx.arePFPFieldsTriviallyCopyable(Parent) &&
2786 Ctx.hasPFPFields(Ctx.getCanonicalTagType(Parent)))
2787 return false;
2788
2789 // We can emit a memcpy for a trivial copy or move constructor/assignment.
2790 if (isTrivial() && !Parent->mayInsertExtraPadding())
2791 return true;
2792
2793 // We *must* emit a memcpy for a defaulted union copy or move op.
2794 if (Parent->isUnion() && isDefaulted())
2795 return true;
2796
2797 return false;
2798}
2799
2801 assert(MD->isCanonicalDecl() && "Method is not canonical!");
2802 assert(MD->isVirtual() && "Method is not virtual!");
2803
2805}
2806
2811
2816
2818 if (isa<CXXConstructorDecl>(this)) return 0;
2820}
2821
2824 if (isa<CXXConstructorDecl>(this))
2825 return overridden_method_range(nullptr, nullptr);
2826 return getASTContext().overridden_methods(this);
2827}
2828
2830 const CXXRecordDecl *Decl) {
2831 CanQualType ClassTy = C.getCanonicalTagType(Decl);
2832 return C.getQualifiedType(ClassTy, FPT->getMethodQuals());
2833}
2834
2836 const CXXRecordDecl *Decl) {
2838 QualType ObjectTy = ::getThisObjectType(C, FPT, Decl);
2839
2840 // Unlike 'const' and 'volatile', a '__restrict' qualifier must be
2841 // attached to the pointer type, not the pointee.
2842 bool Restrict = FPT->getMethodQuals().hasRestrict();
2843 if (Restrict)
2844 ObjectTy.removeLocalRestrict();
2845
2846 ObjectTy = C.getLangOpts().HLSL ? C.getLValueReferenceType(ObjectTy)
2847 : C.getPointerType(ObjectTy);
2848
2849 if (Restrict)
2850 ObjectTy.addRestrict();
2851 return ObjectTy;
2852}
2853
2855 // C++ 9.3.2p1: The type of this in a member function of a class X is X*.
2856 // If the member function is declared const, the type of this is const X*,
2857 // if the member function is declared volatile, the type of this is
2858 // volatile X*, and if the member function is declared const volatile,
2859 // the type of this is const volatile X*.
2860 assert(isInstance() && "No 'this' for static methods!");
2861 return CXXMethodDecl::getThisType(getType()->castAs<FunctionProtoType>(),
2862 getParent());
2863}
2864
2867 return parameters()[0]->getType();
2868
2870 const FunctionProtoType *FPT = getType()->castAs<FunctionProtoType>();
2874 return C.getRValueReferenceType(Type);
2875 return C.getLValueReferenceType(Type);
2876}
2877
2879 // If this function is a template instantiation, look at the template from
2880 // which it was instantiated.
2882 if (!CheckFn)
2883 CheckFn = this;
2884
2885 const FunctionDecl *fn;
2886 return CheckFn->isDefined(fn) && !fn->isOutOfLine() &&
2888}
2889
2891 const CXXRecordDecl *P = getParent();
2892 return P->isLambda() && getDeclName().isIdentifier() &&
2894}
2895
2897 TypeSourceInfo *TInfo, bool IsVirtual,
2898 SourceLocation L, Expr *Init,
2900 SourceLocation EllipsisLoc)
2901 : Initializee(TInfo), Init(Init), MemberOrEllipsisLocation(EllipsisLoc),
2902 LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(IsVirtual),
2903 IsWritten(false), SourceOrder(0) {}
2904
2906 SourceLocation MemberLoc,
2907 SourceLocation L, Expr *Init,
2909 : Initializee(Member), Init(Init), MemberOrEllipsisLocation(MemberLoc),
2910 LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
2911 IsWritten(false), SourceOrder(0) {}
2912
2915 SourceLocation MemberLoc,
2916 SourceLocation L, Expr *Init,
2918 : Initializee(Member), Init(Init), MemberOrEllipsisLocation(MemberLoc),
2919 LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
2920 IsWritten(false), SourceOrder(0) {}
2921
2923 TypeSourceInfo *TInfo,
2924 SourceLocation L, Expr *Init,
2926 : Initializee(TInfo), Init(Init), LParenLoc(L), RParenLoc(R),
2927 IsDelegating(true), IsVirtual(false), IsWritten(false), SourceOrder(0) {}
2928
2929int64_t CXXCtorInitializer::getID(const ASTContext &Context) const {
2930 return Context.getAllocator()
2931 .identifyKnownAlignedObject<CXXCtorInitializer>(this);
2932}
2933
2935 if (isBaseInitializer())
2936 return cast<TypeSourceInfo *>(Initializee)->getTypeLoc();
2937 else
2938 return {};
2939}
2940
2942 if (isBaseInitializer())
2943 return cast<TypeSourceInfo *>(Initializee)->getType().getTypePtr();
2944 else
2945 return nullptr;
2946}
2947
2950 return getAnyMember()->getLocation();
2951
2953 return getMemberLocation();
2954
2955 if (const auto *TSInfo = cast<TypeSourceInfo *>(Initializee))
2956 return TSInfo->getTypeLoc().getBeginLoc();
2957
2958 return {};
2959}
2960
2963 FieldDecl *D = getAnyMember();
2964 if (Expr *I = D->getInClassInitializer())
2965 return I->getSourceRange();
2966 return {};
2967 }
2968
2970}
2971
2972CXXConstructorDecl::CXXConstructorDecl(
2973 ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2974 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2975 ExplicitSpecifier ES, bool UsesFPIntrin, bool isInline,
2976 bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind,
2977 InheritedConstructor Inherited,
2978 const AssociatedConstraint &TrailingRequiresClause)
2979 : CXXMethodDecl(CXXConstructor, C, RD, StartLoc, NameInfo, T, TInfo,
2980 SC_None, UsesFPIntrin, isInline, ConstexprKind,
2981 SourceLocation(), TrailingRequiresClause) {
2982 setNumCtorInitializers(0);
2983 setInheritingConstructor(static_cast<bool>(Inherited));
2984 setImplicit(isImplicitlyDeclared);
2985 CXXConstructorDeclBits.HasTrailingExplicitSpecifier = ES.getExpr() ? 1 : 0;
2986 if (Inherited)
2987 *getTrailingObjects<InheritedConstructor>() = Inherited;
2988 setExplicitSpecifier(ES);
2989}
2990
2991void CXXConstructorDecl::anchor() {}
2992
2994 GlobalDeclID ID,
2995 uint64_t AllocKind) {
2996 bool hasTrailingExplicit = static_cast<bool>(AllocKind & TAKHasTailExplicit);
2998 static_cast<bool>(AllocKind & TAKInheritsConstructor);
2999 unsigned Extra =
3000 additionalSizeToAlloc<InheritedConstructor, ExplicitSpecifier>(
3001 isInheritingConstructor, hasTrailingExplicit);
3002 auto *Result = new (C, ID, Extra) CXXConstructorDecl(
3003 C, nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr,
3004 ExplicitSpecifier(), false, false, false, ConstexprSpecKind::Unspecified,
3005 InheritedConstructor(), /*TrailingRequiresClause=*/{});
3006 Result->setInheritingConstructor(isInheritingConstructor);
3007 Result->CXXConstructorDeclBits.HasTrailingExplicitSpecifier =
3008 hasTrailingExplicit;
3009 Result->setExplicitSpecifier(ExplicitSpecifier());
3010 return Result;
3011}
3012
3013CXXConstructorDecl *CXXConstructorDecl::Create(
3014 ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
3015 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
3016 ExplicitSpecifier ES, bool UsesFPIntrin, bool isInline,
3017 bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind,
3018 InheritedConstructor Inherited,
3019 const AssociatedConstraint &TrailingRequiresClause) {
3020 assert(NameInfo.getName().getNameKind()
3022 "Name must refer to a constructor");
3023 unsigned Extra =
3024 additionalSizeToAlloc<InheritedConstructor, ExplicitSpecifier>(
3025 Inherited ? 1 : 0, ES.getExpr() ? 1 : 0);
3026 return new (C, RD, Extra) CXXConstructorDecl(
3027 C, RD, StartLoc, NameInfo, T, TInfo, ES, UsesFPIntrin, isInline,
3028 isImplicitlyDeclared, ConstexprKind, Inherited, TrailingRequiresClause);
3029}
3030
3032 return CtorInitializers.get(getASTContext().getExternalSource());
3033}
3034
3035CXXConstructorDecl *CXXConstructorDecl::getTargetConstructor() const {
3036 assert(isDelegatingConstructor() && "Not a delegating constructor!");
3037 Expr *E = (*init_begin())->getInit()->IgnoreImplicit();
3038 if (const auto *Construct = dyn_cast<CXXConstructExpr>(E))
3039 return Construct->getConstructor();
3040
3041 return nullptr;
3042}
3043
3045 // C++ [class.default.ctor]p1:
3046 // A default constructor for a class X is a constructor of class X for
3047 // which each parameter that is not a function parameter pack has a default
3048 // argument (including the case of a constructor with no parameters)
3049 return getMinRequiredArguments() == 0;
3050}
3051
3052bool
3053CXXConstructorDecl::isCopyConstructor(unsigned &TypeQuals) const {
3054 return isCopyOrMoveConstructor(TypeQuals) &&
3056}
3057
3058bool CXXConstructorDecl::isMoveConstructor(unsigned &TypeQuals) const {
3059 return isCopyOrMoveConstructor(TypeQuals) &&
3061}
3062
3063/// Determine whether this is a copy or move constructor.
3064bool CXXConstructorDecl::isCopyOrMoveConstructor(unsigned &TypeQuals) const {
3065 // C++ [class.copy]p2:
3066 // A non-template constructor for class X is a copy constructor
3067 // if its first parameter is of type X&, const X&, volatile X& or
3068 // const volatile X&, and either there are no other parameters
3069 // or else all other parameters have default arguments (8.3.6).
3070 // C++0x [class.copy]p3:
3071 // A non-template constructor for class X is a move constructor if its
3072 // first parameter is of type X&&, const X&&, volatile X&&, or
3073 // const volatile X&&, and either there are no other parameters or else
3074 // all other parameters have default arguments.
3075 if (!hasOneParamOrDefaultArgs() || getPrimaryTemplate() != nullptr ||
3076 getDescribedFunctionTemplate() != nullptr)
3077 return false;
3078
3079 const ParmVarDecl *Param = getParamDecl(0);
3080
3081 // Do we have a reference type?
3082 const auto *ParamRefType = Param->getType()->getAs<ReferenceType>();
3083 if (!ParamRefType)
3084 return false;
3085
3086 // Is it a reference to our class type?
3087 ASTContext &Context = getASTContext();
3088
3089 QualType PointeeType = ParamRefType->getPointeeType();
3090 CanQualType ClassTy = Context.getCanonicalTagType(getParent());
3091 if (!Context.hasSameUnqualifiedType(PointeeType, ClassTy))
3092 return false;
3093
3094 // FIXME: other qualifiers?
3095
3096 // We have a copy or move constructor.
3097 TypeQuals = PointeeType.getCVRQualifiers();
3098 return true;
3099}
3100
3101bool CXXConstructorDecl::isConvertingConstructor(bool AllowExplicit) const {
3102 // C++ [class.conv.ctor]p1:
3103 // A constructor declared without the function-specifier explicit
3104 // that can be called with a single parameter specifies a
3105 // conversion from the type of its first parameter to the type of
3106 // its class. Such a constructor is called a converting
3107 // constructor.
3108 if (isExplicit() && !AllowExplicit)
3109 return false;
3110
3111 // FIXME: This has nothing to do with the definition of converting
3112 // constructor, but is convenient for how we use this function in overload
3113 // resolution.
3114 return getNumParams() == 0
3116 : getMinRequiredArguments() <= 1;
3117}
3118
3121 return false;
3122
3123 const ParmVarDecl *Param = getParamDecl(0);
3124
3125 ASTContext &Context = getASTContext();
3126 CanQualType ParamType = Param->getType()->getCanonicalTypeUnqualified();
3127
3128 // Is it the same as our class type?
3129 CanQualType ClassTy = Context.getCanonicalTagType(getParent());
3130 return ParamType == ClassTy;
3131}
3132
3133void CXXDestructorDecl::anchor() {}
3134
3136 GlobalDeclID ID) {
3137 return new (C, ID) CXXDestructorDecl(
3138 C, nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr,
3139 false, false, false, ConstexprSpecKind::Unspecified,
3140 /*TrailingRequiresClause=*/{});
3141}
3142
3143CXXDestructorDecl *CXXDestructorDecl::Create(
3144 ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
3145 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
3146 bool UsesFPIntrin, bool isInline, bool isImplicitlyDeclared,
3147 ConstexprSpecKind ConstexprKind,
3148 const AssociatedConstraint &TrailingRequiresClause) {
3149 assert(NameInfo.getName().getNameKind()
3151 "Name must refer to a destructor");
3152 return new (C, RD) CXXDestructorDecl(
3153 C, RD, StartLoc, NameInfo, T, TInfo, UsesFPIntrin, isInline,
3154 isImplicitlyDeclared, ConstexprKind, TrailingRequiresClause);
3155}
3156
3158 assert(!OD || (OD->getDeclName().getCXXOverloadedOperator() == OO_Delete));
3159 if (OD && !getASTContext().dtorHasOperatorDelete(
3163 getCanonicalDecl()->OperatorDeleteThisArg = ThisArg;
3164 if (auto *L = getASTMutationListener())
3165 L->ResolvedOperatorDelete(cast<CXXDestructorDecl>(getCanonicalDecl()), OD,
3166 ThisArg);
3167 }
3168}
3169
3171 // FIXME: C++23 [expr.delete] specifies that the delete operator will be
3172 // a usual deallocation function declared at global scope. A convenient
3173 // function to assert that is lacking; Sema::isUsualDeallocationFunction()
3174 // only works for CXXMethodDecl.
3175 assert(!OD ||
3176 (OD->getDeclName().getCXXOverloadedOperator() == OO_Delete &&
3178 if (OD && !getASTContext().dtorHasOperatorDelete(
3182 if (auto *L = getASTMutationListener())
3183 L->ResolvedOperatorGlobDelete(cast<CXXDestructorDecl>(getCanonicalDecl()),
3184 OD);
3185 }
3186}
3187
3189 assert(!OD ||
3190 (OD->getDeclName().getCXXOverloadedOperator() == OO_Array_Delete));
3191 if (OD && !getASTContext().dtorHasOperatorDelete(
3195 if (auto *L = getASTMutationListener())
3196 L->ResolvedOperatorArrayDelete(
3198 }
3199}
3200
3202 assert(!OD ||
3203 (OD->getDeclName().getCXXOverloadedOperator() == OO_Array_Delete &&
3205 if (OD && !getASTContext().dtorHasOperatorDelete(
3209 if (auto *L = getASTMutationListener())
3210 L->ResolvedOperatorGlobArrayDelete(
3212 }
3213}
3214
3219
3224
3229
3234
3236 // C++20 [expr.delete]p6: If the value of the operand of the delete-
3237 // expression is not a null pointer value and the selected deallocation
3238 // function (see below) is not a destroying operator delete, the delete-
3239 // expression will invoke the destructor (if any) for the object or the
3240 // elements of the array being deleted.
3241 //
3242 // This means we should not look at the destructor for a destroying
3243 // delete operator, as that destructor is never called, unless the
3244 // destructor is virtual (see [expr.delete]p8.1) because then the
3245 // selected operator depends on the dynamic type of the pointer.
3246 const FunctionDecl *SelectedOperatorDelete =
3247 OpDel ? OpDel : getOperatorDelete();
3248 if (!SelectedOperatorDelete)
3249 return true;
3250
3251 if (!SelectedOperatorDelete->isDestroyingOperatorDelete())
3252 return true;
3253
3254 // We have a destroying operator delete, so it depends on the dtor.
3255 return isVirtual();
3256}
3257
3258void CXXConversionDecl::anchor() {}
3259
3261 GlobalDeclID ID) {
3262 return new (C, ID) CXXConversionDecl(
3263 C, nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr,
3265 SourceLocation(), /*TrailingRequiresClause=*/{});
3266}
3267
3268CXXConversionDecl *CXXConversionDecl::Create(
3269 ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
3270 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
3271 bool UsesFPIntrin, bool isInline, ExplicitSpecifier ES,
3272 ConstexprSpecKind ConstexprKind, SourceLocation EndLocation,
3273 const AssociatedConstraint &TrailingRequiresClause) {
3274 assert(NameInfo.getName().getNameKind()
3276 "Name must refer to a conversion function");
3277 return new (C, RD) CXXConversionDecl(
3278 C, RD, StartLoc, NameInfo, T, TInfo, UsesFPIntrin, isInline, ES,
3279 ConstexprKind, EndLocation, TrailingRequiresClause);
3280}
3281
3286
3287LinkageSpecDecl::LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
3288 SourceLocation LangLoc,
3289 LinkageSpecLanguageIDs lang, bool HasBraces)
3290 : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
3291 ExternLoc(ExternLoc), RBraceLoc(SourceLocation()) {
3292 setLanguage(lang);
3293 LinkageSpecDeclBits.HasBraces = HasBraces;
3294}
3295
3296void LinkageSpecDecl::anchor() {}
3297
3299 SourceLocation ExternLoc,
3300 SourceLocation LangLoc,
3302 bool HasBraces) {
3303 return new (C, DC) LinkageSpecDecl(DC, ExternLoc, LangLoc, Lang, HasBraces);
3304}
3305
3307 GlobalDeclID ID) {
3308 return new (C, ID)
3309 LinkageSpecDecl(nullptr, SourceLocation(), SourceLocation(),
3311}
3312
3313void UsingDirectiveDecl::anchor() {}
3314
3317 SourceLocation NamespaceLoc,
3318 NestedNameSpecifierLoc QualifierLoc,
3319 SourceLocation IdentLoc,
3320 NamedDecl *Used,
3321 DeclContext *CommonAncestor) {
3322 if (auto *NS = dyn_cast_or_null<NamespaceDecl>(Used))
3323 Used = NS->getFirstDecl();
3324 return new (C, DC) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierLoc,
3325 IdentLoc, Used, CommonAncestor);
3326}
3327
3329 GlobalDeclID ID) {
3330 return new (C, ID) UsingDirectiveDecl(nullptr, SourceLocation(),
3333 SourceLocation(), nullptr, nullptr);
3334}
3335
3337 if (auto *Alias = dyn_cast<NamespaceAliasDecl>(this))
3338 return Alias->getNamespace();
3339 return cast<NamespaceDecl>(this);
3340}
3341
3343 if (auto *NA = dyn_cast_or_null<NamespaceAliasDecl>(NominatedNamespace))
3344 return NA->getNamespace();
3345 return cast_or_null<NamespaceDecl>(NominatedNamespace);
3346}
3347
3348NamespaceDecl::NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline,
3349 SourceLocation StartLoc, SourceLocation IdLoc,
3350 IdentifierInfo *Id, NamespaceDecl *PrevDecl,
3351 bool Nested)
3352 : NamespaceBaseDecl(Namespace, DC, IdLoc, Id), DeclContext(Namespace),
3353 redeclarable_base(C), LocStart(StartLoc) {
3354 setInline(Inline);
3355 setNested(Nested);
3356 setPreviousDecl(PrevDecl);
3357}
3358
3360 bool Inline, SourceLocation StartLoc,
3361 SourceLocation IdLoc, IdentifierInfo *Id,
3362 NamespaceDecl *PrevDecl, bool Nested) {
3363 return new (C, DC)
3364 NamespaceDecl(C, DC, Inline, StartLoc, IdLoc, Id, PrevDecl, Nested);
3365}
3366
3368 GlobalDeclID ID) {
3369 return new (C, ID) NamespaceDecl(C, nullptr, false, SourceLocation(),
3370 SourceLocation(), nullptr, nullptr, false);
3371}
3372
3374 return getNextRedeclaration();
3375}
3376
3378 return getPreviousDecl();
3379}
3380
3382 return getMostRecentDecl();
3383}
3384
3385void NamespaceAliasDecl::anchor() {}
3386
3388 return getNextRedeclaration();
3389}
3390
3392 return getPreviousDecl();
3393}
3394
3396 return getMostRecentDecl();
3397}
3398
3399NamespaceAliasDecl *NamespaceAliasDecl::Create(
3400 ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
3401 SourceLocation AliasLoc, IdentifierInfo *Alias,
3402 NestedNameSpecifierLoc QualifierLoc, SourceLocation IdentLoc,
3403 NamespaceBaseDecl *Namespace) {
3404 // FIXME: Preserve the aliased namespace as written.
3405 if (auto *NS = dyn_cast_or_null<NamespaceDecl>(Namespace))
3406 Namespace = NS->getFirstDecl();
3407 return new (C, DC) NamespaceAliasDecl(C, DC, UsingLoc, AliasLoc, Alias,
3408 QualifierLoc, IdentLoc, Namespace);
3409}
3410
3412 GlobalDeclID ID) {
3413 return new (C, ID) NamespaceAliasDecl(C, nullptr, SourceLocation(),
3414 SourceLocation(), nullptr,
3416 SourceLocation(), nullptr);
3417}
3418
3419void LifetimeExtendedTemporaryDecl::anchor() {}
3420
3421/// Retrieve the storage duration for the materialized temporary.
3423 const ValueDecl *ExtendingDecl = getExtendingDecl();
3424 if (!ExtendingDecl)
3425 return SD_FullExpression;
3426 // FIXME: This is not necessarily correct for a temporary materialized
3427 // within a default initializer.
3428 if (isa<FieldDecl>(ExtendingDecl))
3429 return SD_Automatic;
3430 // FIXME: This only works because storage class specifiers are not allowed
3431 // on decomposition declarations.
3432 if (isa<BindingDecl>(ExtendingDecl))
3433 return ExtendingDecl->getDeclContext()->isFunctionOrMethod() ? SD_Automatic
3434 : SD_Static;
3435 return cast<VarDecl>(ExtendingDecl)->getStorageDuration();
3436}
3437
3439 assert(getStorageDuration() == SD_Static &&
3440 "don't need to cache the computed value for this temporary");
3441 if (MayCreate && !Value) {
3442 Value = (new (getASTContext()) APValue);
3444 }
3445 assert(Value && "may not be null");
3446 return Value;
3447}
3448
3449void UsingShadowDecl::anchor() {}
3450
3453 BaseUsingDecl *Introducer, NamedDecl *Target)
3454 : NamedDecl(K, DC, Loc, Name), redeclarable_base(C),
3455 UsingOrNextShadow(Introducer) {
3456 if (Target) {
3457 assert(!isa<UsingShadowDecl>(Target));
3459 }
3460 setImplicit();
3461}
3462
3466
3471
3473 const UsingShadowDecl *Shadow = this;
3474 while (const auto *NextShadow =
3475 dyn_cast<UsingShadowDecl>(Shadow->UsingOrNextShadow))
3476 Shadow = NextShadow;
3477 return cast<BaseUsingDecl>(Shadow->UsingOrNextShadow);
3478}
3479
3480void ConstructorUsingShadowDecl::anchor() {}
3481
3484 SourceLocation Loc, UsingDecl *Using,
3485 NamedDecl *Target, bool IsVirtual) {
3486 return new (C, DC) ConstructorUsingShadowDecl(C, DC, Loc, Using, Target,
3487 IsVirtual);
3488}
3489
3492 return new (C, ID) ConstructorUsingShadowDecl(C, EmptyShell());
3493}
3494
3498
3499void BaseUsingDecl::anchor() {}
3500
3502 assert(!llvm::is_contained(shadows(), S) && "declaration already in set");
3503 assert(S->getIntroducer() == this);
3504
3505 if (FirstUsingShadow.getPointer())
3506 S->UsingOrNextShadow = FirstUsingShadow.getPointer();
3507 FirstUsingShadow.setPointer(S);
3508}
3509
3511 assert(llvm::is_contained(shadows(), S) && "declaration not in set");
3512 assert(S->getIntroducer() == this);
3513
3514 // Remove S from the shadow decl chain. This is O(n) but hopefully rare.
3515
3516 if (FirstUsingShadow.getPointer() == S) {
3517 FirstUsingShadow.setPointer(
3518 dyn_cast<UsingShadowDecl>(S->UsingOrNextShadow));
3519 S->UsingOrNextShadow = this;
3520 return;
3521 }
3522
3523 UsingShadowDecl *Prev = FirstUsingShadow.getPointer();
3524 while (Prev->UsingOrNextShadow != S)
3525 Prev = cast<UsingShadowDecl>(Prev->UsingOrNextShadow);
3526 Prev->UsingOrNextShadow = S->UsingOrNextShadow;
3527 S->UsingOrNextShadow = this;
3528}
3529
3530void UsingDecl::anchor() {}
3531
3533 NestedNameSpecifierLoc QualifierLoc,
3534 const DeclarationNameInfo &NameInfo,
3535 bool HasTypename) {
3536 return new (C, DC) UsingDecl(DC, UL, QualifierLoc, NameInfo, HasTypename);
3537}
3538
3540 return new (C, ID) UsingDecl(nullptr, SourceLocation(),
3542 false);
3543}
3544
3547 ? getQualifierLoc().getBeginLoc() : UsingLocation;
3548 return SourceRange(Begin, getNameInfo().getEndLoc());
3549}
3550
3551void UsingEnumDecl::anchor() {}
3552
3555 SourceLocation NL,
3556 TypeSourceInfo *EnumType) {
3557 return new (C, DC)
3558 UsingEnumDecl(DC, EnumType->getType()->castAsEnumDecl()->getDeclName(),
3559 UL, EL, NL, EnumType);
3560}
3561
3563 GlobalDeclID ID) {
3564 return new (C, ID)
3565 UsingEnumDecl(nullptr, DeclarationName(), SourceLocation(),
3566 SourceLocation(), SourceLocation(), nullptr);
3567}
3568
3570 return SourceRange(UsingLocation, EnumType->getTypeLoc().getEndLoc());
3571}
3572
3573void UsingPackDecl::anchor() {}
3574
3576 NamedDecl *InstantiatedFrom,
3577 ArrayRef<NamedDecl *> UsingDecls) {
3578 size_t Extra = additionalSizeToAlloc<NamedDecl *>(UsingDecls.size());
3579 return new (C, DC, Extra) UsingPackDecl(DC, InstantiatedFrom, UsingDecls);
3580}
3581
3583 unsigned NumExpansions) {
3584 size_t Extra = additionalSizeToAlloc<NamedDecl *>(NumExpansions);
3585 auto *Result = new (C, ID, Extra) UsingPackDecl(nullptr, nullptr, {});
3586 Result->NumExpansions = NumExpansions;
3587 auto *Trail = Result->getTrailingObjects();
3588 std::uninitialized_fill_n(Trail, NumExpansions, nullptr);
3589 return Result;
3590}
3591
3592void UnresolvedUsingValueDecl::anchor() {}
3593
3596 SourceLocation UsingLoc,
3597 NestedNameSpecifierLoc QualifierLoc,
3598 const DeclarationNameInfo &NameInfo,
3599 SourceLocation EllipsisLoc) {
3600 return new (C, DC) UnresolvedUsingValueDecl(DC, C.DependentTy, UsingLoc,
3601 QualifierLoc, NameInfo,
3602 EllipsisLoc);
3603}
3604
3607 return new (C, ID) UnresolvedUsingValueDecl(nullptr, QualType(),
3611 SourceLocation());
3612}
3613
3619
3620void UnresolvedUsingTypenameDecl::anchor() {}
3621
3624 SourceLocation UsingLoc,
3625 SourceLocation TypenameLoc,
3626 NestedNameSpecifierLoc QualifierLoc,
3627 SourceLocation TargetNameLoc,
3628 DeclarationName TargetName,
3629 SourceLocation EllipsisLoc) {
3630 return new (C, DC) UnresolvedUsingTypenameDecl(
3631 DC, UsingLoc, TypenameLoc, QualifierLoc, TargetNameLoc,
3632 TargetName.getAsIdentifierInfo(), EllipsisLoc);
3633}
3634
3637 GlobalDeclID ID) {
3638 return new (C, ID) UnresolvedUsingTypenameDecl(
3640 SourceLocation(), nullptr, SourceLocation());
3641}
3642
3645 SourceLocation Loc, DeclarationName Name) {
3646 return new (Ctx, DC) UnresolvedUsingIfExistsDecl(DC, Loc, Name);
3647}
3648
3651 GlobalDeclID ID) {
3652 return new (Ctx, ID)
3653 UnresolvedUsingIfExistsDecl(nullptr, SourceLocation(), DeclarationName());
3654}
3655
3656UnresolvedUsingIfExistsDecl::UnresolvedUsingIfExistsDecl(DeclContext *DC,
3657 SourceLocation Loc,
3658 DeclarationName Name)
3659 : NamedDecl(Decl::UnresolvedUsingIfExists, DC, Loc, Name) {}
3660
3661void UnresolvedUsingIfExistsDecl::anchor() {}
3662
3663void StaticAssertDecl::anchor() {}
3664
3666 SourceLocation StaticAssertLoc,
3667 Expr *AssertExpr, Expr *Message,
3668 SourceLocation RParenLoc,
3669 bool Failed) {
3670 return new (C, DC) StaticAssertDecl(DC, StaticAssertLoc, AssertExpr, Message,
3671 RParenLoc, Failed);
3672}
3673
3675 GlobalDeclID ID) {
3676 return new (C, ID) StaticAssertDecl(nullptr, SourceLocation(), nullptr,
3677 nullptr, SourceLocation(), false);
3678}
3679
3681 assert((isa<VarDecl, BindingDecl>(this)) &&
3682 "expected a VarDecl or a BindingDecl");
3683 if (auto *Var = llvm::dyn_cast<VarDecl>(this))
3684 return Var;
3685 if (auto *BD = llvm::dyn_cast<BindingDecl>(this))
3686 return llvm::dyn_cast_if_present<VarDecl>(BD->getDecomposedDecl());
3687 return nullptr;
3688}
3689
3690void BindingDecl::anchor() {}
3691
3693 SourceLocation IdLoc, IdentifierInfo *Id,
3694 QualType T) {
3695 return new (C, DC) BindingDecl(DC, IdLoc, Id, T);
3696}
3697
3699 return new (C, ID)
3700 BindingDecl(nullptr, SourceLocation(), nullptr, QualType());
3701}
3702
3704 Expr *B = getBinding();
3705 if (!B)
3706 return nullptr;
3707 auto *DRE = dyn_cast<DeclRefExpr>(B->IgnoreImplicit());
3708 if (!DRE)
3709 return nullptr;
3710
3711 auto *VD = cast<VarDecl>(DRE->getDecl());
3712 assert(VD->isImplicit() && "holding var for binding decl not implicit");
3713 return VD;
3714}
3715
3717 assert(Binding && "expecting a pack expr");
3718 auto *FP = cast<FunctionParmPackExpr>(Binding);
3719 ValueDecl *const *First = FP->getNumExpansions() > 0 ? FP->begin() : nullptr;
3720 assert((!First || isa<BindingDecl>(*First)) && "expecting a BindingDecl");
3721 return ArrayRef<BindingDecl *>(reinterpret_cast<BindingDecl *const *>(First),
3722 FP->getNumExpansions());
3723}
3724
3725void DecompositionDecl::anchor() {}
3726
3728 SourceLocation StartLoc,
3729 SourceLocation LSquareLoc,
3730 QualType T, TypeSourceInfo *TInfo,
3731 StorageClass SC,
3733 size_t Extra = additionalSizeToAlloc<BindingDecl *>(Bindings.size());
3734 return new (C, DC, Extra)
3735 DecompositionDecl(C, DC, StartLoc, LSquareLoc, T, TInfo, SC, Bindings);
3736}
3737
3739 GlobalDeclID ID,
3740 unsigned NumBindings) {
3741 size_t Extra = additionalSizeToAlloc<BindingDecl *>(NumBindings);
3742 auto *Result = new (C, ID, Extra)
3743 DecompositionDecl(C, nullptr, SourceLocation(), SourceLocation(),
3744 QualType(), nullptr, StorageClass(), {});
3745 // Set up and clean out the bindings array.
3746 Result->NumBindings = NumBindings;
3747 auto *Trail = Result->getTrailingObjects();
3748 std::uninitialized_fill_n(Trail, NumBindings, nullptr);
3749 return Result;
3750}
3751
3752void DecompositionDecl::printName(llvm::raw_ostream &OS,
3753 const PrintingPolicy &Policy) const {
3754 OS << '[';
3755 bool Comma = false;
3756 for (const auto *B : bindings()) {
3757 if (Comma)
3758 OS << ", ";
3759 B->printName(OS, Policy);
3760 Comma = true;
3761 }
3762 OS << ']';
3763}
3764
3765void MSPropertyDecl::anchor() {}
3766
3769 QualType T, TypeSourceInfo *TInfo,
3770 SourceLocation StartL,
3771 IdentifierInfo *Getter,
3772 IdentifierInfo *Setter) {
3773 return new (C, DC) MSPropertyDecl(DC, L, N, T, TInfo, StartL, Getter, Setter);
3774}
3775
3777 GlobalDeclID ID) {
3778 return new (C, ID) MSPropertyDecl(nullptr, SourceLocation(),
3779 DeclarationName(), QualType(), nullptr,
3780 SourceLocation(), nullptr, nullptr);
3781}
3782
3783void MSGuidDecl::anchor() {}
3784
3785MSGuidDecl::MSGuidDecl(DeclContext *DC, QualType T, Parts P)
3786 : ValueDecl(Decl::MSGuid, DC, SourceLocation(), DeclarationName(), T),
3787 PartVal(P) {}
3788
3789MSGuidDecl *MSGuidDecl::Create(const ASTContext &C, QualType T, Parts P) {
3790 DeclContext *DC = C.getTranslationUnitDecl();
3791 return new (C, DC) MSGuidDecl(DC, T, P);
3792}
3793
3794MSGuidDecl *MSGuidDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) {
3795 return new (C, ID) MSGuidDecl(nullptr, QualType(), Parts());
3796}
3797
3798void MSGuidDecl::printName(llvm::raw_ostream &OS,
3799 const PrintingPolicy &) const {
3800 OS << llvm::format("GUID{%08" PRIx32 "-%04" PRIx16 "-%04" PRIx16 "-",
3801 PartVal.Part1, PartVal.Part2, PartVal.Part3);
3802 unsigned I = 0;
3803 for (uint8_t Byte : PartVal.Part4And5) {
3804 OS << llvm::format("%02" PRIx8, Byte);
3805 if (++I == 2)
3806 OS << '-';
3807 }
3808 OS << '}';
3809}
3810
3811/// Determine if T is a valid 'struct _GUID' of the shape that we expect.
3813 // FIXME: We only need to check this once, not once each time we compute a
3814 // GUID APValue.
3815 using MatcherRef = llvm::function_ref<bool(QualType)>;
3816
3817 auto IsInt = [&Ctx](unsigned N) {
3818 return [&Ctx, N](QualType T) {
3819 return T->isUnsignedIntegerOrEnumerationType() &&
3820 Ctx.getIntWidth(T) == N;
3821 };
3822 };
3823
3824 auto IsArray = [&Ctx](MatcherRef Elem, unsigned N) {
3825 return [&Ctx, Elem, N](QualType T) {
3826 const ConstantArrayType *CAT = Ctx.getAsConstantArrayType(T);
3827 return CAT && CAT->getSize() == N && Elem(CAT->getElementType());
3828 };
3829 };
3830
3831 auto IsStruct = [](std::initializer_list<MatcherRef> Fields) {
3832 return [Fields](QualType T) {
3833 const RecordDecl *RD = T->getAsRecordDecl();
3834 if (!RD || RD->isUnion())
3835 return false;
3836 RD = RD->getDefinition();
3837 if (!RD)
3838 return false;
3839 if (auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
3840 if (CXXRD->getNumBases())
3841 return false;
3842 auto MatcherIt = Fields.begin();
3843 for (const FieldDecl *FD : RD->fields()) {
3844 if (FD->isUnnamedBitField())
3845 continue;
3846 if (FD->isBitField() || MatcherIt == Fields.end() ||
3847 !(*MatcherIt)(FD->getType()))
3848 return false;
3849 ++MatcherIt;
3850 }
3851 return MatcherIt == Fields.end();
3852 };
3853 };
3854
3855 // We expect an {i32, i16, i16, [8 x i8]}.
3856 return IsStruct({IsInt(32), IsInt(16), IsInt(16), IsArray(IsInt(8), 8)})(T);
3857}
3858
3860 if (APVal.isAbsent() && isValidStructGUID(getASTContext(), getType())) {
3861 using llvm::APInt;
3862 using llvm::APSInt;
3863 APVal = APValue(APValue::UninitStruct(), 0, 4);
3864 APVal.getStructField(0) = APValue(APSInt(APInt(32, PartVal.Part1), true));
3865 APVal.getStructField(1) = APValue(APSInt(APInt(16, PartVal.Part2), true));
3866 APVal.getStructField(2) = APValue(APSInt(APInt(16, PartVal.Part3), true));
3867 APValue &Arr = APVal.getStructField(3) =
3869 for (unsigned I = 0; I != 8; ++I) {
3870 Arr.getArrayInitializedElt(I) =
3871 APValue(APSInt(APInt(8, PartVal.Part4And5[I]), true));
3872 }
3873 // Register this APValue to be destroyed if necessary. (Note that the
3874 // MSGuidDecl destructor is never run.)
3875 getASTContext().addDestruction(&APVal);
3876 }
3877
3878 return APVal;
3879}
3880
3881void UnnamedGlobalConstantDecl::anchor() {}
3882
3883UnnamedGlobalConstantDecl::UnnamedGlobalConstantDecl(const ASTContext &C,
3884 DeclContext *DC,
3885 QualType Ty,
3886 const APValue &Val)
3887 : ValueDecl(Decl::UnnamedGlobalConstant, DC, SourceLocation(),
3888 DeclarationName(), Ty),
3889 Value(Val) {
3890 // Cleanup the embedded APValue if required (note that our destructor is never
3891 // run)
3892 if (Value.needsCleanup())
3893 C.addDestruction(&Value);
3894}
3895
3897UnnamedGlobalConstantDecl::Create(const ASTContext &C, QualType T,
3898 const APValue &Value) {
3899 DeclContext *DC = C.getTranslationUnitDecl();
3900 return new (C, DC) UnnamedGlobalConstantDecl(C, DC, T, Value);
3901}
3902
3904UnnamedGlobalConstantDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) {
3905 return new (C, ID)
3906 UnnamedGlobalConstantDecl(C, nullptr, QualType(), APValue());
3907}
3908
3909void UnnamedGlobalConstantDecl::printName(llvm::raw_ostream &OS,
3910 const PrintingPolicy &) const {
3911 OS << "unnamed-global-constant";
3912}
3913
3914static const char *getAccessName(AccessSpecifier AS) {
3915 switch (AS) {
3916 case AS_none:
3917 llvm_unreachable("Invalid access specifier!");
3918 case AS_public:
3919 return "public";
3920 case AS_private:
3921 return "private";
3922 case AS_protected:
3923 return "protected";
3924 }
3925 llvm_unreachable("Invalid access specifier!");
3926}
3927
3929 AccessSpecifier AS) {
3930 return DB << getAccessName(AS);
3931}
Defines the clang::ASTContext interface.
This file provides some common utility functions for processing Lambda related AST Constructs.
Defines the Diagnostic-related interfaces.
llvm::APSInt APSInt
Definition Compiler.cpp:24
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:1879
static const char * getAccessName(AccessSpecifier AS)
Definition DeclCXX.cpp:3914
static bool recursivelyOverrides(const CXXMethodDecl *DerivedMD, const CXXMethodDecl *BaseMD)
Definition DeclCXX.cpp:2422
static bool isValidStructGUID(ASTContext &Ctx, QualType T)
Determine if T is a valid 'struct _GUID' of the shape that we expect.
Definition DeclCXX.cpp:3812
static DeclContext::lookup_result getLambdaStaticInvokers(const CXXRecordDecl &RD)
Definition DeclCXX.cpp:1762
static NamedDecl * getLambdaCallOperatorHelper(const CXXRecordDecl &RD)
Definition DeclCXX.cpp:1692
static QualType getThisObjectType(ASTContext &C, const FunctionProtoType *FPT, const CXXRecordDecl *Decl)
Definition DeclCXX.cpp:2829
static bool hasPureVirtualFinalOverrider(const CXXRecordDecl &RD, const CXXFinalOverriderMap *FinalOverriders)
Definition DeclCXX.cpp:2246
static bool allLookupResultsAreTheSame(const DeclContext::lookup_result &R)
Definition DeclCXX.cpp:1685
static bool isDeclContextInNamespace(const DeclContext *DC)
Definition DeclCXX.cpp:2182
static bool hasRepeatedBaseClass(const CXXRecordDecl *StartRD)
Determine whether a class has a repeated base class.
Definition DeclCXX.cpp:165
static CanQualType GetConversionType(ASTContext &Context, NamedDecl *Conv)
Definition DeclCXX.cpp:1860
static CXXMethodDecl * getInvokerAsMethod(NamedDecl *ND)
Definition DeclCXX.cpp:1769
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.
TokenType getType() const
Returns the token's type, e.g.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
#define X(type, name)
Definition Value.h:97
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::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.
llvm::SmallVector< std::pair< const MemRegion *, SVal >, 4 > Bindings
static bool hasAttr(const Decl *D, bool IgnoreImplicitAttr)
Definition SemaCUDA.cpp:183
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
Expr * getExpr()
Get 'expr' part of the associated expression/statement.
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition APValue.h:122
APValue & getArrayInitializedElt(unsigned I)
Definition APValue.h:626
APValue & getStructField(unsigned i)
Definition APValue.h:667
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:228
const ConstantArrayType * getAsConstantArrayType(QualType T) const
unsigned getIntWidth(QualType T) const
DeclarationNameTable DeclarationNames
Definition ASTContext.h:810
overridden_method_range overridden_methods(const CXXMethodDecl *Method) const
IdentifierTable & Idents
Definition ASTContext.h:806
const LangOptions & getLangOpts() const
Definition ASTContext.h:960
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
void addOverriddenMethod(const CXXMethodDecl *Method, const CXXMethodDecl *Overridden)
Note that the given C++ Method overrides the given Overridden method.
bool arePFPFieldsTriviallyCopyable(const RecordDecl *RD) const
Returns whether this record's PFP fields (if any) are trivially copyable (i.e.
bool hasPFPFields(QualType Ty) const
unsigned overridden_methods_size(const CXXMethodDecl *Method) const
overridden_cxx_method_iterator overridden_methods_begin(const CXXMethodDecl *Method) const
FunctionDecl * getOperatorDeleteForVDtor(const CXXDestructorDecl *Dtor, OperatorDeleteKind K) const
const TargetInfo & getTargetInfo() const
Definition ASTContext.h:925
void addDestruction(T *Ptr) const
If T isn't trivially destructible, calls AddDeallocation to register it for destruction.
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
CanQualType getCanonicalTagType(const TagDecl *TD) const
static bool hasSameUnqualifiedType(QualType T1, QualType T2)
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
void addOperatorDeleteForVDtor(const CXXDestructorDecl *Dtor, FunctionDecl *OperatorDelete, OperatorDeleteKind K) const
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.
UnresolvedSetIterator iterator
void addDecl(ASTContext &C, NamedDecl *D, AccessSpecifier AS)
static AccessSpecDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclCXX.cpp:60
QualType getElementType() const
Definition TypeBase.h:3796
void addShadowDecl(UsingShadowDecl *S)
Definition DeclCXX.cpp:3501
shadow_range shadows() const
Definition DeclCXX.h:3567
void removeShadowDecl(UsingShadowDecl *S)
Definition DeclCXX.cpp:3510
VarDecl * getHoldingVar() const
Get the variable (if any) that holds the value of evaluating the binding.
Definition DeclCXX.cpp:3703
static BindingDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T)
Definition DeclCXX.cpp:3692
Expr * getBinding() const
Get the expression to which this declaration is bound.
Definition DeclCXX.h:4216
ArrayRef< BindingDecl * > getBindingPackDecls() const
Definition DeclCXX.cpp:3716
static BindingDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclCXX.cpp:3698
Represents a base class of a C++ class.
Definition DeclCXX.h:146
Represents a C++ constructor within a class.
Definition DeclCXX.h:2620
bool isExplicit() const
Return true if the declaration is already resolved to be explicit.
Definition DeclCXX.h:2697
init_iterator init_begin()
Retrieve an iterator to the first initializer.
Definition DeclCXX.h:2714
CXXConstructorDecl * getTargetConstructor() const
When this constructor delegates to another, retrieve the target.
Definition DeclCXX.cpp:3035
static CXXConstructorDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, uint64_t AllocKind)
Definition DeclCXX.cpp:2993
bool isDefaultConstructor() const
Whether this constructor is a default constructor (C++ [class.ctor]p5), which can be used to default-...
Definition DeclCXX.cpp:3044
bool isDelegatingConstructor() const
Determine whether this constructor is a delegating constructor.
Definition DeclCXX.h:2770
bool isSpecializationCopyingObject() const
Determine whether this is a member template specialization that would copy the object to itself.
Definition DeclCXX.cpp:3119
bool isMoveConstructor() const
Determine whether this constructor is a move constructor (C++11 [class.copy]p3), which can be used to...
Definition DeclCXX.h:2815
bool isCopyOrMoveConstructor() const
Determine whether this a copy or move constructor.
Definition DeclCXX.h:2827
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(), const AssociatedConstraint &TrailingRequiresClause={})
Definition DeclCXX.cpp:3013
bool isInheritingConstructor() const
Determine whether this is an implicit constructor synthesized to model a call to a constructor inheri...
Definition DeclCXX.h:2844
CXXCtorInitializer *const * init_const_iterator
Iterates through the member/base initializer list.
Definition DeclCXX.h:2703
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:3101
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:2801
bool isLambdaToBlockPointerConversion() const
Determine whether this conversion function is a conversion from a lambda closure type to a block poin...
Definition DeclCXX.cpp:3282
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, const AssociatedConstraint &TrailingRequiresClause={})
Definition DeclCXX.cpp:3268
QualType getConversionType() const
Returns the type that this conversion function is converting to.
Definition DeclCXX.h:2988
static CXXConversionDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclCXX.cpp:3260
SourceLocation getRParenLoc() const
Definition DeclCXX.h:2584
SourceRange getSourceRange() const LLVM_READONLY
Determine the source range covering the entire initializer.
Definition DeclCXX.cpp:2961
SourceLocation getSourceLocation() const
Determine the source location of the initializer.
Definition DeclCXX.cpp:2948
bool isAnyMemberInitializer() const
Definition DeclCXX.h:2465
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition DeclCXX.h:2457
int64_t getID(const ASTContext &Context) const
Definition DeclCXX.cpp:2929
bool isInClassMemberInitializer() const
Determine whether this initializer is an implicit initializer generated for a field with an initializ...
Definition DeclCXX.h:2479
const Type * getBaseClass() const
If this is a base class initializer, returns the type of the base class.
Definition DeclCXX.cpp:2941
SourceLocation getMemberLocation() const
Definition DeclCXX.h:2545
FieldDecl * getAnyMember() const
Definition DeclCXX.h:2531
TypeLoc getBaseClassLoc() const
If this is a base class initializer, returns the type of the base class with location information.
Definition DeclCXX.cpp:2934
CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual, SourceLocation L, Expr *Init, SourceLocation R, SourceLocation EllipsisLoc)
Creates a new base-class initializer.
Definition DeclCXX.cpp:2896
Represents a C++ deduction guide declaration.
Definition DeclCXX.h:1983
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, const AssociatedConstraint &TrailingRequiresClause={}, const CXXDeductionGuideDecl *SourceDG=nullptr, SourceDeductionGuideKind SK=SourceDeductionGuideKind::None)
Definition DeclCXX.cpp:2378
static CXXDeductionGuideDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclCXX.cpp:2391
Represents a C++ destructor within a class.
Definition DeclCXX.h:2882
void setGlobalOperatorArrayDelete(FunctionDecl *OD)
Definition DeclCXX.cpp:3201
static CXXDestructorDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclCXX.cpp:3135
CXXDestructorDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition DeclCXX.h:2930
const FunctionDecl * getOperatorGlobalDelete() const
Definition DeclCXX.cpp:3220
const FunctionDecl * getGlobalArrayOperatorDelete() const
Definition DeclCXX.cpp:3230
static CXXDestructorDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, bool UsesFPIntrin, bool isInline, bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, const AssociatedConstraint &TrailingRequiresClause={})
Definition DeclCXX.cpp:3143
const FunctionDecl * getOperatorDelete() const
Definition DeclCXX.cpp:3215
void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg)
Definition DeclCXX.cpp:3157
bool isCalledByDelete(const FunctionDecl *OpDel=nullptr) const
Will this destructor ever be called when considering which deallocation function is associated with t...
Definition DeclCXX.cpp:3235
void setOperatorArrayDelete(FunctionDecl *OD)
Definition DeclCXX.cpp:3188
const FunctionDecl * getArrayOperatorDelete() const
Definition DeclCXX.cpp:3225
void setOperatorGlobalDelete(FunctionDecl *OD)
Definition DeclCXX.cpp:3170
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:2132
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:2714
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:2434
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:2721
void addOverriddenMethod(const CXXMethodDecl *MD)
Definition DeclCXX.cpp:2800
bool hasInlineBody() const
Definition DeclCXX.cpp:2878
bool isVirtual() const
Definition DeclCXX.h:2187
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, const AssociatedConstraint &TrailingRequiresClause={})
Definition DeclCXX.cpp:2499
bool isUsualDeallocationFunction(SmallVectorImpl< const FunctionDecl * > &PreventedBy) const
Determine whether this is a usual deallocation function (C++ [basic.stc.dynamic.deallocation]p2),...
Definition DeclCXX.cpp:2604
unsigned getNumExplicitParams() const
Definition DeclCXX.h:2299
overridden_method_range overridden_methods() const
Definition DeclCXX.cpp:2823
unsigned size_overridden_methods() const
Definition DeclCXX.cpp:2817
const CXXMethodDecl *const * method_iterator
Definition DeclCXX.h:2258
QualType getFunctionObjectParameterReferenceType() const
Return the type of the object pointed by this.
Definition DeclCXX.cpp:2865
method_iterator begin_overridden_methods() const
Definition DeclCXX.cpp:2807
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Definition DeclCXX.h:2271
QualType getThisType() const
Return the type of the this pointer.
Definition DeclCXX.cpp:2854
bool isInstance() const
Definition DeclCXX.h:2159
bool isCopyOrMoveConstructorOrAssignment() const
Determine whether this is a copy or move constructor or a copy or move assignment operator.
Definition DeclCXX.cpp:2772
bool isMoveAssignmentOperator() const
Determine whether this is a move assignment operator.
Definition DeclCXX.cpp:2746
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:2519
static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK)
Returns true if the given operator is implicitly static in a record context.
Definition DeclCXX.h:2174
CXXMethodDecl * getCorrespondingMethodInClass(const CXXRecordDecl *RD, bool MayBeBase=false)
Find the method in RD that corresponds to this one.
Definition DeclCXX.cpp:2465
bool isStatic() const
Definition DeclCXX.cpp:2412
bool isMemcpyEquivalentSpecialMember(const ASTContext &Ctx) const
Returns whether this is a copy/move constructor or assignment operator that can be implemented as a m...
Definition DeclCXX.cpp:2777
bool isCopyAssignmentOperator() const
Determine whether this is a copy-assignment operator, regardless of whether it was declared implicitl...
Definition DeclCXX.cpp:2725
CXXMethodDecl(Kind DK, ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin, bool isInline, ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, const AssociatedConstraint &TrailingRequiresClause={})
Definition DeclCXX.h:2136
static CXXMethodDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclCXX.cpp:2510
method_iterator end_overridden_methods() const
Definition DeclCXX.cpp:2812
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition DeclCXX.h:2241
bool isLambdaStaticInvoker() const
Determine whether this is a lambda closure type's static member function that is used for the result ...
Definition DeclCXX.cpp:2890
bool isCopyOrMoveConstructor() const
Determine whether this is a copy or move constructor.
Definition DeclCXX.cpp:2766
llvm::iterator_range< llvm::TinyPtrVector< const CXXMethodDecl * >::const_iterator > overridden_method_range
Definition DeclCXX.h:2264
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
bool isHLSLIntangible() const
Returns true if the class contains HLSL intangible type, either as a field or in base class.
Definition DeclCXX.h:1556
Decl * getLambdaContextDecl() const
Retrieve the declaration that provides additional context for a lambda, when the normal declaration c...
Definition DeclCXX.cpp:1834
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:2321
static CXXRecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, CXXRecordDecl *PrevDecl=nullptr)
Definition DeclCXX.cpp:132
bool isTriviallyCopyable() const
Determine whether this class is considered trivially copyable per (C++11 [class]p6).
Definition DeclCXX.cpp:610
bool hasNonTrivialCopyAssignment() const
Determine whether this class has a non-trivial copy assignment operator (C++ [class....
Definition DeclCXX.h:1340
TemplateParameterList * getGenericLambdaTemplateParameterList() const
Retrieve the generic lambda's template parameter list.
Definition DeclCXX.cpp:1811
bool isEffectivelyFinal() const
Determine whether it's impossible for a class to be derived from this class.
Definition DeclCXX.cpp:2336
bool hasSimpleMoveConstructor() const
true if we know for sure that this class has a single, accessible, unambiguous move constructor that ...
Definition DeclCXX.h:730
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:1143
bool hasTrivialDefaultConstructor() const
Determine whether this class has a trivial default constructor (C++11 [class.ctor]p5).
Definition DeclCXX.h:1246
void setBases(CXXBaseSpecifier const *const *Bases, unsigned NumBases)
Sets the base classes of this struct or class.
Definition DeclCXX.cpp:184
bool isGenericLambda() const
Determine whether this class describes a generic lambda function object (i.e.
Definition DeclCXX.cpp:1679
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
Definition DeclCXX.h:1372
bool hasUserDeclaredDestructor() const
Determine whether this class has a user-declared destructor.
Definition DeclCXX.h:1001
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:2030
bool hasInjectedClassType() const
Determines whether this declaration has is canonically of an injected class type.
Definition DeclCXX.cpp:2159
void completeDefinition() override
Indicates that the definition of this class is now complete.
Definition DeclCXX.cpp:2242
bool isLiteral() const
Determine whether this class is a literal type.
Definition DeclCXX.cpp:1506
bool hasDeletedDestructor() const
Returns the destructor decl for this class.
Definition DeclCXX.cpp:2143
bool defaultedDestructorIsConstexpr() const
Determine whether a defaulted default constructor for this class would be constexpr.
Definition DeclCXX.h:1362
bool isStandardLayout() const
Determine whether this class is standard-layout per C++ [class]p7.
Definition DeclCXX.h:1225
void setCaptures(ASTContext &Context, ArrayRef< LambdaCapture > Captures)
Set the captures for this lambda closure type.
Definition DeclCXX.cpp:1629
unsigned getDeviceLambdaManglingNumber() const
Retrieve the device side mangling number.
Definition DeclCXX.cpp:1855
base_class_range bases()
Definition DeclCXX.h:608
bool hasAnyDependentBases() const
Determine whether this class has any dependent base classes which are not the current instantiation.
Definition DeclCXX.cpp:603
void setTrivialForCallFlags(CXXMethodDecl *MD)
Definition DeclCXX.cpp:1651
bool isLambda() const
Determine whether this class describes a lambda function object.
Definition DeclCXX.h:1018
void addedSelectedDestructor(CXXDestructorDecl *DD)
Notify the class that this destructor is now selected.
Definition DeclCXX.cpp:1531
bool hasFriends() const
Determines whether this record has any friends.
Definition DeclCXX.h:691
method_range methods() const
Definition DeclCXX.h:650
CXXRecordDecl * getDefinition() const
Definition DeclCXX.h:548
static AccessSpecifier MergeAccess(AccessSpecifier PathAccess, AccessSpecifier DeclAccess)
Calculates the access of a decl that is reached along a path.
Definition DeclCXX.h:1727
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:1790
bool hasConstexprNonCopyMoveConstructor() const
Determine whether this class has at least one constexpr constructor other than the copy or move const...
Definition DeclCXX.h:1261
static CXXRecordDecl * CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, unsigned DependencyKind, bool IsGeneric, LambdaCaptureDefault CaptureDefault)
Definition DeclCXX.cpp:141
llvm::iterator_range< conversion_iterator > getVisibleConversionFunctions() const
Get all conversion functions visible in current class, including conversion function templates.
Definition DeclCXX.cpp:1987
bool hasConstexprDestructor() const
Determine whether this class has a constexpr destructor.
Definition DeclCXX.cpp:598
unsigned getNumBases() const
Retrieves the number of base classes of this class.
Definition DeclCXX.h:602
bool hasNonLiteralTypeFieldsOrBases() const
Determine whether this class has a non-literal or/ volatile type non-static data member or base class...
Definition DeclCXX.h:1414
bool isTriviallyCopyConstructible() const
Determine whether this class is considered trivially copyable per.
Definition DeclCXX.cpp:627
bool isCapturelessLambda() const
Definition DeclCXX.h:1064
const CXXRecordDecl * getTemplateInstantiationPattern() const
Retrieve the record declaration from which this record could be instantiated.
Definition DeclCXX.cpp:2085
bool lambdaIsDefaultConstructibleAndAssignable() const
Determine whether this lambda should have an implicit default constructor and copy and move assignmen...
Definition DeclCXX.cpp:729
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
Definition DeclCXX.cpp:2060
base_class_iterator bases_begin()
Definition DeclCXX.h:615
FunctionTemplateDecl * getDependentLambdaCallOperator() const
Retrieve the dependent lambda call operator of the closure type if this is a templated closure type.
Definition DeclCXX.cpp:1737
void addedEligibleSpecialMemberFunction(const CXXMethodDecl *MD, unsigned SMKind)
Notify the class that an eligible SMF has been added.
Definition DeclCXX.cpp:1536
conversion_iterator conversion_end() const
Definition DeclCXX.h:1125
void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD)
Indicates that the declaration of a defaulted or deleted special member function is now complete.
Definition DeclCXX.cpp:1582
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:1668
void setInstantiationOfMemberClass(CXXRecordDecl *RD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member class RD.
Definition DeclCXX.cpp:2043
static CXXRecordDecl * CreateDeserialized(const ASTContext &C, GlobalDeclID ID)
Definition DeclCXX.cpp:154
bool hasSimpleMoveAssignment() const
true if we know for sure that this class has a single, accessible, unambiguous move assignment operat...
Definition DeclCXX.h:744
bool hasNonTrivialMoveConstructor() const
Determine whether this class has a non-trivial move constructor (C++11 [class.copy]p12)
Definition DeclCXX.h:1319
CanQualType getCanonicalTemplateSpecializationType(const ASTContext &Ctx) const
Definition DeclCXX.cpp:2172
bool hasUserDeclaredConstructor() const
Determine whether this class has any user-declared constructors.
Definition DeclCXX.h:780
unsigned getODRHash() const
Definition DeclCXX.cpp:493
bool hasDefinition() const
Definition DeclCXX.h:561
ArrayRef< NamedDecl * > getLambdaExplicitTemplateParameters() const
Retrieve the lambda template parameters that were specified explicitly.
Definition DeclCXX.cpp:1820
ClassTemplateDecl * getDescribedClassTemplate() const
Retrieves the class template that is described by this class declaration.
Definition DeclCXX.cpp:2052
bool isPOD() const
Whether this class is a POD-type (C++ [class]p4)
Definition DeclCXX.h:1171
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:2005
bool hasSimpleCopyConstructor() const
true if we know for sure that this class has a single, accessible, unambiguous copy constructor that ...
Definition DeclCXX.h:723
bool isInjectedClassName() const
Determines whether this declaration represents the injected class name.
Definition DeclCXX.cpp:2149
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
Definition DeclCXX.cpp:2124
bool hasNonTrivialMoveAssignment() const
Determine whether this class has a non-trivial move assignment operator (C++11 [class....
Definition DeclCXX.h:1354
void setLambdaContextDecl(Decl *ContextDecl)
Set the context declaration for a lambda class.
Definition DeclCXX.cpp:1840
UnresolvedSetIterator conversion_iterator
Definition DeclCXX.h:1119
CXXMethodDecl * getLambdaStaticInvoker() const
Retrieve the lambda static invoker, the address of which is returned by the conversion operator,...
Definition DeclCXX.cpp:1754
bool hasSimpleDestructor() const
true if we know for sure that this class has an accessible destructor that is not deleted.
Definition DeclCXX.h:751
void setDescribedClassTemplate(ClassTemplateDecl *Template)
Definition DeclCXX.cpp:2056
bool isInterfaceLike() const
Definition DeclCXX.cpp:2191
friend class DeclContext
Definition DeclCXX.h:266
void setLambdaNumbering(LambdaNumbering Numbering)
Set the mangling numbers for a lambda class.
Definition DeclCXX.cpp:1845
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:2037
bool hasNonTrivialCopyConstructor() const
Determine whether this class has a non-trivial copy constructor (C++ [class.copy]p6,...
Definition DeclCXX.h:1294
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
Definition DeclCXX.cpp:1742
const CXXRecordDecl * getStandardLayoutBaseWithFields() const
If this is a standard-layout class or union, any and all data members will be declared in the same ty...
Definition DeclCXX.cpp:562
bool hasSimpleCopyAssignment() const
true if we know for sure that this class has a single, accessible, unambiguous copy assignment operat...
Definition DeclCXX.h:737
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition DeclCXX.h:522
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition DeclCXX.cpp:2071
bool isTrivial() const
Determine whether this class is considered trivial.
Definition DeclCXX.h:1442
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
Definition DeclCXX.h:623
conversion_iterator conversion_begin() const
Definition DeclCXX.h:1121
Declaration of a class template.
Represents the canonical version of C arrays with a specified constant size.
Definition TypeBase.h:3822
llvm::APInt getSize() const
Return the constant array size as an APInt.
Definition TypeBase.h:3878
Represents a shadow constructor declaration introduced into a class by a C++11 using-declaration that...
Definition DeclCXX.h:3682
static ConstructorUsingShadowDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclCXX.cpp:3491
UsingDecl * getIntroducer() const
Override the UsingShadowDecl's getIntroducer, returning the UsingDecl that introduced this.
Definition DeclCXX.h:3739
static ConstructorUsingShadowDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation Loc, UsingDecl *Using, NamedDecl *Target, bool IsVirtual)
Definition DeclCXX.cpp:3483
CXXRecordDecl * getNominatedBaseClass() const
Get the base class that was named in the using declaration.
Definition DeclCXX.cpp:3495
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1462
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2122
DeclContextLookupResult lookup_result
Definition DeclBase.h:2590
ASTContext & getParentASTContext() const
Definition DeclBase.h:2151
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
bool isNamespace() const
Definition DeclBase.h:2211
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
bool isTranslationUnit() const
Definition DeclBase.h:2198
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
DeclContext(Decl::Kind K)
bool isExternCContext() const
Determines whether this context or some of its ancestors is a linkage specification context that spec...
LinkageSpecDeclBitfields LinkageSpecDeclBits
Definition DeclBase.h:2061
Decl::Kind getDeclKind() const
Definition DeclBase.h:2115
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:1074
SourceLocation getEndLoc() const LLVM_READONLY
Definition DeclBase.h:443
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Definition DeclBase.h:1239
T * getAttr() const
Definition DeclBase.h:581
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:547
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition DeclBase.h:601
virtual Decl * getPreviousDeclImpl()
Implementation of getPreviousDecl(), to be overridden by any subclass that has a redeclaration chain.
Definition DeclBase.h:1008
ASTMutationListener * getASTMutationListener() const
Definition DeclBase.cpp:557
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:997
Module * getOwningModule() const
Get the module that owns this declaration (for visibility purposes).
Definition DeclBase.h:850
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
Definition DeclBase.cpp:273
bool isInvalidDecl() const
Definition DeclBase.h:596
virtual Decl * getNextRedeclarationImpl()
Returns the next redeclaration or itself if this is the only decl.
Definition DeclBase.h:1004
SourceLocation getLocation() const
Definition DeclBase.h:447
void setImplicit(bool I=true)
Definition DeclBase.h:602
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition DeclBase.h:1062
unsigned Access
Access - Used by C++ decls for the access specifier.
Definition DeclBase.h:344
DeclContext * getDeclContext()
Definition DeclBase.h:456
AccessSpecifier getAccess() const
Definition DeclBase.h:515
virtual Decl * getMostRecentDeclImpl()
Implementation of getMostRecentDecl(), to be overridden by any subclass that has a redeclaration chai...
Definition DeclBase.h:1012
bool hasAttr() const
Definition DeclBase.h:585
friend class DeclContext
Definition DeclBase.h:260
Kind getKind() const
Definition DeclBase.h:450
const LangOptions & getLangOpts() const LLVM_READONLY
Helper to get the language options from the ASTContext.
Definition DeclBase.cpp:553
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.
void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override
Pretty-print the unqualified name of this declaration.
Definition DeclCXX.cpp:3752
ArrayRef< BindingDecl * > bindings() const
Definition DeclCXX.h:4292
static DecompositionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation LSquareLoc, QualType T, TypeSourceInfo *TInfo, StorageClass S, ArrayRef< BindingDecl * > Bindings)
Definition DeclCXX.cpp:3727
static DecompositionDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumBindings)
Definition DeclCXX.cpp:3738
Store information needed for an explicit specifier.
Definition DeclCXX.h:1931
ExplicitSpecKind getKind() const
Definition DeclCXX.h:1939
bool isEquivalent(ExplicitSpecifier Other) const
Check for equivalence of explicit specifiers.
Definition DeclCXX.cpp:2350
const Expr * getExpr() const
Definition DeclCXX.h:1940
static ExplicitSpecifier getFromDecl(const FunctionDecl *Function)
Definition DeclCXX.cpp:2365
This represents one expression.
Definition Expr.h:112
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3085
Abstract interface for external sources of AST nodes.
Represents a member of a struct/union/class.
Definition Decl.h:3178
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition Decl.cpp:4699
Represents a function declaration or definition.
Definition Decl.h:2018
static constexpr unsigned RequiredTypeAwareDeleteParameterCount
Count of mandatory parameters for type aware operator delete.
Definition Decl.h:2660
const ParmVarDecl * getParamDecl(unsigned i) const
Definition Decl.h:2815
bool isTrivialForCall() const
Definition Decl.h:2398
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to call this function.
Definition Decl.cpp:3821
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition Decl.cpp:4167
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
Definition Decl.cpp:3525
bool hasCXXExplicitFunctionObjectParameter() const
Definition Decl.cpp:3839
bool UsesFPIntrin() const
Determine whether the function was declared in source context that requires constrained FP intrinsics...
Definition Decl.h:2927
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:2792
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition Decl.h:2395
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
Definition Decl.cpp:4287
const ParmVarDecl * getNonObjectParameter(unsigned I) const
Definition Decl.h:2841
bool isVariadic() const
Whether this function is variadic.
Definition Decl.cpp:3107
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition Decl.h:2344
bool isDeleted() const
Whether this function has been deleted.
Definition Decl.h:2558
FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, StorageClass S, bool UsesFPIntrin, bool isInlineSpecified, ConstexprSpecKind ConstexprKind, const AssociatedConstraint &TrailingRequiresClause)
Definition Decl.cpp:3053
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:2906
bool isOutOfLine() const override
Determine whether this is or was instantiated from an out-of-line definition of a member function.
Definition Decl.cpp:4500
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
Definition Decl.h:2371
bool isTypeAwareOperatorNewOrDelete() const
Determine whether this is a type aware operator new or delete.
Definition Decl.cpp:3533
bool isDefaulted() const
Whether this function is defaulted.
Definition Decl.h:2403
bool isIneligibleOrNotSelected() const
Definition Decl.h:2436
void setIneligibleOrNotSelected(bool II)
Definition Decl.h:2439
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any.
Definition Decl.cpp:4104
bool isUserProvided() const
True if this method is user-declared and was not deleted or defaulted on its first declaration.
Definition Decl.h:2428
bool hasOneParamOrDefaultArgs() const
Determine whether this function has a single parameter, or multiple parameters where all but the firs...
Definition Decl.cpp:3853
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition Decl.cpp:3800
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:3220
bool willHaveBody() const
True if this function will eventually have a body, once it's fully parsed.
Definition Decl.h:2703
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5369
Qualifiers getMethodQuals() const
Definition TypeBase.h:5795
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
Definition TypeBase.h:5803
Declaration of a template function.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition TypeBase.h:4565
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:3485
Description of a constructor that was inherited from a base class.
Definition DeclCXX.h:2591
An lvalue reference type, per C++11 [dcl.ref].
Definition TypeBase.h:3679
Describes the capture of a variable or of this, or of a C++1y init-capture.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
APValue * getOrCreateValue(bool MayCreate) const
Get the storage for the constant value of a materialized temporary of static storage duration.
Definition DeclCXX.cpp:3438
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
Definition DeclCXX.cpp:3422
static LinkageSpecDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation ExternLoc, SourceLocation LangLoc, LinkageSpecLanguageIDs Lang, bool HasBraces)
Definition DeclCXX.cpp:3298
static LinkageSpecDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclCXX.cpp:3306
A global _GUID constant.
Definition DeclCXX.h:4403
APValue & getAsAPValue() const
Get the value of this MSGuidDecl as an APValue.
Definition DeclCXX.cpp:3859
MSGuidDeclParts Parts
Definition DeclCXX.h:4405
void printName(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const override
Print this UUID in a human-readable format.
Definition DeclCXX.cpp:3798
static MSPropertyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName N, QualType T, TypeSourceInfo *TInfo, SourceLocation StartL, IdentifierInfo *Getter, IdentifierInfo *Setter)
Definition DeclCXX.cpp:3767
static MSPropertyDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclCXX.cpp:3776
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition TypeBase.h:3715
Provides information a specialization of a member of a class template, which may be a member function...
Describes a module or submodule.
Definition Module.h:340
This represents a decl that may have a name.
Definition Decl.h:274
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition Decl.h:487
NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
Definition Decl.h:286
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:301
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition Decl.h:340
Represents a C++ namespace alias.
Definition DeclCXX.h:3206
static NamespaceAliasDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclCXX.cpp:3411
static NamespaceAliasDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation NamespaceLoc, SourceLocation AliasLoc, IdentifierInfo *Alias, NestedNameSpecifierLoc QualifierLoc, SourceLocation IdentLoc, NamespaceBaseDecl *Namespace)
Definition DeclCXX.cpp:3399
NamespaceAliasDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
NamespaceAliasDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
Represents C++ namespaces and their aliases.
Definition Decl.h:573
NamespaceDecl * getNamespace()
Definition DeclCXX.cpp:3336
Represent a C++ namespace.
Definition Decl.h:592
NamespaceDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
NamespaceDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
static NamespaceDecl * Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl, bool Nested)
Definition DeclCXX.cpp:3359
static NamespaceDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclCXX.cpp:3367
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, or null.
void AddStmt(const Stmt *S)
Definition ODRHash.cpp:23
void AddCXXRecordDecl(const CXXRecordDecl *Record)
Definition ODRHash.cpp:578
unsigned CalculateHash()
Definition ODRHash.cpp:231
Represents a parameter to a function.
Definition Decl.h:1808
A (possibly-)qualified type.
Definition TypeBase.h:937
void addRestrict()
Add the restrict qualifier to this QualType.
Definition TypeBase.h:1187
bool hasAddressDiscriminatedPointerAuth() const
Definition TypeBase.h:1472
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition TypeBase.h:8529
PointerAuthQualifier getPointerAuth() const
Definition TypeBase.h:1468
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition TypeBase.h:8485
bool isCXX98PODType(const ASTContext &Context) const
Return true if this is a POD type according to the rules of the C++98 standard, regardless of the cur...
Definition Type.cpp:2796
bool isObjCGCStrong() const
true when Type is objc's strong.
Definition TypeBase.h:1448
void removeLocalRestrict()
Definition TypeBase.h:8557
bool isConstQualified() const
Determine whether this type is const-qualified.
Definition TypeBase.h:8518
unsigned getCVRQualifiers() const
Retrieve the set of CVR (const-volatile-restrict) qualifiers applied to this type.
Definition TypeBase.h:8491
bool hasNonTrivialObjCLifetime() const
Definition TypeBase.h:1457
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
Definition TypeBase.h:361
@ OCL_Weak
Reading or writing from this object requires a barrier call.
Definition TypeBase.h:364
bool hasRestrict() const
Definition TypeBase.h:477
ObjCLifetime getObjCLifetime() const
Definition TypeBase.h:545
Represents a struct/union/class.
Definition Decl.h:4343
RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, RecordDecl *PrevDecl)
Definition Decl.cpp:5182
void setArgPassingRestrictions(RecordArgPassingKind Kind)
Definition Decl.h:4489
field_iterator field_end() const
Definition Decl.h:4549
field_range fields() const
Definition Decl.h:4546
void setHasObjectMember(bool val)
Definition Decl.h:4404
void setHasVolatileMember(bool val)
Definition Decl.h:4408
bool mayInsertExtraPadding(bool EmitRemark=false) const
Whether we are allowed to insert extra padding between fields.
Definition Decl.cpp:5334
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition Decl.cpp:5265
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition Decl.h:4527
bool hasUninitializedExplicitInitFields() const
Definition Decl.h:4469
specific_decl_iterator< FieldDecl > field_iterator
Definition Decl.h:4543
void setHasUninitializedExplicitInitFields(bool V)
Definition Decl.h:4473
bool field_empty() const
Definition Decl.h:4554
field_iterator field_begin() const
Definition Decl.cpp:5249
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
NamespaceDecl * getNextRedeclaration() const
Base for LValueReferenceType and RValueReferenceType.
Definition TypeBase.h:3635
Represents the body of a requires-expression.
Definition DeclCXX.h:2101
static RequiresExprBodyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc)
Definition DeclCXX.cpp:2400
static RequiresExprBodyDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclCXX.cpp:2406
Encodes a location in the source.
A trivial tuple used to represent a source range.
static StaticAssertDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StaticAssertLoc, Expr *AssertExpr, Expr *Message, SourceLocation RParenLoc, bool Failed)
Definition DeclCXX.cpp:3665
static StaticAssertDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclCXX.cpp:3674
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
TagTypeKind TagKind
Definition Decl.h:3740
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition Decl.h:3856
bool isStruct() const
Definition Decl.h:3943
bool isUnion() const
Definition Decl.h:3946
bool isInterface() const
Definition Decl.h:3944
TagKind getTagKind() const
Definition Decl.h:3935
bool isDependentType() const
Whether this declaration declares a type that is dependent, i.e., a type that somehow depends on temp...
Definition Decl.h:3881
virtual bool areDefaultedSMFStillPOD(const LangOptions &) const
Controls whether explicitly defaulted (= default) special member functions disqualify something from ...
Stores a list of template parameters for a TemplateDecl and its derived classes.
friend class ASTContext
Definition Decl.h:3532
Base wrapper for a particular "section" of type source info.
Definition TypeLoc.h:59
A container of type source information.
Definition TypeBase.h:8416
The base class of the type hierarchy.
Definition TypeBase.h:1875
bool isBlockPointerType() const
Definition TypeBase.h:8702
bool isLiteralType(const ASTContext &Ctx) const
Return true if this is a literal type (C++11 [basic.types]p10)
Definition Type.cpp:3109
bool isRValueReferenceType() const
Definition TypeBase.h:8714
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition Type.h:26
bool isHLSLBuiltinIntangibleType() const
Definition TypeBase.h:8993
const T * castAs() const
Member-template castAs<specific type>.
Definition TypeBase.h:9342
bool isReferenceType() const
Definition TypeBase.h:8706
const Type * getArrayElementTypeNoTypeQual() const
If this is an array type, return the element type of the array, potentially with type qualifiers miss...
Definition Type.cpp:508
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition Type.cpp:789
bool isLValueReferenceType() const
Definition TypeBase.h:8710
bool isStructuralType() const
Determine if this type is a structural type, per C++20 [temp.param]p7.
Definition Type.cpp:3181
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition TypeBase.h:2844
bool isHLSLAttributedResourceType() const
Definition TypeBase.h:9005
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9275
const Type * getUnqualifiedDesugaredType() const
Return the specified type with any "sugar" removed from the type, removing any typedefs,...
Definition Type.cpp:690
bool isRecordType() const
Definition TypeBase.h:8809
bool isObjCRetainableType() const
Definition Type.cpp:5417
An artificial decl, representing a global anonymous constant value which is uniquified by value withi...
Definition DeclCXX.h:4460
void printName(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const override
Print this in a human-readable format.
Definition DeclCXX.cpp:3909
A set of unresolved declarations.
void addDecl(NamedDecl *D)
The iterator over UnresolvedSets.
NamedDecl * getDecl() const
A set of unresolved declarations.
This node is generated when a using-declaration that was annotated with attribute((using_if_exists)) ...
Definition DeclCXX.h:4123
static UnresolvedUsingIfExistsDecl * CreateDeserialized(ASTContext &Ctx, GlobalDeclID ID)
Definition DeclCXX.cpp:3650
static UnresolvedUsingIfExistsDecl * Create(ASTContext &Ctx, DeclContext *DC, SourceLocation Loc, DeclarationName Name)
Definition DeclCXX.cpp:3644
Represents a dependent using declaration which was marked with typename.
Definition DeclCXX.h:4042
static UnresolvedUsingTypenameDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TargetNameLoc, DeclarationName TargetName, SourceLocation EllipsisLoc)
Definition DeclCXX.cpp:3623
static UnresolvedUsingTypenameDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclCXX.cpp:3636
Represents a dependent using declaration which was not marked with typename.
Definition DeclCXX.h:3945
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no 'using').
Definition DeclCXX.h:3982
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:3986
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:3993
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition DeclCXX.cpp:3614
static UnresolvedUsingValueDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, SourceLocation EllipsisLoc)
Definition DeclCXX.cpp:3595
static UnresolvedUsingValueDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclCXX.cpp:3606
Represents a C++ using-declaration.
Definition DeclCXX.h:3596
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no 'using').
Definition DeclCXX.h:3642
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition DeclCXX.cpp:3545
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Definition DeclCXX.h:3633
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:3630
static UsingDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclCXX.cpp:3539
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:3637
static UsingDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingL, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword)
Definition DeclCXX.cpp:3532
static UsingDirectiveDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclCXX.cpp:3328
static UsingDirectiveDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, SourceLocation NamespaceLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation IdentLoc, NamedDecl *Nominated, DeclContext *CommonAncestor)
Definition DeclCXX.cpp:3315
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
Definition DeclCXX.cpp:3342
friend class DeclContext
Definition DeclCXX.h:3142
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition DeclCXX.cpp:3569
static UsingEnumDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclCXX.cpp:3562
static UsingEnumDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingL, SourceLocation EnumL, SourceLocation NameL, TypeSourceInfo *EnumType)
Definition DeclCXX.cpp:3553
static UsingPackDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumExpansions)
Definition DeclCXX.cpp:3582
static UsingPackDecl * Create(ASTContext &C, DeclContext *DC, NamedDecl *InstantiatedFrom, ArrayRef< NamedDecl * > UsingDecls)
Definition DeclCXX.cpp:3575
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3404
void setTargetDecl(NamedDecl *ND)
Sets the underlying declaration which has been brought into the local scope.
Definition DeclCXX.h:3472
UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC, SourceLocation Loc, DeclarationName Name, BaseUsingDecl *Introducer, NamedDecl *Target)
Definition DeclCXX.cpp:3451
static UsingShadowDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition DeclCXX.cpp:3467
friend class BaseUsingDecl
Definition DeclCXX.h:3405
BaseUsingDecl * getIntroducer() const
Gets the (written or instantiated) using declaration that introduced this declaration.
Definition DeclCXX.cpp:3472
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
ValueDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N, QualType T)
Definition Decl.h:718
QualType getType() const
Definition Decl.h:723
VarDecl * getPotentiallyDecomposedVarDecl()
Definition DeclCXX.cpp:3680
Represents a variable declaration or definition.
Definition Decl.h:924
Defines the clang::TargetInfo interface.
bool LT(InterpState &S, CodePtr OpPC)
Definition Interp.h:1466
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
bool isa(CodeGen::Address addr)
Definition Address.h:330
bool isTemplateInstantiation(TemplateSpecializationKind Kind)
Determine whether this template specialization kind refers to an instantiation of an entity (as oppos...
Definition Specifiers.h:213
@ CPlusPlus20
@ CPlusPlus14
ConstexprSpecKind
Define the kind of constexpr specifier.
Definition Specifiers.h:36
LinkageSpecLanguageIDs
Represents the language in a linkage specification.
Definition DeclCXX.h:3012
RefQualifierKind
The kind of C++11 ref-qualifier associated with a function type.
Definition TypeBase.h:1795
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
Definition TypeBase.h:1803
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition Specifiers.h:124
@ AS_public
Definition Specifiers.h:125
@ AS_protected
Definition Specifiers.h:126
@ AS_none
Definition Specifiers.h:128
@ AS_private
Definition Specifiers.h:127
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
StorageClass
Storage classes.
Definition Specifiers.h:249
@ SC_Static
Definition Specifiers.h:253
@ SC_None
Definition Specifiers.h:251
StorageDuration
The storage duration for an object (per C++ [basic.stc]).
Definition Specifiers.h:340
@ SD_Static
Static storage duration.
Definition Specifiers.h:344
@ SD_FullExpression
Full-expression storage duration (for temporaries).
Definition Specifiers.h:341
@ SD_Automatic
Automatic storage duration (most local variables).
Definition Specifiers.h:342
@ Result
The result type of a method or function.
Definition TypeBase.h:905
@ Template
We are parsing a template declaration.
Definition Parser.h:81
@ Interface
The "__interface" keyword.
Definition TypeBase.h:5998
@ Struct
The "struct" keyword.
Definition TypeBase.h:5995
@ Class
The "class" keyword.
Definition TypeBase.h:6004
@ Type
The name was classified as a type.
Definition Sema.h:564
@ CanNeverPassInRegs
The argument of this type cannot be passed directly in registers.
Definition Decl.h:4336
LambdaCaptureDefault
The default, if any, capture method for a lambda expression.
Definition Lambda.h:22
StringRef getLambdaStaticInvokerName()
Definition ASTLambda.h:23
DeductionCandidate
Only used by CXXDeductionGuideDecl.
Definition DeclBase.h:1434
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition DeclBase.h:1301
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ConceptReference *C)
Insertion operator for diagnostics.
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition Specifiers.h:189
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...
Definition Specifiers.h:192
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition Specifiers.h:279
U cast(CodeGen::Address addr)
Definition Address.h:327
@ Other
Other implicit parameter.
Definition Decl.h:1763
#define false
Definition stdbool.h:26
#define true
Definition stdbool.h:25
Information about how a lambda is numbered within its context.
Definition DeclCXX.h:1805
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.
Describes how types, statements, expressions, and declarations should be printed.