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