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 | 109f5fc | 2013-04-08 17:12:58 +0000 | [diff] [blame] | 545 | // FIXME: We use the 'unsafe' accessor for the access specifier here, |
| 546 | // because Sema may not have set it yet. That's really just a misdesign |
| 547 | // in Sema. However, LLDB *will* have set the access specifier correctly, |
| 548 | // and adds declarations after the class is technically completed, |
| 549 | // so completeDefinition()'s overriding of the access specifiers doesn't |
| 550 | // work. |
| 551 | AccessSpecifier AS = Conversion->getAccessUnsafe(); |
| 552 | |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 553 | if (Conversion->getPrimaryTemplate()) { |
| 554 | // We don't record specializations. |
| 555 | } else if (FunTmpl) { |
Douglas Gregor | ef96ee0 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 556 | if (FunTmpl->getPreviousDecl()) |
| 557 | data().Conversions.replace(FunTmpl->getPreviousDecl(), |
Douglas Gregor | 109f5fc | 2013-04-08 17:12:58 +0000 | [diff] [blame] | 558 | FunTmpl, AS); |
Douglas Gregor | e80622f | 2010-09-29 04:25:11 +0000 | [diff] [blame] | 559 | else |
Douglas Gregor | 109f5fc | 2013-04-08 17:12:58 +0000 | [diff] [blame] | 560 | data().Conversions.addDecl(getASTContext(), FunTmpl, AS); |
Douglas Gregor | e80622f | 2010-09-29 04:25:11 +0000 | [diff] [blame] | 561 | } else { |
Douglas Gregor | ef96ee0 | 2012-01-14 16:38:05 +0000 | [diff] [blame] | 562 | if (Conversion->getPreviousDecl()) |
| 563 | data().Conversions.replace(Conversion->getPreviousDecl(), |
Douglas Gregor | 109f5fc | 2013-04-08 17:12:58 +0000 | [diff] [blame] | 564 | Conversion, AS); |
Douglas Gregor | e80622f | 2010-09-29 04:25:11 +0000 | [diff] [blame] | 565 | else |
Douglas Gregor | 109f5fc | 2013-04-08 17:12:58 +0000 | [diff] [blame] | 566 | data().Conversions.addDecl(getASTContext(), Conversion, AS); |
Douglas Gregor | e80622f | 2010-09-29 04:25:11 +0000 | [diff] [blame] | 567 | } |
| 568 | } |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 569 | |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 570 | if (SMKind) { |
Richard Smith | ac71351 | 2012-12-08 02:53:02 +0000 | [diff] [blame] | 571 | // If this is the first declaration of a special member, we no longer have |
| 572 | // an implicit trivial special member. |
| 573 | data().HasTrivialSpecialMembers &= |
| 574 | data().DeclaredSpecialMembers | ~SMKind; |
| 575 | |
| 576 | if (!Method->isImplicit() && !Method->isUserProvided()) { |
| 577 | // This method is user-declared but not user-provided. We can't work out |
| 578 | // whether it's trivial yet (not until we get to the end of the class). |
| 579 | // We'll handle this method in finishedDefaultedOrDeletedMember. |
| 580 | } else if (Method->isTrivial()) |
| 581 | data().HasTrivialSpecialMembers |= SMKind; |
| 582 | else |
| 583 | data().DeclaredNonTrivialSpecialMembers |= SMKind; |
| 584 | |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 585 | // Note when we have declared a declared special member, and suppress the |
| 586 | // implicit declaration of this special member. |
| 587 | data().DeclaredSpecialMembers |= SMKind; |
| 588 | |
| 589 | if (!Method->isImplicit()) { |
| 590 | data().UserDeclaredSpecialMembers |= SMKind; |
| 591 | |
| 592 | // C++03 [class]p4: |
| 593 | // A POD-struct is an aggregate class that has [...] no user-defined |
| 594 | // copy assignment operator and no user-defined destructor. |
| 595 | // |
| 596 | // Since the POD bit is meant to be C++03 POD-ness, and in C++03, |
| 597 | // aggregates could not have any constructors, clear it even for an |
| 598 | // explicitly defaulted or deleted constructor. |
| 599 | // type is technically an aggregate in C++0x since it wouldn't be in 03. |
| 600 | // |
| 601 | // Also, a user-declared move assignment operator makes a class non-POD. |
| 602 | // This is an extension in C++03. |
| 603 | data().PlainOldData = false; |
| 604 | } |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 605 | } |
| 606 | |
Douglas Gregor | 27c08ab | 2010-09-27 22:06:20 +0000 | [diff] [blame] | 607 | return; |
Douglas Gregor | 1f2023a | 2009-07-22 18:25:24 +0000 | [diff] [blame] | 608 | } |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 609 | |
Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 610 | // Handle non-static data members. |
| 611 | if (FieldDecl *Field = dyn_cast<FieldDecl>(D)) { |
Douglas Gregor | d61db33 | 2011-10-10 17:22:13 +0000 | [diff] [blame] | 612 | // C++ [class.bit]p2: |
| 613 | // A declaration for a bit-field that omits the identifier declares an |
| 614 | // unnamed bit-field. Unnamed bit-fields are not members and cannot be |
| 615 | // initialized. |
| 616 | if (Field->isUnnamedBitfield()) |
| 617 | return; |
| 618 | |
Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 619 | // C++ [dcl.init.aggr]p1: |
| 620 | // An aggregate is an array or a class (clause 9) with [...] no |
| 621 | // private or protected non-static data members (clause 11). |
| 622 | // |
| 623 | // A POD must be an aggregate. |
| 624 | if (D->getAccess() == AS_private || D->getAccess() == AS_protected) { |
| 625 | data().Aggregate = false; |
| 626 | data().PlainOldData = false; |
| 627 | } |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 628 | |
| 629 | // C++0x [class]p7: |
| 630 | // A standard-layout class is a class that: |
| 631 | // [...] |
| 632 | // -- has the same access control for all non-static data members, |
| 633 | switch (D->getAccess()) { |
| 634 | case AS_private: data().HasPrivateFields = true; break; |
| 635 | case AS_protected: data().HasProtectedFields = true; break; |
| 636 | case AS_public: data().HasPublicFields = true; break; |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 637 | case AS_none: llvm_unreachable("Invalid access specifier"); |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 638 | }; |
| 639 | if ((data().HasPrivateFields + data().HasProtectedFields + |
| 640 | data().HasPublicFields) > 1) |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 641 | data().IsStandardLayout = false; |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 642 | |
Douglas Gregor | 2bb1101 | 2011-05-13 01:05:07 +0000 | [diff] [blame] | 643 | // Keep track of the presence of mutable fields. |
| 644 | if (Field->isMutable()) |
| 645 | data().HasMutableFields = true; |
| 646 | |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 647 | // C++0x [class]p9: |
Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 648 | // A POD struct is a class that is both a trivial class and a |
| 649 | // standard-layout class, and has no non-static data members of type |
| 650 | // non-POD struct, non-POD union (or array of such types). |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 651 | // |
| 652 | // Automatic Reference Counting: the presence of a member of Objective-C pointer type |
| 653 | // that does not explicitly have no lifetime makes the class a non-POD. |
| 654 | // However, we delay setting PlainOldData to false in this case so that |
| 655 | // 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] | 656 | // non-POD with Automatic Reference Counting but a POD without ARC. |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 657 | // In this case, the class will become a non-POD class when we complete |
| 658 | // the definition. |
Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 659 | ASTContext &Context = getASTContext(); |
| 660 | QualType T = Context.getBaseElementType(Field->getType()); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 661 | if (T->isObjCRetainableType() || T.isObjCGCStrong()) { |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 662 | if (!Context.getLangOpts().ObjCAutoRefCount || |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 663 | T.getObjCLifetime() != Qualifiers::OCL_ExplicitNone) |
| 664 | setHasObjectMember(true); |
| 665 | } else if (!T.isPODType(Context)) |
Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 666 | data().PlainOldData = false; |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 667 | |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 668 | if (T->isReferenceType()) { |
Richard Smith | d5bc867 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 669 | if (!Field->hasInClassInitializer()) |
| 670 | data().HasUninitializedReferenceMember = true; |
Chandler Carruth | 9b6347c | 2011-04-24 02:49:34 +0000 | [diff] [blame] | 671 | |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 672 | // C++0x [class]p7: |
| 673 | // A standard-layout class is a class that: |
| 674 | // -- has no non-static data members of type [...] reference, |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 675 | data().IsStandardLayout = false; |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 676 | } |
| 677 | |
Richard Smith | 86c3ae4 | 2012-02-13 03:54:03 +0000 | [diff] [blame] | 678 | // Record if this field is the first non-literal or volatile field or base. |
| 679 | if (!T->isLiteralType() || T.isVolatileQualified()) |
Chandler Carruth | 9b6347c | 2011-04-24 02:49:34 +0000 | [diff] [blame] | 680 | data().HasNonLiteralTypeFieldsOrBases = true; |
| 681 | |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 682 | if (Field->hasInClassInitializer()) { |
Richard Smith | d079abf | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 683 | data().HasInClassInitializer = true; |
| 684 | |
| 685 | // C++11 [class]p5: |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 686 | // A default constructor is trivial if [...] no non-static data member |
| 687 | // of its class has a brace-or-equal-initializer. |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 688 | data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor; |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 689 | |
Richard Smith | d079abf | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 690 | // C++11 [dcl.init.aggr]p1: |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 691 | // An aggregate is a [...] class with [...] no |
| 692 | // brace-or-equal-initializers for non-static data members. |
| 693 | data().Aggregate = false; |
| 694 | |
Richard Smith | d079abf | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 695 | // C++11 [class]p10: |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 696 | // A POD struct is [...] a trivial class. |
| 697 | data().PlainOldData = false; |
| 698 | } |
| 699 | |
Richard Smith | bc2a35d | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 700 | // C++11 [class.copy]p23: |
| 701 | // A defaulted copy/move assignment operator for a class X is defined |
| 702 | // as deleted if X has: |
| 703 | // -- a non-static data member of reference type |
| 704 | if (T->isReferenceType()) |
| 705 | data().DefaultedMoveAssignmentIsDeleted = true; |
| 706 | |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 707 | if (const RecordType *RecordTy = T->getAs<RecordType>()) { |
| 708 | CXXRecordDecl* FieldRec = cast<CXXRecordDecl>(RecordTy->getDecl()); |
| 709 | if (FieldRec->getDefinition()) { |
Richard Smith | bc2a35d | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 710 | addedClassSubobject(FieldRec); |
| 711 | |
| 712 | // C++11 [class.ctor]p5, C++11 [class.copy]p11: |
| 713 | // A defaulted [special member] for a class X is defined as |
| 714 | // deleted if: |
| 715 | // -- X is a union-like class that has a variant member with a |
| 716 | // non-trivial [corresponding special member] |
| 717 | if (isUnion()) { |
| 718 | if (FieldRec->hasNonTrivialMoveConstructor()) |
| 719 | data().DefaultedMoveConstructorIsDeleted = true; |
| 720 | if (FieldRec->hasNonTrivialMoveAssignment()) |
| 721 | data().DefaultedMoveAssignmentIsDeleted = true; |
| 722 | if (FieldRec->hasNonTrivialDestructor()) |
| 723 | data().DefaultedDestructorIsDeleted = true; |
| 724 | } |
| 725 | |
Sean Hunt | 023df37 | 2011-05-09 18:22:59 +0000 | [diff] [blame] | 726 | // C++0x [class.ctor]p5: |
Richard Smith | 6180245 | 2011-12-22 02:22:31 +0000 | [diff] [blame] | 727 | // A default constructor is trivial [...] if: |
Sean Hunt | 023df37 | 2011-05-09 18:22:59 +0000 | [diff] [blame] | 728 | // -- for all the non-static data members of its class that are of |
| 729 | // class type (or array thereof), each such class has a trivial |
| 730 | // default constructor. |
| 731 | if (!FieldRec->hasTrivialDefaultConstructor()) |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 732 | data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 733 | |
| 734 | // C++0x [class.copy]p13: |
| 735 | // A copy/move constructor for class X is trivial if [...] |
| 736 | // [...] |
| 737 | // -- for each non-static data member of X that is of class type (or |
| 738 | // an array thereof), the constructor selected to copy/move that |
| 739 | // member is trivial; |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 740 | if (!FieldRec->hasTrivialCopyConstructor()) |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 741 | data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor; |
Richard Smith | bc2a35d | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 742 | // If the field doesn't have a simple move constructor, we'll eagerly |
| 743 | // declare the move constructor for this class and we'll decide whether |
| 744 | // it's trivial then. |
Richard Smith | 426391c | 2012-11-16 00:53:38 +0000 | [diff] [blame] | 745 | if (!FieldRec->hasTrivialMoveConstructor()) |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 746 | data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 747 | |
| 748 | // C++0x [class.copy]p27: |
| 749 | // A copy/move assignment operator for class X is trivial if [...] |
| 750 | // [...] |
| 751 | // -- for each non-static data member of X that is of class type (or |
| 752 | // an array thereof), the assignment operator selected to |
| 753 | // copy/move that member is trivial; |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 754 | if (!FieldRec->hasTrivialCopyAssignment()) |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 755 | data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment; |
Richard Smith | bc2a35d | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 756 | // If the field doesn't have a simple move assignment, we'll eagerly |
| 757 | // declare the move assignment for this class and we'll decide whether |
| 758 | // it's trivial then. |
Richard Smith | 426391c | 2012-11-16 00:53:38 +0000 | [diff] [blame] | 759 | if (!FieldRec->hasTrivialMoveAssignment()) |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 760 | data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment; |
Chandler Carruth | 4d6e5a2 | 2011-04-23 23:10:33 +0000 | [diff] [blame] | 761 | |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 762 | if (!FieldRec->hasTrivialDestructor()) |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 763 | data().HasTrivialSpecialMembers &= ~SMF_Destructor; |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 764 | if (!FieldRec->hasIrrelevantDestructor()) |
| 765 | data().HasIrrelevantDestructor = false; |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 766 | if (FieldRec->hasObjectMember()) |
| 767 | setHasObjectMember(true); |
Fariborz Jahanian | 3ac83d6 | 2013-01-25 23:57:05 +0000 | [diff] [blame] | 768 | if (FieldRec->hasVolatileMember()) |
| 769 | setHasVolatileMember(true); |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 770 | |
| 771 | // C++0x [class]p7: |
| 772 | // A standard-layout class is a class that: |
| 773 | // -- has no non-static data members of type non-standard-layout |
| 774 | // class (or array of such types) [...] |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 775 | if (!FieldRec->isStandardLayout()) |
| 776 | data().IsStandardLayout = false; |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 777 | |
| 778 | // C++0x [class]p7: |
| 779 | // A standard-layout class is a class that: |
| 780 | // [...] |
| 781 | // -- has no base classes of the same type as the first non-static |
| 782 | // data member. |
| 783 | // We don't want to expend bits in the state of the record decl |
| 784 | // tracking whether this is the first non-static data member so we |
| 785 | // cheat a bit and use some of the existing state: the empty bit. |
| 786 | // Virtual bases and virtual methods make a class non-empty, but they |
| 787 | // also make it non-standard-layout so we needn't check here. |
| 788 | // A non-empty base class may leave the class standard-layout, but not |
| 789 | // 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] | 790 | // member. If IsStandardLayout remains true, then the first non-static |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 791 | // data member must come through here with Empty still true, and Empty |
| 792 | // will subsequently be set to false below. |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 793 | if (data().IsStandardLayout && data().Empty) { |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 794 | for (CXXRecordDecl::base_class_const_iterator BI = bases_begin(), |
| 795 | BE = bases_end(); |
| 796 | BI != BE; ++BI) { |
| 797 | if (Context.hasSameUnqualifiedType(BI->getType(), T)) { |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 798 | data().IsStandardLayout = false; |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 799 | break; |
| 800 | } |
| 801 | } |
| 802 | } |
Douglas Gregor | 2bb1101 | 2011-05-13 01:05:07 +0000 | [diff] [blame] | 803 | |
| 804 | // Keep track of the presence of mutable fields. |
| 805 | if (FieldRec->hasMutableFields()) |
| 806 | data().HasMutableFields = true; |
Richard Smith | 6180245 | 2011-12-22 02:22:31 +0000 | [diff] [blame] | 807 | |
| 808 | // C++11 [class.copy]p13: |
| 809 | // If the implicitly-defined constructor would satisfy the |
| 810 | // requirements of a constexpr constructor, the implicitly-defined |
| 811 | // constructor is constexpr. |
| 812 | // C++11 [dcl.constexpr]p4: |
| 813 | // -- every constructor involved in initializing non-static data |
| 814 | // members [...] shall be a constexpr constructor |
| 815 | if (!Field->hasInClassInitializer() && |
Richard Smith | d079abf | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 816 | !FieldRec->hasConstexprDefaultConstructor() && !isUnion()) |
Richard Smith | 6180245 | 2011-12-22 02:22:31 +0000 | [diff] [blame] | 817 | // The standard requires any in-class initializer to be a constant |
| 818 | // expression. We consider this to be a defect. |
| 819 | data().DefaultedDefaultConstructorIsConstexpr = false; |
Richard Smith | acf796b | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 820 | |
| 821 | // C++11 [class.copy]p8: |
| 822 | // The implicitly-declared copy constructor for a class X will have |
| 823 | // the form 'X::X(const X&)' if [...] for all the non-static data |
| 824 | // members of X that are of a class type M (or array thereof), each |
| 825 | // such class type has a copy constructor whose first parameter is |
| 826 | // of type 'const M&' or 'const volatile M&'. |
| 827 | if (!FieldRec->hasCopyConstructorWithConstParam()) |
| 828 | data().ImplicitCopyConstructorHasConstParam = false; |
| 829 | |
| 830 | // C++11 [class.copy]p18: |
| 831 | // The implicitly-declared copy assignment oeprator for a class X will |
| 832 | // have the form 'X& X::operator=(const X&)' if [...] for all the |
| 833 | // non-static data members of X that are of a class type M (or array |
| 834 | // thereof), each such class type has a copy assignment operator whose |
| 835 | // parameter is of type 'const M&', 'const volatile M&' or 'M'. |
| 836 | if (!FieldRec->hasCopyAssignmentWithConstParam()) |
| 837 | data().ImplicitCopyAssignmentHasConstParam = false; |
Richard Smith | d5bc867 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 838 | |
| 839 | if (FieldRec->hasUninitializedReferenceMember() && |
| 840 | !Field->hasInClassInitializer()) |
| 841 | data().HasUninitializedReferenceMember = true; |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 842 | } |
Richard Smith | 6180245 | 2011-12-22 02:22:31 +0000 | [diff] [blame] | 843 | } else { |
| 844 | // Base element type of field is a non-class type. |
Richard Smith | d3861ce | 2012-06-10 07:07:24 +0000 | [diff] [blame] | 845 | if (!T->isLiteralType() || |
| 846 | (!Field->hasInClassInitializer() && !isUnion())) |
Richard Smith | 6180245 | 2011-12-22 02:22:31 +0000 | [diff] [blame] | 847 | data().DefaultedDefaultConstructorIsConstexpr = false; |
Richard Smith | bc2a35d | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 848 | |
| 849 | // C++11 [class.copy]p23: |
| 850 | // A defaulted copy/move assignment operator for a class X is defined |
| 851 | // as deleted if X has: |
| 852 | // -- a non-static data member of const non-class type (or array |
| 853 | // thereof) |
| 854 | if (T.isConstQualified()) |
| 855 | data().DefaultedMoveAssignmentIsDeleted = true; |
Douglas Gregor | 85606eb | 2010-09-28 20:50:54 +0000 | [diff] [blame] | 856 | } |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 857 | |
| 858 | // C++0x [class]p7: |
| 859 | // A standard-layout class is a class that: |
| 860 | // [...] |
| 861 | // -- either has no non-static data members in the most derived |
| 862 | // class and at most one base class with non-static data members, |
| 863 | // or has no base classes with non-static data members, and |
| 864 | // At this point we know that we have a non-static data member, so the last |
| 865 | // clause holds. |
| 866 | if (!data().HasNoNonEmptyBases) |
Chandler Carruth | ec997dc | 2011-04-30 10:07:30 +0000 | [diff] [blame] | 867 | data().IsStandardLayout = false; |
Chandler Carruth | a822544 | 2011-04-30 09:17:45 +0000 | [diff] [blame] | 868 | |
Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 869 | // If this is not a zero-length bit-field, then the class is not empty. |
| 870 | if (data().Empty) { |
Richard Smith | a6b8b2c | 2011-10-10 18:28:20 +0000 | [diff] [blame] | 871 | if (!Field->isBitField() || |
| 872 | (!Field->getBitWidth()->isTypeDependent() && |
| 873 | !Field->getBitWidth()->isValueDependent() && |
| 874 | Field->getBitWidthValue(Context) != 0)) |
Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 875 | data().Empty = false; |
Douglas Gregor | 2cf9d65 | 2010-09-28 20:38:10 +0000 | [diff] [blame] | 876 | } |
Douglas Gregor | 9fe183a | 2010-09-28 19:45:33 +0000 | [diff] [blame] | 877 | } |
Douglas Gregor | e80622f | 2010-09-29 04:25:11 +0000 | [diff] [blame] | 878 | |
| 879 | // Handle using declarations of conversion functions. |
| 880 | if (UsingShadowDecl *Shadow = dyn_cast<UsingShadowDecl>(D)) |
| 881 | if (Shadow->getDeclName().getNameKind() |
| 882 | == DeclarationName::CXXConversionFunctionName) |
Argyrios Kyrtzidis | 2a82ca2 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 883 | data().Conversions.addDecl(getASTContext(), Shadow, Shadow->getAccess()); |
Joao Matos | 17d35c3 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 884 | } |
| 885 | |
Richard Smith | ac71351 | 2012-12-08 02:53:02 +0000 | [diff] [blame] | 886 | void CXXRecordDecl::finishedDefaultedOrDeletedMember(CXXMethodDecl *D) { |
| 887 | assert(!D->isImplicit() && !D->isUserProvided()); |
| 888 | |
| 889 | // The kind of special member this declaration is, if any. |
| 890 | unsigned SMKind = 0; |
| 891 | |
| 892 | if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) { |
| 893 | if (Constructor->isDefaultConstructor()) { |
| 894 | SMKind |= SMF_DefaultConstructor; |
| 895 | if (Constructor->isConstexpr()) |
| 896 | data().HasConstexprDefaultConstructor = true; |
| 897 | } |
| 898 | if (Constructor->isCopyConstructor()) |
| 899 | SMKind |= SMF_CopyConstructor; |
| 900 | else if (Constructor->isMoveConstructor()) |
| 901 | SMKind |= SMF_MoveConstructor; |
| 902 | else if (Constructor->isConstexpr()) |
| 903 | // We may now know that the constructor is constexpr. |
| 904 | data().HasConstexprNonCopyMoveConstructor = true; |
| 905 | } else if (isa<CXXDestructorDecl>(D)) |
| 906 | SMKind |= SMF_Destructor; |
| 907 | else if (D->isCopyAssignmentOperator()) |
| 908 | SMKind |= SMF_CopyAssignment; |
| 909 | else if (D->isMoveAssignmentOperator()) |
| 910 | SMKind |= SMF_MoveAssignment; |
| 911 | |
| 912 | // Update which trivial / non-trivial special members we have. |
| 913 | // addedMember will have skipped this step for this member. |
| 914 | if (D->isTrivial()) |
| 915 | data().HasTrivialSpecialMembers |= SMKind; |
| 916 | else |
| 917 | data().DeclaredNonTrivialSpecialMembers |= SMKind; |
| 918 | } |
| 919 | |
Joao Matos | 17d35c3 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 920 | bool CXXRecordDecl::isCLike() const { |
| 921 | if (getTagKind() == TTK_Class || getTagKind() == TTK_Interface || |
| 922 | !TemplateOrInstantiation.isNull()) |
| 923 | return false; |
| 924 | if (!hasDefinition()) |
| 925 | return true; |
Argyrios Kyrtzidis | 277b156 | 2012-01-23 16:58:45 +0000 | [diff] [blame] | 926 | |
Argyrios Kyrtzidis | c221411 | 2012-02-01 06:36:44 +0000 | [diff] [blame] | 927 | return isPOD() && data().HasOnlyCMembers; |
Argyrios Kyrtzidis | 277b156 | 2012-01-23 16:58:45 +0000 | [diff] [blame] | 928 | } |
| 929 | |
Douglas Gregor | 4d8d22b | 2012-02-10 07:45:31 +0000 | [diff] [blame] | 930 | void CXXRecordDecl::getCaptureFields( |
| 931 | llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures, |
Eli Friedman | 41105ad | 2012-02-11 00:18:00 +0000 | [diff] [blame] | 932 | FieldDecl *&ThisCapture) const { |
Douglas Gregor | 4d8d22b | 2012-02-10 07:45:31 +0000 | [diff] [blame] | 933 | Captures.clear(); |
| 934 | ThisCapture = 0; |
| 935 | |
Douglas Gregor | da8962a | 2012-02-13 15:44:47 +0000 | [diff] [blame] | 936 | LambdaDefinitionData &Lambda = getLambdaData(); |
Douglas Gregor | 4d8d22b | 2012-02-10 07:45:31 +0000 | [diff] [blame] | 937 | RecordDecl::field_iterator Field = field_begin(); |
Douglas Gregor | 7ae282f | 2012-02-13 17:20:40 +0000 | [diff] [blame] | 938 | for (LambdaExpr::Capture *C = Lambda.Captures, *CEnd = C + Lambda.NumCaptures; |
Douglas Gregor | 4d8d22b | 2012-02-10 07:45:31 +0000 | [diff] [blame] | 939 | C != CEnd; ++C, ++Field) { |
| 940 | if (C->capturesThis()) { |
David Blaikie | 581deb3 | 2012-06-06 20:45:41 +0000 | [diff] [blame] | 941 | ThisCapture = *Field; |
Douglas Gregor | 4d8d22b | 2012-02-10 07:45:31 +0000 | [diff] [blame] | 942 | continue; |
| 943 | } |
| 944 | |
David Blaikie | 581deb3 | 2012-06-06 20:45:41 +0000 | [diff] [blame] | 945 | Captures[C->getCapturedVar()] = *Field; |
Douglas Gregor | 4d8d22b | 2012-02-10 07:45:31 +0000 | [diff] [blame] | 946 | } |
| 947 | } |
| 948 | |
| 949 | |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 950 | static CanQualType GetConversionType(ASTContext &Context, NamedDecl *Conv) { |
| 951 | QualType T; |
John McCall | 32daa42 | 2010-03-31 01:36:47 +0000 | [diff] [blame] | 952 | if (isa<UsingShadowDecl>(Conv)) |
| 953 | Conv = cast<UsingShadowDecl>(Conv)->getTargetDecl(); |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 954 | if (FunctionTemplateDecl *ConvTemp = dyn_cast<FunctionTemplateDecl>(Conv)) |
| 955 | T = ConvTemp->getTemplatedDecl()->getResultType(); |
| 956 | else |
| 957 | T = cast<CXXConversionDecl>(Conv)->getConversionType(); |
| 958 | return Context.getCanonicalType(T); |
Fariborz Jahanian | 0351a1e | 2009-10-07 20:43:36 +0000 | [diff] [blame] | 959 | } |
| 960 | |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 961 | /// Collect the visible conversions of a base class. |
| 962 | /// |
James Dennett | a125350 | 2012-06-15 22:28:09 +0000 | [diff] [blame] | 963 | /// \param Record a base class of the class we're considering |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 964 | /// \param InVirtual whether this base class is a virtual base (or a base |
| 965 | /// of a virtual base) |
| 966 | /// \param Access the access along the inheritance path to this base |
| 967 | /// \param ParentHiddenTypes the conversions provided by the inheritors |
| 968 | /// of this base |
| 969 | /// \param Output the set to which to add conversions from non-virtual bases |
| 970 | /// \param VOutput the set to which to add conversions from virtual bases |
| 971 | /// \param HiddenVBaseCs the set of conversions which were hidden in a |
| 972 | /// virtual base along some inheritance path |
| 973 | static void CollectVisibleConversions(ASTContext &Context, |
| 974 | CXXRecordDecl *Record, |
| 975 | bool InVirtual, |
| 976 | AccessSpecifier Access, |
| 977 | const llvm::SmallPtrSet<CanQualType, 8> &ParentHiddenTypes, |
Argyrios Kyrtzidis | 2a82ca2 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 978 | ASTUnresolvedSet &Output, |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 979 | UnresolvedSetImpl &VOutput, |
| 980 | llvm::SmallPtrSet<NamedDecl*, 8> &HiddenVBaseCs) { |
| 981 | // The set of types which have conversions in this class or its |
| 982 | // subclasses. As an optimization, we don't copy the derived set |
| 983 | // unless it might change. |
| 984 | const llvm::SmallPtrSet<CanQualType, 8> *HiddenTypes = &ParentHiddenTypes; |
| 985 | llvm::SmallPtrSet<CanQualType, 8> HiddenTypesBuffer; |
| 986 | |
| 987 | // Collect the direct conversions and figure out which conversions |
| 988 | // will be hidden in the subclasses. |
Argyrios Kyrtzidis | 9d29543 | 2012-11-28 03:56:09 +0000 | [diff] [blame] | 989 | CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin(); |
| 990 | CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end(); |
| 991 | if (ConvI != ConvE) { |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 992 | HiddenTypesBuffer = ParentHiddenTypes; |
| 993 | HiddenTypes = &HiddenTypesBuffer; |
| 994 | |
Argyrios Kyrtzidis | 9d29543 | 2012-11-28 03:56:09 +0000 | [diff] [blame] | 995 | for (CXXRecordDecl::conversion_iterator I = ConvI; I != ConvE; ++I) { |
Richard Smith | f108c63 | 2012-05-06 00:04:32 +0000 | [diff] [blame] | 996 | CanQualType ConvType(GetConversionType(Context, I.getDecl())); |
| 997 | bool Hidden = ParentHiddenTypes.count(ConvType); |
| 998 | if (!Hidden) |
| 999 | HiddenTypesBuffer.insert(ConvType); |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 1000 | |
| 1001 | // If this conversion is hidden and we're in a virtual base, |
| 1002 | // remember that it's hidden along some inheritance path. |
| 1003 | if (Hidden && InVirtual) |
| 1004 | HiddenVBaseCs.insert(cast<NamedDecl>(I.getDecl()->getCanonicalDecl())); |
| 1005 | |
| 1006 | // If this conversion isn't hidden, add it to the appropriate output. |
| 1007 | else if (!Hidden) { |
| 1008 | AccessSpecifier IAccess |
| 1009 | = CXXRecordDecl::MergeAccess(Access, I.getAccess()); |
| 1010 | |
| 1011 | if (InVirtual) |
| 1012 | VOutput.addDecl(I.getDecl(), IAccess); |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 1013 | else |
Argyrios Kyrtzidis | 2a82ca2 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 1014 | Output.addDecl(Context, I.getDecl(), IAccess); |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 1015 | } |
| 1016 | } |
| 1017 | } |
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 | // Collect information recursively from any base classes. |
| 1020 | for (CXXRecordDecl::base_class_iterator |
| 1021 | I = Record->bases_begin(), E = Record->bases_end(); I != E; ++I) { |
| 1022 | const RecordType *RT = I->getType()->getAs<RecordType>(); |
| 1023 | if (!RT) continue; |
Sebastian Redl | 9994a34 | 2009-10-25 17:03:50 +0000 | [diff] [blame] | 1024 | |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 1025 | AccessSpecifier BaseAccess |
| 1026 | = CXXRecordDecl::MergeAccess(Access, I->getAccessSpecifier()); |
| 1027 | bool BaseInVirtual = InVirtual || I->isVirtual(); |
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 | CXXRecordDecl *Base = cast<CXXRecordDecl>(RT->getDecl()); |
| 1030 | CollectVisibleConversions(Context, Base, BaseInVirtual, BaseAccess, |
| 1031 | *HiddenTypes, Output, VOutput, HiddenVBaseCs); |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 1032 | } |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 1033 | } |
Sebastian Redl | 9994a34 | 2009-10-25 17:03:50 +0000 | [diff] [blame] | 1034 | |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 1035 | /// Collect the visible conversions of a class. |
| 1036 | /// |
| 1037 | /// This would be extremely straightforward if it weren't for virtual |
| 1038 | /// bases. It might be worth special-casing that, really. |
| 1039 | static void CollectVisibleConversions(ASTContext &Context, |
| 1040 | CXXRecordDecl *Record, |
Argyrios Kyrtzidis | 2a82ca2 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 1041 | ASTUnresolvedSet &Output) { |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 1042 | // The collection of all conversions in virtual bases that we've |
| 1043 | // found. These will be added to the output as long as they don't |
| 1044 | // appear in the hidden-conversions set. |
| 1045 | UnresolvedSet<8> VBaseCs; |
| 1046 | |
| 1047 | // The set of conversions in virtual bases that we've determined to |
| 1048 | // be hidden. |
| 1049 | llvm::SmallPtrSet<NamedDecl*, 8> HiddenVBaseCs; |
| 1050 | |
| 1051 | // The set of types hidden by classes derived from this one. |
| 1052 | llvm::SmallPtrSet<CanQualType, 8> HiddenTypes; |
| 1053 | |
| 1054 | // Go ahead and collect the direct conversions and add them to the |
| 1055 | // hidden-types set. |
Argyrios Kyrtzidis | 9d29543 | 2012-11-28 03:56:09 +0000 | [diff] [blame] | 1056 | CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin(); |
| 1057 | CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end(); |
Argyrios Kyrtzidis | 2a82ca2 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 1058 | Output.append(Context, ConvI, ConvE); |
Argyrios Kyrtzidis | 9d29543 | 2012-11-28 03:56:09 +0000 | [diff] [blame] | 1059 | for (; ConvI != ConvE; ++ConvI) |
| 1060 | HiddenTypes.insert(GetConversionType(Context, ConvI.getDecl())); |
John McCall | b05b5f3 | 2010-03-15 09:07:48 +0000 | [diff] [blame] | 1061 | |
| 1062 | // Recursively collect conversions from base classes. |
| 1063 | for (CXXRecordDecl::base_class_iterator |
| 1064 | I = Record->bases_begin(), E = Record->bases_end(); I != E; ++I) { |
| 1065 | const RecordType *RT = I->getType()->getAs<RecordType>(); |
| 1066 | if (!RT) continue; |
| 1067 | |
| 1068 | CollectVisibleConversions(Context, cast<CXXRecordDecl>(RT->getDecl()), |
| 1069 | I->isVirtual(), I->getAccessSpecifier(), |
| 1070 | HiddenTypes, Output, VBaseCs, HiddenVBaseCs); |
| 1071 | } |
| 1072 | |
| 1073 | // Add any unhidden conversions provided by virtual bases. |
| 1074 | for (UnresolvedSetIterator I = VBaseCs.begin(), E = VBaseCs.end(); |
| 1075 | I != E; ++I) { |
| 1076 | if (!HiddenVBaseCs.count(cast<NamedDecl>(I.getDecl()->getCanonicalDecl()))) |
Argyrios Kyrtzidis | 2a82ca2 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 1077 | Output.addDecl(Context, I.getDecl(), I.getAccess()); |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 1078 | } |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | /// getVisibleConversionFunctions - get all conversion functions visible |
| 1082 | /// in current class; including conversion function templates. |
Argyrios Kyrtzidis | 9d29543 | 2012-11-28 03:56:09 +0000 | [diff] [blame] | 1083 | std::pair<CXXRecordDecl::conversion_iterator,CXXRecordDecl::conversion_iterator> |
| 1084 | CXXRecordDecl::getVisibleConversionFunctions() { |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 1085 | // If root class, all conversions are visible. |
| 1086 | if (bases_begin() == bases_end()) |
Argyrios Kyrtzidis | 9d29543 | 2012-11-28 03:56:09 +0000 | [diff] [blame] | 1087 | return std::make_pair(data().Conversions.begin(), data().Conversions.end()); |
Fariborz Jahanian | 6250921 | 2009-09-12 18:26:03 +0000 | [diff] [blame] | 1088 | // If visible conversion list is already evaluated, return it. |
Argyrios Kyrtzidis | 9d29543 | 2012-11-28 03:56:09 +0000 | [diff] [blame] | 1089 | if (!data().ComputedVisibleConversions) { |
| 1090 | CollectVisibleConversions(getASTContext(), this, data().VisibleConversions); |
| 1091 | data().ComputedVisibleConversions = true; |
| 1092 | } |
| 1093 | return std::make_pair(data().VisibleConversions.begin(), |
| 1094 | data().VisibleConversions.end()); |
Fariborz Jahanian | 5346278 | 2009-09-11 21:44:33 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
John McCall | 32daa42 | 2010-03-31 01:36:47 +0000 | [diff] [blame] | 1097 | void CXXRecordDecl::removeConversion(const NamedDecl *ConvDecl) { |
| 1098 | // This operation is O(N) but extremely rare. Sema only uses it to |
| 1099 | // remove UsingShadowDecls in a class that were followed by a direct |
| 1100 | // declaration, e.g.: |
| 1101 | // class A : B { |
| 1102 | // using B::operator int; |
| 1103 | // operator int(); |
| 1104 | // }; |
| 1105 | // This is uncommon by itself and even more uncommon in conjunction |
| 1106 | // with sufficiently large numbers of directly-declared conversions |
| 1107 | // that asymptotic behavior matters. |
| 1108 | |
Argyrios Kyrtzidis | 2a82ca2 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 1109 | ASTUnresolvedSet &Convs = data().Conversions; |
John McCall | 32daa42 | 2010-03-31 01:36:47 +0000 | [diff] [blame] | 1110 | for (unsigned I = 0, E = Convs.size(); I != E; ++I) { |
| 1111 | if (Convs[I].getDecl() == ConvDecl) { |
| 1112 | Convs.erase(I); |
| 1113 | assert(std::find(Convs.begin(), Convs.end(), ConvDecl) == Convs.end() |
| 1114 | && "conversion was found multiple times in unresolved set"); |
| 1115 | return; |
| 1116 | } |
| 1117 | } |
| 1118 | |
| 1119 | llvm_unreachable("conversion not found in set!"); |
Douglas Gregor | 65ec1fd | 2009-08-21 23:19:43 +0000 | [diff] [blame] | 1120 | } |
Fariborz Jahanian | f8dcb86 | 2009-06-19 19:55:27 +0000 | [diff] [blame] | 1121 | |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 1122 | CXXRecordDecl *CXXRecordDecl::getInstantiatedFromMemberClass() const { |
Douglas Gregor | b3ae4fc | 2009-10-12 20:18:28 +0000 | [diff] [blame] | 1123 | if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 1124 | return cast<CXXRecordDecl>(MSInfo->getInstantiatedFrom()); |
| 1125 | |
| 1126 | return 0; |
| 1127 | } |
| 1128 | |
| 1129 | void |
| 1130 | CXXRecordDecl::setInstantiationOfMemberClass(CXXRecordDecl *RD, |
| 1131 | TemplateSpecializationKind TSK) { |
| 1132 | assert(TemplateOrInstantiation.isNull() && |
| 1133 | "Previous template or instantiation?"); |
| 1134 | assert(!isa<ClassTemplateSpecializationDecl>(this)); |
| 1135 | TemplateOrInstantiation |
| 1136 | = new (getASTContext()) MemberSpecializationInfo(RD, TSK); |
| 1137 | } |
| 1138 | |
Anders Carlsson | b13e357 | 2009-12-07 06:33:48 +0000 | [diff] [blame] | 1139 | TemplateSpecializationKind CXXRecordDecl::getTemplateSpecializationKind() const{ |
| 1140 | if (const ClassTemplateSpecializationDecl *Spec |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 1141 | = dyn_cast<ClassTemplateSpecializationDecl>(this)) |
| 1142 | return Spec->getSpecializationKind(); |
| 1143 | |
Douglas Gregor | b3ae4fc | 2009-10-12 20:18:28 +0000 | [diff] [blame] | 1144 | if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 1145 | return MSInfo->getTemplateSpecializationKind(); |
| 1146 | |
| 1147 | return TSK_Undeclared; |
| 1148 | } |
| 1149 | |
| 1150 | void |
| 1151 | CXXRecordDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK) { |
| 1152 | if (ClassTemplateSpecializationDecl *Spec |
| 1153 | = dyn_cast<ClassTemplateSpecializationDecl>(this)) { |
| 1154 | Spec->setSpecializationKind(TSK); |
| 1155 | return; |
| 1156 | } |
| 1157 | |
Douglas Gregor | b3ae4fc | 2009-10-12 20:18:28 +0000 | [diff] [blame] | 1158 | if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) { |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 1159 | MSInfo->setTemplateSpecializationKind(TSK); |
| 1160 | return; |
| 1161 | } |
| 1162 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1163 | llvm_unreachable("Not a class template or member class specialization"); |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 1164 | } |
| 1165 | |
Douglas Gregor | 1d110e0 | 2010-07-01 14:13:13 +0000 | [diff] [blame] | 1166 | CXXDestructorDecl *CXXRecordDecl::getDestructor() const { |
| 1167 | ASTContext &Context = getASTContext(); |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 1168 | QualType ClassType = Context.getTypeDeclType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1169 | |
| 1170 | DeclarationName Name |
Douglas Gregor | 50d62d1 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 1171 | = Context.DeclarationNames.getCXXDestructorName( |
| 1172 | Context.getCanonicalType(ClassType)); |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 1173 | |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 1174 | DeclContext::lookup_const_result R = lookup(Name); |
| 1175 | if (R.empty()) |
Sebastian Redl | d4b25cb | 2010-09-02 23:19:42 +0000 | [diff] [blame] | 1176 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1177 | |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 1178 | CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(R.front()); |
Anders Carlsson | 7267c16 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 1179 | return Dtor; |
| 1180 | } |
| 1181 | |
Douglas Gregor | da2142f | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 1182 | void CXXRecordDecl::completeDefinition() { |
| 1183 | completeDefinition(0); |
| 1184 | } |
| 1185 | |
| 1186 | void CXXRecordDecl::completeDefinition(CXXFinalOverriderMap *FinalOverriders) { |
| 1187 | RecordDecl::completeDefinition(); |
| 1188 | |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1189 | if (hasObjectMember() && getASTContext().getLangOpts().ObjCAutoRefCount) { |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1190 | // Objective-C Automatic Reference Counting: |
| 1191 | // If a class has a non-static data member of Objective-C pointer |
| 1192 | // type (or array thereof), it is a non-POD type and its |
Douglas Gregor | 3fe52ff | 2012-07-23 04:23:39 +0000 | [diff] [blame] | 1193 | // default constructor (if any), copy constructor, move constructor, |
| 1194 | // copy assignment operator, move assignment operator, and destructor are |
| 1195 | // non-trivial. |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1196 | struct DefinitionData &Data = data(); |
| 1197 | Data.PlainOldData = false; |
Richard Smith | 7d04d3a | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1198 | Data.HasTrivialSpecialMembers = 0; |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1199 | Data.HasIrrelevantDestructor = false; |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
Douglas Gregor | 7a39dd0 | 2010-09-29 00:15:42 +0000 | [diff] [blame] | 1202 | // If the class may be abstract (but hasn't been marked as such), check for |
| 1203 | // any pure final overriders. |
| 1204 | if (mayBeAbstract()) { |
| 1205 | CXXFinalOverriderMap MyFinalOverriders; |
| 1206 | if (!FinalOverriders) { |
| 1207 | getFinalOverriders(MyFinalOverriders); |
| 1208 | FinalOverriders = &MyFinalOverriders; |
| 1209 | } |
| 1210 | |
| 1211 | bool Done = false; |
| 1212 | for (CXXFinalOverriderMap::iterator M = FinalOverriders->begin(), |
| 1213 | MEnd = FinalOverriders->end(); |
| 1214 | M != MEnd && !Done; ++M) { |
| 1215 | for (OverridingMethods::iterator SO = M->second.begin(), |
| 1216 | SOEnd = M->second.end(); |
| 1217 | SO != SOEnd && !Done; ++SO) { |
| 1218 | assert(SO->second.size() > 0 && |
| 1219 | "All virtual functions have overridding virtual functions"); |
| 1220 | |
| 1221 | // C++ [class.abstract]p4: |
| 1222 | // A class is abstract if it contains or inherits at least one |
| 1223 | // pure virtual function for which the final overrider is pure |
| 1224 | // virtual. |
| 1225 | if (SO->second.front().Method->isPure()) { |
| 1226 | data().Abstract = true; |
| 1227 | Done = true; |
| 1228 | break; |
| 1229 | } |
| 1230 | } |
| 1231 | } |
| 1232 | } |
Douglas Gregor | e80622f | 2010-09-29 04:25:11 +0000 | [diff] [blame] | 1233 | |
| 1234 | // Set access bits correctly on the directly-declared conversions. |
| 1235 | for (UnresolvedSetIterator I = data().Conversions.begin(), |
| 1236 | E = data().Conversions.end(); |
| 1237 | I != E; ++I) |
Argyrios Kyrtzidis | 2a82ca2 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 1238 | I.setAccess((*I)->getAccess()); |
Douglas Gregor | 7a39dd0 | 2010-09-29 00:15:42 +0000 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | bool CXXRecordDecl::mayBeAbstract() const { |
| 1242 | if (data().Abstract || isInvalidDecl() || !data().Polymorphic || |
| 1243 | isDependentContext()) |
| 1244 | return false; |
| 1245 | |
| 1246 | for (CXXRecordDecl::base_class_const_iterator B = bases_begin(), |
| 1247 | BEnd = bases_end(); |
| 1248 | B != BEnd; ++B) { |
| 1249 | CXXRecordDecl *BaseDecl |
| 1250 | = cast<CXXRecordDecl>(B->getType()->getAs<RecordType>()->getDecl()); |
| 1251 | if (BaseDecl->isAbstract()) |
| 1252 | return true; |
| 1253 | } |
| 1254 | |
| 1255 | return false; |
| 1256 | } |
| 1257 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1258 | void CXXMethodDecl::anchor() { } |
| 1259 | |
Rafael Espindola | d2615cc | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 1260 | bool CXXMethodDecl::isStatic() const { |
| 1261 | const CXXMethodDecl *MD = this; |
| 1262 | for (;;) { |
| 1263 | const CXXMethodDecl *C = MD->getCanonicalDecl(); |
| 1264 | if (C != MD) { |
| 1265 | MD = C; |
| 1266 | continue; |
| 1267 | } |
| 1268 | |
| 1269 | FunctionTemplateSpecializationInfo *Info = |
| 1270 | MD->getTemplateSpecializationInfo(); |
| 1271 | if (!Info) |
| 1272 | break; |
| 1273 | MD = cast<CXXMethodDecl>(Info->getTemplate()->getTemplatedDecl()); |
| 1274 | } |
| 1275 | |
| 1276 | if (MD->getStorageClass() == SC_Static) |
| 1277 | return true; |
| 1278 | |
| 1279 | DeclarationName Name = getDeclName(); |
| 1280 | // [class.free]p1: |
| 1281 | // Any allocation function for a class T is a static member |
| 1282 | // (even if not explicitly declared static). |
| 1283 | if (Name.getCXXOverloadedOperator() == OO_New || |
| 1284 | Name.getCXXOverloadedOperator() == OO_Array_New) |
| 1285 | return true; |
| 1286 | |
| 1287 | // [class.free]p6 Any deallocation function for a class X is a static member |
| 1288 | // (even if not explicitly declared static). |
| 1289 | if (Name.getCXXOverloadedOperator() == OO_Delete || |
| 1290 | Name.getCXXOverloadedOperator() == OO_Array_Delete) |
| 1291 | return true; |
| 1292 | |
| 1293 | return false; |
| 1294 | } |
| 1295 | |
Rafael Espindola | 0b4fe50 | 2012-06-26 17:45:31 +0000 | [diff] [blame] | 1296 | static bool recursivelyOverrides(const CXXMethodDecl *DerivedMD, |
| 1297 | const CXXMethodDecl *BaseMD) { |
| 1298 | for (CXXMethodDecl::method_iterator I = DerivedMD->begin_overridden_methods(), |
| 1299 | E = DerivedMD->end_overridden_methods(); I != E; ++I) { |
| 1300 | const CXXMethodDecl *MD = *I; |
| 1301 | if (MD->getCanonicalDecl() == BaseMD->getCanonicalDecl()) |
| 1302 | return true; |
| 1303 | if (recursivelyOverrides(MD, BaseMD)) |
| 1304 | return true; |
| 1305 | } |
| 1306 | return false; |
| 1307 | } |
| 1308 | |
| 1309 | CXXMethodDecl * |
Jordan Rose | 4e79fdf | 2012-08-15 20:07:17 +0000 | [diff] [blame] | 1310 | CXXMethodDecl::getCorrespondingMethodInClass(const CXXRecordDecl *RD, |
| 1311 | bool MayBeBase) { |
Rafael Espindola | 0b4fe50 | 2012-06-26 17:45:31 +0000 | [diff] [blame] | 1312 | if (this->getParent()->getCanonicalDecl() == RD->getCanonicalDecl()) |
| 1313 | return this; |
| 1314 | |
| 1315 | // Lookup doesn't work for destructors, so handle them separately. |
| 1316 | if (isa<CXXDestructorDecl>(this)) { |
| 1317 | CXXMethodDecl *MD = RD->getDestructor(); |
Jordan Rose | 4e79fdf | 2012-08-15 20:07:17 +0000 | [diff] [blame] | 1318 | if (MD) { |
| 1319 | if (recursivelyOverrides(MD, this)) |
| 1320 | return MD; |
| 1321 | if (MayBeBase && recursivelyOverrides(this, MD)) |
| 1322 | return MD; |
| 1323 | } |
Rafael Espindola | 0b4fe50 | 2012-06-26 17:45:31 +0000 | [diff] [blame] | 1324 | return NULL; |
| 1325 | } |
| 1326 | |
| 1327 | lookup_const_result Candidates = RD->lookup(getDeclName()); |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 1328 | for (NamedDecl * const * I = Candidates.begin(); I != Candidates.end(); ++I) { |
Rafael Espindola | 0b4fe50 | 2012-06-26 17:45:31 +0000 | [diff] [blame] | 1329 | CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(*I); |
| 1330 | if (!MD) |
| 1331 | continue; |
| 1332 | if (recursivelyOverrides(MD, this)) |
| 1333 | return MD; |
Jordan Rose | 4e79fdf | 2012-08-15 20:07:17 +0000 | [diff] [blame] | 1334 | if (MayBeBase && recursivelyOverrides(this, MD)) |
| 1335 | return MD; |
Rafael Espindola | 0b4fe50 | 2012-06-26 17:45:31 +0000 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | for (CXXRecordDecl::base_class_const_iterator I = RD->bases_begin(), |
| 1339 | E = RD->bases_end(); I != E; ++I) { |
| 1340 | const RecordType *RT = I->getType()->getAs<RecordType>(); |
| 1341 | if (!RT) |
| 1342 | continue; |
| 1343 | const CXXRecordDecl *Base = cast<CXXRecordDecl>(RT->getDecl()); |
| 1344 | CXXMethodDecl *T = this->getCorrespondingMethodInClass(Base); |
| 1345 | if (T) |
| 1346 | return T; |
| 1347 | } |
| 1348 | |
| 1349 | return NULL; |
| 1350 | } |
| 1351 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 1352 | CXXMethodDecl * |
| 1353 | CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1354 | SourceLocation StartLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1355 | const DeclarationNameInfo &NameInfo, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1356 | QualType T, TypeSourceInfo *TInfo, |
Rafael Espindola | d2615cc | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 1357 | StorageClass SC, bool isInline, |
Richard Smith | af1fc7a | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1358 | bool isConstexpr, SourceLocation EndLocation) { |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1359 | return new (C) CXXMethodDecl(CXXMethod, RD, StartLoc, NameInfo, T, TInfo, |
Rafael Espindola | d2615cc | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 1360 | SC, isInline, isConstexpr, |
Richard Smith | af1fc7a | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1361 | EndLocation); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 1362 | } |
| 1363 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1364 | CXXMethodDecl *CXXMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1365 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(CXXMethodDecl)); |
| 1366 | return new (Mem) CXXMethodDecl(CXXMethod, 0, SourceLocation(), |
| 1367 | DeclarationNameInfo(), QualType(), |
Rafael Espindola | d2615cc | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 1368 | 0, SC_None, false, false, |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1369 | SourceLocation()); |
| 1370 | } |
| 1371 | |
Douglas Gregor | 9091656 | 2009-09-29 18:16:17 +0000 | [diff] [blame] | 1372 | bool CXXMethodDecl::isUsualDeallocationFunction() const { |
| 1373 | if (getOverloadedOperator() != OO_Delete && |
| 1374 | getOverloadedOperator() != OO_Array_Delete) |
| 1375 | return false; |
Douglas Gregor | 6d90870 | 2010-02-26 05:06:18 +0000 | [diff] [blame] | 1376 | |
| 1377 | // C++ [basic.stc.dynamic.deallocation]p2: |
| 1378 | // A template instance is never a usual deallocation function, |
| 1379 | // regardless of its signature. |
| 1380 | if (getPrimaryTemplate()) |
| 1381 | return false; |
| 1382 | |
Douglas Gregor | 9091656 | 2009-09-29 18:16:17 +0000 | [diff] [blame] | 1383 | // C++ [basic.stc.dynamic.deallocation]p2: |
| 1384 | // If a class T has a member deallocation function named operator delete |
| 1385 | // with exactly one parameter, then that function is a usual (non-placement) |
| 1386 | // deallocation function. [...] |
| 1387 | if (getNumParams() == 1) |
| 1388 | return true; |
| 1389 | |
| 1390 | // C++ [basic.stc.dynamic.deallocation]p2: |
| 1391 | // [...] If class T does not declare such an operator delete but does |
| 1392 | // declare a member deallocation function named operator delete with |
| 1393 | // exactly two parameters, the second of which has type std::size_t (18.1), |
| 1394 | // then this function is a usual deallocation function. |
| 1395 | ASTContext &Context = getASTContext(); |
| 1396 | if (getNumParams() != 2 || |
Chandler Carruth | e228ba9 | 2010-02-08 18:54:05 +0000 | [diff] [blame] | 1397 | !Context.hasSameUnqualifiedType(getParamDecl(1)->getType(), |
| 1398 | Context.getSizeType())) |
Douglas Gregor | 9091656 | 2009-09-29 18:16:17 +0000 | [diff] [blame] | 1399 | return false; |
| 1400 | |
| 1401 | // This function is a usual deallocation function if there are no |
| 1402 | // single-parameter deallocation functions of the same kind. |
David Blaikie | 3bc93e3 | 2012-12-19 00:45:41 +0000 | [diff] [blame] | 1403 | DeclContext::lookup_const_result R = getDeclContext()->lookup(getDeclName()); |
| 1404 | for (DeclContext::lookup_const_result::iterator I = R.begin(), E = R.end(); |
| 1405 | I != E; ++I) { |
| 1406 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*I)) |
Douglas Gregor | 9091656 | 2009-09-29 18:16:17 +0000 | [diff] [blame] | 1407 | if (FD->getNumParams() == 1) |
| 1408 | return false; |
| 1409 | } |
| 1410 | |
| 1411 | return true; |
| 1412 | } |
| 1413 | |
Douglas Gregor | 06a9f36 | 2010-05-01 20:49:11 +0000 | [diff] [blame] | 1414 | bool CXXMethodDecl::isCopyAssignmentOperator() const { |
Sean Hunt | ffe37fd | 2011-05-25 20:50:04 +0000 | [diff] [blame] | 1415 | // C++0x [class.copy]p17: |
Douglas Gregor | 06a9f36 | 2010-05-01 20:49:11 +0000 | [diff] [blame] | 1416 | // A user-declared copy assignment operator X::operator= is a non-static |
| 1417 | // non-template member function of class X with exactly one parameter of |
| 1418 | // type X, X&, const X&, volatile X& or const volatile X&. |
| 1419 | if (/*operator=*/getOverloadedOperator() != OO_Equal || |
| 1420 | /*non-static*/ isStatic() || |
Sean Hunt | ffe37fd | 2011-05-25 20:50:04 +0000 | [diff] [blame] | 1421 | /*non-template*/getPrimaryTemplate() || getDescribedFunctionTemplate()) |
Douglas Gregor | 06a9f36 | 2010-05-01 20:49:11 +0000 | [diff] [blame] | 1422 | return false; |
| 1423 | |
| 1424 | QualType ParamType = getParamDecl(0)->getType(); |
| 1425 | if (const LValueReferenceType *Ref = ParamType->getAs<LValueReferenceType>()) |
| 1426 | ParamType = Ref->getPointeeType(); |
| 1427 | |
| 1428 | ASTContext &Context = getASTContext(); |
| 1429 | QualType ClassType |
| 1430 | = Context.getCanonicalType(Context.getTypeDeclType(getParent())); |
| 1431 | return Context.hasSameUnqualifiedType(ClassType, ParamType); |
| 1432 | } |
| 1433 | |
Sean Hunt | ffe37fd | 2011-05-25 20:50:04 +0000 | [diff] [blame] | 1434 | bool CXXMethodDecl::isMoveAssignmentOperator() const { |
| 1435 | // C++0x [class.copy]p19: |
| 1436 | // A user-declared move assignment operator X::operator= is a non-static |
| 1437 | // non-template member function of class X with exactly one parameter of type |
| 1438 | // X&&, const X&&, volatile X&&, or const volatile X&&. |
| 1439 | if (getOverloadedOperator() != OO_Equal || isStatic() || |
| 1440 | getPrimaryTemplate() || getDescribedFunctionTemplate()) |
| 1441 | return false; |
| 1442 | |
| 1443 | QualType ParamType = getParamDecl(0)->getType(); |
| 1444 | if (!isa<RValueReferenceType>(ParamType)) |
| 1445 | return false; |
| 1446 | ParamType = ParamType->getPointeeType(); |
| 1447 | |
| 1448 | ASTContext &Context = getASTContext(); |
| 1449 | QualType ClassType |
| 1450 | = Context.getCanonicalType(Context.getTypeDeclType(getParent())); |
| 1451 | return Context.hasSameUnqualifiedType(ClassType, ParamType); |
| 1452 | } |
| 1453 | |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 1454 | void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) { |
Anders Carlsson | 3aaf486 | 2009-12-04 05:51:56 +0000 | [diff] [blame] | 1455 | assert(MD->isCanonicalDecl() && "Method is not canonical!"); |
Anders Carlsson | c076c45 | 2010-01-30 17:42:34 +0000 | [diff] [blame] | 1456 | assert(!MD->getParent()->isDependentContext() && |
| 1457 | "Can't add an overridden method to a class template!"); |
Eli Friedman | 540659e | 2012-03-10 01:39:01 +0000 | [diff] [blame] | 1458 | assert(MD->isVirtual() && "Method is not virtual!"); |
Anders Carlsson | c076c45 | 2010-01-30 17:42:34 +0000 | [diff] [blame] | 1459 | |
Douglas Gregor | 7d10b7e | 2010-03-02 23:58:15 +0000 | [diff] [blame] | 1460 | getASTContext().addOverriddenMethod(this, MD); |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 1461 | } |
| 1462 | |
| 1463 | CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const { |
Eli Friedman | 540659e | 2012-03-10 01:39:01 +0000 | [diff] [blame] | 1464 | if (isa<CXXConstructorDecl>(this)) return 0; |
Douglas Gregor | 7d10b7e | 2010-03-02 23:58:15 +0000 | [diff] [blame] | 1465 | return getASTContext().overridden_methods_begin(this); |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const { |
Eli Friedman | 540659e | 2012-03-10 01:39:01 +0000 | [diff] [blame] | 1469 | if (isa<CXXConstructorDecl>(this)) return 0; |
Douglas Gregor | 7d10b7e | 2010-03-02 23:58:15 +0000 | [diff] [blame] | 1470 | return getASTContext().overridden_methods_end(this); |
Anders Carlsson | 05eb244 | 2009-05-16 23:58:37 +0000 | [diff] [blame] | 1471 | } |
| 1472 | |
Argyrios Kyrtzidis | c91e9f4 | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 1473 | unsigned CXXMethodDecl::size_overridden_methods() const { |
Eli Friedman | 540659e | 2012-03-10 01:39:01 +0000 | [diff] [blame] | 1474 | if (isa<CXXConstructorDecl>(this)) return 0; |
Argyrios Kyrtzidis | c91e9f4 | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 1475 | return getASTContext().overridden_methods_size(this); |
| 1476 | } |
| 1477 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 1478 | QualType CXXMethodDecl::getThisType(ASTContext &C) const { |
Argyrios Kyrtzidis | b0d178d | 2008-10-24 22:28:18 +0000 | [diff] [blame] | 1479 | // C++ 9.3.2p1: The type of this in a member function of a class X is X*. |
| 1480 | // If the member function is declared const, the type of this is const X*, |
| 1481 | // if the member function is declared volatile, the type of this is |
| 1482 | // volatile X*, and if the member function is declared const volatile, |
| 1483 | // the type of this is const volatile X*. |
| 1484 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 1485 | assert(isInstance() && "No 'this' for static methods!"); |
Anders Carlsson | 31a0875 | 2009-06-13 02:59:33 +0000 | [diff] [blame] | 1486 | |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 1487 | QualType ClassTy = C.getTypeDeclType(getParent()); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1488 | ClassTy = C.getQualifiedType(ClassTy, |
| 1489 | Qualifiers::fromCVRMask(getTypeQualifiers())); |
Anders Carlsson | 4e57992 | 2009-07-10 21:35:09 +0000 | [diff] [blame] | 1490 | return C.getPointerType(ClassTy); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 1491 | } |
| 1492 | |
Eli Friedman | d7d7f67 | 2009-12-06 20:50:05 +0000 | [diff] [blame] | 1493 | bool CXXMethodDecl::hasInlineBody() const { |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 1494 | // If this function is a template instantiation, look at the template from |
| 1495 | // which it was instantiated. |
| 1496 | const FunctionDecl *CheckFn = getTemplateInstantiationPattern(); |
| 1497 | if (!CheckFn) |
| 1498 | CheckFn = this; |
| 1499 | |
Eli Friedman | d7d7f67 | 2009-12-06 20:50:05 +0000 | [diff] [blame] | 1500 | const FunctionDecl *fn; |
Argyrios Kyrtzidis | 06a54a3 | 2010-07-07 11:31:19 +0000 | [diff] [blame] | 1501 | return CheckFn->hasBody(fn) && !fn->isOutOfLine(); |
Eli Friedman | d7d7f67 | 2009-12-06 20:50:05 +0000 | [diff] [blame] | 1502 | } |
| 1503 | |
Douglas Gregor | 27dd7d9 | 2012-02-17 03:02:34 +0000 | [diff] [blame] | 1504 | bool CXXMethodDecl::isLambdaStaticInvoker() const { |
| 1505 | return getParent()->isLambda() && |
| 1506 | getIdentifier() && getIdentifier()->getName() == "__invoke"; |
| 1507 | } |
| 1508 | |
| 1509 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1510 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, |
| 1511 | TypeSourceInfo *TInfo, bool IsVirtual, |
| 1512 | SourceLocation L, Expr *Init, |
| 1513 | SourceLocation R, |
| 1514 | SourceLocation EllipsisLoc) |
Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1515 | : Initializee(TInfo), MemberOrEllipsisLocation(EllipsisLoc), Init(Init), |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 1516 | LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(IsVirtual), |
| 1517 | IsWritten(false), SourceOrderOrNumArrayIndices(0) |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1518 | { |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1519 | } |
| 1520 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1521 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, |
| 1522 | FieldDecl *Member, |
| 1523 | SourceLocation MemberLoc, |
| 1524 | SourceLocation L, Expr *Init, |
| 1525 | SourceLocation R) |
Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1526 | : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 1527 | LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false), |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 1528 | IsWritten(false), SourceOrderOrNumArrayIndices(0) |
| 1529 | { |
| 1530 | } |
| 1531 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1532 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, |
| 1533 | IndirectFieldDecl *Member, |
| 1534 | SourceLocation MemberLoc, |
| 1535 | SourceLocation L, Expr *Init, |
| 1536 | SourceLocation R) |
Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1537 | : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 1538 | LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false), |
Abramo Bagnara | a0af3b4 | 2010-05-26 18:09:23 +0000 | [diff] [blame] | 1539 | IsWritten(false), SourceOrderOrNumArrayIndices(0) |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1540 | { |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1541 | } |
| 1542 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1543 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 1544 | TypeSourceInfo *TInfo, |
| 1545 | SourceLocation L, Expr *Init, |
Sean Hunt | 4171766 | 2011-02-26 19:13:13 +0000 | [diff] [blame] | 1546 | SourceLocation R) |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 1547 | : Initializee(TInfo), MemberOrEllipsisLocation(), Init(Init), |
| 1548 | LParenLoc(L), RParenLoc(R), IsDelegating(true), IsVirtual(false), |
Sean Hunt | 4171766 | 2011-02-26 19:13:13 +0000 | [diff] [blame] | 1549 | IsWritten(false), SourceOrderOrNumArrayIndices(0) |
| 1550 | { |
| 1551 | } |
| 1552 | |
| 1553 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1554 | FieldDecl *Member, |
| 1555 | SourceLocation MemberLoc, |
| 1556 | SourceLocation L, Expr *Init, |
| 1557 | SourceLocation R, |
| 1558 | VarDecl **Indices, |
| 1559 | unsigned NumIndices) |
Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1560 | : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 1561 | LParenLoc(L), RParenLoc(R), IsVirtual(false), |
Abramo Bagnara | a0af3b4 | 2010-05-26 18:09:23 +0000 | [diff] [blame] | 1562 | IsWritten(false), SourceOrderOrNumArrayIndices(NumIndices) |
Douglas Gregor | fb8cc25 | 2010-05-05 05:51:00 +0000 | [diff] [blame] | 1563 | { |
| 1564 | VarDecl **MyIndices = reinterpret_cast<VarDecl **> (this + 1); |
| 1565 | memcpy(MyIndices, Indices, NumIndices * sizeof(VarDecl *)); |
| 1566 | } |
| 1567 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1568 | CXXCtorInitializer *CXXCtorInitializer::Create(ASTContext &Context, |
| 1569 | FieldDecl *Member, |
| 1570 | SourceLocation MemberLoc, |
| 1571 | SourceLocation L, Expr *Init, |
| 1572 | SourceLocation R, |
| 1573 | VarDecl **Indices, |
| 1574 | unsigned NumIndices) { |
| 1575 | void *Mem = Context.Allocate(sizeof(CXXCtorInitializer) + |
Douglas Gregor | fb8cc25 | 2010-05-05 05:51:00 +0000 | [diff] [blame] | 1576 | sizeof(VarDecl *) * NumIndices, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1577 | llvm::alignOf<CXXCtorInitializer>()); |
Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1578 | return new (Mem) CXXCtorInitializer(Context, Member, MemberLoc, L, Init, R, |
| 1579 | Indices, NumIndices); |
Douglas Gregor | fb8cc25 | 2010-05-05 05:51:00 +0000 | [diff] [blame] | 1580 | } |
| 1581 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1582 | TypeLoc CXXCtorInitializer::getBaseClassLoc() const { |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1583 | if (isBaseInitializer()) |
Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1584 | return Initializee.get<TypeSourceInfo*>()->getTypeLoc(); |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1585 | else |
| 1586 | return TypeLoc(); |
| 1587 | } |
| 1588 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1589 | const Type *CXXCtorInitializer::getBaseClass() const { |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1590 | if (isBaseInitializer()) |
Sean Hunt | f51d0b6 | 2011-01-08 23:01:16 +0000 | [diff] [blame] | 1591 | return Initializee.get<TypeSourceInfo*>()->getType().getTypePtr(); |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1592 | else |
| 1593 | return 0; |
| 1594 | } |
| 1595 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1596 | SourceLocation CXXCtorInitializer::getSourceLocation() const { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 1597 | if (isAnyMemberInitializer()) |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1598 | return getMemberLocation(); |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 1599 | |
| 1600 | if (isInClassMemberInitializer()) |
| 1601 | return getAnyMember()->getLocation(); |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1602 | |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 1603 | if (TypeSourceInfo *TSInfo = Initializee.get<TypeSourceInfo*>()) |
| 1604 | return TSInfo->getTypeLoc().getLocalSourceRange().getBegin(); |
| 1605 | |
| 1606 | return SourceLocation(); |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1607 | } |
| 1608 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 1609 | SourceRange CXXCtorInitializer::getSourceRange() const { |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 1610 | if (isInClassMemberInitializer()) { |
| 1611 | FieldDecl *D = getAnyMember(); |
| 1612 | if (Expr *I = D->getInClassInitializer()) |
| 1613 | return I->getSourceRange(); |
| 1614 | return SourceRange(); |
| 1615 | } |
| 1616 | |
Douglas Gregor | 802ab45 | 2009-12-02 22:36:29 +0000 | [diff] [blame] | 1617 | return SourceRange(getSourceLocation(), getRParenLoc()); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 1618 | } |
| 1619 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1620 | void CXXConstructorDecl::anchor() { } |
| 1621 | |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1622 | CXXConstructorDecl * |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1623 | CXXConstructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1624 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(CXXConstructorDecl)); |
| 1625 | return new (Mem) CXXConstructorDecl(0, SourceLocation(),DeclarationNameInfo(), |
| 1626 | QualType(), 0, false, false, false,false); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | CXXConstructorDecl * |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1630 | CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1631 | SourceLocation StartLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1632 | const DeclarationNameInfo &NameInfo, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1633 | QualType T, TypeSourceInfo *TInfo, |
Richard Smith | af1fc7a | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1634 | bool isExplicit, bool isInline, |
| 1635 | bool isImplicitlyDeclared, bool isConstexpr) { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1636 | assert(NameInfo.getName().getNameKind() |
| 1637 | == DeclarationName::CXXConstructorName && |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 1638 | "Name must refer to a constructor"); |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1639 | return new (C) CXXConstructorDecl(RD, StartLoc, NameInfo, T, TInfo, |
Richard Smith | af1fc7a | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1640 | isExplicit, isInline, isImplicitlyDeclared, |
| 1641 | isConstexpr); |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1642 | } |
| 1643 | |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 1644 | CXXConstructorDecl *CXXConstructorDecl::getTargetConstructor() const { |
| 1645 | assert(isDelegatingConstructor() && "Not a delegating constructor!"); |
| 1646 | Expr *E = (*init_begin())->getInit()->IgnoreImplicit(); |
| 1647 | if (CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(E)) |
| 1648 | return Construct->getConstructor(); |
| 1649 | |
| 1650 | return 0; |
| 1651 | } |
| 1652 | |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1653 | bool CXXConstructorDecl::isDefaultConstructor() const { |
| 1654 | // C++ [class.ctor]p5: |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 1655 | // A default constructor for a class X is a constructor of class |
| 1656 | // X that can be called without an argument. |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1657 | return (getNumParams() == 0) || |
Anders Carlsson | da3f4e2 | 2009-08-25 05:12:04 +0000 | [diff] [blame] | 1658 | (getNumParams() > 0 && getParamDecl(0)->hasDefaultArg()); |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1659 | } |
| 1660 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1661 | bool |
Douglas Gregor | 9e9199d | 2009-12-22 00:34:07 +0000 | [diff] [blame] | 1662 | CXXConstructorDecl::isCopyConstructor(unsigned &TypeQuals) const { |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1663 | return isCopyOrMoveConstructor(TypeQuals) && |
| 1664 | getParamDecl(0)->getType()->isLValueReferenceType(); |
| 1665 | } |
| 1666 | |
| 1667 | bool CXXConstructorDecl::isMoveConstructor(unsigned &TypeQuals) const { |
| 1668 | return isCopyOrMoveConstructor(TypeQuals) && |
| 1669 | getParamDecl(0)->getType()->isRValueReferenceType(); |
| 1670 | } |
| 1671 | |
| 1672 | /// \brief Determine whether this is a copy or move constructor. |
| 1673 | bool CXXConstructorDecl::isCopyOrMoveConstructor(unsigned &TypeQuals) const { |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1674 | // C++ [class.copy]p2: |
Douglas Gregor | 64bffa9 | 2008-11-05 16:20:31 +0000 | [diff] [blame] | 1675 | // A non-template constructor for class X is a copy constructor |
| 1676 | // if its first parameter is of type X&, const X&, volatile X& or |
| 1677 | // const volatile X&, and either there are no other parameters |
| 1678 | // or else all other parameters have default arguments (8.3.6). |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1679 | // C++0x [class.copy]p3: |
| 1680 | // A non-template constructor for class X is a move constructor if its |
| 1681 | // first parameter is of type X&&, const X&&, volatile X&&, or |
| 1682 | // const volatile X&&, and either there are no other parameters or else |
| 1683 | // all other parameters have default arguments. |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1684 | if ((getNumParams() < 1) || |
Douglas Gregor | 77da3f4 | 2009-10-13 23:45:19 +0000 | [diff] [blame] | 1685 | (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) || |
Douglas Gregor | fd47648 | 2009-11-13 23:59:09 +0000 | [diff] [blame] | 1686 | (getPrimaryTemplate() != 0) || |
Douglas Gregor | 77da3f4 | 2009-10-13 23:45:19 +0000 | [diff] [blame] | 1687 | (getDescribedFunctionTemplate() != 0)) |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1688 | return false; |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1689 | |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1690 | const ParmVarDecl *Param = getParamDecl(0); |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1691 | |
| 1692 | // Do we have a reference type? |
| 1693 | const ReferenceType *ParamRefType = Param->getType()->getAs<ReferenceType>(); |
Douglas Gregor | fd47648 | 2009-11-13 23:59:09 +0000 | [diff] [blame] | 1694 | if (!ParamRefType) |
| 1695 | return false; |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1696 | |
Douglas Gregor | fd47648 | 2009-11-13 23:59:09 +0000 | [diff] [blame] | 1697 | // Is it a reference to our class type? |
Douglas Gregor | 9e9199d | 2009-12-22 00:34:07 +0000 | [diff] [blame] | 1698 | ASTContext &Context = getASTContext(); |
| 1699 | |
Douglas Gregor | fd47648 | 2009-11-13 23:59:09 +0000 | [diff] [blame] | 1700 | CanQualType PointeeType |
| 1701 | = Context.getCanonicalType(ParamRefType->getPointeeType()); |
Douglas Gregor | 14e0b3d | 2009-09-15 20:50:23 +0000 | [diff] [blame] | 1702 | CanQualType ClassTy |
| 1703 | = Context.getCanonicalType(Context.getTagDeclType(getParent())); |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1704 | if (PointeeType.getUnqualifiedType() != ClassTy) |
| 1705 | return false; |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1706 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1707 | // FIXME: other qualifiers? |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1708 | |
| 1709 | // We have a copy or move constructor. |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1710 | TypeQuals = PointeeType.getCVRQualifiers(); |
Douglas Gregor | cc15f01 | 2011-01-21 19:38:21 +0000 | [diff] [blame] | 1711 | return true; |
Douglas Gregor | 030ff0c | 2008-10-31 20:25:05 +0000 | [diff] [blame] | 1712 | } |
| 1713 | |
Anders Carlsson | faccd72 | 2009-08-28 16:57:08 +0000 | [diff] [blame] | 1714 | bool CXXConstructorDecl::isConvertingConstructor(bool AllowExplicit) const { |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 1715 | // C++ [class.conv.ctor]p1: |
| 1716 | // A constructor declared without the function-specifier explicit |
| 1717 | // that can be called with a single parameter specifies a |
| 1718 | // conversion from the type of its first parameter to the type of |
| 1719 | // its class. Such a constructor is called a converting |
| 1720 | // constructor. |
Anders Carlsson | faccd72 | 2009-08-28 16:57:08 +0000 | [diff] [blame] | 1721 | if (isExplicit() && !AllowExplicit) |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 1722 | return false; |
| 1723 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1724 | return (getNumParams() == 0 && |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 1725 | getType()->getAs<FunctionProtoType>()->isVariadic()) || |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 1726 | (getNumParams() == 1) || |
Douglas Gregor | 113c444 | 2012-06-05 23:44:51 +0000 | [diff] [blame] | 1727 | (getNumParams() > 1 && |
| 1728 | (getParamDecl(1)->hasDefaultArg() || |
| 1729 | getParamDecl(1)->isParameterPack())); |
Douglas Gregor | 60d62c2 | 2008-10-31 16:23:19 +0000 | [diff] [blame] | 1730 | } |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 1731 | |
Douglas Gregor | 6493cc5 | 2010-11-08 17:16:59 +0000 | [diff] [blame] | 1732 | bool CXXConstructorDecl::isSpecializationCopyingObject() const { |
Douglas Gregor | 66724ea | 2009-11-14 01:20:54 +0000 | [diff] [blame] | 1733 | if ((getNumParams() < 1) || |
| 1734 | (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) || |
| 1735 | (getPrimaryTemplate() == 0) || |
| 1736 | (getDescribedFunctionTemplate() != 0)) |
| 1737 | return false; |
| 1738 | |
| 1739 | const ParmVarDecl *Param = getParamDecl(0); |
| 1740 | |
| 1741 | ASTContext &Context = getASTContext(); |
| 1742 | CanQualType ParamType = Context.getCanonicalType(Param->getType()); |
| 1743 | |
Douglas Gregor | 66724ea | 2009-11-14 01:20:54 +0000 | [diff] [blame] | 1744 | // Is it the same as our our class type? |
| 1745 | CanQualType ClassTy |
| 1746 | = Context.getCanonicalType(Context.getTagDeclType(getParent())); |
| 1747 | if (ParamType.getUnqualifiedType() != ClassTy) |
| 1748 | return false; |
| 1749 | |
| 1750 | return true; |
| 1751 | } |
| 1752 | |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 1753 | const CXXConstructorDecl *CXXConstructorDecl::getInheritedConstructor() const { |
| 1754 | // Hack: we store the inherited constructor in the overridden method table |
Eli Friedman | 540659e | 2012-03-10 01:39:01 +0000 | [diff] [blame] | 1755 | method_iterator It = getASTContext().overridden_methods_begin(this); |
| 1756 | if (It == getASTContext().overridden_methods_end(this)) |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 1757 | return 0; |
| 1758 | |
| 1759 | return cast<CXXConstructorDecl>(*It); |
| 1760 | } |
| 1761 | |
| 1762 | void |
| 1763 | CXXConstructorDecl::setInheritedConstructor(const CXXConstructorDecl *BaseCtor){ |
| 1764 | // Hack: we store the inherited constructor in the overridden method table |
Eli Friedman | 540659e | 2012-03-10 01:39:01 +0000 | [diff] [blame] | 1765 | assert(getASTContext().overridden_methods_size(this) == 0 && |
| 1766 | "Base ctor already set."); |
| 1767 | getASTContext().addOverriddenMethod(this, BaseCtor); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 1768 | } |
| 1769 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1770 | void CXXDestructorDecl::anchor() { } |
| 1771 | |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1772 | CXXDestructorDecl * |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1773 | CXXDestructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1774 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(CXXDestructorDecl)); |
| 1775 | return new (Mem) CXXDestructorDecl(0, SourceLocation(), DeclarationNameInfo(), |
Craig Silverstein | b41d899 | 2010-10-21 00:44:50 +0000 | [diff] [blame] | 1776 | QualType(), 0, false, false); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | CXXDestructorDecl * |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1780 | CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1781 | SourceLocation StartLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1782 | const DeclarationNameInfo &NameInfo, |
Craig Silverstein | b41d899 | 2010-10-21 00:44:50 +0000 | [diff] [blame] | 1783 | QualType T, TypeSourceInfo *TInfo, |
Richard Smith | af1fc7a | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1784 | bool isInline, bool isImplicitlyDeclared) { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1785 | assert(NameInfo.getName().getNameKind() |
| 1786 | == DeclarationName::CXXDestructorName && |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 1787 | "Name must refer to a destructor"); |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1788 | return new (C) CXXDestructorDecl(RD, StartLoc, NameInfo, T, TInfo, isInline, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1789 | isImplicitlyDeclared); |
Douglas Gregor | 42a552f | 2008-11-05 20:51:48 +0000 | [diff] [blame] | 1790 | } |
| 1791 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1792 | void CXXConversionDecl::anchor() { } |
| 1793 | |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 1794 | CXXConversionDecl * |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1795 | CXXConversionDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1796 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(CXXConversionDecl)); |
| 1797 | return new (Mem) CXXConversionDecl(0, SourceLocation(), DeclarationNameInfo(), |
| 1798 | QualType(), 0, false, false, false, |
| 1799 | SourceLocation()); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | CXXConversionDecl * |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 1803 | CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1804 | SourceLocation StartLoc, |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1805 | const DeclarationNameInfo &NameInfo, |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1806 | QualType T, TypeSourceInfo *TInfo, |
Douglas Gregor | f525160 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 1807 | bool isInline, bool isExplicit, |
Richard Smith | af1fc7a | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1808 | bool isConstexpr, SourceLocation EndLocation) { |
Abramo Bagnara | 2577743 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1809 | assert(NameInfo.getName().getNameKind() |
| 1810 | == DeclarationName::CXXConversionFunctionName && |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 1811 | "Name must refer to a conversion function"); |
Abramo Bagnara | ff676cb | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 1812 | return new (C) CXXConversionDecl(RD, StartLoc, NameInfo, T, TInfo, |
Richard Smith | af1fc7a | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 1813 | isInline, isExplicit, isConstexpr, |
| 1814 | EndLocation); |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 1815 | } |
| 1816 | |
Douglas Gregor | f6e2e02 | 2012-02-16 01:06:16 +0000 | [diff] [blame] | 1817 | bool CXXConversionDecl::isLambdaToBlockPointerConversion() const { |
| 1818 | return isImplicit() && getParent()->isLambda() && |
| 1819 | getConversionType()->isBlockPointerType(); |
| 1820 | } |
| 1821 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1822 | void LinkageSpecDecl::anchor() { } |
| 1823 | |
Chris Lattner | 21ef7ae | 2008-11-04 16:51:42 +0000 | [diff] [blame] | 1824 | LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1825 | DeclContext *DC, |
Abramo Bagnara | a2026c9 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 1826 | SourceLocation ExternLoc, |
| 1827 | SourceLocation LangLoc, |
Abramo Bagnara | 5f6bcbe | 2011-03-03 14:52:38 +0000 | [diff] [blame] | 1828 | LanguageIDs Lang, |
Abramo Bagnara | 5f6bcbe | 2011-03-03 14:52:38 +0000 | [diff] [blame] | 1829 | SourceLocation RBraceLoc) { |
Abramo Bagnara | a2026c9 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 1830 | return new (C) LinkageSpecDecl(DC, ExternLoc, LangLoc, Lang, RBraceLoc); |
Douglas Gregor | f44515a | 2008-12-16 22:23:02 +0000 | [diff] [blame] | 1831 | } |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1832 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1833 | LinkageSpecDecl *LinkageSpecDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1834 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(LinkageSpecDecl)); |
| 1835 | return new (Mem) LinkageSpecDecl(0, SourceLocation(), SourceLocation(), |
| 1836 | lang_c, SourceLocation()); |
| 1837 | } |
| 1838 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1839 | void UsingDirectiveDecl::anchor() { } |
| 1840 | |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1841 | UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC, |
| 1842 | SourceLocation L, |
| 1843 | SourceLocation NamespaceLoc, |
Douglas Gregor | db99241 | 2011-02-25 16:33:46 +0000 | [diff] [blame] | 1844 | NestedNameSpecifierLoc QualifierLoc, |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1845 | SourceLocation IdentLoc, |
Sebastian Redl | eb0d8c9 | 2009-11-23 15:34:23 +0000 | [diff] [blame] | 1846 | NamedDecl *Used, |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1847 | DeclContext *CommonAncestor) { |
Sebastian Redl | eb0d8c9 | 2009-11-23 15:34:23 +0000 | [diff] [blame] | 1848 | if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Used)) |
| 1849 | Used = NS->getOriginalNamespace(); |
Douglas Gregor | db99241 | 2011-02-25 16:33:46 +0000 | [diff] [blame] | 1850 | return new (C) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierLoc, |
| 1851 | IdentLoc, Used, CommonAncestor); |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1852 | } |
| 1853 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1854 | UsingDirectiveDecl * |
| 1855 | UsingDirectiveDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1856 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(UsingDirectiveDecl)); |
| 1857 | return new (Mem) UsingDirectiveDecl(0, SourceLocation(), SourceLocation(), |
| 1858 | NestedNameSpecifierLoc(), |
| 1859 | SourceLocation(), 0, 0); |
| 1860 | } |
| 1861 | |
Sebastian Redl | eb0d8c9 | 2009-11-23 15:34:23 +0000 | [diff] [blame] | 1862 | NamespaceDecl *UsingDirectiveDecl::getNominatedNamespace() { |
| 1863 | if (NamespaceAliasDecl *NA = |
| 1864 | dyn_cast_or_null<NamespaceAliasDecl>(NominatedNamespace)) |
| 1865 | return NA->getNamespace(); |
| 1866 | return cast_or_null<NamespaceDecl>(NominatedNamespace); |
| 1867 | } |
| 1868 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1869 | void NamespaceDecl::anchor() { } |
| 1870 | |
Douglas Gregor | f5c9f9f | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1871 | NamespaceDecl::NamespaceDecl(DeclContext *DC, bool Inline, |
| 1872 | SourceLocation StartLoc, |
| 1873 | SourceLocation IdLoc, IdentifierInfo *Id, |
| 1874 | NamespaceDecl *PrevDecl) |
| 1875 | : NamedDecl(Namespace, DC, IdLoc, Id), DeclContext(Namespace), |
| 1876 | LocStart(StartLoc), RBraceLoc(), AnonOrFirstNamespaceAndInline(0, Inline) |
| 1877 | { |
| 1878 | setPreviousDeclaration(PrevDecl); |
| 1879 | |
| 1880 | if (PrevDecl) |
| 1881 | AnonOrFirstNamespaceAndInline.setPointer(PrevDecl->getOriginalNamespace()); |
| 1882 | } |
| 1883 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1884 | NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC, |
Douglas Gregor | f5c9f9f | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1885 | bool Inline, SourceLocation StartLoc, |
| 1886 | SourceLocation IdLoc, IdentifierInfo *Id, |
| 1887 | NamespaceDecl *PrevDecl) { |
| 1888 | return new (C) NamespaceDecl(DC, Inline, StartLoc, IdLoc, Id, PrevDecl); |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | NamespaceDecl *NamespaceDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1892 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(NamespaceDecl)); |
Douglas Gregor | f5c9f9f | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1893 | return new (Mem) NamespaceDecl(0, false, SourceLocation(), SourceLocation(), |
| 1894 | 0, 0); |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1895 | } |
| 1896 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1897 | void NamespaceAliasDecl::anchor() { } |
| 1898 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1899 | NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC, |
Douglas Gregor | 0a35bce | 2010-09-01 03:07:18 +0000 | [diff] [blame] | 1900 | SourceLocation UsingLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1901 | SourceLocation AliasLoc, |
| 1902 | IdentifierInfo *Alias, |
Douglas Gregor | 0cfaf6a | 2011-02-25 17:08:07 +0000 | [diff] [blame] | 1903 | NestedNameSpecifierLoc QualifierLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1904 | SourceLocation IdentLoc, |
Anders Carlsson | 68771c7 | 2009-03-28 22:58:02 +0000 | [diff] [blame] | 1905 | NamedDecl *Namespace) { |
Sebastian Redl | eb0d8c9 | 2009-11-23 15:34:23 +0000 | [diff] [blame] | 1906 | if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Namespace)) |
| 1907 | Namespace = NS->getOriginalNamespace(); |
Douglas Gregor | 0cfaf6a | 2011-02-25 17:08:07 +0000 | [diff] [blame] | 1908 | return new (C) NamespaceAliasDecl(DC, UsingLoc, AliasLoc, Alias, |
| 1909 | QualifierLoc, IdentLoc, Namespace); |
Anders Carlsson | 68771c7 | 2009-03-28 22:58:02 +0000 | [diff] [blame] | 1910 | } |
| 1911 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1912 | NamespaceAliasDecl * |
| 1913 | NamespaceAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1914 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(NamespaceAliasDecl)); |
| 1915 | return new (Mem) NamespaceAliasDecl(0, SourceLocation(), SourceLocation(), 0, |
| 1916 | NestedNameSpecifierLoc(), |
| 1917 | SourceLocation(), 0); |
| 1918 | } |
| 1919 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1920 | void UsingShadowDecl::anchor() { } |
| 1921 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1922 | UsingShadowDecl * |
| 1923 | UsingShadowDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1924 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(UsingShadowDecl)); |
| 1925 | return new (Mem) UsingShadowDecl(0, SourceLocation(), 0, 0); |
| 1926 | } |
| 1927 | |
Argyrios Kyrtzidis | 826faa2 | 2010-11-10 05:40:41 +0000 | [diff] [blame] | 1928 | UsingDecl *UsingShadowDecl::getUsingDecl() const { |
| 1929 | const UsingShadowDecl *Shadow = this; |
| 1930 | while (const UsingShadowDecl *NextShadow = |
| 1931 | dyn_cast<UsingShadowDecl>(Shadow->UsingOrNextShadow)) |
| 1932 | Shadow = NextShadow; |
| 1933 | return cast<UsingDecl>(Shadow->UsingOrNextShadow); |
| 1934 | } |
| 1935 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1936 | void UsingDecl::anchor() { } |
| 1937 | |
Argyrios Kyrtzidis | 826faa2 | 2010-11-10 05:40:41 +0000 | [diff] [blame] | 1938 | void UsingDecl::addShadowDecl(UsingShadowDecl *S) { |
| 1939 | assert(std::find(shadow_begin(), shadow_end(), S) == shadow_end() && |
| 1940 | "declaration already in set"); |
| 1941 | assert(S->getUsingDecl() == this); |
| 1942 | |
Benjamin Kramer | 9bc6fb6 | 2012-01-07 19:09:05 +0000 | [diff] [blame] | 1943 | if (FirstUsingShadow.getPointer()) |
| 1944 | S->UsingOrNextShadow = FirstUsingShadow.getPointer(); |
| 1945 | FirstUsingShadow.setPointer(S); |
Argyrios Kyrtzidis | 826faa2 | 2010-11-10 05:40:41 +0000 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | void UsingDecl::removeShadowDecl(UsingShadowDecl *S) { |
| 1949 | assert(std::find(shadow_begin(), shadow_end(), S) != shadow_end() && |
| 1950 | "declaration not in set"); |
| 1951 | assert(S->getUsingDecl() == this); |
| 1952 | |
| 1953 | // Remove S from the shadow decl chain. This is O(n) but hopefully rare. |
| 1954 | |
Benjamin Kramer | 9bc6fb6 | 2012-01-07 19:09:05 +0000 | [diff] [blame] | 1955 | if (FirstUsingShadow.getPointer() == S) { |
| 1956 | FirstUsingShadow.setPointer( |
| 1957 | dyn_cast<UsingShadowDecl>(S->UsingOrNextShadow)); |
Argyrios Kyrtzidis | 826faa2 | 2010-11-10 05:40:41 +0000 | [diff] [blame] | 1958 | S->UsingOrNextShadow = this; |
| 1959 | return; |
| 1960 | } |
| 1961 | |
Benjamin Kramer | 9bc6fb6 | 2012-01-07 19:09:05 +0000 | [diff] [blame] | 1962 | UsingShadowDecl *Prev = FirstUsingShadow.getPointer(); |
Argyrios Kyrtzidis | 826faa2 | 2010-11-10 05:40:41 +0000 | [diff] [blame] | 1963 | while (Prev->UsingOrNextShadow != S) |
| 1964 | Prev = cast<UsingShadowDecl>(Prev->UsingOrNextShadow); |
| 1965 | Prev->UsingOrNextShadow = S->UsingOrNextShadow; |
| 1966 | S->UsingOrNextShadow = this; |
| 1967 | } |
| 1968 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1969 | UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation UL, |
| 1970 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | ef3dce8 | 2010-08-12 11:46:03 +0000 | [diff] [blame] | 1971 | const DeclarationNameInfo &NameInfo, |
| 1972 | bool IsTypeNameArg) { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1973 | return new (C) UsingDecl(DC, UL, QualifierLoc, NameInfo, IsTypeNameArg); |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 1974 | } |
| 1975 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1976 | UsingDecl *UsingDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1977 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(UsingDecl)); |
| 1978 | return new (Mem) UsingDecl(0, SourceLocation(), NestedNameSpecifierLoc(), |
| 1979 | DeclarationNameInfo(), false); |
| 1980 | } |
| 1981 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1982 | void UnresolvedUsingValueDecl::anchor() { } |
| 1983 | |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1984 | UnresolvedUsingValueDecl * |
| 1985 | UnresolvedUsingValueDecl::Create(ASTContext &C, DeclContext *DC, |
| 1986 | SourceLocation UsingLoc, |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1987 | NestedNameSpecifierLoc QualifierLoc, |
Abramo Bagnara | ef3dce8 | 2010-08-12 11:46:03 +0000 | [diff] [blame] | 1988 | const DeclarationNameInfo &NameInfo) { |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1989 | return new (C) UnresolvedUsingValueDecl(DC, C.DependentTy, UsingLoc, |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1990 | QualifierLoc, NameInfo); |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1991 | } |
| 1992 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 1993 | UnresolvedUsingValueDecl * |
| 1994 | UnresolvedUsingValueDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 1995 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(UnresolvedUsingValueDecl)); |
| 1996 | return new (Mem) UnresolvedUsingValueDecl(0, QualType(), SourceLocation(), |
| 1997 | NestedNameSpecifierLoc(), |
| 1998 | DeclarationNameInfo()); |
| 1999 | } |
| 2000 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 2001 | void UnresolvedUsingTypenameDecl::anchor() { } |
| 2002 | |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 2003 | UnresolvedUsingTypenameDecl * |
| 2004 | UnresolvedUsingTypenameDecl::Create(ASTContext &C, DeclContext *DC, |
| 2005 | SourceLocation UsingLoc, |
| 2006 | SourceLocation TypenameLoc, |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 2007 | NestedNameSpecifierLoc QualifierLoc, |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 2008 | SourceLocation TargetNameLoc, |
| 2009 | DeclarationName TargetName) { |
| 2010 | return new (C) UnresolvedUsingTypenameDecl(DC, UsingLoc, TypenameLoc, |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 2011 | QualifierLoc, TargetNameLoc, |
John McCall | 7ba107a | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 2012 | TargetName.getAsIdentifierInfo()); |
Anders Carlsson | 665b49c | 2009-08-28 05:30:28 +0000 | [diff] [blame] | 2013 | } |
| 2014 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 2015 | UnresolvedUsingTypenameDecl * |
| 2016 | UnresolvedUsingTypenameDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
| 2017 | void *Mem = AllocateDeserializedDecl(C, ID, |
| 2018 | sizeof(UnresolvedUsingTypenameDecl)); |
| 2019 | return new (Mem) UnresolvedUsingTypenameDecl(0, SourceLocation(), |
| 2020 | SourceLocation(), |
| 2021 | NestedNameSpecifierLoc(), |
| 2022 | SourceLocation(), |
| 2023 | 0); |
| 2024 | } |
| 2025 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 2026 | void StaticAssertDecl::anchor() { } |
| 2027 | |
Anders Carlsson | fb31176 | 2009-03-14 00:25:26 +0000 | [diff] [blame] | 2028 | StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC, |
Abramo Bagnara | a2026c9 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 2029 | SourceLocation StaticAssertLoc, |
| 2030 | Expr *AssertExpr, |
| 2031 | StringLiteral *Message, |
Richard Smith | e3f470a | 2012-07-11 22:37:56 +0000 | [diff] [blame] | 2032 | SourceLocation RParenLoc, |
| 2033 | bool Failed) { |
Abramo Bagnara | a2026c9 | 2011-03-08 16:41:52 +0000 | [diff] [blame] | 2034 | return new (C) StaticAssertDecl(DC, StaticAssertLoc, AssertExpr, Message, |
Richard Smith | e3f470a | 2012-07-11 22:37:56 +0000 | [diff] [blame] | 2035 | RParenLoc, Failed); |
Anders Carlsson | fb31176 | 2009-03-14 00:25:26 +0000 | [diff] [blame] | 2036 | } |
| 2037 | |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 2038 | StaticAssertDecl *StaticAssertDecl::CreateDeserialized(ASTContext &C, |
| 2039 | unsigned ID) { |
| 2040 | void *Mem = AllocateDeserializedDecl(C, ID, sizeof(StaticAssertDecl)); |
Richard Smith | e3f470a | 2012-07-11 22:37:56 +0000 | [diff] [blame] | 2041 | return new (Mem) StaticAssertDecl(0, SourceLocation(), 0, 0, |
| 2042 | SourceLocation(), false); |
Douglas Gregor | 1e68ecc | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 2043 | } |
| 2044 | |
Anders Carlsson | 05bf2c7 | 2009-03-26 23:46:50 +0000 | [diff] [blame] | 2045 | static const char *getAccessName(AccessSpecifier AS) { |
| 2046 | switch (AS) { |
Anders Carlsson | 05bf2c7 | 2009-03-26 23:46:50 +0000 | [diff] [blame] | 2047 | case AS_none: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 2048 | llvm_unreachable("Invalid access specifier!"); |
Anders Carlsson | 05bf2c7 | 2009-03-26 23:46:50 +0000 | [diff] [blame] | 2049 | case AS_public: |
| 2050 | return "public"; |
| 2051 | case AS_private: |
| 2052 | return "private"; |
| 2053 | case AS_protected: |
| 2054 | return "protected"; |
| 2055 | } |
David Blaikie | 561d3ab | 2012-01-17 02:30:50 +0000 | [diff] [blame] | 2056 | llvm_unreachable("Invalid access specifier!"); |
Anders Carlsson | 05bf2c7 | 2009-03-26 23:46:50 +0000 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB, |
| 2060 | AccessSpecifier AS) { |
| 2061 | return DB << getAccessName(AS); |
| 2062 | } |
Richard Smith | f15fda0 | 2012-02-02 01:16:57 +0000 | [diff] [blame] | 2063 | |
| 2064 | const PartialDiagnostic &clang::operator<<(const PartialDiagnostic &DB, |
| 2065 | AccessSpecifier AS) { |
| 2066 | return DB << getAccessName(AS); |
| 2067 | } |