File: | tools/clang/lib/AST/DeclCXX.cpp |
Warning: | line 2569, column 11 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | //===- DeclCXX.cpp - C++ Declaration AST Node Implementation --------------===// | |||
2 | // | |||
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 | |||
6 | // | |||
7 | //===----------------------------------------------------------------------===// | |||
8 | // | |||
9 | // This file implements the C++ related Decl classes. | |||
10 | // | |||
11 | //===----------------------------------------------------------------------===// | |||
12 | ||||
13 | #include "clang/AST/DeclCXX.h" | |||
14 | #include "clang/AST/ASTContext.h" | |||
15 | #include "clang/AST/ASTLambda.h" | |||
16 | #include "clang/AST/ASTMutationListener.h" | |||
17 | #include "clang/AST/ASTUnresolvedSet.h" | |||
18 | #include "clang/AST/CXXInheritance.h" | |||
19 | #include "clang/AST/DeclBase.h" | |||
20 | #include "clang/AST/DeclTemplate.h" | |||
21 | #include "clang/AST/DeclarationName.h" | |||
22 | #include "clang/AST/Expr.h" | |||
23 | #include "clang/AST/ExprCXX.h" | |||
24 | #include "clang/AST/LambdaCapture.h" | |||
25 | #include "clang/AST/NestedNameSpecifier.h" | |||
26 | #include "clang/AST/ODRHash.h" | |||
27 | #include "clang/AST/Type.h" | |||
28 | #include "clang/AST/TypeLoc.h" | |||
29 | #include "clang/AST/UnresolvedSet.h" | |||
30 | #include "clang/Basic/Diagnostic.h" | |||
31 | #include "clang/Basic/IdentifierTable.h" | |||
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" | |||
39 | #include "llvm/ADT/SmallPtrSet.h" | |||
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 | ||||
50 | using namespace clang; | |||
51 | ||||
52 | //===----------------------------------------------------------------------===// | |||
53 | // Decl Allocation/Deallocation Method Implementations | |||
54 | //===----------------------------------------------------------------------===// | |||
55 | ||||
56 | void AccessSpecDecl::anchor() {} | |||
57 | ||||
58 | AccessSpecDecl *AccessSpecDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
59 | return new (C, ID) AccessSpecDecl(EmptyShell()); | |||
60 | } | |||
61 | ||||
62 | void LazyASTUnresolvedSet::getFromExternalSource(ASTContext &C) const { | |||
63 | ExternalASTSource *Source = C.getExternalSource(); | |||
64 | assert(Impl.Decls.isLazy() && "getFromExternalSource for non-lazy set")((Impl.Decls.isLazy() && "getFromExternalSource for non-lazy set" ) ? static_cast<void> (0) : __assert_fail ("Impl.Decls.isLazy() && \"getFromExternalSource for non-lazy set\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 64, __PRETTY_FUNCTION__)); | |||
65 | assert(Source && "getFromExternalSource with no external source")((Source && "getFromExternalSource with no external source" ) ? static_cast<void> (0) : __assert_fail ("Source && \"getFromExternalSource with no external source\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 65, __PRETTY_FUNCTION__)); | |||
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 | ||||
73 | CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D) | |||
74 | : UserDeclaredConstructor(false), UserDeclaredSpecialMembers(0), | |||
75 | Aggregate(true), PlainOldData(true), Empty(true), Polymorphic(false), | |||
76 | Abstract(false), IsStandardLayout(true), IsCXX11StandardLayout(true), | |||
77 | HasBasesWithFields(false), HasBasesWithNonStaticDataMembers(false), | |||
78 | HasPrivateFields(false), HasProtectedFields(false), | |||
79 | HasPublicFields(false), HasMutableFields(false), HasVariantMembers(false), | |||
80 | HasOnlyCMembers(true), HasInClassInitializer(false), | |||
81 | HasUninitializedReferenceMember(false), HasUninitializedFields(false), | |||
82 | HasInheritedConstructor(false), HasInheritedAssignment(false), | |||
83 | NeedOverloadResolutionForCopyConstructor(false), | |||
84 | NeedOverloadResolutionForMoveConstructor(false), | |||
85 | NeedOverloadResolutionForMoveAssignment(false), | |||
86 | NeedOverloadResolutionForDestructor(false), | |||
87 | DefaultedCopyConstructorIsDeleted(false), | |||
88 | DefaultedMoveConstructorIsDeleted(false), | |||
89 | DefaultedMoveAssignmentIsDeleted(false), | |||
90 | DefaultedDestructorIsDeleted(false), HasTrivialSpecialMembers(SMF_All), | |||
91 | HasTrivialSpecialMembersForCall(SMF_All), | |||
92 | DeclaredNonTrivialSpecialMembers(0), | |||
93 | DeclaredNonTrivialSpecialMembersForCall(0), HasIrrelevantDestructor(true), | |||
94 | HasConstexprNonCopyMoveConstructor(false), | |||
95 | HasDefaultedDefaultConstructor(false), | |||
96 | DefaultedDefaultConstructorIsConstexpr(true), | |||
97 | HasConstexprDefaultConstructor(false), | |||
98 | DefaultedDestructorIsConstexpr(true), | |||
99 | HasNonLiteralTypeFieldsOrBases(false), ComputedVisibleConversions(false), | |||
100 | UserProvidedDefaultConstructor(false), DeclaredSpecialMembers(0), | |||
101 | ImplicitCopyConstructorCanHaveConstParamForVBase(true), | |||
102 | ImplicitCopyConstructorCanHaveConstParamForNonVBase(true), | |||
103 | ImplicitCopyAssignmentHasConstParam(true), | |||
104 | HasDeclaredCopyConstructorWithConstParam(false), | |||
105 | HasDeclaredCopyAssignmentWithConstParam(false), IsLambda(false), | |||
106 | IsParsingBaseSpecifiers(false), HasODRHash(false), Definition(D) {} | |||
107 | ||||
108 | CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getBasesSlowCase() const { | |||
109 | return Bases.get(Definition->getASTContext().getExternalSource()); | |||
110 | } | |||
111 | ||||
112 | CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getVBasesSlowCase() const { | |||
113 | return VBases.get(Definition->getASTContext().getExternalSource()); | |||
114 | } | |||
115 | ||||
116 | CXXRecordDecl::CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, | |||
117 | DeclContext *DC, SourceLocation StartLoc, | |||
118 | SourceLocation IdLoc, IdentifierInfo *Id, | |||
119 | CXXRecordDecl *PrevDecl) | |||
120 | : RecordDecl(K, TK, C, DC, StartLoc, IdLoc, Id, PrevDecl), | |||
121 | DefinitionData(PrevDecl ? PrevDecl->DefinitionData | |||
122 | : nullptr) {} | |||
123 | ||||
124 | CXXRecordDecl *CXXRecordDecl::Create(const ASTContext &C, TagKind TK, | |||
125 | DeclContext *DC, SourceLocation StartLoc, | |||
126 | SourceLocation IdLoc, IdentifierInfo *Id, | |||
127 | CXXRecordDecl *PrevDecl, | |||
128 | bool DelayTypeCreation) { | |||
129 | auto *R = new (C, DC) CXXRecordDecl(CXXRecord, TK, C, DC, StartLoc, IdLoc, Id, | |||
130 | PrevDecl); | |||
131 | R->setMayHaveOutOfDateDef(C.getLangOpts().Modules); | |||
132 | ||||
133 | // FIXME: DelayTypeCreation seems like such a hack | |||
134 | if (!DelayTypeCreation) | |||
135 | C.getTypeDeclType(R, PrevDecl); | |||
136 | return R; | |||
137 | } | |||
138 | ||||
139 | CXXRecordDecl * | |||
140 | CXXRecordDecl::CreateLambda(const ASTContext &C, DeclContext *DC, | |||
141 | TypeSourceInfo *Info, SourceLocation Loc, | |||
142 | bool Dependent, bool IsGeneric, | |||
143 | LambdaCaptureDefault CaptureDefault) { | |||
144 | auto *R = new (C, DC) CXXRecordDecl(CXXRecord, TTK_Class, C, DC, Loc, Loc, | |||
145 | nullptr, nullptr); | |||
146 | R->setBeingDefined(true); | |||
147 | R->DefinitionData = | |||
148 | new (C) struct LambdaDefinitionData(R, Info, Dependent, IsGeneric, | |||
149 | CaptureDefault); | |||
150 | R->setMayHaveOutOfDateDef(false); | |||
151 | R->setImplicit(true); | |||
152 | C.getTypeDeclType(R, /*PrevDecl=*/nullptr); | |||
153 | return R; | |||
154 | } | |||
155 | ||||
156 | CXXRecordDecl * | |||
157 | CXXRecordDecl::CreateDeserialized(const ASTContext &C, unsigned ID) { | |||
158 | auto *R = new (C, ID) CXXRecordDecl( | |||
159 | CXXRecord, TTK_Struct, C, nullptr, SourceLocation(), SourceLocation(), | |||
160 | nullptr, nullptr); | |||
161 | R->setMayHaveOutOfDateDef(false); | |||
162 | return R; | |||
163 | } | |||
164 | ||||
165 | /// Determine whether a class has a repeated base class. This is intended for | |||
166 | /// use when determining if a class is standard-layout, so makes no attempt to | |||
167 | /// handle virtual bases. | |||
168 | static bool hasRepeatedBaseClass(const CXXRecordDecl *StartRD) { | |||
169 | llvm::SmallPtrSet<const CXXRecordDecl*, 8> SeenBaseTypes; | |||
170 | SmallVector<const CXXRecordDecl*, 8> WorkList = {StartRD}; | |||
171 | while (!WorkList.empty()) { | |||
172 | const CXXRecordDecl *RD = WorkList.pop_back_val(); | |||
173 | for (const CXXBaseSpecifier &BaseSpec : RD->bases()) { | |||
174 | if (const CXXRecordDecl *B = BaseSpec.getType()->getAsCXXRecordDecl()) { | |||
175 | if (!SeenBaseTypes.insert(B).second) | |||
176 | return true; | |||
177 | WorkList.push_back(B); | |||
178 | } | |||
179 | } | |||
180 | } | |||
181 | return false; | |||
182 | } | |||
183 | ||||
184 | void | |||
185 | CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases, | |||
186 | unsigned NumBases) { | |||
187 | ASTContext &C = getASTContext(); | |||
188 | ||||
189 | if (!data().Bases.isOffset() && data().NumBases > 0) | |||
190 | C.Deallocate(data().getBases()); | |||
191 | ||||
192 | if (NumBases) { | |||
193 | if (!C.getLangOpts().CPlusPlus17) { | |||
194 | // C++ [dcl.init.aggr]p1: | |||
195 | // An aggregate is [...] a class with [...] no base classes [...]. | |||
196 | data().Aggregate = false; | |||
197 | } | |||
198 | ||||
199 | // C++ [class]p4: | |||
200 | // A POD-struct is an aggregate class... | |||
201 | data().PlainOldData = false; | |||
202 | } | |||
203 | ||||
204 | // The set of seen virtual base types. | |||
205 | llvm::SmallPtrSet<CanQualType, 8> SeenVBaseTypes; | |||
206 | ||||
207 | // The virtual bases of this class. | |||
208 | SmallVector<const CXXBaseSpecifier *, 8> VBases; | |||
209 | ||||
210 | data().Bases = new(C) CXXBaseSpecifier [NumBases]; | |||
211 | data().NumBases = NumBases; | |||
212 | for (unsigned i = 0; i < NumBases; ++i) { | |||
213 | data().getBases()[i] = *Bases[i]; | |||
214 | // Keep track of inherited vbases for this base class. | |||
215 | const CXXBaseSpecifier *Base = Bases[i]; | |||
216 | QualType BaseType = Base->getType(); | |||
217 | // Skip dependent types; we can't do any checking on them now. | |||
218 | if (BaseType->isDependentType()) | |||
219 | continue; | |||
220 | auto *BaseClassDecl = | |||
221 | cast<CXXRecordDecl>(BaseType->getAs<RecordType>()->getDecl()); | |||
222 | ||||
223 | // C++2a [class]p7: | |||
224 | // A standard-layout class is a class that: | |||
225 | // [...] | |||
226 | // -- has all non-static data members and bit-fields in the class and | |||
227 | // its base classes first declared in the same class | |||
228 | if (BaseClassDecl->data().HasBasesWithFields || | |||
229 | !BaseClassDecl->field_empty()) { | |||
230 | if (data().HasBasesWithFields) | |||
231 | // Two bases have members or bit-fields: not standard-layout. | |||
232 | data().IsStandardLayout = false; | |||
233 | data().HasBasesWithFields = true; | |||
234 | } | |||
235 | ||||
236 | // C++11 [class]p7: | |||
237 | // A standard-layout class is a class that: | |||
238 | // -- [...] has [...] at most one base class with non-static data | |||
239 | // members | |||
240 | if (BaseClassDecl->data().HasBasesWithNonStaticDataMembers || | |||
241 | BaseClassDecl->hasDirectFields()) { | |||
242 | if (data().HasBasesWithNonStaticDataMembers) | |||
243 | data().IsCXX11StandardLayout = false; | |||
244 | data().HasBasesWithNonStaticDataMembers = true; | |||
245 | } | |||
246 | ||||
247 | if (!BaseClassDecl->isEmpty()) { | |||
248 | // C++14 [meta.unary.prop]p4: | |||
249 | // T is a class type [...] with [...] no base class B for which | |||
250 | // is_empty<B>::value is false. | |||
251 | data().Empty = false; | |||
252 | } | |||
253 | ||||
254 | // C++1z [dcl.init.agg]p1: | |||
255 | // An aggregate is a class with [...] no private or protected base classes | |||
256 | if (Base->getAccessSpecifier() != AS_public) | |||
257 | data().Aggregate = false; | |||
258 | ||||
259 | // C++ [class.virtual]p1: | |||
260 | // A class that declares or inherits a virtual function is called a | |||
261 | // polymorphic class. | |||
262 | if (BaseClassDecl->isPolymorphic()) { | |||
263 | data().Polymorphic = true; | |||
264 | ||||
265 | // An aggregate is a class with [...] no virtual functions. | |||
266 | data().Aggregate = false; | |||
267 | } | |||
268 | ||||
269 | // C++0x [class]p7: | |||
270 | // A standard-layout class is a class that: [...] | |||
271 | // -- has no non-standard-layout base classes | |||
272 | if (!BaseClassDecl->isStandardLayout()) | |||
273 | data().IsStandardLayout = false; | |||
274 | if (!BaseClassDecl->isCXX11StandardLayout()) | |||
275 | data().IsCXX11StandardLayout = false; | |||
276 | ||||
277 | // Record if this base is the first non-literal field or base. | |||
278 | if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C)) | |||
279 | data().HasNonLiteralTypeFieldsOrBases = true; | |||
280 | ||||
281 | // Now go through all virtual bases of this base and add them. | |||
282 | for (const auto &VBase : BaseClassDecl->vbases()) { | |||
283 | // Add this base if it's not already in the list. | |||
284 | if (SeenVBaseTypes.insert(C.getCanonicalType(VBase.getType())).second) { | |||
285 | VBases.push_back(&VBase); | |||
286 | ||||
287 | // C++11 [class.copy]p8: | |||
288 | // The implicitly-declared copy constructor for a class X will have | |||
289 | // the form 'X::X(const X&)' if each [...] virtual base class B of X | |||
290 | // has a copy constructor whose first parameter is of type | |||
291 | // 'const B&' or 'const volatile B&' [...] | |||
292 | if (CXXRecordDecl *VBaseDecl = VBase.getType()->getAsCXXRecordDecl()) | |||
293 | if (!VBaseDecl->hasCopyConstructorWithConstParam()) | |||
294 | data().ImplicitCopyConstructorCanHaveConstParamForVBase = false; | |||
295 | ||||
296 | // C++1z [dcl.init.agg]p1: | |||
297 | // An aggregate is a class with [...] no virtual base classes | |||
298 | data().Aggregate = false; | |||
299 | } | |||
300 | } | |||
301 | ||||
302 | if (Base->isVirtual()) { | |||
303 | // Add this base if it's not already in the list. | |||
304 | if (SeenVBaseTypes.insert(C.getCanonicalType(BaseType)).second) | |||
305 | VBases.push_back(Base); | |||
306 | ||||
307 | // C++14 [meta.unary.prop] is_empty: | |||
308 | // T is a class type, but not a union type, with ... no virtual base | |||
309 | // classes | |||
310 | data().Empty = false; | |||
311 | ||||
312 | // C++1z [dcl.init.agg]p1: | |||
313 | // An aggregate is a class with [...] no virtual base classes | |||
314 | data().Aggregate = false; | |||
315 | ||||
316 | // C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25: | |||
317 | // A [default constructor, copy/move constructor, or copy/move assignment | |||
318 | // operator for a class X] is trivial [...] if: | |||
319 | // -- class X has [...] no virtual base classes | |||
320 | data().HasTrivialSpecialMembers &= SMF_Destructor; | |||
321 | data().HasTrivialSpecialMembersForCall &= SMF_Destructor; | |||
322 | ||||
323 | // C++0x [class]p7: | |||
324 | // A standard-layout class is a class that: [...] | |||
325 | // -- has [...] no virtual base classes | |||
326 | data().IsStandardLayout = false; | |||
327 | data().IsCXX11StandardLayout = false; | |||
328 | ||||
329 | // C++20 [dcl.constexpr]p3: | |||
330 | // In the definition of a constexpr function [...] | |||
331 | // -- if the function is a constructor or destructor, | |||
332 | // its class shall not have any virtual base classes | |||
333 | data().DefaultedDefaultConstructorIsConstexpr = false; | |||
334 | data().DefaultedDestructorIsConstexpr = false; | |||
335 | ||||
336 | // C++1z [class.copy]p8: | |||
337 | // The implicitly-declared copy constructor for a class X will have | |||
338 | // the form 'X::X(const X&)' if each potentially constructed subobject | |||
339 | // has a copy constructor whose first parameter is of type | |||
340 | // 'const B&' or 'const volatile B&' [...] | |||
341 | if (!BaseClassDecl->hasCopyConstructorWithConstParam()) | |||
342 | data().ImplicitCopyConstructorCanHaveConstParamForVBase = false; | |||
343 | } else { | |||
344 | // C++ [class.ctor]p5: | |||
345 | // A default constructor is trivial [...] if: | |||
346 | // -- all the direct base classes of its class have trivial default | |||
347 | // constructors. | |||
348 | if (!BaseClassDecl->hasTrivialDefaultConstructor()) | |||
349 | data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor; | |||
350 | ||||
351 | // C++0x [class.copy]p13: | |||
352 | // A copy/move constructor for class X is trivial if [...] | |||
353 | // [...] | |||
354 | // -- the constructor selected to copy/move each direct base class | |||
355 | // subobject is trivial, and | |||
356 | if (!BaseClassDecl->hasTrivialCopyConstructor()) | |||
357 | data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor; | |||
358 | ||||
359 | if (!BaseClassDecl->hasTrivialCopyConstructorForCall()) | |||
360 | data().HasTrivialSpecialMembersForCall &= ~SMF_CopyConstructor; | |||
361 | ||||
362 | // If the base class doesn't have a simple move constructor, we'll eagerly | |||
363 | // declare it and perform overload resolution to determine which function | |||
364 | // it actually calls. If it does have a simple move constructor, this | |||
365 | // check is correct. | |||
366 | if (!BaseClassDecl->hasTrivialMoveConstructor()) | |||
367 | data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor; | |||
368 | ||||
369 | if (!BaseClassDecl->hasTrivialMoveConstructorForCall()) | |||
370 | data().HasTrivialSpecialMembersForCall &= ~SMF_MoveConstructor; | |||
371 | ||||
372 | // C++0x [class.copy]p27: | |||
373 | // A copy/move assignment operator for class X is trivial if [...] | |||
374 | // [...] | |||
375 | // -- the assignment operator selected to copy/move each direct base | |||
376 | // class subobject is trivial, and | |||
377 | if (!BaseClassDecl->hasTrivialCopyAssignment()) | |||
378 | data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment; | |||
379 | // If the base class doesn't have a simple move assignment, we'll eagerly | |||
380 | // declare it and perform overload resolution to determine which function | |||
381 | // it actually calls. If it does have a simple move assignment, this | |||
382 | // check is correct. | |||
383 | if (!BaseClassDecl->hasTrivialMoveAssignment()) | |||
384 | data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment; | |||
385 | ||||
386 | // C++11 [class.ctor]p6: | |||
387 | // If that user-written default constructor would satisfy the | |||
388 | // requirements of a constexpr constructor, the implicitly-defined | |||
389 | // default constructor is constexpr. | |||
390 | if (!BaseClassDecl->hasConstexprDefaultConstructor()) | |||
391 | data().DefaultedDefaultConstructorIsConstexpr = false; | |||
392 | ||||
393 | // C++1z [class.copy]p8: | |||
394 | // The implicitly-declared copy constructor for a class X will have | |||
395 | // the form 'X::X(const X&)' if each potentially constructed subobject | |||
396 | // has a copy constructor whose first parameter is of type | |||
397 | // 'const B&' or 'const volatile B&' [...] | |||
398 | if (!BaseClassDecl->hasCopyConstructorWithConstParam()) | |||
399 | data().ImplicitCopyConstructorCanHaveConstParamForNonVBase = false; | |||
400 | } | |||
401 | ||||
402 | // C++ [class.ctor]p3: | |||
403 | // A destructor is trivial if all the direct base classes of its class | |||
404 | // have trivial destructors. | |||
405 | if (!BaseClassDecl->hasTrivialDestructor()) | |||
406 | data().HasTrivialSpecialMembers &= ~SMF_Destructor; | |||
407 | ||||
408 | if (!BaseClassDecl->hasTrivialDestructorForCall()) | |||
409 | data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor; | |||
410 | ||||
411 | if (!BaseClassDecl->hasIrrelevantDestructor()) | |||
412 | data().HasIrrelevantDestructor = false; | |||
413 | ||||
414 | // C++11 [class.copy]p18: | |||
415 | // The implicitly-declared copy assignment oeprator for a class X will | |||
416 | // have the form 'X& X::operator=(const X&)' if each direct base class B | |||
417 | // of X has a copy assignment operator whose parameter is of type 'const | |||
418 | // B&', 'const volatile B&', or 'B' [...] | |||
419 | if (!BaseClassDecl->hasCopyAssignmentWithConstParam()) | |||
420 | data().ImplicitCopyAssignmentHasConstParam = false; | |||
421 | ||||
422 | // A class has an Objective-C object member if... or any of its bases | |||
423 | // has an Objective-C object member. | |||
424 | if (BaseClassDecl->hasObjectMember()) | |||
425 | setHasObjectMember(true); | |||
426 | ||||
427 | if (BaseClassDecl->hasVolatileMember()) | |||
428 | setHasVolatileMember(true); | |||
429 | ||||
430 | if (BaseClassDecl->getArgPassingRestrictions() == | |||
431 | RecordDecl::APK_CanNeverPassInRegs) | |||
432 | setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs); | |||
433 | ||||
434 | // Keep track of the presence of mutable fields. | |||
435 | if (BaseClassDecl->hasMutableFields()) { | |||
436 | data().HasMutableFields = true; | |||
437 | data().NeedOverloadResolutionForCopyConstructor = true; | |||
438 | } | |||
439 | ||||
440 | if (BaseClassDecl->hasUninitializedReferenceMember()) | |||
441 | data().HasUninitializedReferenceMember = true; | |||
442 | ||||
443 | if (!BaseClassDecl->allowConstDefaultInit()) | |||
444 | data().HasUninitializedFields = true; | |||
445 | ||||
446 | addedClassSubobject(BaseClassDecl); | |||
447 | } | |||
448 | ||||
449 | // C++2a [class]p7: | |||
450 | // A class S is a standard-layout class if it: | |||
451 | // -- has at most one base class subobject of any given type | |||
452 | // | |||
453 | // Note that we only need to check this for classes with more than one base | |||
454 | // class. If there's only one base class, and it's standard layout, then | |||
455 | // we know there are no repeated base classes. | |||
456 | if (data().IsStandardLayout && NumBases > 1 && hasRepeatedBaseClass(this)) | |||
457 | data().IsStandardLayout = false; | |||
458 | ||||
459 | if (VBases.empty()) { | |||
460 | data().IsParsingBaseSpecifiers = false; | |||
461 | return; | |||
462 | } | |||
463 | ||||
464 | // Create base specifier for any direct or indirect virtual bases. | |||
465 | data().VBases = new (C) CXXBaseSpecifier[VBases.size()]; | |||
466 | data().NumVBases = VBases.size(); | |||
467 | for (int I = 0, E = VBases.size(); I != E; ++I) { | |||
468 | QualType Type = VBases[I]->getType(); | |||
469 | if (!Type->isDependentType()) | |||
470 | addedClassSubobject(Type->getAsCXXRecordDecl()); | |||
471 | data().getVBases()[I] = *VBases[I]; | |||
472 | } | |||
473 | ||||
474 | data().IsParsingBaseSpecifiers = false; | |||
475 | } | |||
476 | ||||
477 | unsigned CXXRecordDecl::getODRHash() const { | |||
478 | assert(hasDefinition() && "ODRHash only for records with definitions")((hasDefinition() && "ODRHash only for records with definitions" ) ? static_cast<void> (0) : __assert_fail ("hasDefinition() && \"ODRHash only for records with definitions\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 478, __PRETTY_FUNCTION__)); | |||
479 | ||||
480 | // Previously calculated hash is stored in DefinitionData. | |||
481 | if (DefinitionData->HasODRHash) | |||
482 | return DefinitionData->ODRHash; | |||
483 | ||||
484 | // Only calculate hash on first call of getODRHash per record. | |||
485 | ODRHash Hash; | |||
486 | Hash.AddCXXRecordDecl(getDefinition()); | |||
487 | DefinitionData->HasODRHash = true; | |||
488 | DefinitionData->ODRHash = Hash.CalculateHash(); | |||
489 | ||||
490 | return DefinitionData->ODRHash; | |||
491 | } | |||
492 | ||||
493 | void CXXRecordDecl::addedClassSubobject(CXXRecordDecl *Subobj) { | |||
494 | // C++11 [class.copy]p11: | |||
495 | // A defaulted copy/move constructor for a class X is defined as | |||
496 | // deleted if X has: | |||
497 | // -- a direct or virtual base class B that cannot be copied/moved [...] | |||
498 | // -- a non-static data member of class type M (or array thereof) | |||
499 | // that cannot be copied or moved [...] | |||
500 | if (!Subobj->hasSimpleCopyConstructor()) | |||
501 | data().NeedOverloadResolutionForCopyConstructor = true; | |||
502 | if (!Subobj->hasSimpleMoveConstructor()) | |||
503 | data().NeedOverloadResolutionForMoveConstructor = true; | |||
504 | ||||
505 | // C++11 [class.copy]p23: | |||
506 | // A defaulted copy/move assignment operator for a class X is defined as | |||
507 | // deleted if X has: | |||
508 | // -- a direct or virtual base class B that cannot be copied/moved [...] | |||
509 | // -- a non-static data member of class type M (or array thereof) | |||
510 | // that cannot be copied or moved [...] | |||
511 | if (!Subobj->hasSimpleMoveAssignment()) | |||
512 | data().NeedOverloadResolutionForMoveAssignment = true; | |||
513 | ||||
514 | // C++11 [class.ctor]p5, C++11 [class.copy]p11, C++11 [class.dtor]p5: | |||
515 | // A defaulted [ctor or dtor] for a class X is defined as | |||
516 | // deleted if X has: | |||
517 | // -- any direct or virtual base class [...] has a type with a destructor | |||
518 | // that is deleted or inaccessible from the defaulted [ctor or dtor]. | |||
519 | // -- any non-static data member has a type with a destructor | |||
520 | // that is deleted or inaccessible from the defaulted [ctor or dtor]. | |||
521 | if (!Subobj->hasSimpleDestructor()) { | |||
522 | data().NeedOverloadResolutionForCopyConstructor = true; | |||
523 | data().NeedOverloadResolutionForMoveConstructor = true; | |||
524 | data().NeedOverloadResolutionForDestructor = true; | |||
525 | } | |||
526 | ||||
527 | // C++2a [dcl.constexpr]p4: | |||
528 | // The definition of a constexpr destructor [shall] satisfy the | |||
529 | // following requirement: | |||
530 | // -- for every subobject of class type or (possibly multi-dimensional) | |||
531 | // array thereof, that class type shall have a constexpr destructor | |||
532 | if (!Subobj->hasConstexprDestructor()) | |||
533 | data().DefaultedDestructorIsConstexpr = false; | |||
534 | } | |||
535 | ||||
536 | bool CXXRecordDecl::hasConstexprDestructor() const { | |||
537 | auto *Dtor = getDestructor(); | |||
538 | return Dtor ? Dtor->isConstexpr() : defaultedDestructorIsConstexpr(); | |||
539 | } | |||
540 | ||||
541 | bool CXXRecordDecl::hasAnyDependentBases() const { | |||
542 | if (!isDependentContext()) | |||
543 | return false; | |||
544 | ||||
545 | return !forallBases([](const CXXRecordDecl *) { return true; }); | |||
546 | } | |||
547 | ||||
548 | bool CXXRecordDecl::isTriviallyCopyable() const { | |||
549 | // C++0x [class]p5: | |||
550 | // A trivially copyable class is a class that: | |||
551 | // -- has no non-trivial copy constructors, | |||
552 | if (hasNonTrivialCopyConstructor()) return false; | |||
553 | // -- has no non-trivial move constructors, | |||
554 | if (hasNonTrivialMoveConstructor()) return false; | |||
555 | // -- has no non-trivial copy assignment operators, | |||
556 | if (hasNonTrivialCopyAssignment()) return false; | |||
557 | // -- has no non-trivial move assignment operators, and | |||
558 | if (hasNonTrivialMoveAssignment()) return false; | |||
559 | // -- has a trivial destructor. | |||
560 | if (!hasTrivialDestructor()) return false; | |||
561 | ||||
562 | return true; | |||
563 | } | |||
564 | ||||
565 | void CXXRecordDecl::markedVirtualFunctionPure() { | |||
566 | // C++ [class.abstract]p2: | |||
567 | // A class is abstract if it has at least one pure virtual function. | |||
568 | data().Abstract = true; | |||
569 | } | |||
570 | ||||
571 | bool CXXRecordDecl::hasSubobjectAtOffsetZeroOfEmptyBaseType( | |||
572 | ASTContext &Ctx, const CXXRecordDecl *XFirst) { | |||
573 | if (!getNumBases()) | |||
574 | return false; | |||
575 | ||||
576 | llvm::SmallPtrSet<const CXXRecordDecl*, 8> Bases; | |||
577 | llvm::SmallPtrSet<const CXXRecordDecl*, 8> M; | |||
578 | SmallVector<const CXXRecordDecl*, 8> WorkList; | |||
579 | ||||
580 | // Visit a type that we have determined is an element of M(S). | |||
581 | auto Visit = [&](const CXXRecordDecl *RD) -> bool { | |||
582 | RD = RD->getCanonicalDecl(); | |||
583 | ||||
584 | // C++2a [class]p8: | |||
585 | // A class S is a standard-layout class if it [...] has no element of the | |||
586 | // set M(S) of types as a base class. | |||
587 | // | |||
588 | // If we find a subobject of an empty type, it might also be a base class, | |||
589 | // so we'll need to walk the base classes to check. | |||
590 | if (!RD->data().HasBasesWithFields) { | |||
591 | // Walk the bases the first time, stopping if we find the type. Build a | |||
592 | // set of them so we don't need to walk them again. | |||
593 | if (Bases.empty()) { | |||
594 | bool RDIsBase = !forallBases([&](const CXXRecordDecl *Base) -> bool { | |||
595 | Base = Base->getCanonicalDecl(); | |||
596 | if (RD == Base) | |||
597 | return false; | |||
598 | Bases.insert(Base); | |||
599 | return true; | |||
600 | }); | |||
601 | if (RDIsBase) | |||
602 | return true; | |||
603 | } else { | |||
604 | if (Bases.count(RD)) | |||
605 | return true; | |||
606 | } | |||
607 | } | |||
608 | ||||
609 | if (M.insert(RD).second) | |||
610 | WorkList.push_back(RD); | |||
611 | return false; | |||
612 | }; | |||
613 | ||||
614 | if (Visit(XFirst)) | |||
615 | return true; | |||
616 | ||||
617 | while (!WorkList.empty()) { | |||
618 | const CXXRecordDecl *X = WorkList.pop_back_val(); | |||
619 | ||||
620 | // FIXME: We don't check the bases of X. That matches the standard, but | |||
621 | // that sure looks like a wording bug. | |||
622 | ||||
623 | // -- If X is a non-union class type with a non-static data member | |||
624 | // [recurse to each field] that is either of zero size or is the | |||
625 | // first non-static data member of X | |||
626 | // -- If X is a union type, [recurse to union members] | |||
627 | bool IsFirstField = true; | |||
628 | for (auto *FD : X->fields()) { | |||
629 | // FIXME: Should we really care about the type of the first non-static | |||
630 | // data member of a non-union if there are preceding unnamed bit-fields? | |||
631 | if (FD->isUnnamedBitfield()) | |||
632 | continue; | |||
633 | ||||
634 | if (!IsFirstField && !FD->isZeroSize(Ctx)) | |||
635 | continue; | |||
636 | ||||
637 | // -- If X is n array type, [visit the element type] | |||
638 | QualType T = Ctx.getBaseElementType(FD->getType()); | |||
639 | if (auto *RD = T->getAsCXXRecordDecl()) | |||
640 | if (Visit(RD)) | |||
641 | return true; | |||
642 | ||||
643 | if (!X->isUnion()) | |||
644 | IsFirstField = false; | |||
645 | } | |||
646 | } | |||
647 | ||||
648 | return false; | |||
649 | } | |||
650 | ||||
651 | bool CXXRecordDecl::lambdaIsDefaultConstructibleAndAssignable() const { | |||
652 | assert(isLambda() && "not a lambda")((isLambda() && "not a lambda") ? static_cast<void > (0) : __assert_fail ("isLambda() && \"not a lambda\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 652, __PRETTY_FUNCTION__)); | |||
653 | ||||
654 | // C++2a [expr.prim.lambda.capture]p11: | |||
655 | // The closure type associated with a lambda-expression has no default | |||
656 | // constructor if the lambda-expression has a lambda-capture and a | |||
657 | // defaulted default constructor otherwise. It has a deleted copy | |||
658 | // assignment operator if the lambda-expression has a lambda-capture and | |||
659 | // defaulted copy and move assignment operators otherwise. | |||
660 | // | |||
661 | // C++17 [expr.prim.lambda]p21: | |||
662 | // The closure type associated with a lambda-expression has no default | |||
663 | // constructor and a deleted copy assignment operator. | |||
664 | if (getLambdaCaptureDefault() != LCD_None || | |||
665 | getLambdaData().NumCaptures != 0) | |||
666 | return false; | |||
667 | return getASTContext().getLangOpts().CPlusPlus2a; | |||
668 | } | |||
669 | ||||
670 | void CXXRecordDecl::addedMember(Decl *D) { | |||
671 | if (!D->isImplicit() && | |||
672 | !isa<FieldDecl>(D) && | |||
673 | !isa<IndirectFieldDecl>(D) && | |||
674 | (!isa<TagDecl>(D) || cast<TagDecl>(D)->getTagKind() == TTK_Class || | |||
675 | cast<TagDecl>(D)->getTagKind() == TTK_Interface)) | |||
676 | data().HasOnlyCMembers = false; | |||
677 | ||||
678 | // Ignore friends and invalid declarations. | |||
679 | if (D->getFriendObjectKind() || D->isInvalidDecl()) | |||
680 | return; | |||
681 | ||||
682 | auto *FunTmpl = dyn_cast<FunctionTemplateDecl>(D); | |||
683 | if (FunTmpl) | |||
684 | D = FunTmpl->getTemplatedDecl(); | |||
685 | ||||
686 | // FIXME: Pass NamedDecl* to addedMember? | |||
687 | Decl *DUnderlying = D; | |||
688 | if (auto *ND = dyn_cast<NamedDecl>(DUnderlying)) { | |||
689 | DUnderlying = ND->getUnderlyingDecl(); | |||
690 | if (auto *UnderlyingFunTmpl = dyn_cast<FunctionTemplateDecl>(DUnderlying)) | |||
691 | DUnderlying = UnderlyingFunTmpl->getTemplatedDecl(); | |||
692 | } | |||
693 | ||||
694 | if (const auto *Method = dyn_cast<CXXMethodDecl>(D)) { | |||
695 | if (Method->isVirtual()) { | |||
696 | // C++ [dcl.init.aggr]p1: | |||
697 | // An aggregate is an array or a class with [...] no virtual functions. | |||
698 | data().Aggregate = false; | |||
699 | ||||
700 | // C++ [class]p4: | |||
701 | // A POD-struct is an aggregate class... | |||
702 | data().PlainOldData = false; | |||
703 | ||||
704 | // C++14 [meta.unary.prop]p4: | |||
705 | // T is a class type [...] with [...] no virtual member functions... | |||
706 | data().Empty = false; | |||
707 | ||||
708 | // C++ [class.virtual]p1: | |||
709 | // A class that declares or inherits a virtual function is called a | |||
710 | // polymorphic class. | |||
711 | data().Polymorphic = true; | |||
712 | ||||
713 | // C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25: | |||
714 | // A [default constructor, copy/move constructor, or copy/move | |||
715 | // assignment operator for a class X] is trivial [...] if: | |||
716 | // -- class X has no virtual functions [...] | |||
717 | data().HasTrivialSpecialMembers &= SMF_Destructor; | |||
718 | data().HasTrivialSpecialMembersForCall &= SMF_Destructor; | |||
719 | ||||
720 | // C++0x [class]p7: | |||
721 | // A standard-layout class is a class that: [...] | |||
722 | // -- has no virtual functions | |||
723 | data().IsStandardLayout = false; | |||
724 | data().IsCXX11StandardLayout = false; | |||
725 | } | |||
726 | } | |||
727 | ||||
728 | // Notify the listener if an implicit member was added after the definition | |||
729 | // was completed. | |||
730 | if (!isBeingDefined() && D->isImplicit()) | |||
731 | if (ASTMutationListener *L = getASTMutationListener()) | |||
732 | L->AddedCXXImplicitMember(data().Definition, D); | |||
733 | ||||
734 | // The kind of special member this declaration is, if any. | |||
735 | unsigned SMKind = 0; | |||
736 | ||||
737 | // Handle constructors. | |||
738 | if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(D)) { | |||
739 | if (!Constructor->isImplicit()) { | |||
740 | // Note that we have a user-declared constructor. | |||
741 | data().UserDeclaredConstructor = true; | |||
742 | ||||
743 | // C++ [class]p4: | |||
744 | // A POD-struct is an aggregate class [...] | |||
745 | // Since the POD bit is meant to be C++03 POD-ness, clear it even if the | |||
746 | // type is technically an aggregate in C++0x since it wouldn't be in 03. | |||
747 | data().PlainOldData = false; | |||
748 | } | |||
749 | ||||
750 | if (Constructor->isDefaultConstructor()) { | |||
751 | SMKind |= SMF_DefaultConstructor; | |||
752 | ||||
753 | if (Constructor->isUserProvided()) | |||
754 | data().UserProvidedDefaultConstructor = true; | |||
755 | if (Constructor->isConstexpr()) | |||
756 | data().HasConstexprDefaultConstructor = true; | |||
757 | if (Constructor->isDefaulted()) | |||
758 | data().HasDefaultedDefaultConstructor = true; | |||
759 | } | |||
760 | ||||
761 | if (!FunTmpl) { | |||
762 | unsigned Quals; | |||
763 | if (Constructor->isCopyConstructor(Quals)) { | |||
764 | SMKind |= SMF_CopyConstructor; | |||
765 | ||||
766 | if (Quals & Qualifiers::Const) | |||
767 | data().HasDeclaredCopyConstructorWithConstParam = true; | |||
768 | } else if (Constructor->isMoveConstructor()) | |||
769 | SMKind |= SMF_MoveConstructor; | |||
770 | } | |||
771 | ||||
772 | // C++11 [dcl.init.aggr]p1: DR1518 | |||
773 | // An aggregate is an array or a class with no user-provided [or] | |||
774 | // explicit [...] constructors | |||
775 | // C++20 [dcl.init.aggr]p1: | |||
776 | // An aggregate is an array or a class with no user-declared [...] | |||
777 | // constructors | |||
778 | if (getASTContext().getLangOpts().CPlusPlus2a | |||
779 | ? !Constructor->isImplicit() | |||
780 | : (Constructor->isUserProvided() || Constructor->isExplicit())) | |||
781 | data().Aggregate = false; | |||
782 | } | |||
783 | ||||
784 | // Handle constructors, including those inherited from base classes. | |||
785 | if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(DUnderlying)) { | |||
786 | // Record if we see any constexpr constructors which are neither copy | |||
787 | // nor move constructors. | |||
788 | // C++1z [basic.types]p10: | |||
789 | // [...] has at least one constexpr constructor or constructor template | |||
790 | // (possibly inherited from a base class) that is not a copy or move | |||
791 | // constructor [...] | |||
792 | if (Constructor->isConstexpr() && !Constructor->isCopyOrMoveConstructor()) | |||
793 | data().HasConstexprNonCopyMoveConstructor = true; | |||
794 | } | |||
795 | ||||
796 | // Handle destructors. | |||
797 | if (const auto *DD = dyn_cast<CXXDestructorDecl>(D)) { | |||
798 | SMKind |= SMF_Destructor; | |||
799 | ||||
800 | if (DD->isUserProvided()) | |||
801 | data().HasIrrelevantDestructor = false; | |||
802 | // If the destructor is explicitly defaulted and not trivial or not public | |||
803 | // or if the destructor is deleted, we clear HasIrrelevantDestructor in | |||
804 | // finishedDefaultedOrDeletedMember. | |||
805 | ||||
806 | // C++11 [class.dtor]p5: | |||
807 | // A destructor is trivial if [...] the destructor is not virtual. | |||
808 | if (DD->isVirtual()) { | |||
809 | data().HasTrivialSpecialMembers &= ~SMF_Destructor; | |||
810 | data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor; | |||
811 | } | |||
812 | } | |||
813 | ||||
814 | // Handle member functions. | |||
815 | if (const auto *Method = dyn_cast<CXXMethodDecl>(D)) { | |||
816 | if (Method->isCopyAssignmentOperator()) { | |||
817 | SMKind |= SMF_CopyAssignment; | |||
818 | ||||
819 | const auto *ParamTy = | |||
820 | Method->getParamDecl(0)->getType()->getAs<ReferenceType>(); | |||
821 | if (!ParamTy || ParamTy->getPointeeType().isConstQualified()) | |||
822 | data().HasDeclaredCopyAssignmentWithConstParam = true; | |||
823 | } | |||
824 | ||||
825 | if (Method->isMoveAssignmentOperator()) | |||
826 | SMKind |= SMF_MoveAssignment; | |||
827 | ||||
828 | // Keep the list of conversion functions up-to-date. | |||
829 | if (auto *Conversion = dyn_cast<CXXConversionDecl>(D)) { | |||
830 | // FIXME: We use the 'unsafe' accessor for the access specifier here, | |||
831 | // because Sema may not have set it yet. That's really just a misdesign | |||
832 | // in Sema. However, LLDB *will* have set the access specifier correctly, | |||
833 | // and adds declarations after the class is technically completed, | |||
834 | // so completeDefinition()'s overriding of the access specifiers doesn't | |||
835 | // work. | |||
836 | AccessSpecifier AS = Conversion->getAccessUnsafe(); | |||
837 | ||||
838 | if (Conversion->getPrimaryTemplate()) { | |||
839 | // We don't record specializations. | |||
840 | } else { | |||
841 | ASTContext &Ctx = getASTContext(); | |||
842 | ASTUnresolvedSet &Conversions = data().Conversions.get(Ctx); | |||
843 | NamedDecl *Primary = | |||
844 | FunTmpl ? cast<NamedDecl>(FunTmpl) : cast<NamedDecl>(Conversion); | |||
845 | if (Primary->getPreviousDecl()) | |||
846 | Conversions.replace(cast<NamedDecl>(Primary->getPreviousDecl()), | |||
847 | Primary, AS); | |||
848 | else | |||
849 | Conversions.addDecl(Ctx, Primary, AS); | |||
850 | } | |||
851 | } | |||
852 | ||||
853 | if (SMKind) { | |||
854 | // If this is the first declaration of a special member, we no longer have | |||
855 | // an implicit trivial special member. | |||
856 | data().HasTrivialSpecialMembers &= | |||
857 | data().DeclaredSpecialMembers | ~SMKind; | |||
858 | data().HasTrivialSpecialMembersForCall &= | |||
859 | data().DeclaredSpecialMembers | ~SMKind; | |||
860 | ||||
861 | if (!Method->isImplicit() && !Method->isUserProvided()) { | |||
862 | // This method is user-declared but not user-provided. We can't work out | |||
863 | // whether it's trivial yet (not until we get to the end of the class). | |||
864 | // We'll handle this method in finishedDefaultedOrDeletedMember. | |||
865 | } else if (Method->isTrivial()) { | |||
866 | data().HasTrivialSpecialMembers |= SMKind; | |||
867 | data().HasTrivialSpecialMembersForCall |= SMKind; | |||
868 | } else if (Method->isTrivialForCall()) { | |||
869 | data().HasTrivialSpecialMembersForCall |= SMKind; | |||
870 | data().DeclaredNonTrivialSpecialMembers |= SMKind; | |||
871 | } else { | |||
872 | data().DeclaredNonTrivialSpecialMembers |= SMKind; | |||
873 | // If this is a user-provided function, do not set | |||
874 | // DeclaredNonTrivialSpecialMembersForCall here since we don't know | |||
875 | // yet whether the method would be considered non-trivial for the | |||
876 | // purpose of calls (attribute "trivial_abi" can be dropped from the | |||
877 | // class later, which can change the special method's triviality). | |||
878 | if (!Method->isUserProvided()) | |||
879 | data().DeclaredNonTrivialSpecialMembersForCall |= SMKind; | |||
880 | } | |||
881 | ||||
882 | // Note when we have declared a declared special member, and suppress the | |||
883 | // implicit declaration of this special member. | |||
884 | data().DeclaredSpecialMembers |= SMKind; | |||
885 | ||||
886 | if (!Method->isImplicit()) { | |||
887 | data().UserDeclaredSpecialMembers |= SMKind; | |||
888 | ||||
889 | // C++03 [class]p4: | |||
890 | // A POD-struct is an aggregate class that has [...] no user-defined | |||
891 | // copy assignment operator and no user-defined destructor. | |||
892 | // | |||
893 | // Since the POD bit is meant to be C++03 POD-ness, and in C++03, | |||
894 | // aggregates could not have any constructors, clear it even for an | |||
895 | // explicitly defaulted or deleted constructor. | |||
896 | // type is technically an aggregate in C++0x since it wouldn't be in 03. | |||
897 | // | |||
898 | // Also, a user-declared move assignment operator makes a class non-POD. | |||
899 | // This is an extension in C++03. | |||
900 | data().PlainOldData = false; | |||
901 | } | |||
902 | } | |||
903 | ||||
904 | return; | |||
905 | } | |||
906 | ||||
907 | // Handle non-static data members. | |||
908 | if (const auto *Field = dyn_cast<FieldDecl>(D)) { | |||
909 | ASTContext &Context = getASTContext(); | |||
910 | ||||
911 | // C++2a [class]p7: | |||
912 | // A standard-layout class is a class that: | |||
913 | // [...] | |||
914 | // -- has all non-static data members and bit-fields in the class and | |||
915 | // its base classes first declared in the same class | |||
916 | if (data().HasBasesWithFields) | |||
917 | data().IsStandardLayout = false; | |||
918 | ||||
919 | // C++ [class.bit]p2: | |||
920 | // A declaration for a bit-field that omits the identifier declares an | |||
921 | // unnamed bit-field. Unnamed bit-fields are not members and cannot be | |||
922 | // initialized. | |||
923 | if (Field->isUnnamedBitfield()) { | |||
924 | // C++ [meta.unary.prop]p4: [LWG2358] | |||
925 | // T is a class type [...] with [...] no unnamed bit-fields of non-zero | |||
926 | // length | |||
927 | if (data().Empty && !Field->isZeroLengthBitField(Context) && | |||
928 | Context.getLangOpts().getClangABICompat() > | |||
929 | LangOptions::ClangABI::Ver6) | |||
930 | data().Empty = false; | |||
931 | return; | |||
932 | } | |||
933 | ||||
934 | // C++11 [class]p7: | |||
935 | // A standard-layout class is a class that: | |||
936 | // -- either has no non-static data members in the most derived class | |||
937 | // [...] or has no base classes with non-static data members | |||
938 | if (data().HasBasesWithNonStaticDataMembers) | |||
939 | data().IsCXX11StandardLayout = false; | |||
940 | ||||
941 | // C++ [dcl.init.aggr]p1: | |||
942 | // An aggregate is an array or a class (clause 9) with [...] no | |||
943 | // private or protected non-static data members (clause 11). | |||
944 | // | |||
945 | // A POD must be an aggregate. | |||
946 | if (D->getAccess() == AS_private || D->getAccess() == AS_protected) { | |||
947 | data().Aggregate = false; | |||
948 | data().PlainOldData = false; | |||
949 | } | |||
950 | ||||
951 | // Track whether this is the first field. We use this when checking | |||
952 | // whether the class is standard-layout below. | |||
953 | bool IsFirstField = !data().HasPrivateFields && | |||
954 | !data().HasProtectedFields && !data().HasPublicFields; | |||
955 | ||||
956 | // C++0x [class]p7: | |||
957 | // A standard-layout class is a class that: | |||
958 | // [...] | |||
959 | // -- has the same access control for all non-static data members, | |||
960 | switch (D->getAccess()) { | |||
961 | case AS_private: data().HasPrivateFields = true; break; | |||
962 | case AS_protected: data().HasProtectedFields = true; break; | |||
963 | case AS_public: data().HasPublicFields = true; break; | |||
964 | case AS_none: llvm_unreachable("Invalid access specifier")::llvm::llvm_unreachable_internal("Invalid access specifier", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 964); | |||
965 | }; | |||
966 | if ((data().HasPrivateFields + data().HasProtectedFields + | |||
967 | data().HasPublicFields) > 1) { | |||
968 | data().IsStandardLayout = false; | |||
969 | data().IsCXX11StandardLayout = false; | |||
970 | } | |||
971 | ||||
972 | // Keep track of the presence of mutable fields. | |||
973 | if (Field->isMutable()) { | |||
974 | data().HasMutableFields = true; | |||
975 | data().NeedOverloadResolutionForCopyConstructor = true; | |||
976 | } | |||
977 | ||||
978 | // C++11 [class.union]p8, DR1460: | |||
979 | // If X is a union, a non-static data member of X that is not an anonymous | |||
980 | // union is a variant member of X. | |||
981 | if (isUnion() && !Field->isAnonymousStructOrUnion()) | |||
982 | data().HasVariantMembers = true; | |||
983 | ||||
984 | // C++0x [class]p9: | |||
985 | // A POD struct is a class that is both a trivial class and a | |||
986 | // standard-layout class, and has no non-static data members of type | |||
987 | // non-POD struct, non-POD union (or array of such types). | |||
988 | // | |||
989 | // Automatic Reference Counting: the presence of a member of Objective-C pointer type | |||
990 | // that does not explicitly have no lifetime makes the class a non-POD. | |||
991 | QualType T = Context.getBaseElementType(Field->getType()); | |||
992 | if (T->isObjCRetainableType() || T.isObjCGCStrong()) { | |||
993 | if (T.hasNonTrivialObjCLifetime()) { | |||
994 | // Objective-C Automatic Reference Counting: | |||
995 | // If a class has a non-static data member of Objective-C pointer | |||
996 | // type (or array thereof), it is a non-POD type and its | |||
997 | // default constructor (if any), copy constructor, move constructor, | |||
998 | // copy assignment operator, move assignment operator, and destructor are | |||
999 | // non-trivial. | |||
1000 | setHasObjectMember(true); | |||
1001 | struct DefinitionData &Data = data(); | |||
1002 | Data.PlainOldData = false; | |||
1003 | Data.HasTrivialSpecialMembers = 0; | |||
1004 | ||||
1005 | // __strong or __weak fields do not make special functions non-trivial | |||
1006 | // for the purpose of calls. | |||
1007 | Qualifiers::ObjCLifetime LT = T.getQualifiers().getObjCLifetime(); | |||
1008 | if (LT != Qualifiers::OCL_Strong && LT != Qualifiers::OCL_Weak) | |||
1009 | data().HasTrivialSpecialMembersForCall = 0; | |||
1010 | ||||
1011 | // Structs with __weak fields should never be passed directly. | |||
1012 | if (LT == Qualifiers::OCL_Weak) | |||
1013 | setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs); | |||
1014 | ||||
1015 | Data.HasIrrelevantDestructor = false; | |||
1016 | ||||
1017 | if (isUnion()) { | |||
1018 | data().DefaultedCopyConstructorIsDeleted = true; | |||
1019 | data().DefaultedMoveConstructorIsDeleted = true; | |||
1020 | data().DefaultedMoveAssignmentIsDeleted = true; | |||
1021 | data().DefaultedDestructorIsDeleted = true; | |||
1022 | data().NeedOverloadResolutionForCopyConstructor = true; | |||
1023 | data().NeedOverloadResolutionForMoveConstructor = true; | |||
1024 | data().NeedOverloadResolutionForMoveAssignment = true; | |||
1025 | data().NeedOverloadResolutionForDestructor = true; | |||
1026 | } | |||
1027 | } else if (!Context.getLangOpts().ObjCAutoRefCount) { | |||
1028 | setHasObjectMember(true); | |||
1029 | } | |||
1030 | } else if (!T.isCXX98PODType(Context)) | |||
1031 | data().PlainOldData = false; | |||
1032 | ||||
1033 | if (T->isReferenceType()) { | |||
1034 | if (!Field->hasInClassInitializer()) | |||
1035 | data().HasUninitializedReferenceMember = true; | |||
1036 | ||||
1037 | // C++0x [class]p7: | |||
1038 | // A standard-layout class is a class that: | |||
1039 | // -- has no non-static data members of type [...] reference, | |||
1040 | data().IsStandardLayout = false; | |||
1041 | data().IsCXX11StandardLayout = false; | |||
1042 | ||||
1043 | // C++1z [class.copy.ctor]p10: | |||
1044 | // A defaulted copy constructor for a class X is defined as deleted if X has: | |||
1045 | // -- a non-static data member of rvalue reference type | |||
1046 | if (T->isRValueReferenceType()) | |||
1047 | data().DefaultedCopyConstructorIsDeleted = true; | |||
1048 | } | |||
1049 | ||||
1050 | if (!Field->hasInClassInitializer() && !Field->isMutable()) { | |||
1051 | if (CXXRecordDecl *FieldType = T->getAsCXXRecordDecl()) { | |||
1052 | if (FieldType->hasDefinition() && !FieldType->allowConstDefaultInit()) | |||
1053 | data().HasUninitializedFields = true; | |||
1054 | } else { | |||
1055 | data().HasUninitializedFields = true; | |||
1056 | } | |||
1057 | } | |||
1058 | ||||
1059 | // Record if this field is the first non-literal or volatile field or base. | |||
1060 | if (!T->isLiteralType(Context) || T.isVolatileQualified()) | |||
1061 | data().HasNonLiteralTypeFieldsOrBases = true; | |||
1062 | ||||
1063 | if (Field->hasInClassInitializer() || | |||
1064 | (Field->isAnonymousStructOrUnion() && | |||
1065 | Field->getType()->getAsCXXRecordDecl()->hasInClassInitializer())) { | |||
1066 | data().HasInClassInitializer = true; | |||
1067 | ||||
1068 | // C++11 [class]p5: | |||
1069 | // A default constructor is trivial if [...] no non-static data member | |||
1070 | // of its class has a brace-or-equal-initializer. | |||
1071 | data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor; | |||
1072 | ||||
1073 | // C++11 [dcl.init.aggr]p1: | |||
1074 | // An aggregate is a [...] class with [...] no | |||
1075 | // brace-or-equal-initializers for non-static data members. | |||
1076 | // | |||
1077 | // This rule was removed in C++14. | |||
1078 | if (!getASTContext().getLangOpts().CPlusPlus14) | |||
1079 | data().Aggregate = false; | |||
1080 | ||||
1081 | // C++11 [class]p10: | |||
1082 | // A POD struct is [...] a trivial class. | |||
1083 | data().PlainOldData = false; | |||
1084 | } | |||
1085 | ||||
1086 | // C++11 [class.copy]p23: | |||
1087 | // A defaulted copy/move assignment operator for a class X is defined | |||
1088 | // as deleted if X has: | |||
1089 | // -- a non-static data member of reference type | |||
1090 | if (T->isReferenceType()) | |||
1091 | data().DefaultedMoveAssignmentIsDeleted = true; | |||
1092 | ||||
1093 | // Bitfields of length 0 are also zero-sized, but we already bailed out for | |||
1094 | // those because they are always unnamed. | |||
1095 | bool IsZeroSize = Field->isZeroSize(Context); | |||
1096 | ||||
1097 | if (const auto *RecordTy = T->getAs<RecordType>()) { | |||
1098 | auto *FieldRec = cast<CXXRecordDecl>(RecordTy->getDecl()); | |||
1099 | if (FieldRec->getDefinition()) { | |||
1100 | addedClassSubobject(FieldRec); | |||
1101 | ||||
1102 | // We may need to perform overload resolution to determine whether a | |||
1103 | // field can be moved if it's const or volatile qualified. | |||
1104 | if (T.getCVRQualifiers() & (Qualifiers::Const | Qualifiers::Volatile)) { | |||
1105 | // We need to care about 'const' for the copy constructor because an | |||
1106 | // implicit copy constructor might be declared with a non-const | |||
1107 | // parameter. | |||
1108 | data().NeedOverloadResolutionForCopyConstructor = true; | |||
1109 | data().NeedOverloadResolutionForMoveConstructor = true; | |||
1110 | data().NeedOverloadResolutionForMoveAssignment = true; | |||
1111 | } | |||
1112 | ||||
1113 | // C++11 [class.ctor]p5, C++11 [class.copy]p11: | |||
1114 | // A defaulted [special member] for a class X is defined as | |||
1115 | // deleted if: | |||
1116 | // -- X is a union-like class that has a variant member with a | |||
1117 | // non-trivial [corresponding special member] | |||
1118 | if (isUnion()) { | |||
1119 | if (FieldRec->hasNonTrivialCopyConstructor()) | |||
1120 | data().DefaultedCopyConstructorIsDeleted = true; | |||
1121 | if (FieldRec->hasNonTrivialMoveConstructor()) | |||
1122 | data().DefaultedMoveConstructorIsDeleted = true; | |||
1123 | if (FieldRec->hasNonTrivialMoveAssignment()) | |||
1124 | data().DefaultedMoveAssignmentIsDeleted = true; | |||
1125 | if (FieldRec->hasNonTrivialDestructor()) | |||
1126 | data().DefaultedDestructorIsDeleted = true; | |||
1127 | } | |||
1128 | ||||
1129 | // For an anonymous union member, our overload resolution will perform | |||
1130 | // overload resolution for its members. | |||
1131 | if (Field->isAnonymousStructOrUnion()) { | |||
1132 | data().NeedOverloadResolutionForCopyConstructor |= | |||
1133 | FieldRec->data().NeedOverloadResolutionForCopyConstructor; | |||
1134 | data().NeedOverloadResolutionForMoveConstructor |= | |||
1135 | FieldRec->data().NeedOverloadResolutionForMoveConstructor; | |||
1136 | data().NeedOverloadResolutionForMoveAssignment |= | |||
1137 | FieldRec->data().NeedOverloadResolutionForMoveAssignment; | |||
1138 | data().NeedOverloadResolutionForDestructor |= | |||
1139 | FieldRec->data().NeedOverloadResolutionForDestructor; | |||
1140 | } | |||
1141 | ||||
1142 | // C++0x [class.ctor]p5: | |||
1143 | // A default constructor is trivial [...] if: | |||
1144 | // -- for all the non-static data members of its class that are of | |||
1145 | // class type (or array thereof), each such class has a trivial | |||
1146 | // default constructor. | |||
1147 | if (!FieldRec->hasTrivialDefaultConstructor()) | |||
1148 | data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor; | |||
1149 | ||||
1150 | // C++0x [class.copy]p13: | |||
1151 | // A copy/move constructor for class X is trivial if [...] | |||
1152 | // [...] | |||
1153 | // -- for each non-static data member of X that is of class type (or | |||
1154 | // an array thereof), the constructor selected to copy/move that | |||
1155 | // member is trivial; | |||
1156 | if (!FieldRec->hasTrivialCopyConstructor()) | |||
1157 | data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor; | |||
1158 | ||||
1159 | if (!FieldRec->hasTrivialCopyConstructorForCall()) | |||
1160 | data().HasTrivialSpecialMembersForCall &= ~SMF_CopyConstructor; | |||
1161 | ||||
1162 | // If the field doesn't have a simple move constructor, we'll eagerly | |||
1163 | // declare the move constructor for this class and we'll decide whether | |||
1164 | // it's trivial then. | |||
1165 | if (!FieldRec->hasTrivialMoveConstructor()) | |||
1166 | data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor; | |||
1167 | ||||
1168 | if (!FieldRec->hasTrivialMoveConstructorForCall()) | |||
1169 | data().HasTrivialSpecialMembersForCall &= ~SMF_MoveConstructor; | |||
1170 | ||||
1171 | // C++0x [class.copy]p27: | |||
1172 | // A copy/move assignment operator for class X is trivial if [...] | |||
1173 | // [...] | |||
1174 | // -- for each non-static data member of X that is of class type (or | |||
1175 | // an array thereof), the assignment operator selected to | |||
1176 | // copy/move that member is trivial; | |||
1177 | if (!FieldRec->hasTrivialCopyAssignment()) | |||
1178 | data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment; | |||
1179 | // If the field doesn't have a simple move assignment, we'll eagerly | |||
1180 | // declare the move assignment for this class and we'll decide whether | |||
1181 | // it's trivial then. | |||
1182 | if (!FieldRec->hasTrivialMoveAssignment()) | |||
1183 | data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment; | |||
1184 | ||||
1185 | if (!FieldRec->hasTrivialDestructor()) | |||
1186 | data().HasTrivialSpecialMembers &= ~SMF_Destructor; | |||
1187 | if (!FieldRec->hasTrivialDestructorForCall()) | |||
1188 | data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor; | |||
1189 | if (!FieldRec->hasIrrelevantDestructor()) | |||
1190 | data().HasIrrelevantDestructor = false; | |||
1191 | if (FieldRec->hasObjectMember()) | |||
1192 | setHasObjectMember(true); | |||
1193 | if (FieldRec->hasVolatileMember()) | |||
1194 | setHasVolatileMember(true); | |||
1195 | if (FieldRec->getArgPassingRestrictions() == | |||
1196 | RecordDecl::APK_CanNeverPassInRegs) | |||
1197 | setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs); | |||
1198 | ||||
1199 | // C++0x [class]p7: | |||
1200 | // A standard-layout class is a class that: | |||
1201 | // -- has no non-static data members of type non-standard-layout | |||
1202 | // class (or array of such types) [...] | |||
1203 | if (!FieldRec->isStandardLayout()) | |||
1204 | data().IsStandardLayout = false; | |||
1205 | if (!FieldRec->isCXX11StandardLayout()) | |||
1206 | data().IsCXX11StandardLayout = false; | |||
1207 | ||||
1208 | // C++2a [class]p7: | |||
1209 | // A standard-layout class is a class that: | |||
1210 | // [...] | |||
1211 | // -- has no element of the set M(S) of types as a base class. | |||
1212 | if (data().IsStandardLayout && | |||
1213 | (isUnion() || IsFirstField || IsZeroSize) && | |||
1214 | hasSubobjectAtOffsetZeroOfEmptyBaseType(Context, FieldRec)) | |||
1215 | data().IsStandardLayout = false; | |||
1216 | ||||
1217 | // C++11 [class]p7: | |||
1218 | // A standard-layout class is a class that: | |||
1219 | // -- has no base classes of the same type as the first non-static | |||
1220 | // data member | |||
1221 | if (data().IsCXX11StandardLayout && IsFirstField) { | |||
1222 | // FIXME: We should check all base classes here, not just direct | |||
1223 | // base classes. | |||
1224 | for (const auto &BI : bases()) { | |||
1225 | if (Context.hasSameUnqualifiedType(BI.getType(), T)) { | |||
1226 | data().IsCXX11StandardLayout = false; | |||
1227 | break; | |||
1228 | } | |||
1229 | } | |||
1230 | } | |||
1231 | ||||
1232 | // Keep track of the presence of mutable fields. | |||
1233 | if (FieldRec->hasMutableFields()) { | |||
1234 | data().HasMutableFields = true; | |||
1235 | data().NeedOverloadResolutionForCopyConstructor = true; | |||
1236 | } | |||
1237 | ||||
1238 | // C++11 [class.copy]p13: | |||
1239 | // If the implicitly-defined constructor would satisfy the | |||
1240 | // requirements of a constexpr constructor, the implicitly-defined | |||
1241 | // constructor is constexpr. | |||
1242 | // C++11 [dcl.constexpr]p4: | |||
1243 | // -- every constructor involved in initializing non-static data | |||
1244 | // members [...] shall be a constexpr constructor | |||
1245 | if (!Field->hasInClassInitializer() && | |||
1246 | !FieldRec->hasConstexprDefaultConstructor() && !isUnion()) | |||
1247 | // The standard requires any in-class initializer to be a constant | |||
1248 | // expression. We consider this to be a defect. | |||
1249 | data().DefaultedDefaultConstructorIsConstexpr = false; | |||
1250 | ||||
1251 | // C++11 [class.copy]p8: | |||
1252 | // The implicitly-declared copy constructor for a class X will have | |||
1253 | // the form 'X::X(const X&)' if each potentially constructed subobject | |||
1254 | // of a class type M (or array thereof) has a copy constructor whose | |||
1255 | // first parameter is of type 'const M&' or 'const volatile M&'. | |||
1256 | if (!FieldRec->hasCopyConstructorWithConstParam()) | |||
1257 | data().ImplicitCopyConstructorCanHaveConstParamForNonVBase = false; | |||
1258 | ||||
1259 | // C++11 [class.copy]p18: | |||
1260 | // The implicitly-declared copy assignment oeprator for a class X will | |||
1261 | // have the form 'X& X::operator=(const X&)' if [...] for all the | |||
1262 | // non-static data members of X that are of a class type M (or array | |||
1263 | // thereof), each such class type has a copy assignment operator whose | |||
1264 | // parameter is of type 'const M&', 'const volatile M&' or 'M'. | |||
1265 | if (!FieldRec->hasCopyAssignmentWithConstParam()) | |||
1266 | data().ImplicitCopyAssignmentHasConstParam = false; | |||
1267 | ||||
1268 | if (FieldRec->hasUninitializedReferenceMember() && | |||
1269 | !Field->hasInClassInitializer()) | |||
1270 | data().HasUninitializedReferenceMember = true; | |||
1271 | ||||
1272 | // C++11 [class.union]p8, DR1460: | |||
1273 | // a non-static data member of an anonymous union that is a member of | |||
1274 | // X is also a variant member of X. | |||
1275 | if (FieldRec->hasVariantMembers() && | |||
1276 | Field->isAnonymousStructOrUnion()) | |||
1277 | data().HasVariantMembers = true; | |||
1278 | } | |||
1279 | } else { | |||
1280 | // Base element type of field is a non-class type. | |||
1281 | if (!T->isLiteralType(Context) || | |||
1282 | (!Field->hasInClassInitializer() && !isUnion() && | |||
1283 | !Context.getLangOpts().CPlusPlus2a)) | |||
1284 | data().DefaultedDefaultConstructorIsConstexpr = false; | |||
1285 | ||||
1286 | // C++11 [class.copy]p23: | |||
1287 | // A defaulted copy/move assignment operator for a class X is defined | |||
1288 | // as deleted if X has: | |||
1289 | // -- a non-static data member of const non-class type (or array | |||
1290 | // thereof) | |||
1291 | if (T.isConstQualified()) | |||
1292 | data().DefaultedMoveAssignmentIsDeleted = true; | |||
1293 | } | |||
1294 | ||||
1295 | // C++14 [meta.unary.prop]p4: | |||
1296 | // T is a class type [...] with [...] no non-static data members other | |||
1297 | // than subobjects of zero size | |||
1298 | if (data().Empty && !IsZeroSize) | |||
1299 | data().Empty = false; | |||
1300 | } | |||
1301 | ||||
1302 | // Handle using declarations of conversion functions. | |||
1303 | if (auto *Shadow = dyn_cast<UsingShadowDecl>(D)) { | |||
1304 | if (Shadow->getDeclName().getNameKind() | |||
1305 | == DeclarationName::CXXConversionFunctionName) { | |||
1306 | ASTContext &Ctx = getASTContext(); | |||
1307 | data().Conversions.get(Ctx).addDecl(Ctx, Shadow, Shadow->getAccess()); | |||
1308 | } | |||
1309 | } | |||
1310 | ||||
1311 | if (const auto *Using = dyn_cast<UsingDecl>(D)) { | |||
1312 | if (Using->getDeclName().getNameKind() == | |||
1313 | DeclarationName::CXXConstructorName) { | |||
1314 | data().HasInheritedConstructor = true; | |||
1315 | // C++1z [dcl.init.aggr]p1: | |||
1316 | // An aggregate is [...] a class [...] with no inherited constructors | |||
1317 | data().Aggregate = false; | |||
1318 | } | |||
1319 | ||||
1320 | if (Using->getDeclName().getCXXOverloadedOperator() == OO_Equal) | |||
1321 | data().HasInheritedAssignment = true; | |||
1322 | } | |||
1323 | } | |||
1324 | ||||
1325 | void CXXRecordDecl::finishedDefaultedOrDeletedMember(CXXMethodDecl *D) { | |||
1326 | assert(!D->isImplicit() && !D->isUserProvided())((!D->isImplicit() && !D->isUserProvided()) ? static_cast <void> (0) : __assert_fail ("!D->isImplicit() && !D->isUserProvided()" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1326, __PRETTY_FUNCTION__)); | |||
1327 | ||||
1328 | // The kind of special member this declaration is, if any. | |||
1329 | unsigned SMKind = 0; | |||
1330 | ||||
1331 | if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(D)) { | |||
1332 | if (Constructor->isDefaultConstructor()) { | |||
1333 | SMKind |= SMF_DefaultConstructor; | |||
1334 | if (Constructor->isConstexpr()) | |||
1335 | data().HasConstexprDefaultConstructor = true; | |||
1336 | } | |||
1337 | if (Constructor->isCopyConstructor()) | |||
1338 | SMKind |= SMF_CopyConstructor; | |||
1339 | else if (Constructor->isMoveConstructor()) | |||
1340 | SMKind |= SMF_MoveConstructor; | |||
1341 | else if (Constructor->isConstexpr()) | |||
1342 | // We may now know that the constructor is constexpr. | |||
1343 | data().HasConstexprNonCopyMoveConstructor = true; | |||
1344 | } else if (isa<CXXDestructorDecl>(D)) { | |||
1345 | SMKind |= SMF_Destructor; | |||
1346 | if (!D->isTrivial() || D->getAccess() != AS_public || D->isDeleted()) | |||
1347 | data().HasIrrelevantDestructor = false; | |||
1348 | } else if (D->isCopyAssignmentOperator()) | |||
1349 | SMKind |= SMF_CopyAssignment; | |||
1350 | else if (D->isMoveAssignmentOperator()) | |||
1351 | SMKind |= SMF_MoveAssignment; | |||
1352 | ||||
1353 | // Update which trivial / non-trivial special members we have. | |||
1354 | // addedMember will have skipped this step for this member. | |||
1355 | if (D->isTrivial()) | |||
1356 | data().HasTrivialSpecialMembers |= SMKind; | |||
1357 | else | |||
1358 | data().DeclaredNonTrivialSpecialMembers |= SMKind; | |||
1359 | } | |||
1360 | ||||
1361 | void CXXRecordDecl::setTrivialForCallFlags(CXXMethodDecl *D) { | |||
1362 | unsigned SMKind = 0; | |||
1363 | ||||
1364 | if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(D)) { | |||
1365 | if (Constructor->isCopyConstructor()) | |||
1366 | SMKind = SMF_CopyConstructor; | |||
1367 | else if (Constructor->isMoveConstructor()) | |||
1368 | SMKind = SMF_MoveConstructor; | |||
1369 | } else if (isa<CXXDestructorDecl>(D)) | |||
1370 | SMKind = SMF_Destructor; | |||
1371 | ||||
1372 | if (D->isTrivialForCall()) | |||
1373 | data().HasTrivialSpecialMembersForCall |= SMKind; | |||
1374 | else | |||
1375 | data().DeclaredNonTrivialSpecialMembersForCall |= SMKind; | |||
1376 | } | |||
1377 | ||||
1378 | bool CXXRecordDecl::isCLike() const { | |||
1379 | if (getTagKind() == TTK_Class || getTagKind() == TTK_Interface || | |||
1380 | !TemplateOrInstantiation.isNull()) | |||
1381 | return false; | |||
1382 | if (!hasDefinition()) | |||
1383 | return true; | |||
1384 | ||||
1385 | return isPOD() && data().HasOnlyCMembers; | |||
1386 | } | |||
1387 | ||||
1388 | bool CXXRecordDecl::isGenericLambda() const { | |||
1389 | if (!isLambda()) return false; | |||
1390 | return getLambdaData().IsGenericLambda; | |||
1391 | } | |||
1392 | ||||
1393 | #ifndef NDEBUG | |||
1394 | static bool allLookupResultsAreTheSame(const DeclContext::lookup_result &R) { | |||
1395 | for (auto *D : R) | |||
1396 | if (!declaresSameEntity(D, R.front())) | |||
1397 | return false; | |||
1398 | return true; | |||
1399 | } | |||
1400 | #endif | |||
1401 | ||||
1402 | static NamedDecl* getLambdaCallOperatorHelper(const CXXRecordDecl &RD) { | |||
1403 | if (!RD.isLambda()) return nullptr; | |||
1404 | DeclarationName Name = | |||
1405 | RD.getASTContext().DeclarationNames.getCXXOperatorName(OO_Call); | |||
1406 | DeclContext::lookup_result Calls = RD.lookup(Name); | |||
1407 | ||||
1408 | assert(!Calls.empty() && "Missing lambda call operator!")((!Calls.empty() && "Missing lambda call operator!") ? static_cast<void> (0) : __assert_fail ("!Calls.empty() && \"Missing lambda call operator!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1408, __PRETTY_FUNCTION__)); | |||
1409 | assert(allLookupResultsAreTheSame(Calls) &&((allLookupResultsAreTheSame(Calls) && "More than one lambda call operator!" ) ? static_cast<void> (0) : __assert_fail ("allLookupResultsAreTheSame(Calls) && \"More than one lambda call operator!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1410, __PRETTY_FUNCTION__)) | |||
1410 | "More than one lambda call operator!")((allLookupResultsAreTheSame(Calls) && "More than one lambda call operator!" ) ? static_cast<void> (0) : __assert_fail ("allLookupResultsAreTheSame(Calls) && \"More than one lambda call operator!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1410, __PRETTY_FUNCTION__)); | |||
1411 | return Calls.front(); | |||
1412 | } | |||
1413 | ||||
1414 | FunctionTemplateDecl* CXXRecordDecl::getDependentLambdaCallOperator() const { | |||
1415 | NamedDecl *CallOp = getLambdaCallOperatorHelper(*this); | |||
1416 | return dyn_cast_or_null<FunctionTemplateDecl>(CallOp); | |||
1417 | } | |||
1418 | ||||
1419 | CXXMethodDecl *CXXRecordDecl::getLambdaCallOperator() const { | |||
1420 | NamedDecl *CallOp = getLambdaCallOperatorHelper(*this); | |||
1421 | ||||
1422 | if (CallOp == nullptr) | |||
1423 | return nullptr; | |||
1424 | ||||
1425 | if (const auto *CallOpTmpl = dyn_cast<FunctionTemplateDecl>(CallOp)) | |||
1426 | return cast<CXXMethodDecl>(CallOpTmpl->getTemplatedDecl()); | |||
1427 | ||||
1428 | return cast<CXXMethodDecl>(CallOp); | |||
1429 | } | |||
1430 | ||||
1431 | CXXMethodDecl* CXXRecordDecl::getLambdaStaticInvoker() const { | |||
1432 | if (!isLambda()) return nullptr; | |||
1433 | DeclarationName Name = | |||
1434 | &getASTContext().Idents.get(getLambdaStaticInvokerName()); | |||
1435 | DeclContext::lookup_result Invoker = lookup(Name); | |||
1436 | if (Invoker.empty()) return nullptr; | |||
1437 | assert(allLookupResultsAreTheSame(Invoker) &&((allLookupResultsAreTheSame(Invoker) && "More than one static invoker operator!" ) ? static_cast<void> (0) : __assert_fail ("allLookupResultsAreTheSame(Invoker) && \"More than one static invoker operator!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1438, __PRETTY_FUNCTION__)) | |||
1438 | "More than one static invoker operator!")((allLookupResultsAreTheSame(Invoker) && "More than one static invoker operator!" ) ? static_cast<void> (0) : __assert_fail ("allLookupResultsAreTheSame(Invoker) && \"More than one static invoker operator!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1438, __PRETTY_FUNCTION__)); | |||
1439 | NamedDecl *InvokerFun = Invoker.front(); | |||
1440 | if (const auto *InvokerTemplate = dyn_cast<FunctionTemplateDecl>(InvokerFun)) | |||
1441 | return cast<CXXMethodDecl>(InvokerTemplate->getTemplatedDecl()); | |||
1442 | ||||
1443 | return cast<CXXMethodDecl>(InvokerFun); | |||
1444 | } | |||
1445 | ||||
1446 | void CXXRecordDecl::getCaptureFields( | |||
1447 | llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures, | |||
1448 | FieldDecl *&ThisCapture) const { | |||
1449 | Captures.clear(); | |||
1450 | ThisCapture = nullptr; | |||
1451 | ||||
1452 | LambdaDefinitionData &Lambda = getLambdaData(); | |||
1453 | RecordDecl::field_iterator Field = field_begin(); | |||
1454 | for (const LambdaCapture *C = Lambda.Captures, *CEnd = C + Lambda.NumCaptures; | |||
1455 | C != CEnd; ++C, ++Field) { | |||
1456 | if (C->capturesThis()) | |||
1457 | ThisCapture = *Field; | |||
1458 | else if (C->capturesVariable()) | |||
1459 | Captures[C->getCapturedVar()] = *Field; | |||
1460 | } | |||
1461 | assert(Field == field_end())((Field == field_end()) ? static_cast<void> (0) : __assert_fail ("Field == field_end()", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1461, __PRETTY_FUNCTION__)); | |||
1462 | } | |||
1463 | ||||
1464 | TemplateParameterList * | |||
1465 | CXXRecordDecl::getGenericLambdaTemplateParameterList() const { | |||
1466 | if (!isGenericLambda()) return nullptr; | |||
1467 | CXXMethodDecl *CallOp = getLambdaCallOperator(); | |||
1468 | if (FunctionTemplateDecl *Tmpl = CallOp->getDescribedFunctionTemplate()) | |||
1469 | return Tmpl->getTemplateParameters(); | |||
1470 | return nullptr; | |||
1471 | } | |||
1472 | ||||
1473 | ArrayRef<NamedDecl *> | |||
1474 | CXXRecordDecl::getLambdaExplicitTemplateParameters() const { | |||
1475 | TemplateParameterList *List = getGenericLambdaTemplateParameterList(); | |||
1476 | if (!List) | |||
1477 | return {}; | |||
1478 | ||||
1479 | assert(std::is_partitioned(List->begin(), List->end(),((std::is_partitioned(List->begin(), List->end(), [](const NamedDecl *D) { return !D->isImplicit(); }) && "Explicit template params should be ordered before implicit ones" ) ? static_cast<void> (0) : __assert_fail ("std::is_partitioned(List->begin(), List->end(), [](const NamedDecl *D) { return !D->isImplicit(); }) && \"Explicit template params should be ordered before implicit ones\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1481, __PRETTY_FUNCTION__)) | |||
1480 | [](const NamedDecl *D) { return !D->isImplicit(); })((std::is_partitioned(List->begin(), List->end(), [](const NamedDecl *D) { return !D->isImplicit(); }) && "Explicit template params should be ordered before implicit ones" ) ? static_cast<void> (0) : __assert_fail ("std::is_partitioned(List->begin(), List->end(), [](const NamedDecl *D) { return !D->isImplicit(); }) && \"Explicit template params should be ordered before implicit ones\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1481, __PRETTY_FUNCTION__)) | |||
1481 | && "Explicit template params should be ordered before implicit ones")((std::is_partitioned(List->begin(), List->end(), [](const NamedDecl *D) { return !D->isImplicit(); }) && "Explicit template params should be ordered before implicit ones" ) ? static_cast<void> (0) : __assert_fail ("std::is_partitioned(List->begin(), List->end(), [](const NamedDecl *D) { return !D->isImplicit(); }) && \"Explicit template params should be ordered before implicit ones\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1481, __PRETTY_FUNCTION__)); | |||
1482 | ||||
1483 | const auto ExplicitEnd = llvm::partition_point( | |||
1484 | *List, [](const NamedDecl *D) { return !D->isImplicit(); }); | |||
1485 | return llvm::makeArrayRef(List->begin(), ExplicitEnd); | |||
1486 | } | |||
1487 | ||||
1488 | Decl *CXXRecordDecl::getLambdaContextDecl() const { | |||
1489 | assert(isLambda() && "Not a lambda closure type!")((isLambda() && "Not a lambda closure type!") ? static_cast <void> (0) : __assert_fail ("isLambda() && \"Not a lambda closure type!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1489, __PRETTY_FUNCTION__)); | |||
1490 | ExternalASTSource *Source = getParentASTContext().getExternalSource(); | |||
1491 | return getLambdaData().ContextDecl.get(Source); | |||
1492 | } | |||
1493 | ||||
1494 | static CanQualType GetConversionType(ASTContext &Context, NamedDecl *Conv) { | |||
1495 | QualType T = | |||
1496 | cast<CXXConversionDecl>(Conv->getUnderlyingDecl()->getAsFunction()) | |||
1497 | ->getConversionType(); | |||
1498 | return Context.getCanonicalType(T); | |||
1499 | } | |||
1500 | ||||
1501 | /// Collect the visible conversions of a base class. | |||
1502 | /// | |||
1503 | /// \param Record a base class of the class we're considering | |||
1504 | /// \param InVirtual whether this base class is a virtual base (or a base | |||
1505 | /// of a virtual base) | |||
1506 | /// \param Access the access along the inheritance path to this base | |||
1507 | /// \param ParentHiddenTypes the conversions provided by the inheritors | |||
1508 | /// of this base | |||
1509 | /// \param Output the set to which to add conversions from non-virtual bases | |||
1510 | /// \param VOutput the set to which to add conversions from virtual bases | |||
1511 | /// \param HiddenVBaseCs the set of conversions which were hidden in a | |||
1512 | /// virtual base along some inheritance path | |||
1513 | static void CollectVisibleConversions(ASTContext &Context, | |||
1514 | CXXRecordDecl *Record, | |||
1515 | bool InVirtual, | |||
1516 | AccessSpecifier Access, | |||
1517 | const llvm::SmallPtrSet<CanQualType, 8> &ParentHiddenTypes, | |||
1518 | ASTUnresolvedSet &Output, | |||
1519 | UnresolvedSetImpl &VOutput, | |||
1520 | llvm::SmallPtrSet<NamedDecl*, 8> &HiddenVBaseCs) { | |||
1521 | // The set of types which have conversions in this class or its | |||
1522 | // subclasses. As an optimization, we don't copy the derived set | |||
1523 | // unless it might change. | |||
1524 | const llvm::SmallPtrSet<CanQualType, 8> *HiddenTypes = &ParentHiddenTypes; | |||
1525 | llvm::SmallPtrSet<CanQualType, 8> HiddenTypesBuffer; | |||
1526 | ||||
1527 | // Collect the direct conversions and figure out which conversions | |||
1528 | // will be hidden in the subclasses. | |||
1529 | CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin(); | |||
1530 | CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end(); | |||
1531 | if (ConvI != ConvE) { | |||
1532 | HiddenTypesBuffer = ParentHiddenTypes; | |||
1533 | HiddenTypes = &HiddenTypesBuffer; | |||
1534 | ||||
1535 | for (CXXRecordDecl::conversion_iterator I = ConvI; I != ConvE; ++I) { | |||
1536 | CanQualType ConvType(GetConversionType(Context, I.getDecl())); | |||
1537 | bool Hidden = ParentHiddenTypes.count(ConvType); | |||
1538 | if (!Hidden) | |||
1539 | HiddenTypesBuffer.insert(ConvType); | |||
1540 | ||||
1541 | // If this conversion is hidden and we're in a virtual base, | |||
1542 | // remember that it's hidden along some inheritance path. | |||
1543 | if (Hidden && InVirtual) | |||
1544 | HiddenVBaseCs.insert(cast<NamedDecl>(I.getDecl()->getCanonicalDecl())); | |||
1545 | ||||
1546 | // If this conversion isn't hidden, add it to the appropriate output. | |||
1547 | else if (!Hidden) { | |||
1548 | AccessSpecifier IAccess | |||
1549 | = CXXRecordDecl::MergeAccess(Access, I.getAccess()); | |||
1550 | ||||
1551 | if (InVirtual) | |||
1552 | VOutput.addDecl(I.getDecl(), IAccess); | |||
1553 | else | |||
1554 | Output.addDecl(Context, I.getDecl(), IAccess); | |||
1555 | } | |||
1556 | } | |||
1557 | } | |||
1558 | ||||
1559 | // Collect information recursively from any base classes. | |||
1560 | for (const auto &I : Record->bases()) { | |||
1561 | const RecordType *RT = I.getType()->getAs<RecordType>(); | |||
1562 | if (!RT) continue; | |||
1563 | ||||
1564 | AccessSpecifier BaseAccess | |||
1565 | = CXXRecordDecl::MergeAccess(Access, I.getAccessSpecifier()); | |||
1566 | bool BaseInVirtual = InVirtual || I.isVirtual(); | |||
1567 | ||||
1568 | auto *Base = cast<CXXRecordDecl>(RT->getDecl()); | |||
1569 | CollectVisibleConversions(Context, Base, BaseInVirtual, BaseAccess, | |||
1570 | *HiddenTypes, Output, VOutput, HiddenVBaseCs); | |||
1571 | } | |||
1572 | } | |||
1573 | ||||
1574 | /// Collect the visible conversions of a class. | |||
1575 | /// | |||
1576 | /// This would be extremely straightforward if it weren't for virtual | |||
1577 | /// bases. It might be worth special-casing that, really. | |||
1578 | static void CollectVisibleConversions(ASTContext &Context, | |||
1579 | CXXRecordDecl *Record, | |||
1580 | ASTUnresolvedSet &Output) { | |||
1581 | // The collection of all conversions in virtual bases that we've | |||
1582 | // found. These will be added to the output as long as they don't | |||
1583 | // appear in the hidden-conversions set. | |||
1584 | UnresolvedSet<8> VBaseCs; | |||
1585 | ||||
1586 | // The set of conversions in virtual bases that we've determined to | |||
1587 | // be hidden. | |||
1588 | llvm::SmallPtrSet<NamedDecl*, 8> HiddenVBaseCs; | |||
1589 | ||||
1590 | // The set of types hidden by classes derived from this one. | |||
1591 | llvm::SmallPtrSet<CanQualType, 8> HiddenTypes; | |||
1592 | ||||
1593 | // Go ahead and collect the direct conversions and add them to the | |||
1594 | // hidden-types set. | |||
1595 | CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin(); | |||
1596 | CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end(); | |||
1597 | Output.append(Context, ConvI, ConvE); | |||
1598 | for (; ConvI != ConvE; ++ConvI) | |||
1599 | HiddenTypes.insert(GetConversionType(Context, ConvI.getDecl())); | |||
1600 | ||||
1601 | // Recursively collect conversions from base classes. | |||
1602 | for (const auto &I : Record->bases()) { | |||
1603 | const RecordType *RT = I.getType()->getAs<RecordType>(); | |||
1604 | if (!RT) continue; | |||
1605 | ||||
1606 | CollectVisibleConversions(Context, cast<CXXRecordDecl>(RT->getDecl()), | |||
1607 | I.isVirtual(), I.getAccessSpecifier(), | |||
1608 | HiddenTypes, Output, VBaseCs, HiddenVBaseCs); | |||
1609 | } | |||
1610 | ||||
1611 | // Add any unhidden conversions provided by virtual bases. | |||
1612 | for (UnresolvedSetIterator I = VBaseCs.begin(), E = VBaseCs.end(); | |||
1613 | I != E; ++I) { | |||
1614 | if (!HiddenVBaseCs.count(cast<NamedDecl>(I.getDecl()->getCanonicalDecl()))) | |||
1615 | Output.addDecl(Context, I.getDecl(), I.getAccess()); | |||
1616 | } | |||
1617 | } | |||
1618 | ||||
1619 | /// getVisibleConversionFunctions - get all conversion functions visible | |||
1620 | /// in current class; including conversion function templates. | |||
1621 | llvm::iterator_range<CXXRecordDecl::conversion_iterator> | |||
1622 | CXXRecordDecl::getVisibleConversionFunctions() { | |||
1623 | ASTContext &Ctx = getASTContext(); | |||
1624 | ||||
1625 | ASTUnresolvedSet *Set; | |||
1626 | if (bases_begin() == bases_end()) { | |||
1627 | // If root class, all conversions are visible. | |||
1628 | Set = &data().Conversions.get(Ctx); | |||
1629 | } else { | |||
1630 | Set = &data().VisibleConversions.get(Ctx); | |||
1631 | // If visible conversion list is not evaluated, evaluate it. | |||
1632 | if (!data().ComputedVisibleConversions) { | |||
1633 | CollectVisibleConversions(Ctx, this, *Set); | |||
1634 | data().ComputedVisibleConversions = true; | |||
1635 | } | |||
1636 | } | |||
1637 | return llvm::make_range(Set->begin(), Set->end()); | |||
1638 | } | |||
1639 | ||||
1640 | void CXXRecordDecl::removeConversion(const NamedDecl *ConvDecl) { | |||
1641 | // This operation is O(N) but extremely rare. Sema only uses it to | |||
1642 | // remove UsingShadowDecls in a class that were followed by a direct | |||
1643 | // declaration, e.g.: | |||
1644 | // class A : B { | |||
1645 | // using B::operator int; | |||
1646 | // operator int(); | |||
1647 | // }; | |||
1648 | // This is uncommon by itself and even more uncommon in conjunction | |||
1649 | // with sufficiently large numbers of directly-declared conversions | |||
1650 | // that asymptotic behavior matters. | |||
1651 | ||||
1652 | ASTUnresolvedSet &Convs = data().Conversions.get(getASTContext()); | |||
1653 | for (unsigned I = 0, E = Convs.size(); I != E; ++I) { | |||
1654 | if (Convs[I].getDecl() == ConvDecl) { | |||
1655 | Convs.erase(I); | |||
1656 | assert(llvm::find(Convs, ConvDecl) == Convs.end() &&((llvm::find(Convs, ConvDecl) == Convs.end() && "conversion was found multiple times in unresolved set" ) ? static_cast<void> (0) : __assert_fail ("llvm::find(Convs, ConvDecl) == Convs.end() && \"conversion was found multiple times in unresolved set\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1657, __PRETTY_FUNCTION__)) | |||
1657 | "conversion was found multiple times in unresolved set")((llvm::find(Convs, ConvDecl) == Convs.end() && "conversion was found multiple times in unresolved set" ) ? static_cast<void> (0) : __assert_fail ("llvm::find(Convs, ConvDecl) == Convs.end() && \"conversion was found multiple times in unresolved set\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1657, __PRETTY_FUNCTION__)); | |||
1658 | return; | |||
1659 | } | |||
1660 | } | |||
1661 | ||||
1662 | llvm_unreachable("conversion not found in set!")::llvm::llvm_unreachable_internal("conversion not found in set!" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1662); | |||
1663 | } | |||
1664 | ||||
1665 | CXXRecordDecl *CXXRecordDecl::getInstantiatedFromMemberClass() const { | |||
1666 | if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) | |||
1667 | return cast<CXXRecordDecl>(MSInfo->getInstantiatedFrom()); | |||
1668 | ||||
1669 | return nullptr; | |||
1670 | } | |||
1671 | ||||
1672 | MemberSpecializationInfo *CXXRecordDecl::getMemberSpecializationInfo() const { | |||
1673 | return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>(); | |||
1674 | } | |||
1675 | ||||
1676 | void | |||
1677 | CXXRecordDecl::setInstantiationOfMemberClass(CXXRecordDecl *RD, | |||
1678 | TemplateSpecializationKind TSK) { | |||
1679 | assert(TemplateOrInstantiation.isNull() &&((TemplateOrInstantiation.isNull() && "Previous template or instantiation?" ) ? static_cast<void> (0) : __assert_fail ("TemplateOrInstantiation.isNull() && \"Previous template or instantiation?\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1680, __PRETTY_FUNCTION__)) | |||
1680 | "Previous template or instantiation?")((TemplateOrInstantiation.isNull() && "Previous template or instantiation?" ) ? static_cast<void> (0) : __assert_fail ("TemplateOrInstantiation.isNull() && \"Previous template or instantiation?\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1680, __PRETTY_FUNCTION__)); | |||
1681 | assert(!isa<ClassTemplatePartialSpecializationDecl>(this))((!isa<ClassTemplatePartialSpecializationDecl>(this)) ? static_cast<void> (0) : __assert_fail ("!isa<ClassTemplatePartialSpecializationDecl>(this)" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1681, __PRETTY_FUNCTION__)); | |||
1682 | TemplateOrInstantiation | |||
1683 | = new (getASTContext()) MemberSpecializationInfo(RD, TSK); | |||
1684 | } | |||
1685 | ||||
1686 | ClassTemplateDecl *CXXRecordDecl::getDescribedClassTemplate() const { | |||
1687 | return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl *>(); | |||
1688 | } | |||
1689 | ||||
1690 | void CXXRecordDecl::setDescribedClassTemplate(ClassTemplateDecl *Template) { | |||
1691 | TemplateOrInstantiation = Template; | |||
1692 | } | |||
1693 | ||||
1694 | TemplateSpecializationKind CXXRecordDecl::getTemplateSpecializationKind() const{ | |||
1695 | if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(this)) | |||
1696 | return Spec->getSpecializationKind(); | |||
1697 | ||||
1698 | if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) | |||
1699 | return MSInfo->getTemplateSpecializationKind(); | |||
1700 | ||||
1701 | return TSK_Undeclared; | |||
1702 | } | |||
1703 | ||||
1704 | void | |||
1705 | CXXRecordDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK) { | |||
1706 | if (auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(this)) { | |||
1707 | Spec->setSpecializationKind(TSK); | |||
1708 | return; | |||
1709 | } | |||
1710 | ||||
1711 | if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) { | |||
1712 | MSInfo->setTemplateSpecializationKind(TSK); | |||
1713 | return; | |||
1714 | } | |||
1715 | ||||
1716 | llvm_unreachable("Not a class template or member class specialization")::llvm::llvm_unreachable_internal("Not a class template or member class specialization" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1716); | |||
1717 | } | |||
1718 | ||||
1719 | const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const { | |||
1720 | auto GetDefinitionOrSelf = | |||
1721 | [](const CXXRecordDecl *D) -> const CXXRecordDecl * { | |||
1722 | if (auto *Def = D->getDefinition()) | |||
1723 | return Def; | |||
1724 | return D; | |||
1725 | }; | |||
1726 | ||||
1727 | // If it's a class template specialization, find the template or partial | |||
1728 | // specialization from which it was instantiated. | |||
1729 | if (auto *TD = dyn_cast<ClassTemplateSpecializationDecl>(this)) { | |||
1730 | auto From = TD->getInstantiatedFrom(); | |||
1731 | if (auto *CTD = From.dyn_cast<ClassTemplateDecl *>()) { | |||
1732 | while (auto *NewCTD = CTD->getInstantiatedFromMemberTemplate()) { | |||
1733 | if (NewCTD->isMemberSpecialization()) | |||
1734 | break; | |||
1735 | CTD = NewCTD; | |||
1736 | } | |||
1737 | return GetDefinitionOrSelf(CTD->getTemplatedDecl()); | |||
1738 | } | |||
1739 | if (auto *CTPSD = | |||
1740 | From.dyn_cast<ClassTemplatePartialSpecializationDecl *>()) { | |||
1741 | while (auto *NewCTPSD = CTPSD->getInstantiatedFromMember()) { | |||
1742 | if (NewCTPSD->isMemberSpecialization()) | |||
1743 | break; | |||
1744 | CTPSD = NewCTPSD; | |||
1745 | } | |||
1746 | return GetDefinitionOrSelf(CTPSD); | |||
1747 | } | |||
1748 | } | |||
1749 | ||||
1750 | if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) { | |||
1751 | if (isTemplateInstantiation(MSInfo->getTemplateSpecializationKind())) { | |||
1752 | const CXXRecordDecl *RD = this; | |||
1753 | while (auto *NewRD = RD->getInstantiatedFromMemberClass()) | |||
1754 | RD = NewRD; | |||
1755 | return GetDefinitionOrSelf(RD); | |||
1756 | } | |||
1757 | } | |||
1758 | ||||
1759 | assert(!isTemplateInstantiation(this->getTemplateSpecializationKind()) &&((!isTemplateInstantiation(this->getTemplateSpecializationKind ()) && "couldn't find pattern for class template instantiation" ) ? static_cast<void> (0) : __assert_fail ("!isTemplateInstantiation(this->getTemplateSpecializationKind()) && \"couldn't find pattern for class template instantiation\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1760, __PRETTY_FUNCTION__)) | |||
1760 | "couldn't find pattern for class template instantiation")((!isTemplateInstantiation(this->getTemplateSpecializationKind ()) && "couldn't find pattern for class template instantiation" ) ? static_cast<void> (0) : __assert_fail ("!isTemplateInstantiation(this->getTemplateSpecializationKind()) && \"couldn't find pattern for class template instantiation\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1760, __PRETTY_FUNCTION__)); | |||
1761 | return nullptr; | |||
1762 | } | |||
1763 | ||||
1764 | CXXDestructorDecl *CXXRecordDecl::getDestructor() const { | |||
1765 | ASTContext &Context = getASTContext(); | |||
1766 | QualType ClassType = Context.getTypeDeclType(this); | |||
1767 | ||||
1768 | DeclarationName Name | |||
1769 | = Context.DeclarationNames.getCXXDestructorName( | |||
1770 | Context.getCanonicalType(ClassType)); | |||
1771 | ||||
1772 | DeclContext::lookup_result R = lookup(Name); | |||
1773 | ||||
1774 | return R.empty() ? nullptr : dyn_cast<CXXDestructorDecl>(R.front()); | |||
1775 | } | |||
1776 | ||||
1777 | bool CXXRecordDecl::isAnyDestructorNoReturn() const { | |||
1778 | // Destructor is noreturn. | |||
1779 | if (const CXXDestructorDecl *Destructor = getDestructor()) | |||
1780 | if (Destructor->isNoReturn()) | |||
1781 | return true; | |||
1782 | ||||
1783 | // Check base classes destructor for noreturn. | |||
1784 | for (const auto &Base : bases()) | |||
1785 | if (const CXXRecordDecl *RD = Base.getType()->getAsCXXRecordDecl()) | |||
1786 | if (RD->isAnyDestructorNoReturn()) | |||
1787 | return true; | |||
1788 | ||||
1789 | // Check fields for noreturn. | |||
1790 | for (const auto *Field : fields()) | |||
1791 | if (const CXXRecordDecl *RD = | |||
1792 | Field->getType()->getBaseElementTypeUnsafe()->getAsCXXRecordDecl()) | |||
1793 | if (RD->isAnyDestructorNoReturn()) | |||
1794 | return true; | |||
1795 | ||||
1796 | // All destructors are not noreturn. | |||
1797 | return false; | |||
1798 | } | |||
1799 | ||||
1800 | static bool isDeclContextInNamespace(const DeclContext *DC) { | |||
1801 | while (!DC->isTranslationUnit()) { | |||
1802 | if (DC->isNamespace()) | |||
1803 | return true; | |||
1804 | DC = DC->getParent(); | |||
1805 | } | |||
1806 | return false; | |||
1807 | } | |||
1808 | ||||
1809 | bool CXXRecordDecl::isInterfaceLike() const { | |||
1810 | assert(hasDefinition() && "checking for interface-like without a definition")((hasDefinition() && "checking for interface-like without a definition" ) ? static_cast<void> (0) : __assert_fail ("hasDefinition() && \"checking for interface-like without a definition\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1810, __PRETTY_FUNCTION__)); | |||
1811 | // All __interfaces are inheritently interface-like. | |||
1812 | if (isInterface()) | |||
1813 | return true; | |||
1814 | ||||
1815 | // Interface-like types cannot have a user declared constructor, destructor, | |||
1816 | // friends, VBases, conversion functions, or fields. Additionally, lambdas | |||
1817 | // cannot be interface types. | |||
1818 | if (isLambda() || hasUserDeclaredConstructor() || | |||
1819 | hasUserDeclaredDestructor() || !field_empty() || hasFriends() || | |||
1820 | getNumVBases() > 0 || conversion_end() - conversion_begin() > 0) | |||
1821 | return false; | |||
1822 | ||||
1823 | // No interface-like type can have a method with a definition. | |||
1824 | for (const auto *const Method : methods()) | |||
1825 | if (Method->isDefined() && !Method->isImplicit()) | |||
1826 | return false; | |||
1827 | ||||
1828 | // Check "Special" types. | |||
1829 | const auto *Uuid = getAttr<UuidAttr>(); | |||
1830 | // MS SDK declares IUnknown/IDispatch both in the root of a TU, or in an | |||
1831 | // extern C++ block directly in the TU. These are only valid if in one | |||
1832 | // of these two situations. | |||
1833 | if (Uuid && isStruct() && !getDeclContext()->isExternCContext() && | |||
1834 | !isDeclContextInNamespace(getDeclContext()) && | |||
1835 | ((getName() == "IUnknown" && | |||
1836 | Uuid->getGuid() == "00000000-0000-0000-C000-000000000046") || | |||
1837 | (getName() == "IDispatch" && | |||
1838 | Uuid->getGuid() == "00020400-0000-0000-C000-000000000046"))) { | |||
1839 | if (getNumBases() > 0) | |||
1840 | return false; | |||
1841 | return true; | |||
1842 | } | |||
1843 | ||||
1844 | // FIXME: Any access specifiers is supposed to make this no longer interface | |||
1845 | // like. | |||
1846 | ||||
1847 | // If this isn't a 'special' type, it must have a single interface-like base. | |||
1848 | if (getNumBases() != 1) | |||
1849 | return false; | |||
1850 | ||||
1851 | const auto BaseSpec = *bases_begin(); | |||
1852 | if (BaseSpec.isVirtual() || BaseSpec.getAccessSpecifier() != AS_public) | |||
1853 | return false; | |||
1854 | const auto *Base = BaseSpec.getType()->getAsCXXRecordDecl(); | |||
1855 | if (Base->isInterface() || !Base->isInterfaceLike()) | |||
1856 | return false; | |||
1857 | return true; | |||
1858 | } | |||
1859 | ||||
1860 | void CXXRecordDecl::completeDefinition() { | |||
1861 | completeDefinition(nullptr); | |||
1862 | } | |||
1863 | ||||
1864 | void CXXRecordDecl::completeDefinition(CXXFinalOverriderMap *FinalOverriders) { | |||
1865 | RecordDecl::completeDefinition(); | |||
1866 | ||||
1867 | // If the class may be abstract (but hasn't been marked as such), check for | |||
1868 | // any pure final overriders. | |||
1869 | if (mayBeAbstract()) { | |||
1870 | CXXFinalOverriderMap MyFinalOverriders; | |||
1871 | if (!FinalOverriders) { | |||
1872 | getFinalOverriders(MyFinalOverriders); | |||
1873 | FinalOverriders = &MyFinalOverriders; | |||
1874 | } | |||
1875 | ||||
1876 | bool Done = false; | |||
1877 | for (CXXFinalOverriderMap::iterator M = FinalOverriders->begin(), | |||
1878 | MEnd = FinalOverriders->end(); | |||
1879 | M != MEnd && !Done; ++M) { | |||
1880 | for (OverridingMethods::iterator SO = M->second.begin(), | |||
1881 | SOEnd = M->second.end(); | |||
1882 | SO != SOEnd && !Done; ++SO) { | |||
1883 | assert(SO->second.size() > 0 &&((SO->second.size() > 0 && "All virtual functions have overriding virtual functions" ) ? static_cast<void> (0) : __assert_fail ("SO->second.size() > 0 && \"All virtual functions have overriding virtual functions\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1884, __PRETTY_FUNCTION__)) | |||
1884 | "All virtual functions have overriding virtual functions")((SO->second.size() > 0 && "All virtual functions have overriding virtual functions" ) ? static_cast<void> (0) : __assert_fail ("SO->second.size() > 0 && \"All virtual functions have overriding virtual functions\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 1884, __PRETTY_FUNCTION__)); | |||
1885 | ||||
1886 | // C++ [class.abstract]p4: | |||
1887 | // A class is abstract if it contains or inherits at least one | |||
1888 | // pure virtual function for which the final overrider is pure | |||
1889 | // virtual. | |||
1890 | if (SO->second.front().Method->isPure()) { | |||
1891 | data().Abstract = true; | |||
1892 | Done = true; | |||
1893 | break; | |||
1894 | } | |||
1895 | } | |||
1896 | } | |||
1897 | } | |||
1898 | ||||
1899 | // Set access bits correctly on the directly-declared conversions. | |||
1900 | for (conversion_iterator I = conversion_begin(), E = conversion_end(); | |||
1901 | I != E; ++I) | |||
1902 | I.setAccess((*I)->getAccess()); | |||
1903 | } | |||
1904 | ||||
1905 | bool CXXRecordDecl::mayBeAbstract() const { | |||
1906 | if (data().Abstract || isInvalidDecl() || !data().Polymorphic || | |||
1907 | isDependentContext()) | |||
1908 | return false; | |||
1909 | ||||
1910 | for (const auto &B : bases()) { | |||
1911 | const auto *BaseDecl = | |||
1912 | cast<CXXRecordDecl>(B.getType()->getAs<RecordType>()->getDecl()); | |||
1913 | if (BaseDecl->isAbstract()) | |||
1914 | return true; | |||
1915 | } | |||
1916 | ||||
1917 | return false; | |||
1918 | } | |||
1919 | ||||
1920 | void CXXDeductionGuideDecl::anchor() {} | |||
1921 | ||||
1922 | bool ExplicitSpecifier::isEquivalent(const ExplicitSpecifier Other) const { | |||
1923 | if ((getKind() != Other.getKind() || | |||
1924 | getKind() == ExplicitSpecKind::Unresolved)) { | |||
1925 | if (getKind() == ExplicitSpecKind::Unresolved && | |||
1926 | Other.getKind() == ExplicitSpecKind::Unresolved) { | |||
1927 | ODRHash SelfHash, OtherHash; | |||
1928 | SelfHash.AddStmt(getExpr()); | |||
1929 | OtherHash.AddStmt(Other.getExpr()); | |||
1930 | return SelfHash.CalculateHash() == OtherHash.CalculateHash(); | |||
1931 | } else | |||
1932 | return false; | |||
1933 | } | |||
1934 | return true; | |||
1935 | } | |||
1936 | ||||
1937 | ExplicitSpecifier ExplicitSpecifier::getFromDecl(FunctionDecl *Function) { | |||
1938 | switch (Function->getDeclKind()) { | |||
1939 | case Decl::Kind::CXXConstructor: | |||
1940 | return cast<CXXConstructorDecl>(Function)->getExplicitSpecifier(); | |||
1941 | case Decl::Kind::CXXConversion: | |||
1942 | return cast<CXXConversionDecl>(Function)->getExplicitSpecifier(); | |||
1943 | case Decl::Kind::CXXDeductionGuide: | |||
1944 | return cast<CXXDeductionGuideDecl>(Function)->getExplicitSpecifier(); | |||
1945 | default: | |||
1946 | return {}; | |||
1947 | } | |||
1948 | } | |||
1949 | ||||
1950 | CXXDeductionGuideDecl *CXXDeductionGuideDecl::Create( | |||
1951 | ASTContext &C, DeclContext *DC, SourceLocation StartLoc, | |||
1952 | ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T, | |||
1953 | TypeSourceInfo *TInfo, SourceLocation EndLocation) { | |||
1954 | return new (C, DC) CXXDeductionGuideDecl(C, DC, StartLoc, ES, NameInfo, T, | |||
1955 | TInfo, EndLocation); | |||
1956 | } | |||
1957 | ||||
1958 | CXXDeductionGuideDecl *CXXDeductionGuideDecl::CreateDeserialized(ASTContext &C, | |||
1959 | unsigned ID) { | |||
1960 | return new (C, ID) CXXDeductionGuideDecl( | |||
1961 | C, nullptr, SourceLocation(), ExplicitSpecifier(), DeclarationNameInfo(), | |||
1962 | QualType(), nullptr, SourceLocation()); | |||
1963 | } | |||
1964 | ||||
1965 | void CXXMethodDecl::anchor() {} | |||
1966 | ||||
1967 | bool CXXMethodDecl::isStatic() const { | |||
1968 | const CXXMethodDecl *MD = getCanonicalDecl(); | |||
1969 | ||||
1970 | if (MD->getStorageClass() == SC_Static) | |||
1971 | return true; | |||
1972 | ||||
1973 | OverloadedOperatorKind OOK = getDeclName().getCXXOverloadedOperator(); | |||
1974 | return isStaticOverloadedOperator(OOK); | |||
1975 | } | |||
1976 | ||||
1977 | static bool recursivelyOverrides(const CXXMethodDecl *DerivedMD, | |||
1978 | const CXXMethodDecl *BaseMD) { | |||
1979 | for (const CXXMethodDecl *MD : DerivedMD->overridden_methods()) { | |||
1980 | if (MD->getCanonicalDecl() == BaseMD->getCanonicalDecl()) | |||
1981 | return true; | |||
1982 | if (recursivelyOverrides(MD, BaseMD)) | |||
1983 | return true; | |||
1984 | } | |||
1985 | return false; | |||
1986 | } | |||
1987 | ||||
1988 | CXXMethodDecl * | |||
1989 | CXXMethodDecl::getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD, | |||
1990 | bool MayBeBase) { | |||
1991 | if (this->getParent()->getCanonicalDecl() == RD->getCanonicalDecl()) | |||
1992 | return this; | |||
1993 | ||||
1994 | // Lookup doesn't work for destructors, so handle them separately. | |||
1995 | if (isa<CXXDestructorDecl>(this)) { | |||
1996 | CXXMethodDecl *MD = RD->getDestructor(); | |||
1997 | if (MD) { | |||
1998 | if (recursivelyOverrides(MD, this)) | |||
1999 | return MD; | |||
2000 | if (MayBeBase && recursivelyOverrides(this, MD)) | |||
2001 | return MD; | |||
2002 | } | |||
2003 | return nullptr; | |||
2004 | } | |||
2005 | ||||
2006 | for (auto *ND : RD->lookup(getDeclName())) { | |||
2007 | auto *MD = dyn_cast<CXXMethodDecl>(ND); | |||
2008 | if (!MD) | |||
2009 | continue; | |||
2010 | if (recursivelyOverrides(MD, this)) | |||
2011 | return MD; | |||
2012 | if (MayBeBase && recursivelyOverrides(this, MD)) | |||
2013 | return MD; | |||
2014 | } | |||
2015 | ||||
2016 | return nullptr; | |||
2017 | } | |||
2018 | ||||
2019 | CXXMethodDecl * | |||
2020 | CXXMethodDecl::getCorrespondingMethodInClass(const CXXRecordDecl *RD, | |||
2021 | bool MayBeBase) { | |||
2022 | if (auto *MD = getCorrespondingMethodDeclaredInClass(RD, MayBeBase)) | |||
2023 | return MD; | |||
2024 | ||||
2025 | for (const auto &I : RD->bases()) { | |||
2026 | const RecordType *RT = I.getType()->getAs<RecordType>(); | |||
2027 | if (!RT) | |||
2028 | continue; | |||
2029 | const auto *Base = cast<CXXRecordDecl>(RT->getDecl()); | |||
2030 | CXXMethodDecl *T = this->getCorrespondingMethodInClass(Base); | |||
2031 | if (T) | |||
2032 | return T; | |||
2033 | } | |||
2034 | ||||
2035 | return nullptr; | |||
2036 | } | |||
2037 | ||||
2038 | CXXMethodDecl *CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, | |||
2039 | SourceLocation StartLoc, | |||
2040 | const DeclarationNameInfo &NameInfo, | |||
2041 | QualType T, TypeSourceInfo *TInfo, | |||
2042 | StorageClass SC, bool isInline, | |||
2043 | ConstexprSpecKind ConstexprKind, | |||
2044 | SourceLocation EndLocation) { | |||
2045 | return new (C, RD) | |||
2046 | CXXMethodDecl(CXXMethod, C, RD, StartLoc, NameInfo, T, TInfo, SC, | |||
2047 | isInline, ConstexprKind, EndLocation); | |||
2048 | } | |||
2049 | ||||
2050 | CXXMethodDecl *CXXMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
2051 | return new (C, ID) CXXMethodDecl( | |||
2052 | CXXMethod, C, nullptr, SourceLocation(), DeclarationNameInfo(), | |||
2053 | QualType(), nullptr, SC_None, false, CSK_unspecified, SourceLocation()); | |||
2054 | } | |||
2055 | ||||
2056 | CXXMethodDecl *CXXMethodDecl::getDevirtualizedMethod(const Expr *Base, | |||
2057 | bool IsAppleKext) { | |||
2058 | assert(isVirtual() && "this method is expected to be virtual")((isVirtual() && "this method is expected to be virtual" ) ? static_cast<void> (0) : __assert_fail ("isVirtual() && \"this method is expected to be virtual\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2058, __PRETTY_FUNCTION__)); | |||
2059 | ||||
2060 | // When building with -fapple-kext, all calls must go through the vtable since | |||
2061 | // the kernel linker can do runtime patching of vtables. | |||
2062 | if (IsAppleKext) | |||
2063 | return nullptr; | |||
2064 | ||||
2065 | // If the member function is marked 'final', we know that it can't be | |||
2066 | // overridden and can therefore devirtualize it unless it's pure virtual. | |||
2067 | if (hasAttr<FinalAttr>()) | |||
2068 | return isPure() ? nullptr : this; | |||
2069 | ||||
2070 | // If Base is unknown, we cannot devirtualize. | |||
2071 | if (!Base) | |||
2072 | return nullptr; | |||
2073 | ||||
2074 | // If the base expression (after skipping derived-to-base conversions) is a | |||
2075 | // class prvalue, then we can devirtualize. | |||
2076 | Base = Base->getBestDynamicClassTypeExpr(); | |||
2077 | if (Base->isRValue() && Base->getType()->isRecordType()) | |||
2078 | return this; | |||
2079 | ||||
2080 | // If we don't even know what we would call, we can't devirtualize. | |||
2081 | const CXXRecordDecl *BestDynamicDecl = Base->getBestDynamicClassType(); | |||
2082 | if (!BestDynamicDecl) | |||
2083 | return nullptr; | |||
2084 | ||||
2085 | // There may be a method corresponding to MD in a derived class. | |||
2086 | CXXMethodDecl *DevirtualizedMethod = | |||
2087 | getCorrespondingMethodInClass(BestDynamicDecl); | |||
2088 | ||||
2089 | // If that method is pure virtual, we can't devirtualize. If this code is | |||
2090 | // reached, the result would be UB, not a direct call to the derived class | |||
2091 | // function, and we can't assume the derived class function is defined. | |||
2092 | if (DevirtualizedMethod->isPure()) | |||
2093 | return nullptr; | |||
2094 | ||||
2095 | // If that method is marked final, we can devirtualize it. | |||
2096 | if (DevirtualizedMethod->hasAttr<FinalAttr>()) | |||
2097 | return DevirtualizedMethod; | |||
2098 | ||||
2099 | // Similarly, if the class itself or its destructor is marked 'final', | |||
2100 | // the class can't be derived from and we can therefore devirtualize the | |||
2101 | // member function call. | |||
2102 | if (BestDynamicDecl->hasAttr<FinalAttr>()) | |||
2103 | return DevirtualizedMethod; | |||
2104 | if (const auto *dtor = BestDynamicDecl->getDestructor()) { | |||
2105 | if (dtor->hasAttr<FinalAttr>()) | |||
2106 | return DevirtualizedMethod; | |||
2107 | } | |||
2108 | ||||
2109 | if (const auto *DRE = dyn_cast<DeclRefExpr>(Base)) { | |||
2110 | if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) | |||
2111 | if (VD->getType()->isRecordType()) | |||
2112 | // This is a record decl. We know the type and can devirtualize it. | |||
2113 | return DevirtualizedMethod; | |||
2114 | ||||
2115 | return nullptr; | |||
2116 | } | |||
2117 | ||||
2118 | // We can devirtualize calls on an object accessed by a class member access | |||
2119 | // expression, since by C++11 [basic.life]p6 we know that it can't refer to | |||
2120 | // a derived class object constructed in the same location. | |||
2121 | if (const auto *ME = dyn_cast<MemberExpr>(Base)) { | |||
2122 | const ValueDecl *VD = ME->getMemberDecl(); | |||
2123 | return VD->getType()->isRecordType() ? DevirtualizedMethod : nullptr; | |||
2124 | } | |||
2125 | ||||
2126 | // Likewise for calls on an object accessed by a (non-reference) pointer to | |||
2127 | // member access. | |||
2128 | if (auto *BO = dyn_cast<BinaryOperator>(Base)) { | |||
2129 | if (BO->isPtrMemOp()) { | |||
2130 | auto *MPT = BO->getRHS()->getType()->castAs<MemberPointerType>(); | |||
2131 | if (MPT->getPointeeType()->isRecordType()) | |||
2132 | return DevirtualizedMethod; | |||
2133 | } | |||
2134 | } | |||
2135 | ||||
2136 | // We can't devirtualize the call. | |||
2137 | return nullptr; | |||
2138 | } | |||
2139 | ||||
2140 | bool CXXMethodDecl::isUsualDeallocationFunction( | |||
2141 | SmallVectorImpl<const FunctionDecl *> &PreventedBy) const { | |||
2142 | assert(PreventedBy.empty() && "PreventedBy is expected to be empty")((PreventedBy.empty() && "PreventedBy is expected to be empty" ) ? static_cast<void> (0) : __assert_fail ("PreventedBy.empty() && \"PreventedBy is expected to be empty\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2142, __PRETTY_FUNCTION__)); | |||
2143 | if (getOverloadedOperator() != OO_Delete && | |||
2144 | getOverloadedOperator() != OO_Array_Delete) | |||
2145 | return false; | |||
2146 | ||||
2147 | // C++ [basic.stc.dynamic.deallocation]p2: | |||
2148 | // A template instance is never a usual deallocation function, | |||
2149 | // regardless of its signature. | |||
2150 | if (getPrimaryTemplate()) | |||
2151 | return false; | |||
2152 | ||||
2153 | // C++ [basic.stc.dynamic.deallocation]p2: | |||
2154 | // If a class T has a member deallocation function named operator delete | |||
2155 | // with exactly one parameter, then that function is a usual (non-placement) | |||
2156 | // deallocation function. [...] | |||
2157 | if (getNumParams() == 1) | |||
2158 | return true; | |||
2159 | unsigned UsualParams = 1; | |||
2160 | ||||
2161 | // C++ P0722: | |||
2162 | // A destroying operator delete is a usual deallocation function if | |||
2163 | // removing the std::destroying_delete_t parameter and changing the | |||
2164 | // first parameter type from T* to void* results in the signature of | |||
2165 | // a usual deallocation function. | |||
2166 | if (isDestroyingOperatorDelete()) | |||
2167 | ++UsualParams; | |||
2168 | ||||
2169 | // C++ <=14 [basic.stc.dynamic.deallocation]p2: | |||
2170 | // [...] If class T does not declare such an operator delete but does | |||
2171 | // declare a member deallocation function named operator delete with | |||
2172 | // exactly two parameters, the second of which has type std::size_t (18.1), | |||
2173 | // then this function is a usual deallocation function. | |||
2174 | // | |||
2175 | // C++17 says a usual deallocation function is one with the signature | |||
2176 | // (void* [, size_t] [, std::align_val_t] [, ...]) | |||
2177 | // and all such functions are usual deallocation functions. It's not clear | |||
2178 | // that allowing varargs functions was intentional. | |||
2179 | ASTContext &Context = getASTContext(); | |||
2180 | if (UsualParams < getNumParams() && | |||
2181 | Context.hasSameUnqualifiedType(getParamDecl(UsualParams)->getType(), | |||
2182 | Context.getSizeType())) | |||
2183 | ++UsualParams; | |||
2184 | ||||
2185 | if (UsualParams < getNumParams() && | |||
2186 | getParamDecl(UsualParams)->getType()->isAlignValT()) | |||
2187 | ++UsualParams; | |||
2188 | ||||
2189 | if (UsualParams != getNumParams()) | |||
2190 | return false; | |||
2191 | ||||
2192 | // In C++17 onwards, all potential usual deallocation functions are actual | |||
2193 | // usual deallocation functions. Honor this behavior when post-C++14 | |||
2194 | // deallocation functions are offered as extensions too. | |||
2195 | // FIXME(EricWF): Destrying Delete should be a language option. How do we | |||
2196 | // handle when destroying delete is used prior to C++17? | |||
2197 | if (Context.getLangOpts().CPlusPlus17 || | |||
2198 | Context.getLangOpts().AlignedAllocation || | |||
2199 | isDestroyingOperatorDelete()) | |||
2200 | return true; | |||
2201 | ||||
2202 | // This function is a usual deallocation function if there are no | |||
2203 | // single-parameter deallocation functions of the same kind. | |||
2204 | DeclContext::lookup_result R = getDeclContext()->lookup(getDeclName()); | |||
2205 | bool Result = true; | |||
2206 | for (const auto *D : R) { | |||
2207 | if (const auto *FD = dyn_cast<FunctionDecl>(D)) { | |||
2208 | if (FD->getNumParams() == 1) { | |||
2209 | PreventedBy.push_back(FD); | |||
2210 | Result = false; | |||
2211 | } | |||
2212 | } | |||
2213 | } | |||
2214 | return Result; | |||
2215 | } | |||
2216 | ||||
2217 | bool CXXMethodDecl::isCopyAssignmentOperator() const { | |||
2218 | // C++0x [class.copy]p17: | |||
2219 | // A user-declared copy assignment operator X::operator= is a non-static | |||
2220 | // non-template member function of class X with exactly one parameter of | |||
2221 | // type X, X&, const X&, volatile X& or const volatile X&. | |||
2222 | if (/*operator=*/getOverloadedOperator() != OO_Equal || | |||
2223 | /*non-static*/ isStatic() || | |||
2224 | /*non-template*/getPrimaryTemplate() || getDescribedFunctionTemplate() || | |||
2225 | getNumParams() != 1) | |||
2226 | return false; | |||
2227 | ||||
2228 | QualType ParamType = getParamDecl(0)->getType(); | |||
2229 | if (const auto *Ref = ParamType->getAs<LValueReferenceType>()) | |||
2230 | ParamType = Ref->getPointeeType(); | |||
2231 | ||||
2232 | ASTContext &Context = getASTContext(); | |||
2233 | QualType ClassType | |||
2234 | = Context.getCanonicalType(Context.getTypeDeclType(getParent())); | |||
2235 | return Context.hasSameUnqualifiedType(ClassType, ParamType); | |||
2236 | } | |||
2237 | ||||
2238 | bool CXXMethodDecl::isMoveAssignmentOperator() const { | |||
2239 | // C++0x [class.copy]p19: | |||
2240 | // A user-declared move assignment operator X::operator= is a non-static | |||
2241 | // non-template member function of class X with exactly one parameter of type | |||
2242 | // X&&, const X&&, volatile X&&, or const volatile X&&. | |||
2243 | if (getOverloadedOperator() != OO_Equal || isStatic() || | |||
2244 | getPrimaryTemplate() || getDescribedFunctionTemplate() || | |||
2245 | getNumParams() != 1) | |||
2246 | return false; | |||
2247 | ||||
2248 | QualType ParamType = getParamDecl(0)->getType(); | |||
2249 | if (!isa<RValueReferenceType>(ParamType)) | |||
2250 | return false; | |||
2251 | ParamType = ParamType->getPointeeType(); | |||
2252 | ||||
2253 | ASTContext &Context = getASTContext(); | |||
2254 | QualType ClassType | |||
2255 | = Context.getCanonicalType(Context.getTypeDeclType(getParent())); | |||
2256 | return Context.hasSameUnqualifiedType(ClassType, ParamType); | |||
2257 | } | |||
2258 | ||||
2259 | void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) { | |||
2260 | assert(MD->isCanonicalDecl() && "Method is not canonical!")((MD->isCanonicalDecl() && "Method is not canonical!" ) ? static_cast<void> (0) : __assert_fail ("MD->isCanonicalDecl() && \"Method is not canonical!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2260, __PRETTY_FUNCTION__)); | |||
2261 | assert(!MD->getParent()->isDependentContext() &&((!MD->getParent()->isDependentContext() && "Can't add an overridden method to a class template!" ) ? static_cast<void> (0) : __assert_fail ("!MD->getParent()->isDependentContext() && \"Can't add an overridden method to a class template!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2262, __PRETTY_FUNCTION__)) | |||
2262 | "Can't add an overridden method to a class template!")((!MD->getParent()->isDependentContext() && "Can't add an overridden method to a class template!" ) ? static_cast<void> (0) : __assert_fail ("!MD->getParent()->isDependentContext() && \"Can't add an overridden method to a class template!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2262, __PRETTY_FUNCTION__)); | |||
2263 | assert(MD->isVirtual() && "Method is not virtual!")((MD->isVirtual() && "Method is not virtual!") ? static_cast <void> (0) : __assert_fail ("MD->isVirtual() && \"Method is not virtual!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2263, __PRETTY_FUNCTION__)); | |||
2264 | ||||
2265 | getASTContext().addOverriddenMethod(this, MD); | |||
2266 | } | |||
2267 | ||||
2268 | CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const { | |||
2269 | if (isa<CXXConstructorDecl>(this)) return nullptr; | |||
2270 | return getASTContext().overridden_methods_begin(this); | |||
2271 | } | |||
2272 | ||||
2273 | CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const { | |||
2274 | if (isa<CXXConstructorDecl>(this)) return nullptr; | |||
2275 | return getASTContext().overridden_methods_end(this); | |||
2276 | } | |||
2277 | ||||
2278 | unsigned CXXMethodDecl::size_overridden_methods() const { | |||
2279 | if (isa<CXXConstructorDecl>(this)) return 0; | |||
2280 | return getASTContext().overridden_methods_size(this); | |||
2281 | } | |||
2282 | ||||
2283 | CXXMethodDecl::overridden_method_range | |||
2284 | CXXMethodDecl::overridden_methods() const { | |||
2285 | if (isa<CXXConstructorDecl>(this)) | |||
2286 | return overridden_method_range(nullptr, nullptr); | |||
2287 | return getASTContext().overridden_methods(this); | |||
2288 | } | |||
2289 | ||||
2290 | static QualType getThisObjectType(ASTContext &C, const FunctionProtoType *FPT, | |||
2291 | const CXXRecordDecl *Decl) { | |||
2292 | QualType ClassTy = C.getTypeDeclType(Decl); | |||
2293 | return C.getQualifiedType(ClassTy, FPT->getMethodQuals()); | |||
2294 | } | |||
2295 | ||||
2296 | QualType CXXMethodDecl::getThisType(const FunctionProtoType *FPT, | |||
2297 | const CXXRecordDecl *Decl) { | |||
2298 | ASTContext &C = Decl->getASTContext(); | |||
2299 | QualType ObjectTy = ::getThisObjectType(C, FPT, Decl); | |||
2300 | return C.getPointerType(ObjectTy); | |||
2301 | } | |||
2302 | ||||
2303 | QualType CXXMethodDecl::getThisObjectType(const FunctionProtoType *FPT, | |||
2304 | const CXXRecordDecl *Decl) { | |||
2305 | ASTContext &C = Decl->getASTContext(); | |||
2306 | return ::getThisObjectType(C, FPT, Decl); | |||
2307 | } | |||
2308 | ||||
2309 | QualType CXXMethodDecl::getThisType() const { | |||
2310 | // C++ 9.3.2p1: The type of this in a member function of a class X is X*. | |||
2311 | // If the member function is declared const, the type of this is const X*, | |||
2312 | // if the member function is declared volatile, the type of this is | |||
2313 | // volatile X*, and if the member function is declared const volatile, | |||
2314 | // the type of this is const volatile X*. | |||
2315 | assert(isInstance() && "No 'this' for static methods!")((isInstance() && "No 'this' for static methods!") ? static_cast <void> (0) : __assert_fail ("isInstance() && \"No 'this' for static methods!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2315, __PRETTY_FUNCTION__)); | |||
2316 | ||||
2317 | return CXXMethodDecl::getThisType(getType()->getAs<FunctionProtoType>(), | |||
2318 | getParent()); | |||
2319 | } | |||
2320 | ||||
2321 | QualType CXXMethodDecl::getThisObjectType() const { | |||
2322 | // Ditto getThisType. | |||
2323 | assert(isInstance() && "No 'this' for static methods!")((isInstance() && "No 'this' for static methods!") ? static_cast <void> (0) : __assert_fail ("isInstance() && \"No 'this' for static methods!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2323, __PRETTY_FUNCTION__)); | |||
2324 | ||||
2325 | return CXXMethodDecl::getThisObjectType(getType()->getAs<FunctionProtoType>(), | |||
2326 | getParent()); | |||
2327 | } | |||
2328 | ||||
2329 | bool CXXMethodDecl::hasInlineBody() const { | |||
2330 | // If this function is a template instantiation, look at the template from | |||
2331 | // which it was instantiated. | |||
2332 | const FunctionDecl *CheckFn = getTemplateInstantiationPattern(); | |||
2333 | if (!CheckFn) | |||
2334 | CheckFn = this; | |||
2335 | ||||
2336 | const FunctionDecl *fn; | |||
2337 | return CheckFn->isDefined(fn) && !fn->isOutOfLine() && | |||
2338 | (fn->doesThisDeclarationHaveABody() || fn->willHaveBody()); | |||
2339 | } | |||
2340 | ||||
2341 | bool CXXMethodDecl::isLambdaStaticInvoker() const { | |||
2342 | const CXXRecordDecl *P = getParent(); | |||
2343 | if (P->isLambda()) { | |||
2344 | if (const CXXMethodDecl *StaticInvoker = P->getLambdaStaticInvoker()) { | |||
2345 | if (StaticInvoker == this) return true; | |||
2346 | if (P->isGenericLambda() && this->isFunctionTemplateSpecialization()) | |||
2347 | return StaticInvoker == this->getPrimaryTemplate()->getTemplatedDecl(); | |||
2348 | } | |||
2349 | } | |||
2350 | return false; | |||
2351 | } | |||
2352 | ||||
2353 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, | |||
2354 | TypeSourceInfo *TInfo, bool IsVirtual, | |||
2355 | SourceLocation L, Expr *Init, | |||
2356 | SourceLocation R, | |||
2357 | SourceLocation EllipsisLoc) | |||
2358 | : Initializee(TInfo), MemberOrEllipsisLocation(EllipsisLoc), Init(Init), | |||
2359 | LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(IsVirtual), | |||
2360 | IsWritten(false), SourceOrder(0) {} | |||
2361 | ||||
2362 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, | |||
2363 | FieldDecl *Member, | |||
2364 | SourceLocation MemberLoc, | |||
2365 | SourceLocation L, Expr *Init, | |||
2366 | SourceLocation R) | |||
2367 | : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), | |||
2368 | LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false), | |||
2369 | IsWritten(false), SourceOrder(0) {} | |||
2370 | ||||
2371 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, | |||
2372 | IndirectFieldDecl *Member, | |||
2373 | SourceLocation MemberLoc, | |||
2374 | SourceLocation L, Expr *Init, | |||
2375 | SourceLocation R) | |||
2376 | : Initializee(Member), MemberOrEllipsisLocation(MemberLoc), Init(Init), | |||
2377 | LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false), | |||
2378 | IsWritten(false), SourceOrder(0) {} | |||
2379 | ||||
2380 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, | |||
2381 | TypeSourceInfo *TInfo, | |||
2382 | SourceLocation L, Expr *Init, | |||
2383 | SourceLocation R) | |||
2384 | : Initializee(TInfo), Init(Init), LParenLoc(L), RParenLoc(R), | |||
2385 | IsDelegating(true), IsVirtual(false), IsWritten(false), SourceOrder(0) {} | |||
2386 | ||||
2387 | int64_t CXXCtorInitializer::getID(const ASTContext &Context) const { | |||
2388 | return Context.getAllocator() | |||
2389 | .identifyKnownAlignedObject<CXXCtorInitializer>(this); | |||
2390 | } | |||
2391 | ||||
2392 | TypeLoc CXXCtorInitializer::getBaseClassLoc() const { | |||
2393 | if (isBaseInitializer()) | |||
2394 | return Initializee.get<TypeSourceInfo*>()->getTypeLoc(); | |||
2395 | else | |||
2396 | return {}; | |||
2397 | } | |||
2398 | ||||
2399 | const Type *CXXCtorInitializer::getBaseClass() const { | |||
2400 | if (isBaseInitializer()) | |||
2401 | return Initializee.get<TypeSourceInfo*>()->getType().getTypePtr(); | |||
2402 | else | |||
2403 | return nullptr; | |||
2404 | } | |||
2405 | ||||
2406 | SourceLocation CXXCtorInitializer::getSourceLocation() const { | |||
2407 | if (isInClassMemberInitializer()) | |||
2408 | return getAnyMember()->getLocation(); | |||
2409 | ||||
2410 | if (isAnyMemberInitializer()) | |||
2411 | return getMemberLocation(); | |||
2412 | ||||
2413 | if (const auto *TSInfo = Initializee.get<TypeSourceInfo *>()) | |||
2414 | return TSInfo->getTypeLoc().getLocalSourceRange().getBegin(); | |||
2415 | ||||
2416 | return {}; | |||
2417 | } | |||
2418 | ||||
2419 | SourceRange CXXCtorInitializer::getSourceRange() const { | |||
2420 | if (isInClassMemberInitializer()) { | |||
2421 | FieldDecl *D = getAnyMember(); | |||
2422 | if (Expr *I = D->getInClassInitializer()) | |||
2423 | return I->getSourceRange(); | |||
2424 | return {}; | |||
2425 | } | |||
2426 | ||||
2427 | return SourceRange(getSourceLocation(), getRParenLoc()); | |||
2428 | } | |||
2429 | ||||
2430 | CXXConstructorDecl::CXXConstructorDecl( | |||
2431 | ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, | |||
2432 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, | |||
2433 | ExplicitSpecifier ES, bool isInline, bool isImplicitlyDeclared, | |||
2434 | ConstexprSpecKind ConstexprKind, InheritedConstructor Inherited) | |||
2435 | : CXXMethodDecl(CXXConstructor, C, RD, StartLoc, NameInfo, T, TInfo, | |||
2436 | SC_None, isInline, ConstexprKind, SourceLocation()) { | |||
2437 | setNumCtorInitializers(0); | |||
2438 | setInheritingConstructor(static_cast<bool>(Inherited)); | |||
2439 | setImplicit(isImplicitlyDeclared); | |||
2440 | CXXConstructorDeclBits.HasTrailingExplicitSpecifier = ES.getExpr() ? 1 : 0; | |||
2441 | if (Inherited) | |||
2442 | *getTrailingObjects<InheritedConstructor>() = Inherited; | |||
2443 | setExplicitSpecifier(ES); | |||
2444 | } | |||
2445 | ||||
2446 | void CXXConstructorDecl::anchor() {} | |||
2447 | ||||
2448 | CXXConstructorDecl *CXXConstructorDecl::CreateDeserialized(ASTContext &C, | |||
2449 | unsigned ID, | |||
2450 | uint64_t AllocKind) { | |||
2451 | bool hasTraillingExplicit = static_cast<bool>(AllocKind & TAKHasTailExplicit); | |||
2452 | bool isInheritingConstructor = | |||
2453 | static_cast<bool>(AllocKind & TAKInheritsConstructor); | |||
2454 | unsigned Extra = | |||
2455 | additionalSizeToAlloc<InheritedConstructor, ExplicitSpecifier>( | |||
2456 | isInheritingConstructor, hasTraillingExplicit); | |||
2457 | auto *Result = new (C, ID, Extra) | |||
2458 | CXXConstructorDecl(C, nullptr, SourceLocation(), DeclarationNameInfo(), | |||
2459 | QualType(), nullptr, ExplicitSpecifier(), false, false, | |||
2460 | CSK_unspecified, InheritedConstructor()); | |||
2461 | Result->setInheritingConstructor(isInheritingConstructor); | |||
2462 | Result->CXXConstructorDeclBits.HasTrailingExplicitSpecifier = | |||
2463 | hasTraillingExplicit; | |||
2464 | Result->setExplicitSpecifier(ExplicitSpecifier()); | |||
2465 | return Result; | |||
2466 | } | |||
2467 | ||||
2468 | CXXConstructorDecl *CXXConstructorDecl::Create( | |||
2469 | ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, | |||
2470 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, | |||
2471 | ExplicitSpecifier ES, bool isInline, bool isImplicitlyDeclared, | |||
2472 | ConstexprSpecKind ConstexprKind, InheritedConstructor Inherited) { | |||
2473 | assert(NameInfo.getName().getNameKind()((NameInfo.getName().getNameKind() == DeclarationName::CXXConstructorName && "Name must refer to a constructor") ? static_cast <void> (0) : __assert_fail ("NameInfo.getName().getNameKind() == DeclarationName::CXXConstructorName && \"Name must refer to a constructor\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2475, __PRETTY_FUNCTION__)) | |||
2474 | == DeclarationName::CXXConstructorName &&((NameInfo.getName().getNameKind() == DeclarationName::CXXConstructorName && "Name must refer to a constructor") ? static_cast <void> (0) : __assert_fail ("NameInfo.getName().getNameKind() == DeclarationName::CXXConstructorName && \"Name must refer to a constructor\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2475, __PRETTY_FUNCTION__)) | |||
2475 | "Name must refer to a constructor")((NameInfo.getName().getNameKind() == DeclarationName::CXXConstructorName && "Name must refer to a constructor") ? static_cast <void> (0) : __assert_fail ("NameInfo.getName().getNameKind() == DeclarationName::CXXConstructorName && \"Name must refer to a constructor\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2475, __PRETTY_FUNCTION__)); | |||
2476 | unsigned Extra = | |||
2477 | additionalSizeToAlloc<InheritedConstructor, ExplicitSpecifier>( | |||
2478 | Inherited ? 1 : 0, ES.getExpr() ? 1 : 0); | |||
2479 | return new (C, RD, Extra) | |||
2480 | CXXConstructorDecl(C, RD, StartLoc, NameInfo, T, TInfo, ES, isInline, | |||
2481 | isImplicitlyDeclared, ConstexprKind, Inherited); | |||
2482 | } | |||
2483 | ||||
2484 | CXXConstructorDecl::init_const_iterator CXXConstructorDecl::init_begin() const { | |||
2485 | return CtorInitializers.get(getASTContext().getExternalSource()); | |||
2486 | } | |||
2487 | ||||
2488 | CXXConstructorDecl *CXXConstructorDecl::getTargetConstructor() const { | |||
2489 | assert(isDelegatingConstructor() && "Not a delegating constructor!")((isDelegatingConstructor() && "Not a delegating constructor!" ) ? static_cast<void> (0) : __assert_fail ("isDelegatingConstructor() && \"Not a delegating constructor!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2489, __PRETTY_FUNCTION__)); | |||
2490 | Expr *E = (*init_begin())->getInit()->IgnoreImplicit(); | |||
2491 | if (const auto *Construct = dyn_cast<CXXConstructExpr>(E)) | |||
2492 | return Construct->getConstructor(); | |||
2493 | ||||
2494 | return nullptr; | |||
2495 | } | |||
2496 | ||||
2497 | bool CXXConstructorDecl::isDefaultConstructor() const { | |||
2498 | // C++ [class.ctor]p5: | |||
2499 | // A default constructor for a class X is a constructor of class | |||
2500 | // X that can be called without an argument. | |||
2501 | return (getNumParams() == 0) || | |||
2502 | (getNumParams() > 0 && getParamDecl(0)->hasDefaultArg()); | |||
2503 | } | |||
2504 | ||||
2505 | bool | |||
2506 | CXXConstructorDecl::isCopyConstructor(unsigned &TypeQuals) const { | |||
2507 | return isCopyOrMoveConstructor(TypeQuals) && | |||
2508 | getParamDecl(0)->getType()->isLValueReferenceType(); | |||
2509 | } | |||
2510 | ||||
2511 | bool CXXConstructorDecl::isMoveConstructor(unsigned &TypeQuals) const { | |||
2512 | return isCopyOrMoveConstructor(TypeQuals) && | |||
2513 | getParamDecl(0)->getType()->isRValueReferenceType(); | |||
2514 | } | |||
2515 | ||||
2516 | /// Determine whether this is a copy or move constructor. | |||
2517 | bool CXXConstructorDecl::isCopyOrMoveConstructor(unsigned &TypeQuals) const { | |||
2518 | // C++ [class.copy]p2: | |||
2519 | // A non-template constructor for class X is a copy constructor | |||
2520 | // if its first parameter is of type X&, const X&, volatile X& or | |||
2521 | // const volatile X&, and either there are no other parameters | |||
2522 | // or else all other parameters have default arguments (8.3.6). | |||
2523 | // C++0x [class.copy]p3: | |||
2524 | // A non-template constructor for class X is a move constructor if its | |||
2525 | // first parameter is of type X&&, const X&&, volatile X&&, or | |||
2526 | // const volatile X&&, and either there are no other parameters or else | |||
2527 | // all other parameters have default arguments. | |||
2528 | if ((getNumParams() < 1) || | |||
2529 | (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) || | |||
2530 | (getPrimaryTemplate() != nullptr) || | |||
2531 | (getDescribedFunctionTemplate() != nullptr)) | |||
2532 | return false; | |||
2533 | ||||
2534 | const ParmVarDecl *Param = getParamDecl(0); | |||
2535 | ||||
2536 | // Do we have a reference type? | |||
2537 | const auto *ParamRefType = Param->getType()->getAs<ReferenceType>(); | |||
2538 | if (!ParamRefType) | |||
2539 | return false; | |||
2540 | ||||
2541 | // Is it a reference to our class type? | |||
2542 | ASTContext &Context = getASTContext(); | |||
2543 | ||||
2544 | CanQualType PointeeType | |||
2545 | = Context.getCanonicalType(ParamRefType->getPointeeType()); | |||
2546 | CanQualType ClassTy | |||
2547 | = Context.getCanonicalType(Context.getTagDeclType(getParent())); | |||
2548 | if (PointeeType.getUnqualifiedType() != ClassTy) | |||
2549 | return false; | |||
2550 | ||||
2551 | // FIXME: other qualifiers? | |||
2552 | ||||
2553 | // We have a copy or move constructor. | |||
2554 | TypeQuals = PointeeType.getCVRQualifiers(); | |||
2555 | return true; | |||
2556 | } | |||
2557 | ||||
2558 | bool CXXConstructorDecl::isConvertingConstructor(bool AllowExplicit) const { | |||
2559 | // C++ [class.conv.ctor]p1: | |||
2560 | // A constructor declared without the function-specifier explicit | |||
2561 | // that can be called with a single parameter specifies a | |||
2562 | // conversion from the type of its first parameter to the type of | |||
2563 | // its class. Such a constructor is called a converting | |||
2564 | // constructor. | |||
2565 | if (isExplicit() && !AllowExplicit) | |||
| ||||
2566 | return false; | |||
2567 | ||||
2568 | return (getNumParams() == 0 && | |||
2569 | getType()->getAs<FunctionProtoType>()->isVariadic()) || | |||
| ||||
2570 | (getNumParams() == 1) || | |||
2571 | (getNumParams() > 1 && | |||
2572 | (getParamDecl(1)->hasDefaultArg() || | |||
2573 | getParamDecl(1)->isParameterPack())); | |||
2574 | } | |||
2575 | ||||
2576 | bool CXXConstructorDecl::isSpecializationCopyingObject() const { | |||
2577 | if ((getNumParams() < 1) || | |||
2578 | (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) || | |||
2579 | (getDescribedFunctionTemplate() != nullptr)) | |||
2580 | return false; | |||
2581 | ||||
2582 | const ParmVarDecl *Param = getParamDecl(0); | |||
2583 | ||||
2584 | ASTContext &Context = getASTContext(); | |||
2585 | CanQualType ParamType = Context.getCanonicalType(Param->getType()); | |||
2586 | ||||
2587 | // Is it the same as our class type? | |||
2588 | CanQualType ClassTy | |||
2589 | = Context.getCanonicalType(Context.getTagDeclType(getParent())); | |||
2590 | if (ParamType.getUnqualifiedType() != ClassTy) | |||
2591 | return false; | |||
2592 | ||||
2593 | return true; | |||
2594 | } | |||
2595 | ||||
2596 | void CXXDestructorDecl::anchor() {} | |||
2597 | ||||
2598 | CXXDestructorDecl * | |||
2599 | CXXDestructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
2600 | return new (C, ID) | |||
2601 | CXXDestructorDecl(C, nullptr, SourceLocation(), DeclarationNameInfo(), | |||
2602 | QualType(), nullptr, false, false, CSK_unspecified); | |||
2603 | } | |||
2604 | ||||
2605 | CXXDestructorDecl *CXXDestructorDecl::Create( | |||
2606 | ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, | |||
2607 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, | |||
2608 | bool isInline, bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind) { | |||
2609 | assert(NameInfo.getName().getNameKind()((NameInfo.getName().getNameKind() == DeclarationName::CXXDestructorName && "Name must refer to a destructor") ? static_cast< void> (0) : __assert_fail ("NameInfo.getName().getNameKind() == DeclarationName::CXXDestructorName && \"Name must refer to a destructor\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2611, __PRETTY_FUNCTION__)) | |||
2610 | == DeclarationName::CXXDestructorName &&((NameInfo.getName().getNameKind() == DeclarationName::CXXDestructorName && "Name must refer to a destructor") ? static_cast< void> (0) : __assert_fail ("NameInfo.getName().getNameKind() == DeclarationName::CXXDestructorName && \"Name must refer to a destructor\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2611, __PRETTY_FUNCTION__)) | |||
2611 | "Name must refer to a destructor")((NameInfo.getName().getNameKind() == DeclarationName::CXXDestructorName && "Name must refer to a destructor") ? static_cast< void> (0) : __assert_fail ("NameInfo.getName().getNameKind() == DeclarationName::CXXDestructorName && \"Name must refer to a destructor\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2611, __PRETTY_FUNCTION__)); | |||
2612 | return new (C, RD) | |||
2613 | CXXDestructorDecl(C, RD, StartLoc, NameInfo, T, TInfo, isInline, | |||
2614 | isImplicitlyDeclared, ConstexprKind); | |||
2615 | } | |||
2616 | ||||
2617 | void CXXDestructorDecl::setOperatorDelete(FunctionDecl *OD, Expr *ThisArg) { | |||
2618 | auto *First = cast<CXXDestructorDecl>(getFirstDecl()); | |||
2619 | if (OD && !First->OperatorDelete) { | |||
2620 | First->OperatorDelete = OD; | |||
2621 | First->OperatorDeleteThisArg = ThisArg; | |||
2622 | if (auto *L = getASTMutationListener()) | |||
2623 | L->ResolvedOperatorDelete(First, OD, ThisArg); | |||
2624 | } | |||
2625 | } | |||
2626 | ||||
2627 | void CXXConversionDecl::anchor() {} | |||
2628 | ||||
2629 | CXXConversionDecl * | |||
2630 | CXXConversionDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
2631 | return new (C, ID) CXXConversionDecl( | |||
2632 | C, nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr, | |||
2633 | false, ExplicitSpecifier(), CSK_unspecified, SourceLocation()); | |||
2634 | } | |||
2635 | ||||
2636 | CXXConversionDecl *CXXConversionDecl::Create( | |||
2637 | ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, | |||
2638 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, | |||
2639 | bool isInline, ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind, | |||
2640 | SourceLocation EndLocation) { | |||
2641 | assert(NameInfo.getName().getNameKind()((NameInfo.getName().getNameKind() == DeclarationName::CXXConversionFunctionName && "Name must refer to a conversion function") ? static_cast <void> (0) : __assert_fail ("NameInfo.getName().getNameKind() == DeclarationName::CXXConversionFunctionName && \"Name must refer to a conversion function\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2643, __PRETTY_FUNCTION__)) | |||
2642 | == DeclarationName::CXXConversionFunctionName &&((NameInfo.getName().getNameKind() == DeclarationName::CXXConversionFunctionName && "Name must refer to a conversion function") ? static_cast <void> (0) : __assert_fail ("NameInfo.getName().getNameKind() == DeclarationName::CXXConversionFunctionName && \"Name must refer to a conversion function\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2643, __PRETTY_FUNCTION__)) | |||
2643 | "Name must refer to a conversion function")((NameInfo.getName().getNameKind() == DeclarationName::CXXConversionFunctionName && "Name must refer to a conversion function") ? static_cast <void> (0) : __assert_fail ("NameInfo.getName().getNameKind() == DeclarationName::CXXConversionFunctionName && \"Name must refer to a conversion function\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2643, __PRETTY_FUNCTION__)); | |||
2644 | return new (C, RD) | |||
2645 | CXXConversionDecl(C, RD, StartLoc, NameInfo, T, TInfo, isInline, ES, | |||
2646 | ConstexprKind, EndLocation); | |||
2647 | } | |||
2648 | ||||
2649 | bool CXXConversionDecl::isLambdaToBlockPointerConversion() const { | |||
2650 | return isImplicit() && getParent()->isLambda() && | |||
2651 | getConversionType()->isBlockPointerType(); | |||
2652 | } | |||
2653 | ||||
2654 | LinkageSpecDecl::LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc, | |||
2655 | SourceLocation LangLoc, LanguageIDs lang, | |||
2656 | bool HasBraces) | |||
2657 | : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec), | |||
2658 | ExternLoc(ExternLoc), RBraceLoc(SourceLocation()) { | |||
2659 | setLanguage(lang); | |||
2660 | LinkageSpecDeclBits.HasBraces = HasBraces; | |||
2661 | } | |||
2662 | ||||
2663 | void LinkageSpecDecl::anchor() {} | |||
2664 | ||||
2665 | LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, | |||
2666 | DeclContext *DC, | |||
2667 | SourceLocation ExternLoc, | |||
2668 | SourceLocation LangLoc, | |||
2669 | LanguageIDs Lang, | |||
2670 | bool HasBraces) { | |||
2671 | return new (C, DC) LinkageSpecDecl(DC, ExternLoc, LangLoc, Lang, HasBraces); | |||
2672 | } | |||
2673 | ||||
2674 | LinkageSpecDecl *LinkageSpecDecl::CreateDeserialized(ASTContext &C, | |||
2675 | unsigned ID) { | |||
2676 | return new (C, ID) LinkageSpecDecl(nullptr, SourceLocation(), | |||
2677 | SourceLocation(), lang_c, false); | |||
2678 | } | |||
2679 | ||||
2680 | void UsingDirectiveDecl::anchor() {} | |||
2681 | ||||
2682 | UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC, | |||
2683 | SourceLocation L, | |||
2684 | SourceLocation NamespaceLoc, | |||
2685 | NestedNameSpecifierLoc QualifierLoc, | |||
2686 | SourceLocation IdentLoc, | |||
2687 | NamedDecl *Used, | |||
2688 | DeclContext *CommonAncestor) { | |||
2689 | if (auto *NS = dyn_cast_or_null<NamespaceDecl>(Used)) | |||
2690 | Used = NS->getOriginalNamespace(); | |||
2691 | return new (C, DC) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierLoc, | |||
2692 | IdentLoc, Used, CommonAncestor); | |||
2693 | } | |||
2694 | ||||
2695 | UsingDirectiveDecl *UsingDirectiveDecl::CreateDeserialized(ASTContext &C, | |||
2696 | unsigned ID) { | |||
2697 | return new (C, ID) UsingDirectiveDecl(nullptr, SourceLocation(), | |||
2698 | SourceLocation(), | |||
2699 | NestedNameSpecifierLoc(), | |||
2700 | SourceLocation(), nullptr, nullptr); | |||
2701 | } | |||
2702 | ||||
2703 | NamespaceDecl *UsingDirectiveDecl::getNominatedNamespace() { | |||
2704 | if (auto *NA = dyn_cast_or_null<NamespaceAliasDecl>(NominatedNamespace)) | |||
2705 | return NA->getNamespace(); | |||
2706 | return cast_or_null<NamespaceDecl>(NominatedNamespace); | |||
2707 | } | |||
2708 | ||||
2709 | NamespaceDecl::NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline, | |||
2710 | SourceLocation StartLoc, SourceLocation IdLoc, | |||
2711 | IdentifierInfo *Id, NamespaceDecl *PrevDecl) | |||
2712 | : NamedDecl(Namespace, DC, IdLoc, Id), DeclContext(Namespace), | |||
2713 | redeclarable_base(C), LocStart(StartLoc), | |||
2714 | AnonOrFirstNamespaceAndInline(nullptr, Inline) { | |||
2715 | setPreviousDecl(PrevDecl); | |||
2716 | ||||
2717 | if (PrevDecl) | |||
2718 | AnonOrFirstNamespaceAndInline.setPointer(PrevDecl->getOriginalNamespace()); | |||
2719 | } | |||
2720 | ||||
2721 | NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC, | |||
2722 | bool Inline, SourceLocation StartLoc, | |||
2723 | SourceLocation IdLoc, IdentifierInfo *Id, | |||
2724 | NamespaceDecl *PrevDecl) { | |||
2725 | return new (C, DC) NamespaceDecl(C, DC, Inline, StartLoc, IdLoc, Id, | |||
2726 | PrevDecl); | |||
2727 | } | |||
2728 | ||||
2729 | NamespaceDecl *NamespaceDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
2730 | return new (C, ID) NamespaceDecl(C, nullptr, false, SourceLocation(), | |||
2731 | SourceLocation(), nullptr, nullptr); | |||
2732 | } | |||
2733 | ||||
2734 | NamespaceDecl *NamespaceDecl::getOriginalNamespace() { | |||
2735 | if (isFirstDecl()) | |||
2736 | return this; | |||
2737 | ||||
2738 | return AnonOrFirstNamespaceAndInline.getPointer(); | |||
2739 | } | |||
2740 | ||||
2741 | const NamespaceDecl *NamespaceDecl::getOriginalNamespace() const { | |||
2742 | if (isFirstDecl()) | |||
2743 | return this; | |||
2744 | ||||
2745 | return AnonOrFirstNamespaceAndInline.getPointer(); | |||
2746 | } | |||
2747 | ||||
2748 | bool NamespaceDecl::isOriginalNamespace() const { return isFirstDecl(); } | |||
2749 | ||||
2750 | NamespaceDecl *NamespaceDecl::getNextRedeclarationImpl() { | |||
2751 | return getNextRedeclaration(); | |||
2752 | } | |||
2753 | ||||
2754 | NamespaceDecl *NamespaceDecl::getPreviousDeclImpl() { | |||
2755 | return getPreviousDecl(); | |||
2756 | } | |||
2757 | ||||
2758 | NamespaceDecl *NamespaceDecl::getMostRecentDeclImpl() { | |||
2759 | return getMostRecentDecl(); | |||
2760 | } | |||
2761 | ||||
2762 | void NamespaceAliasDecl::anchor() {} | |||
2763 | ||||
2764 | NamespaceAliasDecl *NamespaceAliasDecl::getNextRedeclarationImpl() { | |||
2765 | return getNextRedeclaration(); | |||
2766 | } | |||
2767 | ||||
2768 | NamespaceAliasDecl *NamespaceAliasDecl::getPreviousDeclImpl() { | |||
2769 | return getPreviousDecl(); | |||
2770 | } | |||
2771 | ||||
2772 | NamespaceAliasDecl *NamespaceAliasDecl::getMostRecentDeclImpl() { | |||
2773 | return getMostRecentDecl(); | |||
2774 | } | |||
2775 | ||||
2776 | NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC, | |||
2777 | SourceLocation UsingLoc, | |||
2778 | SourceLocation AliasLoc, | |||
2779 | IdentifierInfo *Alias, | |||
2780 | NestedNameSpecifierLoc QualifierLoc, | |||
2781 | SourceLocation IdentLoc, | |||
2782 | NamedDecl *Namespace) { | |||
2783 | // FIXME: Preserve the aliased namespace as written. | |||
2784 | if (auto *NS = dyn_cast_or_null<NamespaceDecl>(Namespace)) | |||
2785 | Namespace = NS->getOriginalNamespace(); | |||
2786 | return new (C, DC) NamespaceAliasDecl(C, DC, UsingLoc, AliasLoc, Alias, | |||
2787 | QualifierLoc, IdentLoc, Namespace); | |||
2788 | } | |||
2789 | ||||
2790 | NamespaceAliasDecl * | |||
2791 | NamespaceAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
2792 | return new (C, ID) NamespaceAliasDecl(C, nullptr, SourceLocation(), | |||
2793 | SourceLocation(), nullptr, | |||
2794 | NestedNameSpecifierLoc(), | |||
2795 | SourceLocation(), nullptr); | |||
2796 | } | |||
2797 | ||||
2798 | void UsingShadowDecl::anchor() {} | |||
2799 | ||||
2800 | UsingShadowDecl::UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC, | |||
2801 | SourceLocation Loc, UsingDecl *Using, | |||
2802 | NamedDecl *Target) | |||
2803 | : NamedDecl(K, DC, Loc, Using ? Using->getDeclName() : DeclarationName()), | |||
2804 | redeclarable_base(C), UsingOrNextShadow(cast<NamedDecl>(Using)) { | |||
2805 | if (Target) | |||
2806 | setTargetDecl(Target); | |||
2807 | setImplicit(); | |||
2808 | } | |||
2809 | ||||
2810 | UsingShadowDecl::UsingShadowDecl(Kind K, ASTContext &C, EmptyShell Empty) | |||
2811 | : NamedDecl(K, nullptr, SourceLocation(), DeclarationName()), | |||
2812 | redeclarable_base(C) {} | |||
2813 | ||||
2814 | UsingShadowDecl * | |||
2815 | UsingShadowDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
2816 | return new (C, ID) UsingShadowDecl(UsingShadow, C, EmptyShell()); | |||
2817 | } | |||
2818 | ||||
2819 | UsingDecl *UsingShadowDecl::getUsingDecl() const { | |||
2820 | const UsingShadowDecl *Shadow = this; | |||
2821 | while (const auto *NextShadow = | |||
2822 | dyn_cast<UsingShadowDecl>(Shadow->UsingOrNextShadow)) | |||
2823 | Shadow = NextShadow; | |||
2824 | return cast<UsingDecl>(Shadow->UsingOrNextShadow); | |||
2825 | } | |||
2826 | ||||
2827 | void ConstructorUsingShadowDecl::anchor() {} | |||
2828 | ||||
2829 | ConstructorUsingShadowDecl * | |||
2830 | ConstructorUsingShadowDecl::Create(ASTContext &C, DeclContext *DC, | |||
2831 | SourceLocation Loc, UsingDecl *Using, | |||
2832 | NamedDecl *Target, bool IsVirtual) { | |||
2833 | return new (C, DC) ConstructorUsingShadowDecl(C, DC, Loc, Using, Target, | |||
2834 | IsVirtual); | |||
2835 | } | |||
2836 | ||||
2837 | ConstructorUsingShadowDecl * | |||
2838 | ConstructorUsingShadowDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
2839 | return new (C, ID) ConstructorUsingShadowDecl(C, EmptyShell()); | |||
2840 | } | |||
2841 | ||||
2842 | CXXRecordDecl *ConstructorUsingShadowDecl::getNominatedBaseClass() const { | |||
2843 | return getUsingDecl()->getQualifier()->getAsRecordDecl(); | |||
2844 | } | |||
2845 | ||||
2846 | void UsingDecl::anchor() {} | |||
2847 | ||||
2848 | void UsingDecl::addShadowDecl(UsingShadowDecl *S) { | |||
2849 | assert(std::find(shadow_begin(), shadow_end(), S) == shadow_end() &&((std::find(shadow_begin(), shadow_end(), S) == shadow_end() && "declaration already in set") ? static_cast<void> (0) : __assert_fail ("std::find(shadow_begin(), shadow_end(), S) == shadow_end() && \"declaration already in set\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2850, __PRETTY_FUNCTION__)) | |||
2850 | "declaration already in set")((std::find(shadow_begin(), shadow_end(), S) == shadow_end() && "declaration already in set") ? static_cast<void> (0) : __assert_fail ("std::find(shadow_begin(), shadow_end(), S) == shadow_end() && \"declaration already in set\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2850, __PRETTY_FUNCTION__)); | |||
2851 | assert(S->getUsingDecl() == this)((S->getUsingDecl() == this) ? static_cast<void> (0) : __assert_fail ("S->getUsingDecl() == this", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2851, __PRETTY_FUNCTION__)); | |||
2852 | ||||
2853 | if (FirstUsingShadow.getPointer()) | |||
2854 | S->UsingOrNextShadow = FirstUsingShadow.getPointer(); | |||
2855 | FirstUsingShadow.setPointer(S); | |||
2856 | } | |||
2857 | ||||
2858 | void UsingDecl::removeShadowDecl(UsingShadowDecl *S) { | |||
2859 | assert(std::find(shadow_begin(), shadow_end(), S) != shadow_end() &&((std::find(shadow_begin(), shadow_end(), S) != shadow_end() && "declaration not in set") ? static_cast<void> (0) : __assert_fail ("std::find(shadow_begin(), shadow_end(), S) != shadow_end() && \"declaration not in set\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2860, __PRETTY_FUNCTION__)) | |||
2860 | "declaration not in set")((std::find(shadow_begin(), shadow_end(), S) != shadow_end() && "declaration not in set") ? static_cast<void> (0) : __assert_fail ("std::find(shadow_begin(), shadow_end(), S) != shadow_end() && \"declaration not in set\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2860, __PRETTY_FUNCTION__)); | |||
2861 | assert(S->getUsingDecl() == this)((S->getUsingDecl() == this) ? static_cast<void> (0) : __assert_fail ("S->getUsingDecl() == this", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 2861, __PRETTY_FUNCTION__)); | |||
2862 | ||||
2863 | // Remove S from the shadow decl chain. This is O(n) but hopefully rare. | |||
2864 | ||||
2865 | if (FirstUsingShadow.getPointer() == S) { | |||
2866 | FirstUsingShadow.setPointer( | |||
2867 | dyn_cast<UsingShadowDecl>(S->UsingOrNextShadow)); | |||
2868 | S->UsingOrNextShadow = this; | |||
2869 | return; | |||
2870 | } | |||
2871 | ||||
2872 | UsingShadowDecl *Prev = FirstUsingShadow.getPointer(); | |||
2873 | while (Prev->UsingOrNextShadow != S) | |||
2874 | Prev = cast<UsingShadowDecl>(Prev->UsingOrNextShadow); | |||
2875 | Prev->UsingOrNextShadow = S->UsingOrNextShadow; | |||
2876 | S->UsingOrNextShadow = this; | |||
2877 | } | |||
2878 | ||||
2879 | UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation UL, | |||
2880 | NestedNameSpecifierLoc QualifierLoc, | |||
2881 | const DeclarationNameInfo &NameInfo, | |||
2882 | bool HasTypename) { | |||
2883 | return new (C, DC) UsingDecl(DC, UL, QualifierLoc, NameInfo, HasTypename); | |||
2884 | } | |||
2885 | ||||
2886 | UsingDecl *UsingDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
2887 | return new (C, ID) UsingDecl(nullptr, SourceLocation(), | |||
2888 | NestedNameSpecifierLoc(), DeclarationNameInfo(), | |||
2889 | false); | |||
2890 | } | |||
2891 | ||||
2892 | SourceRange UsingDecl::getSourceRange() const { | |||
2893 | SourceLocation Begin = isAccessDeclaration() | |||
2894 | ? getQualifierLoc().getBeginLoc() : UsingLocation; | |||
2895 | return SourceRange(Begin, getNameInfo().getEndLoc()); | |||
2896 | } | |||
2897 | ||||
2898 | void UsingPackDecl::anchor() {} | |||
2899 | ||||
2900 | UsingPackDecl *UsingPackDecl::Create(ASTContext &C, DeclContext *DC, | |||
2901 | NamedDecl *InstantiatedFrom, | |||
2902 | ArrayRef<NamedDecl *> UsingDecls) { | |||
2903 | size_t Extra = additionalSizeToAlloc<NamedDecl *>(UsingDecls.size()); | |||
2904 | return new (C, DC, Extra) UsingPackDecl(DC, InstantiatedFrom, UsingDecls); | |||
2905 | } | |||
2906 | ||||
2907 | UsingPackDecl *UsingPackDecl::CreateDeserialized(ASTContext &C, unsigned ID, | |||
2908 | unsigned NumExpansions) { | |||
2909 | size_t Extra = additionalSizeToAlloc<NamedDecl *>(NumExpansions); | |||
2910 | auto *Result = new (C, ID, Extra) UsingPackDecl(nullptr, nullptr, None); | |||
2911 | Result->NumExpansions = NumExpansions; | |||
2912 | auto *Trail = Result->getTrailingObjects<NamedDecl *>(); | |||
2913 | for (unsigned I = 0; I != NumExpansions; ++I) | |||
2914 | new (Trail + I) NamedDecl*(nullptr); | |||
2915 | return Result; | |||
2916 | } | |||
2917 | ||||
2918 | void UnresolvedUsingValueDecl::anchor() {} | |||
2919 | ||||
2920 | UnresolvedUsingValueDecl * | |||
2921 | UnresolvedUsingValueDecl::Create(ASTContext &C, DeclContext *DC, | |||
2922 | SourceLocation UsingLoc, | |||
2923 | NestedNameSpecifierLoc QualifierLoc, | |||
2924 | const DeclarationNameInfo &NameInfo, | |||
2925 | SourceLocation EllipsisLoc) { | |||
2926 | return new (C, DC) UnresolvedUsingValueDecl(DC, C.DependentTy, UsingLoc, | |||
2927 | QualifierLoc, NameInfo, | |||
2928 | EllipsisLoc); | |||
2929 | } | |||
2930 | ||||
2931 | UnresolvedUsingValueDecl * | |||
2932 | UnresolvedUsingValueDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
2933 | return new (C, ID) UnresolvedUsingValueDecl(nullptr, QualType(), | |||
2934 | SourceLocation(), | |||
2935 | NestedNameSpecifierLoc(), | |||
2936 | DeclarationNameInfo(), | |||
2937 | SourceLocation()); | |||
2938 | } | |||
2939 | ||||
2940 | SourceRange UnresolvedUsingValueDecl::getSourceRange() const { | |||
2941 | SourceLocation Begin = isAccessDeclaration() | |||
2942 | ? getQualifierLoc().getBeginLoc() : UsingLocation; | |||
2943 | return SourceRange(Begin, getNameInfo().getEndLoc()); | |||
2944 | } | |||
2945 | ||||
2946 | void UnresolvedUsingTypenameDecl::anchor() {} | |||
2947 | ||||
2948 | UnresolvedUsingTypenameDecl * | |||
2949 | UnresolvedUsingTypenameDecl::Create(ASTContext &C, DeclContext *DC, | |||
2950 | SourceLocation UsingLoc, | |||
2951 | SourceLocation TypenameLoc, | |||
2952 | NestedNameSpecifierLoc QualifierLoc, | |||
2953 | SourceLocation TargetNameLoc, | |||
2954 | DeclarationName TargetName, | |||
2955 | SourceLocation EllipsisLoc) { | |||
2956 | return new (C, DC) UnresolvedUsingTypenameDecl( | |||
2957 | DC, UsingLoc, TypenameLoc, QualifierLoc, TargetNameLoc, | |||
2958 | TargetName.getAsIdentifierInfo(), EllipsisLoc); | |||
2959 | } | |||
2960 | ||||
2961 | UnresolvedUsingTypenameDecl * | |||
2962 | UnresolvedUsingTypenameDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
2963 | return new (C, ID) UnresolvedUsingTypenameDecl( | |||
2964 | nullptr, SourceLocation(), SourceLocation(), NestedNameSpecifierLoc(), | |||
2965 | SourceLocation(), nullptr, SourceLocation()); | |||
2966 | } | |||
2967 | ||||
2968 | void StaticAssertDecl::anchor() {} | |||
2969 | ||||
2970 | StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC, | |||
2971 | SourceLocation StaticAssertLoc, | |||
2972 | Expr *AssertExpr, | |||
2973 | StringLiteral *Message, | |||
2974 | SourceLocation RParenLoc, | |||
2975 | bool Failed) { | |||
2976 | return new (C, DC) StaticAssertDecl(DC, StaticAssertLoc, AssertExpr, Message, | |||
2977 | RParenLoc, Failed); | |||
2978 | } | |||
2979 | ||||
2980 | StaticAssertDecl *StaticAssertDecl::CreateDeserialized(ASTContext &C, | |||
2981 | unsigned ID) { | |||
2982 | return new (C, ID) StaticAssertDecl(nullptr, SourceLocation(), nullptr, | |||
2983 | nullptr, SourceLocation(), false); | |||
2984 | } | |||
2985 | ||||
2986 | void BindingDecl::anchor() {} | |||
2987 | ||||
2988 | BindingDecl *BindingDecl::Create(ASTContext &C, DeclContext *DC, | |||
2989 | SourceLocation IdLoc, IdentifierInfo *Id) { | |||
2990 | return new (C, DC) BindingDecl(DC, IdLoc, Id); | |||
2991 | } | |||
2992 | ||||
2993 | BindingDecl *BindingDecl::CreateDeserialized(ASTContext &C, unsigned ID) { | |||
2994 | return new (C, ID) BindingDecl(nullptr, SourceLocation(), nullptr); | |||
2995 | } | |||
2996 | ||||
2997 | ValueDecl *BindingDecl::getDecomposedDecl() const { | |||
2998 | ExternalASTSource *Source = | |||
2999 | Decomp.isOffset() ? getASTContext().getExternalSource() : nullptr; | |||
3000 | return cast_or_null<ValueDecl>(Decomp.get(Source)); | |||
3001 | } | |||
3002 | ||||
3003 | VarDecl *BindingDecl::getHoldingVar() const { | |||
3004 | Expr *B = getBinding(); | |||
3005 | if (!B) | |||
3006 | return nullptr; | |||
3007 | auto *DRE = dyn_cast<DeclRefExpr>(B->IgnoreImplicit()); | |||
3008 | if (!DRE) | |||
3009 | return nullptr; | |||
3010 | ||||
3011 | auto *VD = dyn_cast<VarDecl>(DRE->getDecl()); | |||
3012 | assert(VD->isImplicit() && "holding var for binding decl not implicit")((VD->isImplicit() && "holding var for binding decl not implicit" ) ? static_cast<void> (0) : __assert_fail ("VD->isImplicit() && \"holding var for binding decl not implicit\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 3012, __PRETTY_FUNCTION__)); | |||
3013 | return VD; | |||
3014 | } | |||
3015 | ||||
3016 | void DecompositionDecl::anchor() {} | |||
3017 | ||||
3018 | DecompositionDecl *DecompositionDecl::Create(ASTContext &C, DeclContext *DC, | |||
3019 | SourceLocation StartLoc, | |||
3020 | SourceLocation LSquareLoc, | |||
3021 | QualType T, TypeSourceInfo *TInfo, | |||
3022 | StorageClass SC, | |||
3023 | ArrayRef<BindingDecl *> Bindings) { | |||
3024 | size_t Extra = additionalSizeToAlloc<BindingDecl *>(Bindings.size()); | |||
3025 | return new (C, DC, Extra) | |||
3026 | DecompositionDecl(C, DC, StartLoc, LSquareLoc, T, TInfo, SC, Bindings); | |||
3027 | } | |||
3028 | ||||
3029 | DecompositionDecl *DecompositionDecl::CreateDeserialized(ASTContext &C, | |||
3030 | unsigned ID, | |||
3031 | unsigned NumBindings) { | |||
3032 | size_t Extra = additionalSizeToAlloc<BindingDecl *>(NumBindings); | |||
3033 | auto *Result = new (C, ID, Extra) | |||
3034 | DecompositionDecl(C, nullptr, SourceLocation(), SourceLocation(), | |||
3035 | QualType(), nullptr, StorageClass(), None); | |||
3036 | // Set up and clean out the bindings array. | |||
3037 | Result->NumBindings = NumBindings; | |||
3038 | auto *Trail = Result->getTrailingObjects<BindingDecl *>(); | |||
3039 | for (unsigned I = 0; I != NumBindings; ++I) | |||
3040 | new (Trail + I) BindingDecl*(nullptr); | |||
3041 | return Result; | |||
3042 | } | |||
3043 | ||||
3044 | void DecompositionDecl::printName(llvm::raw_ostream &os) const { | |||
3045 | os << '['; | |||
3046 | bool Comma = false; | |||
3047 | for (const auto *B : bindings()) { | |||
3048 | if (Comma) | |||
3049 | os << ", "; | |||
3050 | B->printName(os); | |||
3051 | Comma = true; | |||
3052 | } | |||
3053 | os << ']'; | |||
3054 | } | |||
3055 | ||||
3056 | void MSPropertyDecl::anchor() {} | |||
3057 | ||||
3058 | MSPropertyDecl *MSPropertyDecl::Create(ASTContext &C, DeclContext *DC, | |||
3059 | SourceLocation L, DeclarationName N, | |||
3060 | QualType T, TypeSourceInfo *TInfo, | |||
3061 | SourceLocation StartL, | |||
3062 | IdentifierInfo *Getter, | |||
3063 | IdentifierInfo *Setter) { | |||
3064 | return new (C, DC) MSPropertyDecl(DC, L, N, T, TInfo, StartL, Getter, Setter); | |||
3065 | } | |||
3066 | ||||
3067 | MSPropertyDecl *MSPropertyDecl::CreateDeserialized(ASTContext &C, | |||
3068 | unsigned ID) { | |||
3069 | return new (C, ID) MSPropertyDecl(nullptr, SourceLocation(), | |||
3070 | DeclarationName(), QualType(), nullptr, | |||
3071 | SourceLocation(), nullptr, nullptr); | |||
3072 | } | |||
3073 | ||||
3074 | static const char *getAccessName(AccessSpecifier AS) { | |||
3075 | switch (AS) { | |||
3076 | case AS_none: | |||
3077 | llvm_unreachable("Invalid access specifier!")::llvm::llvm_unreachable_internal("Invalid access specifier!" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 3077); | |||
3078 | case AS_public: | |||
3079 | return "public"; | |||
3080 | case AS_private: | |||
3081 | return "private"; | |||
3082 | case AS_protected: | |||
3083 | return "protected"; | |||
3084 | } | |||
3085 | llvm_unreachable("Invalid access specifier!")::llvm::llvm_unreachable_internal("Invalid access specifier!" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/lib/AST/DeclCXX.cpp" , 3085); | |||
3086 | } | |||
3087 | ||||
3088 | const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB, | |||
3089 | AccessSpecifier AS) { | |||
3090 | return DB << getAccessName(AS); | |||
3091 | } | |||
3092 | ||||
3093 | const PartialDiagnostic &clang::operator<<(const PartialDiagnostic &DB, | |||
3094 | AccessSpecifier AS) { | |||
3095 | return DB << getAccessName(AS); | |||
3096 | } |
1 | //===- DeclCXX.h - Classes for representing C++ declarations --*- C++ -*-=====// |
2 | // |
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 |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | /// \file |
10 | /// Defines the C++ Decl subclasses, other than those for templates |
11 | /// (found in DeclTemplate.h) and friends (in DeclFriend.h). |
12 | // |
13 | //===----------------------------------------------------------------------===// |
14 | |
15 | #ifndef LLVM_CLANG_AST_DECLCXX_H |
16 | #define LLVM_CLANG_AST_DECLCXX_H |
17 | |
18 | #include "clang/AST/ASTContext.h" |
19 | #include "clang/AST/ASTUnresolvedSet.h" |
20 | #include "clang/AST/Attr.h" |
21 | #include "clang/AST/Decl.h" |
22 | #include "clang/AST/DeclBase.h" |
23 | #include "clang/AST/DeclarationName.h" |
24 | #include "clang/AST/Expr.h" |
25 | #include "clang/AST/ExternalASTSource.h" |
26 | #include "clang/AST/LambdaCapture.h" |
27 | #include "clang/AST/NestedNameSpecifier.h" |
28 | #include "clang/AST/Redeclarable.h" |
29 | #include "clang/AST/Stmt.h" |
30 | #include "clang/AST/Type.h" |
31 | #include "clang/AST/TypeLoc.h" |
32 | #include "clang/AST/UnresolvedSet.h" |
33 | #include "clang/Basic/LLVM.h" |
34 | #include "clang/Basic/Lambda.h" |
35 | #include "clang/Basic/LangOptions.h" |
36 | #include "clang/Basic/OperatorKinds.h" |
37 | #include "clang/Basic/SourceLocation.h" |
38 | #include "clang/Basic/Specifiers.h" |
39 | #include "llvm/ADT/ArrayRef.h" |
40 | #include "llvm/ADT/DenseMap.h" |
41 | #include "llvm/ADT/PointerIntPair.h" |
42 | #include "llvm/ADT/PointerUnion.h" |
43 | #include "llvm/ADT/STLExtras.h" |
44 | #include "llvm/ADT/iterator_range.h" |
45 | #include "llvm/BinaryFormat/Dwarf.h" |
46 | #include "llvm/Support/Casting.h" |
47 | #include "llvm/Support/Compiler.h" |
48 | #include "llvm/Support/PointerLikeTypeTraits.h" |
49 | #include "llvm/Support/TrailingObjects.h" |
50 | #include <cassert> |
51 | #include <cstddef> |
52 | #include <iterator> |
53 | #include <memory> |
54 | #include <vector> |
55 | |
56 | namespace clang { |
57 | |
58 | class ClassTemplateDecl; |
59 | class ConstructorUsingShadowDecl; |
60 | class CXXBasePath; |
61 | class CXXBasePaths; |
62 | class CXXConstructorDecl; |
63 | class CXXDestructorDecl; |
64 | class CXXFinalOverriderMap; |
65 | class CXXIndirectPrimaryBaseSet; |
66 | class CXXMethodDecl; |
67 | class DecompositionDecl; |
68 | class DiagnosticBuilder; |
69 | class FriendDecl; |
70 | class FunctionTemplateDecl; |
71 | class IdentifierInfo; |
72 | class MemberSpecializationInfo; |
73 | class TemplateDecl; |
74 | class TemplateParameterList; |
75 | class UsingDecl; |
76 | |
77 | /// Represents an access specifier followed by colon ':'. |
78 | /// |
79 | /// An objects of this class represents sugar for the syntactic occurrence |
80 | /// of an access specifier followed by a colon in the list of member |
81 | /// specifiers of a C++ class definition. |
82 | /// |
83 | /// Note that they do not represent other uses of access specifiers, |
84 | /// such as those occurring in a list of base specifiers. |
85 | /// Also note that this class has nothing to do with so-called |
86 | /// "access declarations" (C++98 11.3 [class.access.dcl]). |
87 | class AccessSpecDecl : public Decl { |
88 | /// The location of the ':'. |
89 | SourceLocation ColonLoc; |
90 | |
91 | AccessSpecDecl(AccessSpecifier AS, DeclContext *DC, |
92 | SourceLocation ASLoc, SourceLocation ColonLoc) |
93 | : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) { |
94 | setAccess(AS); |
95 | } |
96 | |
97 | AccessSpecDecl(EmptyShell Empty) : Decl(AccessSpec, Empty) {} |
98 | |
99 | virtual void anchor(); |
100 | |
101 | public: |
102 | /// The location of the access specifier. |
103 | SourceLocation getAccessSpecifierLoc() const { return getLocation(); } |
104 | |
105 | /// Sets the location of the access specifier. |
106 | void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); } |
107 | |
108 | /// The location of the colon following the access specifier. |
109 | SourceLocation getColonLoc() const { return ColonLoc; } |
110 | |
111 | /// Sets the location of the colon. |
112 | void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; } |
113 | |
114 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
115 | return SourceRange(getAccessSpecifierLoc(), getColonLoc()); |
116 | } |
117 | |
118 | static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS, |
119 | DeclContext *DC, SourceLocation ASLoc, |
120 | SourceLocation ColonLoc) { |
121 | return new (C, DC) AccessSpecDecl(AS, DC, ASLoc, ColonLoc); |
122 | } |
123 | |
124 | static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
125 | |
126 | // Implement isa/cast/dyncast/etc. |
127 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
128 | static bool classofKind(Kind K) { return K == AccessSpec; } |
129 | }; |
130 | |
131 | /// Represents a base class of a C++ class. |
132 | /// |
133 | /// Each CXXBaseSpecifier represents a single, direct base class (or |
134 | /// struct) of a C++ class (or struct). It specifies the type of that |
135 | /// base class, whether it is a virtual or non-virtual base, and what |
136 | /// level of access (public, protected, private) is used for the |
137 | /// derivation. For example: |
138 | /// |
139 | /// \code |
140 | /// class A { }; |
141 | /// class B { }; |
142 | /// class C : public virtual A, protected B { }; |
143 | /// \endcode |
144 | /// |
145 | /// In this code, C will have two CXXBaseSpecifiers, one for "public |
146 | /// virtual A" and the other for "protected B". |
147 | class CXXBaseSpecifier { |
148 | /// The source code range that covers the full base |
149 | /// specifier, including the "virtual" (if present) and access |
150 | /// specifier (if present). |
151 | SourceRange Range; |
152 | |
153 | /// The source location of the ellipsis, if this is a pack |
154 | /// expansion. |
155 | SourceLocation EllipsisLoc; |
156 | |
157 | /// Whether this is a virtual base class or not. |
158 | unsigned Virtual : 1; |
159 | |
160 | /// Whether this is the base of a class (true) or of a struct (false). |
161 | /// |
162 | /// This determines the mapping from the access specifier as written in the |
163 | /// source code to the access specifier used for semantic analysis. |
164 | unsigned BaseOfClass : 1; |
165 | |
166 | /// Access specifier as written in the source code (may be AS_none). |
167 | /// |
168 | /// The actual type of data stored here is an AccessSpecifier, but we use |
169 | /// "unsigned" here to work around a VC++ bug. |
170 | unsigned Access : 2; |
171 | |
172 | /// Whether the class contains a using declaration |
173 | /// to inherit the named class's constructors. |
174 | unsigned InheritConstructors : 1; |
175 | |
176 | /// The type of the base class. |
177 | /// |
178 | /// This will be a class or struct (or a typedef of such). The source code |
179 | /// range does not include the \c virtual or the access specifier. |
180 | TypeSourceInfo *BaseTypeInfo; |
181 | |
182 | public: |
183 | CXXBaseSpecifier() = default; |
184 | CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, |
185 | TypeSourceInfo *TInfo, SourceLocation EllipsisLoc) |
186 | : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC), |
187 | Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) {} |
188 | |
189 | /// Retrieves the source range that contains the entire base specifier. |
190 | SourceRange getSourceRange() const LLVM_READONLY__attribute__((__pure__)) { return Range; } |
191 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { return Range.getBegin(); } |
192 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { return Range.getEnd(); } |
193 | |
194 | /// Get the location at which the base class type was written. |
195 | SourceLocation getBaseTypeLoc() const LLVM_READONLY__attribute__((__pure__)) { |
196 | return BaseTypeInfo->getTypeLoc().getBeginLoc(); |
197 | } |
198 | |
199 | /// Determines whether the base class is a virtual base class (or not). |
200 | bool isVirtual() const { return Virtual; } |
201 | |
202 | /// Determine whether this base class is a base of a class declared |
203 | /// with the 'class' keyword (vs. one declared with the 'struct' keyword). |
204 | bool isBaseOfClass() const { return BaseOfClass; } |
205 | |
206 | /// Determine whether this base specifier is a pack expansion. |
207 | bool isPackExpansion() const { return EllipsisLoc.isValid(); } |
208 | |
209 | /// Determine whether this base class's constructors get inherited. |
210 | bool getInheritConstructors() const { return InheritConstructors; } |
211 | |
212 | /// Set that this base class's constructors should be inherited. |
213 | void setInheritConstructors(bool Inherit = true) { |
214 | InheritConstructors = Inherit; |
215 | } |
216 | |
217 | /// For a pack expansion, determine the location of the ellipsis. |
218 | SourceLocation getEllipsisLoc() const { |
219 | return EllipsisLoc; |
220 | } |
221 | |
222 | /// Returns the access specifier for this base specifier. |
223 | /// |
224 | /// This is the actual base specifier as used for semantic analysis, so |
225 | /// the result can never be AS_none. To retrieve the access specifier as |
226 | /// written in the source code, use getAccessSpecifierAsWritten(). |
227 | AccessSpecifier getAccessSpecifier() const { |
228 | if ((AccessSpecifier)Access == AS_none) |
229 | return BaseOfClass? AS_private : AS_public; |
230 | else |
231 | return (AccessSpecifier)Access; |
232 | } |
233 | |
234 | /// Retrieves the access specifier as written in the source code |
235 | /// (which may mean that no access specifier was explicitly written). |
236 | /// |
237 | /// Use getAccessSpecifier() to retrieve the access specifier for use in |
238 | /// semantic analysis. |
239 | AccessSpecifier getAccessSpecifierAsWritten() const { |
240 | return (AccessSpecifier)Access; |
241 | } |
242 | |
243 | /// Retrieves the type of the base class. |
244 | /// |
245 | /// This type will always be an unqualified class type. |
246 | QualType getType() const { |
247 | return BaseTypeInfo->getType().getUnqualifiedType(); |
248 | } |
249 | |
250 | /// Retrieves the type and source location of the base class. |
251 | TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; } |
252 | }; |
253 | |
254 | /// Represents a C++ struct/union/class. |
255 | class CXXRecordDecl : public RecordDecl { |
256 | friend class ASTDeclReader; |
257 | friend class ASTDeclWriter; |
258 | friend class ASTNodeImporter; |
259 | friend class ASTReader; |
260 | friend class ASTRecordWriter; |
261 | friend class ASTWriter; |
262 | friend class DeclContext; |
263 | friend class LambdaExpr; |
264 | |
265 | friend void FunctionDecl::setPure(bool); |
266 | friend void TagDecl::startDefinition(); |
267 | |
268 | /// Values used in DefinitionData fields to represent special members. |
269 | enum SpecialMemberFlags { |
270 | SMF_DefaultConstructor = 0x1, |
271 | SMF_CopyConstructor = 0x2, |
272 | SMF_MoveConstructor = 0x4, |
273 | SMF_CopyAssignment = 0x8, |
274 | SMF_MoveAssignment = 0x10, |
275 | SMF_Destructor = 0x20, |
276 | SMF_All = 0x3f |
277 | }; |
278 | |
279 | struct DefinitionData { |
280 | /// True if this class has any user-declared constructors. |
281 | unsigned UserDeclaredConstructor : 1; |
282 | |
283 | /// The user-declared special members which this class has. |
284 | unsigned UserDeclaredSpecialMembers : 6; |
285 | |
286 | /// True when this class is an aggregate. |
287 | unsigned Aggregate : 1; |
288 | |
289 | /// True when this class is a POD-type. |
290 | unsigned PlainOldData : 1; |
291 | |
292 | /// True when this class is empty for traits purposes, that is: |
293 | /// * has no data members other than 0-width bit-fields and empty fields |
294 | /// marked [[no_unique_address]] |
295 | /// * has no virtual function/base, and |
296 | /// * doesn't inherit from a non-empty class. |
297 | /// Doesn't take union-ness into account. |
298 | unsigned Empty : 1; |
299 | |
300 | /// True when this class is polymorphic, i.e., has at |
301 | /// least one virtual member or derives from a polymorphic class. |
302 | unsigned Polymorphic : 1; |
303 | |
304 | /// True when this class is abstract, i.e., has at least |
305 | /// one pure virtual function, (that can come from a base class). |
306 | unsigned Abstract : 1; |
307 | |
308 | /// True when this class is standard-layout, per the applicable |
309 | /// language rules (including DRs). |
310 | unsigned IsStandardLayout : 1; |
311 | |
312 | /// True when this class was standard-layout under the C++11 |
313 | /// definition. |
314 | /// |
315 | /// C++11 [class]p7. A standard-layout class is a class that: |
316 | /// * has no non-static data members of type non-standard-layout class (or |
317 | /// array of such types) or reference, |
318 | /// * has no virtual functions (10.3) and no virtual base classes (10.1), |
319 | /// * has the same access control (Clause 11) for all non-static data |
320 | /// members |
321 | /// * has no non-standard-layout base classes, |
322 | /// * either has no non-static data members in the most derived class and at |
323 | /// most one base class with non-static data members, or has no base |
324 | /// classes with non-static data members, and |
325 | /// * has no base classes of the same type as the first non-static data |
326 | /// member. |
327 | unsigned IsCXX11StandardLayout : 1; |
328 | |
329 | /// True when any base class has any declared non-static data |
330 | /// members or bit-fields. |
331 | /// This is a helper bit of state used to implement IsStandardLayout more |
332 | /// efficiently. |
333 | unsigned HasBasesWithFields : 1; |
334 | |
335 | /// True when any base class has any declared non-static data |
336 | /// members. |
337 | /// This is a helper bit of state used to implement IsCXX11StandardLayout |
338 | /// more efficiently. |
339 | unsigned HasBasesWithNonStaticDataMembers : 1; |
340 | |
341 | /// True when there are private non-static data members. |
342 | unsigned HasPrivateFields : 1; |
343 | |
344 | /// True when there are protected non-static data members. |
345 | unsigned HasProtectedFields : 1; |
346 | |
347 | /// True when there are private non-static data members. |
348 | unsigned HasPublicFields : 1; |
349 | |
350 | /// True if this class (or any subobject) has mutable fields. |
351 | unsigned HasMutableFields : 1; |
352 | |
353 | /// True if this class (or any nested anonymous struct or union) |
354 | /// has variant members. |
355 | unsigned HasVariantMembers : 1; |
356 | |
357 | /// True if there no non-field members declared by the user. |
358 | unsigned HasOnlyCMembers : 1; |
359 | |
360 | /// True if any field has an in-class initializer, including those |
361 | /// within anonymous unions or structs. |
362 | unsigned HasInClassInitializer : 1; |
363 | |
364 | /// True if any field is of reference type, and does not have an |
365 | /// in-class initializer. |
366 | /// |
367 | /// In this case, value-initialization of this class is illegal in C++98 |
368 | /// even if the class has a trivial default constructor. |
369 | unsigned HasUninitializedReferenceMember : 1; |
370 | |
371 | /// True if any non-mutable field whose type doesn't have a user- |
372 | /// provided default ctor also doesn't have an in-class initializer. |
373 | unsigned HasUninitializedFields : 1; |
374 | |
375 | /// True if there are any member using-declarations that inherit |
376 | /// constructors from a base class. |
377 | unsigned HasInheritedConstructor : 1; |
378 | |
379 | /// True if there are any member using-declarations named |
380 | /// 'operator='. |
381 | unsigned HasInheritedAssignment : 1; |
382 | |
383 | /// These flags are \c true if a defaulted corresponding special |
384 | /// member can't be fully analyzed without performing overload resolution. |
385 | /// @{ |
386 | unsigned NeedOverloadResolutionForCopyConstructor : 1; |
387 | unsigned NeedOverloadResolutionForMoveConstructor : 1; |
388 | unsigned NeedOverloadResolutionForMoveAssignment : 1; |
389 | unsigned NeedOverloadResolutionForDestructor : 1; |
390 | /// @} |
391 | |
392 | /// These flags are \c true if an implicit defaulted corresponding |
393 | /// special member would be defined as deleted. |
394 | /// @{ |
395 | unsigned DefaultedCopyConstructorIsDeleted : 1; |
396 | unsigned DefaultedMoveConstructorIsDeleted : 1; |
397 | unsigned DefaultedMoveAssignmentIsDeleted : 1; |
398 | unsigned DefaultedDestructorIsDeleted : 1; |
399 | /// @} |
400 | |
401 | /// The trivial special members which this class has, per |
402 | /// C++11 [class.ctor]p5, C++11 [class.copy]p12, C++11 [class.copy]p25, |
403 | /// C++11 [class.dtor]p5, or would have if the member were not suppressed. |
404 | /// |
405 | /// This excludes any user-declared but not user-provided special members |
406 | /// which have been declared but not yet defined. |
407 | unsigned HasTrivialSpecialMembers : 6; |
408 | |
409 | /// These bits keep track of the triviality of special functions for the |
410 | /// purpose of calls. Only the bits corresponding to SMF_CopyConstructor, |
411 | /// SMF_MoveConstructor, and SMF_Destructor are meaningful here. |
412 | unsigned HasTrivialSpecialMembersForCall : 6; |
413 | |
414 | /// The declared special members of this class which are known to be |
415 | /// non-trivial. |
416 | /// |
417 | /// This excludes any user-declared but not user-provided special members |
418 | /// which have been declared but not yet defined, and any implicit special |
419 | /// members which have not yet been declared. |
420 | unsigned DeclaredNonTrivialSpecialMembers : 6; |
421 | |
422 | /// These bits keep track of the declared special members that are |
423 | /// non-trivial for the purpose of calls. |
424 | /// Only the bits corresponding to SMF_CopyConstructor, |
425 | /// SMF_MoveConstructor, and SMF_Destructor are meaningful here. |
426 | unsigned DeclaredNonTrivialSpecialMembersForCall : 6; |
427 | |
428 | /// True when this class has a destructor with no semantic effect. |
429 | unsigned HasIrrelevantDestructor : 1; |
430 | |
431 | /// True when this class has at least one user-declared constexpr |
432 | /// constructor which is neither the copy nor move constructor. |
433 | unsigned HasConstexprNonCopyMoveConstructor : 1; |
434 | |
435 | /// True if this class has a (possibly implicit) defaulted default |
436 | /// constructor. |
437 | unsigned HasDefaultedDefaultConstructor : 1; |
438 | |
439 | /// True if a defaulted default constructor for this class would |
440 | /// be constexpr. |
441 | unsigned DefaultedDefaultConstructorIsConstexpr : 1; |
442 | |
443 | /// True if this class has a constexpr default constructor. |
444 | /// |
445 | /// This is true for either a user-declared constexpr default constructor |
446 | /// or an implicitly declared constexpr default constructor. |
447 | unsigned HasConstexprDefaultConstructor : 1; |
448 | |
449 | /// True if a defaulted destructor for this class would be constexpr. |
450 | unsigned DefaultedDestructorIsConstexpr : 1; |
451 | |
452 | /// True when this class contains at least one non-static data |
453 | /// member or base class of non-literal or volatile type. |
454 | unsigned HasNonLiteralTypeFieldsOrBases : 1; |
455 | |
456 | /// True when visible conversion functions are already computed |
457 | /// and are available. |
458 | unsigned ComputedVisibleConversions : 1; |
459 | |
460 | /// Whether we have a C++11 user-provided default constructor (not |
461 | /// explicitly deleted or defaulted). |
462 | unsigned UserProvidedDefaultConstructor : 1; |
463 | |
464 | /// The special members which have been declared for this class, |
465 | /// either by the user or implicitly. |
466 | unsigned DeclaredSpecialMembers : 6; |
467 | |
468 | /// Whether an implicit copy constructor could have a const-qualified |
469 | /// parameter, for initializing virtual bases and for other subobjects. |
470 | unsigned ImplicitCopyConstructorCanHaveConstParamForVBase : 1; |
471 | unsigned ImplicitCopyConstructorCanHaveConstParamForNonVBase : 1; |
472 | |
473 | /// Whether an implicit copy assignment operator would have a |
474 | /// const-qualified parameter. |
475 | unsigned ImplicitCopyAssignmentHasConstParam : 1; |
476 | |
477 | /// Whether any declared copy constructor has a const-qualified |
478 | /// parameter. |
479 | unsigned HasDeclaredCopyConstructorWithConstParam : 1; |
480 | |
481 | /// Whether any declared copy assignment operator has either a |
482 | /// const-qualified reference parameter or a non-reference parameter. |
483 | unsigned HasDeclaredCopyAssignmentWithConstParam : 1; |
484 | |
485 | /// Whether this class describes a C++ lambda. |
486 | unsigned IsLambda : 1; |
487 | |
488 | /// Whether we are currently parsing base specifiers. |
489 | unsigned IsParsingBaseSpecifiers : 1; |
490 | |
491 | unsigned HasODRHash : 1; |
492 | |
493 | /// A hash of parts of the class to help in ODR checking. |
494 | unsigned ODRHash = 0; |
495 | |
496 | /// The number of base class specifiers in Bases. |
497 | unsigned NumBases = 0; |
498 | |
499 | /// The number of virtual base class specifiers in VBases. |
500 | unsigned NumVBases = 0; |
501 | |
502 | /// Base classes of this class. |
503 | /// |
504 | /// FIXME: This is wasted space for a union. |
505 | LazyCXXBaseSpecifiersPtr Bases; |
506 | |
507 | /// direct and indirect virtual base classes of this class. |
508 | LazyCXXBaseSpecifiersPtr VBases; |
509 | |
510 | /// The conversion functions of this C++ class (but not its |
511 | /// inherited conversion functions). |
512 | /// |
513 | /// Each of the entries in this overload set is a CXXConversionDecl. |
514 | LazyASTUnresolvedSet Conversions; |
515 | |
516 | /// The conversion functions of this C++ class and all those |
517 | /// inherited conversion functions that are visible in this class. |
518 | /// |
519 | /// Each of the entries in this overload set is a CXXConversionDecl or a |
520 | /// FunctionTemplateDecl. |
521 | LazyASTUnresolvedSet VisibleConversions; |
522 | |
523 | /// The declaration which defines this record. |
524 | CXXRecordDecl *Definition; |
525 | |
526 | /// The first friend declaration in this class, or null if there |
527 | /// aren't any. |
528 | /// |
529 | /// This is actually currently stored in reverse order. |
530 | LazyDeclPtr FirstFriend; |
531 | |
532 | DefinitionData(CXXRecordDecl *D); |
533 | |
534 | /// Retrieve the set of direct base classes. |
535 | CXXBaseSpecifier *getBases() const { |
536 | if (!Bases.isOffset()) |
537 | return Bases.get(nullptr); |
538 | return getBasesSlowCase(); |
539 | } |
540 | |
541 | /// Retrieve the set of virtual base classes. |
542 | CXXBaseSpecifier *getVBases() const { |
543 | if (!VBases.isOffset()) |
544 | return VBases.get(nullptr); |
545 | return getVBasesSlowCase(); |
546 | } |
547 | |
548 | ArrayRef<CXXBaseSpecifier> bases() const { |
549 | return llvm::makeArrayRef(getBases(), NumBases); |
550 | } |
551 | |
552 | ArrayRef<CXXBaseSpecifier> vbases() const { |
553 | return llvm::makeArrayRef(getVBases(), NumVBases); |
554 | } |
555 | |
556 | private: |
557 | CXXBaseSpecifier *getBasesSlowCase() const; |
558 | CXXBaseSpecifier *getVBasesSlowCase() const; |
559 | }; |
560 | |
561 | struct DefinitionData *DefinitionData; |
562 | |
563 | /// Describes a C++ closure type (generated by a lambda expression). |
564 | struct LambdaDefinitionData : public DefinitionData { |
565 | using Capture = LambdaCapture; |
566 | |
567 | /// Whether this lambda is known to be dependent, even if its |
568 | /// context isn't dependent. |
569 | /// |
570 | /// A lambda with a non-dependent context can be dependent if it occurs |
571 | /// within the default argument of a function template, because the |
572 | /// lambda will have been created with the enclosing context as its |
573 | /// declaration context, rather than function. This is an unfortunate |
574 | /// artifact of having to parse the default arguments before. |
575 | unsigned Dependent : 1; |
576 | |
577 | /// Whether this lambda is a generic lambda. |
578 | unsigned IsGenericLambda : 1; |
579 | |
580 | /// The Default Capture. |
581 | unsigned CaptureDefault : 2; |
582 | |
583 | /// The number of captures in this lambda is limited 2^NumCaptures. |
584 | unsigned NumCaptures : 15; |
585 | |
586 | /// The number of explicit captures in this lambda. |
587 | unsigned NumExplicitCaptures : 13; |
588 | |
589 | /// The number used to indicate this lambda expression for name |
590 | /// mangling in the Itanium C++ ABI. |
591 | unsigned ManglingNumber = 0; |
592 | |
593 | /// The declaration that provides context for this lambda, if the |
594 | /// actual DeclContext does not suffice. This is used for lambdas that |
595 | /// occur within default arguments of function parameters within the class |
596 | /// or within a data member initializer. |
597 | LazyDeclPtr ContextDecl; |
598 | |
599 | /// The list of captures, both explicit and implicit, for this |
600 | /// lambda. |
601 | Capture *Captures = nullptr; |
602 | |
603 | /// The type of the call method. |
604 | TypeSourceInfo *MethodTyInfo; |
605 | |
606 | LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info, |
607 | bool Dependent, bool IsGeneric, |
608 | LambdaCaptureDefault CaptureDefault) |
609 | : DefinitionData(D), Dependent(Dependent), IsGenericLambda(IsGeneric), |
610 | CaptureDefault(CaptureDefault), NumCaptures(0), NumExplicitCaptures(0), |
611 | MethodTyInfo(Info) { |
612 | IsLambda = true; |
613 | |
614 | // C++1z [expr.prim.lambda]p4: |
615 | // This class type is not an aggregate type. |
616 | Aggregate = false; |
617 | PlainOldData = false; |
618 | } |
619 | }; |
620 | |
621 | struct DefinitionData *dataPtr() const { |
622 | // Complete the redecl chain (if necessary). |
623 | getMostRecentDecl(); |
624 | return DefinitionData; |
625 | } |
626 | |
627 | struct DefinitionData &data() const { |
628 | auto *DD = dataPtr(); |
629 | assert(DD && "queried property of class with no definition")((DD && "queried property of class with no definition" ) ? static_cast<void> (0) : __assert_fail ("DD && \"queried property of class with no definition\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 629, __PRETTY_FUNCTION__)); |
630 | return *DD; |
631 | } |
632 | |
633 | struct LambdaDefinitionData &getLambdaData() const { |
634 | // No update required: a merged definition cannot change any lambda |
635 | // properties. |
636 | auto *DD = DefinitionData; |
637 | assert(DD && DD->IsLambda && "queried lambda property of non-lambda class")((DD && DD->IsLambda && "queried lambda property of non-lambda class" ) ? static_cast<void> (0) : __assert_fail ("DD && DD->IsLambda && \"queried lambda property of non-lambda class\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 637, __PRETTY_FUNCTION__)); |
638 | return static_cast<LambdaDefinitionData&>(*DD); |
639 | } |
640 | |
641 | /// The template or declaration that this declaration |
642 | /// describes or was instantiated from, respectively. |
643 | /// |
644 | /// For non-templates, this value will be null. For record |
645 | /// declarations that describe a class template, this will be a |
646 | /// pointer to a ClassTemplateDecl. For member |
647 | /// classes of class template specializations, this will be the |
648 | /// MemberSpecializationInfo referring to the member class that was |
649 | /// instantiated or specialized. |
650 | llvm::PointerUnion<ClassTemplateDecl *, MemberSpecializationInfo *> |
651 | TemplateOrInstantiation; |
652 | |
653 | /// Called from setBases and addedMember to notify the class that a |
654 | /// direct or virtual base class or a member of class type has been added. |
655 | void addedClassSubobject(CXXRecordDecl *Base); |
656 | |
657 | /// Notify the class that member has been added. |
658 | /// |
659 | /// This routine helps maintain information about the class based on which |
660 | /// members have been added. It will be invoked by DeclContext::addDecl() |
661 | /// whenever a member is added to this record. |
662 | void addedMember(Decl *D); |
663 | |
664 | void markedVirtualFunctionPure(); |
665 | |
666 | /// Get the head of our list of friend declarations, possibly |
667 | /// deserializing the friends from an external AST source. |
668 | FriendDecl *getFirstFriend() const; |
669 | |
670 | /// Determine whether this class has an empty base class subobject of type X |
671 | /// or of one of the types that might be at offset 0 within X (per the C++ |
672 | /// "standard layout" rules). |
673 | bool hasSubobjectAtOffsetZeroOfEmptyBaseType(ASTContext &Ctx, |
674 | const CXXRecordDecl *X); |
675 | |
676 | protected: |
677 | CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, DeclContext *DC, |
678 | SourceLocation StartLoc, SourceLocation IdLoc, |
679 | IdentifierInfo *Id, CXXRecordDecl *PrevDecl); |
680 | |
681 | public: |
682 | /// Iterator that traverses the base classes of a class. |
683 | using base_class_iterator = CXXBaseSpecifier *; |
684 | |
685 | /// Iterator that traverses the base classes of a class. |
686 | using base_class_const_iterator = const CXXBaseSpecifier *; |
687 | |
688 | CXXRecordDecl *getCanonicalDecl() override { |
689 | return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); |
690 | } |
691 | |
692 | const CXXRecordDecl *getCanonicalDecl() const { |
693 | return const_cast<CXXRecordDecl*>(this)->getCanonicalDecl(); |
694 | } |
695 | |
696 | CXXRecordDecl *getPreviousDecl() { |
697 | return cast_or_null<CXXRecordDecl>( |
698 | static_cast<RecordDecl *>(this)->getPreviousDecl()); |
699 | } |
700 | |
701 | const CXXRecordDecl *getPreviousDecl() const { |
702 | return const_cast<CXXRecordDecl*>(this)->getPreviousDecl(); |
703 | } |
704 | |
705 | CXXRecordDecl *getMostRecentDecl() { |
706 | return cast<CXXRecordDecl>( |
707 | static_cast<RecordDecl *>(this)->getMostRecentDecl()); |
708 | } |
709 | |
710 | const CXXRecordDecl *getMostRecentDecl() const { |
711 | return const_cast<CXXRecordDecl*>(this)->getMostRecentDecl(); |
712 | } |
713 | |
714 | CXXRecordDecl *getMostRecentNonInjectedDecl() { |
715 | CXXRecordDecl *Recent = |
716 | static_cast<CXXRecordDecl *>(this)->getMostRecentDecl(); |
717 | while (Recent->isInjectedClassName()) { |
718 | // FIXME: Does injected class name need to be in the redeclarations chain? |
719 | assert(Recent->getPreviousDecl())((Recent->getPreviousDecl()) ? static_cast<void> (0) : __assert_fail ("Recent->getPreviousDecl()", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 719, __PRETTY_FUNCTION__)); |
720 | Recent = Recent->getPreviousDecl(); |
721 | } |
722 | return Recent; |
723 | } |
724 | |
725 | const CXXRecordDecl *getMostRecentNonInjectedDecl() const { |
726 | return const_cast<CXXRecordDecl*>(this)->getMostRecentNonInjectedDecl(); |
727 | } |
728 | |
729 | CXXRecordDecl *getDefinition() const { |
730 | // We only need an update if we don't already know which |
731 | // declaration is the definition. |
732 | auto *DD = DefinitionData ? DefinitionData : dataPtr(); |
733 | return DD ? DD->Definition : nullptr; |
734 | } |
735 | |
736 | bool hasDefinition() const { return DefinitionData || dataPtr(); } |
737 | |
738 | static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC, |
739 | SourceLocation StartLoc, SourceLocation IdLoc, |
740 | IdentifierInfo *Id, |
741 | CXXRecordDecl *PrevDecl = nullptr, |
742 | bool DelayTypeCreation = false); |
743 | static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC, |
744 | TypeSourceInfo *Info, SourceLocation Loc, |
745 | bool DependentLambda, bool IsGeneric, |
746 | LambdaCaptureDefault CaptureDefault); |
747 | static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID); |
748 | |
749 | bool isDynamicClass() const { |
750 | return data().Polymorphic || data().NumVBases != 0; |
751 | } |
752 | |
753 | /// @returns true if class is dynamic or might be dynamic because the |
754 | /// definition is incomplete of dependent. |
755 | bool mayBeDynamicClass() const { |
756 | return !hasDefinition() || isDynamicClass() || hasAnyDependentBases(); |
757 | } |
758 | |
759 | /// @returns true if class is non dynamic or might be non dynamic because the |
760 | /// definition is incomplete of dependent. |
761 | bool mayBeNonDynamicClass() const { |
762 | return !hasDefinition() || !isDynamicClass() || hasAnyDependentBases(); |
763 | } |
764 | |
765 | void setIsParsingBaseSpecifiers() { data().IsParsingBaseSpecifiers = true; } |
766 | |
767 | bool isParsingBaseSpecifiers() const { |
768 | return data().IsParsingBaseSpecifiers; |
769 | } |
770 | |
771 | unsigned getODRHash() const; |
772 | |
773 | /// Sets the base classes of this struct or class. |
774 | void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases); |
775 | |
776 | /// Retrieves the number of base classes of this class. |
777 | unsigned getNumBases() const { return data().NumBases; } |
778 | |
779 | using base_class_range = llvm::iterator_range<base_class_iterator>; |
780 | using base_class_const_range = |
781 | llvm::iterator_range<base_class_const_iterator>; |
782 | |
783 | base_class_range bases() { |
784 | return base_class_range(bases_begin(), bases_end()); |
785 | } |
786 | base_class_const_range bases() const { |
787 | return base_class_const_range(bases_begin(), bases_end()); |
788 | } |
789 | |
790 | base_class_iterator bases_begin() { return data().getBases(); } |
791 | base_class_const_iterator bases_begin() const { return data().getBases(); } |
792 | base_class_iterator bases_end() { return bases_begin() + data().NumBases; } |
793 | base_class_const_iterator bases_end() const { |
794 | return bases_begin() + data().NumBases; |
795 | } |
796 | |
797 | /// Retrieves the number of virtual base classes of this class. |
798 | unsigned getNumVBases() const { return data().NumVBases; } |
799 | |
800 | base_class_range vbases() { |
801 | return base_class_range(vbases_begin(), vbases_end()); |
802 | } |
803 | base_class_const_range vbases() const { |
804 | return base_class_const_range(vbases_begin(), vbases_end()); |
805 | } |
806 | |
807 | base_class_iterator vbases_begin() { return data().getVBases(); } |
808 | base_class_const_iterator vbases_begin() const { return data().getVBases(); } |
809 | base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; } |
810 | base_class_const_iterator vbases_end() const { |
811 | return vbases_begin() + data().NumVBases; |
812 | } |
813 | |
814 | /// Determine whether this class has any dependent base classes which |
815 | /// are not the current instantiation. |
816 | bool hasAnyDependentBases() const; |
817 | |
818 | /// Iterator access to method members. The method iterator visits |
819 | /// all method members of the class, including non-instance methods, |
820 | /// special methods, etc. |
821 | using method_iterator = specific_decl_iterator<CXXMethodDecl>; |
822 | using method_range = |
823 | llvm::iterator_range<specific_decl_iterator<CXXMethodDecl>>; |
824 | |
825 | method_range methods() const { |
826 | return method_range(method_begin(), method_end()); |
827 | } |
828 | |
829 | /// Method begin iterator. Iterates in the order the methods |
830 | /// were declared. |
831 | method_iterator method_begin() const { |
832 | return method_iterator(decls_begin()); |
833 | } |
834 | |
835 | /// Method past-the-end iterator. |
836 | method_iterator method_end() const { |
837 | return method_iterator(decls_end()); |
838 | } |
839 | |
840 | /// Iterator access to constructor members. |
841 | using ctor_iterator = specific_decl_iterator<CXXConstructorDecl>; |
842 | using ctor_range = |
843 | llvm::iterator_range<specific_decl_iterator<CXXConstructorDecl>>; |
844 | |
845 | ctor_range ctors() const { return ctor_range(ctor_begin(), ctor_end()); } |
846 | |
847 | ctor_iterator ctor_begin() const { |
848 | return ctor_iterator(decls_begin()); |
849 | } |
850 | |
851 | ctor_iterator ctor_end() const { |
852 | return ctor_iterator(decls_end()); |
853 | } |
854 | |
855 | /// An iterator over friend declarations. All of these are defined |
856 | /// in DeclFriend.h. |
857 | class friend_iterator; |
858 | using friend_range = llvm::iterator_range<friend_iterator>; |
859 | |
860 | friend_range friends() const; |
861 | friend_iterator friend_begin() const; |
862 | friend_iterator friend_end() const; |
863 | void pushFriendDecl(FriendDecl *FD); |
864 | |
865 | /// Determines whether this record has any friends. |
866 | bool hasFriends() const { |
867 | return data().FirstFriend.isValid(); |
868 | } |
869 | |
870 | /// \c true if a defaulted copy constructor for this class would be |
871 | /// deleted. |
872 | bool defaultedCopyConstructorIsDeleted() const { |
873 | assert((!needsOverloadResolutionForCopyConstructor() ||(((!needsOverloadResolutionForCopyConstructor() || (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForCopyConstructor() || (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 875, __PRETTY_FUNCTION__)) |
874 | (data().DeclaredSpecialMembers & SMF_CopyConstructor)) &&(((!needsOverloadResolutionForCopyConstructor() || (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForCopyConstructor() || (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 875, __PRETTY_FUNCTION__)) |
875 | "this property has not yet been computed by Sema")(((!needsOverloadResolutionForCopyConstructor() || (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForCopyConstructor() || (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 875, __PRETTY_FUNCTION__)); |
876 | return data().DefaultedCopyConstructorIsDeleted; |
877 | } |
878 | |
879 | /// \c true if a defaulted move constructor for this class would be |
880 | /// deleted. |
881 | bool defaultedMoveConstructorIsDeleted() const { |
882 | assert((!needsOverloadResolutionForMoveConstructor() ||(((!needsOverloadResolutionForMoveConstructor() || (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForMoveConstructor() || (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 884, __PRETTY_FUNCTION__)) |
883 | (data().DeclaredSpecialMembers & SMF_MoveConstructor)) &&(((!needsOverloadResolutionForMoveConstructor() || (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForMoveConstructor() || (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 884, __PRETTY_FUNCTION__)) |
884 | "this property has not yet been computed by Sema")(((!needsOverloadResolutionForMoveConstructor() || (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForMoveConstructor() || (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 884, __PRETTY_FUNCTION__)); |
885 | return data().DefaultedMoveConstructorIsDeleted; |
886 | } |
887 | |
888 | /// \c true if a defaulted destructor for this class would be deleted. |
889 | bool defaultedDestructorIsDeleted() const { |
890 | assert((!needsOverloadResolutionForDestructor() ||(((!needsOverloadResolutionForDestructor() || (data().DeclaredSpecialMembers & SMF_Destructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForDestructor() || (data().DeclaredSpecialMembers & SMF_Destructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 892, __PRETTY_FUNCTION__)) |
891 | (data().DeclaredSpecialMembers & SMF_Destructor)) &&(((!needsOverloadResolutionForDestructor() || (data().DeclaredSpecialMembers & SMF_Destructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForDestructor() || (data().DeclaredSpecialMembers & SMF_Destructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 892, __PRETTY_FUNCTION__)) |
892 | "this property has not yet been computed by Sema")(((!needsOverloadResolutionForDestructor() || (data().DeclaredSpecialMembers & SMF_Destructor)) && "this property has not yet been computed by Sema" ) ? static_cast<void> (0) : __assert_fail ("(!needsOverloadResolutionForDestructor() || (data().DeclaredSpecialMembers & SMF_Destructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 892, __PRETTY_FUNCTION__)); |
893 | return data().DefaultedDestructorIsDeleted; |
894 | } |
895 | |
896 | /// \c true if we know for sure that this class has a single, |
897 | /// accessible, unambiguous copy constructor that is not deleted. |
898 | bool hasSimpleCopyConstructor() const { |
899 | return !hasUserDeclaredCopyConstructor() && |
900 | !data().DefaultedCopyConstructorIsDeleted; |
901 | } |
902 | |
903 | /// \c true if we know for sure that this class has a single, |
904 | /// accessible, unambiguous move constructor that is not deleted. |
905 | bool hasSimpleMoveConstructor() const { |
906 | return !hasUserDeclaredMoveConstructor() && hasMoveConstructor() && |
907 | !data().DefaultedMoveConstructorIsDeleted; |
908 | } |
909 | |
910 | /// \c true if we know for sure that this class has a single, |
911 | /// accessible, unambiguous move assignment operator that is not deleted. |
912 | bool hasSimpleMoveAssignment() const { |
913 | return !hasUserDeclaredMoveAssignment() && hasMoveAssignment() && |
914 | !data().DefaultedMoveAssignmentIsDeleted; |
915 | } |
916 | |
917 | /// \c true if we know for sure that this class has an accessible |
918 | /// destructor that is not deleted. |
919 | bool hasSimpleDestructor() const { |
920 | return !hasUserDeclaredDestructor() && |
921 | !data().DefaultedDestructorIsDeleted; |
922 | } |
923 | |
924 | /// Determine whether this class has any default constructors. |
925 | bool hasDefaultConstructor() const { |
926 | return (data().DeclaredSpecialMembers & SMF_DefaultConstructor) || |
927 | needsImplicitDefaultConstructor(); |
928 | } |
929 | |
930 | /// Determine if we need to declare a default constructor for |
931 | /// this class. |
932 | /// |
933 | /// This value is used for lazy creation of default constructors. |
934 | bool needsImplicitDefaultConstructor() const { |
935 | return !data().UserDeclaredConstructor && |
936 | !(data().DeclaredSpecialMembers & SMF_DefaultConstructor) && |
937 | (!isLambda() || lambdaIsDefaultConstructibleAndAssignable()); |
938 | } |
939 | |
940 | /// Determine whether this class has any user-declared constructors. |
941 | /// |
942 | /// When true, a default constructor will not be implicitly declared. |
943 | bool hasUserDeclaredConstructor() const { |
944 | return data().UserDeclaredConstructor; |
945 | } |
946 | |
947 | /// Whether this class has a user-provided default constructor |
948 | /// per C++11. |
949 | bool hasUserProvidedDefaultConstructor() const { |
950 | return data().UserProvidedDefaultConstructor; |
951 | } |
952 | |
953 | /// Determine whether this class has a user-declared copy constructor. |
954 | /// |
955 | /// When false, a copy constructor will be implicitly declared. |
956 | bool hasUserDeclaredCopyConstructor() const { |
957 | return data().UserDeclaredSpecialMembers & SMF_CopyConstructor; |
958 | } |
959 | |
960 | /// Determine whether this class needs an implicit copy |
961 | /// constructor to be lazily declared. |
962 | bool needsImplicitCopyConstructor() const { |
963 | return !(data().DeclaredSpecialMembers & SMF_CopyConstructor); |
964 | } |
965 | |
966 | /// Determine whether we need to eagerly declare a defaulted copy |
967 | /// constructor for this class. |
968 | bool needsOverloadResolutionForCopyConstructor() const { |
969 | // C++17 [class.copy.ctor]p6: |
970 | // If the class definition declares a move constructor or move assignment |
971 | // operator, the implicitly declared copy constructor is defined as |
972 | // deleted. |
973 | // In MSVC mode, sometimes a declared move assignment does not delete an |
974 | // implicit copy constructor, so defer this choice to Sema. |
975 | if (data().UserDeclaredSpecialMembers & |
976 | (SMF_MoveConstructor | SMF_MoveAssignment)) |
977 | return true; |
978 | return data().NeedOverloadResolutionForCopyConstructor; |
979 | } |
980 | |
981 | /// Determine whether an implicit copy constructor for this type |
982 | /// would have a parameter with a const-qualified reference type. |
983 | bool implicitCopyConstructorHasConstParam() const { |
984 | return data().ImplicitCopyConstructorCanHaveConstParamForNonVBase && |
985 | (isAbstract() || |
986 | data().ImplicitCopyConstructorCanHaveConstParamForVBase); |
987 | } |
988 | |
989 | /// Determine whether this class has a copy constructor with |
990 | /// a parameter type which is a reference to a const-qualified type. |
991 | bool hasCopyConstructorWithConstParam() const { |
992 | return data().HasDeclaredCopyConstructorWithConstParam || |
993 | (needsImplicitCopyConstructor() && |
994 | implicitCopyConstructorHasConstParam()); |
995 | } |
996 | |
997 | /// Whether this class has a user-declared move constructor or |
998 | /// assignment operator. |
999 | /// |
1000 | /// When false, a move constructor and assignment operator may be |
1001 | /// implicitly declared. |
1002 | bool hasUserDeclaredMoveOperation() const { |
1003 | return data().UserDeclaredSpecialMembers & |
1004 | (SMF_MoveConstructor | SMF_MoveAssignment); |
1005 | } |
1006 | |
1007 | /// Determine whether this class has had a move constructor |
1008 | /// declared by the user. |
1009 | bool hasUserDeclaredMoveConstructor() const { |
1010 | return data().UserDeclaredSpecialMembers & SMF_MoveConstructor; |
1011 | } |
1012 | |
1013 | /// Determine whether this class has a move constructor. |
1014 | bool hasMoveConstructor() const { |
1015 | return (data().DeclaredSpecialMembers & SMF_MoveConstructor) || |
1016 | needsImplicitMoveConstructor(); |
1017 | } |
1018 | |
1019 | /// Set that we attempted to declare an implicit copy |
1020 | /// constructor, but overload resolution failed so we deleted it. |
1021 | void setImplicitCopyConstructorIsDeleted() { |
1022 | assert((data().DefaultedCopyConstructorIsDeleted ||(((data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor ()) && "Copy constructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor()) && \"Copy constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 1024, __PRETTY_FUNCTION__)) |
1023 | needsOverloadResolutionForCopyConstructor()) &&(((data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor ()) && "Copy constructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor()) && \"Copy constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 1024, __PRETTY_FUNCTION__)) |
1024 | "Copy constructor should not be deleted")(((data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor ()) && "Copy constructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor()) && \"Copy constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 1024, __PRETTY_FUNCTION__)); |
1025 | data().DefaultedCopyConstructorIsDeleted = true; |
1026 | } |
1027 | |
1028 | /// Set that we attempted to declare an implicit move |
1029 | /// constructor, but overload resolution failed so we deleted it. |
1030 | void setImplicitMoveConstructorIsDeleted() { |
1031 | assert((data().DefaultedMoveConstructorIsDeleted ||(((data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor ()) && "move constructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor()) && \"move constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 1033, __PRETTY_FUNCTION__)) |
1032 | needsOverloadResolutionForMoveConstructor()) &&(((data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor ()) && "move constructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor()) && \"move constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 1033, __PRETTY_FUNCTION__)) |
1033 | "move constructor should not be deleted")(((data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor ()) && "move constructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor()) && \"move constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 1033, __PRETTY_FUNCTION__)); |
1034 | data().DefaultedMoveConstructorIsDeleted = true; |
1035 | } |
1036 | |
1037 | /// Set that we attempted to declare an implicit destructor, |
1038 | /// but overload resolution failed so we deleted it. |
1039 | void setImplicitDestructorIsDeleted() { |
1040 | assert((data().DefaultedDestructorIsDeleted ||(((data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor ()) && "destructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor()) && \"destructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 1042, __PRETTY_FUNCTION__)) |
1041 | needsOverloadResolutionForDestructor()) &&(((data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor ()) && "destructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor()) && \"destructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 1042, __PRETTY_FUNCTION__)) |
1042 | "destructor should not be deleted")(((data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor ()) && "destructor should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor()) && \"destructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 1042, __PRETTY_FUNCTION__)); |
1043 | data().DefaultedDestructorIsDeleted = true; |
1044 | } |
1045 | |
1046 | /// Determine whether this class should get an implicit move |
1047 | /// constructor or if any existing special member function inhibits this. |
1048 | bool needsImplicitMoveConstructor() const { |
1049 | return !(data().DeclaredSpecialMembers & SMF_MoveConstructor) && |
1050 | !hasUserDeclaredCopyConstructor() && |
1051 | !hasUserDeclaredCopyAssignment() && |
1052 | !hasUserDeclaredMoveAssignment() && |
1053 | !hasUserDeclaredDestructor(); |
1054 | } |
1055 | |
1056 | /// Determine whether we need to eagerly declare a defaulted move |
1057 | /// constructor for this class. |
1058 | bool needsOverloadResolutionForMoveConstructor() const { |
1059 | return data().NeedOverloadResolutionForMoveConstructor; |
1060 | } |
1061 | |
1062 | /// Determine whether this class has a user-declared copy assignment |
1063 | /// operator. |
1064 | /// |
1065 | /// When false, a copy assignment operator will be implicitly declared. |
1066 | bool hasUserDeclaredCopyAssignment() const { |
1067 | return data().UserDeclaredSpecialMembers & SMF_CopyAssignment; |
1068 | } |
1069 | |
1070 | /// Determine whether this class needs an implicit copy |
1071 | /// assignment operator to be lazily declared. |
1072 | bool needsImplicitCopyAssignment() const { |
1073 | return !(data().DeclaredSpecialMembers & SMF_CopyAssignment); |
1074 | } |
1075 | |
1076 | /// Determine whether we need to eagerly declare a defaulted copy |
1077 | /// assignment operator for this class. |
1078 | bool needsOverloadResolutionForCopyAssignment() const { |
1079 | return data().HasMutableFields; |
1080 | } |
1081 | |
1082 | /// Determine whether an implicit copy assignment operator for this |
1083 | /// type would have a parameter with a const-qualified reference type. |
1084 | bool implicitCopyAssignmentHasConstParam() const { |
1085 | return data().ImplicitCopyAssignmentHasConstParam; |
1086 | } |
1087 | |
1088 | /// Determine whether this class has a copy assignment operator with |
1089 | /// a parameter type which is a reference to a const-qualified type or is not |
1090 | /// a reference. |
1091 | bool hasCopyAssignmentWithConstParam() const { |
1092 | return data().HasDeclaredCopyAssignmentWithConstParam || |
1093 | (needsImplicitCopyAssignment() && |
1094 | implicitCopyAssignmentHasConstParam()); |
1095 | } |
1096 | |
1097 | /// Determine whether this class has had a move assignment |
1098 | /// declared by the user. |
1099 | bool hasUserDeclaredMoveAssignment() const { |
1100 | return data().UserDeclaredSpecialMembers & SMF_MoveAssignment; |
1101 | } |
1102 | |
1103 | /// Determine whether this class has a move assignment operator. |
1104 | bool hasMoveAssignment() const { |
1105 | return (data().DeclaredSpecialMembers & SMF_MoveAssignment) || |
1106 | needsImplicitMoveAssignment(); |
1107 | } |
1108 | |
1109 | /// Set that we attempted to declare an implicit move assignment |
1110 | /// operator, but overload resolution failed so we deleted it. |
1111 | void setImplicitMoveAssignmentIsDeleted() { |
1112 | assert((data().DefaultedMoveAssignmentIsDeleted ||(((data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment ()) && "move assignment should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment()) && \"move assignment should not be deleted\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 1114, __PRETTY_FUNCTION__)) |
1113 | needsOverloadResolutionForMoveAssignment()) &&(((data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment ()) && "move assignment should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment()) && \"move assignment should not be deleted\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 1114, __PRETTY_FUNCTION__)) |
1114 | "move assignment should not be deleted")(((data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment ()) && "move assignment should not be deleted") ? static_cast <void> (0) : __assert_fail ("(data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment()) && \"move assignment should not be deleted\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 1114, __PRETTY_FUNCTION__)); |
1115 | data().DefaultedMoveAssignmentIsDeleted = true; |
1116 | } |
1117 | |
1118 | /// Determine whether this class should get an implicit move |
1119 | /// assignment operator or if any existing special member function inhibits |
1120 | /// this. |
1121 | bool needsImplicitMoveAssignment() const { |
1122 | return !(data().DeclaredSpecialMembers & SMF_MoveAssignment) && |
1123 | !hasUserDeclaredCopyConstructor() && |
1124 | !hasUserDeclaredCopyAssignment() && |
1125 | !hasUserDeclaredMoveConstructor() && |
1126 | !hasUserDeclaredDestructor() && |
1127 | (!isLambda() || lambdaIsDefaultConstructibleAndAssignable()); |
1128 | } |
1129 | |
1130 | /// Determine whether we need to eagerly declare a move assignment |
1131 | /// operator for this class. |
1132 | bool needsOverloadResolutionForMoveAssignment() const { |
1133 | return data().NeedOverloadResolutionForMoveAssignment; |
1134 | } |
1135 | |
1136 | /// Determine whether this class has a user-declared destructor. |
1137 | /// |
1138 | /// When false, a destructor will be implicitly declared. |
1139 | bool hasUserDeclaredDestructor() const { |
1140 | return data().UserDeclaredSpecialMembers & SMF_Destructor; |
1141 | } |
1142 | |
1143 | /// Determine whether this class needs an implicit destructor to |
1144 | /// be lazily declared. |
1145 | bool needsImplicitDestructor() const { |
1146 | return !(data().DeclaredSpecialMembers & SMF_Destructor); |
1147 | } |
1148 | |
1149 | /// Determine whether we need to eagerly declare a destructor for this |
1150 | /// class. |
1151 | bool needsOverloadResolutionForDestructor() const { |
1152 | return data().NeedOverloadResolutionForDestructor; |
1153 | } |
1154 | |
1155 | /// Determine whether this class describes a lambda function object. |
1156 | bool isLambda() const { |
1157 | // An update record can't turn a non-lambda into a lambda. |
1158 | auto *DD = DefinitionData; |
1159 | return DD && DD->IsLambda; |
1160 | } |
1161 | |
1162 | /// Determine whether this class describes a generic |
1163 | /// lambda function object (i.e. function call operator is |
1164 | /// a template). |
1165 | bool isGenericLambda() const; |
1166 | |
1167 | /// Determine whether this lambda should have an implicit default constructor |
1168 | /// and copy and move assignment operators. |
1169 | bool lambdaIsDefaultConstructibleAndAssignable() const; |
1170 | |
1171 | /// Retrieve the lambda call operator of the closure type |
1172 | /// if this is a closure type. |
1173 | CXXMethodDecl *getLambdaCallOperator() const; |
1174 | |
1175 | /// Retrieve the dependent lambda call operator of the closure type |
1176 | /// if this is a templated closure type. |
1177 | FunctionTemplateDecl *getDependentLambdaCallOperator() const; |
1178 | |
1179 | /// Retrieve the lambda static invoker, the address of which |
1180 | /// is returned by the conversion operator, and the body of which |
1181 | /// is forwarded to the lambda call operator. |
1182 | CXXMethodDecl *getLambdaStaticInvoker() const; |
1183 | |
1184 | /// Retrieve the generic lambda's template parameter list. |
1185 | /// Returns null if the class does not represent a lambda or a generic |
1186 | /// lambda. |
1187 | TemplateParameterList *getGenericLambdaTemplateParameterList() const; |
1188 | |
1189 | /// Retrieve the lambda template parameters that were specified explicitly. |
1190 | ArrayRef<NamedDecl *> getLambdaExplicitTemplateParameters() const; |
1191 | |
1192 | LambdaCaptureDefault getLambdaCaptureDefault() const { |
1193 | assert(isLambda())((isLambda()) ? static_cast<void> (0) : __assert_fail ( "isLambda()", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 1193, __PRETTY_FUNCTION__)); |
1194 | return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault); |
1195 | } |
1196 | |
1197 | /// For a closure type, retrieve the mapping from captured |
1198 | /// variables and \c this to the non-static data members that store the |
1199 | /// values or references of the captures. |
1200 | /// |
1201 | /// \param Captures Will be populated with the mapping from captured |
1202 | /// variables to the corresponding fields. |
1203 | /// |
1204 | /// \param ThisCapture Will be set to the field declaration for the |
1205 | /// \c this capture. |
1206 | /// |
1207 | /// \note No entries will be added for init-captures, as they do not capture |
1208 | /// variables. |
1209 | void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures, |
1210 | FieldDecl *&ThisCapture) const; |
1211 | |
1212 | using capture_const_iterator = const LambdaCapture *; |
1213 | using capture_const_range = llvm::iterator_range<capture_const_iterator>; |
1214 | |
1215 | capture_const_range captures() const { |
1216 | return capture_const_range(captures_begin(), captures_end()); |
1217 | } |
1218 | |
1219 | capture_const_iterator captures_begin() const { |
1220 | return isLambda() ? getLambdaData().Captures : nullptr; |
1221 | } |
1222 | |
1223 | capture_const_iterator captures_end() const { |
1224 | return isLambda() ? captures_begin() + getLambdaData().NumCaptures |
1225 | : nullptr; |
1226 | } |
1227 | |
1228 | using conversion_iterator = UnresolvedSetIterator; |
1229 | |
1230 | conversion_iterator conversion_begin() const { |
1231 | return data().Conversions.get(getASTContext()).begin(); |
1232 | } |
1233 | |
1234 | conversion_iterator conversion_end() const { |
1235 | return data().Conversions.get(getASTContext()).end(); |
1236 | } |
1237 | |
1238 | /// Removes a conversion function from this class. The conversion |
1239 | /// function must currently be a member of this class. Furthermore, |
1240 | /// this class must currently be in the process of being defined. |
1241 | void removeConversion(const NamedDecl *Old); |
1242 | |
1243 | /// Get all conversion functions visible in current class, |
1244 | /// including conversion function templates. |
1245 | llvm::iterator_range<conversion_iterator> getVisibleConversionFunctions(); |
1246 | |
1247 | /// Determine whether this class is an aggregate (C++ [dcl.init.aggr]), |
1248 | /// which is a class with no user-declared constructors, no private |
1249 | /// or protected non-static data members, no base classes, and no virtual |
1250 | /// functions (C++ [dcl.init.aggr]p1). |
1251 | bool isAggregate() const { return data().Aggregate; } |
1252 | |
1253 | /// Whether this class has any in-class initializers |
1254 | /// for non-static data members (including those in anonymous unions or |
1255 | /// structs). |
1256 | bool hasInClassInitializer() const { return data().HasInClassInitializer; } |
1257 | |
1258 | /// Whether this class or any of its subobjects has any members of |
1259 | /// reference type which would make value-initialization ill-formed. |
1260 | /// |
1261 | /// Per C++03 [dcl.init]p5: |
1262 | /// - if T is a non-union class type without a user-declared constructor, |
1263 | /// then every non-static data member and base-class component of T is |
1264 | /// value-initialized [...] A program that calls for [...] |
1265 | /// value-initialization of an entity of reference type is ill-formed. |
1266 | bool hasUninitializedReferenceMember() const { |
1267 | return !isUnion() && !hasUserDeclaredConstructor() && |
1268 | data().HasUninitializedReferenceMember; |
1269 | } |
1270 | |
1271 | /// Whether this class is a POD-type (C++ [class]p4) |
1272 | /// |
1273 | /// For purposes of this function a class is POD if it is an aggregate |
1274 | /// that has no non-static non-POD data members, no reference data |
1275 | /// members, no user-defined copy assignment operator and no |
1276 | /// user-defined destructor. |
1277 | /// |
1278 | /// Note that this is the C++ TR1 definition of POD. |
1279 | bool isPOD() const { return data().PlainOldData; } |
1280 | |
1281 | /// True if this class is C-like, without C++-specific features, e.g. |
1282 | /// it contains only public fields, no bases, tag kind is not 'class', etc. |
1283 | bool isCLike() const; |
1284 | |
1285 | /// Determine whether this is an empty class in the sense of |
1286 | /// (C++11 [meta.unary.prop]). |
1287 | /// |
1288 | /// The CXXRecordDecl is a class type, but not a union type, |
1289 | /// with no non-static data members other than bit-fields of length 0, |
1290 | /// no virtual member functions, no virtual base classes, |
1291 | /// and no base class B for which is_empty<B>::value is false. |
1292 | /// |
1293 | /// \note This does NOT include a check for union-ness. |
1294 | bool isEmpty() const { return data().Empty; } |
1295 | |
1296 | bool hasPrivateFields() const { |
1297 | return data().HasPrivateFields; |
1298 | } |
1299 | |
1300 | bool hasProtectedFields() const { |
1301 | return data().HasProtectedFields; |
1302 | } |
1303 | |
1304 | /// Determine whether this class has direct non-static data members. |
1305 | bool hasDirectFields() const { |
1306 | auto &D = data(); |
1307 | return D.HasPublicFields || D.HasProtectedFields || D.HasPrivateFields; |
1308 | } |
1309 | |
1310 | /// Whether this class is polymorphic (C++ [class.virtual]), |
1311 | /// which means that the class contains or inherits a virtual function. |
1312 | bool isPolymorphic() const { return data().Polymorphic; } |
1313 | |
1314 | /// Determine whether this class has a pure virtual function. |
1315 | /// |
1316 | /// The class is is abstract per (C++ [class.abstract]p2) if it declares |
1317 | /// a pure virtual function or inherits a pure virtual function that is |
1318 | /// not overridden. |
1319 | bool isAbstract() const { return data().Abstract; } |
1320 | |
1321 | /// Determine whether this class is standard-layout per |
1322 | /// C++ [class]p7. |
1323 | bool isStandardLayout() const { return data().IsStandardLayout; } |
1324 | |
1325 | /// Determine whether this class was standard-layout per |
1326 | /// C++11 [class]p7, specifically using the C++11 rules without any DRs. |
1327 | bool isCXX11StandardLayout() const { return data().IsCXX11StandardLayout; } |
1328 | |
1329 | /// Determine whether this class, or any of its class subobjects, |
1330 | /// contains a mutable field. |
1331 | bool hasMutableFields() const { return data().HasMutableFields; } |
1332 | |
1333 | /// Determine whether this class has any variant members. |
1334 | bool hasVariantMembers() const { return data().HasVariantMembers; } |
1335 | |
1336 | /// Determine whether this class has a trivial default constructor |
1337 | /// (C++11 [class.ctor]p5). |
1338 | bool hasTrivialDefaultConstructor() const { |
1339 | return hasDefaultConstructor() && |
1340 | (data().HasTrivialSpecialMembers & SMF_DefaultConstructor); |
1341 | } |
1342 | |
1343 | /// Determine whether this class has a non-trivial default constructor |
1344 | /// (C++11 [class.ctor]p5). |
1345 | bool hasNonTrivialDefaultConstructor() const { |
1346 | return (data().DeclaredNonTrivialSpecialMembers & SMF_DefaultConstructor) || |
1347 | (needsImplicitDefaultConstructor() && |
1348 | !(data().HasTrivialSpecialMembers & SMF_DefaultConstructor)); |
1349 | } |
1350 | |
1351 | /// Determine whether this class has at least one constexpr constructor |
1352 | /// other than the copy or move constructors. |
1353 | bool hasConstexprNonCopyMoveConstructor() const { |
1354 | return data().HasConstexprNonCopyMoveConstructor || |
1355 | (needsImplicitDefaultConstructor() && |
1356 | defaultedDefaultConstructorIsConstexpr()); |
1357 | } |
1358 | |
1359 | /// Determine whether a defaulted default constructor for this class |
1360 | /// would be constexpr. |
1361 | bool defaultedDefaultConstructorIsConstexpr() const { |
1362 | return data().DefaultedDefaultConstructorIsConstexpr && |
1363 | (!isUnion() || hasInClassInitializer() || !hasVariantMembers() || |
1364 | getASTContext().getLangOpts().CPlusPlus2a); |
1365 | } |
1366 | |
1367 | /// Determine whether this class has a constexpr default constructor. |
1368 | bool hasConstexprDefaultConstructor() const { |
1369 | return data().HasConstexprDefaultConstructor || |
1370 | (needsImplicitDefaultConstructor() && |
1371 | defaultedDefaultConstructorIsConstexpr()); |
1372 | } |
1373 | |
1374 | /// Determine whether this class has a trivial copy constructor |
1375 | /// (C++ [class.copy]p6, C++11 [class.copy]p12) |
1376 | bool hasTrivialCopyConstructor() const { |
1377 | return data().HasTrivialSpecialMembers & SMF_CopyConstructor; |
1378 | } |
1379 | |
1380 | bool hasTrivialCopyConstructorForCall() const { |
1381 | return data().HasTrivialSpecialMembersForCall & SMF_CopyConstructor; |
1382 | } |
1383 | |
1384 | /// Determine whether this class has a non-trivial copy constructor |
1385 | /// (C++ [class.copy]p6, C++11 [class.copy]p12) |
1386 | bool hasNonTrivialCopyConstructor() const { |
1387 | return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor || |
1388 | !hasTrivialCopyConstructor(); |
1389 | } |
1390 | |
1391 | bool hasNonTrivialCopyConstructorForCall() const { |
1392 | return (data().DeclaredNonTrivialSpecialMembersForCall & |
1393 | SMF_CopyConstructor) || |
1394 | !hasTrivialCopyConstructorForCall(); |
1395 | } |
1396 | |
1397 | /// Determine whether this class has a trivial move constructor |
1398 | /// (C++11 [class.copy]p12) |
1399 | bool hasTrivialMoveConstructor() const { |
1400 | return hasMoveConstructor() && |
1401 | (data().HasTrivialSpecialMembers & SMF_MoveConstructor); |
1402 | } |
1403 | |
1404 | bool hasTrivialMoveConstructorForCall() const { |
1405 | return hasMoveConstructor() && |
1406 | (data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor); |
1407 | } |
1408 | |
1409 | /// Determine whether this class has a non-trivial move constructor |
1410 | /// (C++11 [class.copy]p12) |
1411 | bool hasNonTrivialMoveConstructor() const { |
1412 | return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveConstructor) || |
1413 | (needsImplicitMoveConstructor() && |
1414 | !(data().HasTrivialSpecialMembers & SMF_MoveConstructor)); |
1415 | } |
1416 | |
1417 | bool hasNonTrivialMoveConstructorForCall() const { |
1418 | return (data().DeclaredNonTrivialSpecialMembersForCall & |
1419 | SMF_MoveConstructor) || |
1420 | (needsImplicitMoveConstructor() && |
1421 | !(data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor)); |
1422 | } |
1423 | |
1424 | /// Determine whether this class has a trivial copy assignment operator |
1425 | /// (C++ [class.copy]p11, C++11 [class.copy]p25) |
1426 | bool hasTrivialCopyAssignment() const { |
1427 | return data().HasTrivialSpecialMembers & SMF_CopyAssignment; |
1428 | } |
1429 | |
1430 | /// Determine whether this class has a non-trivial copy assignment |
1431 | /// operator (C++ [class.copy]p11, C++11 [class.copy]p25) |
1432 | bool hasNonTrivialCopyAssignment() const { |
1433 | return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment || |
1434 | !hasTrivialCopyAssignment(); |
1435 | } |
1436 | |
1437 | /// Determine whether this class has a trivial move assignment operator |
1438 | /// (C++11 [class.copy]p25) |
1439 | bool hasTrivialMoveAssignment() const { |
1440 | return hasMoveAssignment() && |
1441 | (data().HasTrivialSpecialMembers & SMF_MoveAssignment); |
1442 | } |
1443 | |
1444 | /// Determine whether this class has a non-trivial move assignment |
1445 | /// operator (C++11 [class.copy]p25) |
1446 | bool hasNonTrivialMoveAssignment() const { |
1447 | return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveAssignment) || |
1448 | (needsImplicitMoveAssignment() && |
1449 | !(data().HasTrivialSpecialMembers & SMF_MoveAssignment)); |
1450 | } |
1451 | |
1452 | /// Determine whether a defaulted default constructor for this class |
1453 | /// would be constexpr. |
1454 | bool defaultedDestructorIsConstexpr() const { |
1455 | return data().DefaultedDestructorIsConstexpr && |
1456 | getASTContext().getLangOpts().CPlusPlus2a; |
1457 | } |
1458 | |
1459 | /// Determine whether this class has a constexpr destructor. |
1460 | bool hasConstexprDestructor() const; |
1461 | |
1462 | /// Determine whether this class has a trivial destructor |
1463 | /// (C++ [class.dtor]p3) |
1464 | bool hasTrivialDestructor() const { |
1465 | return data().HasTrivialSpecialMembers & SMF_Destructor; |
1466 | } |
1467 | |
1468 | bool hasTrivialDestructorForCall() const { |
1469 | return data().HasTrivialSpecialMembersForCall & SMF_Destructor; |
1470 | } |
1471 | |
1472 | /// Determine whether this class has a non-trivial destructor |
1473 | /// (C++ [class.dtor]p3) |
1474 | bool hasNonTrivialDestructor() const { |
1475 | return !(data().HasTrivialSpecialMembers & SMF_Destructor); |
1476 | } |
1477 | |
1478 | bool hasNonTrivialDestructorForCall() const { |
1479 | return !(data().HasTrivialSpecialMembersForCall & SMF_Destructor); |
1480 | } |
1481 | |
1482 | void setHasTrivialSpecialMemberForCall() { |
1483 | data().HasTrivialSpecialMembersForCall = |
1484 | (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor); |
1485 | } |
1486 | |
1487 | /// Determine whether declaring a const variable with this type is ok |
1488 | /// per core issue 253. |
1489 | bool allowConstDefaultInit() const { |
1490 | return !data().HasUninitializedFields || |
1491 | !(data().HasDefaultedDefaultConstructor || |
1492 | needsImplicitDefaultConstructor()); |
1493 | } |
1494 | |
1495 | /// Determine whether this class has a destructor which has no |
1496 | /// semantic effect. |
1497 | /// |
1498 | /// Any such destructor will be trivial, public, defaulted and not deleted, |
1499 | /// and will call only irrelevant destructors. |
1500 | bool hasIrrelevantDestructor() const { |
1501 | return data().HasIrrelevantDestructor; |
1502 | } |
1503 | |
1504 | /// Determine whether this class has a non-literal or/ volatile type |
1505 | /// non-static data member or base class. |
1506 | bool hasNonLiteralTypeFieldsOrBases() const { |
1507 | return data().HasNonLiteralTypeFieldsOrBases; |
1508 | } |
1509 | |
1510 | /// Determine whether this class has a using-declaration that names |
1511 | /// a user-declared base class constructor. |
1512 | bool hasInheritedConstructor() const { |
1513 | return data().HasInheritedConstructor; |
1514 | } |
1515 | |
1516 | /// Determine whether this class has a using-declaration that names |
1517 | /// a base class assignment operator. |
1518 | bool hasInheritedAssignment() const { |
1519 | return data().HasInheritedAssignment; |
1520 | } |
1521 | |
1522 | /// Determine whether this class is considered trivially copyable per |
1523 | /// (C++11 [class]p6). |
1524 | bool isTriviallyCopyable() const; |
1525 | |
1526 | /// Determine whether this class is considered trivial. |
1527 | /// |
1528 | /// C++11 [class]p6: |
1529 | /// "A trivial class is a class that has a trivial default constructor and |
1530 | /// is trivially copyable." |
1531 | bool isTrivial() const { |
1532 | return isTriviallyCopyable() && hasTrivialDefaultConstructor(); |
1533 | } |
1534 | |
1535 | /// Determine whether this class is a literal type. |
1536 | /// |
1537 | /// C++11 [basic.types]p10: |
1538 | /// A class type that has all the following properties: |
1539 | /// - it has a trivial destructor |
1540 | /// - every constructor call and full-expression in the |
1541 | /// brace-or-equal-intializers for non-static data members (if any) is |
1542 | /// a constant expression. |
1543 | /// - it is an aggregate type or has at least one constexpr constructor |
1544 | /// or constructor template that is not a copy or move constructor, and |
1545 | /// - all of its non-static data members and base classes are of literal |
1546 | /// types |
1547 | /// |
1548 | /// We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by |
1549 | /// treating types with trivial default constructors as literal types. |
1550 | /// |
1551 | /// Only in C++17 and beyond, are lambdas literal types. |
1552 | bool isLiteral() const { |
1553 | ASTContext &Ctx = getASTContext(); |
1554 | return (Ctx.getLangOpts().CPlusPlus2a ? hasConstexprDestructor() |
1555 | : hasTrivialDestructor()) && |
1556 | (!isLambda() || Ctx.getLangOpts().CPlusPlus17) && |
1557 | !hasNonLiteralTypeFieldsOrBases() && |
1558 | (isAggregate() || isLambda() || |
1559 | hasConstexprNonCopyMoveConstructor() || |
1560 | hasTrivialDefaultConstructor()); |
1561 | } |
1562 | |
1563 | /// If this record is an instantiation of a member class, |
1564 | /// retrieves the member class from which it was instantiated. |
1565 | /// |
1566 | /// This routine will return non-null for (non-templated) member |
1567 | /// classes of class templates. For example, given: |
1568 | /// |
1569 | /// \code |
1570 | /// template<typename T> |
1571 | /// struct X { |
1572 | /// struct A { }; |
1573 | /// }; |
1574 | /// \endcode |
1575 | /// |
1576 | /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl |
1577 | /// whose parent is the class template specialization X<int>. For |
1578 | /// this declaration, getInstantiatedFromMemberClass() will return |
1579 | /// the CXXRecordDecl X<T>::A. When a complete definition of |
1580 | /// X<int>::A is required, it will be instantiated from the |
1581 | /// declaration returned by getInstantiatedFromMemberClass(). |
1582 | CXXRecordDecl *getInstantiatedFromMemberClass() const; |
1583 | |
1584 | /// If this class is an instantiation of a member class of a |
1585 | /// class template specialization, retrieves the member specialization |
1586 | /// information. |
1587 | MemberSpecializationInfo *getMemberSpecializationInfo() const; |
1588 | |
1589 | /// Specify that this record is an instantiation of the |
1590 | /// member class \p RD. |
1591 | void setInstantiationOfMemberClass(CXXRecordDecl *RD, |
1592 | TemplateSpecializationKind TSK); |
1593 | |
1594 | /// Retrieves the class template that is described by this |
1595 | /// class declaration. |
1596 | /// |
1597 | /// Every class template is represented as a ClassTemplateDecl and a |
1598 | /// CXXRecordDecl. The former contains template properties (such as |
1599 | /// the template parameter lists) while the latter contains the |
1600 | /// actual description of the template's |
1601 | /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the |
1602 | /// CXXRecordDecl that from a ClassTemplateDecl, while |
1603 | /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from |
1604 | /// a CXXRecordDecl. |
1605 | ClassTemplateDecl *getDescribedClassTemplate() const; |
1606 | |
1607 | void setDescribedClassTemplate(ClassTemplateDecl *Template); |
1608 | |
1609 | /// Determine whether this particular class is a specialization or |
1610 | /// instantiation of a class template or member class of a class template, |
1611 | /// and how it was instantiated or specialized. |
1612 | TemplateSpecializationKind getTemplateSpecializationKind() const; |
1613 | |
1614 | /// Set the kind of specialization or template instantiation this is. |
1615 | void setTemplateSpecializationKind(TemplateSpecializationKind TSK); |
1616 | |
1617 | /// Retrieve the record declaration from which this record could be |
1618 | /// instantiated. Returns null if this class is not a template instantiation. |
1619 | const CXXRecordDecl *getTemplateInstantiationPattern() const; |
1620 | |
1621 | CXXRecordDecl *getTemplateInstantiationPattern() { |
1622 | return const_cast<CXXRecordDecl *>(const_cast<const CXXRecordDecl *>(this) |
1623 | ->getTemplateInstantiationPattern()); |
1624 | } |
1625 | |
1626 | /// Returns the destructor decl for this class. |
1627 | CXXDestructorDecl *getDestructor() const; |
1628 | |
1629 | /// Returns true if the class destructor, or any implicitly invoked |
1630 | /// destructors are marked noreturn. |
1631 | bool isAnyDestructorNoReturn() const; |
1632 | |
1633 | /// If the class is a local class [class.local], returns |
1634 | /// the enclosing function declaration. |
1635 | const FunctionDecl *isLocalClass() const { |
1636 | if (const auto *RD = dyn_cast<CXXRecordDecl>(getDeclContext())) |
1637 | return RD->isLocalClass(); |
1638 | |
1639 | return dyn_cast<FunctionDecl>(getDeclContext()); |
1640 | } |
1641 | |
1642 | FunctionDecl *isLocalClass() { |
1643 | return const_cast<FunctionDecl*>( |
1644 | const_cast<const CXXRecordDecl*>(this)->isLocalClass()); |
1645 | } |
1646 | |
1647 | /// Determine whether this dependent class is a current instantiation, |
1648 | /// when viewed from within the given context. |
1649 | bool isCurrentInstantiation(const DeclContext *CurContext) const; |
1650 | |
1651 | /// Determine whether this class is derived from the class \p Base. |
1652 | /// |
1653 | /// This routine only determines whether this class is derived from \p Base, |
1654 | /// but does not account for factors that may make a Derived -> Base class |
1655 | /// ill-formed, such as private/protected inheritance or multiple, ambiguous |
1656 | /// base class subobjects. |
1657 | /// |
1658 | /// \param Base the base class we are searching for. |
1659 | /// |
1660 | /// \returns true if this class is derived from Base, false otherwise. |
1661 | bool isDerivedFrom(const CXXRecordDecl *Base) const; |
1662 | |
1663 | /// Determine whether this class is derived from the type \p Base. |
1664 | /// |
1665 | /// This routine only determines whether this class is derived from \p Base, |
1666 | /// but does not account for factors that may make a Derived -> Base class |
1667 | /// ill-formed, such as private/protected inheritance or multiple, ambiguous |
1668 | /// base class subobjects. |
1669 | /// |
1670 | /// \param Base the base class we are searching for. |
1671 | /// |
1672 | /// \param Paths will contain the paths taken from the current class to the |
1673 | /// given \p Base class. |
1674 | /// |
1675 | /// \returns true if this class is derived from \p Base, false otherwise. |
1676 | /// |
1677 | /// \todo add a separate parameter to configure IsDerivedFrom, rather than |
1678 | /// tangling input and output in \p Paths |
1679 | bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const; |
1680 | |
1681 | /// Determine whether this class is virtually derived from |
1682 | /// the class \p Base. |
1683 | /// |
1684 | /// This routine only determines whether this class is virtually |
1685 | /// derived from \p Base, but does not account for factors that may |
1686 | /// make a Derived -> Base class ill-formed, such as |
1687 | /// private/protected inheritance or multiple, ambiguous base class |
1688 | /// subobjects. |
1689 | /// |
1690 | /// \param Base the base class we are searching for. |
1691 | /// |
1692 | /// \returns true if this class is virtually derived from Base, |
1693 | /// false otherwise. |
1694 | bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const; |
1695 | |
1696 | /// Determine whether this class is provably not derived from |
1697 | /// the type \p Base. |
1698 | bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const; |
1699 | |
1700 | /// Function type used by forallBases() as a callback. |
1701 | /// |
1702 | /// \param BaseDefinition the definition of the base class |
1703 | /// |
1704 | /// \returns true if this base matched the search criteria |
1705 | using ForallBasesCallback = |
1706 | llvm::function_ref<bool(const CXXRecordDecl *BaseDefinition)>; |
1707 | |
1708 | /// Determines if the given callback holds for all the direct |
1709 | /// or indirect base classes of this type. |
1710 | /// |
1711 | /// The class itself does not count as a base class. This routine |
1712 | /// returns false if the class has non-computable base classes. |
1713 | /// |
1714 | /// \param BaseMatches Callback invoked for each (direct or indirect) base |
1715 | /// class of this type, or if \p AllowShortCircuit is true then until a call |
1716 | /// returns false. |
1717 | /// |
1718 | /// \param AllowShortCircuit if false, forces the callback to be called |
1719 | /// for every base class, even if a dependent or non-matching base was |
1720 | /// found. |
1721 | bool forallBases(ForallBasesCallback BaseMatches, |
1722 | bool AllowShortCircuit = true) const; |
1723 | |
1724 | /// Function type used by lookupInBases() to determine whether a |
1725 | /// specific base class subobject matches the lookup criteria. |
1726 | /// |
1727 | /// \param Specifier the base-class specifier that describes the inheritance |
1728 | /// from the base class we are trying to match. |
1729 | /// |
1730 | /// \param Path the current path, from the most-derived class down to the |
1731 | /// base named by the \p Specifier. |
1732 | /// |
1733 | /// \returns true if this base matched the search criteria, false otherwise. |
1734 | using BaseMatchesCallback = |
1735 | llvm::function_ref<bool(const CXXBaseSpecifier *Specifier, |
1736 | CXXBasePath &Path)>; |
1737 | |
1738 | /// Look for entities within the base classes of this C++ class, |
1739 | /// transitively searching all base class subobjects. |
1740 | /// |
1741 | /// This routine uses the callback function \p BaseMatches to find base |
1742 | /// classes meeting some search criteria, walking all base class subobjects |
1743 | /// and populating the given \p Paths structure with the paths through the |
1744 | /// inheritance hierarchy that resulted in a match. On a successful search, |
1745 | /// the \p Paths structure can be queried to retrieve the matching paths and |
1746 | /// to determine if there were any ambiguities. |
1747 | /// |
1748 | /// \param BaseMatches callback function used to determine whether a given |
1749 | /// base matches the user-defined search criteria. |
1750 | /// |
1751 | /// \param Paths used to record the paths from this class to its base class |
1752 | /// subobjects that match the search criteria. |
1753 | /// |
1754 | /// \param LookupInDependent can be set to true to extend the search to |
1755 | /// dependent base classes. |
1756 | /// |
1757 | /// \returns true if there exists any path from this class to a base class |
1758 | /// subobject that matches the search criteria. |
1759 | bool lookupInBases(BaseMatchesCallback BaseMatches, CXXBasePaths &Paths, |
1760 | bool LookupInDependent = false) const; |
1761 | |
1762 | /// Base-class lookup callback that determines whether the given |
1763 | /// base class specifier refers to a specific class declaration. |
1764 | /// |
1765 | /// This callback can be used with \c lookupInBases() to determine whether |
1766 | /// a given derived class has is a base class subobject of a particular type. |
1767 | /// The base record pointer should refer to the canonical CXXRecordDecl of the |
1768 | /// base class that we are searching for. |
1769 | static bool FindBaseClass(const CXXBaseSpecifier *Specifier, |
1770 | CXXBasePath &Path, const CXXRecordDecl *BaseRecord); |
1771 | |
1772 | /// Base-class lookup callback that determines whether the |
1773 | /// given base class specifier refers to a specific class |
1774 | /// declaration and describes virtual derivation. |
1775 | /// |
1776 | /// This callback can be used with \c lookupInBases() to determine |
1777 | /// whether a given derived class has is a virtual base class |
1778 | /// subobject of a particular type. The base record pointer should |
1779 | /// refer to the canonical CXXRecordDecl of the base class that we |
1780 | /// are searching for. |
1781 | static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier, |
1782 | CXXBasePath &Path, |
1783 | const CXXRecordDecl *BaseRecord); |
1784 | |
1785 | /// Base-class lookup callback that determines whether there exists |
1786 | /// a tag with the given name. |
1787 | /// |
1788 | /// This callback can be used with \c lookupInBases() to find tag members |
1789 | /// of the given name within a C++ class hierarchy. |
1790 | static bool FindTagMember(const CXXBaseSpecifier *Specifier, |
1791 | CXXBasePath &Path, DeclarationName Name); |
1792 | |
1793 | /// Base-class lookup callback that determines whether there exists |
1794 | /// a member with the given name. |
1795 | /// |
1796 | /// This callback can be used with \c lookupInBases() to find members |
1797 | /// of the given name within a C++ class hierarchy. |
1798 | static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier, |
1799 | CXXBasePath &Path, DeclarationName Name); |
1800 | |
1801 | /// Base-class lookup callback that determines whether there exists |
1802 | /// a member with the given name. |
1803 | /// |
1804 | /// This callback can be used with \c lookupInBases() to find members |
1805 | /// of the given name within a C++ class hierarchy, including dependent |
1806 | /// classes. |
1807 | static bool |
1808 | FindOrdinaryMemberInDependentClasses(const CXXBaseSpecifier *Specifier, |
1809 | CXXBasePath &Path, DeclarationName Name); |
1810 | |
1811 | /// Base-class lookup callback that determines whether there exists |
1812 | /// an OpenMP declare reduction member with the given name. |
1813 | /// |
1814 | /// This callback can be used with \c lookupInBases() to find members |
1815 | /// of the given name within a C++ class hierarchy. |
1816 | static bool FindOMPReductionMember(const CXXBaseSpecifier *Specifier, |
1817 | CXXBasePath &Path, DeclarationName Name); |
1818 | |
1819 | /// Base-class lookup callback that determines whether there exists |
1820 | /// an OpenMP declare mapper member with the given name. |
1821 | /// |
1822 | /// This callback can be used with \c lookupInBases() to find members |
1823 | /// of the given name within a C++ class hierarchy. |
1824 | static bool FindOMPMapperMember(const CXXBaseSpecifier *Specifier, |
1825 | CXXBasePath &Path, DeclarationName Name); |
1826 | |
1827 | /// Base-class lookup callback that determines whether there exists |
1828 | /// a member with the given name that can be used in a nested-name-specifier. |
1829 | /// |
1830 | /// This callback can be used with \c lookupInBases() to find members of |
1831 | /// the given name within a C++ class hierarchy that can occur within |
1832 | /// nested-name-specifiers. |
1833 | static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier, |
1834 | CXXBasePath &Path, |
1835 | DeclarationName Name); |
1836 | |
1837 | /// Retrieve the final overriders for each virtual member |
1838 | /// function in the class hierarchy where this class is the |
1839 | /// most-derived class in the class hierarchy. |
1840 | void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const; |
1841 | |
1842 | /// Get the indirect primary bases for this class. |
1843 | void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const; |
1844 | |
1845 | /// Performs an imprecise lookup of a dependent name in this class. |
1846 | /// |
1847 | /// This function does not follow strict semantic rules and should be used |
1848 | /// only when lookup rules can be relaxed, e.g. indexing. |
1849 | std::vector<const NamedDecl *> |
1850 | lookupDependentName(const DeclarationName &Name, |
1851 | llvm::function_ref<bool(const NamedDecl *ND)> Filter); |
1852 | |
1853 | /// Renders and displays an inheritance diagram |
1854 | /// for this C++ class and all of its base classes (transitively) using |
1855 | /// GraphViz. |
1856 | void viewInheritance(ASTContext& Context) const; |
1857 | |
1858 | /// Calculates the access of a decl that is reached |
1859 | /// along a path. |
1860 | static AccessSpecifier MergeAccess(AccessSpecifier PathAccess, |
1861 | AccessSpecifier DeclAccess) { |
1862 | assert(DeclAccess != AS_none)((DeclAccess != AS_none) ? static_cast<void> (0) : __assert_fail ("DeclAccess != AS_none", "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 1862, __PRETTY_FUNCTION__)); |
1863 | if (DeclAccess == AS_private) return AS_none; |
1864 | return (PathAccess > DeclAccess ? PathAccess : DeclAccess); |
1865 | } |
1866 | |
1867 | /// Indicates that the declaration of a defaulted or deleted special |
1868 | /// member function is now complete. |
1869 | void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD); |
1870 | |
1871 | void setTrivialForCallFlags(CXXMethodDecl *MD); |
1872 | |
1873 | /// Indicates that the definition of this class is now complete. |
1874 | void completeDefinition() override; |
1875 | |
1876 | /// Indicates that the definition of this class is now complete, |
1877 | /// and provides a final overrider map to help determine |
1878 | /// |
1879 | /// \param FinalOverriders The final overrider map for this class, which can |
1880 | /// be provided as an optimization for abstract-class checking. If NULL, |
1881 | /// final overriders will be computed if they are needed to complete the |
1882 | /// definition. |
1883 | void completeDefinition(CXXFinalOverriderMap *FinalOverriders); |
1884 | |
1885 | /// Determine whether this class may end up being abstract, even though |
1886 | /// it is not yet known to be abstract. |
1887 | /// |
1888 | /// \returns true if this class is not known to be abstract but has any |
1889 | /// base classes that are abstract. In this case, \c completeDefinition() |
1890 | /// will need to compute final overriders to determine whether the class is |
1891 | /// actually abstract. |
1892 | bool mayBeAbstract() const; |
1893 | |
1894 | /// If this is the closure type of a lambda expression, retrieve the |
1895 | /// number to be used for name mangling in the Itanium C++ ABI. |
1896 | /// |
1897 | /// Zero indicates that this closure type has internal linkage, so the |
1898 | /// mangling number does not matter, while a non-zero value indicates which |
1899 | /// lambda expression this is in this particular context. |
1900 | unsigned getLambdaManglingNumber() const { |
1901 | assert(isLambda() && "Not a lambda closure type!")((isLambda() && "Not a lambda closure type!") ? static_cast <void> (0) : __assert_fail ("isLambda() && \"Not a lambda closure type!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 1901, __PRETTY_FUNCTION__)); |
1902 | return getLambdaData().ManglingNumber; |
1903 | } |
1904 | |
1905 | /// Retrieve the declaration that provides additional context for a |
1906 | /// lambda, when the normal declaration context is not specific enough. |
1907 | /// |
1908 | /// Certain contexts (default arguments of in-class function parameters and |
1909 | /// the initializers of data members) have separate name mangling rules for |
1910 | /// lambdas within the Itanium C++ ABI. For these cases, this routine provides |
1911 | /// the declaration in which the lambda occurs, e.g., the function parameter |
1912 | /// or the non-static data member. Otherwise, it returns NULL to imply that |
1913 | /// the declaration context suffices. |
1914 | Decl *getLambdaContextDecl() const; |
1915 | |
1916 | /// Set the mangling number and context declaration for a lambda |
1917 | /// class. |
1918 | void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl) { |
1919 | getLambdaData().ManglingNumber = ManglingNumber; |
1920 | getLambdaData().ContextDecl = ContextDecl; |
1921 | } |
1922 | |
1923 | /// Returns the inheritance model used for this record. |
1924 | MSInheritanceAttr::Spelling getMSInheritanceModel() const; |
1925 | |
1926 | /// Calculate what the inheritance model would be for this class. |
1927 | MSInheritanceAttr::Spelling calculateInheritanceModel() const; |
1928 | |
1929 | /// In the Microsoft C++ ABI, use zero for the field offset of a null data |
1930 | /// member pointer if we can guarantee that zero is not a valid field offset, |
1931 | /// or if the member pointer has multiple fields. Polymorphic classes have a |
1932 | /// vfptr at offset zero, so we can use zero for null. If there are multiple |
1933 | /// fields, we can use zero even if it is a valid field offset because |
1934 | /// null-ness testing will check the other fields. |
1935 | bool nullFieldOffsetIsZero() const { |
1936 | return !MSInheritanceAttr::hasOnlyOneField(/*IsMemberFunction=*/false, |
1937 | getMSInheritanceModel()) || |
1938 | (hasDefinition() && isPolymorphic()); |
1939 | } |
1940 | |
1941 | /// Controls when vtordisps will be emitted if this record is used as a |
1942 | /// virtual base. |
1943 | MSVtorDispAttr::Mode getMSVtorDispMode() const; |
1944 | |
1945 | /// Determine whether this lambda expression was known to be dependent |
1946 | /// at the time it was created, even if its context does not appear to be |
1947 | /// dependent. |
1948 | /// |
1949 | /// This flag is a workaround for an issue with parsing, where default |
1950 | /// arguments are parsed before their enclosing function declarations have |
1951 | /// been created. This means that any lambda expressions within those |
1952 | /// default arguments will have as their DeclContext the context enclosing |
1953 | /// the function declaration, which may be non-dependent even when the |
1954 | /// function declaration itself is dependent. This flag indicates when we |
1955 | /// know that the lambda is dependent despite that. |
1956 | bool isDependentLambda() const { |
1957 | return isLambda() && getLambdaData().Dependent; |
1958 | } |
1959 | |
1960 | TypeSourceInfo *getLambdaTypeInfo() const { |
1961 | return getLambdaData().MethodTyInfo; |
1962 | } |
1963 | |
1964 | // Determine whether this type is an Interface Like type for |
1965 | // __interface inheritance purposes. |
1966 | bool isInterfaceLike() const; |
1967 | |
1968 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1969 | static bool classofKind(Kind K) { |
1970 | return K >= firstCXXRecord && K <= lastCXXRecord; |
1971 | } |
1972 | }; |
1973 | |
1974 | /// Store information needed for an explicit specifier. |
1975 | /// used by CXXDeductionGuideDecl, CXXConstructorDecl and CXXConversionDecl. |
1976 | class ExplicitSpecifier { |
1977 | llvm::PointerIntPair<Expr *, 2, ExplicitSpecKind> ExplicitSpec{ |
1978 | nullptr, ExplicitSpecKind::ResolvedFalse}; |
1979 | |
1980 | public: |
1981 | ExplicitSpecifier() = default; |
1982 | ExplicitSpecifier(Expr *Expression, ExplicitSpecKind Kind) |
1983 | : ExplicitSpec(Expression, Kind) {} |
1984 | ExplicitSpecKind getKind() const { return ExplicitSpec.getInt(); } |
1985 | const Expr *getExpr() const { return ExplicitSpec.getPointer(); } |
1986 | Expr *getExpr() { return ExplicitSpec.getPointer(); } |
1987 | |
1988 | /// Return true if the ExplicitSpecifier isn't defaulted. |
1989 | bool isSpecified() const { |
1990 | return ExplicitSpec.getInt() != ExplicitSpecKind::ResolvedFalse || |
1991 | ExplicitSpec.getPointer(); |
1992 | } |
1993 | |
1994 | /// Check for Equivalence of explicit specifiers. |
1995 | /// Return True if the explicit specifier are equivalent false otherwise. |
1996 | bool isEquivalent(const ExplicitSpecifier Other) const; |
1997 | /// Return true if the explicit specifier is already resolved to be explicit. |
1998 | bool isExplicit() const { |
1999 | return ExplicitSpec.getInt() == ExplicitSpecKind::ResolvedTrue; |
2000 | } |
2001 | /// Return true if the ExplicitSpecifier isn't valid. |
2002 | /// This state occurs after a substitution failures. |
2003 | bool isInvalid() const { |
2004 | return ExplicitSpec.getInt() == ExplicitSpecKind::Unresolved && |
2005 | !ExplicitSpec.getPointer(); |
2006 | } |
2007 | void setKind(ExplicitSpecKind Kind) { ExplicitSpec.setInt(Kind); } |
2008 | void setExpr(Expr *E) { ExplicitSpec.setPointer(E); } |
2009 | // getFromDecl - retrieve the explicit specifier in the given declaration. |
2010 | // if the given declaration has no explicit. the returned explicit specifier |
2011 | // is defaulted. .isSpecified() will be false. |
2012 | static ExplicitSpecifier getFromDecl(FunctionDecl *Function); |
2013 | static const ExplicitSpecifier getFromDecl(const FunctionDecl *Function) { |
2014 | return getFromDecl(const_cast<FunctionDecl *>(Function)); |
2015 | } |
2016 | static ExplicitSpecifier Invalid() { |
2017 | return ExplicitSpecifier(nullptr, ExplicitSpecKind::Unresolved); |
2018 | } |
2019 | }; |
2020 | |
2021 | /// Represents a C++ deduction guide declaration. |
2022 | /// |
2023 | /// \code |
2024 | /// template<typename T> struct A { A(); A(T); }; |
2025 | /// A() -> A<int>; |
2026 | /// \endcode |
2027 | /// |
2028 | /// In this example, there will be an explicit deduction guide from the |
2029 | /// second line, and implicit deduction guide templates synthesized from |
2030 | /// the constructors of \c A. |
2031 | class CXXDeductionGuideDecl : public FunctionDecl { |
2032 | void anchor() override; |
2033 | |
2034 | private: |
2035 | CXXDeductionGuideDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
2036 | ExplicitSpecifier ES, |
2037 | const DeclarationNameInfo &NameInfo, QualType T, |
2038 | TypeSourceInfo *TInfo, SourceLocation EndLocation) |
2039 | : FunctionDecl(CXXDeductionGuide, C, DC, StartLoc, NameInfo, T, TInfo, |
2040 | SC_None, false, CSK_unspecified), |
2041 | ExplicitSpec(ES) { |
2042 | if (EndLocation.isValid()) |
2043 | setRangeEnd(EndLocation); |
2044 | setIsCopyDeductionCandidate(false); |
2045 | } |
2046 | |
2047 | ExplicitSpecifier ExplicitSpec; |
2048 | void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; } |
2049 | |
2050 | public: |
2051 | friend class ASTDeclReader; |
2052 | friend class ASTDeclWriter; |
2053 | |
2054 | static CXXDeductionGuideDecl * |
2055 | Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
2056 | ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T, |
2057 | TypeSourceInfo *TInfo, SourceLocation EndLocation); |
2058 | |
2059 | static CXXDeductionGuideDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2060 | |
2061 | ExplicitSpecifier getExplicitSpecifier() { return ExplicitSpec; } |
2062 | const ExplicitSpecifier getExplicitSpecifier() const { return ExplicitSpec; } |
2063 | |
2064 | /// Return true if the declartion is already resolved to be explicit. |
2065 | bool isExplicit() const { return ExplicitSpec.isExplicit(); } |
2066 | |
2067 | /// Get the template for which this guide performs deduction. |
2068 | TemplateDecl *getDeducedTemplate() const { |
2069 | return getDeclName().getCXXDeductionGuideTemplate(); |
2070 | } |
2071 | |
2072 | void setIsCopyDeductionCandidate(bool isCDC = true) { |
2073 | FunctionDeclBits.IsCopyDeductionCandidate = isCDC; |
2074 | } |
2075 | |
2076 | bool isCopyDeductionCandidate() const { |
2077 | return FunctionDeclBits.IsCopyDeductionCandidate; |
2078 | } |
2079 | |
2080 | // Implement isa/cast/dyncast/etc. |
2081 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2082 | static bool classofKind(Kind K) { return K == CXXDeductionGuide; } |
2083 | }; |
2084 | |
2085 | /// Represents a static or instance method of a struct/union/class. |
2086 | /// |
2087 | /// In the terminology of the C++ Standard, these are the (static and |
2088 | /// non-static) member functions, whether virtual or not. |
2089 | class CXXMethodDecl : public FunctionDecl { |
2090 | void anchor() override; |
2091 | |
2092 | protected: |
2093 | CXXMethodDecl(Kind DK, ASTContext &C, CXXRecordDecl *RD, |
2094 | SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, |
2095 | QualType T, TypeSourceInfo *TInfo, StorageClass SC, |
2096 | bool isInline, ConstexprSpecKind ConstexprKind, |
2097 | SourceLocation EndLocation) |
2098 | : FunctionDecl(DK, C, RD, StartLoc, NameInfo, T, TInfo, SC, isInline, |
2099 | ConstexprKind) { |
2100 | if (EndLocation.isValid()) |
2101 | setRangeEnd(EndLocation); |
2102 | } |
2103 | |
2104 | public: |
2105 | static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD, |
2106 | SourceLocation StartLoc, |
2107 | const DeclarationNameInfo &NameInfo, QualType T, |
2108 | TypeSourceInfo *TInfo, StorageClass SC, |
2109 | bool isInline, ConstexprSpecKind ConstexprKind, |
2110 | SourceLocation EndLocation); |
2111 | |
2112 | static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2113 | |
2114 | bool isStatic() const; |
2115 | bool isInstance() const { return !isStatic(); } |
2116 | |
2117 | /// Returns true if the given operator is implicitly static in a record |
2118 | /// context. |
2119 | static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK) { |
2120 | // [class.free]p1: |
2121 | // Any allocation function for a class T is a static member |
2122 | // (even if not explicitly declared static). |
2123 | // [class.free]p6 Any deallocation function for a class X is a static member |
2124 | // (even if not explicitly declared static). |
2125 | return OOK == OO_New || OOK == OO_Array_New || OOK == OO_Delete || |
2126 | OOK == OO_Array_Delete; |
2127 | } |
2128 | |
2129 | bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); } |
2130 | bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); } |
2131 | |
2132 | bool isVirtual() const { |
2133 | CXXMethodDecl *CD = const_cast<CXXMethodDecl*>(this)->getCanonicalDecl(); |
2134 | |
2135 | // Member function is virtual if it is marked explicitly so, or if it is |
2136 | // declared in __interface -- then it is automatically pure virtual. |
2137 | if (CD->isVirtualAsWritten() || CD->isPure()) |
2138 | return true; |
2139 | |
2140 | return CD->size_overridden_methods() != 0; |
2141 | } |
2142 | |
2143 | /// If it's possible to devirtualize a call to this method, return the called |
2144 | /// function. Otherwise, return null. |
2145 | |
2146 | /// \param Base The object on which this virtual function is called. |
2147 | /// \param IsAppleKext True if we are compiling for Apple kext. |
2148 | CXXMethodDecl *getDevirtualizedMethod(const Expr *Base, bool IsAppleKext); |
2149 | |
2150 | const CXXMethodDecl *getDevirtualizedMethod(const Expr *Base, |
2151 | bool IsAppleKext) const { |
2152 | return const_cast<CXXMethodDecl *>(this)->getDevirtualizedMethod( |
2153 | Base, IsAppleKext); |
2154 | } |
2155 | |
2156 | /// Determine whether this is a usual deallocation function (C++ |
2157 | /// [basic.stc.dynamic.deallocation]p2), which is an overloaded delete or |
2158 | /// delete[] operator with a particular signature. Populates \p PreventedBy |
2159 | /// with the declarations of the functions of the same kind if they were the |
2160 | /// reason for this function returning false. This is used by |
2161 | /// Sema::isUsualDeallocationFunction to reconsider the answer based on the |
2162 | /// context. |
2163 | bool isUsualDeallocationFunction( |
2164 | SmallVectorImpl<const FunctionDecl *> &PreventedBy) const; |
2165 | |
2166 | /// Determine whether this is a copy-assignment operator, regardless |
2167 | /// of whether it was declared implicitly or explicitly. |
2168 | bool isCopyAssignmentOperator() const; |
2169 | |
2170 | /// Determine whether this is a move assignment operator. |
2171 | bool isMoveAssignmentOperator() const; |
2172 | |
2173 | CXXMethodDecl *getCanonicalDecl() override { |
2174 | return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); |
2175 | } |
2176 | const CXXMethodDecl *getCanonicalDecl() const { |
2177 | return const_cast<CXXMethodDecl*>(this)->getCanonicalDecl(); |
2178 | } |
2179 | |
2180 | CXXMethodDecl *getMostRecentDecl() { |
2181 | return cast<CXXMethodDecl>( |
2182 | static_cast<FunctionDecl *>(this)->getMostRecentDecl()); |
2183 | } |
2184 | const CXXMethodDecl *getMostRecentDecl() const { |
2185 | return const_cast<CXXMethodDecl*>(this)->getMostRecentDecl(); |
2186 | } |
2187 | |
2188 | /// True if this method is user-declared and was not |
2189 | /// deleted or defaulted on its first declaration. |
2190 | bool isUserProvided() const { |
2191 | auto *DeclAsWritten = this; |
2192 | if (auto *Pattern = getTemplateInstantiationPattern()) |
2193 | DeclAsWritten = cast<CXXMethodDecl>(Pattern); |
2194 | return !(DeclAsWritten->isDeleted() || |
2195 | DeclAsWritten->getCanonicalDecl()->isDefaulted()); |
2196 | } |
2197 | |
2198 | void addOverriddenMethod(const CXXMethodDecl *MD); |
2199 | |
2200 | using method_iterator = const CXXMethodDecl *const *; |
2201 | |
2202 | method_iterator begin_overridden_methods() const; |
2203 | method_iterator end_overridden_methods() const; |
2204 | unsigned size_overridden_methods() const; |
2205 | |
2206 | using overridden_method_range= ASTContext::overridden_method_range; |
2207 | |
2208 | overridden_method_range overridden_methods() const; |
2209 | |
2210 | /// Return the parent of this method declaration, which |
2211 | /// is the class in which this method is defined. |
2212 | const CXXRecordDecl *getParent() const { |
2213 | return cast<CXXRecordDecl>(FunctionDecl::getParent()); |
2214 | } |
2215 | |
2216 | /// Return the parent of this method declaration, which |
2217 | /// is the class in which this method is defined. |
2218 | CXXRecordDecl *getParent() { |
2219 | return const_cast<CXXRecordDecl *>( |
2220 | cast<CXXRecordDecl>(FunctionDecl::getParent())); |
2221 | } |
2222 | |
2223 | /// Return the type of the \c this pointer. |
2224 | /// |
2225 | /// Should only be called for instance (i.e., non-static) methods. Note |
2226 | /// that for the call operator of a lambda closure type, this returns the |
2227 | /// desugared 'this' type (a pointer to the closure type), not the captured |
2228 | /// 'this' type. |
2229 | QualType getThisType() const; |
2230 | |
2231 | /// Return the type of the object pointed by \c this. |
2232 | /// |
2233 | /// See getThisType() for usage restriction. |
2234 | QualType getThisObjectType() const; |
2235 | |
2236 | static QualType getThisType(const FunctionProtoType *FPT, |
2237 | const CXXRecordDecl *Decl); |
2238 | |
2239 | static QualType getThisObjectType(const FunctionProtoType *FPT, |
2240 | const CXXRecordDecl *Decl); |
2241 | |
2242 | Qualifiers getMethodQualifiers() const { |
2243 | return getType()->castAs<FunctionProtoType>()->getMethodQuals(); |
2244 | } |
2245 | |
2246 | /// Retrieve the ref-qualifier associated with this method. |
2247 | /// |
2248 | /// In the following example, \c f() has an lvalue ref-qualifier, \c g() |
2249 | /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier. |
2250 | /// @code |
2251 | /// struct X { |
2252 | /// void f() &; |
2253 | /// void g() &&; |
2254 | /// void h(); |
2255 | /// }; |
2256 | /// @endcode |
2257 | RefQualifierKind getRefQualifier() const { |
2258 | return getType()->castAs<FunctionProtoType>()->getRefQualifier(); |
2259 | } |
2260 | |
2261 | bool hasInlineBody() const; |
2262 | |
2263 | /// Determine whether this is a lambda closure type's static member |
2264 | /// function that is used for the result of the lambda's conversion to |
2265 | /// function pointer (for a lambda with no captures). |
2266 | /// |
2267 | /// The function itself, if used, will have a placeholder body that will be |
2268 | /// supplied by IR generation to either forward to the function call operator |
2269 | /// or clone the function call operator. |
2270 | bool isLambdaStaticInvoker() const; |
2271 | |
2272 | /// Find the method in \p RD that corresponds to this one. |
2273 | /// |
2274 | /// Find if \p RD or one of the classes it inherits from override this method. |
2275 | /// If so, return it. \p RD is assumed to be a subclass of the class defining |
2276 | /// this method (or be the class itself), unless \p MayBeBase is set to true. |
2277 | CXXMethodDecl * |
2278 | getCorrespondingMethodInClass(const CXXRecordDecl *RD, |
2279 | bool MayBeBase = false); |
2280 | |
2281 | const CXXMethodDecl * |
2282 | getCorrespondingMethodInClass(const CXXRecordDecl *RD, |
2283 | bool MayBeBase = false) const { |
2284 | return const_cast<CXXMethodDecl *>(this) |
2285 | ->getCorrespondingMethodInClass(RD, MayBeBase); |
2286 | } |
2287 | |
2288 | /// Find if \p RD declares a function that overrides this function, and if so, |
2289 | /// return it. Does not search base classes. |
2290 | CXXMethodDecl *getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD, |
2291 | bool MayBeBase = false); |
2292 | const CXXMethodDecl * |
2293 | getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD, |
2294 | bool MayBeBase = false) const { |
2295 | return const_cast<CXXMethodDecl *>(this) |
2296 | ->getCorrespondingMethodDeclaredInClass(RD, MayBeBase); |
2297 | } |
2298 | |
2299 | // Implement isa/cast/dyncast/etc. |
2300 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2301 | static bool classofKind(Kind K) { |
2302 | return K >= firstCXXMethod && K <= lastCXXMethod; |
2303 | } |
2304 | }; |
2305 | |
2306 | /// Represents a C++ base or member initializer. |
2307 | /// |
2308 | /// This is part of a constructor initializer that |
2309 | /// initializes one non-static member variable or one base class. For |
2310 | /// example, in the following, both 'A(a)' and 'f(3.14159)' are member |
2311 | /// initializers: |
2312 | /// |
2313 | /// \code |
2314 | /// class A { }; |
2315 | /// class B : public A { |
2316 | /// float f; |
2317 | /// public: |
2318 | /// B(A& a) : A(a), f(3.14159) { } |
2319 | /// }; |
2320 | /// \endcode |
2321 | class CXXCtorInitializer final { |
2322 | /// Either the base class name/delegating constructor type (stored as |
2323 | /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field |
2324 | /// (IndirectFieldDecl*) being initialized. |
2325 | llvm::PointerUnion3<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *> |
2326 | Initializee; |
2327 | |
2328 | /// The source location for the field name or, for a base initializer |
2329 | /// pack expansion, the location of the ellipsis. |
2330 | /// |
2331 | /// In the case of a delegating |
2332 | /// constructor, it will still include the type's source location as the |
2333 | /// Initializee points to the CXXConstructorDecl (to allow loop detection). |
2334 | SourceLocation MemberOrEllipsisLocation; |
2335 | |
2336 | /// The argument used to initialize the base or member, which may |
2337 | /// end up constructing an object (when multiple arguments are involved). |
2338 | Stmt *Init; |
2339 | |
2340 | /// Location of the left paren of the ctor-initializer. |
2341 | SourceLocation LParenLoc; |
2342 | |
2343 | /// Location of the right paren of the ctor-initializer. |
2344 | SourceLocation RParenLoc; |
2345 | |
2346 | /// If the initializee is a type, whether that type makes this |
2347 | /// a delegating initialization. |
2348 | unsigned IsDelegating : 1; |
2349 | |
2350 | /// If the initializer is a base initializer, this keeps track |
2351 | /// of whether the base is virtual or not. |
2352 | unsigned IsVirtual : 1; |
2353 | |
2354 | /// Whether or not the initializer is explicitly written |
2355 | /// in the sources. |
2356 | unsigned IsWritten : 1; |
2357 | |
2358 | /// If IsWritten is true, then this number keeps track of the textual order |
2359 | /// of this initializer in the original sources, counting from 0. |
2360 | unsigned SourceOrder : 13; |
2361 | |
2362 | public: |
2363 | /// Creates a new base-class initializer. |
2364 | explicit |
2365 | CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual, |
2366 | SourceLocation L, Expr *Init, SourceLocation R, |
2367 | SourceLocation EllipsisLoc); |
2368 | |
2369 | /// Creates a new member initializer. |
2370 | explicit |
2371 | CXXCtorInitializer(ASTContext &Context, FieldDecl *Member, |
2372 | SourceLocation MemberLoc, SourceLocation L, Expr *Init, |
2373 | SourceLocation R); |
2374 | |
2375 | /// Creates a new anonymous field initializer. |
2376 | explicit |
2377 | CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member, |
2378 | SourceLocation MemberLoc, SourceLocation L, Expr *Init, |
2379 | SourceLocation R); |
2380 | |
2381 | /// Creates a new delegating initializer. |
2382 | explicit |
2383 | CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, |
2384 | SourceLocation L, Expr *Init, SourceLocation R); |
2385 | |
2386 | /// \return Unique reproducible object identifier. |
2387 | int64_t getID(const ASTContext &Context) const; |
2388 | |
2389 | /// Determine whether this initializer is initializing a base class. |
2390 | bool isBaseInitializer() const { |
2391 | return Initializee.is<TypeSourceInfo*>() && !IsDelegating; |
2392 | } |
2393 | |
2394 | /// Determine whether this initializer is initializing a non-static |
2395 | /// data member. |
2396 | bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); } |
2397 | |
2398 | bool isAnyMemberInitializer() const { |
2399 | return isMemberInitializer() || isIndirectMemberInitializer(); |
2400 | } |
2401 | |
2402 | bool isIndirectMemberInitializer() const { |
2403 | return Initializee.is<IndirectFieldDecl*>(); |
2404 | } |
2405 | |
2406 | /// Determine whether this initializer is an implicit initializer |
2407 | /// generated for a field with an initializer defined on the member |
2408 | /// declaration. |
2409 | /// |
2410 | /// In-class member initializers (also known as "non-static data member |
2411 | /// initializations", NSDMIs) were introduced in C++11. |
2412 | bool isInClassMemberInitializer() const { |
2413 | return Init->getStmtClass() == Stmt::CXXDefaultInitExprClass; |
2414 | } |
2415 | |
2416 | /// Determine whether this initializer is creating a delegating |
2417 | /// constructor. |
2418 | bool isDelegatingInitializer() const { |
2419 | return Initializee.is<TypeSourceInfo*>() && IsDelegating; |
2420 | } |
2421 | |
2422 | /// Determine whether this initializer is a pack expansion. |
2423 | bool isPackExpansion() const { |
2424 | return isBaseInitializer() && MemberOrEllipsisLocation.isValid(); |
2425 | } |
2426 | |
2427 | // For a pack expansion, returns the location of the ellipsis. |
2428 | SourceLocation getEllipsisLoc() const { |
2429 | assert(isPackExpansion() && "Initializer is not a pack expansion")((isPackExpansion() && "Initializer is not a pack expansion" ) ? static_cast<void> (0) : __assert_fail ("isPackExpansion() && \"Initializer is not a pack expansion\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 2429, __PRETTY_FUNCTION__)); |
2430 | return MemberOrEllipsisLocation; |
2431 | } |
2432 | |
2433 | /// If this is a base class initializer, returns the type of the |
2434 | /// base class with location information. Otherwise, returns an NULL |
2435 | /// type location. |
2436 | TypeLoc getBaseClassLoc() const; |
2437 | |
2438 | /// If this is a base class initializer, returns the type of the base class. |
2439 | /// Otherwise, returns null. |
2440 | const Type *getBaseClass() const; |
2441 | |
2442 | /// Returns whether the base is virtual or not. |
2443 | bool isBaseVirtual() const { |
2444 | assert(isBaseInitializer() && "Must call this on base initializer!")((isBaseInitializer() && "Must call this on base initializer!" ) ? static_cast<void> (0) : __assert_fail ("isBaseInitializer() && \"Must call this on base initializer!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 2444, __PRETTY_FUNCTION__)); |
2445 | |
2446 | return IsVirtual; |
2447 | } |
2448 | |
2449 | /// Returns the declarator information for a base class or delegating |
2450 | /// initializer. |
2451 | TypeSourceInfo *getTypeSourceInfo() const { |
2452 | return Initializee.dyn_cast<TypeSourceInfo *>(); |
2453 | } |
2454 | |
2455 | /// If this is a member initializer, returns the declaration of the |
2456 | /// non-static data member being initialized. Otherwise, returns null. |
2457 | FieldDecl *getMember() const { |
2458 | if (isMemberInitializer()) |
2459 | return Initializee.get<FieldDecl*>(); |
2460 | return nullptr; |
2461 | } |
2462 | |
2463 | FieldDecl *getAnyMember() const { |
2464 | if (isMemberInitializer()) |
2465 | return Initializee.get<FieldDecl*>(); |
2466 | if (isIndirectMemberInitializer()) |
2467 | return Initializee.get<IndirectFieldDecl*>()->getAnonField(); |
2468 | return nullptr; |
2469 | } |
2470 | |
2471 | IndirectFieldDecl *getIndirectMember() const { |
2472 | if (isIndirectMemberInitializer()) |
2473 | return Initializee.get<IndirectFieldDecl*>(); |
2474 | return nullptr; |
2475 | } |
2476 | |
2477 | SourceLocation getMemberLocation() const { |
2478 | return MemberOrEllipsisLocation; |
2479 | } |
2480 | |
2481 | /// Determine the source location of the initializer. |
2482 | SourceLocation getSourceLocation() const; |
2483 | |
2484 | /// Determine the source range covering the entire initializer. |
2485 | SourceRange getSourceRange() const LLVM_READONLY__attribute__((__pure__)); |
2486 | |
2487 | /// Determine whether this initializer is explicitly written |
2488 | /// in the source code. |
2489 | bool isWritten() const { return IsWritten; } |
2490 | |
2491 | /// Return the source position of the initializer, counting from 0. |
2492 | /// If the initializer was implicit, -1 is returned. |
2493 | int getSourceOrder() const { |
2494 | return IsWritten ? static_cast<int>(SourceOrder) : -1; |
2495 | } |
2496 | |
2497 | /// Set the source order of this initializer. |
2498 | /// |
2499 | /// This can only be called once for each initializer; it cannot be called |
2500 | /// on an initializer having a positive number of (implicit) array indices. |
2501 | /// |
2502 | /// This assumes that the initializer was written in the source code, and |
2503 | /// ensures that isWritten() returns true. |
2504 | void setSourceOrder(int Pos) { |
2505 | assert(!IsWritten &&((!IsWritten && "setSourceOrder() used on implicit initializer" ) ? static_cast<void> (0) : __assert_fail ("!IsWritten && \"setSourceOrder() used on implicit initializer\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 2506, __PRETTY_FUNCTION__)) |
2506 | "setSourceOrder() used on implicit initializer")((!IsWritten && "setSourceOrder() used on implicit initializer" ) ? static_cast<void> (0) : __assert_fail ("!IsWritten && \"setSourceOrder() used on implicit initializer\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 2506, __PRETTY_FUNCTION__)); |
2507 | assert(SourceOrder == 0 &&((SourceOrder == 0 && "calling twice setSourceOrder() on the same initializer" ) ? static_cast<void> (0) : __assert_fail ("SourceOrder == 0 && \"calling twice setSourceOrder() on the same initializer\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 2508, __PRETTY_FUNCTION__)) |
2508 | "calling twice setSourceOrder() on the same initializer")((SourceOrder == 0 && "calling twice setSourceOrder() on the same initializer" ) ? static_cast<void> (0) : __assert_fail ("SourceOrder == 0 && \"calling twice setSourceOrder() on the same initializer\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 2508, __PRETTY_FUNCTION__)); |
2509 | assert(Pos >= 0 &&((Pos >= 0 && "setSourceOrder() used to make an initializer implicit" ) ? static_cast<void> (0) : __assert_fail ("Pos >= 0 && \"setSourceOrder() used to make an initializer implicit\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 2510, __PRETTY_FUNCTION__)) |
2510 | "setSourceOrder() used to make an initializer implicit")((Pos >= 0 && "setSourceOrder() used to make an initializer implicit" ) ? static_cast<void> (0) : __assert_fail ("Pos >= 0 && \"setSourceOrder() used to make an initializer implicit\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 2510, __PRETTY_FUNCTION__)); |
2511 | IsWritten = true; |
2512 | SourceOrder = static_cast<unsigned>(Pos); |
2513 | } |
2514 | |
2515 | SourceLocation getLParenLoc() const { return LParenLoc; } |
2516 | SourceLocation getRParenLoc() const { return RParenLoc; } |
2517 | |
2518 | /// Get the initializer. |
2519 | Expr *getInit() const { return static_cast<Expr *>(Init); } |
2520 | }; |
2521 | |
2522 | /// Description of a constructor that was inherited from a base class. |
2523 | class InheritedConstructor { |
2524 | ConstructorUsingShadowDecl *Shadow = nullptr; |
2525 | CXXConstructorDecl *BaseCtor = nullptr; |
2526 | |
2527 | public: |
2528 | InheritedConstructor() = default; |
2529 | InheritedConstructor(ConstructorUsingShadowDecl *Shadow, |
2530 | CXXConstructorDecl *BaseCtor) |
2531 | : Shadow(Shadow), BaseCtor(BaseCtor) {} |
2532 | |
2533 | explicit operator bool() const { return Shadow; } |
2534 | |
2535 | ConstructorUsingShadowDecl *getShadowDecl() const { return Shadow; } |
2536 | CXXConstructorDecl *getConstructor() const { return BaseCtor; } |
2537 | }; |
2538 | |
2539 | /// Represents a C++ constructor within a class. |
2540 | /// |
2541 | /// For example: |
2542 | /// |
2543 | /// \code |
2544 | /// class X { |
2545 | /// public: |
2546 | /// explicit X(int); // represented by a CXXConstructorDecl. |
2547 | /// }; |
2548 | /// \endcode |
2549 | class CXXConstructorDecl final |
2550 | : public CXXMethodDecl, |
2551 | private llvm::TrailingObjects<CXXConstructorDecl, InheritedConstructor, |
2552 | ExplicitSpecifier> { |
2553 | // This class stores some data in DeclContext::CXXConstructorDeclBits |
2554 | // to save some space. Use the provided accessors to access it. |
2555 | |
2556 | /// \name Support for base and member initializers. |
2557 | /// \{ |
2558 | /// The arguments used to initialize the base or member. |
2559 | LazyCXXCtorInitializersPtr CtorInitializers; |
2560 | |
2561 | CXXConstructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2562 | const DeclarationNameInfo &NameInfo, QualType T, |
2563 | TypeSourceInfo *TInfo, ExplicitSpecifier ES, bool isInline, |
2564 | bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, |
2565 | InheritedConstructor Inherited); |
2566 | |
2567 | void anchor() override; |
2568 | |
2569 | size_t numTrailingObjects(OverloadToken<InheritedConstructor>) const { |
2570 | return CXXConstructorDeclBits.IsInheritingConstructor; |
2571 | } |
2572 | size_t numTrailingObjects(OverloadToken<ExplicitSpecifier>) const { |
2573 | return CXXConstructorDeclBits.HasTrailingExplicitSpecifier; |
2574 | } |
2575 | |
2576 | ExplicitSpecifier getExplicitSpecifierInternal() const { |
2577 | if (CXXConstructorDeclBits.HasTrailingExplicitSpecifier) |
2578 | return *getTrailingObjects<ExplicitSpecifier>(); |
2579 | return ExplicitSpecifier( |
2580 | nullptr, CXXConstructorDeclBits.IsSimpleExplicit |
2581 | ? ExplicitSpecKind::ResolvedTrue |
2582 | : ExplicitSpecKind::ResolvedFalse); |
2583 | } |
2584 | |
2585 | void setExplicitSpecifier(ExplicitSpecifier ES) { |
2586 | assert((!ES.getExpr() ||(((!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier ) && "cannot set this explicit specifier. no trail-allocated space for " "explicit") ? static_cast<void> (0) : __assert_fail ("(!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier) && \"cannot set this explicit specifier. no trail-allocated space for \" \"explicit\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 2589, __PRETTY_FUNCTION__)) |
2587 | CXXConstructorDeclBits.HasTrailingExplicitSpecifier) &&(((!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier ) && "cannot set this explicit specifier. no trail-allocated space for " "explicit") ? static_cast<void> (0) : __assert_fail ("(!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier) && \"cannot set this explicit specifier. no trail-allocated space for \" \"explicit\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 2589, __PRETTY_FUNCTION__)) |
2588 | "cannot set this explicit specifier. no trail-allocated space for "(((!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier ) && "cannot set this explicit specifier. no trail-allocated space for " "explicit") ? static_cast<void> (0) : __assert_fail ("(!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier) && \"cannot set this explicit specifier. no trail-allocated space for \" \"explicit\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 2589, __PRETTY_FUNCTION__)) |
2589 | "explicit")(((!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier ) && "cannot set this explicit specifier. no trail-allocated space for " "explicit") ? static_cast<void> (0) : __assert_fail ("(!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier) && \"cannot set this explicit specifier. no trail-allocated space for \" \"explicit\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 2589, __PRETTY_FUNCTION__)); |
2590 | if (ES.getExpr()) |
2591 | *getCanonicalDecl()->getTrailingObjects<ExplicitSpecifier>() = ES; |
2592 | else |
2593 | CXXConstructorDeclBits.IsSimpleExplicit = ES.isExplicit(); |
2594 | } |
2595 | |
2596 | enum TraillingAllocKind { |
2597 | TAKInheritsConstructor = 1, |
2598 | TAKHasTailExplicit = 1 << 1, |
2599 | }; |
2600 | |
2601 | uint64_t getTraillingAllocKind() const { |
2602 | return numTrailingObjects(OverloadToken<InheritedConstructor>()) | |
2603 | (numTrailingObjects(OverloadToken<ExplicitSpecifier>()) << 1); |
2604 | } |
2605 | |
2606 | public: |
2607 | friend class ASTDeclReader; |
2608 | friend class ASTDeclWriter; |
2609 | friend TrailingObjects; |
2610 | |
2611 | static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
2612 | uint64_t AllocKind); |
2613 | static CXXConstructorDecl * |
2614 | Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2615 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
2616 | ExplicitSpecifier ES, bool isInline, bool isImplicitlyDeclared, |
2617 | ConstexprSpecKind ConstexprKind, |
2618 | InheritedConstructor Inherited = InheritedConstructor()); |
2619 | |
2620 | ExplicitSpecifier getExplicitSpecifier() { |
2621 | return getCanonicalDecl()->getExplicitSpecifierInternal(); |
2622 | } |
2623 | const ExplicitSpecifier getExplicitSpecifier() const { |
2624 | return getCanonicalDecl()->getExplicitSpecifierInternal(); |
2625 | } |
2626 | |
2627 | /// Return true if the declartion is already resolved to be explicit. |
2628 | bool isExplicit() const { return getExplicitSpecifier().isExplicit(); } |
2629 | |
2630 | /// Iterates through the member/base initializer list. |
2631 | using init_iterator = CXXCtorInitializer **; |
2632 | |
2633 | /// Iterates through the member/base initializer list. |
2634 | using init_const_iterator = CXXCtorInitializer *const *; |
2635 | |
2636 | using init_range = llvm::iterator_range<init_iterator>; |
2637 | using init_const_range = llvm::iterator_range<init_const_iterator>; |
2638 | |
2639 | init_range inits() { return init_range(init_begin(), init_end()); } |
2640 | init_const_range inits() const { |
2641 | return init_const_range(init_begin(), init_end()); |
2642 | } |
2643 | |
2644 | /// Retrieve an iterator to the first initializer. |
2645 | init_iterator init_begin() { |
2646 | const auto *ConstThis = this; |
2647 | return const_cast<init_iterator>(ConstThis->init_begin()); |
2648 | } |
2649 | |
2650 | /// Retrieve an iterator to the first initializer. |
2651 | init_const_iterator init_begin() const; |
2652 | |
2653 | /// Retrieve an iterator past the last initializer. |
2654 | init_iterator init_end() { |
2655 | return init_begin() + getNumCtorInitializers(); |
2656 | } |
2657 | |
2658 | /// Retrieve an iterator past the last initializer. |
2659 | init_const_iterator init_end() const { |
2660 | return init_begin() + getNumCtorInitializers(); |
2661 | } |
2662 | |
2663 | using init_reverse_iterator = std::reverse_iterator<init_iterator>; |
2664 | using init_const_reverse_iterator = |
2665 | std::reverse_iterator<init_const_iterator>; |
2666 | |
2667 | init_reverse_iterator init_rbegin() { |
2668 | return init_reverse_iterator(init_end()); |
2669 | } |
2670 | init_const_reverse_iterator init_rbegin() const { |
2671 | return init_const_reverse_iterator(init_end()); |
2672 | } |
2673 | |
2674 | init_reverse_iterator init_rend() { |
2675 | return init_reverse_iterator(init_begin()); |
2676 | } |
2677 | init_const_reverse_iterator init_rend() const { |
2678 | return init_const_reverse_iterator(init_begin()); |
2679 | } |
2680 | |
2681 | /// Determine the number of arguments used to initialize the member |
2682 | /// or base. |
2683 | unsigned getNumCtorInitializers() const { |
2684 | return CXXConstructorDeclBits.NumCtorInitializers; |
2685 | } |
2686 | |
2687 | void setNumCtorInitializers(unsigned numCtorInitializers) { |
2688 | CXXConstructorDeclBits.NumCtorInitializers = numCtorInitializers; |
2689 | // This assert added because NumCtorInitializers is stored |
2690 | // in CXXConstructorDeclBits as a bitfield and its width has |
2691 | // been shrunk from 32 bits to fit into CXXConstructorDeclBitfields. |
2692 | assert(CXXConstructorDeclBits.NumCtorInitializers ==((CXXConstructorDeclBits.NumCtorInitializers == numCtorInitializers && "NumCtorInitializers overflow!") ? static_cast< void> (0) : __assert_fail ("CXXConstructorDeclBits.NumCtorInitializers == numCtorInitializers && \"NumCtorInitializers overflow!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 2693, __PRETTY_FUNCTION__)) |
2693 | numCtorInitializers && "NumCtorInitializers overflow!")((CXXConstructorDeclBits.NumCtorInitializers == numCtorInitializers && "NumCtorInitializers overflow!") ? static_cast< void> (0) : __assert_fail ("CXXConstructorDeclBits.NumCtorInitializers == numCtorInitializers && \"NumCtorInitializers overflow!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 2693, __PRETTY_FUNCTION__)); |
2694 | } |
2695 | |
2696 | void setCtorInitializers(CXXCtorInitializer **Initializers) { |
2697 | CtorInitializers = Initializers; |
2698 | } |
2699 | |
2700 | /// Determine whether this constructor is a delegating constructor. |
2701 | bool isDelegatingConstructor() const { |
2702 | return (getNumCtorInitializers() == 1) && |
2703 | init_begin()[0]->isDelegatingInitializer(); |
2704 | } |
2705 | |
2706 | /// When this constructor delegates to another, retrieve the target. |
2707 | CXXConstructorDecl *getTargetConstructor() const; |
2708 | |
2709 | /// Whether this constructor is a default |
2710 | /// constructor (C++ [class.ctor]p5), which can be used to |
2711 | /// default-initialize a class of this type. |
2712 | bool isDefaultConstructor() const; |
2713 | |
2714 | /// Whether this constructor is a copy constructor (C++ [class.copy]p2, |
2715 | /// which can be used to copy the class. |
2716 | /// |
2717 | /// \p TypeQuals will be set to the qualifiers on the |
2718 | /// argument type. For example, \p TypeQuals would be set to \c |
2719 | /// Qualifiers::Const for the following copy constructor: |
2720 | /// |
2721 | /// \code |
2722 | /// class X { |
2723 | /// public: |
2724 | /// X(const X&); |
2725 | /// }; |
2726 | /// \endcode |
2727 | bool isCopyConstructor(unsigned &TypeQuals) const; |
2728 | |
2729 | /// Whether this constructor is a copy |
2730 | /// constructor (C++ [class.copy]p2, which can be used to copy the |
2731 | /// class. |
2732 | bool isCopyConstructor() const { |
2733 | unsigned TypeQuals = 0; |
2734 | return isCopyConstructor(TypeQuals); |
2735 | } |
2736 | |
2737 | /// Determine whether this constructor is a move constructor |
2738 | /// (C++11 [class.copy]p3), which can be used to move values of the class. |
2739 | /// |
2740 | /// \param TypeQuals If this constructor is a move constructor, will be set |
2741 | /// to the type qualifiers on the referent of the first parameter's type. |
2742 | bool isMoveConstructor(unsigned &TypeQuals) const; |
2743 | |
2744 | /// Determine whether this constructor is a move constructor |
2745 | /// (C++11 [class.copy]p3), which can be used to move values of the class. |
2746 | bool isMoveConstructor() const { |
2747 | unsigned TypeQuals = 0; |
2748 | return isMoveConstructor(TypeQuals); |
2749 | } |
2750 | |
2751 | /// Determine whether this is a copy or move constructor. |
2752 | /// |
2753 | /// \param TypeQuals Will be set to the type qualifiers on the reference |
2754 | /// parameter, if in fact this is a copy or move constructor. |
2755 | bool isCopyOrMoveConstructor(unsigned &TypeQuals) const; |
2756 | |
2757 | /// Determine whether this a copy or move constructor. |
2758 | bool isCopyOrMoveConstructor() const { |
2759 | unsigned Quals; |
2760 | return isCopyOrMoveConstructor(Quals); |
2761 | } |
2762 | |
2763 | /// Whether this constructor is a |
2764 | /// converting constructor (C++ [class.conv.ctor]), which can be |
2765 | /// used for user-defined conversions. |
2766 | bool isConvertingConstructor(bool AllowExplicit) const; |
2767 | |
2768 | /// Determine whether this is a member template specialization that |
2769 | /// would copy the object to itself. Such constructors are never used to copy |
2770 | /// an object. |
2771 | bool isSpecializationCopyingObject() const; |
2772 | |
2773 | /// Determine whether this is an implicit constructor synthesized to |
2774 | /// model a call to a constructor inherited from a base class. |
2775 | bool isInheritingConstructor() const { |
2776 | return CXXConstructorDeclBits.IsInheritingConstructor; |
2777 | } |
2778 | |
2779 | /// State that this is an implicit constructor synthesized to |
2780 | /// model a call to a constructor inherited from a base class. |
2781 | void setInheritingConstructor(bool isIC = true) { |
2782 | CXXConstructorDeclBits.IsInheritingConstructor = isIC; |
2783 | } |
2784 | |
2785 | /// Get the constructor that this inheriting constructor is based on. |
2786 | InheritedConstructor getInheritedConstructor() const { |
2787 | return isInheritingConstructor() ? |
2788 | *getTrailingObjects<InheritedConstructor>() : InheritedConstructor(); |
2789 | } |
2790 | |
2791 | CXXConstructorDecl *getCanonicalDecl() override { |
2792 | return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl()); |
2793 | } |
2794 | const CXXConstructorDecl *getCanonicalDecl() const { |
2795 | return const_cast<CXXConstructorDecl*>(this)->getCanonicalDecl(); |
2796 | } |
2797 | |
2798 | // Implement isa/cast/dyncast/etc. |
2799 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2800 | static bool classofKind(Kind K) { return K == CXXConstructor; } |
2801 | }; |
2802 | |
2803 | /// Represents a C++ destructor within a class. |
2804 | /// |
2805 | /// For example: |
2806 | /// |
2807 | /// \code |
2808 | /// class X { |
2809 | /// public: |
2810 | /// ~X(); // represented by a CXXDestructorDecl. |
2811 | /// }; |
2812 | /// \endcode |
2813 | class CXXDestructorDecl : public CXXMethodDecl { |
2814 | friend class ASTDeclReader; |
2815 | friend class ASTDeclWriter; |
2816 | |
2817 | // FIXME: Don't allocate storage for these except in the first declaration |
2818 | // of a virtual destructor. |
2819 | FunctionDecl *OperatorDelete = nullptr; |
2820 | Expr *OperatorDeleteThisArg = nullptr; |
2821 | |
2822 | CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2823 | const DeclarationNameInfo &NameInfo, QualType T, |
2824 | TypeSourceInfo *TInfo, bool isInline, |
2825 | bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind) |
2826 | : CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo, |
2827 | SC_None, isInline, ConstexprKind, SourceLocation()) { |
2828 | setImplicit(isImplicitlyDeclared); |
2829 | } |
2830 | |
2831 | void anchor() override; |
2832 | |
2833 | public: |
2834 | static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, |
2835 | SourceLocation StartLoc, |
2836 | const DeclarationNameInfo &NameInfo, |
2837 | QualType T, TypeSourceInfo *TInfo, |
2838 | bool isInline, bool isImplicitlyDeclared, |
2839 | ConstexprSpecKind ConstexprKind); |
2840 | static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID); |
2841 | |
2842 | void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg); |
2843 | |
2844 | const FunctionDecl *getOperatorDelete() const { |
2845 | return getCanonicalDecl()->OperatorDelete; |
2846 | } |
2847 | |
2848 | Expr *getOperatorDeleteThisArg() const { |
2849 | return getCanonicalDecl()->OperatorDeleteThisArg; |
2850 | } |
2851 | |
2852 | CXXDestructorDecl *getCanonicalDecl() override { |
2853 | return cast<CXXDestructorDecl>(FunctionDecl::getCanonicalDecl()); |
2854 | } |
2855 | const CXXDestructorDecl *getCanonicalDecl() const { |
2856 | return const_cast<CXXDestructorDecl*>(this)->getCanonicalDecl(); |
2857 | } |
2858 | |
2859 | // Implement isa/cast/dyncast/etc. |
2860 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2861 | static bool classofKind(Kind K) { return K == CXXDestructor; } |
2862 | }; |
2863 | |
2864 | /// Represents a C++ conversion function within a class. |
2865 | /// |
2866 | /// For example: |
2867 | /// |
2868 | /// \code |
2869 | /// class X { |
2870 | /// public: |
2871 | /// operator bool(); |
2872 | /// }; |
2873 | /// \endcode |
2874 | class CXXConversionDecl : public CXXMethodDecl { |
2875 | CXXConversionDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2876 | const DeclarationNameInfo &NameInfo, QualType T, |
2877 | TypeSourceInfo *TInfo, bool isInline, ExplicitSpecifier ES, |
2878 | ConstexprSpecKind ConstexprKind, SourceLocation EndLocation) |
2879 | : CXXMethodDecl(CXXConversion, C, RD, StartLoc, NameInfo, T, TInfo, |
2880 | SC_None, isInline, ConstexprKind, EndLocation), |
2881 | ExplicitSpec(ES) {} |
2882 | void anchor() override; |
2883 | |
2884 | ExplicitSpecifier ExplicitSpec; |
2885 | |
2886 | void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; } |
2887 | |
2888 | public: |
2889 | friend class ASTDeclReader; |
2890 | friend class ASTDeclWriter; |
2891 | |
2892 | static CXXConversionDecl * |
2893 | Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2894 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
2895 | bool isInline, ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind, |
2896 | SourceLocation EndLocation); |
2897 | static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2898 | |
2899 | ExplicitSpecifier getExplicitSpecifier() { |
2900 | return getCanonicalDecl()->ExplicitSpec; |
2901 | } |
2902 | |
2903 | const ExplicitSpecifier getExplicitSpecifier() const { |
2904 | return getCanonicalDecl()->ExplicitSpec; |
2905 | } |
2906 | |
2907 | /// Return true if the declartion is already resolved to be explicit. |
2908 | bool isExplicit() const { return getExplicitSpecifier().isExplicit(); } |
2909 | |
2910 | /// Returns the type that this conversion function is converting to. |
2911 | QualType getConversionType() const { |
2912 | return getType()->castAs<FunctionType>()->getReturnType(); |
2913 | } |
2914 | |
2915 | /// Determine whether this conversion function is a conversion from |
2916 | /// a lambda closure type to a block pointer. |
2917 | bool isLambdaToBlockPointerConversion() const; |
2918 | |
2919 | CXXConversionDecl *getCanonicalDecl() override { |
2920 | return cast<CXXConversionDecl>(FunctionDecl::getCanonicalDecl()); |
2921 | } |
2922 | const CXXConversionDecl *getCanonicalDecl() const { |
2923 | return const_cast<CXXConversionDecl*>(this)->getCanonicalDecl(); |
2924 | } |
2925 | |
2926 | // Implement isa/cast/dyncast/etc. |
2927 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2928 | static bool classofKind(Kind K) { return K == CXXConversion; } |
2929 | }; |
2930 | |
2931 | /// Represents a linkage specification. |
2932 | /// |
2933 | /// For example: |
2934 | /// \code |
2935 | /// extern "C" void foo(); |
2936 | /// \endcode |
2937 | class LinkageSpecDecl : public Decl, public DeclContext { |
2938 | virtual void anchor(); |
2939 | // This class stores some data in DeclContext::LinkageSpecDeclBits to save |
2940 | // some space. Use the provided accessors to access it. |
2941 | public: |
2942 | /// Represents the language in a linkage specification. |
2943 | /// |
2944 | /// The values are part of the serialization ABI for |
2945 | /// ASTs and cannot be changed without altering that ABI. To help |
2946 | /// ensure a stable ABI for this, we choose the DW_LANG_ encodings |
2947 | /// from the dwarf standard. |
2948 | enum LanguageIDs { |
2949 | lang_c = llvm::dwarf::DW_LANG_C, |
2950 | lang_cxx = llvm::dwarf::DW_LANG_C_plus_plus, |
2951 | lang_cxx_11 = llvm::dwarf::DW_LANG_C_plus_plus_11, |
2952 | lang_cxx_14 = llvm::dwarf::DW_LANG_C_plus_plus_14 |
2953 | }; |
2954 | |
2955 | private: |
2956 | /// The source location for the extern keyword. |
2957 | SourceLocation ExternLoc; |
2958 | |
2959 | /// The source location for the right brace (if valid). |
2960 | SourceLocation RBraceLoc; |
2961 | |
2962 | LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc, |
2963 | SourceLocation LangLoc, LanguageIDs lang, bool HasBraces); |
2964 | |
2965 | public: |
2966 | static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC, |
2967 | SourceLocation ExternLoc, |
2968 | SourceLocation LangLoc, LanguageIDs Lang, |
2969 | bool HasBraces); |
2970 | static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2971 | |
2972 | /// Return the language specified by this linkage specification. |
2973 | LanguageIDs getLanguage() const { |
2974 | return static_cast<LanguageIDs>(LinkageSpecDeclBits.Language); |
2975 | } |
2976 | |
2977 | /// Set the language specified by this linkage specification. |
2978 | void setLanguage(LanguageIDs L) { LinkageSpecDeclBits.Language = L; } |
2979 | |
2980 | /// Determines whether this linkage specification had braces in |
2981 | /// its syntactic form. |
2982 | bool hasBraces() const { |
2983 | assert(!RBraceLoc.isValid() || LinkageSpecDeclBits.HasBraces)((!RBraceLoc.isValid() || LinkageSpecDeclBits.HasBraces) ? static_cast <void> (0) : __assert_fail ("!RBraceLoc.isValid() || LinkageSpecDeclBits.HasBraces" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 2983, __PRETTY_FUNCTION__)); |
2984 | return LinkageSpecDeclBits.HasBraces; |
2985 | } |
2986 | |
2987 | SourceLocation getExternLoc() const { return ExternLoc; } |
2988 | SourceLocation getRBraceLoc() const { return RBraceLoc; } |
2989 | void setExternLoc(SourceLocation L) { ExternLoc = L; } |
2990 | void setRBraceLoc(SourceLocation L) { |
2991 | RBraceLoc = L; |
2992 | LinkageSpecDeclBits.HasBraces = RBraceLoc.isValid(); |
2993 | } |
2994 | |
2995 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { |
2996 | if (hasBraces()) |
2997 | return getRBraceLoc(); |
2998 | // No braces: get the end location of the (only) declaration in context |
2999 | // (if present). |
3000 | return decls_empty() ? getLocation() : decls_begin()->getEndLoc(); |
3001 | } |
3002 | |
3003 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
3004 | return SourceRange(ExternLoc, getEndLoc()); |
3005 | } |
3006 | |
3007 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3008 | static bool classofKind(Kind K) { return K == LinkageSpec; } |
3009 | |
3010 | static DeclContext *castToDeclContext(const LinkageSpecDecl *D) { |
3011 | return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D)); |
3012 | } |
3013 | |
3014 | static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) { |
3015 | return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC)); |
3016 | } |
3017 | }; |
3018 | |
3019 | /// Represents C++ using-directive. |
3020 | /// |
3021 | /// For example: |
3022 | /// \code |
3023 | /// using namespace std; |
3024 | /// \endcode |
3025 | /// |
3026 | /// \note UsingDirectiveDecl should be Decl not NamedDecl, but we provide |
3027 | /// artificial names for all using-directives in order to store |
3028 | /// them in DeclContext effectively. |
3029 | class UsingDirectiveDecl : public NamedDecl { |
3030 | /// The location of the \c using keyword. |
3031 | SourceLocation UsingLoc; |
3032 | |
3033 | /// The location of the \c namespace keyword. |
3034 | SourceLocation NamespaceLoc; |
3035 | |
3036 | /// The nested-name-specifier that precedes the namespace. |
3037 | NestedNameSpecifierLoc QualifierLoc; |
3038 | |
3039 | /// The namespace nominated by this using-directive. |
3040 | NamedDecl *NominatedNamespace; |
3041 | |
3042 | /// Enclosing context containing both using-directive and nominated |
3043 | /// namespace. |
3044 | DeclContext *CommonAncestor; |
3045 | |
3046 | UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc, |
3047 | SourceLocation NamespcLoc, |
3048 | NestedNameSpecifierLoc QualifierLoc, |
3049 | SourceLocation IdentLoc, |
3050 | NamedDecl *Nominated, |
3051 | DeclContext *CommonAncestor) |
3052 | : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc), |
3053 | NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc), |
3054 | NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) {} |
3055 | |
3056 | /// Returns special DeclarationName used by using-directives. |
3057 | /// |
3058 | /// This is only used by DeclContext for storing UsingDirectiveDecls in |
3059 | /// its lookup structure. |
3060 | static DeclarationName getName() { |
3061 | return DeclarationName::getUsingDirectiveName(); |
3062 | } |
3063 | |
3064 | void anchor() override; |
3065 | |
3066 | public: |
3067 | friend class ASTDeclReader; |
3068 | |
3069 | // Friend for getUsingDirectiveName. |
3070 | friend class DeclContext; |
3071 | |
3072 | /// Retrieve the nested-name-specifier that qualifies the |
3073 | /// name of the namespace, with source-location information. |
3074 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3075 | |
3076 | /// Retrieve the nested-name-specifier that qualifies the |
3077 | /// name of the namespace. |
3078 | NestedNameSpecifier *getQualifier() const { |
3079 | return QualifierLoc.getNestedNameSpecifier(); |
3080 | } |
3081 | |
3082 | NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; } |
3083 | const NamedDecl *getNominatedNamespaceAsWritten() const { |
3084 | return NominatedNamespace; |
3085 | } |
3086 | |
3087 | /// Returns the namespace nominated by this using-directive. |
3088 | NamespaceDecl *getNominatedNamespace(); |
3089 | |
3090 | const NamespaceDecl *getNominatedNamespace() const { |
3091 | return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace(); |
3092 | } |
3093 | |
3094 | /// Returns the common ancestor context of this using-directive and |
3095 | /// its nominated namespace. |
3096 | DeclContext *getCommonAncestor() { return CommonAncestor; } |
3097 | const DeclContext *getCommonAncestor() const { return CommonAncestor; } |
3098 | |
3099 | /// Return the location of the \c using keyword. |
3100 | SourceLocation getUsingLoc() const { return UsingLoc; } |
3101 | |
3102 | // FIXME: Could omit 'Key' in name. |
3103 | /// Returns the location of the \c namespace keyword. |
3104 | SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; } |
3105 | |
3106 | /// Returns the location of this using declaration's identifier. |
3107 | SourceLocation getIdentLocation() const { return getLocation(); } |
3108 | |
3109 | static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC, |
3110 | SourceLocation UsingLoc, |
3111 | SourceLocation NamespaceLoc, |
3112 | NestedNameSpecifierLoc QualifierLoc, |
3113 | SourceLocation IdentLoc, |
3114 | NamedDecl *Nominated, |
3115 | DeclContext *CommonAncestor); |
3116 | static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3117 | |
3118 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
3119 | return SourceRange(UsingLoc, getLocation()); |
3120 | } |
3121 | |
3122 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3123 | static bool classofKind(Kind K) { return K == UsingDirective; } |
3124 | }; |
3125 | |
3126 | /// Represents a C++ namespace alias. |
3127 | /// |
3128 | /// For example: |
3129 | /// |
3130 | /// \code |
3131 | /// namespace Foo = Bar; |
3132 | /// \endcode |
3133 | class NamespaceAliasDecl : public NamedDecl, |
3134 | public Redeclarable<NamespaceAliasDecl> { |
3135 | friend class ASTDeclReader; |
3136 | |
3137 | /// The location of the \c namespace keyword. |
3138 | SourceLocation NamespaceLoc; |
3139 | |
3140 | /// The location of the namespace's identifier. |
3141 | /// |
3142 | /// This is accessed by TargetNameLoc. |
3143 | SourceLocation IdentLoc; |
3144 | |
3145 | /// The nested-name-specifier that precedes the namespace. |
3146 | NestedNameSpecifierLoc QualifierLoc; |
3147 | |
3148 | /// The Decl that this alias points to, either a NamespaceDecl or |
3149 | /// a NamespaceAliasDecl. |
3150 | NamedDecl *Namespace; |
3151 | |
3152 | NamespaceAliasDecl(ASTContext &C, DeclContext *DC, |
3153 | SourceLocation NamespaceLoc, SourceLocation AliasLoc, |
3154 | IdentifierInfo *Alias, NestedNameSpecifierLoc QualifierLoc, |
3155 | SourceLocation IdentLoc, NamedDecl *Namespace) |
3156 | : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias), redeclarable_base(C), |
3157 | NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc), |
3158 | QualifierLoc(QualifierLoc), Namespace(Namespace) {} |
3159 | |
3160 | void anchor() override; |
3161 | |
3162 | using redeclarable_base = Redeclarable<NamespaceAliasDecl>; |
3163 | |
3164 | NamespaceAliasDecl *getNextRedeclarationImpl() override; |
3165 | NamespaceAliasDecl *getPreviousDeclImpl() override; |
3166 | NamespaceAliasDecl *getMostRecentDeclImpl() override; |
3167 | |
3168 | public: |
3169 | static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC, |
3170 | SourceLocation NamespaceLoc, |
3171 | SourceLocation AliasLoc, |
3172 | IdentifierInfo *Alias, |
3173 | NestedNameSpecifierLoc QualifierLoc, |
3174 | SourceLocation IdentLoc, |
3175 | NamedDecl *Namespace); |
3176 | |
3177 | static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3178 | |
3179 | using redecl_range = redeclarable_base::redecl_range; |
3180 | using redecl_iterator = redeclarable_base::redecl_iterator; |
3181 | |
3182 | using redeclarable_base::redecls_begin; |
3183 | using redeclarable_base::redecls_end; |
3184 | using redeclarable_base::redecls; |
3185 | using redeclarable_base::getPreviousDecl; |
3186 | using redeclarable_base::getMostRecentDecl; |
3187 | |
3188 | NamespaceAliasDecl *getCanonicalDecl() override { |
3189 | return getFirstDecl(); |
3190 | } |
3191 | const NamespaceAliasDecl *getCanonicalDecl() const { |
3192 | return getFirstDecl(); |
3193 | } |
3194 | |
3195 | /// Retrieve the nested-name-specifier that qualifies the |
3196 | /// name of the namespace, with source-location information. |
3197 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3198 | |
3199 | /// Retrieve the nested-name-specifier that qualifies the |
3200 | /// name of the namespace. |
3201 | NestedNameSpecifier *getQualifier() const { |
3202 | return QualifierLoc.getNestedNameSpecifier(); |
3203 | } |
3204 | |
3205 | /// Retrieve the namespace declaration aliased by this directive. |
3206 | NamespaceDecl *getNamespace() { |
3207 | if (auto *AD = dyn_cast<NamespaceAliasDecl>(Namespace)) |
3208 | return AD->getNamespace(); |
3209 | |
3210 | return cast<NamespaceDecl>(Namespace); |
3211 | } |
3212 | |
3213 | const NamespaceDecl *getNamespace() const { |
3214 | return const_cast<NamespaceAliasDecl *>(this)->getNamespace(); |
3215 | } |
3216 | |
3217 | /// Returns the location of the alias name, i.e. 'foo' in |
3218 | /// "namespace foo = ns::bar;". |
3219 | SourceLocation getAliasLoc() const { return getLocation(); } |
3220 | |
3221 | /// Returns the location of the \c namespace keyword. |
3222 | SourceLocation getNamespaceLoc() const { return NamespaceLoc; } |
3223 | |
3224 | /// Returns the location of the identifier in the named namespace. |
3225 | SourceLocation getTargetNameLoc() const { return IdentLoc; } |
3226 | |
3227 | /// Retrieve the namespace that this alias refers to, which |
3228 | /// may either be a NamespaceDecl or a NamespaceAliasDecl. |
3229 | NamedDecl *getAliasedNamespace() const { return Namespace; } |
3230 | |
3231 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
3232 | return SourceRange(NamespaceLoc, IdentLoc); |
3233 | } |
3234 | |
3235 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3236 | static bool classofKind(Kind K) { return K == NamespaceAlias; } |
3237 | }; |
3238 | |
3239 | /// Represents a shadow declaration introduced into a scope by a |
3240 | /// (resolved) using declaration. |
3241 | /// |
3242 | /// For example, |
3243 | /// \code |
3244 | /// namespace A { |
3245 | /// void foo(); |
3246 | /// } |
3247 | /// namespace B { |
3248 | /// using A::foo; // <- a UsingDecl |
3249 | /// // Also creates a UsingShadowDecl for A::foo() in B |
3250 | /// } |
3251 | /// \endcode |
3252 | class UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> { |
3253 | friend class UsingDecl; |
3254 | |
3255 | /// The referenced declaration. |
3256 | NamedDecl *Underlying = nullptr; |
3257 | |
3258 | /// The using declaration which introduced this decl or the next using |
3259 | /// shadow declaration contained in the aforementioned using declaration. |
3260 | NamedDecl *UsingOrNextShadow = nullptr; |
3261 | |
3262 | void anchor() override; |
3263 | |
3264 | using redeclarable_base = Redeclarable<UsingShadowDecl>; |
3265 | |
3266 | UsingShadowDecl *getNextRedeclarationImpl() override { |
3267 | return getNextRedeclaration(); |
3268 | } |
3269 | |
3270 | UsingShadowDecl *getPreviousDeclImpl() override { |
3271 | return getPreviousDecl(); |
3272 | } |
3273 | |
3274 | UsingShadowDecl *getMostRecentDeclImpl() override { |
3275 | return getMostRecentDecl(); |
3276 | } |
3277 | |
3278 | protected: |
3279 | UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC, SourceLocation Loc, |
3280 | UsingDecl *Using, NamedDecl *Target); |
3281 | UsingShadowDecl(Kind K, ASTContext &C, EmptyShell); |
3282 | |
3283 | public: |
3284 | friend class ASTDeclReader; |
3285 | friend class ASTDeclWriter; |
3286 | |
3287 | static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC, |
3288 | SourceLocation Loc, UsingDecl *Using, |
3289 | NamedDecl *Target) { |
3290 | return new (C, DC) UsingShadowDecl(UsingShadow, C, DC, Loc, Using, Target); |
3291 | } |
3292 | |
3293 | static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3294 | |
3295 | using redecl_range = redeclarable_base::redecl_range; |
3296 | using redecl_iterator = redeclarable_base::redecl_iterator; |
3297 | |
3298 | using redeclarable_base::redecls_begin; |
3299 | using redeclarable_base::redecls_end; |
3300 | using redeclarable_base::redecls; |
3301 | using redeclarable_base::getPreviousDecl; |
3302 | using redeclarable_base::getMostRecentDecl; |
3303 | using redeclarable_base::isFirstDecl; |
3304 | |
3305 | UsingShadowDecl *getCanonicalDecl() override { |
3306 | return getFirstDecl(); |
3307 | } |
3308 | const UsingShadowDecl *getCanonicalDecl() const { |
3309 | return getFirstDecl(); |
3310 | } |
3311 | |
3312 | /// Gets the underlying declaration which has been brought into the |
3313 | /// local scope. |
3314 | NamedDecl *getTargetDecl() const { return Underlying; } |
3315 | |
3316 | /// Sets the underlying declaration which has been brought into the |
3317 | /// local scope. |
3318 | void setTargetDecl(NamedDecl *ND) { |
3319 | assert(ND && "Target decl is null!")((ND && "Target decl is null!") ? static_cast<void > (0) : __assert_fail ("ND && \"Target decl is null!\"" , "/build/llvm-toolchain-snapshot-10~svn373517/tools/clang/include/clang/AST/DeclCXX.h" , 3319, __PRETTY_FUNCTION__)); |
3320 | Underlying = ND; |
3321 | // A UsingShadowDecl is never a friend or local extern declaration, even |
3322 | // if it is a shadow declaration for one. |
3323 | IdentifierNamespace = |
3324 | ND->getIdentifierNamespace() & |
3325 | ~(IDNS_OrdinaryFriend | IDNS_TagFriend | IDNS_LocalExtern); |
3326 | } |
3327 | |
3328 | /// Gets the using declaration to which this declaration is tied. |
3329 | UsingDecl *getUsingDecl() const; |
3330 | |
3331 | /// The next using shadow declaration contained in the shadow decl |
3332 | /// chain of the using declaration which introduced this decl. |
3333 | UsingShadowDecl *getNextUsingShadowDecl() const { |
3334 | return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow); |
3335 | } |
3336 | |
3337 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3338 | static bool classofKind(Kind K) { |
3339 | return K == Decl::UsingShadow || K == Decl::ConstructorUsingShadow; |
3340 | } |
3341 | }; |
3342 | |
3343 | /// Represents a shadow constructor declaration introduced into a |
3344 | /// class by a C++11 using-declaration that names a constructor. |
3345 | /// |
3346 | /// For example: |
3347 | /// \code |
3348 | /// struct Base { Base(int); }; |
3349 | /// struct Derived { |
3350 | /// using Base::Base; // creates a UsingDecl and a ConstructorUsingShadowDecl |
3351 | /// }; |
3352 | /// \endcode |
3353 | class ConstructorUsingShadowDecl final : public UsingShadowDecl { |
3354 | /// If this constructor using declaration inherted the constructor |
3355 | /// from an indirect base class, this is the ConstructorUsingShadowDecl |
3356 | /// in the named direct base class from which the declaration was inherited. |
3357 | ConstructorUsingShadowDecl *NominatedBaseClassShadowDecl = nullptr; |
3358 | |
3359 | /// If this constructor using declaration inherted the constructor |
3360 | /// from an indirect base class, this is the ConstructorUsingShadowDecl |
3361 | /// that will be used to construct the unique direct or virtual base class |
3362 | /// that receives the constructor arguments. |
3363 | ConstructorUsingShadowDecl *ConstructedBaseClassShadowDecl = nullptr; |
3364 | |
3365 | /// \c true if the constructor ultimately named by this using shadow |
3366 | /// declaration is within a virtual base class subobject of the class that |
3367 | /// contains this declaration. |
3368 | unsigned IsVirtual : 1; |
3369 | |
3370 | ConstructorUsingShadowDecl(ASTContext &C, DeclContext *DC, SourceLocation Loc, |
3371 | UsingDecl *Using, NamedDecl *Target, |
3372 | bool TargetInVirtualBase) |
3373 | : UsingShadowDecl(ConstructorUsingShadow, C, DC, Loc, Using, |
3374 | Target->getUnderlyingDecl()), |
3375 | NominatedBaseClassShadowDecl( |
3376 | dyn_cast<ConstructorUsingShadowDecl>(Target)), |
3377 | ConstructedBaseClassShadowDecl(NominatedBaseClassShadowDecl), |
3378 | IsVirtual(TargetInVirtualBase) { |
3379 | // If we found a constructor that chains to a constructor for a virtual |
3380 | // base, we should directly call that virtual base constructor instead. |
3381 | // FIXME: This logic belongs in Sema. |
3382 | if (NominatedBaseClassShadowDecl && |
3383 | NominatedBaseClassShadowDecl->constructsVirtualBase()) { |
3384 | ConstructedBaseClassShadowDecl = |
3385 | NominatedBaseClassShadowDecl->ConstructedBaseClassShadowDecl; |
3386 | IsVirtual = true; |
3387 | } |
3388 | } |
3389 | |
3390 | ConstructorUsingShadowDecl(ASTContext &C, EmptyShell Empty) |
3391 | : UsingShadowDecl(ConstructorUsingShadow, C, Empty), IsVirtual(false) {} |
3392 | |
3393 | void anchor() override; |
3394 | |
3395 | public: |
3396 | friend class ASTDeclReader; |
3397 | friend class ASTDeclWriter; |
3398 | |
3399 | static ConstructorUsingShadowDecl *Create(ASTContext &C, DeclContext *DC, |
3400 | SourceLocation Loc, |
3401 | UsingDecl *Using, NamedDecl *Target, |
3402 | bool IsVirtual); |
3403 | static ConstructorUsingShadowDecl *CreateDeserialized(ASTContext &C, |
3404 | unsigned ID); |
3405 | |
3406 | /// Returns the parent of this using shadow declaration, which |
3407 | /// is the class in which this is declared. |
3408 | //@{ |
3409 | const CXXRecordDecl *getParent() const { |
3410 | return cast<CXXRecordDecl>(getDeclContext()); |
3411 | } |
3412 | CXXRecordDecl *getParent() { |
3413 | return cast<CXXRecordDecl>(getDeclContext()); |
3414 | } |
3415 | //@} |
3416 | |
3417 | /// Get the inheriting constructor declaration for the direct base |
3418 | /// class from which this using shadow declaration was inherited, if there is |
3419 | /// one. This can be different for each redeclaration of the same shadow decl. |
3420 | ConstructorUsingShadowDecl *getNominatedBaseClassShadowDecl() const { |
3421 | return NominatedBaseClassShadowDecl; |
3422 | } |
3423 | |
3424 | /// Get the inheriting constructor declaration for the base class |
3425 | /// for which we don't have an explicit initializer, if there is one. |
3426 | ConstructorUsingShadowDecl *getConstructedBaseClassShadowDecl() const { |
3427 | return ConstructedBaseClassShadowDecl; |
3428 | } |
3429 | |
3430 | /// Get the base class that was named in the using declaration. This |
3431 | /// can be different for each redeclaration of this same shadow decl. |
3432 | CXXRecordDecl *getNominatedBaseClass() const; |
3433 | |
3434 | /// Get the base class whose constructor or constructor shadow |
3435 | /// declaration is passed the constructor arguments. |
3436 | CXXRecordDecl *getConstructedBaseClass() const { |
3437 | return cast<CXXRecordDecl>((ConstructedBaseClassShadowDecl |
3438 | ? ConstructedBaseClassShadowDecl |
3439 | : getTargetDecl()) |
3440 | ->getDeclContext()); |
3441 | } |
3442 | |
3443 | /// Returns \c true if the constructed base class is a virtual base |
3444 | /// class subobject of this declaration's class. |
3445 | bool constructsVirtualBase() const { |
3446 | return IsVirtual; |
3447 | } |
3448 | |
3449 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3450 | static bool classofKind(Kind K) { return K == ConstructorUsingShadow; } |
3451 | }; |
3452 | |
3453 | /// Represents a C++ using-declaration. |
3454 | /// |
3455 | /// For example: |
3456 | /// \code |
3457 | /// using someNameSpace::someIdentifier; |
3458 | /// \endcode |
3459 | class UsingDecl : public NamedDecl, public Mergeable<UsingDecl> { |
3460 | /// The source location of the 'using' keyword itself. |
3461 | SourceLocation UsingLocation; |
3462 | |
3463 | /// The nested-name-specifier that precedes the name. |
3464 | NestedNameSpecifierLoc QualifierLoc; |
3465 | |
3466 | /// Provides source/type location info for the declaration name |
3467 | /// embedded in the ValueDecl base class. |
3468 | DeclarationNameLoc DNLoc; |
3469 | |
3470 | /// The first shadow declaration of the shadow decl chain associated |
3471 | /// with this using declaration. |
3472 | /// |
3473 | /// The bool member of the pair store whether this decl has the \c typename |
3474 | /// keyword. |
3475 | llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow; |
3476 | |
3477 | UsingDecl(DeclContext *DC, SourceLocation UL, |
3478 | NestedNameSpecifierLoc QualifierLoc, |
3479 | const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword) |
3480 | : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()), |
3481 | UsingLocation(UL), QualifierLoc(QualifierLoc), |
3482 | DNLoc(NameInfo.getInfo()), FirstUsingShadow(nullptr, HasTypenameKeyword) { |
3483 | } |
3484 | |
3485 | void anchor() override; |
3486 | |
3487 | public: |
3488 | friend class ASTDeclReader; |
3489 | friend class ASTDeclWriter; |
3490 | |
3491 | /// Return the source location of the 'using' keyword. |
3492 | SourceLocation getUsingLoc() const { return UsingLocation; } |
3493 | |
3494 | /// Set the source location of the 'using' keyword. |
3495 | void setUsingLoc(SourceLocation L) { UsingLocation = L; } |
3496 | |
3497 | /// Retrieve the nested-name-specifier that qualifies the name, |
3498 | /// with source-location information. |
3499 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3500 | |
3501 | /// Retrieve the nested-name-specifier that qualifies the name. |
3502 | NestedNameSpecifier *getQualifier() const { |
3503 | return QualifierLoc.getNestedNameSpecifier(); |
3504 | } |
3505 | |
3506 | DeclarationNameInfo getNameInfo() const { |
3507 | return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); |
3508 | } |
3509 | |
3510 | /// Return true if it is a C++03 access declaration (no 'using'). |
3511 | bool isAccessDeclaration() const { return UsingLocation.isInvalid(); } |
3512 | |
3513 | /// Return true if the using declaration has 'typename'. |
3514 | bool hasTypename() const { return FirstUsingShadow.getInt(); } |
3515 | |
3516 | /// Sets whether the using declaration has 'typename'. |
3517 | void setTypename(bool TN) { FirstUsingShadow.setInt(TN); } |
3518 | |
3519 | /// Iterates through the using shadow declarations associated with |
3520 | /// this using declaration. |
3521 | class shadow_iterator { |
3522 | /// The current using shadow declaration. |
3523 | UsingShadowDecl *Current = nullptr; |
3524 | |
3525 | public: |
3526 | using value_type = UsingShadowDecl *; |
3527 | using reference = UsingShadowDecl *; |
3528 | using pointer = UsingShadowDecl *; |
3529 | using iterator_category = std::forward_iterator_tag; |
3530 | using difference_type = std::ptrdiff_t; |
3531 | |
3532 | shadow_iterator() = default; |
3533 | explicit shadow_iterator(UsingShadowDecl *C) : Current(C) {} |
3534 | |
3535 | reference operator*() const { return Current; } |
3536 | pointer operator->() const { return Current; } |
3537 | |
3538 | shadow_iterator& operator++() { |
3539 | Current = Current->getNextUsingShadowDecl(); |
3540 | return *this; |
3541 | } |
3542 | |
3543 | shadow_iterator operator++(int) { |
3544 | shadow_iterator tmp(*this); |
3545 | ++(*this); |
3546 | return tmp; |
3547 | } |
3548 | |
3549 | friend bool operator==(shadow_iterator x, shadow_iterator y) { |
3550 | return x.Current == y.Current; |
3551 | } |
3552 | friend bool operator!=(shadow_iterator x, shadow_iterator y) { |
3553 | return x.Current != y.Current; |
3554 | } |
3555 | }; |
3556 | |
3557 | using shadow_range = llvm::iterator_range<shadow_iterator>; |
3558 | |
3559 | shadow_range shadows() const { |
3560 | return shadow_range(shadow_begin(), shadow_end()); |
3561 | } |
3562 | |
3563 | shadow_iterator shadow_begin() const { |
3564 | return shadow_iterator(FirstUsingShadow.getPointer()); |
3565 | } |
3566 | |
3567 | shadow_iterator shadow_end() const { return shadow_iterator(); } |
3568 | |
3569 | /// Return the number of shadowed declarations associated with this |
3570 | /// using declaration. |
3571 | unsigned shadow_size() const { |
3572 | return std::distance(shadow_begin(), shadow_end()); |
3573 | } |
3574 | |
3575 | void addShadowDecl(UsingShadowDecl *S); |
3576 | void removeShadowDecl(UsingShadowDecl *S); |
3577 | |
3578 | static UsingDecl *Create(ASTContext &C, DeclContext *DC, |
3579 | SourceLocation UsingL, |
3580 | NestedNameSpecifierLoc QualifierLoc, |
3581 | const DeclarationNameInfo &NameInfo, |
3582 | bool HasTypenameKeyword); |
3583 | |
3584 | static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3585 | |
3586 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)); |
3587 | |
3588 | /// Retrieves the canonical declaration of this declaration. |
3589 | UsingDecl *getCanonicalDecl() override { return getFirstDecl(); } |
3590 | const UsingDecl *getCanonicalDecl() const { return getFirstDecl(); } |
3591 | |
3592 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3593 | static bool classofKind(Kind K) { return K == Using; } |
3594 | }; |
3595 | |
3596 | /// Represents a pack of using declarations that a single |
3597 | /// using-declarator pack-expanded into. |
3598 | /// |
3599 | /// \code |
3600 | /// template<typename ...T> struct X : T... { |
3601 | /// using T::operator()...; |
3602 | /// using T::operator T...; |
3603 | /// }; |
3604 | /// \endcode |
3605 | /// |
3606 | /// In the second case above, the UsingPackDecl will have the name |
3607 | /// 'operator T' (which contains an unexpanded pack), but the individual |
3608 | /// UsingDecls and UsingShadowDecls will have more reasonable names. |
3609 | class UsingPackDecl final |
3610 | : public NamedDecl, public Mergeable<UsingPackDecl>, |
3611 | private llvm::TrailingObjects<UsingPackDecl, NamedDecl *> { |
3612 | /// The UnresolvedUsingValueDecl or UnresolvedUsingTypenameDecl from |
3613 | /// which this waas instantiated. |
3614 | NamedDecl *InstantiatedFrom; |
3615 | |
3616 | /// The number of using-declarations created by this pack expansion. |
3617 | unsigned NumExpansions; |
3618 | |
3619 | UsingPackDecl(DeclContext *DC, NamedDecl *InstantiatedFrom, |
3620 | ArrayRef<NamedDecl *> UsingDecls) |
3621 | : NamedDecl(UsingPack, DC, |
3622 | InstantiatedFrom ? InstantiatedFrom->getLocation() |
3623 | : SourceLocation(), |
3624 | InstantiatedFrom ? InstantiatedFrom->getDeclName() |
3625 | : DeclarationName()), |
3626 | InstantiatedFrom(InstantiatedFrom), NumExpansions(UsingDecls.size()) { |
3627 | std::uninitialized_copy(UsingDecls.begin(), UsingDecls.end(), |
3628 | getTrailingObjects<NamedDecl *>()); |
3629 | } |
3630 | |
3631 | void anchor() override; |
3632 | |
3633 | public: |
3634 | friend class ASTDeclReader; |
3635 | friend class ASTDeclWriter; |
3636 | friend TrailingObjects; |
3637 | |
3638 | /// Get the using declaration from which this was instantiated. This will |
3639 | /// always be an UnresolvedUsingValueDecl or an UnresolvedUsingTypenameDecl |
3640 | /// that is a pack expansion. |
3641 | NamedDecl *getInstantiatedFromUsingDecl() const { return InstantiatedFrom; } |
3642 | |
3643 | /// Get the set of using declarations that this pack expanded into. Note that |
3644 | /// some of these may still be unresolved. |
3645 | ArrayRef<NamedDecl *> expansions() const { |
3646 | return llvm::makeArrayRef(getTrailingObjects<NamedDecl *>(), NumExpansions); |
3647 | } |
3648 | |
3649 | static UsingPackDecl *Create(ASTContext &C, DeclContext *DC, |
3650 | NamedDecl *InstantiatedFrom, |
3651 | ArrayRef<NamedDecl *> UsingDecls); |
3652 | |
3653 | static UsingPackDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
3654 | unsigned NumExpansions); |
3655 | |
3656 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
3657 | return InstantiatedFrom->getSourceRange(); |
3658 | } |
3659 | |
3660 | UsingPackDecl *getCanonicalDecl() override { return getFirstDecl(); } |
3661 | const UsingPackDecl *getCanonicalDecl() const { return getFirstDecl(); } |
3662 | |
3663 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3664 | static bool classofKind(Kind K) { return K == UsingPack; } |
3665 | }; |
3666 | |
3667 | /// Represents a dependent using declaration which was not marked with |
3668 | /// \c typename. |
3669 | /// |
3670 | /// Unlike non-dependent using declarations, these *only* bring through |
3671 | /// non-types; otherwise they would break two-phase lookup. |
3672 | /// |
3673 | /// \code |
3674 | /// template \<class T> class A : public Base<T> { |
3675 | /// using Base<T>::foo; |
3676 | /// }; |
3677 | /// \endcode |
3678 | class UnresolvedUsingValueDecl : public ValueDecl, |
3679 | public Mergeable<UnresolvedUsingValueDecl> { |
3680 | /// The source location of the 'using' keyword |
3681 | SourceLocation UsingLocation; |
3682 | |
3683 | /// If this is a pack expansion, the location of the '...'. |
3684 | SourceLocation EllipsisLoc; |
3685 | |
3686 | /// The nested-name-specifier that precedes the name. |
3687 | NestedNameSpecifierLoc QualifierLoc; |
3688 | |
3689 | /// Provides source/type location info for the declaration name |
3690 | /// embedded in the ValueDecl base class. |
3691 | DeclarationNameLoc DNLoc; |
3692 | |
3693 | UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty, |
3694 | SourceLocation UsingLoc, |
3695 | NestedNameSpecifierLoc QualifierLoc, |
3696 | const DeclarationNameInfo &NameInfo, |
3697 | SourceLocation EllipsisLoc) |
3698 | : ValueDecl(UnresolvedUsingValue, DC, |
3699 | NameInfo.getLoc(), NameInfo.getName(), Ty), |
3700 | UsingLocation(UsingLoc), EllipsisLoc(EllipsisLoc), |
3701 | QualifierLoc(QualifierLoc), DNLoc(NameInfo.getInfo()) {} |
3702 | |
3703 | void anchor() override; |
3704 | |
3705 | public: |
3706 | friend class ASTDeclReader; |
3707 | friend class ASTDeclWriter; |
3708 | |
3709 | /// Returns the source location of the 'using' keyword. |
3710 | SourceLocation getUsingLoc() const { return UsingLocation; } |
3711 | |
3712 | /// Set the source location of the 'using' keyword. |
3713 | void setUsingLoc(SourceLocation L) { UsingLocation = L; } |
3714 | |
3715 | /// Return true if it is a C++03 access declaration (no 'using'). |
3716 | bool isAccessDeclaration() const { return UsingLocation.isInvalid(); } |
3717 | |
3718 | /// Retrieve the nested-name-specifier that qualifies the name, |
3719 | /// with source-location information. |
3720 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3721 | |
3722 | /// Retrieve the nested-name-specifier that qualifies the name. |
3723 | NestedNameSpecifier *getQualifier() const { |
3724 | return QualifierLoc.getNestedNameSpecifier(); |
3725 | } |
3726 | |
3727 | DeclarationNameInfo getNameInfo() const { |
3728 | return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); |
3729 | } |
3730 | |
3731 | /// Determine whether this is a pack expansion. |
3732 | bool isPackExpansion() const { |
3733 | return EllipsisLoc.isValid(); |
3734 | } |
3735 | |
3736 | /// Get the location of the ellipsis if this is a pack expansion. |
3737 | SourceLocation getEllipsisLoc() const { |
3738 | return EllipsisLoc; |
3739 | } |
3740 | |
3741 | static UnresolvedUsingValueDecl * |
3742 | Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, |
3743 | NestedNameSpecifierLoc QualifierLoc, |
3744 | const DeclarationNameInfo &NameInfo, SourceLocation EllipsisLoc); |
3745 | |
3746 | static UnresolvedUsingValueDecl * |
3747 | CreateDeserialized(ASTContext &C, unsigned ID); |
3748 | |
3749 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)); |
3750 | |
3751 | /// Retrieves the canonical declaration of this declaration. |
3752 | UnresolvedUsingValueDecl *getCanonicalDecl() override { |
3753 | return getFirstDecl(); |
3754 | } |
3755 | const UnresolvedUsingValueDecl *getCanonicalDecl() const { |
3756 | return getFirstDecl(); |
3757 | } |
3758 | |
3759 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3760 | static bool classofKind(Kind K) { return K == UnresolvedUsingValue; } |
3761 | }; |
3762 | |
3763 | /// Represents a dependent using declaration which was marked with |
3764 | /// \c typename. |
3765 | /// |
3766 | /// \code |
3767 | /// template \<class T> class A : public Base<T> { |
3768 | /// using typename Base<T>::foo; |
3769 | /// }; |
3770 | /// \endcode |
3771 | /// |
3772 | /// The type associated with an unresolved using typename decl is |
3773 | /// currently always a typename type. |
3774 | class UnresolvedUsingTypenameDecl |
3775 | : public TypeDecl, |
3776 | public Mergeable<UnresolvedUsingTypenameDecl> { |
3777 | friend class ASTDeclReader; |
3778 | |
3779 | /// The source location of the 'typename' keyword |
3780 | SourceLocation TypenameLocation; |
3781 | |
3782 | /// If this is a pack expansion, the location of the '...'. |
3783 | SourceLocation EllipsisLoc; |
3784 | |
3785 | /// The nested-name-specifier that precedes the name. |
3786 | NestedNameSpecifierLoc QualifierLoc; |
3787 | |
3788 | UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc, |
3789 | SourceLocation TypenameLoc, |
3790 | NestedNameSpecifierLoc QualifierLoc, |
3791 | SourceLocation TargetNameLoc, |
3792 | IdentifierInfo *TargetName, |
3793 | SourceLocation EllipsisLoc) |
3794 | : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName, |
3795 | UsingLoc), |
3796 | TypenameLocation(TypenameLoc), EllipsisLoc(EllipsisLoc), |
3797 | QualifierLoc(QualifierLoc) {} |
3798 | |
3799 | void anchor() override; |
3800 | |
3801 | public: |
3802 | /// Returns the source location of the 'using' keyword. |
3803 | SourceLocation getUsingLoc() const { return getBeginLoc(); } |
3804 | |
3805 | /// Returns the source location of the 'typename' keyword. |
3806 | SourceLocation getTypenameLoc() const { return TypenameLocation; } |
3807 | |
3808 | /// Retrieve the nested-name-specifier that qualifies the name, |
3809 | /// with source-location information. |
3810 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3811 | |
3812 | /// Retrieve the nested-name-specifier that qualifies the name. |
3813 | NestedNameSpecifier *getQualifier() const { |
3814 | return QualifierLoc.getNestedNameSpecifier(); |
3815 | } |
3816 | |
3817 | DeclarationNameInfo getNameInfo() const { |
3818 | return DeclarationNameInfo(getDeclName(), getLocation()); |
3819 | } |
3820 | |
3821 | /// Determine whether this is a pack expansion. |
3822 | bool isPackExpansion() const { |
3823 | return EllipsisLoc.isValid(); |
3824 | } |
3825 | |
3826 | /// Get the location of the ellipsis if this is a pack expansion. |
3827 | SourceLocation getEllipsisLoc() const { |
3828 | return EllipsisLoc; |
3829 | } |
3830 | |
3831 | static UnresolvedUsingTypenameDecl * |
3832 | Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, |
3833 | SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc, |
3834 | SourceLocation TargetNameLoc, DeclarationName TargetName, |
3835 | SourceLocation EllipsisLoc); |
3836 | |
3837 | static UnresolvedUsingTypenameDecl * |
3838 | CreateDeserialized(ASTContext &C, unsigned ID); |
3839 | |
3840 | /// Retrieves the canonical declaration of this declaration. |
3841 | UnresolvedUsingTypenameDecl *getCanonicalDecl() override { |
3842 | return getFirstDecl(); |
3843 | } |
3844 | const UnresolvedUsingTypenameDecl *getCanonicalDecl() const { |
3845 | return getFirstDecl(); |
3846 | } |
3847 | |
3848 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3849 | static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; } |
3850 | }; |
3851 | |
3852 | /// Represents a C++11 static_assert declaration. |
3853 | class StaticAssertDecl : public Decl { |
3854 | llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed; |
3855 | StringLiteral *Message; |
3856 | SourceLocation RParenLoc; |
3857 | |
3858 | StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc, |
3859 | Expr *AssertExpr, StringLiteral *Message, |
3860 | SourceLocation RParenLoc, bool Failed) |
3861 | : Decl(StaticAssert, DC, StaticAssertLoc), |
3862 | AssertExprAndFailed(AssertExpr, Failed), Message(Message), |
3863 | RParenLoc(RParenLoc) {} |
3864 | |
3865 | virtual void anchor(); |
3866 | |
3867 | public: |
3868 | friend class ASTDeclReader; |
3869 | |
3870 | static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC, |
3871 | SourceLocation StaticAssertLoc, |
3872 | Expr *AssertExpr, StringLiteral *Message, |
3873 | SourceLocation RParenLoc, bool Failed); |
3874 | static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3875 | |
3876 | Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); } |
3877 | const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); } |
3878 | |
3879 | StringLiteral *getMessage() { return Message; } |
3880 | const StringLiteral *getMessage() const { return Message; } |
3881 | |
3882 | bool isFailed() const { return AssertExprAndFailed.getInt(); } |
3883 | |
3884 | SourceLocation getRParenLoc() const { return RParenLoc; } |
3885 | |
3886 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
3887 | return SourceRange(getLocation(), getRParenLoc()); |
3888 | } |
3889 | |
3890 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3891 | static bool classofKind(Kind K) { return K == StaticAssert; } |
3892 | }; |
3893 | |
3894 | /// A binding in a decomposition declaration. For instance, given: |
3895 | /// |
3896 | /// int n[3]; |
3897 | /// auto &[a, b, c] = n; |
3898 | /// |
3899 | /// a, b, and c are BindingDecls, whose bindings are the expressions |
3900 | /// x[0], x[1], and x[2] respectively, where x is the implicit |
3901 | /// DecompositionDecl of type 'int (&)[3]'. |
3902 | class BindingDecl : public ValueDecl { |
3903 | /// The declaration that this binding binds to part of. |
3904 | LazyDeclPtr Decomp; |
3905 | /// The binding represented by this declaration. References to this |
3906 | /// declaration are effectively equivalent to this expression (except |
3907 | /// that it is only evaluated once at the point of declaration of the |
3908 | /// binding). |
3909 | Expr *Binding = nullptr; |
3910 | |
3911 | BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id) |
3912 | : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()) {} |
3913 | |
3914 | void anchor() override; |
3915 | |
3916 | public: |
3917 | friend class ASTDeclReader; |
3918 | |
3919 | static BindingDecl *Create(ASTContext &C, DeclContext *DC, |
3920 | SourceLocation IdLoc, IdentifierInfo *Id); |
3921 | static BindingDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3922 | |
3923 | /// Get the expression to which this declaration is bound. This may be null |
3924 | /// in two different cases: while parsing the initializer for the |
3925 | /// decomposition declaration, and when the initializer is type-dependent. |
3926 | Expr *getBinding() const { return Binding; } |
3927 | |
3928 | /// Get the decomposition declaration that this binding represents a |
3929 | /// decomposition of. |
3930 | ValueDecl *getDecomposedDecl() const; |
3931 | |
3932 | /// Get the variable (if any) that holds the value of evaluating the binding. |
3933 | /// Only present for user-defined bindings for tuple-like types. |
3934 | VarDecl *getHoldingVar() const; |
3935 | |
3936 | /// Set the binding for this BindingDecl, along with its declared type (which |
3937 | /// should be a possibly-cv-qualified form of the type of the binding, or a |
3938 | /// reference to such a type). |
3939 | void setBinding(QualType DeclaredType, Expr *Binding) { |
3940 | setType(DeclaredType); |
3941 | this->Binding = Binding; |
3942 | } |
3943 | |
3944 | /// Set the decomposed variable for this BindingDecl. |
3945 | void setDecomposedDecl(ValueDecl *Decomposed) { Decomp = Decomposed; } |
3946 | |
3947 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3948 | static bool classofKind(Kind K) { return K == Decl::Binding; } |
3949 | }; |
3950 | |
3951 | /// A decomposition declaration. For instance, given: |
3952 | /// |
3953 | /// int n[3]; |
3954 | /// auto &[a, b, c] = n; |
3955 | /// |
3956 | /// the second line declares a DecompositionDecl of type 'int (&)[3]', and |
3957 | /// three BindingDecls (named a, b, and c). An instance of this class is always |
3958 | /// unnamed, but behaves in almost all other respects like a VarDecl. |
3959 | class DecompositionDecl final |
3960 | : public VarDecl, |
3961 | private llvm::TrailingObjects<DecompositionDecl, BindingDecl *> { |
3962 | /// The number of BindingDecl*s following this object. |
3963 | unsigned NumBindings; |
3964 | |
3965 | DecompositionDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
3966 | SourceLocation LSquareLoc, QualType T, |
3967 | TypeSourceInfo *TInfo, StorageClass SC, |
3968 | ArrayRef<BindingDecl *> Bindings) |
3969 | : VarDecl(Decomposition, C, DC, StartLoc, LSquareLoc, nullptr, T, TInfo, |
3970 | SC), |
3971 | NumBindings(Bindings.size()) { |
3972 | std::uninitialized_copy(Bindings.begin(), Bindings.end(), |
3973 | getTrailingObjects<BindingDecl *>()); |
3974 | for (auto *B : Bindings) |
3975 | B->setDecomposedDecl(this); |
3976 | } |
3977 | |
3978 | void anchor() override; |
3979 | |
3980 | public: |
3981 | friend class ASTDeclReader; |
3982 | friend TrailingObjects; |
3983 | |
3984 | static DecompositionDecl *Create(ASTContext &C, DeclContext *DC, |
3985 | SourceLocation StartLoc, |
3986 | SourceLocation LSquareLoc, |
3987 | QualType T, TypeSourceInfo *TInfo, |
3988 | StorageClass S, |
3989 | ArrayRef<BindingDecl *> Bindings); |
3990 | static DecompositionDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
3991 | unsigned NumBindings); |
3992 | |
3993 | ArrayRef<BindingDecl *> bindings() const { |
3994 | return llvm::makeArrayRef(getTrailingObjects<BindingDecl *>(), NumBindings); |
3995 | } |
3996 | |
3997 | void printName(raw_ostream &os) const override; |
3998 | |
3999 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
4000 | static bool classofKind(Kind K) { return K == Decomposition; } |
4001 | }; |
4002 | |
4003 | /// An instance of this class represents the declaration of a property |
4004 | /// member. This is a Microsoft extension to C++, first introduced in |
4005 | /// Visual Studio .NET 2003 as a parallel to similar features in C# |
4006 | /// and Managed C++. |
4007 | /// |
4008 | /// A property must always be a non-static class member. |
4009 | /// |
4010 | /// A property member superficially resembles a non-static data |
4011 | /// member, except preceded by a property attribute: |
4012 | /// __declspec(property(get=GetX, put=PutX)) int x; |
4013 | /// Either (but not both) of the 'get' and 'put' names may be omitted. |
4014 | /// |
4015 | /// A reference to a property is always an lvalue. If the lvalue |
4016 | /// undergoes lvalue-to-rvalue conversion, then a getter name is |
4017 | /// required, and that member is called with no arguments. |
4018 | /// If the lvalue is assigned into, then a setter name is required, |
4019 | /// and that member is called with one argument, the value assigned. |
4020 | /// Both operations are potentially overloaded. Compound assignments |
4021 | /// are permitted, as are the increment and decrement operators. |
4022 | /// |
4023 | /// The getter and putter methods are permitted to be overloaded, |
4024 | /// although their return and parameter types are subject to certain |
4025 | /// restrictions according to the type of the property. |
4026 | /// |
4027 | /// A property declared using an incomplete array type may |
4028 | /// additionally be subscripted, adding extra parameters to the getter |
4029 | /// and putter methods. |
4030 | class MSPropertyDecl : public DeclaratorDecl { |
4031 | IdentifierInfo *GetterId, *SetterId; |
4032 | |
4033 | MSPropertyDecl(DeclContext *DC, SourceLocation L, DeclarationName N, |
4034 | QualType T, TypeSourceInfo *TInfo, SourceLocation StartL, |
4035 | IdentifierInfo *Getter, IdentifierInfo *Setter) |
4036 | : DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL), |
4037 | GetterId(Getter), SetterId(Setter) {} |
4038 | |
4039 | void anchor() override; |
4040 | public: |
4041 | friend class ASTDeclReader; |
4042 | |
4043 | static MSPropertyDecl *Create(ASTContext &C, DeclContext *DC, |
4044 | SourceLocation L, DeclarationName N, QualType T, |
4045 | TypeSourceInfo *TInfo, SourceLocation StartL, |
4046 | IdentifierInfo *Getter, IdentifierInfo *Setter); |
4047 | static MSPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
4048 | |
4049 | static bool classof(const Decl *D) { return D->getKind() == MSProperty; } |
4050 | |
4051 | bool hasGetter() const { return GetterId != nullptr; } |
4052 | IdentifierInfo* getGetterId() const { return GetterId; } |
4053 | bool hasSetter() const { return SetterId != nullptr; } |
4054 | IdentifierInfo* getSetterId() const { return SetterId; } |
4055 | }; |
4056 | |
4057 | /// Insertion operator for diagnostics. This allows sending an AccessSpecifier |
4058 | /// into a diagnostic with <<. |
4059 | const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, |
4060 | AccessSpecifier AS); |
4061 | |
4062 | const PartialDiagnostic &operator<<(const PartialDiagnostic &DB, |
4063 | AccessSpecifier AS); |
4064 | |
4065 | } // namespace clang |
4066 | |
4067 | #endif // LLVM_CLANG_AST_DECLCXX_H |