clang 20.0.0git
DeclCXX.h
Go to the documentation of this file.
1//===- DeclCXX.h - Classes for representing C++ declarations --*- C++ -*-=====//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// Defines the C++ Decl subclasses, other than those for templates
11/// (found in DeclTemplate.h) and friends (in DeclFriend.h).
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_AST_DECLCXX_H
16#define LLVM_CLANG_AST_DECLCXX_H
17
19#include "clang/AST/Decl.h"
20#include "clang/AST/DeclBase.h"
22#include "clang/AST/Expr.h"
27#include "clang/AST/Stmt.h"
28#include "clang/AST/Type.h"
29#include "clang/AST/TypeLoc.h"
31#include "clang/Basic/LLVM.h"
32#include "clang/Basic/Lambda.h"
37#include "llvm/ADT/ArrayRef.h"
38#include "llvm/ADT/DenseMap.h"
39#include "llvm/ADT/PointerIntPair.h"
40#include "llvm/ADT/PointerUnion.h"
41#include "llvm/ADT/STLExtras.h"
42#include "llvm/ADT/TinyPtrVector.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"
48#include <cassert>
49#include <cstddef>
50#include <iterator>
51#include <memory>
52#include <vector>
53
54namespace clang {
55
56class ASTContext;
57class ClassTemplateDecl;
58class ConstructorUsingShadowDecl;
59class CXXBasePath;
60class CXXBasePaths;
61class CXXConstructorDecl;
62class CXXDestructorDecl;
63class CXXFinalOverriderMap;
64class CXXIndirectPrimaryBaseSet;
65class CXXMethodDecl;
66class DecompositionDecl;
67class FriendDecl;
68class FunctionTemplateDecl;
69class IdentifierInfo;
70class MemberSpecializationInfo;
71class BaseUsingDecl;
72class TemplateDecl;
73class TemplateParameterList;
74class UsingDecl;
75
76/// Represents an access specifier followed by colon ':'.
77///
78/// An objects of this class represents sugar for the syntactic occurrence
79/// of an access specifier followed by a colon in the list of member
80/// specifiers of a C++ class definition.
81///
82/// Note that they do not represent other uses of access specifiers,
83/// such as those occurring in a list of base specifiers.
84/// Also note that this class has nothing to do with so-called
85/// "access declarations" (C++98 11.3 [class.access.dcl]).
86class AccessSpecDecl : public Decl {
87 /// The location of the ':'.
88 SourceLocation ColonLoc;
89
91 SourceLocation ASLoc, SourceLocation ColonLoc)
92 : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) {
93 setAccess(AS);
94 }
95
96 AccessSpecDecl(EmptyShell Empty) : Decl(AccessSpec, Empty) {}
97
98 virtual void anchor();
99
100public:
101 /// The location of the access specifier.
103
104 /// Sets the location of the access specifier.
106
107 /// The location of the colon following the access specifier.
108 SourceLocation getColonLoc() const { return ColonLoc; }
109
110 /// Sets the location of the colon.
111 void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; }
112
113 SourceRange getSourceRange() const override LLVM_READONLY {
115 }
116
118 DeclContext *DC, SourceLocation ASLoc,
119 SourceLocation ColonLoc) {
120 return new (C, DC) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
121 }
122
124
125 // Implement isa/cast/dyncast/etc.
126 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
127 static bool classofKind(Kind K) { return K == AccessSpec; }
128};
129
130/// Represents a base class of a C++ class.
131///
132/// Each CXXBaseSpecifier represents a single, direct base class (or
133/// struct) of a C++ class (or struct). It specifies the type of that
134/// base class, whether it is a virtual or non-virtual base, and what
135/// level of access (public, protected, private) is used for the
136/// derivation. For example:
137///
138/// \code
139/// class A { };
140/// class B { };
141/// class C : public virtual A, protected B { };
142/// \endcode
143///
144/// In this code, C will have two CXXBaseSpecifiers, one for "public
145/// virtual A" and the other for "protected B".
147 /// The source code range that covers the full base
148 /// specifier, including the "virtual" (if present) and access
149 /// specifier (if present).
150 SourceRange Range;
151
152 /// The source location of the ellipsis, if this is a pack
153 /// expansion.
154 SourceLocation EllipsisLoc;
155
156 /// Whether this is a virtual base class or not.
157 LLVM_PREFERRED_TYPE(bool)
158 unsigned Virtual : 1;
159
160 /// Whether this is the base of a class (true) or of a struct (false).
161 ///
162 /// This determines the mapping from the access specifier as written in the
163 /// source code to the access specifier used for semantic analysis.
164 LLVM_PREFERRED_TYPE(bool)
165 unsigned BaseOfClass : 1;
166
167 /// Access specifier as written in the source code (may be AS_none).
168 ///
169 /// The actual type of data stored here is an AccessSpecifier, but we use
170 /// "unsigned" here to work around Microsoft ABI.
171 LLVM_PREFERRED_TYPE(AccessSpecifier)
172 unsigned Access : 2;
173
174 /// Whether the class contains a using declaration
175 /// to inherit the named class's constructors.
176 LLVM_PREFERRED_TYPE(bool)
177 unsigned InheritConstructors : 1;
178
179 /// The type of the base class.
180 ///
181 /// This will be a class or struct (or a typedef of such). The source code
182 /// range does not include the \c virtual or the access specifier.
183 TypeSourceInfo *BaseTypeInfo;
184
185public:
186 CXXBaseSpecifier() = default;
188 TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
189 : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC),
190 Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) {}
191
192 /// Retrieves the source range that contains the entire base specifier.
193 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
194 SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
195 SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
196
197 /// Get the location at which the base class type was written.
198 SourceLocation getBaseTypeLoc() const LLVM_READONLY {
199 return BaseTypeInfo->getTypeLoc().getBeginLoc();
200 }
201
202 /// Determines whether the base class is a virtual base class (or not).
203 bool isVirtual() const { return Virtual; }
204
205 /// Determine whether this base class is a base of a class declared
206 /// with the 'class' keyword (vs. one declared with the 'struct' keyword).
207 bool isBaseOfClass() const { return BaseOfClass; }
208
209 /// Determine whether this base specifier is a pack expansion.
210 bool isPackExpansion() const { return EllipsisLoc.isValid(); }
211
212 /// Determine whether this base class's constructors get inherited.
213 bool getInheritConstructors() const { return InheritConstructors; }
214
215 /// Set that this base class's constructors should be inherited.
216 void setInheritConstructors(bool Inherit = true) {
217 InheritConstructors = Inherit;
218 }
219
220 /// For a pack expansion, determine the location of the ellipsis.
222 return EllipsisLoc;
223 }
224
225 /// Returns the access specifier for this base specifier.
226 ///
227 /// This is the actual base specifier as used for semantic analysis, so
228 /// the result can never be AS_none. To retrieve the access specifier as
229 /// written in the source code, use getAccessSpecifierAsWritten().
231 if ((AccessSpecifier)Access == AS_none)
232 return BaseOfClass? AS_private : AS_public;
233 else
234 return (AccessSpecifier)Access;
235 }
236
237 /// Retrieves the access specifier as written in the source code
238 /// (which may mean that no access specifier was explicitly written).
239 ///
240 /// Use getAccessSpecifier() to retrieve the access specifier for use in
241 /// semantic analysis.
243 return (AccessSpecifier)Access;
244 }
245
246 /// Retrieves the type of the base class.
247 ///
248 /// This type will always be an unqualified class type.
250 return BaseTypeInfo->getType().getUnqualifiedType();
251 }
252
253 /// Retrieves the type and source location of the base class.
254 TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; }
255};
256
257/// Represents a C++ struct/union/class.
258class CXXRecordDecl : public RecordDecl {
259 friend class ASTDeclReader;
260 friend class ASTDeclWriter;
261 friend class ASTNodeImporter;
262 friend class ASTReader;
263 friend class ASTRecordWriter;
264 friend class ASTWriter;
265 friend class DeclContext;
266 friend class LambdaExpr;
267 friend class ODRDiagsEmitter;
268
271
272 /// Values used in DefinitionData fields to represent special members.
273 enum SpecialMemberFlags {
274 SMF_DefaultConstructor = 0x1,
275 SMF_CopyConstructor = 0x2,
276 SMF_MoveConstructor = 0x4,
277 SMF_CopyAssignment = 0x8,
278 SMF_MoveAssignment = 0x10,
279 SMF_Destructor = 0x20,
280 SMF_All = 0x3f
281 };
282
283public:
288 };
289
290private:
291 struct DefinitionData {
292 #define FIELD(Name, Width, Merge) \
293 unsigned Name : Width;
294 #include "CXXRecordDeclDefinitionBits.def"
295
296 /// Whether this class describes a C++ lambda.
297 LLVM_PREFERRED_TYPE(bool)
298 unsigned IsLambda : 1;
299
300 /// Whether we are currently parsing base specifiers.
301 LLVM_PREFERRED_TYPE(bool)
302 unsigned IsParsingBaseSpecifiers : 1;
303
304 /// True when visible conversion functions are already computed
305 /// and are available.
306 LLVM_PREFERRED_TYPE(bool)
307 unsigned ComputedVisibleConversions : 1;
308
309 LLVM_PREFERRED_TYPE(bool)
310 unsigned HasODRHash : 1;
311
312 /// A hash of parts of the class to help in ODR checking.
313 unsigned ODRHash = 0;
314
315 /// The number of base class specifiers in Bases.
316 unsigned NumBases = 0;
317
318 /// The number of virtual base class specifiers in VBases.
319 unsigned NumVBases = 0;
320
321 /// Base classes of this class.
322 ///
323 /// FIXME: This is wasted space for a union.
325
326 /// direct and indirect virtual base classes of this class.
328
329 /// The conversion functions of this C++ class (but not its
330 /// inherited conversion functions).
331 ///
332 /// Each of the entries in this overload set is a CXXConversionDecl.
333 LazyASTUnresolvedSet Conversions;
334
335 /// The conversion functions of this C++ class and all those
336 /// inherited conversion functions that are visible in this class.
337 ///
338 /// Each of the entries in this overload set is a CXXConversionDecl or a
339 /// FunctionTemplateDecl.
340 LazyASTUnresolvedSet VisibleConversions;
341
342 /// The declaration which defines this record.
343 CXXRecordDecl *Definition;
344
345 /// The first friend declaration in this class, or null if there
346 /// aren't any.
347 ///
348 /// This is actually currently stored in reverse order.
349 LazyDeclPtr FirstFriend;
350
351 DefinitionData(CXXRecordDecl *D);
352
353 /// Retrieve the set of direct base classes.
354 CXXBaseSpecifier *getBases() const {
355 if (!Bases.isOffset())
356 return Bases.get(nullptr);
357 return getBasesSlowCase();
358 }
359
360 /// Retrieve the set of virtual base classes.
361 CXXBaseSpecifier *getVBases() const {
362 if (!VBases.isOffset())
363 return VBases.get(nullptr);
364 return getVBasesSlowCase();
365 }
366
367 ArrayRef<CXXBaseSpecifier> bases() const {
368 return llvm::ArrayRef(getBases(), NumBases);
369 }
370
371 ArrayRef<CXXBaseSpecifier> vbases() const {
372 return llvm::ArrayRef(getVBases(), NumVBases);
373 }
374
375 private:
376 CXXBaseSpecifier *getBasesSlowCase() const;
377 CXXBaseSpecifier *getVBasesSlowCase() const;
378 };
379
380 struct DefinitionData *DefinitionData;
381
382 /// Describes a C++ closure type (generated by a lambda expression).
383 struct LambdaDefinitionData : public DefinitionData {
384 using Capture = LambdaCapture;
385
386 /// Whether this lambda is known to be dependent, even if its
387 /// context isn't dependent.
388 ///
389 /// A lambda with a non-dependent context can be dependent if it occurs
390 /// within the default argument of a function template, because the
391 /// lambda will have been created with the enclosing context as its
392 /// declaration context, rather than function. This is an unfortunate
393 /// artifact of having to parse the default arguments before.
394 LLVM_PREFERRED_TYPE(LambdaDependencyKind)
395 unsigned DependencyKind : 2;
396
397 /// Whether this lambda is a generic lambda.
398 LLVM_PREFERRED_TYPE(bool)
399 unsigned IsGenericLambda : 1;
400
401 /// The Default Capture.
402 LLVM_PREFERRED_TYPE(LambdaCaptureDefault)
403 unsigned CaptureDefault : 2;
404
405 /// The number of captures in this lambda is limited 2^NumCaptures.
406 unsigned NumCaptures : 15;
407
408 /// The number of explicit captures in this lambda.
409 unsigned NumExplicitCaptures : 12;
410
411 /// Has known `internal` linkage.
412 LLVM_PREFERRED_TYPE(bool)
413 unsigned HasKnownInternalLinkage : 1;
414
415 /// The number used to indicate this lambda expression for name
416 /// mangling in the Itanium C++ ABI.
417 unsigned ManglingNumber : 31;
418
419 /// The index of this lambda within its context declaration. This is not in
420 /// general the same as the mangling number.
421 unsigned IndexInContext;
422
423 /// The declaration that provides context for this lambda, if the
424 /// actual DeclContext does not suffice. This is used for lambdas that
425 /// occur within default arguments of function parameters within the class
426 /// or within a data member initializer.
427 LazyDeclPtr ContextDecl;
428
429 /// The lists of captures, both explicit and implicit, for this
430 /// lambda. One list is provided for each merged copy of the lambda.
431 /// The first list corresponds to the canonical definition.
432 /// The destructor is registered by AddCaptureList when necessary.
433 llvm::TinyPtrVector<Capture*> Captures;
434
435 /// The type of the call method.
436 TypeSourceInfo *MethodTyInfo;
437
438 LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info, unsigned DK,
439 bool IsGeneric, LambdaCaptureDefault CaptureDefault)
440 : DefinitionData(D), DependencyKind(DK), IsGenericLambda(IsGeneric),
441 CaptureDefault(CaptureDefault), NumCaptures(0),
442 NumExplicitCaptures(0), HasKnownInternalLinkage(0), ManglingNumber(0),
443 IndexInContext(0), MethodTyInfo(Info) {
444 IsLambda = true;
445
446 // C++1z [expr.prim.lambda]p4:
447 // This class type is not an aggregate type.
448 Aggregate = false;
449 PlainOldData = false;
450 }
451
452 // Add a list of captures.
453 void AddCaptureList(ASTContext &Ctx, Capture *CaptureList);
454 };
455
456 struct DefinitionData *dataPtr() const {
457 // Complete the redecl chain (if necessary).
459 return DefinitionData;
460 }
461
462 struct DefinitionData &data() const {
463 auto *DD = dataPtr();
464 assert(DD && "queried property of class with no definition");
465 return *DD;
466 }
467
468 struct LambdaDefinitionData &getLambdaData() const {
469 // No update required: a merged definition cannot change any lambda
470 // properties.
471 auto *DD = DefinitionData;
472 assert(DD && DD->IsLambda && "queried lambda property of non-lambda class");
473 return static_cast<LambdaDefinitionData&>(*DD);
474 }
475
476 /// The template or declaration that this declaration
477 /// describes or was instantiated from, respectively.
478 ///
479 /// For non-templates, this value will be null. For record
480 /// declarations that describe a class template, this will be a
481 /// pointer to a ClassTemplateDecl. For member
482 /// classes of class template specializations, this will be the
483 /// MemberSpecializationInfo referring to the member class that was
484 /// instantiated or specialized.
485 llvm::PointerUnion<ClassTemplateDecl *, MemberSpecializationInfo *>
486 TemplateOrInstantiation;
487
488 /// Called from setBases and addedMember to notify the class that a
489 /// direct or virtual base class or a member of class type has been added.
490 void addedClassSubobject(CXXRecordDecl *Base);
491
492 /// Notify the class that member has been added.
493 ///
494 /// This routine helps maintain information about the class based on which
495 /// members have been added. It will be invoked by DeclContext::addDecl()
496 /// whenever a member is added to this record.
497 void addedMember(Decl *D);
498
499 void markedVirtualFunctionPure();
500
501 /// Get the head of our list of friend declarations, possibly
502 /// deserializing the friends from an external AST source.
503 FriendDecl *getFirstFriend() const;
504
505 /// Determine whether this class has an empty base class subobject of type X
506 /// or of one of the types that might be at offset 0 within X (per the C++
507 /// "standard layout" rules).
508 bool hasSubobjectAtOffsetZeroOfEmptyBaseType(ASTContext &Ctx,
509 const CXXRecordDecl *X);
510
511protected:
512 CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, DeclContext *DC,
513 SourceLocation StartLoc, SourceLocation IdLoc,
514 IdentifierInfo *Id, CXXRecordDecl *PrevDecl);
515
516public:
517 /// Iterator that traverses the base classes of a class.
519
520 /// Iterator that traverses the base classes of a class.
522
524 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
525 }
526
528 return const_cast<CXXRecordDecl*>(this)->getCanonicalDecl();
529 }
530
532 return cast_or_null<CXXRecordDecl>(
533 static_cast<RecordDecl *>(this)->getPreviousDecl());
534 }
535
537 return const_cast<CXXRecordDecl*>(this)->getPreviousDecl();
538 }
539
541 return cast<CXXRecordDecl>(
542 static_cast<RecordDecl *>(this)->getMostRecentDecl());
543 }
544
546 return const_cast<CXXRecordDecl*>(this)->getMostRecentDecl();
547 }
548
550 CXXRecordDecl *Recent =
551 static_cast<CXXRecordDecl *>(this)->getMostRecentDecl();
552 while (Recent->isInjectedClassName()) {
553 // FIXME: Does injected class name need to be in the redeclarations chain?
554 assert(Recent->getPreviousDecl());
555 Recent = Recent->getPreviousDecl();
556 }
557 return Recent;
558 }
559
561 return const_cast<CXXRecordDecl*>(this)->getMostRecentNonInjectedDecl();
562 }
563
565 // We only need an update if we don't already know which
566 // declaration is the definition.
567 auto *DD = DefinitionData ? DefinitionData : dataPtr();
568 return DD ? DD->Definition : nullptr;
569 }
570
571 bool hasDefinition() const { return DefinitionData || dataPtr(); }
572
573 static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
574 SourceLocation StartLoc, SourceLocation IdLoc,
576 CXXRecordDecl *PrevDecl = nullptr,
577 bool DelayTypeCreation = false);
580 unsigned DependencyKind, bool IsGeneric,
581 LambdaCaptureDefault CaptureDefault);
584
585 bool isDynamicClass() const {
586 return data().Polymorphic || data().NumVBases != 0;
587 }
588
589 /// @returns true if class is dynamic or might be dynamic because the
590 /// definition is incomplete of dependent.
591 bool mayBeDynamicClass() const {
593 }
594
595 /// @returns true if class is non dynamic or might be non dynamic because the
596 /// definition is incomplete of dependent.
597 bool mayBeNonDynamicClass() const {
599 }
600
601 void setIsParsingBaseSpecifiers() { data().IsParsingBaseSpecifiers = true; }
602
604 return data().IsParsingBaseSpecifiers;
605 }
606
607 unsigned getODRHash() const;
608
609 /// Sets the base classes of this struct or class.
610 void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
611
612 /// Retrieves the number of base classes of this class.
613 unsigned getNumBases() const { return data().NumBases; }
614
615 using base_class_range = llvm::iterator_range<base_class_iterator>;
617 llvm::iterator_range<base_class_const_iterator>;
618
621 }
624 }
625
626 base_class_iterator bases_begin() { return data().getBases(); }
627 base_class_const_iterator bases_begin() const { return data().getBases(); }
628 base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
630 return bases_begin() + data().NumBases;
631 }
632
633 /// Retrieves the number of virtual base classes of this class.
634 unsigned getNumVBases() const { return data().NumVBases; }
635
638 }
641 }
642
643 base_class_iterator vbases_begin() { return data().getVBases(); }
644 base_class_const_iterator vbases_begin() const { return data().getVBases(); }
645 base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
647 return vbases_begin() + data().NumVBases;
648 }
649
650 /// Determine whether this class has any dependent base classes which
651 /// are not the current instantiation.
652 bool hasAnyDependentBases() const;
653
654 /// Iterator access to method members. The method iterator visits
655 /// all method members of the class, including non-instance methods,
656 /// special methods, etc.
659 llvm::iterator_range<specific_decl_iterator<CXXMethodDecl>>;
660
663 }
664
665 /// Method begin iterator. Iterates in the order the methods
666 /// were declared.
669 }
670
671 /// Method past-the-end iterator.
673 return method_iterator(decls_end());
674 }
675
676 /// Iterator access to constructor members.
679 llvm::iterator_range<specific_decl_iterator<CXXConstructorDecl>>;
680
682
684 return ctor_iterator(decls_begin());
685 }
686
688 return ctor_iterator(decls_end());
689 }
690
691 /// An iterator over friend declarations. All of these are defined
692 /// in DeclFriend.h.
693 class friend_iterator;
694 using friend_range = llvm::iterator_range<friend_iterator>;
695
696 friend_range friends() const;
699 void pushFriendDecl(FriendDecl *FD);
700
701 /// Determines whether this record has any friends.
702 bool hasFriends() const {
703 return data().FirstFriend.isValid();
704 }
705
706 /// \c true if a defaulted copy constructor for this class would be
707 /// deleted.
710 (data().DeclaredSpecialMembers & SMF_CopyConstructor)) &&
711 "this property has not yet been computed by Sema");
712 return data().DefaultedCopyConstructorIsDeleted;
713 }
714
715 /// \c true if a defaulted move constructor for this class would be
716 /// deleted.
719 (data().DeclaredSpecialMembers & SMF_MoveConstructor)) &&
720 "this property has not yet been computed by Sema");
721 return data().DefaultedMoveConstructorIsDeleted;
722 }
723
724 /// \c true if a defaulted destructor for this class would be deleted.
727 (data().DeclaredSpecialMembers & SMF_Destructor)) &&
728 "this property has not yet been computed by Sema");
729 return data().DefaultedDestructorIsDeleted;
730 }
731
732 /// \c true if we know for sure that this class has a single,
733 /// accessible, unambiguous copy constructor that is not deleted.
736 !data().DefaultedCopyConstructorIsDeleted;
737 }
738
739 /// \c true if we know for sure that this class has a single,
740 /// accessible, unambiguous move constructor that is not deleted.
743 !data().DefaultedMoveConstructorIsDeleted;
744 }
745
746 /// \c true if we know for sure that this class has a single,
747 /// accessible, unambiguous copy assignment operator that is not deleted.
750 !data().DefaultedCopyAssignmentIsDeleted;
751 }
752
753 /// \c true if we know for sure that this class has a single,
754 /// accessible, unambiguous move assignment operator that is not deleted.
757 !data().DefaultedMoveAssignmentIsDeleted;
758 }
759
760 /// \c true if we know for sure that this class has an accessible
761 /// destructor that is not deleted.
762 bool hasSimpleDestructor() const {
763 return !hasUserDeclaredDestructor() &&
764 !data().DefaultedDestructorIsDeleted;
765 }
766
767 /// Determine whether this class has any default constructors.
769 return (data().DeclaredSpecialMembers & SMF_DefaultConstructor) ||
771 }
772
773 /// Determine if we need to declare a default constructor for
774 /// this class.
775 ///
776 /// This value is used for lazy creation of default constructors.
778 return (!data().UserDeclaredConstructor &&
779 !(data().DeclaredSpecialMembers & SMF_DefaultConstructor) &&
781 // FIXME: Proposed fix to core wording issue: if a class inherits
782 // a default constructor and doesn't explicitly declare one, one
783 // is declared implicitly.
784 (data().HasInheritedDefaultConstructor &&
785 !(data().DeclaredSpecialMembers & SMF_DefaultConstructor));
786 }
787
788 /// Determine whether this class has any user-declared constructors.
789 ///
790 /// When true, a default constructor will not be implicitly declared.
792 return data().UserDeclaredConstructor;
793 }
794
795 /// Whether this class has a user-provided default constructor
796 /// per C++11.
798 return data().UserProvidedDefaultConstructor;
799 }
800
801 /// Determine whether this class has a user-declared copy constructor.
802 ///
803 /// When false, a copy constructor will be implicitly declared.
805 return data().UserDeclaredSpecialMembers & SMF_CopyConstructor;
806 }
807
808 /// Determine whether this class needs an implicit copy
809 /// constructor to be lazily declared.
811 return !(data().DeclaredSpecialMembers & SMF_CopyConstructor);
812 }
813
814 /// Determine whether we need to eagerly declare a defaulted copy
815 /// constructor for this class.
817 // C++17 [class.copy.ctor]p6:
818 // If the class definition declares a move constructor or move assignment
819 // operator, the implicitly declared copy constructor is defined as
820 // deleted.
821 // In MSVC mode, sometimes a declared move assignment does not delete an
822 // implicit copy constructor, so defer this choice to Sema.
823 if (data().UserDeclaredSpecialMembers &
824 (SMF_MoveConstructor | SMF_MoveAssignment))
825 return true;
826 return data().NeedOverloadResolutionForCopyConstructor;
827 }
828
829 /// Determine whether an implicit copy constructor for this type
830 /// would have a parameter with a const-qualified reference type.
832 return data().ImplicitCopyConstructorCanHaveConstParamForNonVBase &&
833 (isAbstract() ||
834 data().ImplicitCopyConstructorCanHaveConstParamForVBase);
835 }
836
837 /// Determine whether this class has a copy constructor with
838 /// a parameter type which is a reference to a const-qualified type.
840 return data().HasDeclaredCopyConstructorWithConstParam ||
843 }
844
845 /// Whether this class has a user-declared move constructor or
846 /// assignment operator.
847 ///
848 /// When false, a move constructor and assignment operator may be
849 /// implicitly declared.
851 return data().UserDeclaredSpecialMembers &
852 (SMF_MoveConstructor | SMF_MoveAssignment);
853 }
854
855 /// Determine whether this class has had a move constructor
856 /// declared by the user.
858 return data().UserDeclaredSpecialMembers & SMF_MoveConstructor;
859 }
860
861 /// Determine whether this class has a move constructor.
862 bool hasMoveConstructor() const {
863 return (data().DeclaredSpecialMembers & SMF_MoveConstructor) ||
865 }
866
867 /// Set that we attempted to declare an implicit copy
868 /// constructor, but overload resolution failed so we deleted it.
870 assert((data().DefaultedCopyConstructorIsDeleted ||
872 "Copy constructor should not be deleted");
873 data().DefaultedCopyConstructorIsDeleted = true;
874 }
875
876 /// Set that we attempted to declare an implicit move
877 /// constructor, but overload resolution failed so we deleted it.
879 assert((data().DefaultedMoveConstructorIsDeleted ||
881 "move constructor should not be deleted");
882 data().DefaultedMoveConstructorIsDeleted = true;
883 }
884
885 /// Set that we attempted to declare an implicit destructor,
886 /// but overload resolution failed so we deleted it.
888 assert((data().DefaultedDestructorIsDeleted ||
890 "destructor should not be deleted");
891 data().DefaultedDestructorIsDeleted = true;
892 }
893
894 /// Determine whether this class should get an implicit move
895 /// constructor or if any existing special member function inhibits this.
897 return !(data().DeclaredSpecialMembers & SMF_MoveConstructor) &&
902 }
903
904 /// Determine whether we need to eagerly declare a defaulted move
905 /// constructor for this class.
907 return data().NeedOverloadResolutionForMoveConstructor;
908 }
909
910 /// Determine whether this class has a user-declared copy assignment
911 /// operator.
912 ///
913 /// When false, a copy assignment operator will be implicitly declared.
915 return data().UserDeclaredSpecialMembers & SMF_CopyAssignment;
916 }
917
918 /// Set that we attempted to declare an implicit copy assignment
919 /// operator, but overload resolution failed so we deleted it.
921 assert((data().DefaultedCopyAssignmentIsDeleted ||
923 "copy assignment should not be deleted");
924 data().DefaultedCopyAssignmentIsDeleted = true;
925 }
926
927 /// Determine whether this class needs an implicit copy
928 /// assignment operator to be lazily declared.
930 return !(data().DeclaredSpecialMembers & SMF_CopyAssignment);
931 }
932
933 /// Determine whether we need to eagerly declare a defaulted copy
934 /// assignment operator for this class.
936 // C++20 [class.copy.assign]p2:
937 // If the class definition declares a move constructor or move assignment
938 // operator, the implicitly declared copy assignment operator is defined
939 // as deleted.
940 // In MSVC mode, sometimes a declared move constructor does not delete an
941 // implicit copy assignment, so defer this choice to Sema.
942 if (data().UserDeclaredSpecialMembers &
943 (SMF_MoveConstructor | SMF_MoveAssignment))
944 return true;
945 return data().NeedOverloadResolutionForCopyAssignment;
946 }
947
948 /// Determine whether an implicit copy assignment operator for this
949 /// type would have a parameter with a const-qualified reference type.
951 return data().ImplicitCopyAssignmentHasConstParam;
952 }
953
954 /// Determine whether this class has a copy assignment operator with
955 /// a parameter type which is a reference to a const-qualified type or is not
956 /// a reference.
958 return data().HasDeclaredCopyAssignmentWithConstParam ||
961 }
962
963 /// Determine whether this class has had a move assignment
964 /// declared by the user.
966 return data().UserDeclaredSpecialMembers & SMF_MoveAssignment;
967 }
968
969 /// Determine whether this class has a move assignment operator.
970 bool hasMoveAssignment() const {
971 return (data().DeclaredSpecialMembers & SMF_MoveAssignment) ||
973 }
974
975 /// Set that we attempted to declare an implicit move assignment
976 /// operator, but overload resolution failed so we deleted it.
978 assert((data().DefaultedMoveAssignmentIsDeleted ||
980 "move assignment should not be deleted");
981 data().DefaultedMoveAssignmentIsDeleted = true;
982 }
983
984 /// Determine whether this class should get an implicit move
985 /// assignment operator or if any existing special member function inhibits
986 /// this.
988 return !(data().DeclaredSpecialMembers & SMF_MoveAssignment) &&
994 }
995
996 /// Determine whether we need to eagerly declare a move assignment
997 /// operator for this class.
999 return data().NeedOverloadResolutionForMoveAssignment;
1000 }
1001
1002 /// Determine whether this class has a user-declared destructor.
1003 ///
1004 /// When false, a destructor will be implicitly declared.
1006 return data().UserDeclaredSpecialMembers & SMF_Destructor;
1007 }
1008
1009 /// Determine whether this class needs an implicit destructor to
1010 /// be lazily declared.
1012 return !(data().DeclaredSpecialMembers & SMF_Destructor);
1013 }
1014
1015 /// Determine whether we need to eagerly declare a destructor for this
1016 /// class.
1018 return data().NeedOverloadResolutionForDestructor;
1019 }
1020
1021 /// Determine whether this class describes a lambda function object.
1022 bool isLambda() const {
1023 // An update record can't turn a non-lambda into a lambda.
1024 auto *DD = DefinitionData;
1025 return DD && DD->IsLambda;
1026 }
1027
1028 /// Determine whether this class describes a generic
1029 /// lambda function object (i.e. function call operator is
1030 /// a template).
1031 bool isGenericLambda() const;
1032
1033 /// Determine whether this lambda should have an implicit default constructor
1034 /// and copy and move assignment operators.
1036
1037 /// Retrieve the lambda call operator of the closure type
1038 /// if this is a closure type.
1040
1041 /// Retrieve the dependent lambda call operator of the closure type
1042 /// if this is a templated closure type.
1044
1045 /// Retrieve the lambda static invoker, the address of which
1046 /// is returned by the conversion operator, and the body of which
1047 /// is forwarded to the lambda call operator. The version that does not
1048 /// take a calling convention uses the 'default' calling convention for free
1049 /// functions if the Lambda's calling convention was not modified via
1050 /// attribute. Otherwise, it will return the calling convention specified for
1051 /// the lambda.
1054
1055 /// Retrieve the generic lambda's template parameter list.
1056 /// Returns null if the class does not represent a lambda or a generic
1057 /// lambda.
1059
1060 /// Retrieve the lambda template parameters that were specified explicitly.
1062
1064 assert(isLambda());
1065 return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault);
1066 }
1067
1068 bool isCapturelessLambda() const {
1069 if (!isLambda())
1070 return false;
1071 return getLambdaCaptureDefault() == LCD_None && capture_size() == 0;
1072 }
1073
1074 /// Set the captures for this lambda closure type.
1075 void setCaptures(ASTContext &Context, ArrayRef<LambdaCapture> Captures);
1076
1077 /// For a closure type, retrieve the mapping from captured
1078 /// variables and \c this to the non-static data members that store the
1079 /// values or references of the captures.
1080 ///
1081 /// \param Captures Will be populated with the mapping from captured
1082 /// variables to the corresponding fields.
1083 ///
1084 /// \param ThisCapture Will be set to the field declaration for the
1085 /// \c this capture.
1086 ///
1087 /// \note No entries will be added for init-captures, as they do not capture
1088 /// variables.
1089 ///
1090 /// \note If multiple versions of the lambda are merged together, they may
1091 /// have different variable declarations corresponding to the same capture.
1092 /// In that case, all of those variable declarations will be added to the
1093 /// Captures list, so it may have more than one variable listed per field.
1094 void
1095 getCaptureFields(llvm::DenseMap<const ValueDecl *, FieldDecl *> &Captures,
1096 FieldDecl *&ThisCapture) const;
1097
1099 using capture_const_range = llvm::iterator_range<capture_const_iterator>;
1100
1103 }
1104
1106 if (!isLambda()) return nullptr;
1107 LambdaDefinitionData &LambdaData = getLambdaData();
1108 return LambdaData.Captures.empty() ? nullptr : LambdaData.Captures.front();
1109 }
1110
1112 return isLambda() ? captures_begin() + getLambdaData().NumCaptures
1113 : nullptr;
1114 }
1115
1116 unsigned capture_size() const { return getLambdaData().NumCaptures; }
1117
1118 const LambdaCapture *getCapture(unsigned I) const {
1119 assert(isLambda() && I < capture_size() && "invalid index for capture");
1120 return captures_begin() + I;
1121 }
1122
1124
1126 return data().Conversions.get(getASTContext()).begin();
1127 }
1128
1130 return data().Conversions.get(getASTContext()).end();
1131 }
1132
1133 /// Removes a conversion function from this class. The conversion
1134 /// function must currently be a member of this class. Furthermore,
1135 /// this class must currently be in the process of being defined.
1136 void removeConversion(const NamedDecl *Old);
1137
1138 /// Get all conversion functions visible in current class,
1139 /// including conversion function templates.
1140 llvm::iterator_range<conversion_iterator>
1142
1143 /// Determine whether this class is an aggregate (C++ [dcl.init.aggr]),
1144 /// which is a class with no user-declared constructors, no private
1145 /// or protected non-static data members, no base classes, and no virtual
1146 /// functions (C++ [dcl.init.aggr]p1).
1147 bool isAggregate() const { return data().Aggregate; }
1148
1149 /// Whether this class has any in-class initializers
1150 /// for non-static data members (including those in anonymous unions or
1151 /// structs).
1152 bool hasInClassInitializer() const { return data().HasInClassInitializer; }
1153
1154 /// Whether this class or any of its subobjects has any members of
1155 /// reference type which would make value-initialization ill-formed.
1156 ///
1157 /// Per C++03 [dcl.init]p5:
1158 /// - if T is a non-union class type without a user-declared constructor,
1159 /// then every non-static data member and base-class component of T is
1160 /// value-initialized [...] A program that calls for [...]
1161 /// value-initialization of an entity of reference type is ill-formed.
1163 return !isUnion() && !hasUserDeclaredConstructor() &&
1164 data().HasUninitializedReferenceMember;
1165 }
1166
1167 /// Whether this class is a POD-type (C++ [class]p4)
1168 ///
1169 /// For purposes of this function a class is POD if it is an aggregate
1170 /// that has no non-static non-POD data members, no reference data
1171 /// members, no user-defined copy assignment operator and no
1172 /// user-defined destructor.
1173 ///
1174 /// Note that this is the C++ TR1 definition of POD.
1175 bool isPOD() const { return data().PlainOldData; }
1176
1177 /// True if this class is C-like, without C++-specific features, e.g.
1178 /// it contains only public fields, no bases, tag kind is not 'class', etc.
1179 bool isCLike() const;
1180
1181 /// Determine whether this is an empty class in the sense of
1182 /// (C++11 [meta.unary.prop]).
1183 ///
1184 /// The CXXRecordDecl is a class type, but not a union type,
1185 /// with no non-static data members other than bit-fields of length 0,
1186 /// no virtual member functions, no virtual base classes,
1187 /// and no base class B for which is_empty<B>::value is false.
1188 ///
1189 /// \note This does NOT include a check for union-ness.
1190 bool isEmpty() const { return data().Empty; }
1191
1192 void setInitMethod(bool Val) { data().HasInitMethod = Val; }
1193 bool hasInitMethod() const { return data().HasInitMethod; }
1194
1195 bool hasPrivateFields() const {
1196 return data().HasPrivateFields;
1197 }
1198
1199 bool hasProtectedFields() const {
1200 return data().HasProtectedFields;
1201 }
1202
1203 /// Determine whether this class has direct non-static data members.
1204 bool hasDirectFields() const {
1205 auto &D = data();
1206 return D.HasPublicFields || D.HasProtectedFields || D.HasPrivateFields;
1207 }
1208
1209 /// If this is a standard-layout class or union, any and all data members will
1210 /// be declared in the same type.
1211 ///
1212 /// This retrieves the type where any fields are declared,
1213 /// or the current class if there is no class with fields.
1215
1216 /// Whether this class is polymorphic (C++ [class.virtual]),
1217 /// which means that the class contains or inherits a virtual function.
1218 bool isPolymorphic() const { return data().Polymorphic; }
1219
1220 /// Determine whether this class has a pure virtual function.
1221 ///
1222 /// The class is abstract per (C++ [class.abstract]p2) if it declares
1223 /// a pure virtual function or inherits a pure virtual function that is
1224 /// not overridden.
1225 bool isAbstract() const { return data().Abstract; }
1226
1227 /// Determine whether this class is standard-layout per
1228 /// C++ [class]p7.
1229 bool isStandardLayout() const { return data().IsStandardLayout; }
1230
1231 /// Determine whether this class was standard-layout per
1232 /// C++11 [class]p7, specifically using the C++11 rules without any DRs.
1233 bool isCXX11StandardLayout() const { return data().IsCXX11StandardLayout; }
1234
1235 /// Determine whether this class, or any of its class subobjects,
1236 /// contains a mutable field.
1237 bool hasMutableFields() const { return data().HasMutableFields; }
1238
1239 /// Determine whether this class has any variant members.
1240 bool hasVariantMembers() const { return data().HasVariantMembers; }
1241
1242 /// Determine whether this class has a trivial default constructor
1243 /// (C++11 [class.ctor]p5).
1245 return hasDefaultConstructor() &&
1246 (data().HasTrivialSpecialMembers & SMF_DefaultConstructor);
1247 }
1248
1249 /// Determine whether this class has a non-trivial default constructor
1250 /// (C++11 [class.ctor]p5).
1252 return (data().DeclaredNonTrivialSpecialMembers & SMF_DefaultConstructor) ||
1254 !(data().HasTrivialSpecialMembers & SMF_DefaultConstructor));
1255 }
1256
1257 /// Determine whether this class has at least one constexpr constructor
1258 /// other than the copy or move constructors.
1260 return data().HasConstexprNonCopyMoveConstructor ||
1263 }
1264
1265 /// Determine whether a defaulted default constructor for this class
1266 /// would be constexpr.
1268 return data().DefaultedDefaultConstructorIsConstexpr &&
1270 getLangOpts().CPlusPlus20);
1271 }
1272
1273 /// Determine whether this class has a constexpr default constructor.
1275 return data().HasConstexprDefaultConstructor ||
1278 }
1279
1280 /// Determine whether this class has a trivial copy constructor
1281 /// (C++ [class.copy]p6, C++11 [class.copy]p12)
1283 return data().HasTrivialSpecialMembers & SMF_CopyConstructor;
1284 }
1285
1287 return data().HasTrivialSpecialMembersForCall & SMF_CopyConstructor;
1288 }
1289
1290 /// Determine whether this class has a non-trivial copy constructor
1291 /// (C++ [class.copy]p6, C++11 [class.copy]p12)
1293 return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor ||
1295 }
1296
1298 return (data().DeclaredNonTrivialSpecialMembersForCall &
1299 SMF_CopyConstructor) ||
1301 }
1302
1303 /// Determine whether this class has a trivial move constructor
1304 /// (C++11 [class.copy]p12)
1306 return hasMoveConstructor() &&
1307 (data().HasTrivialSpecialMembers & SMF_MoveConstructor);
1308 }
1309
1311 return hasMoveConstructor() &&
1312 (data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor);
1313 }
1314
1315 /// Determine whether this class has a non-trivial move constructor
1316 /// (C++11 [class.copy]p12)
1318 return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveConstructor) ||
1320 !(data().HasTrivialSpecialMembers & SMF_MoveConstructor));
1321 }
1322
1324 return (data().DeclaredNonTrivialSpecialMembersForCall &
1325 SMF_MoveConstructor) ||
1327 !(data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor));
1328 }
1329
1330 /// Determine whether this class has a trivial copy assignment operator
1331 /// (C++ [class.copy]p11, C++11 [class.copy]p25)
1333 return data().HasTrivialSpecialMembers & SMF_CopyAssignment;
1334 }
1335
1336 /// Determine whether this class has a non-trivial copy assignment
1337 /// operator (C++ [class.copy]p11, C++11 [class.copy]p25)
1339 return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment ||
1341 }
1342
1343 /// Determine whether this class has a trivial move assignment operator
1344 /// (C++11 [class.copy]p25)
1346 return hasMoveAssignment() &&
1347 (data().HasTrivialSpecialMembers & SMF_MoveAssignment);
1348 }
1349
1350 /// Determine whether this class has a non-trivial move assignment
1351 /// operator (C++11 [class.copy]p25)
1353 return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveAssignment) ||
1355 !(data().HasTrivialSpecialMembers & SMF_MoveAssignment));
1356 }
1357
1358 /// Determine whether a defaulted default constructor for this class
1359 /// would be constexpr.
1361 return data().DefaultedDestructorIsConstexpr &&
1362 getLangOpts().CPlusPlus20;
1363 }
1364
1365 /// Determine whether this class has a constexpr destructor.
1366 bool hasConstexprDestructor() const;
1367
1368 /// Determine whether this class has a trivial destructor
1369 /// (C++ [class.dtor]p3)
1371 return data().HasTrivialSpecialMembers & SMF_Destructor;
1372 }
1373
1375 return data().HasTrivialSpecialMembersForCall & SMF_Destructor;
1376 }
1377
1378 /// Determine whether this class has a non-trivial destructor
1379 /// (C++ [class.dtor]p3)
1381 return !(data().HasTrivialSpecialMembers & SMF_Destructor);
1382 }
1383
1385 return !(data().HasTrivialSpecialMembersForCall & SMF_Destructor);
1386 }
1387
1389 data().HasTrivialSpecialMembersForCall =
1390 (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor);
1391 }
1392
1393 /// Determine whether declaring a const variable with this type is ok
1394 /// per core issue 253.
1396 return !data().HasUninitializedFields ||
1397 !(data().HasDefaultedDefaultConstructor ||
1399 }
1400
1401 /// Determine whether this class has a destructor which has no
1402 /// semantic effect.
1403 ///
1404 /// Any such destructor will be trivial, public, defaulted and not deleted,
1405 /// and will call only irrelevant destructors.
1407 return data().HasIrrelevantDestructor;
1408 }
1409
1410 /// Determine whether this class has a non-literal or/ volatile type
1411 /// non-static data member or base class.
1413 return data().HasNonLiteralTypeFieldsOrBases;
1414 }
1415
1416 /// Determine whether this class has a using-declaration that names
1417 /// a user-declared base class constructor.
1419 return data().HasInheritedConstructor;
1420 }
1421
1422 /// Determine whether this class has a using-declaration that names
1423 /// a base class assignment operator.
1425 return data().HasInheritedAssignment;
1426 }
1427
1428 /// Determine whether this class is considered trivially copyable per
1429 /// (C++11 [class]p6).
1430 bool isTriviallyCopyable() const;
1431
1432 /// Determine whether this class is considered trivially copyable per
1433 bool isTriviallyCopyConstructible() const;
1434
1435 /// Determine whether this class is considered trivial.
1436 ///
1437 /// C++11 [class]p6:
1438 /// "A trivial class is a class that has a trivial default constructor and
1439 /// is trivially copyable."
1440 bool isTrivial() const {
1442 }
1443
1444 /// Determine whether this class is a literal type.
1445 ///
1446 /// C++20 [basic.types]p10:
1447 /// A class type that has all the following properties:
1448 /// - it has a constexpr destructor
1449 /// - all of its non-static non-variant data members and base classes
1450 /// are of non-volatile literal types, and it:
1451 /// - is a closure type
1452 /// - is an aggregate union type that has either no variant members
1453 /// or at least one variant member of non-volatile literal type
1454 /// - is a non-union aggregate type for which each of its anonymous
1455 /// union members satisfies the above requirements for an aggregate
1456 /// union type, or
1457 /// - has at least one constexpr constructor or constructor template
1458 /// that is not a copy or move constructor.
1459 bool isLiteral() const;
1460
1461 /// Determine whether this is a structural type.
1462 bool isStructural() const {
1463 return isLiteral() && data().StructuralIfLiteral;
1464 }
1465
1466 /// Notify the class that this destructor is now selected.
1467 ///
1468 /// Important properties of the class depend on destructor properties. Since
1469 /// C++20, it is possible to have multiple destructor declarations in a class
1470 /// out of which one will be selected at the end.
1471 /// This is called separately from addedMember because it has to be deferred
1472 /// to the completion of the class.
1474
1475 /// Notify the class that an eligible SMF has been added.
1476 /// This updates triviality and destructor based properties of the class accordingly.
1477 void addedEligibleSpecialMemberFunction(const CXXMethodDecl *MD, unsigned SMKind);
1478
1479 /// If this record is an instantiation of a member class,
1480 /// retrieves the member class from which it was instantiated.
1481 ///
1482 /// This routine will return non-null for (non-templated) member
1483 /// classes of class templates. For example, given:
1484 ///
1485 /// \code
1486 /// template<typename T>
1487 /// struct X {
1488 /// struct A { };
1489 /// };
1490 /// \endcode
1491 ///
1492 /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl
1493 /// whose parent is the class template specialization X<int>. For
1494 /// this declaration, getInstantiatedFromMemberClass() will return
1495 /// the CXXRecordDecl X<T>::A. When a complete definition of
1496 /// X<int>::A is required, it will be instantiated from the
1497 /// declaration returned by getInstantiatedFromMemberClass().
1499
1500 /// If this class is an instantiation of a member class of a
1501 /// class template specialization, retrieves the member specialization
1502 /// information.
1504
1505 /// Specify that this record is an instantiation of the
1506 /// member class \p RD.
1509
1510 /// Retrieves the class template that is described by this
1511 /// class declaration.
1512 ///
1513 /// Every class template is represented as a ClassTemplateDecl and a
1514 /// CXXRecordDecl. The former contains template properties (such as
1515 /// the template parameter lists) while the latter contains the
1516 /// actual description of the template's
1517 /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the
1518 /// CXXRecordDecl that from a ClassTemplateDecl, while
1519 /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
1520 /// a CXXRecordDecl.
1522
1524
1525 /// Determine whether this particular class is a specialization or
1526 /// instantiation of a class template or member class of a class template,
1527 /// and how it was instantiated or specialized.
1529
1530 /// Set the kind of specialization or template instantiation this is.
1532
1533 /// Retrieve the record declaration from which this record could be
1534 /// instantiated. Returns null if this class is not a template instantiation.
1536
1538 return const_cast<CXXRecordDecl *>(const_cast<const CXXRecordDecl *>(this)
1540 }
1541
1542 /// Returns the destructor decl for this class.
1544
1545 /// Returns true if the class destructor, or any implicitly invoked
1546 /// destructors are marked noreturn.
1547 bool isAnyDestructorNoReturn() const { return data().IsAnyDestructorNoReturn; }
1548
1549 /// If the class is a local class [class.local], returns
1550 /// the enclosing function declaration.
1552 if (const auto *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
1553 return RD->isLocalClass();
1554
1555 return dyn_cast<FunctionDecl>(getDeclContext());
1556 }
1557
1559 return const_cast<FunctionDecl*>(
1560 const_cast<const CXXRecordDecl*>(this)->isLocalClass());
1561 }
1562
1563 /// Determine whether this dependent class is a current instantiation,
1564 /// when viewed from within the given context.
1565 bool isCurrentInstantiation(const DeclContext *CurContext) const;
1566
1567 /// Determine whether this class is derived from the class \p Base.
1568 ///
1569 /// This routine only determines whether this class is derived from \p Base,
1570 /// but does not account for factors that may make a Derived -> Base class
1571 /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1572 /// base class subobjects.
1573 ///
1574 /// \param Base the base class we are searching for.
1575 ///
1576 /// \returns true if this class is derived from Base, false otherwise.
1577 bool isDerivedFrom(const CXXRecordDecl *Base) const;
1578
1579 /// Determine whether this class is derived from the type \p Base.
1580 ///
1581 /// This routine only determines whether this class is derived from \p Base,
1582 /// but does not account for factors that may make a Derived -> Base class
1583 /// ill-formed, such as private/protected inheritance or multiple, ambiguous
1584 /// base class subobjects.
1585 ///
1586 /// \param Base the base class we are searching for.
1587 ///
1588 /// \param Paths will contain the paths taken from the current class to the
1589 /// given \p Base class.
1590 ///
1591 /// \returns true if this class is derived from \p Base, false otherwise.
1592 ///
1593 /// \todo add a separate parameter to configure IsDerivedFrom, rather than
1594 /// tangling input and output in \p Paths
1595 bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const;
1596
1597 /// Determine whether this class is virtually derived from
1598 /// the class \p Base.
1599 ///
1600 /// This routine only determines whether this class is virtually
1601 /// derived from \p Base, but does not account for factors that may
1602 /// make a Derived -> Base class ill-formed, such as
1603 /// private/protected inheritance or multiple, ambiguous base class
1604 /// subobjects.
1605 ///
1606 /// \param Base the base class we are searching for.
1607 ///
1608 /// \returns true if this class is virtually derived from Base,
1609 /// false otherwise.
1610 bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const;
1611
1612 /// Determine whether this class is provably not derived from
1613 /// the type \p Base.
1614 bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
1615
1616 /// Function type used by forallBases() as a callback.
1617 ///
1618 /// \param BaseDefinition the definition of the base class
1619 ///
1620 /// \returns true if this base matched the search criteria
1622 llvm::function_ref<bool(const CXXRecordDecl *BaseDefinition)>;
1623
1624 /// Determines if the given callback holds for all the direct
1625 /// or indirect base classes of this type.
1626 ///
1627 /// The class itself does not count as a base class. This routine
1628 /// returns false if the class has non-computable base classes.
1629 ///
1630 /// \param BaseMatches Callback invoked for each (direct or indirect) base
1631 /// class of this type until a call returns false.
1632 bool forallBases(ForallBasesCallback BaseMatches) const;
1633
1634 /// Function type used by lookupInBases() to determine whether a
1635 /// specific base class subobject matches the lookup criteria.
1636 ///
1637 /// \param Specifier the base-class specifier that describes the inheritance
1638 /// from the base class we are trying to match.
1639 ///
1640 /// \param Path the current path, from the most-derived class down to the
1641 /// base named by the \p Specifier.
1642 ///
1643 /// \returns true if this base matched the search criteria, false otherwise.
1645 llvm::function_ref<bool(const CXXBaseSpecifier *Specifier,
1646 CXXBasePath &Path)>;
1647
1648 /// Look for entities within the base classes of this C++ class,
1649 /// transitively searching all base class subobjects.
1650 ///
1651 /// This routine uses the callback function \p BaseMatches to find base
1652 /// classes meeting some search criteria, walking all base class subobjects
1653 /// and populating the given \p Paths structure with the paths through the
1654 /// inheritance hierarchy that resulted in a match. On a successful search,
1655 /// the \p Paths structure can be queried to retrieve the matching paths and
1656 /// to determine if there were any ambiguities.
1657 ///
1658 /// \param BaseMatches callback function used to determine whether a given
1659 /// base matches the user-defined search criteria.
1660 ///
1661 /// \param Paths used to record the paths from this class to its base class
1662 /// subobjects that match the search criteria.
1663 ///
1664 /// \param LookupInDependent can be set to true to extend the search to
1665 /// dependent base classes.
1666 ///
1667 /// \returns true if there exists any path from this class to a base class
1668 /// subobject that matches the search criteria.
1669 bool lookupInBases(BaseMatchesCallback BaseMatches, CXXBasePaths &Paths,
1670 bool LookupInDependent = false) const;
1671
1672 /// Base-class lookup callback that determines whether the given
1673 /// base class specifier refers to a specific class declaration.
1674 ///
1675 /// This callback can be used with \c lookupInBases() to determine whether
1676 /// a given derived class has is a base class subobject of a particular type.
1677 /// The base record pointer should refer to the canonical CXXRecordDecl of the
1678 /// base class that we are searching for.
1679 static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
1680 CXXBasePath &Path, const CXXRecordDecl *BaseRecord);
1681
1682 /// Base-class lookup callback that determines whether the
1683 /// given base class specifier refers to a specific class
1684 /// declaration and describes virtual derivation.
1685 ///
1686 /// This callback can be used with \c lookupInBases() to determine
1687 /// whether a given derived class has is a virtual base class
1688 /// subobject of a particular type. The base record pointer should
1689 /// refer to the canonical CXXRecordDecl of the base class that we
1690 /// are searching for.
1693 const CXXRecordDecl *BaseRecord);
1694
1695 /// Retrieve the final overriders for each virtual member
1696 /// function in the class hierarchy where this class is the
1697 /// most-derived class in the class hierarchy.
1698 void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
1699
1700 /// Get the indirect primary bases for this class.
1702
1703 /// Determine whether this class has a member with the given name, possibly
1704 /// in a non-dependent base class.
1705 ///
1706 /// No check for ambiguity is performed, so this should never be used when
1707 /// implementing language semantics, but it may be appropriate for warnings,
1708 /// static analysis, or similar.
1709 bool hasMemberName(DeclarationName N) const;
1710
1711 /// Performs an imprecise lookup of a dependent name in this class.
1712 ///
1713 /// This function does not follow strict semantic rules and should be used
1714 /// only when lookup rules can be relaxed, e.g. indexing.
1715 std::vector<const NamedDecl *>
1717 llvm::function_ref<bool(const NamedDecl *ND)> Filter);
1718
1719 /// Renders and displays an inheritance diagram
1720 /// for this C++ class and all of its base classes (transitively) using
1721 /// GraphViz.
1722 void viewInheritance(ASTContext& Context) const;
1723
1724 /// Calculates the access of a decl that is reached
1725 /// along a path.
1727 AccessSpecifier DeclAccess) {
1728 assert(DeclAccess != AS_none);
1729 if (DeclAccess == AS_private) return AS_none;
1730 return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
1731 }
1732
1733 /// Indicates that the declaration of a defaulted or deleted special
1734 /// member function is now complete.
1736
1738
1739 /// Indicates that the definition of this class is now complete.
1740 void completeDefinition() override;
1741
1742 /// Indicates that the definition of this class is now complete,
1743 /// and provides a final overrider map to help determine
1744 ///
1745 /// \param FinalOverriders The final overrider map for this class, which can
1746 /// be provided as an optimization for abstract-class checking. If NULL,
1747 /// final overriders will be computed if they are needed to complete the
1748 /// definition.
1749 void completeDefinition(CXXFinalOverriderMap *FinalOverriders);
1750
1751 /// Determine whether this class may end up being abstract, even though
1752 /// it is not yet known to be abstract.
1753 ///
1754 /// \returns true if this class is not known to be abstract but has any
1755 /// base classes that are abstract. In this case, \c completeDefinition()
1756 /// will need to compute final overriders to determine whether the class is
1757 /// actually abstract.
1758 bool mayBeAbstract() const;
1759
1760 /// Determine whether it's impossible for a class to be derived from this
1761 /// class. This is best-effort, and may conservatively return false.
1762 bool isEffectivelyFinal() const;
1763
1764 /// If this is the closure type of a lambda expression, retrieve the
1765 /// number to be used for name mangling in the Itanium C++ ABI.
1766 ///
1767 /// Zero indicates that this closure type has internal linkage, so the
1768 /// mangling number does not matter, while a non-zero value indicates which
1769 /// lambda expression this is in this particular context.
1770 unsigned getLambdaManglingNumber() const {
1771 assert(isLambda() && "Not a lambda closure type!");
1772 return getLambdaData().ManglingNumber;
1773 }
1774
1775 /// The lambda is known to has internal linkage no matter whether it has name
1776 /// mangling number.
1778 assert(isLambda() && "Not a lambda closure type!");
1779 return getLambdaData().HasKnownInternalLinkage;
1780 }
1781
1782 /// Retrieve the declaration that provides additional context for a
1783 /// lambda, when the normal declaration context is not specific enough.
1784 ///
1785 /// Certain contexts (default arguments of in-class function parameters and
1786 /// the initializers of data members) have separate name mangling rules for
1787 /// lambdas within the Itanium C++ ABI. For these cases, this routine provides
1788 /// the declaration in which the lambda occurs, e.g., the function parameter
1789 /// or the non-static data member. Otherwise, it returns NULL to imply that
1790 /// the declaration context suffices.
1791 Decl *getLambdaContextDecl() const;
1792
1793 /// Retrieve the index of this lambda within the context declaration returned
1794 /// by getLambdaContextDecl().
1795 unsigned getLambdaIndexInContext() const {
1796 assert(isLambda() && "Not a lambda closure type!");
1797 return getLambdaData().IndexInContext;
1798 }
1799
1800 /// Information about how a lambda is numbered within its context.
1802 Decl *ContextDecl = nullptr;
1803 unsigned IndexInContext = 0;
1804 unsigned ManglingNumber = 0;
1807 };
1808
1809 /// Set the mangling numbers and context declaration for a lambda class.
1810 void setLambdaNumbering(LambdaNumbering Numbering);
1811
1812 // Get the mangling numbers and context declaration for a lambda class.
1817 }
1818
1819 /// Retrieve the device side mangling number.
1820 unsigned getDeviceLambdaManglingNumber() const;
1821
1822 /// Returns the inheritance model used for this record.
1824
1825 /// Calculate what the inheritance model would be for this class.
1827
1828 /// In the Microsoft C++ ABI, use zero for the field offset of a null data
1829 /// member pointer if we can guarantee that zero is not a valid field offset,
1830 /// or if the member pointer has multiple fields. Polymorphic classes have a
1831 /// vfptr at offset zero, so we can use zero for null. If there are multiple
1832 /// fields, we can use zero even if it is a valid field offset because
1833 /// null-ness testing will check the other fields.
1834 bool nullFieldOffsetIsZero() const;
1835
1836 /// Controls when vtordisps will be emitted if this record is used as a
1837 /// virtual base.
1839
1840 /// Determine whether this lambda expression was known to be dependent
1841 /// at the time it was created, even if its context does not appear to be
1842 /// dependent.
1843 ///
1844 /// This flag is a workaround for an issue with parsing, where default
1845 /// arguments are parsed before their enclosing function declarations have
1846 /// been created. This means that any lambda expressions within those
1847 /// default arguments will have as their DeclContext the context enclosing
1848 /// the function declaration, which may be non-dependent even when the
1849 /// function declaration itself is dependent. This flag indicates when we
1850 /// know that the lambda is dependent despite that.
1851 bool isDependentLambda() const {
1852 return isLambda() && getLambdaData().DependencyKind == LDK_AlwaysDependent;
1853 }
1854
1856 return isLambda() && getLambdaData().DependencyKind == LDK_NeverDependent;
1857 }
1858
1859 unsigned getLambdaDependencyKind() const {
1860 if (!isLambda())
1861 return LDK_Unknown;
1862 return getLambdaData().DependencyKind;
1863 }
1864
1866 return getLambdaData().MethodTyInfo;
1867 }
1868
1870 assert(DefinitionData && DefinitionData->IsLambda &&
1871 "setting lambda property of non-lambda class");
1872 auto &DL = static_cast<LambdaDefinitionData &>(*DefinitionData);
1873 DL.MethodTyInfo = TS;
1874 }
1875
1877 getLambdaData().DependencyKind = Kind;
1878 }
1879
1880 void setLambdaIsGeneric(bool IsGeneric) {
1881 assert(DefinitionData && DefinitionData->IsLambda &&
1882 "setting lambda property of non-lambda class");
1883 auto &DL = static_cast<LambdaDefinitionData &>(*DefinitionData);
1884 DL.IsGenericLambda = IsGeneric;
1885 }
1886
1887 // Determine whether this type is an Interface Like type for
1888 // __interface inheritance purposes.
1889 bool isInterfaceLike() const;
1890
1891 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1892 static bool classofKind(Kind K) {
1893 return K >= firstCXXRecord && K <= lastCXXRecord;
1894 }
1895 void markAbstract() { data().Abstract = true; }
1896};
1897
1898/// Store information needed for an explicit specifier.
1899/// Used by CXXDeductionGuideDecl, CXXConstructorDecl and CXXConversionDecl.
1901 llvm::PointerIntPair<Expr *, 2, ExplicitSpecKind> ExplicitSpec{
1903
1904public:
1907 : ExplicitSpec(Expression, Kind) {}
1908 ExplicitSpecKind getKind() const { return ExplicitSpec.getInt(); }
1909 const Expr *getExpr() const { return ExplicitSpec.getPointer(); }
1910 Expr *getExpr() { return ExplicitSpec.getPointer(); }
1911
1912 /// Determine if the declaration had an explicit specifier of any kind.
1913 bool isSpecified() const {
1914 return ExplicitSpec.getInt() != ExplicitSpecKind::ResolvedFalse ||
1915 ExplicitSpec.getPointer();
1916 }
1917
1918 /// Check for equivalence of explicit specifiers.
1919 /// \return true if the explicit specifier are equivalent, false otherwise.
1920 bool isEquivalent(const ExplicitSpecifier Other) const;
1921 /// Determine whether this specifier is known to correspond to an explicit
1922 /// declaration. Returns false if the specifier is absent or has an
1923 /// expression that is value-dependent or evaluates to false.
1924 bool isExplicit() const {
1925 return ExplicitSpec.getInt() == ExplicitSpecKind::ResolvedTrue;
1926 }
1927 /// Determine if the explicit specifier is invalid.
1928 /// This state occurs after a substitution failures.
1929 bool isInvalid() const {
1930 return ExplicitSpec.getInt() == ExplicitSpecKind::Unresolved &&
1931 !ExplicitSpec.getPointer();
1932 }
1933 void setKind(ExplicitSpecKind Kind) { ExplicitSpec.setInt(Kind); }
1934 void setExpr(Expr *E) { ExplicitSpec.setPointer(E); }
1935 // Retrieve the explicit specifier in the given declaration, if any.
1938 return getFromDecl(const_cast<FunctionDecl *>(Function));
1939 }
1942 }
1943};
1944
1945/// Represents a C++ deduction guide declaration.
1946///
1947/// \code
1948/// template<typename T> struct A { A(); A(T); };
1949/// A() -> A<int>;
1950/// \endcode
1951///
1952/// In this example, there will be an explicit deduction guide from the
1953/// second line, and implicit deduction guide templates synthesized from
1954/// the constructors of \c A.
1956 void anchor() override;
1957
1958private:
1961 const DeclarationNameInfo &NameInfo, QualType T,
1962 TypeSourceInfo *TInfo, SourceLocation EndLocation,
1964 : FunctionDecl(CXXDeductionGuide, C, DC, StartLoc, NameInfo, T, TInfo,
1966 Ctor(Ctor), ExplicitSpec(ES) {
1967 if (EndLocation.isValid())
1968 setRangeEnd(EndLocation);
1970 }
1971
1972 CXXConstructorDecl *Ctor;
1973 ExplicitSpecifier ExplicitSpec;
1974 void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; }
1975
1976public:
1977 friend class ASTDeclReader;
1978 friend class ASTDeclWriter;
1979
1980 static CXXDeductionGuideDecl *
1982 ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T,
1983 TypeSourceInfo *TInfo, SourceLocation EndLocation,
1984 CXXConstructorDecl *Ctor = nullptr,
1986
1989
1990 ExplicitSpecifier getExplicitSpecifier() { return ExplicitSpec; }
1991 const ExplicitSpecifier getExplicitSpecifier() const { return ExplicitSpec; }
1992
1993 /// Return true if the declaration is already resolved to be explicit.
1994 bool isExplicit() const { return ExplicitSpec.isExplicit(); }
1995
1996 /// Get the template for which this guide performs deduction.
1999 }
2000
2001 /// Get the constructor from which this deduction guide was generated, if
2002 /// this is an implicit deduction guide.
2004
2006 FunctionDeclBits.DeductionCandidateKind = static_cast<unsigned char>(K);
2007 }
2008
2010 return static_cast<DeductionCandidate>(
2011 FunctionDeclBits.DeductionCandidateKind);
2012 }
2013
2014 // Implement isa/cast/dyncast/etc.
2015 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2016 static bool classofKind(Kind K) { return K == CXXDeductionGuide; }
2017};
2018
2019/// \brief Represents the body of a requires-expression.
2020///
2021/// This decl exists merely to serve as the DeclContext for the local
2022/// parameters of the requires expression as well as other declarations inside
2023/// it.
2024///
2025/// \code
2026/// template<typename T> requires requires (T t) { {t++} -> regular; }
2027/// \endcode
2028///
2029/// In this example, a RequiresExpr object will be generated for the expression,
2030/// and a RequiresExprBodyDecl will be created to hold the parameter t and the
2031/// template argument list imposed by the compound requirement.
2032class RequiresExprBodyDecl : public Decl, public DeclContext {
2034 : Decl(RequiresExprBody, DC, StartLoc), DeclContext(RequiresExprBody) {}
2035
2036public:
2037 friend class ASTDeclReader;
2038 friend class ASTDeclWriter;
2039
2041 SourceLocation StartLoc);
2042
2045
2046 // Implement isa/cast/dyncast/etc.
2047 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2048 static bool classofKind(Kind K) { return K == RequiresExprBody; }
2049
2051 return static_cast<DeclContext *>(const_cast<RequiresExprBodyDecl *>(D));
2052 }
2053
2055 return static_cast<RequiresExprBodyDecl *>(const_cast<DeclContext *>(DC));
2056 }
2057};
2058
2059/// Represents a static or instance method of a struct/union/class.
2060///
2061/// In the terminology of the C++ Standard, these are the (static and
2062/// non-static) member functions, whether virtual or not.
2064 void anchor() override;
2065
2066protected:
2068 SourceLocation StartLoc, const DeclarationNameInfo &NameInfo,
2070 bool UsesFPIntrin, bool isInline,
2071 ConstexprSpecKind ConstexprKind, SourceLocation EndLocation,
2072 Expr *TrailingRequiresClause = nullptr)
2073 : FunctionDecl(DK, C, RD, StartLoc, NameInfo, T, TInfo, SC, UsesFPIntrin,
2074 isInline, ConstexprKind, TrailingRequiresClause) {
2075 if (EndLocation.isValid())
2076 setRangeEnd(EndLocation);
2077 }
2078
2079public:
2080 static CXXMethodDecl *
2082 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2083 StorageClass SC, bool UsesFPIntrin, bool isInline,
2084 ConstexprSpecKind ConstexprKind, SourceLocation EndLocation,
2085 Expr *TrailingRequiresClause = nullptr);
2086
2088
2089 bool isStatic() const;
2090 bool isInstance() const { return !isStatic(); }
2091
2092 /// [C++2b][dcl.fct]/p7
2093 /// An explicit object member function is a non-static
2094 /// member function with an explicit object parameter. e.g.,
2095 /// void func(this SomeType);
2096 bool isExplicitObjectMemberFunction() const;
2097
2098 /// [C++2b][dcl.fct]/p7
2099 /// An implicit object member function is a non-static
2100 /// member function without an explicit object parameter.
2101 bool isImplicitObjectMemberFunction() const;
2102
2103 /// Returns true if the given operator is implicitly static in a record
2104 /// context.
2106 // [class.free]p1:
2107 // Any allocation function for a class T is a static member
2108 // (even if not explicitly declared static).
2109 // [class.free]p6 Any deallocation function for a class X is a static member
2110 // (even if not explicitly declared static).
2111 return OOK == OO_New || OOK == OO_Array_New || OOK == OO_Delete ||
2112 OOK == OO_Array_Delete;
2113 }
2114
2115 bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); }
2116 bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); }
2117
2118 bool isVirtual() const {
2119 CXXMethodDecl *CD = const_cast<CXXMethodDecl*>(this)->getCanonicalDecl();
2120
2121 // Member function is virtual if it is marked explicitly so, or if it is
2122 // declared in __interface -- then it is automatically pure virtual.
2123 if (CD->isVirtualAsWritten() || CD->isPureVirtual())
2124 return true;
2125
2126 return CD->size_overridden_methods() != 0;
2127 }
2128
2129 /// If it's possible to devirtualize a call to this method, return the called
2130 /// function. Otherwise, return null.
2131
2132 /// \param Base The object on which this virtual function is called.
2133 /// \param IsAppleKext True if we are compiling for Apple kext.
2134 CXXMethodDecl *getDevirtualizedMethod(const Expr *Base, bool IsAppleKext);
2135
2137 bool IsAppleKext) const {
2138 return const_cast<CXXMethodDecl *>(this)->getDevirtualizedMethod(
2139 Base, IsAppleKext);
2140 }
2141
2142 /// Determine whether this is a usual deallocation function (C++
2143 /// [basic.stc.dynamic.deallocation]p2), which is an overloaded delete or
2144 /// delete[] operator with a particular signature. Populates \p PreventedBy
2145 /// with the declarations of the functions of the same kind if they were the
2146 /// reason for this function returning false. This is used by
2147 /// Sema::isUsualDeallocationFunction to reconsider the answer based on the
2148 /// context.
2150 SmallVectorImpl<const FunctionDecl *> &PreventedBy) const;
2151
2152 /// Determine whether this is a copy-assignment operator, regardless
2153 /// of whether it was declared implicitly or explicitly.
2154 bool isCopyAssignmentOperator() const;
2155
2156 /// Determine whether this is a move assignment operator.
2157 bool isMoveAssignmentOperator() const;
2158
2160 return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
2161 }
2163 return const_cast<CXXMethodDecl*>(this)->getCanonicalDecl();
2164 }
2165
2167 return cast<CXXMethodDecl>(
2168 static_cast<FunctionDecl *>(this)->getMostRecentDecl());
2169 }
2171 return const_cast<CXXMethodDecl*>(this)->getMostRecentDecl();
2172 }
2173
2174 void addOverriddenMethod(const CXXMethodDecl *MD);
2175
2176 using method_iterator = const CXXMethodDecl *const *;
2177
2180 unsigned size_overridden_methods() const;
2181
2182 using overridden_method_range = llvm::iterator_range<
2183 llvm::TinyPtrVector<const CXXMethodDecl *>::const_iterator>;
2184
2186
2187 /// Return the parent of this method declaration, which
2188 /// is the class in which this method is defined.
2189 const CXXRecordDecl *getParent() const {
2190 return cast<CXXRecordDecl>(FunctionDecl::getParent());
2191 }
2192
2193 /// Return the parent of this method declaration, which
2194 /// is the class in which this method is defined.
2196 return const_cast<CXXRecordDecl *>(
2197 cast<CXXRecordDecl>(FunctionDecl::getParent()));
2198 }
2199
2200 /// Return the type of the \c this pointer.
2201 ///
2202 /// Should only be called for instance (i.e., non-static) methods. Note
2203 /// that for the call operator of a lambda closure type, this returns the
2204 /// desugared 'this' type (a pointer to the closure type), not the captured
2205 /// 'this' type.
2206 QualType getThisType() const;
2207
2208 /// Return the type of the object pointed by \c this.
2209 ///
2210 /// See getThisType() for usage restriction.
2211
2215 }
2216
2217 unsigned getNumExplicitParams() const {
2218 return getNumParams() - (isExplicitObjectMemberFunction() ? 1 : 0);
2219 }
2220
2221 static QualType getThisType(const FunctionProtoType *FPT,
2222 const CXXRecordDecl *Decl);
2223
2225 return getType()->castAs<FunctionProtoType>()->getMethodQuals();
2226 }
2227
2228 /// Retrieve the ref-qualifier associated with this method.
2229 ///
2230 /// In the following example, \c f() has an lvalue ref-qualifier, \c g()
2231 /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier.
2232 /// @code
2233 /// struct X {
2234 /// void f() &;
2235 /// void g() &&;
2236 /// void h();
2237 /// };
2238 /// @endcode
2241 }
2242
2243 bool hasInlineBody() const;
2244
2245 /// Determine whether this is a lambda closure type's static member
2246 /// function that is used for the result of the lambda's conversion to
2247 /// function pointer (for a lambda with no captures).
2248 ///
2249 /// The function itself, if used, will have a placeholder body that will be
2250 /// supplied by IR generation to either forward to the function call operator
2251 /// or clone the function call operator.
2252 bool isLambdaStaticInvoker() const;
2253
2254 /// Find the method in \p RD that corresponds to this one.
2255 ///
2256 /// Find if \p RD or one of the classes it inherits from override this method.
2257 /// If so, return it. \p RD is assumed to be a subclass of the class defining
2258 /// this method (or be the class itself), unless \p MayBeBase is set to true.
2261 bool MayBeBase = false);
2262
2263 const CXXMethodDecl *
2265 bool MayBeBase = false) const {
2266 return const_cast<CXXMethodDecl *>(this)
2267 ->getCorrespondingMethodInClass(RD, MayBeBase);
2268 }
2269
2270 /// Find if \p RD declares a function that overrides this function, and if so,
2271 /// return it. Does not search base classes.
2273 bool MayBeBase = false);
2274 const CXXMethodDecl *
2276 bool MayBeBase = false) const {
2277 return const_cast<CXXMethodDecl *>(this)
2279 }
2280
2281 // Implement isa/cast/dyncast/etc.
2282 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2283 static bool classofKind(Kind K) {
2284 return K >= firstCXXMethod && K <= lastCXXMethod;
2285 }
2286};
2287
2288/// Represents a C++ base or member initializer.
2289///
2290/// This is part of a constructor initializer that
2291/// initializes one non-static member variable or one base class. For
2292/// example, in the following, both 'A(a)' and 'f(3.14159)' are member
2293/// initializers:
2294///
2295/// \code
2296/// class A { };
2297/// class B : public A {
2298/// float f;
2299/// public:
2300/// B(A& a) : A(a), f(3.14159) { }
2301/// };
2302/// \endcode
2304 /// Either the base class name/delegating constructor type (stored as
2305 /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field
2306 /// (IndirectFieldDecl*) being initialized.
2307 llvm::PointerUnion<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *>
2308 Initializee;
2309
2310 /// The argument used to initialize the base or member, which may
2311 /// end up constructing an object (when multiple arguments are involved).
2312 Stmt *Init;
2313
2314 /// The source location for the field name or, for a base initializer
2315 /// pack expansion, the location of the ellipsis.
2316 ///
2317 /// In the case of a delegating
2318 /// constructor, it will still include the type's source location as the
2319 /// Initializee points to the CXXConstructorDecl (to allow loop detection).
2320 SourceLocation MemberOrEllipsisLocation;
2321
2322 /// Location of the left paren of the ctor-initializer.
2323 SourceLocation LParenLoc;
2324
2325 /// Location of the right paren of the ctor-initializer.
2326 SourceLocation RParenLoc;
2327
2328 /// If the initializee is a type, whether that type makes this
2329 /// a delegating initialization.
2330 LLVM_PREFERRED_TYPE(bool)
2331 unsigned IsDelegating : 1;
2332
2333 /// If the initializer is a base initializer, this keeps track
2334 /// of whether the base is virtual or not.
2335 LLVM_PREFERRED_TYPE(bool)
2336 unsigned IsVirtual : 1;
2337
2338 /// Whether or not the initializer is explicitly written
2339 /// in the sources.
2340 LLVM_PREFERRED_TYPE(bool)
2341 unsigned IsWritten : 1;
2342
2343 /// If IsWritten is true, then this number keeps track of the textual order
2344 /// of this initializer in the original sources, counting from 0.
2345 unsigned SourceOrder : 13;
2346
2347public:
2348 /// Creates a new base-class initializer.
2349 explicit
2350 CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual,
2352 SourceLocation EllipsisLoc);
2353
2354 /// Creates a new member initializer.
2355 explicit
2357 SourceLocation MemberLoc, SourceLocation L, Expr *Init,
2358 SourceLocation R);
2359
2360 /// Creates a new anonymous field initializer.
2361 explicit
2363 SourceLocation MemberLoc, SourceLocation L, Expr *Init,
2364 SourceLocation R);
2365
2366 /// Creates a new delegating initializer.
2367 explicit
2369 SourceLocation L, Expr *Init, SourceLocation R);
2370
2371 /// \return Unique reproducible object identifier.
2372 int64_t getID(const ASTContext &Context) const;
2373
2374 /// Determine whether this initializer is initializing a base class.
2375 bool isBaseInitializer() const {
2376 return Initializee.is<TypeSourceInfo*>() && !IsDelegating;
2377 }
2378
2379 /// Determine whether this initializer is initializing a non-static
2380 /// data member.
2381 bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); }
2382
2385 }
2386
2388 return Initializee.is<IndirectFieldDecl*>();
2389 }
2390
2391 /// Determine whether this initializer is an implicit initializer
2392 /// generated for a field with an initializer defined on the member
2393 /// declaration.
2394 ///
2395 /// In-class member initializers (also known as "non-static data member
2396 /// initializations", NSDMIs) were introduced in C++11.
2398 return Init->getStmtClass() == Stmt::CXXDefaultInitExprClass;
2399 }
2400
2401 /// Determine whether this initializer is creating a delegating
2402 /// constructor.
2404 return Initializee.is<TypeSourceInfo*>() && IsDelegating;
2405 }
2406
2407 /// Determine whether this initializer is a pack expansion.
2408 bool isPackExpansion() const {
2409 return isBaseInitializer() && MemberOrEllipsisLocation.isValid();
2410 }
2411
2412 // For a pack expansion, returns the location of the ellipsis.
2414 if (!isPackExpansion())
2415 return {};
2416 return MemberOrEllipsisLocation;
2417 }
2418
2419 /// If this is a base class initializer, returns the type of the
2420 /// base class with location information. Otherwise, returns an NULL
2421 /// type location.
2422 TypeLoc getBaseClassLoc() const;
2423
2424 /// If this is a base class initializer, returns the type of the base class.
2425 /// Otherwise, returns null.
2426 const Type *getBaseClass() const;
2427
2428 /// Returns whether the base is virtual or not.
2429 bool isBaseVirtual() const {
2430 assert(isBaseInitializer() && "Must call this on base initializer!");
2431
2432 return IsVirtual;
2433 }
2434
2435 /// Returns the declarator information for a base class or delegating
2436 /// initializer.
2438 return Initializee.dyn_cast<TypeSourceInfo *>();
2439 }
2440
2441 /// If this is a member initializer, returns the declaration of the
2442 /// non-static data member being initialized. Otherwise, returns null.
2444 if (isMemberInitializer())
2445 return Initializee.get<FieldDecl*>();
2446 return nullptr;
2447 }
2448
2450 if (isMemberInitializer())
2451 return Initializee.get<FieldDecl*>();
2453 return Initializee.get<IndirectFieldDecl*>()->getAnonField();
2454 return nullptr;
2455 }
2456
2459 return Initializee.get<IndirectFieldDecl*>();
2460 return nullptr;
2461 }
2462
2464 return MemberOrEllipsisLocation;
2465 }
2466
2467 /// Determine the source location of the initializer.
2469
2470 /// Determine the source range covering the entire initializer.
2471 SourceRange getSourceRange() const LLVM_READONLY;
2472
2473 /// Determine whether this initializer is explicitly written
2474 /// in the source code.
2475 bool isWritten() const { return IsWritten; }
2476
2477 /// Return the source position of the initializer, counting from 0.
2478 /// If the initializer was implicit, -1 is returned.
2479 int getSourceOrder() const {
2480 return IsWritten ? static_cast<int>(SourceOrder) : -1;
2481 }
2482
2483 /// Set the source order of this initializer.
2484 ///
2485 /// This can only be called once for each initializer; it cannot be called
2486 /// on an initializer having a positive number of (implicit) array indices.
2487 ///
2488 /// This assumes that the initializer was written in the source code, and
2489 /// ensures that isWritten() returns true.
2490 void setSourceOrder(int Pos) {
2491 assert(!IsWritten &&
2492 "setSourceOrder() used on implicit initializer");
2493 assert(SourceOrder == 0 &&
2494 "calling twice setSourceOrder() on the same initializer");
2495 assert(Pos >= 0 &&
2496 "setSourceOrder() used to make an initializer implicit");
2497 IsWritten = true;
2498 SourceOrder = static_cast<unsigned>(Pos);
2499 }
2500
2501 SourceLocation getLParenLoc() const { return LParenLoc; }
2502 SourceLocation getRParenLoc() const { return RParenLoc; }
2503
2504 /// Get the initializer.
2505 Expr *getInit() const { return static_cast<Expr *>(Init); }
2506};
2507
2508/// Description of a constructor that was inherited from a base class.
2510 ConstructorUsingShadowDecl *Shadow = nullptr;
2511 CXXConstructorDecl *BaseCtor = nullptr;
2512
2513public:
2516 CXXConstructorDecl *BaseCtor)
2517 : Shadow(Shadow), BaseCtor(BaseCtor) {}
2518
2519 explicit operator bool() const { return Shadow; }
2520
2521 ConstructorUsingShadowDecl *getShadowDecl() const { return Shadow; }
2522 CXXConstructorDecl *getConstructor() const { return BaseCtor; }
2523};
2524
2525/// Represents a C++ constructor within a class.
2526///
2527/// For example:
2528///
2529/// \code
2530/// class X {
2531/// public:
2532/// explicit X(int); // represented by a CXXConstructorDecl.
2533/// };
2534/// \endcode
2536 : public CXXMethodDecl,
2537 private llvm::TrailingObjects<CXXConstructorDecl, InheritedConstructor,
2538 ExplicitSpecifier> {
2539 // This class stores some data in DeclContext::CXXConstructorDeclBits
2540 // to save some space. Use the provided accessors to access it.
2541
2542 /// \name Support for base and member initializers.
2543 /// \{
2544 /// The arguments used to initialize the base or member.
2545 LazyCXXCtorInitializersPtr CtorInitializers;
2546
2548 const DeclarationNameInfo &NameInfo, QualType T,
2550 bool UsesFPIntrin, bool isInline,
2551 bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind,
2552 InheritedConstructor Inherited,
2553 Expr *TrailingRequiresClause);
2554
2555 void anchor() override;
2556
2557 size_t numTrailingObjects(OverloadToken<InheritedConstructor>) const {
2558 return CXXConstructorDeclBits.IsInheritingConstructor;
2559 }
2560 size_t numTrailingObjects(OverloadToken<ExplicitSpecifier>) const {
2561 return CXXConstructorDeclBits.HasTrailingExplicitSpecifier;
2562 }
2563
2564 ExplicitSpecifier getExplicitSpecifierInternal() const {
2565 if (CXXConstructorDeclBits.HasTrailingExplicitSpecifier)
2566 return *getTrailingObjects<ExplicitSpecifier>();
2567 return ExplicitSpecifier(
2568 nullptr, CXXConstructorDeclBits.IsSimpleExplicit
2571 }
2572
2573 enum TrailingAllocKind {
2574 TAKInheritsConstructor = 1,
2575 TAKHasTailExplicit = 1 << 1,
2576 };
2577
2578 uint64_t getTrailingAllocKind() const {
2579 return numTrailingObjects(OverloadToken<InheritedConstructor>()) |
2580 (numTrailingObjects(OverloadToken<ExplicitSpecifier>()) << 1);
2581 }
2582
2583public:
2584 friend class ASTDeclReader;
2585 friend class ASTDeclWriter;
2587
2589 uint64_t AllocKind);
2590 static CXXConstructorDecl *
2592 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2593 ExplicitSpecifier ES, bool UsesFPIntrin, bool isInline,
2594 bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind,
2596 Expr *TrailingRequiresClause = nullptr);
2597
2599 assert((!ES.getExpr() ||
2600 CXXConstructorDeclBits.HasTrailingExplicitSpecifier) &&
2601 "cannot set this explicit specifier. no trail-allocated space for "
2602 "explicit");
2603 if (ES.getExpr())
2604 *getCanonicalDecl()->getTrailingObjects<ExplicitSpecifier>() = ES;
2605 else
2606 CXXConstructorDeclBits.IsSimpleExplicit = ES.isExplicit();
2607 }
2608
2610 return getCanonicalDecl()->getExplicitSpecifierInternal();
2611 }
2613 return getCanonicalDecl()->getExplicitSpecifierInternal();
2614 }
2615
2616 /// Return true if the declaration is already resolved to be explicit.
2617 bool isExplicit() const { return getExplicitSpecifier().isExplicit(); }
2618
2619 /// Iterates through the member/base initializer list.
2621
2622 /// Iterates through the member/base initializer list.
2624
2625 using init_range = llvm::iterator_range<init_iterator>;
2626 using init_const_range = llvm::iterator_range<init_const_iterator>;
2627
2631 }
2632
2633 /// Retrieve an iterator to the first initializer.
2635 const auto *ConstThis = this;
2636 return const_cast<init_iterator>(ConstThis->init_begin());
2637 }
2638
2639 /// Retrieve an iterator to the first initializer.
2641
2642 /// Retrieve an iterator past the last initializer.
2645 }
2646
2647 /// Retrieve an iterator past the last initializer.
2650 }
2651
2652 using init_reverse_iterator = std::reverse_iterator<init_iterator>;
2654 std::reverse_iterator<init_const_iterator>;
2655
2658 }
2661 }
2662
2665 }
2668 }
2669
2670 /// Determine the number of arguments used to initialize the member
2671 /// or base.
2672 unsigned getNumCtorInitializers() const {
2673 return CXXConstructorDeclBits.NumCtorInitializers;
2674 }
2675
2676 void setNumCtorInitializers(unsigned numCtorInitializers) {
2677 CXXConstructorDeclBits.NumCtorInitializers = numCtorInitializers;
2678 // This assert added because NumCtorInitializers is stored
2679 // in CXXConstructorDeclBits as a bitfield and its width has
2680 // been shrunk from 32 bits to fit into CXXConstructorDeclBitfields.
2681 assert(CXXConstructorDeclBits.NumCtorInitializers ==
2682 numCtorInitializers && "NumCtorInitializers overflow!");
2683 }
2684
2686 CtorInitializers = Initializers;
2687 }
2688
2689 /// Determine whether this constructor is a delegating constructor.
2691 return (getNumCtorInitializers() == 1) &&
2693 }
2694
2695 /// When this constructor delegates to another, retrieve the target.
2697
2698 /// Whether this constructor is a default
2699 /// constructor (C++ [class.ctor]p5), which can be used to
2700 /// default-initialize a class of this type.
2701 bool isDefaultConstructor() const;
2702
2703 /// Whether this constructor is a copy constructor (C++ [class.copy]p2,
2704 /// which can be used to copy the class.
2705 ///
2706 /// \p TypeQuals will be set to the qualifiers on the
2707 /// argument type. For example, \p TypeQuals would be set to \c
2708 /// Qualifiers::Const for the following copy constructor:
2709 ///
2710 /// \code
2711 /// class X {
2712 /// public:
2713 /// X(const X&);
2714 /// };
2715 /// \endcode
2716 bool isCopyConstructor(unsigned &TypeQuals) const;
2717
2718 /// Whether this constructor is a copy
2719 /// constructor (C++ [class.copy]p2, which can be used to copy the
2720 /// class.
2721 bool isCopyConstructor() const {
2722 unsigned TypeQuals = 0;
2723 return isCopyConstructor(TypeQuals);
2724 }
2725
2726 /// Determine whether this constructor is a move constructor
2727 /// (C++11 [class.copy]p3), which can be used to move values of the class.
2728 ///
2729 /// \param TypeQuals If this constructor is a move constructor, will be set
2730 /// to the type qualifiers on the referent of the first parameter's type.
2731 bool isMoveConstructor(unsigned &TypeQuals) const;
2732
2733 /// Determine whether this constructor is a move constructor
2734 /// (C++11 [class.copy]p3), which can be used to move values of the class.
2735 bool isMoveConstructor() const {
2736 unsigned TypeQuals = 0;
2737 return isMoveConstructor(TypeQuals);
2738 }
2739
2740 /// Determine whether this is a copy or move constructor.
2741 ///
2742 /// \param TypeQuals Will be set to the type qualifiers on the reference
2743 /// parameter, if in fact this is a copy or move constructor.
2744 bool isCopyOrMoveConstructor(unsigned &TypeQuals) const;
2745
2746 /// Determine whether this a copy or move constructor.
2748 unsigned Quals;
2749 return isCopyOrMoveConstructor(Quals);
2750 }
2751
2752 /// Whether this constructor is a
2753 /// converting constructor (C++ [class.conv.ctor]), which can be
2754 /// used for user-defined conversions.
2755 bool isConvertingConstructor(bool AllowExplicit) const;
2756
2757 /// Determine whether this is a member template specialization that
2758 /// would copy the object to itself. Such constructors are never used to copy
2759 /// an object.
2760 bool isSpecializationCopyingObject() const;
2761
2762 /// Determine whether this is an implicit constructor synthesized to
2763 /// model a call to a constructor inherited from a base class.
2765 return CXXConstructorDeclBits.IsInheritingConstructor;
2766 }
2767
2768 /// State that this is an implicit constructor synthesized to
2769 /// model a call to a constructor inherited from a base class.
2770 void setInheritingConstructor(bool isIC = true) {
2771 CXXConstructorDeclBits.IsInheritingConstructor = isIC;
2772 }
2773
2774 /// Get the constructor that this inheriting constructor is based on.
2776 return isInheritingConstructor() ?
2777 *getTrailingObjects<InheritedConstructor>() : InheritedConstructor();
2778 }
2779
2781 return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
2782 }
2784 return const_cast<CXXConstructorDecl*>(this)->getCanonicalDecl();
2785 }
2786
2787 // Implement isa/cast/dyncast/etc.
2788 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2789 static bool classofKind(Kind K) { return K == CXXConstructor; }
2790};
2791
2792/// Represents a C++ destructor within a class.
2793///
2794/// For example:
2795///
2796/// \code
2797/// class X {
2798/// public:
2799/// ~X(); // represented by a CXXDestructorDecl.
2800/// };
2801/// \endcode
2803 friend class ASTDeclReader;
2804 friend class ASTDeclWriter;
2805
2806 // FIXME: Don't allocate storage for these except in the first declaration
2807 // of a virtual destructor.
2808 FunctionDecl *OperatorDelete = nullptr;
2809 Expr *OperatorDeleteThisArg = nullptr;
2810
2812 const DeclarationNameInfo &NameInfo, QualType T,
2813 TypeSourceInfo *TInfo, bool UsesFPIntrin, bool isInline,
2814 bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind,
2815 Expr *TrailingRequiresClause = nullptr)
2816 : CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo,
2817 SC_None, UsesFPIntrin, isInline, ConstexprKind,
2818 SourceLocation(), TrailingRequiresClause) {
2819 setImplicit(isImplicitlyDeclared);
2820 }
2821
2822 void anchor() override;
2823
2824public:
2825 static CXXDestructorDecl *
2827 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2828 bool UsesFPIntrin, bool isInline, bool isImplicitlyDeclared,
2829 ConstexprSpecKind ConstexprKind,
2830 Expr *TrailingRequiresClause = nullptr);
2832
2833 void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg);
2834
2836 return getCanonicalDecl()->OperatorDelete;
2837 }
2838
2840 return getCanonicalDecl()->OperatorDeleteThisArg;
2841 }
2842
2844 return cast<CXXDestructorDecl>(FunctionDecl::getCanonicalDecl());
2845 }
2847 return const_cast<CXXDestructorDecl*>(this)->getCanonicalDecl();
2848 }
2849
2850 // Implement isa/cast/dyncast/etc.
2851 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2852 static bool classofKind(Kind K) { return K == CXXDestructor; }
2853};
2854
2855/// Represents a C++ conversion function within a class.
2856///
2857/// For example:
2858///
2859/// \code
2860/// class X {
2861/// public:
2862/// operator bool();
2863/// };
2864/// \endcode
2867 const DeclarationNameInfo &NameInfo, QualType T,
2868 TypeSourceInfo *TInfo, bool UsesFPIntrin, bool isInline,
2869 ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind,
2870 SourceLocation EndLocation,
2871 Expr *TrailingRequiresClause = nullptr)
2872 : CXXMethodDecl(CXXConversion, C, RD, StartLoc, NameInfo, T, TInfo,
2873 SC_None, UsesFPIntrin, isInline, ConstexprKind,
2874 EndLocation, TrailingRequiresClause),
2875 ExplicitSpec(ES) {}
2876 void anchor() override;
2877
2878 ExplicitSpecifier ExplicitSpec;
2879
2880public:
2881 friend class ASTDeclReader;
2882 friend class ASTDeclWriter;
2883
2884 static CXXConversionDecl *
2886 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2887 bool UsesFPIntrin, bool isInline, ExplicitSpecifier ES,
2888 ConstexprSpecKind ConstexprKind, SourceLocation EndLocation,
2889 Expr *TrailingRequiresClause = nullptr);
2891
2893 return getCanonicalDecl()->ExplicitSpec;
2894 }
2895
2897 return getCanonicalDecl()->ExplicitSpec;
2898 }
2899
2900 /// Return true if the declaration is already resolved to be explicit.
2901 bool isExplicit() const { return getExplicitSpecifier().isExplicit(); }
2902 void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; }
2903
2904 /// Returns the type that this conversion function is converting to.
2906 return getType()->castAs<FunctionType>()->getReturnType();
2907 }
2908
2909 /// Determine whether this conversion function is a conversion from
2910 /// a lambda closure type to a block pointer.
2912
2914 return cast<CXXConversionDecl>(FunctionDecl::getCanonicalDecl());
2915 }
2917 return const_cast<CXXConversionDecl*>(this)->getCanonicalDecl();
2918 }
2919
2920 // Implement isa/cast/dyncast/etc.
2921 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2922 static bool classofKind(Kind K) { return K == CXXConversion; }
2923};
2924
2925/// Represents the language in a linkage specification.
2926///
2927/// The values are part of the serialization ABI for
2928/// ASTs and cannot be changed without altering that ABI.
2929enum class LinkageSpecLanguageIDs { C = 1, CXX = 2 };
2930
2931/// Represents a linkage specification.
2932///
2933/// For example:
2934/// \code
2935/// extern "C" void foo();
2936/// \endcode
2937class LinkageSpecDecl : public Decl, public DeclContext {
2938 virtual void anchor();
2939 // This class stores some data in DeclContext::LinkageSpecDeclBits to save
2940 // some space. Use the provided accessors to access it.
2941
2942 /// The source location for the extern keyword.
2943 SourceLocation ExternLoc;
2944
2945 /// The source location for the right brace (if valid).
2946 SourceLocation RBraceLoc;
2947
2950 bool HasBraces);
2951
2952public:
2954 SourceLocation ExternLoc,
2955 SourceLocation LangLoc,
2956 LinkageSpecLanguageIDs Lang, bool HasBraces);
2958
2959 /// Return the language specified by this linkage specification.
2961 return static_cast<LinkageSpecLanguageIDs>(LinkageSpecDeclBits.Language);
2962 }
2963
2964 /// Set the language specified by this linkage specification.
2966 LinkageSpecDeclBits.Language = llvm::to_underlying(L);
2967 }
2968
2969 /// Determines whether this linkage specification had braces in
2970 /// its syntactic form.
2971 bool hasBraces() const {
2972 assert(!RBraceLoc.isValid() || LinkageSpecDeclBits.HasBraces);
2973 return LinkageSpecDeclBits.HasBraces;
2974 }
2975
2976 SourceLocation getExternLoc() const { return ExternLoc; }
2977 SourceLocation getRBraceLoc() const { return RBraceLoc; }
2978 void setExternLoc(SourceLocation L) { ExternLoc = L; }
2980 RBraceLoc = L;
2981 LinkageSpecDeclBits.HasBraces = RBraceLoc.isValid();
2982 }
2983
2984 SourceLocation getEndLoc() const LLVM_READONLY {
2985 if (hasBraces())
2986 return getRBraceLoc();
2987 // No braces: get the end location of the (only) declaration in context
2988 // (if present).
2989 return decls_empty() ? getLocation() : decls_begin()->getEndLoc();
2990 }
2991
2992 SourceRange getSourceRange() const override LLVM_READONLY {
2993 return SourceRange(ExternLoc, getEndLoc());
2994 }
2995
2996 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2997 static bool classofKind(Kind K) { return K == LinkageSpec; }
2998
3000 return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
3001 }
3002
3004 return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
3005 }
3006};
3007
3008/// Represents C++ using-directive.
3009///
3010/// For example:
3011/// \code
3012/// using namespace std;
3013/// \endcode
3014///
3015/// \note UsingDirectiveDecl should be Decl not NamedDecl, but we provide
3016/// artificial names for all using-directives in order to store
3017/// them in DeclContext effectively.
3019 /// The location of the \c using keyword.
3020 SourceLocation UsingLoc;
3021
3022 /// The location of the \c namespace keyword.
3023 SourceLocation NamespaceLoc;
3024
3025 /// The nested-name-specifier that precedes the namespace.
3026 NestedNameSpecifierLoc QualifierLoc;
3027
3028 /// The namespace nominated by this using-directive.
3029 NamedDecl *NominatedNamespace;
3030
3031 /// Enclosing context containing both using-directive and nominated
3032 /// namespace.
3033 DeclContext *CommonAncestor;
3034
3036 SourceLocation NamespcLoc,
3037 NestedNameSpecifierLoc QualifierLoc,
3038 SourceLocation IdentLoc,
3039 NamedDecl *Nominated,
3040 DeclContext *CommonAncestor)
3041 : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
3042 NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
3043 NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) {}
3044
3045 /// Returns special DeclarationName used by using-directives.
3046 ///
3047 /// This is only used by DeclContext for storing UsingDirectiveDecls in
3048 /// its lookup structure.
3049 static DeclarationName getName() {
3051 }
3052
3053 void anchor() override;
3054
3055public:
3056 friend class ASTDeclReader;
3057
3058 // Friend for getUsingDirectiveName.
3059 friend class DeclContext;
3060
3061 /// Retrieve the nested-name-specifier that qualifies the
3062 /// name of the namespace, with source-location information.
3063 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3064
3065 /// Retrieve the nested-name-specifier that qualifies the
3066 /// name of the namespace.
3068 return QualifierLoc.getNestedNameSpecifier();
3069 }
3070
3071 NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
3073 return NominatedNamespace;
3074 }
3075
3076 /// Returns the namespace nominated by this using-directive.
3078
3080 return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
3081 }
3082
3083 /// Returns the common ancestor context of this using-directive and
3084 /// its nominated namespace.
3085 DeclContext *getCommonAncestor() { return CommonAncestor; }
3086 const DeclContext *getCommonAncestor() const { return CommonAncestor; }
3087
3088 /// Return the location of the \c using keyword.
3089 SourceLocation getUsingLoc() const { return UsingLoc; }
3090
3091 // FIXME: Could omit 'Key' in name.
3092 /// Returns the location of the \c namespace keyword.
3093 SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
3094
3095 /// Returns the location of this using declaration's identifier.
3097
3099 SourceLocation UsingLoc,
3100 SourceLocation NamespaceLoc,
3101 NestedNameSpecifierLoc QualifierLoc,
3102 SourceLocation IdentLoc,
3103 NamedDecl *Nominated,
3104 DeclContext *CommonAncestor);
3106
3107 SourceRange getSourceRange() const override LLVM_READONLY {
3108 return SourceRange(UsingLoc, getLocation());
3109 }
3110
3111 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3112 static bool classofKind(Kind K) { return K == UsingDirective; }
3113};
3114
3115/// Represents a C++ namespace alias.
3116///
3117/// For example:
3118///
3119/// \code
3120/// namespace Foo = Bar;
3121/// \endcode
3123 public Redeclarable<NamespaceAliasDecl> {
3124 friend class ASTDeclReader;
3125
3126 /// The location of the \c namespace keyword.
3127 SourceLocation NamespaceLoc;
3128
3129 /// The location of the namespace's identifier.
3130 ///
3131 /// This is accessed by TargetNameLoc.
3132 SourceLocation IdentLoc;
3133
3134 /// The nested-name-specifier that precedes the namespace.
3135 NestedNameSpecifierLoc QualifierLoc;
3136
3137 /// The Decl that this alias points to, either a NamespaceDecl or
3138 /// a NamespaceAliasDecl.
3139 NamedDecl *Namespace;
3140
3142 SourceLocation NamespaceLoc, SourceLocation AliasLoc,
3143 IdentifierInfo *Alias, NestedNameSpecifierLoc QualifierLoc,
3144 SourceLocation IdentLoc, NamedDecl *Namespace)
3145 : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias), redeclarable_base(C),
3146 NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc),
3147 QualifierLoc(QualifierLoc), Namespace(Namespace) {}
3148
3149 void anchor() override;
3150
3151 using redeclarable_base = Redeclarable<NamespaceAliasDecl>;
3152
3153 NamespaceAliasDecl *getNextRedeclarationImpl() override;
3154 NamespaceAliasDecl *getPreviousDeclImpl() override;
3155 NamespaceAliasDecl *getMostRecentDeclImpl() override;
3156
3157public:
3159 SourceLocation NamespaceLoc,
3160 SourceLocation AliasLoc,
3161 IdentifierInfo *Alias,
3162 NestedNameSpecifierLoc QualifierLoc,
3163 SourceLocation IdentLoc,
3164 NamedDecl *Namespace);
3165
3167
3169 using redecl_iterator = redeclarable_base::redecl_iterator;
3170
3176
3178 return getFirstDecl();
3179 }
3181 return getFirstDecl();
3182 }
3183
3184 /// Retrieve the nested-name-specifier that qualifies the
3185 /// name of the namespace, with source-location information.
3186 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3187
3188 /// Retrieve the nested-name-specifier that qualifies the
3189 /// name of the namespace.
3191 return QualifierLoc.getNestedNameSpecifier();
3192 }
3193
3194 /// Retrieve the namespace declaration aliased by this directive.
3196 if (auto *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
3197 return AD->getNamespace();
3198
3199 return cast<NamespaceDecl>(Namespace);
3200 }
3201
3203 return const_cast<NamespaceAliasDecl *>(this)->getNamespace();
3204 }
3205
3206 /// Returns the location of the alias name, i.e. 'foo' in
3207 /// "namespace foo = ns::bar;".
3209
3210 /// Returns the location of the \c namespace keyword.
3211 SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
3212
3213 /// Returns the location of the identifier in the named namespace.
3214 SourceLocation getTargetNameLoc() const { return IdentLoc; }
3215
3216 /// Retrieve the namespace that this alias refers to, which
3217 /// may either be a NamespaceDecl or a NamespaceAliasDecl.
3218 NamedDecl *getAliasedNamespace() const { return Namespace; }
3219
3220 SourceRange getSourceRange() const override LLVM_READONLY {
3221 return SourceRange(NamespaceLoc, IdentLoc);
3222 }
3223
3224 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3225 static bool classofKind(Kind K) { return K == NamespaceAlias; }
3226};
3227
3228/// Implicit declaration of a temporary that was materialized by
3229/// a MaterializeTemporaryExpr and lifetime-extended by a declaration
3231 : public Decl,
3232 public Mergeable<LifetimeExtendedTemporaryDecl> {
3234 friend class ASTDeclReader;
3235
3236 Stmt *ExprWithTemporary = nullptr;
3237
3238 /// The declaration which lifetime-extended this reference, if any.
3239 /// Either a VarDecl, or (for a ctor-initializer) a FieldDecl.
3240 ValueDecl *ExtendingDecl = nullptr;
3241 unsigned ManglingNumber;
3242
3243 mutable APValue *Value = nullptr;
3244
3245 virtual void anchor();
3246
3247 LifetimeExtendedTemporaryDecl(Expr *Temp, ValueDecl *EDecl, unsigned Mangling)
3248 : Decl(Decl::LifetimeExtendedTemporary, EDecl->getDeclContext(),
3249 EDecl->getLocation()),
3250 ExprWithTemporary(Temp), ExtendingDecl(EDecl),
3251 ManglingNumber(Mangling) {}
3252
3254 : Decl(Decl::LifetimeExtendedTemporary, EmptyShell{}) {}
3255
3256public:
3258 unsigned Mangling) {
3259 return new (EDec->getASTContext(), EDec->getDeclContext())
3260 LifetimeExtendedTemporaryDecl(Temp, EDec, Mangling);
3261 }
3263 GlobalDeclID ID) {
3265 }
3266
3267 ValueDecl *getExtendingDecl() { return ExtendingDecl; }
3268 const ValueDecl *getExtendingDecl() const { return ExtendingDecl; }
3269
3270 /// Retrieve the storage duration for the materialized temporary.
3272
3273 /// Retrieve the expression to which the temporary materialization conversion
3274 /// was applied. This isn't necessarily the initializer of the temporary due
3275 /// to the C++98 delayed materialization rules, but
3276 /// skipRValueSubobjectAdjustments can be used to find said initializer within
3277 /// the subexpression.
3278 Expr *getTemporaryExpr() { return cast<Expr>(ExprWithTemporary); }
3279 const Expr *getTemporaryExpr() const { return cast<Expr>(ExprWithTemporary); }
3280
3281 unsigned getManglingNumber() const { return ManglingNumber; }
3282
3283 /// Get the storage for the constant value of a materialized temporary
3284 /// of static storage duration.
3285 APValue *getOrCreateValue(bool MayCreate) const;
3286
3287 APValue *getValue() const { return Value; }
3288
3289 // Iterators
3291 return Stmt::child_range(&ExprWithTemporary, &ExprWithTemporary + 1);
3292 }
3293
3295 return Stmt::const_child_range(&ExprWithTemporary, &ExprWithTemporary + 1);
3296 }
3297
3298 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3299 static bool classofKind(Kind K) {
3300 return K == Decl::LifetimeExtendedTemporary;
3301 }
3302};
3303
3304/// Represents a shadow declaration implicitly introduced into a scope by a
3305/// (resolved) using-declaration or using-enum-declaration to achieve
3306/// the desired lookup semantics.
3307///
3308/// For example:
3309/// \code
3310/// namespace A {
3311/// void foo();
3312/// void foo(int);
3313/// struct foo {};
3314/// enum bar { bar1, bar2 };
3315/// }
3316/// namespace B {
3317/// // add a UsingDecl and three UsingShadowDecls (named foo) to B.
3318/// using A::foo;
3319/// // adds UsingEnumDecl and two UsingShadowDecls (named bar1 and bar2) to B.
3320/// using enum A::bar;
3321/// }
3322/// \endcode
3323class UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> {
3324 friend class BaseUsingDecl;
3325
3326 /// The referenced declaration.
3327 NamedDecl *Underlying = nullptr;
3328
3329 /// The using declaration which introduced this decl or the next using
3330 /// shadow declaration contained in the aforementioned using declaration.
3331 NamedDecl *UsingOrNextShadow = nullptr;
3332
3333 void anchor() override;
3334
3336
3337 UsingShadowDecl *getNextRedeclarationImpl() override {
3338 return getNextRedeclaration();
3339 }
3340
3341 UsingShadowDecl *getPreviousDeclImpl() override {
3342 return getPreviousDecl();
3343 }
3344
3345 UsingShadowDecl *getMostRecentDeclImpl() override {
3346 return getMostRecentDecl();
3347 }
3348
3349protected:
3350 UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC, SourceLocation Loc,
3351 DeclarationName Name, BaseUsingDecl *Introducer,
3352 NamedDecl *Target);
3353 UsingShadowDecl(Kind K, ASTContext &C, EmptyShell);
3354
3355public:
3356 friend class ASTDeclReader;
3357 friend class ASTDeclWriter;
3358
3361 BaseUsingDecl *Introducer, NamedDecl *Target) {
3362 return new (C, DC)
3363 UsingShadowDecl(UsingShadow, C, DC, Loc, Name, Introducer, Target);
3364 }
3365
3367
3369 using redecl_iterator = redeclarable_base::redecl_iterator;
3370
3377
3379 return getFirstDecl();
3380 }
3382 return getFirstDecl();
3383 }
3384
3385 /// Gets the underlying declaration which has been brought into the
3386 /// local scope.
3387 NamedDecl *getTargetDecl() const { return Underlying; }
3388
3389 /// Sets the underlying declaration which has been brought into the
3390 /// local scope.
3392 assert(ND && "Target decl is null!");
3393 Underlying = ND;
3394 // A UsingShadowDecl is never a friend or local extern declaration, even
3395 // if it is a shadow declaration for one.
3399 }
3400
3401 /// Gets the (written or instantiated) using declaration that introduced this
3402 /// declaration.
3404
3405 /// The next using shadow declaration contained in the shadow decl
3406 /// chain of the using declaration which introduced this decl.
3408 return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow);
3409 }
3410
3411 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3412 static bool classofKind(Kind K) {
3413 return K == Decl::UsingShadow || K == Decl::ConstructorUsingShadow;
3414 }
3415};
3416
3417/// Represents a C++ declaration that introduces decls from somewhere else. It
3418/// provides a set of the shadow decls so introduced.
3419
3420class BaseUsingDecl : public NamedDecl {
3421 /// The first shadow declaration of the shadow decl chain associated
3422 /// with this using declaration.
3423 ///
3424 /// The bool member of the pair is a bool flag a derived type may use
3425 /// (UsingDecl makes use of it).
3426 llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow;
3427
3428protected:
3430 : NamedDecl(DK, DC, L, N), FirstUsingShadow(nullptr, false) {}
3431
3432private:
3433 void anchor() override;
3434
3435protected:
3436 /// A bool flag for use by a derived type
3437 bool getShadowFlag() const { return FirstUsingShadow.getInt(); }
3438
3439 /// A bool flag a derived type may set
3440 void setShadowFlag(bool V) { FirstUsingShadow.setInt(V); }
3441
3442public:
3443 friend class ASTDeclReader;
3444 friend class ASTDeclWriter;
3445
3446 /// Iterates through the using shadow declarations associated with
3447 /// this using declaration.
3449 /// The current using shadow declaration.
3450 UsingShadowDecl *Current = nullptr;
3451
3452 public:
3456 using iterator_category = std::forward_iterator_tag;
3457 using difference_type = std::ptrdiff_t;
3458
3459 shadow_iterator() = default;
3460 explicit shadow_iterator(UsingShadowDecl *C) : Current(C) {}
3461
3462 reference operator*() const { return Current; }
3463 pointer operator->() const { return Current; }
3464
3466 Current = Current->getNextUsingShadowDecl();
3467 return *this;
3468 }
3469
3471 shadow_iterator tmp(*this);
3472 ++(*this);
3473 return tmp;
3474 }
3475
3477 return x.Current == y.Current;
3478 }
3480 return x.Current != y.Current;
3481 }
3482 };
3483
3484 using shadow_range = llvm::iterator_range<shadow_iterator>;
3485
3488 }
3489
3491 return shadow_iterator(FirstUsingShadow.getPointer());
3492 }
3493
3495
3496 /// Return the number of shadowed declarations associated with this
3497 /// using declaration.
3498 unsigned shadow_size() const {
3499 return std::distance(shadow_begin(), shadow_end());
3500 }
3501
3504
3505 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3506 static bool classofKind(Kind K) { return K == Using || K == UsingEnum; }
3507};
3508
3509/// Represents a C++ using-declaration.
3510///
3511/// For example:
3512/// \code
3513/// using someNameSpace::someIdentifier;
3514/// \endcode
3515class UsingDecl : public BaseUsingDecl, public Mergeable<UsingDecl> {
3516 /// The source location of the 'using' keyword itself.
3517 SourceLocation UsingLocation;
3518
3519 /// The nested-name-specifier that precedes the name.
3520 NestedNameSpecifierLoc QualifierLoc;
3521
3522 /// Provides source/type location info for the declaration name
3523 /// embedded in the ValueDecl base class.
3524 DeclarationNameLoc DNLoc;
3525
3527 NestedNameSpecifierLoc QualifierLoc,
3528 const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword)
3529 : BaseUsingDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()),
3530 UsingLocation(UL), QualifierLoc(QualifierLoc),
3531 DNLoc(NameInfo.getInfo()) {
3532 setShadowFlag(HasTypenameKeyword);
3533 }
3534
3535 void anchor() override;
3536
3537public:
3538 friend class ASTDeclReader;
3539 friend class ASTDeclWriter;
3540
3541 /// Return the source location of the 'using' keyword.
3542 SourceLocation getUsingLoc() const { return UsingLocation; }
3543
3544 /// Set the source location of the 'using' keyword.
3545 void setUsingLoc(SourceLocation L) { UsingLocation = L; }
3546
3547 /// Retrieve the nested-name-specifier that qualifies the name,
3548 /// with source-location information.
3549 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3550
3551 /// Retrieve the nested-name-specifier that qualifies the name.
3553 return QualifierLoc.getNestedNameSpecifier();
3554 }
3555
3557 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
3558 }
3559
3560 /// Return true if it is a C++03 access declaration (no 'using').
3561 bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
3562
3563 /// Return true if the using declaration has 'typename'.
3564 bool hasTypename() const { return getShadowFlag(); }
3565
3566 /// Sets whether the using declaration has 'typename'.
3567 void setTypename(bool TN) { setShadowFlag(TN); }
3568
3569 static UsingDecl *Create(ASTContext &C, DeclContext *DC,
3570 SourceLocation UsingL,
3571 NestedNameSpecifierLoc QualifierLoc,
3572 const DeclarationNameInfo &NameInfo,
3573 bool HasTypenameKeyword);
3574
3576
3577 SourceRange getSourceRange() const override LLVM_READONLY;
3578
3579 /// Retrieves the canonical declaration of this declaration.
3581 return cast<UsingDecl>(getFirstDecl());
3582 }
3584 return cast<UsingDecl>(getFirstDecl());
3585 }
3586
3587 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3588 static bool classofKind(Kind K) { return K == Using; }
3589};
3590
3591/// Represents a shadow constructor declaration introduced into a
3592/// class by a C++11 using-declaration that names a constructor.
3593///
3594/// For example:
3595/// \code
3596/// struct Base { Base(int); };
3597/// struct Derived {
3598/// using Base::Base; // creates a UsingDecl and a ConstructorUsingShadowDecl
3599/// };
3600/// \endcode
3602 /// If this constructor using declaration inherted the constructor
3603 /// from an indirect base class, this is the ConstructorUsingShadowDecl
3604 /// in the named direct base class from which the declaration was inherited.
3605 ConstructorUsingShadowDecl *NominatedBaseClassShadowDecl = nullptr;
3606
3607 /// If this constructor using declaration inherted the constructor
3608 /// from an indirect base class, this is the ConstructorUsingShadowDecl
3609 /// that will be used to construct the unique direct or virtual base class
3610 /// that receives the constructor arguments.
3611 ConstructorUsingShadowDecl *ConstructedBaseClassShadowDecl = nullptr;
3612
3613 /// \c true if the constructor ultimately named by this using shadow
3614 /// declaration is within a virtual base class subobject of the class that
3615 /// contains this declaration.
3616 LLVM_PREFERRED_TYPE(bool)
3617 unsigned IsVirtual : 1;
3618
3620 UsingDecl *Using, NamedDecl *Target,
3621 bool TargetInVirtualBase)
3622 : UsingShadowDecl(ConstructorUsingShadow, C, DC, Loc,
3623 Using->getDeclName(), Using,
3624 Target->getUnderlyingDecl()),
3625 NominatedBaseClassShadowDecl(
3626 dyn_cast<ConstructorUsingShadowDecl>(Target)),
3627 ConstructedBaseClassShadowDecl(NominatedBaseClassShadowDecl),
3628 IsVirtual(TargetInVirtualBase) {
3629 // If we found a constructor that chains to a constructor for a virtual
3630 // base, we should directly call that virtual base constructor instead.
3631 // FIXME: This logic belongs in Sema.
3632 if (NominatedBaseClassShadowDecl &&
3633 NominatedBaseClassShadowDecl->constructsVirtualBase()) {
3634 ConstructedBaseClassShadowDecl =
3635 NominatedBaseClassShadowDecl->ConstructedBaseClassShadowDecl;
3636 IsVirtual = true;
3637 }
3638 }
3639
3641 : UsingShadowDecl(ConstructorUsingShadow, C, Empty), IsVirtual(false) {}
3642
3643 void anchor() override;
3644
3645public:
3646 friend class ASTDeclReader;
3647 friend class ASTDeclWriter;
3648
3651 UsingDecl *Using, NamedDecl *Target,
3652 bool IsVirtual);
3655
3656 /// Override the UsingShadowDecl's getIntroducer, returning the UsingDecl that
3657 /// introduced this.
3659 return cast<UsingDecl>(UsingShadowDecl::getIntroducer());
3660 }
3661
3662 /// Returns the parent of this using shadow declaration, which
3663 /// is the class in which this is declared.
3664 //@{
3665 const CXXRecordDecl *getParent() const {
3666 return cast<CXXRecordDecl>(getDeclContext());
3667 }
3669 return cast<CXXRecordDecl>(getDeclContext());
3670 }
3671 //@}
3672
3673 /// Get the inheriting constructor declaration for the direct base
3674 /// class from which this using shadow declaration was inherited, if there is
3675 /// one. This can be different for each redeclaration of the same shadow decl.
3677 return NominatedBaseClassShadowDecl;
3678 }
3679
3680 /// Get the inheriting constructor declaration for the base class
3681 /// for which we don't have an explicit initializer, if there is one.
3683 return ConstructedBaseClassShadowDecl;
3684 }
3685
3686 /// Get the base class that was named in the using declaration. This
3687 /// can be different for each redeclaration of this same shadow decl.
3689
3690 /// Get the base class whose constructor or constructor shadow
3691 /// declaration is passed the constructor arguments.
3693 return cast<CXXRecordDecl>((ConstructedBaseClassShadowDecl
3694 ? ConstructedBaseClassShadowDecl
3695 : getTargetDecl())
3696 ->getDeclContext());
3697 }
3698
3699 /// Returns \c true if the constructed base class is a virtual base
3700 /// class subobject of this declaration's class.
3702 return IsVirtual;
3703 }
3704
3705 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3706 static bool classofKind(Kind K) { return K == ConstructorUsingShadow; }
3707};
3708
3709/// Represents a C++ using-enum-declaration.
3710///
3711/// For example:
3712/// \code
3713/// using enum SomeEnumTag ;
3714/// \endcode
3715
3716class UsingEnumDecl : public BaseUsingDecl, public Mergeable<UsingEnumDecl> {
3717 /// The source location of the 'using' keyword itself.
3718 SourceLocation UsingLocation;
3719 /// The source location of the 'enum' keyword.
3720 SourceLocation EnumLocation;
3721 /// 'qual::SomeEnum' as an EnumType, possibly with Elaborated/Typedef sugar.
3723
3726 : BaseUsingDecl(UsingEnum, DC, NL, DN), UsingLocation(UL), EnumLocation(EL),
3728
3729 void anchor() override;
3730
3731public:
3732 friend class ASTDeclReader;
3733 friend class ASTDeclWriter;
3734
3735 /// The source location of the 'using' keyword.
3736 SourceLocation getUsingLoc() const { return UsingLocation; }
3737 void setUsingLoc(SourceLocation L) { UsingLocation = L; }
3738
3739 /// The source location of the 'enum' keyword.
3740 SourceLocation getEnumLoc() const { return EnumLocation; }
3741 void setEnumLoc(SourceLocation L) { EnumLocation = L; }
3744 }
3746 if (auto ETL = EnumType->getTypeLoc().getAs<ElaboratedTypeLoc>())
3747 return ETL.getQualifierLoc();
3748 return NestedNameSpecifierLoc();
3749 }
3750 // Returns the "qualifier::Name" part as a TypeLoc.
3752 return EnumType->getTypeLoc();
3753 }
3755 return EnumType;
3756 }
3758
3759public:
3760 EnumDecl *getEnumDecl() const { return cast<EnumDecl>(EnumType->getType()->getAsTagDecl()); }
3761
3763 SourceLocation UsingL, SourceLocation EnumL,
3765
3767
3768 SourceRange getSourceRange() const override LLVM_READONLY;
3769
3770 /// Retrieves the canonical declaration of this declaration.
3772 return cast<UsingEnumDecl>(getFirstDecl());
3773 }
3775 return cast<UsingEnumDecl>(getFirstDecl());
3776 }
3777
3778 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3779 static bool classofKind(Kind K) { return K == UsingEnum; }
3780};
3781
3782/// Represents a pack of using declarations that a single
3783/// using-declarator pack-expanded into.
3784///
3785/// \code
3786/// template<typename ...T> struct X : T... {
3787/// using T::operator()...;
3788/// using T::operator T...;
3789/// };
3790/// \endcode
3791///
3792/// In the second case above, the UsingPackDecl will have the name
3793/// 'operator T' (which contains an unexpanded pack), but the individual
3794/// UsingDecls and UsingShadowDecls will have more reasonable names.
3795class UsingPackDecl final
3796 : public NamedDecl, public Mergeable<UsingPackDecl>,
3797 private llvm::TrailingObjects<UsingPackDecl, NamedDecl *> {
3798 /// The UnresolvedUsingValueDecl or UnresolvedUsingTypenameDecl from
3799 /// which this waas instantiated.
3800 NamedDecl *InstantiatedFrom;
3801
3802 /// The number of using-declarations created by this pack expansion.
3803 unsigned NumExpansions;
3804
3805 UsingPackDecl(DeclContext *DC, NamedDecl *InstantiatedFrom,
3806 ArrayRef<NamedDecl *> UsingDecls)
3807 : NamedDecl(UsingPack, DC,
3808 InstantiatedFrom ? InstantiatedFrom->getLocation()
3809 : SourceLocation(),
3810 InstantiatedFrom ? InstantiatedFrom->getDeclName()
3811 : DeclarationName()),
3812 InstantiatedFrom(InstantiatedFrom), NumExpansions(UsingDecls.size()) {
3813 std::uninitialized_copy(UsingDecls.begin(), UsingDecls.end(),
3814 getTrailingObjects<NamedDecl *>());
3815 }
3816
3817 void anchor() override;
3818
3819public:
3820 friend class ASTDeclReader;
3821 friend class ASTDeclWriter;
3823
3824 /// Get the using declaration from which this was instantiated. This will
3825 /// always be an UnresolvedUsingValueDecl or an UnresolvedUsingTypenameDecl
3826 /// that is a pack expansion.
3827 NamedDecl *getInstantiatedFromUsingDecl() const { return InstantiatedFrom; }
3828
3829 /// Get the set of using declarations that this pack expanded into. Note that
3830 /// some of these may still be unresolved.
3832 return llvm::ArrayRef(getTrailingObjects<NamedDecl *>(), NumExpansions);
3833 }
3834
3836 NamedDecl *InstantiatedFrom,
3837 ArrayRef<NamedDecl *> UsingDecls);
3838
3840 unsigned NumExpansions);
3841
3842 SourceRange getSourceRange() const override LLVM_READONLY {
3843 return InstantiatedFrom->getSourceRange();
3844 }
3845
3847 const UsingPackDecl *getCanonicalDecl() const { return getFirstDecl(); }
3848
3849 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3850 static bool classofKind(Kind K) { return K == UsingPack; }
3851};
3852
3853/// Represents a dependent using declaration which was not marked with
3854/// \c typename.
3855///
3856/// Unlike non-dependent using declarations, these *only* bring through
3857/// non-types; otherwise they would break two-phase lookup.
3858///
3859/// \code
3860/// template <class T> class A : public Base<T> {
3861/// using Base<T>::foo;
3862/// };
3863/// \endcode
3865 public Mergeable<UnresolvedUsingValueDecl> {
3866 /// The source location of the 'using' keyword
3867 SourceLocation UsingLocation;
3868
3869 /// If this is a pack expansion, the location of the '...'.
3870 SourceLocation EllipsisLoc;
3871
3872 /// The nested-name-specifier that precedes the name.
3873 NestedNameSpecifierLoc QualifierLoc;
3874
3875 /// Provides source/type location info for the declaration name
3876 /// embedded in the ValueDecl base class.
3877 DeclarationNameLoc DNLoc;
3878
3880 SourceLocation UsingLoc,
3881 NestedNameSpecifierLoc QualifierLoc,
3882 const DeclarationNameInfo &NameInfo,
3883 SourceLocation EllipsisLoc)
3884 : ValueDecl(UnresolvedUsingValue, DC,
3885 NameInfo.getLoc(), NameInfo.getName(), Ty),
3886 UsingLocation(UsingLoc), EllipsisLoc(EllipsisLoc),
3887 QualifierLoc(QualifierLoc), DNLoc(NameInfo.getInfo()) {}
3888
3889 void anchor() override;
3890
3891public:
3892 friend class ASTDeclReader;
3893 friend class ASTDeclWriter;
3894
3895 /// Returns the source location of the 'using' keyword.
3896 SourceLocation getUsingLoc() const { return UsingLocation; }
3897
3898 /// Set the source location of the 'using' keyword.
3899 void setUsingLoc(SourceLocation L) { UsingLocation = L; }
3900
3901 /// Return true if it is a C++03 access declaration (no 'using').
3902 bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
3903
3904 /// Retrieve the nested-name-specifier that qualifies the name,
3905 /// with source-location information.
3906 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3907
3908 /// Retrieve the nested-name-specifier that qualifies the name.
3910 return QualifierLoc.getNestedNameSpecifier();
3911 }
3912
3914 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
3915 }
3916
3917 /// Determine whether this is a pack expansion.
3918 bool isPackExpansion() const {
3919 return EllipsisLoc.isValid();
3920 }
3921
3922 /// Get the location of the ellipsis if this is a pack expansion.
3924 return EllipsisLoc;
3925 }
3926
3929 NestedNameSpecifierLoc QualifierLoc,
3930 const DeclarationNameInfo &NameInfo, SourceLocation EllipsisLoc);
3931
3934
3935 SourceRange getSourceRange() const override LLVM_READONLY;
3936
3937 /// Retrieves the canonical declaration of this declaration.
3939 return getFirstDecl();
3940 }
3942 return getFirstDecl();
3943 }
3944
3945 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3946 static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
3947};
3948
3949/// Represents a dependent using declaration which was marked with
3950/// \c typename.
3951///
3952/// \code
3953/// template <class T> class A : public Base<T> {
3954/// using typename Base<T>::foo;
3955/// };
3956/// \endcode
3957///
3958/// The type associated with an unresolved using typename decl is
3959/// currently always a typename type.
3961 : public TypeDecl,
3962 public Mergeable<UnresolvedUsingTypenameDecl> {
3963 friend class ASTDeclReader;
3964
3965 /// The source location of the 'typename' keyword
3966 SourceLocation TypenameLocation;
3967
3968 /// If this is a pack expansion, the location of the '...'.
3969 SourceLocation EllipsisLoc;
3970
3971 /// The nested-name-specifier that precedes the name.
3972 NestedNameSpecifierLoc QualifierLoc;
3973
3975 SourceLocation TypenameLoc,
3976 NestedNameSpecifierLoc QualifierLoc,
3977 SourceLocation TargetNameLoc,
3978 IdentifierInfo *TargetName,
3979 SourceLocation EllipsisLoc)
3980 : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName,
3981 UsingLoc),
3982 TypenameLocation(TypenameLoc), EllipsisLoc(EllipsisLoc),
3983 QualifierLoc(QualifierLoc) {}
3984
3985 void anchor() override;
3986
3987public:
3988 /// Returns the source location of the 'using' keyword.
3990
3991 /// Returns the source location of the 'typename' keyword.
3992 SourceLocation getTypenameLoc() const { return TypenameLocation; }
3993
3994 /// Retrieve the nested-name-specifier that qualifies the name,
3995 /// with source-location information.
3996 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3997
3998 /// Retrieve the nested-name-specifier that qualifies the name.
4000 return QualifierLoc.getNestedNameSpecifier();
4001 }
4002
4005 }
4006
4007 /// Determine whether this is a pack expansion.
4008 bool isPackExpansion() const {
4009 return EllipsisLoc.isValid();
4010 }
4011
4012 /// Get the location of the ellipsis if this is a pack expansion.
4014 return EllipsisLoc;
4015 }
4016
4019 SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc,
4020 SourceLocation TargetNameLoc, DeclarationName TargetName,
4021 SourceLocation EllipsisLoc);
4022
4025
4026 /// Retrieves the canonical declaration of this declaration.
4028 return getFirstDecl();
4029 }
4031 return getFirstDecl();
4032 }
4033
4034 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4035 static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; }
4036};
4037
4038/// This node is generated when a using-declaration that was annotated with
4039/// __attribute__((using_if_exists)) failed to resolve to a known declaration.
4040/// In that case, Sema builds a UsingShadowDecl whose target is an instance of
4041/// this declaration, adding it to the current scope. Referring to this
4042/// declaration in any way is an error.
4045 DeclarationName Name);
4046
4047 void anchor() override;
4048
4049public:
4052 DeclarationName Name);
4055
4056 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4057 static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingIfExists; }
4058};
4059
4060/// Represents a C++11 static_assert declaration.
4061class StaticAssertDecl : public Decl {
4062 llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed;
4063 Expr *Message;
4064 SourceLocation RParenLoc;
4065
4066 StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc,
4067 Expr *AssertExpr, Expr *Message, SourceLocation RParenLoc,
4068 bool Failed)
4069 : Decl(StaticAssert, DC, StaticAssertLoc),
4070 AssertExprAndFailed(AssertExpr, Failed), Message(Message),
4071 RParenLoc(RParenLoc) {}
4072
4073 virtual void anchor();
4074
4075public:
4076 friend class ASTDeclReader;
4077
4079 SourceLocation StaticAssertLoc,
4080 Expr *AssertExpr, Expr *Message,
4081 SourceLocation RParenLoc, bool Failed);
4083
4084 Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); }
4085 const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); }
4086
4087 Expr *getMessage() { return Message; }
4088 const Expr *getMessage() const { return Message; }
4089
4090 bool isFailed() const { return AssertExprAndFailed.getInt(); }
4091
4092 SourceLocation getRParenLoc() const { return RParenLoc; }
4093
4094 SourceRange getSourceRange() const override LLVM_READONLY {
4096 }
4097
4098 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4099 static bool classofKind(Kind K) { return K == StaticAssert; }
4100};
4101
4102/// A binding in a decomposition declaration. For instance, given:
4103///
4104/// int n[3];
4105/// auto &[a, b, c] = n;
4106///
4107/// a, b, and c are BindingDecls, whose bindings are the expressions
4108/// x[0], x[1], and x[2] respectively, where x is the implicit
4109/// DecompositionDecl of type 'int (&)[3]'.
4110class BindingDecl : public ValueDecl {
4111 /// The declaration that this binding binds to part of.
4112 ValueDecl *Decomp;
4113 /// The binding represented by this declaration. References to this
4114 /// declaration are effectively equivalent to this expression (except
4115 /// that it is only evaluated once at the point of declaration of the
4116 /// binding).
4117 Expr *Binding = nullptr;
4118
4120 : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()) {}
4121
4122 void anchor() override;
4123
4124public:
4125 friend class ASTDeclReader;
4126
4130
4131 /// Get the expression to which this declaration is bound. This may be null
4132 /// in two different cases: while parsing the initializer for the
4133 /// decomposition declaration, and when the initializer is type-dependent.
4134 Expr *getBinding() const { return Binding; }
4135
4136 /// Get the decomposition declaration that this binding represents a
4137 /// decomposition of.
4138 ValueDecl *getDecomposedDecl() const { return Decomp; }
4139
4140 /// Get the variable (if any) that holds the value of evaluating the binding.
4141 /// Only present for user-defined bindings for tuple-like types.
4142 VarDecl *getHoldingVar() const;
4143
4144 /// Set the binding for this BindingDecl, along with its declared type (which
4145 /// should be a possibly-cv-qualified form of the type of the binding, or a
4146 /// reference to such a type).
4147 void setBinding(QualType DeclaredType, Expr *Binding) {
4148 setType(DeclaredType);
4149 this->Binding = Binding;
4150 }
4151
4152 /// Set the decomposed variable for this BindingDecl.
4153 void setDecomposedDecl(ValueDecl *Decomposed) { Decomp = Decomposed; }
4154
4155 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4156 static bool classofKind(Kind K) { return K == Decl::Binding; }
4157};
4158
4159/// A decomposition declaration. For instance, given:
4160///
4161/// int n[3];
4162/// auto &[a, b, c] = n;
4163///
4164/// the second line declares a DecompositionDecl of type 'int (&)[3]', and
4165/// three BindingDecls (named a, b, and c). An instance of this class is always
4166/// unnamed, but behaves in almost all other respects like a VarDecl.
4168 : public VarDecl,
4169 private llvm::TrailingObjects<DecompositionDecl, BindingDecl *> {
4170 /// The number of BindingDecl*s following this object.
4171 unsigned NumBindings;
4172
4174 SourceLocation LSquareLoc, QualType T,
4175 TypeSourceInfo *TInfo, StorageClass SC,
4177 : VarDecl(Decomposition, C, DC, StartLoc, LSquareLoc, nullptr, T, TInfo,
4178 SC),
4179 NumBindings(Bindings.size()) {
4180 std::uninitialized_copy(Bindings.begin(), Bindings.end(),
4181 getTrailingObjects<BindingDecl *>());
4182 for (auto *B : Bindings)
4183 B->setDecomposedDecl(this);
4184 }
4185
4186 void anchor() override;
4187
4188public:
4189 friend class ASTDeclReader;
4191
4193 SourceLocation StartLoc,
4194 SourceLocation LSquareLoc,
4195 QualType T, TypeSourceInfo *TInfo,
4196 StorageClass S,
4199 unsigned NumBindings);
4200
4202 return llvm::ArrayRef(getTrailingObjects<BindingDecl *>(), NumBindings);
4203 }
4204
4205 void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override;
4206
4207 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4208 static bool classofKind(Kind K) { return K == Decomposition; }
4209};
4210
4211/// An instance of this class represents the declaration of a property
4212/// member. This is a Microsoft extension to C++, first introduced in
4213/// Visual Studio .NET 2003 as a parallel to similar features in C#
4214/// and Managed C++.
4215///
4216/// A property must always be a non-static class member.
4217///
4218/// A property member superficially resembles a non-static data
4219/// member, except preceded by a property attribute:
4220/// __declspec(property(get=GetX, put=PutX)) int x;
4221/// Either (but not both) of the 'get' and 'put' names may be omitted.
4222///
4223/// A reference to a property is always an lvalue. If the lvalue
4224/// undergoes lvalue-to-rvalue conversion, then a getter name is
4225/// required, and that member is called with no arguments.
4226/// If the lvalue is assigned into, then a setter name is required,
4227/// and that member is called with one argument, the value assigned.
4228/// Both operations are potentially overloaded. Compound assignments
4229/// are permitted, as are the increment and decrement operators.
4230///
4231/// The getter and putter methods are permitted to be overloaded,
4232/// although their return and parameter types are subject to certain
4233/// restrictions according to the type of the property.
4234///
4235/// A property declared using an incomplete array type may
4236/// additionally be subscripted, adding extra parameters to the getter
4237/// and putter methods.
4239 IdentifierInfo *GetterId, *SetterId;
4240
4242 QualType T, TypeSourceInfo *TInfo, SourceLocation StartL,
4243 IdentifierInfo *Getter, IdentifierInfo *Setter)
4244 : DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL),
4245 GetterId(Getter), SetterId(Setter) {}
4246
4247 void anchor() override;
4248public:
4249 friend class ASTDeclReader;
4250
4253 TypeSourceInfo *TInfo, SourceLocation StartL,
4254 IdentifierInfo *Getter, IdentifierInfo *Setter);
4256
4257 static bool classof(const Decl *D) { return D->getKind() == MSProperty; }
4258
4259 bool hasGetter() const { return GetterId != nullptr; }
4260 IdentifierInfo* getGetterId() const { return GetterId; }
4261 bool hasSetter() const { return SetterId != nullptr; }
4262 IdentifierInfo* getSetterId() const { return SetterId; }
4263};
4264
4265/// Parts of a decomposed MSGuidDecl. Factored out to avoid unnecessary
4266/// dependencies on DeclCXX.h.
4268 /// {01234567-...
4269 uint32_t Part1;
4270 /// ...-89ab-...
4271 uint16_t Part2;
4272 /// ...-cdef-...
4273 uint16_t Part3;
4274 /// ...-0123-456789abcdef}
4275 uint8_t Part4And5[8];
4276
4277 uint64_t getPart4And5AsUint64() const {
4278 uint64_t Val;
4279 memcpy(&Val, &Part4And5, sizeof(Part4And5));
4280 return Val;
4281 }
4282};
4283
4284/// A global _GUID constant. These are implicitly created by UuidAttrs.
4285///
4286/// struct _declspec(uuid("01234567-89ab-cdef-0123-456789abcdef")) X{};
4287///
4288/// X is a CXXRecordDecl that contains a UuidAttr that references the (unique)
4289/// MSGuidDecl for the specified UUID.
4290class MSGuidDecl : public ValueDecl,
4291 public Mergeable<MSGuidDecl>,
4292 public llvm::FoldingSetNode {
4293public:
4295
4296private:
4297 /// The decomposed form of the UUID.
4298 Parts PartVal;
4299
4300 /// The resolved value of the UUID as an APValue. Computed on demand and
4301 /// cached.
4302 mutable APValue APVal;
4303
4304 void anchor() override;
4305
4307
4308 static MSGuidDecl *Create(const ASTContext &C, QualType T, Parts P);
4309 static MSGuidDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
4310
4311 // Only ASTContext::getMSGuidDecl and deserialization create these.
4312 friend class ASTContext;
4313 friend class ASTReader;
4314 friend class ASTDeclReader;
4315
4316public:
4317 /// Print this UUID in a human-readable format.
4318 void printName(llvm::raw_ostream &OS,
4319 const PrintingPolicy &Policy) const override;
4320
4321 /// Get the decomposed parts of this declaration.
4322 Parts getParts() const { return PartVal; }
4323
4324 /// Get the value of this MSGuidDecl as an APValue. This may fail and return
4325 /// an absent APValue if the type of the declaration is not of the expected
4326 /// shape.
4327 APValue &getAsAPValue() const;
4328
4329 static void Profile(llvm::FoldingSetNodeID &ID, Parts P) {
4330 ID.AddInteger(P.Part1);
4331 ID.AddInteger(P.Part2);
4332 ID.AddInteger(P.Part3);
4333 ID.AddInteger(P.getPart4And5AsUint64());
4334 }
4335 void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, PartVal); }
4336
4337 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4338 static bool classofKind(Kind K) { return K == Decl::MSGuid; }
4339};
4340
4341/// An artificial decl, representing a global anonymous constant value which is
4342/// uniquified by value within a translation unit.
4343///
4344/// These is currently only used to back the LValue returned by
4345/// __builtin_source_location, but could potentially be used for other similar
4346/// situations in the future.
4348 public Mergeable<UnnamedGlobalConstantDecl>,
4349 public llvm::FoldingSetNode {
4350
4351 // The constant value of this global.
4352 APValue Value;
4353
4354 void anchor() override;
4355
4357 const APValue &Val);
4358
4360 const APValue &APVal);
4361 static UnnamedGlobalConstantDecl *CreateDeserialized(ASTContext &C,
4363
4364 // Only ASTContext::getUnnamedGlobalConstantDecl and deserialization create
4365 // these.
4366 friend class ASTContext;
4367 friend class ASTReader;
4368 friend class ASTDeclReader;
4369
4370public:
4371 /// Print this in a human-readable format.
4372 void printName(llvm::raw_ostream &OS,
4373 const PrintingPolicy &Policy) const override;
4374
4375 const APValue &getValue() const { return Value; }
4376
4377 static void Profile(llvm::FoldingSetNodeID &ID, QualType Ty,
4378 const APValue &APVal) {
4379 Ty.Profile(ID);
4380 APVal.Profile(ID);
4381 }
4382 void Profile(llvm::FoldingSetNodeID &ID) {
4383 Profile(ID, getType(), getValue());
4384 }
4385
4386 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4387 static bool classofKind(Kind K) { return K == Decl::UnnamedGlobalConstant; }
4388};
4389
4390/// Insertion operator for diagnostics. This allows sending an AccessSpecifier
4391/// into a diagnostic with <<.
4392const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
4393 AccessSpecifier AS);
4394
4395} // namespace clang
4396
4397#endif // LLVM_CLANG_AST_DECLCXX_H
#define V(N, I)
Definition: ASTContext.h:3341
StringRef P
static char ID
Definition: Arena.cpp:183
const Decl * D
enum clang::sema::@1655::IndirectLocalPathEntry::EntryKind Kind
IndirectLocalPath & Path
const LambdaCapture * Capture
Expr * E
#define X(type, name)
Definition: Value.h:143
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the LambdaCapture class.
Defines several types used to describe C++ lambda expressions that are shared between the parser and ...
Defines the clang::LangOptions interface.
llvm::MachO::Target Target
Definition: MachO.h:51
Defines an enumeration for C++ overloaded operators.
uint32_t Id
Definition: SemaARM.cpp:1143
SourceRange Range
Definition: SemaObjC.cpp:757
SourceLocation Loc
Definition: SemaObjC.cpp:758
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
const NestedNameSpecifier * Specifier
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
void Profile(llvm::FoldingSetNodeID &ID) const
profile this value.
Definition: APValue.cpp:479
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:187
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:378
An object for streaming information to a record.
Writes an AST file containing the contents of a translation unit.
Definition: ASTWriter.h:89
Represents an access specifier followed by colon ':'.
Definition: DeclCXX.h:86
static AccessSpecDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: DeclCXX.cpp:60
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclCXX.h:113
static AccessSpecDecl * Create(ASTContext &C, AccessSpecifier AS, DeclContext *DC, SourceLocation ASLoc, SourceLocation ColonLoc)
Definition: DeclCXX.h:117
SourceLocation getColonLoc() const
The location of the colon following the access specifier.
Definition: DeclCXX.h:108
static bool classof(const Decl *D)
Definition: DeclCXX.h:126
static bool classofKind(Kind K)
Definition: DeclCXX.h:127
SourceLocation getAccessSpecifierLoc() const
The location of the access specifier.
Definition: DeclCXX.h:102
void setAccessSpecifierLoc(SourceLocation ASLoc)
Sets the location of the access specifier.
Definition: DeclCXX.h:105
void setColonLoc(SourceLocation CLoc)
Sets the location of the colon.
Definition: DeclCXX.h:111
Iterates through the using shadow declarations associated with this using declaration.
Definition: DeclCXX.h:3448
shadow_iterator & operator++()
Definition: DeclCXX.h:3465
std::forward_iterator_tag iterator_category
Definition: DeclCXX.h:3456
shadow_iterator(UsingShadowDecl *C)
Definition: DeclCXX.h:3460
friend bool operator==(shadow_iterator x, shadow_iterator y)
Definition: DeclCXX.h:3476
shadow_iterator operator++(int)
Definition: DeclCXX.h:3470
friend bool operator!=(shadow_iterator x, shadow_iterator y)
Definition: DeclCXX.h:3479
Represents a C++ declaration that introduces decls from somewhere else.
Definition: DeclCXX.h:3420
llvm::iterator_range< shadow_iterator > shadow_range
Definition: DeclCXX.h:3484
bool getShadowFlag() const
A bool flag for use by a derived type.
Definition: DeclCXX.h:3437
unsigned shadow_size() const
Return the number of shadowed declarations associated with this using declaration.
Definition: DeclCXX.h:3498
void addShadowDecl(UsingShadowDecl *S)
Definition: DeclCXX.cpp:3157
shadow_range shadows() const
Definition: DeclCXX.h:3486
shadow_iterator shadow_end() const
Definition: DeclCXX.h:3494
static bool classofKind(Kind K)
Definition: DeclCXX.h:3506
BaseUsingDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
Definition: DeclCXX.h:3429
shadow_iterator shadow_begin() const
Definition: DeclCXX.h:3490
void setShadowFlag(bool V)
A bool flag a derived type may set.
Definition: DeclCXX.h:3440
void removeShadowDecl(UsingShadowDecl *S)
Definition: DeclCXX.cpp:3166
static bool classof(const Decl *D)
Definition: DeclCXX.h:3505
A binding in a decomposition declaration.
Definition: DeclCXX.h:4110
VarDecl * getHoldingVar() const
Get the variable (if any) that holds the value of evaluating the binding.
Definition: DeclCXX.cpp:3360
ValueDecl * getDecomposedDecl() const
Get the decomposition declaration that this binding represents a decomposition of.
Definition: DeclCXX.h:4138
Expr * getBinding() const
Get the expression to which this declaration is bound.
Definition: DeclCXX.h:4134
static bool classof(const Decl *D)
Definition: DeclCXX.h:4155
void setBinding(QualType DeclaredType, Expr *Binding)
Set the binding for this BindingDecl, along with its declared type (which should be a possibly-cv-qua...
Definition: DeclCXX.h:4147
void setDecomposedDecl(ValueDecl *Decomposed)
Set the decomposed variable for this BindingDecl.
Definition: DeclCXX.h:4153
static BindingDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID)
Definition: DeclCXX.cpp:3356
static bool classofKind(Kind K)
Definition: DeclCXX.h:4156
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
void setInheritConstructors(bool Inherit=true)
Set that this base class's constructors should be inherited.
Definition: DeclCXX.h:216
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclCXX.h:194
AccessSpecifier getAccessSpecifierAsWritten() const
Retrieves the access specifier as written in the source code (which may mean that no access specifier...
Definition: DeclCXX.h:242
CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
Definition: DeclCXX.h:187
SourceLocation getEllipsisLoc() const
For a pack expansion, determine the location of the ellipsis.
Definition: DeclCXX.h:221
bool isVirtual() const
Determines whether the base class is a virtual base class (or not).
Definition: DeclCXX.h:203
QualType getType() const
Retrieves the type of the base class.
Definition: DeclCXX.h:249
TypeSourceInfo * getTypeSourceInfo() const
Retrieves the type and source location of the base class.
Definition: DeclCXX.h:254
bool getInheritConstructors() const
Determine whether this base class's constructors get inherited.
Definition: DeclCXX.h:213
bool isPackExpansion() const
Determine whether this base specifier is a pack expansion.
Definition: DeclCXX.h:210
SourceLocation getBaseTypeLoc() const LLVM_READONLY
Get the location at which the base class type was written.
Definition: DeclCXX.h:198
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclCXX.h:195
bool isBaseOfClass() const
Determine whether this base class is a base of a class declared with the 'class' keyword (vs.
Definition: DeclCXX.h:207
SourceRange getSourceRange() const LLVM_READONLY
Retrieves the source range that contains the entire base specifier.
Definition: DeclCXX.h:193
AccessSpecifier getAccessSpecifier() const
Returns the access specifier for this base specifier.
Definition: DeclCXX.h:230
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2538
init_const_iterator init_end() const
Retrieve an iterator past the last initializer.
Definition: DeclCXX.h:2648
init_iterator init_end()
Retrieve an iterator past the last initializer.
Definition: DeclCXX.h:2643
std::reverse_iterator< init_iterator > init_reverse_iterator
Definition: DeclCXX.h:2652
std::reverse_iterator< init_const_iterator > init_const_reverse_iterator
Definition: DeclCXX.h:2654
init_reverse_iterator init_rbegin()
Definition: DeclCXX.h:2656
CXXConstructorDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:2780
void setInheritingConstructor(bool isIC=true)
State that this is an implicit constructor synthesized to model a call to a constructor inherited fro...
Definition: DeclCXX.h:2770
bool isExplicit() const
Return true if the declaration is already resolved to be explicit.
Definition: DeclCXX.h:2617
ExplicitSpecifier getExplicitSpecifier()
Definition: DeclCXX.h:2609
init_iterator init_begin()
Retrieve an iterator to the first initializer.
Definition: DeclCXX.h:2634
CXXConstructorDecl * getTargetConstructor() const
When this constructor delegates to another, retrieve the target.
Definition: DeclCXX.cpp:2782
static bool classofKind(Kind K)
Definition: DeclCXX.h:2789
static CXXConstructorDecl * CreateDeserialized(ASTContext &C, GlobalDeclID ID, uint64_t AllocKind)
Definition: