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