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