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 14 #include "clang/AST/DeclCXX.h" 15 #include "clang/AST/DeclTemplate.h" 16 #include "clang/AST/ASTContext.h" 17 #include "clang/AST/ASTMutationListener.h" 18 #include "clang/AST/CXXInheritance.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 CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D) 32 : UserDeclaredConstructor(false), UserDeclaredCopyConstructor(false), 33 UserDeclaredMoveConstructor(false), UserDeclaredCopyAssignment(false), 34 UserDeclaredMoveAssignment(false), UserDeclaredDestructor(false), 35 Aggregate(true), PlainOldData(true), Empty(true), Polymorphic(false), 36 Abstract(false), IsStandardLayout(true), HasNoNonEmptyBases(true), 37 HasPrivateFields(false), HasProtectedFields(false), HasPublicFields(false), 38 HasMutableFields(false), HasTrivialDefaultConstructor(true), 39 HasConstexprNonCopyMoveConstructor(false), HasTrivialCopyConstructor(true), 40 HasTrivialMoveConstructor(true), HasTrivialCopyAssignment(true), 41 HasTrivialMoveAssignment(true), HasTrivialDestructor(true), 42 HasNonLiteralTypeFieldsOrBases(false), ComputedVisibleConversions(false), 43 UserProvidedDefaultConstructor(false), DeclaredDefaultConstructor(false), 44 DeclaredCopyConstructor(false), DeclaredMoveConstructor(false), 45 DeclaredCopyAssignment(false), DeclaredMoveAssignment(false), 46 DeclaredDestructor(false), FailedImplicitMoveConstructor(false), 47 FailedImplicitMoveAssignment(false), NumBases(0), NumVBases(0), Bases(), 48 VBases(), Definition(D), FirstFriend(0) { 49 } 50 51 CXXRecordDecl::CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC, 52 SourceLocation StartLoc, SourceLocation IdLoc, 53 IdentifierInfo *Id, CXXRecordDecl *PrevDecl) 54 : RecordDecl(K, TK, DC, StartLoc, IdLoc, Id, PrevDecl), 55 DefinitionData(PrevDecl ? PrevDecl->DefinitionData : 0), 56 TemplateOrInstantiation() { } 57 58 CXXRecordDecl *CXXRecordDecl::Create(const ASTContext &C, TagKind TK, 59 DeclContext *DC, SourceLocation StartLoc, 60 SourceLocation IdLoc, IdentifierInfo *Id, 61 CXXRecordDecl* PrevDecl, 62 bool DelayTypeCreation) { 63 CXXRecordDecl* R = new (C) CXXRecordDecl(CXXRecord, TK, DC, StartLoc, IdLoc, 64 Id, PrevDecl); 65 66 // FIXME: DelayTypeCreation seems like such a hack 67 if (!DelayTypeCreation) 68 C.getTypeDeclType(R, PrevDecl); 69 return R; 70 } 71 72 CXXRecordDecl *CXXRecordDecl::Create(const ASTContext &C, EmptyShell Empty) { 73 return new (C) CXXRecordDecl(CXXRecord, TTK_Struct, 0, SourceLocation(), 74 SourceLocation(), 0, 0); 75 } 76 77 void 78 CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases, 79 unsigned NumBases) { 80 ASTContext &C = getASTContext(); 81 82 if (!data().Bases.isOffset() && data().NumBases > 0) 83 C.Deallocate(data().getBases()); 84 85 if (NumBases) { 86 // C++ [dcl.init.aggr]p1: 87 // An aggregate is [...] a class with [...] no base classes [...]. 88 data().Aggregate = false; 89 90 // C++ [class]p4: 91 // A POD-struct is an aggregate class... 92 data().PlainOldData = false; 93 } 94 95 // The set of seen virtual base types. 96 llvm::SmallPtrSet<CanQualType, 8> SeenVBaseTypes; 97 98 // The virtual bases of this class. 99 SmallVector<const CXXBaseSpecifier *, 8> VBases; 100 101 data().Bases = new(C) CXXBaseSpecifier [NumBases]; 102 data().NumBases = NumBases; 103 for (unsigned i = 0; i < NumBases; ++i) { 104 data().getBases()[i] = *Bases[i]; 105 // Keep track of inherited vbases for this base class. 106 const CXXBaseSpecifier *Base = Bases[i]; 107 QualType BaseType = Base->getType(); 108 // Skip dependent types; we can't do any checking on them now. 109 if (BaseType->isDependentType()) 110 continue; 111 CXXRecordDecl *BaseClassDecl 112 = cast<CXXRecordDecl>(BaseType->getAs<RecordType>()->getDecl()); 113 114 // A class with a non-empty base class is not empty. 115 // FIXME: Standard ref? 116 if (!BaseClassDecl->isEmpty()) { 117 if (!data().Empty) { 118 // C++0x [class]p7: 119 // A standard-layout class is a class that: 120 // [...] 121 // -- either has no non-static data members in the most derived 122 // class and at most one base class with non-static data members, 123 // or has no base classes with non-static data members, and 124 // If this is the second non-empty base, then neither of these two 125 // clauses can be true. 126 data().IsStandardLayout = false; 127 } 128 129 data().Empty = false; 130 data().HasNoNonEmptyBases = false; 131 } 132 133 // C++ [class.virtual]p1: 134 // A class that declares or inherits a virtual function is called a 135 // polymorphic class. 136 if (BaseClassDecl->isPolymorphic()) 137 data().Polymorphic = true; 138 139 // C++0x [class]p7: 140 // A standard-layout class is a class that: [...] 141 // -- has no non-standard-layout base classes 142 if (!BaseClassDecl->isStandardLayout()) 143 data().IsStandardLayout = false; 144 145 // Record if this base is the first non-literal field or base. 146 if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType()) 147 data().HasNonLiteralTypeFieldsOrBases = true; 148 149 // Now go through all virtual bases of this base and add them. 150 for (CXXRecordDecl::base_class_iterator VBase = 151 BaseClassDecl->vbases_begin(), 152 E = BaseClassDecl->vbases_end(); VBase != E; ++VBase) { 153 // Add this base if it's not already in the list. 154 if (SeenVBaseTypes.insert(C.getCanonicalType(VBase->getType()))) 155 VBases.push_back(VBase); 156 } 157 158 if (Base->isVirtual()) { 159 // Add this base if it's not already in the list. 160 if (SeenVBaseTypes.insert(C.getCanonicalType(BaseType))) 161 VBases.push_back(Base); 162 163 // C++0x [meta.unary.prop] is_empty: 164 // T is a class type, but not a union type, with ... no virtual base 165 // classes 166 data().Empty = false; 167 168 // C++ [class.ctor]p5: 169 // A default constructor is trivial [...] if: 170 // -- its class has [...] no virtual bases 171 data().HasTrivialDefaultConstructor = false; 172 173 // C++0x [class.copy]p13: 174 // A copy/move constructor for class X is trivial if it is neither 175 // user-provided nor deleted and if 176 // -- class X has no virtual functions and no virtual base classes, and 177 data().HasTrivialCopyConstructor = false; 178 data().HasTrivialMoveConstructor = false; 179 180 // C++0x [class.copy]p27: 181 // A copy/move assignment operator for class X is trivial if it is 182 // neither user-provided nor deleted and if 183 // -- class X has no virtual functions and no virtual base classes, and 184 data().HasTrivialCopyAssignment = false; 185 data().HasTrivialMoveAssignment = false; 186 187 // C++0x [class]p7: 188 // A standard-layout class is a class that: [...] 189 // -- has [...] no virtual base classes 190 data().IsStandardLayout = false; 191 } else { 192 // C++ [class.ctor]p5: 193 // A default constructor is trivial [...] if: 194 // -- all the direct base classes of its class have trivial default 195 // constructors. 196 if (!BaseClassDecl->hasTrivialDefaultConstructor()) 197 data().HasTrivialDefaultConstructor = false; 198 199 // C++0x [class.copy]p13: 200 // A copy/move constructor for class X is trivial if [...] 201 // [...] 202 // -- the constructor selected to copy/move each direct base class 203 // subobject is trivial, and 204 // FIXME: C++0x: We need to only consider the selected constructor 205 // instead of all of them. 206 if (!BaseClassDecl->hasTrivialCopyConstructor()) 207 data().HasTrivialCopyConstructor = false; 208 if (!BaseClassDecl->hasTrivialMoveConstructor()) 209 data().HasTrivialMoveConstructor = false; 210 211 // C++0x [class.copy]p27: 212 // A copy/move assignment operator for class X is trivial if [...] 213 // [...] 214 // -- the assignment operator selected to copy/move each direct base 215 // class subobject is trivial, and 216 // FIXME: C++0x: We need to only consider the selected operator instead 217 // of all of them. 218 if (!BaseClassDecl->hasTrivialCopyAssignment()) 219 data().HasTrivialCopyAssignment = false; 220 if (!BaseClassDecl->hasTrivialMoveAssignment()) 221 data().HasTrivialMoveAssignment = false; 222 } 223 224 // C++ [class.ctor]p3: 225 // A destructor is trivial if all the direct base classes of its class 226 // have trivial destructors. 227 if (!BaseClassDecl->hasTrivialDestructor()) 228 data().HasTrivialDestructor = false; 229 230 // A class has an Objective-C object member if... or any of its bases 231 // has an Objective-C object member. 232 if (BaseClassDecl->hasObjectMember()) 233 setHasObjectMember(true); 234 235 // Keep track of the presence of mutable fields. 236 if (BaseClassDecl->hasMutableFields()) 237 data().HasMutableFields = true; 238 } 239 240 if (VBases.empty()) 241 return; 242 243 // Create base specifier for any direct or indirect virtual bases. 244 data().VBases = new (C) CXXBaseSpecifier[VBases.size()]; 245 data().NumVBases = VBases.size(); 246 for (int I = 0, E = VBases.size(); I != E; ++I) 247 data().getVBases()[I] = *VBases[I]; 248 } 249 250 /// Callback function for CXXRecordDecl::forallBases that acknowledges 251 /// that it saw a base class. 252 static bool SawBase(const CXXRecordDecl *, void *) { 253 return true; 254 } 255 256 bool CXXRecordDecl::hasAnyDependentBases() const { 257 if (!isDependentContext()) 258 return false; 259 260 return !forallBases(SawBase, 0); 261 } 262 263 bool CXXRecordDecl::hasConstCopyConstructor() const { 264 return getCopyConstructor(Qualifiers::Const) != 0; 265 } 266 267 bool CXXRecordDecl::isTriviallyCopyable() const { 268 // C++0x [class]p5: 269 // A trivially copyable class is a class that: 270 // -- has no non-trivial copy constructors, 271 if (!hasTrivialCopyConstructor()) return false; 272 // -- has no non-trivial move constructors, 273 if (!hasTrivialMoveConstructor()) return false; 274 // -- has no non-trivial copy assignment operators, 275 if (!hasTrivialCopyAssignment()) return false; 276 // -- has no non-trivial move assignment operators, and 277 if (!hasTrivialMoveAssignment()) return false; 278 // -- has a trivial destructor. 279 if (!hasTrivialDestructor()) return false; 280 281 return true; 282 } 283 284 /// \brief Perform a simplistic form of overload resolution that only considers 285 /// cv-qualifiers on a single parameter, and return the best overload candidate 286 /// (if there is one). 287 static CXXMethodDecl * 288 GetBestOverloadCandidateSimple( 289 const SmallVectorImpl<std::pair<CXXMethodDecl *, Qualifiers> > &Cands) { 290 if (Cands.empty()) 291 return 0; 292 if (Cands.size() == 1) 293 return Cands[0].first; 294 295 unsigned Best = 0, N = Cands.size(); 296 for (unsigned I = 1; I != N; ++I) 297 if (Cands[Best].second.compatiblyIncludes(Cands[I].second)) 298 Best = I; 299 300 for (unsigned I = 1; I != N; ++I) 301 if (Cands[Best].second.compatiblyIncludes(Cands[I].second)) 302 return 0; 303 304 return Cands[Best].first; 305 } 306 307 CXXConstructorDecl *CXXRecordDecl::getCopyConstructor(unsigned TypeQuals) const{ 308 ASTContext &Context = getASTContext(); 309 QualType ClassType 310 = Context.getTypeDeclType(const_cast<CXXRecordDecl*>(this)); 311 DeclarationName ConstructorName 312 = Context.DeclarationNames.getCXXConstructorName( 313 Context.getCanonicalType(ClassType)); 314 unsigned FoundTQs; 315 SmallVector<std::pair<CXXMethodDecl *, Qualifiers>, 4> Found; 316 DeclContext::lookup_const_iterator Con, ConEnd; 317 for (llvm::tie(Con, ConEnd) = this->lookup(ConstructorName); 318 Con != ConEnd; ++Con) { 319 // C++ [class.copy]p2: 320 // A non-template constructor for class X is a copy constructor if [...] 321 if (isa<FunctionTemplateDecl>(*Con)) 322 continue; 323 324 CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(*Con); 325 if (Constructor->isCopyConstructor(FoundTQs)) { 326 if (((TypeQuals & Qualifiers::Const) == (FoundTQs & Qualifiers::Const)) || 327 (!(TypeQuals & Qualifiers::Const) && (FoundTQs & Qualifiers::Const))) 328 Found.push_back(std::make_pair( 329 const_cast<CXXConstructorDecl *>(Constructor), 330 Qualifiers::fromCVRMask(FoundTQs))); 331 } 332 } 333 334 return cast_or_null<CXXConstructorDecl>( 335 GetBestOverloadCandidateSimple(Found)); 336 } 337 338 CXXConstructorDecl *CXXRecordDecl::getMoveConstructor() const { 339 for (ctor_iterator I = ctor_begin(), E = ctor_end(); I != E; ++I) 340 if (I->isMoveConstructor()) 341 return *I; 342 343 return 0; 344 } 345 346 CXXMethodDecl *CXXRecordDecl::getCopyAssignmentOperator(bool ArgIsConst) const { 347 ASTContext &Context = getASTContext(); 348 QualType Class = Context.getTypeDeclType(const_cast<CXXRecordDecl *>(this)); 349 DeclarationName Name = Context.DeclarationNames.getCXXOperatorName(OO_Equal); 350 351 SmallVector<std::pair<CXXMethodDecl *, Qualifiers>, 4> Found; 352 DeclContext::lookup_const_iterator Op, OpEnd; 353 for (llvm::tie(Op, OpEnd) = this->lookup(Name); Op != OpEnd; ++Op) { 354 // C++ [class.copy]p9: 355 // A user-declared copy assignment operator is a non-static non-template 356 // member function of class X with exactly one parameter of type X, X&, 357 // const X&, volatile X& or const volatile X&. 358 const CXXMethodDecl* Method = dyn_cast<CXXMethodDecl>(*Op); 359 if (!Method || Method->isStatic() || Method->getPrimaryTemplate()) 360 continue; 361 362 const FunctionProtoType *FnType 363 = Method->getType()->getAs<FunctionProtoType>(); 364 assert(FnType && "Overloaded operator has no prototype."); 365 // Don't assert on this; an invalid decl might have been left in the AST. 366 if (FnType->getNumArgs() != 1 || FnType->isVariadic()) 367 continue; 368 369 QualType ArgType = FnType->getArgType(0); 370 Qualifiers Quals; 371 if (const LValueReferenceType *Ref = ArgType->getAs<LValueReferenceType>()) { 372 ArgType = Ref->getPointeeType(); 373 // If we have a const argument and we have a reference to a non-const, 374 // this function does not match. 375 if (ArgIsConst && !ArgType.isConstQualified()) 376 continue; 377 378 Quals = ArgType.getQualifiers(); 379 } else { 380 // By-value copy-assignment operators are treated like const X& 381 // copy-assignment operators. 382 Quals = Qualifiers::fromCVRMask(Qualifiers::Const); 383 } 384 385 if (!Context.hasSameUnqualifiedType(ArgType, Class)) 386 continue; 387 388 // Save this copy-assignment operator. It might be "the one". 389 Found.push_back(std::make_pair(const_cast<CXXMethodDecl *>(Method), Quals)); 390 } 391 392 // Use a simplistic form of overload resolution to find the candidate. 393 return GetBestOverloadCandidateSimple(Found); 394 } 395 396 CXXMethodDecl *CXXRecordDecl::getMoveAssignmentOperator() const { 397 for (method_iterator I = method_begin(), E = method_end(); I != E; ++I) 398 if (I->isMoveAssignmentOperator()) 399 return *I; 400 401 return 0; 402 } 403 404 void CXXRecordDecl::markedVirtualFunctionPure() { 405 // C++ [class.abstract]p2: 406 // A class is abstract if it has at least one pure virtual function. 407 data().Abstract = true; 408 } 409 410 void CXXRecordDecl::addedMember(Decl *D) { 411 // Ignore friends and invalid declarations. 412 if (D->getFriendObjectKind() || D->isInvalidDecl()) 413 return; 414 415 FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D); 416 if (FunTmpl) 417 D = FunTmpl->getTemplatedDecl(); 418 419 if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) { 420 if (Method->isVirtual()) { 421 // C++ [dcl.init.aggr]p1: 422 // An aggregate is an array or a class with [...] no virtual functions. 423 data().Aggregate = false; 424 425 // C++ [class]p4: 426 // A POD-struct is an aggregate class... 427 data().PlainOldData = false; 428 429 // Virtual functions make the class non-empty. 430 // FIXME: Standard ref? 431 data().Empty = false; 432 433 // C++ [class.virtual]p1: 434 // A class that declares or inherits a virtual function is called a 435 // polymorphic class. 436 data().Polymorphic = true; 437 438 // C++0x [class.ctor]p5 439 // A default constructor is trivial [...] if: 440 // -- its class has no virtual functions [...] 441 data().HasTrivialDefaultConstructor = false; 442 443 // C++0x [class.copy]p13: 444 // A copy/move constructor for class X is trivial if [...] 445 // -- class X has no virtual functions [...] 446 data().HasTrivialCopyConstructor = false; 447 data().HasTrivialMoveConstructor = false; 448 449 // C++0x [class.copy]p27: 450 // A copy/move assignment operator for class X is trivial if [...] 451 // -- class X has no virtual functions [...] 452 data().HasTrivialCopyAssignment = false; 453 data().HasTrivialMoveAssignment = false; 454 455 // C++0x [class]p7: 456 // A standard-layout class is a class that: [...] 457 // -- has no virtual functions 458 data().IsStandardLayout = false; 459 } 460 } 461 462 if (D->isImplicit()) { 463 // Notify that an implicit member was added after the definition 464 // was completed. 465 if (!isBeingDefined()) 466 if (ASTMutationListener *L = getASTMutationListener()) 467 L->AddedCXXImplicitMember(data().Definition, D); 468 469 // If this is a special member function, note that it was added and then 470 // return early. 471 if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) { 472 if (Constructor->isDefaultConstructor()) 473 data().DeclaredDefaultConstructor = true; 474 else if (Constructor->isCopyConstructor()) 475 data().DeclaredCopyConstructor = true; 476 else if (Constructor->isMoveConstructor()) 477 data().DeclaredMoveConstructor = true; 478 else 479 goto NotASpecialMember; 480 return; 481 } else if (isa<CXXDestructorDecl>(D)) { 482 data().DeclaredDestructor = true; 483 return; 484 } else if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) { 485 if (Method->isCopyAssignmentOperator()) 486 data().DeclaredCopyAssignment = true; 487 else if (Method->isMoveAssignmentOperator()) 488 data().DeclaredMoveAssignment = true; 489 else 490 goto NotASpecialMember; 491 return; 492 } 493 494 NotASpecialMember:; 495 // Any other implicit declarations are handled like normal declarations. 496 } 497 498 // Handle (user-declared) constructors. 499 if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) { 500 // Note that we have a user-declared constructor. 501 data().UserDeclaredConstructor = true; 502 503 // Technically, "user-provided" is only defined for special member 504 // functions, but the intent of the standard is clearly that it should apply 505 // to all functions. 506 bool UserProvided = Constructor->isUserProvided(); 507 508 // C++0x [class.ctor]p5: 509 // A default constructor is trivial if it is not user-provided [...] 510 if (Constructor->isDefaultConstructor()) { 511 data().DeclaredDefaultConstructor = true; 512 if (UserProvided) { 513 data().HasTrivialDefaultConstructor = false; 514 data().UserProvidedDefaultConstructor = true; 515 } 516 } 517 518 // Note when we have a user-declared copy or move constructor, which will 519 // suppress the implicit declaration of those constructors. 520 if (!FunTmpl) { 521 if (Constructor->isCopyConstructor()) { 522 data().UserDeclaredCopyConstructor = true; 523 data().DeclaredCopyConstructor = true; 524 525 // C++0x [class.copy]p13: 526 // A copy/move constructor for class X is trivial if it is not 527 // user-provided [...] 528 if (UserProvided) 529 data().HasTrivialCopyConstructor = false; 530 } else if (Constructor->isMoveConstructor()) { 531 data().UserDeclaredMoveConstructor = true; 532 data().DeclaredMoveConstructor = true; 533 534 // C++0x [class.copy]p13: 535 // A copy/move constructor for class X is trivial if it is not 536 // user-provided [...] 537 if (UserProvided) 538 data().HasTrivialMoveConstructor = false; 539 } 540 } 541 if (Constructor->isConstexpr() && !Constructor->isCopyOrMoveConstructor()) { 542 // Record if we see any constexpr constructors which are neither copy 543 // nor move constructors. 544 data().HasConstexprNonCopyMoveConstructor = true; 545 } 546 547 // C++ [dcl.init.aggr]p1: 548 // An aggregate is an array or a class with no user-declared 549 // constructors [...]. 550 // C++0x [dcl.init.aggr]p1: 551 // An aggregate is an array or a class with no user-provided 552 // constructors [...]. 553 if (!getASTContext().getLangOptions().CPlusPlus0x || UserProvided) 554 data().Aggregate = false; 555 556 // C++ [class]p4: 557 // A POD-struct is an aggregate class [...] 558 // Since the POD bit is meant to be C++03 POD-ness, clear it even if the 559 // type is technically an aggregate in C++0x since it wouldn't be in 03. 560 data().PlainOldData = false; 561 562 return; 563 } 564 565 // Handle (user-declared) destructors. 566 if (CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(D)) { 567 data().DeclaredDestructor = true; 568 data().UserDeclaredDestructor = true; 569 570 // C++ [class]p4: 571 // A POD-struct is an aggregate class that has [...] no user-defined 572 // destructor. 573 // This bit is the C++03 POD bit, not the 0x one. 574 data().PlainOldData = false; 575 576 // C++11 [class.dtor]p5: 577 // A destructor is trivial if it is not user-provided and if 578 // -- the destructor is not virtual. 579 if (DD->isUserProvided() || DD->isVirtual()) 580 data().HasTrivialDestructor = false; 581 582 return; 583 } 584 585 // Handle (user-declared) member functions. 586 if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) { 587 if (Method->isCopyAssignmentOperator()) { 588 // C++ [class]p4: 589 // A POD-struct is an aggregate class that [...] has no user-defined 590 // copy assignment operator [...]. 591 // This is the C++03 bit only. 592 data().PlainOldData = false; 593 594 // This is a copy assignment operator. 595 596 // Suppress the implicit declaration of a copy constructor. 597 data().UserDeclaredCopyAssignment = true; 598 data().DeclaredCopyAssignment = true; 599 600 // C++0x [class.copy]p27: 601 // A copy/move assignment operator for class X is trivial if it is 602 // neither user-provided nor deleted [...] 603 if (Method->isUserProvided()) 604 data().HasTrivialCopyAssignment = false; 605 606 return; 607 } 608 609 if (Method->isMoveAssignmentOperator()) { 610 // This is an extension in C++03 mode, but we'll keep consistency by 611 // taking a move assignment operator to induce non-POD-ness 612 data().PlainOldData = false; 613 614 // This is a move assignment operator. 615 data().UserDeclaredMoveAssignment = true; 616 data().DeclaredMoveAssignment = true; 617 618 // C++0x [class.copy]p27: 619 // A copy/move assignment operator for class X is trivial if it is 620 // neither user-provided nor deleted [...] 621 if (Method->isUserProvided()) 622 data().HasTrivialMoveAssignment = false; 623 } 624 625 // Keep the list of conversion functions up-to-date. 626 if (CXXConversionDecl *Conversion = dyn_cast<CXXConversionDecl>(D)) { 627 // We don't record specializations. 628 if (Conversion->getPrimaryTemplate()) 629 return; 630 631 // FIXME: We intentionally don't use the decl's access here because it 632 // hasn't been set yet. That's really just a misdesign in Sema. 633 634 if (FunTmpl) { 635 if (FunTmpl->getPreviousDeclaration()) 636 data().Conversions.replace(FunTmpl->getPreviousDeclaration(), 637 FunTmpl); 638 else 639 data().Conversions.addDecl(FunTmpl); 640 } else { 641 if (Conversion->getPreviousDeclaration()) 642 data().Conversions.replace(Conversion->getPreviousDeclaration(), 643 Conversion); 644 else 645 data().Conversions.addDecl(Conversion); 646 } 647 } 648 649 return; 650 } 651 652 // Handle non-static data members. 653 if (FieldDecl *Field = dyn_cast<FieldDecl>(D)) { 654 // C++ [class.bit]p2: 655 // A declaration for a bit-field that omits the identifier declares an 656 // unnamed bit-field. Unnamed bit-fields are not members and cannot be 657 // initialized. 658 if (Field->isUnnamedBitfield()) 659 return; 660 661 // C++ [dcl.init.aggr]p1: 662 // An aggregate is an array or a class (clause 9) with [...] no 663 // private or protected non-static data members (clause 11). 664 // 665 // A POD must be an aggregate. 666 if (D->getAccess() == AS_private || D->getAccess() == AS_protected) { 667 data().Aggregate = false; 668 data().PlainOldData = false; 669 } 670 671 // C++0x [class]p7: 672 // A standard-layout class is a class that: 673 // [...] 674 // -- has the same access control for all non-static data members, 675 switch (D->getAccess()) { 676 case AS_private: data().HasPrivateFields = true; break; 677 case AS_protected: data().HasProtectedFields = true; break; 678 case AS_public: data().HasPublicFields = true; break; 679 case AS_none: llvm_unreachable("Invalid access specifier"); 680 }; 681 if ((data().HasPrivateFields + data().HasProtectedFields + 682 data().HasPublicFields) > 1) 683 data().IsStandardLayout = false; 684 685 // Keep track of the presence of mutable fields. 686 if (Field->isMutable()) 687 data().HasMutableFields = true; 688 689 // C++0x [class]p9: 690 // A POD struct is a class that is both a trivial class and a 691 // standard-layout class, and has no non-static data members of type 692 // non-POD struct, non-POD union (or array of such types). 693 // 694 // Automatic Reference Counting: the presence of a member of Objective-C pointer type 695 // that does not explicitly have no lifetime makes the class a non-POD. 696 // However, we delay setting PlainOldData to false in this case so that 697 // Sema has a chance to diagnostic causes where the same class will be 698 // non-POD with Automatic Reference Counting but a POD without Instant Objects. 699 // In this case, the class will become a non-POD class when we complete 700 // the definition. 701 ASTContext &Context = getASTContext(); 702 QualType T = Context.getBaseElementType(Field->getType()); 703 if (T->isObjCRetainableType() || T.isObjCGCStrong()) { 704 if (!Context.getLangOptions().ObjCAutoRefCount || 705 T.getObjCLifetime() != Qualifiers::OCL_ExplicitNone) 706 setHasObjectMember(true); 707 } else if (!T.isPODType(Context)) 708 data().PlainOldData = false; 709 710 if (T->isReferenceType()) { 711 data().HasTrivialDefaultConstructor = false; 712 713 // C++0x [class]p7: 714 // A standard-layout class is a class that: 715 // -- has no non-static data members of type [...] reference, 716 data().IsStandardLayout = false; 717 } 718 719 // Record if this field is the first non-literal field or base. 720 // As a slight variation on the standard, we regard mutable members as being 721 // non-literal, since mutating a constexpr variable would break C++11 722 // constant expression semantics. 723 if ((!hasNonLiteralTypeFieldsOrBases() && !T->isLiteralType()) || 724 Field->isMutable()) 725 data().HasNonLiteralTypeFieldsOrBases = true; 726 727 if (Field->hasInClassInitializer()) { 728 // C++0x [class]p5: 729 // A default constructor is trivial if [...] no non-static data member 730 // of its class has a brace-or-equal-initializer. 731 data().HasTrivialDefaultConstructor = false; 732 733 // C++0x [dcl.init.aggr]p1: 734 // An aggregate is a [...] class with [...] no 735 // brace-or-equal-initializers for non-static data members. 736 data().Aggregate = false; 737 738 // C++0x [class]p10: 739 // A POD struct is [...] a trivial class. 740 data().PlainOldData = false; 741 } 742 743 if (const RecordType *RecordTy = T->getAs<RecordType>()) { 744 CXXRecordDecl* FieldRec = cast<CXXRecordDecl>(RecordTy->getDecl()); 745 if (FieldRec->getDefinition()) { 746 // C++0x [class.ctor]p5: 747 // A defulat constructor is trivial [...] if: 748 // -- for all the non-static data members of its class that are of 749 // class type (or array thereof), each such class has a trivial 750 // default constructor. 751 if (!FieldRec->hasTrivialDefaultConstructor()) 752 data().HasTrivialDefaultConstructor = false; 753 754 // C++0x [class.copy]p13: 755 // A copy/move constructor for class X is trivial if [...] 756 // [...] 757 // -- for each non-static data member of X that is of class type (or 758 // an array thereof), the constructor selected to copy/move that 759 // member is trivial; 760 // FIXME: C++0x: We don't correctly model 'selected' constructors. 761 if (!FieldRec->hasTrivialCopyConstructor()) 762 data().HasTrivialCopyConstructor = false; 763 if (!FieldRec->hasTrivialMoveConstructor()) 764 data().HasTrivialMoveConstructor = false; 765 766 // C++0x [class.copy]p27: 767 // A copy/move assignment operator for class X is trivial if [...] 768 // [...] 769 // -- for each non-static data member of X that is of class type (or 770 // an array thereof), the assignment operator selected to 771 // copy/move that member is trivial; 772 // FIXME: C++0x: We don't correctly model 'selected' operators. 773 if (!FieldRec->hasTrivialCopyAssignment()) 774 data().HasTrivialCopyAssignment = false; 775 if (!FieldRec->hasTrivialMoveAssignment()) 776 data().HasTrivialMoveAssignment = false; 777 778 if (!FieldRec->hasTrivialDestructor()) 779 data().HasTrivialDestructor = false; 780 if (FieldRec->hasObjectMember()) 781 setHasObjectMember(true); 782 783 // C++0x [class]p7: 784 // A standard-layout class is a class that: 785 // -- has no non-static data members of type non-standard-layout 786 // class (or array of such types) [...] 787 if (!FieldRec->isStandardLayout()) 788 data().IsStandardLayout = false; 789 790 // C++0x [class]p7: 791 // A standard-layout class is a class that: 792 // [...] 793 // -- has no base classes of the same type as the first non-static 794 // data member. 795 // We don't want to expend bits in the state of the record decl 796 // tracking whether this is the first non-static data member so we 797 // cheat a bit and use some of the existing state: the empty bit. 798 // Virtual bases and virtual methods make a class non-empty, but they 799 // also make it non-standard-layout so we needn't check here. 800 // A non-empty base class may leave the class standard-layout, but not 801 // if we have arrived here, and have at least on non-static data 802 // member. If IsStandardLayout remains true, then the first non-static 803 // data member must come through here with Empty still true, and Empty 804 // will subsequently be set to false below. 805 if (data().IsStandardLayout && data().Empty) { 806 for (CXXRecordDecl::base_class_const_iterator BI = bases_begin(), 807 BE = bases_end(); 808 BI != BE; ++BI) { 809 if (Context.hasSameUnqualifiedType(BI->getType(), T)) { 810 data().IsStandardLayout = false; 811 break; 812 } 813 } 814 } 815 816 // Keep track of the presence of mutable fields. 817 if (FieldRec->hasMutableFields()) 818 data().HasMutableFields = true; 819 } 820 } 821 822 // C++0x [class]p7: 823 // A standard-layout class is a class that: 824 // [...] 825 // -- either has no non-static data members in the most derived 826 // class and at most one base class with non-static data members, 827 // or has no base classes with non-static data members, and 828 // At this point we know that we have a non-static data member, so the last 829 // clause holds. 830 if (!data().HasNoNonEmptyBases) 831 data().IsStandardLayout = false; 832 833 // If this is not a zero-length bit-field, then the class is not empty. 834 if (data().Empty) { 835 if (!Field->isBitField() || 836 (!Field->getBitWidth()->isTypeDependent() && 837 !Field->getBitWidth()->isValueDependent() && 838 Field->getBitWidthValue(Context) != 0)) 839 data().Empty = false; 840 } 841 } 842 843 // Handle using declarations of conversion functions. 844 if (UsingShadowDecl *Shadow = dyn_cast<UsingShadowDecl>(D)) 845 if (Shadow->getDeclName().getNameKind() 846 == DeclarationName::CXXConversionFunctionName) 847 data().Conversions.addDecl(Shadow, Shadow->getAccess()); 848 } 849 850 static CanQualType GetConversionType(ASTContext &Context, NamedDecl *Conv) { 851 QualType T; 852 if (isa<UsingShadowDecl>(Conv)) 853 Conv = cast<UsingShadowDecl>(Conv)->getTargetDecl(); 854 if (FunctionTemplateDecl *ConvTemp = dyn_cast<FunctionTemplateDecl>(Conv)) 855 T = ConvTemp->getTemplatedDecl()->getResultType(); 856 else 857 T = cast<CXXConversionDecl>(Conv)->getConversionType(); 858 return Context.getCanonicalType(T); 859 } 860 861 /// Collect the visible conversions of a base class. 862 /// 863 /// \param Base a base class of the class we're considering 864 /// \param InVirtual whether this base class is a virtual base (or a base 865 /// of a virtual base) 866 /// \param Access the access along the inheritance path to this base 867 /// \param ParentHiddenTypes the conversions provided by the inheritors 868 /// of this base 869 /// \param Output the set to which to add conversions from non-virtual bases 870 /// \param VOutput the set to which to add conversions from virtual bases 871 /// \param HiddenVBaseCs the set of conversions which were hidden in a 872 /// virtual base along some inheritance path 873 static void CollectVisibleConversions(ASTContext &Context, 874 CXXRecordDecl *Record, 875 bool InVirtual, 876 AccessSpecifier Access, 877 const llvm::SmallPtrSet<CanQualType, 8> &ParentHiddenTypes, 878 UnresolvedSetImpl &Output, 879 UnresolvedSetImpl &VOutput, 880 llvm::SmallPtrSet<NamedDecl*, 8> &HiddenVBaseCs) { 881 // The set of types which have conversions in this class or its 882 // subclasses. As an optimization, we don't copy the derived set 883 // unless it might change. 884 const llvm::SmallPtrSet<CanQualType, 8> *HiddenTypes = &ParentHiddenTypes; 885 llvm::SmallPtrSet<CanQualType, 8> HiddenTypesBuffer; 886 887 // Collect the direct conversions and figure out which conversions 888 // will be hidden in the subclasses. 889 UnresolvedSetImpl &Cs = *Record->getConversionFunctions(); 890 if (!Cs.empty()) { 891 HiddenTypesBuffer = ParentHiddenTypes; 892 HiddenTypes = &HiddenTypesBuffer; 893 894 for (UnresolvedSetIterator I = Cs.begin(), E = Cs.end(); I != E; ++I) { 895 bool Hidden = 896 !HiddenTypesBuffer.insert(GetConversionType(Context, I.getDecl())); 897 898 // If this conversion is hidden and we're in a virtual base, 899 // remember that it's hidden along some inheritance path. 900 if (Hidden && InVirtual) 901 HiddenVBaseCs.insert(cast<NamedDecl>(I.getDecl()->getCanonicalDecl())); 902 903 // If this conversion isn't hidden, add it to the appropriate output. 904 else if (!Hidden) { 905 AccessSpecifier IAccess 906 = CXXRecordDecl::MergeAccess(Access, I.getAccess()); 907 908 if (InVirtual) 909 VOutput.addDecl(I.getDecl(), IAccess); 910 else 911 Output.addDecl(I.getDecl(), IAccess); 912 } 913 } 914 } 915 916 // Collect information recursively from any base classes. 917 for (CXXRecordDecl::base_class_iterator 918 I = Record->bases_begin(), E = Record->bases_end(); I != E; ++I) { 919 const RecordType *RT = I->getType()->getAs<RecordType>(); 920 if (!RT) continue; 921 922 AccessSpecifier BaseAccess 923 = CXXRecordDecl::MergeAccess(Access, I->getAccessSpecifier()); 924 bool BaseInVirtual = InVirtual || I->isVirtual(); 925 926 CXXRecordDecl *Base = cast<CXXRecordDecl>(RT->getDecl()); 927 CollectVisibleConversions(Context, Base, BaseInVirtual, BaseAccess, 928 *HiddenTypes, Output, VOutput, HiddenVBaseCs); 929 } 930 } 931 932 /// Collect the visible conversions of a class. 933 /// 934 /// This would be extremely straightforward if it weren't for virtual 935 /// bases. It might be worth special-casing that, really. 936 static void CollectVisibleConversions(ASTContext &Context, 937 CXXRecordDecl *Record, 938 UnresolvedSetImpl &Output) { 939 // The collection of all conversions in virtual bases that we've 940 // found. These will be added to the output as long as they don't 941 // appear in the hidden-conversions set. 942 UnresolvedSet<8> VBaseCs; 943 944 // The set of conversions in virtual bases that we've determined to 945 // be hidden. 946 llvm::SmallPtrSet<NamedDecl*, 8> HiddenVBaseCs; 947 948 // The set of types hidden by classes derived from this one. 949 llvm::SmallPtrSet<CanQualType, 8> HiddenTypes; 950 951 // Go ahead and collect the direct conversions and add them to the 952 // hidden-types set. 953 UnresolvedSetImpl &Cs = *Record->getConversionFunctions(); 954 Output.append(Cs.begin(), Cs.end()); 955 for (UnresolvedSetIterator I = Cs.begin(), E = Cs.end(); I != E; ++I) 956 HiddenTypes.insert(GetConversionType(Context, I.getDecl())); 957 958 // Recursively collect conversions from base classes. 959 for (CXXRecordDecl::base_class_iterator 960 I = Record->bases_begin(), E = Record->bases_end(); I != E; ++I) { 961 const RecordType *RT = I->getType()->getAs<RecordType>(); 962 if (!RT) continue; 963 964 CollectVisibleConversions(Context, cast<CXXRecordDecl>(RT->getDecl()), 965 I->isVirtual(), I->getAccessSpecifier(), 966 HiddenTypes, Output, VBaseCs, HiddenVBaseCs); 967 } 968 969 // Add any unhidden conversions provided by virtual bases. 970 for (UnresolvedSetIterator I = VBaseCs.begin(), E = VBaseCs.end(); 971 I != E; ++I) { 972 if (!HiddenVBaseCs.count(cast<NamedDecl>(I.getDecl()->getCanonicalDecl()))) 973 Output.addDecl(I.getDecl(), I.getAccess()); 974 } 975 } 976 977 /// getVisibleConversionFunctions - get all conversion functions visible 978 /// in current class; including conversion function templates. 979 const UnresolvedSetImpl *CXXRecordDecl::getVisibleConversionFunctions() { 980 // If root class, all conversions are visible. 981 if (bases_begin() == bases_end()) 982 return &data().Conversions; 983 // If visible conversion list is already evaluated, return it. 984 if (data().ComputedVisibleConversions) 985 return &data().VisibleConversions; 986 CollectVisibleConversions(getASTContext(), this, data().VisibleConversions); 987 data().ComputedVisibleConversions = true; 988 return &data().VisibleConversions; 989 } 990 991 void CXXRecordDecl::removeConversion(const NamedDecl *ConvDecl) { 992 // This operation is O(N) but extremely rare. Sema only uses it to 993 // remove UsingShadowDecls in a class that were followed by a direct 994 // declaration, e.g.: 995 // class A : B { 996 // using B::operator int; 997 // operator int(); 998 // }; 999 // This is uncommon by itself and even more uncommon in conjunction 1000 // with sufficiently large numbers of directly-declared conversions 1001 // that asymptotic behavior matters. 1002 1003 UnresolvedSetImpl &Convs = *getConversionFunctions(); 1004 for (unsigned I = 0, E = Convs.size(); I != E; ++I) { 1005 if (Convs[I].getDecl() == ConvDecl) { 1006 Convs.erase(I); 1007 assert(std::find(Convs.begin(), Convs.end(), ConvDecl) == Convs.end() 1008 && "conversion was found multiple times in unresolved set"); 1009 return; 1010 } 1011 } 1012 1013 llvm_unreachable("conversion not found in set!"); 1014 } 1015 1016 CXXRecordDecl *CXXRecordDecl::getInstantiatedFromMemberClass() const { 1017 if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) 1018 return cast<CXXRecordDecl>(MSInfo->getInstantiatedFrom()); 1019 1020 return 0; 1021 } 1022 1023 MemberSpecializationInfo *CXXRecordDecl::getMemberSpecializationInfo() const { 1024 return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>(); 1025 } 1026 1027 void 1028 CXXRecordDecl::setInstantiationOfMemberClass(CXXRecordDecl *RD, 1029 TemplateSpecializationKind TSK) { 1030 assert(TemplateOrInstantiation.isNull() && 1031 "Previous template or instantiation?"); 1032 assert(!isa<ClassTemplateSpecializationDecl>(this)); 1033 TemplateOrInstantiation 1034 = new (getASTContext()) MemberSpecializationInfo(RD, TSK); 1035 } 1036 1037 TemplateSpecializationKind CXXRecordDecl::getTemplateSpecializationKind() const{ 1038 if (const ClassTemplateSpecializationDecl *Spec 1039 = dyn_cast<ClassTemplateSpecializationDecl>(this)) 1040 return Spec->getSpecializationKind(); 1041 1042 if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) 1043 return MSInfo->getTemplateSpecializationKind(); 1044 1045 return TSK_Undeclared; 1046 } 1047 1048 void 1049 CXXRecordDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK) { 1050 if (ClassTemplateSpecializationDecl *Spec 1051 = dyn_cast<ClassTemplateSpecializationDecl>(this)) { 1052 Spec->setSpecializationKind(TSK); 1053 return; 1054 } 1055 1056 if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) { 1057 MSInfo->setTemplateSpecializationKind(TSK); 1058 return; 1059 } 1060 1061 llvm_unreachable("Not a class template or member class specialization"); 1062 } 1063 1064 CXXDestructorDecl *CXXRecordDecl::getDestructor() const { 1065 ASTContext &Context = getASTContext(); 1066 QualType ClassType = Context.getTypeDeclType(this); 1067 1068 DeclarationName Name 1069 = Context.DeclarationNames.getCXXDestructorName( 1070 Context.getCanonicalType(ClassType)); 1071 1072 DeclContext::lookup_const_iterator I, E; 1073 llvm::tie(I, E) = lookup(Name); 1074 if (I == E) 1075 return 0; 1076 1077 CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(*I); 1078 return Dtor; 1079 } 1080 1081 void CXXRecordDecl::completeDefinition() { 1082 completeDefinition(0); 1083 } 1084 1085 void CXXRecordDecl::completeDefinition(CXXFinalOverriderMap *FinalOverriders) { 1086 RecordDecl::completeDefinition(); 1087 1088 if (hasObjectMember() && getASTContext().getLangOptions().ObjCAutoRefCount) { 1089 // Objective-C Automatic Reference Counting: 1090 // If a class has a non-static data member of Objective-C pointer 1091 // type (or array thereof), it is a non-POD type and its 1092 // default constructor (if any), copy constructor, copy assignment 1093 // operator, and destructor are non-trivial. 1094 struct DefinitionData &Data = data(); 1095 Data.PlainOldData = false; 1096 Data.HasTrivialDefaultConstructor = false; 1097 Data.HasTrivialCopyConstructor = false; 1098 Data.HasTrivialCopyAssignment = false; 1099 Data.HasTrivialDestructor = false; 1100 } 1101 1102 // If the class may be abstract (but hasn't been marked as such), check for 1103 // any pure final overriders. 1104 if (mayBeAbstract()) { 1105 CXXFinalOverriderMap MyFinalOverriders; 1106 if (!FinalOverriders) { 1107 getFinalOverriders(MyFinalOverriders); 1108 FinalOverriders = &MyFinalOverriders; 1109 } 1110 1111 bool Done = false; 1112 for (CXXFinalOverriderMap::iterator M = FinalOverriders->begin(), 1113 MEnd = FinalOverriders->end(); 1114 M != MEnd && !Done; ++M) { 1115 for (OverridingMethods::iterator SO = M->second.begin(), 1116 SOEnd = M->second.end(); 1117 SO != SOEnd && !Done; ++SO) { 1118 assert(SO->second.size() > 0 && 1119 "All virtual functions have overridding virtual functions"); 1120 1121 // C++ [class.abstract]p4: 1122 // A class is abstract if it contains or inherits at least one 1123 // pure virtual function for which the final overrider is pure 1124 // virtual. 1125 if (SO->second.front().Method->isPure()) { 1126 data().Abstract = true; 1127 Done = true; 1128 break; 1129 } 1130 } 1131 } 1132 } 1133 1134 // Set access bits correctly on the directly-declared conversions. 1135 for (UnresolvedSetIterator I = data().Conversions.begin(), 1136 E = data().Conversions.end(); 1137 I != E; ++I) 1138 data().Conversions.setAccess(I, (*I)->getAccess()); 1139 } 1140 1141 bool CXXRecordDecl::mayBeAbstract() const { 1142 if (data().Abstract || isInvalidDecl() || !data().Polymorphic || 1143 isDependentContext()) 1144 return false; 1145 1146 for (CXXRecordDecl::base_class_const_iterator B = bases_begin(), 1147 BEnd = bases_end(); 1148 B != BEnd; ++B) { 1149 CXXRecordDecl *BaseDecl 1150 = cast<CXXRecordDecl>(B->getType()->getAs<RecordType>()->getDecl()); 1151 if (BaseDecl->isAbstract()) 1152 return true; 1153 } 1154 1155 return false; 1156 } 1157 1158 CXXMethodDecl * 1159 CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, 1160 SourceLocation StartLoc, 1161 const DeclarationNameInfo &NameInfo, 1162 QualType T, TypeSourceInfo *TInfo, 1163 bool isStatic, StorageClass SCAsWritten, bool isInline, 1164 bool isConstexpr, SourceLocation EndLocation) { 1165 return new (C) CXXMethodDecl(CXXMethod, RD, StartLoc, NameInfo, T, TInfo, 1166 isStatic, SCAsWritten, isInline, isConstexpr, 1167 EndLocation); 1168 } 1169 1170 bool CXXMethodDecl::isUsualDeallocationFunction() const { 1171 if (getOverloadedOperator() != OO_Delete && 1172 getOverloadedOperator() != OO_Array_Delete) 1173 return false; 1174 1175 // C++ [basic.stc.dynamic.deallocation]p2: 1176 // A template instance is never a usual deallocation function, 1177 // regardless of its signature. 1178 if (getPrimaryTemplate()) 1179 return false; 1180 1181 // C++ [basic.stc.dynamic.deallocation]p2: 1182 // If a class T has a member deallocation function named operator delete 1183 // with exactly one parameter, then that function is a usual (non-placement) 1184 // deallocation function. [...] 1185 if (getNumParams() == 1) 1186 return true; 1187 1188 // C++ [basic.stc.dynamic.deallocation]p2: 1189 // [...] If class T does not declare such an operator delete but does 1190 // declare a member deallocation function named operator delete with 1191 // exactly two parameters, the second of which has type std::size_t (18.1), 1192 // then this function is a usual deallocation function. 1193 ASTContext &Context = getASTContext(); 1194 if (getNumParams() != 2 || 1195 !Context.hasSameUnqualifiedType(getParamDecl(1)->getType(), 1196 Context.getSizeType())) 1197 return false; 1198 1199 // This function is a usual deallocation function if there are no 1200 // single-parameter deallocation functions of the same kind. 1201 for (DeclContext::lookup_const_result R = getDeclContext()->lookup(getDeclName()); 1202 R.first != R.second; ++R.first) { 1203 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*R.first)) 1204 if (FD->getNumParams() == 1) 1205 return false; 1206 } 1207 1208 return true; 1209 } 1210 1211 bool CXXMethodDecl::isCopyAssignmentOperator() const { 1212 // C++0x [class.copy]p17: 1213 // A user-declared copy assignment operator X::operator= is a non-static 1214 // non-template member function of class X with exactly one parameter of 1215 // type X, X&, const X&, volatile X& or const volatile X&. 1216 if (/*operator=*/getOverloadedOperator() != OO_Equal || 1217 /*non-static*/ isStatic() || 1218 /*non-template*/getPrimaryTemplate() || getDescribedFunctionTemplate()) 1219 return false; 1220 1221 QualType ParamType = getParamDecl(0)->getType(); 1222 if (const LValueReferenceType *Ref = ParamType->getAs<LValueReferenceType>()) 1223 ParamType = Ref->getPointeeType(); 1224 1225 ASTContext &Context = getASTContext(); 1226 QualType ClassType 1227 = Context.getCanonicalType(Context.getTypeDeclType(getParent())); 1228 return Context.hasSameUnqualifiedType(ClassType, ParamType); 1229 } 1230 1231 bool CXXMethodDecl::isMoveAssignmentOperator() const { 1232 // C++0x [class.copy]p19: 1233 // A user-declared move assignment operator X::operator= is a non-static 1234 // non-template member function of class X with exactly one parameter of type 1235 // X&&, const X&&, volatile X&&, or const volatile X&&. 1236 if (getOverloadedOperator() != OO_Equal || isStatic() || 1237 getPrimaryTemplate() || getDescribedFunctionTemplate()) 1238 return false; 1239 1240 QualType ParamType = getParamDecl(0)->getType(); 1241 if (!isa<RValueReferenceType>(ParamType)) 1242 return false; 1243 ParamType = ParamType->getPointeeType(); 1244 1245 ASTContext &Context = getASTContext(); 1246 QualType ClassType 1247 = Context.getCanonicalType(Context.getTypeDeclType(getParent())); 1248 return Context.hasSameUnqualifiedType(ClassType, ParamType); 1249 } 1250 1251 void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) { 1252 assert(MD->isCanonicalDecl() && "Method is not canonical!"); 1253 assert(!MD->getParent()->isDependentContext() && 1254 "Can't add an overridden method to a class template!"); 1255 1256 getASTContext().addOverriddenMethod(this, MD); 1257 } 1258 1259 CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const { 1260 return getASTContext().overridden_methods_begin(this); 1261 } 1262 1263 CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const { 1264 return getASTContext().overridden_methods_end(this); 1265 } 1266 1267 unsigned CXXMethodDecl::size_overridden_methods() const { 1268 return getASTContext().overridden_methods_size(this); 1269 } 1270 1271 QualType CXXMethodDecl::getThisType(ASTContext &C) const { 1272 // C++ 9.3.2p1: The type of this in a member function of a class X is X*. 1273 // If the member function is declared const, the type of this is const X*, 1274 // if the member function is declared volatile, the type of this is 1275 // volatile X*, and if the member function is declared const volatile, 1276 // the type of this is const volatile X*. 1277 1278 assert(isInstance() && "No 'this' for static methods!"); 1279 1280 QualType ClassTy = C.getTypeDeclType(getParent()); 1281 ClassTy = C.getQualifiedType(ClassTy, 1282 Qualifiers::fromCVRMask(getTypeQualifiers())); 1283 return C.getPointerType(ClassTy); 1284 } 1285 1286 bool CXXMethodDecl::hasInlineBody() const { 1287 // If this function is a template instantiation, look at the template from 1288 // which it was instantiated. 1289 const FunctionDecl *CheckFn = getTemplateInstantiationPattern(); 1290 if (!CheckFn) 1291 CheckFn = this; 1292 1293 const FunctionDecl *fn; 1294 return CheckFn->hasBody(fn) && !fn->isOutOfLine(); 1295 } 1296 1297 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, 1298 TypeSourceInfo *TInfo, bool IsVirtual, 1299 SourceLocation L, Expr *Init, 1300 SourceLocation R, 1301 SourceLocation EllipsisLoc) 1302 : Initializee(TInfo), MemberOrEllipsisLocation(EllipsisLoc), Init(Init), 1303 LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(IsVirtual), 1304 IsWritten(false), SourceOrderOrNumArrayIndices(0) 1305 { 1306 } 1307 1308 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, 1309 FieldDecl *Member, 1310 SourceLocation MemberLoc, 1311 SourceLocation L, Expr *Init, 1312 SourceLocation R) 1313 : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), 1314 LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false), 1315 IsWritten(false), SourceOrderOrNumArrayIndices(0) 1316 { 1317 } 1318 1319 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, 1320 IndirectFieldDecl *Member, 1321 SourceLocation MemberLoc, 1322 SourceLocation L, Expr *Init, 1323 SourceLocation R) 1324 : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), 1325 LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false), 1326 IsWritten(false), SourceOrderOrNumArrayIndices(0) 1327 { 1328 } 1329 1330 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, 1331 TypeSourceInfo *TInfo, 1332 SourceLocation L, Expr *Init, 1333 SourceLocation R) 1334 : Initializee(TInfo), MemberOrEllipsisLocation(), Init(Init), 1335 LParenLoc(L), RParenLoc(R), IsDelegating(true), IsVirtual(false), 1336 IsWritten(false), SourceOrderOrNumArrayIndices(0) 1337 { 1338 } 1339 1340 CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, 1341 FieldDecl *Member, 1342 SourceLocation MemberLoc, 1343 SourceLocation L, Expr *Init, 1344 SourceLocation R, 1345 VarDecl **Indices, 1346 unsigned NumIndices) 1347 : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), 1348 LParenLoc(L), RParenLoc(R), IsVirtual(false), 1349 IsWritten(false), SourceOrderOrNumArrayIndices(NumIndices) 1350 { 1351 VarDecl **MyIndices = reinterpret_cast<VarDecl **> (this + 1); 1352 memcpy(MyIndices, Indices, NumIndices * sizeof(VarDecl *)); 1353 } 1354 1355 CXXCtorInitializer *CXXCtorInitializer::Create(ASTContext &Context, 1356 FieldDecl *Member, 1357 SourceLocation MemberLoc, 1358 SourceLocation L, Expr *Init, 1359 SourceLocation R, 1360 VarDecl **Indices, 1361 unsigned NumIndices) { 1362 void *Mem = Context.Allocate(sizeof(CXXCtorInitializer) + 1363 sizeof(VarDecl *) * NumIndices, 1364 llvm::alignOf<CXXCtorInitializer>()); 1365 return new (Mem) CXXCtorInitializer(Context, Member, MemberLoc, L, Init, R, 1366 Indices, NumIndices); 1367 } 1368 1369 TypeLoc CXXCtorInitializer::getBaseClassLoc() const { 1370 if (isBaseInitializer()) 1371 return Initializee.get<TypeSourceInfo*>()->getTypeLoc(); 1372 else 1373 return TypeLoc(); 1374 } 1375 1376 const Type *CXXCtorInitializer::getBaseClass() const { 1377 if (isBaseInitializer()) 1378 return Initializee.get<TypeSourceInfo*>()->getType().getTypePtr(); 1379 else 1380 return 0; 1381 } 1382 1383 SourceLocation CXXCtorInitializer::getSourceLocation() const { 1384 if (isAnyMemberInitializer()) 1385 return getMemberLocation(); 1386 1387 if (isInClassMemberInitializer()) 1388 return getAnyMember()->getLocation(); 1389 1390 if (TypeSourceInfo *TSInfo = Initializee.get<TypeSourceInfo*>()) 1391 return TSInfo->getTypeLoc().getLocalSourceRange().getBegin(); 1392 1393 return SourceLocation(); 1394 } 1395 1396 SourceRange CXXCtorInitializer::getSourceRange() const { 1397 if (isInClassMemberInitializer()) { 1398 FieldDecl *D = getAnyMember(); 1399 if (Expr *I = D->getInClassInitializer()) 1400 return I->getSourceRange(); 1401 return SourceRange(); 1402 } 1403 1404 return SourceRange(getSourceLocation(), getRParenLoc()); 1405 } 1406 1407 CXXConstructorDecl * 1408 CXXConstructorDecl::Create(ASTContext &C, EmptyShell Empty) { 1409 return new (C) CXXConstructorDecl(0, SourceLocation(), DeclarationNameInfo(), 1410 QualType(), 0, false, false, false, false); 1411 } 1412 1413 CXXConstructorDecl * 1414 CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, 1415 SourceLocation StartLoc, 1416 const DeclarationNameInfo &NameInfo, 1417 QualType T, TypeSourceInfo *TInfo, 1418 bool isExplicit, bool isInline, 1419 bool isImplicitlyDeclared, bool isConstexpr) { 1420 assert(NameInfo.getName().getNameKind() 1421 == DeclarationName::CXXConstructorName && 1422 "Name must refer to a constructor"); 1423 return new (C) CXXConstructorDecl(RD, StartLoc, NameInfo, T, TInfo, 1424 isExplicit, isInline, isImplicitlyDeclared, 1425 isConstexpr); 1426 } 1427 1428 CXXConstructorDecl *CXXConstructorDecl::getTargetConstructor() const { 1429 assert(isDelegatingConstructor() && "Not a delegating constructor!"); 1430 Expr *E = (*init_begin())->getInit()->IgnoreImplicit(); 1431 if (CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(E)) 1432 return Construct->getConstructor(); 1433 1434 return 0; 1435 } 1436 1437 bool CXXConstructorDecl::isDefaultConstructor() const { 1438 // C++ [class.ctor]p5: 1439 // A default constructor for a class X is a constructor of class 1440 // X that can be called without an argument. 1441 return (getNumParams() == 0) || 1442 (getNumParams() > 0 && getParamDecl(0)->hasDefaultArg()); 1443 } 1444 1445 bool 1446 CXXConstructorDecl::isCopyConstructor(unsigned &TypeQuals) const { 1447 return isCopyOrMoveConstructor(TypeQuals) && 1448 getParamDecl(0)->getType()->isLValueReferenceType(); 1449 } 1450 1451 bool CXXConstructorDecl::isMoveConstructor(unsigned &TypeQuals) const { 1452 return isCopyOrMoveConstructor(TypeQuals) && 1453 getParamDecl(0)->getType()->isRValueReferenceType(); 1454 } 1455 1456 /// \brief Determine whether this is a copy or move constructor. 1457 bool CXXConstructorDecl::isCopyOrMoveConstructor(unsigned &TypeQuals) const { 1458 // C++ [class.copy]p2: 1459 // A non-template constructor for class X is a copy constructor 1460 // if its first parameter is of type X&, const X&, volatile X& or 1461 // const volatile X&, and either there are no other parameters 1462 // or else all other parameters have default arguments (8.3.6). 1463 // C++0x [class.copy]p3: 1464 // A non-template constructor for class X is a move constructor if its 1465 // first parameter is of type X&&, const X&&, volatile X&&, or 1466 // const volatile X&&, and either there are no other parameters or else 1467 // all other parameters have default arguments. 1468 if ((getNumParams() < 1) || 1469 (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) || 1470 (getPrimaryTemplate() != 0) || 1471 (getDescribedFunctionTemplate() != 0)) 1472 return false; 1473 1474 const ParmVarDecl *Param = getParamDecl(0); 1475 1476 // Do we have a reference type? 1477 const ReferenceType *ParamRefType = Param->getType()->getAs<ReferenceType>(); 1478 if (!ParamRefType) 1479 return false; 1480 1481 // Is it a reference to our class type? 1482 ASTContext &Context = getASTContext(); 1483 1484 CanQualType PointeeType 1485 = Context.getCanonicalType(ParamRefType->getPointeeType()); 1486 CanQualType ClassTy 1487 = Context.getCanonicalType(Context.getTagDeclType(getParent())); 1488 if (PointeeType.getUnqualifiedType() != ClassTy) 1489 return false; 1490 1491 // FIXME: other qualifiers? 1492 1493 // We have a copy or move constructor. 1494 TypeQuals = PointeeType.getCVRQualifiers(); 1495 return true; 1496 } 1497 1498 bool CXXConstructorDecl::isConvertingConstructor(bool AllowExplicit) const { 1499 // C++ [class.conv.ctor]p1: 1500 // A constructor declared without the function-specifier explicit 1501 // that can be called with a single parameter specifies a 1502 // conversion from the type of its first parameter to the type of 1503 // its class. Such a constructor is called a converting 1504 // constructor. 1505 if (isExplicit() && !AllowExplicit) 1506 return false; 1507 1508 return (getNumParams() == 0 && 1509 getType()->getAs<FunctionProtoType>()->isVariadic()) || 1510 (getNumParams() == 1) || 1511 (getNumParams() > 1 && getParamDecl(1)->hasDefaultArg()); 1512 } 1513 1514 bool CXXConstructorDecl::isSpecializationCopyingObject() const { 1515 if ((getNumParams() < 1) || 1516 (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) || 1517 (getPrimaryTemplate() == 0) || 1518 (getDescribedFunctionTemplate() != 0)) 1519 return false; 1520 1521 const ParmVarDecl *Param = getParamDecl(0); 1522 1523 ASTContext &Context = getASTContext(); 1524 CanQualType ParamType = Context.getCanonicalType(Param->getType()); 1525 1526 // Is it the same as our our class type? 1527 CanQualType ClassTy 1528 = Context.getCanonicalType(Context.getTagDeclType(getParent())); 1529 if (ParamType.getUnqualifiedType() != ClassTy) 1530 return false; 1531 1532 return true; 1533 } 1534 1535 const CXXConstructorDecl *CXXConstructorDecl::getInheritedConstructor() const { 1536 // Hack: we store the inherited constructor in the overridden method table 1537 method_iterator It = begin_overridden_methods(); 1538 if (It == end_overridden_methods()) 1539 return 0; 1540 1541 return cast<CXXConstructorDecl>(*It); 1542 } 1543 1544 void 1545 CXXConstructorDecl::setInheritedConstructor(const CXXConstructorDecl *BaseCtor){ 1546 // Hack: we store the inherited constructor in the overridden method table 1547 assert(size_overridden_methods() == 0 && "Base ctor already set."); 1548 addOverriddenMethod(BaseCtor); 1549 } 1550 1551 CXXDestructorDecl * 1552 CXXDestructorDecl::Create(ASTContext &C, EmptyShell Empty) { 1553 return new (C) CXXDestructorDecl(0, SourceLocation(), DeclarationNameInfo(), 1554 QualType(), 0, false, false); 1555 } 1556 1557 CXXDestructorDecl * 1558 CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, 1559 SourceLocation StartLoc, 1560 const DeclarationNameInfo &NameInfo, 1561 QualType T, TypeSourceInfo *TInfo, 1562 bool isInline, bool isImplicitlyDeclared) { 1563 assert(NameInfo.getName().getNameKind() 1564 == DeclarationName::CXXDestructorName && 1565 "Name must refer to a destructor"); 1566 return new (C) CXXDestructorDecl(RD, StartLoc, NameInfo, T, TInfo, isInline, 1567 isImplicitlyDeclared); 1568 } 1569 1570 CXXConversionDecl * 1571 CXXConversionDecl::Create(ASTContext &C, EmptyShell Empty) { 1572 return new (C) CXXConversionDecl(0, SourceLocation(), DeclarationNameInfo(), 1573 QualType(), 0, false, false, false, 1574 SourceLocation()); 1575 } 1576 1577 CXXConversionDecl * 1578 CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD, 1579 SourceLocation StartLoc, 1580 const DeclarationNameInfo &NameInfo, 1581 QualType T, TypeSourceInfo *TInfo, 1582 bool isInline, bool isExplicit, 1583 bool isConstexpr, SourceLocation EndLocation) { 1584 assert(NameInfo.getName().getNameKind() 1585 == DeclarationName::CXXConversionFunctionName && 1586 "Name must refer to a conversion function"); 1587 return new (C) CXXConversionDecl(RD, StartLoc, NameInfo, T, TInfo, 1588 isInline, isExplicit, isConstexpr, 1589 EndLocation); 1590 } 1591 1592 LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, 1593 DeclContext *DC, 1594 SourceLocation ExternLoc, 1595 SourceLocation LangLoc, 1596 LanguageIDs Lang, 1597 SourceLocation RBraceLoc) { 1598 return new (C) LinkageSpecDecl(DC, ExternLoc, LangLoc, Lang, RBraceLoc); 1599 } 1600 1601 UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC, 1602 SourceLocation L, 1603 SourceLocation NamespaceLoc, 1604 NestedNameSpecifierLoc QualifierLoc, 1605 SourceLocation IdentLoc, 1606 NamedDecl *Used, 1607 DeclContext *CommonAncestor) { 1608 if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Used)) 1609 Used = NS->getOriginalNamespace(); 1610 return new (C) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierLoc, 1611 IdentLoc, Used, CommonAncestor); 1612 } 1613 1614 NamespaceDecl *UsingDirectiveDecl::getNominatedNamespace() { 1615 if (NamespaceAliasDecl *NA = 1616 dyn_cast_or_null<NamespaceAliasDecl>(NominatedNamespace)) 1617 return NA->getNamespace(); 1618 return cast_or_null<NamespaceDecl>(NominatedNamespace); 1619 } 1620 1621 NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC, 1622 SourceLocation UsingLoc, 1623 SourceLocation AliasLoc, 1624 IdentifierInfo *Alias, 1625 NestedNameSpecifierLoc QualifierLoc, 1626 SourceLocation IdentLoc, 1627 NamedDecl *Namespace) { 1628 if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Namespace)) 1629 Namespace = NS->getOriginalNamespace(); 1630 return new (C) NamespaceAliasDecl(DC, UsingLoc, AliasLoc, Alias, 1631 QualifierLoc, IdentLoc, Namespace); 1632 } 1633 1634 UsingDecl *UsingShadowDecl::getUsingDecl() const { 1635 const UsingShadowDecl *Shadow = this; 1636 while (const UsingShadowDecl *NextShadow = 1637 dyn_cast<UsingShadowDecl>(Shadow->UsingOrNextShadow)) 1638 Shadow = NextShadow; 1639 return cast<UsingDecl>(Shadow->UsingOrNextShadow); 1640 } 1641 1642 void UsingDecl::addShadowDecl(UsingShadowDecl *S) { 1643 assert(std::find(shadow_begin(), shadow_end(), S) == shadow_end() && 1644 "declaration already in set"); 1645 assert(S->getUsingDecl() == this); 1646 1647 if (FirstUsingShadow) 1648 S->UsingOrNextShadow = FirstUsingShadow; 1649 FirstUsingShadow = S; 1650 } 1651 1652 void UsingDecl::removeShadowDecl(UsingShadowDecl *S) { 1653 assert(std::find(shadow_begin(), shadow_end(), S) != shadow_end() && 1654 "declaration not in set"); 1655 assert(S->getUsingDecl() == this); 1656 1657 // Remove S from the shadow decl chain. This is O(n) but hopefully rare. 1658 1659 if (FirstUsingShadow == S) { 1660 FirstUsingShadow = dyn_cast<UsingShadowDecl>(S->UsingOrNextShadow); 1661 S->UsingOrNextShadow = this; 1662 return; 1663 } 1664 1665 UsingShadowDecl *Prev = FirstUsingShadow; 1666 while (Prev->UsingOrNextShadow != S) 1667 Prev = cast<UsingShadowDecl>(Prev->UsingOrNextShadow); 1668 Prev->UsingOrNextShadow = S->UsingOrNextShadow; 1669 S->UsingOrNextShadow = this; 1670 } 1671 1672 UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation UL, 1673 NestedNameSpecifierLoc QualifierLoc, 1674 const DeclarationNameInfo &NameInfo, 1675 bool IsTypeNameArg) { 1676 return new (C) UsingDecl(DC, UL, QualifierLoc, NameInfo, IsTypeNameArg); 1677 } 1678 1679 UnresolvedUsingValueDecl * 1680 UnresolvedUsingValueDecl::Create(ASTContext &C, DeclContext *DC, 1681 SourceLocation UsingLoc, 1682 NestedNameSpecifierLoc QualifierLoc, 1683 const DeclarationNameInfo &NameInfo) { 1684 return new (C) UnresolvedUsingValueDecl(DC, C.DependentTy, UsingLoc, 1685 QualifierLoc, NameInfo); 1686 } 1687 1688 UnresolvedUsingTypenameDecl * 1689 UnresolvedUsingTypenameDecl::Create(ASTContext &C, DeclContext *DC, 1690 SourceLocation UsingLoc, 1691 SourceLocation TypenameLoc, 1692 NestedNameSpecifierLoc QualifierLoc, 1693 SourceLocation TargetNameLoc, 1694 DeclarationName TargetName) { 1695 return new (C) UnresolvedUsingTypenameDecl(DC, UsingLoc, TypenameLoc, 1696 QualifierLoc, TargetNameLoc, 1697 TargetName.getAsIdentifierInfo()); 1698 } 1699 1700 StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC, 1701 SourceLocation StaticAssertLoc, 1702 Expr *AssertExpr, 1703 StringLiteral *Message, 1704 SourceLocation RParenLoc) { 1705 return new (C) StaticAssertDecl(DC, StaticAssertLoc, AssertExpr, Message, 1706 RParenLoc); 1707 } 1708 1709 static const char *getAccessName(AccessSpecifier AS) { 1710 switch (AS) { 1711 default: 1712 case AS_none: 1713 llvm_unreachable("Invalid access specifier!"); 1714 case AS_public: 1715 return "public"; 1716 case AS_private: 1717 return "private"; 1718 case AS_protected: 1719 return "protected"; 1720 } 1721 } 1722 1723 const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB, 1724 AccessSpecifier AS) { 1725 return DB << getAccessName(AS); 1726 } 1727