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