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