1 //===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Defines the C++ Decl subclasses, other than those for templates
12 /// (found in DeclTemplate.h) and friends (in DeclFriend.h).
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CLANG_AST_DECLCXX_H
17 #define LLVM_CLANG_AST_DECLCXX_H
19 #include "clang/AST/ASTContext.h"
20 #include "clang/AST/ASTUnresolvedSet.h"
21 #include "clang/AST/Attr.h"
22 #include "clang/AST/Decl.h"
23 #include "clang/AST/Expr.h"
24 #include "clang/AST/LambdaCapture.h"
25 #include "llvm/ADT/DenseMap.h"
26 #include "llvm/ADT/PointerIntPair.h"
27 #include "llvm/Support/Compiler.h"
31 class ClassTemplateDecl;
32 class ClassTemplateSpecializationDecl;
33 class ConstructorUsingShadowDecl;
36 class CXXConstructorDecl;
37 class CXXConversionDecl;
38 class CXXDestructorDecl;
41 class CXXMemberLookupCriteria;
42 class CXXFinalOverriderMap;
43 class CXXIndirectPrimaryBaseSet;
48 /// \brief Represents any kind of function declaration, whether it is a
49 /// concrete function or a function template.
50 class AnyFunctionDecl {
53 AnyFunctionDecl(NamedDecl *ND) : Function(ND) { }
56 AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { }
57 AnyFunctionDecl(FunctionTemplateDecl *FTD);
59 /// \brief Implicily converts any function or function template into a
60 /// named declaration.
61 operator NamedDecl *() const { return Function; }
63 /// \brief Retrieve the underlying function or function template.
64 NamedDecl *get() const { return Function; }
66 static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
67 return AnyFunctionDecl(ND);
71 } // end namespace clang
74 // Provide PointerLikeTypeTraits for non-cvr pointers.
76 class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
78 static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
81 static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
82 return ::clang::AnyFunctionDecl::getFromNamedDecl(
83 static_cast< ::clang::NamedDecl*>(P));
86 enum { NumLowBitsAvailable = 2 };
89 } // end namespace llvm
93 /// \brief Represents an access specifier followed by colon ':'.
95 /// An objects of this class represents sugar for the syntactic occurrence
96 /// of an access specifier followed by a colon in the list of member
97 /// specifiers of a C++ class definition.
99 /// Note that they do not represent other uses of access specifiers,
100 /// such as those occurring in a list of base specifiers.
101 /// Also note that this class has nothing to do with so-called
102 /// "access declarations" (C++98 11.3 [class.access.dcl]).
103 class AccessSpecDecl : public Decl {
104 virtual void anchor();
105 /// \brief The location of the ':'.
106 SourceLocation ColonLoc;
108 AccessSpecDecl(AccessSpecifier AS, DeclContext *DC,
109 SourceLocation ASLoc, SourceLocation ColonLoc)
110 : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) {
113 AccessSpecDecl(EmptyShell Empty)
114 : Decl(AccessSpec, Empty) { }
116 /// \brief The location of the access specifier.
117 SourceLocation getAccessSpecifierLoc() const { return getLocation(); }
118 /// \brief Sets the location of the access specifier.
119 void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); }
121 /// \brief The location of the colon following the access specifier.
122 SourceLocation getColonLoc() const { return ColonLoc; }
123 /// \brief Sets the location of the colon.
124 void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; }
126 SourceRange getSourceRange() const override LLVM_READONLY {
127 return SourceRange(getAccessSpecifierLoc(), getColonLoc());
130 static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS,
131 DeclContext *DC, SourceLocation ASLoc,
132 SourceLocation ColonLoc) {
133 return new (C, DC) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
135 static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
137 // Implement isa/cast/dyncast/etc.
138 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
139 static bool classofKind(Kind K) { return K == AccessSpec; }
142 /// \brief Represents a base class of a C++ class.
144 /// Each CXXBaseSpecifier represents a single, direct base class (or
145 /// struct) of a C++ class (or struct). It specifies the type of that
146 /// base class, whether it is a virtual or non-virtual base, and what
147 /// level of access (public, protected, private) is used for the
148 /// derivation. For example:
153 /// class C : public virtual A, protected B { };
156 /// In this code, C will have two CXXBaseSpecifiers, one for "public
157 /// virtual A" and the other for "protected B".
158 class CXXBaseSpecifier {
159 /// \brief The source code range that covers the full base
160 /// specifier, including the "virtual" (if present) and access
161 /// specifier (if present).
164 /// \brief The source location of the ellipsis, if this is a pack
166 SourceLocation EllipsisLoc;
168 /// \brief Whether this is a virtual base class or not.
169 unsigned Virtual : 1;
171 /// \brief Whether this is the base of a class (true) or of a struct (false).
173 /// This determines the mapping from the access specifier as written in the
174 /// source code to the access specifier used for semantic analysis.
175 unsigned BaseOfClass : 1;
177 /// \brief Access specifier as written in the source code (may be AS_none).
179 /// The actual type of data stored here is an AccessSpecifier, but we use
180 /// "unsigned" here to work around a VC++ bug.
183 /// \brief Whether the class contains a using declaration
184 /// to inherit the named class's constructors.
185 unsigned InheritConstructors : 1;
187 /// \brief The type of the base class.
189 /// This will be a class or struct (or a typedef of such). The source code
190 /// range does not include the \c virtual or the access specifier.
191 TypeSourceInfo *BaseTypeInfo;
194 CXXBaseSpecifier() { }
196 CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A,
197 TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
198 : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC),
199 Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) { }
201 /// \brief Retrieves the source range that contains the entire base specifier.
202 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
203 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
204 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
206 /// \brief Determines whether the base class is a virtual base class (or not).
207 bool isVirtual() const { return Virtual; }
209 /// \brief Determine whether this base class is a base of a class declared
210 /// with the 'class' keyword (vs. one declared with the 'struct' keyword).
211 bool isBaseOfClass() const { return BaseOfClass; }
213 /// \brief Determine whether this base specifier is a pack expansion.
214 bool isPackExpansion() const { return EllipsisLoc.isValid(); }
216 /// \brief Determine whether this base class's constructors get inherited.
217 bool getInheritConstructors() const { return InheritConstructors; }
219 /// \brief Set that this base class's constructors should be inherited.
220 void setInheritConstructors(bool Inherit = true) {
221 InheritConstructors = Inherit;
224 /// \brief For a pack expansion, determine the location of the ellipsis.
225 SourceLocation getEllipsisLoc() const {
229 /// \brief Returns the access specifier for this base specifier.
231 /// This is the actual base specifier as used for semantic analysis, so
232 /// the result can never be AS_none. To retrieve the access specifier as
233 /// written in the source code, use getAccessSpecifierAsWritten().
234 AccessSpecifier getAccessSpecifier() const {
235 if ((AccessSpecifier)Access == AS_none)
236 return BaseOfClass? AS_private : AS_public;
238 return (AccessSpecifier)Access;
241 /// \brief Retrieves the access specifier as written in the source code
242 /// (which may mean that no access specifier was explicitly written).
244 /// Use getAccessSpecifier() to retrieve the access specifier for use in
245 /// semantic analysis.
246 AccessSpecifier getAccessSpecifierAsWritten() const {
247 return (AccessSpecifier)Access;
250 /// \brief Retrieves the type of the base class.
252 /// This type will always be an unqualified class type.
253 QualType getType() const {
254 return BaseTypeInfo->getType().getUnqualifiedType();
257 /// \brief Retrieves the type and source location of the base class.
258 TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; }
261 /// \brief Represents a C++ struct/union/class.
262 class CXXRecordDecl : public RecordDecl {
264 friend void TagDecl::startDefinition();
266 /// Values used in DefinitionData fields to represent special members.
267 enum SpecialMemberFlags {
268 SMF_DefaultConstructor = 0x1,
269 SMF_CopyConstructor = 0x2,
270 SMF_MoveConstructor = 0x4,
271 SMF_CopyAssignment = 0x8,
272 SMF_MoveAssignment = 0x10,
273 SMF_Destructor = 0x20,
277 struct DefinitionData {
278 DefinitionData(CXXRecordDecl *D);
280 /// \brief True if this class has any user-declared constructors.
281 unsigned UserDeclaredConstructor : 1;
283 /// \brief The user-declared special members which this class has.
284 unsigned UserDeclaredSpecialMembers : 6;
286 /// \brief True when this class is an aggregate.
287 unsigned Aggregate : 1;
289 /// \brief True when this class is a POD-type.
290 unsigned PlainOldData : 1;
292 /// true when this class is empty for traits purposes,
293 /// i.e. has no data members other than 0-width bit-fields, has no
294 /// virtual function/base, and doesn't inherit from a non-empty
295 /// class. Doesn't take union-ness into account.
298 /// \brief True when this class is polymorphic, i.e., has at
299 /// least one virtual member or derives from a polymorphic class.
300 unsigned Polymorphic : 1;
302 /// \brief True when this class is abstract, i.e., has at least
303 /// one pure virtual function, (that can come from a base class).
304 unsigned Abstract : 1;
306 /// \brief True when this class has standard layout.
308 /// C++11 [class]p7. A standard-layout class is a class that:
309 /// * has no non-static data members of type non-standard-layout class (or
310 /// array of such types) or reference,
311 /// * has no virtual functions (10.3) and no virtual base classes (10.1),
312 /// * has the same access control (Clause 11) for all non-static data
314 /// * has no non-standard-layout base classes,
315 /// * either has no non-static data members in the most derived class and at
316 /// most one base class with non-static data members, or has no base
317 /// classes with non-static data members, and
318 /// * has no base classes of the same type as the first non-static data
320 unsigned IsStandardLayout : 1;
322 /// \brief True when there are no non-empty base classes.
324 /// This is a helper bit of state used to implement IsStandardLayout more
326 unsigned HasNoNonEmptyBases : 1;
328 /// \brief True when there are private non-static data members.
329 unsigned HasPrivateFields : 1;
331 /// \brief True when there are protected non-static data members.
332 unsigned HasProtectedFields : 1;
334 /// \brief True when there are private non-static data members.
335 unsigned HasPublicFields : 1;
337 /// \brief True if this class (or any subobject) has mutable fields.
338 unsigned HasMutableFields : 1;
340 /// \brief True if this class (or any nested anonymous struct or union)
341 /// has variant members.
342 unsigned HasVariantMembers : 1;
344 /// \brief True if there no non-field members declared by the user.
345 unsigned HasOnlyCMembers : 1;
347 /// \brief True if any field has an in-class initializer, including those
348 /// within anonymous unions or structs.
349 unsigned HasInClassInitializer : 1;
351 /// \brief True if any field is of reference type, and does not have an
352 /// in-class initializer.
354 /// In this case, value-initialization of this class is illegal in C++98
355 /// even if the class has a trivial default constructor.
356 unsigned HasUninitializedReferenceMember : 1;
358 /// \brief True if any non-mutable field whose type doesn't have a user-
359 /// provided default ctor also doesn't have an in-class initializer.
360 unsigned HasUninitializedFields : 1;
362 /// \brief True if there are any member using-declarations that inherit
363 /// constructors from a base class.
364 unsigned HasInheritedConstructor : 1;
366 /// \brief True if there are any member using-declarations named
368 unsigned HasInheritedAssignment : 1;
370 /// \brief These flags are \c true if a defaulted corresponding special
371 /// member can't be fully analyzed without performing overload resolution.
373 unsigned NeedOverloadResolutionForMoveConstructor : 1;
374 unsigned NeedOverloadResolutionForMoveAssignment : 1;
375 unsigned NeedOverloadResolutionForDestructor : 1;
378 /// \brief These flags are \c true if an implicit defaulted corresponding
379 /// special member would be defined as deleted.
381 unsigned DefaultedMoveConstructorIsDeleted : 1;
382 unsigned DefaultedMoveAssignmentIsDeleted : 1;
383 unsigned DefaultedDestructorIsDeleted : 1;
386 /// \brief The trivial special members which this class has, per
387 /// C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25,
388 /// C++11 [class.dtor]p5, or would have if the member were not suppressed.
390 /// This excludes any user-declared but not user-provided special members
391 /// which have been declared but not yet defined.
392 unsigned HasTrivialSpecialMembers : 6;
394 /// \brief The declared special members of this class which are known to be
397 /// This excludes any user-declared but not user-provided special members
398 /// which have been declared but not yet defined, and any implicit special
399 /// members which have not yet been declared.
400 unsigned DeclaredNonTrivialSpecialMembers : 6;
402 /// \brief True when this class has a destructor with no semantic effect.
403 unsigned HasIrrelevantDestructor : 1;
405 /// \brief True when this class has at least one user-declared constexpr
406 /// constructor which is neither the copy nor move constructor.
407 unsigned HasConstexprNonCopyMoveConstructor : 1;
409 /// \brief True if this class has a (possibly implicit) defaulted default
411 unsigned HasDefaultedDefaultConstructor : 1;
413 /// \brief True if a defaulted default constructor for this class would
415 unsigned DefaultedDefaultConstructorIsConstexpr : 1;
417 /// \brief True if this class has a constexpr default constructor.
419 /// This is true for either a user-declared constexpr default constructor
420 /// or an implicitly declared constexpr default constructor.
421 unsigned HasConstexprDefaultConstructor : 1;
423 /// \brief True when this class contains at least one non-static data
424 /// member or base class of non-literal or volatile type.
425 unsigned HasNonLiteralTypeFieldsOrBases : 1;
427 /// \brief True when visible conversion functions are already computed
428 /// and are available.
429 unsigned ComputedVisibleConversions : 1;
431 /// \brief Whether we have a C++11 user-provided default constructor (not
432 /// explicitly deleted or defaulted).
433 unsigned UserProvidedDefaultConstructor : 1;
435 /// \brief The special members which have been declared for this class,
436 /// either by the user or implicitly.
437 unsigned DeclaredSpecialMembers : 6;
439 /// \brief Whether an implicit copy constructor would have a const-qualified
441 unsigned ImplicitCopyConstructorHasConstParam : 1;
443 /// \brief Whether an implicit copy assignment operator would have a
444 /// const-qualified parameter.
445 unsigned ImplicitCopyAssignmentHasConstParam : 1;
447 /// \brief Whether any declared copy constructor has a const-qualified
449 unsigned HasDeclaredCopyConstructorWithConstParam : 1;
451 /// \brief Whether any declared copy assignment operator has either a
452 /// const-qualified reference parameter or a non-reference parameter.
453 unsigned HasDeclaredCopyAssignmentWithConstParam : 1;
455 /// \brief Whether this class describes a C++ lambda.
456 unsigned IsLambda : 1;
458 /// \brief Whether we are currently parsing base specifiers.
459 unsigned IsParsingBaseSpecifiers : 1;
461 /// \brief The number of base class specifiers in Bases.
464 /// \brief The number of virtual base class specifiers in VBases.
467 /// \brief Base classes of this class.
469 /// FIXME: This is wasted space for a union.
470 LazyCXXBaseSpecifiersPtr Bases;
472 /// \brief direct and indirect virtual base classes of this class.
473 LazyCXXBaseSpecifiersPtr VBases;
475 /// \brief The conversion functions of this C++ class (but not its
476 /// inherited conversion functions).
478 /// Each of the entries in this overload set is a CXXConversionDecl.
479 LazyASTUnresolvedSet Conversions;
481 /// \brief The conversion functions of this C++ class and all those
482 /// inherited conversion functions that are visible in this class.
484 /// Each of the entries in this overload set is a CXXConversionDecl or a
485 /// FunctionTemplateDecl.
486 LazyASTUnresolvedSet VisibleConversions;
488 /// \brief The declaration which defines this record.
489 CXXRecordDecl *Definition;
491 /// \brief The first friend declaration in this class, or null if there
494 /// This is actually currently stored in reverse order.
495 LazyDeclPtr FirstFriend;
497 /// \brief Retrieve the set of direct base classes.
498 CXXBaseSpecifier *getBases() const {
499 if (!Bases.isOffset())
500 return Bases.get(nullptr);
501 return getBasesSlowCase();
504 /// \brief Retrieve the set of virtual base classes.
505 CXXBaseSpecifier *getVBases() const {
506 if (!VBases.isOffset())
507 return VBases.get(nullptr);
508 return getVBasesSlowCase();
511 ArrayRef<CXXBaseSpecifier> bases() const {
512 return llvm::makeArrayRef(getBases(), NumBases);
514 ArrayRef<CXXBaseSpecifier> vbases() const {
515 return llvm::makeArrayRef(getVBases(), NumVBases);
519 CXXBaseSpecifier *getBasesSlowCase() const;
520 CXXBaseSpecifier *getVBasesSlowCase() const;
523 struct DefinitionData *DefinitionData;
525 /// \brief Describes a C++ closure type (generated by a lambda expression).
526 struct LambdaDefinitionData : public DefinitionData {
527 typedef LambdaCapture Capture;
529 LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info,
530 bool Dependent, bool IsGeneric,
531 LambdaCaptureDefault CaptureDefault)
532 : DefinitionData(D), Dependent(Dependent), IsGenericLambda(IsGeneric),
533 CaptureDefault(CaptureDefault), NumCaptures(0), NumExplicitCaptures(0),
534 ManglingNumber(0), ContextDecl(nullptr), Captures(nullptr),
538 // C++1z [expr.prim.lambda]p4:
539 // This class type is not an aggregate type.
541 PlainOldData = false;
544 /// \brief Whether this lambda is known to be dependent, even if its
545 /// context isn't dependent.
547 /// A lambda with a non-dependent context can be dependent if it occurs
548 /// within the default argument of a function template, because the
549 /// lambda will have been created with the enclosing context as its
550 /// declaration context, rather than function. This is an unfortunate
551 /// artifact of having to parse the default arguments before.
552 unsigned Dependent : 1;
554 /// \brief Whether this lambda is a generic lambda.
555 unsigned IsGenericLambda : 1;
557 /// \brief The Default Capture.
558 unsigned CaptureDefault : 2;
560 /// \brief The number of captures in this lambda is limited 2^NumCaptures.
561 unsigned NumCaptures : 15;
563 /// \brief The number of explicit captures in this lambda.
564 unsigned NumExplicitCaptures : 13;
566 /// \brief The number used to indicate this lambda expression for name
567 /// mangling in the Itanium C++ ABI.
568 unsigned ManglingNumber;
570 /// \brief The declaration that provides context for this lambda, if the
571 /// actual DeclContext does not suffice. This is used for lambdas that
572 /// occur within default arguments of function parameters within the class
573 /// or within a data member initializer.
574 LazyDeclPtr ContextDecl;
576 /// \brief The list of captures, both explicit and implicit, for this
580 /// \brief The type of the call method.
581 TypeSourceInfo *MethodTyInfo;
585 struct DefinitionData *dataPtr() const {
586 // Complete the redecl chain (if necessary).
588 return DefinitionData;
591 struct DefinitionData &data() const {
592 auto *DD = dataPtr();
593 assert(DD && "queried property of class with no definition");
597 struct LambdaDefinitionData &getLambdaData() const {
598 // No update required: a merged definition cannot change any lambda
600 auto *DD = DefinitionData;
601 assert(DD && DD->IsLambda && "queried lambda property of non-lambda class");
602 return static_cast<LambdaDefinitionData&>(*DD);
605 /// \brief The template or declaration that this declaration
606 /// describes or was instantiated from, respectively.
608 /// For non-templates, this value will be null. For record
609 /// declarations that describe a class template, this will be a
610 /// pointer to a ClassTemplateDecl. For member
611 /// classes of class template specializations, this will be the
612 /// MemberSpecializationInfo referring to the member class that was
613 /// instantiated or specialized.
614 llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*>
615 TemplateOrInstantiation;
617 friend class DeclContext;
618 friend class LambdaExpr;
620 /// \brief Called from setBases and addedMember to notify the class that a
621 /// direct or virtual base class or a member of class type has been added.
622 void addedClassSubobject(CXXRecordDecl *Base);
624 /// \brief Notify the class that member has been added.
626 /// This routine helps maintain information about the class based on which
627 /// members have been added. It will be invoked by DeclContext::addDecl()
628 /// whenever a member is added to this record.
629 void addedMember(Decl *D);
631 void markedVirtualFunctionPure();
632 friend void FunctionDecl::setPure(bool);
634 friend class ASTNodeImporter;
636 /// \brief Get the head of our list of friend declarations, possibly
637 /// deserializing the friends from an external AST source.
638 FriendDecl *getFirstFriend() const;
641 CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, DeclContext *DC,
642 SourceLocation StartLoc, SourceLocation IdLoc,
643 IdentifierInfo *Id, CXXRecordDecl *PrevDecl);
646 /// \brief Iterator that traverses the base classes of a class.
647 typedef CXXBaseSpecifier* base_class_iterator;
649 /// \brief Iterator that traverses the base classes of a class.
650 typedef const CXXBaseSpecifier* base_class_const_iterator;
652 CXXRecordDecl *getCanonicalDecl() override {
653 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
655 const CXXRecordDecl *getCanonicalDecl() const {
656 return const_cast<CXXRecordDecl*>(this)->getCanonicalDecl();
659 CXXRecordDecl *getPreviousDecl() {
660 return cast_or_null<CXXRecordDecl>(
661 static_cast<RecordDecl *>(this)->getPreviousDecl());
663 const CXXRecordDecl *getPreviousDecl() const {
664 return const_cast<CXXRecordDecl*>(this)->getPreviousDecl();
667 CXXRecordDecl *getMostRecentDecl() {
668 return cast<CXXRecordDecl>(
669 static_cast<RecordDecl *>(this)->getMostRecentDecl());
672 const CXXRecordDecl *getMostRecentDecl() const {
673 return const_cast<CXXRecordDecl*>(this)->getMostRecentDecl();
676 CXXRecordDecl *getDefinition() const {
677 // We only need an update if we don't already know which
678 // declaration is the definition.
679 auto *DD = DefinitionData ? DefinitionData : dataPtr();
680 return DD ? DD->Definition : nullptr;
683 bool hasDefinition() const { return DefinitionData || dataPtr(); }
685 static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
686 SourceLocation StartLoc, SourceLocation IdLoc,
688 CXXRecordDecl *PrevDecl = nullptr,
689 bool DelayTypeCreation = false);
690 static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC,
691 TypeSourceInfo *Info, SourceLocation Loc,
692 bool DependentLambda, bool IsGeneric,
693 LambdaCaptureDefault CaptureDefault);
694 static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
696 bool isDynamicClass() const {
697 return data().Polymorphic || data().NumVBases != 0;
700 void setIsParsingBaseSpecifiers() { data().IsParsingBaseSpecifiers = true; }
702 bool isParsingBaseSpecifiers() const {
703 return data().IsParsingBaseSpecifiers;
706 /// \brief Sets the base classes of this struct or class.
707 void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
709 /// \brief Retrieves the number of base classes of this class.
710 unsigned getNumBases() const { return data().NumBases; }
712 typedef llvm::iterator_range<base_class_iterator> base_class_range;
713 typedef llvm::iterator_range<base_class_const_iterator>
714 base_class_const_range;
716 base_class_range bases() {
717 return base_class_range(bases_begin(), bases_end());
719 base_class_const_range bases() const {
720 return base_class_const_range(bases_begin(), bases_end());
723 base_class_iterator bases_begin() { return data().getBases(); }
724 base_class_const_iterator bases_begin() const { return data().getBases(); }
725 base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
726 base_class_const_iterator bases_end() const {
727 return bases_begin() + data().NumBases;
730 /// \brief Retrieves the number of virtual base classes of this class.
731 unsigned getNumVBases() const { return data().NumVBases; }
733 base_class_range vbases() {
734 return base_class_range(vbases_begin(), vbases_end());
736 base_class_const_range vbases() const {
737 return base_class_const_range(vbases_begin(), vbases_end());
740 base_class_iterator vbases_begin() { return data().getVBases(); }
741 base_class_const_iterator vbases_begin() const { return data().getVBases(); }
742 base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
743 base_class_const_iterator vbases_end() const {
744 return vbases_begin() + data().NumVBases;
747 /// \brief Determine whether this class has any dependent base classes which
748 /// are not the current instantiation.
749 bool hasAnyDependentBases() const;
751 /// Iterator access to method members. The method iterator visits
752 /// all method members of the class, including non-instance methods,
753 /// special methods, etc.
754 typedef specific_decl_iterator<CXXMethodDecl> method_iterator;
755 typedef llvm::iterator_range<specific_decl_iterator<CXXMethodDecl>>
758 method_range methods() const {
759 return method_range(method_begin(), method_end());
762 /// \brief Method begin iterator. Iterates in the order the methods
764 method_iterator method_begin() const {
765 return method_iterator(decls_begin());
767 /// \brief Method past-the-end iterator.
768 method_iterator method_end() const {
769 return method_iterator(decls_end());
772 /// Iterator access to constructor members.
773 typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator;
774 typedef llvm::iterator_range<specific_decl_iterator<CXXConstructorDecl>>
777 ctor_range ctors() const { return ctor_range(ctor_begin(), ctor_end()); }
779 ctor_iterator ctor_begin() const {
780 return ctor_iterator(decls_begin());
782 ctor_iterator ctor_end() const {
783 return ctor_iterator(decls_end());
786 /// An iterator over friend declarations. All of these are defined
788 class friend_iterator;
789 typedef llvm::iterator_range<friend_iterator> friend_range;
791 friend_range friends() const;
792 friend_iterator friend_begin() const;
793 friend_iterator friend_end() const;
794 void pushFriendDecl(FriendDecl *FD);
796 /// Determines whether this record has any friends.
797 bool hasFriends() const {
798 return data().FirstFriend.isValid();
801 /// \brief \c true if we know for sure that this class has a single,
802 /// accessible, unambiguous move constructor that is not deleted.
803 bool hasSimpleMoveConstructor() const {
804 return !hasUserDeclaredMoveConstructor() && hasMoveConstructor() &&
805 !data().DefaultedMoveConstructorIsDeleted;
807 /// \brief \c true if we know for sure that this class has a single,
808 /// accessible, unambiguous move assignment operator that is not deleted.
809 bool hasSimpleMoveAssignment() const {
810 return !hasUserDeclaredMoveAssignment() && hasMoveAssignment() &&
811 !data().DefaultedMoveAssignmentIsDeleted;
813 /// \brief \c true if we know for sure that this class has an accessible
814 /// destructor that is not deleted.
815 bool hasSimpleDestructor() const {
816 return !hasUserDeclaredDestructor() &&
817 !data().DefaultedDestructorIsDeleted;
820 /// \brief Determine whether this class has any default constructors.
821 bool hasDefaultConstructor() const {
822 return (data().DeclaredSpecialMembers & SMF_DefaultConstructor) ||
823 needsImplicitDefaultConstructor();
826 /// \brief Determine if we need to declare a default constructor for
829 /// This value is used for lazy creation of default constructors.
830 bool needsImplicitDefaultConstructor() const {
831 return !data().UserDeclaredConstructor &&
832 !(data().DeclaredSpecialMembers & SMF_DefaultConstructor) &&
833 // C++14 [expr.prim.lambda]p20:
834 // The closure type associated with a lambda-expression has no
835 // default constructor.
839 /// \brief Determine whether this class has any user-declared constructors.
841 /// When true, a default constructor will not be implicitly declared.
842 bool hasUserDeclaredConstructor() const {
843 return data().UserDeclaredConstructor;
846 /// \brief Whether this class has a user-provided default constructor
848 bool hasUserProvidedDefaultConstructor() const {
849 return data().UserProvidedDefaultConstructor;
852 /// \brief Determine whether this class has a user-declared copy constructor.
854 /// When false, a copy constructor will be implicitly declared.
855 bool hasUserDeclaredCopyConstructor() const {
856 return data().UserDeclaredSpecialMembers & SMF_CopyConstructor;
859 /// \brief Determine whether this class needs an implicit copy
860 /// constructor to be lazily declared.
861 bool needsImplicitCopyConstructor() const {
862 return !(data().DeclaredSpecialMembers & SMF_CopyConstructor);
865 /// \brief Determine whether we need to eagerly declare a defaulted copy
866 /// constructor for this class.
867 bool needsOverloadResolutionForCopyConstructor() const {
868 return data().HasMutableFields;
871 /// \brief Determine whether an implicit copy constructor for this type
872 /// would have a parameter with a const-qualified reference type.
873 bool implicitCopyConstructorHasConstParam() const {
874 return data().ImplicitCopyConstructorHasConstParam;
877 /// \brief Determine whether this class has a copy constructor with
878 /// a parameter type which is a reference to a const-qualified type.
879 bool hasCopyConstructorWithConstParam() const {
880 return data().HasDeclaredCopyConstructorWithConstParam ||
881 (needsImplicitCopyConstructor() &&
882 implicitCopyConstructorHasConstParam());
885 /// \brief Whether this class has a user-declared move constructor or
886 /// assignment operator.
888 /// When false, a move constructor and assignment operator may be
889 /// implicitly declared.
890 bool hasUserDeclaredMoveOperation() const {
891 return data().UserDeclaredSpecialMembers &
892 (SMF_MoveConstructor | SMF_MoveAssignment);
895 /// \brief Determine whether this class has had a move constructor
896 /// declared by the user.
897 bool hasUserDeclaredMoveConstructor() const {
898 return data().UserDeclaredSpecialMembers & SMF_MoveConstructor;
901 /// \brief Determine whether this class has a move constructor.
902 bool hasMoveConstructor() const {
903 return (data().DeclaredSpecialMembers & SMF_MoveConstructor) ||
904 needsImplicitMoveConstructor();
907 /// \brief Set that we attempted to declare an implicitly move
908 /// constructor, but overload resolution failed so we deleted it.
909 void setImplicitMoveConstructorIsDeleted() {
910 assert((data().DefaultedMoveConstructorIsDeleted ||
911 needsOverloadResolutionForMoveConstructor()) &&
912 "move constructor should not be deleted");
913 data().DefaultedMoveConstructorIsDeleted = true;
916 /// \brief Determine whether this class should get an implicit move
917 /// constructor or if any existing special member function inhibits this.
918 bool needsImplicitMoveConstructor() const {
919 return !(data().DeclaredSpecialMembers & SMF_MoveConstructor) &&
920 !hasUserDeclaredCopyConstructor() &&
921 !hasUserDeclaredCopyAssignment() &&
922 !hasUserDeclaredMoveAssignment() &&
923 !hasUserDeclaredDestructor();
926 /// \brief Determine whether we need to eagerly declare a defaulted move
927 /// constructor for this class.
928 bool needsOverloadResolutionForMoveConstructor() const {
929 return data().NeedOverloadResolutionForMoveConstructor;
932 /// \brief Determine whether this class has a user-declared copy assignment
935 /// When false, a copy assigment operator will be implicitly declared.
936 bool hasUserDeclaredCopyAssignment() const {
937 return data().UserDeclaredSpecialMembers & SMF_CopyAssignment;
940 /// \brief Determine whether this class needs an implicit copy
941 /// assignment operator to be lazily declared.
942 bool needsImplicitCopyAssignment() const {
943 return !(data().DeclaredSpecialMembers & SMF_CopyAssignment);
946 /// \brief Determine whether we need to eagerly declare a defaulted copy
947 /// assignment operator for this class.
948 bool needsOverloadResolutionForCopyAssignment() const {
949 return data().HasMutableFields;
952 /// \brief Determine whether an implicit copy assignment operator for this
953 /// type would have a parameter with a const-qualified reference type.
954 bool implicitCopyAssignmentHasConstParam() const {
955 return data().ImplicitCopyAssignmentHasConstParam;
958 /// \brief Determine whether this class has a copy assignment operator with
959 /// a parameter type which is a reference to a const-qualified type or is not
961 bool hasCopyAssignmentWithConstParam() const {
962 return data().HasDeclaredCopyAssignmentWithConstParam ||
963 (needsImplicitCopyAssignment() &&
964 implicitCopyAssignmentHasConstParam());
967 /// \brief Determine whether this class has had a move assignment
968 /// declared by the user.
969 bool hasUserDeclaredMoveAssignment() const {
970 return data().UserDeclaredSpecialMembers & SMF_MoveAssignment;
973 /// \brief Determine whether this class has a move assignment operator.
974 bool hasMoveAssignment() const {
975 return (data().DeclaredSpecialMembers & SMF_MoveAssignment) ||
976 needsImplicitMoveAssignment();
979 /// \brief Set that we attempted to declare an implicit move assignment
980 /// operator, but overload resolution failed so we deleted it.
981 void setImplicitMoveAssignmentIsDeleted() {
982 assert((data().DefaultedMoveAssignmentIsDeleted ||
983 needsOverloadResolutionForMoveAssignment()) &&
984 "move assignment should not be deleted");
985 data().DefaultedMoveAssignmentIsDeleted = true;
988 /// \brief Determine whether this class should get an implicit move
989 /// assignment operator or if any existing special member function inhibits
991 bool needsImplicitMoveAssignment() const {
992 return !(data().DeclaredSpecialMembers & SMF_MoveAssignment) &&
993 !hasUserDeclaredCopyConstructor() &&
994 !hasUserDeclaredCopyAssignment() &&
995 !hasUserDeclaredMoveConstructor() &&
996 !hasUserDeclaredDestructor() &&
997 // C++1z [expr.prim.lambda]p21: "the closure type has a deleted copy
998 // assignment operator". The intent is that this counts as a user
999 // declared copy assignment, but we do not model it that way.
1003 /// \brief Determine whether we need to eagerly declare a move assignment
1004 /// operator for this class.
1005 bool needsOverloadResolutionForMoveAssignment() const {
1006 return data().NeedOverloadResolutionForMoveAssignment;
1009 /// \brief Determine whether this class has a user-declared destructor.
1011 /// When false, a destructor will be implicitly declared.
1012 bool hasUserDeclaredDestructor() const {
1013 return data().UserDeclaredSpecialMembers & SMF_Destructor;
1016 /// \brief Determine whether this class needs an implicit destructor to
1017 /// be lazily declared.
1018 bool needsImplicitDestructor() const {
1019 return !(data().DeclaredSpecialMembers & SMF_Destructor);
1022 /// \brief Determine whether we need to eagerly declare a destructor for this
1024 bool needsOverloadResolutionForDestructor() const {
1025 return data().NeedOverloadResolutionForDestructor;
1028 /// \brief Determine whether this class describes a lambda function object.
1029 bool isLambda() const {
1030 // An update record can't turn a non-lambda into a lambda.
1031 auto *DD = DefinitionData;
1032 return DD && DD->IsLambda;
1035 /// \brief Determine whether this class describes a generic
1036 /// lambda function object (i.e. function call operator is
1038 bool isGenericLambda() const;
1040 /// \brief Retrieve the lambda call operator of the closure type
1041 /// if this is a closure type.
1042 CXXMethodDecl *getLambdaCallOperator() const;
1044 /// \brief Retrieve the lambda static invoker, the address of which
1045 /// is returned by the conversion operator, and the body of which
1046 /// is forwarded to the lambda call operator.
1047 CXXMethodDecl *getLambdaStaticInvoker() const;
1049 /// \brief Retrieve the generic lambda's template parameter list.
1050 /// Returns null if the class does not represent a lambda or a generic
1052 TemplateParameterList *getGenericLambdaTemplateParameterList() const;
1054 LambdaCaptureDefault getLambdaCaptureDefault() const {
1056 return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault);
1059 /// \brief For a closure type, retrieve the mapping from captured
1060 /// variables and \c this to the non-static data members that store the
1061 /// values or references of the captures.
1063 /// \param Captures Will be populated with the mapping from captured
1064 /// variables to the corresponding fields.
1066 /// \param ThisCapture Will be set to the field declaration for the
1067 /// \c this capture.
1069 /// \note No entries will be added for init-captures, as they do not capture
1071 void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures,
1072 FieldDecl *&ThisCapture) const;
1074 typedef const LambdaCapture *capture_const_iterator;
1075 typedef llvm::iterator_range<capture_const_iterator> capture_const_range;
1077 capture_const_range captures() const {
1078 return capture_const_range(captures_begin(), captures_end());
1080 capture_const_iterator captures_begin() const {
1081 return isLambda() ? getLambdaData().Captures : nullptr;
1083 capture_const_iterator captures_end() const {
1084 return isLambda() ? captures_begin() + getLambdaData().NumCaptures
1088 typedef UnresolvedSetIterator conversion_iterator;
1089 conversion_iterator conversion_begin() const {
1090 return data().Conversions.get(getASTContext()).begin();
1092 conversion_iterator conversion_end() const {
1093 return data().Conversions.get(getASTContext()).end();
1096 /// Removes a conversion function from this class. The conversion
1097 /// function must currently be a member of this class. Furthermore,
1098 /// this class must currently be in the process of being defined.
1099 void removeConversion(const NamedDecl *Old);
1101 /// \brief Get all conversion functions visible in current class,
1102 /// including conversion function templates.
1103 llvm::iterator_range<conversion_iterator> getVisibleConversionFunctions();
1105 /// Determine whether this class is an aggregate (C++ [dcl.init.aggr]),
1106 /// which is a class with no user-declared constructors, no private
1107 /// or protected non-static data members, no base classes, and no virtual
1108 /// functions (C++ [dcl.init.aggr]p1).
1109 bool isAggregate() const { return data().Aggregate; }
1111 /// \brief Whether this class has any in-class initializers
1112 /// for non-static data members (including those in anonymous unions or
1114 bool hasInClassInitializer() const { return data().HasInClassInitializer; }
1116 /// \brief Whether this class or any of its subobjects has any members of
1117 /// reference type which would make value-initialization ill-formed.
1119 /// Per C++03 [dcl.init]p5:
1120 /// - if T is a non-union class type without a user-declared constructor,
1121 /// then every non-static data member and base-class component of T is
1122 /// value-initialized [...] A program that calls for [...]
1123 /// value-initialization of an entity of reference type is ill-formed.
1124 bool hasUninitializedReferenceMember() const {
1125 return !isUnion() && !hasUserDeclaredConstructor() &&
1126 data().HasUninitializedReferenceMember;
1129 /// \brief Whether this class is a POD-type (C++ [class]p4)
1131 /// For purposes of this function a class is POD if it is an aggregate
1132 /// that has no non-static non-POD data members, no reference data
1133 /// members, no user-defined copy assignment operator and no
1134 /// user-defined destructor.
1136 /// Note that this is the C++ TR1 definition of POD.
1137 bool isPOD() const { return data().PlainOldData; }
1139 /// \brief True if this class is C-like, without C++-specific features, e.g.
1140 /// it contains only public fields, no bases, tag kind is not 'class', etc.
1141 bool isCLike() const;
1143 /// \brief Determine whether this is an empty class in the sense of
1144 /// (C++11 [meta.unary.prop]).
1146 /// The CXXRecordDecl is a class type, but not a union type,
1147 /// with no non-static data members other than bit-fields of length 0,
1148 /// no virtual member functions, no virtual base classes,
1149 /// and no base class B for which is_empty<B>::value is false.
1151 /// \note This does NOT include a check for union-ness.
1152 bool isEmpty() const { return data().Empty; }
1154 /// \brief Determine whether this class has direct non-static data members.
1155 bool hasDirectFields() const {
1157 return D.HasPublicFields || D.HasProtectedFields || D.HasPrivateFields;
1160 /// Whether this class is polymorphic (C++ [class.virtual]),
1161 /// which means that the class contains or inherits a virtual function.
1162 bool isPolymorphic() const { return data().Polymorphic; }
1164 /// \brief Determine whether this class has a pure virtual function.
1166 /// The class is is abstract per (C++ [class.abstract]p2) if it declares
1167 /// a pure virtual function or inherits a pure virtual function that is
1169 bool isAbstract() const { return data().Abstract; }
1171 /// \brief Determine whether this class has standard layout per
1173 bool isStandardLayout() const { return data().IsStandardLayout; }
1175 /// \brief Determine whether this class, or any of its class subobjects,
1176 /// contains a mutable field.
1177 bool hasMutableFields() const { return data().HasMutableFields; }
1179 /// \brief Determine whether this class has any variant members.
1180 bool hasVariantMembers() const { return data().HasVariantMembers; }
1182 /// \brief Determine whether this class has a trivial default constructor
1183 /// (C++11 [class.ctor]p5).
1184 bool hasTrivialDefaultConstructor() const {
1185 return hasDefaultConstructor() &&
1186 (data().HasTrivialSpecialMembers & SMF_DefaultConstructor);
1189 /// \brief Determine whether this class has a non-trivial default constructor
1190 /// (C++11 [class.ctor]p5).
1191 bool hasNonTrivialDefaultConstructor() const {
1192 return (data().DeclaredNonTrivialSpecialMembers & SMF_DefaultConstructor) ||
1193 (needsImplicitDefaultConstructor() &&
1194 !(data().HasTrivialSpecialMembers & SMF_DefaultConstructor));
1197 /// \brief Determine whether this class has at least one constexpr constructor
1198 /// other than the copy or move constructors.
1199 bool hasConstexprNonCopyMoveConstructor() const {
1200 return data().HasConstexprNonCopyMoveConstructor ||
1201 (needsImplicitDefaultConstructor() &&
1202 defaultedDefaultConstructorIsConstexpr());
1205 /// \brief Determine whether a defaulted default constructor for this class
1206 /// would be constexpr.
1207 bool defaultedDefaultConstructorIsConstexpr() const {
1208 return data().DefaultedDefaultConstructorIsConstexpr &&
1209 (!isUnion() || hasInClassInitializer() || !hasVariantMembers());
1212 /// \brief Determine whether this class has a constexpr default constructor.
1213 bool hasConstexprDefaultConstructor() const {
1214 return data().HasConstexprDefaultConstructor ||
1215 (needsImplicitDefaultConstructor() &&
1216 defaultedDefaultConstructorIsConstexpr());
1219 /// \brief Determine whether this class has a trivial copy constructor
1220 /// (C++ [class.copy]p6, C++11 [class.copy]p12)
1221 bool hasTrivialCopyConstructor() const {
1222 return data().HasTrivialSpecialMembers & SMF_CopyConstructor;
1225 /// \brief Determine whether this class has a non-trivial copy constructor
1226 /// (C++ [class.copy]p6, C++11 [class.copy]p12)
1227 bool hasNonTrivialCopyConstructor() const {
1228 return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor ||
1229 !hasTrivialCopyConstructor();
1232 /// \brief Determine whether this class has a trivial move constructor
1233 /// (C++11 [class.copy]p12)
1234 bool hasTrivialMoveConstructor() const {
1235 return hasMoveConstructor() &&
1236 (data().HasTrivialSpecialMembers & SMF_MoveConstructor);
1239 /// \brief Determine whether this class has a non-trivial move constructor
1240 /// (C++11 [class.copy]p12)
1241 bool hasNonTrivialMoveConstructor() const {
1242 return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveConstructor) ||
1243 (needsImplicitMoveConstructor() &&
1244 !(data().HasTrivialSpecialMembers & SMF_MoveConstructor));
1247 /// \brief Determine whether this class has a trivial copy assignment operator
1248 /// (C++ [class.copy]p11, C++11 [class.copy]p25)
1249 bool hasTrivialCopyAssignment() const {
1250 return data().HasTrivialSpecialMembers & SMF_CopyAssignment;
1253 /// \brief Determine whether this class has a non-trivial copy assignment
1254 /// operator (C++ [class.copy]p11, C++11 [class.copy]p25)
1255 bool hasNonTrivialCopyAssignment() const {
1256 return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment ||
1257 !hasTrivialCopyAssignment();
1260 /// \brief Determine whether this class has a trivial move assignment operator
1261 /// (C++11 [class.copy]p25)
1262 bool hasTrivialMoveAssignment() const {
1263 return hasMoveAssignment() &&
1264 (data().HasTrivialSpecialMembers & SMF_MoveAssignment);
1267 /// \brief Determine whether this class has a non-trivial move assignment
1268 /// operator (C++11 [class.copy]p25)
1269 bool hasNonTrivialMoveAssignment() const {
1270 return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveAssignment) ||
1271 (needsImplicitMoveAssignment() &&
1272 !(data().HasTrivialSpecialMembers & SMF_MoveAssignment));
1275 /// \brief Determine whether this class has a trivial destructor
1276 /// (C++ [class.dtor]p3)
1277 bool hasTrivialDestructor() const {
1278 return data().HasTrivialSpecialMembers & SMF_Destructor;
1281 /// \brief Determine whether this class has a non-trivial destructor
1282 /// (C++ [class.dtor]p3)
1283 bool hasNonTrivialDestructor() const {
1284 return !(data().HasTrivialSpecialMembers & SMF_Destructor);
1287 /// \brief Determine whether declaring a const variable with this type is ok
1288 /// per core issue 253.
1289 bool allowConstDefaultInit() const {
1290 return !data().HasUninitializedFields ||
1291 !(data().HasDefaultedDefaultConstructor ||
1292 needsImplicitDefaultConstructor());
1295 /// \brief Determine whether this class has a destructor which has no
1296 /// semantic effect.
1298 /// Any such destructor will be trivial, public, defaulted and not deleted,
1299 /// and will call only irrelevant destructors.
1300 bool hasIrrelevantDestructor() const {
1301 return data().HasIrrelevantDestructor;
1304 /// \brief Determine whether this class has a non-literal or/ volatile type
1305 /// non-static data member or base class.
1306 bool hasNonLiteralTypeFieldsOrBases() const {
1307 return data().HasNonLiteralTypeFieldsOrBases;
1310 /// \brief Determine whether this class has a using-declaration that names
1311 /// a user-declared base class constructor.
1312 bool hasInheritedConstructor() const {
1313 return data().HasInheritedConstructor;
1316 /// \brief Determine whether this class has a using-declaration that names
1317 /// a base class assignment operator.
1318 bool hasInheritedAssignment() const {
1319 return data().HasInheritedAssignment;
1322 /// \brief Determine whether this class is considered trivially copyable per
1323 /// (C++11 [class]p6).
1324 bool isTriviallyCopyable() const;
1326 /// \brief Determine whether this class is considered trivial.
1328 /// C++11 [class]p6:
1329 /// "A trivial class is a class that has a trivial default constructor and
1330 /// is trivially copiable."
1331 bool isTrivial() const {
1332 return isTriviallyCopyable() && hasTrivialDefaultConstructor();
1335 /// \brief Determine whether this class is a literal type.
1337 /// C++11 [basic.types]p10:
1338 /// A class type that has all the following properties:
1339 /// - it has a trivial destructor
1340 /// - every constructor call and full-expression in the
1341 /// brace-or-equal-intializers for non-static data members (if any) is
1342 /// a constant expression.
1343 /// - it is an aggregate type or has at least one constexpr constructor
1344 /// or constructor template that is not a copy or move constructor, and
1345 /// - all of its non-static data members and base classes are of literal
1348 /// We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by
1349 /// treating types with trivial default constructors as literal types.
1351 /// Only in C++1z and beyond, are lambdas literal types.
1352 bool isLiteral() const {
1353 return hasTrivialDestructor() &&
1354 (!isLambda() || getASTContext().getLangOpts().CPlusPlus1z) &&
1355 !hasNonLiteralTypeFieldsOrBases() &&
1356 (isAggregate() || isLambda() ||
1357 hasConstexprNonCopyMoveConstructor() ||
1358 hasTrivialDefaultConstructor());
1361 /// \brief If this record is an instantiation of a member class,
1362 /// retrieves the member class from which it was instantiated.
1364 /// This routine will return non-null for (non-templated) member
1365 /// classes of class templates. For example, given:
1368 /// template<typename T>
1374 /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
1375 /// whose parent is the class template specialization X<int>. For
1376 /// this declaration, getInstantiatedFromMemberClass() will return
1377 /// the CXXRecordDecl X<T>::A. When a complete definition of
1378 /// X<int>::A is required, it will be instantiated from the
1379 /// declaration returned by getInstantiatedFromMemberClass().
1380 CXXRecordDecl *getInstantiatedFromMemberClass() const;
1382 /// \brief If this class is an instantiation of a member class of a
1383 /// class template specialization, retrieves the member specialization
1385 MemberSpecializationInfo *getMemberSpecializationInfo() const;
1387 /// \brief Specify that this record is an instantiation of the
1388 /// member class \p RD.
1389 void setInstantiationOfMemberClass(CXXRecordDecl *RD,
1390 TemplateSpecializationKind TSK);
1392 /// \brief Retrieves the class template that is described by this
1393 /// class declaration.
1395 /// Every class template is represented as a ClassTemplateDecl and a
1396 /// CXXRecordDecl. The former contains template properties (such as
1397 /// the template parameter lists) while the latter contains the
1398 /// actual description of the template's
1399 /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
1400 /// CXXRecordDecl that from a ClassTemplateDecl, while
1401 /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
1402 /// a CXXRecordDecl.
1403 ClassTemplateDecl *getDescribedClassTemplate() const;
1405 void setDescribedClassTemplate(ClassTemplateDecl *Template);
1407 /// \brief Determine whether this particular class is a specialization or
1408 /// instantiation of a class template or member class of a class template,
1409 /// and how it was instantiated or specialized.
1410 TemplateSpecializationKind getTemplateSpecializationKind() const;
1412 /// \brief Set the kind of specialization or template instantiation this is.
1413 void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
1415 /// \brief Retrieve the record declaration from which this record could be
1416 /// instantiated. Returns null if this class is not a template instantiation.
1417 const CXXRecordDecl *getTemplateInstantiationPattern() const;
1419 CXXRecordDecl *getTemplateInstantiationPattern() {
1420 return const_cast<CXXRecordDecl *>(const_cast<const CXXRecordDecl *>(this)
1421 ->getTemplateInstantiationPattern());
1424 /// \brief Returns the destructor decl for this class.
1425 CXXDestructorDecl *getDestructor() const;
1427 /// \brief Returns true if the class destructor, or any implicitly invoked
1428 /// destructors are marked noreturn.
1429 bool isAnyDestructorNoReturn() const;
1431 /// \brief If the class is a local class [class.local], returns
1432 /// the enclosing function declaration.
1433 const FunctionDecl *isLocalClass() const {
1434 if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
1435 return RD->isLocalClass();
1437 return dyn_cast<FunctionDecl>(getDeclContext());
1440 FunctionDecl *isLocalClass() {
1441 return const_cast<FunctionDecl*>(
1442 const_cast<const CXXRecordDecl*>(this)->isLocalClass());
1445 /// \brief Determine whether this dependent class is a current instantiation,
1446 /// when viewed from within the given context.
1447 bool isCurrentInstantiation(const DeclContext *CurContext) const;
1449 /// \brief Determine whether this class is derived from the class \p Base.
1451 /// This routine only determines whether this class is derived from \p Base,
1452 /// but does not account for factors that may make a Derived -> Base class
1453 /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1454 /// base class subobjects.
1456 /// \param Base the base class we are searching for.
1458 /// \returns true if this class is derived from Base, false otherwise.
1459 bool isDerivedFrom(const CXXRecordDecl *Base) const;
1461 /// \brief Determine whether this class is derived from the type \p Base.
1463 /// This routine only determines whether this class is derived from \p Base,
1464 /// but does not account for factors that may make a Derived -> Base class
1465 /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1466 /// base class subobjects.
1468 /// \param Base the base class we are searching for.
1470 /// \param Paths will contain the paths taken from the current class to the
1471 /// given \p Base class.
1473 /// \returns true if this class is derived from \p Base, false otherwise.
1475 /// \todo add a separate parameter to configure IsDerivedFrom, rather than
1476 /// tangling input and output in \p Paths
1477 bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const;
1479 /// \brief Determine whether this class is virtually derived from
1480 /// the class \p Base.
1482 /// This routine only determines whether this class is virtually
1483 /// derived from \p Base, but does not account for factors that may
1484 /// make a Derived -> Base class ill-formed, such as
1485 /// private/protected inheritance or multiple, ambiguous base class
1488 /// \param Base the base class we are searching for.
1490 /// \returns true if this class is virtually derived from Base,
1491 /// false otherwise.
1492 bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const;
1494 /// \brief Determine whether this class is provably not derived from
1495 /// the type \p Base.
1496 bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
1498 /// \brief Function type used by forallBases() as a callback.
1500 /// \param BaseDefinition the definition of the base class
1502 /// \returns true if this base matched the search criteria
1503 typedef llvm::function_ref<bool(const CXXRecordDecl *BaseDefinition)>
1504 ForallBasesCallback;
1506 /// \brief Determines if the given callback holds for all the direct
1507 /// or indirect base classes of this type.
1509 /// The class itself does not count as a base class. This routine
1510 /// returns false if the class has non-computable base classes.
1512 /// \param BaseMatches Callback invoked for each (direct or indirect) base
1513 /// class of this type, or if \p AllowShortCircuit is true then until a call
1516 /// \param AllowShortCircuit if false, forces the callback to be called
1517 /// for every base class, even if a dependent or non-matching base was
1519 bool forallBases(ForallBasesCallback BaseMatches,
1520 bool AllowShortCircuit = true) const;
1522 /// \brief Function type used by lookupInBases() to determine whether a
1523 /// specific base class subobject matches the lookup criteria.
1525 /// \param Specifier the base-class specifier that describes the inheritance
1526 /// from the base class we are trying to match.
1528 /// \param Path the current path, from the most-derived class down to the
1529 /// base named by the \p Specifier.
1531 /// \returns true if this base matched the search criteria, false otherwise.
1532 typedef llvm::function_ref<bool(const CXXBaseSpecifier *Specifier,
1533 CXXBasePath &Path)> BaseMatchesCallback;
1535 /// \brief Look for entities within the base classes of this C++ class,
1536 /// transitively searching all base class subobjects.
1538 /// This routine uses the callback function \p BaseMatches to find base
1539 /// classes meeting some search criteria, walking all base class subobjects
1540 /// and populating the given \p Paths structure with the paths through the
1541 /// inheritance hierarchy that resulted in a match. On a successful search,
1542 /// the \p Paths structure can be queried to retrieve the matching paths and
1543 /// to determine if there were any ambiguities.
1545 /// \param BaseMatches callback function used to determine whether a given
1546 /// base matches the user-defined search criteria.
1548 /// \param Paths used to record the paths from this class to its base class
1549 /// subobjects that match the search criteria.
1551 /// \returns true if there exists any path from this class to a base class
1552 /// subobject that matches the search criteria.
1553 bool lookupInBases(BaseMatchesCallback BaseMatches,
1554 CXXBasePaths &Paths) const;
1556 /// \brief Base-class lookup callback that determines whether the given
1557 /// base class specifier refers to a specific class declaration.
1559 /// This callback can be used with \c lookupInBases() to determine whether
1560 /// a given derived class has is a base class subobject of a particular type.
1561 /// The base record pointer should refer to the canonical CXXRecordDecl of the
1562 /// base class that we are searching for.
1563 static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
1564 CXXBasePath &Path, const CXXRecordDecl *BaseRecord);
1566 /// \brief Base-class lookup callback that determines whether the
1567 /// given base class specifier refers to a specific class
1568 /// declaration and describes virtual derivation.
1570 /// This callback can be used with \c lookupInBases() to determine
1571 /// whether a given derived class has is a virtual base class
1572 /// subobject of a particular type. The base record pointer should
1573 /// refer to the canonical CXXRecordDecl of the base class that we
1574 /// are searching for.
1575 static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
1577 const CXXRecordDecl *BaseRecord);
1579 /// \brief Base-class lookup callback that determines whether there exists
1580 /// a tag with the given name.
1582 /// This callback can be used with \c lookupInBases() to find tag members
1583 /// of the given name within a C++ class hierarchy.
1584 static bool FindTagMember(const CXXBaseSpecifier *Specifier,
1585 CXXBasePath &Path, DeclarationName Name);
1587 /// \brief Base-class lookup callback that determines whether there exists
1588 /// a member with the given name.
1590 /// This callback can be used with \c lookupInBases() to find members
1591 /// of the given name within a C++ class hierarchy.
1592 static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
1593 CXXBasePath &Path, DeclarationName Name);
1595 /// \brief Base-class lookup callback that determines whether there exists
1596 /// an OpenMP declare reduction member with the given name.
1598 /// This callback can be used with \c lookupInBases() to find members
1599 /// of the given name within a C++ class hierarchy.
1600 static bool FindOMPReductionMember(const CXXBaseSpecifier *Specifier,
1601 CXXBasePath &Path, DeclarationName Name);
1603 /// \brief Base-class lookup callback that determines whether there exists
1604 /// a member with the given name that can be used in a nested-name-specifier.
1606 /// This callback can be used with \c lookupInBases() to find members of
1607 /// the given name within a C++ class hierarchy that can occur within
1608 /// nested-name-specifiers.
1609 static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
1611 DeclarationName Name);
1613 /// \brief Retrieve the final overriders for each virtual member
1614 /// function in the class hierarchy where this class is the
1615 /// most-derived class in the class hierarchy.
1616 void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
1618 /// \brief Get the indirect primary bases for this class.
1619 void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const;
1621 /// Renders and displays an inheritance diagram
1622 /// for this C++ class and all of its base classes (transitively) using
1624 void viewInheritance(ASTContext& Context) const;
1626 /// \brief Calculates the access of a decl that is reached
1628 static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
1629 AccessSpecifier DeclAccess) {
1630 assert(DeclAccess != AS_none);
1631 if (DeclAccess == AS_private) return AS_none;
1632 return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
1635 /// \brief Indicates that the declaration of a defaulted or deleted special
1636 /// member function is now complete.
1637 void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD);
1639 /// \brief Indicates that the definition of this class is now complete.
1640 void completeDefinition() override;
1642 /// \brief Indicates that the definition of this class is now complete,
1643 /// and provides a final overrider map to help determine
1645 /// \param FinalOverriders The final overrider map for this class, which can
1646 /// be provided as an optimization for abstract-class checking. If NULL,
1647 /// final overriders will be computed if they are needed to complete the
1649 void completeDefinition(CXXFinalOverriderMap *FinalOverriders);
1651 /// \brief Determine whether this class may end up being abstract, even though
1652 /// it is not yet known to be abstract.
1654 /// \returns true if this class is not known to be abstract but has any
1655 /// base classes that are abstract. In this case, \c completeDefinition()
1656 /// will need to compute final overriders to determine whether the class is
1657 /// actually abstract.
1658 bool mayBeAbstract() const;
1660 /// \brief If this is the closure type of a lambda expression, retrieve the
1661 /// number to be used for name mangling in the Itanium C++ ABI.
1663 /// Zero indicates that this closure type has internal linkage, so the
1664 /// mangling number does not matter, while a non-zero value indicates which
1665 /// lambda expression this is in this particular context.
1666 unsigned getLambdaManglingNumber() const {
1667 assert(isLambda() && "Not a lambda closure type!");
1668 return getLambdaData().ManglingNumber;
1671 /// \brief Retrieve the declaration that provides additional context for a
1672 /// lambda, when the normal declaration context is not specific enough.
1674 /// Certain contexts (default arguments of in-class function parameters and
1675 /// the initializers of data members) have separate name mangling rules for
1676 /// lambdas within the Itanium C++ ABI. For these cases, this routine provides
1677 /// the declaration in which the lambda occurs, e.g., the function parameter
1678 /// or the non-static data member. Otherwise, it returns NULL to imply that
1679 /// the declaration context suffices.
1680 Decl *getLambdaContextDecl() const;
1682 /// \brief Set the mangling number and context declaration for a lambda
1684 void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl) {
1685 getLambdaData().ManglingNumber = ManglingNumber;
1686 getLambdaData().ContextDecl = ContextDecl;
1689 /// \brief Returns the inheritance model used for this record.
1690 MSInheritanceAttr::Spelling getMSInheritanceModel() const;
1691 /// \brief Calculate what the inheritance model would be for this class.
1692 MSInheritanceAttr::Spelling calculateInheritanceModel() const;
1694 /// In the Microsoft C++ ABI, use zero for the field offset of a null data
1695 /// member pointer if we can guarantee that zero is not a valid field offset,
1696 /// or if the member pointer has multiple fields. Polymorphic classes have a
1697 /// vfptr at offset zero, so we can use zero for null. If there are multiple
1698 /// fields, we can use zero even if it is a valid field offset because
1699 /// null-ness testing will check the other fields.
1700 bool nullFieldOffsetIsZero() const {
1701 return !MSInheritanceAttr::hasOnlyOneField(/*IsMemberFunction=*/false,
1702 getMSInheritanceModel()) ||
1703 (hasDefinition() && isPolymorphic());
1706 /// \brief Controls when vtordisps will be emitted if this record is used as a
1708 MSVtorDispAttr::Mode getMSVtorDispMode() const;
1710 /// \brief Determine whether this lambda expression was known to be dependent
1711 /// at the time it was created, even if its context does not appear to be
1714 /// This flag is a workaround for an issue with parsing, where default
1715 /// arguments are parsed before their enclosing function declarations have
1716 /// been created. This means that any lambda expressions within those
1717 /// default arguments will have as their DeclContext the context enclosing
1718 /// the function declaration, which may be non-dependent even when the
1719 /// function declaration itself is dependent. This flag indicates when we
1720 /// know that the lambda is dependent despite that.
1721 bool isDependentLambda() const {
1722 return isLambda() && getLambdaData().Dependent;
1725 TypeSourceInfo *getLambdaTypeInfo() const {
1726 return getLambdaData().MethodTyInfo;
1729 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1730 static bool classofKind(Kind K) {
1731 return K >= firstCXXRecord && K <= lastCXXRecord;
1734 friend class ASTDeclReader;
1735 friend class ASTDeclWriter;
1736 friend class ASTRecordWriter;
1737 friend class ASTReader;
1738 friend class ASTWriter;
1741 /// \brief Represents a static or instance method of a struct/union/class.
1743 /// In the terminology of the C++ Standard, these are the (static and
1744 /// non-static) member functions, whether virtual or not.
1745 class CXXMethodDecl : public FunctionDecl {
1746 void anchor() override;
1748 CXXMethodDecl(Kind DK, ASTContext &C, CXXRecordDecl *RD,
1749 SourceLocation StartLoc, const DeclarationNameInfo &NameInfo,
1750 QualType T, TypeSourceInfo *TInfo,
1751 StorageClass SC, bool isInline,
1752 bool isConstexpr, SourceLocation EndLocation)
1753 : FunctionDecl(DK, C, RD, StartLoc, NameInfo, T, TInfo,
1754 SC, isInline, isConstexpr) {
1755 if (EndLocation.isValid())
1756 setRangeEnd(EndLocation);
1760 static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1761 SourceLocation StartLoc,
1762 const DeclarationNameInfo &NameInfo,
1763 QualType T, TypeSourceInfo *TInfo,
1767 SourceLocation EndLocation);
1769 static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1771 bool isStatic() const;
1772 bool isInstance() const { return !isStatic(); }
1774 /// Returns true if the given operator is implicitly static in a record
1776 static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK) {
1778 // Any allocation function for a class T is a static member
1779 // (even if not explicitly declared static).
1780 // [class.free]p6 Any deallocation function for a class X is a static member
1781 // (even if not explicitly declared static).
1782 return OOK == OO_New || OOK == OO_Array_New || OOK == OO_Delete ||
1783 OOK == OO_Array_Delete;
1786 bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); }
1787 bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); }
1789 bool isVirtual() const {
1791 cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl());
1793 // Member function is virtual if it is marked explicitly so, or if it is
1794 // declared in __interface -- then it is automatically pure virtual.
1795 if (CD->isVirtualAsWritten() || CD->isPure())
1798 return (CD->begin_overridden_methods() != CD->end_overridden_methods());
1801 /// \brief Determine whether this is a usual deallocation function
1802 /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded
1803 /// delete or delete[] operator with a particular signature.
1804 bool isUsualDeallocationFunction() const;
1806 /// \brief Determine whether this is a copy-assignment operator, regardless
1807 /// of whether it was declared implicitly or explicitly.
1808 bool isCopyAssignmentOperator() const;
1810 /// \brief Determine whether this is a move assignment operator.
1811 bool isMoveAssignmentOperator() const;
1813 CXXMethodDecl *getCanonicalDecl() override {
1814 return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
1816 const CXXMethodDecl *getCanonicalDecl() const {
1817 return const_cast<CXXMethodDecl*>(this)->getCanonicalDecl();
1820 CXXMethodDecl *getMostRecentDecl() {
1821 return cast<CXXMethodDecl>(
1822 static_cast<FunctionDecl *>(this)->getMostRecentDecl());
1824 const CXXMethodDecl *getMostRecentDecl() const {
1825 return const_cast<CXXMethodDecl*>(this)->getMostRecentDecl();
1828 /// True if this method is user-declared and was not
1829 /// deleted or defaulted on its first declaration.
1830 bool isUserProvided() const {
1831 return !(isDeleted() || getCanonicalDecl()->isDefaulted());
1835 void addOverriddenMethod(const CXXMethodDecl *MD);
1837 typedef const CXXMethodDecl *const* method_iterator;
1839 method_iterator begin_overridden_methods() const;
1840 method_iterator end_overridden_methods() const;
1841 unsigned size_overridden_methods() const;
1842 typedef ASTContext::overridden_method_range overridden_method_range;
1843 overridden_method_range overridden_methods() const;
1845 /// Returns the parent of this method declaration, which
1846 /// is the class in which this method is defined.
1847 const CXXRecordDecl *getParent() const {
1848 return cast<CXXRecordDecl>(FunctionDecl::getParent());
1851 /// Returns the parent of this method declaration, which
1852 /// is the class in which this method is defined.
1853 CXXRecordDecl *getParent() {
1854 return const_cast<CXXRecordDecl *>(
1855 cast<CXXRecordDecl>(FunctionDecl::getParent()));
1858 /// \brief Returns the type of the \c this pointer.
1860 /// Should only be called for instance (i.e., non-static) methods.
1861 QualType getThisType(ASTContext &C) const;
1863 unsigned getTypeQualifiers() const {
1864 return getType()->getAs<FunctionProtoType>()->getTypeQuals();
1867 /// \brief Retrieve the ref-qualifier associated with this method.
1869 /// In the following example, \c f() has an lvalue ref-qualifier, \c g()
1870 /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier.
1878 RefQualifierKind getRefQualifier() const {
1879 return getType()->getAs<FunctionProtoType>()->getRefQualifier();
1882 bool hasInlineBody() const;
1884 /// \brief Determine whether this is a lambda closure type's static member
1885 /// function that is used for the result of the lambda's conversion to
1886 /// function pointer (for a lambda with no captures).
1888 /// The function itself, if used, will have a placeholder body that will be
1889 /// supplied by IR generation to either forward to the function call operator
1890 /// or clone the function call operator.
1891 bool isLambdaStaticInvoker() const;
1893 /// \brief Find the method in \p RD that corresponds to this one.
1895 /// Find if \p RD or one of the classes it inherits from override this method.
1896 /// If so, return it. \p RD is assumed to be a subclass of the class defining
1897 /// this method (or be the class itself), unless \p MayBeBase is set to true.
1899 getCorrespondingMethodInClass(const CXXRecordDecl *RD,
1900 bool MayBeBase = false);
1902 const CXXMethodDecl *
1903 getCorrespondingMethodInClass(const CXXRecordDecl *RD,
1904 bool MayBeBase = false) const {
1905 return const_cast<CXXMethodDecl *>(this)
1906 ->getCorrespondingMethodInClass(RD, MayBeBase);
1909 // Implement isa/cast/dyncast/etc.
1910 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1911 static bool classofKind(Kind K) {
1912 return K >= firstCXXMethod && K <= lastCXXMethod;
1916 /// \brief Represents a C++ base or member initializer.
1918 /// This is part of a constructor initializer that
1919 /// initializes one non-static member variable or one base class. For
1920 /// example, in the following, both 'A(a)' and 'f(3.14159)' are member
1925 /// class B : public A {
1928 /// B(A& a) : A(a), f(3.14159) { }
1931 class CXXCtorInitializer final {
1932 /// \brief Either the base class name/delegating constructor type (stored as
1933 /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field
1934 /// (IndirectFieldDecl*) being initialized.
1935 llvm::PointerUnion3<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *>
1938 /// \brief The source location for the field name or, for a base initializer
1939 /// pack expansion, the location of the ellipsis.
1941 /// In the case of a delegating
1942 /// constructor, it will still include the type's source location as the
1943 /// Initializee points to the CXXConstructorDecl (to allow loop detection).
1944 SourceLocation MemberOrEllipsisLocation;
1946 /// \brief The argument used to initialize the base or member, which may
1947 /// end up constructing an object (when multiple arguments are involved).
1950 /// \brief Location of the left paren of the ctor-initializer.
1951 SourceLocation LParenLoc;
1953 /// \brief Location of the right paren of the ctor-initializer.
1954 SourceLocation RParenLoc;
1956 /// \brief If the initializee is a type, whether that type makes this
1957 /// a delegating initialization.
1958 unsigned IsDelegating : 1;
1960 /// \brief If the initializer is a base initializer, this keeps track
1961 /// of whether the base is virtual or not.
1962 unsigned IsVirtual : 1;
1964 /// \brief Whether or not the initializer is explicitly written
1966 unsigned IsWritten : 1;
1968 /// If IsWritten is true, then this number keeps track of the textual order
1969 /// of this initializer in the original sources, counting from 0.
1970 unsigned SourceOrder : 13;
1973 /// \brief Creates a new base-class initializer.
1975 CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual,
1976 SourceLocation L, Expr *Init, SourceLocation R,
1977 SourceLocation EllipsisLoc);
1979 /// \brief Creates a new member initializer.
1981 CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
1982 SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1985 /// \brief Creates a new anonymous field initializer.
1987 CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member,
1988 SourceLocation MemberLoc, SourceLocation L, Expr *Init,
1991 /// \brief Creates a new delegating initializer.
1993 CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo,
1994 SourceLocation L, Expr *Init, SourceLocation R);
1996 /// \brief Determine whether this initializer is initializing a base class.
1997 bool isBaseInitializer() const {
1998 return Initializee.is<TypeSourceInfo*>() && !IsDelegating;
2001 /// \brief Determine whether this initializer is initializing a non-static
2003 bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); }
2005 bool isAnyMemberInitializer() const {
2006 return isMemberInitializer() || isIndirectMemberInitializer();
2009 bool isIndirectMemberInitializer() const {
2010 return Initializee.is<IndirectFieldDecl*>();
2013 /// \brief Determine whether this initializer is an implicit initializer
2014 /// generated for a field with an initializer defined on the member
2017 /// In-class member initializers (also known as "non-static data member
2018 /// initializations", NSDMIs) were introduced in C++11.
2019 bool isInClassMemberInitializer() const {
2020 return Init->getStmtClass() == Stmt::CXXDefaultInitExprClass;
2023 /// \brief Determine whether this initializer is creating a delegating
2025 bool isDelegatingInitializer() const {
2026 return Initializee.is<TypeSourceInfo*>() && IsDelegating;
2029 /// \brief Determine whether this initializer is a pack expansion.
2030 bool isPackExpansion() const {
2031 return isBaseInitializer() && MemberOrEllipsisLocation.isValid();
2034 // \brief For a pack expansion, returns the location of the ellipsis.
2035 SourceLocation getEllipsisLoc() const {
2036 assert(isPackExpansion() && "Initializer is not a pack expansion");
2037 return MemberOrEllipsisLocation;
2040 /// If this is a base class initializer, returns the type of the
2041 /// base class with location information. Otherwise, returns an NULL
2043 TypeLoc getBaseClassLoc() const;
2045 /// If this is a base class initializer, returns the type of the base class.
2046 /// Otherwise, returns null.
2047 const Type *getBaseClass() const;
2049 /// Returns whether the base is virtual or not.
2050 bool isBaseVirtual() const {
2051 assert(isBaseInitializer() && "Must call this on base initializer!");
2056 /// \brief Returns the declarator information for a base class or delegating
2058 TypeSourceInfo *getTypeSourceInfo() const {
2059 return Initializee.dyn_cast<TypeSourceInfo *>();
2062 /// \brief If this is a member initializer, returns the declaration of the
2063 /// non-static data member being initialized. Otherwise, returns null.
2064 FieldDecl *getMember() const {
2065 if (isMemberInitializer())
2066 return Initializee.get<FieldDecl*>();
2069 FieldDecl *getAnyMember() const {
2070 if (isMemberInitializer())
2071 return Initializee.get<FieldDecl*>();
2072 if (isIndirectMemberInitializer())
2073 return Initializee.get<IndirectFieldDecl*>()->getAnonField();
2077 IndirectFieldDecl *getIndirectMember() const {
2078 if (isIndirectMemberInitializer())
2079 return Initializee.get<IndirectFieldDecl*>();
2083 SourceLocation getMemberLocation() const {
2084 return MemberOrEllipsisLocation;
2087 /// \brief Determine the source location of the initializer.
2088 SourceLocation getSourceLocation() const;
2090 /// \brief Determine the source range covering the entire initializer.
2091 SourceRange getSourceRange() const LLVM_READONLY;
2093 /// \brief Determine whether this initializer is explicitly written
2094 /// in the source code.
2095 bool isWritten() const { return IsWritten; }
2097 /// \brief Return the source position of the initializer, counting from 0.
2098 /// If the initializer was implicit, -1 is returned.
2099 int getSourceOrder() const {
2100 return IsWritten ? static_cast<int>(SourceOrder) : -1;
2103 /// \brief Set the source order of this initializer.
2105 /// This can only be called once for each initializer; it cannot be called
2106 /// on an initializer having a positive number of (implicit) array indices.
2108 /// This assumes that the initializer was written in the source code, and
2109 /// ensures that isWritten() returns true.
2110 void setSourceOrder(int Pos) {
2111 assert(!IsWritten &&
2112 "setSourceOrder() used on implicit initializer");
2113 assert(SourceOrder == 0 &&
2114 "calling twice setSourceOrder() on the same initializer");
2116 "setSourceOrder() used to make an initializer implicit");
2118 SourceOrder = static_cast<unsigned>(Pos);
2121 SourceLocation getLParenLoc() const { return LParenLoc; }
2122 SourceLocation getRParenLoc() const { return RParenLoc; }
2124 /// \brief Get the initializer.
2125 Expr *getInit() const { return static_cast<Expr*>(Init); }
2128 /// Description of a constructor that was inherited from a base class.
2129 class InheritedConstructor {
2130 ConstructorUsingShadowDecl *Shadow;
2131 CXXConstructorDecl *BaseCtor;
2134 InheritedConstructor() : Shadow(), BaseCtor() {}
2135 InheritedConstructor(ConstructorUsingShadowDecl *Shadow,
2136 CXXConstructorDecl *BaseCtor)
2137 : Shadow(Shadow), BaseCtor(BaseCtor) {}
2139 explicit operator bool() const { return Shadow; }
2141 ConstructorUsingShadowDecl *getShadowDecl() const { return Shadow; }
2142 CXXConstructorDecl *getConstructor() const { return BaseCtor; }
2145 /// \brief Represents a C++ constructor within a class.
2152 /// explicit X(int); // represented by a CXXConstructorDecl.
2155 class CXXConstructorDecl final
2156 : public CXXMethodDecl,
2157 private llvm::TrailingObjects<CXXConstructorDecl, InheritedConstructor> {
2158 void anchor() override;
2160 /// \name Support for base and member initializers.
2162 /// \brief The arguments used to initialize the base or member.
2163 LazyCXXCtorInitializersPtr CtorInitializers;
2164 unsigned NumCtorInitializers : 30;
2167 /// \brief Whether this constructor declaration has the \c explicit keyword
2169 unsigned IsExplicitSpecified : 1;
2171 /// \brief Whether this constructor declaration is an implicitly-declared
2172 /// inheriting constructor.
2173 unsigned IsInheritingConstructor : 1;
2175 CXXConstructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2176 const DeclarationNameInfo &NameInfo,
2177 QualType T, TypeSourceInfo *TInfo,
2178 bool isExplicitSpecified, bool isInline,
2179 bool isImplicitlyDeclared, bool isConstexpr,
2180 InheritedConstructor Inherited)
2181 : CXXMethodDecl(CXXConstructor, C, RD, StartLoc, NameInfo, T, TInfo,
2182 SC_None, isInline, isConstexpr, SourceLocation()),
2183 CtorInitializers(nullptr), NumCtorInitializers(0),
2184 IsExplicitSpecified(isExplicitSpecified),
2185 IsInheritingConstructor((bool)Inherited) {
2186 setImplicit(isImplicitlyDeclared);
2188 *getTrailingObjects<InheritedConstructor>() = Inherited;
2192 static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID,
2193 bool InheritsConstructor);
2194 static CXXConstructorDecl *
2195 Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2196 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2197 bool isExplicit, bool isInline, bool isImplicitlyDeclared,
2199 InheritedConstructor Inherited = InheritedConstructor());
2201 /// \brief Determine whether this constructor declaration has the
2202 /// \c explicit keyword specified.
2203 bool isExplicitSpecified() const { return IsExplicitSpecified; }
2205 /// \brief Determine whether this constructor was marked "explicit" or not.
2206 bool isExplicit() const {
2207 return cast<CXXConstructorDecl>(getFirstDecl())->isExplicitSpecified();
2210 /// \brief Iterates through the member/base initializer list.
2211 typedef CXXCtorInitializer **init_iterator;
2213 /// \brief Iterates through the member/base initializer list.
2214 typedef CXXCtorInitializer *const *init_const_iterator;
2216 typedef llvm::iterator_range<init_iterator> init_range;
2217 typedef llvm::iterator_range<init_const_iterator> init_const_range;
2219 init_range inits() { return init_range(init_begin(), init_end()); }
2220 init_const_range inits() const {
2221 return init_const_range(init_begin(), init_end());
2224 /// \brief Retrieve an iterator to the first initializer.
2225 init_iterator init_begin() {
2226 const auto *ConstThis = this;
2227 return const_cast<init_iterator>(ConstThis->init_begin());
2229 /// \brief Retrieve an iterator to the first initializer.
2230 init_const_iterator init_begin() const;
2232 /// \brief Retrieve an iterator past the last initializer.
2233 init_iterator init_end() {
2234 return init_begin() + NumCtorInitializers;
2236 /// \brief Retrieve an iterator past the last initializer.
2237 init_const_iterator init_end() const {
2238 return init_begin() + NumCtorInitializers;
2241 typedef std::reverse_iterator<init_iterator> init_reverse_iterator;
2242 typedef std::reverse_iterator<init_const_iterator>
2243 init_const_reverse_iterator;
2245 init_reverse_iterator init_rbegin() {
2246 return init_reverse_iterator(init_end());
2248 init_const_reverse_iterator init_rbegin() const {
2249 return init_const_reverse_iterator(init_end());
2252 init_reverse_iterator init_rend() {
2253 return init_reverse_iterator(init_begin());
2255 init_const_reverse_iterator init_rend() const {
2256 return init_const_reverse_iterator(init_begin());
2259 /// \brief Determine the number of arguments used to initialize the member
2261 unsigned getNumCtorInitializers() const {
2262 return NumCtorInitializers;
2265 void setNumCtorInitializers(unsigned numCtorInitializers) {
2266 NumCtorInitializers = numCtorInitializers;
2269 void setCtorInitializers(CXXCtorInitializer **Initializers) {
2270 CtorInitializers = Initializers;
2273 /// \brief Determine whether this constructor is a delegating constructor.
2274 bool isDelegatingConstructor() const {
2275 return (getNumCtorInitializers() == 1) &&
2276 init_begin()[0]->isDelegatingInitializer();
2279 /// \brief When this constructor delegates to another, retrieve the target.
2280 CXXConstructorDecl *getTargetConstructor() const;
2282 /// Whether this constructor is a default
2283 /// constructor (C++ [class.ctor]p5), which can be used to
2284 /// default-initialize a class of this type.
2285 bool isDefaultConstructor() const;
2287 /// \brief Whether this constructor is a copy constructor (C++ [class.copy]p2,
2288 /// which can be used to copy the class.
2290 /// \p TypeQuals will be set to the qualifiers on the
2291 /// argument type. For example, \p TypeQuals would be set to \c
2292 /// Qualifiers::Const for the following copy constructor:
2300 bool isCopyConstructor(unsigned &TypeQuals) const;
2302 /// Whether this constructor is a copy
2303 /// constructor (C++ [class.copy]p2, which can be used to copy the
2305 bool isCopyConstructor() const {
2306 unsigned TypeQuals = 0;
2307 return isCopyConstructor(TypeQuals);
2310 /// \brief Determine whether this constructor is a move constructor
2311 /// (C++11 [class.copy]p3), which can be used to move values of the class.
2313 /// \param TypeQuals If this constructor is a move constructor, will be set
2314 /// to the type qualifiers on the referent of the first parameter's type.
2315 bool isMoveConstructor(unsigned &TypeQuals) const;
2317 /// \brief Determine whether this constructor is a move constructor
2318 /// (C++11 [class.copy]p3), which can be used to move values of the class.
2319 bool isMoveConstructor() const {
2320 unsigned TypeQuals = 0;
2321 return isMoveConstructor(TypeQuals);
2324 /// \brief Determine whether this is a copy or move constructor.
2326 /// \param TypeQuals Will be set to the type qualifiers on the reference
2327 /// parameter, if in fact this is a copy or move constructor.
2328 bool isCopyOrMoveConstructor(unsigned &TypeQuals) const;
2330 /// \brief Determine whether this a copy or move constructor.
2331 bool isCopyOrMoveConstructor() const {
2333 return isCopyOrMoveConstructor(Quals);
2336 /// Whether this constructor is a
2337 /// converting constructor (C++ [class.conv.ctor]), which can be
2338 /// used for user-defined conversions.
2339 bool isConvertingConstructor(bool AllowExplicit) const;
2341 /// \brief Determine whether this is a member template specialization that
2342 /// would copy the object to itself. Such constructors are never used to copy
2344 bool isSpecializationCopyingObject() const;
2346 /// \brief Determine whether this is an implicit constructor synthesized to
2347 /// model a call to a constructor inherited from a base class.
2348 bool isInheritingConstructor() const { return IsInheritingConstructor; }
2350 /// \brief Get the constructor that this inheriting constructor is based on.
2351 InheritedConstructor getInheritedConstructor() const {
2352 return IsInheritingConstructor ? *getTrailingObjects<InheritedConstructor>()
2353 : InheritedConstructor();
2356 CXXConstructorDecl *getCanonicalDecl() override {
2357 return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
2359 const CXXConstructorDecl *getCanonicalDecl() const {
2360 return const_cast<CXXConstructorDecl*>(this)->getCanonicalDecl();
2363 // Implement isa/cast/dyncast/etc.
2364 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2365 static bool classofKind(Kind K) { return K == CXXConstructor; }
2367 friend class ASTDeclReader;
2368 friend class ASTDeclWriter;
2369 friend TrailingObjects;
2372 /// \brief Represents a C++ destructor within a class.
2379 /// ~X(); // represented by a CXXDestructorDecl.
2382 class CXXDestructorDecl : public CXXMethodDecl {
2383 void anchor() override;
2385 FunctionDecl *OperatorDelete;
2387 CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2388 const DeclarationNameInfo &NameInfo,
2389 QualType T, TypeSourceInfo *TInfo,
2390 bool isInline, bool isImplicitlyDeclared)
2391 : CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo,
2392 SC_None, isInline, /*isConstexpr=*/false, SourceLocation()),
2393 OperatorDelete(nullptr) {
2394 setImplicit(isImplicitlyDeclared);
2398 static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2399 SourceLocation StartLoc,
2400 const DeclarationNameInfo &NameInfo,
2401 QualType T, TypeSourceInfo* TInfo,
2403 bool isImplicitlyDeclared);
2404 static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID);
2406 void setOperatorDelete(FunctionDecl *OD);
2407 const FunctionDecl *getOperatorDelete() const {
2408 return cast<CXXDestructorDecl>(getFirstDecl())->OperatorDelete;
2411 // Implement isa/cast/dyncast/etc.
2412 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2413 static bool classofKind(Kind K) { return K == CXXDestructor; }
2415 friend class ASTDeclReader;
2416 friend class ASTDeclWriter;
2419 /// \brief Represents a C++ conversion function within a class.
2426 /// operator bool();
2429 class CXXConversionDecl : public CXXMethodDecl {
2430 void anchor() override;
2431 /// Whether this conversion function declaration is marked
2432 /// "explicit", meaning that it can only be applied when the user
2433 /// explicitly wrote a cast. This is a C++11 feature.
2434 bool IsExplicitSpecified : 1;
2436 CXXConversionDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2437 const DeclarationNameInfo &NameInfo,
2438 QualType T, TypeSourceInfo *TInfo,
2439 bool isInline, bool isExplicitSpecified,
2440 bool isConstexpr, SourceLocation EndLocation)
2441 : CXXMethodDecl(CXXConversion, C, RD, StartLoc, NameInfo, T, TInfo,
2442 SC_None, isInline, isConstexpr, EndLocation),
2443 IsExplicitSpecified(isExplicitSpecified) { }
2446 static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2447 SourceLocation StartLoc,
2448 const DeclarationNameInfo &NameInfo,
2449 QualType T, TypeSourceInfo *TInfo,
2450 bool isInline, bool isExplicit,
2452 SourceLocation EndLocation);
2453 static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2455 /// Whether this conversion function declaration is marked
2456 /// "explicit", meaning that it can only be used for direct initialization
2457 /// (including explitly written casts). This is a C++11 feature.
2458 bool isExplicitSpecified() const { return IsExplicitSpecified; }
2460 /// \brief Whether this is an explicit conversion operator (C++11 and later).
2462 /// Explicit conversion operators are only considered for direct
2463 /// initialization, e.g., when the user has explicitly written a cast.
2464 bool isExplicit() const {
2465 return cast<CXXConversionDecl>(getFirstDecl())->isExplicitSpecified();
2468 /// \brief Returns the type that this conversion function is converting to.
2469 QualType getConversionType() const {
2470 return getType()->getAs<FunctionType>()->getReturnType();
2473 /// \brief Determine whether this conversion function is a conversion from
2474 /// a lambda closure type to a block pointer.
2475 bool isLambdaToBlockPointerConversion() const;
2477 // Implement isa/cast/dyncast/etc.
2478 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2479 static bool classofKind(Kind K) { return K == CXXConversion; }
2481 friend class ASTDeclReader;
2482 friend class ASTDeclWriter;
2485 /// \brief Represents a linkage specification.
2489 /// extern "C" void foo();
2491 class LinkageSpecDecl : public Decl, public DeclContext {
2492 virtual void anchor();
2494 /// \brief Represents the language in a linkage specification.
2496 /// The values are part of the serialization ABI for
2497 /// ASTs and cannot be changed without altering that ABI. To help
2498 /// ensure a stable ABI for this, we choose the DW_LANG_ encodings
2499 /// from the dwarf standard.
2501 lang_c = /* DW_LANG_C */ 0x0002,
2502 lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004
2505 /// \brief The language for this linkage specification.
2506 unsigned Language : 3;
2507 /// \brief True if this linkage spec has braces.
2509 /// This is needed so that hasBraces() returns the correct result while the
2510 /// linkage spec body is being parsed. Once RBraceLoc has been set this is
2511 /// not used, so it doesn't need to be serialized.
2512 unsigned HasBraces : 1;
2513 /// \brief The source location for the extern keyword.
2514 SourceLocation ExternLoc;
2515 /// \brief The source location for the right brace (if valid).
2516 SourceLocation RBraceLoc;
2518 LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
2519 SourceLocation LangLoc, LanguageIDs lang, bool HasBraces)
2520 : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
2521 Language(lang), HasBraces(HasBraces), ExternLoc(ExternLoc),
2522 RBraceLoc(SourceLocation()) { }
2525 static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
2526 SourceLocation ExternLoc,
2527 SourceLocation LangLoc, LanguageIDs Lang,
2529 static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2531 /// \brief Return the language specified by this linkage specification.
2532 LanguageIDs getLanguage() const { return LanguageIDs(Language); }
2533 /// \brief Set the language specified by this linkage specification.
2534 void setLanguage(LanguageIDs L) { Language = L; }
2536 /// \brief Determines whether this linkage specification had braces in
2537 /// its syntactic form.
2538 bool hasBraces() const {
2539 assert(!RBraceLoc.isValid() || HasBraces);
2543 SourceLocation getExternLoc() const { return ExternLoc; }
2544 SourceLocation getRBraceLoc() const { return RBraceLoc; }
2545 void setExternLoc(SourceLocation L) { ExternLoc = L; }
2546 void setRBraceLoc(SourceLocation L) {
2548 HasBraces = RBraceLoc.isValid();
2551 SourceLocation getLocEnd() const LLVM_READONLY {
2553 return getRBraceLoc();
2554 // No braces: get the end location of the (only) declaration in context
2556 return decls_empty() ? getLocation() : decls_begin()->getLocEnd();
2559 SourceRange getSourceRange() const override LLVM_READONLY {
2560 return SourceRange(ExternLoc, getLocEnd());
2563 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2564 static bool classofKind(Kind K) { return K == LinkageSpec; }
2565 static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
2566 return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
2568 static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
2569 return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
2573 /// \brief Represents C++ using-directive.
2577 /// using namespace std;
2580 /// \note UsingDirectiveDecl should be Decl not NamedDecl, but we provide
2581 /// artificial names for all using-directives in order to store
2582 /// them in DeclContext effectively.
2583 class UsingDirectiveDecl : public NamedDecl {
2584 void anchor() override;
2585 /// \brief The location of the \c using keyword.
2586 SourceLocation UsingLoc;
2588 /// \brief The location of the \c namespace keyword.
2589 SourceLocation NamespaceLoc;
2591 /// \brief The nested-name-specifier that precedes the namespace.
2592 NestedNameSpecifierLoc QualifierLoc;
2594 /// \brief The namespace nominated by this using-directive.
2595 NamedDecl *NominatedNamespace;
2597 /// Enclosing context containing both using-directive and nominated
2599 DeclContext *CommonAncestor;
2601 /// \brief Returns special DeclarationName used by using-directives.
2603 /// This is only used by DeclContext for storing UsingDirectiveDecls in
2604 /// its lookup structure.
2605 static DeclarationName getName() {
2606 return DeclarationName::getUsingDirectiveName();
2609 UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
2610 SourceLocation NamespcLoc,
2611 NestedNameSpecifierLoc QualifierLoc,
2612 SourceLocation IdentLoc,
2613 NamedDecl *Nominated,
2614 DeclContext *CommonAncestor)
2615 : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
2616 NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
2617 NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) { }
2620 /// \brief Retrieve the nested-name-specifier that qualifies the
2621 /// name of the namespace, with source-location information.
2622 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2624 /// \brief Retrieve the nested-name-specifier that qualifies the
2625 /// name of the namespace.
2626 NestedNameSpecifier *getQualifier() const {
2627 return QualifierLoc.getNestedNameSpecifier();
2630 NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
2631 const NamedDecl *getNominatedNamespaceAsWritten() const {
2632 return NominatedNamespace;
2635 /// \brief Returns the namespace nominated by this using-directive.
2636 NamespaceDecl *getNominatedNamespace();
2638 const NamespaceDecl *getNominatedNamespace() const {
2639 return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
2642 /// \brief Returns the common ancestor context of this using-directive and
2643 /// its nominated namespace.
2644 DeclContext *getCommonAncestor() { return CommonAncestor; }
2645 const DeclContext *getCommonAncestor() const { return CommonAncestor; }
2647 /// \brief Return the location of the \c using keyword.
2648 SourceLocation getUsingLoc() const { return UsingLoc; }
2650 // FIXME: Could omit 'Key' in name.
2651 /// \brief Returns the location of the \c namespace keyword.
2652 SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
2654 /// \brief Returns the location of this using declaration's identifier.
2655 SourceLocation getIdentLocation() const { return getLocation(); }
2657 static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
2658 SourceLocation UsingLoc,
2659 SourceLocation NamespaceLoc,
2660 NestedNameSpecifierLoc QualifierLoc,
2661 SourceLocation IdentLoc,
2662 NamedDecl *Nominated,
2663 DeclContext *CommonAncestor);
2664 static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2666 SourceRange getSourceRange() const override LLVM_READONLY {
2667 return SourceRange(UsingLoc, getLocation());
2670 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2671 static bool classofKind(Kind K) { return K == UsingDirective; }
2673 // Friend for getUsingDirectiveName.
2674 friend class DeclContext;
2676 friend class ASTDeclReader;
2679 /// \brief Represents a C++ namespace alias.
2684 /// namespace Foo = Bar;
2686 class NamespaceAliasDecl : public NamedDecl,
2687 public Redeclarable<NamespaceAliasDecl> {
2688 void anchor() override;
2690 /// \brief The location of the \c namespace keyword.
2691 SourceLocation NamespaceLoc;
2693 /// \brief The location of the namespace's identifier.
2695 /// This is accessed by TargetNameLoc.
2696 SourceLocation IdentLoc;
2698 /// \brief The nested-name-specifier that precedes the namespace.
2699 NestedNameSpecifierLoc QualifierLoc;
2701 /// \brief The Decl that this alias points to, either a NamespaceDecl or
2702 /// a NamespaceAliasDecl.
2703 NamedDecl *Namespace;
2705 NamespaceAliasDecl(ASTContext &C, DeclContext *DC,
2706 SourceLocation NamespaceLoc, SourceLocation AliasLoc,
2707 IdentifierInfo *Alias, NestedNameSpecifierLoc QualifierLoc,
2708 SourceLocation IdentLoc, NamedDecl *Namespace)
2709 : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias), redeclarable_base(C),
2710 NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc),
2711 QualifierLoc(QualifierLoc), Namespace(Namespace) {}
2713 typedef Redeclarable<NamespaceAliasDecl> redeclarable_base;
2714 NamespaceAliasDecl *getNextRedeclarationImpl() override;
2715 NamespaceAliasDecl *getPreviousDeclImpl() override;
2716 NamespaceAliasDecl *getMostRecentDeclImpl() override;
2718 friend class ASTDeclReader;
2721 static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
2722 SourceLocation NamespaceLoc,
2723 SourceLocation AliasLoc,
2724 IdentifierInfo *Alias,
2725 NestedNameSpecifierLoc QualifierLoc,
2726 SourceLocation IdentLoc,
2727 NamedDecl *Namespace);
2729 static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2731 typedef redeclarable_base::redecl_range redecl_range;
2732 typedef redeclarable_base::redecl_iterator redecl_iterator;
2733 using redeclarable_base::redecls_begin;
2734 using redeclarable_base::redecls_end;
2735 using redeclarable_base::redecls;
2736 using redeclarable_base::getPreviousDecl;
2737 using redeclarable_base::getMostRecentDecl;
2739 NamespaceAliasDecl *getCanonicalDecl() override {
2740 return getFirstDecl();
2742 const NamespaceAliasDecl *getCanonicalDecl() const {
2743 return getFirstDecl();
2746 /// \brief Retrieve the nested-name-specifier that qualifies the
2747 /// name of the namespace, with source-location information.
2748 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2750 /// \brief Retrieve the nested-name-specifier that qualifies the
2751 /// name of the namespace.
2752 NestedNameSpecifier *getQualifier() const {
2753 return QualifierLoc.getNestedNameSpecifier();
2756 /// \brief Retrieve the namespace declaration aliased by this directive.
2757 NamespaceDecl *getNamespace() {
2758 if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
2759 return AD->getNamespace();
2761 return cast<NamespaceDecl>(Namespace);
2764 const NamespaceDecl *getNamespace() const {
2765 return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
2768 /// Returns the location of the alias name, i.e. 'foo' in
2769 /// "namespace foo = ns::bar;".
2770 SourceLocation getAliasLoc() const { return getLocation(); }
2772 /// Returns the location of the \c namespace keyword.
2773 SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
2775 /// Returns the location of the identifier in the named namespace.
2776 SourceLocation getTargetNameLoc() const { return IdentLoc; }
2778 /// \brief Retrieve the namespace that this alias refers to, which
2779 /// may either be a NamespaceDecl or a NamespaceAliasDecl.
2780 NamedDecl *getAliasedNamespace() const { return Namespace; }
2782 SourceRange getSourceRange() const override LLVM_READONLY {
2783 return SourceRange(NamespaceLoc, IdentLoc);
2786 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2787 static bool classofKind(Kind K) { return K == NamespaceAlias; }
2790 /// \brief Represents a shadow declaration introduced into a scope by a
2791 /// (resolved) using declaration.
2799 /// using A::foo; // <- a UsingDecl
2800 /// // Also creates a UsingShadowDecl for A::foo() in B
2803 class UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> {
2804 void anchor() override;
2806 /// The referenced declaration.
2807 NamedDecl *Underlying;
2809 /// \brief The using declaration which introduced this decl or the next using
2810 /// shadow declaration contained in the aforementioned using declaration.
2811 NamedDecl *UsingOrNextShadow;
2812 friend class UsingDecl;
2814 typedef Redeclarable<UsingShadowDecl> redeclarable_base;
2815 UsingShadowDecl *getNextRedeclarationImpl() override {
2816 return getNextRedeclaration();
2818 UsingShadowDecl *getPreviousDeclImpl() override {
2819 return getPreviousDecl();
2821 UsingShadowDecl *getMostRecentDeclImpl() override {
2822 return getMostRecentDecl();
2826 UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC, SourceLocation Loc,
2827 UsingDecl *Using, NamedDecl *Target);
2828 UsingShadowDecl(Kind K, ASTContext &C, EmptyShell);
2831 static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
2832 SourceLocation Loc, UsingDecl *Using,
2833 NamedDecl *Target) {
2834 return new (C, DC) UsingShadowDecl(UsingShadow, C, DC, Loc, Using, Target);
2837 static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2839 typedef redeclarable_base::redecl_range redecl_range;
2840 typedef redeclarable_base::redecl_iterator redecl_iterator;
2841 using redeclarable_base::redecls_begin;
2842 using redeclarable_base::redecls_end;
2843 using redeclarable_base::redecls;
2844 using redeclarable_base::getPreviousDecl;
2845 using redeclarable_base::getMostRecentDecl;
2846 using redeclarable_base::isFirstDecl;
2848 UsingShadowDecl *getCanonicalDecl() override {
2849 return getFirstDecl();
2851 const UsingShadowDecl *getCanonicalDecl() const {
2852 return getFirstDecl();
2855 /// \brief Gets the underlying declaration which has been brought into the
2857 NamedDecl *getTargetDecl() const { return Underlying; }
2859 /// \brief Sets the underlying declaration which has been brought into the
2861 void setTargetDecl(NamedDecl* ND) {
2862 assert(ND && "Target decl is null!");
2864 IdentifierNamespace = ND->getIdentifierNamespace();
2867 /// \brief Gets the using declaration to which this declaration is tied.
2868 UsingDecl *getUsingDecl() const;
2870 /// \brief The next using shadow declaration contained in the shadow decl
2871 /// chain of the using declaration which introduced this decl.
2872 UsingShadowDecl *getNextUsingShadowDecl() const {
2873 return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow);
2876 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2877 static bool classofKind(Kind K) {
2878 return K == Decl::UsingShadow || K == Decl::ConstructorUsingShadow;
2881 friend class ASTDeclReader;
2882 friend class ASTDeclWriter;
2885 /// \brief Represents a shadow constructor declaration introduced into a
2886 /// class by a C++11 using-declaration that names a constructor.
2890 /// struct Base { Base(int); };
2891 /// struct Derived {
2892 /// using Base::Base; // creates a UsingDecl and a ConstructorUsingShadowDecl
2895 class ConstructorUsingShadowDecl final : public UsingShadowDecl {
2896 void anchor() override;
2898 /// \brief If this constructor using declaration inherted the constructor
2899 /// from an indirect base class, this is the ConstructorUsingShadowDecl
2900 /// in the named direct base class from which the declaration was inherited.
2901 ConstructorUsingShadowDecl *NominatedBaseClassShadowDecl;
2903 /// \brief If this constructor using declaration inherted the constructor
2904 /// from an indirect base class, this is the ConstructorUsingShadowDecl
2905 /// that will be used to construct the unique direct or virtual base class
2906 /// that receives the constructor arguments.
2907 ConstructorUsingShadowDecl *ConstructedBaseClassShadowDecl;
2909 /// \brief \c true if the constructor ultimately named by this using shadow
2910 /// declaration is within a virtual base class subobject of the class that
2911 /// contains this declaration.
2912 unsigned IsVirtual : 1;
2914 ConstructorUsingShadowDecl(ASTContext &C, DeclContext *DC, SourceLocation Loc,
2915 UsingDecl *Using, NamedDecl *Target,
2916 bool TargetInVirtualBase)
2917 : UsingShadowDecl(ConstructorUsingShadow, C, DC, Loc, Using,
2918 Target->getUnderlyingDecl()),
2919 NominatedBaseClassShadowDecl(
2920 dyn_cast<ConstructorUsingShadowDecl>(Target)),
2921 ConstructedBaseClassShadowDecl(NominatedBaseClassShadowDecl),
2922 IsVirtual(TargetInVirtualBase) {
2923 // If we found a constructor that chains to a constructor for a virtual
2924 // base, we should directly call that virtual base constructor instead.
2925 // FIXME: This logic belongs in Sema.
2926 if (NominatedBaseClassShadowDecl &&
2927 NominatedBaseClassShadowDecl->constructsVirtualBase()) {
2928 ConstructedBaseClassShadowDecl =
2929 NominatedBaseClassShadowDecl->ConstructedBaseClassShadowDecl;
2933 ConstructorUsingShadowDecl(ASTContext &C, EmptyShell Empty)
2934 : UsingShadowDecl(ConstructorUsingShadow, C, Empty),
2935 NominatedBaseClassShadowDecl(), ConstructedBaseClassShadowDecl(),
2939 static ConstructorUsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
2941 UsingDecl *Using, NamedDecl *Target,
2943 static ConstructorUsingShadowDecl *CreateDeserialized(ASTContext &C,
2946 /// Returns the parent of this using shadow declaration, which
2947 /// is the class in which this is declared.
2949 const CXXRecordDecl *getParent() const {
2950 return cast<CXXRecordDecl>(getDeclContext());
2952 CXXRecordDecl *getParent() {
2953 return cast<CXXRecordDecl>(getDeclContext());
2957 /// \brief Get the inheriting constructor declaration for the direct base
2958 /// class from which this using shadow declaration was inherited, if there is
2959 /// one. This can be different for each redeclaration of the same shadow decl.
2960 ConstructorUsingShadowDecl *getNominatedBaseClassShadowDecl() const {
2961 return NominatedBaseClassShadowDecl;
2964 /// \brief Get the inheriting constructor declaration for the base class
2965 /// for which we don't have an explicit initializer, if there is one.
2966 ConstructorUsingShadowDecl *getConstructedBaseClassShadowDecl() const {
2967 return ConstructedBaseClassShadowDecl;
2970 /// \brief Get the base class that was named in the using declaration. This
2971 /// can be different for each redeclaration of this same shadow decl.
2972 CXXRecordDecl *getNominatedBaseClass() const;
2974 /// \brief Get the base class whose constructor or constructor shadow
2975 /// declaration is passed the constructor arguments.
2976 CXXRecordDecl *getConstructedBaseClass() const {
2977 return cast<CXXRecordDecl>((ConstructedBaseClassShadowDecl
2978 ? ConstructedBaseClassShadowDecl
2980 ->getDeclContext());
2983 /// \brief Returns \c true if the constructed base class is a virtual base
2984 /// class subobject of this declaration's class.
2985 bool constructsVirtualBase() const {
2989 /// \brief Get the constructor or constructor template in the derived class
2990 /// correspnding to this using shadow declaration, if it has been implicitly
2991 /// declared already.
2992 CXXConstructorDecl *getConstructor() const;
2993 void setConstructor(NamedDecl *Ctor);
2995 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2996 static bool classofKind(Kind K) { return K == ConstructorUsingShadow; }
2998 friend class ASTDeclReader;
2999 friend class ASTDeclWriter;
3002 /// \brief Represents a C++ using-declaration.
3006 /// using someNameSpace::someIdentifier;
3008 class UsingDecl : public NamedDecl, public Mergeable<UsingDecl> {
3009 void anchor() override;
3011 /// \brief The source location of the 'using' keyword itself.
3012 SourceLocation UsingLocation;
3014 /// \brief The nested-name-specifier that precedes the name.
3015 NestedNameSpecifierLoc QualifierLoc;
3017 /// \brief Provides source/type location info for the declaration name
3018 /// embedded in the ValueDecl base class.
3019 DeclarationNameLoc DNLoc;
3021 /// \brief The first shadow declaration of the shadow decl chain associated
3022 /// with this using declaration.
3024 /// The bool member of the pair store whether this decl has the \c typename
3026 llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow;
3028 UsingDecl(DeclContext *DC, SourceLocation UL,
3029 NestedNameSpecifierLoc QualifierLoc,
3030 const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword)
3031 : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()),
3032 UsingLocation(UL), QualifierLoc(QualifierLoc),
3033 DNLoc(NameInfo.getInfo()), FirstUsingShadow(nullptr, HasTypenameKeyword) {
3037 /// \brief Return the source location of the 'using' keyword.
3038 SourceLocation getUsingLoc() const { return UsingLocation; }
3040 /// \brief Set the source location of the 'using' keyword.
3041 void setUsingLoc(SourceLocation L) { UsingLocation = L; }
3043 /// \brief Retrieve the nested-name-specifier that qualifies the name,
3044 /// with source-location information.
3045 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3047 /// \brief Retrieve the nested-name-specifier that qualifies the name.
3048 NestedNameSpecifier *getQualifier() const {
3049 return QualifierLoc.getNestedNameSpecifier();
3052 DeclarationNameInfo getNameInfo() const {
3053 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
3056 /// \brief Return true if it is a C++03 access declaration (no 'using').
3057 bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
3059 /// \brief Return true if the using declaration has 'typename'.
3060 bool hasTypename() const { return FirstUsingShadow.getInt(); }
3062 /// \brief Sets whether the using declaration has 'typename'.
3063 void setTypename(bool TN) { FirstUsingShadow.setInt(TN); }
3065 /// \brief Iterates through the using shadow declarations associated with
3066 /// this using declaration.
3067 class shadow_iterator {
3068 /// \brief The current using shadow declaration.
3069 UsingShadowDecl *Current;
3072 typedef UsingShadowDecl* value_type;
3073 typedef UsingShadowDecl* reference;
3074 typedef UsingShadowDecl* pointer;
3075 typedef std::forward_iterator_tag iterator_category;
3076 typedef std::ptrdiff_t difference_type;
3078 shadow_iterator() : Current(nullptr) { }
3079 explicit shadow_iterator(UsingShadowDecl *C) : Current(C) { }
3081 reference operator*() const { return Current; }
3082 pointer operator->() const { return Current; }
3084 shadow_iterator& operator++() {
3085 Current = Current->getNextUsingShadowDecl();
3089 shadow_iterator operator++(int) {
3090 shadow_iterator tmp(*this);
3095 friend bool operator==(shadow_iterator x, shadow_iterator y) {
3096 return x.Current == y.Current;
3098 friend bool operator!=(shadow_iterator x, shadow_iterator y) {
3099 return x.Current != y.Current;
3103 typedef llvm::iterator_range<shadow_iterator> shadow_range;
3105 shadow_range shadows() const {
3106 return shadow_range(shadow_begin(), shadow_end());
3108 shadow_iterator shadow_begin() const {
3109 return shadow_iterator(FirstUsingShadow.getPointer());
3111 shadow_iterator shadow_end() const { return shadow_iterator(); }
3113 /// \brief Return the number of shadowed declarations associated with this
3114 /// using declaration.
3115 unsigned shadow_size() const {
3116 return std::distance(shadow_begin(), shadow_end());
3119 void addShadowDecl(UsingShadowDecl *S);
3120 void removeShadowDecl(UsingShadowDecl *S);
3122 static UsingDecl *Create(ASTContext &C, DeclContext *DC,
3123 SourceLocation UsingL,
3124 NestedNameSpecifierLoc QualifierLoc,
3125 const DeclarationNameInfo &NameInfo,
3126 bool HasTypenameKeyword);
3128 static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3130 SourceRange getSourceRange() const override LLVM_READONLY;
3132 /// Retrieves the canonical declaration of this declaration.
3133 UsingDecl *getCanonicalDecl() override { return getFirstDecl(); }
3134 const UsingDecl *getCanonicalDecl() const { return getFirstDecl(); }
3136 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3137 static bool classofKind(Kind K) { return K == Using; }
3139 friend class ASTDeclReader;
3140 friend class ASTDeclWriter;
3143 /// Represents a pack of using declarations that a single
3144 /// using-declarator pack-expanded into.
3147 /// template<typename ...T> struct X : T... {
3148 /// using T::operator()...;
3149 /// using T::operator T...;
3153 /// In the second case above, the UsingPackDecl will have the name
3154 /// 'operator T' (which contains an unexpanded pack), but the individual
3155 /// UsingDecls and UsingShadowDecls will have more reasonable names.
3156 class UsingPackDecl final
3157 : public NamedDecl, public Mergeable<UsingPackDecl>,
3158 private llvm::TrailingObjects<UsingPackDecl, NamedDecl *> {
3159 void anchor() override;
3161 /// The UnresolvedUsingValueDecl or UnresolvedUsingTypenameDecl from
3162 /// which this waas instantiated.
3163 NamedDecl *InstantiatedFrom;
3165 /// The number of using-declarations created by this pack expansion.
3166 unsigned NumExpansions;
3168 UsingPackDecl(DeclContext *DC, NamedDecl *InstantiatedFrom,
3169 ArrayRef<NamedDecl *> UsingDecls)
3170 : NamedDecl(UsingPack, DC,
3171 InstantiatedFrom ? InstantiatedFrom->getLocation()
3173 InstantiatedFrom ? InstantiatedFrom->getDeclName()
3174 : DeclarationName()),
3175 InstantiatedFrom(InstantiatedFrom), NumExpansions(UsingDecls.size()) {
3176 std::uninitialized_copy(UsingDecls.begin(), UsingDecls.end(),
3177 getTrailingObjects<NamedDecl *>());
3181 /// Get the using declaration from which this was instantiated. This will
3182 /// always be an UnresolvedUsingValueDecl or an UnresolvedUsingTypenameDecl
3183 /// that is a pack expansion.
3184 NamedDecl *getInstantiatedFromUsingDecl() { return InstantiatedFrom; }
3186 /// Get the set of using declarations that this pack expanded into. Note that
3187 /// some of these may still be unresolved.
3188 ArrayRef<NamedDecl *> expansions() const {
3189 return llvm::makeArrayRef(getTrailingObjects<NamedDecl *>(), NumExpansions);
3192 static UsingPackDecl *Create(ASTContext &C, DeclContext *DC,
3193 NamedDecl *InstantiatedFrom,
3194 ArrayRef<NamedDecl *> UsingDecls);
3196 static UsingPackDecl *CreateDeserialized(ASTContext &C, unsigned ID,
3197 unsigned NumExpansions);
3199 SourceRange getSourceRange() const override LLVM_READONLY {
3200 return InstantiatedFrom->getSourceRange();
3203 UsingPackDecl *getCanonicalDecl() override { return getFirstDecl(); }
3204 const UsingPackDecl *getCanonicalDecl() const { return getFirstDecl(); }
3206 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3207 static bool classofKind(Kind K) { return K == UsingPack; }
3209 friend class ASTDeclReader;
3210 friend class ASTDeclWriter;
3211 friend TrailingObjects;
3214 /// \brief Represents a dependent using declaration which was not marked with
3217 /// Unlike non-dependent using declarations, these *only* bring through
3218 /// non-types; otherwise they would break two-phase lookup.
3221 /// template \<class T> class A : public Base<T> {
3222 /// using Base<T>::foo;
3225 class UnresolvedUsingValueDecl : public ValueDecl,
3226 public Mergeable<UnresolvedUsingValueDecl> {
3227 void anchor() override;
3229 /// \brief The source location of the 'using' keyword
3230 SourceLocation UsingLocation;
3232 /// \brief If this is a pack expansion, the location of the '...'.
3233 SourceLocation EllipsisLoc;
3235 /// \brief The nested-name-specifier that precedes the name.
3236 NestedNameSpecifierLoc QualifierLoc;
3238 /// \brief Provides source/type location info for the declaration name
3239 /// embedded in the ValueDecl base class.
3240 DeclarationNameLoc DNLoc;
3242 UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
3243 SourceLocation UsingLoc,
3244 NestedNameSpecifierLoc QualifierLoc,
3245 const DeclarationNameInfo &NameInfo,
3246 SourceLocation EllipsisLoc)
3247 : ValueDecl(UnresolvedUsingValue, DC,
3248 NameInfo.getLoc(), NameInfo.getName(), Ty),
3249 UsingLocation(UsingLoc), EllipsisLoc(EllipsisLoc),
3250 QualifierLoc(QualifierLoc), DNLoc(NameInfo.getInfo())
3254 /// \brief Returns the source location of the 'using' keyword.
3255 SourceLocation getUsingLoc() const { return UsingLocation; }
3257 /// \brief Set the source location of the 'using' keyword.
3258 void setUsingLoc(SourceLocation L) { UsingLocation = L; }
3260 /// \brief Return true if it is a C++03 access declaration (no 'using').
3261 bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
3263 /// \brief Retrieve the nested-name-specifier that qualifies the name,
3264 /// with source-location information.
3265 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3267 /// \brief Retrieve the nested-name-specifier that qualifies the name.
3268 NestedNameSpecifier *getQualifier() const {
3269 return QualifierLoc.getNestedNameSpecifier();
3272 DeclarationNameInfo getNameInfo() const {
3273 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
3276 /// \brief Determine whether this is a pack expansion.
3277 bool isPackExpansion() const {
3278 return EllipsisLoc.isValid();
3281 /// \brief Get the location of the ellipsis if this is a pack expansion.
3282 SourceLocation getEllipsisLoc() const {
3286 static UnresolvedUsingValueDecl *
3287 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
3288 NestedNameSpecifierLoc QualifierLoc,
3289 const DeclarationNameInfo &NameInfo, SourceLocation EllipsisLoc);
3291 static UnresolvedUsingValueDecl *
3292 CreateDeserialized(ASTContext &C, unsigned ID);
3294 SourceRange getSourceRange() const override LLVM_READONLY;
3296 /// Retrieves the canonical declaration of this declaration.
3297 UnresolvedUsingValueDecl *getCanonicalDecl() override {
3298 return getFirstDecl();
3300 const UnresolvedUsingValueDecl *getCanonicalDecl() const {
3301 return getFirstDecl();
3304 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3305 static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
3307 friend class ASTDeclReader;
3308 friend class ASTDeclWriter;
3311 /// \brief Represents a dependent using declaration which was marked with
3315 /// template \<class T> class A : public Base<T> {
3316 /// using typename Base<T>::foo;
3320 /// The type associated with an unresolved using typename decl is
3321 /// currently always a typename type.
3322 class UnresolvedUsingTypenameDecl
3324 public Mergeable<UnresolvedUsingTypenameDecl> {
3325 void anchor() override;
3327 /// \brief The source location of the 'typename' keyword
3328 SourceLocation TypenameLocation;
3330 /// \brief If this is a pack expansion, the location of the '...'.
3331 SourceLocation EllipsisLoc;
3333 /// \brief The nested-name-specifier that precedes the name.
3334 NestedNameSpecifierLoc QualifierLoc;
3336 UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
3337 SourceLocation TypenameLoc,
3338 NestedNameSpecifierLoc QualifierLoc,
3339 SourceLocation TargetNameLoc,
3340 IdentifierInfo *TargetName,
3341 SourceLocation EllipsisLoc)
3342 : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName,
3344 TypenameLocation(TypenameLoc), EllipsisLoc(EllipsisLoc),
3345 QualifierLoc(QualifierLoc) { }
3347 friend class ASTDeclReader;
3350 /// \brief Returns the source location of the 'using' keyword.
3351 SourceLocation getUsingLoc() const { return getLocStart(); }
3353 /// \brief Returns the source location of the 'typename' keyword.
3354 SourceLocation getTypenameLoc() const { return TypenameLocation; }
3356 /// \brief Retrieve the nested-name-specifier that qualifies the name,
3357 /// with source-location information.
3358 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3360 /// \brief Retrieve the nested-name-specifier that qualifies the name.
3361 NestedNameSpecifier *getQualifier() const {
3362 return QualifierLoc.getNestedNameSpecifier();
3365 DeclarationNameInfo getNameInfo() const {
3366 return DeclarationNameInfo(getDeclName(), getLocation());
3369 /// \brief Determine whether this is a pack expansion.
3370 bool isPackExpansion() const {
3371 return EllipsisLoc.isValid();
3374 /// \brief Get the location of the ellipsis if this is a pack expansion.
3375 SourceLocation getEllipsisLoc() const {
3379 static UnresolvedUsingTypenameDecl *
3380 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
3381 SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc,
3382 SourceLocation TargetNameLoc, DeclarationName TargetName,
3383 SourceLocation EllipsisLoc);
3385 static UnresolvedUsingTypenameDecl *
3386 CreateDeserialized(ASTContext &C, unsigned ID);
3388 /// Retrieves the canonical declaration of this declaration.
3389 UnresolvedUsingTypenameDecl *getCanonicalDecl() override {
3390 return getFirstDecl();
3392 const UnresolvedUsingTypenameDecl *getCanonicalDecl() const {
3393 return getFirstDecl();
3396 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3397 static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; }
3400 /// \brief Represents a C++11 static_assert declaration.
3401 class StaticAssertDecl : public Decl {
3402 virtual void anchor();
3403 llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed;
3404 StringLiteral *Message;
3405 SourceLocation RParenLoc;
3407 StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc,
3408 Expr *AssertExpr, StringLiteral *Message,
3409 SourceLocation RParenLoc, bool Failed)
3410 : Decl(StaticAssert, DC, StaticAssertLoc),
3411 AssertExprAndFailed(AssertExpr, Failed), Message(Message),
3412 RParenLoc(RParenLoc) { }
3415 static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
3416 SourceLocation StaticAssertLoc,
3417 Expr *AssertExpr, StringLiteral *Message,
3418 SourceLocation RParenLoc, bool Failed);
3419 static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3421 Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); }
3422 const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); }
3424 StringLiteral *getMessage() { return Message; }
3425 const StringLiteral *getMessage() const { return Message; }
3427 bool isFailed() const { return AssertExprAndFailed.getInt(); }
3429 SourceLocation getRParenLoc() const { return RParenLoc; }
3431 SourceRange getSourceRange() const override LLVM_READONLY {
3432 return SourceRange(getLocation(), getRParenLoc());
3435 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3436 static bool classofKind(Kind K) { return K == StaticAssert; }
3438 friend class ASTDeclReader;
3441 /// A binding in a decomposition declaration. For instance, given:
3444 /// auto &[a, b, c] = n;
3446 /// a, b, and c are BindingDecls, whose bindings are the expressions
3447 /// x[0], x[1], and x[2] respectively, where x is the implicit
3448 /// DecompositionDecl of type 'int (&)[3]'.
3449 class BindingDecl : public ValueDecl {
3450 void anchor() override;
3452 /// The binding represented by this declaration. References to this
3453 /// declaration are effectively equivalent to this expression (except
3454 /// that it is only evaluated once at the point of declaration of the
3458 BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id)
3459 : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()), Binding(nullptr) {}
3462 static BindingDecl *Create(ASTContext &C, DeclContext *DC,
3463 SourceLocation IdLoc, IdentifierInfo *Id);
3464 static BindingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3466 /// Get the expression to which this declaration is bound. This may be null
3467 /// in two different cases: while parsing the initializer for the
3468 /// decomposition declaration, and when the initializer is type-dependent.
3469 Expr *getBinding() const { return Binding; }
3471 /// Get the variable (if any) that holds the value of evaluating the binding.
3472 /// Only present for user-defined bindings for tuple-like types.
3473 VarDecl *getHoldingVar() const;
3475 /// Set the binding for this BindingDecl, along with its declared type (which
3476 /// should be a possibly-cv-qualified form of the type of the binding, or a
3477 /// reference to such a type).
3478 void setBinding(QualType DeclaredType, Expr *Binding) {
3479 setType(DeclaredType);
3480 this->Binding = Binding;
3483 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3484 static bool classofKind(Kind K) { return K == Decl::Binding; }
3486 friend class ASTDeclReader;
3489 /// A decomposition declaration. For instance, given:
3492 /// auto &[a, b, c] = n;
3494 /// the second line declares a DecompositionDecl of type 'int (&)[3]', and
3495 /// three BindingDecls (named a, b, and c). An instance of this class is always
3496 /// unnamed, but behaves in almost all other respects like a VarDecl.
3497 class DecompositionDecl final
3499 private llvm::TrailingObjects<DecompositionDecl, BindingDecl *> {
3500 void anchor() override;
3502 /// The number of BindingDecl*s following this object.
3503 unsigned NumBindings;
3505 DecompositionDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3506 SourceLocation LSquareLoc, QualType T,
3507 TypeSourceInfo *TInfo, StorageClass SC,
3508 ArrayRef<BindingDecl *> Bindings)
3509 : VarDecl(Decomposition, C, DC, StartLoc, LSquareLoc, nullptr, T, TInfo,
3511 NumBindings(Bindings.size()) {
3512 std::uninitialized_copy(Bindings.begin(), Bindings.end(),
3513 getTrailingObjects<BindingDecl *>());
3517 static DecompositionDecl *Create(ASTContext &C, DeclContext *DC,
3518 SourceLocation StartLoc,
3519 SourceLocation LSquareLoc,
3520 QualType T, TypeSourceInfo *TInfo,
3522 ArrayRef<BindingDecl *> Bindings);
3523 static DecompositionDecl *CreateDeserialized(ASTContext &C, unsigned ID,
3524 unsigned NumBindings);
3526 ArrayRef<BindingDecl *> bindings() const {
3527 return llvm::makeArrayRef(getTrailingObjects<BindingDecl *>(), NumBindings);
3530 void printName(raw_ostream &os) const override;
3532 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3533 static bool classofKind(Kind K) { return K == Decomposition; }
3535 friend TrailingObjects;
3536 friend class ASTDeclReader;
3539 /// An instance of this class represents the declaration of a property
3540 /// member. This is a Microsoft extension to C++, first introduced in
3541 /// Visual Studio .NET 2003 as a parallel to similar features in C#
3542 /// and Managed C++.
3544 /// A property must always be a non-static class member.
3546 /// A property member superficially resembles a non-static data
3547 /// member, except preceded by a property attribute:
3548 /// __declspec(property(get=GetX, put=PutX)) int x;
3549 /// Either (but not both) of the 'get' and 'put' names may be omitted.
3551 /// A reference to a property is always an lvalue. If the lvalue
3552 /// undergoes lvalue-to-rvalue conversion, then a getter name is
3553 /// required, and that member is called with no arguments.
3554 /// If the lvalue is assigned into, then a setter name is required,
3555 /// and that member is called with one argument, the value assigned.
3556 /// Both operations are potentially overloaded. Compound assignments
3557 /// are permitted, as are the increment and decrement operators.
3559 /// The getter and putter methods are permitted to be overloaded,
3560 /// although their return and parameter types are subject to certain
3561 /// restrictions according to the type of the property.
3563 /// A property declared using an incomplete array type may
3564 /// additionally be subscripted, adding extra parameters to the getter
3565 /// and putter methods.
3566 class MSPropertyDecl : public DeclaratorDecl {
3567 IdentifierInfo *GetterId, *SetterId;
3569 MSPropertyDecl(DeclContext *DC, SourceLocation L, DeclarationName N,
3570 QualType T, TypeSourceInfo *TInfo, SourceLocation StartL,
3571 IdentifierInfo *Getter, IdentifierInfo *Setter)
3572 : DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL),
3573 GetterId(Getter), SetterId(Setter) {}
3576 static MSPropertyDecl *Create(ASTContext &C, DeclContext *DC,
3577 SourceLocation L, DeclarationName N, QualType T,
3578 TypeSourceInfo *TInfo, SourceLocation StartL,
3579 IdentifierInfo *Getter, IdentifierInfo *Setter);
3580 static MSPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3582 static bool classof(const Decl *D) { return D->getKind() == MSProperty; }
3584 bool hasGetter() const { return GetterId != nullptr; }
3585 IdentifierInfo* getGetterId() const { return GetterId; }
3586 bool hasSetter() const { return SetterId != nullptr; }
3587 IdentifierInfo* getSetterId() const { return SetterId; }
3589 friend class ASTDeclReader;
3592 /// Insertion operator for diagnostics. This allows sending an AccessSpecifier
3593 /// into a diagnostic with <<.
3594 const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
3595 AccessSpecifier AS);
3597 const PartialDiagnostic &operator<<(const PartialDiagnostic &DB,
3598 AccessSpecifier AS);
3600 } // end namespace clang