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