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