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