File: | clang/lib/Sema/SemaTemplateInstantiate.cpp |
Warning: | line 1029, column 15 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | //===------- SemaTemplateInstantiate.cpp - C++ Template Instantiation ------===/ | ||||||
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 | // This file implements C++ template instantiation. | ||||||
9 | // | ||||||
10 | //===----------------------------------------------------------------------===/ | ||||||
11 | |||||||
12 | #include "TreeTransform.h" | ||||||
13 | #include "clang/AST/ASTConsumer.h" | ||||||
14 | #include "clang/AST/ASTContext.h" | ||||||
15 | #include "clang/AST/ASTLambda.h" | ||||||
16 | #include "clang/AST/ASTMutationListener.h" | ||||||
17 | #include "clang/AST/DeclTemplate.h" | ||||||
18 | #include "clang/AST/Expr.h" | ||||||
19 | #include "clang/AST/PrettyDeclStackTrace.h" | ||||||
20 | #include "clang/AST/TypeVisitor.h" | ||||||
21 | #include "clang/Basic/LangOptions.h" | ||||||
22 | #include "clang/Basic/Stack.h" | ||||||
23 | #include "clang/Basic/TargetInfo.h" | ||||||
24 | #include "clang/Sema/DeclSpec.h" | ||||||
25 | #include "clang/Sema/Initialization.h" | ||||||
26 | #include "clang/Sema/Lookup.h" | ||||||
27 | #include "clang/Sema/SemaConcept.h" | ||||||
28 | #include "clang/Sema/SemaInternal.h" | ||||||
29 | #include "clang/Sema/Template.h" | ||||||
30 | #include "clang/Sema/TemplateDeduction.h" | ||||||
31 | #include "clang/Sema/TemplateInstCallback.h" | ||||||
32 | #include "llvm/Support/TimeProfiler.h" | ||||||
33 | |||||||
34 | using namespace clang; | ||||||
35 | using namespace sema; | ||||||
36 | |||||||
37 | //===----------------------------------------------------------------------===/ | ||||||
38 | // Template Instantiation Support | ||||||
39 | //===----------------------------------------------------------------------===/ | ||||||
40 | |||||||
41 | /// Retrieve the template argument list(s) that should be used to | ||||||
42 | /// instantiate the definition of the given declaration. | ||||||
43 | /// | ||||||
44 | /// \param D the declaration for which we are computing template instantiation | ||||||
45 | /// arguments. | ||||||
46 | /// | ||||||
47 | /// \param Innermost if non-NULL, the innermost template argument list. | ||||||
48 | /// | ||||||
49 | /// \param RelativeToPrimary true if we should get the template | ||||||
50 | /// arguments relative to the primary template, even when we're | ||||||
51 | /// dealing with a specialization. This is only relevant for function | ||||||
52 | /// template specializations. | ||||||
53 | /// | ||||||
54 | /// \param Pattern If non-NULL, indicates the pattern from which we will be | ||||||
55 | /// instantiating the definition of the given declaration, \p D. This is | ||||||
56 | /// used to determine the proper set of template instantiation arguments for | ||||||
57 | /// friend function template specializations. | ||||||
58 | MultiLevelTemplateArgumentList | ||||||
59 | Sema::getTemplateInstantiationArgs(NamedDecl *D, | ||||||
60 | const TemplateArgumentList *Innermost, | ||||||
61 | bool RelativeToPrimary, | ||||||
62 | const FunctionDecl *Pattern) { | ||||||
63 | // Accumulate the set of template argument lists in this structure. | ||||||
64 | MultiLevelTemplateArgumentList Result; | ||||||
65 | |||||||
66 | if (Innermost) | ||||||
67 | Result.addOuterTemplateArguments(Innermost); | ||||||
68 | |||||||
69 | DeclContext *Ctx = dyn_cast<DeclContext>(D); | ||||||
70 | if (!Ctx) { | ||||||
71 | Ctx = D->getDeclContext(); | ||||||
72 | |||||||
73 | // Add template arguments from a variable template instantiation. For a | ||||||
74 | // class-scope explicit specialization, there are no template arguments | ||||||
75 | // at this level, but there may be enclosing template arguments. | ||||||
76 | VarTemplateSpecializationDecl *Spec = | ||||||
77 | dyn_cast<VarTemplateSpecializationDecl>(D); | ||||||
78 | if (Spec && !Spec->isClassScopeExplicitSpecialization()) { | ||||||
79 | // We're done when we hit an explicit specialization. | ||||||
80 | if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization && | ||||||
81 | !isa<VarTemplatePartialSpecializationDecl>(Spec)) | ||||||
82 | return Result; | ||||||
83 | |||||||
84 | Result.addOuterTemplateArguments(&Spec->getTemplateInstantiationArgs()); | ||||||
85 | |||||||
86 | // If this variable template specialization was instantiated from a | ||||||
87 | // specialized member that is a variable template, we're done. | ||||||
88 | assert(Spec->getSpecializedTemplate() && "No variable template?")(static_cast <bool> (Spec->getSpecializedTemplate() && "No variable template?") ? void (0) : __assert_fail ("Spec->getSpecializedTemplate() && \"No variable template?\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 88, __extension__ __PRETTY_FUNCTION__)); | ||||||
89 | llvm::PointerUnion<VarTemplateDecl*, | ||||||
90 | VarTemplatePartialSpecializationDecl*> Specialized | ||||||
91 | = Spec->getSpecializedTemplateOrPartial(); | ||||||
92 | if (VarTemplatePartialSpecializationDecl *Partial = | ||||||
93 | Specialized.dyn_cast<VarTemplatePartialSpecializationDecl *>()) { | ||||||
94 | if (Partial->isMemberSpecialization()) | ||||||
95 | return Result; | ||||||
96 | } else { | ||||||
97 | VarTemplateDecl *Tmpl = Specialized.get<VarTemplateDecl *>(); | ||||||
98 | if (Tmpl->isMemberSpecialization()) | ||||||
99 | return Result; | ||||||
100 | } | ||||||
101 | } | ||||||
102 | |||||||
103 | // If we have a template template parameter with translation unit context, | ||||||
104 | // then we're performing substitution into a default template argument of | ||||||
105 | // this template template parameter before we've constructed the template | ||||||
106 | // that will own this template template parameter. In this case, we | ||||||
107 | // use empty template parameter lists for all of the outer templates | ||||||
108 | // to avoid performing any substitutions. | ||||||
109 | if (Ctx->isTranslationUnit()) { | ||||||
110 | if (TemplateTemplateParmDecl *TTP | ||||||
111 | = dyn_cast<TemplateTemplateParmDecl>(D)) { | ||||||
112 | for (unsigned I = 0, N = TTP->getDepth() + 1; I != N; ++I) | ||||||
113 | Result.addOuterTemplateArguments(None); | ||||||
114 | return Result; | ||||||
115 | } | ||||||
116 | } | ||||||
117 | } | ||||||
118 | |||||||
119 | while (!Ctx->isFileContext()) { | ||||||
120 | // Add template arguments from a class template instantiation. | ||||||
121 | ClassTemplateSpecializationDecl *Spec | ||||||
122 | = dyn_cast<ClassTemplateSpecializationDecl>(Ctx); | ||||||
123 | if (Spec && !Spec->isClassScopeExplicitSpecialization()) { | ||||||
124 | // We're done when we hit an explicit specialization. | ||||||
125 | if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization && | ||||||
126 | !isa<ClassTemplatePartialSpecializationDecl>(Spec)) | ||||||
127 | break; | ||||||
128 | |||||||
129 | Result.addOuterTemplateArguments(&Spec->getTemplateInstantiationArgs()); | ||||||
130 | |||||||
131 | // If this class template specialization was instantiated from a | ||||||
132 | // specialized member that is a class template, we're done. | ||||||
133 | assert(Spec->getSpecializedTemplate() && "No class template?")(static_cast <bool> (Spec->getSpecializedTemplate() && "No class template?") ? void (0) : __assert_fail ("Spec->getSpecializedTemplate() && \"No class template?\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 133, __extension__ __PRETTY_FUNCTION__)); | ||||||
134 | if (Spec->getSpecializedTemplate()->isMemberSpecialization()) | ||||||
135 | break; | ||||||
136 | } | ||||||
137 | // Add template arguments from a function template specialization. | ||||||
138 | else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Ctx)) { | ||||||
139 | if (!RelativeToPrimary && | ||||||
140 | Function->getTemplateSpecializationKindForInstantiation() == | ||||||
141 | TSK_ExplicitSpecialization) | ||||||
142 | break; | ||||||
143 | |||||||
144 | if (!RelativeToPrimary && Function->getTemplateSpecializationKind() == | ||||||
145 | TSK_ExplicitSpecialization) { | ||||||
146 | // This is an implicit instantiation of an explicit specialization. We | ||||||
147 | // don't get any template arguments from this function but might get | ||||||
148 | // some from an enclosing template. | ||||||
149 | } else if (const TemplateArgumentList *TemplateArgs | ||||||
150 | = Function->getTemplateSpecializationArgs()) { | ||||||
151 | // Add the template arguments for this specialization. | ||||||
152 | Result.addOuterTemplateArguments(TemplateArgs); | ||||||
153 | |||||||
154 | // If this function was instantiated from a specialized member that is | ||||||
155 | // a function template, we're done. | ||||||
156 | assert(Function->getPrimaryTemplate() && "No function template?")(static_cast <bool> (Function->getPrimaryTemplate() && "No function template?") ? void (0) : __assert_fail ("Function->getPrimaryTemplate() && \"No function template?\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 156, __extension__ __PRETTY_FUNCTION__)); | ||||||
157 | if (Function->getPrimaryTemplate()->isMemberSpecialization()) | ||||||
158 | break; | ||||||
159 | |||||||
160 | // If this function is a generic lambda specialization, we are done. | ||||||
161 | if (isGenericLambdaCallOperatorOrStaticInvokerSpecialization(Function)) | ||||||
162 | break; | ||||||
163 | |||||||
164 | } else if (FunctionTemplateDecl *FunTmpl | ||||||
165 | = Function->getDescribedFunctionTemplate()) { | ||||||
166 | // Add the "injected" template arguments. | ||||||
167 | Result.addOuterTemplateArguments(FunTmpl->getInjectedTemplateArgs()); | ||||||
168 | } | ||||||
169 | |||||||
170 | // If this is a friend declaration and it declares an entity at | ||||||
171 | // namespace scope, take arguments from its lexical parent | ||||||
172 | // instead of its semantic parent, unless of course the pattern we're | ||||||
173 | // instantiating actually comes from the file's context! | ||||||
174 | if (Function->getFriendObjectKind() && | ||||||
175 | Function->getDeclContext()->isFileContext() && | ||||||
176 | (!Pattern || !Pattern->getLexicalDeclContext()->isFileContext())) { | ||||||
177 | Ctx = Function->getLexicalDeclContext(); | ||||||
178 | RelativeToPrimary = false; | ||||||
179 | continue; | ||||||
180 | } | ||||||
181 | } else if (CXXRecordDecl *Rec = dyn_cast<CXXRecordDecl>(Ctx)) { | ||||||
182 | if (ClassTemplateDecl *ClassTemplate = Rec->getDescribedClassTemplate()) { | ||||||
183 | QualType T = ClassTemplate->getInjectedClassNameSpecialization(); | ||||||
184 | const TemplateSpecializationType *TST = | ||||||
185 | cast<TemplateSpecializationType>(Context.getCanonicalType(T)); | ||||||
186 | Result.addOuterTemplateArguments( | ||||||
187 | llvm::makeArrayRef(TST->getArgs(), TST->getNumArgs())); | ||||||
188 | if (ClassTemplate->isMemberSpecialization()) | ||||||
189 | break; | ||||||
190 | } | ||||||
191 | } | ||||||
192 | |||||||
193 | Ctx = Ctx->getParent(); | ||||||
194 | RelativeToPrimary = false; | ||||||
195 | } | ||||||
196 | |||||||
197 | return Result; | ||||||
198 | } | ||||||
199 | |||||||
200 | bool Sema::CodeSynthesisContext::isInstantiationRecord() const { | ||||||
201 | switch (Kind) { | ||||||
202 | case TemplateInstantiation: | ||||||
203 | case ExceptionSpecInstantiation: | ||||||
204 | case DefaultTemplateArgumentInstantiation: | ||||||
205 | case DefaultFunctionArgumentInstantiation: | ||||||
206 | case ExplicitTemplateArgumentSubstitution: | ||||||
207 | case DeducedTemplateArgumentSubstitution: | ||||||
208 | case PriorTemplateArgumentSubstitution: | ||||||
209 | case ConstraintsCheck: | ||||||
210 | case NestedRequirementConstraintsCheck: | ||||||
211 | return true; | ||||||
212 | |||||||
213 | case RequirementInstantiation: | ||||||
214 | case DefaultTemplateArgumentChecking: | ||||||
215 | case DeclaringSpecialMember: | ||||||
216 | case DeclaringImplicitEqualityComparison: | ||||||
217 | case DefiningSynthesizedFunction: | ||||||
218 | case ExceptionSpecEvaluation: | ||||||
219 | case ConstraintSubstitution: | ||||||
220 | case ParameterMappingSubstitution: | ||||||
221 | case ConstraintNormalization: | ||||||
222 | case RewritingOperatorAsSpaceship: | ||||||
223 | case InitializingStructuredBinding: | ||||||
224 | case MarkingClassDllexported: | ||||||
225 | return false; | ||||||
226 | |||||||
227 | // This function should never be called when Kind's value is Memoization. | ||||||
228 | case Memoization: | ||||||
229 | break; | ||||||
230 | } | ||||||
231 | |||||||
232 | llvm_unreachable("Invalid SynthesisKind!")::llvm::llvm_unreachable_internal("Invalid SynthesisKind!", "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 232); | ||||||
233 | } | ||||||
234 | |||||||
235 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||||
236 | Sema &SemaRef, CodeSynthesisContext::SynthesisKind Kind, | ||||||
237 | SourceLocation PointOfInstantiation, SourceRange InstantiationRange, | ||||||
238 | Decl *Entity, NamedDecl *Template, ArrayRef<TemplateArgument> TemplateArgs, | ||||||
239 | sema::TemplateDeductionInfo *DeductionInfo) | ||||||
240 | : SemaRef(SemaRef) { | ||||||
241 | // Don't allow further instantiation if a fatal error and an uncompilable | ||||||
242 | // error have occurred. Any diagnostics we might have raised will not be | ||||||
243 | // visible, and we do not need to construct a correct AST. | ||||||
244 | if (SemaRef.Diags.hasFatalErrorOccurred() && | ||||||
245 | SemaRef.hasUncompilableErrorOccurred()) { | ||||||
246 | Invalid = true; | ||||||
247 | return; | ||||||
248 | } | ||||||
249 | Invalid = CheckInstantiationDepth(PointOfInstantiation, InstantiationRange); | ||||||
250 | if (!Invalid) { | ||||||
251 | CodeSynthesisContext Inst; | ||||||
252 | Inst.Kind = Kind; | ||||||
253 | Inst.PointOfInstantiation = PointOfInstantiation; | ||||||
254 | Inst.Entity = Entity; | ||||||
255 | Inst.Template = Template; | ||||||
256 | Inst.TemplateArgs = TemplateArgs.data(); | ||||||
257 | Inst.NumTemplateArgs = TemplateArgs.size(); | ||||||
258 | Inst.DeductionInfo = DeductionInfo; | ||||||
259 | Inst.InstantiationRange = InstantiationRange; | ||||||
260 | SemaRef.pushCodeSynthesisContext(Inst); | ||||||
261 | |||||||
262 | AlreadyInstantiating = !Inst.Entity ? false : | ||||||
263 | !SemaRef.InstantiatingSpecializations | ||||||
264 | .insert({Inst.Entity->getCanonicalDecl(), Inst.Kind}) | ||||||
265 | .second; | ||||||
266 | atTemplateBegin(SemaRef.TemplateInstCallbacks, SemaRef, Inst); | ||||||
267 | } | ||||||
268 | } | ||||||
269 | |||||||
270 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||||
271 | Sema &SemaRef, SourceLocation PointOfInstantiation, Decl *Entity, | ||||||
272 | SourceRange InstantiationRange) | ||||||
273 | : InstantiatingTemplate(SemaRef, | ||||||
274 | CodeSynthesisContext::TemplateInstantiation, | ||||||
275 | PointOfInstantiation, InstantiationRange, Entity) {} | ||||||
276 | |||||||
277 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||||
278 | Sema &SemaRef, SourceLocation PointOfInstantiation, FunctionDecl *Entity, | ||||||
279 | ExceptionSpecification, SourceRange InstantiationRange) | ||||||
280 | : InstantiatingTemplate( | ||||||
281 | SemaRef, CodeSynthesisContext::ExceptionSpecInstantiation, | ||||||
282 | PointOfInstantiation, InstantiationRange, Entity) {} | ||||||
283 | |||||||
284 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||||
285 | Sema &SemaRef, SourceLocation PointOfInstantiation, TemplateParameter Param, | ||||||
286 | TemplateDecl *Template, ArrayRef<TemplateArgument> TemplateArgs, | ||||||
287 | SourceRange InstantiationRange) | ||||||
288 | : InstantiatingTemplate( | ||||||
289 | SemaRef, | ||||||
290 | CodeSynthesisContext::DefaultTemplateArgumentInstantiation, | ||||||
291 | PointOfInstantiation, InstantiationRange, getAsNamedDecl(Param), | ||||||
292 | Template, TemplateArgs) {} | ||||||
293 | |||||||
294 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||||
295 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||||
296 | FunctionTemplateDecl *FunctionTemplate, | ||||||
297 | ArrayRef<TemplateArgument> TemplateArgs, | ||||||
298 | CodeSynthesisContext::SynthesisKind Kind, | ||||||
299 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | ||||||
300 | : InstantiatingTemplate(SemaRef, Kind, PointOfInstantiation, | ||||||
301 | InstantiationRange, FunctionTemplate, nullptr, | ||||||
302 | TemplateArgs, &DeductionInfo) { | ||||||
303 | assert((static_cast <bool> (Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution ) ? void (0) : __assert_fail ("Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 305, __extension__ __PRETTY_FUNCTION__)) | ||||||
304 | Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution ||(static_cast <bool> (Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution ) ? void (0) : __assert_fail ("Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 305, __extension__ __PRETTY_FUNCTION__)) | ||||||
305 | Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution)(static_cast <bool> (Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution ) ? void (0) : __assert_fail ("Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 305, __extension__ __PRETTY_FUNCTION__)); | ||||||
306 | } | ||||||
307 | |||||||
308 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||||
309 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||||
310 | TemplateDecl *Template, | ||||||
311 | ArrayRef<TemplateArgument> TemplateArgs, | ||||||
312 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | ||||||
313 | : InstantiatingTemplate( | ||||||
314 | SemaRef, | ||||||
315 | CodeSynthesisContext::DeducedTemplateArgumentSubstitution, | ||||||
316 | PointOfInstantiation, InstantiationRange, Template, nullptr, | ||||||
317 | TemplateArgs, &DeductionInfo) {} | ||||||
318 | |||||||
319 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||||
320 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||||
321 | ClassTemplatePartialSpecializationDecl *PartialSpec, | ||||||
322 | ArrayRef<TemplateArgument> TemplateArgs, | ||||||
323 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | ||||||
324 | : InstantiatingTemplate( | ||||||
325 | SemaRef, | ||||||
326 | CodeSynthesisContext::DeducedTemplateArgumentSubstitution, | ||||||
327 | PointOfInstantiation, InstantiationRange, PartialSpec, nullptr, | ||||||
328 | TemplateArgs, &DeductionInfo) {} | ||||||
329 | |||||||
330 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||||
331 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||||
332 | VarTemplatePartialSpecializationDecl *PartialSpec, | ||||||
333 | ArrayRef<TemplateArgument> TemplateArgs, | ||||||
334 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | ||||||
335 | : InstantiatingTemplate( | ||||||
336 | SemaRef, | ||||||
337 | CodeSynthesisContext::DeducedTemplateArgumentSubstitution, | ||||||
338 | PointOfInstantiation, InstantiationRange, PartialSpec, nullptr, | ||||||
339 | TemplateArgs, &DeductionInfo) {} | ||||||
340 | |||||||
341 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||||
342 | Sema &SemaRef, SourceLocation PointOfInstantiation, ParmVarDecl *Param, | ||||||
343 | ArrayRef<TemplateArgument> TemplateArgs, SourceRange InstantiationRange) | ||||||
344 | : InstantiatingTemplate( | ||||||
345 | SemaRef, | ||||||
346 | CodeSynthesisContext::DefaultFunctionArgumentInstantiation, | ||||||
347 | PointOfInstantiation, InstantiationRange, Param, nullptr, | ||||||
348 | TemplateArgs) {} | ||||||
349 | |||||||
350 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||||
351 | Sema &SemaRef, SourceLocation PointOfInstantiation, NamedDecl *Template, | ||||||
352 | NonTypeTemplateParmDecl *Param, ArrayRef<TemplateArgument> TemplateArgs, | ||||||
353 | SourceRange InstantiationRange) | ||||||
354 | : InstantiatingTemplate( | ||||||
355 | SemaRef, | ||||||
356 | CodeSynthesisContext::PriorTemplateArgumentSubstitution, | ||||||
357 | PointOfInstantiation, InstantiationRange, Param, Template, | ||||||
358 | TemplateArgs) {} | ||||||
359 | |||||||
360 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||||
361 | Sema &SemaRef, SourceLocation PointOfInstantiation, NamedDecl *Template, | ||||||
362 | TemplateTemplateParmDecl *Param, ArrayRef<TemplateArgument> TemplateArgs, | ||||||
363 | SourceRange InstantiationRange) | ||||||
364 | : InstantiatingTemplate( | ||||||
365 | SemaRef, | ||||||
366 | CodeSynthesisContext::PriorTemplateArgumentSubstitution, | ||||||
367 | PointOfInstantiation, InstantiationRange, Param, Template, | ||||||
368 | TemplateArgs) {} | ||||||
369 | |||||||
370 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||||
371 | Sema &SemaRef, SourceLocation PointOfInstantiation, TemplateDecl *Template, | ||||||
372 | NamedDecl *Param, ArrayRef<TemplateArgument> TemplateArgs, | ||||||
373 | SourceRange InstantiationRange) | ||||||
374 | : InstantiatingTemplate( | ||||||
375 | SemaRef, CodeSynthesisContext::DefaultTemplateArgumentChecking, | ||||||
376 | PointOfInstantiation, InstantiationRange, Param, Template, | ||||||
377 | TemplateArgs) {} | ||||||
378 | |||||||
379 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||||
380 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||||
381 | concepts::Requirement *Req, sema::TemplateDeductionInfo &DeductionInfo, | ||||||
382 | SourceRange InstantiationRange) | ||||||
383 | : InstantiatingTemplate( | ||||||
384 | SemaRef, CodeSynthesisContext::RequirementInstantiation, | ||||||
385 | PointOfInstantiation, InstantiationRange, /*Entity=*/nullptr, | ||||||
386 | /*Template=*/nullptr, /*TemplateArgs=*/None, &DeductionInfo) {} | ||||||
387 | |||||||
388 | |||||||
389 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||||
390 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||||
391 | concepts::NestedRequirement *Req, ConstraintsCheck, | ||||||
392 | SourceRange InstantiationRange) | ||||||
393 | : InstantiatingTemplate( | ||||||
394 | SemaRef, CodeSynthesisContext::NestedRequirementConstraintsCheck, | ||||||
395 | PointOfInstantiation, InstantiationRange, /*Entity=*/nullptr, | ||||||
396 | /*Template=*/nullptr, /*TemplateArgs=*/None) {} | ||||||
397 | |||||||
398 | |||||||
399 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||||
400 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||||
401 | ConstraintsCheck, NamedDecl *Template, | ||||||
402 | ArrayRef<TemplateArgument> TemplateArgs, SourceRange InstantiationRange) | ||||||
403 | : InstantiatingTemplate( | ||||||
404 | SemaRef, CodeSynthesisContext::ConstraintsCheck, | ||||||
405 | PointOfInstantiation, InstantiationRange, Template, nullptr, | ||||||
406 | TemplateArgs) {} | ||||||
407 | |||||||
408 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||||
409 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||||
410 | ConstraintSubstitution, NamedDecl *Template, | ||||||
411 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | ||||||
412 | : InstantiatingTemplate( | ||||||
413 | SemaRef, CodeSynthesisContext::ConstraintSubstitution, | ||||||
414 | PointOfInstantiation, InstantiationRange, Template, nullptr, | ||||||
415 | {}, &DeductionInfo) {} | ||||||
416 | |||||||
417 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||||
418 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||||
419 | ConstraintNormalization, NamedDecl *Template, | ||||||
420 | SourceRange InstantiationRange) | ||||||
421 | : InstantiatingTemplate( | ||||||
422 | SemaRef, CodeSynthesisContext::ConstraintNormalization, | ||||||
423 | PointOfInstantiation, InstantiationRange, Template) {} | ||||||
424 | |||||||
425 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||||
426 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||||
427 | ParameterMappingSubstitution, NamedDecl *Template, | ||||||
428 | SourceRange InstantiationRange) | ||||||
429 | : InstantiatingTemplate( | ||||||
430 | SemaRef, CodeSynthesisContext::ParameterMappingSubstitution, | ||||||
431 | PointOfInstantiation, InstantiationRange, Template) {} | ||||||
432 | |||||||
433 | void Sema::pushCodeSynthesisContext(CodeSynthesisContext Ctx) { | ||||||
434 | Ctx.SavedInNonInstantiationSFINAEContext = InNonInstantiationSFINAEContext; | ||||||
435 | InNonInstantiationSFINAEContext = false; | ||||||
436 | |||||||
437 | CodeSynthesisContexts.push_back(Ctx); | ||||||
438 | |||||||
439 | if (!Ctx.isInstantiationRecord()) | ||||||
440 | ++NonInstantiationEntries; | ||||||
441 | |||||||
442 | // Check to see if we're low on stack space. We can't do anything about this | ||||||
443 | // from here, but we can at least warn the user. | ||||||
444 | if (isStackNearlyExhausted()) | ||||||
445 | warnStackExhausted(Ctx.PointOfInstantiation); | ||||||
446 | } | ||||||
447 | |||||||
448 | void Sema::popCodeSynthesisContext() { | ||||||
449 | auto &Active = CodeSynthesisContexts.back(); | ||||||
450 | if (!Active.isInstantiationRecord()) { | ||||||
451 | assert(NonInstantiationEntries > 0)(static_cast <bool> (NonInstantiationEntries > 0) ? void (0) : __assert_fail ("NonInstantiationEntries > 0", "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 451, __extension__ __PRETTY_FUNCTION__)); | ||||||
452 | --NonInstantiationEntries; | ||||||
453 | } | ||||||
454 | |||||||
455 | InNonInstantiationSFINAEContext = Active.SavedInNonInstantiationSFINAEContext; | ||||||
456 | |||||||
457 | // Name lookup no longer looks in this template's defining module. | ||||||
458 | assert(CodeSynthesisContexts.size() >=(static_cast <bool> (CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules.size() && "forgot to remove a lookup module for a template instantiation" ) ? void (0) : __assert_fail ("CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules.size() && \"forgot to remove a lookup module for a template instantiation\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 460, __extension__ __PRETTY_FUNCTION__)) | ||||||
459 | CodeSynthesisContextLookupModules.size() &&(static_cast <bool> (CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules.size() && "forgot to remove a lookup module for a template instantiation" ) ? void (0) : __assert_fail ("CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules.size() && \"forgot to remove a lookup module for a template instantiation\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 460, __extension__ __PRETTY_FUNCTION__)) | ||||||
460 | "forgot to remove a lookup module for a template instantiation")(static_cast <bool> (CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules.size() && "forgot to remove a lookup module for a template instantiation" ) ? void (0) : __assert_fail ("CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules.size() && \"forgot to remove a lookup module for a template instantiation\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 460, __extension__ __PRETTY_FUNCTION__)); | ||||||
461 | if (CodeSynthesisContexts.size() == | ||||||
462 | CodeSynthesisContextLookupModules.size()) { | ||||||
463 | if (Module *M = CodeSynthesisContextLookupModules.back()) | ||||||
464 | LookupModulesCache.erase(M); | ||||||
465 | CodeSynthesisContextLookupModules.pop_back(); | ||||||
466 | } | ||||||
467 | |||||||
468 | // If we've left the code synthesis context for the current context stack, | ||||||
469 | // stop remembering that we've emitted that stack. | ||||||
470 | if (CodeSynthesisContexts.size() == | ||||||
471 | LastEmittedCodeSynthesisContextDepth) | ||||||
472 | LastEmittedCodeSynthesisContextDepth = 0; | ||||||
473 | |||||||
474 | CodeSynthesisContexts.pop_back(); | ||||||
475 | } | ||||||
476 | |||||||
477 | void Sema::InstantiatingTemplate::Clear() { | ||||||
478 | if (!Invalid) { | ||||||
479 | if (!AlreadyInstantiating) { | ||||||
480 | auto &Active = SemaRef.CodeSynthesisContexts.back(); | ||||||
481 | if (Active.Entity) | ||||||
482 | SemaRef.InstantiatingSpecializations.erase( | ||||||
483 | {Active.Entity->getCanonicalDecl(), Active.Kind}); | ||||||
484 | } | ||||||
485 | |||||||
486 | atTemplateEnd(SemaRef.TemplateInstCallbacks, SemaRef, | ||||||
487 | SemaRef.CodeSynthesisContexts.back()); | ||||||
488 | |||||||
489 | SemaRef.popCodeSynthesisContext(); | ||||||
490 | Invalid = true; | ||||||
491 | } | ||||||
492 | } | ||||||
493 | |||||||
494 | bool Sema::InstantiatingTemplate::CheckInstantiationDepth( | ||||||
495 | SourceLocation PointOfInstantiation, | ||||||
496 | SourceRange InstantiationRange) { | ||||||
497 | assert(SemaRef.NonInstantiationEntries <=(static_cast <bool> (SemaRef.NonInstantiationEntries <= SemaRef.CodeSynthesisContexts.size()) ? void (0) : __assert_fail ("SemaRef.NonInstantiationEntries <= SemaRef.CodeSynthesisContexts.size()" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 498, __extension__ __PRETTY_FUNCTION__)) | ||||||
498 | SemaRef.CodeSynthesisContexts.size())(static_cast <bool> (SemaRef.NonInstantiationEntries <= SemaRef.CodeSynthesisContexts.size()) ? void (0) : __assert_fail ("SemaRef.NonInstantiationEntries <= SemaRef.CodeSynthesisContexts.size()" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 498, __extension__ __PRETTY_FUNCTION__)); | ||||||
499 | if ((SemaRef.CodeSynthesisContexts.size() - | ||||||
500 | SemaRef.NonInstantiationEntries) | ||||||
501 | <= SemaRef.getLangOpts().InstantiationDepth) | ||||||
502 | return false; | ||||||
503 | |||||||
504 | SemaRef.Diag(PointOfInstantiation, | ||||||
505 | diag::err_template_recursion_depth_exceeded) | ||||||
506 | << SemaRef.getLangOpts().InstantiationDepth | ||||||
507 | << InstantiationRange; | ||||||
508 | SemaRef.Diag(PointOfInstantiation, diag::note_template_recursion_depth) | ||||||
509 | << SemaRef.getLangOpts().InstantiationDepth; | ||||||
510 | return true; | ||||||
511 | } | ||||||
512 | |||||||
513 | /// Prints the current instantiation stack through a series of | ||||||
514 | /// notes. | ||||||
515 | void Sema::PrintInstantiationStack() { | ||||||
516 | // Determine which template instantiations to skip, if any. | ||||||
517 | unsigned SkipStart = CodeSynthesisContexts.size(), SkipEnd = SkipStart; | ||||||
518 | unsigned Limit = Diags.getTemplateBacktraceLimit(); | ||||||
519 | if (Limit && Limit < CodeSynthesisContexts.size()) { | ||||||
520 | SkipStart = Limit / 2 + Limit % 2; | ||||||
521 | SkipEnd = CodeSynthesisContexts.size() - Limit / 2; | ||||||
522 | } | ||||||
523 | |||||||
524 | // FIXME: In all of these cases, we need to show the template arguments | ||||||
525 | unsigned InstantiationIdx = 0; | ||||||
526 | for (SmallVectorImpl<CodeSynthesisContext>::reverse_iterator | ||||||
527 | Active = CodeSynthesisContexts.rbegin(), | ||||||
528 | ActiveEnd = CodeSynthesisContexts.rend(); | ||||||
529 | Active != ActiveEnd; | ||||||
530 | ++Active, ++InstantiationIdx) { | ||||||
531 | // Skip this instantiation? | ||||||
532 | if (InstantiationIdx >= SkipStart && InstantiationIdx < SkipEnd) { | ||||||
533 | if (InstantiationIdx == SkipStart) { | ||||||
534 | // Note that we're skipping instantiations. | ||||||
535 | Diags.Report(Active->PointOfInstantiation, | ||||||
536 | diag::note_instantiation_contexts_suppressed) | ||||||
537 | << unsigned(CodeSynthesisContexts.size() - Limit); | ||||||
538 | } | ||||||
539 | continue; | ||||||
540 | } | ||||||
541 | |||||||
542 | switch (Active->Kind) { | ||||||
543 | case CodeSynthesisContext::TemplateInstantiation: { | ||||||
544 | Decl *D = Active->Entity; | ||||||
545 | if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) { | ||||||
546 | unsigned DiagID = diag::note_template_member_class_here; | ||||||
547 | if (isa<ClassTemplateSpecializationDecl>(Record)) | ||||||
548 | DiagID = diag::note_template_class_instantiation_here; | ||||||
549 | Diags.Report(Active->PointOfInstantiation, DiagID) | ||||||
550 | << Record << Active->InstantiationRange; | ||||||
551 | } else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) { | ||||||
552 | unsigned DiagID; | ||||||
553 | if (Function->getPrimaryTemplate()) | ||||||
554 | DiagID = diag::note_function_template_spec_here; | ||||||
555 | else | ||||||
556 | DiagID = diag::note_template_member_function_here; | ||||||
557 | Diags.Report(Active->PointOfInstantiation, DiagID) | ||||||
558 | << Function | ||||||
559 | << Active->InstantiationRange; | ||||||
560 | } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) { | ||||||
561 | Diags.Report(Active->PointOfInstantiation, | ||||||
562 | VD->isStaticDataMember()? | ||||||
563 | diag::note_template_static_data_member_def_here | ||||||
564 | : diag::note_template_variable_def_here) | ||||||
565 | << VD | ||||||
566 | << Active->InstantiationRange; | ||||||
567 | } else if (EnumDecl *ED = dyn_cast<EnumDecl>(D)) { | ||||||
568 | Diags.Report(Active->PointOfInstantiation, | ||||||
569 | diag::note_template_enum_def_here) | ||||||
570 | << ED | ||||||
571 | << Active->InstantiationRange; | ||||||
572 | } else if (FieldDecl *FD = dyn_cast<FieldDecl>(D)) { | ||||||
573 | Diags.Report(Active->PointOfInstantiation, | ||||||
574 | diag::note_template_nsdmi_here) | ||||||
575 | << FD << Active->InstantiationRange; | ||||||
576 | } else { | ||||||
577 | Diags.Report(Active->PointOfInstantiation, | ||||||
578 | diag::note_template_type_alias_instantiation_here) | ||||||
579 | << cast<TypeAliasTemplateDecl>(D) | ||||||
580 | << Active->InstantiationRange; | ||||||
581 | } | ||||||
582 | break; | ||||||
583 | } | ||||||
584 | |||||||
585 | case CodeSynthesisContext::DefaultTemplateArgumentInstantiation: { | ||||||
586 | TemplateDecl *Template = cast<TemplateDecl>(Active->Template); | ||||||
587 | SmallString<128> TemplateArgsStr; | ||||||
588 | llvm::raw_svector_ostream OS(TemplateArgsStr); | ||||||
589 | Template->printName(OS); | ||||||
590 | printTemplateArgumentList(OS, Active->template_arguments(), | ||||||
591 | getPrintingPolicy()); | ||||||
592 | Diags.Report(Active->PointOfInstantiation, | ||||||
593 | diag::note_default_arg_instantiation_here) | ||||||
594 | << OS.str() | ||||||
595 | << Active->InstantiationRange; | ||||||
596 | break; | ||||||
597 | } | ||||||
598 | |||||||
599 | case CodeSynthesisContext::ExplicitTemplateArgumentSubstitution: { | ||||||
600 | FunctionTemplateDecl *FnTmpl = cast<FunctionTemplateDecl>(Active->Entity); | ||||||
601 | Diags.Report(Active->PointOfInstantiation, | ||||||
602 | diag::note_explicit_template_arg_substitution_here) | ||||||
603 | << FnTmpl | ||||||
604 | << getTemplateArgumentBindingsText(FnTmpl->getTemplateParameters(), | ||||||
605 | Active->TemplateArgs, | ||||||
606 | Active->NumTemplateArgs) | ||||||
607 | << Active->InstantiationRange; | ||||||
608 | break; | ||||||
609 | } | ||||||
610 | |||||||
611 | case CodeSynthesisContext::DeducedTemplateArgumentSubstitution: { | ||||||
612 | if (FunctionTemplateDecl *FnTmpl = | ||||||
613 | dyn_cast<FunctionTemplateDecl>(Active->Entity)) { | ||||||
614 | Diags.Report(Active->PointOfInstantiation, | ||||||
615 | diag::note_function_template_deduction_instantiation_here) | ||||||
616 | << FnTmpl | ||||||
617 | << getTemplateArgumentBindingsText(FnTmpl->getTemplateParameters(), | ||||||
618 | Active->TemplateArgs, | ||||||
619 | Active->NumTemplateArgs) | ||||||
620 | << Active->InstantiationRange; | ||||||
621 | } else { | ||||||
622 | bool IsVar = isa<VarTemplateDecl>(Active->Entity) || | ||||||
623 | isa<VarTemplateSpecializationDecl>(Active->Entity); | ||||||
624 | bool IsTemplate = false; | ||||||
625 | TemplateParameterList *Params; | ||||||
626 | if (auto *D = dyn_cast<TemplateDecl>(Active->Entity)) { | ||||||
627 | IsTemplate = true; | ||||||
628 | Params = D->getTemplateParameters(); | ||||||
629 | } else if (auto *D = dyn_cast<ClassTemplatePartialSpecializationDecl>( | ||||||
630 | Active->Entity)) { | ||||||
631 | Params = D->getTemplateParameters(); | ||||||
632 | } else if (auto *D = dyn_cast<VarTemplatePartialSpecializationDecl>( | ||||||
633 | Active->Entity)) { | ||||||
634 | Params = D->getTemplateParameters(); | ||||||
635 | } else { | ||||||
636 | llvm_unreachable("unexpected template kind")::llvm::llvm_unreachable_internal("unexpected template kind", "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 636); | ||||||
637 | } | ||||||
638 | |||||||
639 | Diags.Report(Active->PointOfInstantiation, | ||||||
640 | diag::note_deduced_template_arg_substitution_here) | ||||||
641 | << IsVar << IsTemplate << cast<NamedDecl>(Active->Entity) | ||||||
642 | << getTemplateArgumentBindingsText(Params, Active->TemplateArgs, | ||||||
643 | Active->NumTemplateArgs) | ||||||
644 | << Active->InstantiationRange; | ||||||
645 | } | ||||||
646 | break; | ||||||
647 | } | ||||||
648 | |||||||
649 | case CodeSynthesisContext::DefaultFunctionArgumentInstantiation: { | ||||||
650 | ParmVarDecl *Param = cast<ParmVarDecl>(Active->Entity); | ||||||
651 | FunctionDecl *FD = cast<FunctionDecl>(Param->getDeclContext()); | ||||||
652 | |||||||
653 | SmallString<128> TemplateArgsStr; | ||||||
654 | llvm::raw_svector_ostream OS(TemplateArgsStr); | ||||||
655 | FD->printName(OS); | ||||||
656 | printTemplateArgumentList(OS, Active->template_arguments(), | ||||||
657 | getPrintingPolicy()); | ||||||
658 | Diags.Report(Active->PointOfInstantiation, | ||||||
659 | diag::note_default_function_arg_instantiation_here) | ||||||
660 | << OS.str() | ||||||
661 | << Active->InstantiationRange; | ||||||
662 | break; | ||||||
663 | } | ||||||
664 | |||||||
665 | case CodeSynthesisContext::PriorTemplateArgumentSubstitution: { | ||||||
666 | NamedDecl *Parm = cast<NamedDecl>(Active->Entity); | ||||||
667 | std::string Name; | ||||||
668 | if (!Parm->getName().empty()) | ||||||
669 | Name = std::string(" '") + Parm->getName().str() + "'"; | ||||||
670 | |||||||
671 | TemplateParameterList *TemplateParams = nullptr; | ||||||
672 | if (TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template)) | ||||||
673 | TemplateParams = Template->getTemplateParameters(); | ||||||
674 | else | ||||||
675 | TemplateParams = | ||||||
676 | cast<ClassTemplatePartialSpecializationDecl>(Active->Template) | ||||||
677 | ->getTemplateParameters(); | ||||||
678 | Diags.Report(Active->PointOfInstantiation, | ||||||
679 | diag::note_prior_template_arg_substitution) | ||||||
680 | << isa<TemplateTemplateParmDecl>(Parm) | ||||||
681 | << Name | ||||||
682 | << getTemplateArgumentBindingsText(TemplateParams, | ||||||
683 | Active->TemplateArgs, | ||||||
684 | Active->NumTemplateArgs) | ||||||
685 | << Active->InstantiationRange; | ||||||
686 | break; | ||||||
687 | } | ||||||
688 | |||||||
689 | case CodeSynthesisContext::DefaultTemplateArgumentChecking: { | ||||||
690 | TemplateParameterList *TemplateParams = nullptr; | ||||||
691 | if (TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template)) | ||||||
692 | TemplateParams = Template->getTemplateParameters(); | ||||||
693 | else | ||||||
694 | TemplateParams = | ||||||
695 | cast<ClassTemplatePartialSpecializationDecl>(Active->Template) | ||||||
696 | ->getTemplateParameters(); | ||||||
697 | |||||||
698 | Diags.Report(Active->PointOfInstantiation, | ||||||
699 | diag::note_template_default_arg_checking) | ||||||
700 | << getTemplateArgumentBindingsText(TemplateParams, | ||||||
701 | Active->TemplateArgs, | ||||||
702 | Active->NumTemplateArgs) | ||||||
703 | << Active->InstantiationRange; | ||||||
704 | break; | ||||||
705 | } | ||||||
706 | |||||||
707 | case CodeSynthesisContext::ExceptionSpecEvaluation: | ||||||
708 | Diags.Report(Active->PointOfInstantiation, | ||||||
709 | diag::note_evaluating_exception_spec_here) | ||||||
710 | << cast<FunctionDecl>(Active->Entity); | ||||||
711 | break; | ||||||
712 | |||||||
713 | case CodeSynthesisContext::ExceptionSpecInstantiation: | ||||||
714 | Diags.Report(Active->PointOfInstantiation, | ||||||
715 | diag::note_template_exception_spec_instantiation_here) | ||||||
716 | << cast<FunctionDecl>(Active->Entity) | ||||||
717 | << Active->InstantiationRange; | ||||||
718 | break; | ||||||
719 | |||||||
720 | case CodeSynthesisContext::RequirementInstantiation: | ||||||
721 | Diags.Report(Active->PointOfInstantiation, | ||||||
722 | diag::note_template_requirement_instantiation_here) | ||||||
723 | << Active->InstantiationRange; | ||||||
724 | break; | ||||||
725 | |||||||
726 | case CodeSynthesisContext::NestedRequirementConstraintsCheck: | ||||||
727 | Diags.Report(Active->PointOfInstantiation, | ||||||
728 | diag::note_nested_requirement_here) | ||||||
729 | << Active->InstantiationRange; | ||||||
730 | break; | ||||||
731 | |||||||
732 | case CodeSynthesisContext::DeclaringSpecialMember: | ||||||
733 | Diags.Report(Active->PointOfInstantiation, | ||||||
734 | diag::note_in_declaration_of_implicit_special_member) | ||||||
735 | << cast<CXXRecordDecl>(Active->Entity) << Active->SpecialMember; | ||||||
736 | break; | ||||||
737 | |||||||
738 | case CodeSynthesisContext::DeclaringImplicitEqualityComparison: | ||||||
739 | Diags.Report(Active->Entity->getLocation(), | ||||||
740 | diag::note_in_declaration_of_implicit_equality_comparison); | ||||||
741 | break; | ||||||
742 | |||||||
743 | case CodeSynthesisContext::DefiningSynthesizedFunction: { | ||||||
744 | // FIXME: For synthesized functions that are not defaulted, | ||||||
745 | // produce a note. | ||||||
746 | auto *FD = dyn_cast<FunctionDecl>(Active->Entity); | ||||||
747 | DefaultedFunctionKind DFK = | ||||||
748 | FD ? getDefaultedFunctionKind(FD) : DefaultedFunctionKind(); | ||||||
749 | if (DFK.isSpecialMember()) { | ||||||
750 | auto *MD = cast<CXXMethodDecl>(FD); | ||||||
751 | Diags.Report(Active->PointOfInstantiation, | ||||||
752 | diag::note_member_synthesized_at) | ||||||
753 | << MD->isExplicitlyDefaulted() << DFK.asSpecialMember() | ||||||
754 | << Context.getTagDeclType(MD->getParent()); | ||||||
755 | } else if (DFK.isComparison()) { | ||||||
756 | Diags.Report(Active->PointOfInstantiation, | ||||||
757 | diag::note_comparison_synthesized_at) | ||||||
758 | << (int)DFK.asComparison() | ||||||
759 | << Context.getTagDeclType( | ||||||
760 | cast<CXXRecordDecl>(FD->getLexicalDeclContext())); | ||||||
761 | } | ||||||
762 | break; | ||||||
763 | } | ||||||
764 | |||||||
765 | case CodeSynthesisContext::RewritingOperatorAsSpaceship: | ||||||
766 | Diags.Report(Active->Entity->getLocation(), | ||||||
767 | diag::note_rewriting_operator_as_spaceship); | ||||||
768 | break; | ||||||
769 | |||||||
770 | case CodeSynthesisContext::InitializingStructuredBinding: | ||||||
771 | Diags.Report(Active->PointOfInstantiation, | ||||||
772 | diag::note_in_binding_decl_init) | ||||||
773 | << cast<BindingDecl>(Active->Entity); | ||||||
774 | break; | ||||||
775 | |||||||
776 | case CodeSynthesisContext::MarkingClassDllexported: | ||||||
777 | Diags.Report(Active->PointOfInstantiation, | ||||||
778 | diag::note_due_to_dllexported_class) | ||||||
779 | << cast<CXXRecordDecl>(Active->Entity) << !getLangOpts().CPlusPlus11; | ||||||
780 | break; | ||||||
781 | |||||||
782 | case CodeSynthesisContext::Memoization: | ||||||
783 | break; | ||||||
784 | |||||||
785 | case CodeSynthesisContext::ConstraintsCheck: { | ||||||
786 | unsigned DiagID = 0; | ||||||
787 | if (!Active->Entity) { | ||||||
788 | Diags.Report(Active->PointOfInstantiation, | ||||||
789 | diag::note_nested_requirement_here) | ||||||
790 | << Active->InstantiationRange; | ||||||
791 | break; | ||||||
792 | } | ||||||
793 | if (isa<ConceptDecl>(Active->Entity)) | ||||||
794 | DiagID = diag::note_concept_specialization_here; | ||||||
795 | else if (isa<TemplateDecl>(Active->Entity)) | ||||||
796 | DiagID = diag::note_checking_constraints_for_template_id_here; | ||||||
797 | else if (isa<VarTemplatePartialSpecializationDecl>(Active->Entity)) | ||||||
798 | DiagID = diag::note_checking_constraints_for_var_spec_id_here; | ||||||
799 | else if (isa<ClassTemplatePartialSpecializationDecl>(Active->Entity)) | ||||||
800 | DiagID = diag::note_checking_constraints_for_class_spec_id_here; | ||||||
801 | else { | ||||||
802 | assert(isa<FunctionDecl>(Active->Entity))(static_cast <bool> (isa<FunctionDecl>(Active-> Entity)) ? void (0) : __assert_fail ("isa<FunctionDecl>(Active->Entity)" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 802, __extension__ __PRETTY_FUNCTION__)); | ||||||
803 | DiagID = diag::note_checking_constraints_for_function_here; | ||||||
804 | } | ||||||
805 | SmallString<128> TemplateArgsStr; | ||||||
806 | llvm::raw_svector_ostream OS(TemplateArgsStr); | ||||||
807 | cast<NamedDecl>(Active->Entity)->printName(OS); | ||||||
808 | if (!isa<FunctionDecl>(Active->Entity)) { | ||||||
809 | printTemplateArgumentList(OS, Active->template_arguments(), | ||||||
810 | getPrintingPolicy()); | ||||||
811 | } | ||||||
812 | Diags.Report(Active->PointOfInstantiation, DiagID) << OS.str() | ||||||
813 | << Active->InstantiationRange; | ||||||
814 | break; | ||||||
815 | } | ||||||
816 | case CodeSynthesisContext::ConstraintSubstitution: | ||||||
817 | Diags.Report(Active->PointOfInstantiation, | ||||||
818 | diag::note_constraint_substitution_here) | ||||||
819 | << Active->InstantiationRange; | ||||||
820 | break; | ||||||
821 | case CodeSynthesisContext::ConstraintNormalization: | ||||||
822 | Diags.Report(Active->PointOfInstantiation, | ||||||
823 | diag::note_constraint_normalization_here) | ||||||
824 | << cast<NamedDecl>(Active->Entity)->getName() | ||||||
825 | << Active->InstantiationRange; | ||||||
826 | break; | ||||||
827 | case CodeSynthesisContext::ParameterMappingSubstitution: | ||||||
828 | Diags.Report(Active->PointOfInstantiation, | ||||||
829 | diag::note_parameter_mapping_substitution_here) | ||||||
830 | << Active->InstantiationRange; | ||||||
831 | break; | ||||||
832 | } | ||||||
833 | } | ||||||
834 | } | ||||||
835 | |||||||
836 | Optional<TemplateDeductionInfo *> Sema::isSFINAEContext() const { | ||||||
837 | if (InNonInstantiationSFINAEContext) | ||||||
838 | return Optional<TemplateDeductionInfo *>(nullptr); | ||||||
839 | |||||||
840 | for (SmallVectorImpl<CodeSynthesisContext>::const_reverse_iterator | ||||||
841 | Active = CodeSynthesisContexts.rbegin(), | ||||||
842 | ActiveEnd = CodeSynthesisContexts.rend(); | ||||||
843 | Active != ActiveEnd; | ||||||
844 | ++Active) | ||||||
845 | { | ||||||
846 | switch (Active->Kind) { | ||||||
847 | case CodeSynthesisContext::TemplateInstantiation: | ||||||
848 | // An instantiation of an alias template may or may not be a SFINAE | ||||||
849 | // context, depending on what else is on the stack. | ||||||
850 | if (isa<TypeAliasTemplateDecl>(Active->Entity)) | ||||||
851 | break; | ||||||
852 | LLVM_FALLTHROUGH[[gnu::fallthrough]]; | ||||||
853 | case CodeSynthesisContext::DefaultFunctionArgumentInstantiation: | ||||||
854 | case CodeSynthesisContext::ExceptionSpecInstantiation: | ||||||
855 | case CodeSynthesisContext::ConstraintsCheck: | ||||||
856 | case CodeSynthesisContext::ParameterMappingSubstitution: | ||||||
857 | case CodeSynthesisContext::ConstraintNormalization: | ||||||
858 | case CodeSynthesisContext::NestedRequirementConstraintsCheck: | ||||||
859 | // This is a template instantiation, so there is no SFINAE. | ||||||
860 | return None; | ||||||
861 | |||||||
862 | case CodeSynthesisContext::DefaultTemplateArgumentInstantiation: | ||||||
863 | case CodeSynthesisContext::PriorTemplateArgumentSubstitution: | ||||||
864 | case CodeSynthesisContext::DefaultTemplateArgumentChecking: | ||||||
865 | case CodeSynthesisContext::RewritingOperatorAsSpaceship: | ||||||
866 | // A default template argument instantiation and substitution into | ||||||
867 | // template parameters with arguments for prior parameters may or may | ||||||
868 | // not be a SFINAE context; look further up the stack. | ||||||
869 | break; | ||||||
870 | |||||||
871 | case CodeSynthesisContext::ExplicitTemplateArgumentSubstitution: | ||||||
872 | case CodeSynthesisContext::DeducedTemplateArgumentSubstitution: | ||||||
873 | case CodeSynthesisContext::ConstraintSubstitution: | ||||||
874 | case CodeSynthesisContext::RequirementInstantiation: | ||||||
875 | // We're either substituting explicitly-specified template arguments, | ||||||
876 | // deduced template arguments, a constraint expression or a requirement | ||||||
877 | // in a requires expression, so SFINAE applies. | ||||||
878 | assert(Active->DeductionInfo && "Missing deduction info pointer")(static_cast <bool> (Active->DeductionInfo && "Missing deduction info pointer") ? void (0) : __assert_fail ("Active->DeductionInfo && \"Missing deduction info pointer\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 878, __extension__ __PRETTY_FUNCTION__)); | ||||||
879 | return Active->DeductionInfo; | ||||||
880 | |||||||
881 | case CodeSynthesisContext::DeclaringSpecialMember: | ||||||
882 | case CodeSynthesisContext::DeclaringImplicitEqualityComparison: | ||||||
883 | case CodeSynthesisContext::DefiningSynthesizedFunction: | ||||||
884 | case CodeSynthesisContext::InitializingStructuredBinding: | ||||||
885 | case CodeSynthesisContext::MarkingClassDllexported: | ||||||
886 | // This happens in a context unrelated to template instantiation, so | ||||||
887 | // there is no SFINAE. | ||||||
888 | return None; | ||||||
889 | |||||||
890 | case CodeSynthesisContext::ExceptionSpecEvaluation: | ||||||
891 | // FIXME: This should not be treated as a SFINAE context, because | ||||||
892 | // we will cache an incorrect exception specification. However, clang | ||||||
893 | // bootstrap relies this! See PR31692. | ||||||
894 | break; | ||||||
895 | |||||||
896 | case CodeSynthesisContext::Memoization: | ||||||
897 | break; | ||||||
898 | } | ||||||
899 | |||||||
900 | // The inner context was transparent for SFINAE. If it occurred within a | ||||||
901 | // non-instantiation SFINAE context, then SFINAE applies. | ||||||
902 | if (Active->SavedInNonInstantiationSFINAEContext) | ||||||
903 | return Optional<TemplateDeductionInfo *>(nullptr); | ||||||
904 | } | ||||||
905 | |||||||
906 | return None; | ||||||
907 | } | ||||||
908 | |||||||
909 | //===----------------------------------------------------------------------===/ | ||||||
910 | // Template Instantiation for Types | ||||||
911 | //===----------------------------------------------------------------------===/ | ||||||
912 | namespace { | ||||||
913 | class TemplateInstantiator : public TreeTransform<TemplateInstantiator> { | ||||||
914 | const MultiLevelTemplateArgumentList &TemplateArgs; | ||||||
915 | SourceLocation Loc; | ||||||
916 | DeclarationName Entity; | ||||||
917 | |||||||
918 | public: | ||||||
919 | typedef TreeTransform<TemplateInstantiator> inherited; | ||||||
920 | |||||||
921 | TemplateInstantiator(Sema &SemaRef, | ||||||
922 | const MultiLevelTemplateArgumentList &TemplateArgs, | ||||||
923 | SourceLocation Loc, | ||||||
924 | DeclarationName Entity) | ||||||
925 | : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc), | ||||||
926 | Entity(Entity) { } | ||||||
927 | |||||||
928 | /// Determine whether the given type \p T has already been | ||||||
929 | /// transformed. | ||||||
930 | /// | ||||||
931 | /// For the purposes of template instantiation, a type has already been | ||||||
932 | /// transformed if it is NULL or if it is not dependent. | ||||||
933 | bool AlreadyTransformed(QualType T); | ||||||
934 | |||||||
935 | /// Returns the location of the entity being instantiated, if known. | ||||||
936 | SourceLocation getBaseLocation() { return Loc; } | ||||||
937 | |||||||
938 | /// Returns the name of the entity being instantiated, if any. | ||||||
939 | DeclarationName getBaseEntity() { return Entity; } | ||||||
940 | |||||||
941 | /// Sets the "base" location and entity when that | ||||||
942 | /// information is known based on another transformation. | ||||||
943 | void setBase(SourceLocation Loc, DeclarationName Entity) { | ||||||
944 | this->Loc = Loc; | ||||||
945 | this->Entity = Entity; | ||||||
946 | } | ||||||
947 | |||||||
948 | unsigned TransformTemplateDepth(unsigned Depth) { | ||||||
949 | return TemplateArgs.getNewDepth(Depth); | ||||||
950 | } | ||||||
951 | |||||||
952 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, | ||||||
953 | SourceRange PatternRange, | ||||||
954 | ArrayRef<UnexpandedParameterPack> Unexpanded, | ||||||
955 | bool &ShouldExpand, bool &RetainExpansion, | ||||||
956 | Optional<unsigned> &NumExpansions) { | ||||||
957 | return getSema().CheckParameterPacksForExpansion(EllipsisLoc, | ||||||
958 | PatternRange, Unexpanded, | ||||||
959 | TemplateArgs, | ||||||
960 | ShouldExpand, | ||||||
961 | RetainExpansion, | ||||||
962 | NumExpansions); | ||||||
963 | } | ||||||
964 | |||||||
965 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { | ||||||
966 | SemaRef.CurrentInstantiationScope->MakeInstantiatedLocalArgPack(Pack); | ||||||
967 | } | ||||||
968 | |||||||
969 | TemplateArgument ForgetPartiallySubstitutedPack() { | ||||||
970 | TemplateArgument Result; | ||||||
971 | if (NamedDecl *PartialPack | ||||||
972 | = SemaRef.CurrentInstantiationScope->getPartiallySubstitutedPack()){ | ||||||
973 | MultiLevelTemplateArgumentList &TemplateArgs | ||||||
974 | = const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs); | ||||||
975 | unsigned Depth, Index; | ||||||
976 | std::tie(Depth, Index) = getDepthAndIndex(PartialPack); | ||||||
977 | if (TemplateArgs.hasTemplateArgument(Depth, Index)) { | ||||||
978 | Result = TemplateArgs(Depth, Index); | ||||||
979 | TemplateArgs.setArgument(Depth, Index, TemplateArgument()); | ||||||
980 | } | ||||||
981 | } | ||||||
982 | |||||||
983 | return Result; | ||||||
984 | } | ||||||
985 | |||||||
986 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { | ||||||
987 | if (Arg.isNull()) | ||||||
988 | return; | ||||||
989 | |||||||
990 | if (NamedDecl *PartialPack | ||||||
991 | = SemaRef.CurrentInstantiationScope->getPartiallySubstitutedPack()){ | ||||||
992 | MultiLevelTemplateArgumentList &TemplateArgs | ||||||
993 | = const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs); | ||||||
994 | unsigned Depth, Index; | ||||||
995 | std::tie(Depth, Index) = getDepthAndIndex(PartialPack); | ||||||
996 | TemplateArgs.setArgument(Depth, Index, Arg); | ||||||
997 | } | ||||||
998 | } | ||||||
999 | |||||||
1000 | /// Transform the given declaration by instantiating a reference to | ||||||
1001 | /// this declaration. | ||||||
1002 | Decl *TransformDecl(SourceLocation Loc, Decl *D); | ||||||
1003 | |||||||
1004 | void transformAttrs(Decl *Old, Decl *New) { | ||||||
1005 | SemaRef.InstantiateAttrs(TemplateArgs, Old, New); | ||||||
1006 | } | ||||||
1007 | |||||||
1008 | void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> NewDecls) { | ||||||
1009 | if (Old->isParameterPack()) { | ||||||
| |||||||
1010 | SemaRef.CurrentInstantiationScope->MakeInstantiatedLocalArgPack(Old); | ||||||
1011 | for (auto *New : NewDecls) | ||||||
1012 | SemaRef.CurrentInstantiationScope->InstantiatedLocalPackArg( | ||||||
1013 | Old, cast<VarDecl>(New)); | ||||||
1014 | return; | ||||||
1015 | } | ||||||
1016 | |||||||
1017 | assert(NewDecls.size() == 1 &&(static_cast <bool> (NewDecls.size() == 1 && "should only have multiple expansions for a pack" ) ? void (0) : __assert_fail ("NewDecls.size() == 1 && \"should only have multiple expansions for a pack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1018, __extension__ __PRETTY_FUNCTION__)) | ||||||
1018 | "should only have multiple expansions for a pack")(static_cast <bool> (NewDecls.size() == 1 && "should only have multiple expansions for a pack" ) ? void (0) : __assert_fail ("NewDecls.size() == 1 && \"should only have multiple expansions for a pack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1018, __extension__ __PRETTY_FUNCTION__)); | ||||||
1019 | Decl *New = NewDecls.front(); | ||||||
1020 | |||||||
1021 | // If we've instantiated the call operator of a lambda or the call | ||||||
1022 | // operator template of a generic lambda, update the "instantiation of" | ||||||
1023 | // information. | ||||||
1024 | auto *NewMD = dyn_cast<CXXMethodDecl>(New); | ||||||
1025 | if (NewMD
| ||||||
1026 | auto *OldMD = dyn_cast<CXXMethodDecl>(Old); | ||||||
1027 | if (auto *NewTD = NewMD->getDescribedFunctionTemplate()) | ||||||
1028 | NewTD->setInstantiatedFromMemberTemplate( | ||||||
1029 | OldMD->getDescribedFunctionTemplate()); | ||||||
| |||||||
1030 | else | ||||||
1031 | NewMD->setInstantiationOfMemberFunction(OldMD, | ||||||
1032 | TSK_ImplicitInstantiation); | ||||||
1033 | } | ||||||
1034 | |||||||
1035 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(Old, New); | ||||||
1036 | |||||||
1037 | // We recreated a local declaration, but not by instantiating it. There | ||||||
1038 | // may be pending dependent diagnostics to produce. | ||||||
1039 | if (auto *DC = dyn_cast<DeclContext>(Old)) | ||||||
1040 | SemaRef.PerformDependentDiagnostics(DC, TemplateArgs); | ||||||
1041 | } | ||||||
1042 | |||||||
1043 | /// Transform the definition of the given declaration by | ||||||
1044 | /// instantiating it. | ||||||
1045 | Decl *TransformDefinition(SourceLocation Loc, Decl *D); | ||||||
1046 | |||||||
1047 | /// Transform the first qualifier within a scope by instantiating the | ||||||
1048 | /// declaration. | ||||||
1049 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc); | ||||||
1050 | |||||||
1051 | /// Rebuild the exception declaration and register the declaration | ||||||
1052 | /// as an instantiated local. | ||||||
1053 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, | ||||||
1054 | TypeSourceInfo *Declarator, | ||||||
1055 | SourceLocation StartLoc, | ||||||
1056 | SourceLocation NameLoc, | ||||||
1057 | IdentifierInfo *Name); | ||||||
1058 | |||||||
1059 | /// Rebuild the Objective-C exception declaration and register the | ||||||
1060 | /// declaration as an instantiated local. | ||||||
1061 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, | ||||||
1062 | TypeSourceInfo *TSInfo, QualType T); | ||||||
1063 | |||||||
1064 | /// Check for tag mismatches when instantiating an | ||||||
1065 | /// elaborated type. | ||||||
1066 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, | ||||||
1067 | ElaboratedTypeKeyword Keyword, | ||||||
1068 | NestedNameSpecifierLoc QualifierLoc, | ||||||
1069 | QualType T); | ||||||
1070 | |||||||
1071 | TemplateName | ||||||
1072 | TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, | ||||||
1073 | SourceLocation NameLoc, | ||||||
1074 | QualType ObjectType = QualType(), | ||||||
1075 | NamedDecl *FirstQualifierInScope = nullptr, | ||||||
1076 | bool AllowInjectedClassName = false); | ||||||
1077 | |||||||
1078 | const LoopHintAttr *TransformLoopHintAttr(const LoopHintAttr *LH); | ||||||
1079 | |||||||
1080 | ExprResult TransformPredefinedExpr(PredefinedExpr *E); | ||||||
1081 | ExprResult TransformDeclRefExpr(DeclRefExpr *E); | ||||||
1082 | ExprResult TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E); | ||||||
1083 | |||||||
1084 | ExprResult TransformTemplateParmRefExpr(DeclRefExpr *E, | ||||||
1085 | NonTypeTemplateParmDecl *D); | ||||||
1086 | ExprResult TransformSubstNonTypeTemplateParmPackExpr( | ||||||
1087 | SubstNonTypeTemplateParmPackExpr *E); | ||||||
1088 | ExprResult TransformSubstNonTypeTemplateParmExpr( | ||||||
1089 | SubstNonTypeTemplateParmExpr *E); | ||||||
1090 | |||||||
1091 | /// Rebuild a DeclRefExpr for a VarDecl reference. | ||||||
1092 | ExprResult RebuildVarDeclRefExpr(VarDecl *PD, SourceLocation Loc); | ||||||
1093 | |||||||
1094 | /// Transform a reference to a function or init-capture parameter pack. | ||||||
1095 | ExprResult TransformFunctionParmPackRefExpr(DeclRefExpr *E, VarDecl *PD); | ||||||
1096 | |||||||
1097 | /// Transform a FunctionParmPackExpr which was built when we couldn't | ||||||
1098 | /// expand a function parameter pack reference which refers to an expanded | ||||||
1099 | /// pack. | ||||||
1100 | ExprResult TransformFunctionParmPackExpr(FunctionParmPackExpr *E); | ||||||
1101 | |||||||
1102 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, | ||||||
1103 | FunctionProtoTypeLoc TL) { | ||||||
1104 | // Call the base version; it will forward to our overridden version below. | ||||||
1105 | return inherited::TransformFunctionProtoType(TLB, TL); | ||||||
1106 | } | ||||||
1107 | |||||||
1108 | template<typename Fn> | ||||||
1109 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, | ||||||
1110 | FunctionProtoTypeLoc TL, | ||||||
1111 | CXXRecordDecl *ThisContext, | ||||||
1112 | Qualifiers ThisTypeQuals, | ||||||
1113 | Fn TransformExceptionSpec); | ||||||
1114 | |||||||
1115 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, | ||||||
1116 | int indexAdjustment, | ||||||
1117 | Optional<unsigned> NumExpansions, | ||||||
1118 | bool ExpectParameterPack); | ||||||
1119 | |||||||
1120 | /// Transforms a template type parameter type by performing | ||||||
1121 | /// substitution of the corresponding template type argument. | ||||||
1122 | QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB, | ||||||
1123 | TemplateTypeParmTypeLoc TL); | ||||||
1124 | |||||||
1125 | /// Transforms an already-substituted template type parameter pack | ||||||
1126 | /// into either itself (if we aren't substituting into its pack expansion) | ||||||
1127 | /// or the appropriate substituted argument. | ||||||
1128 | QualType TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB, | ||||||
1129 | SubstTemplateTypeParmPackTypeLoc TL); | ||||||
1130 | |||||||
1131 | ExprResult TransformLambdaExpr(LambdaExpr *E) { | ||||||
1132 | LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true); | ||||||
1133 | return TreeTransform<TemplateInstantiator>::TransformLambdaExpr(E); | ||||||
1134 | } | ||||||
1135 | |||||||
1136 | ExprResult TransformRequiresExpr(RequiresExpr *E) { | ||||||
1137 | LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true); | ||||||
1138 | return TreeTransform<TemplateInstantiator>::TransformRequiresExpr(E); | ||||||
1139 | } | ||||||
1140 | |||||||
1141 | bool TransformRequiresExprRequirements( | ||||||
1142 | ArrayRef<concepts::Requirement *> Reqs, | ||||||
1143 | SmallVectorImpl<concepts::Requirement *> &Transformed) { | ||||||
1144 | bool SatisfactionDetermined = false; | ||||||
1145 | for (concepts::Requirement *Req : Reqs) { | ||||||
1146 | concepts::Requirement *TransReq = nullptr; | ||||||
1147 | if (!SatisfactionDetermined) { | ||||||
1148 | if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req)) | ||||||
1149 | TransReq = TransformTypeRequirement(TypeReq); | ||||||
1150 | else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req)) | ||||||
1151 | TransReq = TransformExprRequirement(ExprReq); | ||||||
1152 | else | ||||||
1153 | TransReq = TransformNestedRequirement( | ||||||
1154 | cast<concepts::NestedRequirement>(Req)); | ||||||
1155 | if (!TransReq) | ||||||
1156 | return true; | ||||||
1157 | if (!TransReq->isDependent() && !TransReq->isSatisfied()) | ||||||
1158 | // [expr.prim.req]p6 | ||||||
1159 | // [...] The substitution and semantic constraint checking | ||||||
1160 | // proceeds in lexical order and stops when a condition that | ||||||
1161 | // determines the result of the requires-expression is | ||||||
1162 | // encountered. [..] | ||||||
1163 | SatisfactionDetermined = true; | ||||||
1164 | } else | ||||||
1165 | TransReq = Req; | ||||||
1166 | Transformed.push_back(TransReq); | ||||||
1167 | } | ||||||
1168 | return false; | ||||||
1169 | } | ||||||
1170 | |||||||
1171 | TemplateParameterList *TransformTemplateParameterList( | ||||||
1172 | TemplateParameterList *OrigTPL) { | ||||||
1173 | if (!OrigTPL || !OrigTPL->size()) return OrigTPL; | ||||||
1174 | |||||||
1175 | DeclContext *Owner = OrigTPL->getParam(0)->getDeclContext(); | ||||||
1176 | TemplateDeclInstantiator DeclInstantiator(getSema(), | ||||||
1177 | /* DeclContext *Owner */ Owner, TemplateArgs); | ||||||
1178 | return DeclInstantiator.SubstTemplateParams(OrigTPL); | ||||||
1179 | } | ||||||
1180 | |||||||
1181 | concepts::TypeRequirement * | ||||||
1182 | TransformTypeRequirement(concepts::TypeRequirement *Req); | ||||||
1183 | concepts::ExprRequirement * | ||||||
1184 | TransformExprRequirement(concepts::ExprRequirement *Req); | ||||||
1185 | concepts::NestedRequirement * | ||||||
1186 | TransformNestedRequirement(concepts::NestedRequirement *Req); | ||||||
1187 | |||||||
1188 | private: | ||||||
1189 | ExprResult transformNonTypeTemplateParmRef(NonTypeTemplateParmDecl *parm, | ||||||
1190 | SourceLocation loc, | ||||||
1191 | TemplateArgument arg); | ||||||
1192 | }; | ||||||
1193 | } | ||||||
1194 | |||||||
1195 | bool TemplateInstantiator::AlreadyTransformed(QualType T) { | ||||||
1196 | if (T.isNull()) | ||||||
1197 | return true; | ||||||
1198 | |||||||
1199 | if (T->isInstantiationDependentType() || T->isVariablyModifiedType()) | ||||||
1200 | return false; | ||||||
1201 | |||||||
1202 | getSema().MarkDeclarationsReferencedInType(Loc, T); | ||||||
1203 | return true; | ||||||
1204 | } | ||||||
1205 | |||||||
1206 | static TemplateArgument | ||||||
1207 | getPackSubstitutedTemplateArgument(Sema &S, TemplateArgument Arg) { | ||||||
1208 | assert(S.ArgumentPackSubstitutionIndex >= 0)(static_cast <bool> (S.ArgumentPackSubstitutionIndex >= 0) ? void (0) : __assert_fail ("S.ArgumentPackSubstitutionIndex >= 0" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1208, __extension__ __PRETTY_FUNCTION__)); | ||||||
1209 | assert(S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size())(static_cast <bool> (S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size()) ? void (0) : __assert_fail ("S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size()" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1209, __extension__ __PRETTY_FUNCTION__)); | ||||||
1210 | Arg = Arg.pack_begin()[S.ArgumentPackSubstitutionIndex]; | ||||||
1211 | if (Arg.isPackExpansion()) | ||||||
1212 | Arg = Arg.getPackExpansionPattern(); | ||||||
1213 | return Arg; | ||||||
1214 | } | ||||||
1215 | |||||||
1216 | Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) { | ||||||
1217 | if (!D) | ||||||
1218 | return nullptr; | ||||||
1219 | |||||||
1220 | if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) { | ||||||
1221 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { | ||||||
1222 | // If the corresponding template argument is NULL or non-existent, it's | ||||||
1223 | // because we are performing instantiation from explicitly-specified | ||||||
1224 | // template arguments in a function template, but there were some | ||||||
1225 | // arguments left unspecified. | ||||||
1226 | if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(), | ||||||
1227 | TTP->getPosition())) | ||||||
1228 | return D; | ||||||
1229 | |||||||
1230 | TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition()); | ||||||
1231 | |||||||
1232 | if (TTP->isParameterPack()) { | ||||||
1233 | assert(Arg.getKind() == TemplateArgument::Pack &&(static_cast <bool> (Arg.getKind() == TemplateArgument:: Pack && "Missing argument pack") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1234, __extension__ __PRETTY_FUNCTION__)) | ||||||
1234 | "Missing argument pack")(static_cast <bool> (Arg.getKind() == TemplateArgument:: Pack && "Missing argument pack") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1234, __extension__ __PRETTY_FUNCTION__)); | ||||||
1235 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||||
1236 | } | ||||||
1237 | |||||||
1238 | TemplateName Template = Arg.getAsTemplate().getNameToSubstitute(); | ||||||
1239 | assert(!Template.isNull() && Template.getAsTemplateDecl() &&(static_cast <bool> (!Template.isNull() && Template .getAsTemplateDecl() && "Wrong kind of template template argument" ) ? void (0) : __assert_fail ("!Template.isNull() && Template.getAsTemplateDecl() && \"Wrong kind of template template argument\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1240, __extension__ __PRETTY_FUNCTION__)) | ||||||
1240 | "Wrong kind of template template argument")(static_cast <bool> (!Template.isNull() && Template .getAsTemplateDecl() && "Wrong kind of template template argument" ) ? void (0) : __assert_fail ("!Template.isNull() && Template.getAsTemplateDecl() && \"Wrong kind of template template argument\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1240, __extension__ __PRETTY_FUNCTION__)); | ||||||
1241 | return Template.getAsTemplateDecl(); | ||||||
1242 | } | ||||||
1243 | |||||||
1244 | // Fall through to find the instantiated declaration for this template | ||||||
1245 | // template parameter. | ||||||
1246 | } | ||||||
1247 | |||||||
1248 | return SemaRef.FindInstantiatedDecl(Loc, cast<NamedDecl>(D), TemplateArgs); | ||||||
1249 | } | ||||||
1250 | |||||||
1251 | Decl *TemplateInstantiator::TransformDefinition(SourceLocation Loc, Decl *D) { | ||||||
1252 | Decl *Inst = getSema().SubstDecl(D, getSema().CurContext, TemplateArgs); | ||||||
1253 | if (!Inst) | ||||||
1254 | return nullptr; | ||||||
1255 | |||||||
1256 | getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst); | ||||||
1257 | return Inst; | ||||||
1258 | } | ||||||
1259 | |||||||
1260 | NamedDecl * | ||||||
1261 | TemplateInstantiator::TransformFirstQualifierInScope(NamedDecl *D, | ||||||
1262 | SourceLocation Loc) { | ||||||
1263 | // If the first part of the nested-name-specifier was a template type | ||||||
1264 | // parameter, instantiate that type parameter down to a tag type. | ||||||
1265 | if (TemplateTypeParmDecl *TTPD = dyn_cast_or_null<TemplateTypeParmDecl>(D)) { | ||||||
1266 | const TemplateTypeParmType *TTP | ||||||
1267 | = cast<TemplateTypeParmType>(getSema().Context.getTypeDeclType(TTPD)); | ||||||
1268 | |||||||
1269 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { | ||||||
1270 | // FIXME: This needs testing w/ member access expressions. | ||||||
1271 | TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getIndex()); | ||||||
1272 | |||||||
1273 | if (TTP->isParameterPack()) { | ||||||
1274 | assert(Arg.getKind() == TemplateArgument::Pack &&(static_cast <bool> (Arg.getKind() == TemplateArgument:: Pack && "Missing argument pack") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1275, __extension__ __PRETTY_FUNCTION__)) | ||||||
1275 | "Missing argument pack")(static_cast <bool> (Arg.getKind() == TemplateArgument:: Pack && "Missing argument pack") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1275, __extension__ __PRETTY_FUNCTION__)); | ||||||
1276 | |||||||
1277 | if (getSema().ArgumentPackSubstitutionIndex == -1) | ||||||
1278 | return nullptr; | ||||||
1279 | |||||||
1280 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||||
1281 | } | ||||||
1282 | |||||||
1283 | QualType T = Arg.getAsType(); | ||||||
1284 | if (T.isNull()) | ||||||
1285 | return cast_or_null<NamedDecl>(TransformDecl(Loc, D)); | ||||||
1286 | |||||||
1287 | if (const TagType *Tag = T->getAs<TagType>()) | ||||||
1288 | return Tag->getDecl(); | ||||||
1289 | |||||||
1290 | // The resulting type is not a tag; complain. | ||||||
1291 | getSema().Diag(Loc, diag::err_nested_name_spec_non_tag) << T; | ||||||
1292 | return nullptr; | ||||||
1293 | } | ||||||
1294 | } | ||||||
1295 | |||||||
1296 | return cast_or_null<NamedDecl>(TransformDecl(Loc, D)); | ||||||
1297 | } | ||||||
1298 | |||||||
1299 | VarDecl * | ||||||
1300 | TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl, | ||||||
1301 | TypeSourceInfo *Declarator, | ||||||
1302 | SourceLocation StartLoc, | ||||||
1303 | SourceLocation NameLoc, | ||||||
1304 | IdentifierInfo *Name) { | ||||||
1305 | VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, Declarator, | ||||||
1306 | StartLoc, NameLoc, Name); | ||||||
1307 | if (Var) | ||||||
1308 | getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var); | ||||||
1309 | return Var; | ||||||
1310 | } | ||||||
1311 | |||||||
1312 | VarDecl *TemplateInstantiator::RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, | ||||||
1313 | TypeSourceInfo *TSInfo, | ||||||
1314 | QualType T) { | ||||||
1315 | VarDecl *Var = inherited::RebuildObjCExceptionDecl(ExceptionDecl, TSInfo, T); | ||||||
1316 | if (Var) | ||||||
1317 | getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var); | ||||||
1318 | return Var; | ||||||
1319 | } | ||||||
1320 | |||||||
1321 | QualType | ||||||
1322 | TemplateInstantiator::RebuildElaboratedType(SourceLocation KeywordLoc, | ||||||
1323 | ElaboratedTypeKeyword Keyword, | ||||||
1324 | NestedNameSpecifierLoc QualifierLoc, | ||||||
1325 | QualType T) { | ||||||
1326 | if (const TagType *TT = T->getAs<TagType>()) { | ||||||
1327 | TagDecl* TD = TT->getDecl(); | ||||||
1328 | |||||||
1329 | SourceLocation TagLocation = KeywordLoc; | ||||||
1330 | |||||||
1331 | IdentifierInfo *Id = TD->getIdentifier(); | ||||||
1332 | |||||||
1333 | // TODO: should we even warn on struct/class mismatches for this? Seems | ||||||
1334 | // like it's likely to produce a lot of spurious errors. | ||||||
1335 | if (Id && Keyword != ETK_None && Keyword != ETK_Typename) { | ||||||
1336 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); | ||||||
1337 | if (!SemaRef.isAcceptableTagRedeclaration(TD, Kind, /*isDefinition*/false, | ||||||
1338 | TagLocation, Id)) { | ||||||
1339 | SemaRef.Diag(TagLocation, diag::err_use_with_wrong_tag) | ||||||
1340 | << Id | ||||||
1341 | << FixItHint::CreateReplacement(SourceRange(TagLocation), | ||||||
1342 | TD->getKindName()); | ||||||
1343 | SemaRef.Diag(TD->getLocation(), diag::note_previous_use); | ||||||
1344 | } | ||||||
1345 | } | ||||||
1346 | } | ||||||
1347 | |||||||
1348 | return TreeTransform<TemplateInstantiator>::RebuildElaboratedType(KeywordLoc, | ||||||
1349 | Keyword, | ||||||
1350 | QualifierLoc, | ||||||
1351 | T); | ||||||
1352 | } | ||||||
1353 | |||||||
1354 | TemplateName TemplateInstantiator::TransformTemplateName( | ||||||
1355 | CXXScopeSpec &SS, TemplateName Name, SourceLocation NameLoc, | ||||||
1356 | QualType ObjectType, NamedDecl *FirstQualifierInScope, | ||||||
1357 | bool AllowInjectedClassName) { | ||||||
1358 | if (TemplateTemplateParmDecl *TTP | ||||||
1359 | = dyn_cast_or_null<TemplateTemplateParmDecl>(Name.getAsTemplateDecl())) { | ||||||
1360 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { | ||||||
1361 | // If the corresponding template argument is NULL or non-existent, it's | ||||||
1362 | // because we are performing instantiation from explicitly-specified | ||||||
1363 | // template arguments in a function template, but there were some | ||||||
1364 | // arguments left unspecified. | ||||||
1365 | if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(), | ||||||
1366 | TTP->getPosition())) | ||||||
1367 | return Name; | ||||||
1368 | |||||||
1369 | TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition()); | ||||||
1370 | |||||||
1371 | if (TemplateArgs.isRewrite()) { | ||||||
1372 | // We're rewriting the template parameter as a reference to another | ||||||
1373 | // template parameter. | ||||||
1374 | if (Arg.getKind() == TemplateArgument::Pack) { | ||||||
1375 | assert(Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() &&(static_cast <bool> (Arg.pack_size() == 1 && Arg .pack_begin()->isPackExpansion() && "unexpected pack arguments in template rewrite" ) ? void (0) : __assert_fail ("Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && \"unexpected pack arguments in template rewrite\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1376, __extension__ __PRETTY_FUNCTION__)) | ||||||
1376 | "unexpected pack arguments in template rewrite")(static_cast <bool> (Arg.pack_size() == 1 && Arg .pack_begin()->isPackExpansion() && "unexpected pack arguments in template rewrite" ) ? void (0) : __assert_fail ("Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && \"unexpected pack arguments in template rewrite\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1376, __extension__ __PRETTY_FUNCTION__)); | ||||||
1377 | Arg = Arg.pack_begin()->getPackExpansionPattern(); | ||||||
1378 | } | ||||||
1379 | assert(Arg.getKind() == TemplateArgument::Template &&(static_cast <bool> (Arg.getKind() == TemplateArgument:: Template && "unexpected nontype template argument kind in template rewrite" ) ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Template && \"unexpected nontype template argument kind in template rewrite\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1380, __extension__ __PRETTY_FUNCTION__)) | ||||||
1380 | "unexpected nontype template argument kind in template rewrite")(static_cast <bool> (Arg.getKind() == TemplateArgument:: Template && "unexpected nontype template argument kind in template rewrite" ) ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Template && \"unexpected nontype template argument kind in template rewrite\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1380, __extension__ __PRETTY_FUNCTION__)); | ||||||
1381 | return Arg.getAsTemplate(); | ||||||
1382 | } | ||||||
1383 | |||||||
1384 | if (TTP->isParameterPack()) { | ||||||
1385 | assert(Arg.getKind() == TemplateArgument::Pack &&(static_cast <bool> (Arg.getKind() == TemplateArgument:: Pack && "Missing argument pack") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1386, __extension__ __PRETTY_FUNCTION__)) | ||||||
1386 | "Missing argument pack")(static_cast <bool> (Arg.getKind() == TemplateArgument:: Pack && "Missing argument pack") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1386, __extension__ __PRETTY_FUNCTION__)); | ||||||
1387 | |||||||
1388 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | ||||||
1389 | // We have the template argument pack to substitute, but we're not | ||||||
1390 | // actually expanding the enclosing pack expansion yet. So, just | ||||||
1391 | // keep the entire argument pack. | ||||||
1392 | return getSema().Context.getSubstTemplateTemplateParmPack(TTP, Arg); | ||||||
1393 | } | ||||||
1394 | |||||||
1395 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||||
1396 | } | ||||||
1397 | |||||||
1398 | TemplateName Template = Arg.getAsTemplate().getNameToSubstitute(); | ||||||
1399 | assert(!Template.isNull() && "Null template template argument")(static_cast <bool> (!Template.isNull() && "Null template template argument" ) ? void (0) : __assert_fail ("!Template.isNull() && \"Null template template argument\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1399, __extension__ __PRETTY_FUNCTION__)); | ||||||
1400 | assert(!Template.getAsQualifiedTemplateName() &&(static_cast <bool> (!Template.getAsQualifiedTemplateName () && "template decl to substitute is qualified?") ? void (0) : __assert_fail ("!Template.getAsQualifiedTemplateName() && \"template decl to substitute is qualified?\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1401, __extension__ __PRETTY_FUNCTION__)) | ||||||
1401 | "template decl to substitute is qualified?")(static_cast <bool> (!Template.getAsQualifiedTemplateName () && "template decl to substitute is qualified?") ? void (0) : __assert_fail ("!Template.getAsQualifiedTemplateName() && \"template decl to substitute is qualified?\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1401, __extension__ __PRETTY_FUNCTION__)); | ||||||
1402 | |||||||
1403 | Template = getSema().Context.getSubstTemplateTemplateParm(TTP, Template); | ||||||
1404 | return Template; | ||||||
1405 | } | ||||||
1406 | } | ||||||
1407 | |||||||
1408 | if (SubstTemplateTemplateParmPackStorage *SubstPack | ||||||
1409 | = Name.getAsSubstTemplateTemplateParmPack()) { | ||||||
1410 | if (getSema().ArgumentPackSubstitutionIndex == -1) | ||||||
1411 | return Name; | ||||||
1412 | |||||||
1413 | TemplateArgument Arg = SubstPack->getArgumentPack(); | ||||||
1414 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||||
1415 | return Arg.getAsTemplate().getNameToSubstitute(); | ||||||
1416 | } | ||||||
1417 | |||||||
1418 | return inherited::TransformTemplateName(SS, Name, NameLoc, ObjectType, | ||||||
1419 | FirstQualifierInScope, | ||||||
1420 | AllowInjectedClassName); | ||||||
1421 | } | ||||||
1422 | |||||||
1423 | ExprResult | ||||||
1424 | TemplateInstantiator::TransformPredefinedExpr(PredefinedExpr *E) { | ||||||
1425 | if (!E->isTypeDependent()) | ||||||
1426 | return E; | ||||||
1427 | |||||||
1428 | return getSema().BuildPredefinedExpr(E->getLocation(), E->getIdentKind()); | ||||||
1429 | } | ||||||
1430 | |||||||
1431 | ExprResult | ||||||
1432 | TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E, | ||||||
1433 | NonTypeTemplateParmDecl *NTTP) { | ||||||
1434 | // If the corresponding template argument is NULL or non-existent, it's | ||||||
1435 | // because we are performing instantiation from explicitly-specified | ||||||
1436 | // template arguments in a function template, but there were some | ||||||
1437 | // arguments left unspecified. | ||||||
1438 | if (!TemplateArgs.hasTemplateArgument(NTTP->getDepth(), | ||||||
1439 | NTTP->getPosition())) | ||||||
1440 | return E; | ||||||
1441 | |||||||
1442 | TemplateArgument Arg = TemplateArgs(NTTP->getDepth(), NTTP->getPosition()); | ||||||
1443 | |||||||
1444 | if (TemplateArgs.isRewrite()) { | ||||||
1445 | // We're rewriting the template parameter as a reference to another | ||||||
1446 | // template parameter. | ||||||
1447 | if (Arg.getKind() == TemplateArgument::Pack) { | ||||||
1448 | assert(Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() &&(static_cast <bool> (Arg.pack_size() == 1 && Arg .pack_begin()->isPackExpansion() && "unexpected pack arguments in template rewrite" ) ? void (0) : __assert_fail ("Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && \"unexpected pack arguments in template rewrite\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1449, __extension__ __PRETTY_FUNCTION__)) | ||||||
1449 | "unexpected pack arguments in template rewrite")(static_cast <bool> (Arg.pack_size() == 1 && Arg .pack_begin()->isPackExpansion() && "unexpected pack arguments in template rewrite" ) ? void (0) : __assert_fail ("Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && \"unexpected pack arguments in template rewrite\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1449, __extension__ __PRETTY_FUNCTION__)); | ||||||
1450 | Arg = Arg.pack_begin()->getPackExpansionPattern(); | ||||||
1451 | } | ||||||
1452 | assert(Arg.getKind() == TemplateArgument::Expression &&(static_cast <bool> (Arg.getKind() == TemplateArgument:: Expression && "unexpected nontype template argument kind in template rewrite" ) ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Expression && \"unexpected nontype template argument kind in template rewrite\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1453, __extension__ __PRETTY_FUNCTION__)) | ||||||
1453 | "unexpected nontype template argument kind in template rewrite")(static_cast <bool> (Arg.getKind() == TemplateArgument:: Expression && "unexpected nontype template argument kind in template rewrite" ) ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Expression && \"unexpected nontype template argument kind in template rewrite\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1453, __extension__ __PRETTY_FUNCTION__)); | ||||||
1454 | // FIXME: This can lead to the same subexpression appearing multiple times | ||||||
1455 | // in a complete expression. | ||||||
1456 | return Arg.getAsExpr(); | ||||||
1457 | } | ||||||
1458 | |||||||
1459 | if (NTTP->isParameterPack()) { | ||||||
1460 | assert(Arg.getKind() == TemplateArgument::Pack &&(static_cast <bool> (Arg.getKind() == TemplateArgument:: Pack && "Missing argument pack") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1461, __extension__ __PRETTY_FUNCTION__)) | ||||||
1461 | "Missing argument pack")(static_cast <bool> (Arg.getKind() == TemplateArgument:: Pack && "Missing argument pack") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1461, __extension__ __PRETTY_FUNCTION__)); | ||||||
1462 | |||||||
1463 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | ||||||
1464 | // We have an argument pack, but we can't select a particular argument | ||||||
1465 | // out of it yet. Therefore, we'll build an expression to hold on to that | ||||||
1466 | // argument pack. | ||||||
1467 | QualType TargetType = SemaRef.SubstType(NTTP->getType(), TemplateArgs, | ||||||
1468 | E->getLocation(), | ||||||
1469 | NTTP->getDeclName()); | ||||||
1470 | if (TargetType.isNull()) | ||||||
1471 | return ExprError(); | ||||||
1472 | |||||||
1473 | QualType ExprType = TargetType.getNonLValueExprType(SemaRef.Context); | ||||||
1474 | if (TargetType->isRecordType()) | ||||||
1475 | ExprType.addConst(); | ||||||
1476 | |||||||
1477 | return new (SemaRef.Context) SubstNonTypeTemplateParmPackExpr( | ||||||
1478 | ExprType, TargetType->isReferenceType() ? VK_LValue : VK_PRValue, | ||||||
1479 | NTTP, E->getLocation(), Arg); | ||||||
1480 | } | ||||||
1481 | |||||||
1482 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||||
1483 | } | ||||||
1484 | |||||||
1485 | return transformNonTypeTemplateParmRef(NTTP, E->getLocation(), Arg); | ||||||
1486 | } | ||||||
1487 | |||||||
1488 | const LoopHintAttr * | ||||||
1489 | TemplateInstantiator::TransformLoopHintAttr(const LoopHintAttr *LH) { | ||||||
1490 | Expr *TransformedExpr = getDerived().TransformExpr(LH->getValue()).get(); | ||||||
1491 | |||||||
1492 | if (TransformedExpr == LH->getValue()) | ||||||
1493 | return LH; | ||||||
1494 | |||||||
1495 | // Generate error if there is a problem with the value. | ||||||
1496 | if (getSema().CheckLoopHintExpr(TransformedExpr, LH->getLocation())) | ||||||
1497 | return LH; | ||||||
1498 | |||||||
1499 | // Create new LoopHintValueAttr with integral expression in place of the | ||||||
1500 | // non-type template parameter. | ||||||
1501 | return LoopHintAttr::CreateImplicit(getSema().Context, LH->getOption(), | ||||||
1502 | LH->getState(), TransformedExpr, *LH); | ||||||
1503 | } | ||||||
1504 | |||||||
1505 | ExprResult TemplateInstantiator::transformNonTypeTemplateParmRef( | ||||||
1506 | NonTypeTemplateParmDecl *parm, | ||||||
1507 | SourceLocation loc, | ||||||
1508 | TemplateArgument arg) { | ||||||
1509 | ExprResult result; | ||||||
1510 | |||||||
1511 | // Determine the substituted parameter type. We can usually infer this from | ||||||
1512 | // the template argument, but not always. | ||||||
1513 | auto SubstParamType = [&] { | ||||||
1514 | QualType T; | ||||||
1515 | if (parm->isExpandedParameterPack()) | ||||||
1516 | T = parm->getExpansionType(SemaRef.ArgumentPackSubstitutionIndex); | ||||||
1517 | else | ||||||
1518 | T = parm->getType(); | ||||||
1519 | if (parm->isParameterPack() && isa<PackExpansionType>(T)) | ||||||
1520 | T = cast<PackExpansionType>(T)->getPattern(); | ||||||
1521 | return SemaRef.SubstType(T, TemplateArgs, loc, parm->getDeclName()); | ||||||
1522 | }; | ||||||
1523 | |||||||
1524 | bool refParam = false; | ||||||
1525 | |||||||
1526 | // The template argument itself might be an expression, in which case we just | ||||||
1527 | // return that expression. This happens when substituting into an alias | ||||||
1528 | // template. | ||||||
1529 | if (arg.getKind() == TemplateArgument::Expression) { | ||||||
1530 | Expr *argExpr = arg.getAsExpr(); | ||||||
1531 | result = argExpr; | ||||||
1532 | if (argExpr->isLValue()) { | ||||||
1533 | if (argExpr->getType()->isRecordType()) { | ||||||
1534 | // Check whether the parameter was actually a reference. | ||||||
1535 | QualType paramType = SubstParamType(); | ||||||
1536 | if (paramType.isNull()) | ||||||
1537 | return ExprError(); | ||||||
1538 | refParam = paramType->isReferenceType(); | ||||||
1539 | } else { | ||||||
1540 | refParam = true; | ||||||
1541 | } | ||||||
1542 | } | ||||||
1543 | } else if (arg.getKind() == TemplateArgument::Declaration || | ||||||
1544 | arg.getKind() == TemplateArgument::NullPtr) { | ||||||
1545 | ValueDecl *VD; | ||||||
1546 | if (arg.getKind() == TemplateArgument::Declaration) { | ||||||
1547 | VD = arg.getAsDecl(); | ||||||
1548 | |||||||
1549 | // Find the instantiation of the template argument. This is | ||||||
1550 | // required for nested templates. | ||||||
1551 | VD = cast_or_null<ValueDecl>( | ||||||
1552 | getSema().FindInstantiatedDecl(loc, VD, TemplateArgs)); | ||||||
1553 | if (!VD) | ||||||
1554 | return ExprError(); | ||||||
1555 | } else { | ||||||
1556 | // Propagate NULL template argument. | ||||||
1557 | VD = nullptr; | ||||||
1558 | } | ||||||
1559 | |||||||
1560 | QualType paramType = VD ? arg.getParamTypeForDecl() : arg.getNullPtrType(); | ||||||
1561 | assert(!paramType.isNull() && "type substitution failed for param type")(static_cast <bool> (!paramType.isNull() && "type substitution failed for param type" ) ? void (0) : __assert_fail ("!paramType.isNull() && \"type substitution failed for param type\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1561, __extension__ __PRETTY_FUNCTION__)); | ||||||
1562 | assert(!paramType->isDependentType() && "param type still dependent")(static_cast <bool> (!paramType->isDependentType() && "param type still dependent") ? void (0) : __assert_fail ("!paramType->isDependentType() && \"param type still dependent\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1562, __extension__ __PRETTY_FUNCTION__)); | ||||||
1563 | result = SemaRef.BuildExpressionFromDeclTemplateArgument(arg, paramType, loc); | ||||||
1564 | refParam = paramType->isReferenceType(); | ||||||
1565 | } else { | ||||||
1566 | result = SemaRef.BuildExpressionFromIntegralTemplateArgument(arg, loc); | ||||||
1567 | assert(result.isInvalid() ||(static_cast <bool> (result.isInvalid() || SemaRef.Context .hasSameType(result.get()->getType(), arg.getIntegralType( ))) ? void (0) : __assert_fail ("result.isInvalid() || SemaRef.Context.hasSameType(result.get()->getType(), arg.getIntegralType())" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1569, __extension__ __PRETTY_FUNCTION__)) | ||||||
1568 | SemaRef.Context.hasSameType(result.get()->getType(),(static_cast <bool> (result.isInvalid() || SemaRef.Context .hasSameType(result.get()->getType(), arg.getIntegralType( ))) ? void (0) : __assert_fail ("result.isInvalid() || SemaRef.Context.hasSameType(result.get()->getType(), arg.getIntegralType())" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1569, __extension__ __PRETTY_FUNCTION__)) | ||||||
1569 | arg.getIntegralType()))(static_cast <bool> (result.isInvalid() || SemaRef.Context .hasSameType(result.get()->getType(), arg.getIntegralType( ))) ? void (0) : __assert_fail ("result.isInvalid() || SemaRef.Context.hasSameType(result.get()->getType(), arg.getIntegralType())" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1569, __extension__ __PRETTY_FUNCTION__)); | ||||||
1570 | } | ||||||
1571 | |||||||
1572 | if (result.isInvalid()) | ||||||
1573 | return ExprError(); | ||||||
1574 | |||||||
1575 | Expr *resultExpr = result.get(); | ||||||
1576 | return new (SemaRef.Context) SubstNonTypeTemplateParmExpr( | ||||||
1577 | resultExpr->getType(), resultExpr->getValueKind(), loc, parm, refParam, | ||||||
1578 | resultExpr); | ||||||
1579 | } | ||||||
1580 | |||||||
1581 | ExprResult | ||||||
1582 | TemplateInstantiator::TransformSubstNonTypeTemplateParmPackExpr( | ||||||
1583 | SubstNonTypeTemplateParmPackExpr *E) { | ||||||
1584 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | ||||||
1585 | // We aren't expanding the parameter pack, so just return ourselves. | ||||||
1586 | return E; | ||||||
1587 | } | ||||||
1588 | |||||||
1589 | TemplateArgument Arg = E->getArgumentPack(); | ||||||
1590 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||||
1591 | return transformNonTypeTemplateParmRef(E->getParameterPack(), | ||||||
1592 | E->getParameterPackLocation(), | ||||||
1593 | Arg); | ||||||
1594 | } | ||||||
1595 | |||||||
1596 | ExprResult | ||||||
1597 | TemplateInstantiator::TransformSubstNonTypeTemplateParmExpr( | ||||||
1598 | SubstNonTypeTemplateParmExpr *E) { | ||||||
1599 | ExprResult SubstReplacement = E->getReplacement(); | ||||||
1600 | if (!isa<ConstantExpr>(SubstReplacement.get())) | ||||||
1601 | SubstReplacement = TransformExpr(E->getReplacement()); | ||||||
1602 | if (SubstReplacement.isInvalid()) | ||||||
1603 | return true; | ||||||
1604 | QualType SubstType = TransformType(E->getParameterType(getSema().Context)); | ||||||
1605 | if (SubstType.isNull()) | ||||||
1606 | return true; | ||||||
1607 | // The type may have been previously dependent and not now, which means we | ||||||
1608 | // might have to implicit cast the argument to the new type, for example: | ||||||
1609 | // template<auto T, decltype(T) U> | ||||||
1610 | // concept C = sizeof(U) == 4; | ||||||
1611 | // void foo() requires C<2, 'a'> { } | ||||||
1612 | // When normalizing foo(), we first form the normalized constraints of C: | ||||||
1613 | // AtomicExpr(sizeof(U) == 4, | ||||||
1614 | // U=SubstNonTypeTemplateParmExpr(Param=U, | ||||||
1615 | // Expr=DeclRef(U), | ||||||
1616 | // Type=decltype(T))) | ||||||
1617 | // Then we substitute T = 2, U = 'a' into the parameter mapping, and need to | ||||||
1618 | // produce: | ||||||
1619 | // AtomicExpr(sizeof(U) == 4, | ||||||
1620 | // U=SubstNonTypeTemplateParmExpr(Param=U, | ||||||
1621 | // Expr=ImpCast( | ||||||
1622 | // decltype(2), | ||||||
1623 | // SubstNTTPE(Param=U, Expr='a', | ||||||
1624 | // Type=char)), | ||||||
1625 | // Type=decltype(2))) | ||||||
1626 | // The call to CheckTemplateArgument here produces the ImpCast. | ||||||
1627 | TemplateArgument Converted; | ||||||
1628 | if (SemaRef.CheckTemplateArgument(E->getParameter(), SubstType, | ||||||
1629 | SubstReplacement.get(), | ||||||
1630 | Converted).isInvalid()) | ||||||
1631 | return true; | ||||||
1632 | return transformNonTypeTemplateParmRef(E->getParameter(), | ||||||
1633 | E->getExprLoc(), Converted); | ||||||
1634 | } | ||||||
1635 | |||||||
1636 | ExprResult TemplateInstantiator::RebuildVarDeclRefExpr(VarDecl *PD, | ||||||
1637 | SourceLocation Loc) { | ||||||
1638 | DeclarationNameInfo NameInfo(PD->getDeclName(), Loc); | ||||||
1639 | return getSema().BuildDeclarationNameExpr(CXXScopeSpec(), NameInfo, PD); | ||||||
1640 | } | ||||||
1641 | |||||||
1642 | ExprResult | ||||||
1643 | TemplateInstantiator::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { | ||||||
1644 | if (getSema().ArgumentPackSubstitutionIndex != -1) { | ||||||
1645 | // We can expand this parameter pack now. | ||||||
1646 | VarDecl *D = E->getExpansion(getSema().ArgumentPackSubstitutionIndex); | ||||||
1647 | VarDecl *VD = cast_or_null<VarDecl>(TransformDecl(E->getExprLoc(), D)); | ||||||
1648 | if (!VD) | ||||||
1649 | return ExprError(); | ||||||
1650 | return RebuildVarDeclRefExpr(VD, E->getExprLoc()); | ||||||
1651 | } | ||||||
1652 | |||||||
1653 | QualType T = TransformType(E->getType()); | ||||||
1654 | if (T.isNull()) | ||||||
1655 | return ExprError(); | ||||||
1656 | |||||||
1657 | // Transform each of the parameter expansions into the corresponding | ||||||
1658 | // parameters in the instantiation of the function decl. | ||||||
1659 | SmallVector<VarDecl *, 8> Vars; | ||||||
1660 | Vars.reserve(E->getNumExpansions()); | ||||||
1661 | for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end(); | ||||||
1662 | I != End; ++I) { | ||||||
1663 | VarDecl *D = cast_or_null<VarDecl>(TransformDecl(E->getExprLoc(), *I)); | ||||||
1664 | if (!D) | ||||||
1665 | return ExprError(); | ||||||
1666 | Vars.push_back(D); | ||||||
1667 | } | ||||||
1668 | |||||||
1669 | auto *PackExpr = | ||||||
1670 | FunctionParmPackExpr::Create(getSema().Context, T, E->getParameterPack(), | ||||||
1671 | E->getParameterPackLocation(), Vars); | ||||||
1672 | getSema().MarkFunctionParmPackReferenced(PackExpr); | ||||||
1673 | return PackExpr; | ||||||
1674 | } | ||||||
1675 | |||||||
1676 | ExprResult | ||||||
1677 | TemplateInstantiator::TransformFunctionParmPackRefExpr(DeclRefExpr *E, | ||||||
1678 | VarDecl *PD) { | ||||||
1679 | typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack; | ||||||
1680 | llvm::PointerUnion<Decl *, DeclArgumentPack *> *Found | ||||||
1681 | = getSema().CurrentInstantiationScope->findInstantiationOf(PD); | ||||||
1682 | assert(Found && "no instantiation for parameter pack")(static_cast <bool> (Found && "no instantiation for parameter pack" ) ? void (0) : __assert_fail ("Found && \"no instantiation for parameter pack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1682, __extension__ __PRETTY_FUNCTION__)); | ||||||
1683 | |||||||
1684 | Decl *TransformedDecl; | ||||||
1685 | if (DeclArgumentPack *Pack = Found->dyn_cast<DeclArgumentPack *>()) { | ||||||
1686 | // If this is a reference to a function parameter pack which we can | ||||||
1687 | // substitute but can't yet expand, build a FunctionParmPackExpr for it. | ||||||
1688 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | ||||||
1689 | QualType T = TransformType(E->getType()); | ||||||
1690 | if (T.isNull()) | ||||||
1691 | return ExprError(); | ||||||
1692 | auto *PackExpr = FunctionParmPackExpr::Create(getSema().Context, T, PD, | ||||||
1693 | E->getExprLoc(), *Pack); | ||||||
1694 | getSema().MarkFunctionParmPackReferenced(PackExpr); | ||||||
1695 | return PackExpr; | ||||||
1696 | } | ||||||
1697 | |||||||
1698 | TransformedDecl = (*Pack)[getSema().ArgumentPackSubstitutionIndex]; | ||||||
1699 | } else { | ||||||
1700 | TransformedDecl = Found->get<Decl*>(); | ||||||
1701 | } | ||||||
1702 | |||||||
1703 | // We have either an unexpanded pack or a specific expansion. | ||||||
1704 | return RebuildVarDeclRefExpr(cast<VarDecl>(TransformedDecl), E->getExprLoc()); | ||||||
1705 | } | ||||||
1706 | |||||||
1707 | ExprResult | ||||||
1708 | TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) { | ||||||
1709 | NamedDecl *D = E->getDecl(); | ||||||
1710 | |||||||
1711 | // Handle references to non-type template parameters and non-type template | ||||||
1712 | // parameter packs. | ||||||
1713 | if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) { | ||||||
1714 | if (NTTP->getDepth() < TemplateArgs.getNumLevels()) | ||||||
1715 | return TransformTemplateParmRefExpr(E, NTTP); | ||||||
1716 | |||||||
1717 | // We have a non-type template parameter that isn't fully substituted; | ||||||
1718 | // FindInstantiatedDecl will find it in the local instantiation scope. | ||||||
1719 | } | ||||||
1720 | |||||||
1721 | // Handle references to function parameter packs. | ||||||
1722 | if (VarDecl *PD = dyn_cast<VarDecl>(D)) | ||||||
1723 | if (PD->isParameterPack()) | ||||||
1724 | return TransformFunctionParmPackRefExpr(E, PD); | ||||||
1725 | |||||||
1726 | return TreeTransform<TemplateInstantiator>::TransformDeclRefExpr(E); | ||||||
1727 | } | ||||||
1728 | |||||||
1729 | ExprResult TemplateInstantiator::TransformCXXDefaultArgExpr( | ||||||
1730 | CXXDefaultArgExpr *E) { | ||||||
1731 | assert(!cast<FunctionDecl>(E->getParam()->getDeclContext())->(static_cast <bool> (!cast<FunctionDecl>(E->getParam ()->getDeclContext())-> getDescribedFunctionTemplate() && "Default arg expressions are never formed in dependent cases." ) ? void (0) : __assert_fail ("!cast<FunctionDecl>(E->getParam()->getDeclContext())-> getDescribedFunctionTemplate() && \"Default arg expressions are never formed in dependent cases.\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1733, __extension__ __PRETTY_FUNCTION__)) | ||||||
1732 | getDescribedFunctionTemplate() &&(static_cast <bool> (!cast<FunctionDecl>(E->getParam ()->getDeclContext())-> getDescribedFunctionTemplate() && "Default arg expressions are never formed in dependent cases." ) ? void (0) : __assert_fail ("!cast<FunctionDecl>(E->getParam()->getDeclContext())-> getDescribedFunctionTemplate() && \"Default arg expressions are never formed in dependent cases.\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1733, __extension__ __PRETTY_FUNCTION__)) | ||||||
1733 | "Default arg expressions are never formed in dependent cases.")(static_cast <bool> (!cast<FunctionDecl>(E->getParam ()->getDeclContext())-> getDescribedFunctionTemplate() && "Default arg expressions are never formed in dependent cases." ) ? void (0) : __assert_fail ("!cast<FunctionDecl>(E->getParam()->getDeclContext())-> getDescribedFunctionTemplate() && \"Default arg expressions are never formed in dependent cases.\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1733, __extension__ __PRETTY_FUNCTION__)); | ||||||
1734 | return SemaRef.BuildCXXDefaultArgExpr(E->getUsedLocation(), | ||||||
1735 | cast<FunctionDecl>(E->getParam()->getDeclContext()), | ||||||
1736 | E->getParam()); | ||||||
1737 | } | ||||||
1738 | |||||||
1739 | template<typename Fn> | ||||||
1740 | QualType TemplateInstantiator::TransformFunctionProtoType(TypeLocBuilder &TLB, | ||||||
1741 | FunctionProtoTypeLoc TL, | ||||||
1742 | CXXRecordDecl *ThisContext, | ||||||
1743 | Qualifiers ThisTypeQuals, | ||||||
1744 | Fn TransformExceptionSpec) { | ||||||
1745 | // We need a local instantiation scope for this function prototype. | ||||||
1746 | LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true); | ||||||
1747 | return inherited::TransformFunctionProtoType( | ||||||
1748 | TLB, TL, ThisContext, ThisTypeQuals, TransformExceptionSpec); | ||||||
1749 | } | ||||||
1750 | |||||||
1751 | ParmVarDecl * | ||||||
1752 | TemplateInstantiator::TransformFunctionTypeParam(ParmVarDecl *OldParm, | ||||||
1753 | int indexAdjustment, | ||||||
1754 | Optional<unsigned> NumExpansions, | ||||||
1755 | bool ExpectParameterPack) { | ||||||
1756 | auto NewParm = | ||||||
1757 | SemaRef.SubstParmVarDecl(OldParm, TemplateArgs, indexAdjustment, | ||||||
1758 | NumExpansions, ExpectParameterPack); | ||||||
1759 | if (NewParm && SemaRef.getLangOpts().OpenCL) | ||||||
1760 | SemaRef.deduceOpenCLAddressSpace(NewParm); | ||||||
1761 | return NewParm; | ||||||
1762 | } | ||||||
1763 | |||||||
1764 | QualType | ||||||
1765 | TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB, | ||||||
1766 | TemplateTypeParmTypeLoc TL) { | ||||||
1767 | const TemplateTypeParmType *T = TL.getTypePtr(); | ||||||
1768 | if (T->getDepth() < TemplateArgs.getNumLevels()) { | ||||||
1769 | // Replace the template type parameter with its corresponding | ||||||
1770 | // template argument. | ||||||
1771 | |||||||
1772 | // If the corresponding template argument is NULL or doesn't exist, it's | ||||||
1773 | // because we are performing instantiation from explicitly-specified | ||||||
1774 | // template arguments in a function template class, but there were some | ||||||
1775 | // arguments left unspecified. | ||||||
1776 | if (!TemplateArgs.hasTemplateArgument(T->getDepth(), T->getIndex())) { | ||||||
1777 | TemplateTypeParmTypeLoc NewTL | ||||||
1778 | = TLB.push<TemplateTypeParmTypeLoc>(TL.getType()); | ||||||
1779 | NewTL.setNameLoc(TL.getNameLoc()); | ||||||
1780 | return TL.getType(); | ||||||
1781 | } | ||||||
1782 | |||||||
1783 | TemplateArgument Arg = TemplateArgs(T->getDepth(), T->getIndex()); | ||||||
1784 | |||||||
1785 | if (TemplateArgs.isRewrite()) { | ||||||
1786 | // We're rewriting the template parameter as a reference to another | ||||||
1787 | // template parameter. | ||||||
1788 | if (Arg.getKind() == TemplateArgument::Pack) { | ||||||
1789 | assert(Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() &&(static_cast <bool> (Arg.pack_size() == 1 && Arg .pack_begin()->isPackExpansion() && "unexpected pack arguments in template rewrite" ) ? void (0) : __assert_fail ("Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && \"unexpected pack arguments in template rewrite\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1790, __extension__ __PRETTY_FUNCTION__)) | ||||||
1790 | "unexpected pack arguments in template rewrite")(static_cast <bool> (Arg.pack_size() == 1 && Arg .pack_begin()->isPackExpansion() && "unexpected pack arguments in template rewrite" ) ? void (0) : __assert_fail ("Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && \"unexpected pack arguments in template rewrite\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1790, __extension__ __PRETTY_FUNCTION__)); | ||||||
1791 | Arg = Arg.pack_begin()->getPackExpansionPattern(); | ||||||
1792 | } | ||||||
1793 | assert(Arg.getKind() == TemplateArgument::Type &&(static_cast <bool> (Arg.getKind() == TemplateArgument:: Type && "unexpected nontype template argument kind in template rewrite" ) ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Type && \"unexpected nontype template argument kind in template rewrite\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1794, __extension__ __PRETTY_FUNCTION__)) | ||||||
1794 | "unexpected nontype template argument kind in template rewrite")(static_cast <bool> (Arg.getKind() == TemplateArgument:: Type && "unexpected nontype template argument kind in template rewrite" ) ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Type && \"unexpected nontype template argument kind in template rewrite\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1794, __extension__ __PRETTY_FUNCTION__)); | ||||||
1795 | QualType NewT = Arg.getAsType(); | ||||||
1796 | assert(isa<TemplateTypeParmType>(NewT) &&(static_cast <bool> (isa<TemplateTypeParmType>(NewT ) && "type parm not rewritten to type parm") ? void ( 0) : __assert_fail ("isa<TemplateTypeParmType>(NewT) && \"type parm not rewritten to type parm\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1797, __extension__ __PRETTY_FUNCTION__)) | ||||||
1797 | "type parm not rewritten to type parm")(static_cast <bool> (isa<TemplateTypeParmType>(NewT ) && "type parm not rewritten to type parm") ? void ( 0) : __assert_fail ("isa<TemplateTypeParmType>(NewT) && \"type parm not rewritten to type parm\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1797, __extension__ __PRETTY_FUNCTION__)); | ||||||
1798 | auto NewTL = TLB.push<TemplateTypeParmTypeLoc>(NewT); | ||||||
1799 | NewTL.setNameLoc(TL.getNameLoc()); | ||||||
1800 | return NewT; | ||||||
1801 | } | ||||||
1802 | |||||||
1803 | if (T->isParameterPack()) { | ||||||
1804 | assert(Arg.getKind() == TemplateArgument::Pack &&(static_cast <bool> (Arg.getKind() == TemplateArgument:: Pack && "Missing argument pack") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1805, __extension__ __PRETTY_FUNCTION__)) | ||||||
1805 | "Missing argument pack")(static_cast <bool> (Arg.getKind() == TemplateArgument:: Pack && "Missing argument pack") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1805, __extension__ __PRETTY_FUNCTION__)); | ||||||
1806 | |||||||
1807 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | ||||||
1808 | // We have the template argument pack, but we're not expanding the | ||||||
1809 | // enclosing pack expansion yet. Just save the template argument | ||||||
1810 | // pack for later substitution. | ||||||
1811 | QualType Result | ||||||
1812 | = getSema().Context.getSubstTemplateTypeParmPackType(T, Arg); | ||||||
1813 | SubstTemplateTypeParmPackTypeLoc NewTL | ||||||
1814 | = TLB.push<SubstTemplateTypeParmPackTypeLoc>(Result); | ||||||
1815 | NewTL.setNameLoc(TL.getNameLoc()); | ||||||
1816 | return Result; | ||||||
1817 | } | ||||||
1818 | |||||||
1819 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||||
1820 | } | ||||||
1821 | |||||||
1822 | assert(Arg.getKind() == TemplateArgument::Type &&(static_cast <bool> (Arg.getKind() == TemplateArgument:: Type && "Template argument kind mismatch") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Type && \"Template argument kind mismatch\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1823, __extension__ __PRETTY_FUNCTION__)) | ||||||
1823 | "Template argument kind mismatch")(static_cast <bool> (Arg.getKind() == TemplateArgument:: Type && "Template argument kind mismatch") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Type && \"Template argument kind mismatch\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1823, __extension__ __PRETTY_FUNCTION__)); | ||||||
1824 | |||||||
1825 | QualType Replacement = Arg.getAsType(); | ||||||
1826 | |||||||
1827 | // TODO: only do this uniquing once, at the start of instantiation. | ||||||
1828 | QualType Result | ||||||
1829 | = getSema().Context.getSubstTemplateTypeParmType(T, Replacement); | ||||||
1830 | SubstTemplateTypeParmTypeLoc NewTL | ||||||
1831 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); | ||||||
1832 | NewTL.setNameLoc(TL.getNameLoc()); | ||||||
1833 | return Result; | ||||||
1834 | } | ||||||
1835 | |||||||
1836 | // The template type parameter comes from an inner template (e.g., | ||||||
1837 | // the template parameter list of a member template inside the | ||||||
1838 | // template we are instantiating). Create a new template type | ||||||
1839 | // parameter with the template "level" reduced by one. | ||||||
1840 | TemplateTypeParmDecl *NewTTPDecl = nullptr; | ||||||
1841 | if (TemplateTypeParmDecl *OldTTPDecl = T->getDecl()) | ||||||
1842 | NewTTPDecl = cast_or_null<TemplateTypeParmDecl>( | ||||||
1843 | TransformDecl(TL.getNameLoc(), OldTTPDecl)); | ||||||
1844 | |||||||
1845 | QualType Result = getSema().Context.getTemplateTypeParmType( | ||||||
1846 | T->getDepth() - TemplateArgs.getNumSubstitutedLevels(), T->getIndex(), | ||||||
1847 | T->isParameterPack(), NewTTPDecl); | ||||||
1848 | TemplateTypeParmTypeLoc NewTL = TLB.push<TemplateTypeParmTypeLoc>(Result); | ||||||
1849 | NewTL.setNameLoc(TL.getNameLoc()); | ||||||
1850 | return Result; | ||||||
1851 | } | ||||||
1852 | |||||||
1853 | QualType | ||||||
1854 | TemplateInstantiator::TransformSubstTemplateTypeParmPackType( | ||||||
1855 | TypeLocBuilder &TLB, | ||||||
1856 | SubstTemplateTypeParmPackTypeLoc TL) { | ||||||
1857 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | ||||||
1858 | // We aren't expanding the parameter pack, so just return ourselves. | ||||||
1859 | SubstTemplateTypeParmPackTypeLoc NewTL | ||||||
1860 | = TLB.push<SubstTemplateTypeParmPackTypeLoc>(TL.getType()); | ||||||
1861 | NewTL.setNameLoc(TL.getNameLoc()); | ||||||
1862 | return TL.getType(); | ||||||
1863 | } | ||||||
1864 | |||||||
1865 | TemplateArgument Arg = TL.getTypePtr()->getArgumentPack(); | ||||||
1866 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||||
1867 | QualType Result = Arg.getAsType(); | ||||||
1868 | |||||||
1869 | Result = getSema().Context.getSubstTemplateTypeParmType( | ||||||
1870 | TL.getTypePtr()->getReplacedParameter(), | ||||||
1871 | Result); | ||||||
1872 | SubstTemplateTypeParmTypeLoc NewTL | ||||||
1873 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); | ||||||
1874 | NewTL.setNameLoc(TL.getNameLoc()); | ||||||
1875 | return Result; | ||||||
1876 | } | ||||||
1877 | |||||||
1878 | template<typename EntityPrinter> | ||||||
1879 | static concepts::Requirement::SubstitutionDiagnostic * | ||||||
1880 | createSubstDiag(Sema &S, TemplateDeductionInfo &Info, EntityPrinter Printer) { | ||||||
1881 | SmallString<128> Message; | ||||||
1882 | SourceLocation ErrorLoc; | ||||||
1883 | if (Info.hasSFINAEDiagnostic()) { | ||||||
1884 | PartialDiagnosticAt PDA(SourceLocation(), | ||||||
1885 | PartialDiagnostic::NullDiagnostic{}); | ||||||
1886 | Info.takeSFINAEDiagnostic(PDA); | ||||||
1887 | PDA.second.EmitToString(S.getDiagnostics(), Message); | ||||||
1888 | ErrorLoc = PDA.first; | ||||||
1889 | } else { | ||||||
1890 | ErrorLoc = Info.getLocation(); | ||||||
1891 | } | ||||||
1892 | char *MessageBuf = new (S.Context) char[Message.size()]; | ||||||
1893 | std::copy(Message.begin(), Message.end(), MessageBuf); | ||||||
1894 | SmallString<128> Entity; | ||||||
1895 | llvm::raw_svector_ostream OS(Entity); | ||||||
1896 | Printer(OS); | ||||||
1897 | char *EntityBuf = new (S.Context) char[Entity.size()]; | ||||||
1898 | std::copy(Entity.begin(), Entity.end(), EntityBuf); | ||||||
1899 | return new (S.Context) concepts::Requirement::SubstitutionDiagnostic{ | ||||||
1900 | StringRef(EntityBuf, Entity.size()), ErrorLoc, | ||||||
1901 | StringRef(MessageBuf, Message.size())}; | ||||||
1902 | } | ||||||
1903 | |||||||
1904 | concepts::TypeRequirement * | ||||||
1905 | TemplateInstantiator::TransformTypeRequirement(concepts::TypeRequirement *Req) { | ||||||
1906 | if (!Req->isDependent() && !AlwaysRebuild()) | ||||||
1907 | return Req; | ||||||
1908 | if (Req->isSubstitutionFailure()) { | ||||||
1909 | if (AlwaysRebuild()) | ||||||
1910 | return RebuildTypeRequirement( | ||||||
1911 | Req->getSubstitutionDiagnostic()); | ||||||
1912 | return Req; | ||||||
1913 | } | ||||||
1914 | |||||||
1915 | Sema::SFINAETrap Trap(SemaRef); | ||||||
1916 | TemplateDeductionInfo Info(Req->getType()->getTypeLoc().getBeginLoc()); | ||||||
1917 | Sema::InstantiatingTemplate TypeInst(SemaRef, | ||||||
1918 | Req->getType()->getTypeLoc().getBeginLoc(), Req, Info, | ||||||
1919 | Req->getType()->getTypeLoc().getSourceRange()); | ||||||
1920 | if (TypeInst.isInvalid()) | ||||||
1921 | return nullptr; | ||||||
1922 | TypeSourceInfo *TransType = TransformType(Req->getType()); | ||||||
1923 | if (!TransType || Trap.hasErrorOccurred()) | ||||||
1924 | return RebuildTypeRequirement(createSubstDiag(SemaRef, Info, | ||||||
1925 | [&] (llvm::raw_ostream& OS) { | ||||||
1926 | Req->getType()->getType().print(OS, SemaRef.getPrintingPolicy()); | ||||||
1927 | })); | ||||||
1928 | return RebuildTypeRequirement(TransType); | ||||||
1929 | } | ||||||
1930 | |||||||
1931 | concepts::ExprRequirement * | ||||||
1932 | TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) { | ||||||
1933 | if (!Req->isDependent() && !AlwaysRebuild()) | ||||||
1934 | return Req; | ||||||
1935 | |||||||
1936 | Sema::SFINAETrap Trap(SemaRef); | ||||||
1937 | |||||||
1938 | llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> | ||||||
1939 | TransExpr; | ||||||
1940 | if (Req->isExprSubstitutionFailure()) | ||||||
1941 | TransExpr = Req->getExprSubstitutionDiagnostic(); | ||||||
1942 | else { | ||||||
1943 | Expr *E = Req->getExpr(); | ||||||
1944 | TemplateDeductionInfo Info(E->getBeginLoc()); | ||||||
1945 | Sema::InstantiatingTemplate ExprInst(SemaRef, E->getBeginLoc(), Req, Info, | ||||||
1946 | E->getSourceRange()); | ||||||
1947 | if (ExprInst.isInvalid()) | ||||||
1948 | return nullptr; | ||||||
1949 | ExprResult TransExprRes = TransformExpr(E); | ||||||
1950 | if (TransExprRes.isInvalid() || Trap.hasErrorOccurred()) | ||||||
1951 | TransExpr = createSubstDiag(SemaRef, Info, [&](llvm::raw_ostream &OS) { | ||||||
1952 | E->printPretty(OS, nullptr, SemaRef.getPrintingPolicy()); | ||||||
1953 | }); | ||||||
1954 | else | ||||||
1955 | TransExpr = TransExprRes.get(); | ||||||
1956 | } | ||||||
1957 | |||||||
1958 | llvm::Optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq; | ||||||
1959 | const auto &RetReq = Req->getReturnTypeRequirement(); | ||||||
1960 | if (RetReq.isEmpty()) | ||||||
1961 | TransRetReq.emplace(); | ||||||
1962 | else if (RetReq.isSubstitutionFailure()) | ||||||
1963 | TransRetReq.emplace(RetReq.getSubstitutionDiagnostic()); | ||||||
1964 | else if (RetReq.isTypeConstraint()) { | ||||||
1965 | TemplateParameterList *OrigTPL = | ||||||
1966 | RetReq.getTypeConstraintTemplateParameterList(); | ||||||
1967 | TemplateDeductionInfo Info(OrigTPL->getTemplateLoc()); | ||||||
1968 | Sema::InstantiatingTemplate TPLInst(SemaRef, OrigTPL->getTemplateLoc(), | ||||||
1969 | Req, Info, OrigTPL->getSourceRange()); | ||||||
1970 | if (TPLInst.isInvalid()) | ||||||
1971 | return nullptr; | ||||||
1972 | TemplateParameterList *TPL = | ||||||
1973 | TransformTemplateParameterList(OrigTPL); | ||||||
1974 | if (!TPL) | ||||||
1975 | TransRetReq.emplace(createSubstDiag(SemaRef, Info, | ||||||
1976 | [&] (llvm::raw_ostream& OS) { | ||||||
1977 | RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint() | ||||||
1978 | ->printPretty(OS, nullptr, SemaRef.getPrintingPolicy()); | ||||||
1979 | })); | ||||||
1980 | else { | ||||||
1981 | TPLInst.Clear(); | ||||||
1982 | TransRetReq.emplace(TPL); | ||||||
1983 | } | ||||||
1984 | } | ||||||
1985 | assert(TransRetReq.hasValue() &&(static_cast <bool> (TransRetReq.hasValue() && "All code paths leading here must set TransRetReq" ) ? void (0) : __assert_fail ("TransRetReq.hasValue() && \"All code paths leading here must set TransRetReq\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1986, __extension__ __PRETTY_FUNCTION__)) | ||||||
1986 | "All code paths leading here must set TransRetReq")(static_cast <bool> (TransRetReq.hasValue() && "All code paths leading here must set TransRetReq" ) ? void (0) : __assert_fail ("TransRetReq.hasValue() && \"All code paths leading here must set TransRetReq\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1986, __extension__ __PRETTY_FUNCTION__)); | ||||||
1987 | if (Expr *E = TransExpr.dyn_cast<Expr *>()) | ||||||
1988 | return RebuildExprRequirement(E, Req->isSimple(), Req->getNoexceptLoc(), | ||||||
1989 | std::move(*TransRetReq)); | ||||||
1990 | return RebuildExprRequirement( | ||||||
1991 | TransExpr.get<concepts::Requirement::SubstitutionDiagnostic *>(), | ||||||
1992 | Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq)); | ||||||
1993 | } | ||||||
1994 | |||||||
1995 | concepts::NestedRequirement * | ||||||
1996 | TemplateInstantiator::TransformNestedRequirement( | ||||||
1997 | concepts::NestedRequirement *Req) { | ||||||
1998 | if (!Req->isDependent() && !AlwaysRebuild()) | ||||||
1999 | return Req; | ||||||
2000 | if (Req->isSubstitutionFailure()) { | ||||||
2001 | if (AlwaysRebuild()) | ||||||
2002 | return RebuildNestedRequirement( | ||||||
2003 | Req->getSubstitutionDiagnostic()); | ||||||
2004 | return Req; | ||||||
2005 | } | ||||||
2006 | Sema::InstantiatingTemplate ReqInst(SemaRef, | ||||||
2007 | Req->getConstraintExpr()->getBeginLoc(), Req, | ||||||
2008 | Sema::InstantiatingTemplate::ConstraintsCheck{}, | ||||||
2009 | Req->getConstraintExpr()->getSourceRange()); | ||||||
2010 | |||||||
2011 | ExprResult TransConstraint; | ||||||
2012 | TemplateDeductionInfo Info(Req->getConstraintExpr()->getBeginLoc()); | ||||||
2013 | { | ||||||
2014 | EnterExpressionEvaluationContext ContextRAII( | ||||||
2015 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); | ||||||
2016 | Sema::SFINAETrap Trap(SemaRef); | ||||||
2017 | Sema::InstantiatingTemplate ConstrInst(SemaRef, | ||||||
2018 | Req->getConstraintExpr()->getBeginLoc(), Req, Info, | ||||||
2019 | Req->getConstraintExpr()->getSourceRange()); | ||||||
2020 | if (ConstrInst.isInvalid()) | ||||||
2021 | return nullptr; | ||||||
2022 | TransConstraint = TransformExpr(Req->getConstraintExpr()); | ||||||
2023 | if (TransConstraint.isInvalid() || Trap.hasErrorOccurred()) | ||||||
2024 | return RebuildNestedRequirement(createSubstDiag(SemaRef, Info, | ||||||
2025 | [&] (llvm::raw_ostream& OS) { | ||||||
2026 | Req->getConstraintExpr()->printPretty(OS, nullptr, | ||||||
2027 | SemaRef.getPrintingPolicy()); | ||||||
2028 | })); | ||||||
2029 | } | ||||||
2030 | return RebuildNestedRequirement(TransConstraint.get()); | ||||||
2031 | } | ||||||
2032 | |||||||
2033 | |||||||
2034 | /// Perform substitution on the type T with a given set of template | ||||||
2035 | /// arguments. | ||||||
2036 | /// | ||||||
2037 | /// This routine substitutes the given template arguments into the | ||||||
2038 | /// type T and produces the instantiated type. | ||||||
2039 | /// | ||||||
2040 | /// \param T the type into which the template arguments will be | ||||||
2041 | /// substituted. If this type is not dependent, it will be returned | ||||||
2042 | /// immediately. | ||||||
2043 | /// | ||||||
2044 | /// \param Args the template arguments that will be | ||||||
2045 | /// substituted for the top-level template parameters within T. | ||||||
2046 | /// | ||||||
2047 | /// \param Loc the location in the source code where this substitution | ||||||
2048 | /// is being performed. It will typically be the location of the | ||||||
2049 | /// declarator (if we're instantiating the type of some declaration) | ||||||
2050 | /// or the location of the type in the source code (if, e.g., we're | ||||||
2051 | /// instantiating the type of a cast expression). | ||||||
2052 | /// | ||||||
2053 | /// \param Entity the name of the entity associated with a declaration | ||||||
2054 | /// being instantiated (if any). May be empty to indicate that there | ||||||
2055 | /// is no such entity (if, e.g., this is a type that occurs as part of | ||||||
2056 | /// a cast expression) or that the entity has no name (e.g., an | ||||||
2057 | /// unnamed function parameter). | ||||||
2058 | /// | ||||||
2059 | /// \param AllowDeducedTST Whether a DeducedTemplateSpecializationType is | ||||||
2060 | /// acceptable as the top level type of the result. | ||||||
2061 | /// | ||||||
2062 | /// \returns If the instantiation succeeds, the instantiated | ||||||
2063 | /// type. Otherwise, produces diagnostics and returns a NULL type. | ||||||
2064 | TypeSourceInfo *Sema::SubstType(TypeSourceInfo *T, | ||||||
2065 | const MultiLevelTemplateArgumentList &Args, | ||||||
2066 | SourceLocation Loc, | ||||||
2067 | DeclarationName Entity, | ||||||
2068 | bool AllowDeducedTST) { | ||||||
2069 | assert(!CodeSynthesisContexts.empty() &&(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2071, __extension__ __PRETTY_FUNCTION__)) | ||||||
2070 | "Cannot perform an instantiation without some context on the "(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2071, __extension__ __PRETTY_FUNCTION__)) | ||||||
2071 | "instantiation stack")(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2071, __extension__ __PRETTY_FUNCTION__)); | ||||||
2072 | |||||||
2073 | if (!T->getType()->isInstantiationDependentType() && | ||||||
2074 | !T->getType()->isVariablyModifiedType()) | ||||||
2075 | return T; | ||||||
2076 | |||||||
2077 | TemplateInstantiator Instantiator(*this, Args, Loc, Entity); | ||||||
2078 | return AllowDeducedTST ? Instantiator.TransformTypeWithDeducedTST(T) | ||||||
2079 | : Instantiator.TransformType(T); | ||||||
2080 | } | ||||||
2081 | |||||||
2082 | TypeSourceInfo *Sema::SubstType(TypeLoc TL, | ||||||
2083 | const MultiLevelTemplateArgumentList &Args, | ||||||
2084 | SourceLocation Loc, | ||||||
2085 | DeclarationName Entity) { | ||||||
2086 | assert(!CodeSynthesisContexts.empty() &&(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2088, __extension__ __PRETTY_FUNCTION__)) | ||||||
2087 | "Cannot perform an instantiation without some context on the "(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2088, __extension__ __PRETTY_FUNCTION__)) | ||||||
2088 | "instantiation stack")(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2088, __extension__ __PRETTY_FUNCTION__)); | ||||||
2089 | |||||||
2090 | if (TL.getType().isNull()) | ||||||
2091 | return nullptr; | ||||||
2092 | |||||||
2093 | if (!TL.getType()->isInstantiationDependentType() && | ||||||
2094 | !TL.getType()->isVariablyModifiedType()) { | ||||||
2095 | // FIXME: Make a copy of the TypeLoc data here, so that we can | ||||||
2096 | // return a new TypeSourceInfo. Inefficient! | ||||||
2097 | TypeLocBuilder TLB; | ||||||
2098 | TLB.pushFullCopy(TL); | ||||||
2099 | return TLB.getTypeSourceInfo(Context, TL.getType()); | ||||||
2100 | } | ||||||
2101 | |||||||
2102 | TemplateInstantiator Instantiator(*this, Args, Loc, Entity); | ||||||
2103 | TypeLocBuilder TLB; | ||||||
2104 | TLB.reserve(TL.getFullDataSize()); | ||||||
2105 | QualType Result = Instantiator.TransformType(TLB, TL); | ||||||
2106 | if (Result.isNull()) | ||||||
2107 | return nullptr; | ||||||
2108 | |||||||
2109 | return TLB.getTypeSourceInfo(Context, Result); | ||||||
2110 | } | ||||||
2111 | |||||||
2112 | /// Deprecated form of the above. | ||||||
2113 | QualType Sema::SubstType(QualType T, | ||||||
2114 | const MultiLevelTemplateArgumentList &TemplateArgs, | ||||||
2115 | SourceLocation Loc, DeclarationName Entity) { | ||||||
2116 | assert(!CodeSynthesisContexts.empty() &&(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2118, __extension__ __PRETTY_FUNCTION__)) | ||||||
2117 | "Cannot perform an instantiation without some context on the "(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2118, __extension__ __PRETTY_FUNCTION__)) | ||||||
2118 | "instantiation stack")(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2118, __extension__ __PRETTY_FUNCTION__)); | ||||||
2119 | |||||||
2120 | // If T is not a dependent type or a variably-modified type, there | ||||||
2121 | // is nothing to do. | ||||||
2122 | if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType()) | ||||||
2123 | return T; | ||||||
2124 | |||||||
2125 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity); | ||||||
2126 | return Instantiator.TransformType(T); | ||||||
2127 | } | ||||||
2128 | |||||||
2129 | static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T) { | ||||||
2130 | if (T->getType()->isInstantiationDependentType() || | ||||||
2131 | T->getType()->isVariablyModifiedType()) | ||||||
2132 | return true; | ||||||
2133 | |||||||
2134 | TypeLoc TL = T->getTypeLoc().IgnoreParens(); | ||||||
2135 | if (!TL.getAs<FunctionProtoTypeLoc>()) | ||||||
2136 | return false; | ||||||
2137 | |||||||
2138 | FunctionProtoTypeLoc FP = TL.castAs<FunctionProtoTypeLoc>(); | ||||||
2139 | for (ParmVarDecl *P : FP.getParams()) { | ||||||
2140 | // This must be synthesized from a typedef. | ||||||
2141 | if (!P) continue; | ||||||
2142 | |||||||
2143 | // If there are any parameters, a new TypeSourceInfo that refers to the | ||||||
2144 | // instantiated parameters must be built. | ||||||
2145 | return true; | ||||||
2146 | } | ||||||
2147 | |||||||
2148 | return false; | ||||||
2149 | } | ||||||
2150 | |||||||
2151 | /// A form of SubstType intended specifically for instantiating the | ||||||
2152 | /// type of a FunctionDecl. Its purpose is solely to force the | ||||||
2153 | /// instantiation of default-argument expressions and to avoid | ||||||
2154 | /// instantiating an exception-specification. | ||||||
2155 | TypeSourceInfo *Sema::SubstFunctionDeclType(TypeSourceInfo *T, | ||||||
2156 | const MultiLevelTemplateArgumentList &Args, | ||||||
2157 | SourceLocation Loc, | ||||||
2158 | DeclarationName Entity, | ||||||
2159 | CXXRecordDecl *ThisContext, | ||||||
2160 | Qualifiers ThisTypeQuals) { | ||||||
2161 | assert(!CodeSynthesisContexts.empty() &&(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2163, __extension__ __PRETTY_FUNCTION__)) | ||||||
2162 | "Cannot perform an instantiation without some context on the "(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2163, __extension__ __PRETTY_FUNCTION__)) | ||||||
2163 | "instantiation stack")(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2163, __extension__ __PRETTY_FUNCTION__)); | ||||||
2164 | |||||||
2165 | if (!NeedsInstantiationAsFunctionType(T)) | ||||||
2166 | return T; | ||||||
2167 | |||||||
2168 | TemplateInstantiator Instantiator(*this, Args, Loc, Entity); | ||||||
2169 | |||||||
2170 | TypeLocBuilder TLB; | ||||||
2171 | |||||||
2172 | TypeLoc TL = T->getTypeLoc(); | ||||||
2173 | TLB.reserve(TL.getFullDataSize()); | ||||||
2174 | |||||||
2175 | QualType Result; | ||||||
2176 | |||||||
2177 | if (FunctionProtoTypeLoc Proto = | ||||||
2178 | TL.IgnoreParens().getAs<FunctionProtoTypeLoc>()) { | ||||||
2179 | // Instantiate the type, other than its exception specification. The | ||||||
2180 | // exception specification is instantiated in InitFunctionInstantiation | ||||||
2181 | // once we've built the FunctionDecl. | ||||||
2182 | // FIXME: Set the exception specification to EST_Uninstantiated here, | ||||||
2183 | // instead of rebuilding the function type again later. | ||||||
2184 | Result = Instantiator.TransformFunctionProtoType( | ||||||
2185 | TLB, Proto, ThisContext, ThisTypeQuals, | ||||||
2186 | [](FunctionProtoType::ExceptionSpecInfo &ESI, | ||||||
2187 | bool &Changed) { return false; }); | ||||||
2188 | } else { | ||||||
2189 | Result = Instantiator.TransformType(TLB, TL); | ||||||
2190 | } | ||||||
2191 | if (Result.isNull()) | ||||||
2192 | return nullptr; | ||||||
2193 | |||||||
2194 | return TLB.getTypeSourceInfo(Context, Result); | ||||||
2195 | } | ||||||
2196 | |||||||
2197 | bool Sema::SubstExceptionSpec(SourceLocation Loc, | ||||||
2198 | FunctionProtoType::ExceptionSpecInfo &ESI, | ||||||
2199 | SmallVectorImpl<QualType> &ExceptionStorage, | ||||||
2200 | const MultiLevelTemplateArgumentList &Args) { | ||||||
2201 | assert(ESI.Type != EST_Uninstantiated)(static_cast <bool> (ESI.Type != EST_Uninstantiated) ? void (0) : __assert_fail ("ESI.Type != EST_Uninstantiated", "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2201, __extension__ __PRETTY_FUNCTION__)); | ||||||
2202 | |||||||
2203 | bool Changed = false; | ||||||
2204 | TemplateInstantiator Instantiator(*this, Args, Loc, DeclarationName()); | ||||||
2205 | return Instantiator.TransformExceptionSpec(Loc, ESI, ExceptionStorage, | ||||||
2206 | Changed); | ||||||
2207 | } | ||||||
2208 | |||||||
2209 | void Sema::SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, | ||||||
2210 | const MultiLevelTemplateArgumentList &Args) { | ||||||
2211 | FunctionProtoType::ExceptionSpecInfo ESI = | ||||||
2212 | Proto->getExtProtoInfo().ExceptionSpec; | ||||||
2213 | |||||||
2214 | SmallVector<QualType, 4> ExceptionStorage; | ||||||
2215 | if (SubstExceptionSpec(New->getTypeSourceInfo()->getTypeLoc().getEndLoc(), | ||||||
2216 | ESI, ExceptionStorage, Args)) | ||||||
2217 | // On error, recover by dropping the exception specification. | ||||||
2218 | ESI.Type = EST_None; | ||||||
2219 | |||||||
2220 | UpdateExceptionSpec(New, ESI); | ||||||
2221 | } | ||||||
2222 | |||||||
2223 | namespace { | ||||||
2224 | |||||||
2225 | struct GetContainedInventedTypeParmVisitor : | ||||||
2226 | public TypeVisitor<GetContainedInventedTypeParmVisitor, | ||||||
2227 | TemplateTypeParmDecl *> { | ||||||
2228 | using TypeVisitor<GetContainedInventedTypeParmVisitor, | ||||||
2229 | TemplateTypeParmDecl *>::Visit; | ||||||
2230 | |||||||
2231 | TemplateTypeParmDecl *Visit(QualType T) { | ||||||
2232 | if (T.isNull()) | ||||||
2233 | return nullptr; | ||||||
2234 | return Visit(T.getTypePtr()); | ||||||
2235 | } | ||||||
2236 | // The deduced type itself. | ||||||
2237 | TemplateTypeParmDecl *VisitTemplateTypeParmType( | ||||||
2238 | const TemplateTypeParmType *T) { | ||||||
2239 | if (!T->getDecl() || !T->getDecl()->isImplicit()) | ||||||
2240 | return nullptr; | ||||||
2241 | return T->getDecl(); | ||||||
2242 | } | ||||||
2243 | |||||||
2244 | // Only these types can contain 'auto' types, and subsequently be replaced | ||||||
2245 | // by references to invented parameters. | ||||||
2246 | |||||||
2247 | TemplateTypeParmDecl *VisitElaboratedType(const ElaboratedType *T) { | ||||||
2248 | return Visit(T->getNamedType()); | ||||||
2249 | } | ||||||
2250 | |||||||
2251 | TemplateTypeParmDecl *VisitPointerType(const PointerType *T) { | ||||||
2252 | return Visit(T->getPointeeType()); | ||||||
2253 | } | ||||||
2254 | |||||||
2255 | TemplateTypeParmDecl *VisitBlockPointerType(const BlockPointerType *T) { | ||||||
2256 | return Visit(T->getPointeeType()); | ||||||
2257 | } | ||||||
2258 | |||||||
2259 | TemplateTypeParmDecl *VisitReferenceType(const ReferenceType *T) { | ||||||
2260 | return Visit(T->getPointeeTypeAsWritten()); | ||||||
2261 | } | ||||||
2262 | |||||||
2263 | TemplateTypeParmDecl *VisitMemberPointerType(const MemberPointerType *T) { | ||||||
2264 | return Visit(T->getPointeeType()); | ||||||
2265 | } | ||||||
2266 | |||||||
2267 | TemplateTypeParmDecl *VisitArrayType(const ArrayType *T) { | ||||||
2268 | return Visit(T->getElementType()); | ||||||
2269 | } | ||||||
2270 | |||||||
2271 | TemplateTypeParmDecl *VisitDependentSizedExtVectorType( | ||||||
2272 | const DependentSizedExtVectorType *T) { | ||||||
2273 | return Visit(T->getElementType()); | ||||||
2274 | } | ||||||
2275 | |||||||
2276 | TemplateTypeParmDecl *VisitVectorType(const VectorType *T) { | ||||||
2277 | return Visit(T->getElementType()); | ||||||
2278 | } | ||||||
2279 | |||||||
2280 | TemplateTypeParmDecl *VisitFunctionProtoType(const FunctionProtoType *T) { | ||||||
2281 | return VisitFunctionType(T); | ||||||
2282 | } | ||||||
2283 | |||||||
2284 | TemplateTypeParmDecl *VisitFunctionType(const FunctionType *T) { | ||||||
2285 | return Visit(T->getReturnType()); | ||||||
2286 | } | ||||||
2287 | |||||||
2288 | TemplateTypeParmDecl *VisitParenType(const ParenType *T) { | ||||||
2289 | return Visit(T->getInnerType()); | ||||||
2290 | } | ||||||
2291 | |||||||
2292 | TemplateTypeParmDecl *VisitAttributedType(const AttributedType *T) { | ||||||
2293 | return Visit(T->getModifiedType()); | ||||||
2294 | } | ||||||
2295 | |||||||
2296 | TemplateTypeParmDecl *VisitMacroQualifiedType(const MacroQualifiedType *T) { | ||||||
2297 | return Visit(T->getUnderlyingType()); | ||||||
2298 | } | ||||||
2299 | |||||||
2300 | TemplateTypeParmDecl *VisitAdjustedType(const AdjustedType *T) { | ||||||
2301 | return Visit(T->getOriginalType()); | ||||||
2302 | } | ||||||
2303 | |||||||
2304 | TemplateTypeParmDecl *VisitPackExpansionType(const PackExpansionType *T) { | ||||||
2305 | return Visit(T->getPattern()); | ||||||
2306 | } | ||||||
2307 | }; | ||||||
2308 | |||||||
2309 | } // namespace | ||||||
2310 | |||||||
2311 | ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm, | ||||||
2312 | const MultiLevelTemplateArgumentList &TemplateArgs, | ||||||
2313 | int indexAdjustment, | ||||||
2314 | Optional<unsigned> NumExpansions, | ||||||
2315 | bool ExpectParameterPack) { | ||||||
2316 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); | ||||||
2317 | TypeSourceInfo *NewDI = nullptr; | ||||||
2318 | |||||||
2319 | TypeLoc OldTL = OldDI->getTypeLoc(); | ||||||
2320 | if (PackExpansionTypeLoc ExpansionTL = OldTL.getAs<PackExpansionTypeLoc>()) { | ||||||
2321 | |||||||
2322 | // We have a function parameter pack. Substitute into the pattern of the | ||||||
2323 | // expansion. | ||||||
2324 | NewDI = SubstType(ExpansionTL.getPatternLoc(), TemplateArgs, | ||||||
2325 | OldParm->getLocation(), OldParm->getDeclName()); | ||||||
2326 | if (!NewDI) | ||||||
2327 | return nullptr; | ||||||
2328 | |||||||
2329 | if (NewDI->getType()->containsUnexpandedParameterPack()) { | ||||||
2330 | // We still have unexpanded parameter packs, which means that | ||||||
2331 | // our function parameter is still a function parameter pack. | ||||||
2332 | // Therefore, make its type a pack expansion type. | ||||||
2333 | NewDI = CheckPackExpansion(NewDI, ExpansionTL.getEllipsisLoc(), | ||||||
2334 | NumExpansions); | ||||||
2335 | } else if (ExpectParameterPack) { | ||||||
2336 | // We expected to get a parameter pack but didn't (because the type | ||||||
2337 | // itself is not a pack expansion type), so complain. This can occur when | ||||||
2338 | // the substitution goes through an alias template that "loses" the | ||||||
2339 | // pack expansion. | ||||||
2340 | Diag(OldParm->getLocation(), | ||||||
2341 | diag::err_function_parameter_pack_without_parameter_packs) | ||||||
2342 | << NewDI->getType(); | ||||||
2343 | return nullptr; | ||||||
2344 | } | ||||||
2345 | } else { | ||||||
2346 | NewDI = SubstType(OldDI, TemplateArgs, OldParm->getLocation(), | ||||||
2347 | OldParm->getDeclName()); | ||||||
2348 | } | ||||||
2349 | |||||||
2350 | if (!NewDI) | ||||||
2351 | return nullptr; | ||||||
2352 | |||||||
2353 | if (NewDI->getType()->isVoidType()) { | ||||||
2354 | Diag(OldParm->getLocation(), diag::err_param_with_void_type); | ||||||
2355 | return nullptr; | ||||||
2356 | } | ||||||
2357 | |||||||
2358 | // In abbreviated templates, TemplateTypeParmDecls with possible | ||||||
2359 | // TypeConstraints are created when the parameter list is originally parsed. | ||||||
2360 | // The TypeConstraints can therefore reference other functions parameters in | ||||||
2361 | // the abbreviated function template, which is why we must instantiate them | ||||||
2362 | // here, when the instantiated versions of those referenced parameters are in | ||||||
2363 | // scope. | ||||||
2364 | if (TemplateTypeParmDecl *TTP = | ||||||
2365 | GetContainedInventedTypeParmVisitor().Visit(OldDI->getType())) { | ||||||
2366 | if (const TypeConstraint *TC = TTP->getTypeConstraint()) { | ||||||
2367 | auto *Inst = cast_or_null<TemplateTypeParmDecl>( | ||||||
2368 | FindInstantiatedDecl(TTP->getLocation(), TTP, TemplateArgs)); | ||||||
2369 | // We will first get here when instantiating the abbreviated function | ||||||
2370 | // template's described function, but we might also get here later. | ||||||
2371 | // Make sure we do not instantiate the TypeConstraint more than once. | ||||||
2372 | if (Inst && !Inst->getTypeConstraint()) { | ||||||
2373 | // TODO: Concepts: do not instantiate the constraint (delayed constraint | ||||||
2374 | // substitution) | ||||||
2375 | const ASTTemplateArgumentListInfo *TemplArgInfo | ||||||
2376 | = TC->getTemplateArgsAsWritten(); | ||||||
2377 | TemplateArgumentListInfo InstArgs; | ||||||
2378 | |||||||
2379 | if (TemplArgInfo) { | ||||||
2380 | InstArgs.setLAngleLoc(TemplArgInfo->LAngleLoc); | ||||||
2381 | InstArgs.setRAngleLoc(TemplArgInfo->RAngleLoc); | ||||||
2382 | if (Subst(TemplArgInfo->getTemplateArgs(), | ||||||
2383 | TemplArgInfo->NumTemplateArgs, InstArgs, TemplateArgs)) | ||||||
2384 | return nullptr; | ||||||
2385 | } | ||||||
2386 | if (AttachTypeConstraint( | ||||||
2387 | TC->getNestedNameSpecifierLoc(), TC->getConceptNameInfo(), | ||||||
2388 | TC->getNamedConcept(), TemplArgInfo ? &InstArgs : nullptr, Inst, | ||||||
2389 | TTP->isParameterPack() | ||||||
2390 | ? cast<CXXFoldExpr>(TC->getImmediatelyDeclaredConstraint()) | ||||||
2391 | ->getEllipsisLoc() | ||||||
2392 | : SourceLocation())) | ||||||
2393 | return nullptr; | ||||||
2394 | } | ||||||
2395 | } | ||||||
2396 | } | ||||||
2397 | |||||||
2398 | ParmVarDecl *NewParm = CheckParameter(Context.getTranslationUnitDecl(), | ||||||
2399 | OldParm->getInnerLocStart(), | ||||||
2400 | OldParm->getLocation(), | ||||||
2401 | OldParm->getIdentifier(), | ||||||
2402 | NewDI->getType(), NewDI, | ||||||
2403 | OldParm->getStorageClass()); | ||||||
2404 | if (!NewParm) | ||||||
2405 | return nullptr; | ||||||
2406 | |||||||
2407 | // Mark the (new) default argument as uninstantiated (if any). | ||||||
2408 | if (OldParm->hasUninstantiatedDefaultArg()) { | ||||||
2409 | Expr *Arg = OldParm->getUninstantiatedDefaultArg(); | ||||||
2410 | NewParm->setUninstantiatedDefaultArg(Arg); | ||||||
2411 | } else if (OldParm->hasUnparsedDefaultArg()) { | ||||||
2412 | NewParm->setUnparsedDefaultArg(); | ||||||
2413 | UnparsedDefaultArgInstantiations[OldParm].push_back(NewParm); | ||||||
2414 | } else if (Expr *Arg = OldParm->getDefaultArg()) { | ||||||
2415 | FunctionDecl *OwningFunc = cast<FunctionDecl>(OldParm->getDeclContext()); | ||||||
2416 | if (OwningFunc->isInLocalScopeForInstantiation()) { | ||||||
2417 | // Instantiate default arguments for methods of local classes (DR1484) | ||||||
2418 | // and non-defining declarations. | ||||||
2419 | Sema::ContextRAII SavedContext(*this, OwningFunc); | ||||||
2420 | LocalInstantiationScope Local(*this, true); | ||||||
2421 | ExprResult NewArg = SubstExpr(Arg, TemplateArgs); | ||||||
2422 | if (NewArg.isUsable()) { | ||||||
2423 | // It would be nice if we still had this. | ||||||
2424 | SourceLocation EqualLoc = NewArg.get()->getBeginLoc(); | ||||||
2425 | ExprResult Result = | ||||||
2426 | ConvertParamDefaultArgument(NewParm, NewArg.get(), EqualLoc); | ||||||
2427 | if (Result.isInvalid()) | ||||||
2428 | return nullptr; | ||||||
2429 | |||||||
2430 | SetParamDefaultArgument(NewParm, Result.getAs<Expr>(), EqualLoc); | ||||||
2431 | } | ||||||
2432 | } else { | ||||||
2433 | // FIXME: if we non-lazily instantiated non-dependent default args for | ||||||
2434 | // non-dependent parameter types we could remove a bunch of duplicate | ||||||
2435 | // conversion warnings for such arguments. | ||||||
2436 | NewParm->setUninstantiatedDefaultArg(Arg); | ||||||
2437 | } | ||||||
2438 | } | ||||||
2439 | |||||||
2440 | NewParm->setHasInheritedDefaultArg(OldParm->hasInheritedDefaultArg()); | ||||||
2441 | |||||||
2442 | if (OldParm->isParameterPack() && !NewParm->isParameterPack()) { | ||||||
2443 | // Add the new parameter to the instantiated parameter pack. | ||||||
2444 | CurrentInstantiationScope->InstantiatedLocalPackArg(OldParm, NewParm); | ||||||
2445 | } else { | ||||||
2446 | // Introduce an Old -> New mapping | ||||||
2447 | CurrentInstantiationScope->InstantiatedLocal(OldParm, NewParm); | ||||||
2448 | } | ||||||
2449 | |||||||
2450 | // FIXME: OldParm may come from a FunctionProtoType, in which case CurContext | ||||||
2451 | // can be anything, is this right ? | ||||||
2452 | NewParm->setDeclContext(CurContext); | ||||||
2453 | |||||||
2454 | NewParm->setScopeInfo(OldParm->getFunctionScopeDepth(), | ||||||
2455 | OldParm->getFunctionScopeIndex() + indexAdjustment); | ||||||
2456 | |||||||
2457 | InstantiateAttrs(TemplateArgs, OldParm, NewParm); | ||||||
2458 | |||||||
2459 | return NewParm; | ||||||
2460 | } | ||||||
2461 | |||||||
2462 | /// Substitute the given template arguments into the given set of | ||||||
2463 | /// parameters, producing the set of parameter types that would be generated | ||||||
2464 | /// from such a substitution. | ||||||
2465 | bool Sema::SubstParmTypes( | ||||||
2466 | SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, | ||||||
2467 | const FunctionProtoType::ExtParameterInfo *ExtParamInfos, | ||||||
2468 | const MultiLevelTemplateArgumentList &TemplateArgs, | ||||||
2469 | SmallVectorImpl<QualType> &ParamTypes, | ||||||
2470 | SmallVectorImpl<ParmVarDecl *> *OutParams, | ||||||
2471 | ExtParameterInfoBuilder &ParamInfos) { | ||||||
2472 | assert(!CodeSynthesisContexts.empty() &&(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2474, __extension__ __PRETTY_FUNCTION__)) | ||||||
2473 | "Cannot perform an instantiation without some context on the "(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2474, __extension__ __PRETTY_FUNCTION__)) | ||||||
2474 | "instantiation stack")(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2474, __extension__ __PRETTY_FUNCTION__)); | ||||||
2475 | |||||||
2476 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, | ||||||
2477 | DeclarationName()); | ||||||
2478 | return Instantiator.TransformFunctionTypeParams( | ||||||
2479 | Loc, Params, nullptr, ExtParamInfos, ParamTypes, OutParams, ParamInfos); | ||||||
2480 | } | ||||||
2481 | |||||||
2482 | /// Perform substitution on the base class specifiers of the | ||||||
2483 | /// given class template specialization. | ||||||
2484 | /// | ||||||
2485 | /// Produces a diagnostic and returns true on error, returns false and | ||||||
2486 | /// attaches the instantiated base classes to the class template | ||||||
2487 | /// specialization if successful. | ||||||
2488 | bool | ||||||
2489 | Sema::SubstBaseSpecifiers(CXXRecordDecl *Instantiation, | ||||||
2490 | CXXRecordDecl *Pattern, | ||||||
2491 | const MultiLevelTemplateArgumentList &TemplateArgs) { | ||||||
2492 | bool Invalid = false; | ||||||
2493 | SmallVector<CXXBaseSpecifier*, 4> InstantiatedBases; | ||||||
2494 | for (const auto &Base : Pattern->bases()) { | ||||||
2495 | if (!Base.getType()->isDependentType()) { | ||||||
2496 | if (const CXXRecordDecl *RD = Base.getType()->getAsCXXRecordDecl()) { | ||||||
2497 | if (RD->isInvalidDecl()) | ||||||
2498 | Instantiation->setInvalidDecl(); | ||||||
2499 | } | ||||||
2500 | InstantiatedBases.push_back(new (Context) CXXBaseSpecifier(Base)); | ||||||
2501 | continue; | ||||||
2502 | } | ||||||
2503 | |||||||
2504 | SourceLocation EllipsisLoc; | ||||||
2505 | TypeSourceInfo *BaseTypeLoc; | ||||||
2506 | if (Base.isPackExpansion()) { | ||||||
2507 | // This is a pack expansion. See whether we should expand it now, or | ||||||
2508 | // wait until later. | ||||||
2509 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; | ||||||
2510 | collectUnexpandedParameterPacks(Base.getTypeSourceInfo()->getTypeLoc(), | ||||||
2511 | Unexpanded); | ||||||
2512 | bool ShouldExpand = false; | ||||||
2513 | bool RetainExpansion = false; | ||||||
2514 | Optional<unsigned> NumExpansions; | ||||||
2515 | if (CheckParameterPacksForExpansion(Base.getEllipsisLoc(), | ||||||
2516 | Base.getSourceRange(), | ||||||
2517 | Unexpanded, | ||||||
2518 | TemplateArgs, ShouldExpand, | ||||||
2519 | RetainExpansion, | ||||||
2520 | NumExpansions)) { | ||||||
2521 | Invalid = true; | ||||||
2522 | continue; | ||||||
2523 | } | ||||||
2524 | |||||||
2525 | // If we should expand this pack expansion now, do so. | ||||||
2526 | if (ShouldExpand) { | ||||||
2527 | for (unsigned I = 0; I != *NumExpansions; ++I) { | ||||||
2528 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, I); | ||||||
2529 | |||||||
2530 | TypeSourceInfo *BaseTypeLoc = SubstType(Base.getTypeSourceInfo(), | ||||||
2531 | TemplateArgs, | ||||||
2532 | Base.getSourceRange().getBegin(), | ||||||
2533 | DeclarationName()); | ||||||
2534 | if (!BaseTypeLoc) { | ||||||
2535 | Invalid = true; | ||||||
2536 | continue; | ||||||
2537 | } | ||||||
2538 | |||||||
2539 | if (CXXBaseSpecifier *InstantiatedBase | ||||||
2540 | = CheckBaseSpecifier(Instantiation, | ||||||
2541 | Base.getSourceRange(), | ||||||
2542 | Base.isVirtual(), | ||||||
2543 | Base.getAccessSpecifierAsWritten(), | ||||||
2544 | BaseTypeLoc, | ||||||
2545 | SourceLocation())) | ||||||
2546 | InstantiatedBases.push_back(InstantiatedBase); | ||||||
2547 | else | ||||||
2548 | Invalid = true; | ||||||
2549 | } | ||||||
2550 | |||||||
2551 | continue; | ||||||
2552 | } | ||||||
2553 | |||||||
2554 | // The resulting base specifier will (still) be a pack expansion. | ||||||
2555 | EllipsisLoc = Base.getEllipsisLoc(); | ||||||
2556 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, -1); | ||||||
2557 | BaseTypeLoc = SubstType(Base.getTypeSourceInfo(), | ||||||
2558 | TemplateArgs, | ||||||
2559 | Base.getSourceRange().getBegin(), | ||||||
2560 | DeclarationName()); | ||||||
2561 | } else { | ||||||
2562 | BaseTypeLoc = SubstType(Base.getTypeSourceInfo(), | ||||||
2563 | TemplateArgs, | ||||||
2564 | Base.getSourceRange().getBegin(), | ||||||
2565 | DeclarationName()); | ||||||
2566 | } | ||||||
2567 | |||||||
2568 | if (!BaseTypeLoc) { | ||||||
2569 | Invalid = true; | ||||||
2570 | continue; | ||||||
2571 | } | ||||||
2572 | |||||||
2573 | if (CXXBaseSpecifier *InstantiatedBase | ||||||
2574 | = CheckBaseSpecifier(Instantiation, | ||||||
2575 | Base.getSourceRange(), | ||||||
2576 | Base.isVirtual(), | ||||||
2577 | Base.getAccessSpecifierAsWritten(), | ||||||
2578 | BaseTypeLoc, | ||||||
2579 | EllipsisLoc)) | ||||||
2580 | InstantiatedBases.push_back(InstantiatedBase); | ||||||
2581 | else | ||||||
2582 | Invalid = true; | ||||||
2583 | } | ||||||
2584 | |||||||
2585 | if (!Invalid && AttachBaseSpecifiers(Instantiation, InstantiatedBases)) | ||||||
2586 | Invalid = true; | ||||||
2587 | |||||||
2588 | return Invalid; | ||||||
2589 | } | ||||||
2590 | |||||||
2591 | // Defined via #include from SemaTemplateInstantiateDecl.cpp | ||||||
2592 | namespace clang { | ||||||
2593 | namespace sema { | ||||||
2594 | Attr *instantiateTemplateAttribute(const Attr *At, ASTContext &C, Sema &S, | ||||||
2595 | const MultiLevelTemplateArgumentList &TemplateArgs); | ||||||
2596 | Attr *instantiateTemplateAttributeForDecl( | ||||||
2597 | const Attr *At, ASTContext &C, Sema &S, | ||||||
2598 | const MultiLevelTemplateArgumentList &TemplateArgs); | ||||||
2599 | } | ||||||
2600 | } | ||||||
2601 | |||||||
2602 | /// Instantiate the definition of a class from a given pattern. | ||||||
2603 | /// | ||||||
2604 | /// \param PointOfInstantiation The point of instantiation within the | ||||||
2605 | /// source code. | ||||||
2606 | /// | ||||||
2607 | /// \param Instantiation is the declaration whose definition is being | ||||||
2608 | /// instantiated. This will be either a class template specialization | ||||||
2609 | /// or a member class of a class template specialization. | ||||||
2610 | /// | ||||||
2611 | /// \param Pattern is the pattern from which the instantiation | ||||||
2612 | /// occurs. This will be either the declaration of a class template or | ||||||
2613 | /// the declaration of a member class of a class template. | ||||||
2614 | /// | ||||||
2615 | /// \param TemplateArgs The template arguments to be substituted into | ||||||
2616 | /// the pattern. | ||||||
2617 | /// | ||||||
2618 | /// \param TSK the kind of implicit or explicit instantiation to perform. | ||||||
2619 | /// | ||||||
2620 | /// \param Complain whether to complain if the class cannot be instantiated due | ||||||
2621 | /// to the lack of a definition. | ||||||
2622 | /// | ||||||
2623 | /// \returns true if an error occurred, false otherwise. | ||||||
2624 | bool | ||||||
2625 | Sema::InstantiateClass(SourceLocation PointOfInstantiation, | ||||||
2626 | CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, | ||||||
2627 | const MultiLevelTemplateArgumentList &TemplateArgs, | ||||||
2628 | TemplateSpecializationKind TSK, | ||||||
2629 | bool Complain) { | ||||||
2630 | CXXRecordDecl *PatternDef | ||||||
2631 | = cast_or_null<CXXRecordDecl>(Pattern->getDefinition()); | ||||||
2632 | if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Instantiation, | ||||||
2633 | Instantiation->getInstantiatedFromMemberClass(), | ||||||
2634 | Pattern, PatternDef, TSK, Complain)) | ||||||
2635 | return true; | ||||||
2636 | |||||||
2637 | llvm::TimeTraceScope TimeScope("InstantiateClass", [&]() { | ||||||
2638 | std::string Name; | ||||||
2639 | llvm::raw_string_ostream OS(Name); | ||||||
2640 | Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(), | ||||||
2641 | /*Qualified=*/true); | ||||||
2642 | return Name; | ||||||
2643 | }); | ||||||
2644 | |||||||
2645 | Pattern = PatternDef; | ||||||
2646 | |||||||
2647 | // Record the point of instantiation. | ||||||
2648 | if (MemberSpecializationInfo *MSInfo | ||||||
2649 | = Instantiation->getMemberSpecializationInfo()) { | ||||||
2650 | MSInfo->setTemplateSpecializationKind(TSK); | ||||||
2651 | MSInfo->setPointOfInstantiation(PointOfInstantiation); | ||||||
2652 | } else if (ClassTemplateSpecializationDecl *Spec | ||||||
2653 | = dyn_cast<ClassTemplateSpecializationDecl>(Instantiation)) { | ||||||
2654 | Spec->setTemplateSpecializationKind(TSK); | ||||||
2655 | Spec->setPointOfInstantiation(PointOfInstantiation); | ||||||
2656 | } | ||||||
2657 | |||||||
2658 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation); | ||||||
2659 | if (Inst.isInvalid()) | ||||||
2660 | return true; | ||||||
2661 | assert(!Inst.isAlreadyInstantiating() && "should have been caught by caller")(static_cast <bool> (!Inst.isAlreadyInstantiating() && "should have been caught by caller") ? void (0) : __assert_fail ("!Inst.isAlreadyInstantiating() && \"should have been caught by caller\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2661, __extension__ __PRETTY_FUNCTION__)); | ||||||
2662 | PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(), | ||||||
2663 | "instantiating class definition"); | ||||||
2664 | |||||||
2665 | // Enter the scope of this instantiation. We don't use | ||||||
2666 | // PushDeclContext because we don't have a scope. | ||||||
2667 | ContextRAII SavedContext(*this, Instantiation); | ||||||
2668 | EnterExpressionEvaluationContext EvalContext( | ||||||
2669 | *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); | ||||||
2670 | |||||||
2671 | // If this is an instantiation of a local class, merge this local | ||||||
2672 | // instantiation scope with the enclosing scope. Otherwise, every | ||||||
2673 | // instantiation of a class has its own local instantiation scope. | ||||||
2674 | bool MergeWithParentScope = !Instantiation->isDefinedOutsideFunctionOrMethod(); | ||||||
2675 | LocalInstantiationScope Scope(*this, MergeWithParentScope); | ||||||
2676 | |||||||
2677 | // Some class state isn't processed immediately but delayed till class | ||||||
2678 | // instantiation completes. We may not be ready to handle any delayed state | ||||||
2679 | // already on the stack as it might correspond to a different class, so save | ||||||
2680 | // it now and put it back later. | ||||||
2681 | SavePendingParsedClassStateRAII SavedPendingParsedClassState(*this); | ||||||
2682 | |||||||
2683 | // Pull attributes from the pattern onto the instantiation. | ||||||
2684 | InstantiateAttrs(TemplateArgs, Pattern, Instantiation); | ||||||
2685 | |||||||
2686 | // Start the definition of this instantiation. | ||||||
2687 | Instantiation->startDefinition(); | ||||||
2688 | |||||||
2689 | // The instantiation is visible here, even if it was first declared in an | ||||||
2690 | // unimported module. | ||||||
2691 | Instantiation->setVisibleDespiteOwningModule(); | ||||||
2692 | |||||||
2693 | // FIXME: This loses the as-written tag kind for an explicit instantiation. | ||||||
2694 | Instantiation->setTagKind(Pattern->getTagKind()); | ||||||
2695 | |||||||
2696 | // Do substitution on the base class specifiers. | ||||||
2697 | if (SubstBaseSpecifiers(Instantiation, Pattern, TemplateArgs)) | ||||||
2698 | Instantiation->setInvalidDecl(); | ||||||
2699 | |||||||
2700 | TemplateDeclInstantiator Instantiator(*this, Instantiation, TemplateArgs); | ||||||
2701 | SmallVector<Decl*, 4> Fields; | ||||||
2702 | // Delay instantiation of late parsed attributes. | ||||||
2703 | LateInstantiatedAttrVec LateAttrs; | ||||||
2704 | Instantiator.enableLateAttributeInstantiation(&LateAttrs); | ||||||
2705 | |||||||
2706 | bool MightHaveConstexprVirtualFunctions = false; | ||||||
2707 | for (auto *Member : Pattern->decls()) { | ||||||
2708 | // Don't instantiate members not belonging in this semantic context. | ||||||
2709 | // e.g. for: | ||||||
2710 | // @code | ||||||
2711 | // template <int i> class A { | ||||||
2712 | // class B *g; | ||||||
2713 | // }; | ||||||
2714 | // @endcode | ||||||
2715 | // 'class B' has the template as lexical context but semantically it is | ||||||
2716 | // introduced in namespace scope. | ||||||
2717 | if (Member->getDeclContext() != Pattern) | ||||||
2718 | continue; | ||||||
2719 | |||||||
2720 | // BlockDecls can appear in a default-member-initializer. They must be the | ||||||
2721 | // child of a BlockExpr, so we only know how to instantiate them from there. | ||||||
2722 | // Similarly, lambda closure types are recreated when instantiating the | ||||||
2723 | // corresponding LambdaExpr. | ||||||
2724 | if (isa<BlockDecl>(Member) || | ||||||
2725 | (isa<CXXRecordDecl>(Member) && cast<CXXRecordDecl>(Member)->isLambda())) | ||||||
2726 | continue; | ||||||
2727 | |||||||
2728 | if (Member->isInvalidDecl()) { | ||||||
2729 | Instantiation->setInvalidDecl(); | ||||||
2730 | continue; | ||||||
2731 | } | ||||||
2732 | |||||||
2733 | Decl *NewMember = Instantiator.Visit(Member); | ||||||
2734 | if (NewMember) { | ||||||
2735 | if (FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) { | ||||||
2736 | Fields.push_back(Field); | ||||||
2737 | } else if (EnumDecl *Enum = dyn_cast<EnumDecl>(NewMember)) { | ||||||
2738 | // C++11 [temp.inst]p1: The implicit instantiation of a class template | ||||||
2739 | // specialization causes the implicit instantiation of the definitions | ||||||
2740 | // of unscoped member enumerations. | ||||||
2741 | // Record a point of instantiation for this implicit instantiation. | ||||||
2742 | if (TSK == TSK_ImplicitInstantiation && !Enum->isScoped() && | ||||||
2743 | Enum->isCompleteDefinition()) { | ||||||
2744 | MemberSpecializationInfo *MSInfo =Enum->getMemberSpecializationInfo(); | ||||||
2745 | assert(MSInfo && "no spec info for member enum specialization")(static_cast <bool> (MSInfo && "no spec info for member enum specialization" ) ? void (0) : __assert_fail ("MSInfo && \"no spec info for member enum specialization\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2745, __extension__ __PRETTY_FUNCTION__)); | ||||||
2746 | MSInfo->setTemplateSpecializationKind(TSK_ImplicitInstantiation); | ||||||
2747 | MSInfo->setPointOfInstantiation(PointOfInstantiation); | ||||||
2748 | } | ||||||
2749 | } else if (StaticAssertDecl *SA = dyn_cast<StaticAssertDecl>(NewMember)) { | ||||||
2750 | if (SA->isFailed()) { | ||||||
2751 | // A static_assert failed. Bail out; instantiating this | ||||||
2752 | // class is probably not meaningful. | ||||||
2753 | Instantiation->setInvalidDecl(); | ||||||
2754 | break; | ||||||
2755 | } | ||||||
2756 | } else if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewMember)) { | ||||||
2757 | if (MD->isConstexpr() && !MD->getFriendObjectKind() && | ||||||
2758 | (MD->isVirtualAsWritten() || Instantiation->getNumBases())) | ||||||
2759 | MightHaveConstexprVirtualFunctions = true; | ||||||
2760 | } | ||||||
2761 | |||||||
2762 | if (NewMember->isInvalidDecl()) | ||||||
2763 | Instantiation->setInvalidDecl(); | ||||||
2764 | } else { | ||||||
2765 | // FIXME: Eventually, a NULL return will mean that one of the | ||||||
2766 | // instantiations was a semantic disaster, and we'll want to mark the | ||||||
2767 | // declaration invalid. | ||||||
2768 | // For now, we expect to skip some members that we can't yet handle. | ||||||
2769 | } | ||||||
2770 | } | ||||||
2771 | |||||||
2772 | // Finish checking fields. | ||||||
2773 | ActOnFields(nullptr, Instantiation->getLocation(), Instantiation, Fields, | ||||||
2774 | SourceLocation(), SourceLocation(), ParsedAttributesView()); | ||||||
2775 | CheckCompletedCXXClass(nullptr, Instantiation); | ||||||
2776 | |||||||
2777 | // Default arguments are parsed, if not instantiated. We can go instantiate | ||||||
2778 | // default arg exprs for default constructors if necessary now. Unless we're | ||||||
2779 | // parsing a class, in which case wait until that's finished. | ||||||
2780 | if (ParsingClassDepth == 0) | ||||||
2781 | ActOnFinishCXXNonNestedClass(); | ||||||
2782 | |||||||
2783 | // Instantiate late parsed attributes, and attach them to their decls. | ||||||
2784 | // See Sema::InstantiateAttrs | ||||||
2785 | for (LateInstantiatedAttrVec::iterator I = LateAttrs.begin(), | ||||||
2786 | E = LateAttrs.end(); I != E; ++I) { | ||||||
2787 | assert(CurrentInstantiationScope == Instantiator.getStartingScope())(static_cast <bool> (CurrentInstantiationScope == Instantiator .getStartingScope()) ? void (0) : __assert_fail ("CurrentInstantiationScope == Instantiator.getStartingScope()" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2787, __extension__ __PRETTY_FUNCTION__)); | ||||||
2788 | CurrentInstantiationScope = I->Scope; | ||||||
2789 | |||||||
2790 | // Allow 'this' within late-parsed attributes. | ||||||
2791 | NamedDecl *ND = dyn_cast<NamedDecl>(I->NewDecl); | ||||||
2792 | CXXRecordDecl *ThisContext = | ||||||
2793 | dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext()); | ||||||
2794 | CXXThisScopeRAII ThisScope(*this, ThisContext, Qualifiers(), | ||||||
2795 | ND && ND->isCXXInstanceMember()); | ||||||
2796 | |||||||
2797 | Attr *NewAttr = | ||||||
2798 | instantiateTemplateAttribute(I->TmplAttr, Context, *this, TemplateArgs); | ||||||
2799 | if (NewAttr) | ||||||
2800 | I->NewDecl->addAttr(NewAttr); | ||||||
2801 | LocalInstantiationScope::deleteScopes(I->Scope, | ||||||
2802 | Instantiator.getStartingScope()); | ||||||
2803 | } | ||||||
2804 | Instantiator.disableLateAttributeInstantiation(); | ||||||
2805 | LateAttrs.clear(); | ||||||
2806 | |||||||
2807 | ActOnFinishDelayedMemberInitializers(Instantiation); | ||||||
2808 | |||||||
2809 | // FIXME: We should do something similar for explicit instantiations so they | ||||||
2810 | // end up in the right module. | ||||||
2811 | if (TSK == TSK_ImplicitInstantiation) { | ||||||
2812 | Instantiation->setLocation(Pattern->getLocation()); | ||||||
2813 | Instantiation->setLocStart(Pattern->getInnerLocStart()); | ||||||
2814 | Instantiation->setBraceRange(Pattern->getBraceRange()); | ||||||
2815 | } | ||||||
2816 | |||||||
2817 | if (!Instantiation->isInvalidDecl()) { | ||||||
2818 | // Perform any dependent diagnostics from the pattern. | ||||||
2819 | if (Pattern->isDependentContext()) | ||||||
2820 | PerformDependentDiagnostics(Pattern, TemplateArgs); | ||||||
2821 | |||||||
2822 | // Instantiate any out-of-line class template partial | ||||||
2823 | // specializations now. | ||||||
2824 | for (TemplateDeclInstantiator::delayed_partial_spec_iterator | ||||||
2825 | P = Instantiator.delayed_partial_spec_begin(), | ||||||
2826 | PEnd = Instantiator.delayed_partial_spec_end(); | ||||||
2827 | P != PEnd; ++P) { | ||||||
2828 | if (!Instantiator.InstantiateClassTemplatePartialSpecialization( | ||||||
2829 | P->first, P->second)) { | ||||||
2830 | Instantiation->setInvalidDecl(); | ||||||
2831 | break; | ||||||
2832 | } | ||||||
2833 | } | ||||||
2834 | |||||||
2835 | // Instantiate any out-of-line variable template partial | ||||||
2836 | // specializations now. | ||||||
2837 | for (TemplateDeclInstantiator::delayed_var_partial_spec_iterator | ||||||
2838 | P = Instantiator.delayed_var_partial_spec_begin(), | ||||||
2839 | PEnd = Instantiator.delayed_var_partial_spec_end(); | ||||||
2840 | P != PEnd; ++P) { | ||||||
2841 | if (!Instantiator.InstantiateVarTemplatePartialSpecialization( | ||||||
2842 | P->first, P->second)) { | ||||||
2843 | Instantiation->setInvalidDecl(); | ||||||
2844 | break; | ||||||
2845 | } | ||||||
2846 | } | ||||||
2847 | } | ||||||
2848 | |||||||
2849 | // Exit the scope of this instantiation. | ||||||
2850 | SavedContext.pop(); | ||||||
2851 | |||||||
2852 | if (!Instantiation->isInvalidDecl()) { | ||||||
2853 | // Always emit the vtable for an explicit instantiation definition | ||||||
2854 | // of a polymorphic class template specialization. Otherwise, eagerly | ||||||
2855 | // instantiate only constexpr virtual functions in preparation for their use | ||||||
2856 | // in constant evaluation. | ||||||
2857 | if (TSK == TSK_ExplicitInstantiationDefinition) | ||||||
2858 | MarkVTableUsed(PointOfInstantiation, Instantiation, true); | ||||||
2859 | else if (MightHaveConstexprVirtualFunctions) | ||||||
2860 | MarkVirtualMembersReferenced(PointOfInstantiation, Instantiation, | ||||||
2861 | /*ConstexprOnly*/ true); | ||||||
2862 | } | ||||||
2863 | |||||||
2864 | Consumer.HandleTagDeclDefinition(Instantiation); | ||||||
2865 | |||||||
2866 | return Instantiation->isInvalidDecl(); | ||||||
2867 | } | ||||||
2868 | |||||||
2869 | /// Instantiate the definition of an enum from a given pattern. | ||||||
2870 | /// | ||||||
2871 | /// \param PointOfInstantiation The point of instantiation within the | ||||||
2872 | /// source code. | ||||||
2873 | /// \param Instantiation is the declaration whose definition is being | ||||||
2874 | /// instantiated. This will be a member enumeration of a class | ||||||
2875 | /// temploid specialization, or a local enumeration within a | ||||||
2876 | /// function temploid specialization. | ||||||
2877 | /// \param Pattern The templated declaration from which the instantiation | ||||||
2878 | /// occurs. | ||||||
2879 | /// \param TemplateArgs The template arguments to be substituted into | ||||||
2880 | /// the pattern. | ||||||
2881 | /// \param TSK The kind of implicit or explicit instantiation to perform. | ||||||
2882 | /// | ||||||
2883 | /// \return \c true if an error occurred, \c false otherwise. | ||||||
2884 | bool Sema::InstantiateEnum(SourceLocation PointOfInstantiation, | ||||||
2885 | EnumDecl *Instantiation, EnumDecl *Pattern, | ||||||
2886 | const MultiLevelTemplateArgumentList &TemplateArgs, | ||||||
2887 | TemplateSpecializationKind TSK) { | ||||||
2888 | EnumDecl *PatternDef = Pattern->getDefinition(); | ||||||
2889 | if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Instantiation, | ||||||
2890 | Instantiation->getInstantiatedFromMemberEnum(), | ||||||
2891 | Pattern, PatternDef, TSK,/*Complain*/true)) | ||||||
2892 | return true; | ||||||
2893 | Pattern = PatternDef; | ||||||
2894 | |||||||
2895 | // Record the point of instantiation. | ||||||
2896 | if (MemberSpecializationInfo *MSInfo | ||||||
2897 | = Instantiation->getMemberSpecializationInfo()) { | ||||||
2898 | MSInfo->setTemplateSpecializationKind(TSK); | ||||||
2899 | MSInfo->setPointOfInstantiation(PointOfInstantiation); | ||||||
2900 | } | ||||||
2901 | |||||||
2902 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation); | ||||||
2903 | if (Inst.isInvalid()) | ||||||
2904 | return true; | ||||||
2905 | if (Inst.isAlreadyInstantiating()) | ||||||
2906 | return false; | ||||||
2907 | PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(), | ||||||
2908 | "instantiating enum definition"); | ||||||
2909 | |||||||
2910 | // The instantiation is visible here, even if it was first declared in an | ||||||
2911 | // unimported module. | ||||||
2912 | Instantiation->setVisibleDespiteOwningModule(); | ||||||
2913 | |||||||
2914 | // Enter the scope of this instantiation. We don't use | ||||||
2915 | // PushDeclContext because we don't have a scope. | ||||||
2916 | ContextRAII SavedContext(*this, Instantiation); | ||||||
2917 | EnterExpressionEvaluationContext EvalContext( | ||||||
2918 | *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); | ||||||
2919 | |||||||
2920 | LocalInstantiationScope Scope(*this, /*MergeWithParentScope*/true); | ||||||
2921 | |||||||
2922 | // Pull attributes from the pattern onto the instantiation. | ||||||
2923 | InstantiateAttrs(TemplateArgs, Pattern, Instantiation); | ||||||
2924 | |||||||
2925 | TemplateDeclInstantiator Instantiator(*this, Instantiation, TemplateArgs); | ||||||
2926 | Instantiator.InstantiateEnumDefinition(Instantiation, Pattern); | ||||||
2927 | |||||||
2928 | // Exit the scope of this instantiation. | ||||||
2929 | SavedContext.pop(); | ||||||
2930 | |||||||
2931 | return Instantiation->isInvalidDecl(); | ||||||
2932 | } | ||||||
2933 | |||||||
2934 | |||||||
2935 | /// Instantiate the definition of a field from the given pattern. | ||||||
2936 | /// | ||||||
2937 | /// \param PointOfInstantiation The point of instantiation within the | ||||||
2938 | /// source code. | ||||||
2939 | /// \param Instantiation is the declaration whose definition is being | ||||||
2940 | /// instantiated. This will be a class of a class temploid | ||||||
2941 | /// specialization, or a local enumeration within a function temploid | ||||||
2942 | /// specialization. | ||||||
2943 | /// \param Pattern The templated declaration from which the instantiation | ||||||
2944 | /// occurs. | ||||||
2945 | /// \param TemplateArgs The template arguments to be substituted into | ||||||
2946 | /// the pattern. | ||||||
2947 | /// | ||||||
2948 | /// \return \c true if an error occurred, \c false otherwise. | ||||||
2949 | bool Sema::InstantiateInClassInitializer( | ||||||
2950 | SourceLocation PointOfInstantiation, FieldDecl *Instantiation, | ||||||
2951 | FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs) { | ||||||
2952 | // If there is no initializer, we don't need to do anything. | ||||||
2953 | if (!Pattern->hasInClassInitializer()) | ||||||
2954 | return false; | ||||||
2955 | |||||||
2956 | assert(Instantiation->getInClassInitStyle() ==(static_cast <bool> (Instantiation->getInClassInitStyle () == Pattern->getInClassInitStyle() && "pattern and instantiation disagree about init style" ) ? void (0) : __assert_fail ("Instantiation->getInClassInitStyle() == Pattern->getInClassInitStyle() && \"pattern and instantiation disagree about init style\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2958, __extension__ __PRETTY_FUNCTION__)) | ||||||
2957 | Pattern->getInClassInitStyle() &&(static_cast <bool> (Instantiation->getInClassInitStyle () == Pattern->getInClassInitStyle() && "pattern and instantiation disagree about init style" ) ? void (0) : __assert_fail ("Instantiation->getInClassInitStyle() == Pattern->getInClassInitStyle() && \"pattern and instantiation disagree about init style\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2958, __extension__ __PRETTY_FUNCTION__)) | ||||||
2958 | "pattern and instantiation disagree about init style")(static_cast <bool> (Instantiation->getInClassInitStyle () == Pattern->getInClassInitStyle() && "pattern and instantiation disagree about init style" ) ? void (0) : __assert_fail ("Instantiation->getInClassInitStyle() == Pattern->getInClassInitStyle() && \"pattern and instantiation disagree about init style\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2958, __extension__ __PRETTY_FUNCTION__)); | ||||||
2959 | |||||||
2960 | // Error out if we haven't parsed the initializer of the pattern yet because | ||||||
2961 | // we are waiting for the closing brace of the outer class. | ||||||
2962 | Expr *OldInit = Pattern->getInClassInitializer(); | ||||||
2963 | if (!OldInit) { | ||||||
2964 | RecordDecl *PatternRD = Pattern->getParent(); | ||||||
2965 | RecordDecl *OutermostClass = PatternRD->getOuterLexicalRecordContext(); | ||||||
2966 | Diag(PointOfInstantiation, | ||||||
2967 | diag::err_default_member_initializer_not_yet_parsed) | ||||||
2968 | << OutermostClass << Pattern; | ||||||
2969 | Diag(Pattern->getEndLoc(), | ||||||
2970 | diag::note_default_member_initializer_not_yet_parsed); | ||||||
2971 | Instantiation->setInvalidDecl(); | ||||||
2972 | return true; | ||||||
2973 | } | ||||||
2974 | |||||||
2975 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation); | ||||||
2976 | if (Inst.isInvalid()) | ||||||
2977 | return true; | ||||||
2978 | if (Inst.isAlreadyInstantiating()) { | ||||||
2979 | // Error out if we hit an instantiation cycle for this initializer. | ||||||
2980 | Diag(PointOfInstantiation, diag::err_default_member_initializer_cycle) | ||||||
2981 | << Instantiation; | ||||||
2982 | return true; | ||||||
2983 | } | ||||||
2984 | PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(), | ||||||
2985 | "instantiating default member init"); | ||||||
2986 | |||||||
2987 | // Enter the scope of this instantiation. We don't use PushDeclContext because | ||||||
2988 | // we don't have a scope. | ||||||
2989 | ContextRAII SavedContext(*this, Instantiation->getParent()); | ||||||
2990 | EnterExpressionEvaluationContext EvalContext( | ||||||
2991 | *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); | ||||||
2992 | |||||||
2993 | LocalInstantiationScope Scope(*this, true); | ||||||
2994 | |||||||
2995 | // Instantiate the initializer. | ||||||
2996 | ActOnStartCXXInClassMemberInitializer(); | ||||||
2997 | CXXThisScopeRAII ThisScope(*this, Instantiation->getParent(), Qualifiers()); | ||||||
2998 | |||||||
2999 | ExprResult NewInit = SubstInitializer(OldInit, TemplateArgs, | ||||||
3000 | /*CXXDirectInit=*/false); | ||||||
3001 | Expr *Init = NewInit.get(); | ||||||
3002 | assert((!Init || !isa<ParenListExpr>(Init)) && "call-style init in class")(static_cast <bool> ((!Init || !isa<ParenListExpr> (Init)) && "call-style init in class") ? void (0) : __assert_fail ("(!Init || !isa<ParenListExpr>(Init)) && \"call-style init in class\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3002, __extension__ __PRETTY_FUNCTION__)); | ||||||
3003 | ActOnFinishCXXInClassMemberInitializer( | ||||||
3004 | Instantiation, Init ? Init->getBeginLoc() : SourceLocation(), Init); | ||||||
3005 | |||||||
3006 | if (auto *L = getASTMutationListener()) | ||||||
3007 | L->DefaultMemberInitializerInstantiated(Instantiation); | ||||||
3008 | |||||||
3009 | // Return true if the in-class initializer is still missing. | ||||||
3010 | return !Instantiation->getInClassInitializer(); | ||||||
3011 | } | ||||||
3012 | |||||||
3013 | namespace { | ||||||
3014 | /// A partial specialization whose template arguments have matched | ||||||
3015 | /// a given template-id. | ||||||
3016 | struct PartialSpecMatchResult { | ||||||
3017 | ClassTemplatePartialSpecializationDecl *Partial; | ||||||
3018 | TemplateArgumentList *Args; | ||||||
3019 | }; | ||||||
3020 | } | ||||||
3021 | |||||||
3022 | bool Sema::usesPartialOrExplicitSpecialization( | ||||||
3023 | SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec) { | ||||||
3024 | if (ClassTemplateSpec->getTemplateSpecializationKind() == | ||||||
3025 | TSK_ExplicitSpecialization) | ||||||
3026 | return true; | ||||||
3027 | |||||||
3028 | SmallVector<ClassTemplatePartialSpecializationDecl *, 4> PartialSpecs; | ||||||
3029 | ClassTemplateSpec->getSpecializedTemplate() | ||||||
3030 | ->getPartialSpecializations(PartialSpecs); | ||||||
3031 | for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) { | ||||||
3032 | TemplateDeductionInfo Info(Loc); | ||||||
3033 | if (!DeduceTemplateArguments(PartialSpecs[I], | ||||||
3034 | ClassTemplateSpec->getTemplateArgs(), Info)) | ||||||
3035 | return true; | ||||||
3036 | } | ||||||
3037 | |||||||
3038 | return false; | ||||||
3039 | } | ||||||
3040 | |||||||
3041 | /// Get the instantiation pattern to use to instantiate the definition of a | ||||||
3042 | /// given ClassTemplateSpecializationDecl (either the pattern of the primary | ||||||
3043 | /// template or of a partial specialization). | ||||||
3044 | static ActionResult<CXXRecordDecl *> | ||||||
3045 | getPatternForClassTemplateSpecialization( | ||||||
3046 | Sema &S, SourceLocation PointOfInstantiation, | ||||||
3047 | ClassTemplateSpecializationDecl *ClassTemplateSpec, | ||||||
3048 | TemplateSpecializationKind TSK) { | ||||||
3049 | Sema::InstantiatingTemplate Inst(S, PointOfInstantiation, ClassTemplateSpec); | ||||||
3050 | if (Inst.isInvalid()) | ||||||
3051 | return {/*Invalid=*/true}; | ||||||
3052 | if (Inst.isAlreadyInstantiating()) | ||||||
3053 | return {/*Invalid=*/false}; | ||||||
3054 | |||||||
3055 | llvm::PointerUnion<ClassTemplateDecl *, | ||||||
3056 | ClassTemplatePartialSpecializationDecl *> | ||||||
3057 | Specialized = ClassTemplateSpec->getSpecializedTemplateOrPartial(); | ||||||
3058 | if (!Specialized.is<ClassTemplatePartialSpecializationDecl *>()) { | ||||||
3059 | // Find best matching specialization. | ||||||
3060 | ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate(); | ||||||
3061 | |||||||
3062 | // C++ [temp.class.spec.match]p1: | ||||||
3063 | // When a class template is used in a context that requires an | ||||||
3064 | // instantiation of the class, it is necessary to determine | ||||||
3065 | // whether the instantiation is to be generated using the primary | ||||||
3066 | // template or one of the partial specializations. This is done by | ||||||
3067 | // matching the template arguments of the class template | ||||||
3068 | // specialization with the template argument lists of the partial | ||||||
3069 | // specializations. | ||||||
3070 | typedef PartialSpecMatchResult MatchResult; | ||||||
3071 | SmallVector<MatchResult, 4> Matched; | ||||||
3072 | SmallVector<ClassTemplatePartialSpecializationDecl *, 4> PartialSpecs; | ||||||
3073 | Template->getPartialSpecializations(PartialSpecs); | ||||||
3074 | TemplateSpecCandidateSet FailedCandidates(PointOfInstantiation); | ||||||
3075 | for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) { | ||||||
3076 | ClassTemplatePartialSpecializationDecl *Partial = PartialSpecs[I]; | ||||||
3077 | TemplateDeductionInfo Info(FailedCandidates.getLocation()); | ||||||
3078 | if (Sema::TemplateDeductionResult Result = S.DeduceTemplateArguments( | ||||||
3079 | Partial, ClassTemplateSpec->getTemplateArgs(), Info)) { | ||||||
3080 | // Store the failed-deduction information for use in diagnostics, later. | ||||||
3081 | // TODO: Actually use the failed-deduction info? | ||||||
3082 | FailedCandidates.addCandidate().set( | ||||||
3083 | DeclAccessPair::make(Template, AS_public), Partial, | ||||||
3084 | MakeDeductionFailureInfo(S.Context, Result, Info)); | ||||||
3085 | (void)Result; | ||||||
3086 | } else { | ||||||
3087 | Matched.push_back(PartialSpecMatchResult()); | ||||||
3088 | Matched.back().Partial = Partial; | ||||||
3089 | Matched.back().Args = Info.take(); | ||||||
3090 | } | ||||||
3091 | } | ||||||
3092 | |||||||
3093 | // If we're dealing with a member template where the template parameters | ||||||
3094 | // have been instantiated, this provides the original template parameters | ||||||
3095 | // from which the member template's parameters were instantiated. | ||||||
3096 | |||||||
3097 | if (Matched.size() >= 1) { | ||||||
3098 | SmallVectorImpl<MatchResult>::iterator Best = Matched.begin(); | ||||||
3099 | if (Matched.size() == 1) { | ||||||
3100 | // -- If exactly one matching specialization is found, the | ||||||
3101 | // instantiation is generated from that specialization. | ||||||
3102 | // We don't need to do anything for this. | ||||||
3103 | } else { | ||||||
3104 | // -- If more than one matching specialization is found, the | ||||||
3105 | // partial order rules (14.5.4.2) are used to determine | ||||||
3106 | // whether one of the specializations is more specialized | ||||||
3107 | // than the others. If none of the specializations is more | ||||||
3108 | // specialized than all of the other matching | ||||||
3109 | // specializations, then the use of the class template is | ||||||
3110 | // ambiguous and the program is ill-formed. | ||||||
3111 | for (SmallVectorImpl<MatchResult>::iterator P = Best + 1, | ||||||
3112 | PEnd = Matched.end(); | ||||||
3113 | P != PEnd; ++P) { | ||||||
3114 | if (S.getMoreSpecializedPartialSpecialization( | ||||||
3115 | P->Partial, Best->Partial, PointOfInstantiation) == | ||||||
3116 | P->Partial) | ||||||
3117 | Best = P; | ||||||
3118 | } | ||||||
3119 | |||||||
3120 | // Determine if the best partial specialization is more specialized than | ||||||
3121 | // the others. | ||||||
3122 | bool Ambiguous = false; | ||||||
3123 | for (SmallVectorImpl<MatchResult>::iterator P = Matched.begin(), | ||||||
3124 | PEnd = Matched.end(); | ||||||
3125 | P != PEnd; ++P) { | ||||||
3126 | if (P != Best && S.getMoreSpecializedPartialSpecialization( | ||||||
3127 | P->Partial, Best->Partial, | ||||||
3128 | PointOfInstantiation) != Best->Partial) { | ||||||
3129 | Ambiguous = true; | ||||||
3130 | break; | ||||||
3131 | } | ||||||
3132 | } | ||||||
3133 | |||||||
3134 | if (Ambiguous) { | ||||||
3135 | // Partial ordering did not produce a clear winner. Complain. | ||||||
3136 | Inst.Clear(); | ||||||
3137 | ClassTemplateSpec->setInvalidDecl(); | ||||||
3138 | S.Diag(PointOfInstantiation, | ||||||
3139 | diag::err_partial_spec_ordering_ambiguous) | ||||||
3140 | << ClassTemplateSpec; | ||||||
3141 | |||||||
3142 | // Print the matching partial specializations. | ||||||
3143 | for (SmallVectorImpl<MatchResult>::iterator P = Matched.begin(), | ||||||
3144 | PEnd = Matched.end(); | ||||||
3145 | P != PEnd; ++P) | ||||||
3146 | S.Diag(P->Partial->getLocation(), diag::note_partial_spec_match) | ||||||
3147 | << S.getTemplateArgumentBindingsText( | ||||||
3148 | P->Partial->getTemplateParameters(), *P->Args); | ||||||
3149 | |||||||
3150 | return {/*Invalid=*/true}; | ||||||
3151 | } | ||||||
3152 | } | ||||||
3153 | |||||||
3154 | ClassTemplateSpec->setInstantiationOf(Best->Partial, Best->Args); | ||||||
3155 | } else { | ||||||
3156 | // -- If no matches are found, the instantiation is generated | ||||||
3157 | // from the primary template. | ||||||
3158 | } | ||||||
3159 | } | ||||||
3160 | |||||||
3161 | CXXRecordDecl *Pattern = nullptr; | ||||||
3162 | Specialized = ClassTemplateSpec->getSpecializedTemplateOrPartial(); | ||||||
3163 | if (auto *PartialSpec = | ||||||
3164 | Specialized.dyn_cast<ClassTemplatePartialSpecializationDecl *>()) { | ||||||
3165 | // Instantiate using the best class template partial specialization. | ||||||
3166 | while (PartialSpec->getInstantiatedFromMember()) { | ||||||
3167 | // If we've found an explicit specialization of this class template, | ||||||
3168 | // stop here and use that as the pattern. | ||||||
3169 | if (PartialSpec->isMemberSpecialization()) | ||||||
3170 | break; | ||||||
3171 | |||||||
3172 | PartialSpec = PartialSpec->getInstantiatedFromMember(); | ||||||
3173 | } | ||||||
3174 | Pattern = PartialSpec; | ||||||
3175 | } else { | ||||||
3176 | ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate(); | ||||||
3177 | while (Template->getInstantiatedFromMemberTemplate()) { | ||||||
3178 | // If we've found an explicit specialization of this class template, | ||||||
3179 | // stop here and use that as the pattern. | ||||||
3180 | if (Template->isMemberSpecialization()) | ||||||
3181 | break; | ||||||
3182 | |||||||
3183 | Template = Template->getInstantiatedFromMemberTemplate(); | ||||||
3184 | } | ||||||
3185 | Pattern = Template->getTemplatedDecl(); | ||||||
3186 | } | ||||||
3187 | |||||||
3188 | return Pattern; | ||||||
3189 | } | ||||||
3190 | |||||||
3191 | bool Sema::InstantiateClassTemplateSpecialization( | ||||||
3192 | SourceLocation PointOfInstantiation, | ||||||
3193 | ClassTemplateSpecializationDecl *ClassTemplateSpec, | ||||||
3194 | TemplateSpecializationKind TSK, bool Complain) { | ||||||
3195 | // Perform the actual instantiation on the canonical declaration. | ||||||
3196 | ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>( | ||||||
3197 | ClassTemplateSpec->getCanonicalDecl()); | ||||||
3198 | if (ClassTemplateSpec->isInvalidDecl()) | ||||||
3199 | return true; | ||||||
3200 | |||||||
3201 | ActionResult<CXXRecordDecl *> Pattern = | ||||||
3202 | getPatternForClassTemplateSpecialization(*this, PointOfInstantiation, | ||||||
3203 | ClassTemplateSpec, TSK); | ||||||
3204 | if (!Pattern.isUsable()) | ||||||
3205 | return Pattern.isInvalid(); | ||||||
3206 | |||||||
3207 | return InstantiateClass( | ||||||
3208 | PointOfInstantiation, ClassTemplateSpec, Pattern.get(), | ||||||
3209 | getTemplateInstantiationArgs(ClassTemplateSpec), TSK, Complain); | ||||||
3210 | } | ||||||
3211 | |||||||
3212 | /// Instantiates the definitions of all of the member | ||||||
3213 | /// of the given class, which is an instantiation of a class template | ||||||
3214 | /// or a member class of a template. | ||||||
3215 | void | ||||||
3216 | Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation, | ||||||
3217 | CXXRecordDecl *Instantiation, | ||||||
3218 | const MultiLevelTemplateArgumentList &TemplateArgs, | ||||||
3219 | TemplateSpecializationKind TSK) { | ||||||
3220 | // FIXME: We need to notify the ASTMutationListener that we did all of these | ||||||
3221 | // things, in case we have an explicit instantiation definition in a PCM, a | ||||||
3222 | // module, or preamble, and the declaration is in an imported AST. | ||||||
3223 | assert((static_cast <bool> ((TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && "Unexpected template specialization kind!" ) ? void (0) : __assert_fail ("(TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && \"Unexpected template specialization kind!\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3227, __extension__ __PRETTY_FUNCTION__)) | ||||||
3224 | (TSK == TSK_ExplicitInstantiationDefinition ||(static_cast <bool> ((TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && "Unexpected template specialization kind!" ) ? void (0) : __assert_fail ("(TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && \"Unexpected template specialization kind!\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3227, __extension__ __PRETTY_FUNCTION__)) | ||||||
3225 | TSK == TSK_ExplicitInstantiationDeclaration ||(static_cast <bool> ((TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && "Unexpected template specialization kind!" ) ? void (0) : __assert_fail ("(TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && \"Unexpected template specialization kind!\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3227, __extension__ __PRETTY_FUNCTION__)) | ||||||
3226 | (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) &&(static_cast <bool> ((TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && "Unexpected template specialization kind!" ) ? void (0) : __assert_fail ("(TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && \"Unexpected template specialization kind!\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3227, __extension__ __PRETTY_FUNCTION__)) | ||||||
3227 | "Unexpected template specialization kind!")(static_cast <bool> ((TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && "Unexpected template specialization kind!" ) ? void (0) : __assert_fail ("(TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && \"Unexpected template specialization kind!\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3227, __extension__ __PRETTY_FUNCTION__)); | ||||||
3228 | for (auto *D : Instantiation->decls()) { | ||||||
3229 | bool SuppressNew = false; | ||||||
3230 | if (auto *Function = dyn_cast<FunctionDecl>(D)) { | ||||||
3231 | if (FunctionDecl *Pattern = | ||||||
3232 | Function->getInstantiatedFromMemberFunction()) { | ||||||
3233 | |||||||
3234 | if (Function->hasAttr<ExcludeFromExplicitInstantiationAttr>()) | ||||||
3235 | continue; | ||||||
3236 | |||||||
3237 | MemberSpecializationInfo *MSInfo = | ||||||
3238 | Function->getMemberSpecializationInfo(); | ||||||
3239 | assert(MSInfo && "No member specialization information?")(static_cast <bool> (MSInfo && "No member specialization information?" ) ? void (0) : __assert_fail ("MSInfo && \"No member specialization information?\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3239, __extension__ __PRETTY_FUNCTION__)); | ||||||
3240 | if (MSInfo->getTemplateSpecializationKind() | ||||||
3241 | == TSK_ExplicitSpecialization) | ||||||
3242 | continue; | ||||||
3243 | |||||||
3244 | if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, | ||||||
3245 | Function, | ||||||
3246 | MSInfo->getTemplateSpecializationKind(), | ||||||
3247 | MSInfo->getPointOfInstantiation(), | ||||||
3248 | SuppressNew) || | ||||||
3249 | SuppressNew) | ||||||
3250 | continue; | ||||||
3251 | |||||||
3252 | // C++11 [temp.explicit]p8: | ||||||
3253 | // An explicit instantiation definition that names a class template | ||||||
3254 | // specialization explicitly instantiates the class template | ||||||
3255 | // specialization and is only an explicit instantiation definition | ||||||
3256 | // of members whose definition is visible at the point of | ||||||
3257 | // instantiation. | ||||||
3258 | if (TSK == TSK_ExplicitInstantiationDefinition && !Pattern->isDefined()) | ||||||
3259 | continue; | ||||||
3260 | |||||||
3261 | Function->setTemplateSpecializationKind(TSK, PointOfInstantiation); | ||||||
3262 | |||||||
3263 | if (Function->isDefined()) { | ||||||
3264 | // Let the ASTConsumer know that this function has been explicitly | ||||||
3265 | // instantiated now, and its linkage might have changed. | ||||||
3266 | Consumer.HandleTopLevelDecl(DeclGroupRef(Function)); | ||||||
3267 | } else if (TSK == TSK_ExplicitInstantiationDefinition) { | ||||||
3268 | InstantiateFunctionDefinition(PointOfInstantiation, Function); | ||||||
3269 | } else if (TSK == TSK_ImplicitInstantiation) { | ||||||
3270 | PendingLocalImplicitInstantiations.push_back( | ||||||
3271 | std::make_pair(Function, PointOfInstantiation)); | ||||||
3272 | } | ||||||
3273 | } | ||||||
3274 | } else if (auto *Var = dyn_cast<VarDecl>(D)) { | ||||||
3275 | if (isa<VarTemplateSpecializationDecl>(Var)) | ||||||
3276 | continue; | ||||||
3277 | |||||||
3278 | if (Var->isStaticDataMember()) { | ||||||
3279 | if (Var->hasAttr<ExcludeFromExplicitInstantiationAttr>()) | ||||||
3280 | continue; | ||||||
3281 | |||||||
3282 | MemberSpecializationInfo *MSInfo = Var->getMemberSpecializationInfo(); | ||||||
3283 | assert(MSInfo && "No member specialization information?")(static_cast <bool> (MSInfo && "No member specialization information?" ) ? void (0) : __assert_fail ("MSInfo && \"No member specialization information?\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3283, __extension__ __PRETTY_FUNCTION__)); | ||||||
3284 | if (MSInfo->getTemplateSpecializationKind() | ||||||
3285 | == TSK_ExplicitSpecialization) | ||||||
3286 | continue; | ||||||
3287 | |||||||
3288 | if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, | ||||||
3289 | Var, | ||||||
3290 | MSInfo->getTemplateSpecializationKind(), | ||||||
3291 | MSInfo->getPointOfInstantiation(), | ||||||
3292 | SuppressNew) || | ||||||
3293 | SuppressNew) | ||||||
3294 | continue; | ||||||
3295 | |||||||
3296 | if (TSK == TSK_ExplicitInstantiationDefinition) { | ||||||
3297 | // C++0x [temp.explicit]p8: | ||||||
3298 | // An explicit instantiation definition that names a class template | ||||||
3299 | // specialization explicitly instantiates the class template | ||||||
3300 | // specialization and is only an explicit instantiation definition | ||||||
3301 | // of members whose definition is visible at the point of | ||||||
3302 | // instantiation. | ||||||
3303 | if (!Var->getInstantiatedFromStaticDataMember()->getDefinition()) | ||||||
3304 | continue; | ||||||
3305 | |||||||
3306 | Var->setTemplateSpecializationKind(TSK, PointOfInstantiation); | ||||||
3307 | InstantiateVariableDefinition(PointOfInstantiation, Var); | ||||||
3308 | } else { | ||||||
3309 | Var->setTemplateSpecializationKind(TSK, PointOfInstantiation); | ||||||
3310 | } | ||||||
3311 | } | ||||||
3312 | } else if (auto *Record = dyn_cast<CXXRecordDecl>(D)) { | ||||||
3313 | if (Record->hasAttr<ExcludeFromExplicitInstantiationAttr>()) | ||||||
3314 | continue; | ||||||
3315 | |||||||
3316 | // Always skip the injected-class-name, along with any | ||||||
3317 | // redeclarations of nested classes, since both would cause us | ||||||
3318 | // to try to instantiate the members of a class twice. | ||||||
3319 | // Skip closure types; they'll get instantiated when we instantiate | ||||||
3320 | // the corresponding lambda-expression. | ||||||
3321 | if (Record->isInjectedClassName() || Record->getPreviousDecl() || | ||||||
3322 | Record->isLambda()) | ||||||
3323 | continue; | ||||||
3324 | |||||||
3325 | MemberSpecializationInfo *MSInfo = Record->getMemberSpecializationInfo(); | ||||||
3326 | assert(MSInfo && "No member specialization information?")(static_cast <bool> (MSInfo && "No member specialization information?" ) ? void (0) : __assert_fail ("MSInfo && \"No member specialization information?\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3326, __extension__ __PRETTY_FUNCTION__)); | ||||||
3327 | |||||||
3328 | if (MSInfo->getTemplateSpecializationKind() | ||||||
3329 | == TSK_ExplicitSpecialization) | ||||||
3330 | continue; | ||||||
3331 | |||||||
3332 | if (Context.getTargetInfo().getTriple().isOSWindows() && | ||||||
3333 | TSK == TSK_ExplicitInstantiationDeclaration) { | ||||||
3334 | // On Windows, explicit instantiation decl of the outer class doesn't | ||||||
3335 | // affect the inner class. Typically extern template declarations are | ||||||
3336 | // used in combination with dll import/export annotations, but those | ||||||
3337 | // are not propagated from the outer class templates to inner classes. | ||||||
3338 | // Therefore, do not instantiate inner classes on this platform, so | ||||||
3339 | // that users don't end up with undefined symbols during linking. | ||||||
3340 | continue; | ||||||
3341 | } | ||||||
3342 | |||||||
3343 | if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, | ||||||
3344 | Record, | ||||||
3345 | MSInfo->getTemplateSpecializationKind(), | ||||||
3346 | MSInfo->getPointOfInstantiation(), | ||||||
3347 | SuppressNew) || | ||||||
3348 | SuppressNew) | ||||||
3349 | continue; | ||||||
3350 | |||||||
3351 | CXXRecordDecl *Pattern = Record->getInstantiatedFromMemberClass(); | ||||||
3352 | assert(Pattern && "Missing instantiated-from-template information")(static_cast <bool> (Pattern && "Missing instantiated-from-template information" ) ? void (0) : __assert_fail ("Pattern && \"Missing instantiated-from-template information\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3352, __extension__ __PRETTY_FUNCTION__)); | ||||||
3353 | |||||||
3354 | if (!Record->getDefinition()) { | ||||||
3355 | if (!Pattern->getDefinition()) { | ||||||
3356 | // C++0x [temp.explicit]p8: | ||||||
3357 | // An explicit instantiation definition that names a class template | ||||||
3358 | // specialization explicitly instantiates the class template | ||||||
3359 | // specialization and is only an explicit instantiation definition | ||||||
3360 | // of members whose definition is visible at the point of | ||||||
3361 | // instantiation. | ||||||
3362 | if (TSK == TSK_ExplicitInstantiationDeclaration) { | ||||||
3363 | MSInfo->setTemplateSpecializationKind(TSK); | ||||||
3364 | MSInfo->setPointOfInstantiation(PointOfInstantiation); | ||||||
3365 | } | ||||||
3366 | |||||||
3367 | continue; | ||||||
3368 | } | ||||||
3369 | |||||||
3370 | InstantiateClass(PointOfInstantiation, Record, Pattern, | ||||||
3371 | TemplateArgs, | ||||||
3372 | TSK); | ||||||
3373 | } else { | ||||||
3374 | if (TSK == TSK_ExplicitInstantiationDefinition && | ||||||
3375 | Record->getTemplateSpecializationKind() == | ||||||
3376 | TSK_ExplicitInstantiationDeclaration) { | ||||||
3377 | Record->setTemplateSpecializationKind(TSK); | ||||||
3378 | MarkVTableUsed(PointOfInstantiation, Record, true); | ||||||
3379 | } | ||||||
3380 | } | ||||||
3381 | |||||||
3382 | Pattern = cast_or_null<CXXRecordDecl>(Record->getDefinition()); | ||||||
3383 | if (Pattern) | ||||||
3384 | InstantiateClassMembers(PointOfInstantiation, Pattern, TemplateArgs, | ||||||
3385 | TSK); | ||||||
3386 | } else if (auto *Enum = dyn_cast<EnumDecl>(D)) { | ||||||
3387 | MemberSpecializationInfo *MSInfo = Enum->getMemberSpecializationInfo(); | ||||||
3388 | assert(MSInfo && "No member specialization information?")(static_cast <bool> (MSInfo && "No member specialization information?" ) ? void (0) : __assert_fail ("MSInfo && \"No member specialization information?\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3388, __extension__ __PRETTY_FUNCTION__)); | ||||||
3389 | |||||||
3390 | if (MSInfo->getTemplateSpecializationKind() | ||||||
3391 | == TSK_ExplicitSpecialization) | ||||||
3392 | continue; | ||||||
3393 | |||||||
3394 | if (CheckSpecializationInstantiationRedecl( | ||||||
3395 | PointOfInstantiation, TSK, Enum, | ||||||
3396 | MSInfo->getTemplateSpecializationKind(), | ||||||
3397 | MSInfo->getPointOfInstantiation(), SuppressNew) || | ||||||
3398 | SuppressNew) | ||||||
3399 | continue; | ||||||
3400 | |||||||
3401 | if (Enum->getDefinition()) | ||||||
3402 | continue; | ||||||
3403 | |||||||
3404 | EnumDecl *Pattern = Enum->getTemplateInstantiationPattern(); | ||||||
3405 | assert(Pattern && "Missing instantiated-from-template information")(static_cast <bool> (Pattern && "Missing instantiated-from-template information" ) ? void (0) : __assert_fail ("Pattern && \"Missing instantiated-from-template information\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3405, __extension__ __PRETTY_FUNCTION__)); | ||||||
3406 | |||||||
3407 | if (TSK == TSK_ExplicitInstantiationDefinition) { | ||||||
3408 | if (!Pattern->getDefinition()) | ||||||
3409 | continue; | ||||||
3410 | |||||||
3411 | InstantiateEnum(PointOfInstantiation, Enum, Pattern, TemplateArgs, TSK); | ||||||
3412 | } else { | ||||||
3413 | MSInfo->setTemplateSpecializationKind(TSK); | ||||||
3414 | MSInfo->setPointOfInstantiation(PointOfInstantiation); | ||||||
3415 | } | ||||||
3416 | } else if (auto *Field = dyn_cast<FieldDecl>(D)) { | ||||||
3417 | // No need to instantiate in-class initializers during explicit | ||||||
3418 | // instantiation. | ||||||
3419 | if (Field->hasInClassInitializer() && TSK == TSK_ImplicitInstantiation) { | ||||||
3420 | CXXRecordDecl *ClassPattern = | ||||||
3421 | Instantiation->getTemplateInstantiationPattern(); | ||||||
3422 | DeclContext::lookup_result Lookup = | ||||||
3423 | ClassPattern->lookup(Field->getDeclName()); | ||||||
3424 | FieldDecl *Pattern = Lookup.find_first<FieldDecl>(); | ||||||
3425 | assert(Pattern)(static_cast <bool> (Pattern) ? void (0) : __assert_fail ("Pattern", "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3425, __extension__ __PRETTY_FUNCTION__)); | ||||||
3426 | InstantiateInClassInitializer(PointOfInstantiation, Field, Pattern, | ||||||
3427 | TemplateArgs); | ||||||
3428 | } | ||||||
3429 | } | ||||||
3430 | } | ||||||
3431 | } | ||||||
3432 | |||||||
3433 | /// Instantiate the definitions of all of the members of the | ||||||
3434 | /// given class template specialization, which was named as part of an | ||||||
3435 | /// explicit instantiation. | ||||||
3436 | void | ||||||
3437 | Sema::InstantiateClassTemplateSpecializationMembers( | ||||||
3438 | SourceLocation PointOfInstantiation, | ||||||
3439 | ClassTemplateSpecializationDecl *ClassTemplateSpec, | ||||||
3440 | TemplateSpecializationKind TSK) { | ||||||
3441 | // C++0x [temp.explicit]p7: | ||||||
3442 | // An explicit instantiation that names a class template | ||||||
3443 | // specialization is an explicit instantion of the same kind | ||||||
3444 | // (declaration or definition) of each of its members (not | ||||||
3445 | // including members inherited from base classes) that has not | ||||||
3446 | // been previously explicitly specialized in the translation unit | ||||||
3447 | // containing the explicit instantiation, except as described | ||||||
3448 | // below. | ||||||
3449 | InstantiateClassMembers(PointOfInstantiation, ClassTemplateSpec, | ||||||
3450 | getTemplateInstantiationArgs(ClassTemplateSpec), | ||||||
3451 | TSK); | ||||||
3452 | } | ||||||
3453 | |||||||
3454 | StmtResult | ||||||
3455 | Sema::SubstStmt(Stmt *S, const MultiLevelTemplateArgumentList &TemplateArgs) { | ||||||
3456 | if (!S) | ||||||
3457 | return S; | ||||||
3458 | |||||||
3459 | TemplateInstantiator Instantiator(*this, TemplateArgs, | ||||||
3460 | SourceLocation(), | ||||||
3461 | DeclarationName()); | ||||||
3462 | return Instantiator.TransformStmt(S); | ||||||
3463 | } | ||||||
3464 | |||||||
3465 | bool Sema::SubstTemplateArguments( | ||||||
3466 | ArrayRef<TemplateArgumentLoc> Args, | ||||||
3467 | const MultiLevelTemplateArgumentList &TemplateArgs, | ||||||
3468 | TemplateArgumentListInfo &Out) { | ||||||
3469 | TemplateInstantiator Instantiator(*this, TemplateArgs, | ||||||
3470 | SourceLocation(), | ||||||
3471 | DeclarationName()); | ||||||
3472 | return Instantiator.TransformTemplateArguments(Args.begin(), Args.end(), | ||||||
3473 | Out); | ||||||
3474 | } | ||||||
3475 | |||||||
3476 | ExprResult | ||||||
3477 | Sema::SubstExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs) { | ||||||
3478 | if (!E) | ||||||
3479 | return E; | ||||||
3480 | |||||||
3481 | TemplateInstantiator Instantiator(*this, TemplateArgs, | ||||||
3482 | SourceLocation(), | ||||||
3483 | DeclarationName()); | ||||||
3484 | return Instantiator.TransformExpr(E); | ||||||
3485 | } | ||||||
3486 | |||||||
3487 | ExprResult Sema::SubstInitializer(Expr *Init, | ||||||
3488 | const MultiLevelTemplateArgumentList &TemplateArgs, | ||||||
3489 | bool CXXDirectInit) { | ||||||
3490 | TemplateInstantiator Instantiator(*this, TemplateArgs, | ||||||
3491 | SourceLocation(), | ||||||
3492 | DeclarationName()); | ||||||
3493 | return Instantiator.TransformInitializer(Init, CXXDirectInit); | ||||||
3494 | } | ||||||
3495 | |||||||
3496 | bool Sema::SubstExprs(ArrayRef<Expr *> Exprs, bool IsCall, | ||||||
3497 | const MultiLevelTemplateArgumentList &TemplateArgs, | ||||||
3498 | SmallVectorImpl<Expr *> &Outputs) { | ||||||
3499 | if (Exprs.empty()) | ||||||
3500 | return false; | ||||||
3501 | |||||||
3502 | TemplateInstantiator Instantiator(*this, TemplateArgs, | ||||||
3503 | SourceLocation(), | ||||||
3504 | DeclarationName()); | ||||||
3505 | return Instantiator.TransformExprs(Exprs.data(), Exprs.size(), | ||||||
3506 | IsCall, Outputs); | ||||||
3507 | } | ||||||
3508 | |||||||
3509 | NestedNameSpecifierLoc | ||||||
3510 | Sema::SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, | ||||||
3511 | const MultiLevelTemplateArgumentList &TemplateArgs) { | ||||||
3512 | if (!NNS) | ||||||
3513 | return NestedNameSpecifierLoc(); | ||||||
3514 | |||||||
3515 | TemplateInstantiator Instantiator(*this, TemplateArgs, NNS.getBeginLoc(), | ||||||
3516 | DeclarationName()); | ||||||
3517 | return Instantiator.TransformNestedNameSpecifierLoc(NNS); | ||||||
3518 | } | ||||||
3519 | |||||||
3520 | /// Do template substitution on declaration name info. | ||||||
3521 | DeclarationNameInfo | ||||||
3522 | Sema::SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, | ||||||
3523 | const MultiLevelTemplateArgumentList &TemplateArgs) { | ||||||
3524 | TemplateInstantiator Instantiator(*this, TemplateArgs, NameInfo.getLoc(), | ||||||
3525 | NameInfo.getName()); | ||||||
3526 | return Instantiator.TransformDeclarationNameInfo(NameInfo); | ||||||
3527 | } | ||||||
3528 | |||||||
3529 | TemplateName | ||||||
3530 | Sema::SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, | ||||||
3531 | TemplateName Name, SourceLocation Loc, | ||||||
3532 | const MultiLevelTemplateArgumentList &TemplateArgs) { | ||||||
3533 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, | ||||||
3534 | DeclarationName()); | ||||||
3535 | CXXScopeSpec SS; | ||||||
3536 | SS.Adopt(QualifierLoc); | ||||||
3537 | return Instantiator.TransformTemplateName(SS, Name, Loc); | ||||||
3538 | } | ||||||
3539 | |||||||
3540 | bool Sema::Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, | ||||||
3541 | TemplateArgumentListInfo &Result, | ||||||
3542 | const MultiLevelTemplateArgumentList &TemplateArgs) { | ||||||
3543 | TemplateInstantiator Instantiator(*this, TemplateArgs, SourceLocation(), | ||||||
3544 | DeclarationName()); | ||||||
3545 | |||||||
3546 | return Instantiator.TransformTemplateArguments(Args, NumArgs, Result); | ||||||
3547 | } | ||||||
3548 | |||||||
3549 | static const Decl *getCanonicalParmVarDecl(const Decl *D) { | ||||||
3550 | // When storing ParmVarDecls in the local instantiation scope, we always | ||||||
3551 | // want to use the ParmVarDecl from the canonical function declaration, | ||||||
3552 | // since the map is then valid for any redeclaration or definition of that | ||||||
3553 | // function. | ||||||
3554 | if (const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(D)) { | ||||||
3555 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) { | ||||||
3556 | unsigned i = PV->getFunctionScopeIndex(); | ||||||
3557 | // This parameter might be from a freestanding function type within the | ||||||
3558 | // function and isn't necessarily referring to one of FD's parameters. | ||||||
3559 | if (i < FD->getNumParams() && FD->getParamDecl(i) == PV) | ||||||
3560 | return FD->getCanonicalDecl()->getParamDecl(i); | ||||||
3561 | } | ||||||
3562 | } | ||||||
3563 | return D; | ||||||
3564 | } | ||||||
3565 | |||||||
3566 | |||||||
3567 | llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> * | ||||||
3568 | LocalInstantiationScope::findInstantiationOf(const Decl *D) { | ||||||
3569 | D = getCanonicalParmVarDecl(D); | ||||||
3570 | for (LocalInstantiationScope *Current = this; Current; | ||||||
3571 | Current = Current->Outer) { | ||||||
3572 | |||||||
3573 | // Check if we found something within this scope. | ||||||
3574 | const Decl *CheckD = D; | ||||||
3575 | do { | ||||||
3576 | LocalDeclsMap::iterator Found = Current->LocalDecls.find(CheckD); | ||||||
3577 | if (Found != Current->LocalDecls.end()) | ||||||
3578 | return &Found->second; | ||||||
3579 | |||||||
3580 | // If this is a tag declaration, it's possible that we need to look for | ||||||
3581 | // a previous declaration. | ||||||
3582 | if (const TagDecl *Tag = dyn_cast<TagDecl>(CheckD)) | ||||||
3583 | CheckD = Tag->getPreviousDecl(); | ||||||
3584 | else | ||||||
3585 | CheckD = nullptr; | ||||||
3586 | } while (CheckD); | ||||||
3587 | |||||||
3588 | // If we aren't combined with our outer scope, we're done. | ||||||
3589 | if (!Current->CombineWithOuterScope) | ||||||
3590 | break; | ||||||
3591 | } | ||||||
3592 | |||||||
3593 | // If we're performing a partial substitution during template argument | ||||||
3594 | // deduction, we may not have values for template parameters yet. | ||||||
3595 | if (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D) || | ||||||
3596 | isa<TemplateTemplateParmDecl>(D)) | ||||||
3597 | return nullptr; | ||||||
3598 | |||||||
3599 | // Local types referenced prior to definition may require instantiation. | ||||||
3600 | if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) | ||||||
3601 | if (RD->isLocalClass()) | ||||||
3602 | return nullptr; | ||||||
3603 | |||||||
3604 | // Enumeration types referenced prior to definition may appear as a result of | ||||||
3605 | // error recovery. | ||||||
3606 | if (isa<EnumDecl>(D)) | ||||||
3607 | return nullptr; | ||||||
3608 | |||||||
3609 | // Materialized typedefs/type alias for implicit deduction guides may require | ||||||
3610 | // instantiation. | ||||||
3611 | if (isa<TypedefNameDecl>(D) && | ||||||
3612 | isa<CXXDeductionGuideDecl>(D->getDeclContext())) | ||||||
3613 | return nullptr; | ||||||
3614 | |||||||
3615 | // If we didn't find the decl, then we either have a sema bug, or we have a | ||||||
3616 | // forward reference to a label declaration. Return null to indicate that | ||||||
3617 | // we have an uninstantiated label. | ||||||
3618 | assert(isa<LabelDecl>(D) && "declaration not instantiated in this scope")(static_cast <bool> (isa<LabelDecl>(D) && "declaration not instantiated in this scope") ? void (0) : __assert_fail ("isa<LabelDecl>(D) && \"declaration not instantiated in this scope\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3618, __extension__ __PRETTY_FUNCTION__)); | ||||||
3619 | return nullptr; | ||||||
3620 | } | ||||||
3621 | |||||||
3622 | void LocalInstantiationScope::InstantiatedLocal(const Decl *D, Decl *Inst) { | ||||||
3623 | D = getCanonicalParmVarDecl(D); | ||||||
3624 | llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D]; | ||||||
3625 | if (Stored.isNull()) { | ||||||
3626 | #ifndef NDEBUG | ||||||
3627 | // It should not be present in any surrounding scope either. | ||||||
3628 | LocalInstantiationScope *Current = this; | ||||||
3629 | while (Current->CombineWithOuterScope && Current->Outer) { | ||||||
3630 | Current = Current->Outer; | ||||||
3631 | assert(Current->LocalDecls.find(D) == Current->LocalDecls.end() &&(static_cast <bool> (Current->LocalDecls.find(D) == Current ->LocalDecls.end() && "Instantiated local in inner and outer scopes" ) ? void (0) : __assert_fail ("Current->LocalDecls.find(D) == Current->LocalDecls.end() && \"Instantiated local in inner and outer scopes\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3632, __extension__ __PRETTY_FUNCTION__)) | ||||||
3632 | "Instantiated local in inner and outer scopes")(static_cast <bool> (Current->LocalDecls.find(D) == Current ->LocalDecls.end() && "Instantiated local in inner and outer scopes" ) ? void (0) : __assert_fail ("Current->LocalDecls.find(D) == Current->LocalDecls.end() && \"Instantiated local in inner and outer scopes\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3632, __extension__ __PRETTY_FUNCTION__)); | ||||||
3633 | } | ||||||
3634 | #endif | ||||||
3635 | Stored = Inst; | ||||||
3636 | } else if (DeclArgumentPack *Pack = Stored.dyn_cast<DeclArgumentPack *>()) { | ||||||
3637 | Pack->push_back(cast<VarDecl>(Inst)); | ||||||
3638 | } else { | ||||||
3639 | assert(Stored.get<Decl *>() == Inst && "Already instantiated this local")(static_cast <bool> (Stored.get<Decl *>() == Inst && "Already instantiated this local") ? void (0) : __assert_fail ("Stored.get<Decl *>() == Inst && \"Already instantiated this local\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3639, __extension__ __PRETTY_FUNCTION__)); | ||||||
3640 | } | ||||||
3641 | } | ||||||
3642 | |||||||
3643 | void LocalInstantiationScope::InstantiatedLocalPackArg(const Decl *D, | ||||||
3644 | VarDecl *Inst) { | ||||||
3645 | D = getCanonicalParmVarDecl(D); | ||||||
3646 | DeclArgumentPack *Pack = LocalDecls[D].get<DeclArgumentPack *>(); | ||||||
3647 | Pack->push_back(Inst); | ||||||
3648 | } | ||||||
3649 | |||||||
3650 | void LocalInstantiationScope::MakeInstantiatedLocalArgPack(const Decl *D) { | ||||||
3651 | #ifndef NDEBUG | ||||||
3652 | // This should be the first time we've been told about this decl. | ||||||
3653 | for (LocalInstantiationScope *Current = this; | ||||||
3654 | Current && Current->CombineWithOuterScope; Current = Current->Outer) | ||||||
3655 | assert(Current->LocalDecls.find(D) == Current->LocalDecls.end() &&(static_cast <bool> (Current->LocalDecls.find(D) == Current ->LocalDecls.end() && "Creating local pack after instantiation of local" ) ? void (0) : __assert_fail ("Current->LocalDecls.find(D) == Current->LocalDecls.end() && \"Creating local pack after instantiation of local\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3656, __extension__ __PRETTY_FUNCTION__)) | ||||||
3656 | "Creating local pack after instantiation of local")(static_cast <bool> (Current->LocalDecls.find(D) == Current ->LocalDecls.end() && "Creating local pack after instantiation of local" ) ? void (0) : __assert_fail ("Current->LocalDecls.find(D) == Current->LocalDecls.end() && \"Creating local pack after instantiation of local\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3656, __extension__ __PRETTY_FUNCTION__)); | ||||||
3657 | #endif | ||||||
3658 | |||||||
3659 | D = getCanonicalParmVarDecl(D); | ||||||
3660 | llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D]; | ||||||
3661 | DeclArgumentPack *Pack = new DeclArgumentPack; | ||||||
3662 | Stored = Pack; | ||||||
3663 | ArgumentPacks.push_back(Pack); | ||||||
3664 | } | ||||||
3665 | |||||||
3666 | bool LocalInstantiationScope::isLocalPackExpansion(const Decl *D) { | ||||||
3667 | for (DeclArgumentPack *Pack : ArgumentPacks) | ||||||
3668 | if (std::find(Pack->begin(), Pack->end(), D) != Pack->end()) | ||||||
3669 | return true; | ||||||
3670 | return false; | ||||||
3671 | } | ||||||
3672 | |||||||
3673 | void LocalInstantiationScope::SetPartiallySubstitutedPack(NamedDecl *Pack, | ||||||
3674 | const TemplateArgument *ExplicitArgs, | ||||||
3675 | unsigned NumExplicitArgs) { | ||||||
3676 | assert((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) &&(static_cast <bool> ((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) && "Already have a partially-substituted pack" ) ? void (0) : __assert_fail ("(!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) && \"Already have a partially-substituted pack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3677, __extension__ __PRETTY_FUNCTION__)) | ||||||
3677 | "Already have a partially-substituted pack")(static_cast <bool> ((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) && "Already have a partially-substituted pack" ) ? void (0) : __assert_fail ("(!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) && \"Already have a partially-substituted pack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3677, __extension__ __PRETTY_FUNCTION__)); | ||||||
3678 | assert((!PartiallySubstitutedPack(static_cast <bool> ((!PartiallySubstitutedPack || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) && "Wrong number of arguments in partially-substituted pack" ) ? void (0) : __assert_fail ("(!PartiallySubstitutedPack || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) && \"Wrong number of arguments in partially-substituted pack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3680, __extension__ __PRETTY_FUNCTION__)) | ||||||
3679 | || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) &&(static_cast <bool> ((!PartiallySubstitutedPack || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) && "Wrong number of arguments in partially-substituted pack" ) ? void (0) : __assert_fail ("(!PartiallySubstitutedPack || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) && \"Wrong number of arguments in partially-substituted pack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3680, __extension__ __PRETTY_FUNCTION__)) | ||||||
3680 | "Wrong number of arguments in partially-substituted pack")(static_cast <bool> ((!PartiallySubstitutedPack || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) && "Wrong number of arguments in partially-substituted pack" ) ? void (0) : __assert_fail ("(!PartiallySubstitutedPack || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) && \"Wrong number of arguments in partially-substituted pack\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3680, __extension__ __PRETTY_FUNCTION__)); | ||||||
3681 | PartiallySubstitutedPack = Pack; | ||||||
3682 | ArgsInPartiallySubstitutedPack = ExplicitArgs; | ||||||
3683 | NumArgsInPartiallySubstitutedPack = NumExplicitArgs; | ||||||
3684 | } | ||||||
3685 | |||||||
3686 | NamedDecl *LocalInstantiationScope::getPartiallySubstitutedPack( | ||||||
3687 | const TemplateArgument **ExplicitArgs, | ||||||
3688 | unsigned *NumExplicitArgs) const { | ||||||
3689 | if (ExplicitArgs) | ||||||
3690 | *ExplicitArgs = nullptr; | ||||||
3691 | if (NumExplicitArgs) | ||||||
3692 | *NumExplicitArgs = 0; | ||||||
3693 | |||||||
3694 | for (const LocalInstantiationScope *Current = this; Current; | ||||||
3695 | Current = Current->Outer) { | ||||||
3696 | if (Current->PartiallySubstitutedPack) { | ||||||
3697 | if (ExplicitArgs) | ||||||
3698 | *ExplicitArgs = Current->ArgsInPartiallySubstitutedPack; | ||||||
3699 | if (NumExplicitArgs) | ||||||
3700 | *NumExplicitArgs = Current->NumArgsInPartiallySubstitutedPack; | ||||||
3701 | |||||||
3702 | return Current->PartiallySubstitutedPack; | ||||||
3703 | } | ||||||
3704 | |||||||
3705 | if (!Current->CombineWithOuterScope) | ||||||
3706 | break; | ||||||
3707 | } | ||||||
3708 | |||||||
3709 | return nullptr; | ||||||
3710 | } |
1 | //===--- ASTLambda.h - Lambda Helper Functions --------------*- 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 | /// This file provides some common utility functions for processing | ||||||
11 | /// Lambda related AST Constructs. | ||||||
12 | /// | ||||||
13 | //===----------------------------------------------------------------------===// | ||||||
14 | |||||||
15 | #ifndef LLVM_CLANG_AST_ASTLAMBDA_H | ||||||
16 | #define LLVM_CLANG_AST_ASTLAMBDA_H | ||||||
17 | |||||||
18 | #include "clang/AST/DeclCXX.h" | ||||||
19 | #include "clang/AST/DeclTemplate.h" | ||||||
20 | |||||||
21 | namespace clang { | ||||||
22 | inline StringRef getLambdaStaticInvokerName() { | ||||||
23 | return "__invoke"; | ||||||
24 | } | ||||||
25 | // This function returns true if M is a specialization, a template, | ||||||
26 | // or a non-generic lambda call operator. | ||||||
27 | inline bool isLambdaCallOperator(const CXXMethodDecl *MD) { | ||||||
28 | const CXXRecordDecl *LambdaClass = MD->getParent(); | ||||||
29 | if (!LambdaClass
| ||||||
30 | return MD->getOverloadedOperator() == OO_Call; | ||||||
31 | } | ||||||
32 | |||||||
33 | inline bool isLambdaCallOperator(const DeclContext *DC) { | ||||||
34 | if (!DC || !isa<CXXMethodDecl>(DC)) return false; | ||||||
35 | return isLambdaCallOperator(cast<CXXMethodDecl>(DC)); | ||||||
36 | } | ||||||
37 | |||||||
38 | inline bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD) { | ||||||
39 | if (!MD) return false; | ||||||
40 | const CXXRecordDecl *LambdaClass = MD->getParent(); | ||||||
41 | if (LambdaClass && LambdaClass->isGenericLambda()) | ||||||
42 | return isLambdaCallOperator(MD) && | ||||||
43 | MD->isFunctionTemplateSpecialization(); | ||||||
44 | return false; | ||||||
45 | } | ||||||
46 | |||||||
47 | inline bool isLambdaConversionOperator(CXXConversionDecl *C) { | ||||||
48 | return C ? C->getParent()->isLambda() : false; | ||||||
49 | } | ||||||
50 | |||||||
51 | inline bool isLambdaConversionOperator(Decl *D) { | ||||||
52 | if (!D) return false; | ||||||
53 | if (CXXConversionDecl *Conv = dyn_cast<CXXConversionDecl>(D)) | ||||||
54 | return isLambdaConversionOperator(Conv); | ||||||
55 | if (FunctionTemplateDecl *F = dyn_cast<FunctionTemplateDecl>(D)) | ||||||
56 | if (CXXConversionDecl *Conv = | ||||||
57 | dyn_cast_or_null<CXXConversionDecl>(F->getTemplatedDecl())) | ||||||
58 | return isLambdaConversionOperator(Conv); | ||||||
59 | return false; | ||||||
60 | } | ||||||
61 | |||||||
62 | inline bool isGenericLambdaCallOperatorSpecialization(DeclContext *DC) { | ||||||
63 | return isGenericLambdaCallOperatorSpecialization( | ||||||
64 | dyn_cast<CXXMethodDecl>(DC)); | ||||||
65 | } | ||||||
66 | |||||||
67 | inline bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization( | ||||||
68 | DeclContext *DC) { | ||||||
69 | CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC); | ||||||
70 | if (!MD) return false; | ||||||
71 | const CXXRecordDecl *LambdaClass = MD->getParent(); | ||||||
72 | if (LambdaClass && LambdaClass->isGenericLambda()) | ||||||
73 | return (isLambdaCallOperator(MD) || MD->isLambdaStaticInvoker()) && | ||||||
74 | MD->isFunctionTemplateSpecialization(); | ||||||
75 | return false; | ||||||
76 | } | ||||||
77 | |||||||
78 | |||||||
79 | // This returns the parent DeclContext ensuring that the correct | ||||||
80 | // parent DeclContext is returned for Lambdas | ||||||
81 | inline DeclContext *getLambdaAwareParentOfDeclContext(DeclContext *DC) { | ||||||
82 | if (isLambdaCallOperator(DC)) | ||||||
83 | return DC->getParent()->getParent(); | ||||||
84 | else | ||||||
85 | return DC->getParent(); | ||||||
86 | } | ||||||
87 | |||||||
88 | } // clang | ||||||
89 | |||||||
90 | #endif |
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/ASTUnresolvedSet.h" |
19 | #include "clang/AST/Decl.h" |
20 | #include "clang/AST/DeclBase.h" |
21 | #include "clang/AST/DeclarationName.h" |
22 | #include "clang/AST/Expr.h" |
23 | #include "clang/AST/ExternalASTSource.h" |
24 | #include "clang/AST/LambdaCapture.h" |
25 | #include "clang/AST/NestedNameSpecifier.h" |
26 | #include "clang/AST/Redeclarable.h" |
27 | #include "clang/AST/Stmt.h" |
28 | #include "clang/AST/Type.h" |
29 | #include "clang/AST/TypeLoc.h" |
30 | #include "clang/AST/UnresolvedSet.h" |
31 | #include "clang/Basic/LLVM.h" |
32 | #include "clang/Basic/Lambda.h" |
33 | #include "clang/Basic/LangOptions.h" |
34 | #include "clang/Basic/OperatorKinds.h" |
35 | #include "clang/Basic/SourceLocation.h" |
36 | #include "clang/Basic/Specifiers.h" |
37 | #include "llvm/ADT/ArrayRef.h" |
38 | #include "llvm/ADT/DenseMap.h" |
39 | #include "llvm/ADT/PointerIntPair.h" |
40 | #include "llvm/ADT/PointerUnion.h" |
41 | #include "llvm/ADT/STLExtras.h" |
42 | #include "llvm/ADT/TinyPtrVector.h" |
43 | #include "llvm/ADT/iterator_range.h" |
44 | #include "llvm/Support/Casting.h" |
45 | #include "llvm/Support/Compiler.h" |
46 | #include "llvm/Support/PointerLikeTypeTraits.h" |
47 | #include "llvm/Support/TrailingObjects.h" |
48 | #include <cassert> |
49 | #include <cstddef> |
50 | #include <iterator> |
51 | #include <memory> |
52 | #include <vector> |
53 | |
54 | namespace clang { |
55 | |
56 | class ASTContext; |
57 | class ClassTemplateDecl; |
58 | class ConstructorUsingShadowDecl; |
59 | class CXXBasePath; |
60 | class CXXBasePaths; |
61 | class CXXConstructorDecl; |
62 | class CXXDestructorDecl; |
63 | class CXXFinalOverriderMap; |
64 | class CXXIndirectPrimaryBaseSet; |
65 | class CXXMethodDecl; |
66 | class DecompositionDecl; |
67 | class DiagnosticBuilder; |
68 | class FriendDecl; |
69 | class FunctionTemplateDecl; |
70 | class IdentifierInfo; |
71 | class MemberSpecializationInfo; |
72 | class BaseUsingDecl; |
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 | #define FIELD(Name, Width, Merge) \ |
281 | unsigned Name : Width; |
282 | #include "CXXRecordDeclDefinitionBits.def" |
283 | |
284 | /// Whether this class describes a C++ lambda. |
285 | unsigned IsLambda : 1; |
286 | |
287 | /// Whether we are currently parsing base specifiers. |
288 | unsigned IsParsingBaseSpecifiers : 1; |
289 | |
290 | /// True when visible conversion functions are already computed |
291 | /// and are available. |
292 | unsigned ComputedVisibleConversions : 1; |
293 | |
294 | unsigned HasODRHash : 1; |
295 | |
296 | /// A hash of parts of the class to help in ODR checking. |
297 | unsigned ODRHash = 0; |
298 | |
299 | /// The number of base class specifiers in Bases. |
300 | unsigned NumBases = 0; |
301 | |
302 | /// The number of virtual base class specifiers in VBases. |
303 | unsigned NumVBases = 0; |
304 | |
305 | /// Base classes of this class. |
306 | /// |
307 | /// FIXME: This is wasted space for a union. |
308 | LazyCXXBaseSpecifiersPtr Bases; |
309 | |
310 | /// direct and indirect virtual base classes of this class. |
311 | LazyCXXBaseSpecifiersPtr VBases; |
312 | |
313 | /// The conversion functions of this C++ class (but not its |
314 | /// inherited conversion functions). |
315 | /// |
316 | /// Each of the entries in this overload set is a CXXConversionDecl. |
317 | LazyASTUnresolvedSet Conversions; |
318 | |
319 | /// The conversion functions of this C++ class and all those |
320 | /// inherited conversion functions that are visible in this class. |
321 | /// |
322 | /// Each of the entries in this overload set is a CXXConversionDecl or a |
323 | /// FunctionTemplateDecl. |
324 | LazyASTUnresolvedSet VisibleConversions; |
325 | |
326 | /// The declaration which defines this record. |
327 | CXXRecordDecl *Definition; |
328 | |
329 | /// The first friend declaration in this class, or null if there |
330 | /// aren't any. |
331 | /// |
332 | /// This is actually currently stored in reverse order. |
333 | LazyDeclPtr FirstFriend; |
334 | |
335 | DefinitionData(CXXRecordDecl *D); |
336 | |
337 | /// Retrieve the set of direct base classes. |
338 | CXXBaseSpecifier *getBases() const { |
339 | if (!Bases.isOffset()) |
340 | return Bases.get(nullptr); |
341 | return getBasesSlowCase(); |
342 | } |
343 | |
344 | /// Retrieve the set of virtual base classes. |
345 | CXXBaseSpecifier *getVBases() const { |
346 | if (!VBases.isOffset()) |
347 | return VBases.get(nullptr); |
348 | return getVBasesSlowCase(); |
349 | } |
350 | |
351 | ArrayRef<CXXBaseSpecifier> bases() const { |
352 | return llvm::makeArrayRef(getBases(), NumBases); |
353 | } |
354 | |
355 | ArrayRef<CXXBaseSpecifier> vbases() const { |
356 | return llvm::makeArrayRef(getVBases(), NumVBases); |
357 | } |
358 | |
359 | private: |
360 | CXXBaseSpecifier *getBasesSlowCase() const; |
361 | CXXBaseSpecifier *getVBasesSlowCase() const; |
362 | }; |
363 | |
364 | struct DefinitionData *DefinitionData; |
365 | |
366 | /// Describes a C++ closure type (generated by a lambda expression). |
367 | struct LambdaDefinitionData : public DefinitionData { |
368 | using Capture = LambdaCapture; |
369 | |
370 | /// Whether this lambda is known to be dependent, even if its |
371 | /// context isn't dependent. |
372 | /// |
373 | /// A lambda with a non-dependent context can be dependent if it occurs |
374 | /// within the default argument of a function template, because the |
375 | /// lambda will have been created with the enclosing context as its |
376 | /// declaration context, rather than function. This is an unfortunate |
377 | /// artifact of having to parse the default arguments before. |
378 | unsigned Dependent : 1; |
379 | |
380 | /// Whether this lambda is a generic lambda. |
381 | unsigned IsGenericLambda : 1; |
382 | |
383 | /// The Default Capture. |
384 | unsigned CaptureDefault : 2; |
385 | |
386 | /// The number of captures in this lambda is limited 2^NumCaptures. |
387 | unsigned NumCaptures : 15; |
388 | |
389 | /// The number of explicit captures in this lambda. |
390 | unsigned NumExplicitCaptures : 13; |
391 | |
392 | /// Has known `internal` linkage. |
393 | unsigned HasKnownInternalLinkage : 1; |
394 | |
395 | /// The number used to indicate this lambda expression for name |
396 | /// mangling in the Itanium C++ ABI. |
397 | unsigned ManglingNumber : 31; |
398 | |
399 | /// The declaration that provides context for this lambda, if the |
400 | /// actual DeclContext does not suffice. This is used for lambdas that |
401 | /// occur within default arguments of function parameters within the class |
402 | /// or within a data member initializer. |
403 | LazyDeclPtr ContextDecl; |
404 | |
405 | /// The list of captures, both explicit and implicit, for this |
406 | /// lambda. |
407 | Capture *Captures = nullptr; |
408 | |
409 | /// The type of the call method. |
410 | TypeSourceInfo *MethodTyInfo; |
411 | |
412 | LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info, bool Dependent, |
413 | bool IsGeneric, LambdaCaptureDefault CaptureDefault) |
414 | : DefinitionData(D), Dependent(Dependent), IsGenericLambda(IsGeneric), |
415 | CaptureDefault(CaptureDefault), NumCaptures(0), |
416 | NumExplicitCaptures(0), HasKnownInternalLinkage(0), ManglingNumber(0), |
417 | MethodTyInfo(Info) { |
418 | IsLambda = true; |
419 | |
420 | // C++1z [expr.prim.lambda]p4: |
421 | // This class type is not an aggregate type. |
422 | Aggregate = false; |
423 | PlainOldData = false; |
424 | } |
425 | }; |
426 | |
427 | struct DefinitionData *dataPtr() const { |
428 | // Complete the redecl chain (if necessary). |
429 | getMostRecentDecl(); |
430 | return DefinitionData; |
431 | } |
432 | |
433 | struct DefinitionData &data() const { |
434 | auto *DD = dataPtr(); |
435 | assert(DD && "queried property of class with no definition")(static_cast <bool> (DD && "queried property of class with no definition" ) ? void (0) : __assert_fail ("DD && \"queried property of class with no definition\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 435, __extension__ __PRETTY_FUNCTION__)); |
436 | return *DD; |
437 | } |
438 | |
439 | struct LambdaDefinitionData &getLambdaData() const { |
440 | // No update required: a merged definition cannot change any lambda |
441 | // properties. |
442 | auto *DD = DefinitionData; |
443 | assert(DD && DD->IsLambda && "queried lambda property of non-lambda class")(static_cast <bool> (DD && DD->IsLambda && "queried lambda property of non-lambda class") ? void (0) : __assert_fail ("DD && DD->IsLambda && \"queried lambda property of non-lambda class\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 443, __extension__ __PRETTY_FUNCTION__)); |
444 | return static_cast<LambdaDefinitionData&>(*DD); |
445 | } |
446 | |
447 | /// The template or declaration that this declaration |
448 | /// describes or was instantiated from, respectively. |
449 | /// |
450 | /// For non-templates, this value will be null. For record |
451 | /// declarations that describe a class template, this will be a |
452 | /// pointer to a ClassTemplateDecl. For member |
453 | /// classes of class template specializations, this will be the |
454 | /// MemberSpecializationInfo referring to the member class that was |
455 | /// instantiated or specialized. |
456 | llvm::PointerUnion<ClassTemplateDecl *, MemberSpecializationInfo *> |
457 | TemplateOrInstantiation; |
458 | |
459 | /// Called from setBases and addedMember to notify the class that a |
460 | /// direct or virtual base class or a member of class type has been added. |
461 | void addedClassSubobject(CXXRecordDecl *Base); |
462 | |
463 | /// Notify the class that member has been added. |
464 | /// |
465 | /// This routine helps maintain information about the class based on which |
466 | /// members have been added. It will be invoked by DeclContext::addDecl() |
467 | /// whenever a member is added to this record. |
468 | void addedMember(Decl *D); |
469 | |
470 | void markedVirtualFunctionPure(); |
471 | |
472 | /// Get the head of our list of friend declarations, possibly |
473 | /// deserializing the friends from an external AST source. |
474 | FriendDecl *getFirstFriend() const; |
475 | |
476 | /// Determine whether this class has an empty base class subobject of type X |
477 | /// or of one of the types that might be at offset 0 within X (per the C++ |
478 | /// "standard layout" rules). |
479 | bool hasSubobjectAtOffsetZeroOfEmptyBaseType(ASTContext &Ctx, |
480 | const CXXRecordDecl *X); |
481 | |
482 | protected: |
483 | CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, DeclContext *DC, |
484 | SourceLocation StartLoc, SourceLocation IdLoc, |
485 | IdentifierInfo *Id, CXXRecordDecl *PrevDecl); |
486 | |
487 | public: |
488 | /// Iterator that traverses the base classes of a class. |
489 | using base_class_iterator = CXXBaseSpecifier *; |
490 | |
491 | /// Iterator that traverses the base classes of a class. |
492 | using base_class_const_iterator = const CXXBaseSpecifier *; |
493 | |
494 | CXXRecordDecl *getCanonicalDecl() override { |
495 | return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); |
496 | } |
497 | |
498 | const CXXRecordDecl *getCanonicalDecl() const { |
499 | return const_cast<CXXRecordDecl*>(this)->getCanonicalDecl(); |
500 | } |
501 | |
502 | CXXRecordDecl *getPreviousDecl() { |
503 | return cast_or_null<CXXRecordDecl>( |
504 | static_cast<RecordDecl *>(this)->getPreviousDecl()); |
505 | } |
506 | |
507 | const CXXRecordDecl *getPreviousDecl() const { |
508 | return const_cast<CXXRecordDecl*>(this)->getPreviousDecl(); |
509 | } |
510 | |
511 | CXXRecordDecl *getMostRecentDecl() { |
512 | return cast<CXXRecordDecl>( |
513 | static_cast<RecordDecl *>(this)->getMostRecentDecl()); |
514 | } |
515 | |
516 | const CXXRecordDecl *getMostRecentDecl() const { |
517 | return const_cast<CXXRecordDecl*>(this)->getMostRecentDecl(); |
518 | } |
519 | |
520 | CXXRecordDecl *getMostRecentNonInjectedDecl() { |
521 | CXXRecordDecl *Recent = |
522 | static_cast<CXXRecordDecl *>(this)->getMostRecentDecl(); |
523 | while (Recent->isInjectedClassName()) { |
524 | // FIXME: Does injected class name need to be in the redeclarations chain? |
525 | assert(Recent->getPreviousDecl())(static_cast <bool> (Recent->getPreviousDecl()) ? void (0) : __assert_fail ("Recent->getPreviousDecl()", "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 525, __extension__ __PRETTY_FUNCTION__)); |
526 | Recent = Recent->getPreviousDecl(); |
527 | } |
528 | return Recent; |
529 | } |
530 | |
531 | const CXXRecordDecl *getMostRecentNonInjectedDecl() const { |
532 | return const_cast<CXXRecordDecl*>(this)->getMostRecentNonInjectedDecl(); |
533 | } |
534 | |
535 | CXXRecordDecl *getDefinition() const { |
536 | // We only need an update if we don't already know which |
537 | // declaration is the definition. |
538 | auto *DD = DefinitionData ? DefinitionData : dataPtr(); |
539 | return DD ? DD->Definition : nullptr; |
540 | } |
541 | |
542 | bool hasDefinition() const { return DefinitionData || dataPtr(); } |
543 | |
544 | static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC, |
545 | SourceLocation StartLoc, SourceLocation IdLoc, |
546 | IdentifierInfo *Id, |
547 | CXXRecordDecl *PrevDecl = nullptr, |
548 | bool DelayTypeCreation = false); |
549 | static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC, |
550 | TypeSourceInfo *Info, SourceLocation Loc, |
551 | bool DependentLambda, bool IsGeneric, |
552 | LambdaCaptureDefault CaptureDefault); |
553 | static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID); |
554 | |
555 | bool isDynamicClass() const { |
556 | return data().Polymorphic || data().NumVBases != 0; |
557 | } |
558 | |
559 | /// @returns true if class is dynamic or might be dynamic because the |
560 | /// definition is incomplete of dependent. |
561 | bool mayBeDynamicClass() const { |
562 | return !hasDefinition() || isDynamicClass() || hasAnyDependentBases(); |
563 | } |
564 | |
565 | /// @returns true if class is non dynamic or might be non dynamic because the |
566 | /// definition is incomplete of dependent. |
567 | bool mayBeNonDynamicClass() const { |
568 | return !hasDefinition() || !isDynamicClass() || hasAnyDependentBases(); |
569 | } |
570 | |
571 | void setIsParsingBaseSpecifiers() { data().IsParsingBaseSpecifiers = true; } |
572 | |
573 | bool isParsingBaseSpecifiers() const { |
574 | return data().IsParsingBaseSpecifiers; |
575 | } |
576 | |
577 | unsigned getODRHash() const; |
578 | |
579 | /// Sets the base classes of this struct or class. |
580 | void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases); |
581 | |
582 | /// Retrieves the number of base classes of this class. |
583 | unsigned getNumBases() const { return data().NumBases; } |
584 | |
585 | using base_class_range = llvm::iterator_range<base_class_iterator>; |
586 | using base_class_const_range = |
587 | llvm::iterator_range<base_class_const_iterator>; |
588 | |
589 | base_class_range bases() { |
590 | return base_class_range(bases_begin(), bases_end()); |
591 | } |
592 | base_class_const_range bases() const { |
593 | return base_class_const_range(bases_begin(), bases_end()); |
594 | } |
595 | |
596 | base_class_iterator bases_begin() { return data().getBases(); } |
597 | base_class_const_iterator bases_begin() const { return data().getBases(); } |
598 | base_class_iterator bases_end() { return bases_begin() + data().NumBases; } |
599 | base_class_const_iterator bases_end() const { |
600 | return bases_begin() + data().NumBases; |
601 | } |
602 | |
603 | /// Retrieves the number of virtual base classes of this class. |
604 | unsigned getNumVBases() const { return data().NumVBases; } |
605 | |
606 | base_class_range vbases() { |
607 | return base_class_range(vbases_begin(), vbases_end()); |
608 | } |
609 | base_class_const_range vbases() const { |
610 | return base_class_const_range(vbases_begin(), vbases_end()); |
611 | } |
612 | |
613 | base_class_iterator vbases_begin() { return data().getVBases(); } |
614 | base_class_const_iterator vbases_begin() const { return data().getVBases(); } |
615 | base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; } |
616 | base_class_const_iterator vbases_end() const { |
617 | return vbases_begin() + data().NumVBases; |
618 | } |
619 | |
620 | /// Determine whether this class has any dependent base classes which |
621 | /// are not the current instantiation. |
622 | bool hasAnyDependentBases() const; |
623 | |
624 | /// Iterator access to method members. The method iterator visits |
625 | /// all method members of the class, including non-instance methods, |
626 | /// special methods, etc. |
627 | using method_iterator = specific_decl_iterator<CXXMethodDecl>; |
628 | using method_range = |
629 | llvm::iterator_range<specific_decl_iterator<CXXMethodDecl>>; |
630 | |
631 | method_range methods() const { |
632 | return method_range(method_begin(), method_end()); |
633 | } |
634 | |
635 | /// Method begin iterator. Iterates in the order the methods |
636 | /// were declared. |
637 | method_iterator method_begin() const { |
638 | return method_iterator(decls_begin()); |
639 | } |
640 | |
641 | /// Method past-the-end iterator. |
642 | method_iterator method_end() const { |
643 | return method_iterator(decls_end()); |
644 | } |
645 | |
646 | /// Iterator access to constructor members. |
647 | using ctor_iterator = specific_decl_iterator<CXXConstructorDecl>; |
648 | using ctor_range = |
649 | llvm::iterator_range<specific_decl_iterator<CXXConstructorDecl>>; |
650 | |
651 | ctor_range ctors() const { return ctor_range(ctor_begin(), ctor_end()); } |
652 | |
653 | ctor_iterator ctor_begin() const { |
654 | return ctor_iterator(decls_begin()); |
655 | } |
656 | |
657 | ctor_iterator ctor_end() const { |
658 | return ctor_iterator(decls_end()); |
659 | } |
660 | |
661 | /// An iterator over friend declarations. All of these are defined |
662 | /// in DeclFriend.h. |
663 | class friend_iterator; |
664 | using friend_range = llvm::iterator_range<friend_iterator>; |
665 | |
666 | friend_range friends() const; |
667 | friend_iterator friend_begin() const; |
668 | friend_iterator friend_end() const; |
669 | void pushFriendDecl(FriendDecl *FD); |
670 | |
671 | /// Determines whether this record has any friends. |
672 | bool hasFriends() const { |
673 | return data().FirstFriend.isValid(); |
674 | } |
675 | |
676 | /// \c true if a defaulted copy constructor for this class would be |
677 | /// deleted. |
678 | bool defaultedCopyConstructorIsDeleted() const { |
679 | assert((!needsOverloadResolutionForCopyConstructor() ||(static_cast <bool> ((!needsOverloadResolutionForCopyConstructor () || (data().DeclaredSpecialMembers & SMF_CopyConstructor )) && "this property has not yet been computed by Sema" ) ? void (0) : __assert_fail ("(!needsOverloadResolutionForCopyConstructor() || (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 681, __extension__ __PRETTY_FUNCTION__)) |
680 | (data().DeclaredSpecialMembers & SMF_CopyConstructor)) &&(static_cast <bool> ((!needsOverloadResolutionForCopyConstructor () || (data().DeclaredSpecialMembers & SMF_CopyConstructor )) && "this property has not yet been computed by Sema" ) ? void (0) : __assert_fail ("(!needsOverloadResolutionForCopyConstructor() || (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 681, __extension__ __PRETTY_FUNCTION__)) |
681 | "this property has not yet been computed by Sema")(static_cast <bool> ((!needsOverloadResolutionForCopyConstructor () || (data().DeclaredSpecialMembers & SMF_CopyConstructor )) && "this property has not yet been computed by Sema" ) ? void (0) : __assert_fail ("(!needsOverloadResolutionForCopyConstructor() || (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 681, __extension__ __PRETTY_FUNCTION__)); |
682 | return data().DefaultedCopyConstructorIsDeleted; |
683 | } |
684 | |
685 | /// \c true if a defaulted move constructor for this class would be |
686 | /// deleted. |
687 | bool defaultedMoveConstructorIsDeleted() const { |
688 | assert((!needsOverloadResolutionForMoveConstructor() ||(static_cast <bool> ((!needsOverloadResolutionForMoveConstructor () || (data().DeclaredSpecialMembers & SMF_MoveConstructor )) && "this property has not yet been computed by Sema" ) ? void (0) : __assert_fail ("(!needsOverloadResolutionForMoveConstructor() || (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 690, __extension__ __PRETTY_FUNCTION__)) |
689 | (data().DeclaredSpecialMembers & SMF_MoveConstructor)) &&(static_cast <bool> ((!needsOverloadResolutionForMoveConstructor () || (data().DeclaredSpecialMembers & SMF_MoveConstructor )) && "this property has not yet been computed by Sema" ) ? void (0) : __assert_fail ("(!needsOverloadResolutionForMoveConstructor() || (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 690, __extension__ __PRETTY_FUNCTION__)) |
690 | "this property has not yet been computed by Sema")(static_cast <bool> ((!needsOverloadResolutionForMoveConstructor () || (data().DeclaredSpecialMembers & SMF_MoveConstructor )) && "this property has not yet been computed by Sema" ) ? void (0) : __assert_fail ("(!needsOverloadResolutionForMoveConstructor() || (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 690, __extension__ __PRETTY_FUNCTION__)); |
691 | return data().DefaultedMoveConstructorIsDeleted; |
692 | } |
693 | |
694 | /// \c true if a defaulted destructor for this class would be deleted. |
695 | bool defaultedDestructorIsDeleted() const { |
696 | assert((!needsOverloadResolutionForDestructor() ||(static_cast <bool> ((!needsOverloadResolutionForDestructor () || (data().DeclaredSpecialMembers & SMF_Destructor)) && "this property has not yet been computed by Sema") ? void (0 ) : __assert_fail ("(!needsOverloadResolutionForDestructor() || (data().DeclaredSpecialMembers & SMF_Destructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 698, __extension__ __PRETTY_FUNCTION__)) |
697 | (data().DeclaredSpecialMembers & SMF_Destructor)) &&(static_cast <bool> ((!needsOverloadResolutionForDestructor () || (data().DeclaredSpecialMembers & SMF_Destructor)) && "this property has not yet been computed by Sema") ? void (0 ) : __assert_fail ("(!needsOverloadResolutionForDestructor() || (data().DeclaredSpecialMembers & SMF_Destructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 698, __extension__ __PRETTY_FUNCTION__)) |
698 | "this property has not yet been computed by Sema")(static_cast <bool> ((!needsOverloadResolutionForDestructor () || (data().DeclaredSpecialMembers & SMF_Destructor)) && "this property has not yet been computed by Sema") ? void (0 ) : __assert_fail ("(!needsOverloadResolutionForDestructor() || (data().DeclaredSpecialMembers & SMF_Destructor)) && \"this property has not yet been computed by Sema\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 698, __extension__ __PRETTY_FUNCTION__)); |
699 | return data().DefaultedDestructorIsDeleted; |
700 | } |
701 | |
702 | /// \c true if we know for sure that this class has a single, |
703 | /// accessible, unambiguous copy constructor that is not deleted. |
704 | bool hasSimpleCopyConstructor() const { |
705 | return !hasUserDeclaredCopyConstructor() && |
706 | !data().DefaultedCopyConstructorIsDeleted; |
707 | } |
708 | |
709 | /// \c true if we know for sure that this class has a single, |
710 | /// accessible, unambiguous move constructor that is not deleted. |
711 | bool hasSimpleMoveConstructor() const { |
712 | return !hasUserDeclaredMoveConstructor() && hasMoveConstructor() && |
713 | !data().DefaultedMoveConstructorIsDeleted; |
714 | } |
715 | |
716 | /// \c true if we know for sure that this class has a single, |
717 | /// accessible, unambiguous copy assignment operator that is not deleted. |
718 | bool hasSimpleCopyAssignment() const { |
719 | return !hasUserDeclaredCopyAssignment() && |
720 | !data().DefaultedCopyAssignmentIsDeleted; |
721 | } |
722 | |
723 | /// \c true if we know for sure that this class has a single, |
724 | /// accessible, unambiguous move assignment operator that is not deleted. |
725 | bool hasSimpleMoveAssignment() const { |
726 | return !hasUserDeclaredMoveAssignment() && hasMoveAssignment() && |
727 | !data().DefaultedMoveAssignmentIsDeleted; |
728 | } |
729 | |
730 | /// \c true if we know for sure that this class has an accessible |
731 | /// destructor that is not deleted. |
732 | bool hasSimpleDestructor() const { |
733 | return !hasUserDeclaredDestructor() && |
734 | !data().DefaultedDestructorIsDeleted; |
735 | } |
736 | |
737 | /// Determine whether this class has any default constructors. |
738 | bool hasDefaultConstructor() const { |
739 | return (data().DeclaredSpecialMembers & SMF_DefaultConstructor) || |
740 | needsImplicitDefaultConstructor(); |
741 | } |
742 | |
743 | /// Determine if we need to declare a default constructor for |
744 | /// this class. |
745 | /// |
746 | /// This value is used for lazy creation of default constructors. |
747 | bool needsImplicitDefaultConstructor() const { |
748 | return (!data().UserDeclaredConstructor && |
749 | !(data().DeclaredSpecialMembers & SMF_DefaultConstructor) && |
750 | (!isLambda() || lambdaIsDefaultConstructibleAndAssignable())) || |
751 | // FIXME: Proposed fix to core wording issue: if a class inherits |
752 | // a default constructor and doesn't explicitly declare one, one |
753 | // is declared implicitly. |
754 | (data().HasInheritedDefaultConstructor && |
755 | !(data().DeclaredSpecialMembers & SMF_DefaultConstructor)); |
756 | } |
757 | |
758 | /// Determine whether this class has any user-declared constructors. |
759 | /// |
760 | /// When true, a default constructor will not be implicitly declared. |
761 | bool hasUserDeclaredConstructor() const { |
762 | return data().UserDeclaredConstructor; |
763 | } |
764 | |
765 | /// Whether this class has a user-provided default constructor |
766 | /// per C++11. |
767 | bool hasUserProvidedDefaultConstructor() const { |
768 | return data().UserProvidedDefaultConstructor; |
769 | } |
770 | |
771 | /// Determine whether this class has a user-declared copy constructor. |
772 | /// |
773 | /// When false, a copy constructor will be implicitly declared. |
774 | bool hasUserDeclaredCopyConstructor() const { |
775 | return data().UserDeclaredSpecialMembers & SMF_CopyConstructor; |
776 | } |
777 | |
778 | /// Determine whether this class needs an implicit copy |
779 | /// constructor to be lazily declared. |
780 | bool needsImplicitCopyConstructor() const { |
781 | return !(data().DeclaredSpecialMembers & SMF_CopyConstructor); |
782 | } |
783 | |
784 | /// Determine whether we need to eagerly declare a defaulted copy |
785 | /// constructor for this class. |
786 | bool needsOverloadResolutionForCopyConstructor() const { |
787 | // C++17 [class.copy.ctor]p6: |
788 | // If the class definition declares a move constructor or move assignment |
789 | // operator, the implicitly declared copy constructor is defined as |
790 | // deleted. |
791 | // In MSVC mode, sometimes a declared move assignment does not delete an |
792 | // implicit copy constructor, so defer this choice to Sema. |
793 | if (data().UserDeclaredSpecialMembers & |
794 | (SMF_MoveConstructor | SMF_MoveAssignment)) |
795 | return true; |
796 | return data().NeedOverloadResolutionForCopyConstructor; |
797 | } |
798 | |
799 | /// Determine whether an implicit copy constructor for this type |
800 | /// would have a parameter with a const-qualified reference type. |
801 | bool implicitCopyConstructorHasConstParam() const { |
802 | return data().ImplicitCopyConstructorCanHaveConstParamForNonVBase && |
803 | (isAbstract() || |
804 | data().ImplicitCopyConstructorCanHaveConstParamForVBase); |
805 | } |
806 | |
807 | /// Determine whether this class has a copy constructor with |
808 | /// a parameter type which is a reference to a const-qualified type. |
809 | bool hasCopyConstructorWithConstParam() const { |
810 | return data().HasDeclaredCopyConstructorWithConstParam || |
811 | (needsImplicitCopyConstructor() && |
812 | implicitCopyConstructorHasConstParam()); |
813 | } |
814 | |
815 | /// Whether this class has a user-declared move constructor or |
816 | /// assignment operator. |
817 | /// |
818 | /// When false, a move constructor and assignment operator may be |
819 | /// implicitly declared. |
820 | bool hasUserDeclaredMoveOperation() const { |
821 | return data().UserDeclaredSpecialMembers & |
822 | (SMF_MoveConstructor | SMF_MoveAssignment); |
823 | } |
824 | |
825 | /// Determine whether this class has had a move constructor |
826 | /// declared by the user. |
827 | bool hasUserDeclaredMoveConstructor() const { |
828 | return data().UserDeclaredSpecialMembers & SMF_MoveConstructor; |
829 | } |
830 | |
831 | /// Determine whether this class has a move constructor. |
832 | bool hasMoveConstructor() const { |
833 | return (data().DeclaredSpecialMembers & SMF_MoveConstructor) || |
834 | needsImplicitMoveConstructor(); |
835 | } |
836 | |
837 | /// Set that we attempted to declare an implicit copy |
838 | /// constructor, but overload resolution failed so we deleted it. |
839 | void setImplicitCopyConstructorIsDeleted() { |
840 | assert((data().DefaultedCopyConstructorIsDeleted ||(static_cast <bool> ((data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor()) && "Copy constructor should not be deleted" ) ? void (0) : __assert_fail ("(data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor()) && \"Copy constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 842, __extension__ __PRETTY_FUNCTION__)) |
841 | needsOverloadResolutionForCopyConstructor()) &&(static_cast <bool> ((data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor()) && "Copy constructor should not be deleted" ) ? void (0) : __assert_fail ("(data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor()) && \"Copy constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 842, __extension__ __PRETTY_FUNCTION__)) |
842 | "Copy constructor should not be deleted")(static_cast <bool> ((data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor()) && "Copy constructor should not be deleted" ) ? void (0) : __assert_fail ("(data().DefaultedCopyConstructorIsDeleted || needsOverloadResolutionForCopyConstructor()) && \"Copy constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 842, __extension__ __PRETTY_FUNCTION__)); |
843 | data().DefaultedCopyConstructorIsDeleted = true; |
844 | } |
845 | |
846 | /// Set that we attempted to declare an implicit move |
847 | /// constructor, but overload resolution failed so we deleted it. |
848 | void setImplicitMoveConstructorIsDeleted() { |
849 | assert((data().DefaultedMoveConstructorIsDeleted ||(static_cast <bool> ((data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor()) && "move constructor should not be deleted" ) ? void (0) : __assert_fail ("(data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor()) && \"move constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 851, __extension__ __PRETTY_FUNCTION__)) |
850 | needsOverloadResolutionForMoveConstructor()) &&(static_cast <bool> ((data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor()) && "move constructor should not be deleted" ) ? void (0) : __assert_fail ("(data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor()) && \"move constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 851, __extension__ __PRETTY_FUNCTION__)) |
851 | "move constructor should not be deleted")(static_cast <bool> ((data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor()) && "move constructor should not be deleted" ) ? void (0) : __assert_fail ("(data().DefaultedMoveConstructorIsDeleted || needsOverloadResolutionForMoveConstructor()) && \"move constructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 851, __extension__ __PRETTY_FUNCTION__)); |
852 | data().DefaultedMoveConstructorIsDeleted = true; |
853 | } |
854 | |
855 | /// Set that we attempted to declare an implicit destructor, |
856 | /// but overload resolution failed so we deleted it. |
857 | void setImplicitDestructorIsDeleted() { |
858 | assert((data().DefaultedDestructorIsDeleted ||(static_cast <bool> ((data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor()) && "destructor should not be deleted" ) ? void (0) : __assert_fail ("(data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor()) && \"destructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 860, __extension__ __PRETTY_FUNCTION__)) |
859 | needsOverloadResolutionForDestructor()) &&(static_cast <bool> ((data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor()) && "destructor should not be deleted" ) ? void (0) : __assert_fail ("(data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor()) && \"destructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 860, __extension__ __PRETTY_FUNCTION__)) |
860 | "destructor should not be deleted")(static_cast <bool> ((data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor()) && "destructor should not be deleted" ) ? void (0) : __assert_fail ("(data().DefaultedDestructorIsDeleted || needsOverloadResolutionForDestructor()) && \"destructor should not be deleted\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 860, __extension__ __PRETTY_FUNCTION__)); |
861 | data().DefaultedDestructorIsDeleted = true; |
862 | } |
863 | |
864 | /// Determine whether this class should get an implicit move |
865 | /// constructor or if any existing special member function inhibits this. |
866 | bool needsImplicitMoveConstructor() const { |
867 | return !(data().DeclaredSpecialMembers & SMF_MoveConstructor) && |
868 | !hasUserDeclaredCopyConstructor() && |
869 | !hasUserDeclaredCopyAssignment() && |
870 | !hasUserDeclaredMoveAssignment() && |
871 | !hasUserDeclaredDestructor(); |
872 | } |
873 | |
874 | /// Determine whether we need to eagerly declare a defaulted move |
875 | /// constructor for this class. |
876 | bool needsOverloadResolutionForMoveConstructor() const { |
877 | return data().NeedOverloadResolutionForMoveConstructor; |
878 | } |
879 | |
880 | /// Determine whether this class has a user-declared copy assignment |
881 | /// operator. |
882 | /// |
883 | /// When false, a copy assignment operator will be implicitly declared. |
884 | bool hasUserDeclaredCopyAssignment() const { |
885 | return data().UserDeclaredSpecialMembers & SMF_CopyAssignment; |
886 | } |
887 | |
888 | /// Set that we attempted to declare an implicit copy assignment |
889 | /// operator, but overload resolution failed so we deleted it. |
890 | void setImplicitCopyAssignmentIsDeleted() { |
891 | assert((data().DefaultedCopyAssignmentIsDeleted ||(static_cast <bool> ((data().DefaultedCopyAssignmentIsDeleted || needsOverloadResolutionForCopyAssignment()) && "copy assignment should not be deleted" ) ? void (0) : __assert_fail ("(data().DefaultedCopyAssignmentIsDeleted || needsOverloadResolutionForCopyAssignment()) && \"copy assignment should not be deleted\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 893, __extension__ __PRETTY_FUNCTION__)) |
892 | needsOverloadResolutionForCopyAssignment()) &&(static_cast <bool> ((data().DefaultedCopyAssignmentIsDeleted || needsOverloadResolutionForCopyAssignment()) && "copy assignment should not be deleted" ) ? void (0) : __assert_fail ("(data().DefaultedCopyAssignmentIsDeleted || needsOverloadResolutionForCopyAssignment()) && \"copy assignment should not be deleted\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 893, __extension__ __PRETTY_FUNCTION__)) |
893 | "copy assignment should not be deleted")(static_cast <bool> ((data().DefaultedCopyAssignmentIsDeleted || needsOverloadResolutionForCopyAssignment()) && "copy assignment should not be deleted" ) ? void (0) : __assert_fail ("(data().DefaultedCopyAssignmentIsDeleted || needsOverloadResolutionForCopyAssignment()) && \"copy assignment should not be deleted\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 893, __extension__ __PRETTY_FUNCTION__)); |
894 | data().DefaultedCopyAssignmentIsDeleted = true; |
895 | } |
896 | |
897 | /// Determine whether this class needs an implicit copy |
898 | /// assignment operator to be lazily declared. |
899 | bool needsImplicitCopyAssignment() const { |
900 | return !(data().DeclaredSpecialMembers & SMF_CopyAssignment); |
901 | } |
902 | |
903 | /// Determine whether we need to eagerly declare a defaulted copy |
904 | /// assignment operator for this class. |
905 | bool needsOverloadResolutionForCopyAssignment() const { |
906 | // C++20 [class.copy.assign]p2: |
907 | // If the class definition declares a move constructor or move assignment |
908 | // operator, the implicitly declared copy assignment operator is defined |
909 | // as deleted. |
910 | // In MSVC mode, sometimes a declared move constructor does not delete an |
911 | // implicit copy assignment, so defer this choice to Sema. |
912 | if (data().UserDeclaredSpecialMembers & |
913 | (SMF_MoveConstructor | SMF_MoveAssignment)) |
914 | return true; |
915 | return data().NeedOverloadResolutionForCopyAssignment; |
916 | } |
917 | |
918 | /// Determine whether an implicit copy assignment operator for this |
919 | /// type would have a parameter with a const-qualified reference type. |
920 | bool implicitCopyAssignmentHasConstParam() const { |
921 | return data().ImplicitCopyAssignmentHasConstParam; |
922 | } |
923 | |
924 | /// Determine whether this class has a copy assignment operator with |
925 | /// a parameter type which is a reference to a const-qualified type or is not |
926 | /// a reference. |
927 | bool hasCopyAssignmentWithConstParam() const { |
928 | return data().HasDeclaredCopyAssignmentWithConstParam || |
929 | (needsImplicitCopyAssignment() && |
930 | implicitCopyAssignmentHasConstParam()); |
931 | } |
932 | |
933 | /// Determine whether this class has had a move assignment |
934 | /// declared by the user. |
935 | bool hasUserDeclaredMoveAssignment() const { |
936 | return data().UserDeclaredSpecialMembers & SMF_MoveAssignment; |
937 | } |
938 | |
939 | /// Determine whether this class has a move assignment operator. |
940 | bool hasMoveAssignment() const { |
941 | return (data().DeclaredSpecialMembers & SMF_MoveAssignment) || |
942 | needsImplicitMoveAssignment(); |
943 | } |
944 | |
945 | /// Set that we attempted to declare an implicit move assignment |
946 | /// operator, but overload resolution failed so we deleted it. |
947 | void setImplicitMoveAssignmentIsDeleted() { |
948 | assert((data().DefaultedMoveAssignmentIsDeleted ||(static_cast <bool> ((data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment()) && "move assignment should not be deleted" ) ? void (0) : __assert_fail ("(data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment()) && \"move assignment should not be deleted\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 950, __extension__ __PRETTY_FUNCTION__)) |
949 | needsOverloadResolutionForMoveAssignment()) &&(static_cast <bool> ((data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment()) && "move assignment should not be deleted" ) ? void (0) : __assert_fail ("(data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment()) && \"move assignment should not be deleted\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 950, __extension__ __PRETTY_FUNCTION__)) |
950 | "move assignment should not be deleted")(static_cast <bool> ((data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment()) && "move assignment should not be deleted" ) ? void (0) : __assert_fail ("(data().DefaultedMoveAssignmentIsDeleted || needsOverloadResolutionForMoveAssignment()) && \"move assignment should not be deleted\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 950, __extension__ __PRETTY_FUNCTION__)); |
951 | data().DefaultedMoveAssignmentIsDeleted = true; |
952 | } |
953 | |
954 | /// Determine whether this class should get an implicit move |
955 | /// assignment operator or if any existing special member function inhibits |
956 | /// this. |
957 | bool needsImplicitMoveAssignment() const { |
958 | return !(data().DeclaredSpecialMembers & SMF_MoveAssignment) && |
959 | !hasUserDeclaredCopyConstructor() && |
960 | !hasUserDeclaredCopyAssignment() && |
961 | !hasUserDeclaredMoveConstructor() && |
962 | !hasUserDeclaredDestructor() && |
963 | (!isLambda() || lambdaIsDefaultConstructibleAndAssignable()); |
964 | } |
965 | |
966 | /// Determine whether we need to eagerly declare a move assignment |
967 | /// operator for this class. |
968 | bool needsOverloadResolutionForMoveAssignment() const { |
969 | return data().NeedOverloadResolutionForMoveAssignment; |
970 | } |
971 | |
972 | /// Determine whether this class has a user-declared destructor. |
973 | /// |
974 | /// When false, a destructor will be implicitly declared. |
975 | bool hasUserDeclaredDestructor() const { |
976 | return data().UserDeclaredSpecialMembers & SMF_Destructor; |
977 | } |
978 | |
979 | /// Determine whether this class needs an implicit destructor to |
980 | /// be lazily declared. |
981 | bool needsImplicitDestructor() const { |
982 | return !(data().DeclaredSpecialMembers & SMF_Destructor); |
983 | } |
984 | |
985 | /// Determine whether we need to eagerly declare a destructor for this |
986 | /// class. |
987 | bool needsOverloadResolutionForDestructor() const { |
988 | return data().NeedOverloadResolutionForDestructor; |
989 | } |
990 | |
991 | /// Determine whether this class describes a lambda function object. |
992 | bool isLambda() const { |
993 | // An update record can't turn a non-lambda into a lambda. |
994 | auto *DD = DefinitionData; |
995 | return DD && DD->IsLambda; |
996 | } |
997 | |
998 | /// Determine whether this class describes a generic |
999 | /// lambda function object (i.e. function call operator is |
1000 | /// a template). |
1001 | bool isGenericLambda() const; |
1002 | |
1003 | /// Determine whether this lambda should have an implicit default constructor |
1004 | /// and copy and move assignment operators. |
1005 | bool lambdaIsDefaultConstructibleAndAssignable() const; |
1006 | |
1007 | /// Retrieve the lambda call operator of the closure type |
1008 | /// if this is a closure type. |
1009 | CXXMethodDecl *getLambdaCallOperator() const; |
1010 | |
1011 | /// Retrieve the dependent lambda call operator of the closure type |
1012 | /// if this is a templated closure type. |
1013 | FunctionTemplateDecl *getDependentLambdaCallOperator() const; |
1014 | |
1015 | /// Retrieve the lambda static invoker, the address of which |
1016 | /// is returned by the conversion operator, and the body of which |
1017 | /// is forwarded to the lambda call operator. The version that does not |
1018 | /// take a calling convention uses the 'default' calling convention for free |
1019 | /// functions if the Lambda's calling convention was not modified via |
1020 | /// attribute. Otherwise, it will return the calling convention specified for |
1021 | /// the lambda. |
1022 | CXXMethodDecl *getLambdaStaticInvoker() const; |
1023 | CXXMethodDecl *getLambdaStaticInvoker(CallingConv CC) const; |
1024 | |
1025 | /// Retrieve the generic lambda's template parameter list. |
1026 | /// Returns null if the class does not represent a lambda or a generic |
1027 | /// lambda. |
1028 | TemplateParameterList *getGenericLambdaTemplateParameterList() const; |
1029 | |
1030 | /// Retrieve the lambda template parameters that were specified explicitly. |
1031 | ArrayRef<NamedDecl *> getLambdaExplicitTemplateParameters() const; |
1032 | |
1033 | LambdaCaptureDefault getLambdaCaptureDefault() const { |
1034 | assert(isLambda())(static_cast <bool> (isLambda()) ? void (0) : __assert_fail ("isLambda()", "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 1034, __extension__ __PRETTY_FUNCTION__)); |
1035 | return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault); |
1036 | } |
1037 | |
1038 | /// Set the captures for this lambda closure type. |
1039 | void setCaptures(ASTContext &Context, ArrayRef<LambdaCapture> Captures); |
1040 | |
1041 | /// For a closure type, retrieve the mapping from captured |
1042 | /// variables and \c this to the non-static data members that store the |
1043 | /// values or references of the captures. |
1044 | /// |
1045 | /// \param Captures Will be populated with the mapping from captured |
1046 | /// variables to the corresponding fields. |
1047 | /// |
1048 | /// \param ThisCapture Will be set to the field declaration for the |
1049 | /// \c this capture. |
1050 | /// |
1051 | /// \note No entries will be added for init-captures, as they do not capture |
1052 | /// variables. |
1053 | void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures, |
1054 | FieldDecl *&ThisCapture) const; |
1055 | |
1056 | using capture_const_iterator = const LambdaCapture *; |
1057 | using capture_const_range = llvm::iterator_range<capture_const_iterator>; |
1058 | |
1059 | capture_const_range captures() const { |
1060 | return capture_const_range(captures_begin(), captures_end()); |
1061 | } |
1062 | |
1063 | capture_const_iterator captures_begin() const { |
1064 | return isLambda() ? getLambdaData().Captures : nullptr; |
1065 | } |
1066 | |
1067 | capture_const_iterator captures_end() const { |
1068 | return isLambda() ? captures_begin() + getLambdaData().NumCaptures |
1069 | : nullptr; |
1070 | } |
1071 | |
1072 | unsigned capture_size() const { return getLambdaData().NumCaptures; } |
1073 | |
1074 | using conversion_iterator = UnresolvedSetIterator; |
1075 | |
1076 | conversion_iterator conversion_begin() const { |
1077 | return data().Conversions.get(getASTContext()).begin(); |
1078 | } |
1079 | |
1080 | conversion_iterator conversion_end() const { |
1081 | return data().Conversions.get(getASTContext()).end(); |
1082 | } |
1083 | |
1084 | /// Removes a conversion function from this class. The conversion |
1085 | /// function must currently be a member of this class. Furthermore, |
1086 | /// this class must currently be in the process of being defined. |
1087 | void removeConversion(const NamedDecl *Old); |
1088 | |
1089 | /// Get all conversion functions visible in current class, |
1090 | /// including conversion function templates. |
1091 | llvm::iterator_range<conversion_iterator> |
1092 | getVisibleConversionFunctions() const; |
1093 | |
1094 | /// Determine whether this class is an aggregate (C++ [dcl.init.aggr]), |
1095 | /// which is a class with no user-declared constructors, no private |
1096 | /// or protected non-static data members, no base classes, and no virtual |
1097 | /// functions (C++ [dcl.init.aggr]p1). |
1098 | bool isAggregate() const { return data().Aggregate; } |
1099 | |
1100 | /// Whether this class has any in-class initializers |
1101 | /// for non-static data members (including those in anonymous unions or |
1102 | /// structs). |
1103 | bool hasInClassInitializer() const { return data().HasInClassInitializer; } |
1104 | |
1105 | /// Whether this class or any of its subobjects has any members of |
1106 | /// reference type which would make value-initialization ill-formed. |
1107 | /// |
1108 | /// Per C++03 [dcl.init]p5: |
1109 | /// - if T is a non-union class type without a user-declared constructor, |
1110 | /// then every non-static data member and base-class component of T is |
1111 | /// value-initialized [...] A program that calls for [...] |
1112 | /// value-initialization of an entity of reference type is ill-formed. |
1113 | bool hasUninitializedReferenceMember() const { |
1114 | return !isUnion() && !hasUserDeclaredConstructor() && |
1115 | data().HasUninitializedReferenceMember; |
1116 | } |
1117 | |
1118 | /// Whether this class is a POD-type (C++ [class]p4) |
1119 | /// |
1120 | /// For purposes of this function a class is POD if it is an aggregate |
1121 | /// that has no non-static non-POD data members, no reference data |
1122 | /// members, no user-defined copy assignment operator and no |
1123 | /// user-defined destructor. |
1124 | /// |
1125 | /// Note that this is the C++ TR1 definition of POD. |
1126 | bool isPOD() const { return data().PlainOldData; } |
1127 | |
1128 | /// True if this class is C-like, without C++-specific features, e.g. |
1129 | /// it contains only public fields, no bases, tag kind is not 'class', etc. |
1130 | bool isCLike() const; |
1131 | |
1132 | /// Determine whether this is an empty class in the sense of |
1133 | /// (C++11 [meta.unary.prop]). |
1134 | /// |
1135 | /// The CXXRecordDecl is a class type, but not a union type, |
1136 | /// with no non-static data members other than bit-fields of length 0, |
1137 | /// no virtual member functions, no virtual base classes, |
1138 | /// and no base class B for which is_empty<B>::value is false. |
1139 | /// |
1140 | /// \note This does NOT include a check for union-ness. |
1141 | bool isEmpty() const { return data().Empty; } |
1142 | |
1143 | bool hasPrivateFields() const { |
1144 | return data().HasPrivateFields; |
1145 | } |
1146 | |
1147 | bool hasProtectedFields() const { |
1148 | return data().HasProtectedFields; |
1149 | } |
1150 | |
1151 | /// Determine whether this class has direct non-static data members. |
1152 | bool hasDirectFields() const { |
1153 | auto &D = data(); |
1154 | return D.HasPublicFields || D.HasProtectedFields || D.HasPrivateFields; |
1155 | } |
1156 | |
1157 | /// Whether this class is polymorphic (C++ [class.virtual]), |
1158 | /// which means that the class contains or inherits a virtual function. |
1159 | bool isPolymorphic() const { return data().Polymorphic; } |
1160 | |
1161 | /// Determine whether this class has a pure virtual function. |
1162 | /// |
1163 | /// The class is is abstract per (C++ [class.abstract]p2) if it declares |
1164 | /// a pure virtual function or inherits a pure virtual function that is |
1165 | /// not overridden. |
1166 | bool isAbstract() const { return data().Abstract; } |
1167 | |
1168 | /// Determine whether this class is standard-layout per |
1169 | /// C++ [class]p7. |
1170 | bool isStandardLayout() const { return data().IsStandardLayout; } |
1171 | |
1172 | /// Determine whether this class was standard-layout per |
1173 | /// C++11 [class]p7, specifically using the C++11 rules without any DRs. |
1174 | bool isCXX11StandardLayout() const { return data().IsCXX11StandardLayout; } |
1175 | |
1176 | /// Determine whether this class, or any of its class subobjects, |
1177 | /// contains a mutable field. |
1178 | bool hasMutableFields() const { return data().HasMutableFields; } |
1179 | |
1180 | /// Determine whether this class has any variant members. |
1181 | bool hasVariantMembers() const { return data().HasVariantMembers; } |
1182 | |
1183 | /// Determine whether this class has a trivial default constructor |
1184 | /// (C++11 [class.ctor]p5). |
1185 | bool hasTrivialDefaultConstructor() const { |
1186 | return hasDefaultConstructor() && |
1187 | (data().HasTrivialSpecialMembers & SMF_DefaultConstructor); |
1188 | } |
1189 | |
1190 | /// Determine whether this class has a non-trivial default constructor |
1191 | /// (C++11 [class.ctor]p5). |
1192 | bool hasNonTrivialDefaultConstructor() const { |
1193 | return (data().DeclaredNonTrivialSpecialMembers & SMF_DefaultConstructor) || |
1194 | (needsImplicitDefaultConstructor() && |
1195 | !(data().HasTrivialSpecialMembers & SMF_DefaultConstructor)); |
1196 | } |
1197 | |
1198 | /// Determine whether this class has at least one constexpr constructor |
1199 | /// other than the copy or move constructors. |
1200 | bool hasConstexprNonCopyMoveConstructor() const { |
1201 | return data().HasConstexprNonCopyMoveConstructor || |
1202 | (needsImplicitDefaultConstructor() && |
1203 | defaultedDefaultConstructorIsConstexpr()); |
1204 | } |
1205 | |
1206 | /// Determine whether a defaulted default constructor for this class |
1207 | /// would be constexpr. |
1208 | bool defaultedDefaultConstructorIsConstexpr() const { |
1209 | return data().DefaultedDefaultConstructorIsConstexpr && |
1210 | (!isUnion() || hasInClassInitializer() || !hasVariantMembers() || |
1211 | getLangOpts().CPlusPlus20); |
1212 | } |
1213 | |
1214 | /// Determine whether this class has a constexpr default constructor. |
1215 | bool hasConstexprDefaultConstructor() const { |
1216 | return data().HasConstexprDefaultConstructor || |
1217 | (needsImplicitDefaultConstructor() && |
1218 | defaultedDefaultConstructorIsConstexpr()); |
1219 | } |
1220 | |
1221 | /// Determine whether this class has a trivial copy constructor |
1222 | /// (C++ [class.copy]p6, C++11 [class.copy]p12) |
1223 | bool hasTrivialCopyConstructor() const { |
1224 | return data().HasTrivialSpecialMembers & SMF_CopyConstructor; |
1225 | } |
1226 | |
1227 | bool hasTrivialCopyConstructorForCall() const { |
1228 | return data().HasTrivialSpecialMembersForCall & SMF_CopyConstructor; |
1229 | } |
1230 | |
1231 | /// Determine whether this class has a non-trivial copy constructor |
1232 | /// (C++ [class.copy]p6, C++11 [class.copy]p12) |
1233 | bool hasNonTrivialCopyConstructor() const { |
1234 | return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor || |
1235 | !hasTrivialCopyConstructor(); |
1236 | } |
1237 | |
1238 | bool hasNonTrivialCopyConstructorForCall() const { |
1239 | return (data().DeclaredNonTrivialSpecialMembersForCall & |
1240 | SMF_CopyConstructor) || |
1241 | !hasTrivialCopyConstructorForCall(); |
1242 | } |
1243 | |
1244 | /// Determine whether this class has a trivial move constructor |
1245 | /// (C++11 [class.copy]p12) |
1246 | bool hasTrivialMoveConstructor() const { |
1247 | return hasMoveConstructor() && |
1248 | (data().HasTrivialSpecialMembers & SMF_MoveConstructor); |
1249 | } |
1250 | |
1251 | bool hasTrivialMoveConstructorForCall() const { |
1252 | return hasMoveConstructor() && |
1253 | (data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor); |
1254 | } |
1255 | |
1256 | /// Determine whether this class has a non-trivial move constructor |
1257 | /// (C++11 [class.copy]p12) |
1258 | bool hasNonTrivialMoveConstructor() const { |
1259 | return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveConstructor) || |
1260 | (needsImplicitMoveConstructor() && |
1261 | !(data().HasTrivialSpecialMembers & SMF_MoveConstructor)); |
1262 | } |
1263 | |
1264 | bool hasNonTrivialMoveConstructorForCall() const { |
1265 | return (data().DeclaredNonTrivialSpecialMembersForCall & |
1266 | SMF_MoveConstructor) || |
1267 | (needsImplicitMoveConstructor() && |
1268 | !(data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor)); |
1269 | } |
1270 | |
1271 | /// Determine whether this class has a trivial copy assignment operator |
1272 | /// (C++ [class.copy]p11, C++11 [class.copy]p25) |
1273 | bool hasTrivialCopyAssignment() const { |
1274 | return data().HasTrivialSpecialMembers & SMF_CopyAssignment; |
1275 | } |
1276 | |
1277 | /// Determine whether this class has a non-trivial copy assignment |
1278 | /// operator (C++ [class.copy]p11, C++11 [class.copy]p25) |
1279 | bool hasNonTrivialCopyAssignment() const { |
1280 | return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment || |
1281 | !hasTrivialCopyAssignment(); |
1282 | } |
1283 | |
1284 | /// Determine whether this class has a trivial move assignment operator |
1285 | /// (C++11 [class.copy]p25) |
1286 | bool hasTrivialMoveAssignment() const { |
1287 | return hasMoveAssignment() && |
1288 | (data().HasTrivialSpecialMembers & SMF_MoveAssignment); |
1289 | } |
1290 | |
1291 | /// Determine whether this class has a non-trivial move assignment |
1292 | /// operator (C++11 [class.copy]p25) |
1293 | bool hasNonTrivialMoveAssignment() const { |
1294 | return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveAssignment) || |
1295 | (needsImplicitMoveAssignment() && |
1296 | !(data().HasTrivialSpecialMembers & SMF_MoveAssignment)); |
1297 | } |
1298 | |
1299 | /// Determine whether a defaulted default constructor for this class |
1300 | /// would be constexpr. |
1301 | bool defaultedDestructorIsConstexpr() const { |
1302 | return data().DefaultedDestructorIsConstexpr && |
1303 | getLangOpts().CPlusPlus20; |
1304 | } |
1305 | |
1306 | /// Determine whether this class has a constexpr destructor. |
1307 | bool hasConstexprDestructor() const; |
1308 | |
1309 | /// Determine whether this class has a trivial destructor |
1310 | /// (C++ [class.dtor]p3) |
1311 | bool hasTrivialDestructor() const { |
1312 | return data().HasTrivialSpecialMembers & SMF_Destructor; |
1313 | } |
1314 | |
1315 | bool hasTrivialDestructorForCall() const { |
1316 | return data().HasTrivialSpecialMembersForCall & SMF_Destructor; |
1317 | } |
1318 | |
1319 | /// Determine whether this class has a non-trivial destructor |
1320 | /// (C++ [class.dtor]p3) |
1321 | bool hasNonTrivialDestructor() const { |
1322 | return !(data().HasTrivialSpecialMembers & SMF_Destructor); |
1323 | } |
1324 | |
1325 | bool hasNonTrivialDestructorForCall() const { |
1326 | return !(data().HasTrivialSpecialMembersForCall & SMF_Destructor); |
1327 | } |
1328 | |
1329 | void setHasTrivialSpecialMemberForCall() { |
1330 | data().HasTrivialSpecialMembersForCall = |
1331 | (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor); |
1332 | } |
1333 | |
1334 | /// Determine whether declaring a const variable with this type is ok |
1335 | /// per core issue 253. |
1336 | bool allowConstDefaultInit() const { |
1337 | return !data().HasUninitializedFields || |
1338 | !(data().HasDefaultedDefaultConstructor || |
1339 | needsImplicitDefaultConstructor()); |
1340 | } |
1341 | |
1342 | /// Determine whether this class has a destructor which has no |
1343 | /// semantic effect. |
1344 | /// |
1345 | /// Any such destructor will be trivial, public, defaulted and not deleted, |
1346 | /// and will call only irrelevant destructors. |
1347 | bool hasIrrelevantDestructor() const { |
1348 | return data().HasIrrelevantDestructor; |
1349 | } |
1350 | |
1351 | /// Determine whether this class has a non-literal or/ volatile type |
1352 | /// non-static data member or base class. |
1353 | bool hasNonLiteralTypeFieldsOrBases() const { |
1354 | return data().HasNonLiteralTypeFieldsOrBases; |
1355 | } |
1356 | |
1357 | /// Determine whether this class has a using-declaration that names |
1358 | /// a user-declared base class constructor. |
1359 | bool hasInheritedConstructor() const { |
1360 | return data().HasInheritedConstructor; |
1361 | } |
1362 | |
1363 | /// Determine whether this class has a using-declaration that names |
1364 | /// a base class assignment operator. |
1365 | bool hasInheritedAssignment() const { |
1366 | return data().HasInheritedAssignment; |
1367 | } |
1368 | |
1369 | /// Determine whether this class is considered trivially copyable per |
1370 | /// (C++11 [class]p6). |
1371 | bool isTriviallyCopyable() const; |
1372 | |
1373 | /// Determine whether this class is considered trivial. |
1374 | /// |
1375 | /// C++11 [class]p6: |
1376 | /// "A trivial class is a class that has a trivial default constructor and |
1377 | /// is trivially copyable." |
1378 | bool isTrivial() const { |
1379 | return isTriviallyCopyable() && hasTrivialDefaultConstructor(); |
1380 | } |
1381 | |
1382 | /// Determine whether this class is a literal type. |
1383 | /// |
1384 | /// C++11 [basic.types]p10: |
1385 | /// A class type that has all the following properties: |
1386 | /// - it has a trivial destructor |
1387 | /// - every constructor call and full-expression in the |
1388 | /// brace-or-equal-intializers for non-static data members (if any) is |
1389 | /// a constant expression. |
1390 | /// - it is an aggregate type or has at least one constexpr constructor |
1391 | /// or constructor template that is not a copy or move constructor, and |
1392 | /// - all of its non-static data members and base classes are of literal |
1393 | /// types |
1394 | /// |
1395 | /// We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by |
1396 | /// treating types with trivial default constructors as literal types. |
1397 | /// |
1398 | /// Only in C++17 and beyond, are lambdas literal types. |
1399 | bool isLiteral() const { |
1400 | const LangOptions &LangOpts = getLangOpts(); |
1401 | return (LangOpts.CPlusPlus20 ? hasConstexprDestructor() |
1402 | : hasTrivialDestructor()) && |
1403 | (!isLambda() || LangOpts.CPlusPlus17) && |
1404 | !hasNonLiteralTypeFieldsOrBases() && |
1405 | (isAggregate() || isLambda() || |
1406 | hasConstexprNonCopyMoveConstructor() || |
1407 | hasTrivialDefaultConstructor()); |
1408 | } |
1409 | |
1410 | /// Determine whether this is a structural type. |
1411 | bool isStructural() const { |
1412 | return isLiteral() && data().StructuralIfLiteral; |
1413 | } |
1414 | |
1415 | /// If this record is an instantiation of a member class, |
1416 | /// retrieves the member class from which it was instantiated. |
1417 | /// |
1418 | /// This routine will return non-null for (non-templated) member |
1419 | /// classes of class templates. For example, given: |
1420 | /// |
1421 | /// \code |
1422 | /// template<typename T> |
1423 | /// struct X { |
1424 | /// struct A { }; |
1425 | /// }; |
1426 | /// \endcode |
1427 | /// |
1428 | /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl |
1429 | /// whose parent is the class template specialization X<int>. For |
1430 | /// this declaration, getInstantiatedFromMemberClass() will return |
1431 | /// the CXXRecordDecl X<T>::A. When a complete definition of |
1432 | /// X<int>::A is required, it will be instantiated from the |
1433 | /// declaration returned by getInstantiatedFromMemberClass(). |
1434 | CXXRecordDecl *getInstantiatedFromMemberClass() const; |
1435 | |
1436 | /// If this class is an instantiation of a member class of a |
1437 | /// class template specialization, retrieves the member specialization |
1438 | /// information. |
1439 | MemberSpecializationInfo *getMemberSpecializationInfo() const; |
1440 | |
1441 | /// Specify that this record is an instantiation of the |
1442 | /// member class \p RD. |
1443 | void setInstantiationOfMemberClass(CXXRecordDecl *RD, |
1444 | TemplateSpecializationKind TSK); |
1445 | |
1446 | /// Retrieves the class template that is described by this |
1447 | /// class declaration. |
1448 | /// |
1449 | /// Every class template is represented as a ClassTemplateDecl and a |
1450 | /// CXXRecordDecl. The former contains template properties (such as |
1451 | /// the template parameter lists) while the latter contains the |
1452 | /// actual description of the template's |
1453 | /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the |
1454 | /// CXXRecordDecl that from a ClassTemplateDecl, while |
1455 | /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from |
1456 | /// a CXXRecordDecl. |
1457 | ClassTemplateDecl *getDescribedClassTemplate() const; |
1458 | |
1459 | void setDescribedClassTemplate(ClassTemplateDecl *Template); |
1460 | |
1461 | /// Determine whether this particular class is a specialization or |
1462 | /// instantiation of a class template or member class of a class template, |
1463 | /// and how it was instantiated or specialized. |
1464 | TemplateSpecializationKind getTemplateSpecializationKind() const; |
1465 | |
1466 | /// Set the kind of specialization or template instantiation this is. |
1467 | void setTemplateSpecializationKind(TemplateSpecializationKind TSK); |
1468 | |
1469 | /// Retrieve the record declaration from which this record could be |
1470 | /// instantiated. Returns null if this class is not a template instantiation. |
1471 | const CXXRecordDecl *getTemplateInstantiationPattern() const; |
1472 | |
1473 | CXXRecordDecl *getTemplateInstantiationPattern() { |
1474 | return const_cast<CXXRecordDecl *>(const_cast<const CXXRecordDecl *>(this) |
1475 | ->getTemplateInstantiationPattern()); |
1476 | } |
1477 | |
1478 | /// Returns the destructor decl for this class. |
1479 | CXXDestructorDecl *getDestructor() const; |
1480 | |
1481 | /// Returns true if the class destructor, or any implicitly invoked |
1482 | /// destructors are marked noreturn. |
1483 | bool isAnyDestructorNoReturn() const { return data().IsAnyDestructorNoReturn; } |
1484 | |
1485 | /// If the class is a local class [class.local], returns |
1486 | /// the enclosing function declaration. |
1487 | const FunctionDecl *isLocalClass() const { |
1488 | if (const auto *RD = dyn_cast<CXXRecordDecl>(getDeclContext())) |
1489 | return RD->isLocalClass(); |
1490 | |
1491 | return dyn_cast<FunctionDecl>(getDeclContext()); |
1492 | } |
1493 | |
1494 | FunctionDecl *isLocalClass() { |
1495 | return const_cast<FunctionDecl*>( |
1496 | const_cast<const CXXRecordDecl*>(this)->isLocalClass()); |
1497 | } |
1498 | |
1499 | /// Determine whether this dependent class is a current instantiation, |
1500 | /// when viewed from within the given context. |
1501 | bool isCurrentInstantiation(const DeclContext *CurContext) const; |
1502 | |
1503 | /// Determine whether this class is derived from the class \p Base. |
1504 | /// |
1505 | /// This routine only determines whether this class is derived from \p Base, |
1506 | /// but does not account for factors that may make a Derived -> Base class |
1507 | /// ill-formed, such as private/protected inheritance or multiple, ambiguous |
1508 | /// base class subobjects. |
1509 | /// |
1510 | /// \param Base the base class we are searching for. |
1511 | /// |
1512 | /// \returns true if this class is derived from Base, false otherwise. |
1513 | bool isDerivedFrom(const CXXRecordDecl *Base) const; |
1514 | |
1515 | /// Determine whether this class is derived from the type \p Base. |
1516 | /// |
1517 | /// This routine only determines whether this class is derived from \p Base, |
1518 | /// but does not account for factors that may make a Derived -> Base class |
1519 | /// ill-formed, such as private/protected inheritance or multiple, ambiguous |
1520 | /// base class subobjects. |
1521 | /// |
1522 | /// \param Base the base class we are searching for. |
1523 | /// |
1524 | /// \param Paths will contain the paths taken from the current class to the |
1525 | /// given \p Base class. |
1526 | /// |
1527 | /// \returns true if this class is derived from \p Base, false otherwise. |
1528 | /// |
1529 | /// \todo add a separate parameter to configure IsDerivedFrom, rather than |
1530 | /// tangling input and output in \p Paths |
1531 | bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const; |
1532 | |
1533 | /// Determine whether this class is virtually derived from |
1534 | /// the class \p Base. |
1535 | /// |
1536 | /// This routine only determines whether this class is virtually |
1537 | /// derived from \p Base, but does not account for factors that may |
1538 | /// make a Derived -> Base class ill-formed, such as |
1539 | /// private/protected inheritance or multiple, ambiguous base class |
1540 | /// subobjects. |
1541 | /// |
1542 | /// \param Base the base class we are searching for. |
1543 | /// |
1544 | /// \returns true if this class is virtually derived from Base, |
1545 | /// false otherwise. |
1546 | bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const; |
1547 | |
1548 | /// Determine whether this class is provably not derived from |
1549 | /// the type \p Base. |
1550 | bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const; |
1551 | |
1552 | /// Function type used by forallBases() as a callback. |
1553 | /// |
1554 | /// \param BaseDefinition the definition of the base class |
1555 | /// |
1556 | /// \returns true if this base matched the search criteria |
1557 | using ForallBasesCallback = |
1558 | llvm::function_ref<bool(const CXXRecordDecl *BaseDefinition)>; |
1559 | |
1560 | /// Determines if the given callback holds for all the direct |
1561 | /// or indirect base classes of this type. |
1562 | /// |
1563 | /// The class itself does not count as a base class. This routine |
1564 | /// returns false if the class has non-computable base classes. |
1565 | /// |
1566 | /// \param BaseMatches Callback invoked for each (direct or indirect) base |
1567 | /// class of this type until a call returns false. |
1568 | bool forallBases(ForallBasesCallback BaseMatches) const; |
1569 | |
1570 | /// Function type used by lookupInBases() to determine whether a |
1571 | /// specific base class subobject matches the lookup criteria. |
1572 | /// |
1573 | /// \param Specifier the base-class specifier that describes the inheritance |
1574 | /// from the base class we are trying to match. |
1575 | /// |
1576 | /// \param Path the current path, from the most-derived class down to the |
1577 | /// base named by the \p Specifier. |
1578 | /// |
1579 | /// \returns true if this base matched the search criteria, false otherwise. |
1580 | using BaseMatchesCallback = |
1581 | llvm::function_ref<bool(const CXXBaseSpecifier *Specifier, |
1582 | CXXBasePath &Path)>; |
1583 | |
1584 | /// Look for entities within the base classes of this C++ class, |
1585 | /// transitively searching all base class subobjects. |
1586 | /// |
1587 | /// This routine uses the callback function \p BaseMatches to find base |
1588 | /// classes meeting some search criteria, walking all base class subobjects |
1589 | /// and populating the given \p Paths structure with the paths through the |
1590 | /// inheritance hierarchy that resulted in a match. On a successful search, |
1591 | /// the \p Paths structure can be queried to retrieve the matching paths and |
1592 | /// to determine if there were any ambiguities. |
1593 | /// |
1594 | /// \param BaseMatches callback function used to determine whether a given |
1595 | /// base matches the user-defined search criteria. |
1596 | /// |
1597 | /// \param Paths used to record the paths from this class to its base class |
1598 | /// subobjects that match the search criteria. |
1599 | /// |
1600 | /// \param LookupInDependent can be set to true to extend the search to |
1601 | /// dependent base classes. |
1602 | /// |
1603 | /// \returns true if there exists any path from this class to a base class |
1604 | /// subobject that matches the search criteria. |
1605 | bool lookupInBases(BaseMatchesCallback BaseMatches, CXXBasePaths &Paths, |
1606 | bool LookupInDependent = false) const; |
1607 | |
1608 | /// Base-class lookup callback that determines whether the given |
1609 | /// base class specifier refers to a specific class declaration. |
1610 | /// |
1611 | /// This callback can be used with \c lookupInBases() to determine whether |
1612 | /// a given derived class has is a base class subobject of a particular type. |
1613 | /// The base record pointer should refer to the canonical CXXRecordDecl of the |
1614 | /// base class that we are searching for. |
1615 | static bool FindBaseClass(const CXXBaseSpecifier *Specifier, |
1616 | CXXBasePath &Path, const CXXRecordDecl *BaseRecord); |
1617 | |
1618 | /// Base-class lookup callback that determines whether the |
1619 | /// given base class specifier refers to a specific class |
1620 | /// declaration and describes virtual derivation. |
1621 | /// |
1622 | /// This callback can be used with \c lookupInBases() to determine |
1623 | /// whether a given derived class has is a virtual base class |
1624 | /// subobject of a particular type. The base record pointer should |
1625 | /// refer to the canonical CXXRecordDecl of the base class that we |
1626 | /// are searching for. |
1627 | static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier, |
1628 | CXXBasePath &Path, |
1629 | const CXXRecordDecl *BaseRecord); |
1630 | |
1631 | /// Retrieve the final overriders for each virtual member |
1632 | /// function in the class hierarchy where this class is the |
1633 | /// most-derived class in the class hierarchy. |
1634 | void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const; |
1635 | |
1636 | /// Get the indirect primary bases for this class. |
1637 | void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const; |
1638 | |
1639 | /// Determine whether this class has a member with the given name, possibly |
1640 | /// in a non-dependent base class. |
1641 | /// |
1642 | /// No check for ambiguity is performed, so this should never be used when |
1643 | /// implementing language semantics, but it may be appropriate for warnings, |
1644 | /// static analysis, or similar. |
1645 | bool hasMemberName(DeclarationName N) const; |
1646 | |
1647 | /// Performs an imprecise lookup of a dependent name in this class. |
1648 | /// |
1649 | /// This function does not follow strict semantic rules and should be used |
1650 | /// only when lookup rules can be relaxed, e.g. indexing. |
1651 | std::vector<const NamedDecl *> |
1652 | lookupDependentName(DeclarationName Name, |
1653 | llvm::function_ref<bool(const NamedDecl *ND)> Filter); |
1654 | |
1655 | /// Renders and displays an inheritance diagram |
1656 | /// for this C++ class and all of its base classes (transitively) using |
1657 | /// GraphViz. |
1658 | void viewInheritance(ASTContext& Context) const; |
1659 | |
1660 | /// Calculates the access of a decl that is reached |
1661 | /// along a path. |
1662 | static AccessSpecifier MergeAccess(AccessSpecifier PathAccess, |
1663 | AccessSpecifier DeclAccess) { |
1664 | assert(DeclAccess != AS_none)(static_cast <bool> (DeclAccess != AS_none) ? void (0) : __assert_fail ("DeclAccess != AS_none", "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 1664, __extension__ __PRETTY_FUNCTION__)); |
1665 | if (DeclAccess == AS_private) return AS_none; |
1666 | return (PathAccess > DeclAccess ? PathAccess : DeclAccess); |
1667 | } |
1668 | |
1669 | /// Indicates that the declaration of a defaulted or deleted special |
1670 | /// member function is now complete. |
1671 | void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD); |
1672 | |
1673 | void setTrivialForCallFlags(CXXMethodDecl *MD); |
1674 | |
1675 | /// Indicates that the definition of this class is now complete. |
1676 | void completeDefinition() override; |
1677 | |
1678 | /// Indicates that the definition of this class is now complete, |
1679 | /// and provides a final overrider map to help determine |
1680 | /// |
1681 | /// \param FinalOverriders The final overrider map for this class, which can |
1682 | /// be provided as an optimization for abstract-class checking. If NULL, |
1683 | /// final overriders will be computed if they are needed to complete the |
1684 | /// definition. |
1685 | void completeDefinition(CXXFinalOverriderMap *FinalOverriders); |
1686 | |
1687 | /// Determine whether this class may end up being abstract, even though |
1688 | /// it is not yet known to be abstract. |
1689 | /// |
1690 | /// \returns true if this class is not known to be abstract but has any |
1691 | /// base classes that are abstract. In this case, \c completeDefinition() |
1692 | /// will need to compute final overriders to determine whether the class is |
1693 | /// actually abstract. |
1694 | bool mayBeAbstract() const; |
1695 | |
1696 | /// Determine whether it's impossible for a class to be derived from this |
1697 | /// class. This is best-effort, and may conservatively return false. |
1698 | bool isEffectivelyFinal() const; |
1699 | |
1700 | /// If this is the closure type of a lambda expression, retrieve the |
1701 | /// number to be used for name mangling in the Itanium C++ ABI. |
1702 | /// |
1703 | /// Zero indicates that this closure type has internal linkage, so the |
1704 | /// mangling number does not matter, while a non-zero value indicates which |
1705 | /// lambda expression this is in this particular context. |
1706 | unsigned getLambdaManglingNumber() const { |
1707 | assert(isLambda() && "Not a lambda closure type!")(static_cast <bool> (isLambda() && "Not a lambda closure type!" ) ? void (0) : __assert_fail ("isLambda() && \"Not a lambda closure type!\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 1707, __extension__ __PRETTY_FUNCTION__)); |
1708 | return getLambdaData().ManglingNumber; |
1709 | } |
1710 | |
1711 | /// The lambda is known to has internal linkage no matter whether it has name |
1712 | /// mangling number. |
1713 | bool hasKnownLambdaInternalLinkage() const { |
1714 | assert(isLambda() && "Not a lambda closure type!")(static_cast <bool> (isLambda() && "Not a lambda closure type!" ) ? void (0) : __assert_fail ("isLambda() && \"Not a lambda closure type!\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 1714, __extension__ __PRETTY_FUNCTION__)); |
1715 | return getLambdaData().HasKnownInternalLinkage; |
1716 | } |
1717 | |
1718 | /// Retrieve the declaration that provides additional context for a |
1719 | /// lambda, when the normal declaration context is not specific enough. |
1720 | /// |
1721 | /// Certain contexts (default arguments of in-class function parameters and |
1722 | /// the initializers of data members) have separate name mangling rules for |
1723 | /// lambdas within the Itanium C++ ABI. For these cases, this routine provides |
1724 | /// the declaration in which the lambda occurs, e.g., the function parameter |
1725 | /// or the non-static data member. Otherwise, it returns NULL to imply that |
1726 | /// the declaration context suffices. |
1727 | Decl *getLambdaContextDecl() const; |
1728 | |
1729 | /// Set the mangling number and context declaration for a lambda |
1730 | /// class. |
1731 | void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl, |
1732 | bool HasKnownInternalLinkage = false) { |
1733 | assert(isLambda() && "Not a lambda closure type!")(static_cast <bool> (isLambda() && "Not a lambda closure type!" ) ? void (0) : __assert_fail ("isLambda() && \"Not a lambda closure type!\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 1733, __extension__ __PRETTY_FUNCTION__)); |
1734 | getLambdaData().ManglingNumber = ManglingNumber; |
1735 | getLambdaData().ContextDecl = ContextDecl; |
1736 | getLambdaData().HasKnownInternalLinkage = HasKnownInternalLinkage; |
1737 | } |
1738 | |
1739 | /// Set the device side mangling number. |
1740 | void setDeviceLambdaManglingNumber(unsigned Num) const; |
1741 | |
1742 | /// Retrieve the device side mangling number. |
1743 | unsigned getDeviceLambdaManglingNumber() const; |
1744 | |
1745 | /// Returns the inheritance model used for this record. |
1746 | MSInheritanceModel getMSInheritanceModel() const; |
1747 | |
1748 | /// Calculate what the inheritance model would be for this class. |
1749 | MSInheritanceModel calculateInheritanceModel() const; |
1750 | |
1751 | /// In the Microsoft C++ ABI, use zero for the field offset of a null data |
1752 | /// member pointer if we can guarantee that zero is not a valid field offset, |
1753 | /// or if the member pointer has multiple fields. Polymorphic classes have a |
1754 | /// vfptr at offset zero, so we can use zero for null. If there are multiple |
1755 | /// fields, we can use zero even if it is a valid field offset because |
1756 | /// null-ness testing will check the other fields. |
1757 | bool nullFieldOffsetIsZero() const; |
1758 | |
1759 | /// Controls when vtordisps will be emitted if this record is used as a |
1760 | /// virtual base. |
1761 | MSVtorDispMode getMSVtorDispMode() const; |
1762 | |
1763 | /// Determine whether this lambda expression was known to be dependent |
1764 | /// at the time it was created, even if its context does not appear to be |
1765 | /// dependent. |
1766 | /// |
1767 | /// This flag is a workaround for an issue with parsing, where default |
1768 | /// arguments are parsed before their enclosing function declarations have |
1769 | /// been created. This means that any lambda expressions within those |
1770 | /// default arguments will have as their DeclContext the context enclosing |
1771 | /// the function declaration, which may be non-dependent even when the |
1772 | /// function declaration itself is dependent. This flag indicates when we |
1773 | /// know that the lambda is dependent despite that. |
1774 | bool isDependentLambda() const { |
1775 | return isLambda() && getLambdaData().Dependent; |
1776 | } |
1777 | |
1778 | TypeSourceInfo *getLambdaTypeInfo() const { |
1779 | return getLambdaData().MethodTyInfo; |
1780 | } |
1781 | |
1782 | // Determine whether this type is an Interface Like type for |
1783 | // __interface inheritance purposes. |
1784 | bool isInterfaceLike() const; |
1785 | |
1786 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1787 | static bool classofKind(Kind K) { |
1788 | return K >= firstCXXRecord && K <= lastCXXRecord; |
1789 | } |
1790 | void markAbstract() { data().Abstract = true; } |
1791 | }; |
1792 | |
1793 | /// Store information needed for an explicit specifier. |
1794 | /// Used by CXXDeductionGuideDecl, CXXConstructorDecl and CXXConversionDecl. |
1795 | class ExplicitSpecifier { |
1796 | llvm::PointerIntPair<Expr *, 2, ExplicitSpecKind> ExplicitSpec{ |
1797 | nullptr, ExplicitSpecKind::ResolvedFalse}; |
1798 | |
1799 | public: |
1800 | ExplicitSpecifier() = default; |
1801 | ExplicitSpecifier(Expr *Expression, ExplicitSpecKind Kind) |
1802 | : ExplicitSpec(Expression, Kind) {} |
1803 | ExplicitSpecKind getKind() const { return ExplicitSpec.getInt(); } |
1804 | const Expr *getExpr() const { return ExplicitSpec.getPointer(); } |
1805 | Expr *getExpr() { return ExplicitSpec.getPointer(); } |
1806 | |
1807 | /// Determine if the declaration had an explicit specifier of any kind. |
1808 | bool isSpecified() const { |
1809 | return ExplicitSpec.getInt() != ExplicitSpecKind::ResolvedFalse || |
1810 | ExplicitSpec.getPointer(); |
1811 | } |
1812 | |
1813 | /// Check for equivalence of explicit specifiers. |
1814 | /// \return true if the explicit specifier are equivalent, false otherwise. |
1815 | bool isEquivalent(const ExplicitSpecifier Other) const; |
1816 | /// Determine whether this specifier is known to correspond to an explicit |
1817 | /// declaration. Returns false if the specifier is absent or has an |
1818 | /// expression that is value-dependent or evaluates to false. |
1819 | bool isExplicit() const { |
1820 | return ExplicitSpec.getInt() == ExplicitSpecKind::ResolvedTrue; |
1821 | } |
1822 | /// Determine if the explicit specifier is invalid. |
1823 | /// This state occurs after a substitution failures. |
1824 | bool isInvalid() const { |
1825 | return ExplicitSpec.getInt() == ExplicitSpecKind::Unresolved && |
1826 | !ExplicitSpec.getPointer(); |
1827 | } |
1828 | void setKind(ExplicitSpecKind Kind) { ExplicitSpec.setInt(Kind); } |
1829 | void setExpr(Expr *E) { ExplicitSpec.setPointer(E); } |
1830 | // Retrieve the explicit specifier in the given declaration, if any. |
1831 | static ExplicitSpecifier getFromDecl(FunctionDecl *Function); |
1832 | static const ExplicitSpecifier getFromDecl(const FunctionDecl *Function) { |
1833 | return getFromDecl(const_cast<FunctionDecl *>(Function)); |
1834 | } |
1835 | static ExplicitSpecifier Invalid() { |
1836 | return ExplicitSpecifier(nullptr, ExplicitSpecKind::Unresolved); |
1837 | } |
1838 | }; |
1839 | |
1840 | /// Represents a C++ deduction guide declaration. |
1841 | /// |
1842 | /// \code |
1843 | /// template<typename T> struct A { A(); A(T); }; |
1844 | /// A() -> A<int>; |
1845 | /// \endcode |
1846 | /// |
1847 | /// In this example, there will be an explicit deduction guide from the |
1848 | /// second line, and implicit deduction guide templates synthesized from |
1849 | /// the constructors of \c A. |
1850 | class CXXDeductionGuideDecl : public FunctionDecl { |
1851 | void anchor() override; |
1852 | |
1853 | private: |
1854 | CXXDeductionGuideDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
1855 | ExplicitSpecifier ES, |
1856 | const DeclarationNameInfo &NameInfo, QualType T, |
1857 | TypeSourceInfo *TInfo, SourceLocation EndLocation, |
1858 | CXXConstructorDecl *Ctor) |
1859 | : FunctionDecl(CXXDeductionGuide, C, DC, StartLoc, NameInfo, T, TInfo, |
1860 | SC_None, false, false, ConstexprSpecKind::Unspecified), |
1861 | Ctor(Ctor), ExplicitSpec(ES) { |
1862 | if (EndLocation.isValid()) |
1863 | setRangeEnd(EndLocation); |
1864 | setIsCopyDeductionCandidate(false); |
1865 | } |
1866 | |
1867 | CXXConstructorDecl *Ctor; |
1868 | ExplicitSpecifier ExplicitSpec; |
1869 | void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; } |
1870 | |
1871 | public: |
1872 | friend class ASTDeclReader; |
1873 | friend class ASTDeclWriter; |
1874 | |
1875 | static CXXDeductionGuideDecl * |
1876 | Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
1877 | ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T, |
1878 | TypeSourceInfo *TInfo, SourceLocation EndLocation, |
1879 | CXXConstructorDecl *Ctor = nullptr); |
1880 | |
1881 | static CXXDeductionGuideDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
1882 | |
1883 | ExplicitSpecifier getExplicitSpecifier() { return ExplicitSpec; } |
1884 | const ExplicitSpecifier getExplicitSpecifier() const { return ExplicitSpec; } |
1885 | |
1886 | /// Return true if the declartion is already resolved to be explicit. |
1887 | bool isExplicit() const { return ExplicitSpec.isExplicit(); } |
1888 | |
1889 | /// Get the template for which this guide performs deduction. |
1890 | TemplateDecl *getDeducedTemplate() const { |
1891 | return getDeclName().getCXXDeductionGuideTemplate(); |
1892 | } |
1893 | |
1894 | /// Get the constructor from which this deduction guide was generated, if |
1895 | /// this is an implicit deduction guide. |
1896 | CXXConstructorDecl *getCorrespondingConstructor() const { |
1897 | return Ctor; |
1898 | } |
1899 | |
1900 | void setIsCopyDeductionCandidate(bool isCDC = true) { |
1901 | FunctionDeclBits.IsCopyDeductionCandidate = isCDC; |
1902 | } |
1903 | |
1904 | bool isCopyDeductionCandidate() const { |
1905 | return FunctionDeclBits.IsCopyDeductionCandidate; |
1906 | } |
1907 | |
1908 | // Implement isa/cast/dyncast/etc. |
1909 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1910 | static bool classofKind(Kind K) { return K == CXXDeductionGuide; } |
1911 | }; |
1912 | |
1913 | /// \brief Represents the body of a requires-expression. |
1914 | /// |
1915 | /// This decl exists merely to serve as the DeclContext for the local |
1916 | /// parameters of the requires expression as well as other declarations inside |
1917 | /// it. |
1918 | /// |
1919 | /// \code |
1920 | /// template<typename T> requires requires (T t) { {t++} -> regular; } |
1921 | /// \endcode |
1922 | /// |
1923 | /// In this example, a RequiresExpr object will be generated for the expression, |
1924 | /// and a RequiresExprBodyDecl will be created to hold the parameter t and the |
1925 | /// template argument list imposed by the compound requirement. |
1926 | class RequiresExprBodyDecl : public Decl, public DeclContext { |
1927 | RequiresExprBodyDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc) |
1928 | : Decl(RequiresExprBody, DC, StartLoc), DeclContext(RequiresExprBody) {} |
1929 | |
1930 | public: |
1931 | friend class ASTDeclReader; |
1932 | friend class ASTDeclWriter; |
1933 | |
1934 | static RequiresExprBodyDecl *Create(ASTContext &C, DeclContext *DC, |
1935 | SourceLocation StartLoc); |
1936 | |
1937 | static RequiresExprBodyDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
1938 | |
1939 | // Implement isa/cast/dyncast/etc. |
1940 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1941 | static bool classofKind(Kind K) { return K == RequiresExprBody; } |
1942 | }; |
1943 | |
1944 | /// Represents a static or instance method of a struct/union/class. |
1945 | /// |
1946 | /// In the terminology of the C++ Standard, these are the (static and |
1947 | /// non-static) member functions, whether virtual or not. |
1948 | class CXXMethodDecl : public FunctionDecl { |
1949 | void anchor() override; |
1950 | |
1951 | protected: |
1952 | CXXMethodDecl(Kind DK, ASTContext &C, CXXRecordDecl *RD, |
1953 | SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, |
1954 | QualType T, TypeSourceInfo *TInfo, StorageClass SC, |
1955 | bool UsesFPIntrin, bool isInline, |
1956 | ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, |
1957 | Expr *TrailingRequiresClause = nullptr) |
1958 | : FunctionDecl(DK, C, RD, StartLoc, NameInfo, T, TInfo, SC, UsesFPIntrin, |
1959 | isInline, ConstexprKind, TrailingRequiresClause) { |
1960 | if (EndLocation.isValid()) |
1961 | setRangeEnd(EndLocation); |
1962 | } |
1963 | |
1964 | public: |
1965 | static CXXMethodDecl * |
1966 | Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
1967 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
1968 | StorageClass SC, bool UsesFPIntrin, bool isInline, |
1969 | ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, |
1970 | Expr *TrailingRequiresClause = nullptr); |
1971 | |
1972 | static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
1973 | |
1974 | bool isStatic() const; |
1975 | bool isInstance() const { return !isStatic(); } |
1976 | |
1977 | /// Returns true if the given operator is implicitly static in a record |
1978 | /// context. |
1979 | static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK) { |
1980 | // [class.free]p1: |
1981 | // Any allocation function for a class T is a static member |
1982 | // (even if not explicitly declared static). |
1983 | // [class.free]p6 Any deallocation function for a class X is a static member |
1984 | // (even if not explicitly declared static). |
1985 | return OOK == OO_New || OOK == OO_Array_New || OOK == OO_Delete || |
1986 | OOK == OO_Array_Delete; |
1987 | } |
1988 | |
1989 | bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); } |
1990 | bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); } |
1991 | |
1992 | bool isVirtual() const { |
1993 | CXXMethodDecl *CD = const_cast<CXXMethodDecl*>(this)->getCanonicalDecl(); |
1994 | |
1995 | // Member function is virtual if it is marked explicitly so, or if it is |
1996 | // declared in __interface -- then it is automatically pure virtual. |
1997 | if (CD->isVirtualAsWritten() || CD->isPure()) |
1998 | return true; |
1999 | |
2000 | return CD->size_overridden_methods() != 0; |
2001 | } |
2002 | |
2003 | /// If it's possible to devirtualize a call to this method, return the called |
2004 | /// function. Otherwise, return null. |
2005 | |
2006 | /// \param Base The object on which this virtual function is called. |
2007 | /// \param IsAppleKext True if we are compiling for Apple kext. |
2008 | CXXMethodDecl *getDevirtualizedMethod(const Expr *Base, bool IsAppleKext); |
2009 | |
2010 | const CXXMethodDecl *getDevirtualizedMethod(const Expr *Base, |
2011 | bool IsAppleKext) const { |
2012 | return const_cast<CXXMethodDecl *>(this)->getDevirtualizedMethod( |
2013 | Base, IsAppleKext); |
2014 | } |
2015 | |
2016 | /// Determine whether this is a usual deallocation function (C++ |
2017 | /// [basic.stc.dynamic.deallocation]p2), which is an overloaded delete or |
2018 | /// delete[] operator with a particular signature. Populates \p PreventedBy |
2019 | /// with the declarations of the functions of the same kind if they were the |
2020 | /// reason for this function returning false. This is used by |
2021 | /// Sema::isUsualDeallocationFunction to reconsider the answer based on the |
2022 | /// context. |
2023 | bool isUsualDeallocationFunction( |
2024 | SmallVectorImpl<const FunctionDecl *> &PreventedBy) const; |
2025 | |
2026 | /// Determine whether this is a copy-assignment operator, regardless |
2027 | /// of whether it was declared implicitly or explicitly. |
2028 | bool isCopyAssignmentOperator() const; |
2029 | |
2030 | /// Determine whether this is a move assignment operator. |
2031 | bool isMoveAssignmentOperator() const; |
2032 | |
2033 | CXXMethodDecl *getCanonicalDecl() override { |
2034 | return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); |
2035 | } |
2036 | const CXXMethodDecl *getCanonicalDecl() const { |
2037 | return const_cast<CXXMethodDecl*>(this)->getCanonicalDecl(); |
2038 | } |
2039 | |
2040 | CXXMethodDecl *getMostRecentDecl() { |
2041 | return cast<CXXMethodDecl>( |
2042 | static_cast<FunctionDecl *>(this)->getMostRecentDecl()); |
2043 | } |
2044 | const CXXMethodDecl *getMostRecentDecl() const { |
2045 | return const_cast<CXXMethodDecl*>(this)->getMostRecentDecl(); |
2046 | } |
2047 | |
2048 | void addOverriddenMethod(const CXXMethodDecl *MD); |
2049 | |
2050 | using method_iterator = const CXXMethodDecl *const *; |
2051 | |
2052 | method_iterator begin_overridden_methods() const; |
2053 | method_iterator end_overridden_methods() const; |
2054 | unsigned size_overridden_methods() const; |
2055 | |
2056 | using overridden_method_range = llvm::iterator_range< |
2057 | llvm::TinyPtrVector<const CXXMethodDecl *>::const_iterator>; |
2058 | |
2059 | overridden_method_range overridden_methods() const; |
2060 | |
2061 | /// Return the parent of this method declaration, which |
2062 | /// is the class in which this method is defined. |
2063 | const CXXRecordDecl *getParent() const { |
2064 | return cast<CXXRecordDecl>(FunctionDecl::getParent()); |
2065 | } |
2066 | |
2067 | /// Return the parent of this method declaration, which |
2068 | /// is the class in which this method is defined. |
2069 | CXXRecordDecl *getParent() { |
2070 | return const_cast<CXXRecordDecl *>( |
2071 | cast<CXXRecordDecl>(FunctionDecl::getParent())); |
2072 | } |
2073 | |
2074 | /// Return the type of the \c this pointer. |
2075 | /// |
2076 | /// Should only be called for instance (i.e., non-static) methods. Note |
2077 | /// that for the call operator of a lambda closure type, this returns the |
2078 | /// desugared 'this' type (a pointer to the closure type), not the captured |
2079 | /// 'this' type. |
2080 | QualType getThisType() const; |
2081 | |
2082 | /// Return the type of the object pointed by \c this. |
2083 | /// |
2084 | /// See getThisType() for usage restriction. |
2085 | QualType getThisObjectType() const; |
2086 | |
2087 | static QualType getThisType(const FunctionProtoType *FPT, |
2088 | const CXXRecordDecl *Decl); |
2089 | |
2090 | static QualType getThisObjectType(const FunctionProtoType *FPT, |
2091 | const CXXRecordDecl *Decl); |
2092 | |
2093 | Qualifiers getMethodQualifiers() const { |
2094 | return getType()->castAs<FunctionProtoType>()->getMethodQuals(); |
2095 | } |
2096 | |
2097 | /// Retrieve the ref-qualifier associated with this method. |
2098 | /// |
2099 | /// In the following example, \c f() has an lvalue ref-qualifier, \c g() |
2100 | /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier. |
2101 | /// @code |
2102 | /// struct X { |
2103 | /// void f() &; |
2104 | /// void g() &&; |
2105 | /// void h(); |
2106 | /// }; |
2107 | /// @endcode |
2108 | RefQualifierKind getRefQualifier() const { |
2109 | return getType()->castAs<FunctionProtoType>()->getRefQualifier(); |
2110 | } |
2111 | |
2112 | bool hasInlineBody() const; |
2113 | |
2114 | /// Determine whether this is a lambda closure type's static member |
2115 | /// function that is used for the result of the lambda's conversion to |
2116 | /// function pointer (for a lambda with no captures). |
2117 | /// |
2118 | /// The function itself, if used, will have a placeholder body that will be |
2119 | /// supplied by IR generation to either forward to the function call operator |
2120 | /// or clone the function call operator. |
2121 | bool isLambdaStaticInvoker() const; |
2122 | |
2123 | /// Find the method in \p RD that corresponds to this one. |
2124 | /// |
2125 | /// Find if \p RD or one of the classes it inherits from override this method. |
2126 | /// If so, return it. \p RD is assumed to be a subclass of the class defining |
2127 | /// this method (or be the class itself), unless \p MayBeBase is set to true. |
2128 | CXXMethodDecl * |
2129 | getCorrespondingMethodInClass(const CXXRecordDecl *RD, |
2130 | bool MayBeBase = false); |
2131 | |
2132 | const CXXMethodDecl * |
2133 | getCorrespondingMethodInClass(const CXXRecordDecl *RD, |
2134 | bool MayBeBase = false) const { |
2135 | return const_cast<CXXMethodDecl *>(this) |
2136 | ->getCorrespondingMethodInClass(RD, MayBeBase); |
2137 | } |
2138 | |
2139 | /// Find if \p RD declares a function that overrides this function, and if so, |
2140 | /// return it. Does not search base classes. |
2141 | CXXMethodDecl *getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD, |
2142 | bool MayBeBase = false); |
2143 | const CXXMethodDecl * |
2144 | getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD, |
2145 | bool MayBeBase = false) const { |
2146 | return const_cast<CXXMethodDecl *>(this) |
2147 | ->getCorrespondingMethodDeclaredInClass(RD, MayBeBase); |
2148 | } |
2149 | |
2150 | // Implement isa/cast/dyncast/etc. |
2151 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2152 | static bool classofKind(Kind K) { |
2153 | return K >= firstCXXMethod && K <= lastCXXMethod; |
2154 | } |
2155 | }; |
2156 | |
2157 | /// Represents a C++ base or member initializer. |
2158 | /// |
2159 | /// This is part of a constructor initializer that |
2160 | /// initializes one non-static member variable or one base class. For |
2161 | /// example, in the following, both 'A(a)' and 'f(3.14159)' are member |
2162 | /// initializers: |
2163 | /// |
2164 | /// \code |
2165 | /// class A { }; |
2166 | /// class B : public A { |
2167 | /// float f; |
2168 | /// public: |
2169 | /// B(A& a) : A(a), f(3.14159) { } |
2170 | /// }; |
2171 | /// \endcode |
2172 | class CXXCtorInitializer final { |
2173 | /// Either the base class name/delegating constructor type (stored as |
2174 | /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field |
2175 | /// (IndirectFieldDecl*) being initialized. |
2176 | llvm::PointerUnion<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *> |
2177 | Initializee; |
2178 | |
2179 | /// The argument used to initialize the base or member, which may |
2180 | /// end up constructing an object (when multiple arguments are involved). |
2181 | Stmt *Init; |
2182 | |
2183 | /// The source location for the field name or, for a base initializer |
2184 | /// pack expansion, the location of the ellipsis. |
2185 | /// |
2186 | /// In the case of a delegating |
2187 | /// constructor, it will still include the type's source location as the |
2188 | /// Initializee points to the CXXConstructorDecl (to allow loop detection). |
2189 | SourceLocation MemberOrEllipsisLocation; |
2190 | |
2191 | /// Location of the left paren of the ctor-initializer. |
2192 | SourceLocation LParenLoc; |
2193 | |
2194 | /// Location of the right paren of the ctor-initializer. |
2195 | SourceLocation RParenLoc; |
2196 | |
2197 | /// If the initializee is a type, whether that type makes this |
2198 | /// a delegating initialization. |
2199 | unsigned IsDelegating : 1; |
2200 | |
2201 | /// If the initializer is a base initializer, this keeps track |
2202 | /// of whether the base is virtual or not. |
2203 | unsigned IsVirtual : 1; |
2204 | |
2205 | /// Whether or not the initializer is explicitly written |
2206 | /// in the sources. |
2207 | unsigned IsWritten : 1; |
2208 | |
2209 | /// If IsWritten is true, then this number keeps track of the textual order |
2210 | /// of this initializer in the original sources, counting from 0. |
2211 | unsigned SourceOrder : 13; |
2212 | |
2213 | public: |
2214 | /// Creates a new base-class initializer. |
2215 | explicit |
2216 | CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual, |
2217 | SourceLocation L, Expr *Init, SourceLocation R, |
2218 | SourceLocation EllipsisLoc); |
2219 | |
2220 | /// Creates a new member initializer. |
2221 | explicit |
2222 | CXXCtorInitializer(ASTContext &Context, FieldDecl *Member, |
2223 | SourceLocation MemberLoc, SourceLocation L, Expr *Init, |
2224 | SourceLocation R); |
2225 | |
2226 | /// Creates a new anonymous field initializer. |
2227 | explicit |
2228 | CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member, |
2229 | SourceLocation MemberLoc, SourceLocation L, Expr *Init, |
2230 | SourceLocation R); |
2231 | |
2232 | /// Creates a new delegating initializer. |
2233 | explicit |
2234 | CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, |
2235 | SourceLocation L, Expr *Init, SourceLocation R); |
2236 | |
2237 | /// \return Unique reproducible object identifier. |
2238 | int64_t getID(const ASTContext &Context) const; |
2239 | |
2240 | /// Determine whether this initializer is initializing a base class. |
2241 | bool isBaseInitializer() const { |
2242 | return Initializee.is<TypeSourceInfo*>() && !IsDelegating; |
2243 | } |
2244 | |
2245 | /// Determine whether this initializer is initializing a non-static |
2246 | /// data member. |
2247 | bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); } |
2248 | |
2249 | bool isAnyMemberInitializer() const { |
2250 | return isMemberInitializer() || isIndirectMemberInitializer(); |
2251 | } |
2252 | |
2253 | bool isIndirectMemberInitializer() const { |
2254 | return Initializee.is<IndirectFieldDecl*>(); |
2255 | } |
2256 | |
2257 | /// Determine whether this initializer is an implicit initializer |
2258 | /// generated for a field with an initializer defined on the member |
2259 | /// declaration. |
2260 | /// |
2261 | /// In-class member initializers (also known as "non-static data member |
2262 | /// initializations", NSDMIs) were introduced in C++11. |
2263 | bool isInClassMemberInitializer() const { |
2264 | return Init->getStmtClass() == Stmt::CXXDefaultInitExprClass; |
2265 | } |
2266 | |
2267 | /// Determine whether this initializer is creating a delegating |
2268 | /// constructor. |
2269 | bool isDelegatingInitializer() const { |
2270 | return Initializee.is<TypeSourceInfo*>() && IsDelegating; |
2271 | } |
2272 | |
2273 | /// Determine whether this initializer is a pack expansion. |
2274 | bool isPackExpansion() const { |
2275 | return isBaseInitializer() && MemberOrEllipsisLocation.isValid(); |
2276 | } |
2277 | |
2278 | // For a pack expansion, returns the location of the ellipsis. |
2279 | SourceLocation getEllipsisLoc() const { |
2280 | if (!isPackExpansion()) |
2281 | return {}; |
2282 | return MemberOrEllipsisLocation; |
2283 | } |
2284 | |
2285 | /// If this is a base class initializer, returns the type of the |
2286 | /// base class with location information. Otherwise, returns an NULL |
2287 | /// type location. |
2288 | TypeLoc getBaseClassLoc() const; |
2289 | |
2290 | /// If this is a base class initializer, returns the type of the base class. |
2291 | /// Otherwise, returns null. |
2292 | const Type *getBaseClass() const; |
2293 | |
2294 | /// Returns whether the base is virtual or not. |
2295 | bool isBaseVirtual() const { |
2296 | assert(isBaseInitializer() && "Must call this on base initializer!")(static_cast <bool> (isBaseInitializer() && "Must call this on base initializer!" ) ? void (0) : __assert_fail ("isBaseInitializer() && \"Must call this on base initializer!\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 2296, __extension__ __PRETTY_FUNCTION__)); |
2297 | |
2298 | return IsVirtual; |
2299 | } |
2300 | |
2301 | /// Returns the declarator information for a base class or delegating |
2302 | /// initializer. |
2303 | TypeSourceInfo *getTypeSourceInfo() const { |
2304 | return Initializee.dyn_cast<TypeSourceInfo *>(); |
2305 | } |
2306 | |
2307 | /// If this is a member initializer, returns the declaration of the |
2308 | /// non-static data member being initialized. Otherwise, returns null. |
2309 | FieldDecl *getMember() const { |
2310 | if (isMemberInitializer()) |
2311 | return Initializee.get<FieldDecl*>(); |
2312 | return nullptr; |
2313 | } |
2314 | |
2315 | FieldDecl *getAnyMember() const { |
2316 | if (isMemberInitializer()) |
2317 | return Initializee.get<FieldDecl*>(); |
2318 | if (isIndirectMemberInitializer()) |
2319 | return Initializee.get<IndirectFieldDecl*>()->getAnonField(); |
2320 | return nullptr; |
2321 | } |
2322 | |
2323 | IndirectFieldDecl *getIndirectMember() const { |
2324 | if (isIndirectMemberInitializer()) |
2325 | return Initializee.get<IndirectFieldDecl*>(); |
2326 | return nullptr; |
2327 | } |
2328 | |
2329 | SourceLocation getMemberLocation() const { |
2330 | return MemberOrEllipsisLocation; |
2331 | } |
2332 | |
2333 | /// Determine the source location of the initializer. |
2334 | SourceLocation getSourceLocation() const; |
2335 | |
2336 | /// Determine the source range covering the entire initializer. |
2337 | SourceRange getSourceRange() const LLVM_READONLY__attribute__((__pure__)); |
2338 | |
2339 | /// Determine whether this initializer is explicitly written |
2340 | /// in the source code. |
2341 | bool isWritten() const { return IsWritten; } |
2342 | |
2343 | /// Return the source position of the initializer, counting from 0. |
2344 | /// If the initializer was implicit, -1 is returned. |
2345 | int getSourceOrder() const { |
2346 | return IsWritten ? static_cast<int>(SourceOrder) : -1; |
2347 | } |
2348 | |
2349 | /// Set the source order of this initializer. |
2350 | /// |
2351 | /// This can only be called once for each initializer; it cannot be called |
2352 | /// on an initializer having a positive number of (implicit) array indices. |
2353 | /// |
2354 | /// This assumes that the initializer was written in the source code, and |
2355 | /// ensures that isWritten() returns true. |
2356 | void setSourceOrder(int Pos) { |
2357 | assert(!IsWritten &&(static_cast <bool> (!IsWritten && "setSourceOrder() used on implicit initializer" ) ? void (0) : __assert_fail ("!IsWritten && \"setSourceOrder() used on implicit initializer\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 2358, __extension__ __PRETTY_FUNCTION__)) |
2358 | "setSourceOrder() used on implicit initializer")(static_cast <bool> (!IsWritten && "setSourceOrder() used on implicit initializer" ) ? void (0) : __assert_fail ("!IsWritten && \"setSourceOrder() used on implicit initializer\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 2358, __extension__ __PRETTY_FUNCTION__)); |
2359 | assert(SourceOrder == 0 &&(static_cast <bool> (SourceOrder == 0 && "calling twice setSourceOrder() on the same initializer" ) ? void (0) : __assert_fail ("SourceOrder == 0 && \"calling twice setSourceOrder() on the same initializer\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 2360, __extension__ __PRETTY_FUNCTION__)) |
2360 | "calling twice setSourceOrder() on the same initializer")(static_cast <bool> (SourceOrder == 0 && "calling twice setSourceOrder() on the same initializer" ) ? void (0) : __assert_fail ("SourceOrder == 0 && \"calling twice setSourceOrder() on the same initializer\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 2360, __extension__ __PRETTY_FUNCTION__)); |
2361 | assert(Pos >= 0 &&(static_cast <bool> (Pos >= 0 && "setSourceOrder() used to make an initializer implicit" ) ? void (0) : __assert_fail ("Pos >= 0 && \"setSourceOrder() used to make an initializer implicit\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 2362, __extension__ __PRETTY_FUNCTION__)) |
2362 | "setSourceOrder() used to make an initializer implicit")(static_cast <bool> (Pos >= 0 && "setSourceOrder() used to make an initializer implicit" ) ? void (0) : __assert_fail ("Pos >= 0 && \"setSourceOrder() used to make an initializer implicit\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 2362, __extension__ __PRETTY_FUNCTION__)); |
2363 | IsWritten = true; |
2364 | SourceOrder = static_cast<unsigned>(Pos); |
2365 | } |
2366 | |
2367 | SourceLocation getLParenLoc() const { return LParenLoc; } |
2368 | SourceLocation getRParenLoc() const { return RParenLoc; } |
2369 | |
2370 | /// Get the initializer. |
2371 | Expr *getInit() const { return static_cast<Expr *>(Init); } |
2372 | }; |
2373 | |
2374 | /// Description of a constructor that was inherited from a base class. |
2375 | class InheritedConstructor { |
2376 | ConstructorUsingShadowDecl *Shadow = nullptr; |
2377 | CXXConstructorDecl *BaseCtor = nullptr; |
2378 | |
2379 | public: |
2380 | InheritedConstructor() = default; |
2381 | InheritedConstructor(ConstructorUsingShadowDecl *Shadow, |
2382 | CXXConstructorDecl *BaseCtor) |
2383 | : Shadow(Shadow), BaseCtor(BaseCtor) {} |
2384 | |
2385 | explicit operator bool() const { return Shadow; } |
2386 | |
2387 | ConstructorUsingShadowDecl *getShadowDecl() const { return Shadow; } |
2388 | CXXConstructorDecl *getConstructor() const { return BaseCtor; } |
2389 | }; |
2390 | |
2391 | /// Represents a C++ constructor within a class. |
2392 | /// |
2393 | /// For example: |
2394 | /// |
2395 | /// \code |
2396 | /// class X { |
2397 | /// public: |
2398 | /// explicit X(int); // represented by a CXXConstructorDecl. |
2399 | /// }; |
2400 | /// \endcode |
2401 | class CXXConstructorDecl final |
2402 | : public CXXMethodDecl, |
2403 | private llvm::TrailingObjects<CXXConstructorDecl, InheritedConstructor, |
2404 | ExplicitSpecifier> { |
2405 | // This class stores some data in DeclContext::CXXConstructorDeclBits |
2406 | // to save some space. Use the provided accessors to access it. |
2407 | |
2408 | /// \name Support for base and member initializers. |
2409 | /// \{ |
2410 | /// The arguments used to initialize the base or member. |
2411 | LazyCXXCtorInitializersPtr CtorInitializers; |
2412 | |
2413 | CXXConstructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2414 | const DeclarationNameInfo &NameInfo, QualType T, |
2415 | TypeSourceInfo *TInfo, ExplicitSpecifier ES, |
2416 | bool UsesFPIntrin, bool isInline, |
2417 | bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, |
2418 | InheritedConstructor Inherited, |
2419 | Expr *TrailingRequiresClause); |
2420 | |
2421 | void anchor() override; |
2422 | |
2423 | size_t numTrailingObjects(OverloadToken<InheritedConstructor>) const { |
2424 | return CXXConstructorDeclBits.IsInheritingConstructor; |
2425 | } |
2426 | size_t numTrailingObjects(OverloadToken<ExplicitSpecifier>) const { |
2427 | return CXXConstructorDeclBits.HasTrailingExplicitSpecifier; |
2428 | } |
2429 | |
2430 | ExplicitSpecifier getExplicitSpecifierInternal() const { |
2431 | if (CXXConstructorDeclBits.HasTrailingExplicitSpecifier) |
2432 | return *getTrailingObjects<ExplicitSpecifier>(); |
2433 | return ExplicitSpecifier( |
2434 | nullptr, CXXConstructorDeclBits.IsSimpleExplicit |
2435 | ? ExplicitSpecKind::ResolvedTrue |
2436 | : ExplicitSpecKind::ResolvedFalse); |
2437 | } |
2438 | |
2439 | enum TrailingAllocKind { |
2440 | TAKInheritsConstructor = 1, |
2441 | TAKHasTailExplicit = 1 << 1, |
2442 | }; |
2443 | |
2444 | uint64_t getTrailingAllocKind() const { |
2445 | return numTrailingObjects(OverloadToken<InheritedConstructor>()) | |
2446 | (numTrailingObjects(OverloadToken<ExplicitSpecifier>()) << 1); |
2447 | } |
2448 | |
2449 | public: |
2450 | friend class ASTDeclReader; |
2451 | friend class ASTDeclWriter; |
2452 | friend TrailingObjects; |
2453 | |
2454 | static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
2455 | uint64_t AllocKind); |
2456 | static CXXConstructorDecl * |
2457 | Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2458 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
2459 | ExplicitSpecifier ES, bool UsesFPIntrin, bool isInline, |
2460 | bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, |
2461 | InheritedConstructor Inherited = InheritedConstructor(), |
2462 | Expr *TrailingRequiresClause = nullptr); |
2463 | |
2464 | void setExplicitSpecifier(ExplicitSpecifier ES) { |
2465 | assert((!ES.getExpr() ||(static_cast <bool> ((!ES.getExpr() || CXXConstructorDeclBits .HasTrailingExplicitSpecifier) && "cannot set this explicit specifier. no trail-allocated space for " "explicit") ? void (0) : __assert_fail ("(!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier) && \"cannot set this explicit specifier. no trail-allocated space for \" \"explicit\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 2468, __extension__ __PRETTY_FUNCTION__)) |
2466 | CXXConstructorDeclBits.HasTrailingExplicitSpecifier) &&(static_cast <bool> ((!ES.getExpr() || CXXConstructorDeclBits .HasTrailingExplicitSpecifier) && "cannot set this explicit specifier. no trail-allocated space for " "explicit") ? void (0) : __assert_fail ("(!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier) && \"cannot set this explicit specifier. no trail-allocated space for \" \"explicit\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 2468, __extension__ __PRETTY_FUNCTION__)) |
2467 | "cannot set this explicit specifier. no trail-allocated space for "(static_cast <bool> ((!ES.getExpr() || CXXConstructorDeclBits .HasTrailingExplicitSpecifier) && "cannot set this explicit specifier. no trail-allocated space for " "explicit") ? void (0) : __assert_fail ("(!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier) && \"cannot set this explicit specifier. no trail-allocated space for \" \"explicit\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 2468, __extension__ __PRETTY_FUNCTION__)) |
2468 | "explicit")(static_cast <bool> ((!ES.getExpr() || CXXConstructorDeclBits .HasTrailingExplicitSpecifier) && "cannot set this explicit specifier. no trail-allocated space for " "explicit") ? void (0) : __assert_fail ("(!ES.getExpr() || CXXConstructorDeclBits.HasTrailingExplicitSpecifier) && \"cannot set this explicit specifier. no trail-allocated space for \" \"explicit\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 2468, __extension__ __PRETTY_FUNCTION__)); |
2469 | if (ES.getExpr()) |
2470 | *getCanonicalDecl()->getTrailingObjects<ExplicitSpecifier>() = ES; |
2471 | else |
2472 | CXXConstructorDeclBits.IsSimpleExplicit = ES.isExplicit(); |
2473 | } |
2474 | |
2475 | ExplicitSpecifier getExplicitSpecifier() { |
2476 | return getCanonicalDecl()->getExplicitSpecifierInternal(); |
2477 | } |
2478 | const ExplicitSpecifier getExplicitSpecifier() const { |
2479 | return getCanonicalDecl()->getExplicitSpecifierInternal(); |
2480 | } |
2481 | |
2482 | /// Return true if the declartion is already resolved to be explicit. |
2483 | bool isExplicit() const { return getExplicitSpecifier().isExplicit(); } |
2484 | |
2485 | /// Iterates through the member/base initializer list. |
2486 | using init_iterator = CXXCtorInitializer **; |
2487 | |
2488 | /// Iterates through the member/base initializer list. |
2489 | using init_const_iterator = CXXCtorInitializer *const *; |
2490 | |
2491 | using init_range = llvm::iterator_range<init_iterator>; |
2492 | using init_const_range = llvm::iterator_range<init_const_iterator>; |
2493 | |
2494 | init_range inits() { return init_range(init_begin(), init_end()); } |
2495 | init_const_range inits() const { |
2496 | return init_const_range(init_begin(), init_end()); |
2497 | } |
2498 | |
2499 | /// Retrieve an iterator to the first initializer. |
2500 | init_iterator init_begin() { |
2501 | const auto *ConstThis = this; |
2502 | return const_cast<init_iterator>(ConstThis->init_begin()); |
2503 | } |
2504 | |
2505 | /// Retrieve an iterator to the first initializer. |
2506 | init_const_iterator init_begin() const; |
2507 | |
2508 | /// Retrieve an iterator past the last initializer. |
2509 | init_iterator init_end() { |
2510 | return init_begin() + getNumCtorInitializers(); |
2511 | } |
2512 | |
2513 | /// Retrieve an iterator past the last initializer. |
2514 | init_const_iterator init_end() const { |
2515 | return init_begin() + getNumCtorInitializers(); |
2516 | } |
2517 | |
2518 | using init_reverse_iterator = std::reverse_iterator<init_iterator>; |
2519 | using init_const_reverse_iterator = |
2520 | std::reverse_iterator<init_const_iterator>; |
2521 | |
2522 | init_reverse_iterator init_rbegin() { |
2523 | return init_reverse_iterator(init_end()); |
2524 | } |
2525 | init_const_reverse_iterator init_rbegin() const { |
2526 | return init_const_reverse_iterator(init_end()); |
2527 | } |
2528 | |
2529 | init_reverse_iterator init_rend() { |
2530 | return init_reverse_iterator(init_begin()); |
2531 | } |
2532 | init_const_reverse_iterator init_rend() const { |
2533 | return init_const_reverse_iterator(init_begin()); |
2534 | } |
2535 | |
2536 | /// Determine the number of arguments used to initialize the member |
2537 | /// or base. |
2538 | unsigned getNumCtorInitializers() const { |
2539 | return CXXConstructorDeclBits.NumCtorInitializers; |
2540 | } |
2541 | |
2542 | void setNumCtorInitializers(unsigned numCtorInitializers) { |
2543 | CXXConstructorDeclBits.NumCtorInitializers = numCtorInitializers; |
2544 | // This assert added because NumCtorInitializers is stored |
2545 | // in CXXConstructorDeclBits as a bitfield and its width has |
2546 | // been shrunk from 32 bits to fit into CXXConstructorDeclBitfields. |
2547 | assert(CXXConstructorDeclBits.NumCtorInitializers ==(static_cast <bool> (CXXConstructorDeclBits.NumCtorInitializers == numCtorInitializers && "NumCtorInitializers overflow!" ) ? void (0) : __assert_fail ("CXXConstructorDeclBits.NumCtorInitializers == numCtorInitializers && \"NumCtorInitializers overflow!\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 2548, __extension__ __PRETTY_FUNCTION__)) |
2548 | numCtorInitializers && "NumCtorInitializers overflow!")(static_cast <bool> (CXXConstructorDeclBits.NumCtorInitializers == numCtorInitializers && "NumCtorInitializers overflow!" ) ? void (0) : __assert_fail ("CXXConstructorDeclBits.NumCtorInitializers == numCtorInitializers && \"NumCtorInitializers overflow!\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 2548, __extension__ __PRETTY_FUNCTION__)); |
2549 | } |
2550 | |
2551 | void setCtorInitializers(CXXCtorInitializer **Initializers) { |
2552 | CtorInitializers = Initializers; |
2553 | } |
2554 | |
2555 | /// Determine whether this constructor is a delegating constructor. |
2556 | bool isDelegatingConstructor() const { |
2557 | return (getNumCtorInitializers() == 1) && |
2558 | init_begin()[0]->isDelegatingInitializer(); |
2559 | } |
2560 | |
2561 | /// When this constructor delegates to another, retrieve the target. |
2562 | CXXConstructorDecl *getTargetConstructor() const; |
2563 | |
2564 | /// Whether this constructor is a default |
2565 | /// constructor (C++ [class.ctor]p5), which can be used to |
2566 | /// default-initialize a class of this type. |
2567 | bool isDefaultConstructor() const; |
2568 | |
2569 | /// Whether this constructor is a copy constructor (C++ [class.copy]p2, |
2570 | /// which can be used to copy the class. |
2571 | /// |
2572 | /// \p TypeQuals will be set to the qualifiers on the |
2573 | /// argument type. For example, \p TypeQuals would be set to \c |
2574 | /// Qualifiers::Const for the following copy constructor: |
2575 | /// |
2576 | /// \code |
2577 | /// class X { |
2578 | /// public: |
2579 | /// X(const X&); |
2580 | /// }; |
2581 | /// \endcode |
2582 | bool isCopyConstructor(unsigned &TypeQuals) const; |
2583 | |
2584 | /// Whether this constructor is a copy |
2585 | /// constructor (C++ [class.copy]p2, which can be used to copy the |
2586 | /// class. |
2587 | bool isCopyConstructor() const { |
2588 | unsigned TypeQuals = 0; |
2589 | return isCopyConstructor(TypeQuals); |
2590 | } |
2591 | |
2592 | /// Determine whether this constructor is a move constructor |
2593 | /// (C++11 [class.copy]p3), which can be used to move values of the class. |
2594 | /// |
2595 | /// \param TypeQuals If this constructor is a move constructor, will be set |
2596 | /// to the type qualifiers on the referent of the first parameter's type. |
2597 | bool isMoveConstructor(unsigned &TypeQuals) const; |
2598 | |
2599 | /// Determine whether this constructor is a move constructor |
2600 | /// (C++11 [class.copy]p3), which can be used to move values of the class. |
2601 | bool isMoveConstructor() const { |
2602 | unsigned TypeQuals = 0; |
2603 | return isMoveConstructor(TypeQuals); |
2604 | } |
2605 | |
2606 | /// Determine whether this is a copy or move constructor. |
2607 | /// |
2608 | /// \param TypeQuals Will be set to the type qualifiers on the reference |
2609 | /// parameter, if in fact this is a copy or move constructor. |
2610 | bool isCopyOrMoveConstructor(unsigned &TypeQuals) const; |
2611 | |
2612 | /// Determine whether this a copy or move constructor. |
2613 | bool isCopyOrMoveConstructor() const { |
2614 | unsigned Quals; |
2615 | return isCopyOrMoveConstructor(Quals); |
2616 | } |
2617 | |
2618 | /// Whether this constructor is a |
2619 | /// converting constructor (C++ [class.conv.ctor]), which can be |
2620 | /// used for user-defined conversions. |
2621 | bool isConvertingConstructor(bool AllowExplicit) const; |
2622 | |
2623 | /// Determine whether this is a member template specialization that |
2624 | /// would copy the object to itself. Such constructors are never used to copy |
2625 | /// an object. |
2626 | bool isSpecializationCopyingObject() const; |
2627 | |
2628 | /// Determine whether this is an implicit constructor synthesized to |
2629 | /// model a call to a constructor inherited from a base class. |
2630 | bool isInheritingConstructor() const { |
2631 | return CXXConstructorDeclBits.IsInheritingConstructor; |
2632 | } |
2633 | |
2634 | /// State that this is an implicit constructor synthesized to |
2635 | /// model a call to a constructor inherited from a base class. |
2636 | void setInheritingConstructor(bool isIC = true) { |
2637 | CXXConstructorDeclBits.IsInheritingConstructor = isIC; |
2638 | } |
2639 | |
2640 | /// Get the constructor that this inheriting constructor is based on. |
2641 | InheritedConstructor getInheritedConstructor() const { |
2642 | return isInheritingConstructor() ? |
2643 | *getTrailingObjects<InheritedConstructor>() : InheritedConstructor(); |
2644 | } |
2645 | |
2646 | CXXConstructorDecl *getCanonicalDecl() override { |
2647 | return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl()); |
2648 | } |
2649 | const CXXConstructorDecl *getCanonicalDecl() const { |
2650 | return const_cast<CXXConstructorDecl*>(this)->getCanonicalDecl(); |
2651 | } |
2652 | |
2653 | // Implement isa/cast/dyncast/etc. |
2654 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2655 | static bool classofKind(Kind K) { return K == CXXConstructor; } |
2656 | }; |
2657 | |
2658 | /// Represents a C++ destructor within a class. |
2659 | /// |
2660 | /// For example: |
2661 | /// |
2662 | /// \code |
2663 | /// class X { |
2664 | /// public: |
2665 | /// ~X(); // represented by a CXXDestructorDecl. |
2666 | /// }; |
2667 | /// \endcode |
2668 | class CXXDestructorDecl : public CXXMethodDecl { |
2669 | friend class ASTDeclReader; |
2670 | friend class ASTDeclWriter; |
2671 | |
2672 | // FIXME: Don't allocate storage for these except in the first declaration |
2673 | // of a virtual destructor. |
2674 | FunctionDecl *OperatorDelete = nullptr; |
2675 | Expr *OperatorDeleteThisArg = nullptr; |
2676 | |
2677 | CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2678 | const DeclarationNameInfo &NameInfo, QualType T, |
2679 | TypeSourceInfo *TInfo, bool UsesFPIntrin, bool isInline, |
2680 | bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, |
2681 | Expr *TrailingRequiresClause = nullptr) |
2682 | : CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo, |
2683 | SC_None, UsesFPIntrin, isInline, ConstexprKind, |
2684 | SourceLocation(), TrailingRequiresClause) { |
2685 | setImplicit(isImplicitlyDeclared); |
2686 | } |
2687 | |
2688 | void anchor() override; |
2689 | |
2690 | public: |
2691 | static CXXDestructorDecl * |
2692 | Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2693 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
2694 | bool UsesFPIntrin, bool isInline, bool isImplicitlyDeclared, |
2695 | ConstexprSpecKind ConstexprKind, |
2696 | Expr *TrailingRequiresClause = nullptr); |
2697 | static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID); |
2698 | |
2699 | void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg); |
2700 | |
2701 | const FunctionDecl *getOperatorDelete() const { |
2702 | return getCanonicalDecl()->OperatorDelete; |
2703 | } |
2704 | |
2705 | Expr *getOperatorDeleteThisArg() const { |
2706 | return getCanonicalDecl()->OperatorDeleteThisArg; |
2707 | } |
2708 | |
2709 | CXXDestructorDecl *getCanonicalDecl() override { |
2710 | return cast<CXXDestructorDecl>(FunctionDecl::getCanonicalDecl()); |
2711 | } |
2712 | const CXXDestructorDecl *getCanonicalDecl() const { |
2713 | return const_cast<CXXDestructorDecl*>(this)->getCanonicalDecl(); |
2714 | } |
2715 | |
2716 | // Implement isa/cast/dyncast/etc. |
2717 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2718 | static bool classofKind(Kind K) { return K == CXXDestructor; } |
2719 | }; |
2720 | |
2721 | /// Represents a C++ conversion function within a class. |
2722 | /// |
2723 | /// For example: |
2724 | /// |
2725 | /// \code |
2726 | /// class X { |
2727 | /// public: |
2728 | /// operator bool(); |
2729 | /// }; |
2730 | /// \endcode |
2731 | class CXXConversionDecl : public CXXMethodDecl { |
2732 | CXXConversionDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2733 | const DeclarationNameInfo &NameInfo, QualType T, |
2734 | TypeSourceInfo *TInfo, bool UsesFPIntrin, bool isInline, |
2735 | ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind, |
2736 | SourceLocation EndLocation, |
2737 | Expr *TrailingRequiresClause = nullptr) |
2738 | : CXXMethodDecl(CXXConversion, C, RD, StartLoc, NameInfo, T, TInfo, |
2739 | SC_None, UsesFPIntrin, isInline, ConstexprKind, |
2740 | EndLocation, TrailingRequiresClause), |
2741 | ExplicitSpec(ES) {} |
2742 | void anchor() override; |
2743 | |
2744 | ExplicitSpecifier ExplicitSpec; |
2745 | |
2746 | public: |
2747 | friend class ASTDeclReader; |
2748 | friend class ASTDeclWriter; |
2749 | |
2750 | static CXXConversionDecl * |
2751 | Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2752 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
2753 | bool UsesFPIntrin, bool isInline, ExplicitSpecifier ES, |
2754 | ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, |
2755 | Expr *TrailingRequiresClause = nullptr); |
2756 | static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2757 | |
2758 | ExplicitSpecifier getExplicitSpecifier() { |
2759 | return getCanonicalDecl()->ExplicitSpec; |
2760 | } |
2761 | |
2762 | const ExplicitSpecifier getExplicitSpecifier() const { |
2763 | return getCanonicalDecl()->ExplicitSpec; |
2764 | } |
2765 | |
2766 | /// Return true if the declartion is already resolved to be explicit. |
2767 | bool isExplicit() const { return getExplicitSpecifier().isExplicit(); } |
2768 | void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; } |
2769 | |
2770 | /// Returns the type that this conversion function is converting to. |
2771 | QualType getConversionType() const { |
2772 | return getType()->castAs<FunctionType>()->getReturnType(); |
2773 | } |
2774 | |
2775 | /// Determine whether this conversion function is a conversion from |
2776 | /// a lambda closure type to a block pointer. |
2777 | bool isLambdaToBlockPointerConversion() const; |
2778 | |
2779 | CXXConversionDecl *getCanonicalDecl() override { |
2780 | return cast<CXXConversionDecl>(FunctionDecl::getCanonicalDecl()); |
2781 | } |
2782 | const CXXConversionDecl *getCanonicalDecl() const { |
2783 | return const_cast<CXXConversionDecl*>(this)->getCanonicalDecl(); |
2784 | } |
2785 | |
2786 | // Implement isa/cast/dyncast/etc. |
2787 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2788 | static bool classofKind(Kind K) { return K == CXXConversion; } |
2789 | }; |
2790 | |
2791 | /// Represents a linkage specification. |
2792 | /// |
2793 | /// For example: |
2794 | /// \code |
2795 | /// extern "C" void foo(); |
2796 | /// \endcode |
2797 | class LinkageSpecDecl : public Decl, public DeclContext { |
2798 | virtual void anchor(); |
2799 | // This class stores some data in DeclContext::LinkageSpecDeclBits to save |
2800 | // some space. Use the provided accessors to access it. |
2801 | public: |
2802 | /// Represents the language in a linkage specification. |
2803 | /// |
2804 | /// The values are part of the serialization ABI for |
2805 | /// ASTs and cannot be changed without altering that ABI. |
2806 | enum LanguageIDs { lang_c = 1, lang_cxx = 2 }; |
2807 | |
2808 | private: |
2809 | /// The source location for the extern keyword. |
2810 | SourceLocation ExternLoc; |
2811 | |
2812 | /// The source location for the right brace (if valid). |
2813 | SourceLocation RBraceLoc; |
2814 | |
2815 | LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc, |
2816 | SourceLocation LangLoc, LanguageIDs lang, bool HasBraces); |
2817 | |
2818 | public: |
2819 | static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC, |
2820 | SourceLocation ExternLoc, |
2821 | SourceLocation LangLoc, LanguageIDs Lang, |
2822 | bool HasBraces); |
2823 | static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2824 | |
2825 | /// Return the language specified by this linkage specification. |
2826 | LanguageIDs getLanguage() const { |
2827 | return static_cast<LanguageIDs>(LinkageSpecDeclBits.Language); |
2828 | } |
2829 | |
2830 | /// Set the language specified by this linkage specification. |
2831 | void setLanguage(LanguageIDs L) { LinkageSpecDeclBits.Language = L; } |
2832 | |
2833 | /// Determines whether this linkage specification had braces in |
2834 | /// its syntactic form. |
2835 | bool hasBraces() const { |
2836 | assert(!RBraceLoc.isValid() || LinkageSpecDeclBits.HasBraces)(static_cast <bool> (!RBraceLoc.isValid() || LinkageSpecDeclBits .HasBraces) ? void (0) : __assert_fail ("!RBraceLoc.isValid() || LinkageSpecDeclBits.HasBraces" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 2836, __extension__ __PRETTY_FUNCTION__)); |
2837 | return LinkageSpecDeclBits.HasBraces; |
2838 | } |
2839 | |
2840 | SourceLocation getExternLoc() const { return ExternLoc; } |
2841 | SourceLocation getRBraceLoc() const { return RBraceLoc; } |
2842 | void setExternLoc(SourceLocation L) { ExternLoc = L; } |
2843 | void setRBraceLoc(SourceLocation L) { |
2844 | RBraceLoc = L; |
2845 | LinkageSpecDeclBits.HasBraces = RBraceLoc.isValid(); |
2846 | } |
2847 | |
2848 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { |
2849 | if (hasBraces()) |
2850 | return getRBraceLoc(); |
2851 | // No braces: get the end location of the (only) declaration in context |
2852 | // (if present). |
2853 | return decls_empty() ? getLocation() : decls_begin()->getEndLoc(); |
2854 | } |
2855 | |
2856 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
2857 | return SourceRange(ExternLoc, getEndLoc()); |
2858 | } |
2859 | |
2860 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2861 | static bool classofKind(Kind K) { return K == LinkageSpec; } |
2862 | |
2863 | static DeclContext *castToDeclContext(const LinkageSpecDecl *D) { |
2864 | return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D)); |
2865 | } |
2866 | |
2867 | static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) { |
2868 | return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC)); |
2869 | } |
2870 | }; |
2871 | |
2872 | /// Represents C++ using-directive. |
2873 | /// |
2874 | /// For example: |
2875 | /// \code |
2876 | /// using namespace std; |
2877 | /// \endcode |
2878 | /// |
2879 | /// \note UsingDirectiveDecl should be Decl not NamedDecl, but we provide |
2880 | /// artificial names for all using-directives in order to store |
2881 | /// them in DeclContext effectively. |
2882 | class UsingDirectiveDecl : public NamedDecl { |
2883 | /// The location of the \c using keyword. |
2884 | SourceLocation UsingLoc; |
2885 | |
2886 | /// The location of the \c namespace keyword. |
2887 | SourceLocation NamespaceLoc; |
2888 | |
2889 | /// The nested-name-specifier that precedes the namespace. |
2890 | NestedNameSpecifierLoc QualifierLoc; |
2891 | |
2892 | /// The namespace nominated by this using-directive. |
2893 | NamedDecl *NominatedNamespace; |
2894 | |
2895 | /// Enclosing context containing both using-directive and nominated |
2896 | /// namespace. |
2897 | DeclContext *CommonAncestor; |
2898 | |
2899 | UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc, |
2900 | SourceLocation NamespcLoc, |
2901 | NestedNameSpecifierLoc QualifierLoc, |
2902 | SourceLocation IdentLoc, |
2903 | NamedDecl *Nominated, |
2904 | DeclContext *CommonAncestor) |
2905 | : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc), |
2906 | NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc), |
2907 | NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) {} |
2908 | |
2909 | /// Returns special DeclarationName used by using-directives. |
2910 | /// |
2911 | /// This is only used by DeclContext for storing UsingDirectiveDecls in |
2912 | /// its lookup structure. |
2913 | static DeclarationName getName() { |
2914 | return DeclarationName::getUsingDirectiveName(); |
2915 | } |
2916 | |
2917 | void anchor() override; |
2918 | |
2919 | public: |
2920 | friend class ASTDeclReader; |
2921 | |
2922 | // Friend for getUsingDirectiveName. |
2923 | friend class DeclContext; |
2924 | |
2925 | /// Retrieve the nested-name-specifier that qualifies the |
2926 | /// name of the namespace, with source-location information. |
2927 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
2928 | |
2929 | /// Retrieve the nested-name-specifier that qualifies the |
2930 | /// name of the namespace. |
2931 | NestedNameSpecifier *getQualifier() const { |
2932 | return QualifierLoc.getNestedNameSpecifier(); |
2933 | } |
2934 | |
2935 | NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; } |
2936 | const NamedDecl *getNominatedNamespaceAsWritten() const { |
2937 | return NominatedNamespace; |
2938 | } |
2939 | |
2940 | /// Returns the namespace nominated by this using-directive. |
2941 | NamespaceDecl *getNominatedNamespace(); |
2942 | |
2943 | const NamespaceDecl *getNominatedNamespace() const { |
2944 | return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace(); |
2945 | } |
2946 | |
2947 | /// Returns the common ancestor context of this using-directive and |
2948 | /// its nominated namespace. |
2949 | DeclContext *getCommonAncestor() { return CommonAncestor; } |
2950 | const DeclContext *getCommonAncestor() const { return CommonAncestor; } |
2951 | |
2952 | /// Return the location of the \c using keyword. |
2953 | SourceLocation getUsingLoc() const { return UsingLoc; } |
2954 | |
2955 | // FIXME: Could omit 'Key' in name. |
2956 | /// Returns the location of the \c namespace keyword. |
2957 | SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; } |
2958 | |
2959 | /// Returns the location of this using declaration's identifier. |
2960 | SourceLocation getIdentLocation() const { return getLocation(); } |
2961 | |
2962 | static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC, |
2963 | SourceLocation UsingLoc, |
2964 | SourceLocation NamespaceLoc, |
2965 | NestedNameSpecifierLoc QualifierLoc, |
2966 | SourceLocation IdentLoc, |
2967 | NamedDecl *Nominated, |
2968 | DeclContext *CommonAncestor); |
2969 | static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2970 | |
2971 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
2972 | return SourceRange(UsingLoc, getLocation()); |
2973 | } |
2974 | |
2975 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2976 | static bool classofKind(Kind K) { return K == UsingDirective; } |
2977 | }; |
2978 | |
2979 | /// Represents a C++ namespace alias. |
2980 | /// |
2981 | /// For example: |
2982 | /// |
2983 | /// \code |
2984 | /// namespace Foo = Bar; |
2985 | /// \endcode |
2986 | class NamespaceAliasDecl : public NamedDecl, |
2987 | public Redeclarable<NamespaceAliasDecl> { |
2988 | friend class ASTDeclReader; |
2989 | |
2990 | /// The location of the \c namespace keyword. |
2991 | SourceLocation NamespaceLoc; |
2992 | |
2993 | /// The location of the namespace's identifier. |
2994 | /// |
2995 | /// This is accessed by TargetNameLoc. |
2996 | SourceLocation IdentLoc; |
2997 | |
2998 | /// The nested-name-specifier that precedes the namespace. |
2999 | NestedNameSpecifierLoc QualifierLoc; |
3000 | |
3001 | /// The Decl that this alias points to, either a NamespaceDecl or |
3002 | /// a NamespaceAliasDecl. |
3003 | NamedDecl *Namespace; |
3004 | |
3005 | NamespaceAliasDecl(ASTContext &C, DeclContext *DC, |
3006 | SourceLocation NamespaceLoc, SourceLocation AliasLoc, |
3007 | IdentifierInfo *Alias, NestedNameSpecifierLoc QualifierLoc, |
3008 | SourceLocation IdentLoc, NamedDecl *Namespace) |
3009 | : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias), redeclarable_base(C), |
3010 | NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc), |
3011 | QualifierLoc(QualifierLoc), Namespace(Namespace) {} |
3012 | |
3013 | void anchor() override; |
3014 | |
3015 | using redeclarable_base = Redeclarable<NamespaceAliasDecl>; |
3016 | |
3017 | NamespaceAliasDecl *getNextRedeclarationImpl() override; |
3018 | NamespaceAliasDecl *getPreviousDeclImpl() override; |
3019 | NamespaceAliasDecl *getMostRecentDeclImpl() override; |
3020 | |
3021 | public: |
3022 | static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC, |
3023 | SourceLocation NamespaceLoc, |
3024 | SourceLocation AliasLoc, |
3025 | IdentifierInfo *Alias, |
3026 | NestedNameSpecifierLoc QualifierLoc, |
3027 | SourceLocation IdentLoc, |
3028 | NamedDecl *Namespace); |
3029 | |
3030 | static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3031 | |
3032 | using redecl_range = redeclarable_base::redecl_range; |
3033 | using redecl_iterator = redeclarable_base::redecl_iterator; |
3034 | |
3035 | using redeclarable_base::redecls_begin; |
3036 | using redeclarable_base::redecls_end; |
3037 | using redeclarable_base::redecls; |
3038 | using redeclarable_base::getPreviousDecl; |
3039 | using redeclarable_base::getMostRecentDecl; |
3040 | |
3041 | NamespaceAliasDecl *getCanonicalDecl() override { |
3042 | return getFirstDecl(); |
3043 | } |
3044 | const NamespaceAliasDecl *getCanonicalDecl() const { |
3045 | return getFirstDecl(); |
3046 | } |
3047 | |
3048 | /// Retrieve the nested-name-specifier that qualifies the |
3049 | /// name of the namespace, with source-location information. |
3050 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3051 | |
3052 | /// Retrieve the nested-name-specifier that qualifies the |
3053 | /// name of the namespace. |
3054 | NestedNameSpecifier *getQualifier() const { |
3055 | return QualifierLoc.getNestedNameSpecifier(); |
3056 | } |
3057 | |
3058 | /// Retrieve the namespace declaration aliased by this directive. |
3059 | NamespaceDecl *getNamespace() { |
3060 | if (auto *AD = dyn_cast<NamespaceAliasDecl>(Namespace)) |
3061 | return AD->getNamespace(); |
3062 | |
3063 | return cast<NamespaceDecl>(Namespace); |
3064 | } |
3065 | |
3066 | const NamespaceDecl *getNamespace() const { |
3067 | return const_cast<NamespaceAliasDecl *>(this)->getNamespace(); |
3068 | } |
3069 | |
3070 | /// Returns the location of the alias name, i.e. 'foo' in |
3071 | /// "namespace foo = ns::bar;". |
3072 | SourceLocation getAliasLoc() const { return getLocation(); } |
3073 | |
3074 | /// Returns the location of the \c namespace keyword. |
3075 | SourceLocation getNamespaceLoc() const { return NamespaceLoc; } |
3076 | |
3077 | /// Returns the location of the identifier in the named namespace. |
3078 | SourceLocation getTargetNameLoc() const { return IdentLoc; } |
3079 | |
3080 | /// Retrieve the namespace that this alias refers to, which |
3081 | /// may either be a NamespaceDecl or a NamespaceAliasDecl. |
3082 | NamedDecl *getAliasedNamespace() const { return Namespace; } |
3083 | |
3084 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
3085 | return SourceRange(NamespaceLoc, IdentLoc); |
3086 | } |
3087 | |
3088 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3089 | static bool classofKind(Kind K) { return K == NamespaceAlias; } |
3090 | }; |
3091 | |
3092 | /// Implicit declaration of a temporary that was materialized by |
3093 | /// a MaterializeTemporaryExpr and lifetime-extended by a declaration |
3094 | class LifetimeExtendedTemporaryDecl final |
3095 | : public Decl, |
3096 | public Mergeable<LifetimeExtendedTemporaryDecl> { |
3097 | friend class MaterializeTemporaryExpr; |
3098 | friend class ASTDeclReader; |
3099 | |
3100 | Stmt *ExprWithTemporary = nullptr; |
3101 | |
3102 | /// The declaration which lifetime-extended this reference, if any. |
3103 | /// Either a VarDecl, or (for a ctor-initializer) a FieldDecl. |
3104 | ValueDecl *ExtendingDecl = nullptr; |
3105 | unsigned ManglingNumber; |
3106 | |
3107 | mutable APValue *Value = nullptr; |
3108 | |
3109 | virtual void anchor(); |
3110 | |
3111 | LifetimeExtendedTemporaryDecl(Expr *Temp, ValueDecl *EDecl, unsigned Mangling) |
3112 | : Decl(Decl::LifetimeExtendedTemporary, EDecl->getDeclContext(), |
3113 | EDecl->getLocation()), |
3114 | ExprWithTemporary(Temp), ExtendingDecl(EDecl), |
3115 | ManglingNumber(Mangling) {} |
3116 | |
3117 | LifetimeExtendedTemporaryDecl(EmptyShell) |
3118 | : Decl(Decl::LifetimeExtendedTemporary, EmptyShell{}) {} |
3119 | |
3120 | public: |
3121 | static LifetimeExtendedTemporaryDecl *Create(Expr *Temp, ValueDecl *EDec, |
3122 | unsigned Mangling) { |
3123 | return new (EDec->getASTContext(), EDec->getDeclContext()) |
3124 | LifetimeExtendedTemporaryDecl(Temp, EDec, Mangling); |
3125 | } |
3126 | static LifetimeExtendedTemporaryDecl *CreateDeserialized(ASTContext &C, |
3127 | unsigned ID) { |
3128 | return new (C, ID) LifetimeExtendedTemporaryDecl(EmptyShell{}); |
3129 | } |
3130 | |
3131 | ValueDecl *getExtendingDecl() { return ExtendingDecl; } |
3132 | const ValueDecl *getExtendingDecl() const { return ExtendingDecl; } |
3133 | |
3134 | /// Retrieve the storage duration for the materialized temporary. |
3135 | StorageDuration getStorageDuration() const; |
3136 | |
3137 | /// Retrieve the expression to which the temporary materialization conversion |
3138 | /// was applied. This isn't necessarily the initializer of the temporary due |
3139 | /// to the C++98 delayed materialization rules, but |
3140 | /// skipRValueSubobjectAdjustments can be used to find said initializer within |
3141 | /// the subexpression. |
3142 | Expr *getTemporaryExpr() { return cast<Expr>(ExprWithTemporary); } |
3143 | const Expr *getTemporaryExpr() const { return cast<Expr>(ExprWithTemporary); } |
3144 | |
3145 | unsigned getManglingNumber() const { return ManglingNumber; } |
3146 | |
3147 | /// Get the storage for the constant value of a materialized temporary |
3148 | /// of static storage duration. |
3149 | APValue *getOrCreateValue(bool MayCreate) const; |
3150 | |
3151 | APValue *getValue() const { return Value; } |
3152 | |
3153 | // Iterators |
3154 | Stmt::child_range childrenExpr() { |
3155 | return Stmt::child_range(&ExprWithTemporary, &ExprWithTemporary + 1); |
3156 | } |
3157 | |
3158 | Stmt::const_child_range childrenExpr() const { |
3159 | return Stmt::const_child_range(&ExprWithTemporary, &ExprWithTemporary + 1); |
3160 | } |
3161 | |
3162 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3163 | static bool classofKind(Kind K) { |
3164 | return K == Decl::LifetimeExtendedTemporary; |
3165 | } |
3166 | }; |
3167 | |
3168 | /// Represents a shadow declaration implicitly introduced into a scope by a |
3169 | /// (resolved) using-declaration or using-enum-declaration to achieve |
3170 | /// the desired lookup semantics. |
3171 | /// |
3172 | /// For example: |
3173 | /// \code |
3174 | /// namespace A { |
3175 | /// void foo(); |
3176 | /// void foo(int); |
3177 | /// struct foo {}; |
3178 | /// enum bar { bar1, bar2 }; |
3179 | /// } |
3180 | /// namespace B { |
3181 | /// // add a UsingDecl and three UsingShadowDecls (named foo) to B. |
3182 | /// using A::foo; |
3183 | /// // adds UsingEnumDecl and two UsingShadowDecls (named bar1 and bar2) to B. |
3184 | /// using enum A::bar; |
3185 | /// } |
3186 | /// \endcode |
3187 | class UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> { |
3188 | friend class BaseUsingDecl; |
3189 | |
3190 | /// The referenced declaration. |
3191 | NamedDecl *Underlying = nullptr; |
3192 | |
3193 | /// The using declaration which introduced this decl or the next using |
3194 | /// shadow declaration contained in the aforementioned using declaration. |
3195 | NamedDecl *UsingOrNextShadow = nullptr; |
3196 | |
3197 | void anchor() override; |
3198 | |
3199 | using redeclarable_base = Redeclarable<UsingShadowDecl>; |
3200 | |
3201 | UsingShadowDecl *getNextRedeclarationImpl() override { |
3202 | return getNextRedeclaration(); |
3203 | } |
3204 | |
3205 | UsingShadowDecl *getPreviousDeclImpl() override { |
3206 | return getPreviousDecl(); |
3207 | } |
3208 | |
3209 | UsingShadowDecl *getMostRecentDeclImpl() override { |
3210 | return getMostRecentDecl(); |
3211 | } |
3212 | |
3213 | protected: |
3214 | UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC, SourceLocation Loc, |
3215 | DeclarationName Name, BaseUsingDecl *Introducer, |
3216 | NamedDecl *Target); |
3217 | UsingShadowDecl(Kind K, ASTContext &C, EmptyShell); |
3218 | |
3219 | public: |
3220 | friend class ASTDeclReader; |
3221 | friend class ASTDeclWriter; |
3222 | |
3223 | static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC, |
3224 | SourceLocation Loc, DeclarationName Name, |
3225 | BaseUsingDecl *Introducer, NamedDecl *Target) { |
3226 | return new (C, DC) |
3227 | UsingShadowDecl(UsingShadow, C, DC, Loc, Name, Introducer, Target); |
3228 | } |
3229 | |
3230 | static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3231 | |
3232 | using redecl_range = redeclarable_base::redecl_range; |
3233 | using redecl_iterator = redeclarable_base::redecl_iterator; |
3234 | |
3235 | using redeclarable_base::redecls_begin; |
3236 | using redeclarable_base::redecls_end; |
3237 | using redeclarable_base::redecls; |
3238 | using redeclarable_base::getPreviousDecl; |
3239 | using redeclarable_base::getMostRecentDecl; |
3240 | using redeclarable_base::isFirstDecl; |
3241 | |
3242 | UsingShadowDecl *getCanonicalDecl() override { |
3243 | return getFirstDecl(); |
3244 | } |
3245 | const UsingShadowDecl *getCanonicalDecl() const { |
3246 | return getFirstDecl(); |
3247 | } |
3248 | |
3249 | /// Gets the underlying declaration which has been brought into the |
3250 | /// local scope. |
3251 | NamedDecl *getTargetDecl() const { return Underlying; } |
3252 | |
3253 | /// Sets the underlying declaration which has been brought into the |
3254 | /// local scope. |
3255 | void setTargetDecl(NamedDecl *ND) { |
3256 | assert(ND && "Target decl is null!")(static_cast <bool> (ND && "Target decl is null!" ) ? void (0) : __assert_fail ("ND && \"Target decl is null!\"" , "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include/clang/AST/DeclCXX.h" , 3256, __extension__ __PRETTY_FUNCTION__)); |
3257 | Underlying = ND; |
3258 | // A UsingShadowDecl is never a friend or local extern declaration, even |
3259 | // if it is a shadow declaration for one. |
3260 | IdentifierNamespace = |
3261 | ND->getIdentifierNamespace() & |
3262 | ~(IDNS_OrdinaryFriend | IDNS_TagFriend | IDNS_LocalExtern); |
3263 | } |
3264 | |
3265 | /// Gets the (written or instantiated) using declaration that introduced this |
3266 | /// declaration. |
3267 | BaseUsingDecl *getIntroducer() const; |
3268 | |
3269 | /// The next using shadow declaration contained in the shadow decl |
3270 | /// chain of the using declaration which introduced this decl. |
3271 | UsingShadowDecl *getNextUsingShadowDecl() const { |
3272 | return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow); |
3273 | } |
3274 | |
3275 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3276 | static bool classofKind(Kind K) { |
3277 | return K == Decl::UsingShadow || K == Decl::ConstructorUsingShadow; |
3278 | } |
3279 | }; |
3280 | |
3281 | /// Represents a C++ declaration that introduces decls from somewhere else. It |
3282 | /// provides a set of the shadow decls so introduced. |
3283 | |
3284 | class BaseUsingDecl : public NamedDecl { |
3285 | /// The first shadow declaration of the shadow decl chain associated |
3286 | /// with this using declaration. |
3287 | /// |
3288 | /// The bool member of the pair is a bool flag a derived type may use |
3289 | /// (UsingDecl makes use of it). |
3290 | llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow; |
3291 | |
3292 | protected: |
3293 | BaseUsingDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N) |
3294 | : NamedDecl(DK, DC, L, N), FirstUsingShadow(nullptr, 0) {} |
3295 | |
3296 | private: |
3297 | void anchor() override; |
3298 | |
3299 | protected: |
3300 | /// A bool flag for use by a derived type |
3301 | bool getShadowFlag() const { return FirstUsingShadow.getInt(); } |
3302 | |
3303 | /// A bool flag a derived type may set |
3304 | void setShadowFlag(bool V) { FirstUsingShadow.setInt(V); } |
3305 | |
3306 | public: |
3307 | friend class ASTDeclReader; |
3308 | friend class ASTDeclWriter; |
3309 | |
3310 | /// Iterates through the using shadow declarations associated with |
3311 | /// this using declaration. |
3312 | class shadow_iterator { |
3313 | /// The current using shadow declaration. |
3314 | UsingShadowDecl *Current = nullptr; |
3315 | |
3316 | public: |
3317 | using value_type = UsingShadowDecl *; |
3318 | using reference = UsingShadowDecl *; |
3319 | using pointer = UsingShadowDecl *; |
3320 | using iterator_category = std::forward_iterator_tag; |
3321 | using difference_type = std::ptrdiff_t; |
3322 | |
3323 | shadow_iterator() = default; |
3324 | explicit shadow_iterator(UsingShadowDecl *C) : Current(C) {} |
3325 | |
3326 | reference operator*() const { return Current; } |
3327 | pointer operator->() const { return Current; } |
3328 | |
3329 | shadow_iterator &operator++() { |
3330 | Current = Current->getNextUsingShadowDecl(); |
3331 | return *this; |
3332 | } |
3333 | |
3334 | shadow_iterator operator++(int) { |
3335 | shadow_iterator tmp(*this); |
3336 | ++(*this); |
3337 | return tmp; |
3338 | } |
3339 | |
3340 | friend bool operator==(shadow_iterator x, shadow_iterator y) { |
3341 | return x.Current == y.Current; |
3342 | } |
3343 | friend bool operator!=(shadow_iterator x, shadow_iterator y) { |
3344 | return x.Current != y.Current; |
3345 | } |
3346 | }; |
3347 | |
3348 | using shadow_range = llvm::iterator_range<shadow_iterator>; |
3349 | |
3350 | shadow_range shadows() const { |
3351 | return shadow_range(shadow_begin(), shadow_end()); |
3352 | } |
3353 | |
3354 | shadow_iterator shadow_begin() const { |
3355 | return shadow_iterator(FirstUsingShadow.getPointer()); |
3356 | } |
3357 | |
3358 | shadow_iterator shadow_end() const { return shadow_iterator(); } |
3359 | |
3360 | /// Return the number of shadowed declarations associated with this |
3361 | /// using declaration. |
3362 | unsigned shadow_size() const { |
3363 | return std::distance(shadow_begin(), shadow_end()); |
3364 | } |
3365 | |
3366 | void addShadowDecl(UsingShadowDecl *S); |
3367 | void removeShadowDecl(UsingShadowDecl *S); |
3368 | |
3369 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3370 | static bool classofKind(Kind K) { return K == Using || K == UsingEnum; } |
3371 | }; |
3372 | |
3373 | /// Represents a C++ using-declaration. |
3374 | /// |
3375 | /// For example: |
3376 | /// \code |
3377 | /// using someNameSpace::someIdentifier; |
3378 | /// \endcode |
3379 | class UsingDecl : public BaseUsingDecl, public Mergeable<UsingDecl> { |
3380 | /// The source location of the 'using' keyword itself. |
3381 | SourceLocation UsingLocation; |
3382 | |
3383 | /// The nested-name-specifier that precedes the name. |
3384 | NestedNameSpecifierLoc QualifierLoc; |
3385 | |
3386 | /// Provides source/type location info for the declaration name |
3387 | /// embedded in the ValueDecl base class. |
3388 | DeclarationNameLoc DNLoc; |
3389 | |
3390 | UsingDecl(DeclContext *DC, SourceLocation UL, |
3391 | NestedNameSpecifierLoc QualifierLoc, |
3392 | const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword) |
3393 | : BaseUsingDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()), |
3394 | UsingLocation(UL), QualifierLoc(QualifierLoc), |
3395 | DNLoc(NameInfo.getInfo()) { |
3396 | setShadowFlag(HasTypenameKeyword); |
3397 | } |
3398 | |
3399 | void anchor() override; |
3400 | |
3401 | public: |
3402 | friend class ASTDeclReader; |
3403 | friend class ASTDeclWriter; |
3404 | |
3405 | /// Return the source location of the 'using' keyword. |
3406 | SourceLocation getUsingLoc() const { return UsingLocation; } |
3407 | |
3408 | /// Set the source location of the 'using' keyword. |
3409 | void setUsingLoc(SourceLocation L) { UsingLocation = L; } |
3410 | |
3411 | /// Retrieve the nested-name-specifier that qualifies the name, |
3412 | /// with source-location information. |
3413 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3414 | |
3415 | /// Retrieve the nested-name-specifier that qualifies the name. |
3416 | NestedNameSpecifier *getQualifier() const { |
3417 | return QualifierLoc.getNestedNameSpecifier(); |
3418 | } |
3419 | |
3420 | DeclarationNameInfo getNameInfo() const { |
3421 | return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); |
3422 | } |
3423 | |
3424 | /// Return true if it is a C++03 access declaration (no 'using'). |
3425 | bool isAccessDeclaration() const { return UsingLocation.isInvalid(); } |
3426 | |
3427 | /// Return true if the using declaration has 'typename'. |
3428 | bool hasTypename() const { return getShadowFlag(); } |
3429 | |
3430 | /// Sets whether the using declaration has 'typename'. |
3431 | void setTypename(bool TN) { setShadowFlag(TN); } |
3432 | |
3433 | static UsingDecl *Create(ASTContext &C, DeclContext *DC, |
3434 | SourceLocation UsingL, |
3435 | NestedNameSpecifierLoc QualifierLoc, |
3436 | const DeclarationNameInfo &NameInfo, |
3437 | bool HasTypenameKeyword); |
3438 | |
3439 | static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3440 | |
3441 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)); |
3442 | |
3443 | /// Retrieves the canonical declaration of this declaration. |
3444 | UsingDecl *getCanonicalDecl() override { |
3445 | return cast<UsingDecl>(getFirstDecl()); |
3446 | } |
3447 | const UsingDecl *getCanonicalDecl() const { |
3448 | return cast<UsingDecl>(getFirstDecl()); |
3449 | } |
3450 | |
3451 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3452 | static bool classofKind(Kind K) { return K == Using; } |
3453 | }; |
3454 | |
3455 | /// Represents a shadow constructor declaration introduced into a |
3456 | /// class by a C++11 using-declaration that names a constructor. |
3457 | /// |
3458 | /// For example: |
3459 | /// \code |
3460 | /// struct Base { Base(int); }; |
3461 | /// struct Derived { |
3462 | /// using Base::Base; // creates a UsingDecl and a ConstructorUsingShadowDecl |
3463 | /// }; |
3464 | /// \endcode |
3465 | class ConstructorUsingShadowDecl final : public UsingShadowDecl { |
3466 | /// If this constructor using declaration inherted the constructor |
3467 | /// from an indirect base class, this is the ConstructorUsingShadowDecl |
3468 | /// in the named direct base class from which the declaration was inherited. |
3469 | ConstructorUsingShadowDecl *NominatedBaseClassShadowDecl = nullptr; |
3470 | |
3471 | /// If this constructor using declaration inherted the constructor |
3472 | /// from an indirect base class, this is the ConstructorUsingShadowDecl |
3473 | /// that will be used to construct the unique direct or virtual base class |
3474 | /// that receives the constructor arguments. |
3475 | ConstructorUsingShadowDecl *ConstructedBaseClassShadowDecl = nullptr; |
3476 | |
3477 | /// \c true if the constructor ultimately named by this using shadow |
3478 | /// declaration is within a virtual base class subobject of the class that |
3479 | /// contains this declaration. |
3480 | unsigned IsVirtual : 1; |
3481 | |
3482 | ConstructorUsingShadowDecl(ASTContext &C, DeclContext *DC, SourceLocation Loc, |
3483 | UsingDecl *Using, NamedDecl *Target, |
3484 | bool TargetInVirtualBase) |
3485 | : UsingShadowDecl(ConstructorUsingShadow, C, DC, Loc, |
3486 | Using->getDeclName(), Using, |
3487 | Target->getUnderlyingDecl()), |
3488 | NominatedBaseClassShadowDecl( |
3489 | dyn_cast<ConstructorUsingShadowDecl>(Target)), |
3490 | ConstructedBaseClassShadowDecl(NominatedBaseClassShadowDecl), |
3491 | IsVirtual(TargetInVirtualBase) { |
3492 | // If we found a constructor that chains to a constructor for a virtual |
3493 | // base, we should directly call that virtual base constructor instead. |
3494 | // FIXME: This logic belongs in Sema. |
3495 | if (NominatedBaseClassShadowDecl && |
3496 | NominatedBaseClassShadowDecl->constructsVirtualBase()) { |
3497 | ConstructedBaseClassShadowDecl = |
3498 | NominatedBaseClassShadowDecl->ConstructedBaseClassShadowDecl; |
3499 | IsVirtual = true; |
3500 | } |
3501 | } |
3502 | |
3503 | ConstructorUsingShadowDecl(ASTContext &C, EmptyShell Empty) |
3504 | : UsingShadowDecl(ConstructorUsingShadow, C, Empty), IsVirtual(false) {} |
3505 | |
3506 | void anchor() override; |
3507 | |
3508 | public: |
3509 | friend class ASTDeclReader; |
3510 | friend class ASTDeclWriter; |
3511 | |
3512 | static ConstructorUsingShadowDecl *Create(ASTContext &C, DeclContext *DC, |
3513 | SourceLocation Loc, |
3514 | UsingDecl *Using, NamedDecl *Target, |
3515 | bool IsVirtual); |
3516 | static ConstructorUsingShadowDecl *CreateDeserialized(ASTContext &C, |
3517 | unsigned ID); |
3518 | |
3519 | /// Override the UsingShadowDecl's getIntroducer, returning the UsingDecl that |
3520 | /// introduced this. |
3521 | UsingDecl *getIntroducer() const { |
3522 | return cast<UsingDecl>(UsingShadowDecl::getIntroducer()); |
3523 | } |
3524 | |
3525 | /// Returns the parent of this using shadow declaration, which |
3526 | /// is the class in which this is declared. |
3527 | //@{ |
3528 | const CXXRecordDecl *getParent() const { |
3529 | return cast<CXXRecordDecl>(getDeclContext()); |
3530 | } |
3531 | CXXRecordDecl *getParent() { |
3532 | return cast<CXXRecordDecl>(getDeclContext()); |
3533 | } |
3534 | //@} |
3535 | |
3536 | /// Get the inheriting constructor declaration for the direct base |
3537 | /// class from which this using shadow declaration was inherited, if there is |
3538 | /// one. This can be different for each redeclaration of the same shadow decl. |
3539 | ConstructorUsingShadowDecl *getNominatedBaseClassShadowDecl() const { |
3540 | return NominatedBaseClassShadowDecl; |
3541 | } |
3542 | |
3543 | /// Get the inheriting constructor declaration for the base class |
3544 | /// for which we don't have an explicit initializer, if there is one. |
3545 | ConstructorUsingShadowDecl *getConstructedBaseClassShadowDecl() const { |
3546 | return ConstructedBaseClassShadowDecl; |
3547 | } |
3548 | |
3549 | /// Get the base class that was named in the using declaration. This |
3550 | /// can be different for each redeclaration of this same shadow decl. |
3551 | CXXRecordDecl *getNominatedBaseClass() const; |
3552 | |
3553 | /// Get the base class whose constructor or constructor shadow |
3554 | /// declaration is passed the constructor arguments. |
3555 | CXXRecordDecl *getConstructedBaseClass() const { |
3556 | return cast<CXXRecordDecl>((ConstructedBaseClassShadowDecl |
3557 | ? ConstructedBaseClassShadowDecl |
3558 | : getTargetDecl()) |
3559 | ->getDeclContext()); |
3560 | } |
3561 | |
3562 | /// Returns \c true if the constructed base class is a virtual base |
3563 | /// class subobject of this declaration's class. |
3564 | bool constructsVirtualBase() const { |
3565 | return IsVirtual; |
3566 | } |
3567 | |
3568 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3569 | static bool classofKind(Kind K) { return K == ConstructorUsingShadow; } |
3570 | }; |
3571 | |
3572 | /// Represents a C++ using-enum-declaration. |
3573 | /// |
3574 | /// For example: |
3575 | /// \code |
3576 | /// using enum SomeEnumTag ; |
3577 | /// \endcode |
3578 | |
3579 | class UsingEnumDecl : public BaseUsingDecl, public Mergeable<UsingEnumDecl> { |
3580 | /// The source location of the 'using' keyword itself. |
3581 | SourceLocation UsingLocation; |
3582 | |
3583 | /// Location of the 'enum' keyword. |
3584 | SourceLocation EnumLocation; |
3585 | |
3586 | /// The enum |
3587 | EnumDecl *Enum; |
3588 | |
3589 | UsingEnumDecl(DeclContext *DC, DeclarationName DN, SourceLocation UL, |
3590 | SourceLocation EL, SourceLocation NL, EnumDecl *ED) |
3591 | : BaseUsingDecl(UsingEnum, DC, NL, DN), UsingLocation(UL), |
3592 | EnumLocation(EL), Enum(ED) {} |
3593 | |
3594 | void anchor() override; |
3595 | |
3596 | public: |
3597 | friend class ASTDeclReader; |
3598 | friend class ASTDeclWriter; |
3599 | |
3600 | /// The source location of the 'using' keyword. |
3601 | SourceLocation getUsingLoc() const { return UsingLocation; } |
3602 | void setUsingLoc(SourceLocation L) { UsingLocation = L; } |
3603 | |
3604 | /// The source location of the 'enum' keyword. |
3605 | SourceLocation getEnumLoc() const { return EnumLocation; } |
3606 | void setEnumLoc(SourceLocation L) { EnumLocation = L; } |
3607 | |
3608 | public: |
3609 | EnumDecl *getEnumDecl() const { return Enum; } |
3610 | |
3611 | static UsingEnumDecl *Create(ASTContext &C, DeclContext *DC, |
3612 | SourceLocation UsingL, SourceLocation EnumL, |
3613 | SourceLocation NameL, EnumDecl *ED); |
3614 | |
3615 | static UsingEnumDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3616 | |
3617 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)); |
3618 | |
3619 | /// Retrieves the canonical declaration of this declaration. |
3620 | UsingEnumDecl *getCanonicalDecl() override { |
3621 | return cast<UsingEnumDecl>(getFirstDecl()); |
3622 | } |
3623 | const UsingEnumDecl *getCanonicalDecl() const { |
3624 | return cast<UsingEnumDecl>(getFirstDecl()); |
3625 | } |
3626 | |
3627 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3628 | static bool classofKind(Kind K) { return K == UsingEnum; } |
3629 | }; |
3630 | |
3631 | /// Represents a pack of using declarations that a single |
3632 | /// using-declarator pack-expanded into. |
3633 | /// |
3634 | /// \code |
3635 | /// template<typename ...T> struct X : T... { |
3636 | /// using T::operator()...; |
3637 | /// using T::operator T...; |
3638 | /// }; |
3639 | /// \endcode |
3640 | /// |
3641 | /// In the second case above, the UsingPackDecl will have the name |
3642 | /// 'operator T' (which contains an unexpanded pack), but the individual |
3643 | /// UsingDecls and UsingShadowDecls will have more reasonable names. |
3644 | class UsingPackDecl final |
3645 | : public NamedDecl, public Mergeable<UsingPackDecl>, |
3646 | private llvm::TrailingObjects<UsingPackDecl, NamedDecl *> { |
3647 | /// The UnresolvedUsingValueDecl or UnresolvedUsingTypenameDecl from |
3648 | /// which this waas instantiated. |
3649 | NamedDecl *InstantiatedFrom; |
3650 | |
3651 | /// The number of using-declarations created by this pack expansion. |
3652 | unsigned NumExpansions; |
3653 | |
3654 | UsingPackDecl(DeclContext *DC, NamedDecl *InstantiatedFrom, |
3655 | ArrayRef<NamedDecl *> UsingDecls) |
3656 | : NamedDecl(UsingPack, DC, |
3657 | InstantiatedFrom ? InstantiatedFrom->getLocation() |
3658 | : SourceLocation(), |
3659 | InstantiatedFrom ? InstantiatedFrom->getDeclName() |
3660 | : DeclarationName()), |
3661 | InstantiatedFrom(InstantiatedFrom), NumExpansions(UsingDecls.size()) { |
3662 | std::uninitialized_copy(UsingDecls.begin(), UsingDecls.end(), |
3663 | getTrailingObjects<NamedDecl *>()); |
3664 | } |
3665 | |
3666 | void anchor() override; |
3667 | |
3668 | public: |
3669 | friend class ASTDeclReader; |
3670 | friend class ASTDeclWriter; |
3671 | friend TrailingObjects; |
3672 | |
3673 | /// Get the using declaration from which this was instantiated. This will |
3674 | /// always be an UnresolvedUsingValueDecl or an UnresolvedUsingTypenameDecl |
3675 | /// that is a pack expansion. |
3676 | NamedDecl *getInstantiatedFromUsingDecl() const { return InstantiatedFrom; } |
3677 | |
3678 | /// Get the set of using declarations that this pack expanded into. Note that |
3679 | /// some of these may still be unresolved. |
3680 | ArrayRef<NamedDecl *> expansions() const { |
3681 | return llvm::makeArrayRef(getTrailingObjects<NamedDecl *>(), NumExpansions); |
3682 | } |
3683 | |
3684 | static UsingPackDecl *Create(ASTContext &C, DeclContext *DC, |
3685 | NamedDecl *InstantiatedFrom, |
3686 | ArrayRef<NamedDecl *> UsingDecls); |
3687 | |
3688 | static UsingPackDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
3689 | unsigned NumExpansions); |
3690 | |
3691 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
3692 | return InstantiatedFrom->getSourceRange(); |
3693 | } |
3694 | |
3695 | UsingPackDecl *getCanonicalDecl() override { return getFirstDecl(); } |
3696 | const UsingPackDecl *getCanonicalDecl() const { return getFirstDecl(); } |
3697 | |
3698 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3699 | static bool classofKind(Kind K) { return K == UsingPack; } |
3700 | }; |
3701 | |
3702 | /// Represents a dependent using declaration which was not marked with |
3703 | /// \c typename. |
3704 | /// |
3705 | /// Unlike non-dependent using declarations, these *only* bring through |
3706 | /// non-types; otherwise they would break two-phase lookup. |
3707 | /// |
3708 | /// \code |
3709 | /// template \<class T> class A : public Base<T> { |
3710 | /// using Base<T>::foo; |
3711 | /// }; |
3712 | /// \endcode |
3713 | class UnresolvedUsingValueDecl : public ValueDecl, |
3714 | public Mergeable<UnresolvedUsingValueDecl> { |
3715 | /// The source location of the 'using' keyword |
3716 | SourceLocation UsingLocation; |
3717 | |
3718 | /// If this is a pack expansion, the location of the '...'. |
3719 | SourceLocation EllipsisLoc; |
3720 | |
3721 | /// The nested-name-specifier that precedes the name. |
3722 | NestedNameSpecifierLoc QualifierLoc; |
3723 | |
3724 | /// Provides source/type location info for the declaration name |
3725 | /// embedded in the ValueDecl base class. |
3726 | DeclarationNameLoc DNLoc; |
3727 | |
3728 | UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty, |
3729 | SourceLocation UsingLoc, |
3730 | NestedNameSpecifierLoc QualifierLoc, |
3731 | const DeclarationNameInfo &NameInfo, |
3732 | SourceLocation EllipsisLoc) |
3733 | : ValueDecl(UnresolvedUsingValue, DC, |
3734 | NameInfo.getLoc(), NameInfo.getName(), Ty), |
3735 | UsingLocation(UsingLoc), EllipsisLoc(EllipsisLoc), |
3736 | QualifierLoc(QualifierLoc), DNLoc(NameInfo.getInfo()) {} |
3737 | |
3738 | void anchor() override; |
3739 | |
3740 | public: |
3741 | friend class ASTDeclReader; |
3742 | friend class ASTDeclWriter; |
3743 | |
3744 | /// Returns the source location of the 'using' keyword. |
3745 | SourceLocation getUsingLoc() const { return UsingLocation; } |
3746 | |
3747 | /// Set the source location of the 'using' keyword. |
3748 | void setUsingLoc(SourceLocation L) { UsingLocation = L; } |
3749 | |
3750 | /// Return true if it is a C++03 access declaration (no 'using'). |
3751 | bool isAccessDeclaration() const { return UsingLocation.isInvalid(); } |
3752 | |
3753 | /// Retrieve the nested-name-specifier that qualifies the name, |
3754 | /// with source-location information. |
3755 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3756 | |
3757 | /// Retrieve the nested-name-specifier that qualifies the name. |
3758 | NestedNameSpecifier *getQualifier() const { |
3759 | return QualifierLoc.getNestedNameSpecifier(); |
3760 | } |
3761 | |
3762 | DeclarationNameInfo getNameInfo() const { |
3763 | return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); |
3764 | } |
3765 | |
3766 | /// Determine whether this is a pack expansion. |
3767 | bool isPackExpansion() const { |
3768 | return EllipsisLoc.isValid(); |
3769 | } |
3770 | |
3771 | /// Get the location of the ellipsis if this is a pack expansion. |
3772 | SourceLocation getEllipsisLoc() const { |
3773 | return EllipsisLoc; |
3774 | } |
3775 | |
3776 | static UnresolvedUsingValueDecl * |
3777 | Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, |
3778 | NestedNameSpecifierLoc QualifierLoc, |
3779 | const DeclarationNameInfo &NameInfo, SourceLocation EllipsisLoc); |
3780 | |
3781 | static UnresolvedUsingValueDecl * |
3782 | CreateDeserialized(ASTContext &C, unsigned ID); |
3783 | |
3784 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)); |
3785 | |
3786 | /// Retrieves the canonical declaration of this declaration. |
3787 | UnresolvedUsingValueDecl *getCanonicalDecl() override { |
3788 | return getFirstDecl(); |
3789 | } |
3790 | const UnresolvedUsingValueDecl *getCanonicalDecl() const { |
3791 | return getFirstDecl(); |
3792 | } |
3793 | |
3794 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3795 | static bool classofKind(Kind K) { return K == UnresolvedUsingValue; } |
3796 | }; |
3797 | |
3798 | /// Represents a dependent using declaration which was marked with |
3799 | /// \c typename. |
3800 | /// |
3801 | /// \code |
3802 | /// template \<class T> class A : public Base<T> { |
3803 | /// using typename Base<T>::foo; |
3804 | /// }; |
3805 | /// \endcode |
3806 | /// |
3807 | /// The type associated with an unresolved using typename decl is |
3808 | /// currently always a typename type. |
3809 | class UnresolvedUsingTypenameDecl |
3810 | : public TypeDecl, |
3811 | public Mergeable<UnresolvedUsingTypenameDecl> { |
3812 | friend class ASTDeclReader; |
3813 | |
3814 | /// The source location of the 'typename' keyword |
3815 | SourceLocation TypenameLocation; |
3816 | |
3817 | /// If this is a pack expansion, the location of the '...'. |
3818 | SourceLocation EllipsisLoc; |
3819 | |
3820 | /// The nested-name-specifier that precedes the name. |
3821 | NestedNameSpecifierLoc QualifierLoc; |
3822 | |
3823 | UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc, |
3824 | SourceLocation TypenameLoc, |
3825 | NestedNameSpecifierLoc QualifierLoc, |
3826 | SourceLocation TargetNameLoc, |
3827 | IdentifierInfo *TargetName, |
3828 | SourceLocation EllipsisLoc) |
3829 | : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName, |
3830 | UsingLoc), |
3831 | TypenameLocation(TypenameLoc), EllipsisLoc(EllipsisLoc), |
3832 | QualifierLoc(QualifierLoc) {} |
3833 | |
3834 | void anchor() override; |
3835 | |
3836 | public: |
3837 | /// Returns the source location of the 'using' keyword. |
3838 | SourceLocation getUsingLoc() const { return getBeginLoc(); } |
3839 | |
3840 | /// Returns the source location of the 'typename' keyword. |
3841 | SourceLocation getTypenameLoc() const { return TypenameLocation; } |
3842 | |
3843 | /// Retrieve the nested-name-specifier that qualifies the name, |
3844 | /// with source-location information. |
3845 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3846 | |
3847 | /// Retrieve the nested-name-specifier that qualifies the name. |
3848 | NestedNameSpecifier *getQualifier() const { |
3849 | return QualifierLoc.getNestedNameSpecifier(); |
3850 | } |
3851 | |
3852 | DeclarationNameInfo getNameInfo() const { |
3853 | return DeclarationNameInfo(getDeclName(), getLocation()); |
3854 | } |
3855 | |
3856 | /// Determine whether this is a pack expansion. |
3857 | bool isPackExpansion() const { |
3858 | return EllipsisLoc.isValid(); |
3859 | } |
3860 | |
3861 | /// Get the location of the ellipsis if this is a pack expansion. |
3862 | SourceLocation getEllipsisLoc() const { |
3863 | return EllipsisLoc; |
3864 | } |
3865 | |
3866 | static UnresolvedUsingTypenameDecl * |
3867 | Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, |
3868 | SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc, |
3869 | SourceLocation TargetNameLoc, DeclarationName TargetName, |
3870 | SourceLocation EllipsisLoc); |
3871 | |
3872 | static UnresolvedUsingTypenameDecl * |
3873 | CreateDeserialized(ASTContext &C, unsigned ID); |
3874 | |
3875 | /// Retrieves the canonical declaration of this declaration. |
3876 | UnresolvedUsingTypenameDecl *getCanonicalDecl() override { |
3877 | return getFirstDecl(); |
3878 | } |
3879 | const UnresolvedUsingTypenameDecl *getCanonicalDecl() const { |
3880 | return getFirstDecl(); |
3881 | } |
3882 | |
3883 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3884 | static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; } |
3885 | }; |
3886 | |
3887 | /// This node is generated when a using-declaration that was annotated with |
3888 | /// __attribute__((using_if_exists)) failed to resolve to a known declaration. |
3889 | /// In that case, Sema builds a UsingShadowDecl whose target is an instance of |
3890 | /// this declaration, adding it to the current scope. Referring to this |
3891 | /// declaration in any way is an error. |
3892 | class UnresolvedUsingIfExistsDecl final : public NamedDecl { |
3893 | UnresolvedUsingIfExistsDecl(DeclContext *DC, SourceLocation Loc, |
3894 | DeclarationName Name); |
3895 | |
3896 | void anchor() override; |
3897 | |
3898 | public: |
3899 | static UnresolvedUsingIfExistsDecl *Create(ASTContext &Ctx, DeclContext *DC, |
3900 | SourceLocation Loc, |
3901 | DeclarationName Name); |
3902 | static UnresolvedUsingIfExistsDecl *CreateDeserialized(ASTContext &Ctx, |
3903 | unsigned ID); |
3904 | |
3905 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3906 | static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingIfExists; } |
3907 | }; |
3908 | |
3909 | /// Represents a C++11 static_assert declaration. |
3910 | class StaticAssertDecl : public Decl { |
3911 | llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed; |
3912 | StringLiteral *Message; |
3913 | SourceLocation RParenLoc; |
3914 | |
3915 | StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc, |
3916 | Expr *AssertExpr, StringLiteral *Message, |
3917 | SourceLocation RParenLoc, bool Failed) |
3918 | : Decl(StaticAssert, DC, StaticAssertLoc), |
3919 | AssertExprAndFailed(AssertExpr, Failed), Message(Message), |
3920 | RParenLoc(RParenLoc) {} |
3921 | |
3922 | virtual void anchor(); |
3923 | |
3924 | public: |
3925 | friend class ASTDeclReader; |
3926 | |
3927 | static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC, |
3928 | SourceLocation StaticAssertLoc, |
3929 | Expr *AssertExpr, StringLiteral *Message, |
3930 | SourceLocation RParenLoc, bool Failed); |
3931 | static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3932 | |
3933 | Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); } |
3934 | const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); } |
3935 | |
3936 | StringLiteral *getMessage() { return Message; } |
3937 | const StringLiteral *getMessage() const { return Message; } |
3938 | |
3939 | bool isFailed() const { return AssertExprAndFailed.getInt(); } |
3940 | |
3941 | SourceLocation getRParenLoc() const { return RParenLoc; } |
3942 | |
3943 | SourceRange getSourceRange() const override LLVM_READONLY__attribute__((__pure__)) { |
3944 | return SourceRange(getLocation(), getRParenLoc()); |
3945 | } |
3946 | |
3947 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3948 | static bool classofKind(Kind K) { return K == StaticAssert; } |
3949 | }; |
3950 | |
3951 | /// A binding in a decomposition declaration. For instance, given: |
3952 | /// |
3953 | /// int n[3]; |
3954 | /// auto &[a, b, c] = n; |
3955 | /// |
3956 | /// a, b, and c are BindingDecls, whose bindings are the expressions |
3957 | /// x[0], x[1], and x[2] respectively, where x is the implicit |
3958 | /// DecompositionDecl of type 'int (&)[3]'. |
3959 | class BindingDecl : public ValueDecl { |
3960 | /// The declaration that this binding binds to part of. |
3961 | ValueDecl *Decomp; |
3962 | /// The binding represented by this declaration. References to this |
3963 | /// declaration are effectively equivalent to this expression (except |
3964 | /// that it is only evaluated once at the point of declaration of the |
3965 | /// binding). |
3966 | Expr *Binding = nullptr; |
3967 | |
3968 | BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id) |
3969 | : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()) {} |
3970 | |
3971 | void anchor() override; |
3972 | |
3973 | public: |
3974 | friend class ASTDeclReader; |
3975 | |
3976 | static BindingDecl *Create(ASTContext &C, DeclContext *DC, |
3977 | SourceLocation IdLoc, IdentifierInfo *Id); |
3978 | static BindingDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3979 | |
3980 | /// Get the expression to which this declaration is bound. This may be null |
3981 | /// in two different cases: while parsing the initializer for the |
3982 | /// decomposition declaration, and when the initializer is type-dependent. |
3983 | Expr *getBinding() const { return Binding; } |
3984 | |
3985 | /// Get the decomposition declaration that this binding represents a |
3986 | /// decomposition of. |
3987 | ValueDecl *getDecomposedDecl() const { return Decomp; } |
3988 | |
3989 | /// Get the variable (if any) that holds the value of evaluating the binding. |
3990 | /// Only present for user-defined bindings for tuple-like types. |
3991 | VarDecl *getHoldingVar() const; |
3992 | |
3993 | /// Set the binding for this BindingDecl, along with its declared type (which |
3994 | /// should be a possibly-cv-qualified form of the type of the binding, or a |
3995 | /// reference to such a type). |
3996 | void setBinding(QualType DeclaredType, Expr *Binding) { |
3997 | setType(DeclaredType); |
3998 | this->Binding = Binding; |
3999 | } |
4000 | |
4001 | /// Set the decomposed variable for this BindingDecl. |
4002 | void setDecomposedDecl(ValueDecl *Decomposed) { Decomp = Decomposed; } |
4003 | |
4004 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
4005 | static bool classofKind(Kind K) { return K == Decl::Binding; } |
4006 | }; |
4007 | |
4008 | /// A decomposition declaration. For instance, given: |
4009 | /// |
4010 | /// int n[3]; |
4011 | /// auto &[a, b, c] = n; |
4012 | /// |
4013 | /// the second line declares a DecompositionDecl of type 'int (&)[3]', and |
4014 | /// three BindingDecls (named a, b, and c). An instance of this class is always |
4015 | /// unnamed, but behaves in almost all other respects like a VarDecl. |
4016 | class DecompositionDecl final |
4017 | : public VarDecl, |
4018 | private llvm::TrailingObjects<DecompositionDecl, BindingDecl *> { |
4019 | /// The number of BindingDecl*s following this object. |
4020 | unsigned NumBindings; |
4021 | |
4022 | DecompositionDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
4023 | SourceLocation LSquareLoc, QualType T, |
4024 | TypeSourceInfo *TInfo, StorageClass SC, |
4025 | ArrayRef<BindingDecl *> Bindings) |
4026 | : VarDecl(Decomposition, C, DC, StartLoc, LSquareLoc, nullptr, T, TInfo, |
4027 | SC), |
4028 | NumBindings(Bindings.size()) { |
4029 | std::uninitialized_copy(Bindings.begin(), Bindings.end(), |
4030 | getTrailingObjects<BindingDecl *>()); |
4031 | for (auto *B : Bindings) |
4032 | B->setDecomposedDecl(this); |
4033 | } |
4034 | |
4035 | void anchor() override; |
4036 | |
4037 | public: |
4038 | friend class ASTDeclReader; |
4039 | friend TrailingObjects; |
4040 | |
4041 | static DecompositionDecl *Create(ASTContext &C, DeclContext *DC, |
4042 | SourceLocation StartLoc, |
4043 | SourceLocation LSquareLoc, |
4044 | QualType T, TypeSourceInfo *TInfo, |
4045 | StorageClass S, |
4046 | ArrayRef<BindingDecl *> Bindings); |
4047 | static DecompositionDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
4048 | unsigned NumBindings); |
4049 | |
4050 | ArrayRef<BindingDecl *> bindings() const { |
4051 | return llvm::makeArrayRef(getTrailingObjects<BindingDecl *>(), NumBindings); |
4052 | } |
4053 | |
4054 | void printName(raw_ostream &os) const override; |
4055 | |
4056 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
4057 | static bool classofKind(Kind K) { return K == Decomposition; } |
4058 | }; |
4059 | |
4060 | /// An instance of this class represents the declaration of a property |
4061 | /// member. This is a Microsoft extension to C++, first introduced in |
4062 | /// Visual Studio .NET 2003 as a parallel to similar features in C# |
4063 | /// and Managed C++. |
4064 | /// |
4065 | /// A property must always be a non-static class member. |
4066 | /// |
4067 | /// A property member superficially resembles a non-static data |
4068 | /// member, except preceded by a property attribute: |
4069 | /// __declspec(property(get=GetX, put=PutX)) int x; |
4070 | /// Either (but not both) of the 'get' and 'put' names may be omitted. |
4071 | /// |
4072 | /// A reference to a property is always an lvalue. If the lvalue |
4073 | /// undergoes lvalue-to-rvalue conversion, then a getter name is |
4074 | /// required, and that member is called with no arguments. |
4075 | /// If the lvalue is assigned into, then a setter name is required, |
4076 | /// and that member is called with one argument, the value assigned. |
4077 | /// Both operations are potentially overloaded. Compound assignments |
4078 | /// are permitted, as are the increment and decrement operators. |
4079 | /// |
4080 | /// The getter and putter methods are permitted to be overloaded, |
4081 | /// although their return and parameter types are subject to certain |
4082 | /// restrictions according to the type of the property. |
4083 | /// |
4084 | /// A property declared using an incomplete array type may |
4085 | /// additionally be subscripted, adding extra parameters to the getter |
4086 | /// and putter methods. |
4087 | class MSPropertyDecl : public DeclaratorDecl { |
4088 | IdentifierInfo *GetterId, *SetterId; |
4089 | |
4090 | MSPropertyDecl(DeclContext *DC, SourceLocation L, DeclarationName N, |
4091 | QualType T, TypeSourceInfo *TInfo, SourceLocation StartL, |
4092 | IdentifierInfo *Getter, IdentifierInfo *Setter) |
4093 | : DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL), |
4094 | GetterId(Getter), SetterId(Setter) {} |
4095 | |
4096 | void anchor() override; |
4097 | public: |
4098 | friend class ASTDeclReader; |
4099 | |
4100 | static MSPropertyDecl *Create(ASTContext &C, DeclContext *DC, |
4101 | SourceLocation L, DeclarationName N, QualType T, |
4102 | TypeSourceInfo *TInfo, SourceLocation StartL, |
4103 | IdentifierInfo *Getter, IdentifierInfo *Setter); |
4104 | static MSPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
4105 | |
4106 | static bool classof(const Decl *D) { return D->getKind() == MSProperty; } |
4107 | |
4108 | bool hasGetter() const { return GetterId != nullptr; } |
4109 | IdentifierInfo* getGetterId() const { return GetterId; } |
4110 | bool hasSetter() const { return SetterId != nullptr; } |
4111 | IdentifierInfo* getSetterId() const { return SetterId; } |
4112 | }; |
4113 | |
4114 | /// Parts of a decomposed MSGuidDecl. Factored out to avoid unnecessary |
4115 | /// dependencies on DeclCXX.h. |
4116 | struct MSGuidDeclParts { |
4117 | /// {01234567-... |
4118 | uint32_t Part1; |
4119 | /// ...-89ab-... |
4120 | uint16_t Part2; |
4121 | /// ...-cdef-... |
4122 | uint16_t Part3; |
4123 | /// ...-0123-456789abcdef} |
4124 | uint8_t Part4And5[8]; |
4125 | |
4126 | uint64_t getPart4And5AsUint64() const { |
4127 | uint64_t Val; |
4128 | memcpy(&Val, &Part4And5, sizeof(Part4And5)); |
4129 | return Val; |
4130 | } |
4131 | }; |
4132 | |
4133 | /// A global _GUID constant. These are implicitly created by UuidAttrs. |
4134 | /// |
4135 | /// struct _declspec(uuid("01234567-89ab-cdef-0123-456789abcdef")) X{}; |
4136 | /// |
4137 | /// X is a CXXRecordDecl that contains a UuidAttr that references the (unique) |
4138 | /// MSGuidDecl for the specified UUID. |
4139 | class MSGuidDecl : public ValueDecl, |
4140 | public Mergeable<MSGuidDecl>, |
4141 | public llvm::FoldingSetNode { |
4142 | public: |
4143 | using Parts = MSGuidDeclParts; |
4144 | |
4145 | private: |
4146 | /// The decomposed form of the UUID. |
4147 | Parts PartVal; |
4148 | |
4149 | /// The resolved value of the UUID as an APValue. Computed on demand and |
4150 | /// cached. |
4151 | mutable APValue APVal; |
4152 | |
4153 | void anchor() override; |
4154 | |
4155 | MSGuidDecl(DeclContext *DC, QualType T, Parts P); |
4156 | |
4157 | static MSGuidDecl *Create(const ASTContext &C, QualType T, Parts P); |
4158 | static MSGuidDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
4159 | |
4160 | // Only ASTContext::getMSGuidDecl and deserialization create these. |
4161 | friend class ASTContext; |
4162 | friend class ASTReader; |
4163 | friend class ASTDeclReader; |
4164 | |
4165 | public: |
4166 | /// Print this UUID in a human-readable format. |
4167 | void printName(llvm::raw_ostream &OS) const override; |
4168 | |
4169 | /// Get the decomposed parts of this declaration. |
4170 | Parts getParts() const { return PartVal; } |
4171 | |
4172 | /// Get the value of this MSGuidDecl as an APValue. This may fail and return |
4173 | /// an absent APValue if the type of the declaration is not of the expected |
4174 | /// shape. |
4175 | APValue &getAsAPValue() const; |
4176 | |
4177 | static void Profile(llvm::FoldingSetNodeID &ID, Parts P) { |
4178 | ID.AddInteger(P.Part1); |
4179 | ID.AddInteger(P.Part2); |
4180 | ID.AddInteger(P.Part3); |
4181 | ID.AddInteger(P.getPart4And5AsUint64()); |
4182 | } |
4183 | void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, PartVal); } |
4184 | |
4185 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
4186 | static bool classofKind(Kind K) { return K == Decl::MSGuid; } |
4187 | }; |
4188 | |
4189 | /// Insertion operator for diagnostics. This allows sending an AccessSpecifier |
4190 | /// into a diagnostic with <<. |
4191 | const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB, |
4192 | AccessSpecifier AS); |
4193 | |
4194 | } // namespace clang |
4195 | |
4196 | #endif // LLVM_CLANG_AST_DECLCXX_H |