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