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