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