clang 18.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, TTK_Class, C, DC, Loc, Loc,
152 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) CXXRecordDecl(
166 CXXRecord, TTK_Struct, C, nullptr, SourceLocation(), SourceLocation(),
167 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
590void CXXRecordDecl::markedVirtualFunctionPure() {
591 // C++ [class.abstract]p2:
592 // A class is abstract if it has at least one pure virtual function.
593 data().Abstract = true;
594}
595
596bool CXXRecordDecl::hasSubobjectAtOffsetZeroOfEmptyBaseType(
597 ASTContext &Ctx, const CXXRecordDecl *XFirst) {
598 if (!getNumBases())
599 return false;
600
604
605 // Visit a type that we have determined is an element of M(S).
606 auto Visit = [&](const CXXRecordDecl *RD) -> bool {
607 RD = RD->getCanonicalDecl();
608
609 // C++2a [class]p8:
610 // A class S is a standard-layout class if it [...] has no element of the
611 // set M(S) of types as a base class.
612 //
613 // If we find a subobject of an empty type, it might also be a base class,
614 // so we'll need to walk the base classes to check.
615 if (!RD->data().HasBasesWithFields) {
616 // Walk the bases the first time, stopping if we find the type. Build a
617 // set of them so we don't need to walk them again.
618 if (Bases.empty()) {
619 bool RDIsBase = !forallBases([&](const CXXRecordDecl *Base) -> bool {
620 Base = Base->getCanonicalDecl();
621 if (RD == Base)
622 return false;
623 Bases.insert(Base);
624 return true;
625 });
626 if (RDIsBase)
627 return true;
628 } else {
629 if (Bases.count(RD))
630 return true;
631 }
632 }
633
634 if (M.insert(RD).second)
635 WorkList.push_back(RD);
636 return false;
637 };
638
639 if (Visit(XFirst))
640 return true;
641
642 while (!WorkList.empty()) {
643 const CXXRecordDecl *X = WorkList.pop_back_val();
644
645 // FIXME: We don't check the bases of X. That matches the standard, but
646 // that sure looks like a wording bug.
647
648 // -- If X is a non-union class type with a non-static data member
649 // [recurse to each field] that is either of zero size or is the
650 // first non-static data member of X
651 // -- If X is a union type, [recurse to union members]
652 bool IsFirstField = true;
653 for (auto *FD : X->fields()) {
654 // FIXME: Should we really care about the type of the first non-static
655 // data member of a non-union if there are preceding unnamed bit-fields?
656 if (FD->isUnnamedBitfield())
657 continue;
658
659 if (!IsFirstField && !FD->isZeroSize(Ctx))
660 continue;
661
662 // -- If X is n array type, [visit the element type]
663 QualType T = Ctx.getBaseElementType(FD->getType());
664 if (auto *RD = T->getAsCXXRecordDecl())
665 if (Visit(RD))
666 return true;
667
668 if (!X->isUnion())
669 IsFirstField = false;
670 }
671 }
672
673 return false;
674}
675
677 assert(isLambda() && "not a lambda");
678
679 // C++2a [expr.prim.lambda.capture]p11:
680 // The closure type associated with a lambda-expression has no default
681 // constructor if the lambda-expression has a lambda-capture and a
682 // defaulted default constructor otherwise. It has a deleted copy
683 // assignment operator if the lambda-expression has a lambda-capture and
684 // defaulted copy and move assignment operators otherwise.
685 //
686 // C++17 [expr.prim.lambda]p21:
687 // The closure type associated with a lambda-expression has no default
688 // constructor and a deleted copy assignment operator.
690 return false;
691 return getASTContext().getLangOpts().CPlusPlus20;
692}
693
694void CXXRecordDecl::addedMember(Decl *D) {
695 if (!D->isImplicit() &&
696 !isa<FieldDecl>(D) &&
697 !isa<IndirectFieldDecl>(D) &&
698 (!isa<TagDecl>(D) || cast<TagDecl>(D)->getTagKind() == TTK_Class ||
699 cast<TagDecl>(D)->getTagKind() == TTK_Interface))
700 data().HasOnlyCMembers = false;
701
702 // Ignore friends and invalid declarations.
703 if (D->getFriendObjectKind() || D->isInvalidDecl())
704 return;
705
706 auto *FunTmpl = dyn_cast<FunctionTemplateDecl>(D);
707 if (FunTmpl)
708 D = FunTmpl->getTemplatedDecl();
709
710 // FIXME: Pass NamedDecl* to addedMember?
711 Decl *DUnderlying = D;
712 if (auto *ND = dyn_cast<NamedDecl>(DUnderlying)) {
713 DUnderlying = ND->getUnderlyingDecl();
714 if (auto *UnderlyingFunTmpl = dyn_cast<FunctionTemplateDecl>(DUnderlying))
715 DUnderlying = UnderlyingFunTmpl->getTemplatedDecl();
716 }
717
718 if (const auto *Method = dyn_cast<CXXMethodDecl>(D)) {
719 if (Method->isVirtual()) {
720 // C++ [dcl.init.aggr]p1:
721 // An aggregate is an array or a class with [...] no virtual functions.
722 data().Aggregate = false;
723
724 // C++ [class]p4:
725 // A POD-struct is an aggregate class...
726 data().PlainOldData = false;
727
728 // C++14 [meta.unary.prop]p4:
729 // T is a class type [...] with [...] no virtual member functions...
730 data().Empty = false;
731
732 // C++ [class.virtual]p1:
733 // A class that declares or inherits a virtual function is called a
734 // polymorphic class.
735 data().Polymorphic = true;
736
737 // C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25:
738 // A [default constructor, copy/move constructor, or copy/move
739 // assignment operator for a class X] is trivial [...] if:
740 // -- class X has no virtual functions [...]
741 data().HasTrivialSpecialMembers &= SMF_Destructor;
742 data().HasTrivialSpecialMembersForCall &= SMF_Destructor;
743
744 // C++0x [class]p7:
745 // A standard-layout class is a class that: [...]
746 // -- has no virtual functions
747 data().IsStandardLayout = false;
748 data().IsCXX11StandardLayout = false;
749 }
750 }
751
752 // Notify the listener if an implicit member was added after the definition
753 // was completed.
754 if (!isBeingDefined() && D->isImplicit())
756 L->AddedCXXImplicitMember(data().Definition, D);
757
758 // The kind of special member this declaration is, if any.
759 unsigned SMKind = 0;
760
761 // Handle constructors.
762 if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(D)) {
763 if (Constructor->isInheritingConstructor()) {
764 // Ignore constructor shadow declarations. They are lazily created and
765 // so shouldn't affect any properties of the class.
766 } else {
767 if (!Constructor->isImplicit()) {
768 // Note that we have a user-declared constructor.
769 data().UserDeclaredConstructor = true;
770
771 const TargetInfo &TI = getASTContext().getTargetInfo();
772 if ((!Constructor->isDeleted() && !Constructor->isDefaulted()) ||
774 // C++ [class]p4:
775 // A POD-struct is an aggregate class [...]
776 // Since the POD bit is meant to be C++03 POD-ness, clear it even if
777 // the type is technically an aggregate in C++0x since it wouldn't be
778 // in 03.
779 data().PlainOldData = false;
780 }
781 }
782
783 if (Constructor->isDefaultConstructor()) {
784 SMKind |= SMF_DefaultConstructor;
785
786 if (Constructor->isUserProvided())
787 data().UserProvidedDefaultConstructor = true;
788 if (Constructor->isConstexpr())
789 data().HasConstexprDefaultConstructor = true;
790 if (Constructor->isDefaulted())
791 data().HasDefaultedDefaultConstructor = true;
792 }
793
794 if (!FunTmpl) {
795 unsigned Quals;
796 if (Constructor->isCopyConstructor(Quals)) {
797 SMKind |= SMF_CopyConstructor;
798
799 if (Quals & Qualifiers::Const)
800 data().HasDeclaredCopyConstructorWithConstParam = true;
801 } else if (Constructor->isMoveConstructor())
802 SMKind |= SMF_MoveConstructor;
803 }
804
805 // C++11 [dcl.init.aggr]p1: DR1518
806 // An aggregate is an array or a class with no user-provided [or]
807 // explicit [...] constructors
808 // C++20 [dcl.init.aggr]p1:
809 // An aggregate is an array or a class with no user-declared [...]
810 // constructors
812 ? !Constructor->isImplicit()
813 : (Constructor->isUserProvided() || Constructor->isExplicit()))
814 data().Aggregate = false;
815 }
816 }
817
818 // Handle constructors, including those inherited from base classes.
819 if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(DUnderlying)) {
820 // Record if we see any constexpr constructors which are neither copy
821 // nor move constructors.
822 // C++1z [basic.types]p10:
823 // [...] has at least one constexpr constructor or constructor template
824 // (possibly inherited from a base class) that is not a copy or move
825 // constructor [...]
826 if (Constructor->isConstexpr() && !Constructor->isCopyOrMoveConstructor())
827 data().HasConstexprNonCopyMoveConstructor = true;
828 if (!isa<CXXConstructorDecl>(D) && Constructor->isDefaultConstructor())
829 data().HasInheritedDefaultConstructor = true;
830 }
831
832 // Handle member functions.
833 if (const auto *Method = dyn_cast<CXXMethodDecl>(D)) {
834 if (isa<CXXDestructorDecl>(D))
835 SMKind |= SMF_Destructor;
836
837 if (Method->isCopyAssignmentOperator()) {
838 SMKind |= SMF_CopyAssignment;
839
840 const auto *ParamTy =
841 Method->getParamDecl(0)->getType()->getAs<ReferenceType>();
842 if (!ParamTy || ParamTy->getPointeeType().isConstQualified())
843 data().HasDeclaredCopyAssignmentWithConstParam = true;
844 }
845
846 if (Method->isMoveAssignmentOperator())
847 SMKind |= SMF_MoveAssignment;
848
849 // Keep the list of conversion functions up-to-date.
850 if (auto *Conversion = dyn_cast<CXXConversionDecl>(D)) {
851 // FIXME: We use the 'unsafe' accessor for the access specifier here,
852 // because Sema may not have set it yet. That's really just a misdesign
853 // in Sema. However, LLDB *will* have set the access specifier correctly,
854 // and adds declarations after the class is technically completed,
855 // so completeDefinition()'s overriding of the access specifiers doesn't
856 // work.
857 AccessSpecifier AS = Conversion->getAccessUnsafe();
858
859 if (Conversion->getPrimaryTemplate()) {
860 // We don't record specializations.
861 } else {
862 ASTContext &Ctx = getASTContext();
863 ASTUnresolvedSet &Conversions = data().Conversions.get(Ctx);
864 NamedDecl *Primary =
865 FunTmpl ? cast<NamedDecl>(FunTmpl) : cast<NamedDecl>(Conversion);
866 if (Primary->getPreviousDecl())
867 Conversions.replace(cast<NamedDecl>(Primary->getPreviousDecl()),
868 Primary, AS);
869 else
870 Conversions.addDecl(Ctx, Primary, AS);
871 }
872 }
873
874 if (SMKind) {
875 // If this is the first declaration of a special member, we no longer have
876 // an implicit trivial special member.
877 data().HasTrivialSpecialMembers &=
878 data().DeclaredSpecialMembers | ~SMKind;
879 data().HasTrivialSpecialMembersForCall &=
880 data().DeclaredSpecialMembers | ~SMKind;
881
882 // Note when we have declared a declared special member, and suppress the
883 // implicit declaration of this special member.
884 data().DeclaredSpecialMembers |= SMKind;
885 if (!Method->isImplicit()) {
886 data().UserDeclaredSpecialMembers |= SMKind;
887
888 const TargetInfo &TI = getASTContext().getTargetInfo();
889 if ((!Method->isDeleted() && !Method->isDefaulted() &&
890 SMKind != SMF_MoveAssignment) ||
892 // C++03 [class]p4:
893 // A POD-struct is an aggregate class that has [...] no user-defined
894 // copy assignment operator and no user-defined destructor.
895 //
896 // Since the POD bit is meant to be C++03 POD-ness, and in C++03,
897 // aggregates could not have any constructors, clear it even for an
898 // explicitly defaulted or deleted constructor.
899 // type is technically an aggregate in C++0x since it wouldn't be in
900 // 03.
901 //
902 // Also, a user-declared move assignment operator makes a class
903 // non-POD. This is an extension in C++03.
904 data().PlainOldData = false;
905 }
906 }
907 // When instantiating a class, we delay updating the destructor and
908 // triviality properties of the class until selecting a destructor and
909 // computing the eligibility of its special member functions. This is
910 // because there might be function constraints that we need to evaluate
911 // and compare later in the instantiation.
912 if (!Method->isIneligibleOrNotSelected()) {
914 }
915 }
916
917 return;
918 }
919
920 // Handle non-static data members.
921 if (const auto *Field = dyn_cast<FieldDecl>(D)) {
922 ASTContext &Context = getASTContext();
923
924 // C++2a [class]p7:
925 // A standard-layout class is a class that:
926 // [...]
927 // -- has all non-static data members and bit-fields in the class and
928 // its base classes first declared in the same class
929 if (data().HasBasesWithFields)
930 data().IsStandardLayout = false;
931
932 // C++ [class.bit]p2:
933 // A declaration for a bit-field that omits the identifier declares an
934 // unnamed bit-field. Unnamed bit-fields are not members and cannot be
935 // initialized.
936 if (Field->isUnnamedBitfield()) {
937 // C++ [meta.unary.prop]p4: [LWG2358]
938 // T is a class type [...] with [...] no unnamed bit-fields of non-zero
939 // length
940 if (data().Empty && !Field->isZeroLengthBitField(Context) &&
941 Context.getLangOpts().getClangABICompat() >
943 data().Empty = false;
944 return;
945 }
946
947 // C++11 [class]p7:
948 // A standard-layout class is a class that:
949 // -- either has no non-static data members in the most derived class
950 // [...] or has no base classes with non-static data members
951 if (data().HasBasesWithNonStaticDataMembers)
952 data().IsCXX11StandardLayout = false;
953
954 // C++ [dcl.init.aggr]p1:
955 // An aggregate is an array or a class (clause 9) with [...] no
956 // private or protected non-static data members (clause 11).
957 //
958 // A POD must be an aggregate.
959 if (D->getAccess() == AS_private || D->getAccess() == AS_protected) {
960 data().Aggregate = false;
961 data().PlainOldData = false;
962
963 // C++20 [temp.param]p7:
964 // A structural type is [...] a literal class type [for which] all
965 // non-static data members are public
966 data().StructuralIfLiteral = false;
967 }
968
969 // Track whether this is the first field. We use this when checking
970 // whether the class is standard-layout below.
971 bool IsFirstField = !data().HasPrivateFields &&
972 !data().HasProtectedFields && !data().HasPublicFields;
973
974 // C++0x [class]p7:
975 // A standard-layout class is a class that:
976 // [...]
977 // -- has the same access control for all non-static data members,
978 switch (D->getAccess()) {
979 case AS_private: data().HasPrivateFields = true; break;
980 case AS_protected: data().HasProtectedFields = true; break;
981 case AS_public: data().HasPublicFields = true; break;
982 case AS_none: llvm_unreachable("Invalid access specifier");
983 };
984 if ((data().HasPrivateFields + data().HasProtectedFields +
985 data().HasPublicFields) > 1) {
986 data().IsStandardLayout = false;
987 data().IsCXX11StandardLayout = false;
988 }
989
990 // Keep track of the presence of mutable fields.
991 if (Field->isMutable()) {
992 data().HasMutableFields = true;
993
994 // C++20 [temp.param]p7:
995 // A structural type is [...] a literal class type [for which] all
996 // non-static data members are public
997 data().StructuralIfLiteral = false;
998 }
999
1000 // C++11 [class.union]p8, DR1460:
1001 // If X is a union, a non-static data member of X that is not an anonymous
1002 // union is a variant member of X.
1003 if (isUnion() && !Field->isAnonymousStructOrUnion())
1004 data().HasVariantMembers = true;
1005
1006 // C++0x [class]p9:
1007 // A POD struct is a class that is both a trivial class and a
1008 // standard-layout class, and has no non-static data members of type
1009 // non-POD struct, non-POD union (or array of such types).
1010 //
1011 // Automatic Reference Counting: the presence of a member of Objective-C pointer type
1012 // that does not explicitly have no lifetime makes the class a non-POD.
1013 QualType T = Context.getBaseElementType(Field->getType());
1014 if (T->isObjCRetainableType() || T.isObjCGCStrong()) {
1015 if (T.hasNonTrivialObjCLifetime()) {
1016 // Objective-C Automatic Reference Counting:
1017 // If a class has a non-static data member of Objective-C pointer
1018 // type (or array thereof), it is a non-POD type and its
1019 // default constructor (if any), copy constructor, move constructor,
1020 // copy assignment operator, move assignment operator, and destructor are
1021 // non-trivial.
1022 setHasObjectMember(true);
1023 struct DefinitionData &Data = data();
1024 Data.PlainOldData = false;
1025 Data.HasTrivialSpecialMembers = 0;
1026
1027 // __strong or __weak fields do not make special functions non-trivial
1028 // for the purpose of calls.
1031 data().HasTrivialSpecialMembersForCall = 0;
1032
1033 // Structs with __weak fields should never be passed directly.
1034 if (LT == Qualifiers::OCL_Weak)
1036
1037 Data.HasIrrelevantDestructor = false;
1038
1039 if (isUnion()) {
1040 data().DefaultedCopyConstructorIsDeleted = true;
1041 data().DefaultedMoveConstructorIsDeleted = true;
1042 data().DefaultedCopyAssignmentIsDeleted = true;
1043 data().DefaultedMoveAssignmentIsDeleted = true;
1044 data().DefaultedDestructorIsDeleted = true;
1045 data().NeedOverloadResolutionForCopyConstructor = true;
1046 data().NeedOverloadResolutionForMoveConstructor = true;
1047 data().NeedOverloadResolutionForCopyAssignment = true;
1048 data().NeedOverloadResolutionForMoveAssignment = true;
1049 data().NeedOverloadResolutionForDestructor = true;
1050 }
1051 } else if (!Context.getLangOpts().ObjCAutoRefCount) {
1052 setHasObjectMember(true);
1053 }
1054 } else if (!T.isCXX98PODType(Context))
1055 data().PlainOldData = false;
1056
1057 if (T->isReferenceType()) {
1058 if (!Field->hasInClassInitializer())
1059 data().HasUninitializedReferenceMember = true;
1060
1061 // C++0x [class]p7:
1062 // A standard-layout class is a class that:
1063 // -- has no non-static data members of type [...] reference,
1064 data().IsStandardLayout = false;
1065 data().IsCXX11StandardLayout = false;
1066
1067 // C++1z [class.copy.ctor]p10:
1068 // A defaulted copy constructor for a class X is defined as deleted if X has:
1069 // -- a non-static data member of rvalue reference type
1070 if (T->isRValueReferenceType())
1071 data().DefaultedCopyConstructorIsDeleted = true;
1072 }
1073
1074 if (!Field->hasInClassInitializer() && !Field->isMutable()) {
1075 if (CXXRecordDecl *FieldType = T->getAsCXXRecordDecl()) {
1076 if (FieldType->hasDefinition() && !FieldType->allowConstDefaultInit())
1077 data().HasUninitializedFields = true;
1078 } else {
1079 data().HasUninitializedFields = true;
1080 }
1081 }
1082
1083 // Record if this field is the first non-literal or volatile field or base.
1084 if (!T->isLiteralType(Context) || T.isVolatileQualified())
1085 data().HasNonLiteralTypeFieldsOrBases = true;
1086
1087 if (Field->hasInClassInitializer() ||
1088 (Field->isAnonymousStructOrUnion() &&
1089 Field->getType()->getAsCXXRecordDecl()->hasInClassInitializer())) {
1090 data().HasInClassInitializer = true;
1091
1092 // C++11 [class]p5:
1093 // A default constructor is trivial if [...] no non-static data member
1094 // of its class has a brace-or-equal-initializer.
1095 data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor;
1096
1097 // C++11 [dcl.init.aggr]p1:
1098 // An aggregate is a [...] class with [...] no
1099 // brace-or-equal-initializers for non-static data members.
1100 //
1101 // This rule was removed in C++14.
1103 data().Aggregate = false;
1104
1105 // C++11 [class]p10:
1106 // A POD struct is [...] a trivial class.
1107 data().PlainOldData = false;
1108 }
1109
1110 // C++11 [class.copy]p23:
1111 // A defaulted copy/move assignment operator for a class X is defined
1112 // as deleted if X has:
1113 // -- a non-static data member of reference type
1114 if (T->isReferenceType()) {
1115 data().DefaultedCopyAssignmentIsDeleted = true;
1116 data().DefaultedMoveAssignmentIsDeleted = true;
1117 }
1118
1119 // Bitfields of length 0 are also zero-sized, but we already bailed out for
1120 // those because they are always unnamed.
1121 bool IsZeroSize = Field->isZeroSize(Context);
1122
1123 if (const auto *RecordTy = T->getAs<RecordType>()) {
1124 auto *FieldRec = cast<CXXRecordDecl>(RecordTy->getDecl());
1125 if (FieldRec->getDefinition()) {
1126 addedClassSubobject(FieldRec);
1127
1128 // We may need to perform overload resolution to determine whether a
1129 // field can be moved if it's const or volatile qualified.
1131 // We need to care about 'const' for the copy constructor because an
1132 // implicit copy constructor might be declared with a non-const
1133 // parameter.
1134 data().NeedOverloadResolutionForCopyConstructor = true;
1135 data().NeedOverloadResolutionForMoveConstructor = true;
1136 data().NeedOverloadResolutionForCopyAssignment = true;
1137 data().NeedOverloadResolutionForMoveAssignment = true;
1138 }
1139
1140 // C++11 [class.ctor]p5, C++11 [class.copy]p11:
1141 // A defaulted [special member] for a class X is defined as
1142 // deleted if:
1143 // -- X is a union-like class that has a variant member with a
1144 // non-trivial [corresponding special member]
1145 if (isUnion()) {
1146 if (FieldRec->hasNonTrivialCopyConstructor())
1147 data().DefaultedCopyConstructorIsDeleted = true;
1148 if (FieldRec->hasNonTrivialMoveConstructor())
1149 data().DefaultedMoveConstructorIsDeleted = true;
1150 if (FieldRec->hasNonTrivialCopyAssignment())
1151 data().DefaultedCopyAssignmentIsDeleted = true;
1152 if (FieldRec->hasNonTrivialMoveAssignment())
1153 data().DefaultedMoveAssignmentIsDeleted = true;
1154 if (FieldRec->hasNonTrivialDestructor())
1155 data().DefaultedDestructorIsDeleted = true;
1156 }
1157
1158 // For an anonymous union member, our overload resolution will perform
1159 // overload resolution for its members.
1160 if (Field->isAnonymousStructOrUnion()) {
1161 data().NeedOverloadResolutionForCopyConstructor |=
1162 FieldRec->data().NeedOverloadResolutionForCopyConstructor;
1163 data().NeedOverloadResolutionForMoveConstructor |=
1164 FieldRec->data().NeedOverloadResolutionForMoveConstructor;
1165 data().NeedOverloadResolutionForCopyAssignment |=
1166 FieldRec->data().NeedOverloadResolutionForCopyAssignment;
1167 data().NeedOverloadResolutionForMoveAssignment |=
1168 FieldRec->data().NeedOverloadResolutionForMoveAssignment;
1169 data().NeedOverloadResolutionForDestructor |=
1170 FieldRec->data().NeedOverloadResolutionForDestructor;
1171 }
1172
1173 // C++0x [class.ctor]p5:
1174 // A default constructor is trivial [...] if:
1175 // -- for all the non-static data members of its class that are of
1176 // class type (or array thereof), each such class has a trivial
1177 // default constructor.
1178 if (!FieldRec->hasTrivialDefaultConstructor())
1179 data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor;
1180
1181 // C++0x [class.copy]p13:
1182 // A copy/move constructor for class X is trivial if [...]
1183 // [...]
1184 // -- for each non-static data member of X that is of class type (or
1185 // an array thereof), the constructor selected to copy/move that
1186 // member is trivial;
1187 if (!FieldRec->hasTrivialCopyConstructor())
1188 data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor;
1189
1190 if (!FieldRec->hasTrivialCopyConstructorForCall())
1191 data().HasTrivialSpecialMembersForCall &= ~SMF_CopyConstructor;
1192
1193 // If the field doesn't have a simple move constructor, we'll eagerly
1194 // declare the move constructor for this class and we'll decide whether
1195 // it's trivial then.
1196 if (!FieldRec->hasTrivialMoveConstructor())
1197 data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor;
1198
1199 if (!FieldRec->hasTrivialMoveConstructorForCall())
1200 data().HasTrivialSpecialMembersForCall &= ~SMF_MoveConstructor;
1201
1202 // C++0x [class.copy]p27:
1203 // A copy/move assignment operator for class X is trivial if [...]
1204 // [...]
1205 // -- for each non-static data member of X that is of class type (or
1206 // an array thereof), the assignment operator selected to
1207 // copy/move that member is trivial;
1208 if (!FieldRec->hasTrivialCopyAssignment())
1209 data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment;
1210 // If the field doesn't have a simple move assignment, we'll eagerly
1211 // declare the move assignment for this class and we'll decide whether
1212 // it's trivial then.
1213 if (!FieldRec->hasTrivialMoveAssignment())
1214 data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment;
1215
1216 if (!FieldRec->hasTrivialDestructor())
1217 data().HasTrivialSpecialMembers &= ~SMF_Destructor;
1218 if (!FieldRec->hasTrivialDestructorForCall())
1219 data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor;
1220 if (!FieldRec->hasIrrelevantDestructor())
1221 data().HasIrrelevantDestructor = false;
1222 if (FieldRec->isAnyDestructorNoReturn())
1223 data().IsAnyDestructorNoReturn = true;
1224 if (FieldRec->hasObjectMember())
1225 setHasObjectMember(true);
1226 if (FieldRec->hasVolatileMember())
1228 if (FieldRec->getArgPassingRestrictions() ==
1231
1232 // C++0x [class]p7:
1233 // A standard-layout class is a class that:
1234 // -- has no non-static data members of type non-standard-layout
1235 // class (or array of such types) [...]
1236 if (!FieldRec->isStandardLayout())
1237 data().IsStandardLayout = false;
1238 if (!FieldRec->isCXX11StandardLayout())
1239 data().IsCXX11StandardLayout = false;
1240
1241 // C++2a [class]p7:
1242 // A standard-layout class is a class that:
1243 // [...]
1244 // -- has no element of the set M(S) of types as a base class.
1245 if (data().IsStandardLayout &&
1246 (isUnion() || IsFirstField || IsZeroSize) &&
1247 hasSubobjectAtOffsetZeroOfEmptyBaseType(Context, FieldRec))
1248 data().IsStandardLayout = false;
1249
1250 // C++11 [class]p7:
1251 // A standard-layout class is a class that:
1252 // -- has no base classes of the same type as the first non-static
1253 // data member
1254 if (data().IsCXX11StandardLayout && IsFirstField) {
1255 // FIXME: We should check all base classes here, not just direct
1256 // base classes.
1257 for (const auto &BI : bases()) {
1258 if (Context.hasSameUnqualifiedType(BI.getType(), T)) {
1259 data().IsCXX11StandardLayout = false;
1260 break;
1261 }
1262 }
1263 }
1264
1265 // Keep track of the presence of mutable fields.
1266 if (FieldRec->hasMutableFields())
1267 data().HasMutableFields = true;
1268
1269 if (Field->isMutable()) {
1270 // Our copy constructor/assignment might call something other than
1271 // the subobject's copy constructor/assignment if it's mutable and of
1272 // class type.
1273 data().NeedOverloadResolutionForCopyConstructor = true;
1274 data().NeedOverloadResolutionForCopyAssignment = true;
1275 }
1276
1277 // C++11 [class.copy]p13:
1278 // If the implicitly-defined constructor would satisfy the
1279 // requirements of a constexpr constructor, the implicitly-defined
1280 // constructor is constexpr.
1281 // C++11 [dcl.constexpr]p4:
1282 // -- every constructor involved in initializing non-static data
1283 // members [...] shall be a constexpr constructor
1284 if (!Field->hasInClassInitializer() &&
1285 !FieldRec->hasConstexprDefaultConstructor() && !isUnion())
1286 // The standard requires any in-class initializer to be a constant
1287 // expression. We consider this to be a defect.
1288 data().DefaultedDefaultConstructorIsConstexpr = false;
1289
1290 // C++11 [class.copy]p8:
1291 // The implicitly-declared copy constructor for a class X will have
1292 // the form 'X::X(const X&)' if each potentially constructed subobject
1293 // of a class type M (or array thereof) has a copy constructor whose
1294 // first parameter is of type 'const M&' or 'const volatile M&'.
1295 if (!FieldRec->hasCopyConstructorWithConstParam())
1296 data().ImplicitCopyConstructorCanHaveConstParamForNonVBase = false;
1297
1298 // C++11 [class.copy]p18:
1299 // The implicitly-declared copy assignment oeprator for a class X will
1300 // have the form 'X& X::operator=(const X&)' if [...] for all the
1301 // non-static data members of X that are of a class type M (or array
1302 // thereof), each such class type has a copy assignment operator whose
1303 // parameter is of type 'const M&', 'const volatile M&' or 'M'.
1304 if (!FieldRec->hasCopyAssignmentWithConstParam())
1305 data().ImplicitCopyAssignmentHasConstParam = false;
1306
1307 if (FieldRec->hasUninitializedReferenceMember() &&
1308 !Field->hasInClassInitializer())
1309 data().HasUninitializedReferenceMember = true;
1310
1311 // C++11 [class.union]p8, DR1460:
1312 // a non-static data member of an anonymous union that is a member of
1313 // X is also a variant member of X.
1314 if (FieldRec->hasVariantMembers() &&
1315 Field->isAnonymousStructOrUnion())
1316 data().HasVariantMembers = true;
1317 }
1318 } else {
1319 // Base element type of field is a non-class type.
1320 if (!T->isLiteralType(Context) ||
1321 (!Field->hasInClassInitializer() && !isUnion() &&
1322 !Context.getLangOpts().CPlusPlus20))
1323 data().DefaultedDefaultConstructorIsConstexpr = false;
1324
1325 // C++11 [class.copy]p23:
1326 // A defaulted copy/move assignment operator for a class X is defined
1327 // as deleted if X has:
1328 // -- a non-static data member of const non-class type (or array
1329 // thereof)
1330 if (T.isConstQualified()) {
1331 data().DefaultedCopyAssignmentIsDeleted = true;
1332 data().DefaultedMoveAssignmentIsDeleted = true;
1333 }
1334
1335 // C++20 [temp.param]p7:
1336 // A structural type is [...] a literal class type [for which] the
1337 // types of all non-static data members are structural types or
1338 // (possibly multidimensional) array thereof
1339 // We deal with class types elsewhere.
1340 if (!T->isStructuralType())
1341 data().StructuralIfLiteral = false;
1342 }
1343
1344 // C++14 [meta.unary.prop]p4:
1345 // T is a class type [...] with [...] no non-static data members other
1346 // than subobjects of zero size
1347 if (data().Empty && !IsZeroSize)
1348 data().Empty = false;
1349 }
1350
1351 // Handle using declarations of conversion functions.
1352 if (auto *Shadow = dyn_cast<UsingShadowDecl>(D)) {
1353 if (Shadow->getDeclName().getNameKind()
1355 ASTContext &Ctx = getASTContext();
1356 data().Conversions.get(Ctx).addDecl(Ctx, Shadow, Shadow->getAccess());
1357 }
1358 }
1359
1360 if (const auto *Using = dyn_cast<UsingDecl>(D)) {
1361 if (Using->getDeclName().getNameKind() ==
1363 data().HasInheritedConstructor = true;
1364 // C++1z [dcl.init.aggr]p1:
1365 // An aggregate is [...] a class [...] with no inherited constructors
1366 data().Aggregate = false;
1367 }
1368
1369 if (Using->getDeclName().getCXXOverloadedOperator() == OO_Equal)
1370 data().HasInheritedAssignment = true;
1371 }
1372}
1373
1375 DD->setIneligibleOrNotSelected(false);
1376 addedEligibleSpecialMemberFunction(DD, SMF_Destructor);
1377}
1378
1380 unsigned SMKind) {
1381 // FIXME: We shouldn't change DeclaredNonTrivialSpecialMembers if `MD` is
1382 // a function template, but this needs CWG attention before we break ABI.
1383 // See https://github.com/llvm/llvm-project/issues/59206
1384
1385 if (const auto *DD = dyn_cast<CXXDestructorDecl>(MD)) {
1386 if (DD->isUserProvided())
1387 data().HasIrrelevantDestructor = false;
1388 // If the destructor is explicitly defaulted and not trivial or not public
1389 // or if the destructor is deleted, we clear HasIrrelevantDestructor in
1390 // finishedDefaultedOrDeletedMember.
1391
1392 // C++11 [class.dtor]p5:
1393 // A destructor is trivial if [...] the destructor is not virtual.
1394 if (DD->isVirtual()) {
1395 data().HasTrivialSpecialMembers &= ~SMF_Destructor;
1396 data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor;
1397 }
1398
1399 if (DD->isNoReturn())
1400 data().IsAnyDestructorNoReturn = true;
1401 }
1402
1403 if (!MD->isImplicit() && !MD->isUserProvided()) {
1404 // This method is user-declared but not user-provided. We can't work
1405 // out whether it's trivial yet (not until we get to the end of the
1406 // class). We'll handle this method in
1407 // finishedDefaultedOrDeletedMember.
1408 } else if (MD->isTrivial()) {
1409 data().HasTrivialSpecialMembers |= SMKind;
1410 data().HasTrivialSpecialMembersForCall |= SMKind;
1411 } else if (MD->isTrivialForCall()) {
1412 data().HasTrivialSpecialMembersForCall |= SMKind;
1413 data().DeclaredNonTrivialSpecialMembers |= SMKind;
1414 } else {
1415 data().DeclaredNonTrivialSpecialMembers |= SMKind;
1416 // If this is a user-provided function, do not set
1417 // DeclaredNonTrivialSpecialMembersForCall here since we don't know
1418 // yet whether the method would be considered non-trivial for the
1419 // purpose of calls (attribute "trivial_abi" can be dropped from the
1420 // class later, which can change the special method's triviality).
1421 if (!MD->isUserProvided())
1422 data().DeclaredNonTrivialSpecialMembersForCall |= SMKind;
1423 }
1424}
1425
1427 assert(!D->isImplicit() && !D->isUserProvided());
1428
1429 // The kind of special member this declaration is, if any.
1430 unsigned SMKind = 0;
1431
1432 if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(D)) {
1433 if (Constructor->isDefaultConstructor()) {
1434 SMKind |= SMF_DefaultConstructor;
1435 if (Constructor->isConstexpr())
1436 data().HasConstexprDefaultConstructor = true;
1437 }
1438 if (Constructor->isCopyConstructor())
1439 SMKind |= SMF_CopyConstructor;
1440 else if (Constructor->isMoveConstructor())
1441 SMKind |= SMF_MoveConstructor;
1442 else if (Constructor->isConstexpr())
1443 // We may now know that the constructor is constexpr.
1444 data().HasConstexprNonCopyMoveConstructor = true;
1445 } else if (isa<CXXDestructorDecl>(D)) {
1446 SMKind |= SMF_Destructor;
1447 if (!D->isTrivial() || D->getAccess() != AS_public || D->isDeleted())
1448 data().HasIrrelevantDestructor = false;
1449 } else if (D->isCopyAssignmentOperator())
1450 SMKind |= SMF_CopyAssignment;
1451 else if (D->isMoveAssignmentOperator())
1452 SMKind |= SMF_MoveAssignment;
1453
1454 // Update which trivial / non-trivial special members we have.
1455 // addedMember will have skipped this step for this member.
1456 if (!D->isIneligibleOrNotSelected()) {
1457 if (D->isTrivial())
1458 data().HasTrivialSpecialMembers |= SMKind;
1459 else
1460 data().DeclaredNonTrivialSpecialMembers |= SMKind;
1461 }
1462}
1463
1464void CXXRecordDecl::LambdaDefinitionData::AddCaptureList(ASTContext &Ctx,
1465 Capture *CaptureList) {
1466 Captures.push_back(CaptureList);
1467 if (Captures.size() == 2) {
1468 // The TinyPtrVector member now needs destruction.
1469 Ctx.addDestruction(&Captures);
1470 }
1471}
1472
1474 ArrayRef<LambdaCapture> Captures) {
1475 CXXRecordDecl::LambdaDefinitionData &Data = getLambdaData();
1476
1477 // Copy captures.
1478 Data.NumCaptures = Captures.size();
1479 Data.NumExplicitCaptures = 0;
1480 auto *ToCapture = (LambdaCapture *)Context.Allocate(sizeof(LambdaCapture) *
1481 Captures.size());
1482 Data.AddCaptureList(Context, ToCapture);
1483 for (unsigned I = 0, N = Captures.size(); I != N; ++I) {
1484 if (Captures[I].isExplicit())
1485 ++Data.NumExplicitCaptures;
1486
1487 *ToCapture++ = Captures[I];
1488 }
1489
1491 Data.DefaultedCopyAssignmentIsDeleted = true;
1492}
1493
1495 unsigned SMKind = 0;
1496
1497 if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(D)) {
1498 if (Constructor->isCopyConstructor())
1499 SMKind = SMF_CopyConstructor;
1500 else if (Constructor->isMoveConstructor())
1501 SMKind = SMF_MoveConstructor;
1502 } else if (isa<CXXDestructorDecl>(D))
1503 SMKind = SMF_Destructor;
1504
1505 if (D->isTrivialForCall())
1506 data().HasTrivialSpecialMembersForCall |= SMKind;
1507 else
1508 data().DeclaredNonTrivialSpecialMembersForCall |= SMKind;
1509}
1510
1512 if (getTagKind() == TTK_Class || getTagKind() == TTK_Interface ||
1513 !TemplateOrInstantiation.isNull())
1514 return false;
1515 if (!hasDefinition())
1516 return true;
1517
1518 return isPOD() && data().HasOnlyCMembers;
1519}
1520
1522 if (!isLambda()) return false;
1523 return getLambdaData().IsGenericLambda;
1524}
1525
1526#ifndef NDEBUG
1528 for (auto *D : R)
1529 if (!declaresSameEntity(D, R.front()))
1530 return false;
1531 return true;
1532}
1533#endif
1534
1536 if (!RD.isLambda()) return nullptr;
1537 DeclarationName Name =
1539 DeclContext::lookup_result Calls = RD.lookup(Name);
1540
1541 assert(!Calls.empty() && "Missing lambda call operator!");
1542 assert(allLookupResultsAreTheSame(Calls) &&
1543 "More than one lambda call operator!");
1544 return Calls.front();
1545}
1546
1548 NamedDecl *CallOp = getLambdaCallOperatorHelper(*this);
1549 return dyn_cast_or_null<FunctionTemplateDecl>(CallOp);
1550}
1551
1553 NamedDecl *CallOp = getLambdaCallOperatorHelper(*this);
1554
1555 if (CallOp == nullptr)
1556 return nullptr;
1557
1558 if (const auto *CallOpTmpl = dyn_cast<FunctionTemplateDecl>(CallOp))
1559 return cast<CXXMethodDecl>(CallOpTmpl->getTemplatedDecl());
1560
1561 return cast<CXXMethodDecl>(CallOp);
1562}
1563
1566 CallingConv CC = CallOp->getType()->castAs<FunctionType>()->getCallConv();
1567 return getLambdaStaticInvoker(CC);
1568}
1569
1572 assert(RD.isLambda() && "Must be a lambda");
1573 DeclarationName Name =
1575 return RD.lookup(Name);
1576}
1577
1579 if (const auto *InvokerTemplate = dyn_cast<FunctionTemplateDecl>(ND))
1580 return cast<CXXMethodDecl>(InvokerTemplate->getTemplatedDecl());
1581 return cast<CXXMethodDecl>(ND);
1582}
1583
1585 if (!isLambda())
1586 return nullptr;
1588
1589 for (NamedDecl *ND : Invoker) {
1590 const auto *FTy =
1591 cast<ValueDecl>(ND->getAsFunction())->getType()->castAs<FunctionType>();
1592 if (FTy->getCallConv() == CC)
1593 return getInvokerAsMethod(ND);
1594 }
1595
1596 return nullptr;
1597}
1598
1600 llvm::DenseMap<const ValueDecl *, FieldDecl *> &Captures,
1601 FieldDecl *&ThisCapture) const {
1602 Captures.clear();
1603 ThisCapture = nullptr;
1604
1605 LambdaDefinitionData &Lambda = getLambdaData();
1606 for (const LambdaCapture *List : Lambda.Captures) {
1608 for (const LambdaCapture *C = List, *CEnd = C + Lambda.NumCaptures;
1609 C != CEnd; ++C, ++Field) {
1610 if (C->capturesThis())
1611 ThisCapture = *Field;
1612 else if (C->capturesVariable())
1613 Captures[C->getCapturedVar()] = *Field;
1614 }
1615 assert(Field == field_end());
1616 }
1617}
1618
1621 if (!isGenericLambda()) return nullptr;
1624 return Tmpl->getTemplateParameters();
1625 return nullptr;
1626}
1627
1631 if (!List)
1632 return {};
1633
1634 assert(std::is_partitioned(List->begin(), List->end(),
1635 [](const NamedDecl *D) { return !D->isImplicit(); })
1636 && "Explicit template params should be ordered before implicit ones");
1637
1638 const auto ExplicitEnd = llvm::partition_point(
1639 *List, [](const NamedDecl *D) { return !D->isImplicit(); });
1640 return llvm::ArrayRef(List->begin(), ExplicitEnd);
1641}
1642
1644 assert(isLambda() && "Not a lambda closure type!");
1646 return getLambdaData().ContextDecl.get(Source);
1647}
1648
1650 assert(isLambda() && "Not a lambda closure type!");
1651 getLambdaData().ManglingNumber = Numbering.ManglingNumber;
1652 if (Numbering.DeviceManglingNumber)
1653 getASTContext().DeviceLambdaManglingNumbers[this] =
1654 Numbering.DeviceManglingNumber;
1655 getLambdaData().IndexInContext = Numbering.IndexInContext;
1656 getLambdaData().ContextDecl = Numbering.ContextDecl;
1657 getLambdaData().HasKnownInternalLinkage = Numbering.HasKnownInternalLinkage;
1658}
1659
1661 assert(isLambda() && "Not a lambda closure type!");
1662 return getASTContext().DeviceLambdaManglingNumbers.lookup(this);
1663}
1664
1666 QualType T =
1667 cast<CXXConversionDecl>(Conv->getUnderlyingDecl()->getAsFunction())
1668 ->getConversionType();
1669 return Context.getCanonicalType(T);
1670}
1671
1672/// Collect the visible conversions of a base class.
1673///
1674/// \param Record a base class of the class we're considering
1675/// \param InVirtual whether this base class is a virtual base (or a base
1676/// of a virtual base)
1677/// \param Access the access along the inheritance path to this base
1678/// \param ParentHiddenTypes the conversions provided by the inheritors
1679/// of this base
1680/// \param Output the set to which to add conversions from non-virtual bases
1681/// \param VOutput the set to which to add conversions from virtual bases
1682/// \param HiddenVBaseCs the set of conversions which were hidden in a
1683/// virtual base along some inheritance path
1685 ASTContext &Context, const CXXRecordDecl *Record, bool InVirtual,
1686 AccessSpecifier Access,
1687 const llvm::SmallPtrSet<CanQualType, 8> &ParentHiddenTypes,
1688 ASTUnresolvedSet &Output, UnresolvedSetImpl &VOutput,
1689 llvm::SmallPtrSet<NamedDecl *, 8> &HiddenVBaseCs) {
1690 // The set of types which have conversions in this class or its
1691 // subclasses. As an optimization, we don't copy the derived set
1692 // unless it might change.
1693 const llvm::SmallPtrSet<CanQualType, 8> *HiddenTypes = &ParentHiddenTypes;
1694 llvm::SmallPtrSet<CanQualType, 8> HiddenTypesBuffer;
1695
1696 // Collect the direct conversions and figure out which conversions
1697 // will be hidden in the subclasses.
1698 CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin();
1699 CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end();
1700 if (ConvI != ConvE) {
1701 HiddenTypesBuffer = ParentHiddenTypes;
1702 HiddenTypes = &HiddenTypesBuffer;
1703
1704 for (CXXRecordDecl::conversion_iterator I = ConvI; I != ConvE; ++I) {
1705 CanQualType ConvType(GetConversionType(Context, I.getDecl()));
1706 bool Hidden = ParentHiddenTypes.count(ConvType);
1707 if (!Hidden)
1708 HiddenTypesBuffer.insert(ConvType);
1709
1710 // If this conversion is hidden and we're in a virtual base,
1711 // remember that it's hidden along some inheritance path.
1712 if (Hidden && InVirtual)
1713 HiddenVBaseCs.insert(cast<NamedDecl>(I.getDecl()->getCanonicalDecl()));
1714
1715 // If this conversion isn't hidden, add it to the appropriate output.
1716 else if (!Hidden) {
1717 AccessSpecifier IAccess
1718 = CXXRecordDecl::MergeAccess(Access, I.getAccess());
1719
1720 if (InVirtual)
1721 VOutput.addDecl(I.getDecl(), IAccess);
1722 else
1723 Output.addDecl(Context, I.getDecl(), IAccess);
1724 }
1725 }
1726 }
1727
1728 // Collect information recursively from any base classes.
1729 for (const auto &I : Record->bases()) {
1730 const auto *RT = I.getType()->getAs<RecordType>();
1731 if (!RT) continue;
1732
1733 AccessSpecifier BaseAccess
1734 = CXXRecordDecl::MergeAccess(Access, I.getAccessSpecifier());
1735 bool BaseInVirtual = InVirtual || I.isVirtual();
1736
1737 auto *Base = cast<CXXRecordDecl>(RT->getDecl());
1738 CollectVisibleConversions(Context, Base, BaseInVirtual, BaseAccess,
1739 *HiddenTypes, Output, VOutput, HiddenVBaseCs);
1740 }
1741}
1742
1743/// Collect the visible conversions of a class.
1744///
1745/// This would be extremely straightforward if it weren't for virtual
1746/// bases. It might be worth special-casing that, really.
1748 const CXXRecordDecl *Record,
1749 ASTUnresolvedSet &Output) {
1750 // The collection of all conversions in virtual bases that we've
1751 // found. These will be added to the output as long as they don't
1752 // appear in the hidden-conversions set.
1753 UnresolvedSet<8> VBaseCs;
1754
1755 // The set of conversions in virtual bases that we've determined to
1756 // be hidden.
1758
1759 // The set of types hidden by classes derived from this one.
1761
1762 // Go ahead and collect the direct conversions and add them to the
1763 // hidden-types set.
1764 CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin();
1765 CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end();
1766 Output.append(Context, ConvI, ConvE);
1767 for (; ConvI != ConvE; ++ConvI)
1768 HiddenTypes.insert(GetConversionType(Context, ConvI.getDecl()));
1769
1770 // Recursively collect conversions from base classes.
1771 for (const auto &I : Record->bases()) {
1772 const auto *RT = I.getType()->getAs<RecordType>();
1773 if (!RT) continue;
1774
1775 CollectVisibleConversions(Context, cast<CXXRecordDecl>(RT->getDecl()),
1776 I.isVirtual(), I.getAccessSpecifier(),
1777 HiddenTypes, Output, VBaseCs, HiddenVBaseCs);
1778 }
1779
1780 // Add any unhidden conversions provided by virtual bases.
1781 for (UnresolvedSetIterator I = VBaseCs.begin(), E = VBaseCs.end();
1782 I != E; ++I) {
1783 if (!HiddenVBaseCs.count(cast<NamedDecl>(I.getDecl()->getCanonicalDecl())))
1784 Output.addDecl(Context, I.getDecl(), I.getAccess());
1785 }
1786}
1787
1788/// getVisibleConversionFunctions - get all conversion functions visible
1789/// in current class; including conversion function templates.
1790llvm::iterator_range<CXXRecordDecl::conversion_iterator>
1792 ASTContext &Ctx = getASTContext();
1793
1794 ASTUnresolvedSet *Set;
1795 if (bases_begin() == bases_end()) {
1796 // If root class, all conversions are visible.
1797 Set = &data().Conversions.get(Ctx);
1798 } else {
1799 Set = &data().VisibleConversions.get(Ctx);
1800 // If visible conversion list is not evaluated, evaluate it.
1801 if (!data().ComputedVisibleConversions) {
1802 CollectVisibleConversions(Ctx, this, *Set);
1803 data().ComputedVisibleConversions = true;
1804 }
1805 }
1806 return llvm::make_range(Set->begin(), Set->end());
1807}
1808
1810 // This operation is O(N) but extremely rare. Sema only uses it to
1811 // remove UsingShadowDecls in a class that were followed by a direct
1812 // declaration, e.g.:
1813 // class A : B {
1814 // using B::operator int;
1815 // operator int();
1816 // };
1817 // This is uncommon by itself and even more uncommon in conjunction
1818 // with sufficiently large numbers of directly-declared conversions
1819 // that asymptotic behavior matters.
1820
1821 ASTUnresolvedSet &Convs = data().Conversions.get(getASTContext());
1822 for (unsigned I = 0, E = Convs.size(); I != E; ++I) {
1823 if (Convs[I].getDecl() == ConvDecl) {
1824 Convs.erase(I);
1825 assert(!llvm::is_contained(Convs, ConvDecl) &&
1826 "conversion was found multiple times in unresolved set");
1827 return;
1828 }
1829 }
1830
1831 llvm_unreachable("conversion not found in set!");
1832}
1833
1836 return cast<CXXRecordDecl>(MSInfo->getInstantiatedFrom());
1837
1838 return nullptr;
1839}
1840
1842 return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>();
1843}
1844
1845void
1848 assert(TemplateOrInstantiation.isNull() &&
1849 "Previous template or instantiation?");
1850 assert(!isa<ClassTemplatePartialSpecializationDecl>(this));
1851 TemplateOrInstantiation
1852 = new (getASTContext()) MemberSpecializationInfo(RD, TSK);
1853}
1854
1856 return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl *>();
1857}
1858
1860 TemplateOrInstantiation = Template;
1861}
1862
1864 if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(this))
1865 return Spec->getSpecializationKind();
1866
1868 return MSInfo->getTemplateSpecializationKind();
1869
1870 return TSK_Undeclared;
1871}
1872
1873void
1875 if (auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(this)) {
1876 Spec->setSpecializationKind(TSK);
1877 return;
1878 }
1879
1881 MSInfo->setTemplateSpecializationKind(TSK);
1882 return;
1883 }
1884
1885 llvm_unreachable("Not a class template or member class specialization");
1886}
1887
1889 auto GetDefinitionOrSelf =
1890 [](const CXXRecordDecl *D) -> const CXXRecordDecl * {
1891 if (auto *Def = D->getDefinition())
1892 return Def;
1893 return D;
1894 };
1895
1896 // If it's a class template specialization, find the template or partial
1897 // specialization from which it was instantiated.
1898 if (auto *TD = dyn_cast<ClassTemplateSpecializationDecl>(this)) {
1899 auto From = TD->getInstantiatedFrom();
1900 if (auto *CTD = From.dyn_cast<ClassTemplateDecl *>()) {
1901 while (auto *NewCTD = CTD->getInstantiatedFromMemberTemplate()) {
1902 if (NewCTD->isMemberSpecialization())
1903 break;
1904 CTD = NewCTD;
1905 }
1906 return GetDefinitionOrSelf(CTD->getTemplatedDecl());
1907 }
1908 if (auto *CTPSD =
1909 From.dyn_cast<ClassTemplatePartialSpecializationDecl *>()) {
1910 while (auto *NewCTPSD = CTPSD->getInstantiatedFromMember()) {
1911 if (NewCTPSD->isMemberSpecialization())
1912 break;
1913 CTPSD = NewCTPSD;
1914 }
1915 return GetDefinitionOrSelf(CTPSD);
1916 }
1917 }
1918
1920 if (isTemplateInstantiation(MSInfo->getTemplateSpecializationKind())) {
1921 const CXXRecordDecl *RD = this;
1922 while (auto *NewRD = RD->getInstantiatedFromMemberClass())
1923 RD = NewRD;
1924 return GetDefinitionOrSelf(RD);
1925 }
1926 }
1927
1929 "couldn't find pattern for class template instantiation");
1930 return nullptr;
1931}
1932
1934 ASTContext &Context = getASTContext();
1935 QualType ClassType = Context.getTypeDeclType(this);
1936
1937 DeclarationName Name
1939 Context.getCanonicalType(ClassType));
1940
1942
1943 // If a destructor was marked as not selected, we skip it. We don't always
1944 // have a selected destructor: dependent types, unnamed structs.
1945 for (auto *Decl : R) {
1946 auto* DD = dyn_cast<CXXDestructorDecl>(Decl);
1947 if (DD && !DD->isIneligibleOrNotSelected())
1948 return DD;
1949 }
1950 return nullptr;
1951}
1952
1954 while (!DC->isTranslationUnit()) {
1955 if (DC->isNamespace())
1956 return true;
1957 DC = DC->getParent();
1958 }
1959 return false;
1960}
1961
1963 assert(hasDefinition() && "checking for interface-like without a definition");
1964 // All __interfaces are inheritently interface-like.
1965 if (isInterface())
1966 return true;
1967
1968 // Interface-like types cannot have a user declared constructor, destructor,
1969 // friends, VBases, conversion functions, or fields. Additionally, lambdas
1970 // cannot be interface types.
1973 getNumVBases() > 0 || conversion_end() - conversion_begin() > 0)
1974 return false;
1975
1976 // No interface-like type can have a method with a definition.
1977 for (const auto *const Method : methods())
1978 if (Method->isDefined() && !Method->isImplicit())
1979 return false;
1980
1981 // Check "Special" types.
1982 const auto *Uuid = getAttr<UuidAttr>();
1983 // MS SDK declares IUnknown/IDispatch both in the root of a TU, or in an
1984 // extern C++ block directly in the TU. These are only valid if in one
1985 // of these two situations.
1986 if (Uuid && isStruct() && !getDeclContext()->isExternCContext() &&
1988 ((getName() == "IUnknown" &&
1989 Uuid->getGuid() == "00000000-0000-0000-C000-000000000046") ||
1990 (getName() == "IDispatch" &&
1991 Uuid->getGuid() == "00020400-0000-0000-C000-000000000046"))) {
1992 if (getNumBases() > 0)
1993 return false;
1994 return true;
1995 }
1996
1997 // FIXME: Any access specifiers is supposed to make this no longer interface
1998 // like.
1999
2000 // If this isn't a 'special' type, it must have a single interface-like base.
2001 if (getNumBases() != 1)
2002 return false;
2003
2004 const auto BaseSpec = *bases_begin();
2005 if (BaseSpec.isVirtual() || BaseSpec.getAccessSpecifier() != AS_public)
2006 return false;
2007 const auto *Base = BaseSpec.getType()->getAsCXXRecordDecl();
2008 if (Base->isInterface() || !Base->isInterfaceLike())
2009 return false;
2010 return true;
2011}
2012
2014 completeDefinition(nullptr);
2015}
2016
2019
2020 // If the class may be abstract (but hasn't been marked as such), check for
2021 // any pure final overriders.
2022 if (mayBeAbstract()) {
2023 CXXFinalOverriderMap MyFinalOverriders;
2024 if (!FinalOverriders) {
2025 getFinalOverriders(MyFinalOverriders);
2026 FinalOverriders = &MyFinalOverriders;
2027 }
2028
2029 bool Done = false;
2030 for (CXXFinalOverriderMap::iterator M = FinalOverriders->begin(),
2031 MEnd = FinalOverriders->end();
2032 M != MEnd && !Done; ++M) {
2033 for (OverridingMethods::iterator SO = M->second.begin(),
2034 SOEnd = M->second.end();
2035 SO != SOEnd && !Done; ++SO) {
2036 assert(SO->second.size() > 0 &&
2037 "All virtual functions have overriding virtual functions");
2038
2039 // C++ [class.abstract]p4:
2040 // A class is abstract if it contains or inherits at least one
2041 // pure virtual function for which the final overrider is pure
2042 // virtual.
2043 if (SO->second.front().Method->isPure()) {
2044 data().Abstract = true;
2045 Done = true;
2046 break;
2047 }
2048 }
2049 }
2050 }
2051
2052 // Set access bits correctly on the directly-declared conversions.
2054 I != E; ++I)
2055 I.setAccess((*I)->getAccess());
2056}
2057
2059 if (data().Abstract || isInvalidDecl() || !data().Polymorphic ||
2061 return false;
2062
2063 for (const auto &B : bases()) {
2064 const auto *BaseDecl =
2065 cast<CXXRecordDecl>(B.getType()->castAs<RecordType>()->getDecl());
2066 if (BaseDecl->isAbstract())
2067 return true;
2068 }
2069
2070 return false;
2071}
2072
2074 auto *Def = getDefinition();
2075 if (!Def)
2076 return false;
2077 if (Def->hasAttr<FinalAttr>())
2078 return true;
2079 if (const auto *Dtor = Def->getDestructor())
2080 if (Dtor->hasAttr<FinalAttr>())
2081 return true;
2082 return false;
2083}
2084
2085void CXXDeductionGuideDecl::anchor() {}
2086
2088 if ((getKind() != Other.getKind() ||
2091 Other.getKind() == ExplicitSpecKind::Unresolved) {
2092 ODRHash SelfHash, OtherHash;
2093 SelfHash.AddStmt(getExpr());
2094 OtherHash.AddStmt(Other.getExpr());
2095 return SelfHash.CalculateHash() == OtherHash.CalculateHash();
2096 } else
2097 return false;
2098 }
2099 return true;
2100}
2101
2103 switch (Function->getDeclKind()) {
2104 case Decl::Kind::CXXConstructor:
2105 return cast<CXXConstructorDecl>(Function)->getExplicitSpecifier();
2106 case Decl::Kind::CXXConversion:
2107 return cast<CXXConversionDecl>(Function)->getExplicitSpecifier();
2108 case Decl::Kind::CXXDeductionGuide:
2109 return cast<CXXDeductionGuideDecl>(Function)->getExplicitSpecifier();
2110 default:
2111 return {};
2112 }
2113}
2114
2116 ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
2117 ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T,
2118 TypeSourceInfo *TInfo, SourceLocation EndLocation, CXXConstructorDecl *Ctor,
2119 DeductionCandidate Kind) {
2120 return new (C, DC) CXXDeductionGuideDecl(C, DC, StartLoc, ES, NameInfo, T,
2121 TInfo, EndLocation, Ctor, Kind);
2122}
2123
2125 unsigned ID) {
2126 return new (C, ID) CXXDeductionGuideDecl(
2128 QualType(), nullptr, SourceLocation(), nullptr,
2130}
2131
2133 ASTContext &C, DeclContext *DC, SourceLocation StartLoc) {
2134 return new (C, DC) RequiresExprBodyDecl(C, DC, StartLoc);
2135}
2136
2138 unsigned ID) {
2139 return new (C, ID) RequiresExprBodyDecl(C, nullptr, SourceLocation());
2140}
2141
2142void CXXMethodDecl::anchor() {}
2143
2145 const CXXMethodDecl *MD = getCanonicalDecl();
2146
2147 if (MD->getStorageClass() == SC_Static)
2148 return true;
2149
2151 return isStaticOverloadedOperator(OOK);
2152}
2153
2154static bool recursivelyOverrides(const CXXMethodDecl *DerivedMD,
2155 const CXXMethodDecl *BaseMD) {
2156 for (const CXXMethodDecl *MD : DerivedMD->overridden_methods()) {
2157 if (MD->getCanonicalDecl() == BaseMD->getCanonicalDecl())
2158 return true;
2159 if (recursivelyOverrides(MD, BaseMD))
2160 return true;
2161 }
2162 return false;
2163}
2164
2167 bool MayBeBase) {
2168 if (this->getParent()->getCanonicalDecl() == RD->getCanonicalDecl())
2169 return this;
2170
2171 // Lookup doesn't work for destructors, so handle them separately.
2172 if (isa<CXXDestructorDecl>(this)) {
2173 CXXMethodDecl *MD = RD->getDestructor();
2174 if (MD) {
2175 if (recursivelyOverrides(MD, this))
2176 return MD;
2177 if (MayBeBase && recursivelyOverrides(this, MD))
2178 return MD;
2179 }
2180 return nullptr;
2181 }
2182
2183 for (auto *ND : RD->lookup(getDeclName())) {
2184 auto *MD = dyn_cast<CXXMethodDecl>(ND);
2185 if (!MD)
2186 continue;
2187 if (recursivelyOverrides(MD, this))
2188 return MD;
2189 if (MayBeBase && recursivelyOverrides(this, MD))
2190 return MD;
2191 }
2192
2193 return nullptr;
2194}
2195
2198 bool MayBeBase) {
2199 if (auto *MD = getCorrespondingMethodDeclaredInClass(RD, MayBeBase))
2200 return MD;
2201
2203 auto AddFinalOverrider = [&](CXXMethodDecl *D) {
2204 // If this function is overridden by a candidate final overrider, it is not
2205 // a final overrider.
2206 for (CXXMethodDecl *OtherD : FinalOverriders) {
2207 if (declaresSameEntity(D, OtherD) || recursivelyOverrides(OtherD, D))
2208 return;
2209 }
2210
2211 // Other candidate final overriders might be overridden by this function.
2212 llvm::erase_if(FinalOverriders, [&](CXXMethodDecl *OtherD) {
2213 return recursivelyOverrides(D, OtherD);
2214 });
2215
2216 FinalOverriders.push_back(D);
2217 };
2218
2219 for (const auto &I : RD->bases()) {
2220 const RecordType *RT = I.getType()->getAs<RecordType>();
2221 if (!RT)
2222 continue;
2223 const auto *Base = cast<CXXRecordDecl>(RT->getDecl());
2224 if (CXXMethodDecl *D = this->getCorrespondingMethodInClass(Base))
2225 AddFinalOverrider(D);
2226 }
2227
2228 return FinalOverriders.size() == 1 ? FinalOverriders.front() : nullptr;
2229}
2230
2233 const DeclarationNameInfo &NameInfo, QualType T,
2234 TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin,
2235 bool isInline, ConstexprSpecKind ConstexprKind,
2236 SourceLocation EndLocation,
2237 Expr *TrailingRequiresClause) {
2238 return new (C, RD) CXXMethodDecl(
2239 CXXMethod, C, RD, StartLoc, NameInfo, T, TInfo, SC, UsesFPIntrin,
2240 isInline, ConstexprKind, EndLocation, TrailingRequiresClause);
2241}
2242
2244 return new (C, ID) CXXMethodDecl(
2245 CXXMethod, C, nullptr, SourceLocation(), DeclarationNameInfo(),
2246 QualType(), nullptr, SC_None, false, false,
2248}
2249
2251 bool IsAppleKext) {
2252 assert(isVirtual() && "this method is expected to be virtual");
2253
2254 // When building with -fapple-kext, all calls must go through the vtable since
2255 // the kernel linker can do runtime patching of vtables.
2256 if (IsAppleKext)
2257 return nullptr;
2258
2259 // If the member function is marked 'final', we know that it can't be
2260 // overridden and can therefore devirtualize it unless it's pure virtual.
2261 if (hasAttr<FinalAttr>())
2262 return isPure() ? nullptr : this;
2263
2264 // If Base is unknown, we cannot devirtualize.
2265 if (!Base)
2266 return nullptr;
2267
2268 // If the base expression (after skipping derived-to-base conversions) is a
2269 // class prvalue, then we can devirtualize.
2270 Base = Base->getBestDynamicClassTypeExpr();
2271 if (Base->isPRValue() && Base->getType()->isRecordType())
2272 return this;
2273
2274 // If we don't even know what we would call, we can't devirtualize.
2275 const CXXRecordDecl *BestDynamicDecl = Base->getBestDynamicClassType();
2276 if (!BestDynamicDecl)
2277 return nullptr;
2278
2279 // There may be a method corresponding to MD in a derived class.
2280 CXXMethodDecl *DevirtualizedMethod =
2281 getCorrespondingMethodInClass(BestDynamicDecl);
2282
2283 // If there final overrider in the dynamic type is ambiguous, we can't
2284 // devirtualize this call.
2285 if (!DevirtualizedMethod)
2286 return nullptr;
2287
2288 // If that method is pure virtual, we can't devirtualize. If this code is
2289 // reached, the result would be UB, not a direct call to the derived class
2290 // function, and we can't assume the derived class function is defined.
2291 if (DevirtualizedMethod->isPure())
2292 return nullptr;
2293
2294 // If that method is marked final, we can devirtualize it.
2295 if (DevirtualizedMethod->hasAttr<FinalAttr>())
2296 return DevirtualizedMethod;
2297
2298 // Similarly, if the class itself or its destructor is marked 'final',
2299 // the class can't be derived from and we can therefore devirtualize the
2300 // member function call.
2301 if (BestDynamicDecl->isEffectivelyFinal())
2302 return DevirtualizedMethod;
2303
2304 if (const auto *DRE = dyn_cast<DeclRefExpr>(Base)) {
2305 if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl()))
2306 if (VD->getType()->isRecordType())
2307 // This is a record decl. We know the type and can devirtualize it.
2308 return DevirtualizedMethod;
2309
2310 return nullptr;
2311 }
2312
2313 // We can devirtualize calls on an object accessed by a class member access
2314 // expression, since by C++11 [basic.life]p6 we know that it can't refer to
2315 // a derived class object constructed in the same location.
2316 if (const auto *ME = dyn_cast<MemberExpr>(Base)) {
2317 const ValueDecl *VD = ME->getMemberDecl();
2318 return VD->getType()->isRecordType() ? DevirtualizedMethod : nullptr;
2319 }
2320
2321 // Likewise for calls on an object accessed by a (non-reference) pointer to
2322 // member access.
2323 if (auto *BO = dyn_cast<BinaryOperator>(Base)) {
2324 if (BO->isPtrMemOp()) {
2325 auto *MPT = BO->getRHS()->getType()->castAs<MemberPointerType>();
2326 if (MPT->getPointeeType()->isRecordType())
2327 return DevirtualizedMethod;
2328 }
2329 }
2330
2331 // We can't devirtualize the call.
2332 return nullptr;
2333}
2334
2336 SmallVectorImpl<const FunctionDecl *> &PreventedBy) const {
2337 assert(PreventedBy.empty() && "PreventedBy is expected to be empty");
2338 if (getOverloadedOperator() != OO_Delete &&
2339 getOverloadedOperator() != OO_Array_Delete)
2340 return false;
2341
2342 // C++ [basic.stc.dynamic.deallocation]p2:
2343 // A template instance is never a usual deallocation function,
2344 // regardless of its signature.
2345 if (getPrimaryTemplate())
2346 return false;
2347
2348 // C++ [basic.stc.dynamic.deallocation]p2:
2349 // If a class T has a member deallocation function named operator delete
2350 // with exactly one parameter, then that function is a usual (non-placement)
2351 // deallocation function. [...]
2352 if (getNumParams() == 1)
2353 return true;
2354 unsigned UsualParams = 1;
2355
2356 // C++ P0722:
2357 // A destroying operator delete is a usual deallocation function if
2358 // removing the std::destroying_delete_t parameter and changing the
2359 // first parameter type from T* to void* results in the signature of
2360 // a usual deallocation function.
2362 ++UsualParams;
2363
2364 // C++ <=14 [basic.stc.dynamic.deallocation]p2:
2365 // [...] If class T does not declare such an operator delete but does
2366 // declare a member deallocation function named operator delete with
2367 // exactly two parameters, the second of which has type std::size_t (18.1),
2368 // then this function is a usual deallocation function.
2369 //
2370 // C++17 says a usual deallocation function is one with the signature
2371 // (void* [, size_t] [, std::align_val_t] [, ...])
2372 // and all such functions are usual deallocation functions. It's not clear
2373 // that allowing varargs functions was intentional.
2374 ASTContext &Context = getASTContext();
2375 if (UsualParams < getNumParams() &&
2376 Context.hasSameUnqualifiedType(getParamDecl(UsualParams)->getType(),
2377 Context.getSizeType()))
2378 ++UsualParams;
2379
2380 if (UsualParams < getNumParams() &&
2381 getParamDecl(UsualParams)->getType()->isAlignValT())
2382 ++UsualParams;
2383
2384 if (UsualParams != getNumParams())
2385 return false;
2386
2387 // In C++17 onwards, all potential usual deallocation functions are actual
2388 // usual deallocation functions. Honor this behavior when post-C++14
2389 // deallocation functions are offered as extensions too.
2390 // FIXME(EricWF): Destroying Delete should be a language option. How do we
2391 // handle when destroying delete is used prior to C++17?
2392 if (Context.getLangOpts().CPlusPlus17 ||
2393 Context.getLangOpts().AlignedAllocation ||
2395 return true;
2396
2397 // This function is a usual deallocation function if there are no
2398 // single-parameter deallocation functions of the same kind.
2400 bool Result = true;
2401 for (const auto *D : R) {
2402 if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
2403 if (FD->getNumParams() == 1) {
2404 PreventedBy.push_back(FD);
2405 Result = false;
2406 }
2407 }
2408 }
2409 return Result;
2410}
2411
2413 // C++0x [class.copy]p17:
2414 // A user-declared copy assignment operator X::operator= is a non-static
2415 // non-template member function of class X with exactly one parameter of
2416 // type X, X&, const X&, volatile X& or const volatile X&.
2417 if (/*operator=*/getOverloadedOperator() != OO_Equal ||
2418 /*non-static*/ isStatic() ||
2419 /*non-template*/getPrimaryTemplate() || getDescribedFunctionTemplate() ||
2420 getNumParams() != 1)
2421 return false;
2422
2423 QualType ParamType = getParamDecl(0)->getType();
2424 if (const auto *Ref = ParamType->getAs<LValueReferenceType>())
2425 ParamType = Ref->getPointeeType();
2426
2427 ASTContext &Context = getASTContext();
2428 QualType ClassType
2429 = Context.getCanonicalType(Context.getTypeDeclType(getParent()));
2430 return Context.hasSameUnqualifiedType(ClassType, ParamType);
2431}
2432
2434 // C++0x [class.copy]p19:
2435 // A user-declared move assignment operator X::operator= is a non-static
2436 // non-template member function of class X with exactly one parameter of type
2437 // X&&, const X&&, volatile X&&, or const volatile X&&.
2438 if (getOverloadedOperator() != OO_Equal || isStatic() ||
2440 getNumParams() != 1)
2441 return false;
2442
2443 QualType ParamType = getParamDecl(0)->getType();
2444 if (!ParamType->isRValueReferenceType())
2445 return false;
2446 ParamType = ParamType->getPointeeType();
2447
2448 ASTContext &Context = getASTContext();
2449 QualType ClassType
2450 = Context.getCanonicalType(Context.getTypeDeclType(getParent()));
2451 return Context.hasSameUnqualifiedType(ClassType, ParamType);
2452}
2453
2455 assert(MD->isCanonicalDecl() && "Method is not canonical!");
2456 assert(!MD->getParent()->isDependentContext() &&
2457 "Can't add an overridden method to a class template!");
2458 assert(MD->isVirtual() && "Method is not virtual!");
2459
2461}
2462
2464 if (isa<CXXConstructorDecl>(this)) return nullptr;
2466}
2467
2469 if (isa<CXXConstructorDecl>(this)) return nullptr;
2471}
2472
2474 if (isa<CXXConstructorDecl>(this)) return 0;
2476}
2477
2480 if (isa<CXXConstructorDecl>(this))
2481 return overridden_method_range(nullptr, nullptr);
2482 return getASTContext().overridden_methods(this);
2483}
2484
2486 const CXXRecordDecl *Decl) {
2487 QualType ClassTy = C.getTypeDeclType(Decl);
2488 return C.getQualifiedType(ClassTy, FPT->getMethodQuals());
2489}
2490
2492 const CXXRecordDecl *Decl) {
2494 QualType ObjectTy = ::getThisObjectType(C, FPT, Decl);
2495 return C.getLangOpts().HLSL ? C.getLValueReferenceType(ObjectTy)
2496 : C.getPointerType(ObjectTy);
2497}
2498
2500 const CXXRecordDecl *Decl) {
2502 return ::getThisObjectType(C, FPT, Decl);
2503}
2504
2506 // C++ 9.3.2p1: The type of this in a member function of a class X is X*.
2507 // If the member function is declared const, the type of this is const X*,
2508 // if the member function is declared volatile, the type of this is
2509 // volatile X*, and if the member function is declared const volatile,
2510 // the type of this is const volatile X*.
2511 assert(isInstance() && "No 'this' for static methods!");
2512 return CXXMethodDecl::getThisType(getType()->castAs<FunctionProtoType>(),
2513 getParent());
2514}
2515
2517 // Ditto getThisType.
2518 assert(isInstance() && "No 'this' for static methods!");
2520 getType()->castAs<FunctionProtoType>(), getParent());
2521}
2522
2524 // If this function is a template instantiation, look at the template from
2525 // which it was instantiated.
2527 if (!CheckFn)
2528 CheckFn = this;
2529
2530 const FunctionDecl *fn;
2531 return CheckFn->isDefined(fn) && !fn->isOutOfLine() &&
2533}
2534
2536 const CXXRecordDecl *P = getParent();
2537 return P->isLambda() && getDeclName().isIdentifier() &&
2539}
2540
2542 TypeSourceInfo *TInfo, bool IsVirtual,
2543 SourceLocation L, Expr *Init,
2545 SourceLocation EllipsisLoc)
2546 : Initializee(TInfo), Init(Init), MemberOrEllipsisLocation(EllipsisLoc),
2547 LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(IsVirtual),
2548 IsWritten(false), SourceOrder(0) {}
2549
2551 SourceLocation MemberLoc,
2552 SourceLocation L, Expr *Init,
2554 : Initializee(Member), Init(Init), MemberOrEllipsisLocation(MemberLoc),
2555 LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
2556 IsWritten(false), SourceOrder(0) {}
2557
2560 SourceLocation MemberLoc,
2561 SourceLocation L, Expr *Init,
2563 : Initializee(Member), Init(Init), MemberOrEllipsisLocation(MemberLoc),
2564 LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false),
2565 IsWritten(false), SourceOrder(0) {}
2566
2568 TypeSourceInfo *TInfo,
2569 SourceLocation L, Expr *Init,
2571 : Initializee(TInfo), Init(Init), LParenLoc(L), RParenLoc(R),
2572 IsDelegating(true), IsVirtual(false), IsWritten(false), SourceOrder(0) {}
2573
2574int64_t CXXCtorInitializer::getID(const ASTContext &Context) const {
2575 return Context.getAllocator()
2576 .identifyKnownAlignedObject<CXXCtorInitializer>(this);
2577}
2578
2580 if (isBaseInitializer())
2581 return Initializee.get<TypeSourceInfo*>()->getTypeLoc();
2582 else
2583 return {};
2584}
2585
2587 if (isBaseInitializer())
2588 return Initializee.get<TypeSourceInfo*>()->getType().getTypePtr();
2589 else
2590 return nullptr;
2591}
2592
2595 return getAnyMember()->getLocation();
2596
2598 return getMemberLocation();
2599
2600 if (const auto *TSInfo = Initializee.get<TypeSourceInfo *>())
2601 return TSInfo->getTypeLoc().getBeginLoc();
2602
2603 return {};
2604}
2605
2608 FieldDecl *D = getAnyMember();
2609 if (Expr *I = D->getInClassInitializer())
2610 return I->getSourceRange();
2611 return {};
2612 }
2613
2615}
2616
2617CXXConstructorDecl::CXXConstructorDecl(
2618 ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2619 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2620 ExplicitSpecifier ES, bool UsesFPIntrin, bool isInline,
2621 bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind,
2622 InheritedConstructor Inherited, Expr *TrailingRequiresClause)
2623 : CXXMethodDecl(CXXConstructor, C, RD, StartLoc, NameInfo, T, TInfo,
2624 SC_None, UsesFPIntrin, isInline, ConstexprKind,
2625 SourceLocation(), TrailingRequiresClause) {
2626 setNumCtorInitializers(0);
2627 setInheritingConstructor(static_cast<bool>(Inherited));
2628 setImplicit(isImplicitlyDeclared);
2629 CXXConstructorDeclBits.HasTrailingExplicitSpecifier = ES.getExpr() ? 1 : 0;
2630 if (Inherited)
2631 *getTrailingObjects<InheritedConstructor>() = Inherited;
2632 setExplicitSpecifier(ES);
2633}
2634
2635void CXXConstructorDecl::anchor() {}
2636
2638 unsigned ID,
2639 uint64_t AllocKind) {
2640 bool hasTrailingExplicit = static_cast<bool>(AllocKind & TAKHasTailExplicit);
2642 static_cast<bool>(AllocKind & TAKInheritsConstructor);
2643 unsigned Extra =
2644 additionalSizeToAlloc<InheritedConstructor, ExplicitSpecifier>(
2645 isInheritingConstructor, hasTrailingExplicit);
2646 auto *Result = new (C, ID, Extra) CXXConstructorDecl(
2647 C, nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr,
2648 ExplicitSpecifier(), false, false, false, ConstexprSpecKind::Unspecified,
2649 InheritedConstructor(), nullptr);
2650 Result->setInheritingConstructor(isInheritingConstructor);
2651 Result->CXXConstructorDeclBits.HasTrailingExplicitSpecifier =
2652 hasTrailingExplicit;
2653 Result->setExplicitSpecifier(ExplicitSpecifier());
2654 return Result;
2655}
2656
2658 ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2659 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2660 ExplicitSpecifier ES, bool UsesFPIntrin, bool isInline,
2661 bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind,
2662 InheritedConstructor Inherited, Expr *TrailingRequiresClause) {
2663 assert(NameInfo.getName().getNameKind()
2665 "Name must refer to a constructor");
2666 unsigned Extra =
2667 additionalSizeToAlloc<InheritedConstructor, ExplicitSpecifier>(
2668 Inherited ? 1 : 0, ES.getExpr() ? 1 : 0);
2669 return new (C, RD, Extra) CXXConstructorDecl(
2670 C, RD, StartLoc, NameInfo, T, TInfo, ES, UsesFPIntrin, isInline,
2671 isImplicitlyDeclared, ConstexprKind, Inherited, TrailingRequiresClause);
2672}
2673
2675 return CtorInitializers.get(getASTContext().getExternalSource());
2676}
2677
2679 assert(isDelegatingConstructor() && "Not a delegating constructor!");
2680 Expr *E = (*init_begin())->getInit()->IgnoreImplicit();
2681 if (const auto *Construct = dyn_cast<CXXConstructExpr>(E))
2682 return Construct->getConstructor();
2683
2684 return nullptr;
2685}
2686
2688 // C++ [class.default.ctor]p1:
2689 // A default constructor for a class X is a constructor of class X for
2690 // which each parameter that is not a function parameter pack has a default
2691 // argument (including the case of a constructor with no parameters)
2692 return getMinRequiredArguments() == 0;
2693}
2694
2695bool
2696CXXConstructorDecl::isCopyConstructor(unsigned &TypeQuals) const {
2697 return isCopyOrMoveConstructor(TypeQuals) &&
2699}
2700
2701bool CXXConstructorDecl::isMoveConstructor(unsigned &TypeQuals) const {
2702 return isCopyOrMoveConstructor(TypeQuals) &&
2704}
2705
2706/// Determine whether this is a copy or move constructor.
2707bool CXXConstructorDecl::isCopyOrMoveConstructor(unsigned &TypeQuals) const {
2708 // C++ [class.copy]p2:
2709 // A non-template constructor for class X is a copy constructor
2710 // if its first parameter is of type X&, const X&, volatile X& or
2711 // const volatile X&, and either there are no other parameters
2712 // or else all other parameters have default arguments (8.3.6).
2713 // C++0x [class.copy]p3:
2714 // A non-template constructor for class X is a move constructor if its
2715 // first parameter is of type X&&, const X&&, volatile X&&, or
2716 // const volatile X&&, and either there are no other parameters or else
2717 // all other parameters have default arguments.
2718 if (!hasOneParamOrDefaultArgs() || getPrimaryTemplate() != nullptr ||
2719 getDescribedFunctionTemplate() != nullptr)
2720 return false;
2721
2722 const ParmVarDecl *Param = getParamDecl(0);
2723
2724 // Do we have a reference type?
2725 const auto *ParamRefType = Param->getType()->getAs<ReferenceType>();
2726 if (!ParamRefType)
2727 return false;
2728
2729 // Is it a reference to our class type?
2730 ASTContext &Context = getASTContext();
2731
2732 CanQualType PointeeType
2733 = Context.getCanonicalType(ParamRefType->getPointeeType());
2734 CanQualType ClassTy
2735 = Context.getCanonicalType(Context.getTagDeclType(getParent()));
2736 if (PointeeType.getUnqualifiedType() != ClassTy)
2737 return false;
2738
2739 // FIXME: other qualifiers?
2740
2741 // We have a copy or move constructor.
2742 TypeQuals = PointeeType.getCVRQualifiers();
2743 return true;
2744}
2745
2746bool CXXConstructorDecl::isConvertingConstructor(bool AllowExplicit) const {
2747 // C++ [class.conv.ctor]p1:
2748 // A constructor declared without the function-specifier explicit
2749 // that can be called with a single parameter specifies a
2750 // conversion from the type of its first parameter to the type of
2751 // its class. Such a constructor is called a converting
2752 // constructor.
2753 if (isExplicit() && !AllowExplicit)
2754 return false;
2755
2756 // FIXME: This has nothing to do with the definition of converting
2757 // constructor, but is convenient for how we use this function in overload
2758 // resolution.
2759 return getNumParams() == 0
2761 : getMinRequiredArguments() <= 1;
2762}
2763
2766 return false;
2767
2768 const ParmVarDecl *Param = getParamDecl(0);
2769
2770 ASTContext &Context = getASTContext();
2771 CanQualType ParamType = Context.getCanonicalType(Param->getType());
2772
2773 // Is it the same as our class type?
2774 CanQualType ClassTy
2775 = Context.getCanonicalType(Context.getTagDeclType(getParent()));
2776 if (ParamType.getUnqualifiedType() != ClassTy)
2777 return false;
2778
2779 return true;
2780}
2781
2782void CXXDestructorDecl::anchor() {}
2783
2786 return new (C, ID) CXXDestructorDecl(
2787 C, nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr,
2788 false, false, false, ConstexprSpecKind::Unspecified, nullptr);
2789}
2790
2792 ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2793 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2794 bool UsesFPIntrin, bool isInline, bool isImplicitlyDeclared,
2795 ConstexprSpecKind ConstexprKind, Expr *TrailingRequiresClause) {
2796 assert(NameInfo.getName().getNameKind()
2798 "Name must refer to a destructor");
2799 return new (C, RD) CXXDestructorDecl(
2800 C, RD, StartLoc, NameInfo, T, TInfo, UsesFPIntrin, isInline,
2801 isImplicitlyDeclared, ConstexprKind, TrailingRequiresClause);
2802}
2803
2805 auto *First = cast<CXXDestructorDecl>(getFirstDecl());
2806 if (OD && !First->OperatorDelete) {
2807 First->OperatorDelete = OD;
2808 First->OperatorDeleteThisArg = ThisArg;
2809 if (auto *L = getASTMutationListener())
2810 L->ResolvedOperatorDelete(First, OD, ThisArg);
2811 }
2812}
2813
2814void CXXConversionDecl::anchor() {}
2815
2818 return new (C, ID) CXXConversionDecl(
2819 C, nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr,
2821 SourceLocation(), nullptr);
2822}
2823
2825 ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2826 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2827 bool UsesFPIntrin, bool isInline, ExplicitSpecifier ES,
2828 ConstexprSpecKind ConstexprKind, SourceLocation EndLocation,
2829 Expr *TrailingRequiresClause) {
2830 assert(NameInfo.getName().getNameKind()
2832 "Name must refer to a conversion function");
2833 return new (C, RD) CXXConversionDecl(
2834 C, RD, StartLoc, NameInfo, T, TInfo, UsesFPIntrin, isInline, ES,
2835 ConstexprKind, EndLocation, TrailingRequiresClause);
2836}
2837
2839 return isImplicit() && getParent()->isLambda() &&
2841}
2842
2843LinkageSpecDecl::LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
2844 SourceLocation LangLoc, LanguageIDs lang,
2845 bool HasBraces)
2846 : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
2847 ExternLoc(ExternLoc), RBraceLoc(SourceLocation()) {
2848 setLanguage(lang);
2849 LinkageSpecDeclBits.HasBraces = HasBraces;
2850}
2851
2852void LinkageSpecDecl::anchor() {}
2853
2855 DeclContext *DC,
2856 SourceLocation ExternLoc,
2857 SourceLocation LangLoc,
2858 LanguageIDs Lang,
2859 bool HasBraces) {
2860 return new (C, DC) LinkageSpecDecl(DC, ExternLoc, LangLoc, Lang, HasBraces);
2861}
2862
2864 unsigned ID) {
2865 return new (C, ID) LinkageSpecDecl(nullptr, SourceLocation(),
2866 SourceLocation(), lang_c, false);
2867}
2868
2869void UsingDirectiveDecl::anchor() {}
2870
2873 SourceLocation NamespaceLoc,
2874 NestedNameSpecifierLoc QualifierLoc,
2875 SourceLocation IdentLoc,
2876 NamedDecl *Used,
2877 DeclContext *CommonAncestor) {
2878 if (auto *NS = dyn_cast_or_null<NamespaceDecl>(Used))
2879 Used = NS->getOriginalNamespace();
2880 return new (C, DC) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierLoc,
2881 IdentLoc, Used, CommonAncestor);
2882}
2883
2885 unsigned ID) {
2886 return new (C, ID) UsingDirectiveDecl(nullptr, SourceLocation(),
2889 SourceLocation(), nullptr, nullptr);
2890}
2891
2893 if (auto *NA = dyn_cast_or_null<NamespaceAliasDecl>(NominatedNamespace))
2894 return NA->getNamespace();
2895 return cast_or_null<NamespaceDecl>(NominatedNamespace);
2896}
2897
2898NamespaceDecl::NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline,
2899 SourceLocation StartLoc, SourceLocation IdLoc,
2900 IdentifierInfo *Id, NamespaceDecl *PrevDecl,
2901 bool Nested)
2902 : NamedDecl(Namespace, DC, IdLoc, Id), DeclContext(Namespace),
2903 redeclarable_base(C), LocStart(StartLoc) {
2904 unsigned Flags = 0;
2905 if (Inline)
2906 Flags |= F_Inline;
2907 if (Nested)
2908 Flags |= F_Nested;
2909 AnonOrFirstNamespaceAndFlags = {nullptr, Flags};
2910 setPreviousDecl(PrevDecl);
2911
2912 if (PrevDecl)
2913 AnonOrFirstNamespaceAndFlags.setPointer(PrevDecl->getOriginalNamespace());
2914}
2915
2917 bool Inline, SourceLocation StartLoc,
2919 NamespaceDecl *PrevDecl, bool Nested) {
2920 return new (C, DC)
2921 NamespaceDecl(C, DC, Inline, StartLoc, IdLoc, Id, PrevDecl, Nested);
2922}
2923
2925 return new (C, ID) NamespaceDecl(C, nullptr, false, SourceLocation(),
2926 SourceLocation(), nullptr, nullptr, false);
2927}
2928
2930 if (isFirstDecl())
2931 return this;
2932
2933 return AnonOrFirstNamespaceAndFlags.getPointer();
2934}
2935
2937 if (isFirstDecl())
2938 return this;
2939
2940 return AnonOrFirstNamespaceAndFlags.getPointer();
2941}
2942
2944
2945NamespaceDecl *NamespaceDecl::getNextRedeclarationImpl() {
2946 return getNextRedeclaration();
2947}
2948
2949NamespaceDecl *NamespaceDecl::getPreviousDeclImpl() {
2950 return getPreviousDecl();
2951}
2952
2953NamespaceDecl *NamespaceDecl::getMostRecentDeclImpl() {
2954 return getMostRecentDecl();
2955}
2956
2957void NamespaceAliasDecl::anchor() {}
2958
2959NamespaceAliasDecl *NamespaceAliasDecl::getNextRedeclarationImpl() {
2960 return getNextRedeclaration();
2961}
2962
2963NamespaceAliasDecl *NamespaceAliasDecl::getPreviousDeclImpl() {
2964 return getPreviousDecl();
2965}
2966
2967NamespaceAliasDecl *NamespaceAliasDecl::getMostRecentDeclImpl() {
2968 return getMostRecentDecl();
2969}
2970
2972 SourceLocation UsingLoc,
2973 SourceLocation AliasLoc,
2974 IdentifierInfo *Alias,
2975 NestedNameSpecifierLoc QualifierLoc,
2976 SourceLocation IdentLoc,
2977 NamedDecl *Namespace) {
2978 // FIXME: Preserve the aliased namespace as written.
2979 if (auto *NS = dyn_cast_or_null<NamespaceDecl>(Namespace))
2980 Namespace = NS->getOriginalNamespace();
2981 return new (C, DC) NamespaceAliasDecl(C, DC, UsingLoc, AliasLoc, Alias,
2982 QualifierLoc, IdentLoc, Namespace);
2983}
2984
2987 return new (C, ID) NamespaceAliasDecl(C, nullptr, SourceLocation(),
2988 SourceLocation(), nullptr,
2990 SourceLocation(), nullptr);
2991}
2992
2993void LifetimeExtendedTemporaryDecl::anchor() {}
2994
2995/// Retrieve the storage duration for the materialized temporary.
2997 const ValueDecl *ExtendingDecl = getExtendingDecl();
2998 if (!ExtendingDecl)
2999 return SD_FullExpression;
3000 // FIXME: This is not necessarily correct for a temporary materialized
3001 // within a default initializer.
3002 if (isa<FieldDecl>(ExtendingDecl))
3003 return SD_Automatic;
3004 // FIXME: This only works because storage class specifiers are not allowed
3005 // on decomposition declarations.
3006 if (isa<BindingDecl>(ExtendingDecl))
3007 return ExtendingDecl->getDeclContext()->isFunctionOrMethod() ? SD_Automatic
3008 : SD_Static;
3009 return cast<VarDecl>(ExtendingDecl)->getStorageDuration();
3010}
3011
3013 assert(getStorageDuration() == SD_Static &&
3014 "don't need to cache the computed value for this temporary");
3015 if (MayCreate && !Value) {
3016 Value = (new (getASTContext()) APValue);
3018 }
3019 assert(Value && "may not be null");
3020 return Value;
3021}
3022
3023void UsingShadowDecl::anchor() {}
3024
3027 BaseUsingDecl *Introducer, NamedDecl *Target)
3028 : NamedDecl(K, DC, Loc, Name), redeclarable_base(C),
3029 UsingOrNextShadow(Introducer) {
3030 if (Target) {
3031 assert(!isa<UsingShadowDecl>(Target));
3033 }
3034 setImplicit();
3035}
3036
3038 : NamedDecl(K, nullptr, SourceLocation(), DeclarationName()),
3040
3043 return new (C, ID) UsingShadowDecl(UsingShadow, C, EmptyShell());
3044}
3045
3047 const UsingShadowDecl *Shadow = this;
3048 while (const auto *NextShadow =
3049 dyn_cast<UsingShadowDecl>(Shadow->UsingOrNextShadow))
3050 Shadow = NextShadow;
3051 return cast<BaseUsingDecl>(Shadow->UsingOrNextShadow);
3052}
3053
3054void ConstructorUsingShadowDecl::anchor() {}
3055
3058 SourceLocation Loc, UsingDecl *Using,
3059 NamedDecl *Target, bool IsVirtual) {
3060 return new (C, DC) ConstructorUsingShadowDecl(C, DC, Loc, Using, Target,
3061 IsVirtual);
3062}
3063
3066 return new (C, ID) ConstructorUsingShadowDecl(C, EmptyShell());
3067}
3068
3071}
3072
3073void BaseUsingDecl::anchor() {}
3074
3076 assert(!llvm::is_contained(shadows(), S) && "declaration already in set");
3077 assert(S->getIntroducer() == this);
3078
3079 if (FirstUsingShadow.getPointer())
3080 S->UsingOrNextShadow = FirstUsingShadow.getPointer();
3081 FirstUsingShadow.setPointer(S);
3082}
3083
3085 assert(llvm::is_contained(shadows(), S) && "declaration not in set");
3086 assert(S->getIntroducer() == this);
3087
3088 // Remove S from the shadow decl chain. This is O(n) but hopefully rare.
3089
3090 if (FirstUsingShadow.getPointer() == S) {
3091 FirstUsingShadow.setPointer(
3092 dyn_cast<UsingShadowDecl>(S->UsingOrNextShadow));
3093 S->UsingOrNextShadow = this;
3094 return;
3095 }
3096
3097 UsingShadowDecl *Prev = FirstUsingShadow.getPointer();
3098 while (Prev->UsingOrNextShadow != S)
3099 Prev = cast<UsingShadowDecl>(Prev->UsingOrNextShadow);
3100 Prev->UsingOrNextShadow = S->UsingOrNextShadow;
3101 S->UsingOrNextShadow = this;
3102}
3103
3104void UsingDecl::anchor() {}
3105
3107 NestedNameSpecifierLoc QualifierLoc,
3108 const DeclarationNameInfo &NameInfo,
3109 bool HasTypename) {
3110 return new (C, DC) UsingDecl(DC, UL, QualifierLoc, NameInfo, HasTypename);
3111}
3112
3114 return new (C, ID) UsingDecl(nullptr, SourceLocation(),
3116 false);
3117}
3118
3121 ? getQualifierLoc().getBeginLoc() : UsingLocation;
3123}
3124
3125void UsingEnumDecl::anchor() {}
3126
3128 SourceLocation UL,
3129 SourceLocation EL,
3130 SourceLocation NL,
3132 assert(isa<EnumDecl>(EnumType->getType()->getAsTagDecl()));
3133 return new (C, DC)
3134 UsingEnumDecl(DC, EnumType->getType()->getAsTagDecl()->getDeclName(), UL, EL, NL, EnumType);
3135}
3136
3138 return new (C, ID)
3140 SourceLocation(), SourceLocation(), nullptr);
3141}
3142
3144 return SourceRange(UsingLocation, EnumType->getTypeLoc().getEndLoc());
3145}
3146
3147void UsingPackDecl::anchor() {}
3148
3150 NamedDecl *InstantiatedFrom,
3151 ArrayRef<NamedDecl *> UsingDecls) {
3152 size_t Extra = additionalSizeToAlloc<NamedDecl *>(UsingDecls.size());
3153 return new (C, DC, Extra) UsingPackDecl(DC, InstantiatedFrom, UsingDecls);
3154}
3155
3157 unsigned NumExpansions) {
3158 size_t Extra = additionalSizeToAlloc<NamedDecl *>(NumExpansions);
3159 auto *Result =
3160 new (C, ID, Extra) UsingPackDecl(nullptr, nullptr, std::nullopt);
3161 Result->NumExpansions = NumExpansions;
3162 auto *Trail = Result->getTrailingObjects<NamedDecl *>();
3163 for (unsigned I = 0; I != NumExpansions; ++I)
3164 new (Trail + I) NamedDecl*(nullptr);
3165 return Result;
3166}
3167
3168void UnresolvedUsingValueDecl::anchor() {}
3169
3172 SourceLocation UsingLoc,
3173 NestedNameSpecifierLoc QualifierLoc,
3174 const DeclarationNameInfo &NameInfo,
3175 SourceLocation EllipsisLoc) {
3176 return new (C, DC) UnresolvedUsingValueDecl(DC, C.DependentTy, UsingLoc,
3177 QualifierLoc, NameInfo,
3178 EllipsisLoc);
3179}
3180
3183 return new (C, ID) UnresolvedUsingValueDecl(nullptr, QualType(),
3187 SourceLocation());
3188}
3189
3192 ? getQualifierLoc().getBeginLoc() : UsingLocation;
3194}
3195
3196void UnresolvedUsingTypenameDecl::anchor() {}
3197
3200 SourceLocation UsingLoc,
3201 SourceLocation TypenameLoc,
3202 NestedNameSpecifierLoc QualifierLoc,
3203 SourceLocation TargetNameLoc,
3204 DeclarationName TargetName,
3205 SourceLocation EllipsisLoc) {
3206 return new (C, DC) UnresolvedUsingTypenameDecl(
3207 DC, UsingLoc, TypenameLoc, QualifierLoc, TargetNameLoc,
3208 TargetName.getAsIdentifierInfo(), EllipsisLoc);
3209}
3210
3213 return new (C, ID) UnresolvedUsingTypenameDecl(
3215 SourceLocation(), nullptr, SourceLocation());
3216}
3217
3220 SourceLocation Loc, DeclarationName Name) {
3221 return new (Ctx, DC) UnresolvedUsingIfExistsDecl(DC, Loc, Name);
3222}
3223
3226 return new (Ctx, ID)
3228}
3229
3230UnresolvedUsingIfExistsDecl::UnresolvedUsingIfExistsDecl(DeclContext *DC,
3231 SourceLocation Loc,
3232 DeclarationName Name)
3233 : NamedDecl(Decl::UnresolvedUsingIfExists, DC, Loc, Name) {}
3234
3235void UnresolvedUsingIfExistsDecl::anchor() {}
3236
3237void StaticAssertDecl::anchor() {}
3238
3240 SourceLocation StaticAssertLoc,
3241 Expr *AssertExpr, Expr *Message,
3242 SourceLocation RParenLoc,
3243 bool Failed) {
3244 return new (C, DC) StaticAssertDecl(DC, StaticAssertLoc, AssertExpr, Message,
3245 RParenLoc, Failed);
3246}
3247
3249 unsigned ID) {
3250 return new (C, ID) StaticAssertDecl(nullptr, SourceLocation(), nullptr,
3251 nullptr, SourceLocation(), false);
3252}
3253
3255 assert((isa<VarDecl, BindingDecl>(this)) &&
3256 "expected a VarDecl or a BindingDecl");
3257 if (auto *Var = llvm::dyn_cast<VarDecl>(this))
3258 return Var;
3259 if (auto *BD = llvm::dyn_cast<BindingDecl>(this))
3260 return llvm::dyn_cast<VarDecl>(BD->getDecomposedDecl());
3261 return nullptr;
3262}
3263
3264void BindingDecl::anchor() {}
3265
3268 return new (C, DC) BindingDecl(DC, IdLoc, Id);
3269}
3270
3272 return new (C, ID) BindingDecl(nullptr, SourceLocation(), nullptr);
3273}
3274
3276 Expr *B = getBinding();
3277 if (!B)
3278 return nullptr;
3279 auto *DRE = dyn_cast<DeclRefExpr>(B->IgnoreImplicit());
3280 if (!DRE)
3281 return nullptr;
3282
3283 auto *VD = cast<VarDecl>(DRE->getDecl());
3284 assert(VD->isImplicit() && "holding var for binding decl not implicit");
3285 return VD;
3286}
3287
3288void DecompositionDecl::anchor() {}
3289
3291 SourceLocation StartLoc,
3292 SourceLocation LSquareLoc,
3293 QualType T, TypeSourceInfo *TInfo,
3294 StorageClass SC,
3296 size_t Extra = additionalSizeToAlloc<BindingDecl *>(Bindings.size());
3297 return new (C, DC, Extra)
3298 DecompositionDecl(C, DC, StartLoc, LSquareLoc, T, TInfo, SC, Bindings);
3299}
3300
3302 unsigned ID,
3303 unsigned NumBindings) {
3304 size_t Extra = additionalSizeToAlloc<BindingDecl *>(NumBindings);
3305 auto *Result = new (C, ID, Extra)
3307 QualType(), nullptr, StorageClass(), std::nullopt);
3308 // Set up and clean out the bindings array.
3309 Result->NumBindings = NumBindings;
3310 auto *Trail = Result->getTrailingObjects<BindingDecl *>();
3311 for (unsigned I = 0; I != NumBindings; ++I)
3312 new (Trail + I) BindingDecl*(nullptr);
3313 return Result;
3314}
3315
3316void DecompositionDecl::printName(llvm::raw_ostream &OS,
3317 const PrintingPolicy &Policy) const {
3318 OS << '[';
3319 bool Comma = false;
3320 for (const auto *B : bindings()) {
3321 if (Comma)
3322 OS << ", ";
3323 B->printName(OS, Policy);
3324 Comma = true;
3325 }
3326 OS << ']';
3327}
3328
3329void MSPropertyDecl::anchor() {}
3330
3333 QualType T, TypeSourceInfo *TInfo,
3334 SourceLocation StartL,
3335 IdentifierInfo *Getter,
3336 IdentifierInfo *Setter) {
3337 return new (C, DC) MSPropertyDecl(DC, L, N, T, TInfo, StartL, Getter, Setter);
3338}
3339
3341 unsigned ID) {
3342 return new (C, ID) MSPropertyDecl(nullptr, SourceLocation(),
3343 DeclarationName(), QualType(), nullptr,
3344 SourceLocation(), nullptr, nullptr);
3345}
3346
3347void MSGuidDecl::anchor() {}
3348
3349MSGuidDecl::MSGuidDecl(DeclContext *DC, QualType T, Parts P)
3350 : ValueDecl(Decl::MSGuid, DC, SourceLocation(), DeclarationName(), T),
3351 PartVal(P) {}
3352
3353MSGuidDecl *MSGuidDecl::Create(const ASTContext &C, QualType T, Parts P) {
3354 DeclContext *DC = C.getTranslationUnitDecl();
3355 return new (C, DC) MSGuidDecl(DC, T, P);
3356}
3357
3358MSGuidDecl *MSGuidDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
3359 return new (C, ID) MSGuidDecl(nullptr, QualType(), Parts());
3360}
3361
3362void MSGuidDecl::printName(llvm::raw_ostream &OS,
3363 const PrintingPolicy &) const {
3364 OS << llvm::format("GUID{%08" PRIx32 "-%04" PRIx16 "-%04" PRIx16 "-",
3365 PartVal.Part1, PartVal.Part2, PartVal.Part3);
3366 unsigned I = 0;
3367 for (uint8_t Byte : PartVal.Part4And5) {
3368 OS << llvm::format("%02" PRIx8, Byte);
3369 if (++I == 2)
3370 OS << '-';
3371 }
3372 OS << '}';
3373}
3374
3375/// Determine if T is a valid 'struct _GUID' of the shape that we expect.
3377 // FIXME: We only need to check this once, not once each time we compute a
3378 // GUID APValue.
3379 using MatcherRef = llvm::function_ref<bool(QualType)>;
3380
3381 auto IsInt = [&Ctx](unsigned N) {
3382 return [&Ctx, N](QualType T) {
3384 Ctx.getIntWidth(T) == N;
3385 };
3386 };
3387
3388 auto IsArray = [&Ctx](MatcherRef Elem, unsigned N) {
3389 return [&Ctx, Elem, N](QualType T) {
3390 const ConstantArrayType *CAT = Ctx.getAsConstantArrayType(T);
3391 return CAT && CAT->getSize() == N && Elem(CAT->getElementType());
3392 };
3393 };
3394
3395 auto IsStruct = [](std::initializer_list<MatcherRef> Fields) {
3396 return [Fields](QualType T) {
3397 const RecordDecl *RD = T->getAsRecordDecl();
3398 if (!RD || RD->isUnion())
3399 return false;
3400 RD = RD->getDefinition();
3401 if (!RD)
3402 return false;
3403 if (auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
3404 if (CXXRD->getNumBases())
3405 return false;
3406 auto MatcherIt = Fields.begin();
3407 for (const FieldDecl *FD : RD->fields()) {
3408 if (FD->isUnnamedBitfield()) continue;
3409 if (FD->isBitField() || MatcherIt == Fields.end() ||
3410 !(*MatcherIt)(FD->getType()))
3411 return false;
3412 ++MatcherIt;
3413 }
3414 return MatcherIt == Fields.end();
3415 };
3416 };
3417
3418 // We expect an {i32, i16, i16, [8 x i8]}.
3419 return IsStruct({IsInt(32), IsInt(16), IsInt(16), IsArray(IsInt(8), 8)})(T);
3420}
3421
3423 if (APVal.isAbsent() && isValidStructGUID(getASTContext(), getType())) {
3424 using llvm::APInt;
3425 using llvm::APSInt;
3426 APVal = APValue(APValue::UninitStruct(), 0, 4);
3427 APVal.getStructField(0) = APValue(APSInt(APInt(32, PartVal.Part1), true));
3428 APVal.getStructField(1) = APValue(APSInt(APInt(16, PartVal.Part2), true));
3429 APVal.getStructField(2) = APValue(APSInt(APInt(16, PartVal.Part3), true));
3430 APValue &Arr = APVal.getStructField(3) =
3432 for (unsigned I = 0; I != 8; ++I) {
3433 Arr.getArrayInitializedElt(I) =
3434 APValue(APSInt(APInt(8, PartVal.Part4And5[I]), true));
3435 }
3436 // Register this APValue to be destroyed if necessary. (Note that the
3437 // MSGuidDecl destructor is never run.)
3438 getASTContext().addDestruction(&APVal);
3439 }
3440
3441 return APVal;
3442}
3443
3444void UnnamedGlobalConstantDecl::anchor() {}
3445
3446UnnamedGlobalConstantDecl::UnnamedGlobalConstantDecl(const ASTContext &C,
3447 DeclContext *DC,
3448 QualType Ty,
3449 const APValue &Val)
3450 : ValueDecl(Decl::UnnamedGlobalConstant, DC, SourceLocation(),
3451 DeclarationName(), Ty),
3452 Value(Val) {
3453 // Cleanup the embedded APValue if required (note that our destructor is never
3454 // run)
3455 if (Value.needsCleanup())
3456 C.addDestruction(&Value);
3457}
3458
3460UnnamedGlobalConstantDecl::Create(const ASTContext &C, QualType T,
3461 const APValue &Value) {
3462 DeclContext *DC = C.getTranslationUnitDecl();
3463 return new (C, DC) UnnamedGlobalConstantDecl(C, DC, T, Value);
3464}
3465
3467UnnamedGlobalConstantDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
3468 return new (C, ID)
3470}
3471
3472void UnnamedGlobalConstantDecl::printName(llvm::raw_ostream &OS,
3473 const PrintingPolicy &) const {
3474 OS << "unnamed-global-constant";
3475}
3476
3477static const char *getAccessName(AccessSpecifier AS) {
3478 switch (AS) {
3479 case AS_none:
3480 llvm_unreachable("Invalid access specifier!");
3481 case AS_public:
3482 return "public";
3483 case AS_private:
3484 return "private";
3485 case AS_protected:
3486 return "protected";
3487 }
3488 llvm_unreachable("Invalid access specifier!");
3489}
3490
3492 AccessSpecifier AS) {
3493 return DB << getAccessName(AS);
3494}
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:163
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:1684
static const char * getAccessName(AccessSpecifier AS)
Definition: DeclCXX.cpp:3477
static bool recursivelyOverrides(const CXXMethodDecl *DerivedMD, const CXXMethodDecl *BaseMD)
Definition: DeclCXX.cpp:2154
static bool isValidStructGUID(ASTContext &Ctx, QualType T)
Determine if T is a valid 'struct _GUID' of the shape that we expect.
Definition: DeclCXX.cpp:3376
static DeclContext::lookup_result getLambdaStaticInvokers(const CXXRecordDecl &RD)
Definition: DeclCXX.cpp:1571
static NamedDecl * getLambdaCallOperatorHelper(const CXXRecordDecl &RD)
Definition: DeclCXX.cpp:1535
static QualType getThisObjectType(ASTContext &C, const FunctionProtoType *FPT, const CXXRecordDecl *Decl)
Definition: DeclCXX.cpp:2485
static bool allLookupResultsAreTheSame(const DeclContext::lookup_result &R)
Definition: DeclCXX.cpp:1527
static bool isDeclContextInNamespace(const DeclContext *DC)
Definition: DeclCXX.cpp:1953
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:1665
static CXXMethodDecl * getInvokerAsMethod(NamedDecl *ND)
Definition: DeclCXX.cpp:1578
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.
const char * Data
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:2720
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:634
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2527
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:1564
IdentifierTable & Idents
Definition: ASTContext.h:630
const LangOptions & getLangOpts() const
Definition: ASTContext.h:761
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:700
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:2570
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:704
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:743
void addDestruction(T *Ptr) const
If T isn't trivially destructible, calls AddDeallocation to register it for destruction.
Definition: ASTContext.h:3060
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
Definition: ASTContext.h:1169
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:3104
Represents a C++ declaration that introduces decls from somewhere else.
Definition: DeclCXX.h:3371
void addShadowDecl(UsingShadowDecl *S)
Definition: DeclCXX.cpp:3075
shadow_range shadows() const
Definition: DeclCXX.h:3437
void removeShadowDecl(UsingShadowDecl *S)
Definition: DeclCXX.cpp:3084
A binding in a decomposition declaration.
Definition: DeclCXX.h:4060
static BindingDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:3271
VarDecl * getHoldingVar() const
Get the variable (if any) that holds the value of evaluating the binding.
Definition: DeclCXX.cpp:3275
Expr * getBinding() const
Get the expression to which this declaration is bound.
Definition: DeclCXX.h:4084
static BindingDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id)
Definition: DeclCXX.cpp:3266
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2491
bool isExplicit() const
Return true if the declaration is already resolved to be explicit.
Definition: DeclCXX.h:2570
init_iterator init_begin()
Retrieve an iterator to the first initializer.
Definition: DeclCXX.h:2587
CXXConstructorDecl * getTargetConstructor() const
When this constructor delegates to another, retrieve the target.
Definition: DeclCXX.cpp:2678
bool isDefaultConstructor() const
Whether this constructor is a default constructor (C++ [class.ctor]p5), which can be used to default-...
Definition: DeclCXX.cpp:2687
bool isDelegatingConstructor() const
Determine whether this constructor is a delegating constructor.
Definition: DeclCXX.h:2643
bool isSpecializationCopyingObject() const
Determine whether this is a member template specialization that would copy the object to itself.
Definition: DeclCXX.cpp:2764
bool isMoveConstructor() const
Determine whether this constructor is a move constructor (C++11 [class.copy]p3), which can be used to...
Definition: DeclCXX.h:2688
bool isCopyOrMoveConstructor() const
Determine whether this a copy or move constructor.
Definition: DeclCXX.h:2700
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:2657
bool isInheritingConstructor() const
Determine whether this is an implicit constructor synthesized to model a call to a constructor inheri...
Definition: DeclCXX.h:2717
CXXCtorInitializer *const * init_const_iterator
Iterates through the member/base initializer list.
Definition: DeclCXX.h:2576
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:2746
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:2674
static CXXConstructorDecl * CreateDeserialized(ASTContext &C, unsigned ID, uint64_t AllocKind)
Definition: DeclCXX.cpp:2637
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2818
bool isLambdaToBlockPointerConversion() const
Determine whether this conversion function is a conversion from a lambda closure type to a block poin...
Definition: DeclCXX.cpp:2838
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:2824
QualType getConversionType() const
Returns the type that this conversion function is converting to.
Definition: DeclCXX.h:2858
static CXXConversionDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:2817
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2259
SourceLocation getRParenLoc() const
Definition: DeclCXX.h:2455
SourceRange getSourceRange() const LLVM_READONLY
Determine the source range covering the entire initializer.
Definition: DeclCXX.cpp:2606
SourceLocation getSourceLocation() const
Determine the source location of the initializer.
Definition: DeclCXX.cpp:2593
bool isAnyMemberInitializer() const
Definition: DeclCXX.h:2336
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition: DeclCXX.h:2328
int64_t getID(const ASTContext &Context) const
Definition: DeclCXX.cpp:2574
bool isInClassMemberInitializer() const
Determine whether this initializer is an implicit initializer generated for a field with an initializ...
Definition: DeclCXX.h:2350
const Type * getBaseClass() const
If this is a base class initializer, returns the type of the base class.
Definition: DeclCXX.cpp:2586
SourceLocation getMemberLocation() const
Definition: DeclCXX.h:2416
FieldDecl * getAnyMember() const
Definition: DeclCXX.h:2402
TypeLoc getBaseClassLoc() const
If this is a base class initializer, returns the type of the base class with location information.
Definition: DeclCXX.cpp:2579
CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual, SourceLocation L, Expr *Init, SourceLocation R, SourceLocation EllipsisLoc)
Creates a new base-class initializer.
Definition: DeclCXX.cpp:2541
Represents a C++ deduction guide declaration.
Definition: DeclCXX.h:1937
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:2115
static CXXDeductionGuideDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:2124
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2755
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:2791
void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg)
Definition: DeclCXX.cpp:2804
static CXXDestructorDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:2785
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:2035
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:2166
void addOverriddenMethod(const CXXMethodDecl *MD)
Definition: DeclCXX.cpp:2454
bool hasInlineBody() const
Definition: DeclCXX.cpp:2523
bool isVirtual() const
Definition: DeclCXX.h:2079
static CXXMethodDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:2243
bool isUsualDeallocationFunction(SmallVectorImpl< const FunctionDecl * > &PreventedBy) const
Determine whether this is a usual deallocation function (C++ [basic.stc.dynamic.deallocation]p2),...
Definition: DeclCXX.cpp:2335
overridden_method_range overridden_methods() const
Definition: DeclCXX.cpp:2479
unsigned size_overridden_methods() const
Definition: DeclCXX.cpp:2473
const CXXMethodDecl *const * method_iterator
Definition: DeclCXX.h:2137
method_iterator begin_overridden_methods() const
Definition: DeclCXX.cpp:2463
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Definition: DeclCXX.h:2150
QualType getThisType() const
Return the type of the this pointer.
Definition: DeclCXX.cpp:2505
bool isInstance() const
Definition: DeclCXX.h:2062
bool isMoveAssignmentOperator() const
Determine whether this is a move assignment operator.
Definition: DeclCXX.cpp:2433
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:2232
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:2250
static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK)
Returns true if the given operator is implicitly static in a record context.
Definition: DeclCXX.h:2066
CXXMethodDecl * getCorrespondingMethodInClass(const CXXRecordDecl *RD, bool MayBeBase=false)
Find the method in RD that corresponds to this one.
Definition: DeclCXX.cpp:2197
llvm::iterator_range< llvm::TinyPtrVector< const CXXMethodDecl * >::const_iterator > overridden_method_range
Definition: DeclCXX.h:2144
QualType getThisObjectType() const
Return the type of the object pointed by this.
Definition: DeclCXX.cpp:2516
bool isStatic() const
Definition: DeclCXX.cpp:2144
bool isCopyAssignmentOperator() const
Determine whether this is a copy-assignment operator, regardless of whether it was declared implicitl...
Definition: DeclCXX.cpp:2412
method_iterator end_overridden_methods() const
Definition: DeclCXX.cpp:2468
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:2120
bool isLambdaStaticInvoker() const
Determine whether this is a lambda closure type's static member function that is used for the result ...
Definition: DeclCXX.cpp:2535
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
Decl * getLambdaContextDecl() const
Retrieve the declaration that provides additional context for a lambda, when the normal declaration c...
Definition: DeclCXX.cpp:1643
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:2058
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:1316
TemplateParameterList * getGenericLambdaTemplateParameterList() const
Retrieve the generic lambda's template parameter list.
Definition: DeclCXX.cpp:1620
bool isEffectivelyFinal() const
Determine whether it's impossible for a class to be derived from this class.
Definition: DeclCXX.cpp:2073
bool hasSimpleMoveConstructor() const
true if we know for sure that this class has a single, accessible, unambiguous move constructor that ...
Definition: DeclCXX.h:728
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:1521
base_class_iterator bases_end()
Definition: DeclCXX.h:615
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
Definition: DeclCXX.h:1348
bool hasUserDeclaredDestructor() const
Determine whether this class has a user-declared destructor.
Definition: DeclCXX.h:992
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:1834
void completeDefinition() override
Indicates that the definition of this class is now complete.
Definition: DeclCXX.cpp:2013
bool defaultedDestructorIsConstexpr() const
Determine whether a defaulted default constructor for this class would be constexpr.
Definition: DeclCXX.h:1338
void setCaptures(ASTContext &Context, ArrayRef< LambdaCapture > Captures)
Set the captures for this lambda closure type.
Definition: DeclCXX.cpp:1473
unsigned getDeviceLambdaManglingNumber() const
Retrieve the device side mangling number.
Definition: DeclCXX.cpp:1660
base_class_range bases()
Definition: DeclCXX.h:606
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:1494
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:1009
void addedSelectedDestructor(CXXDestructorDecl *DD)
Notify the class that this destructor is now selected.
Definition: DeclCXX.cpp:1374
bool hasFriends() const
Determines whether this record has any friends.
Definition: DeclCXX.h:689
method_range methods() const
Definition: DeclCXX.h:648
CXXRecordDecl * getDefinition() const
Definition: DeclCXX.h:552
static AccessSpecifier MergeAccess(AccessSpecifier PathAccess, AccessSpecifier DeclAccess)
Calculates the access of a decl that is reached along a path.
Definition: DeclCXX.h:1712
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:1599
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:1791
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:600
bool hasNonLiteralTypeFieldsOrBases() const
Determine whether this class has a non-literal or/ volatile type non-static data member or base class...
Definition: DeclCXX.h:1390
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
const CXXRecordDecl * getTemplateInstantiationPattern() const
Retrieve the record declaration from which this record could be instantiated.
Definition: DeclCXX.cpp:1888
bool lambdaIsDefaultConstructibleAndAssignable() const
Determine whether this lambda should have an implicit default constructor and copy and move assignmen...
Definition: DeclCXX.cpp:676
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
Definition: DeclCXX.cpp:1863
base_class_iterator bases_begin()
Definition: DeclCXX.h:613
FunctionTemplateDecl * getDependentLambdaCallOperator() const
Retrieve the dependent lambda call operator of the closure type if this is a templated closure type.
Definition: DeclCXX.cpp:1547
void addedEligibleSpecialMemberFunction(const CXXMethodDecl *MD, unsigned SMKind)
Notify the class that an eligible SMF has been added.
Definition: DeclCXX.cpp:1379
conversion_iterator conversion_end() const
Definition: DeclCXX.h:1110
void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD)
Indicates that the declaration of a defaulted or deleted special member function is now complete.
Definition: DeclCXX.cpp:1426
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:1511
void setInstantiationOfMemberClass(CXXRecordDecl *RD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member class RD.
Definition: DeclCXX.cpp:1846
bool hasSimpleMoveAssignment() const
true if we know for sure that this class has a single, accessible, unambiguous move assignment operat...
Definition: DeclCXX.h:742
bool hasNonTrivialMoveConstructor() const
Determine whether this class has a non-trivial move constructor (C++11 [class.copy]p12)
Definition: DeclCXX.h:1295
bool hasUserDeclaredConstructor() const
Determine whether this class has any user-declared constructors.
Definition: DeclCXX.h:778
unsigned getODRHash() const
Definition: DeclCXX.cpp:493
bool hasDefinition() const
Definition: DeclCXX.h:559
ArrayRef< NamedDecl * > getLambdaExplicitTemplateParameters() const
Retrieve the lambda template parameters that were specified explicitly.
Definition: DeclCXX.cpp:1629
ClassTemplateDecl * getDescribedClassTemplate() const
Retrieves the class template that is described by this class declaration.
Definition: DeclCXX.cpp:1855
bool isPOD() const
Whether this class is a POD-type (C++ [class]p4)
Definition: DeclCXX.h:1156
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:1809
bool hasSimpleCopyConstructor() const
true if we know for sure that this class has a single, accessible, unambiguous copy constructor that ...
Definition: DeclCXX.h:721
LambdaCaptureDefault getLambdaCaptureDefault() const
Definition: DeclCXX.h:1050
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
Definition: DeclCXX.cpp:1933
bool hasNonTrivialMoveAssignment() const
Determine whether this class has a non-trivial move assignment operator (C++11 [class....
Definition: DeclCXX.h:1330
CXXMethodDecl * getLambdaStaticInvoker() const
Retrieve the lambda static invoker, the address of which is returned by the conversion operator,...
Definition: DeclCXX.cpp:1564
bool hasSimpleDestructor() const
true if we know for sure that this class has an accessible destructor that is not deleted.
Definition: DeclCXX.h:749
void setDescribedClassTemplate(ClassTemplateDecl *Template)
Definition: DeclCXX.cpp:1859
bool isInterfaceLike() const
Definition: DeclCXX.cpp:1962
unsigned capture_size() const
Definition: DeclCXX.h:1097
void setLambdaNumbering(LambdaNumbering Numbering)
Set the mangling numbers and context declaration for a lambda class.
Definition: DeclCXX.cpp:1649
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:1841
bool hasNonTrivialCopyConstructor() const
Determine whether this class has a non-trivial copy constructor (C++ [class.copy]p6,...
Definition: DeclCXX.h:1270
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
Definition: DeclCXX.cpp:1552
bool hasSimpleCopyAssignment() const
true if we know for sure that this class has a single, accessible, unambiguous copy assignment operat...
Definition: DeclCXX.h:735
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:511
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition: DeclCXX.cpp:1874
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
Definition: DeclCXX.h:621
conversion_iterator conversion_begin() const
Definition: DeclCXX.h:1106
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:3131
const llvm::APInt & getSize() const
Definition: Type.h:3152
Represents a shadow constructor declaration introduced into a class by a C++11 using-declaration that...
Definition: DeclCXX.h:3552
UsingDecl * getIntroducer() const
Override the UsingShadowDecl's getIntroducer, returning the UsingDecl that introduced this.
Definition: DeclCXX.h:3608
static ConstructorUsingShadowDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:3065
static ConstructorUsingShadowDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation Loc, UsingDecl *Using, NamedDecl *Target, bool IsVirtual)
Definition: DeclCXX.cpp:3057
CXXRecordDecl * getNominatedBaseClass() const
Get the base class that was named in the using declaration.
Definition: DeclCXX.cpp:3069
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1347
reference front() const
Definition: DeclBase.h:1370
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
Definition: DeclBase.h:2226
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1409
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1951
ASTContext & getParentASTContext() const
Definition: DeclBase.h:1980
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1209
bool isNamespace() const
Definition: DeclBase.h:2035
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1728
bool isTranslationUnit() const
Definition: DeclBase.h:2026
bool isFunctionOrMethod() const
Definition: DeclBase.h:2003
bool isExternCContext() const
Determines whether this context or some of its ancestors is a linkage specification context that spec...
Definition: DeclBase.cpp:1260
LinkageSpecDeclBitfields LinkageSpecDeclBits
Definition: DeclBase.h:1892
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
Definition: DeclBase.h:1029
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:428
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Definition: DeclBase.h:1194
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:429
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:576
ASTMutationListener * getASTMutationListener() const
Definition: DeclBase.cpp:439
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:86
bool isCanonicalDecl() const
Whether this particular Decl is a canonical one.
Definition: DeclBase.h:952
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
Definition: DeclBase.cpp:228
bool isInvalidDecl() const
Definition: DeclBase.h:571
SourceLocation getLocation() const
Definition: DeclBase.h:432
void setImplicit(bool I=true)
Definition: DeclBase.h:577
DeclContext * getDeclContext()
Definition: DeclBase.h:441
AccessSpecifier getAccess() const
Definition: DeclBase.h:491
bool hasAttr() const
Definition: DeclBase.h:560
const LangOptions & getLangOpts() const LLVM_READONLY
Helper to get the language options from the ASTContext.
Definition: DeclBase.cpp:435
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:4119
void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override
Pretty-print the unqualified name of this declaration.
Definition: DeclCXX.cpp:3316
ArrayRef< BindingDecl * > bindings() const
Definition: DeclCXX.h:4151
static DecompositionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation LSquareLoc, QualType T, TypeSourceInfo *TInfo, StorageClass S, ArrayRef< BindingDecl * > Bindings)
Definition: DeclCXX.cpp:3290
static DecompositionDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned NumBindings)
Definition: DeclCXX.cpp:3301
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:4959
Store information needed for an explicit specifier.
Definition: DeclCXX.h:1882
ExplicitSpecKind getKind() const
Definition: DeclCXX.h:1890
const Expr * getExpr() const
Definition: DeclCXX.h:1891
static ExplicitSpecifier getFromDecl(FunctionDecl *Function)
Definition: DeclCXX.cpp:2102
bool isEquivalent(const ExplicitSpecifier Other) const
Check for equivalence of explicit specifiers.
Definition: DeclCXX.cpp:2087
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:3060
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:2962
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition: Decl.cpp:4456
Represents a function declaration or definition.
Definition: Decl.h:1919
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:2626
bool isTrivialForCall() const
Definition: Decl.h:2277
bool isPure() const
Whether this virtual function is pure, i.e.
Definition: Decl.h:2257
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to call this function.
Definition: Decl.cpp:3637
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:3952
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
Definition: Decl.cpp:3411
bool UsesFPIntrin() const
Determine whether the function was declared in source context that requires constrained FP intrinsics...
Definition: Decl.h:2721
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:4017
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition: Decl.h:2274
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
Definition: Decl.cpp:4066
bool isVariadic() const
Whether this function is variadic.
Definition: Decl.cpp:3062
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition: Decl.h:2230
bool isDeleted() const
Whether this function has been deleted.
Definition: Decl.h:2437
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:2700
bool isOutOfLine() const override
Determine whether this is or was instantiated from an out-of-line definition of a member function.
Definition: Decl.cpp:4258
bool isIneligibleOrNotSelected() const
Definition: Decl.h:2315
void setIneligibleOrNotSelected(bool II)
Definition: Decl.h:2318
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any.
Definition: Decl.cpp:3889
bool isUserProvided() const
True if this method is user-declared and was not deleted or defaulted on its first declaration.
Definition: Decl.h:2307
bool hasOneParamOrDefaultArgs() const
Determine whether this function has a single parameter, or multiple parameters where all but the firs...
Definition: Decl.cpp:3655
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3616
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:3141
bool willHaveBody() const
True if this function will eventually have a body, once it's fully parsed.
Definition: Decl.h:2530
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4117
Qualifiers getMethodQuals() const
Definition: Type.h:4475
Declaration of a template function.
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3751
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:3237
Description of a constructor that was inherited from a base class.
Definition: DeclCXX.h:2462
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:2995
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).
APValue * getOrCreateValue(bool MayCreate) const
Get the storage for the constant value of a materialized temporary of static storage duration.
Definition: DeclCXX.cpp:3012
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
Definition: DeclCXX.cpp:2996
Represents a linkage specification.
Definition: DeclCXX.h:2884
static LinkageSpecDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:2863
static LinkageSpecDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation ExternLoc, SourceLocation LangLoc, LanguageIDs Lang, bool HasBraces)
Definition: DeclCXX.cpp:2854
LanguageIDs
Represents the language in a linkage specification.
Definition: DeclCXX.h:2893
A global _GUID constant.
Definition: DeclCXX.h:4242
APValue & getAsAPValue() const
Get the value of this MSGuidDecl as an APValue.
Definition: DeclCXX.cpp:3422
MSGuidDeclParts Parts
Definition: DeclCXX.h:4244
void printName(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const override
Print this UUID in a human-readable format.
Definition: DeclCXX.cpp:3362
An instance of this class represents the declaration of a property member.
Definition: DeclCXX.h:4188
static MSPropertyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName N, QualType T, TypeSourceInfo *TInfo, SourceLocation StartL, IdentifierInfo *Getter, IdentifierInfo *Setter)
Definition: DeclCXX.cpp:3331
static MSPropertyDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:3340
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:3031
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:632
This represents a decl that may have a name.
Definition: Decl.h:247
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition: Decl.h:459
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:274
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:313
NamedDecl * getMostRecentDecl()
Definition: Decl.h:473
Represents a C++ namespace alias.
Definition: DeclCXX.h:3074
static NamespaceAliasDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation NamespaceLoc, SourceLocation AliasLoc, IdentifierInfo *Alias, NestedNameSpecifierLoc QualifierLoc, SourceLocation IdentLoc, NamedDecl *Namespace)
Definition: DeclCXX.cpp:2971
static NamespaceAliasDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:2986
Represent a C++ namespace.
Definition: Decl.h:544
static NamespaceDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:2924
bool isOriginalNamespace() const
Return true if this declaration is an original (first) declaration of the namespace.
Definition: DeclCXX.cpp:2943
NamespaceDecl * getOriginalNamespace()
Get the original (first) namespace declaration.
Definition: DeclCXX.cpp:2929
static NamespaceDecl * Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl, bool Nested)
Definition: DeclCXX.cpp:2916
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:557
unsigned CalculateHash()
Definition: ODRHash.cpp:214
MapType::iterator iterator
Represents a parameter to a function.
Definition: Decl.h:1724
A (possibly-)qualified type.
Definition: Type.h:736
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition: Type.h:6830
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:6787
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:2504
bool isObjCGCStrong() const
true when Type is objc's strong.
Definition: Type.h:1220
bool isConstQualified() const
Determine whether this type is const-qualified.
Definition: Type.h:6819
unsigned getCVRQualifiers() const
Retrieve the set of CVR (const-volatile-restrict) qualifiers applied to this type.
Definition: Type.h:6793
bool hasNonTrivialObjCLifetime() const
Definition: Type.h:1229
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
Definition: Type.h:174
@ OCL_Weak
Reading or writing from this object requires a barrier call.
Definition: Type.h:177
ObjCLifetime getObjCLifetime() const
Definition: Type.h:351
Represents a struct/union/class.
Definition: Decl.h:4036
field_iterator field_end() const
Definition: Decl.h:4266
field_range fields() const
Definition: Decl.h:4263
void setHasObjectMember(bool val)
Definition: Decl.h:4119
void setHasVolatileMember(bool val)
Definition: Decl.h:4123
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition: Decl.cpp:4966
@ APK_CanNeverPassInRegs
The argument of this type cannot be passed directly in registers.
Definition: Decl.h:4062
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition: Decl.h:4248
void setArgPassingRestrictions(ArgPassingKind Kind)
Definition: Decl.h:4195
bool field_empty() const
Definition: Decl.h:4271
field_iterator field_begin() const
Definition: Decl.cpp:4954
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4933
RecordDecl * getDecl() const
Definition: Type.h:4943
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:2951
Represents the body of a requires-expression.
Definition: DeclCXX.h:2013
static RequiresExprBodyDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:2137
static RequiresExprBodyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc)
Definition: DeclCXX.cpp:2132
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:4011
static StaticAssertDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StaticAssertLoc, Expr *AssertExpr, Expr *Message, SourceLocation RParenLoc, bool Failed)
Definition: DeclCXX.cpp:3239
static StaticAssertDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:3248
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
Definition: Diagnostic.h:1110
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition: Decl.h:3600
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:3538
bool isStruct() const
Definition: Decl.h:3678
bool isUnion() const
Definition: Decl.h:3681
void setBeingDefined(bool V=true)
True if this decl is currently being defined.
Definition: Decl.h:3532
bool isInterface() const
Definition: Decl.h:3679
TagKind getTagKind() const
Definition: Decl.h:3672
Exposes information about the current target.
Definition: TargetInfo.h:207
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:3309
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:59
A container of type source information.
Definition: Type.h:6718
The base class of the type hierarchy.
Definition: Type.h:1597
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1823
bool isBlockPointerType() const
Definition: Type.h:7007
bool isLiteralType(const ASTContext &Ctx) const
Return true if this is a literal type (C++11 [basic.types]p10)
Definition: Type.cpp:2793
bool isUnsignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is unsigned or an enumeration types whose underlying ...
Definition: Type.cpp:2158
bool isRValueReferenceType() const
Definition: Type.h:7019
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7590
bool isReferenceType() const
Definition: Type.h:7011
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:655
bool isLValueReferenceType() const
Definition: Type.h:7015
bool isStructuralType() const
Determine if this type is a structural type, per C++20 [temp.param]p7.
Definition: Type.cpp:2858
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2365
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7523
bool isRecordType() const
Definition: Type.h:7089
bool isObjCRetainableType() const
Definition: Type.cpp:4616
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:1831
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition: Type.cpp:1827
An artificial decl, representing a global anonymous constant value which is uniquified by value withi...
Definition: DeclCXX.h:4299
void printName(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const override
Print this in a human-readable format.
Definition: DeclCXX.cpp:3472
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:3993
static UnresolvedUsingIfExistsDecl * Create(ASTContext &Ctx, DeclContext *DC, SourceLocation Loc, DeclarationName Name)
Definition: DeclCXX.cpp:3219
static UnresolvedUsingIfExistsDecl * CreateDeserialized(ASTContext &Ctx, unsigned ID)
Definition: DeclCXX.cpp:3225
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3912
static UnresolvedUsingTypenameDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TargetNameLoc, DeclarationName TargetName, SourceLocation EllipsisLoc)
Definition: DeclCXX.cpp:3199
static UnresolvedUsingTypenameDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:3212
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3815
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no 'using').
Definition: DeclCXX.h:3852
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition: DeclCXX.h:3856
static UnresolvedUsingValueDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:3182
DeclarationNameInfo getNameInfo() const
Definition: DeclCXX.h:3863
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclCXX.cpp:3190
static UnresolvedUsingValueDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, SourceLocation EllipsisLoc)
Definition: DeclCXX.cpp:3171
Represents a C++ using-declaration.
Definition: DeclCXX.h:3466
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no 'using').
Definition: DeclCXX.h:3512
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclCXX.cpp:3119
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition: DeclCXX.h:3500
DeclarationNameInfo getNameInfo() const
Definition: DeclCXX.h:3507
static UsingDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingL, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword)
Definition: DeclCXX.cpp:3106
static UsingDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:3113
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Definition: DeclCXX.h:3503
Represents C++ using-directive.
Definition: DeclCXX.h:2969
static UsingDirectiveDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, SourceLocation NamespaceLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation IdentLoc, NamedDecl *Nominated, DeclContext *CommonAncestor)
Definition: DeclCXX.cpp:2871
static UsingDirectiveDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:2884
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
Definition: DeclCXX.cpp:2892
Represents a C++ using-enum-declaration.
Definition: DeclCXX.h:3666
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclCXX.cpp:3143
static UsingEnumDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:3137
static UsingEnumDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingL, SourceLocation EnumL, SourceLocation NameL, TypeSourceInfo *EnumType)
Definition: DeclCXX.cpp:3127
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition: DeclCXX.h:3747
static UsingPackDecl * Create(ASTContext &C, DeclContext *DC, NamedDecl *InstantiatedFrom, ArrayRef< NamedDecl * > UsingDecls)
Definition: DeclCXX.cpp:3149
static UsingPackDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned NumExpansions)
Definition: DeclCXX.cpp:3156
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3274
void setTargetDecl(NamedDecl *ND)
Sets the underlying declaration which has been brought into the local scope.
Definition: DeclCXX.h:3342
static UsingShadowDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:3042
UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC, SourceLocation Loc, DeclarationName Name, BaseUsingDecl *Introducer, NamedDecl *Target)
Definition: DeclCXX.cpp:3025
BaseUsingDecl * getIntroducer() const
Gets the (written or instantiated) using declaration that introduced this declaration.
Definition: DeclCXX.cpp:3046
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:703
QualType getType() const
Definition: Decl.h:714
VarDecl * getPotentiallyDecomposedVarDecl()
Definition: DeclCXX.cpp:3254
Represents a variable declaration or definition.
Definition: Decl.h:915
Defines the clang::TargetInfo interface.
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:203
@ CPlusPlus20
Definition: LangStandard.h:57
@ CPlusPlus14
Definition: LangStandard.h:55
ConstexprSpecKind
Define the kind of constexpr specifier.
Definition: Specifiers.h:35
StorageClass
Storage classes.
Definition: Specifiers.h:239
@ SC_Static
Definition: Specifiers.h:243
@ SC_None
Definition: Specifiers.h:241
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)
Insertion operator for diagnostics.
@ C
Languages that the frontend can parse and compile.
StorageDuration
The storage duration for an object (per C++ [basic.stc]).
Definition: Specifiers.h:314
@ SD_Static
Static storage duration.
Definition: Specifiers.h:318
@ SD_FullExpression
Full-expression storage duration (for temporaries).
Definition: Specifiers.h:315
@ SD_Automatic
Automatic storage duration (most local variables).
Definition: Specifiers.h:316
@ Result
The result type of a method or function.
TagTypeKind
The kind of a tag type.
Definition: Type.h:5659
@ TTK_Class
The "class" keyword.
Definition: Type.h:5670
@ TTK_Struct
The "struct" keyword.
Definition: Type.h:5661
@ TTK_Interface
The "__interface" keyword.
Definition: Type.h:5664
LambdaCaptureDefault
The default, if any, capture method for a lambda expression.
Definition: Lambda.h:22
@ LCD_None
Definition: Lambda.h:23
StringRef getLambdaStaticInvokerName()
Definition: ASTLambda.h:22
DeductionCandidate
Only used by CXXDeductionGuideDecl.
Definition: DeclBase.h:1386
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition: DeclBase.h:1253
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:179
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...
Definition: Specifiers.h:182
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:269
U cast(CodeGen::Address addr)
Definition: Address.h:152
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:114
@ AS_public
Definition: Specifiers.h:115
@ AS_protected
Definition: Specifiers.h:116
@ AS_none
Definition: Specifiers.h:118
@ AS_private
Definition: Specifiers.h:117
__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:1787
A placeholder type used to construct an empty shell of a decl-derived type that will be filled in lat...
Definition: DeclBase.h:99
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:4221
uint32_t Part1
{01234567-...
Definition: DeclCXX.h:4219
uint16_t Part3
...-cdef-...
Definition: DeclCXX.h:4223
uint8_t Part4And5[8]
...-0123-456789abcdef}
Definition: DeclCXX.h:4225
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57