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