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