1 //===--- DeclCXX.cpp - C++ Declaration AST Node Implementation ------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file implements the C++ related Decl classes. 11 // 12 //===----------------------------------------------------------------------===// 13 #include "clang/AST/DeclCXX.h" 14 #include "clang/AST/ASTContext.h" 15 #include "clang/AST/ASTLambda.h" 16 #include "clang/AST/ASTMutationListener.h" 17 #include "clang/AST/CXXInheritance.h" 18 #include "clang/AST/DeclTemplate.h" 19 #include "clang/AST/Expr.h" 20 #include "clang/AST/ExprCXX.h" 21 #include "clang/AST/TypeLoc.h" 22 #include "clang/Basic/IdentifierTable.h" 23 #include "llvm/ADT/STLExtras.h" 24 #include "llvm/ADT/SmallPtrSet.h" 25 using namespace clang; 26 27 //===----------------------------------------------------------------------===// 28 // Decl Allocation/Deallocation Method Implementations 29 //===----------------------------------------------------------------------===// 30 31 void AccessSpecDecl::anchor() { } 32 33 AccessSpecDecl *AccessSpecDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 34 return new (C, ID) AccessSpecDecl(EmptyShell()); 35 } 36 37 void LazyASTUnresolvedSet::getFromExternalSource(ASTContext &C) const { 38 ExternalASTSource *Source = C.getExternalSource(); 39 assert(Impl.Decls.isLazy() && "getFromExternalSource for non-lazy set"); 40 assert(Source && "getFromExternalSource with no external source"); 41 42 for (ASTUnresolvedSet::iterator I = Impl.begin(); I != Impl.end(); ++I) 43 I.setDecl(cast<NamedDecl>(Source->GetExternalDecl( 44 reinterpret_cast<uintptr_t>(I.getDecl()) >> 2))); 45 Impl.Decls.setLazy(false); 46 } 47 48 CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D) 49 : UserDeclaredConstructor(false), UserDeclaredSpecialMembers(0), 50 Aggregate(true), PlainOldData(true), Empty(true), Polymorphic(false), 51 Abstract(false), IsStandardLayout(true), HasNoNonEmptyBases(true), 52 HasPrivateFields(false), HasProtectedFields(false), 53 HasPublicFields(false), HasMutableFields(false), HasVariantMembers(false), 54 HasOnlyCMembers(true), HasInClassInitializer(false), 55 HasUninitializedReferenceMember(false), HasUninitializedFields(false), 56 HasInheritedConstructor(false), HasInheritedAssignment(false), 57 NeedOverloadResolutionForMoveConstructor(false), 58 NeedOverloadResolutionForMoveAssignment(false), 59 NeedOverloadResolutionForDestructor(false), 60 DefaultedMoveConstructorIsDeleted(false), 61 DefaultedMoveAssignmentIsDeleted(false), 62 DefaultedDestructorIsDeleted(false), HasTrivialSpecialMembers(SMF_All), 63 DeclaredNonTrivialSpecialMembers(0), HasIrrelevantDestructor(true), 64 HasConstexprNonCopyMoveConstructor(false), 65 HasDefaultedDefaultConstructor(false), 66 DefaultedDefaultConstructorIsConstexpr(true), 67 HasConstexprDefaultConstructor(false), 68 HasNonLiteralTypeFieldsOrBases(false), ComputedVisibleConversions(false), 69 UserProvidedDefaultConstructor(false), DeclaredSpecialMembers(0), 70 ImplicitCopyConstructorHasConstParam(true), 71 ImplicitCopyAssignmentHasConstParam(true), 72 HasDeclaredCopyConstructorWithConstParam(false), 73 HasDeclaredCopyAssignmentWithConstParam(false), IsLambda(false), 74 IsParsingBaseSpecifiers(false), NumBases(0), NumVBases(0), Bases(), 75 VBases(), Definition(D), FirstFriend() {} 76 77 CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getBasesSlowCase() const { 78 return Bases.get(Definition->getASTContext().getExternalSource()); 79 } 80 81 CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getVBasesSlowCase() const { 82 return VBases.get(Definition->getASTContext().getExternalSource()); 83 } 84 85 CXXRecordDecl::CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, 86 DeclContext *DC, SourceLocation StartLoc, 87 SourceLocation IdLoc, IdentifierInfo *Id, 88 CXXRecordDecl *PrevDecl) 89 : RecordDecl(K, TK, C, DC, StartLoc, IdLoc, Id, PrevDecl), 90 DefinitionData(PrevDecl ? PrevDecl->DefinitionData 91 : DefinitionDataPtr(this)), 92 TemplateOrInstantiation() {} 93 94 CXXRecordDecl *CXXRecordDecl::Create(const ASTContext &C, TagKind TK, 95 DeclContext *DC, SourceLocation StartLoc, 96 SourceLocation IdLoc, IdentifierInfo *Id, 97 CXXRecordDecl* PrevDecl, 98 bool DelayTypeCreation) { 99 CXXRecordDecl *R = new (C, DC) CXXRecordDecl(CXXRecord, TK, C, DC, StartLoc, 100 IdLoc, Id, PrevDecl); 101 R->MayHaveOutOfDateDef = C.getLangOpts().Modules; 102 103 // FIXME: DelayTypeCreation seems like such a hack 104 if (!DelayTypeCreation) 105 C.getTypeDeclType(R, PrevDecl); 106 return R; 107 } 108 109 CXXRecordDecl * 110 CXXRecordDecl::CreateLambda(const ASTContext &C, DeclContext *DC, 111 TypeSourceInfo *Info, SourceLocation Loc, 112 bool Dependent, bool IsGeneric, 113 LambdaCaptureDefault CaptureDefault) { 114 CXXRecordDecl *R = 115 new (C, DC) CXXRecordDecl(CXXRecord, TTK_Class, C, DC, Loc, Loc, 116 nullptr, nullptr); 117 R->IsBeingDefined = true; 118 R->DefinitionData = 119 new (C) struct LambdaDefinitionData(R, Info, Dependent, IsGeneric, 120 CaptureDefault); 121 R->MayHaveOutOfDateDef = false; 122 R->setImplicit(true); 123 C.getTypeDeclType(R, /*PrevDecl=*/nullptr); 124 return R; 125 } 126 127 CXXRecordDecl * 128 CXXRecordDecl::CreateDeserialized(const ASTContext &C, unsigned ID) { 129 CXXRecordDecl *R = new (C, ID) CXXRecordDecl( 130 CXXRecord, TTK_Struct, C, nullptr, SourceLocation(), SourceLocation(), 131 nullptr, nullptr); 132 R->MayHaveOutOfDateDef = false; 133 return R; 134 } 135 136 void 137 CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases, 138 unsigned NumBases) { 139 ASTContext &C = getASTContext(); 140 141 if (!data().Bases.isOffset() && data().NumBases > 0) 142 C.Deallocate(data().getBases()); 143 144 if (NumBases) { 145 if (!C.getLangOpts().CPlusPlus1z) { 146 // C++ [dcl.init.aggr]p1: 147 // An aggregate is [...] a class with [...] no base classes [...]. 148 data().Aggregate = false; 149 } 150 151 // C++ [class]p4: 152 // A POD-struct is an aggregate class... 153 data().PlainOldData = false; 154 } 155 156 // The set of seen virtual base types. 157 llvm::SmallPtrSet<CanQualType, 8> SeenVBaseTypes; 158 159 // The virtual bases of this class. 160 SmallVector<const CXXBaseSpecifier *, 8> VBases; 161 162 data().Bases = new(C) CXXBaseSpecifier [NumBases]; 163 data().NumBases = NumBases; 164 for (unsigned i = 0; i < NumBases; ++i) { 165 data().getBases()[i] = *Bases[i]; 166 // Keep track of inherited vbases for this base class. 167 const CXXBaseSpecifier *Base = Bases[i]; 168 QualType BaseType = Base->getType(); 169 // Skip dependent types; we can't do any checking on them now. 170 if (BaseType->isDependentType()) 171 continue; 172 CXXRecordDecl *BaseClassDecl 173 = cast<CXXRecordDecl>(BaseType->getAs<RecordType>()->getDecl()); 174 175 // A class with a non-empty base class is not empty. 176 // FIXME: Standard ref? 177 if (!BaseClassDecl->isEmpty()) { 178 if (!data().Empty) { 179 // C++0x [class]p7: 180 // A standard-layout class is a class that: 181 // [...] 182 // -- either has no non-static data members in the most derived 183 // class and at most one base class with non-static data members, 184 // or has no base classes with non-static data members, and 185 // If this is the second non-empty base, then neither of these two 186 // clauses can be true. 187 data().IsStandardLayout = false; 188 } 189 190 data().Empty = false; 191 data().HasNoNonEmptyBases = false; 192 } 193 194 // C++1z [dcl.init.agg]p1: 195 // An aggregate is a class with [...] no private or protected base classes 196 if (Base->getAccessSpecifier() != AS_public) 197 data().Aggregate = false; 198 199 // C++ [class.virtual]p1: 200 // A class that declares or inherits a virtual function is called a 201 // polymorphic class. 202 if (BaseClassDecl->isPolymorphic()) 203 data().Polymorphic = true; 204 205 // C++0x [class]p7: 206 // A standard-layout class is a class that: [...] 207 // -- has no non-standard-layout base classes 208 if (!BaseClassDecl->isStandardLayout()) 209 data().IsStandardLayout = false; 210 211 // Record if this base is the first non-literal field or base. 212 if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C)) 213 data().HasNonLiteralTypeFieldsOrBases = true; 214 215 // Now go through all virtual bases of this base and add them. 216 for (const auto &VBase : BaseClassDecl->vbases()) { 217 // Add this base if it's not already in the list. 218 if (SeenVBaseTypes.insert(C.getCanonicalType(VBase.getType())).second) { 219 VBases.push_back(&VBase); 220 221 // C++11 [class.copy]p8: 222 // The implicitly-declared copy constructor for a class X will have 223 // the form 'X::X(const X&)' if each [...] virtual base class B of X 224 // has a copy constructor whose first parameter is of type 225 // 'const B&' or 'const volatile B&' [...] 226 if (CXXRecordDecl *VBaseDecl = VBase.getType()->getAsCXXRecordDecl()) 227 if (!VBaseDecl->hasCopyConstructorWithConstParam()) 228 data().ImplicitCopyConstructorHasConstParam = false; 229 230 // C++1z [dcl.init.agg]p1: 231 // An aggregate is a class with [...] no virtual base classes 232 data().Aggregate = false; 233 } 234 } 235 236 if (Base->isVirtual()) { 237 // Add this base if it's not already in the list. 238 if (SeenVBaseTypes.insert(C.getCanonicalType(BaseType)).second) 239 VBases.push_back(Base); 240 241 // C++11 [meta.unary.prop] is_empty: 242 // T is a class type, but not a union type, with ... no virtual base 243 // classes 244 data().Empty = false; 245 246 // C++1z [dcl.init.agg]p1: 247 // An aggregate is a class with [...] no virtual base classes 248 data().Aggregate = false; 249 250 // C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25: 251 // A [default constructor, copy/move constructor, or copy/move assignment 252 // operator for a class X] is trivial [...] if: 253 // -- class X has [...] no virtual base classes 254 data().HasTrivialSpecialMembers &= SMF_Destructor; 255 256 // C++0x [class]p7: 257 // A standard-layout class is a class that: [...] 258 // -- has [...] no virtual base classes 259 data().IsStandardLayout = false; 260 261 // C++11 [dcl.constexpr]p4: 262 // In the definition of a constexpr constructor [...] 263 // -- the class shall not have any virtual base classes 264 data().DefaultedDefaultConstructorIsConstexpr = false; 265 } else { 266 // C++ [class.ctor]p5: 267 // A default constructor is trivial [...] if: 268 // -- all the direct base classes of its class have trivial default 269 // constructors. 270 if (!BaseClassDecl->hasTrivialDefaultConstructor()) 271 data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor; 272 273 // C++0x [class.copy]p13: 274 // A copy/move constructor for class X is trivial if [...] 275 // [...] 276 // -- the constructor selected to copy/move each direct base class 277 // subobject is trivial, and 278 if (!BaseClassDecl->hasTrivialCopyConstructor()) 279 data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor; 280 // If the base class doesn't have a simple move constructor, we'll eagerly 281 // declare it and perform overload resolution to determine which function 282 // it actually calls. If it does have a simple move constructor, this 283 // check is correct. 284 if (!BaseClassDecl->hasTrivialMoveConstructor()) 285 data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor; 286 287 // C++0x [class.copy]p27: 288 // A copy/move assignment operator for class X is trivial if [...] 289 // [...] 290 // -- the assignment operator selected to copy/move each direct base 291 // class subobject is trivial, and 292 if (!BaseClassDecl->hasTrivialCopyAssignment()) 293 data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment; 294 // If the base class doesn't have a simple move assignment, we'll eagerly 295 // declare it and perform overload resolution to determine which function 296 // it actually calls. If it does have a simple move assignment, this 297 // check is correct. 298 if (!BaseClassDecl->hasTrivialMoveAssignment()) 299 data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment; 300 301 // C++11 [class.ctor]p6: 302 // If that user-written default constructor would satisfy the 303 // requirements of a constexpr constructor, the implicitly-defined 304 // default constructor is constexpr. 305 if (!BaseClassDecl->hasConstexprDefaultConstructor()) 306 data().DefaultedDefaultConstructorIsConstexpr = false; 307 } 308 309 // C++ [class.ctor]p3: 310 // A destructor is trivial if all the direct base classes of its class 311 // have trivial destructors. 312 if (!BaseClassDecl->hasTrivialDestructor()) 313 data().HasTrivialSpecialMembers &= ~SMF_Destructor; 314 315 if (!BaseClassDecl->hasIrrelevantDestructor()) 316 data().HasIrrelevantDestructor = false; 317 318 // C++11 [class.copy]p18: 319 // The implicitly-declared copy assignment oeprator for a class X will 320 // have the form 'X& X::operator=(const X&)' if each direct base class B 321 // of X has a copy assignment operator whose parameter is of type 'const 322 // B&', 'const volatile B&', or 'B' [...] 323 if (!BaseClassDecl->hasCopyAssignmentWithConstParam()) 324 data().ImplicitCopyAssignmentHasConstParam = false; 325 326 // C++11 [class.copy]p8: 327 // The implicitly-declared copy constructor for a class X will have 328 // the form 'X::X(const X&)' if each direct [...] base class B of X 329 // has a copy constructor whose first parameter is of type 330 // 'const B&' or 'const volatile B&' [...] 331 if (!BaseClassDecl->hasCopyConstructorWithConstParam()) 332 data().ImplicitCopyConstructorHasConstParam = false; 333 334 // A class has an Objective-C object member if... or any of its bases 335 // has an Objective-C object member. 336 if (BaseClassDecl->hasObjectMember()) 337 setHasObjectMember(true); 338 339 if (BaseClassDecl->hasVolatileMember()) 340 setHasVolatileMember(true); 341 342 // Keep track of the presence of mutable fields. 343 if (BaseClassDecl->hasMutableFields()) 344 data().HasMutableFields = true; 345 346 if (BaseClassDecl->hasUninitializedReferenceMember()) 347 data().HasUninitializedReferenceMember = true; 348 349 if (!BaseClassDecl->allowConstDefaultInit()) 350 data().HasUninitializedFields = true; 351 352 addedClassSubobject(BaseClassDecl); 353 } 354 355 if (VBases.empty()) { 356 data().IsParsingBaseSpecifiers = false; 357 return; 358 } 359 360 // Create base specifier for any direct or indirect virtual bases. 361 data().VBases = new (C) CXXBaseSpecifier[VBases.size()]; 362 data().NumVBases = VBases.size(); 363 for (int I = 0, E = VBases.size(); I != E; ++I) { 364 QualType Type = VBases[I]->getType(); 365 if (!Type->isDependentType()) 366 addedClassSubobject(Type->getAsCXXRecordDecl()); 367 data().getVBases()[I] = *VBases[I]; 368 } 369 370 data().IsParsingBaseSpecifiers = false; 371 } 372 373 void CXXRecordDecl::addedClassSubobject(CXXRecordDecl *Subobj) { 374 // C++11 [class.copy]p11: 375 // A defaulted copy/move constructor for a class X is defined as 376 // deleted if X has: 377 // -- a direct or virtual base class B that cannot be copied/moved [...] 378 // -- a non-static data member of class type M (or array thereof) 379 // that cannot be copied or moved [...] 380 if (!Subobj->hasSimpleMoveConstructor()) 381 data().NeedOverloadResolutionForMoveConstructor = true; 382 383 // C++11 [class.copy]p23: 384 // A defaulted copy/move assignment operator for a class X is defined as 385 // deleted if X has: 386 // -- a direct or virtual base class B that cannot be copied/moved [...] 387 // -- a non-static data member of class type M (or array thereof) 388 // that cannot be copied or moved [...] 389 if (!Subobj->hasSimpleMoveAssignment()) 390 data().NeedOverloadResolutionForMoveAssignment = true; 391 392 // C++11 [class.ctor]p5, C++11 [class.copy]p11, C++11 [class.dtor]p5: 393 // A defaulted [ctor or dtor] for a class X is defined as 394 // deleted if X has: 395 // -- any direct or virtual base class [...] has a type with a destructor 396 // that is deleted or inaccessible from the defaulted [ctor or dtor]. 397 // -- any non-static data member has a type with a destructor 398 // that is deleted or inaccessible from the defaulted [ctor or dtor]. 399 if (!Subobj->hasSimpleDestructor()) { 400 data().NeedOverloadResolutionForMoveConstructor = true; 401 data().NeedOverloadResolutionForDestructor = true; 402 } 403 } 404 405 bool CXXRecordDecl::hasAnyDependentBases() const { 406 if (!isDependentContext()) 407 return false; 408 409 return !forallBases([](const CXXRecordDecl *) { return true; }); 410 } 411 412 bool CXXRecordDecl::isTriviallyCopyable() const { 413 // C++0x [class]p5: 414 // A trivially copyable class is a class that: 415 // -- has no non-trivial copy constructors, 416 if (hasNonTrivialCopyConstructor()) return false; 417 // -- has no non-trivial move constructors, 418 if (hasNonTrivialMoveConstructor()) return false; 419 // -- has no non-trivial copy assignment operators, 420 if (hasNonTrivialCopyAssignment()) return false; 421 // -- has no non-trivial move assignment operators, and 422 if (hasNonTrivialMoveAssignment()) return false; 423 // -- has a trivial destructor. 424 if (!hasTrivialDestructor()) return false; 425 426 return true; 427 } 428 429 void CXXRecordDecl::markedVirtualFunctionPure() { 430 // C++ [class.abstract]p2: 431 // A class is abstract if it has at least one pure virtual function. 432 data().Abstract = true; 433 } 434 435 void CXXRecordDecl::addedMember(Decl *D) { 436 if (!D->isImplicit() && 437 !isa<FieldDecl>(D) && 438 !isa<IndirectFieldDecl>(D) && 439 (!isa<TagDecl>(D) || cast<TagDecl>(D)->getTagKind() == TTK_Class || 440 cast<TagDecl>(D)->getTagKind() == TTK_Interface)) 441 data().HasOnlyCMembers = false; 442 443 // Ignore friends and invalid declarations. 444 if (D->getFriendObjectKind() || D->isInvalidDecl()) 445 return; 446 447 FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D); 448 if (FunTmpl) 449 D = FunTmpl->getTemplatedDecl(); 450 451 if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) { 452 if (Method->isVirtual()) { 453 // C++ [dcl.init.aggr]p1: 454 // An aggregate is an array or a class with [...] no virtual functions. 455 data().Aggregate = false; 456 457 // C++ [class]p4: 458 // A POD-struct is an aggregate class... 459 data().PlainOldData = false; 460 461 // Virtual functions make the class non-empty. 462 // FIXME: Standard ref? 463 data().Empty = false; 464 465 // C++ [class.virtual]p1: 466 // A class that declares or inherits a virtual function is called a 467 // polymorphic class. 468 data().Polymorphic = true; 469 470 // C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25: 471 // A [default constructor, copy/move constructor, or copy/move 472 // assignment operator for a class X] is trivial [...] if: 473 // -- class X has no virtual functions [...] 474 data().HasTrivialSpecialMembers &= SMF_Destructor; 475 476 // C++0x [class]p7: 477 // A standard-layout class is a class that: [...] 478 // -- has no virtual functions 479 data().IsStandardLayout = false; 480 } 481 } 482 483 // Notify the listener if an implicit member was added after the definition 484 // was completed. 485 if (!isBeingDefined() && D->isImplicit()) 486 if (ASTMutationListener *L = getASTMutationListener()) 487 L->AddedCXXImplicitMember(data().Definition, D); 488 489 // The kind of special member this declaration is, if any. 490 unsigned SMKind = 0; 491 492 // Handle constructors. 493 if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) { 494 if (!Constructor->isImplicit()) { 495 // Note that we have a user-declared constructor. 496 data().UserDeclaredConstructor = true; 497 498 // C++ [class]p4: 499 // A POD-struct is an aggregate class [...] 500 // Since the POD bit is meant to be C++03 POD-ness, clear it even if the 501 // type is technically an aggregate in C++0x since it wouldn't be in 03. 502 data().PlainOldData = false; 503 } 504 505 // Technically, "user-provided" is only defined for special member 506 // functions, but the intent of the standard is clearly that it should apply 507 // to all functions. 508 bool UserProvided = Constructor->isUserProvided(); 509 510 if (Constructor->isDefaultConstructor()) { 511 SMKind |= SMF_DefaultConstructor; 512 513 if (UserProvided) 514 data().UserProvidedDefaultConstructor = true; 515 if (Constructor->isConstexpr()) 516 data().HasConstexprDefaultConstructor = true; 517 if (Constructor->isDefaulted()) 518 data().HasDefaultedDefaultConstructor = true; 519 } 520 521 if (!FunTmpl) { 522 unsigned Quals; 523 if (Constructor->isCopyConstructor(Quals)) { 524 SMKind |= SMF_CopyConstructor; 525 526 if (Quals & Qualifiers::Const) 527 data().HasDeclaredCopyConstructorWithConstParam = true; 528 } else if (Constructor->isMoveConstructor()) 529 SMKind |= SMF_MoveConstructor; 530 } 531 532 // Record if we see any constexpr constructors which are neither copy 533 // nor move constructors. 534 if (Constructor->isConstexpr() && !Constructor->isCopyOrMoveConstructor()) 535 data().HasConstexprNonCopyMoveConstructor = true; 536 537 // C++ [dcl.init.aggr]p1: 538 // An aggregate is an array or a class with no user-declared 539 // constructors [...]. 540 // C++11 [dcl.init.aggr]p1: 541 // An aggregate is an array or a class with no user-provided 542 // constructors [...]. 543 if (getASTContext().getLangOpts().CPlusPlus11 544 ? UserProvided : !Constructor->isImplicit()) 545 data().Aggregate = false; 546 } 547 548 // Handle destructors. 549 if (CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(D)) { 550 SMKind |= SMF_Destructor; 551 552 if (DD->isUserProvided()) 553 data().HasIrrelevantDestructor = false; 554 // If the destructor is explicitly defaulted and not trivial or not public 555 // or if the destructor is deleted, we clear HasIrrelevantDestructor in 556 // finishedDefaultedOrDeletedMember. 557 558 // C++11 [class.dtor]p5: 559 // A destructor is trivial if [...] the destructor is not virtual. 560 if (DD->isVirtual()) 561 data().HasTrivialSpecialMembers &= ~SMF_Destructor; 562 } 563 564 // Handle member functions. 565 if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) { 566 if (Method->isCopyAssignmentOperator()) { 567 SMKind |= SMF_CopyAssignment; 568 569 const ReferenceType *ParamTy = 570 Method->getParamDecl(0)->getType()->getAs<ReferenceType>(); 571 if (!ParamTy || ParamTy->getPointeeType().isConstQualified()) 572 data().HasDeclaredCopyAssignmentWithConstParam = true; 573 } 574 575 if (Method->isMoveAssignmentOperator()) 576 SMKind |= SMF_MoveAssignment; 577 578 // Keep the list of conversion functions up-to-date. 579 if (CXXConversionDecl *Conversion = dyn_cast<CXXConversionDecl>(D)) { 580 // FIXME: We use the 'unsafe' accessor for the access specifier here, 581 // because Sema may not have set it yet. That's really just a misdesign 582 // in Sema. However, LLDB *will* have set the access specifier correctly, 583 // and adds declarations after the class is technically completed, 584 // so completeDefinition()'s overriding of the access specifiers doesn't 585 // work. 586 AccessSpecifier AS = Conversion->getAccessUnsafe(); 587 588 if (Conversion->getPrimaryTemplate()) { 589 // We don't record specializations. 590 } else { 591 ASTContext &Ctx = getASTContext(); 592 ASTUnresolvedSet &Conversions = data().Conversions.get(Ctx); 593 NamedDecl *Primary = 594 FunTmpl ? cast<NamedDecl>(FunTmpl) : cast<NamedDecl>(Conversion); 595 if (Primary->getPreviousDecl()) 596 Conversions.replace(cast<NamedDecl>(Primary->getPreviousDecl()), 597 Primary, AS); 598 else 599 Conversions.addDecl(Ctx, Primary, AS); 600 } 601 } 602 603 if (SMKind) { 604 // If this is the first declaration of a special member, we no longer have 605 // an implicit trivial special member. 606 data().HasTrivialSpecialMembers &= 607 data().DeclaredSpecialMembers | ~SMKind; 608 609 if (!Method->isImplicit() && !Method->isUserProvided()) { 610 // This method is user-declared but not user-provided. We can't work out 611 // whether it's trivial yet (not until we get to the end of the class). 612 // We'll handle this method in finishedDefaultedOrDeletedMember. 613 } else if (Method->isTrivial()) 614 data().HasTrivialSpecialMembers |= SMKind; 615 else 616 data().DeclaredNonTrivialSpecialMembers |= SMKind; 617 618 // Note when we have declared a declared special member, and suppress the 619 // implicit declaration of this special member. 620 data().DeclaredSpecialMembers |= SMKind; 621 622 if (!Method->isImplicit()) { 623 data().UserDeclaredSpecialMembers |= SMKind; 624 625 // C++03 [class]p4: 626 // A POD-struct is an aggregate class that has [...] no user-defined 627 // copy assignment operator and no user-defined destructor. 628 // 629 // Since the POD bit is meant to be C++03 POD-ness, and in C++03, 630 // aggregates could not have any constructors, clear it even for an 631 // explicitly defaulted or deleted constructor. 632 // type is technically an aggregate in C++0x since it wouldn't be in 03. 633 // 634 // Also, a user-declared move assignment operator makes a class non-POD. 635 // This is an extension in C++03. 636 data().PlainOldData = false; 637 } 638 } 639 640 return; 641 } 642 643 // Handle non-static data members. 644 if (FieldDecl *Field = dyn_cast<FieldDecl>(D)) { 645 // C++ [class.bit]p2: 646 // A declaration for a bit-field that omits the identifier declares an 647 // unnamed bit-field. Unnamed bit-fields are not members and cannot be 648 // initialized. 649 if (Field->isUnnamedBitfield()) 650 return; 651 652 // C++ [dcl.init.aggr]p1: 653 // An aggregate is an array or a class (clause 9) with [...] no 654 // private or protected non-static data members (clause 11). 655 // 656 // A POD must be an aggregate. 657 if (D->getAccess() == AS_private || D->getAccess() == AS_protected) { 658 data().Aggregate = false; 659 data().PlainOldData = false; 660 } 661 662 // C++0x [class]p7: 663 // A standard-layout class is a class that: 664 // [...] 665 // -- has the same access control for all non-static data members, 666 switch (D->getAccess()) { 667 case AS_private: data().HasPrivateFields = true; break; 668 case AS_protected: data().HasProtectedFields = true; break; 669 case AS_public: data().HasPublicFields = true; break; 670 case AS_none: llvm_unreachable("Invalid access specifier"); 671 }; 672 if ((data().HasPrivateFields + data().HasProtectedFields + 673 data().HasPublicFields) > 1) 674 data().IsStandardLayout = false; 675 676 // Keep track of the presence of mutable fields. 677 if (Field->isMutable()) 678 data().HasMutableFields = true; 679 680 // C++11 [class.union]p8, DR1460: 681 // If X is a union, a non-static data member of X that is not an anonymous 682 // union is a variant member of X. 683 if (isUnion() && !Field->isAnonymousStructOrUnion()) 684 data().HasVariantMembers = true; 685 686 // C++0x [class]p9: 687 // A POD struct is a class that is both a trivial class and a 688 // standard-layout class, and has no non-static data members of type 689 // non-POD struct, non-POD union (or array of such types). 690 // 691 // Automatic Reference Counting: the presence of a member of Objective-C pointer type 692 // that does not explicitly have no lifetime makes the class a non-POD. 693 ASTContext &Context = getASTContext(); 694 QualType T = Context.getBaseElementType(Field->getType()); 695 if (T->isObjCRetainableType() || T.isObjCGCStrong()) { 696 if (!Context.getLangOpts().ObjCAutoRefCount) { 697 setHasObjectMember(true); 698 } else if (T.getObjCLifetime() != Qualifiers::OCL_ExplicitNone) { 699 // Objective-C Automatic Reference Counting: 700 // If a class has a non-static data member of Objective-C pointer 701 // type (or array thereof), it is a non-POD type and its 702 // default constructor (if any), copy constructor, move constructor, 703 // copy assignment operator, move assignment operator, and destructor are 704 // non-trivial. 705 setHasObjectMember(true); 706 struct DefinitionData &Data = data(); 707 Data.PlainOldData = false; 708 Data.HasTrivialSpecialMembers = 0; 709 Data.HasIrrelevantDestructor = false; 710 } 711 } else if (!T.isCXX98PODType(Context)) 712 data().PlainOldData = false; 713 714 if (T->isReferenceType()) { 715 if (!Field->hasInClassInitializer()) 716 data().HasUninitializedReferenceMember = true; 717 718 // C++0x [class]p7: 719 // A standard-layout class is a class that: 720 // -- has no non-static data members of type [...] reference, 721 data().IsStandardLayout = false; 722 } 723 724 if (!Field->hasInClassInitializer() && !Field->isMutable()) { 725 if (CXXRecordDecl *FieldType = Field->getType()->getAsCXXRecordDecl()) { 726 if (FieldType->hasDefinition() && !FieldType->allowConstDefaultInit()) 727 data().HasUninitializedFields = true; 728 } else { 729 data().HasUninitializedFields = true; 730 } 731 } 732 733 // Record if this field is the first non-literal or volatile field or base. 734 if (!T->isLiteralType(Context) || T.isVolatileQualified()) 735 data().HasNonLiteralTypeFieldsOrBases = true; 736 737 if (Field->hasInClassInitializer() || 738 (Field->isAnonymousStructOrUnion() && 739 Field->getType()->getAsCXXRecordDecl()->hasInClassInitializer())) { 740 data().HasInClassInitializer = true; 741 742 // C++11 [class]p5: 743 // A default constructor is trivial if [...] no non-static data member 744 // of its class has a brace-or-equal-initializer. 745 data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor; 746 747 // C++11 [dcl.init.aggr]p1: 748 // An aggregate is a [...] class with [...] no 749 // brace-or-equal-initializers for non-static data members. 750 // 751 // This rule was removed in C++14. 752 if (!getASTContext().getLangOpts().CPlusPlus14) 753 data().Aggregate = false; 754 755 // C++11 [class]p10: 756 // A POD struct is [...] a trivial class. 757 data().PlainOldData = false; 758 } 759 760 // C++11 [class.copy]p23: 761 // A defaulted copy/move assignment operator for a class X is defined 762 // as deleted if X has: 763 // -- a non-static data member of reference type 764 if (T->isReferenceType()) 765 data().DefaultedMoveAssignmentIsDeleted = true; 766 767 if (const RecordType *RecordTy = T->getAs<RecordType>()) { 768 CXXRecordDecl* FieldRec = cast<CXXRecordDecl>(RecordTy->getDecl()); 769 if (FieldRec->getDefinition()) { 770 addedClassSubobject(FieldRec); 771 772 // We may need to perform overload resolution to determine whether a 773 // field can be moved if it's const or volatile qualified. 774 if (T.getCVRQualifiers() & (Qualifiers::Const | Qualifiers::Volatile)) { 775 data().NeedOverloadResolutionForMoveConstructor = true; 776 data().NeedOverloadResolutionForMoveAssignment = true; 777 } 778 779 // C++11 [class.ctor]p5, C++11 [class.copy]p11: 780 // A defaulted [special member] for a class X is defined as 781 // deleted if: 782 // -- X is a union-like class that has a variant member with a 783 // non-trivial [corresponding special member] 784 if (isUnion()) { 785 if (FieldRec->hasNonTrivialMoveConstructor()) 786 data().DefaultedMoveConstructorIsDeleted = true; 787 if (FieldRec->hasNonTrivialMoveAssignment()) 788 data().DefaultedMoveAssignmentIsDeleted = true; 789 if (FieldRec->hasNonTrivialDestructor()) 790 data().DefaultedDestructorIsDeleted = true; 791 } 792 793 // C++0x [class.ctor]p5: 794 // A default constructor is trivial [...] if: 795 // -- for all the non-static data members of its class that are of 796 // class type (or array thereof), each such class has a trivial 797 // default constructor. 798 if (!FieldRec->hasTrivialDefaultConstructor()) 799 data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor; 800 801 // C++0x [class.copy]p13: 802 // A copy/move constructor for class X is trivial if [...] 803 // [...] 804 // -- for each non-static data member of X that is of class type (or 805 // an array thereof), the constructor selected to copy/move that 806 // member is trivial; 807 if (!FieldRec->hasTrivialCopyConstructor()) 808 data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor; 809 // If the field doesn't have a simple move constructor, we'll eagerly 810 // declare the move constructor for this class and we'll decide whether 811 // it's trivial then. 812 if (!FieldRec->hasTrivialMoveConstructor()) 813 data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor; 814 815 // C++0x [class.copy]p27: 816 // A copy/move assignment operator for class X is trivial if [...] 817 // [...] 818 // -- for each non-static data member of X that is of class type (or 819 // an array thereof), the assignment operator selected to 820 // copy/move that member is trivial; 821 if (!FieldRec->hasTrivialCopyAssignment()) 822 data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment; 823 // If the field doesn't have a simple move assignment, we'll eagerly 824 // declare the move assignment for this class and we'll decide whether 825 // it's trivial then. 826 if (!FieldRec->hasTrivialMoveAssignment()) 827 data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment; 828 829 if (!FieldRec->hasTrivialDestructor()) 830 data().HasTrivialSpecialMembers &= ~SMF_Destructor; 831 if (!FieldRec->hasIrrelevantDestructor()) 832 data().HasIrrelevantDestructor = false; 833 if (FieldRec->hasObjectMember()) 834 setHasObjectMember(true); 835 if (FieldRec->hasVolatileMember()) 836 setHasVolatileMember(true); 837 838 // C++0x [class]p7: 839 // A standard-layout class is a class that: 840 // -- has no non-static data members of type non-standard-layout 841 // class (or array of such types) [...] 842 if (!FieldRec->isStandardLayout()) 843 data().IsStandardLayout = false; 844 845 // C++0x [class]p7: 846 // A standard-layout class is a class that: 847 // [...] 848 // -- has no base classes of the same type as the first non-static 849 // data member. 850 // We don't want to expend bits in the state of the record decl 851 // tracking whether this is the first non-static data member so we 852 // cheat a bit and use some of the existing state: the empty bit. 853 // Virtual bases and virtual methods make a class non-empty, but they 854 // also make it non-standard-layout so we needn't check here. 855 // A non-empty base class may leave the class standard-layout, but not 856 // if we have arrived here, and have at least one non-static data 857 // member. If IsStandardLayout remains true, then the first non-static 858 // data member must come through here with Empty still true, and Empty 859 // will subsequently be set to false below. 860 if (data().IsStandardLayout && data().Empty) { 861 for (const auto &BI : bases()) { 862 if (Context.hasSameUnqualifiedType(BI.getType(), T)) { 863 data().IsStandardLayout = false; 864 break; 865 } 866 } 867 } 868 869 // Keep track of the presence of mutable fields. 870 if (FieldRec->hasMutableFields()) 871 data().HasMutableFields = true; 872 873 // C++11 [class.copy]p13: 874 // If the implicitly-defined constructor would satisfy the 875 // requirements of a constexpr constructor, the implicitly-defined 876 // constructor is constexpr. 877 // C++11 [dcl.constexpr]p4: 878 // -- every constructor involved in initializing non-static data 879 // members [...] shall be a constexpr constructor 880 if (!Field->hasInClassInitializer() && 881 !FieldRec->hasConstexprDefaultConstructor() && !isUnion()) 882 // The standard requires any in-class initializer to be a constant 883 // expression. We consider this to be a defect. 884 data().DefaultedDefaultConstructorIsConstexpr = false; 885 886 // C++11 [class.copy]p8: 887 // The implicitly-declared copy constructor for a class X will have 888 // the form 'X::X(const X&)' if [...] for all the non-static data 889 // members of X that are of a class type M (or array thereof), each 890 // such class type has a copy constructor whose first parameter is 891 // of type 'const M&' or 'const volatile M&'. 892 if (!FieldRec->hasCopyConstructorWithConstParam()) 893 data().ImplicitCopyConstructorHasConstParam = false; 894 895 // C++11 [class.copy]p18: 896 // The implicitly-declared copy assignment oeprator for a class X will 897 // have the form 'X& X::operator=(const X&)' if [...] for all the 898 // non-static data members of X that are of a class type M (or array 899 // thereof), each such class type has a copy assignment operator whose 900 // parameter is of type 'const M&', 'const volatile M&' or 'M'. 901 if (!FieldRec->hasCopyAssignmentWithConstParam()) 902 data().ImplicitCopyAssignmentHasConstParam = false; 903 904 if (FieldRec->hasUninitializedReferenceMember() && 905 !Field->hasInClassInitializer()) 906 data().HasUninitializedReferenceMember = true; 907 908 // C++11 [class.union]p8, DR1460: 909 // a non-static data member of an anonymous union that is a member of 910 // X is also a variant member of X. 911 if (FieldRec->hasVariantMembers() && 912 Field->isAnonymousStructOrUnion()) 913 data().HasVariantMembers = true; 914 } 915 } else { 916 // Base element type of field is a non-class type. 917 if (!T->isLiteralType(Context) || 918 (!Field->hasInClassInitializer() && !isUnion())) 919 data().DefaultedDefaultConstructorIsConstexpr = false; 920 921 // C++11 [class.copy]p23: 922 // A defaulted copy/move assignment operator for a class X is defined 923 // as deleted if X has: 924 // -- a non-static data member of const non-class type (or array 925 // thereof) 926 if (T.isConstQualified()) 927 data().DefaultedMoveAssignmentIsDeleted = true; 928 } 929 930 // C++0x [class]p7: 931 // A standard-layout class is a class that: 932 // [...] 933 // -- either has no non-static data members in the most derived 934 // class and at most one base class with non-static data members, 935 // or has no base classes with non-static data members, and 936 // At this point we know that we have a non-static data member, so the last 937 // clause holds. 938 if (!data().HasNoNonEmptyBases) 939 data().IsStandardLayout = false; 940 941 // If this is not a zero-length bit-field, then the class is not empty. 942 if (data().Empty) { 943 if (!Field->isBitField() || 944 (!Field->getBitWidth()->isTypeDependent() && 945 !Field->getBitWidth()->isValueDependent() && 946 Field->getBitWidthValue(Context) != 0)) 947 data().Empty = false; 948 } 949 } 950 951 // Handle using declarations of conversion functions. 952 if (UsingShadowDecl *Shadow = dyn_cast<UsingShadowDecl>(D)) { 953 if (Shadow->getDeclName().getNameKind() 954 == DeclarationName::CXXConversionFunctionName) { 955 ASTContext &Ctx = getASTContext(); 956 data().Conversions.get(Ctx).addDecl(Ctx, Shadow, Shadow->getAccess()); 957 } 958 } 959 960 if (UsingDecl *Using = dyn_cast<UsingDecl>(D)) { 961 if (Using->getDeclName().getNameKind() == 962 DeclarationName::CXXConstructorName) 963 data().HasInheritedConstructor = true; 964 965 if (Using->getDeclName().getCXXOverloadedOperator() == OO_Equal) 966 data().HasInheritedAssignment = true; 967 } 968 } 969 970 void CXXRecordDecl::finishedDefaultedOrDeletedMember(CXXMethodDecl *D) { 971 assert(!D->isImplicit() && !D->isUserProvided()); 972 973 // The kind of special member this declaration is, if any. 974 unsigned SMKind = 0; 975 976 if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) { 977 if (Constructor->isDefaultConstructor()) { 978 SMKind |= SMF_DefaultConstructor; 979 if (Constructor->isConstexpr()) 980 data().HasConstexprDefaultConstructor = true; 981 } 982 if (Constructor->isCopyConstructor()) 983 SMKind |= SMF_CopyConstructor; 984 else if (Constructor->isMoveConstructor()) 985 SMKind |= SMF_MoveConstructor; 986 else if (Constructor->isConstexpr()) 987 // We may now know that the constructor is constexpr. 988 data().HasConstexprNonCopyMoveConstructor = true; 989 } else if (isa<CXXDestructorDecl>(D)) { 990 SMKind |= SMF_Destructor; 991 if (!D->isTrivial() || D->getAccess() != AS_public || D->isDeleted()) 992 data().HasIrrelevantDestructor = false; 993 } else if (D->isCopyAssignmentOperator()) 994 SMKind |= SMF_CopyAssignment; 995 else if (D->isMoveAssignmentOperator()) 996 SMKind |= SMF_MoveAssignment; 997 998 // Update which trivial / non-trivial special members we have. 999 // addedMember will have skipped this step for this member. 1000 if (D->isTrivial()) 1001 data().HasTrivialSpecialMembers |= SMKind; 1002 else 1003 data().DeclaredNonTrivialSpecialMembers |= SMKind; 1004 } 1005 1006 bool CXXRecordDecl::isCLike() const { 1007 if (getTagKind() == TTK_Class || getTagKind() == TTK_Interface || 1008 !TemplateOrInstantiation.isNull()) 1009 return false; 1010 if (!hasDefinition()) 1011 return true; 1012 1013 return isPOD() && data().HasOnlyCMembers; 1014 } 1015 1016 bool CXXRecordDecl::isGenericLambda() const { 1017 if (!isLambda()) return false; 1018 return getLambdaData().IsGenericLambda; 1019 } 1020 1021 CXXMethodDecl* CXXRecordDecl::getLambdaCallOperator() const { 1022 if (!isLambda()) return nullptr; 1023 DeclarationName Name = 1024 getASTContext().DeclarationNames.getCXXOperatorName(OO_Call); 1025 DeclContext::lookup_result Calls = lookup(Name); 1026 1027 assert(!Calls.empty() && "Missing lambda call operator!"); 1028 assert(Calls.size() == 1 && "More than one lambda call operator!"); 1029 1030 NamedDecl *CallOp = Calls.front(); 1031 if (FunctionTemplateDecl *CallOpTmpl = 1032 dyn_cast<FunctionTemplateDecl>(CallOp)) 1033 return cast<CXXMethodDecl>(CallOpTmpl->getTemplatedDecl()); 1034 1035 return cast<CXXMethodDecl>(CallOp); 1036 } 1037 1038 CXXMethodDecl* CXXRecordDecl::getLambdaStaticInvoker() const { 1039 if (!isLambda()) return nullptr; 1040 DeclarationName Name = 1041 &getASTContext().Idents.get(getLambdaStaticInvokerName()); 1042 DeclContext::lookup_result Invoker = lookup(Name); 1043 if (Invoker.empty()) return nullptr; 1044 assert(Invoker.size() == 1 && "More than one static invoker operator!"); 1045 NamedDecl *InvokerFun = Invoker.front(); 1046 if (FunctionTemplateDecl *InvokerTemplate = 1047 dyn_cast<FunctionTemplateDecl>(InvokerFun)) 1048 return cast<CXXMethodDecl>(InvokerTemplate->getTemplatedDecl()); 1049 1050 return cast<CXXMethodDecl>(InvokerFun); 1051 } 1052 1053 void CXXRecordDecl::getCaptureFields( 1054 llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures, 1055 FieldDecl *&ThisCapture) const { 1056 Captures.clear(); 1057 ThisCapture = nullptr; 1058 1059 LambdaDefinitionData &Lambda = getLambdaData(); 1060 RecordDecl::field_iterator Field = field_begin(); 1061 for (const LambdaCapture *C = Lambda.Captures, *CEnd = C + Lambda.NumCaptures; 1062 C != CEnd; ++C, ++Field) { 1063 if (C->capturesThis()) 1064 ThisCapture = *Field; 1065 else if (C->capturesVariable()) 1066 Captures[C->getCapturedVar()] = *Field; 1067 } 1068 assert(Field == field_end()); 1069 } 1070 1071 TemplateParameterList * 1072 CXXRecordDecl::getGenericLambdaTemplateParameterList() const { 1073 if (!isLambda()) return nullptr; 1074 CXXMethodDecl *CallOp = getLambdaCallOperator(); 1075 if (FunctionTemplateDecl *Tmpl = CallOp->getDescribedFunctionTemplate()) 1076 return Tmpl->getTemplateParameters(); 1077 return nullptr; 1078 } 1079 1080 static CanQualType GetConversionType(ASTContext &Context, NamedDecl *Conv) { 1081 QualType T = 1082 cast<CXXConversionDecl>(Conv->getUnderlyingDecl()->getAsFunction()) 1083 ->getConversionType(); 1084 return Context.getCanonicalType(T); 1085 } 1086 1087 /// Collect the visible conversions of a base class. 1088 /// 1089 /// \param Record a base class of the class we're considering 1090 /// \param InVirtual whether this base class is a virtual base (or a base 1091 /// of a virtual base) 1092 /// \param Access the access along the inheritance path to this base 1093 /// \param ParentHiddenTypes the conversions provided by the inheritors 1094 /// of this base 1095 /// \param Output the set to which to add conversions from non-virtual bases 1096 /// \param VOutput the set to which to add conversions from virtual bases 1097 /// \param HiddenVBaseCs the set of conversions which were hidden in a 1098 /// virtual base along some inheritance path 1099 static void CollectVisibleConversions(ASTContext &Context, 1100 CXXRecordDecl *Record, 1101 bool InVirtual, 1102 AccessSpecifier Access, 1103 const llvm::SmallPtrSet<CanQualType, 8> &ParentHiddenTypes, 1104 ASTUnresolvedSet &Output, 1105 UnresolvedSetImpl &VOutput, 1106 llvm::SmallPtrSet<NamedDecl*, 8> &HiddenVBaseCs) { 1107 // The set of types which have conversions in this class or its 1108 // subclasses. As an optimization, we don't copy the derived set 1109 // unless it might change. 1110 const llvm::SmallPtrSet<CanQualType, 8> *HiddenTypes = &ParentHiddenTypes; 1111 llvm::SmallPtrSet<CanQualType, 8> HiddenTypesBuffer; 1112 1113 // Collect the direct conversions and figure out which conversions 1114 // will be hidden in the subclasses. 1115 CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin(); 1116 CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end(); 1117 if (ConvI != ConvE) { 1118 HiddenTypesBuffer = ParentHiddenTypes; 1119 HiddenTypes = &HiddenTypesBuffer; 1120 1121 for (CXXRecordDecl::conversion_iterator I = ConvI; I != ConvE; ++I) { 1122 CanQualType ConvType(GetConversionType(Context, I.getDecl())); 1123 bool Hidden = ParentHiddenTypes.count(ConvType); 1124 if (!Hidden) 1125 HiddenTypesBuffer.insert(ConvType); 1126 1127 // If this conversion is hidden and we're in a virtual base, 1128 // remember that it's hidden along some inheritance path. 1129 if (Hidden && InVirtual) 1130 HiddenVBaseCs.insert(cast<NamedDecl>(I.getDecl()->getCanonicalDecl())); 1131 1132 // If this conversion isn't hidden, add it to the appropriate output. 1133 else if (!Hidden) { 1134 AccessSpecifier IAccess 1135 = CXXRecordDecl::MergeAccess(Access, I.getAccess()); 1136 1137 if (InVirtual) 1138 VOutput.addDecl(I.getDecl(), IAccess); 1139 else 1140 Output.addDecl(Context, I.getDecl(), IAccess); 1141 } 1142 } 1143 } 1144 1145 // Collect information recursively from any base classes. 1146 for (const auto &I : Record->bases()) { 1147 const RecordType *RT = I.getType()->getAs<RecordType>(); 1148 if (!RT) continue; 1149 1150 AccessSpecifier BaseAccess 1151 = CXXRecordDecl::MergeAccess(Access, I.getAccessSpecifier()); 1152 bool BaseInVirtual = InVirtual || I.isVirtual(); 1153 1154 CXXRecordDecl *Base = cast<CXXRecordDecl>(RT->getDecl()); 1155 CollectVisibleConversions(Context, Base, BaseInVirtual, BaseAccess, 1156 *HiddenTypes, Output, VOutput, HiddenVBaseCs); 1157 } 1158 } 1159 1160 /// Collect the visible conversions of a class. 1161 /// 1162 /// This would be extremely straightforward if it weren't for virtual 1163 /// bases. It might be worth special-casing that, really. 1164 static void CollectVisibleConversions(ASTContext &Context, 1165 CXXRecordDecl *Record, 1166 ASTUnresolvedSet &Output) { 1167 // The collection of all conversions in virtual bases that we've 1168 // found. These will be added to the output as long as they don't 1169 // appear in the hidden-conversions set. 1170 UnresolvedSet<8> VBaseCs; 1171 1172 // The set of conversions in virtual bases that we've determined to 1173 // be hidden. 1174 llvm::SmallPtrSet<NamedDecl*, 8> HiddenVBaseCs; 1175 1176 // The set of types hidden by classes derived from this one. 1177 llvm::SmallPtrSet<CanQualType, 8> HiddenTypes; 1178 1179 // Go ahead and collect the direct conversions and add them to the 1180 // hidden-types set. 1181 CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin(); 1182 CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end(); 1183 Output.append(Context, ConvI, ConvE); 1184 for (; ConvI != ConvE; ++ConvI) 1185 HiddenTypes.insert(GetConversionType(Context, ConvI.getDecl())); 1186 1187 // Recursively collect conversions from base classes. 1188 for (const auto &I : Record->bases()) { 1189 const RecordType *RT = I.getType()->getAs<RecordType>(); 1190 if (!RT) continue; 1191 1192 CollectVisibleConversions(Context, cast<CXXRecordDecl>(RT->getDecl()), 1193 I.isVirtual(), I.getAccessSpecifier(), 1194 HiddenTypes, Output, VBaseCs, HiddenVBaseCs); 1195 } 1196 1197 // Add any unhidden conversions provided by virtual bases. 1198 for (UnresolvedSetIterator I = VBaseCs.begin(), E = VBaseCs.end(); 1199 I != E; ++I) { 1200 if (!HiddenVBaseCs.count(cast<NamedDecl>(I.getDecl()->getCanonicalDecl()))) 1201 Output.addDecl(Context, I.getDecl(), I.getAccess()); 1202 } 1203 } 1204 1205 /// getVisibleConversionFunctions - get all conversion functions visible 1206 /// in current class; including conversion function templates. 1207 llvm::iterator_range<CXXRecordDecl::conversion_iterator> 1208 CXXRecordDecl::getVisibleConversionFunctions() { 1209 ASTContext &Ctx = getASTContext(); 1210 1211 ASTUnresolvedSet *Set; 1212 if (bases_begin() == bases_end()) { 1213 // If root class, all conversions are visible. 1214 Set = &data().Conversions.get(Ctx); 1215 } else { 1216 Set = &data().VisibleConversions.get(Ctx); 1217 // If visible conversion list is not evaluated, evaluate it. 1218 if (!data().ComputedVisibleConversions) { 1219 CollectVisibleConversions(Ctx, this, *Set); 1220 data().ComputedVisibleConversions = true; 1221 } 1222 } 1223 return llvm::make_range(Set->begin(), Set->end()); 1224 } 1225 1226 void CXXRecordDecl::removeConversion(const NamedDecl *ConvDecl) { 1227 // This operation is O(N) but extremely rare. Sema only uses it to 1228 // remove UsingShadowDecls in a class that were followed by a direct 1229 // declaration, e.g.: 1230 // class A : B { 1231 // using B::operator int; 1232 // operator int(); 1233 // }; 1234 // This is uncommon by itself and even more uncommon in conjunction 1235 // with sufficiently large numbers of directly-declared conversions 1236 // that asymptotic behavior matters. 1237 1238 ASTUnresolvedSet &Convs = data().Conversions.get(getASTContext()); 1239 for (unsigned I = 0, E = Convs.size(); I != E; ++I) { 1240 if (Convs[I].getDecl() == ConvDecl) { 1241 Convs.erase(I); 1242 assert(std::find(Convs.begin(), Convs.end(), ConvDecl) == Convs.end() 1243 && "conversion was found multiple times in unresolved set"); 1244 return; 1245 } 1246 } 1247 1248 llvm_unreachable("conversion not found in set!"); 1249 } 1250 1251 CXXRecordDecl *CXXRecordDecl::getInstantiatedFromMemberClass() const { 1252 if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) 1253 return cast<CXXRecordDecl>(MSInfo->getInstantiatedFrom()); 1254 1255 return nullptr; 1256 } 1257 1258 MemberSpecializationInfo *CXXRecordDecl::getMemberSpecializationInfo() const { 1259 return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>(); 1260 } 1261 1262 void 1263 CXXRecordDecl::setInstantiationOfMemberClass(CXXRecordDecl *RD, 1264 TemplateSpecializationKind TSK) { 1265 assert(TemplateOrInstantiation.isNull() && 1266 "Previous template or instantiation?"); 1267 assert(!isa<ClassTemplatePartialSpecializationDecl>(this)); 1268 TemplateOrInstantiation 1269 = new (getASTContext()) MemberSpecializationInfo(RD, TSK); 1270 } 1271 1272 ClassTemplateDecl *CXXRecordDecl::getDescribedClassTemplate() const { 1273 return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl *>(); 1274 } 1275 1276 void CXXRecordDecl::setDescribedClassTemplate(ClassTemplateDecl *Template) { 1277 TemplateOrInstantiation = Template; 1278 } 1279 1280 TemplateSpecializationKind CXXRecordDecl::getTemplateSpecializationKind() const{ 1281 if (const ClassTemplateSpecializationDecl *Spec 1282 = dyn_cast<ClassTemplateSpecializationDecl>(this)) 1283 return Spec->getSpecializationKind(); 1284 1285 if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) 1286 return MSInfo->getTemplateSpecializationKind(); 1287 1288 return TSK_Undeclared; 1289 } 1290 1291 void 1292 CXXRecordDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK) { 1293 if (ClassTemplateSpecializationDecl *Spec 1294 = dyn_cast<ClassTemplateSpecializationDecl>(this)) { 1295 Spec->setSpecializationKind(TSK); 1296 return; 1297 } 1298 1299 if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) { 1300 MSInfo->setTemplateSpecializationKind(TSK); 1301 return; 1302 } 1303 1304 llvm_unreachable("Not a class template or member class specialization"); 1305 } 1306 1307 const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const { 1308 // If it's a class template specialization, find the template or partial 1309 // specialization from which it was instantiated. 1310 if (auto *TD = dyn_cast<ClassTemplateSpecializationDecl>(this)) { 1311 auto From = TD->getInstantiatedFrom(); 1312 if (auto *CTD = From.dyn_cast<ClassTemplateDecl *>()) { 1313 while (auto *NewCTD = CTD->getInstantiatedFromMemberTemplate()) { 1314 if (NewCTD->isMemberSpecialization()) 1315 break; 1316 CTD = NewCTD; 1317 } 1318 return CTD->getTemplatedDecl()->getDefinition(); 1319 } 1320 if (auto *CTPSD = 1321 From.dyn_cast<ClassTemplatePartialSpecializationDecl *>()) { 1322 while (auto *NewCTPSD = CTPSD->getInstantiatedFromMember()) { 1323 if (NewCTPSD->isMemberSpecialization()) 1324 break; 1325 CTPSD = NewCTPSD; 1326 } 1327 return CTPSD->getDefinition(); 1328 } 1329 } 1330 1331 if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) { 1332 if (isTemplateInstantiation(MSInfo->getTemplateSpecializationKind())) { 1333 const CXXRecordDecl *RD = this; 1334 while (auto *NewRD = RD->getInstantiatedFromMemberClass()) 1335 RD = NewRD; 1336 return RD->getDefinition(); 1337 } 1338 } 1339 1340 assert(!isTemplateInstantiation(this->getTemplateSpecializationKind()) && 1341 "couldn't find pattern for class template instantiation"); 1342 return nullptr; 1343 } 1344 1345 CXXDestructorDecl *CXXRecordDecl::getDestructor() const { 1346 ASTContext &Context = getASTContext(); 1347 QualType ClassType = Context.getTypeDeclType(this); 1348 1349 DeclarationName Name 1350 = Context.DeclarationNames.getCXXDestructorName( 1351 Context.getCanonicalType(ClassType)); 1352 1353 DeclContext::lookup_result R = lookup(Name); 1354 if (R.empty()) 1355 return nullptr; 1356 1357 CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(R.front()); 1358 return Dtor; 1359 } 1360 1361 bool CXXRecordDecl::isAnyDestructorNoReturn() const { 1362 // Destructor is noreturn. 1363 if (const CXXDestructorDecl *Destructor = getDestructor()) 1364 if (Destructor->isNoReturn()) 1365 return true; 1366 1367 // Check base classes destructor for noreturn. 1368 for (const auto &Base : bases()) 1369 if (Base.getType()->getAsCXXRecordDecl()->isAnyDestructorNoReturn()) 1370 return true; 1371 1372 // Check fields for noreturn. 1373 for (const auto *Field : fields()) 1374 if (const CXXRecordDecl *RD = 1375 Field->getType()->getBaseElementTypeUnsafe()->getAsCXXRecordDecl()) 1376 if (RD->isAnyDestructorNoReturn()) 1377 return true; 1378 1379 // All destructors are not noreturn. 1380 return false; 1381 } 1382 1383 void CXXRecordDecl::completeDefinition() { 1384 completeDefinition(nullptr); 1385 } 1386 1387 void CXXRecordDecl::completeDefinition(CXXFinalOverriderMap *FinalOverriders) { 1388 RecordDecl::completeDefinition(); 1389 1390 // If the class may be abstract (but hasn't been marked as such), check for 1391 // any pure final overriders. 1392 if (mayBeAbstract()) { 1393 CXXFinalOverriderMap MyFinalOverriders; 1394 if (!FinalOverriders) { 1395 getFinalOverriders(MyFinalOverriders); 1396 FinalOverriders = &MyFinalOverriders; 1397 } 1398 1399 bool Done = false; 1400 for (CXXFinalOverriderMap::iterator M = FinalOverriders->begin(), 1401 MEnd = FinalOverriders->end(); 1402 M != MEnd && !Done; ++M) { 1403 for (OverridingMethods::iterator SO = M->second.begin(), 1404 SOEnd = M->second.end(); 1405 SO != SOEnd && !Done; ++SO) { 1406 assert(SO->second.size() > 0 && 1407 "All virtual functions have overridding virtual functions"); 1408 1409 // C++ [class.abstract]p4: 1410 // A class is abstract if it contains or inherits at least one 1411 // pure virtual function for which the final overrider is pure 1412 // virtual. 1413 if (SO->second.front().Method->isPure()) { 1414 data().Abstract = true; 1415 Done = true; 1416 break; 1417 } 1418 } 1419 } 1420 } 1421 1422 // Set access bits correctly on the directly-declared conversions. 1423 for (conversion_iterator I = conversion_begin(), E = conversion_end(); 1424 I != E; ++I) 1425 I.setAccess((*I)->getAccess()); 1426 } 1427 1428 bool CXXRecordDecl::mayBeAbstract() const { 1429 if (data().Abstract || isInvalidDecl() || !data().Polymorphic || 1430 isDependentContext()) 1431 return false; 1432 1433 for (const auto &B : bases()) { 1434 CXXRecordDecl *BaseDecl 1435 = cast<CXXRecordDecl>(B.getType()->getAs<RecordType>()->getDecl()); 1436 if (BaseDecl->isAbstract()) 1437 return true; 1438 } 1439 1440 return false; 1441 } 1442 1443 void CXXMethodDecl::anchor() { } 1444 1445 bool CXXMethodDecl::isStatic() const { 1446 const CXXMethodDecl *MD = getCanonicalDecl(); 1447 1448 if (MD->getStorageClass() == SC_Static) 1449 return true; 1450 1451 OverloadedOperatorKind OOK = getDeclName().getCXXOverloadedOperator(); 1452 return isStaticOverloadedOperator(OOK); 1453 } 1454 1455 static bool recursivelyOverrides(const CXXMethodDecl *DerivedMD, 1456 const CXXMethodDecl *BaseMD) { 1457 for (CXXMethodDecl::method_iterator I = DerivedMD->begin_overridden_methods(), 1458 E = DerivedMD->end_overridden_methods(); I != E; ++I) { 1459 const CXXMethodDecl *MD = *I; 1460 if (MD->getCanonicalDecl() == BaseMD->getCanonicalDecl()) 1461 return true; 1462 if (recursivelyOverrides(MD, BaseMD)) 1463 return true; 1464 } 1465 return false; 1466 } 1467 1468 CXXMethodDecl * 1469 CXXMethodDecl::getCorrespondingMethodInClass(const CXXRecordDecl *RD, 1470 bool MayBeBase) { 1471 if (this->getParent()->getCanonicalDecl() == RD->getCanonicalDecl()) 1472 return this; 1473 1474 // Lookup doesn't work for destructors, so handle them separately. 1475 if (isa<CXXDestructorDecl>(this)) { 1476 CXXMethodDecl *MD = RD->getDestructor(); 1477 if (MD) { 1478 if (recursivelyOverrides(MD, this)) 1479 return MD; 1480 if (MayBeBase && recursivelyOverrides(this, MD)) 1481 return MD; 1482 } 1483 return nullptr; 1484 } 1485 1486 for (auto *ND : RD->lookup(getDeclName())) { 1487 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(ND); 1488 if (!MD) 1489 continue; 1490 if (recursivelyOverrides(MD, this)) 1491 return MD; 1492 if (MayBeBase && recursivelyOverrides(this, MD)) 1493 return MD; 1494 } 1495 1496 for (const auto &I : RD->bases()) { 1497 const RecordType *RT = I.getType()->getAs<RecordType>(); 1498 if (!RT) 1499 continue; 1500 const CXXRecordDecl *Base = cast<CXXRecordDecl>(RT->getDecl()); 1501 CXXMethodDecl *T = this->getCorrespondingMethodInClass(Base); 1502 if (T) 1503 return T; 1504 } 1505 1506 return nullptr; 1507 } 1508 1509 CXXMethodDecl * 1510 CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, 1511 SourceLocation StartLoc, 1512 const DeclarationNameInfo &NameInfo, 1513 QualType T, TypeSourceInfo *TInfo, 1514 StorageClass SC, bool isInline, 1515 bool isConstexpr, SourceLocation EndLocation) { 1516 return new (C, RD) CXXMethodDecl(CXXMethod, C, RD, StartLoc, NameInfo, 1517 T, TInfo, SC, isInline, isConstexpr, 1518 EndLocation); 1519 } 1520 1521 CXXMethodDecl *CXXMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 1522 return new (C, ID) CXXMethodDecl(CXXMethod, C, nullptr, SourceLocation(), 1523 DeclarationNameInfo(), QualType(), nullptr, 1524 SC_None, false, false, SourceLocation()); 1525 } 1526 1527 bool CXXMethodDecl::isUsualDeallocationFunction() const { 1528 if (getOverloadedOperator() != OO_Delete && 1529 getOverloadedOperator() != OO_Array_Delete) 1530 return false; 1531 1532 // C++ [basic.stc.dynamic.deallocation]p2: 1533 // A template instance is never a usual deallocation function, 1534 // regardless of its signature. 1535 if (getPrimaryTemplate()) 1536 return false; 1537 1538 // C++ [basic.stc.dynamic.deallocation]p2: 1539 // If a class T has a member deallocation function named operator delete 1540 // with exactly one parameter, then that function is a usual (non-placement) 1541 // deallocation function. [...] 1542 if (getNumParams() == 1) 1543 return true; 1544 1545 // C++ [basic.stc.dynamic.deallocation]p2: 1546 // [...] If class T does not declare such an operator delete but does 1547 // declare a member deallocation function named operator delete with 1548 // exactly two parameters, the second of which has type std::size_t (18.1), 1549 // then this function is a usual deallocation function. 1550 ASTContext &Context = getASTContext(); 1551 if (getNumParams() != 2 || 1552 !Context.hasSameUnqualifiedType(getParamDecl(1)->getType(), 1553 Context.getSizeType())) 1554 return false; 1555 1556 // This function is a usual deallocation function if there are no 1557 // single-parameter deallocation functions of the same kind. 1558 DeclContext::lookup_result R = getDeclContext()->lookup(getDeclName()); 1559 for (DeclContext::lookup_result::iterator I = R.begin(), E = R.end(); 1560 I != E; ++I) { 1561 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*I)) 1562 if (FD->getNumParams() == 1) 1563 return false; 1564 } 1565 1566 return true; 1567 } 1568 1569 bool CXXMethodDecl::isCopyAssignmentOperator() const { 1570 // C++0x [class.copy]p17: 1571 // A user-declared copy assignment operator X::operator= is a non-static 1572 // non-template member function of class X with exactly one parameter of 1573 // type X, X&, const X&, volatile X& or const volatile X&. 1574 if (/*operator=*/getOverloadedOperator() != OO_Equal || 1575 /*non-static*/ isStatic() || 1576 /*non-template*/getPrimaryTemplate() || getDescribedFunctionTemplate() || 1577 getNumParams() != 1) 1578 return false; 1579 1580 QualType ParamType = getParamDecl(0)->getType(); 1581 if (const LValueReferenceType *Ref = ParamType->getAs<LValueReferenceType>()) 1582 ParamType = Ref->getPointeeType(); 1583 1584 ASTContext &Context = getASTContext(); 1585 QualType ClassType 1586 = Context.getCanonicalType(Context.getTypeDeclType(getParent())); 1587 return Context.hasSameUnqualifiedType(ClassType, ParamType); 1588 } 1589 1590 bool CXXMethodDecl::isMoveAssignmentOperator() const { 1591 // C++0x [class.copy]p19: 1592 // A user-declared move assignment operator X::operator= is a non-static 1593 // non-template member function of class X with exactly one parameter of type 1594 // X&&, const X&&, volatile X&&, or const volatile X&&. 1595 if (getOverloadedOperator() != OO_Equal || isStatic() || 1596 getPrimaryTemplate() || getDescribedFunctionTemplate() || 1597 getNumParams() != 1) 1598 return false; 1599 1600 QualType ParamType = getParamDecl(0)->getType(); 1601 if (!isa<RValueReferenceType>(ParamType)) 1602 return false; 1603 ParamType = ParamType->getPointeeType(); 1604 1605 ASTContext &Context = getASTContext(); 1606 QualType ClassType 1607 = Context.getCanonicalType(Context.getTypeDeclType(getParent())); 1608 return Context.hasSameUnqualifiedType(ClassType, ParamType); 1609 } 1610 1611 void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) { 1612 assert(MD->isCanonicalDecl() && "Method is not canonical!"); 1613 assert(!MD->getParent()->isDependentContext() && 1614 "Can't add an overridden method to a class template!"); 1615 assert(MD->isVirtual() && "Method is not virtual!"); 1616 1617 getASTContext().addOverriddenMethod(this, MD); 1618 } 1619 1620 CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const { 1621 if (isa<CXXConstructorDecl>(this)) return nullptr; 1622 return getASTContext().overridden_methods_begin(this); 1623 } 1624 1625 CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const { 1626 if (isa<CXXConstructorDecl>(this)) return nullptr; 1627 return getASTContext().overridden_methods_end(this); 1628 } 1629 1630 unsigned CXXMethodDecl::size_overridden_methods() const { 1631 if (isa<CXXConstructorDecl>(this)) return 0; 1632 return getASTContext().overridden_methods_size(this); 1633 } 1634 1635 QualType CXXMethodDecl::getThisType(ASTContext &C) const { 1636 // C++ 9.3.2p1: The type of this in a member function of a class X is X*. 1637 // If the member function is declared const, the type of this is const X*, 1638 // if the member function is declared volatile, the type of this is 1639 // volatile X*, and if the member function is declared const volatile, 1640 // the type of this is const volatile X*. 1641 1642 assert(isInstance() && "No 'this' for static methods!"); 1643 1644 QualType ClassTy = C.getTypeDeclType(getParent()); 1645 ClassTy = C.getQualifiedType(ClassTy, 1646 Qualifiers::fromCVRMask(getTypeQualifiers())); 1647 return C.getPointerType(ClassTy); 1648 } 1649 1650 bool CXXMethodDecl::hasInlineBody() const { 1651 // If this function is a template instantiation, look at the template from 1652 // which it was instantiated. 1653 const FunctionDecl *CheckFn = getTemplateInstantiationPattern(); 1654 if (!CheckFn) 1655 CheckFn = this; 1656 1657 const FunctionDecl *fn; 1658 return CheckFn->hasBody(fn) && !fn->isOutOfLine(); 1659 } 1660 1661 bool CXXMethodDecl::isLambdaStaticInvoker() const { 1662 const CXXRecordDecl *P = getParent(); 1663 if (P->isLambda()) { 1664 if (const CXXMethodDecl *StaticInvoker = P->getLambdaStaticInvoker()) { 1665 if (StaticInvoker == this) return true; 1666 if (P->isGenericLambda() && this->isFunctionTemplateSpecialization()) 1667 return StaticInvoker == this->getPrimaryTemplate()->getTemplatedDecl(); 1668 } 1669 } 1670 return false; 1671 } 1672 1673 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, 1674 TypeSourceInfo *TInfo, bool IsVirtual, 1675 SourceLocation L, Expr *Init, 1676 SourceLocation R, 1677 SourceLocation EllipsisLoc) 1678 : Initializee(TInfo), MemberOrEllipsisLocation(EllipsisLoc), Init(Init), 1679 LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(IsVirtual), 1680 IsWritten(false), SourceOrderOrNumArrayIndices(0) 1681 { 1682 } 1683 1684 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, 1685 FieldDecl *Member, 1686 SourceLocation MemberLoc, 1687 SourceLocation L, Expr *Init, 1688 SourceLocation R) 1689 : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), 1690 LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false), 1691 IsWritten(false), SourceOrderOrNumArrayIndices(0) 1692 { 1693 } 1694 1695 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, 1696 IndirectFieldDecl *Member, 1697 SourceLocation MemberLoc, 1698 SourceLocation L, Expr *Init, 1699 SourceLocation R) 1700 : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), 1701 LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false), 1702 IsWritten(false), SourceOrderOrNumArrayIndices(0) 1703 { 1704 } 1705 1706 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, 1707 TypeSourceInfo *TInfo, 1708 SourceLocation L, Expr *Init, 1709 SourceLocation R) 1710 : Initializee(TInfo), MemberOrEllipsisLocation(), Init(Init), 1711 LParenLoc(L), RParenLoc(R), IsDelegating(true), IsVirtual(false), 1712 IsWritten(false), SourceOrderOrNumArrayIndices(0) 1713 { 1714 } 1715 1716 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, 1717 FieldDecl *Member, 1718 SourceLocation MemberLoc, 1719 SourceLocation L, Expr *Init, 1720 SourceLocation R, 1721 VarDecl **Indices, 1722 unsigned NumIndices) 1723 : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), 1724 LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false), 1725 IsWritten(false), SourceOrderOrNumArrayIndices(NumIndices) 1726 { 1727 std::uninitialized_copy(Indices, Indices + NumIndices, 1728 getTrailingObjects<VarDecl *>()); 1729 } 1730 1731 CXXCtorInitializer *CXXCtorInitializer::Create(ASTContext &Context, 1732 FieldDecl *Member, 1733 SourceLocation MemberLoc, 1734 SourceLocation L, Expr *Init, 1735 SourceLocation R, 1736 VarDecl **Indices, 1737 unsigned NumIndices) { 1738 void *Mem = Context.Allocate(totalSizeToAlloc<VarDecl *>(NumIndices), 1739 llvm::alignOf<CXXCtorInitializer>()); 1740 return new (Mem) CXXCtorInitializer(Context, Member, MemberLoc, L, Init, R, 1741 Indices, NumIndices); 1742 } 1743 1744 TypeLoc CXXCtorInitializer::getBaseClassLoc() const { 1745 if (isBaseInitializer()) 1746 return Initializee.get<TypeSourceInfo*>()->getTypeLoc(); 1747 else 1748 return TypeLoc(); 1749 } 1750 1751 const Type *CXXCtorInitializer::getBaseClass() const { 1752 if (isBaseInitializer()) 1753 return Initializee.get<TypeSourceInfo*>()->getType().getTypePtr(); 1754 else 1755 return nullptr; 1756 } 1757 1758 SourceLocation CXXCtorInitializer::getSourceLocation() const { 1759 if (isInClassMemberInitializer()) 1760 return getAnyMember()->getLocation(); 1761 1762 if (isAnyMemberInitializer()) 1763 return getMemberLocation(); 1764 1765 if (TypeSourceInfo *TSInfo = Initializee.get<TypeSourceInfo*>()) 1766 return TSInfo->getTypeLoc().getLocalSourceRange().getBegin(); 1767 1768 return SourceLocation(); 1769 } 1770 1771 SourceRange CXXCtorInitializer::getSourceRange() const { 1772 if (isInClassMemberInitializer()) { 1773 FieldDecl *D = getAnyMember(); 1774 if (Expr *I = D->getInClassInitializer()) 1775 return I->getSourceRange(); 1776 return SourceRange(); 1777 } 1778 1779 return SourceRange(getSourceLocation(), getRParenLoc()); 1780 } 1781 1782 void CXXConstructorDecl::anchor() { } 1783 1784 CXXConstructorDecl * 1785 CXXConstructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 1786 return new (C, ID) CXXConstructorDecl(C, nullptr, SourceLocation(), 1787 DeclarationNameInfo(), QualType(), 1788 nullptr, false, false, false, false); 1789 } 1790 1791 CXXConstructorDecl * 1792 CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, 1793 SourceLocation StartLoc, 1794 const DeclarationNameInfo &NameInfo, 1795 QualType T, TypeSourceInfo *TInfo, 1796 bool isExplicit, bool isInline, 1797 bool isImplicitlyDeclared, bool isConstexpr) { 1798 assert(NameInfo.getName().getNameKind() 1799 == DeclarationName::CXXConstructorName && 1800 "Name must refer to a constructor"); 1801 return new (C, RD) CXXConstructorDecl(C, RD, StartLoc, NameInfo, T, TInfo, 1802 isExplicit, isInline, 1803 isImplicitlyDeclared, isConstexpr); 1804 } 1805 1806 CXXConstructorDecl::init_const_iterator CXXConstructorDecl::init_begin() const { 1807 return CtorInitializers.get(getASTContext().getExternalSource()); 1808 } 1809 1810 CXXConstructorDecl *CXXConstructorDecl::getTargetConstructor() const { 1811 assert(isDelegatingConstructor() && "Not a delegating constructor!"); 1812 Expr *E = (*init_begin())->getInit()->IgnoreImplicit(); 1813 if (CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(E)) 1814 return Construct->getConstructor(); 1815 1816 return nullptr; 1817 } 1818 1819 bool CXXConstructorDecl::isDefaultConstructor() const { 1820 // C++ [class.ctor]p5: 1821 // A default constructor for a class X is a constructor of class 1822 // X that can be called without an argument. 1823 return (getNumParams() == 0) || 1824 (getNumParams() > 0 && getParamDecl(0)->hasDefaultArg()); 1825 } 1826 1827 bool 1828 CXXConstructorDecl::isCopyConstructor(unsigned &TypeQuals) const { 1829 return isCopyOrMoveConstructor(TypeQuals) && 1830 getParamDecl(0)->getType()->isLValueReferenceType(); 1831 } 1832 1833 bool CXXConstructorDecl::isMoveConstructor(unsigned &TypeQuals) const { 1834 return isCopyOrMoveConstructor(TypeQuals) && 1835 getParamDecl(0)->getType()->isRValueReferenceType(); 1836 } 1837 1838 /// \brief Determine whether this is a copy or move constructor. 1839 bool CXXConstructorDecl::isCopyOrMoveConstructor(unsigned &TypeQuals) const { 1840 // C++ [class.copy]p2: 1841 // A non-template constructor for class X is a copy constructor 1842 // if its first parameter is of type X&, const X&, volatile X& or 1843 // const volatile X&, and either there are no other parameters 1844 // or else all other parameters have default arguments (8.3.6). 1845 // C++0x [class.copy]p3: 1846 // A non-template constructor for class X is a move constructor if its 1847 // first parameter is of type X&&, const X&&, volatile X&&, or 1848 // const volatile X&&, and either there are no other parameters or else 1849 // all other parameters have default arguments. 1850 if ((getNumParams() < 1) || 1851 (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) || 1852 (getPrimaryTemplate() != nullptr) || 1853 (getDescribedFunctionTemplate() != nullptr)) 1854 return false; 1855 1856 const ParmVarDecl *Param = getParamDecl(0); 1857 1858 // Do we have a reference type? 1859 const ReferenceType *ParamRefType = Param->getType()->getAs<ReferenceType>(); 1860 if (!ParamRefType) 1861 return false; 1862 1863 // Is it a reference to our class type? 1864 ASTContext &Context = getASTContext(); 1865 1866 CanQualType PointeeType 1867 = Context.getCanonicalType(ParamRefType->getPointeeType()); 1868 CanQualType ClassTy 1869 = Context.getCanonicalType(Context.getTagDeclType(getParent())); 1870 if (PointeeType.getUnqualifiedType() != ClassTy) 1871 return false; 1872 1873 // FIXME: other qualifiers? 1874 1875 // We have a copy or move constructor. 1876 TypeQuals = PointeeType.getCVRQualifiers(); 1877 return true; 1878 } 1879 1880 bool CXXConstructorDecl::isConvertingConstructor(bool AllowExplicit) const { 1881 // C++ [class.conv.ctor]p1: 1882 // A constructor declared without the function-specifier explicit 1883 // that can be called with a single parameter specifies a 1884 // conversion from the type of its first parameter to the type of 1885 // its class. Such a constructor is called a converting 1886 // constructor. 1887 if (isExplicit() && !AllowExplicit) 1888 return false; 1889 1890 return (getNumParams() == 0 && 1891 getType()->getAs<FunctionProtoType>()->isVariadic()) || 1892 (getNumParams() == 1) || 1893 (getNumParams() > 1 && 1894 (getParamDecl(1)->hasDefaultArg() || 1895 getParamDecl(1)->isParameterPack())); 1896 } 1897 1898 bool CXXConstructorDecl::isSpecializationCopyingObject() const { 1899 if ((getNumParams() < 1) || 1900 (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) || 1901 (getDescribedFunctionTemplate() != nullptr)) 1902 return false; 1903 1904 const ParmVarDecl *Param = getParamDecl(0); 1905 1906 ASTContext &Context = getASTContext(); 1907 CanQualType ParamType = Context.getCanonicalType(Param->getType()); 1908 1909 // Is it the same as our our class type? 1910 CanQualType ClassTy 1911 = Context.getCanonicalType(Context.getTagDeclType(getParent())); 1912 if (ParamType.getUnqualifiedType() != ClassTy) 1913 return false; 1914 1915 return true; 1916 } 1917 1918 const CXXConstructorDecl *CXXConstructorDecl::getInheritedConstructor() const { 1919 // Hack: we store the inherited constructor in the overridden method table 1920 method_iterator It = getASTContext().overridden_methods_begin(this); 1921 if (It == getASTContext().overridden_methods_end(this)) 1922 return nullptr; 1923 1924 return cast<CXXConstructorDecl>(*It); 1925 } 1926 1927 void 1928 CXXConstructorDecl::setInheritedConstructor(const CXXConstructorDecl *BaseCtor){ 1929 // Hack: we store the inherited constructor in the overridden method table 1930 assert(getASTContext().overridden_methods_size(this) == 0 && 1931 "Base ctor already set."); 1932 getASTContext().addOverriddenMethod(this, BaseCtor); 1933 } 1934 1935 void CXXDestructorDecl::anchor() { } 1936 1937 CXXDestructorDecl * 1938 CXXDestructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 1939 return new (C, ID) 1940 CXXDestructorDecl(C, nullptr, SourceLocation(), DeclarationNameInfo(), 1941 QualType(), nullptr, false, false); 1942 } 1943 1944 CXXDestructorDecl * 1945 CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, 1946 SourceLocation StartLoc, 1947 const DeclarationNameInfo &NameInfo, 1948 QualType T, TypeSourceInfo *TInfo, 1949 bool isInline, bool isImplicitlyDeclared) { 1950 assert(NameInfo.getName().getNameKind() 1951 == DeclarationName::CXXDestructorName && 1952 "Name must refer to a destructor"); 1953 return new (C, RD) CXXDestructorDecl(C, RD, StartLoc, NameInfo, T, TInfo, 1954 isInline, isImplicitlyDeclared); 1955 } 1956 1957 void CXXDestructorDecl::setOperatorDelete(FunctionDecl *OD) { 1958 auto *First = cast<CXXDestructorDecl>(getFirstDecl()); 1959 if (OD && !First->OperatorDelete) { 1960 First->OperatorDelete = OD; 1961 if (auto *L = getASTMutationListener()) 1962 L->ResolvedOperatorDelete(First, OD); 1963 } 1964 } 1965 1966 void CXXConversionDecl::anchor() { } 1967 1968 CXXConversionDecl * 1969 CXXConversionDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 1970 return new (C, ID) CXXConversionDecl(C, nullptr, SourceLocation(), 1971 DeclarationNameInfo(), QualType(), 1972 nullptr, false, false, false, 1973 SourceLocation()); 1974 } 1975 1976 CXXConversionDecl * 1977 CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD, 1978 SourceLocation StartLoc, 1979 const DeclarationNameInfo &NameInfo, 1980 QualType T, TypeSourceInfo *TInfo, 1981 bool isInline, bool isExplicit, 1982 bool isConstexpr, SourceLocation EndLocation) { 1983 assert(NameInfo.getName().getNameKind() 1984 == DeclarationName::CXXConversionFunctionName && 1985 "Name must refer to a conversion function"); 1986 return new (C, RD) CXXConversionDecl(C, RD, StartLoc, NameInfo, T, TInfo, 1987 isInline, isExplicit, isConstexpr, 1988 EndLocation); 1989 } 1990 1991 bool CXXConversionDecl::isLambdaToBlockPointerConversion() const { 1992 return isImplicit() && getParent()->isLambda() && 1993 getConversionType()->isBlockPointerType(); 1994 } 1995 1996 void LinkageSpecDecl::anchor() { } 1997 1998 LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, 1999 DeclContext *DC, 2000 SourceLocation ExternLoc, 2001 SourceLocation LangLoc, 2002 LanguageIDs Lang, 2003 bool HasBraces) { 2004 return new (C, DC) LinkageSpecDecl(DC, ExternLoc, LangLoc, Lang, HasBraces); 2005 } 2006 2007 LinkageSpecDecl *LinkageSpecDecl::CreateDeserialized(ASTContext &C, 2008 unsigned ID) { 2009 return new (C, ID) LinkageSpecDecl(nullptr, SourceLocation(), 2010 SourceLocation(), lang_c, false); 2011 } 2012 2013 void UsingDirectiveDecl::anchor() { } 2014 2015 UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC, 2016 SourceLocation L, 2017 SourceLocation NamespaceLoc, 2018 NestedNameSpecifierLoc QualifierLoc, 2019 SourceLocation IdentLoc, 2020 NamedDecl *Used, 2021 DeclContext *CommonAncestor) { 2022 if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Used)) 2023 Used = NS->getOriginalNamespace(); 2024 return new (C, DC) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierLoc, 2025 IdentLoc, Used, CommonAncestor); 2026 } 2027 2028 UsingDirectiveDecl *UsingDirectiveDecl::CreateDeserialized(ASTContext &C, 2029 unsigned ID) { 2030 return new (C, ID) UsingDirectiveDecl(nullptr, SourceLocation(), 2031 SourceLocation(), 2032 NestedNameSpecifierLoc(), 2033 SourceLocation(), nullptr, nullptr); 2034 } 2035 2036 NamespaceDecl *UsingDirectiveDecl::getNominatedNamespace() { 2037 if (NamespaceAliasDecl *NA = 2038 dyn_cast_or_null<NamespaceAliasDecl>(NominatedNamespace)) 2039 return NA->getNamespace(); 2040 return cast_or_null<NamespaceDecl>(NominatedNamespace); 2041 } 2042 2043 NamespaceDecl::NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline, 2044 SourceLocation StartLoc, SourceLocation IdLoc, 2045 IdentifierInfo *Id, NamespaceDecl *PrevDecl) 2046 : NamedDecl(Namespace, DC, IdLoc, Id), DeclContext(Namespace), 2047 redeclarable_base(C), LocStart(StartLoc), RBraceLoc(), 2048 AnonOrFirstNamespaceAndInline(nullptr, Inline) { 2049 setPreviousDecl(PrevDecl); 2050 2051 if (PrevDecl) 2052 AnonOrFirstNamespaceAndInline.setPointer(PrevDecl->getOriginalNamespace()); 2053 } 2054 2055 NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC, 2056 bool Inline, SourceLocation StartLoc, 2057 SourceLocation IdLoc, IdentifierInfo *Id, 2058 NamespaceDecl *PrevDecl) { 2059 return new (C, DC) NamespaceDecl(C, DC, Inline, StartLoc, IdLoc, Id, 2060 PrevDecl); 2061 } 2062 2063 NamespaceDecl *NamespaceDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 2064 return new (C, ID) NamespaceDecl(C, nullptr, false, SourceLocation(), 2065 SourceLocation(), nullptr, nullptr); 2066 } 2067 2068 NamespaceDecl *NamespaceDecl::getOriginalNamespace() { 2069 if (isFirstDecl()) 2070 return this; 2071 2072 return AnonOrFirstNamespaceAndInline.getPointer(); 2073 } 2074 2075 const NamespaceDecl *NamespaceDecl::getOriginalNamespace() const { 2076 if (isFirstDecl()) 2077 return this; 2078 2079 return AnonOrFirstNamespaceAndInline.getPointer(); 2080 } 2081 2082 bool NamespaceDecl::isOriginalNamespace() const { return isFirstDecl(); } 2083 2084 NamespaceDecl *NamespaceDecl::getNextRedeclarationImpl() { 2085 return getNextRedeclaration(); 2086 } 2087 NamespaceDecl *NamespaceDecl::getPreviousDeclImpl() { 2088 return getPreviousDecl(); 2089 } 2090 NamespaceDecl *NamespaceDecl::getMostRecentDeclImpl() { 2091 return getMostRecentDecl(); 2092 } 2093 2094 void NamespaceAliasDecl::anchor() { } 2095 2096 NamespaceAliasDecl *NamespaceAliasDecl::getNextRedeclarationImpl() { 2097 return getNextRedeclaration(); 2098 } 2099 NamespaceAliasDecl *NamespaceAliasDecl::getPreviousDeclImpl() { 2100 return getPreviousDecl(); 2101 } 2102 NamespaceAliasDecl *NamespaceAliasDecl::getMostRecentDeclImpl() { 2103 return getMostRecentDecl(); 2104 } 2105 2106 NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC, 2107 SourceLocation UsingLoc, 2108 SourceLocation AliasLoc, 2109 IdentifierInfo *Alias, 2110 NestedNameSpecifierLoc QualifierLoc, 2111 SourceLocation IdentLoc, 2112 NamedDecl *Namespace) { 2113 // FIXME: Preserve the aliased namespace as written. 2114 if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Namespace)) 2115 Namespace = NS->getOriginalNamespace(); 2116 return new (C, DC) NamespaceAliasDecl(C, DC, UsingLoc, AliasLoc, Alias, 2117 QualifierLoc, IdentLoc, Namespace); 2118 } 2119 2120 NamespaceAliasDecl * 2121 NamespaceAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 2122 return new (C, ID) NamespaceAliasDecl(C, nullptr, SourceLocation(), 2123 SourceLocation(), nullptr, 2124 NestedNameSpecifierLoc(), 2125 SourceLocation(), nullptr); 2126 } 2127 2128 void UsingShadowDecl::anchor() { } 2129 2130 UsingShadowDecl * 2131 UsingShadowDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 2132 return new (C, ID) UsingShadowDecl(C, nullptr, SourceLocation(), 2133 nullptr, nullptr); 2134 } 2135 2136 UsingDecl *UsingShadowDecl::getUsingDecl() const { 2137 const UsingShadowDecl *Shadow = this; 2138 while (const UsingShadowDecl *NextShadow = 2139 dyn_cast<UsingShadowDecl>(Shadow->UsingOrNextShadow)) 2140 Shadow = NextShadow; 2141 return cast<UsingDecl>(Shadow->UsingOrNextShadow); 2142 } 2143 2144 void UsingDecl::anchor() { } 2145 2146 void UsingDecl::addShadowDecl(UsingShadowDecl *S) { 2147 assert(std::find(shadow_begin(), shadow_end(), S) == shadow_end() && 2148 "declaration already in set"); 2149 assert(S->getUsingDecl() == this); 2150 2151 if (FirstUsingShadow.getPointer()) 2152 S->UsingOrNextShadow = FirstUsingShadow.getPointer(); 2153 FirstUsingShadow.setPointer(S); 2154 } 2155 2156 void UsingDecl::removeShadowDecl(UsingShadowDecl *S) { 2157 assert(std::find(shadow_begin(), shadow_end(), S) != shadow_end() && 2158 "declaration not in set"); 2159 assert(S->getUsingDecl() == this); 2160 2161 // Remove S from the shadow decl chain. This is O(n) but hopefully rare. 2162 2163 if (FirstUsingShadow.getPointer() == S) { 2164 FirstUsingShadow.setPointer( 2165 dyn_cast<UsingShadowDecl>(S->UsingOrNextShadow)); 2166 S->UsingOrNextShadow = this; 2167 return; 2168 } 2169 2170 UsingShadowDecl *Prev = FirstUsingShadow.getPointer(); 2171 while (Prev->UsingOrNextShadow != S) 2172 Prev = cast<UsingShadowDecl>(Prev->UsingOrNextShadow); 2173 Prev->UsingOrNextShadow = S->UsingOrNextShadow; 2174 S->UsingOrNextShadow = this; 2175 } 2176 2177 UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation UL, 2178 NestedNameSpecifierLoc QualifierLoc, 2179 const DeclarationNameInfo &NameInfo, 2180 bool HasTypename) { 2181 return new (C, DC) UsingDecl(DC, UL, QualifierLoc, NameInfo, HasTypename); 2182 } 2183 2184 UsingDecl *UsingDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 2185 return new (C, ID) UsingDecl(nullptr, SourceLocation(), 2186 NestedNameSpecifierLoc(), DeclarationNameInfo(), 2187 false); 2188 } 2189 2190 SourceRange UsingDecl::getSourceRange() const { 2191 SourceLocation Begin = isAccessDeclaration() 2192 ? getQualifierLoc().getBeginLoc() : UsingLocation; 2193 return SourceRange(Begin, getNameInfo().getEndLoc()); 2194 } 2195 2196 void UnresolvedUsingValueDecl::anchor() { } 2197 2198 UnresolvedUsingValueDecl * 2199 UnresolvedUsingValueDecl::Create(ASTContext &C, DeclContext *DC, 2200 SourceLocation UsingLoc, 2201 NestedNameSpecifierLoc QualifierLoc, 2202 const DeclarationNameInfo &NameInfo) { 2203 return new (C, DC) UnresolvedUsingValueDecl(DC, C.DependentTy, UsingLoc, 2204 QualifierLoc, NameInfo); 2205 } 2206 2207 UnresolvedUsingValueDecl * 2208 UnresolvedUsingValueDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 2209 return new (C, ID) UnresolvedUsingValueDecl(nullptr, QualType(), 2210 SourceLocation(), 2211 NestedNameSpecifierLoc(), 2212 DeclarationNameInfo()); 2213 } 2214 2215 SourceRange UnresolvedUsingValueDecl::getSourceRange() const { 2216 SourceLocation Begin = isAccessDeclaration() 2217 ? getQualifierLoc().getBeginLoc() : UsingLocation; 2218 return SourceRange(Begin, getNameInfo().getEndLoc()); 2219 } 2220 2221 void UnresolvedUsingTypenameDecl::anchor() { } 2222 2223 UnresolvedUsingTypenameDecl * 2224 UnresolvedUsingTypenameDecl::Create(ASTContext &C, DeclContext *DC, 2225 SourceLocation UsingLoc, 2226 SourceLocation TypenameLoc, 2227 NestedNameSpecifierLoc QualifierLoc, 2228 SourceLocation TargetNameLoc, 2229 DeclarationName TargetName) { 2230 return new (C, DC) UnresolvedUsingTypenameDecl( 2231 DC, UsingLoc, TypenameLoc, QualifierLoc, TargetNameLoc, 2232 TargetName.getAsIdentifierInfo()); 2233 } 2234 2235 UnresolvedUsingTypenameDecl * 2236 UnresolvedUsingTypenameDecl::CreateDeserialized(ASTContext &C, unsigned ID) { 2237 return new (C, ID) UnresolvedUsingTypenameDecl( 2238 nullptr, SourceLocation(), SourceLocation(), NestedNameSpecifierLoc(), 2239 SourceLocation(), nullptr); 2240 } 2241 2242 void StaticAssertDecl::anchor() { } 2243 2244 StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC, 2245 SourceLocation StaticAssertLoc, 2246 Expr *AssertExpr, 2247 StringLiteral *Message, 2248 SourceLocation RParenLoc, 2249 bool Failed) { 2250 return new (C, DC) StaticAssertDecl(DC, StaticAssertLoc, AssertExpr, Message, 2251 RParenLoc, Failed); 2252 } 2253 2254 StaticAssertDecl *StaticAssertDecl::CreateDeserialized(ASTContext &C, 2255 unsigned ID) { 2256 return new (C, ID) StaticAssertDecl(nullptr, SourceLocation(), nullptr, 2257 nullptr, SourceLocation(), false); 2258 } 2259 2260 MSPropertyDecl *MSPropertyDecl::Create(ASTContext &C, DeclContext *DC, 2261 SourceLocation L, DeclarationName N, 2262 QualType T, TypeSourceInfo *TInfo, 2263 SourceLocation StartL, 2264 IdentifierInfo *Getter, 2265 IdentifierInfo *Setter) { 2266 return new (C, DC) MSPropertyDecl(DC, L, N, T, TInfo, StartL, Getter, Setter); 2267 } 2268 2269 MSPropertyDecl *MSPropertyDecl::CreateDeserialized(ASTContext &C, 2270 unsigned ID) { 2271 return new (C, ID) MSPropertyDecl(nullptr, SourceLocation(), 2272 DeclarationName(), QualType(), nullptr, 2273 SourceLocation(), nullptr, nullptr); 2274 } 2275 2276 static const char *getAccessName(AccessSpecifier AS) { 2277 switch (AS) { 2278 case AS_none: 2279 llvm_unreachable("Invalid access specifier!"); 2280 case AS_public: 2281 return "public"; 2282 case AS_private: 2283 return "private"; 2284 case AS_protected: 2285 return "protected"; 2286 } 2287 llvm_unreachable("Invalid access specifier!"); 2288 } 2289 2290 const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB, 2291 AccessSpecifier AS) { 2292 return DB << getAccessName(AS); 2293 } 2294 2295 const PartialDiagnostic &clang::operator<<(const PartialDiagnostic &DB, 2296 AccessSpecifier AS) { 2297 return DB << getAccessName(AS); 2298 } 2299