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