1 //===- DeclCXX.h - Classes for representing C++ declarations --*- C++ -*-=====//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// Defines the C++ Decl subclasses, other than those for templates
11 /// (found in DeclTemplate.h) and friends (in DeclFriend.h).
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_AST_DECLCXX_H
16 #define LLVM_CLANG_AST_DECLCXX_H
18 #include "clang/AST/ASTContext.h"
19 #include "clang/AST/ASTUnresolvedSet.h"
20 #include "clang/AST/Decl.h"
21 #include "clang/AST/DeclBase.h"
22 #include "clang/AST/DeclarationName.h"
23 #include "clang/AST/Expr.h"
24 #include "clang/AST/ExternalASTSource.h"
25 #include "clang/AST/LambdaCapture.h"
26 #include "clang/AST/NestedNameSpecifier.h"
27 #include "clang/AST/Redeclarable.h"
28 #include "clang/AST/Stmt.h"
29 #include "clang/AST/Type.h"
30 #include "clang/AST/TypeLoc.h"
31 #include "clang/AST/UnresolvedSet.h"
32 #include "clang/Basic/LLVM.h"
33 #include "clang/Basic/Lambda.h"
34 #include "clang/Basic/LangOptions.h"
35 #include "clang/Basic/OperatorKinds.h"
36 #include "clang/Basic/SourceLocation.h"
37 #include "clang/Basic/Specifiers.h"
38 #include "llvm/ADT/ArrayRef.h"
39 #include "llvm/ADT/DenseMap.h"
40 #include "llvm/ADT/PointerIntPair.h"
41 #include "llvm/ADT/PointerUnion.h"
42 #include "llvm/ADT/STLExtras.h"
43 #include "llvm/ADT/iterator_range.h"
44 #include "llvm/Support/Casting.h"
45 #include "llvm/Support/Compiler.h"
46 #include "llvm/Support/PointerLikeTypeTraits.h"
47 #include "llvm/Support/TrailingObjects.h"
56 class ClassTemplateDecl;
57 class ConstructorUsingShadowDecl;
60 class CXXConstructorDecl;
61 class CXXDestructorDecl;
62 class CXXFinalOverriderMap;
63 class CXXIndirectPrimaryBaseSet;
65 class DecompositionDecl;
66 class DiagnosticBuilder;
68 class FunctionTemplateDecl;
70 class MemberSpecializationInfo;
72 class TemplateParameterList;
75 /// Represents an access specifier followed by colon ':'.
77 /// An objects of this class represents sugar for the syntactic occurrence
78 /// of an access specifier followed by a colon in the list of member
79 /// specifiers of a C++ class definition.
81 /// Note that they do not represent other uses of access specifiers,
82 /// such as those occurring in a list of base specifiers.
83 /// Also note that this class has nothing to do with so-called
84 /// "access declarations" (C++98 11.3 [class.access.dcl]).
85 class AccessSpecDecl : public Decl {
86 /// The location of the ':'.
87 SourceLocation ColonLoc;
89 AccessSpecDecl(AccessSpecifier AS, DeclContext *DC,
90 SourceLocation ASLoc, SourceLocation ColonLoc)
91 : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) {
95 AccessSpecDecl(EmptyShell Empty) : Decl(AccessSpec, Empty) {}
97 virtual void anchor();
100 /// The location of the access specifier.
101 SourceLocation getAccessSpecifierLoc() const { return getLocation(); }
103 /// Sets the location of the access specifier.
104 void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); }
106 /// The location of the colon following the access specifier.
107 SourceLocation getColonLoc() const { return ColonLoc; }
109 /// Sets the location of the colon.
110 void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; }
112 SourceRange getSourceRange() const override LLVM_READONLY {
113 return SourceRange(getAccessSpecifierLoc(), getColonLoc());
116 static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS,
117 DeclContext *DC, SourceLocation ASLoc,
118 SourceLocation ColonLoc) {
119 return new (C, DC) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
122 static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
124 // Implement isa/cast/dyncast/etc.
125 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
126 static bool classofKind(Kind K) { return K == AccessSpec; }
129 /// Represents a base class of a C++ class.
131 /// Each CXXBaseSpecifier represents a single, direct base class (or
132 /// struct) of a C++ class (or struct). It specifies the type of that
133 /// base class, whether it is a virtual or non-virtual base, and what
134 /// level of access (public, protected, private) is used for the
135 /// derivation. For example:
140 /// class C : public virtual A, protected B { };
143 /// In this code, C will have two CXXBaseSpecifiers, one for "public
144 /// virtual A" and the other for "protected B".
145 class CXXBaseSpecifier {
146 /// The source code range that covers the full base
147 /// specifier, including the "virtual" (if present) and access
148 /// specifier (if present).
151 /// The source location of the ellipsis, if this is a pack
153 SourceLocation EllipsisLoc;
155 /// Whether this is a virtual base class or not.
156 unsigned Virtual : 1;
158 /// Whether this is the base of a class (true) or of a struct (false).
160 /// This determines the mapping from the access specifier as written in the
161 /// source code to the access specifier used for semantic analysis.
162 unsigned BaseOfClass : 1;
164 /// Access specifier as written in the source code (may be AS_none).
166 /// The actual type of data stored here is an AccessSpecifier, but we use
167 /// "unsigned" here to work around a VC++ bug.
170 /// Whether the class contains a using declaration
171 /// to inherit the named class's constructors.
172 unsigned InheritConstructors : 1;
174 /// The type of the base class.
176 /// This will be a class or struct (or a typedef of such). The source code
177 /// range does not include the \c virtual or the access specifier.
178 TypeSourceInfo *BaseTypeInfo;
181 CXXBaseSpecifier() = default;
182 CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A,
183 TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
184 : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC),
185 Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) {}
187 /// Retrieves the source range that contains the entire base specifier.
188 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
189 SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
190 SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
192 /// Get the location at which the base class type was written.
193 SourceLocation getBaseTypeLoc() const LLVM_READONLY {
194 return BaseTypeInfo->getTypeLoc().getBeginLoc();
197 /// Determines whether the base class is a virtual base class (or not).
198 bool isVirtual() const { return Virtual; }
200 /// Determine whether this base class is a base of a class declared
201 /// with the 'class' keyword (vs. one declared with the 'struct' keyword).
202 bool isBaseOfClass() const { return BaseOfClass; }
204 /// Determine whether this base specifier is a pack expansion.
205 bool isPackExpansion() const { return EllipsisLoc.isValid(); }
207 /// Determine whether this base class's constructors get inherited.
208 bool getInheritConstructors() const { return InheritConstructors; }
210 /// Set that this base class's constructors should be inherited.
211 void setInheritConstructors(bool Inherit = true) {
212 InheritConstructors = Inherit;
215 /// For a pack expansion, determine the location of the ellipsis.
216 SourceLocation getEllipsisLoc() const {
220 /// Returns the access specifier for this base specifier.
222 /// This is the actual base specifier as used for semantic analysis, so
223 /// the result can never be AS_none. To retrieve the access specifier as
224 /// written in the source code, use getAccessSpecifierAsWritten().
225 AccessSpecifier getAccessSpecifier() const {
226 if ((AccessSpecifier)Access == AS_none)
227 return BaseOfClass? AS_private : AS_public;
229 return (AccessSpecifier)Access;
232 /// Retrieves the access specifier as written in the source code
233 /// (which may mean that no access specifier was explicitly written).
235 /// Use getAccessSpecifier() to retrieve the access specifier for use in
236 /// semantic analysis.
237 AccessSpecifier getAccessSpecifierAsWritten() const {
238 return (AccessSpecifier)Access;
241 /// Retrieves the type of the base class.
243 /// This type will always be an unqualified class type.
244 QualType getType() const {
245 return BaseTypeInfo->getType().getUnqualifiedType();
248 /// Retrieves the type and source location of the base class.
249 TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; }
252 /// Represents a C++ struct/union/class.
253 class CXXRecordDecl : public RecordDecl {
254 friend class ASTDeclReader;
255 friend class ASTDeclWriter;
256 friend class ASTNodeImporter;
257 friend class ASTReader;
258 friend class ASTRecordWriter;
259 friend class ASTWriter;
260 friend class DeclContext;
261 friend class LambdaExpr;
263 friend void FunctionDecl::setPure(bool);
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 #define FIELD(Name, Width, Merge) \
279 unsigned Name : Width;
280 #include "CXXRecordDeclDefinitionBits.def"
282 /// Whether this class describes a C++ lambda.
283 unsigned IsLambda : 1;
285 /// Whether we are currently parsing base specifiers.
286 unsigned IsParsingBaseSpecifiers : 1;
288 /// True when visible conversion functions are already computed
289 /// and are available.
290 unsigned ComputedVisibleConversions : 1;
292 unsigned HasODRHash : 1;
294 /// A hash of parts of the class to help in ODR checking.
295 unsigned ODRHash = 0;
297 /// The number of base class specifiers in Bases.
298 unsigned NumBases = 0;
300 /// The number of virtual base class specifiers in VBases.
301 unsigned NumVBases = 0;
303 /// Base classes of this class.
305 /// FIXME: This is wasted space for a union.
306 LazyCXXBaseSpecifiersPtr Bases;
308 /// direct and indirect virtual base classes of this class.
309 LazyCXXBaseSpecifiersPtr VBases;
311 /// The conversion functions of this C++ class (but not its
312 /// inherited conversion functions).
314 /// Each of the entries in this overload set is a CXXConversionDecl.
315 LazyASTUnresolvedSet Conversions;
317 /// The conversion functions of this C++ class and all those
318 /// inherited conversion functions that are visible in this class.
320 /// Each of the entries in this overload set is a CXXConversionDecl or a
321 /// FunctionTemplateDecl.
322 LazyASTUnresolvedSet VisibleConversions;
324 /// The declaration which defines this record.
325 CXXRecordDecl *Definition;
327 /// The first friend declaration in this class, or null if there
330 /// This is actually currently stored in reverse order.
331 LazyDeclPtr FirstFriend;
333 DefinitionData(CXXRecordDecl *D);
335 /// Retrieve the set of direct base classes.
336 CXXBaseSpecifier *getBases() const {
337 if (!Bases.isOffset())
338 return Bases.get(nullptr);
339 return getBasesSlowCase();
342 /// Retrieve the set of virtual base classes.
343 CXXBaseSpecifier *getVBases() const {
344 if (!VBases.isOffset())
345 return VBases.get(nullptr);
346 return getVBasesSlowCase();
349 ArrayRef<CXXBaseSpecifier> bases() const {
350 return llvm::makeArrayRef(getBases(), NumBases);
353 ArrayRef<CXXBaseSpecifier> vbases() const {
354 return llvm::makeArrayRef(getVBases(), NumVBases);
358 CXXBaseSpecifier *getBasesSlowCase() const;
359 CXXBaseSpecifier *getVBasesSlowCase() const;
362 struct DefinitionData *DefinitionData;
364 /// Describes a C++ closure type (generated by a lambda expression).
365 struct LambdaDefinitionData : public DefinitionData {
366 using Capture = LambdaCapture;
368 /// Whether this lambda is known to be dependent, even if its
369 /// context isn't dependent.
371 /// A lambda with a non-dependent context can be dependent if it occurs
372 /// within the default argument of a function template, because the
373 /// lambda will have been created with the enclosing context as its
374 /// declaration context, rather than function. This is an unfortunate
375 /// artifact of having to parse the default arguments before.
376 unsigned Dependent : 1;
378 /// Whether this lambda is a generic lambda.
379 unsigned IsGenericLambda : 1;
381 /// The Default Capture.
382 unsigned CaptureDefault : 2;
384 /// The number of captures in this lambda is limited 2^NumCaptures.
385 unsigned NumCaptures : 15;
387 /// The number of explicit captures in this lambda.
388 unsigned NumExplicitCaptures : 13;
390 /// Has known `internal` linkage.
391 unsigned HasKnownInternalLinkage : 1;
393 /// The number used to indicate this lambda expression for name
394 /// mangling in the Itanium C++ ABI.
395 unsigned ManglingNumber : 31;
397 /// The declaration that provides context for this lambda, if the
398 /// actual DeclContext does not suffice. This is used for lambdas that
399 /// occur within default arguments of function parameters within the class
400 /// or within a data member initializer.
401 LazyDeclPtr ContextDecl;
403 /// The list of captures, both explicit and implicit, for this
405 Capture *Captures = nullptr;
407 /// The type of the call method.
408 TypeSourceInfo *MethodTyInfo;
410 LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info, bool Dependent,
411 bool IsGeneric, LambdaCaptureDefault CaptureDefault)
412 : DefinitionData(D), Dependent(Dependent), IsGenericLambda(IsGeneric),
413 CaptureDefault(CaptureDefault), NumCaptures(0),
414 NumExplicitCaptures(0), HasKnownInternalLinkage(0), ManglingNumber(0),
418 // C++1z [expr.prim.lambda]p4:
419 // This class type is not an aggregate type.
421 PlainOldData = false;
425 struct DefinitionData *dataPtr() const {
426 // Complete the redecl chain (if necessary).
428 return DefinitionData;
431 struct DefinitionData &data() const {
432 auto *DD = dataPtr();
433 assert(DD && "queried property of class with no definition");
437 struct LambdaDefinitionData &getLambdaData() const {
438 // No update required: a merged definition cannot change any lambda
440 auto *DD = DefinitionData;
441 assert(DD && DD->IsLambda && "queried lambda property of non-lambda class");
442 return static_cast<LambdaDefinitionData&>(*DD);
445 /// The template or declaration that this declaration
446 /// describes or was instantiated from, respectively.
448 /// For non-templates, this value will be null. For record
449 /// declarations that describe a class template, this will be a
450 /// pointer to a ClassTemplateDecl. For member
451 /// classes of class template specializations, this will be the
452 /// MemberSpecializationInfo referring to the member class that was
453 /// instantiated or specialized.
454 llvm::PointerUnion<ClassTemplateDecl *, MemberSpecializationInfo *>
455 TemplateOrInstantiation;
457 /// Called from setBases and addedMember to notify the class that a
458 /// direct or virtual base class or a member of class type has been added.
459 void addedClassSubobject(CXXRecordDecl *Base);
461 /// Notify the class that member has been added.
463 /// This routine helps maintain information about the class based on which
464 /// members have been added. It will be invoked by DeclContext::addDecl()
465 /// whenever a member is added to this record.
466 void addedMember(Decl *D);
468 void markedVirtualFunctionPure();
470 /// Get the head of our list of friend declarations, possibly
471 /// deserializing the friends from an external AST source.
472 FriendDecl *getFirstFriend() const;
474 /// Determine whether this class has an empty base class subobject of type X
475 /// or of one of the types that might be at offset 0 within X (per the C++
476 /// "standard layout" rules).
477 bool hasSubobjectAtOffsetZeroOfEmptyBaseType(ASTContext &Ctx,
478 const CXXRecordDecl *X);
481 CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, DeclContext *DC,
482 SourceLocation StartLoc, SourceLocation IdLoc,
483 IdentifierInfo *Id, CXXRecordDecl *PrevDecl);
486 /// Iterator that traverses the base classes of a class.
487 using base_class_iterator = CXXBaseSpecifier *;
489 /// Iterator that traverses the base classes of a class.
490 using base_class_const_iterator = const CXXBaseSpecifier *;
492 CXXRecordDecl *getCanonicalDecl() override {
493 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
496 const CXXRecordDecl *getCanonicalDecl() const {
497 return const_cast<CXXRecordDecl*>(this)->getCanonicalDecl();
500 CXXRecordDecl *getPreviousDecl() {
501 return cast_or_null<CXXRecordDecl>(
502 static_cast<RecordDecl *>(this)->getPreviousDecl());
505 const CXXRecordDecl *getPreviousDecl() const {
506 return const_cast<CXXRecordDecl*>(this)->getPreviousDecl();
509 CXXRecordDecl *getMostRecentDecl() {
510 return cast<CXXRecordDecl>(
511 static_cast<RecordDecl *>(this)->getMostRecentDecl());
514 const CXXRecordDecl *getMostRecentDecl() const {
515 return const_cast<CXXRecordDecl*>(this)->getMostRecentDecl();
518 CXXRecordDecl *getMostRecentNonInjectedDecl() {
519 CXXRecordDecl *Recent =
520 static_cast<CXXRecordDecl *>(this)->getMostRecentDecl();
521 while (Recent->isInjectedClassName()) {
522 // FIXME: Does injected class name need to be in the redeclarations chain?
523 assert(Recent->getPreviousDecl());
524 Recent = Recent->getPreviousDecl();
529 const CXXRecordDecl *getMostRecentNonInjectedDecl() const {
530 return const_cast<CXXRecordDecl*>(this)->getMostRecentNonInjectedDecl();
533 CXXRecordDecl *getDefinition() const {
534 // We only need an update if we don't already know which
535 // declaration is the definition.
536 auto *DD = DefinitionData ? DefinitionData : dataPtr();
537 return DD ? DD->Definition : nullptr;
540 bool hasDefinition() const { return DefinitionData || dataPtr(); }
542 static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
543 SourceLocation StartLoc, SourceLocation IdLoc,
545 CXXRecordDecl *PrevDecl = nullptr,
546 bool DelayTypeCreation = false);
547 static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC,
548 TypeSourceInfo *Info, SourceLocation Loc,
549 bool DependentLambda, bool IsGeneric,
550 LambdaCaptureDefault CaptureDefault);
551 static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID);
553 bool isDynamicClass() const {
554 return data().Polymorphic || data().NumVBases != 0;
557 /// @returns true if class is dynamic or might be dynamic because the
558 /// definition is incomplete of dependent.
559 bool mayBeDynamicClass() const {
560 return !hasDefinition() || isDynamicClass() || hasAnyDependentBases();
563 /// @returns true if class is non dynamic or might be non dynamic because the
564 /// definition is incomplete of dependent.
565 bool mayBeNonDynamicClass() const {
566 return !hasDefinition() || !isDynamicClass() || hasAnyDependentBases();
569 void setIsParsingBaseSpecifiers() { data().IsParsingBaseSpecifiers = true; }
571 bool isParsingBaseSpecifiers() const {
572 return data().IsParsingBaseSpecifiers;
575 unsigned getODRHash() const;
577 /// Sets the base classes of this struct or class.
578 void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
580 /// Retrieves the number of base classes of this class.
581 unsigned getNumBases() const { return data().NumBases; }
583 using base_class_range = llvm::iterator_range<base_class_iterator>;
584 using base_class_const_range =
585 llvm::iterator_range<base_class_const_iterator>;
587 base_class_range bases() {
588 return base_class_range(bases_begin(), bases_end());
590 base_class_const_range bases() const {
591 return base_class_const_range(bases_begin(), bases_end());
594 base_class_iterator bases_begin() { return data().getBases(); }
595 base_class_const_iterator bases_begin() const { return data().getBases(); }
596 base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
597 base_class_const_iterator bases_end() const {
598 return bases_begin() + data().NumBases;
601 /// Retrieves the number of virtual base classes of this class.
602 unsigned getNumVBases() const { return data().NumVBases; }
604 base_class_range vbases() {
605 return base_class_range(vbases_begin(), vbases_end());
607 base_class_const_range vbases() const {
608 return base_class_const_range(vbases_begin(), vbases_end());
611 base_class_iterator vbases_begin() { return data().getVBases(); }
612 base_class_const_iterator vbases_begin() const { return data().getVBases(); }
613 base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
614 base_class_const_iterator vbases_end() const {
615 return vbases_begin() + data().NumVBases;
618 /// Determine whether this class has any dependent base classes which
619 /// are not the current instantiation.
620 bool hasAnyDependentBases() const;
622 /// Iterator access to method members. The method iterator visits
623 /// all method members of the class, including non-instance methods,
624 /// special methods, etc.
625 using method_iterator = specific_decl_iterator<CXXMethodDecl>;
627 llvm::iterator_range<specific_decl_iterator<CXXMethodDecl>>;
629 method_range methods() const {
630 return method_range(method_begin(), method_end());
633 /// Method begin iterator. Iterates in the order the methods
635 method_iterator method_begin() const {
636 return method_iterator(decls_begin());
639 /// Method past-the-end iterator.
640 method_iterator method_end() const {
641 return method_iterator(decls_end());
644 /// Iterator access to constructor members.
645 using ctor_iterator = specific_decl_iterator<CXXConstructorDecl>;
647 llvm::iterator_range<specific_decl_iterator<CXXConstructorDecl>>;
649 ctor_range ctors() const { return ctor_range(ctor_begin(), ctor_end()); }
651 ctor_iterator ctor_begin() const {
652 return ctor_iterator(decls_begin());
655 ctor_iterator ctor_end() const {
656 return ctor_iterator(decls_end());
659 /// An iterator over friend declarations. All of these are defined
661 class friend_iterator;
662 using friend_range = llvm::iterator_range<friend_iterator>;
664 friend_range friends() const;
665 friend_iterator friend_begin() const;
666 friend_iterator friend_end() const;
667 void pushFriendDecl(FriendDecl *FD);
669 /// Determines whether this record has any friends.
670 bool hasFriends() const {
671 return data().FirstFriend.isValid();
674 /// \c true if a defaulted copy constructor for this class would be
676 bool defaultedCopyConstructorIsDeleted() const {
677 assert((!needsOverloadResolutionForCopyConstructor() ||
678 (data().DeclaredSpecialMembers & SMF_CopyConstructor)) &&
679 "this property has not yet been computed by Sema");
680 return data().DefaultedCopyConstructorIsDeleted;
683 /// \c true if a defaulted move constructor for this class would be
685 bool defaultedMoveConstructorIsDeleted() const {
686 assert((!needsOverloadResolutionForMoveConstructor() ||
687 (data().DeclaredSpecialMembers & SMF_MoveConstructor)) &&
688 "this property has not yet been computed by Sema");
689 return data().DefaultedMoveConstructorIsDeleted;
692 /// \c true if a defaulted destructor for this class would be deleted.
693 bool defaultedDestructorIsDeleted() const {
694 assert((!needsOverloadResolutionForDestructor() ||
695 (data().DeclaredSpecialMembers & SMF_Destructor)) &&
696 "this property has not yet been computed by Sema");
697 return data().DefaultedDestructorIsDeleted;
700 /// \c true if we know for sure that this class has a single,
701 /// accessible, unambiguous copy constructor that is not deleted.
702 bool hasSimpleCopyConstructor() const {
703 return !hasUserDeclaredCopyConstructor() &&
704 !data().DefaultedCopyConstructorIsDeleted;
707 /// \c true if we know for sure that this class has a single,
708 /// accessible, unambiguous move constructor that is not deleted.
709 bool hasSimpleMoveConstructor() const {
710 return !hasUserDeclaredMoveConstructor() && hasMoveConstructor() &&
711 !data().DefaultedMoveConstructorIsDeleted;
714 /// \c true if we know for sure that this class has a single,
715 /// accessible, unambiguous move assignment operator that is not deleted.
716 bool hasSimpleMoveAssignment() const {
717 return !hasUserDeclaredMoveAssignment() && hasMoveAssignment() &&
718 !data().DefaultedMoveAssignmentIsDeleted;
721 /// \c true if we know for sure that this class has an accessible
722 /// destructor that is not deleted.
723 bool hasSimpleDestructor() const {
724 return !hasUserDeclaredDestructor() &&
725 !data().DefaultedDestructorIsDeleted;
728 /// Determine whether this class has any default constructors.
729 bool hasDefaultConstructor() const {
730 return (data().DeclaredSpecialMembers & SMF_DefaultConstructor) ||
731 needsImplicitDefaultConstructor();
734 /// Determine if we need to declare a default constructor for
737 /// This value is used for lazy creation of default constructors.
738 bool needsImplicitDefaultConstructor() const {
739 return !data().UserDeclaredConstructor &&
740 !(data().DeclaredSpecialMembers & SMF_DefaultConstructor) &&
741 (!isLambda() || lambdaIsDefaultConstructibleAndAssignable());
744 /// Determine whether this class has any user-declared constructors.
746 /// When true, a default constructor will not be implicitly declared.
747 bool hasUserDeclaredConstructor() const {
748 return data().UserDeclaredConstructor;
751 /// Whether this class has a user-provided default constructor
753 bool hasUserProvidedDefaultConstructor() const {
754 return data().UserProvidedDefaultConstructor;
757 /// Determine whether this class has a user-declared copy constructor.
759 /// When false, a copy constructor will be implicitly declared.
760 bool hasUserDeclaredCopyConstructor() const {
761 return data().UserDeclaredSpecialMembers & SMF_CopyConstructor;
764 /// Determine whether this class needs an implicit copy
765 /// constructor to be lazily declared.
766 bool needsImplicitCopyConstructor() const {
767 return !(data().DeclaredSpecialMembers & SMF_CopyConstructor);
770 /// Determine whether we need to eagerly declare a defaulted copy
771 /// constructor for this class.
772 bool needsOverloadResolutionForCopyConstructor() const {
773 // C++17 [class.copy.ctor]p6:
774 // If the class definition declares a move constructor or move assignment
775 // operator, the implicitly declared copy constructor is defined as
777 // In MSVC mode, sometimes a declared move assignment does not delete an
778 // implicit copy constructor, so defer this choice to Sema.
779 if (data().UserDeclaredSpecialMembers &
780 (SMF_MoveConstructor | SMF_MoveAssignment))
782 return data().NeedOverloadResolutionForCopyConstructor;
785 /// Determine whether an implicit copy constructor for this type
786 /// would have a parameter with a const-qualified reference type.
787 bool implicitCopyConstructorHasConstParam() const {
788 return data().ImplicitCopyConstructorCanHaveConstParamForNonVBase &&
790 data().ImplicitCopyConstructorCanHaveConstParamForVBase);
793 /// Determine whether this class has a copy constructor with
794 /// a parameter type which is a reference to a const-qualified type.
795 bool hasCopyConstructorWithConstParam() const {
796 return data().HasDeclaredCopyConstructorWithConstParam ||
797 (needsImplicitCopyConstructor() &&
798 implicitCopyConstructorHasConstParam());
801 /// Whether this class has a user-declared move constructor or
802 /// assignment operator.
804 /// When false, a move constructor and assignment operator may be
805 /// implicitly declared.
806 bool hasUserDeclaredMoveOperation() const {
807 return data().UserDeclaredSpecialMembers &
808 (SMF_MoveConstructor | SMF_MoveAssignment);
811 /// Determine whether this class has had a move constructor
812 /// declared by the user.
813 bool hasUserDeclaredMoveConstructor() const {
814 return data().UserDeclaredSpecialMembers & SMF_MoveConstructor;
817 /// Determine whether this class has a move constructor.
818 bool hasMoveConstructor() const {
819 return (data().DeclaredSpecialMembers & SMF_MoveConstructor) ||
820 needsImplicitMoveConstructor();
823 /// Set that we attempted to declare an implicit copy
824 /// constructor, but overload resolution failed so we deleted it.
825 void setImplicitCopyConstructorIsDeleted() {
826 assert((data().DefaultedCopyConstructorIsDeleted ||
827 needsOverloadResolutionForCopyConstructor()) &&
828 "Copy constructor should not be deleted");
829 data().DefaultedCopyConstructorIsDeleted = true;
832 /// Set that we attempted to declare an implicit move
833 /// constructor, but overload resolution failed so we deleted it.
834 void setImplicitMoveConstructorIsDeleted() {
835 assert((data().DefaultedMoveConstructorIsDeleted ||
836 needsOverloadResolutionForMoveConstructor()) &&
837 "move constructor should not be deleted");
838 data().DefaultedMoveConstructorIsDeleted = true;
841 /// Set that we attempted to declare an implicit destructor,
842 /// but overload resolution failed so we deleted it.
843 void setImplicitDestructorIsDeleted() {
844 assert((data().DefaultedDestructorIsDeleted ||
845 needsOverloadResolutionForDestructor()) &&
846 "destructor should not be deleted");
847 data().DefaultedDestructorIsDeleted = true;
850 /// Determine whether this class should get an implicit move
851 /// constructor or if any existing special member function inhibits this.
852 bool needsImplicitMoveConstructor() const {
853 return !(data().DeclaredSpecialMembers & SMF_MoveConstructor) &&
854 !hasUserDeclaredCopyConstructor() &&
855 !hasUserDeclaredCopyAssignment() &&
856 !hasUserDeclaredMoveAssignment() &&
857 !hasUserDeclaredDestructor();
860 /// Determine whether we need to eagerly declare a defaulted move
861 /// constructor for this class.
862 bool needsOverloadResolutionForMoveConstructor() const {
863 return data().NeedOverloadResolutionForMoveConstructor;
866 /// Determine whether this class has a user-declared copy assignment
869 /// When false, a copy assignment operator will be implicitly declared.
870 bool hasUserDeclaredCopyAssignment() const {
871 return data().UserDeclaredSpecialMembers & SMF_CopyAssignment;
874 /// Determine whether this class needs an implicit copy
875 /// assignment operator to be lazily declared.
876 bool needsImplicitCopyAssignment() const {
877 return !(data().DeclaredSpecialMembers & SMF_CopyAssignment);
880 /// Determine whether we need to eagerly declare a defaulted copy
881 /// assignment operator for this class.
882 bool needsOverloadResolutionForCopyAssignment() const {
883 return data().HasMutableFields;
886 /// Determine whether an implicit copy assignment operator for this
887 /// type would have a parameter with a const-qualified reference type.
888 bool implicitCopyAssignmentHasConstParam() const {
889 return data().ImplicitCopyAssignmentHasConstParam;
892 /// Determine whether this class has a copy assignment operator with
893 /// a parameter type which is a reference to a const-qualified type or is not
895 bool hasCopyAssignmentWithConstParam() const {
896 return data().HasDeclaredCopyAssignmentWithConstParam ||
897 (needsImplicitCopyAssignment() &&
898 implicitCopyAssignmentHasConstParam());
901 /// Determine whether this class has had a move assignment
902 /// declared by the user.
903 bool hasUserDeclaredMoveAssignment() const {
904 return data().UserDeclaredSpecialMembers & SMF_MoveAssignment;
907 /// Determine whether this class has a move assignment operator.
908 bool hasMoveAssignment() const {
909 return (data().DeclaredSpecialMembers & SMF_MoveAssignment) ||
910 needsImplicitMoveAssignment();
913 /// Set that we attempted to declare an implicit move assignment
914 /// operator, but overload resolution failed so we deleted it.
915 void setImplicitMoveAssignmentIsDeleted() {
916 assert((data().DefaultedMoveAssignmentIsDeleted ||
917 needsOverloadResolutionForMoveAssignment()) &&
918 "move assignment should not be deleted");
919 data().DefaultedMoveAssignmentIsDeleted = true;
922 /// Determine whether this class should get an implicit move
923 /// assignment operator or if any existing special member function inhibits
925 bool needsImplicitMoveAssignment() const {
926 return !(data().DeclaredSpecialMembers & SMF_MoveAssignment) &&
927 !hasUserDeclaredCopyConstructor() &&
928 !hasUserDeclaredCopyAssignment() &&
929 !hasUserDeclaredMoveConstructor() &&
930 !hasUserDeclaredDestructor() &&
931 (!isLambda() || lambdaIsDefaultConstructibleAndAssignable());
934 /// Determine whether we need to eagerly declare a move assignment
935 /// operator for this class.
936 bool needsOverloadResolutionForMoveAssignment() const {
937 return data().NeedOverloadResolutionForMoveAssignment;
940 /// Determine whether this class has a user-declared destructor.
942 /// When false, a destructor will be implicitly declared.
943 bool hasUserDeclaredDestructor() const {
944 return data().UserDeclaredSpecialMembers & SMF_Destructor;
947 /// Determine whether this class needs an implicit destructor to
948 /// be lazily declared.
949 bool needsImplicitDestructor() const {
950 return !(data().DeclaredSpecialMembers & SMF_Destructor);
953 /// Determine whether we need to eagerly declare a destructor for this
955 bool needsOverloadResolutionForDestructor() const {
956 return data().NeedOverloadResolutionForDestructor;
959 /// Determine whether this class describes a lambda function object.
960 bool isLambda() const {
961 // An update record can't turn a non-lambda into a lambda.
962 auto *DD = DefinitionData;
963 return DD && DD->IsLambda;
966 /// Determine whether this class describes a generic
967 /// lambda function object (i.e. function call operator is
969 bool isGenericLambda() const;
971 /// Determine whether this lambda should have an implicit default constructor
972 /// and copy and move assignment operators.
973 bool lambdaIsDefaultConstructibleAndAssignable() const;
975 /// Retrieve the lambda call operator of the closure type
976 /// if this is a closure type.
977 CXXMethodDecl *getLambdaCallOperator() const;
979 /// Retrieve the dependent lambda call operator of the closure type
980 /// if this is a templated closure type.
981 FunctionTemplateDecl *getDependentLambdaCallOperator() const;
983 /// Retrieve the lambda static invoker, the address of which
984 /// is returned by the conversion operator, and the body of which
985 /// is forwarded to the lambda call operator.
986 CXXMethodDecl *getLambdaStaticInvoker() const;
988 /// Retrieve the generic lambda's template parameter list.
989 /// Returns null if the class does not represent a lambda or a generic
991 TemplateParameterList *getGenericLambdaTemplateParameterList() const;
993 /// Retrieve the lambda template parameters that were specified explicitly.
994 ArrayRef<NamedDecl *> getLambdaExplicitTemplateParameters() const;
996 LambdaCaptureDefault getLambdaCaptureDefault() const {
998 return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault);
1001 /// For a closure type, retrieve the mapping from captured
1002 /// variables and \c this to the non-static data members that store the
1003 /// values or references of the captures.
1005 /// \param Captures Will be populated with the mapping from captured
1006 /// variables to the corresponding fields.
1008 /// \param ThisCapture Will be set to the field declaration for the
1009 /// \c this capture.
1011 /// \note No entries will be added for init-captures, as they do not capture
1013 void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures,
1014 FieldDecl *&ThisCapture) const;
1016 using capture_const_iterator = const LambdaCapture *;
1017 using capture_const_range = llvm::iterator_range<capture_const_iterator>;
1019 capture_const_range captures() const {
1020 return capture_const_range(captures_begin(), captures_end());
1023 capture_const_iterator captures_begin() const {
1024 return isLambda() ? getLambdaData().Captures : nullptr;
1027 capture_const_iterator captures_end() const {
1028 return isLambda() ? captures_begin() + getLambdaData().NumCaptures
1032 using conversion_iterator = UnresolvedSetIterator;
1034 conversion_iterator conversion_begin() const {
1035 return data().Conversions.get(getASTContext()).begin();
1038 conversion_iterator conversion_end() const {
1039 return data().Conversions.get(getASTContext()).end();
1042 /// Removes a conversion function from this class. The conversion
1043 /// function must currently be a member of this class. Furthermore,
1044 /// this class must currently be in the process of being defined.
1045 void removeConversion(const NamedDecl *Old);
1047 /// Get all conversion functions visible in current class,
1048 /// including conversion function templates.
1049 llvm::iterator_range<conversion_iterator>
1050 getVisibleConversionFunctions() const;
1052 /// Determine whether this class is an aggregate (C++ [dcl.init.aggr]),
1053 /// which is a class with no user-declared constructors, no private
1054 /// or protected non-static data members, no base classes, and no virtual
1055 /// functions (C++ [dcl.init.aggr]p1).
1056 bool isAggregate() const { return data().Aggregate; }
1058 /// Whether this class has any in-class initializers
1059 /// for non-static data members (including those in anonymous unions or
1061 bool hasInClassInitializer() const { return data().HasInClassInitializer; }
1063 /// Whether this class or any of its subobjects has any members of
1064 /// reference type which would make value-initialization ill-formed.
1066 /// Per C++03 [dcl.init]p5:
1067 /// - if T is a non-union class type without a user-declared constructor,
1068 /// then every non-static data member and base-class component of T is
1069 /// value-initialized [...] A program that calls for [...]
1070 /// value-initialization of an entity of reference type is ill-formed.
1071 bool hasUninitializedReferenceMember() const {
1072 return !isUnion() && !hasUserDeclaredConstructor() &&
1073 data().HasUninitializedReferenceMember;
1076 /// Whether this class is a POD-type (C++ [class]p4)
1078 /// For purposes of this function a class is POD if it is an aggregate
1079 /// that has no non-static non-POD data members, no reference data
1080 /// members, no user-defined copy assignment operator and no
1081 /// user-defined destructor.
1083 /// Note that this is the C++ TR1 definition of POD.
1084 bool isPOD() const { return data().PlainOldData; }
1086 /// True if this class is C-like, without C++-specific features, e.g.
1087 /// it contains only public fields, no bases, tag kind is not 'class', etc.
1088 bool isCLike() const;
1090 /// Determine whether this is an empty class in the sense of
1091 /// (C++11 [meta.unary.prop]).
1093 /// The CXXRecordDecl is a class type, but not a union type,
1094 /// with no non-static data members other than bit-fields of length 0,
1095 /// no virtual member functions, no virtual base classes,
1096 /// and no base class B for which is_empty<B>::value is false.
1098 /// \note This does NOT include a check for union-ness.
1099 bool isEmpty() const { return data().Empty; }
1101 bool hasPrivateFields() const {
1102 return data().HasPrivateFields;
1105 bool hasProtectedFields() const {
1106 return data().HasProtectedFields;
1109 /// Determine whether this class has direct non-static data members.
1110 bool hasDirectFields() const {
1112 return D.HasPublicFields || D.HasProtectedFields || D.HasPrivateFields;
1115 /// Whether this class is polymorphic (C++ [class.virtual]),
1116 /// which means that the class contains or inherits a virtual function.
1117 bool isPolymorphic() const { return data().Polymorphic; }
1119 /// Determine whether this class has a pure virtual function.
1121 /// The class is is abstract per (C++ [class.abstract]p2) if it declares
1122 /// a pure virtual function or inherits a pure virtual function that is
1124 bool isAbstract() const { return data().Abstract; }
1126 /// Determine whether this class is standard-layout per
1128 bool isStandardLayout() const { return data().IsStandardLayout; }
1130 /// Determine whether this class was standard-layout per
1131 /// C++11 [class]p7, specifically using the C++11 rules without any DRs.
1132 bool isCXX11StandardLayout() const { return data().IsCXX11StandardLayout; }
1134 /// Determine whether this class, or any of its class subobjects,
1135 /// contains a mutable field.
1136 bool hasMutableFields() const { return data().HasMutableFields; }
1138 /// Determine whether this class has any variant members.
1139 bool hasVariantMembers() const { return data().HasVariantMembers; }
1141 /// Determine whether this class has a trivial default constructor
1142 /// (C++11 [class.ctor]p5).
1143 bool hasTrivialDefaultConstructor() const {
1144 return hasDefaultConstructor() &&
1145 (data().HasTrivialSpecialMembers & SMF_DefaultConstructor);
1148 /// Determine whether this class has a non-trivial default constructor
1149 /// (C++11 [class.ctor]p5).
1150 bool hasNonTrivialDefaultConstructor() const {
1151 return (data().DeclaredNonTrivialSpecialMembers & SMF_DefaultConstructor) ||
1152 (needsImplicitDefaultConstructor() &&
1153 !(data().HasTrivialSpecialMembers & SMF_DefaultConstructor));
1156 /// Determine whether this class has at least one constexpr constructor
1157 /// other than the copy or move constructors.
1158 bool hasConstexprNonCopyMoveConstructor() const {
1159 return data().HasConstexprNonCopyMoveConstructor ||
1160 (needsImplicitDefaultConstructor() &&
1161 defaultedDefaultConstructorIsConstexpr());
1164 /// Determine whether a defaulted default constructor for this class
1165 /// would be constexpr.
1166 bool defaultedDefaultConstructorIsConstexpr() const {
1167 return data().DefaultedDefaultConstructorIsConstexpr &&
1168 (!isUnion() || hasInClassInitializer() || !hasVariantMembers() ||
1169 getASTContext().getLangOpts().CPlusPlus2a);
1172 /// Determine whether this class has a constexpr default constructor.
1173 bool hasConstexprDefaultConstructor() const {
1174 return data().HasConstexprDefaultConstructor ||
1175 (needsImplicitDefaultConstructor() &&
1176 defaultedDefaultConstructorIsConstexpr());
1179 /// Determine whether this class has a trivial copy constructor
1180 /// (C++ [class.copy]p6, C++11 [class.copy]p12)
1181 bool hasTrivialCopyConstructor() const {
1182 return data().HasTrivialSpecialMembers & SMF_CopyConstructor;
1185 bool hasTrivialCopyConstructorForCall() const {
1186 return data().HasTrivialSpecialMembersForCall & SMF_CopyConstructor;
1189 /// Determine whether this class has a non-trivial copy constructor
1190 /// (C++ [class.copy]p6, C++11 [class.copy]p12)
1191 bool hasNonTrivialCopyConstructor() const {
1192 return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor ||
1193 !hasTrivialCopyConstructor();
1196 bool hasNonTrivialCopyConstructorForCall() const {
1197 return (data().DeclaredNonTrivialSpecialMembersForCall &
1198 SMF_CopyConstructor) ||
1199 !hasTrivialCopyConstructorForCall();
1202 /// Determine whether this class has a trivial move constructor
1203 /// (C++11 [class.copy]p12)
1204 bool hasTrivialMoveConstructor() const {
1205 return hasMoveConstructor() &&
1206 (data().HasTrivialSpecialMembers & SMF_MoveConstructor);
1209 bool hasTrivialMoveConstructorForCall() const {
1210 return hasMoveConstructor() &&
1211 (data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor);
1214 /// Determine whether this class has a non-trivial move constructor
1215 /// (C++11 [class.copy]p12)
1216 bool hasNonTrivialMoveConstructor() const {
1217 return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveConstructor) ||
1218 (needsImplicitMoveConstructor() &&
1219 !(data().HasTrivialSpecialMembers & SMF_MoveConstructor));
1222 bool hasNonTrivialMoveConstructorForCall() const {
1223 return (data().DeclaredNonTrivialSpecialMembersForCall &
1224 SMF_MoveConstructor) ||
1225 (needsImplicitMoveConstructor() &&
1226 !(data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor));
1229 /// Determine whether this class has a trivial copy assignment operator
1230 /// (C++ [class.copy]p11, C++11 [class.copy]p25)
1231 bool hasTrivialCopyAssignment() const {
1232 return data().HasTrivialSpecialMembers & SMF_CopyAssignment;
1235 /// Determine whether this class has a non-trivial copy assignment
1236 /// operator (C++ [class.copy]p11, C++11 [class.copy]p25)
1237 bool hasNonTrivialCopyAssignment() const {
1238 return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment ||
1239 !hasTrivialCopyAssignment();
1242 /// Determine whether this class has a trivial move assignment operator
1243 /// (C++11 [class.copy]p25)
1244 bool hasTrivialMoveAssignment() const {
1245 return hasMoveAssignment() &&
1246 (data().HasTrivialSpecialMembers & SMF_MoveAssignment);
1249 /// Determine whether this class has a non-trivial move assignment
1250 /// operator (C++11 [class.copy]p25)
1251 bool hasNonTrivialMoveAssignment() const {
1252 return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveAssignment) ||
1253 (needsImplicitMoveAssignment() &&
1254 !(data().HasTrivialSpecialMembers & SMF_MoveAssignment));
1257 /// Determine whether a defaulted default constructor for this class
1258 /// would be constexpr.
1259 bool defaultedDestructorIsConstexpr() const {
1260 return data().DefaultedDestructorIsConstexpr &&
1261 getASTContext().getLangOpts().CPlusPlus2a;
1264 /// Determine whether this class has a constexpr destructor.
1265 bool hasConstexprDestructor() const;
1267 /// Determine whether this class has a trivial destructor
1268 /// (C++ [class.dtor]p3)
1269 bool hasTrivialDestructor() const {
1270 return data().HasTrivialSpecialMembers & SMF_Destructor;
1273 bool hasTrivialDestructorForCall() const {
1274 return data().HasTrivialSpecialMembersForCall & SMF_Destructor;
1277 /// Determine whether this class has a non-trivial destructor
1278 /// (C++ [class.dtor]p3)
1279 bool hasNonTrivialDestructor() const {
1280 return !(data().HasTrivialSpecialMembers & SMF_Destructor);
1283 bool hasNonTrivialDestructorForCall() const {
1284 return !(data().HasTrivialSpecialMembersForCall & SMF_Destructor);
1287 void setHasTrivialSpecialMemberForCall() {
1288 data().HasTrivialSpecialMembersForCall =
1289 (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor);
1292 /// Determine whether declaring a const variable with this type is ok
1293 /// per core issue 253.
1294 bool allowConstDefaultInit() const {
1295 return !data().HasUninitializedFields ||
1296 !(data().HasDefaultedDefaultConstructor ||
1297 needsImplicitDefaultConstructor());
1300 /// Determine whether this class has a destructor which has no
1301 /// semantic effect.
1303 /// Any such destructor will be trivial, public, defaulted and not deleted,
1304 /// and will call only irrelevant destructors.
1305 bool hasIrrelevantDestructor() const {
1306 return data().HasIrrelevantDestructor;
1309 /// Determine whether this class has a non-literal or/ volatile type
1310 /// non-static data member or base class.
1311 bool hasNonLiteralTypeFieldsOrBases() const {
1312 return data().HasNonLiteralTypeFieldsOrBases;
1315 /// Determine whether this class has a using-declaration that names
1316 /// a user-declared base class constructor.
1317 bool hasInheritedConstructor() const {
1318 return data().HasInheritedConstructor;
1321 /// Determine whether this class has a using-declaration that names
1322 /// a base class assignment operator.
1323 bool hasInheritedAssignment() const {
1324 return data().HasInheritedAssignment;
1327 /// Determine whether this class is considered trivially copyable per
1328 /// (C++11 [class]p6).
1329 bool isTriviallyCopyable() const;
1331 /// Determine whether this class is considered trivial.
1333 /// C++11 [class]p6:
1334 /// "A trivial class is a class that has a trivial default constructor and
1335 /// is trivially copyable."
1336 bool isTrivial() const {
1337 return isTriviallyCopyable() && hasTrivialDefaultConstructor();
1340 /// Determine whether this class is a literal type.
1342 /// C++11 [basic.types]p10:
1343 /// A class type that has all the following properties:
1344 /// - it has a trivial destructor
1345 /// - every constructor call and full-expression in the
1346 /// brace-or-equal-intializers for non-static data members (if any) is
1347 /// a constant expression.
1348 /// - it is an aggregate type or has at least one constexpr constructor
1349 /// or constructor template that is not a copy or move constructor, and
1350 /// - all of its non-static data members and base classes are of literal
1353 /// We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by
1354 /// treating types with trivial default constructors as literal types.
1356 /// Only in C++17 and beyond, are lambdas literal types.
1357 bool isLiteral() const {
1358 ASTContext &Ctx = getASTContext();
1359 return (Ctx.getLangOpts().CPlusPlus2a ? hasConstexprDestructor()
1360 : hasTrivialDestructor()) &&
1361 (!isLambda() || Ctx.getLangOpts().CPlusPlus17) &&
1362 !hasNonLiteralTypeFieldsOrBases() &&
1363 (isAggregate() || isLambda() ||
1364 hasConstexprNonCopyMoveConstructor() ||
1365 hasTrivialDefaultConstructor());
1368 /// If this record is an instantiation of a member class,
1369 /// retrieves the member class from which it was instantiated.
1371 /// This routine will return non-null for (non-templated) member
1372 /// classes of class templates. For example, given:
1375 /// template<typename T>
1381 /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
1382 /// whose parent is the class template specialization X<int>. For
1383 /// this declaration, getInstantiatedFromMemberClass() will return
1384 /// the CXXRecordDecl X<T>::A. When a complete definition of
1385 /// X<int>::A is required, it will be instantiated from the
1386 /// declaration returned by getInstantiatedFromMemberClass().
1387 CXXRecordDecl *getInstantiatedFromMemberClass() const;
1389 /// If this class is an instantiation of a member class of a
1390 /// class template specialization, retrieves the member specialization
1392 MemberSpecializationInfo *getMemberSpecializationInfo() const;
1394 /// Specify that this record is an instantiation of the
1395 /// member class \p RD.
1396 void setInstantiationOfMemberClass(CXXRecordDecl *RD,
1397 TemplateSpecializationKind TSK);
1399 /// Retrieves the class template that is described by this
1400 /// class declaration.
1402 /// Every class template is represented as a ClassTemplateDecl and a
1403 /// CXXRecordDecl. The former contains template properties (such as
1404 /// the template parameter lists) while the latter contains the
1405 /// actual description of the template's
1406 /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
1407 /// CXXRecordDecl that from a ClassTemplateDecl, while
1408 /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
1409 /// a CXXRecordDecl.
1410 ClassTemplateDecl *getDescribedClassTemplate() const;
1412 void setDescribedClassTemplate(ClassTemplateDecl *Template);
1414 /// Determine whether this particular class is a specialization or
1415 /// instantiation of a class template or member class of a class template,
1416 /// and how it was instantiated or specialized.
1417 TemplateSpecializationKind getTemplateSpecializationKind() const;
1419 /// Set the kind of specialization or template instantiation this is.
1420 void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
1422 /// Retrieve the record declaration from which this record could be
1423 /// instantiated. Returns null if this class is not a template instantiation.
1424 const CXXRecordDecl *getTemplateInstantiationPattern() const;
1426 CXXRecordDecl *getTemplateInstantiationPattern() {
1427 return const_cast<CXXRecordDecl *>(const_cast<const CXXRecordDecl *>(this)
1428 ->getTemplateInstantiationPattern());
1431 /// Returns the destructor decl for this class.
1432 CXXDestructorDecl *getDestructor() const;
1434 /// Returns true if the class destructor, or any implicitly invoked
1435 /// destructors are marked noreturn.
1436 bool isAnyDestructorNoReturn() const;
1438 /// If the class is a local class [class.local], returns
1439 /// the enclosing function declaration.
1440 const FunctionDecl *isLocalClass() const {
1441 if (const auto *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
1442 return RD->isLocalClass();
1444 return dyn_cast<FunctionDecl>(getDeclContext());
1447 FunctionDecl *isLocalClass() {
1448 return const_cast<FunctionDecl*>(
1449 const_cast<const CXXRecordDecl*>(this)->isLocalClass());
1452 /// Determine whether this dependent class is a current instantiation,
1453 /// when viewed from within the given context.
1454 bool isCurrentInstantiation(const DeclContext *CurContext) const;
1456 /// Determine whether this class is derived from the class \p Base.
1458 /// This routine only determines whether this class is derived from \p Base,
1459 /// but does not account for factors that may make a Derived -> Base class
1460 /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1461 /// base class subobjects.
1463 /// \param Base the base class we are searching for.
1465 /// \returns true if this class is derived from Base, false otherwise.
1466 bool isDerivedFrom(const CXXRecordDecl *Base) const;
1468 /// Determine whether this class is derived from the type \p Base.
1470 /// This routine only determines whether this class is derived from \p Base,
1471 /// but does not account for factors that may make a Derived -> Base class
1472 /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1473 /// base class subobjects.
1475 /// \param Base the base class we are searching for.
1477 /// \param Paths will contain the paths taken from the current class to the
1478 /// given \p Base class.
1480 /// \returns true if this class is derived from \p Base, false otherwise.
1482 /// \todo add a separate parameter to configure IsDerivedFrom, rather than
1483 /// tangling input and output in \p Paths
1484 bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const;
1486 /// Determine whether this class is virtually derived from
1487 /// the class \p Base.
1489 /// This routine only determines whether this class is virtually
1490 /// derived from \p Base, but does not account for factors that may
1491 /// make a Derived -> Base class ill-formed, such as
1492 /// private/protected inheritance or multiple, ambiguous base class
1495 /// \param Base the base class we are searching for.
1497 /// \returns true if this class is virtually derived from Base,
1498 /// false otherwise.
1499 bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const;
1501 /// Determine whether this class is provably not derived from
1502 /// the type \p Base.
1503 bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
1505 /// Function type used by forallBases() as a callback.
1507 /// \param BaseDefinition the definition of the base class
1509 /// \returns true if this base matched the search criteria
1510 using ForallBasesCallback =
1511 llvm::function_ref<bool(const CXXRecordDecl *BaseDefinition)>;
1513 /// Determines if the given callback holds for all the direct
1514 /// or indirect base classes of this type.
1516 /// The class itself does not count as a base class. This routine
1517 /// returns false if the class has non-computable base classes.
1519 /// \param BaseMatches Callback invoked for each (direct or indirect) base
1520 /// class of this type until a call returns false.
1521 bool forallBases(ForallBasesCallback BaseMatches) const;
1523 /// Function type used by lookupInBases() to determine whether a
1524 /// specific base class subobject matches the lookup criteria.
1526 /// \param Specifier the base-class specifier that describes the inheritance
1527 /// from the base class we are trying to match.
1529 /// \param Path the current path, from the most-derived class down to the
1530 /// base named by the \p Specifier.
1532 /// \returns true if this base matched the search criteria, false otherwise.
1533 using BaseMatchesCallback =
1534 llvm::function_ref<bool(const CXXBaseSpecifier *Specifier,
1535 CXXBasePath &Path)>;
1537 /// Look for entities within the base classes of this C++ class,
1538 /// transitively searching all base class subobjects.
1540 /// This routine uses the callback function \p BaseMatches to find base
1541 /// classes meeting some search criteria, walking all base class subobjects
1542 /// and populating the given \p Paths structure with the paths through the
1543 /// inheritance hierarchy that resulted in a match. On a successful search,
1544 /// the \p Paths structure can be queried to retrieve the matching paths and
1545 /// to determine if there were any ambiguities.
1547 /// \param BaseMatches callback function used to determine whether a given
1548 /// base matches the user-defined search criteria.
1550 /// \param Paths used to record the paths from this class to its base class
1551 /// subobjects that match the search criteria.
1553 /// \param LookupInDependent can be set to true to extend the search to
1554 /// dependent base classes.
1556 /// \returns true if there exists any path from this class to a base class
1557 /// subobject that matches the search criteria.
1558 bool lookupInBases(BaseMatchesCallback BaseMatches, CXXBasePaths &Paths,
1559 bool LookupInDependent = false) const;
1561 /// Base-class lookup callback that determines whether the given
1562 /// base class specifier refers to a specific class declaration.
1564 /// This callback can be used with \c lookupInBases() to determine whether
1565 /// a given derived class has is a base class subobject of a particular type.
1566 /// The base record pointer should refer to the canonical CXXRecordDecl of the
1567 /// base class that we are searching for.
1568 static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
1569 CXXBasePath &Path, const CXXRecordDecl *BaseRecord);
1571 /// Base-class lookup callback that determines whether the
1572 /// given base class specifier refers to a specific class
1573 /// declaration and describes virtual derivation.
1575 /// This callback can be used with \c lookupInBases() to determine
1576 /// whether a given derived class has is a virtual base class
1577 /// subobject of a particular type. The base record pointer should
1578 /// refer to the canonical CXXRecordDecl of the base class that we
1579 /// are searching for.
1580 static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
1582 const CXXRecordDecl *BaseRecord);
1584 /// Base-class lookup callback that determines whether there exists
1585 /// a tag with the given name.
1587 /// This callback can be used with \c lookupInBases() to find tag members
1588 /// of the given name within a C++ class hierarchy.
1589 static bool FindTagMember(const CXXBaseSpecifier *Specifier,
1590 CXXBasePath &Path, DeclarationName Name);
1592 /// Base-class lookup callback that determines whether there exists
1593 /// a member with the given name.
1595 /// This callback can be used with \c lookupInBases() to find members
1596 /// of the given name within a C++ class hierarchy.
1597 static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier,
1598 CXXBasePath &Path, DeclarationName Name);
1600 /// Base-class lookup callback that determines whether there exists
1601 /// a member with the given name.
1603 /// This callback can be used with \c lookupInBases() to find members
1604 /// of the given name within a C++ class hierarchy, including dependent
1607 FindOrdinaryMemberInDependentClasses(const CXXBaseSpecifier *Specifier,
1608 CXXBasePath &Path, DeclarationName Name);
1610 /// Base-class lookup callback that determines whether there exists
1611 /// an OpenMP declare reduction member with the given name.
1613 /// This callback can be used with \c lookupInBases() to find members
1614 /// of the given name within a C++ class hierarchy.
1615 static bool FindOMPReductionMember(const CXXBaseSpecifier *Specifier,
1616 CXXBasePath &Path, DeclarationName Name);
1618 /// Base-class lookup callback that determines whether there exists
1619 /// an OpenMP declare mapper member with the given name.
1621 /// This callback can be used with \c lookupInBases() to find members
1622 /// of the given name within a C++ class hierarchy.
1623 static bool FindOMPMapperMember(const CXXBaseSpecifier *Specifier,
1624 CXXBasePath &Path, DeclarationName Name);
1626 /// Base-class lookup callback that determines whether there exists
1627 /// a member with the given name that can be used in a nested-name-specifier.
1629 /// This callback can be used with \c lookupInBases() to find members of
1630 /// the given name within a C++ class hierarchy that can occur within
1631 /// nested-name-specifiers.
1632 static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier,
1634 DeclarationName Name);
1636 /// Retrieve the final overriders for each virtual member
1637 /// function in the class hierarchy where this class is the
1638 /// most-derived class in the class hierarchy.
1639 void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
1641 /// Get the indirect primary bases for this class.
1642 void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const;
1644 /// Performs an imprecise lookup of a dependent name in this class.
1646 /// This function does not follow strict semantic rules and should be used
1647 /// only when lookup rules can be relaxed, e.g. indexing.
1648 std::vector<const NamedDecl *>
1649 lookupDependentName(const DeclarationName &Name,
1650 llvm::function_ref<bool(const NamedDecl *ND)> Filter);
1652 /// Renders and displays an inheritance diagram
1653 /// for this C++ class and all of its base classes (transitively) using
1655 void viewInheritance(ASTContext& Context) const;
1657 /// Calculates the access of a decl that is reached
1659 static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
1660 AccessSpecifier DeclAccess) {
1661 assert(DeclAccess != AS_none);
1662 if (DeclAccess == AS_private) return AS_none;
1663 return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
1666 /// Indicates that the declaration of a defaulted or deleted special
1667 /// member function is now complete.
1668 void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD);
1670 void setTrivialForCallFlags(CXXMethodDecl *MD);
1672 /// Indicates that the definition of this class is now complete.
1673 void completeDefinition() override;
1675 /// Indicates that the definition of this class is now complete,
1676 /// and provides a final overrider map to help determine
1678 /// \param FinalOverriders The final overrider map for this class, which can
1679 /// be provided as an optimization for abstract-class checking. If NULL,
1680 /// final overriders will be computed if they are needed to complete the
1682 void completeDefinition(CXXFinalOverriderMap *FinalOverriders);
1684 /// Determine whether this class may end up being abstract, even though
1685 /// it is not yet known to be abstract.
1687 /// \returns true if this class is not known to be abstract but has any
1688 /// base classes that are abstract. In this case, \c completeDefinition()
1689 /// will need to compute final overriders to determine whether the class is
1690 /// actually abstract.
1691 bool mayBeAbstract() const;
1693 /// Determine whether it's impossible for a class to be derived from this
1694 /// class. This is best-effort, and may conservatively return false.
1695 bool isEffectivelyFinal() const;
1697 /// If this is the closure type of a lambda expression, retrieve the
1698 /// number to be used for name mangling in the Itanium C++ ABI.
1700 /// Zero indicates that this closure type has internal linkage, so the
1701 /// mangling number does not matter, while a non-zero value indicates which
1702 /// lambda expression this is in this particular context.
1703 unsigned getLambdaManglingNumber() const {
1704 assert(isLambda() && "Not a lambda closure type!");
1705 return getLambdaData().ManglingNumber;
1708 /// The lambda is known to has internal linkage no matter whether it has name
1709 /// mangling number.
1710 bool hasKnownLambdaInternalLinkage() const {
1711 assert(isLambda() && "Not a lambda closure type!");
1712 return getLambdaData().HasKnownInternalLinkage;
1715 /// Retrieve the declaration that provides additional context for a
1716 /// lambda, when the normal declaration context is not specific enough.
1718 /// Certain contexts (default arguments of in-class function parameters and
1719 /// the initializers of data members) have separate name mangling rules for
1720 /// lambdas within the Itanium C++ ABI. For these cases, this routine provides
1721 /// the declaration in which the lambda occurs, e.g., the function parameter
1722 /// or the non-static data member. Otherwise, it returns NULL to imply that
1723 /// the declaration context suffices.
1724 Decl *getLambdaContextDecl() const;
1726 /// Set the mangling number and context declaration for a lambda
1728 void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl,
1729 bool HasKnownInternalLinkage = false) {
1730 assert(isLambda() && "Not a lambda closure type!");
1731 getLambdaData().ManglingNumber = ManglingNumber;
1732 getLambdaData().ContextDecl = ContextDecl;
1733 getLambdaData().HasKnownInternalLinkage = HasKnownInternalLinkage;
1736 /// Returns the inheritance model used for this record.
1737 MSInheritanceModel getMSInheritanceModel() const;
1739 /// Calculate what the inheritance model would be for this class.
1740 MSInheritanceModel calculateInheritanceModel() const;
1742 /// In the Microsoft C++ ABI, use zero for the field offset of a null data
1743 /// member pointer if we can guarantee that zero is not a valid field offset,
1744 /// or if the member pointer has multiple fields. Polymorphic classes have a
1745 /// vfptr at offset zero, so we can use zero for null. If there are multiple
1746 /// fields, we can use zero even if it is a valid field offset because
1747 /// null-ness testing will check the other fields.
1748 bool nullFieldOffsetIsZero() const;
1750 /// Controls when vtordisps will be emitted if this record is used as a
1752 MSVtorDispMode getMSVtorDispMode() const;
1754 /// Determine whether this lambda expression was known to be dependent
1755 /// at the time it was created, even if its context does not appear to be
1758 /// This flag is a workaround for an issue with parsing, where default
1759 /// arguments are parsed before their enclosing function declarations have
1760 /// been created. This means that any lambda expressions within those
1761 /// default arguments will have as their DeclContext the context enclosing
1762 /// the function declaration, which may be non-dependent even when the
1763 /// function declaration itself is dependent. This flag indicates when we
1764 /// know that the lambda is dependent despite that.
1765 bool isDependentLambda() const {
1766 return isLambda() && getLambdaData().Dependent;
1769 TypeSourceInfo *getLambdaTypeInfo() const {
1770 return getLambdaData().MethodTyInfo;
1773 // Determine whether this type is an Interface Like type for
1774 // __interface inheritance purposes.
1775 bool isInterfaceLike() const;
1777 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1778 static bool classofKind(Kind K) {
1779 return K >= firstCXXRecord && K <= lastCXXRecord;
1783 /// Store information needed for an explicit specifier.
1784 /// Used by CXXDeductionGuideDecl, CXXConstructorDecl and CXXConversionDecl.
1785 class ExplicitSpecifier {
1786 llvm::PointerIntPair<Expr *, 2, ExplicitSpecKind> ExplicitSpec{
1787 nullptr, ExplicitSpecKind::ResolvedFalse};
1790 ExplicitSpecifier() = default;
1791 ExplicitSpecifier(Expr *Expression, ExplicitSpecKind Kind)
1792 : ExplicitSpec(Expression, Kind) {}
1793 ExplicitSpecKind getKind() const { return ExplicitSpec.getInt(); }
1794 const Expr *getExpr() const { return ExplicitSpec.getPointer(); }
1795 Expr *getExpr() { return ExplicitSpec.getPointer(); }
1797 /// Determine if the declaration had an explicit specifier of any kind.
1798 bool isSpecified() const {
1799 return ExplicitSpec.getInt() != ExplicitSpecKind::ResolvedFalse ||
1800 ExplicitSpec.getPointer();
1803 /// Check for equivalence of explicit specifiers.
1804 /// \return true if the explicit specifier are equivalent, false otherwise.
1805 bool isEquivalent(const ExplicitSpecifier Other) const;
1806 /// Determine whether this specifier is known to correspond to an explicit
1807 /// declaration. Returns false if the specifier is absent or has an
1808 /// expression that is value-dependent or evaluates to false.
1809 bool isExplicit() const {
1810 return ExplicitSpec.getInt() == ExplicitSpecKind::ResolvedTrue;
1812 /// Determine if the explicit specifier is invalid.
1813 /// This state occurs after a substitution failures.
1814 bool isInvalid() const {
1815 return ExplicitSpec.getInt() == ExplicitSpecKind::Unresolved &&
1816 !ExplicitSpec.getPointer();
1818 void setKind(ExplicitSpecKind Kind) { ExplicitSpec.setInt(Kind); }
1819 void setExpr(Expr *E) { ExplicitSpec.setPointer(E); }
1820 // Retrieve the explicit specifier in the given declaration, if any.
1821 static ExplicitSpecifier getFromDecl(FunctionDecl *Function);
1822 static const ExplicitSpecifier getFromDecl(const FunctionDecl *Function) {
1823 return getFromDecl(const_cast<FunctionDecl *>(Function));
1825 static ExplicitSpecifier Invalid() {
1826 return ExplicitSpecifier(nullptr, ExplicitSpecKind::Unresolved);
1830 /// Represents a C++ deduction guide declaration.
1833 /// template<typename T> struct A { A(); A(T); };
1837 /// In this example, there will be an explicit deduction guide from the
1838 /// second line, and implicit deduction guide templates synthesized from
1839 /// the constructors of \c A.
1840 class CXXDeductionGuideDecl : public FunctionDecl {
1841 void anchor() override;
1844 CXXDeductionGuideDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1845 ExplicitSpecifier ES,
1846 const DeclarationNameInfo &NameInfo, QualType T,
1847 TypeSourceInfo *TInfo, SourceLocation EndLocation)
1848 : FunctionDecl(CXXDeductionGuide, C, DC, StartLoc, NameInfo, T, TInfo,
1849 SC_None, false, CSK_unspecified),
1851 if (EndLocation.isValid())
1852 setRangeEnd(EndLocation);
1853 setIsCopyDeductionCandidate(false);
1856 ExplicitSpecifier ExplicitSpec;
1857 void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; }
1860 friend class ASTDeclReader;
1861 friend class ASTDeclWriter;
1863 static CXXDeductionGuideDecl *
1864 Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1865 ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T,
1866 TypeSourceInfo *TInfo, SourceLocation EndLocation);
1868 static CXXDeductionGuideDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1870 ExplicitSpecifier getExplicitSpecifier() { return ExplicitSpec; }
1871 const ExplicitSpecifier getExplicitSpecifier() const { return ExplicitSpec; }
1873 /// Return true if the declartion is already resolved to be explicit.
1874 bool isExplicit() const { return ExplicitSpec.isExplicit(); }
1876 /// Get the template for which this guide performs deduction.
1877 TemplateDecl *getDeducedTemplate() const {
1878 return getDeclName().getCXXDeductionGuideTemplate();
1881 void setIsCopyDeductionCandidate(bool isCDC = true) {
1882 FunctionDeclBits.IsCopyDeductionCandidate = isCDC;
1885 bool isCopyDeductionCandidate() const {
1886 return FunctionDeclBits.IsCopyDeductionCandidate;
1889 // Implement isa/cast/dyncast/etc.
1890 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1891 static bool classofKind(Kind K) { return K == CXXDeductionGuide; }
1894 /// \brief Represents the body of a requires-expression.
1896 /// This decl exists merely to serve as the DeclContext for the local
1897 /// parameters of the requires expression as well as other declarations inside
1901 /// template<typename T> requires requires (T t) { {t++} -> regular; }
1904 /// In this example, a RequiresExpr object will be generated for the expression,
1905 /// and a RequiresExprBodyDecl will be created to hold the parameter t and the
1906 /// template argument list imposed by the compound requirement.
1907 class RequiresExprBodyDecl : public Decl, public DeclContext {
1908 RequiresExprBodyDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc)
1909 : Decl(RequiresExprBody, DC, StartLoc), DeclContext(RequiresExprBody) {}
1912 friend class ASTDeclReader;
1913 friend class ASTDeclWriter;
1915 static RequiresExprBodyDecl *Create(ASTContext &C, DeclContext *DC,
1916 SourceLocation StartLoc);
1918 static RequiresExprBodyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1920 // Implement isa/cast/dyncast/etc.
1921 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1922 static bool classofKind(Kind K) { return K == RequiresExprBody; }
1925 /// Represents a static or instance method of a struct/union/class.
1927 /// In the terminology of the C++ Standard, these are the (static and
1928 /// non-static) member functions, whether virtual or not.
1929 class CXXMethodDecl : public FunctionDecl {
1930 void anchor() override;
1933 CXXMethodDecl(Kind DK, ASTContext &C, CXXRecordDecl *RD,
1934 SourceLocation StartLoc, const DeclarationNameInfo &NameInfo,
1935 QualType T, TypeSourceInfo *TInfo, StorageClass SC,
1936 bool isInline, ConstexprSpecKind ConstexprKind,
1937 SourceLocation EndLocation,
1938 Expr *TrailingRequiresClause = nullptr)
1939 : FunctionDecl(DK, C, RD, StartLoc, NameInfo, T, TInfo, SC, isInline,
1940 ConstexprKind, TrailingRequiresClause) {
1941 if (EndLocation.isValid())
1942 setRangeEnd(EndLocation);
1946 static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
1947 SourceLocation StartLoc,
1948 const DeclarationNameInfo &NameInfo, QualType T,
1949 TypeSourceInfo *TInfo, StorageClass SC,
1950 bool isInline, ConstexprSpecKind ConstexprKind,
1951 SourceLocation EndLocation,
1952 Expr *TrailingRequiresClause = nullptr);
1954 static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID);
1956 bool isStatic() const;
1957 bool isInstance() const { return !isStatic(); }
1959 /// Returns true if the given operator is implicitly static in a record
1961 static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK) {
1963 // Any allocation function for a class T is a static member
1964 // (even if not explicitly declared static).
1965 // [class.free]p6 Any deallocation function for a class X is a static member
1966 // (even if not explicitly declared static).
1967 return OOK == OO_New || OOK == OO_Array_New || OOK == OO_Delete ||
1968 OOK == OO_Array_Delete;
1971 bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); }
1972 bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); }
1974 bool isVirtual() const {
1975 CXXMethodDecl *CD = const_cast<CXXMethodDecl*>(this)->getCanonicalDecl();
1977 // Member function is virtual if it is marked explicitly so, or if it is
1978 // declared in __interface -- then it is automatically pure virtual.
1979 if (CD->isVirtualAsWritten() || CD->isPure())
1982 return CD->size_overridden_methods() != 0;
1985 /// If it's possible to devirtualize a call to this method, return the called
1986 /// function. Otherwise, return null.
1988 /// \param Base The object on which this virtual function is called.
1989 /// \param IsAppleKext True if we are compiling for Apple kext.
1990 CXXMethodDecl *getDevirtualizedMethod(const Expr *Base, bool IsAppleKext);
1992 const CXXMethodDecl *getDevirtualizedMethod(const Expr *Base,
1993 bool IsAppleKext) const {
1994 return const_cast<CXXMethodDecl *>(this)->getDevirtualizedMethod(
1998 /// Determine whether this is a usual deallocation function (C++
1999 /// [basic.stc.dynamic.deallocation]p2), which is an overloaded delete or
2000 /// delete[] operator with a particular signature. Populates \p PreventedBy
2001 /// with the declarations of the functions of the same kind if they were the
2002 /// reason for this function returning false. This is used by
2003 /// Sema::isUsualDeallocationFunction to reconsider the answer based on the
2005 bool isUsualDeallocationFunction(
2006 SmallVectorImpl<const FunctionDecl *> &PreventedBy) const;
2008 /// Determine whether this is a copy-assignment operator, regardless
2009 /// of whether it was declared implicitly or explicitly.
2010 bool isCopyAssignmentOperator() const;
2012 /// Determine whether this is a move assignment operator.
2013 bool isMoveAssignmentOperator() const;
2015 CXXMethodDecl *getCanonicalDecl() override {
2016 return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
2018 const CXXMethodDecl *getCanonicalDecl() const {
2019 return const_cast<CXXMethodDecl*>(this)->getCanonicalDecl();
2022 CXXMethodDecl *getMostRecentDecl() {
2023 return cast<CXXMethodDecl>(
2024 static_cast<FunctionDecl *>(this)->getMostRecentDecl());
2026 const CXXMethodDecl *getMostRecentDecl() const {
2027 return const_cast<CXXMethodDecl*>(this)->getMostRecentDecl();
2030 void addOverriddenMethod(const CXXMethodDecl *MD);
2032 using method_iterator = const CXXMethodDecl *const *;
2034 method_iterator begin_overridden_methods() const;
2035 method_iterator end_overridden_methods() const;
2036 unsigned size_overridden_methods() const;
2038 using overridden_method_range= ASTContext::overridden_method_range;
2040 overridden_method_range overridden_methods() const;
2042 /// Return the parent of this method declaration, which
2043 /// is the class in which this method is defined.
2044 const CXXRecordDecl *getParent() const {
2045 return cast<CXXRecordDecl>(FunctionDecl::getParent());
2048 /// Return the parent of this method declaration, which
2049 /// is the class in which this method is defined.
2050 CXXRecordDecl *getParent() {
2051 return const_cast<CXXRecordDecl *>(
2052 cast<CXXRecordDecl>(FunctionDecl::getParent()));
2055 /// Return the type of the \c this pointer.
2057 /// Should only be called for instance (i.e., non-static) methods. Note
2058 /// that for the call operator of a lambda closure type, this returns the
2059 /// desugared 'this' type (a pointer to the closure type), not the captured
2061 QualType getThisType() const;
2063 /// Return the type of the object pointed by \c this.
2065 /// See getThisType() for usage restriction.
2066 QualType getThisObjectType() const;
2068 static QualType getThisType(const FunctionProtoType *FPT,
2069 const CXXRecordDecl *Decl);
2071 static QualType getThisObjectType(const FunctionProtoType *FPT,
2072 const CXXRecordDecl *Decl);
2074 Qualifiers getMethodQualifiers() const {
2075 return getType()->castAs<FunctionProtoType>()->getMethodQuals();
2078 /// Retrieve the ref-qualifier associated with this method.
2080 /// In the following example, \c f() has an lvalue ref-qualifier, \c g()
2081 /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier.
2089 RefQualifierKind getRefQualifier() const {
2090 return getType()->castAs<FunctionProtoType>()->getRefQualifier();
2093 bool hasInlineBody() const;
2095 /// Determine whether this is a lambda closure type's static member
2096 /// function that is used for the result of the lambda's conversion to
2097 /// function pointer (for a lambda with no captures).
2099 /// The function itself, if used, will have a placeholder body that will be
2100 /// supplied by IR generation to either forward to the function call operator
2101 /// or clone the function call operator.
2102 bool isLambdaStaticInvoker() const;
2104 /// Find the method in \p RD that corresponds to this one.
2106 /// Find if \p RD or one of the classes it inherits from override this method.
2107 /// If so, return it. \p RD is assumed to be a subclass of the class defining
2108 /// this method (or be the class itself), unless \p MayBeBase is set to true.
2110 getCorrespondingMethodInClass(const CXXRecordDecl *RD,
2111 bool MayBeBase = false);
2113 const CXXMethodDecl *
2114 getCorrespondingMethodInClass(const CXXRecordDecl *RD,
2115 bool MayBeBase = false) const {
2116 return const_cast<CXXMethodDecl *>(this)
2117 ->getCorrespondingMethodInClass(RD, MayBeBase);
2120 /// Find if \p RD declares a function that overrides this function, and if so,
2121 /// return it. Does not search base classes.
2122 CXXMethodDecl *getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD,
2123 bool MayBeBase = false);
2124 const CXXMethodDecl *
2125 getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD,
2126 bool MayBeBase = false) const {
2127 return const_cast<CXXMethodDecl *>(this)
2128 ->getCorrespondingMethodDeclaredInClass(RD, MayBeBase);
2131 // Implement isa/cast/dyncast/etc.
2132 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2133 static bool classofKind(Kind K) {
2134 return K >= firstCXXMethod && K <= lastCXXMethod;
2138 /// Represents a C++ base or member initializer.
2140 /// This is part of a constructor initializer that
2141 /// initializes one non-static member variable or one base class. For
2142 /// example, in the following, both 'A(a)' and 'f(3.14159)' are member
2147 /// class B : public A {
2150 /// B(A& a) : A(a), f(3.14159) { }
2153 class CXXCtorInitializer final {
2154 /// Either the base class name/delegating constructor type (stored as
2155 /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field
2156 /// (IndirectFieldDecl*) being initialized.
2157 llvm::PointerUnion<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *>
2160 /// The source location for the field name or, for a base initializer
2161 /// pack expansion, the location of the ellipsis.
2163 /// In the case of a delegating
2164 /// constructor, it will still include the type's source location as the
2165 /// Initializee points to the CXXConstructorDecl (to allow loop detection).
2166 SourceLocation MemberOrEllipsisLocation;
2168 /// The argument used to initialize the base or member, which may
2169 /// end up constructing an object (when multiple arguments are involved).
2172 /// Location of the left paren of the ctor-initializer.
2173 SourceLocation LParenLoc;
2175 /// Location of the right paren of the ctor-initializer.
2176 SourceLocation RParenLoc;
2178 /// If the initializee is a type, whether that type makes this
2179 /// a delegating initialization.
2180 unsigned IsDelegating : 1;
2182 /// If the initializer is a base initializer, this keeps track
2183 /// of whether the base is virtual or not.
2184 unsigned IsVirtual : 1;
2186 /// Whether or not the initializer is explicitly written
2188 unsigned IsWritten : 1;
2190 /// If IsWritten is true, then this number keeps track of the textual order
2191 /// of this initializer in the original sources, counting from 0.
2192 unsigned SourceOrder : 13;
2195 /// Creates a new base-class initializer.
2197 CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual,
2198 SourceLocation L, Expr *Init, SourceLocation R,
2199 SourceLocation EllipsisLoc);
2201 /// Creates a new member initializer.
2203 CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
2204 SourceLocation MemberLoc, SourceLocation L, Expr *Init,
2207 /// Creates a new anonymous field initializer.
2209 CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member,
2210 SourceLocation MemberLoc, SourceLocation L, Expr *Init,
2213 /// Creates a new delegating initializer.
2215 CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo,
2216 SourceLocation L, Expr *Init, SourceLocation R);
2218 /// \return Unique reproducible object identifier.
2219 int64_t getID(const ASTContext &Context) const;
2221 /// Determine whether this initializer is initializing a base class.
2222 bool isBaseInitializer() const {
2223 return Initializee.is<TypeSourceInfo*>() && !IsDelegating;
2226 /// Determine whether this initializer is initializing a non-static
2228 bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); }
2230 bool isAnyMemberInitializer() const {
2231 return isMemberInitializer() || isIndirectMemberInitializer();
2234 bool isIndirectMemberInitializer() const {
2235 return Initializee.is<IndirectFieldDecl*>();
2238 /// Determine whether this initializer is an implicit initializer
2239 /// generated for a field with an initializer defined on the member
2242 /// In-class member initializers (also known as "non-static data member
2243 /// initializations", NSDMIs) were introduced in C++11.
2244 bool isInClassMemberInitializer() const {
2245 return Init->getStmtClass() == Stmt::CXXDefaultInitExprClass;
2248 /// Determine whether this initializer is creating a delegating
2250 bool isDelegatingInitializer() const {
2251 return Initializee.is<TypeSourceInfo*>() && IsDelegating;
2254 /// Determine whether this initializer is a pack expansion.
2255 bool isPackExpansion() const {
2256 return isBaseInitializer() && MemberOrEllipsisLocation.isValid();
2259 // For a pack expansion, returns the location of the ellipsis.
2260 SourceLocation getEllipsisLoc() const {
2261 assert(isPackExpansion() && "Initializer is not a pack expansion");
2262 return MemberOrEllipsisLocation;
2265 /// If this is a base class initializer, returns the type of the
2266 /// base class with location information. Otherwise, returns an NULL
2268 TypeLoc getBaseClassLoc() const;
2270 /// If this is a base class initializer, returns the type of the base class.
2271 /// Otherwise, returns null.
2272 const Type *getBaseClass() const;
2274 /// Returns whether the base is virtual or not.
2275 bool isBaseVirtual() const {
2276 assert(isBaseInitializer() && "Must call this on base initializer!");
2281 /// Returns the declarator information for a base class or delegating
2283 TypeSourceInfo *getTypeSourceInfo() const {
2284 return Initializee.dyn_cast<TypeSourceInfo *>();
2287 /// If this is a member initializer, returns the declaration of the
2288 /// non-static data member being initialized. Otherwise, returns null.
2289 FieldDecl *getMember() const {
2290 if (isMemberInitializer())
2291 return Initializee.get<FieldDecl*>();
2295 FieldDecl *getAnyMember() const {
2296 if (isMemberInitializer())
2297 return Initializee.get<FieldDecl*>();
2298 if (isIndirectMemberInitializer())
2299 return Initializee.get<IndirectFieldDecl*>()->getAnonField();
2303 IndirectFieldDecl *getIndirectMember() const {
2304 if (isIndirectMemberInitializer())
2305 return Initializee.get<IndirectFieldDecl*>();
2309 SourceLocation getMemberLocation() const {
2310 return MemberOrEllipsisLocation;
2313 /// Determine the source location of the initializer.
2314 SourceLocation getSourceLocation() const;
2316 /// Determine the source range covering the entire initializer.
2317 SourceRange getSourceRange() const LLVM_READONLY;
2319 /// Determine whether this initializer is explicitly written
2320 /// in the source code.
2321 bool isWritten() const { return IsWritten; }
2323 /// Return the source position of the initializer, counting from 0.
2324 /// If the initializer was implicit, -1 is returned.
2325 int getSourceOrder() const {
2326 return IsWritten ? static_cast<int>(SourceOrder) : -1;
2329 /// Set the source order of this initializer.
2331 /// This can only be called once for each initializer; it cannot be called
2332 /// on an initializer having a positive number of (implicit) array indices.
2334 /// This assumes that the initializer was written in the source code, and
2335 /// ensures that isWritten() returns true.
2336 void setSourceOrder(int Pos) {
2337 assert(!IsWritten &&
2338 "setSourceOrder() used on implicit initializer");
2339 assert(SourceOrder == 0 &&
2340 "calling twice setSourceOrder() on the same initializer");
2342 "setSourceOrder() used to make an initializer implicit");
2344 SourceOrder = static_cast<unsigned>(Pos);
2347 SourceLocation getLParenLoc() const { return LParenLoc; }
2348 SourceLocation getRParenLoc() const { return RParenLoc; }
2350 /// Get the initializer.
2351 Expr *getInit() const { return static_cast<Expr *>(Init); }
2354 /// Description of a constructor that was inherited from a base class.
2355 class InheritedConstructor {
2356 ConstructorUsingShadowDecl *Shadow = nullptr;
2357 CXXConstructorDecl *BaseCtor = nullptr;
2360 InheritedConstructor() = default;
2361 InheritedConstructor(ConstructorUsingShadowDecl *Shadow,
2362 CXXConstructorDecl *BaseCtor)
2363 : Shadow(Shadow), BaseCtor(BaseCtor) {}
2365 explicit operator bool() const { return Shadow; }
2367 ConstructorUsingShadowDecl *getShadowDecl() const { return Shadow; }
2368 CXXConstructorDecl *getConstructor() const { return BaseCtor; }
2371 /// Represents a C++ constructor within a class.
2378 /// explicit X(int); // represented by a CXXConstructorDecl.
2381 class CXXConstructorDecl final
2382 : public CXXMethodDecl,
2383 private llvm::TrailingObjects<CXXConstructorDecl, InheritedConstructor,
2384 ExplicitSpecifier> {
2385 // This class stores some data in DeclContext::CXXConstructorDeclBits
2386 // to save some space. Use the provided accessors to access it.
2388 /// \name Support for base and member initializers.
2390 /// The arguments used to initialize the base or member.
2391 LazyCXXCtorInitializersPtr CtorInitializers;
2393 CXXConstructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2394 const DeclarationNameInfo &NameInfo, QualType T,
2395 TypeSourceInfo *TInfo, ExplicitSpecifier ES, bool isInline,
2396 bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind,
2397 InheritedConstructor Inherited,
2398 Expr *TrailingRequiresClause);
2400 void anchor() override;
2402 size_t numTrailingObjects(OverloadToken<InheritedConstructor>) const {
2403 return CXXConstructorDeclBits.IsInheritingConstructor;
2405 size_t numTrailingObjects(OverloadToken<ExplicitSpecifier>) const {
2406 return CXXConstructorDeclBits.HasTrailingExplicitSpecifier;
2409 ExplicitSpecifier getExplicitSpecifierInternal() const {
2410 if (CXXConstructorDeclBits.HasTrailingExplicitSpecifier)
2411 return *getTrailingObjects<ExplicitSpecifier>();
2412 return ExplicitSpecifier(
2413 nullptr, CXXConstructorDeclBits.IsSimpleExplicit
2414 ? ExplicitSpecKind::ResolvedTrue
2415 : ExplicitSpecKind::ResolvedFalse);
2418 enum TraillingAllocKind {
2419 TAKInheritsConstructor = 1,
2420 TAKHasTailExplicit = 1 << 1,
2423 uint64_t getTraillingAllocKind() const {
2424 return numTrailingObjects(OverloadToken<InheritedConstructor>()) |
2425 (numTrailingObjects(OverloadToken<ExplicitSpecifier>()) << 1);
2429 friend class ASTDeclReader;
2430 friend class ASTDeclWriter;
2431 friend TrailingObjects;
2433 static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID,
2434 uint64_t AllocKind);
2435 static CXXConstructorDecl *
2436 Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2437 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2438 ExplicitSpecifier ES, bool isInline, bool isImplicitlyDeclared,
2439 ConstexprSpecKind ConstexprKind,
2440 InheritedConstructor Inherited = InheritedConstructor(),
2441 Expr *TrailingRequiresClause = nullptr);
2443 void setExplicitSpecifier(ExplicitSpecifier ES) {
2444 assert((!ES.getExpr() ||
2445 CXXConstructorDeclBits.HasTrailingExplicitSpecifier) &&
2446 "cannot set this explicit specifier. no trail-allocated space for "
2449 *getCanonicalDecl()->getTrailingObjects<ExplicitSpecifier>() = ES;
2451 CXXConstructorDeclBits.IsSimpleExplicit = ES.isExplicit();
2454 ExplicitSpecifier getExplicitSpecifier() {
2455 return getCanonicalDecl()->getExplicitSpecifierInternal();
2457 const ExplicitSpecifier getExplicitSpecifier() const {
2458 return getCanonicalDecl()->getExplicitSpecifierInternal();
2461 /// Return true if the declartion is already resolved to be explicit.
2462 bool isExplicit() const { return getExplicitSpecifier().isExplicit(); }
2464 /// Iterates through the member/base initializer list.
2465 using init_iterator = CXXCtorInitializer **;
2467 /// Iterates through the member/base initializer list.
2468 using init_const_iterator = CXXCtorInitializer *const *;
2470 using init_range = llvm::iterator_range<init_iterator>;
2471 using init_const_range = llvm::iterator_range<init_const_iterator>;
2473 init_range inits() { return init_range(init_begin(), init_end()); }
2474 init_const_range inits() const {
2475 return init_const_range(init_begin(), init_end());
2478 /// Retrieve an iterator to the first initializer.
2479 init_iterator init_begin() {
2480 const auto *ConstThis = this;
2481 return const_cast<init_iterator>(ConstThis->init_begin());
2484 /// Retrieve an iterator to the first initializer.
2485 init_const_iterator init_begin() const;
2487 /// Retrieve an iterator past the last initializer.
2488 init_iterator init_end() {
2489 return init_begin() + getNumCtorInitializers();
2492 /// Retrieve an iterator past the last initializer.
2493 init_const_iterator init_end() const {
2494 return init_begin() + getNumCtorInitializers();
2497 using init_reverse_iterator = std::reverse_iterator<init_iterator>;
2498 using init_const_reverse_iterator =
2499 std::reverse_iterator<init_const_iterator>;
2501 init_reverse_iterator init_rbegin() {
2502 return init_reverse_iterator(init_end());
2504 init_const_reverse_iterator init_rbegin() const {
2505 return init_const_reverse_iterator(init_end());
2508 init_reverse_iterator init_rend() {
2509 return init_reverse_iterator(init_begin());
2511 init_const_reverse_iterator init_rend() const {
2512 return init_const_reverse_iterator(init_begin());
2515 /// Determine the number of arguments used to initialize the member
2517 unsigned getNumCtorInitializers() const {
2518 return CXXConstructorDeclBits.NumCtorInitializers;
2521 void setNumCtorInitializers(unsigned numCtorInitializers) {
2522 CXXConstructorDeclBits.NumCtorInitializers = numCtorInitializers;
2523 // This assert added because NumCtorInitializers is stored
2524 // in CXXConstructorDeclBits as a bitfield and its width has
2525 // been shrunk from 32 bits to fit into CXXConstructorDeclBitfields.
2526 assert(CXXConstructorDeclBits.NumCtorInitializers ==
2527 numCtorInitializers && "NumCtorInitializers overflow!");
2530 void setCtorInitializers(CXXCtorInitializer **Initializers) {
2531 CtorInitializers = Initializers;
2534 /// Determine whether this constructor is a delegating constructor.
2535 bool isDelegatingConstructor() const {
2536 return (getNumCtorInitializers() == 1) &&
2537 init_begin()[0]->isDelegatingInitializer();
2540 /// When this constructor delegates to another, retrieve the target.
2541 CXXConstructorDecl *getTargetConstructor() const;
2543 /// Whether this constructor is a default
2544 /// constructor (C++ [class.ctor]p5), which can be used to
2545 /// default-initialize a class of this type.
2546 bool isDefaultConstructor() const;
2548 /// Whether this constructor is a copy constructor (C++ [class.copy]p2,
2549 /// which can be used to copy the class.
2551 /// \p TypeQuals will be set to the qualifiers on the
2552 /// argument type. For example, \p TypeQuals would be set to \c
2553 /// Qualifiers::Const for the following copy constructor:
2561 bool isCopyConstructor(unsigned &TypeQuals) const;
2563 /// Whether this constructor is a copy
2564 /// constructor (C++ [class.copy]p2, which can be used to copy the
2566 bool isCopyConstructor() const {
2567 unsigned TypeQuals = 0;
2568 return isCopyConstructor(TypeQuals);
2571 /// Determine whether this constructor is a move constructor
2572 /// (C++11 [class.copy]p3), which can be used to move values of the class.
2574 /// \param TypeQuals If this constructor is a move constructor, will be set
2575 /// to the type qualifiers on the referent of the first parameter's type.
2576 bool isMoveConstructor(unsigned &TypeQuals) const;
2578 /// Determine whether this constructor is a move constructor
2579 /// (C++11 [class.copy]p3), which can be used to move values of the class.
2580 bool isMoveConstructor() const {
2581 unsigned TypeQuals = 0;
2582 return isMoveConstructor(TypeQuals);
2585 /// Determine whether this is a copy or move constructor.
2587 /// \param TypeQuals Will be set to the type qualifiers on the reference
2588 /// parameter, if in fact this is a copy or move constructor.
2589 bool isCopyOrMoveConstructor(unsigned &TypeQuals) const;
2591 /// Determine whether this a copy or move constructor.
2592 bool isCopyOrMoveConstructor() const {
2594 return isCopyOrMoveConstructor(Quals);
2597 /// Whether this constructor is a
2598 /// converting constructor (C++ [class.conv.ctor]), which can be
2599 /// used for user-defined conversions.
2600 bool isConvertingConstructor(bool AllowExplicit) const;
2602 /// Determine whether this is a member template specialization that
2603 /// would copy the object to itself. Such constructors are never used to copy
2605 bool isSpecializationCopyingObject() const;
2607 /// Determine whether this is an implicit constructor synthesized to
2608 /// model a call to a constructor inherited from a base class.
2609 bool isInheritingConstructor() const {
2610 return CXXConstructorDeclBits.IsInheritingConstructor;
2613 /// State that this is an implicit constructor synthesized to
2614 /// model a call to a constructor inherited from a base class.
2615 void setInheritingConstructor(bool isIC = true) {
2616 CXXConstructorDeclBits.IsInheritingConstructor = isIC;
2619 /// Get the constructor that this inheriting constructor is based on.
2620 InheritedConstructor getInheritedConstructor() const {
2621 return isInheritingConstructor() ?
2622 *getTrailingObjects<InheritedConstructor>() : InheritedConstructor();
2625 CXXConstructorDecl *getCanonicalDecl() override {
2626 return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
2628 const CXXConstructorDecl *getCanonicalDecl() const {
2629 return const_cast<CXXConstructorDecl*>(this)->getCanonicalDecl();
2632 // Implement isa/cast/dyncast/etc.
2633 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2634 static bool classofKind(Kind K) { return K == CXXConstructor; }
2637 /// Represents a C++ destructor within a class.
2644 /// ~X(); // represented by a CXXDestructorDecl.
2647 class CXXDestructorDecl : public CXXMethodDecl {
2648 friend class ASTDeclReader;
2649 friend class ASTDeclWriter;
2651 // FIXME: Don't allocate storage for these except in the first declaration
2652 // of a virtual destructor.
2653 FunctionDecl *OperatorDelete = nullptr;
2654 Expr *OperatorDeleteThisArg = nullptr;
2656 CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2657 const DeclarationNameInfo &NameInfo, QualType T,
2658 TypeSourceInfo *TInfo, bool isInline,
2659 bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind,
2660 Expr *TrailingRequiresClause = nullptr)
2661 : CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo,
2662 SC_None, isInline, ConstexprKind, SourceLocation(),
2663 TrailingRequiresClause) {
2664 setImplicit(isImplicitlyDeclared);
2667 void anchor() override;
2670 static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
2671 SourceLocation StartLoc,
2672 const DeclarationNameInfo &NameInfo,
2673 QualType T, TypeSourceInfo *TInfo,
2674 bool isInline, bool isImplicitlyDeclared,
2675 ConstexprSpecKind ConstexprKind,
2676 Expr *TrailingRequiresClause = nullptr);
2677 static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID);
2679 void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg);
2681 const FunctionDecl *getOperatorDelete() const {
2682 return getCanonicalDecl()->OperatorDelete;
2685 Expr *getOperatorDeleteThisArg() const {
2686 return getCanonicalDecl()->OperatorDeleteThisArg;
2689 CXXDestructorDecl *getCanonicalDecl() override {
2690 return cast<CXXDestructorDecl>(FunctionDecl::getCanonicalDecl());
2692 const CXXDestructorDecl *getCanonicalDecl() const {
2693 return const_cast<CXXDestructorDecl*>(this)->getCanonicalDecl();
2696 // Implement isa/cast/dyncast/etc.
2697 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2698 static bool classofKind(Kind K) { return K == CXXDestructor; }
2701 /// Represents a C++ conversion function within a class.
2708 /// operator bool();
2711 class CXXConversionDecl : public CXXMethodDecl {
2712 CXXConversionDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2713 const DeclarationNameInfo &NameInfo, QualType T,
2714 TypeSourceInfo *TInfo, bool isInline, ExplicitSpecifier ES,
2715 ConstexprSpecKind ConstexprKind, SourceLocation EndLocation,
2716 Expr *TrailingRequiresClause = nullptr)
2717 : CXXMethodDecl(CXXConversion, C, RD, StartLoc, NameInfo, T, TInfo,
2718 SC_None, isInline, ConstexprKind, EndLocation,
2719 TrailingRequiresClause),
2721 void anchor() override;
2723 ExplicitSpecifier ExplicitSpec;
2726 friend class ASTDeclReader;
2727 friend class ASTDeclWriter;
2729 static CXXConversionDecl *
2730 Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2731 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2732 bool isInline, ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind,
2733 SourceLocation EndLocation, Expr *TrailingRequiresClause = nullptr);
2734 static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2736 ExplicitSpecifier getExplicitSpecifier() {
2737 return getCanonicalDecl()->ExplicitSpec;
2740 const ExplicitSpecifier getExplicitSpecifier() const {
2741 return getCanonicalDecl()->ExplicitSpec;
2744 /// Return true if the declartion is already resolved to be explicit.
2745 bool isExplicit() const { return getExplicitSpecifier().isExplicit(); }
2746 void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; }
2748 /// Returns the type that this conversion function is converting to.
2749 QualType getConversionType() const {
2750 return getType()->castAs<FunctionType>()->getReturnType();
2753 /// Determine whether this conversion function is a conversion from
2754 /// a lambda closure type to a block pointer.
2755 bool isLambdaToBlockPointerConversion() const;
2757 CXXConversionDecl *getCanonicalDecl() override {
2758 return cast<CXXConversionDecl>(FunctionDecl::getCanonicalDecl());
2760 const CXXConversionDecl *getCanonicalDecl() const {
2761 return const_cast<CXXConversionDecl*>(this)->getCanonicalDecl();
2764 // Implement isa/cast/dyncast/etc.
2765 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2766 static bool classofKind(Kind K) { return K == CXXConversion; }
2769 /// Represents a linkage specification.
2773 /// extern "C" void foo();
2775 class LinkageSpecDecl : public Decl, public DeclContext {
2776 virtual void anchor();
2777 // This class stores some data in DeclContext::LinkageSpecDeclBits to save
2778 // some space. Use the provided accessors to access it.
2780 /// Represents the language in a linkage specification.
2782 /// The values are part of the serialization ABI for
2783 /// ASTs and cannot be changed without altering that ABI.
2784 enum LanguageIDs { lang_c = 1, lang_cxx = 2 };
2787 /// The source location for the extern keyword.
2788 SourceLocation ExternLoc;
2790 /// The source location for the right brace (if valid).
2791 SourceLocation RBraceLoc;
2793 LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
2794 SourceLocation LangLoc, LanguageIDs lang, bool HasBraces);
2797 static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
2798 SourceLocation ExternLoc,
2799 SourceLocation LangLoc, LanguageIDs Lang,
2801 static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2803 /// Return the language specified by this linkage specification.
2804 LanguageIDs getLanguage() const {
2805 return static_cast<LanguageIDs>(LinkageSpecDeclBits.Language);
2808 /// Set the language specified by this linkage specification.
2809 void setLanguage(LanguageIDs L) { LinkageSpecDeclBits.Language = L; }
2811 /// Determines whether this linkage specification had braces in
2812 /// its syntactic form.
2813 bool hasBraces() const {
2814 assert(!RBraceLoc.isValid() || LinkageSpecDeclBits.HasBraces);
2815 return LinkageSpecDeclBits.HasBraces;
2818 SourceLocation getExternLoc() const { return ExternLoc; }
2819 SourceLocation getRBraceLoc() const { return RBraceLoc; }
2820 void setExternLoc(SourceLocation L) { ExternLoc = L; }
2821 void setRBraceLoc(SourceLocation L) {
2823 LinkageSpecDeclBits.HasBraces = RBraceLoc.isValid();
2826 SourceLocation getEndLoc() const LLVM_READONLY {
2828 return getRBraceLoc();
2829 // No braces: get the end location of the (only) declaration in context
2831 return decls_empty() ? getLocation() : decls_begin()->getEndLoc();
2834 SourceRange getSourceRange() const override LLVM_READONLY {
2835 return SourceRange(ExternLoc, getEndLoc());
2838 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2839 static bool classofKind(Kind K) { return K == LinkageSpec; }
2841 static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
2842 return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
2845 static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
2846 return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
2850 /// Represents C++ using-directive.
2854 /// using namespace std;
2857 /// \note UsingDirectiveDecl should be Decl not NamedDecl, but we provide
2858 /// artificial names for all using-directives in order to store
2859 /// them in DeclContext effectively.
2860 class UsingDirectiveDecl : public NamedDecl {
2861 /// The location of the \c using keyword.
2862 SourceLocation UsingLoc;
2864 /// The location of the \c namespace keyword.
2865 SourceLocation NamespaceLoc;
2867 /// The nested-name-specifier that precedes the namespace.
2868 NestedNameSpecifierLoc QualifierLoc;
2870 /// The namespace nominated by this using-directive.
2871 NamedDecl *NominatedNamespace;
2873 /// Enclosing context containing both using-directive and nominated
2875 DeclContext *CommonAncestor;
2877 UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
2878 SourceLocation NamespcLoc,
2879 NestedNameSpecifierLoc QualifierLoc,
2880 SourceLocation IdentLoc,
2881 NamedDecl *Nominated,
2882 DeclContext *CommonAncestor)
2883 : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
2884 NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
2885 NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) {}
2887 /// Returns special DeclarationName used by using-directives.
2889 /// This is only used by DeclContext for storing UsingDirectiveDecls in
2890 /// its lookup structure.
2891 static DeclarationName getName() {
2892 return DeclarationName::getUsingDirectiveName();
2895 void anchor() override;
2898 friend class ASTDeclReader;
2900 // Friend for getUsingDirectiveName.
2901 friend class DeclContext;
2903 /// Retrieve the nested-name-specifier that qualifies the
2904 /// name of the namespace, with source-location information.
2905 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2907 /// Retrieve the nested-name-specifier that qualifies the
2908 /// name of the namespace.
2909 NestedNameSpecifier *getQualifier() const {
2910 return QualifierLoc.getNestedNameSpecifier();
2913 NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
2914 const NamedDecl *getNominatedNamespaceAsWritten() const {
2915 return NominatedNamespace;
2918 /// Returns the namespace nominated by this using-directive.
2919 NamespaceDecl *getNominatedNamespace();
2921 const NamespaceDecl *getNominatedNamespace() const {
2922 return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
2925 /// Returns the common ancestor context of this using-directive and
2926 /// its nominated namespace.
2927 DeclContext *getCommonAncestor() { return CommonAncestor; }
2928 const DeclContext *getCommonAncestor() const { return CommonAncestor; }
2930 /// Return the location of the \c using keyword.
2931 SourceLocation getUsingLoc() const { return UsingLoc; }
2933 // FIXME: Could omit 'Key' in name.
2934 /// Returns the location of the \c namespace keyword.
2935 SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
2937 /// Returns the location of this using declaration's identifier.
2938 SourceLocation getIdentLocation() const { return getLocation(); }
2940 static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
2941 SourceLocation UsingLoc,
2942 SourceLocation NamespaceLoc,
2943 NestedNameSpecifierLoc QualifierLoc,
2944 SourceLocation IdentLoc,
2945 NamedDecl *Nominated,
2946 DeclContext *CommonAncestor);
2947 static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID);
2949 SourceRange getSourceRange() const override LLVM_READONLY {
2950 return SourceRange(UsingLoc, getLocation());
2953 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2954 static bool classofKind(Kind K) { return K == UsingDirective; }
2957 /// Represents a C++ namespace alias.
2962 /// namespace Foo = Bar;
2964 class NamespaceAliasDecl : public NamedDecl,
2965 public Redeclarable<NamespaceAliasDecl> {
2966 friend class ASTDeclReader;
2968 /// The location of the \c namespace keyword.
2969 SourceLocation NamespaceLoc;
2971 /// The location of the namespace's identifier.
2973 /// This is accessed by TargetNameLoc.
2974 SourceLocation IdentLoc;
2976 /// The nested-name-specifier that precedes the namespace.
2977 NestedNameSpecifierLoc QualifierLoc;
2979 /// The Decl that this alias points to, either a NamespaceDecl or
2980 /// a NamespaceAliasDecl.
2981 NamedDecl *Namespace;
2983 NamespaceAliasDecl(ASTContext &C, DeclContext *DC,
2984 SourceLocation NamespaceLoc, SourceLocation AliasLoc,
2985 IdentifierInfo *Alias, NestedNameSpecifierLoc QualifierLoc,
2986 SourceLocation IdentLoc, NamedDecl *Namespace)
2987 : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias), redeclarable_base(C),
2988 NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc),
2989 QualifierLoc(QualifierLoc), Namespace(Namespace) {}
2991 void anchor() override;
2993 using redeclarable_base = Redeclarable<NamespaceAliasDecl>;
2995 NamespaceAliasDecl *getNextRedeclarationImpl() override;
2996 NamespaceAliasDecl *getPreviousDeclImpl() override;
2997 NamespaceAliasDecl *getMostRecentDeclImpl() override;
3000 static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
3001 SourceLocation NamespaceLoc,
3002 SourceLocation AliasLoc,
3003 IdentifierInfo *Alias,
3004 NestedNameSpecifierLoc QualifierLoc,
3005 SourceLocation IdentLoc,
3006 NamedDecl *Namespace);
3008 static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3010 using redecl_range = redeclarable_base::redecl_range;
3011 using redecl_iterator = redeclarable_base::redecl_iterator;
3013 using redeclarable_base::redecls_begin;
3014 using redeclarable_base::redecls_end;
3015 using redeclarable_base::redecls;
3016 using redeclarable_base::getPreviousDecl;
3017 using redeclarable_base::getMostRecentDecl;
3019 NamespaceAliasDecl *getCanonicalDecl() override {
3020 return getFirstDecl();
3022 const NamespaceAliasDecl *getCanonicalDecl() const {
3023 return getFirstDecl();
3026 /// Retrieve the nested-name-specifier that qualifies the
3027 /// name of the namespace, with source-location information.
3028 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3030 /// Retrieve the nested-name-specifier that qualifies the
3031 /// name of the namespace.
3032 NestedNameSpecifier *getQualifier() const {
3033 return QualifierLoc.getNestedNameSpecifier();
3036 /// Retrieve the namespace declaration aliased by this directive.
3037 NamespaceDecl *getNamespace() {
3038 if (auto *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
3039 return AD->getNamespace();
3041 return cast<NamespaceDecl>(Namespace);
3044 const NamespaceDecl *getNamespace() const {
3045 return const_cast<NamespaceAliasDecl *>(this)->getNamespace();
3048 /// Returns the location of the alias name, i.e. 'foo' in
3049 /// "namespace foo = ns::bar;".
3050 SourceLocation getAliasLoc() const { return getLocation(); }
3052 /// Returns the location of the \c namespace keyword.
3053 SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
3055 /// Returns the location of the identifier in the named namespace.
3056 SourceLocation getTargetNameLoc() const { return IdentLoc; }
3058 /// Retrieve the namespace that this alias refers to, which
3059 /// may either be a NamespaceDecl or a NamespaceAliasDecl.
3060 NamedDecl *getAliasedNamespace() const { return Namespace; }
3062 SourceRange getSourceRange() const override LLVM_READONLY {
3063 return SourceRange(NamespaceLoc, IdentLoc);
3066 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3067 static bool classofKind(Kind K) { return K == NamespaceAlias; }
3070 /// Implicit declaration of a temporary that was materialized by
3071 /// a MaterializeTemporaryExpr and lifetime-extended by a declaration
3072 class LifetimeExtendedTemporaryDecl final
3074 public Mergeable<LifetimeExtendedTemporaryDecl> {
3075 friend class MaterializeTemporaryExpr;
3076 friend class ASTDeclReader;
3078 Stmt *ExprWithTemporary = nullptr;
3080 /// The declaration which lifetime-extended this reference, if any.
3081 /// Either a VarDecl, or (for a ctor-initializer) a FieldDecl.
3082 ValueDecl *ExtendingDecl = nullptr;
3083 unsigned ManglingNumber;
3085 mutable APValue *Value = nullptr;
3087 virtual void anchor();
3089 LifetimeExtendedTemporaryDecl(Expr *Temp, ValueDecl *EDecl, unsigned Mangling)
3090 : Decl(Decl::LifetimeExtendedTemporary, EDecl->getDeclContext(),
3091 EDecl->getLocation()),
3092 ExprWithTemporary(Temp), ExtendingDecl(EDecl),
3093 ManglingNumber(Mangling) {}
3095 LifetimeExtendedTemporaryDecl(EmptyShell)
3096 : Decl(Decl::LifetimeExtendedTemporary, EmptyShell{}) {}
3099 static LifetimeExtendedTemporaryDecl *Create(Expr *Temp, ValueDecl *EDec,
3100 unsigned Mangling) {
3101 return new (EDec->getASTContext(), EDec->getDeclContext())
3102 LifetimeExtendedTemporaryDecl(Temp, EDec, Mangling);
3104 static LifetimeExtendedTemporaryDecl *CreateDeserialized(ASTContext &C,
3106 return new (C, ID) LifetimeExtendedTemporaryDecl(EmptyShell{});
3109 ValueDecl *getExtendingDecl() { return ExtendingDecl; }
3110 const ValueDecl *getExtendingDecl() const { return ExtendingDecl; }
3112 /// Retrieve the storage duration for the materialized temporary.
3113 StorageDuration getStorageDuration() const;
3115 /// Retrieve the expression to which the temporary materialization conversion
3116 /// was applied. This isn't necessarily the initializer of the temporary due
3117 /// to the C++98 delayed materialization rules, but
3118 /// skipRValueSubobjectAdjustments can be used to find said initializer within
3119 /// the subexpression.
3120 Expr *getTemporaryExpr() { return cast<Expr>(ExprWithTemporary); }
3121 const Expr *getTemporaryExpr() const { return cast<Expr>(ExprWithTemporary); }
3123 unsigned getManglingNumber() const { return ManglingNumber; }
3125 /// Get the storage for the constant value of a materialized temporary
3126 /// of static storage duration.
3127 APValue *getOrCreateValue(bool MayCreate) const;
3129 APValue *getValue() const { return Value; }
3132 Stmt::child_range childrenExpr() {
3133 return Stmt::child_range(&ExprWithTemporary, &ExprWithTemporary + 1);
3136 Stmt::const_child_range childrenExpr() const {
3137 return Stmt::const_child_range(&ExprWithTemporary, &ExprWithTemporary + 1);
3140 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3141 static bool classofKind(Kind K) {
3142 return K == Decl::LifetimeExtendedTemporary;
3146 /// Represents a shadow declaration introduced into a scope by a
3147 /// (resolved) using declaration.
3155 /// using A::foo; // <- a UsingDecl
3156 /// // Also creates a UsingShadowDecl for A::foo() in B
3159 class UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> {
3160 friend class UsingDecl;
3162 /// The referenced declaration.
3163 NamedDecl *Underlying = nullptr;
3165 /// The using declaration which introduced this decl or the next using
3166 /// shadow declaration contained in the aforementioned using declaration.
3167 NamedDecl *UsingOrNextShadow = nullptr;
3169 void anchor() override;
3171 using redeclarable_base = Redeclarable<UsingShadowDecl>;
3173 UsingShadowDecl *getNextRedeclarationImpl() override {
3174 return getNextRedeclaration();
3177 UsingShadowDecl *getPreviousDeclImpl() override {
3178 return getPreviousDecl();
3181 UsingShadowDecl *getMostRecentDeclImpl() override {
3182 return getMostRecentDecl();
3186 UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC, SourceLocation Loc,
3187 UsingDecl *Using, NamedDecl *Target);
3188 UsingShadowDecl(Kind K, ASTContext &C, EmptyShell);
3191 friend class ASTDeclReader;
3192 friend class ASTDeclWriter;
3194 static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
3195 SourceLocation Loc, UsingDecl *Using,
3196 NamedDecl *Target) {
3197 return new (C, DC) UsingShadowDecl(UsingShadow, C, DC, Loc, Using, Target);
3200 static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3202 using redecl_range = redeclarable_base::redecl_range;
3203 using redecl_iterator = redeclarable_base::redecl_iterator;
3205 using redeclarable_base::redecls_begin;
3206 using redeclarable_base::redecls_end;
3207 using redeclarable_base::redecls;
3208 using redeclarable_base::getPreviousDecl;
3209 using redeclarable_base::getMostRecentDecl;
3210 using redeclarable_base::isFirstDecl;
3212 UsingShadowDecl *getCanonicalDecl() override {
3213 return getFirstDecl();
3215 const UsingShadowDecl *getCanonicalDecl() const {
3216 return getFirstDecl();
3219 /// Gets the underlying declaration which has been brought into the
3221 NamedDecl *getTargetDecl() const { return Underlying; }
3223 /// Sets the underlying declaration which has been brought into the
3225 void setTargetDecl(NamedDecl *ND) {
3226 assert(ND && "Target decl is null!");
3228 // A UsingShadowDecl is never a friend or local extern declaration, even
3229 // if it is a shadow declaration for one.
3230 IdentifierNamespace =
3231 ND->getIdentifierNamespace() &
3232 ~(IDNS_OrdinaryFriend | IDNS_TagFriend | IDNS_LocalExtern);
3235 /// Gets the using declaration to which this declaration is tied.
3236 UsingDecl *getUsingDecl() const;
3238 /// The next using shadow declaration contained in the shadow decl
3239 /// chain of the using declaration which introduced this decl.
3240 UsingShadowDecl *getNextUsingShadowDecl() const {
3241 return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow);
3244 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3245 static bool classofKind(Kind K) {
3246 return K == Decl::UsingShadow || K == Decl::ConstructorUsingShadow;
3250 /// Represents a shadow constructor declaration introduced into a
3251 /// class by a C++11 using-declaration that names a constructor.
3255 /// struct Base { Base(int); };
3256 /// struct Derived {
3257 /// using Base::Base; // creates a UsingDecl and a ConstructorUsingShadowDecl
3260 class ConstructorUsingShadowDecl final : public UsingShadowDecl {
3261 /// If this constructor using declaration inherted the constructor
3262 /// from an indirect base class, this is the ConstructorUsingShadowDecl
3263 /// in the named direct base class from which the declaration was inherited.
3264 ConstructorUsingShadowDecl *NominatedBaseClassShadowDecl = nullptr;
3266 /// If this constructor using declaration inherted the constructor
3267 /// from an indirect base class, this is the ConstructorUsingShadowDecl
3268 /// that will be used to construct the unique direct or virtual base class
3269 /// that receives the constructor arguments.
3270 ConstructorUsingShadowDecl *ConstructedBaseClassShadowDecl = nullptr;
3272 /// \c true if the constructor ultimately named by this using shadow
3273 /// declaration is within a virtual base class subobject of the class that
3274 /// contains this declaration.
3275 unsigned IsVirtual : 1;
3277 ConstructorUsingShadowDecl(ASTContext &C, DeclContext *DC, SourceLocation Loc,
3278 UsingDecl *Using, NamedDecl *Target,
3279 bool TargetInVirtualBase)
3280 : UsingShadowDecl(ConstructorUsingShadow, C, DC, Loc, Using,
3281 Target->getUnderlyingDecl()),
3282 NominatedBaseClassShadowDecl(
3283 dyn_cast<ConstructorUsingShadowDecl>(Target)),
3284 ConstructedBaseClassShadowDecl(NominatedBaseClassShadowDecl),
3285 IsVirtual(TargetInVirtualBase) {
3286 // If we found a constructor that chains to a constructor for a virtual
3287 // base, we should directly call that virtual base constructor instead.
3288 // FIXME: This logic belongs in Sema.
3289 if (NominatedBaseClassShadowDecl &&
3290 NominatedBaseClassShadowDecl->constructsVirtualBase()) {
3291 ConstructedBaseClassShadowDecl =
3292 NominatedBaseClassShadowDecl->ConstructedBaseClassShadowDecl;
3297 ConstructorUsingShadowDecl(ASTContext &C, EmptyShell Empty)
3298 : UsingShadowDecl(ConstructorUsingShadow, C, Empty), IsVirtual(false) {}
3300 void anchor() override;
3303 friend class ASTDeclReader;
3304 friend class ASTDeclWriter;
3306 static ConstructorUsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
3308 UsingDecl *Using, NamedDecl *Target,
3310 static ConstructorUsingShadowDecl *CreateDeserialized(ASTContext &C,
3313 /// Returns the parent of this using shadow declaration, which
3314 /// is the class in which this is declared.
3316 const CXXRecordDecl *getParent() const {
3317 return cast<CXXRecordDecl>(getDeclContext());
3319 CXXRecordDecl *getParent() {
3320 return cast<CXXRecordDecl>(getDeclContext());
3324 /// Get the inheriting constructor declaration for the direct base
3325 /// class from which this using shadow declaration was inherited, if there is
3326 /// one. This can be different for each redeclaration of the same shadow decl.
3327 ConstructorUsingShadowDecl *getNominatedBaseClassShadowDecl() const {
3328 return NominatedBaseClassShadowDecl;
3331 /// Get the inheriting constructor declaration for the base class
3332 /// for which we don't have an explicit initializer, if there is one.
3333 ConstructorUsingShadowDecl *getConstructedBaseClassShadowDecl() const {
3334 return ConstructedBaseClassShadowDecl;
3337 /// Get the base class that was named in the using declaration. This
3338 /// can be different for each redeclaration of this same shadow decl.
3339 CXXRecordDecl *getNominatedBaseClass() const;
3341 /// Get the base class whose constructor or constructor shadow
3342 /// declaration is passed the constructor arguments.
3343 CXXRecordDecl *getConstructedBaseClass() const {
3344 return cast<CXXRecordDecl>((ConstructedBaseClassShadowDecl
3345 ? ConstructedBaseClassShadowDecl
3347 ->getDeclContext());
3350 /// Returns \c true if the constructed base class is a virtual base
3351 /// class subobject of this declaration's class.
3352 bool constructsVirtualBase() const {
3356 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3357 static bool classofKind(Kind K) { return K == ConstructorUsingShadow; }
3360 /// Represents a C++ using-declaration.
3364 /// using someNameSpace::someIdentifier;
3366 class UsingDecl : public NamedDecl, public Mergeable<UsingDecl> {
3367 /// The source location of the 'using' keyword itself.
3368 SourceLocation UsingLocation;
3370 /// The nested-name-specifier that precedes the name.
3371 NestedNameSpecifierLoc QualifierLoc;
3373 /// Provides source/type location info for the declaration name
3374 /// embedded in the ValueDecl base class.
3375 DeclarationNameLoc DNLoc;
3377 /// The first shadow declaration of the shadow decl chain associated
3378 /// with this using declaration.
3380 /// The bool member of the pair store whether this decl has the \c typename
3382 llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow;
3384 UsingDecl(DeclContext *DC, SourceLocation UL,
3385 NestedNameSpecifierLoc QualifierLoc,
3386 const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword)
3387 : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()),
3388 UsingLocation(UL), QualifierLoc(QualifierLoc),
3389 DNLoc(NameInfo.getInfo()), FirstUsingShadow(nullptr, HasTypenameKeyword) {
3392 void anchor() override;
3395 friend class ASTDeclReader;
3396 friend class ASTDeclWriter;
3398 /// Return the source location of the 'using' keyword.
3399 SourceLocation getUsingLoc() const { return UsingLocation; }
3401 /// Set the source location of the 'using' keyword.
3402 void setUsingLoc(SourceLocation L) { UsingLocation = L; }
3404 /// Retrieve the nested-name-specifier that qualifies the name,
3405 /// with source-location information.
3406 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3408 /// Retrieve the nested-name-specifier that qualifies the name.
3409 NestedNameSpecifier *getQualifier() const {
3410 return QualifierLoc.getNestedNameSpecifier();
3413 DeclarationNameInfo getNameInfo() const {
3414 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
3417 /// Return true if it is a C++03 access declaration (no 'using').
3418 bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
3420 /// Return true if the using declaration has 'typename'.
3421 bool hasTypename() const { return FirstUsingShadow.getInt(); }
3423 /// Sets whether the using declaration has 'typename'.
3424 void setTypename(bool TN) { FirstUsingShadow.setInt(TN); }
3426 /// Iterates through the using shadow declarations associated with
3427 /// this using declaration.
3428 class shadow_iterator {
3429 /// The current using shadow declaration.
3430 UsingShadowDecl *Current = nullptr;
3433 using value_type = UsingShadowDecl *;
3434 using reference = UsingShadowDecl *;
3435 using pointer = UsingShadowDecl *;
3436 using iterator_category = std::forward_iterator_tag;
3437 using difference_type = std::ptrdiff_t;
3439 shadow_iterator() = default;
3440 explicit shadow_iterator(UsingShadowDecl *C) : Current(C) {}
3442 reference operator*() const { return Current; }
3443 pointer operator->() const { return Current; }
3445 shadow_iterator& operator++() {
3446 Current = Current->getNextUsingShadowDecl();
3450 shadow_iterator operator++(int) {
3451 shadow_iterator tmp(*this);
3456 friend bool operator==(shadow_iterator x, shadow_iterator y) {
3457 return x.Current == y.Current;
3459 friend bool operator!=(shadow_iterator x, shadow_iterator y) {
3460 return x.Current != y.Current;
3464 using shadow_range = llvm::iterator_range<shadow_iterator>;
3466 shadow_range shadows() const {
3467 return shadow_range(shadow_begin(), shadow_end());
3470 shadow_iterator shadow_begin() const {
3471 return shadow_iterator(FirstUsingShadow.getPointer());
3474 shadow_iterator shadow_end() const { return shadow_iterator(); }
3476 /// Return the number of shadowed declarations associated with this
3477 /// using declaration.
3478 unsigned shadow_size() const {
3479 return std::distance(shadow_begin(), shadow_end());
3482 void addShadowDecl(UsingShadowDecl *S);
3483 void removeShadowDecl(UsingShadowDecl *S);
3485 static UsingDecl *Create(ASTContext &C, DeclContext *DC,
3486 SourceLocation UsingL,
3487 NestedNameSpecifierLoc QualifierLoc,
3488 const DeclarationNameInfo &NameInfo,
3489 bool HasTypenameKeyword);
3491 static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3493 SourceRange getSourceRange() const override LLVM_READONLY;
3495 /// Retrieves the canonical declaration of this declaration.
3496 UsingDecl *getCanonicalDecl() override { return getFirstDecl(); }
3497 const UsingDecl *getCanonicalDecl() const { return getFirstDecl(); }
3499 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3500 static bool classofKind(Kind K) { return K == Using; }
3503 /// Represents a pack of using declarations that a single
3504 /// using-declarator pack-expanded into.
3507 /// template<typename ...T> struct X : T... {
3508 /// using T::operator()...;
3509 /// using T::operator T...;
3513 /// In the second case above, the UsingPackDecl will have the name
3514 /// 'operator T' (which contains an unexpanded pack), but the individual
3515 /// UsingDecls and UsingShadowDecls will have more reasonable names.
3516 class UsingPackDecl final
3517 : public NamedDecl, public Mergeable<UsingPackDecl>,
3518 private llvm::TrailingObjects<UsingPackDecl, NamedDecl *> {
3519 /// The UnresolvedUsingValueDecl or UnresolvedUsingTypenameDecl from
3520 /// which this waas instantiated.
3521 NamedDecl *InstantiatedFrom;
3523 /// The number of using-declarations created by this pack expansion.
3524 unsigned NumExpansions;
3526 UsingPackDecl(DeclContext *DC, NamedDecl *InstantiatedFrom,
3527 ArrayRef<NamedDecl *> UsingDecls)
3528 : NamedDecl(UsingPack, DC,
3529 InstantiatedFrom ? InstantiatedFrom->getLocation()
3531 InstantiatedFrom ? InstantiatedFrom->getDeclName()
3532 : DeclarationName()),
3533 InstantiatedFrom(InstantiatedFrom), NumExpansions(UsingDecls.size()) {
3534 std::uninitialized_copy(UsingDecls.begin(), UsingDecls.end(),
3535 getTrailingObjects<NamedDecl *>());
3538 void anchor() override;
3541 friend class ASTDeclReader;
3542 friend class ASTDeclWriter;
3543 friend TrailingObjects;
3545 /// Get the using declaration from which this was instantiated. This will
3546 /// always be an UnresolvedUsingValueDecl or an UnresolvedUsingTypenameDecl
3547 /// that is a pack expansion.
3548 NamedDecl *getInstantiatedFromUsingDecl() const { return InstantiatedFrom; }
3550 /// Get the set of using declarations that this pack expanded into. Note that
3551 /// some of these may still be unresolved.
3552 ArrayRef<NamedDecl *> expansions() const {
3553 return llvm::makeArrayRef(getTrailingObjects<NamedDecl *>(), NumExpansions);
3556 static UsingPackDecl *Create(ASTContext &C, DeclContext *DC,
3557 NamedDecl *InstantiatedFrom,
3558 ArrayRef<NamedDecl *> UsingDecls);
3560 static UsingPackDecl *CreateDeserialized(ASTContext &C, unsigned ID,
3561 unsigned NumExpansions);
3563 SourceRange getSourceRange() const override LLVM_READONLY {
3564 return InstantiatedFrom->getSourceRange();
3567 UsingPackDecl *getCanonicalDecl() override { return getFirstDecl(); }
3568 const UsingPackDecl *getCanonicalDecl() const { return getFirstDecl(); }
3570 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3571 static bool classofKind(Kind K) { return K == UsingPack; }
3574 /// Represents a dependent using declaration which was not marked with
3577 /// Unlike non-dependent using declarations, these *only* bring through
3578 /// non-types; otherwise they would break two-phase lookup.
3581 /// template \<class T> class A : public Base<T> {
3582 /// using Base<T>::foo;
3585 class UnresolvedUsingValueDecl : public ValueDecl,
3586 public Mergeable<UnresolvedUsingValueDecl> {
3587 /// The source location of the 'using' keyword
3588 SourceLocation UsingLocation;
3590 /// If this is a pack expansion, the location of the '...'.
3591 SourceLocation EllipsisLoc;
3593 /// The nested-name-specifier that precedes the name.
3594 NestedNameSpecifierLoc QualifierLoc;
3596 /// Provides source/type location info for the declaration name
3597 /// embedded in the ValueDecl base class.
3598 DeclarationNameLoc DNLoc;
3600 UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
3601 SourceLocation UsingLoc,
3602 NestedNameSpecifierLoc QualifierLoc,
3603 const DeclarationNameInfo &NameInfo,
3604 SourceLocation EllipsisLoc)
3605 : ValueDecl(UnresolvedUsingValue, DC,
3606 NameInfo.getLoc(), NameInfo.getName(), Ty),
3607 UsingLocation(UsingLoc), EllipsisLoc(EllipsisLoc),
3608 QualifierLoc(QualifierLoc), DNLoc(NameInfo.getInfo()) {}
3610 void anchor() override;
3613 friend class ASTDeclReader;
3614 friend class ASTDeclWriter;
3616 /// Returns the source location of the 'using' keyword.
3617 SourceLocation getUsingLoc() const { return UsingLocation; }
3619 /// Set the source location of the 'using' keyword.
3620 void setUsingLoc(SourceLocation L) { UsingLocation = L; }
3622 /// Return true if it is a C++03 access declaration (no 'using').
3623 bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
3625 /// Retrieve the nested-name-specifier that qualifies the name,
3626 /// with source-location information.
3627 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3629 /// Retrieve the nested-name-specifier that qualifies the name.
3630 NestedNameSpecifier *getQualifier() const {
3631 return QualifierLoc.getNestedNameSpecifier();
3634 DeclarationNameInfo getNameInfo() const {
3635 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
3638 /// Determine whether this is a pack expansion.
3639 bool isPackExpansion() const {
3640 return EllipsisLoc.isValid();
3643 /// Get the location of the ellipsis if this is a pack expansion.
3644 SourceLocation getEllipsisLoc() const {
3648 static UnresolvedUsingValueDecl *
3649 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
3650 NestedNameSpecifierLoc QualifierLoc,
3651 const DeclarationNameInfo &NameInfo, SourceLocation EllipsisLoc);
3653 static UnresolvedUsingValueDecl *
3654 CreateDeserialized(ASTContext &C, unsigned ID);
3656 SourceRange getSourceRange() const override LLVM_READONLY;
3658 /// Retrieves the canonical declaration of this declaration.
3659 UnresolvedUsingValueDecl *getCanonicalDecl() override {
3660 return getFirstDecl();
3662 const UnresolvedUsingValueDecl *getCanonicalDecl() const {
3663 return getFirstDecl();
3666 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3667 static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
3670 /// Represents a dependent using declaration which was marked with
3674 /// template \<class T> class A : public Base<T> {
3675 /// using typename Base<T>::foo;
3679 /// The type associated with an unresolved using typename decl is
3680 /// currently always a typename type.
3681 class UnresolvedUsingTypenameDecl
3683 public Mergeable<UnresolvedUsingTypenameDecl> {
3684 friend class ASTDeclReader;
3686 /// The source location of the 'typename' keyword
3687 SourceLocation TypenameLocation;
3689 /// If this is a pack expansion, the location of the '...'.
3690 SourceLocation EllipsisLoc;
3692 /// The nested-name-specifier that precedes the name.
3693 NestedNameSpecifierLoc QualifierLoc;
3695 UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
3696 SourceLocation TypenameLoc,
3697 NestedNameSpecifierLoc QualifierLoc,
3698 SourceLocation TargetNameLoc,
3699 IdentifierInfo *TargetName,
3700 SourceLocation EllipsisLoc)
3701 : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName,
3703 TypenameLocation(TypenameLoc), EllipsisLoc(EllipsisLoc),
3704 QualifierLoc(QualifierLoc) {}
3706 void anchor() override;
3709 /// Returns the source location of the 'using' keyword.
3710 SourceLocation getUsingLoc() const { return getBeginLoc(); }
3712 /// Returns the source location of the 'typename' keyword.
3713 SourceLocation getTypenameLoc() const { return TypenameLocation; }
3715 /// Retrieve the nested-name-specifier that qualifies the name,
3716 /// with source-location information.
3717 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3719 /// Retrieve the nested-name-specifier that qualifies the name.
3720 NestedNameSpecifier *getQualifier() const {
3721 return QualifierLoc.getNestedNameSpecifier();
3724 DeclarationNameInfo getNameInfo() const {
3725 return DeclarationNameInfo(getDeclName(), getLocation());
3728 /// Determine whether this is a pack expansion.
3729 bool isPackExpansion() const {
3730 return EllipsisLoc.isValid();
3733 /// Get the location of the ellipsis if this is a pack expansion.
3734 SourceLocation getEllipsisLoc() const {
3738 static UnresolvedUsingTypenameDecl *
3739 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
3740 SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc,
3741 SourceLocation TargetNameLoc, DeclarationName TargetName,
3742 SourceLocation EllipsisLoc);
3744 static UnresolvedUsingTypenameDecl *
3745 CreateDeserialized(ASTContext &C, unsigned ID);
3747 /// Retrieves the canonical declaration of this declaration.
3748 UnresolvedUsingTypenameDecl *getCanonicalDecl() override {
3749 return getFirstDecl();
3751 const UnresolvedUsingTypenameDecl *getCanonicalDecl() const {
3752 return getFirstDecl();
3755 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3756 static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; }
3759 /// Represents a C++11 static_assert declaration.
3760 class StaticAssertDecl : public Decl {
3761 llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed;
3762 StringLiteral *Message;
3763 SourceLocation RParenLoc;
3765 StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc,
3766 Expr *AssertExpr, StringLiteral *Message,
3767 SourceLocation RParenLoc, bool Failed)
3768 : Decl(StaticAssert, DC, StaticAssertLoc),
3769 AssertExprAndFailed(AssertExpr, Failed), Message(Message),
3770 RParenLoc(RParenLoc) {}
3772 virtual void anchor();
3775 friend class ASTDeclReader;
3777 static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
3778 SourceLocation StaticAssertLoc,
3779 Expr *AssertExpr, StringLiteral *Message,
3780 SourceLocation RParenLoc, bool Failed);
3781 static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3783 Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); }
3784 const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); }
3786 StringLiteral *getMessage() { return Message; }
3787 const StringLiteral *getMessage() const { return Message; }
3789 bool isFailed() const { return AssertExprAndFailed.getInt(); }
3791 SourceLocation getRParenLoc() const { return RParenLoc; }
3793 SourceRange getSourceRange() const override LLVM_READONLY {
3794 return SourceRange(getLocation(), getRParenLoc());
3797 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3798 static bool classofKind(Kind K) { return K == StaticAssert; }
3801 /// A binding in a decomposition declaration. For instance, given:
3804 /// auto &[a, b, c] = n;
3806 /// a, b, and c are BindingDecls, whose bindings are the expressions
3807 /// x[0], x[1], and x[2] respectively, where x is the implicit
3808 /// DecompositionDecl of type 'int (&)[3]'.
3809 class BindingDecl : public ValueDecl {
3810 /// The declaration that this binding binds to part of.
3812 /// The binding represented by this declaration. References to this
3813 /// declaration are effectively equivalent to this expression (except
3814 /// that it is only evaluated once at the point of declaration of the
3816 Expr *Binding = nullptr;
3818 BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id)
3819 : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()) {}
3821 void anchor() override;
3824 friend class ASTDeclReader;
3826 static BindingDecl *Create(ASTContext &C, DeclContext *DC,
3827 SourceLocation IdLoc, IdentifierInfo *Id);
3828 static BindingDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3830 /// Get the expression to which this declaration is bound. This may be null
3831 /// in two different cases: while parsing the initializer for the
3832 /// decomposition declaration, and when the initializer is type-dependent.
3833 Expr *getBinding() const { return Binding; }
3835 /// Get the decomposition declaration that this binding represents a
3836 /// decomposition of.
3837 ValueDecl *getDecomposedDecl() const;
3839 /// Get the variable (if any) that holds the value of evaluating the binding.
3840 /// Only present for user-defined bindings for tuple-like types.
3841 VarDecl *getHoldingVar() const;
3843 /// Set the binding for this BindingDecl, along with its declared type (which
3844 /// should be a possibly-cv-qualified form of the type of the binding, or a
3845 /// reference to such a type).
3846 void setBinding(QualType DeclaredType, Expr *Binding) {
3847 setType(DeclaredType);
3848 this->Binding = Binding;
3851 /// Set the decomposed variable for this BindingDecl.
3852 void setDecomposedDecl(ValueDecl *Decomposed) { Decomp = Decomposed; }
3854 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3855 static bool classofKind(Kind K) { return K == Decl::Binding; }
3858 /// A decomposition declaration. For instance, given:
3861 /// auto &[a, b, c] = n;
3863 /// the second line declares a DecompositionDecl of type 'int (&)[3]', and
3864 /// three BindingDecls (named a, b, and c). An instance of this class is always
3865 /// unnamed, but behaves in almost all other respects like a VarDecl.
3866 class DecompositionDecl final
3868 private llvm::TrailingObjects<DecompositionDecl, BindingDecl *> {
3869 /// The number of BindingDecl*s following this object.
3870 unsigned NumBindings;
3872 DecompositionDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3873 SourceLocation LSquareLoc, QualType T,
3874 TypeSourceInfo *TInfo, StorageClass SC,
3875 ArrayRef<BindingDecl *> Bindings)
3876 : VarDecl(Decomposition, C, DC, StartLoc, LSquareLoc, nullptr, T, TInfo,
3878 NumBindings(Bindings.size()) {
3879 std::uninitialized_copy(Bindings.begin(), Bindings.end(),
3880 getTrailingObjects<BindingDecl *>());
3881 for (auto *B : Bindings)
3882 B->setDecomposedDecl(this);
3885 void anchor() override;
3888 friend class ASTDeclReader;
3889 friend TrailingObjects;
3891 static DecompositionDecl *Create(ASTContext &C, DeclContext *DC,
3892 SourceLocation StartLoc,
3893 SourceLocation LSquareLoc,
3894 QualType T, TypeSourceInfo *TInfo,
3896 ArrayRef<BindingDecl *> Bindings);
3897 static DecompositionDecl *CreateDeserialized(ASTContext &C, unsigned ID,
3898 unsigned NumBindings);
3900 ArrayRef<BindingDecl *> bindings() const {
3901 return llvm::makeArrayRef(getTrailingObjects<BindingDecl *>(), NumBindings);
3904 void printName(raw_ostream &os) const override;
3906 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3907 static bool classofKind(Kind K) { return K == Decomposition; }
3910 /// An instance of this class represents the declaration of a property
3911 /// member. This is a Microsoft extension to C++, first introduced in
3912 /// Visual Studio .NET 2003 as a parallel to similar features in C#
3913 /// and Managed C++.
3915 /// A property must always be a non-static class member.
3917 /// A property member superficially resembles a non-static data
3918 /// member, except preceded by a property attribute:
3919 /// __declspec(property(get=GetX, put=PutX)) int x;
3920 /// Either (but not both) of the 'get' and 'put' names may be omitted.
3922 /// A reference to a property is always an lvalue. If the lvalue
3923 /// undergoes lvalue-to-rvalue conversion, then a getter name is
3924 /// required, and that member is called with no arguments.
3925 /// If the lvalue is assigned into, then a setter name is required,
3926 /// and that member is called with one argument, the value assigned.
3927 /// Both operations are potentially overloaded. Compound assignments
3928 /// are permitted, as are the increment and decrement operators.
3930 /// The getter and putter methods are permitted to be overloaded,
3931 /// although their return and parameter types are subject to certain
3932 /// restrictions according to the type of the property.
3934 /// A property declared using an incomplete array type may
3935 /// additionally be subscripted, adding extra parameters to the getter
3936 /// and putter methods.
3937 class MSPropertyDecl : public DeclaratorDecl {
3938 IdentifierInfo *GetterId, *SetterId;
3940 MSPropertyDecl(DeclContext *DC, SourceLocation L, DeclarationName N,
3941 QualType T, TypeSourceInfo *TInfo, SourceLocation StartL,
3942 IdentifierInfo *Getter, IdentifierInfo *Setter)
3943 : DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL),
3944 GetterId(Getter), SetterId(Setter) {}
3946 void anchor() override;
3948 friend class ASTDeclReader;
3950 static MSPropertyDecl *Create(ASTContext &C, DeclContext *DC,
3951 SourceLocation L, DeclarationName N, QualType T,
3952 TypeSourceInfo *TInfo, SourceLocation StartL,
3953 IdentifierInfo *Getter, IdentifierInfo *Setter);
3954 static MSPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
3956 static bool classof(const Decl *D) { return D->getKind() == MSProperty; }
3958 bool hasGetter() const { return GetterId != nullptr; }
3959 IdentifierInfo* getGetterId() const { return GetterId; }
3960 bool hasSetter() const { return SetterId != nullptr; }
3961 IdentifierInfo* getSetterId() const { return SetterId; }
3964 /// Insertion operator for diagnostics. This allows sending an AccessSpecifier
3965 /// into a diagnostic with <<.
3966 const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
3967 AccessSpecifier AS);
3969 const PartialDiagnostic &operator<<(const PartialDiagnostic &DB,
3970 AccessSpecifier AS);
3972 } // namespace clang
3974 #endif // LLVM_CLANG_AST_DECLCXX_H