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