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