1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | #include "clang/Sema/SemaInternal.h" |
12 | #include "clang/AST/ASTConsumer.h" |
13 | #include "clang/AST/ASTContext.h" |
14 | #include "clang/AST/ASTMutationListener.h" |
15 | #include "clang/AST/DeclTemplate.h" |
16 | #include "clang/AST/DeclVisitor.h" |
17 | #include "clang/AST/DependentDiagnostic.h" |
18 | #include "clang/AST/Expr.h" |
19 | #include "clang/AST/ExprCXX.h" |
20 | #include "clang/AST/PrettyDeclStackTrace.h" |
21 | #include "clang/AST/TypeLoc.h" |
22 | #include "clang/Sema/Initialization.h" |
23 | #include "clang/Sema/Lookup.h" |
24 | #include "clang/Sema/Template.h" |
25 | #include "clang/Sema/TemplateInstCallback.h" |
26 | |
27 | using namespace clang; |
28 | |
29 | static bool isDeclWithinFunction(const Decl *D) { |
30 | const DeclContext *DC = D->getDeclContext(); |
31 | if (DC->isFunctionOrMethod()) |
32 | return true; |
33 | |
34 | if (DC->isRecord()) |
35 | return cast<CXXRecordDecl>(DC)->isLocalClass(); |
36 | |
37 | return false; |
38 | } |
39 | |
40 | template<typename DeclT> |
41 | static bool SubstQualifier(Sema &SemaRef, const DeclT *OldDecl, DeclT *NewDecl, |
42 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
43 | if (!OldDecl->getQualifierLoc()) |
44 | return false; |
45 | |
46 | (0) . __assert_fail ("(NewDecl->getFriendObjectKind() || !OldDecl->getLexicalDeclContext()->isDependentContext()) && \"non-friend with qualified name defined in dependent context\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 48, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((NewDecl->getFriendObjectKind() || |
47 | (0) . __assert_fail ("(NewDecl->getFriendObjectKind() || !OldDecl->getLexicalDeclContext()->isDependentContext()) && \"non-friend with qualified name defined in dependent context\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 48, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> !OldDecl->getLexicalDeclContext()->isDependentContext()) && |
48 | (0) . __assert_fail ("(NewDecl->getFriendObjectKind() || !OldDecl->getLexicalDeclContext()->isDependentContext()) && \"non-friend with qualified name defined in dependent context\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 48, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "non-friend with qualified name defined in dependent context"); |
49 | Sema::ContextRAII SavedContext( |
50 | SemaRef, |
51 | const_cast<DeclContext *>(NewDecl->getFriendObjectKind() |
52 | ? NewDecl->getLexicalDeclContext() |
53 | : OldDecl->getLexicalDeclContext())); |
54 | |
55 | NestedNameSpecifierLoc NewQualifierLoc |
56 | = SemaRef.SubstNestedNameSpecifierLoc(OldDecl->getQualifierLoc(), |
57 | TemplateArgs); |
58 | |
59 | if (!NewQualifierLoc) |
60 | return true; |
61 | |
62 | NewDecl->setQualifierInfo(NewQualifierLoc); |
63 | return false; |
64 | } |
65 | |
66 | bool TemplateDeclInstantiator::SubstQualifier(const DeclaratorDecl *OldDecl, |
67 | DeclaratorDecl *NewDecl) { |
68 | return ::SubstQualifier(SemaRef, OldDecl, NewDecl, TemplateArgs); |
69 | } |
70 | |
71 | bool TemplateDeclInstantiator::SubstQualifier(const TagDecl *OldDecl, |
72 | TagDecl *NewDecl) { |
73 | return ::SubstQualifier(SemaRef, OldDecl, NewDecl, TemplateArgs); |
74 | } |
75 | |
76 | |
77 | #include "clang/Sema/AttrTemplateInstantiate.inc" |
78 | |
79 | static void instantiateDependentAlignedAttr( |
80 | Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, |
81 | const AlignedAttr *Aligned, Decl *New, bool IsPackExpansion) { |
82 | if (Aligned->isAlignmentExpr()) { |
83 | |
84 | EnterExpressionEvaluationContext Unevaluated( |
85 | S, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
86 | ExprResult Result = S.SubstExpr(Aligned->getAlignmentExpr(), TemplateArgs); |
87 | if (!Result.isInvalid()) |
88 | S.AddAlignedAttr(Aligned->getLocation(), New, Result.getAs<Expr>(), |
89 | Aligned->getSpellingListIndex(), IsPackExpansion); |
90 | } else { |
91 | TypeSourceInfo *Result = S.SubstType(Aligned->getAlignmentType(), |
92 | TemplateArgs, Aligned->getLocation(), |
93 | DeclarationName()); |
94 | if (Result) |
95 | S.AddAlignedAttr(Aligned->getLocation(), New, Result, |
96 | Aligned->getSpellingListIndex(), IsPackExpansion); |
97 | } |
98 | } |
99 | |
100 | static void instantiateDependentAlignedAttr( |
101 | Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, |
102 | const AlignedAttr *Aligned, Decl *New) { |
103 | if (!Aligned->isPackExpansion()) { |
104 | instantiateDependentAlignedAttr(S, TemplateArgs, Aligned, New, false); |
105 | return; |
106 | } |
107 | |
108 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
109 | if (Aligned->isAlignmentExpr()) |
110 | S.collectUnexpandedParameterPacks(Aligned->getAlignmentExpr(), |
111 | Unexpanded); |
112 | else |
113 | S.collectUnexpandedParameterPacks(Aligned->getAlignmentType()->getTypeLoc(), |
114 | Unexpanded); |
115 | (0) . __assert_fail ("!Unexpanded.empty() && \"Pack expansion without parameter packs?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 115, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); |
116 | |
117 | |
118 | bool Expand = true, RetainExpansion = false; |
119 | Optional<unsigned> NumExpansions; |
120 | |
121 | SourceLocation EllipsisLoc = Aligned->getLocation(); |
122 | if (S.CheckParameterPacksForExpansion(EllipsisLoc, Aligned->getRange(), |
123 | Unexpanded, TemplateArgs, Expand, |
124 | RetainExpansion, NumExpansions)) |
125 | return; |
126 | |
127 | if (!Expand) { |
128 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(S, -1); |
129 | instantiateDependentAlignedAttr(S, TemplateArgs, Aligned, New, true); |
130 | } else { |
131 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
132 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(S, I); |
133 | instantiateDependentAlignedAttr(S, TemplateArgs, Aligned, New, false); |
134 | } |
135 | } |
136 | } |
137 | |
138 | static void instantiateDependentAssumeAlignedAttr( |
139 | Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, |
140 | const AssumeAlignedAttr *Aligned, Decl *New) { |
141 | |
142 | EnterExpressionEvaluationContext Unevaluated( |
143 | S, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
144 | |
145 | Expr *E, *OE = nullptr; |
146 | ExprResult Result = S.SubstExpr(Aligned->getAlignment(), TemplateArgs); |
147 | if (Result.isInvalid()) |
148 | return; |
149 | E = Result.getAs<Expr>(); |
150 | |
151 | if (Aligned->getOffset()) { |
152 | Result = S.SubstExpr(Aligned->getOffset(), TemplateArgs); |
153 | if (Result.isInvalid()) |
154 | return; |
155 | OE = Result.getAs<Expr>(); |
156 | } |
157 | |
158 | S.AddAssumeAlignedAttr(Aligned->getLocation(), New, E, OE, |
159 | Aligned->getSpellingListIndex()); |
160 | } |
161 | |
162 | static void instantiateDependentAlignValueAttr( |
163 | Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, |
164 | const AlignValueAttr *Aligned, Decl *New) { |
165 | |
166 | EnterExpressionEvaluationContext Unevaluated( |
167 | S, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
168 | ExprResult Result = S.SubstExpr(Aligned->getAlignment(), TemplateArgs); |
169 | if (!Result.isInvalid()) |
170 | S.AddAlignValueAttr(Aligned->getLocation(), New, Result.getAs<Expr>(), |
171 | Aligned->getSpellingListIndex()); |
172 | } |
173 | |
174 | static void instantiateDependentAllocAlignAttr( |
175 | Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, |
176 | const AllocAlignAttr *Align, Decl *New) { |
177 | Expr *Param = IntegerLiteral::Create( |
178 | S.getASTContext(), |
179 | llvm::APInt(64, Align->getParamIndex().getSourceIndex()), |
180 | S.getASTContext().UnsignedLongLongTy, Align->getLocation()); |
181 | S.AddAllocAlignAttr(Align->getLocation(), New, Param, |
182 | Align->getSpellingListIndex()); |
183 | } |
184 | |
185 | static Expr *instantiateDependentFunctionAttrCondition( |
186 | Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, |
187 | const Attr *A, Expr *OldCond, const Decl *Tmpl, FunctionDecl *New) { |
188 | Expr *Cond = nullptr; |
189 | { |
190 | Sema::ContextRAII SwitchContext(S, New); |
191 | EnterExpressionEvaluationContext Unevaluated( |
192 | S, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
193 | ExprResult Result = S.SubstExpr(OldCond, TemplateArgs); |
194 | if (Result.isInvalid()) |
195 | return nullptr; |
196 | Cond = Result.getAs<Expr>(); |
197 | } |
198 | if (!Cond->isTypeDependent()) { |
199 | ExprResult Converted = S.PerformContextuallyConvertToBool(Cond); |
200 | if (Converted.isInvalid()) |
201 | return nullptr; |
202 | Cond = Converted.get(); |
203 | } |
204 | |
205 | SmallVector<PartialDiagnosticAt, 8> Diags; |
206 | if (OldCond->isValueDependent() && !Cond->isValueDependent() && |
207 | !Expr::isPotentialConstantExprUnevaluated(Cond, New, Diags)) { |
208 | S.Diag(A->getLocation(), diag::err_attr_cond_never_constant_expr) << A; |
209 | for (const auto &P : Diags) |
210 | S.Diag(P.first, P.second); |
211 | return nullptr; |
212 | } |
213 | return Cond; |
214 | } |
215 | |
216 | static void instantiateDependentEnableIfAttr( |
217 | Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, |
218 | const EnableIfAttr *EIA, const Decl *Tmpl, FunctionDecl *New) { |
219 | Expr *Cond = instantiateDependentFunctionAttrCondition( |
220 | S, TemplateArgs, EIA, EIA->getCond(), Tmpl, New); |
221 | |
222 | if (Cond) |
223 | New->addAttr(new (S.getASTContext()) EnableIfAttr( |
224 | EIA->getLocation(), S.getASTContext(), Cond, EIA->getMessage(), |
225 | EIA->getSpellingListIndex())); |
226 | } |
227 | |
228 | static void instantiateDependentDiagnoseIfAttr( |
229 | Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, |
230 | const DiagnoseIfAttr *DIA, const Decl *Tmpl, FunctionDecl *New) { |
231 | Expr *Cond = instantiateDependentFunctionAttrCondition( |
232 | S, TemplateArgs, DIA, DIA->getCond(), Tmpl, New); |
233 | |
234 | if (Cond) |
235 | New->addAttr(new (S.getASTContext()) DiagnoseIfAttr( |
236 | DIA->getLocation(), S.getASTContext(), Cond, DIA->getMessage(), |
237 | DIA->getDiagnosticType(), DIA->getArgDependent(), New, |
238 | DIA->getSpellingListIndex())); |
239 | } |
240 | |
241 | |
242 | |
243 | static void instantiateDependentCUDALaunchBoundsAttr( |
244 | Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, |
245 | const CUDALaunchBoundsAttr &Attr, Decl *New) { |
246 | |
247 | EnterExpressionEvaluationContext Unevaluated( |
248 | S, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
249 | |
250 | ExprResult Result = S.SubstExpr(Attr.getMaxThreads(), TemplateArgs); |
251 | if (Result.isInvalid()) |
252 | return; |
253 | Expr *MaxThreads = Result.getAs<Expr>(); |
254 | |
255 | Expr *MinBlocks = nullptr; |
256 | if (Attr.getMinBlocks()) { |
257 | Result = S.SubstExpr(Attr.getMinBlocks(), TemplateArgs); |
258 | if (Result.isInvalid()) |
259 | return; |
260 | MinBlocks = Result.getAs<Expr>(); |
261 | } |
262 | |
263 | S.AddLaunchBoundsAttr(Attr.getLocation(), New, MaxThreads, MinBlocks, |
264 | Attr.getSpellingListIndex()); |
265 | } |
266 | |
267 | static void |
268 | instantiateDependentModeAttr(Sema &S, |
269 | const MultiLevelTemplateArgumentList &TemplateArgs, |
270 | const ModeAttr &Attr, Decl *New) { |
271 | S.AddModeAttr(Attr.getRange(), New, Attr.getMode(), |
272 | Attr.getSpellingListIndex(), ); |
273 | } |
274 | |
275 | |
276 | static void instantiateOMPDeclareSimdDeclAttr( |
277 | Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, |
278 | const OMPDeclareSimdDeclAttr &Attr, Decl *New) { |
279 | |
280 | if (auto *FTD = dyn_cast<FunctionTemplateDecl>(New)) |
281 | New = FTD->getTemplatedDecl(); |
282 | auto *FD = cast<FunctionDecl>(New); |
283 | auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(FD->getDeclContext()); |
284 | SmallVector<Expr *, 4> Uniforms, Aligneds, Alignments, Linears, Steps; |
285 | SmallVector<unsigned, 4> LinModifiers; |
286 | |
287 | auto &&Subst = [&](Expr *E) -> ExprResult { |
288 | if (auto *DRE = dyn_cast<DeclRefExpr>(E->IgnoreParenImpCasts())) |
289 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
290 | Sema::ContextRAII SavedContext(S, FD); |
291 | LocalInstantiationScope Local(S); |
292 | if (FD->getNumParams() > PVD->getFunctionScopeIndex()) |
293 | Local.InstantiatedLocal( |
294 | PVD, FD->getParamDecl(PVD->getFunctionScopeIndex())); |
295 | return S.SubstExpr(E, TemplateArgs); |
296 | } |
297 | Sema::CXXThisScopeRAII ThisScope(S, ThisContext, Qualifiers(), |
298 | FD->isCXXInstanceMember()); |
299 | return S.SubstExpr(E, TemplateArgs); |
300 | }; |
301 | |
302 | ExprResult Simdlen; |
303 | if (auto *E = Attr.getSimdlen()) |
304 | Simdlen = Subst(E); |
305 | |
306 | if (Attr.uniforms_size() > 0) { |
307 | for(auto *E : Attr.uniforms()) { |
308 | ExprResult Inst = Subst(E); |
309 | if (Inst.isInvalid()) |
310 | continue; |
311 | Uniforms.push_back(Inst.get()); |
312 | } |
313 | } |
314 | |
315 | auto AI = Attr.alignments_begin(); |
316 | for (auto *E : Attr.aligneds()) { |
317 | ExprResult Inst = Subst(E); |
318 | if (Inst.isInvalid()) |
319 | continue; |
320 | Aligneds.push_back(Inst.get()); |
321 | Inst = ExprEmpty(); |
322 | if (*AI) |
323 | Inst = S.SubstExpr(*AI, TemplateArgs); |
324 | Alignments.push_back(Inst.get()); |
325 | ++AI; |
326 | } |
327 | |
328 | auto SI = Attr.steps_begin(); |
329 | for (auto *E : Attr.linears()) { |
330 | ExprResult Inst = Subst(E); |
331 | if (Inst.isInvalid()) |
332 | continue; |
333 | Linears.push_back(Inst.get()); |
334 | Inst = ExprEmpty(); |
335 | if (*SI) |
336 | Inst = S.SubstExpr(*SI, TemplateArgs); |
337 | Steps.push_back(Inst.get()); |
338 | ++SI; |
339 | } |
340 | LinModifiers.append(Attr.modifiers_begin(), Attr.modifiers_end()); |
341 | (void)S.ActOnOpenMPDeclareSimdDirective( |
342 | S.ConvertDeclToDeclGroup(New), Attr.getBranchState(), Simdlen.get(), |
343 | Uniforms, Aligneds, Alignments, Linears, LinModifiers, Steps, |
344 | Attr.getRange()); |
345 | } |
346 | |
347 | static void instantiateDependentAMDGPUFlatWorkGroupSizeAttr( |
348 | Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, |
349 | const AMDGPUFlatWorkGroupSizeAttr &Attr, Decl *New) { |
350 | |
351 | EnterExpressionEvaluationContext Unevaluated( |
352 | S, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
353 | |
354 | ExprResult Result = S.SubstExpr(Attr.getMin(), TemplateArgs); |
355 | if (Result.isInvalid()) |
356 | return; |
357 | Expr *MinExpr = Result.getAs<Expr>(); |
358 | |
359 | Result = S.SubstExpr(Attr.getMax(), TemplateArgs); |
360 | if (Result.isInvalid()) |
361 | return; |
362 | Expr *MaxExpr = Result.getAs<Expr>(); |
363 | |
364 | S.addAMDGPUFlatWorkGroupSizeAttr(Attr.getLocation(), New, MinExpr, MaxExpr, |
365 | Attr.getSpellingListIndex()); |
366 | } |
367 | |
368 | static void instantiateDependentAMDGPUWavesPerEUAttr( |
369 | Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, |
370 | const AMDGPUWavesPerEUAttr &Attr, Decl *New) { |
371 | |
372 | EnterExpressionEvaluationContext Unevaluated( |
373 | S, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
374 | |
375 | ExprResult Result = S.SubstExpr(Attr.getMin(), TemplateArgs); |
376 | if (Result.isInvalid()) |
377 | return; |
378 | Expr *MinExpr = Result.getAs<Expr>(); |
379 | |
380 | Expr *MaxExpr = nullptr; |
381 | if (auto Max = Attr.getMax()) { |
382 | Result = S.SubstExpr(Max, TemplateArgs); |
383 | if (Result.isInvalid()) |
384 | return; |
385 | MaxExpr = Result.getAs<Expr>(); |
386 | } |
387 | |
388 | S.addAMDGPUWavesPerEUAttr(Attr.getLocation(), New, MinExpr, MaxExpr, |
389 | Attr.getSpellingListIndex()); |
390 | } |
391 | |
392 | void Sema::InstantiateAttrsForDecl( |
393 | const MultiLevelTemplateArgumentList &TemplateArgs, const Decl *Tmpl, |
394 | Decl *New, LateInstantiatedAttrVec *LateAttrs, |
395 | LocalInstantiationScope *OuterMostScope) { |
396 | if (NamedDecl *ND = dyn_cast<NamedDecl>(New)) { |
397 | for (const auto *TmplAttr : Tmpl->attrs()) { |
398 | |
399 | |
400 | CXXThisScopeRAII ThisScope( |
401 | *this, dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext()), |
402 | Qualifiers(), ND->isCXXInstanceMember()); |
403 | |
404 | Attr *NewAttr = sema::instantiateTemplateAttributeForDecl( |
405 | TmplAttr, Context, *this, TemplateArgs); |
406 | if (NewAttr) |
407 | New->addAttr(NewAttr); |
408 | } |
409 | } |
410 | } |
411 | |
412 | static Sema::RetainOwnershipKind |
413 | attrToRetainOwnershipKind(const Attr *A) { |
414 | switch (A->getKind()) { |
415 | case clang::attr::CFConsumed: |
416 | return Sema::RetainOwnershipKind::CF; |
417 | case clang::attr::OSConsumed: |
418 | return Sema::RetainOwnershipKind::OS; |
419 | case clang::attr::NSConsumed: |
420 | return Sema::RetainOwnershipKind::NS; |
421 | default: |
422 | llvm_unreachable("Wrong argument supplied"); |
423 | } |
424 | } |
425 | |
426 | void Sema::InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, |
427 | const Decl *Tmpl, Decl *New, |
428 | LateInstantiatedAttrVec *LateAttrs, |
429 | LocalInstantiationScope *OuterMostScope) { |
430 | for (const auto *TmplAttr : Tmpl->attrs()) { |
431 | |
432 | const AlignedAttr *Aligned = dyn_cast<AlignedAttr>(TmplAttr); |
433 | if (Aligned && Aligned->isAlignmentDependent()) { |
434 | instantiateDependentAlignedAttr(*this, TemplateArgs, Aligned, New); |
435 | continue; |
436 | } |
437 | |
438 | const AssumeAlignedAttr *AssumeAligned = dyn_cast<AssumeAlignedAttr>(TmplAttr); |
439 | if (AssumeAligned) { |
440 | instantiateDependentAssumeAlignedAttr(*this, TemplateArgs, AssumeAligned, New); |
441 | continue; |
442 | } |
443 | |
444 | const AlignValueAttr *AlignValue = dyn_cast<AlignValueAttr>(TmplAttr); |
445 | if (AlignValue) { |
446 | instantiateDependentAlignValueAttr(*this, TemplateArgs, AlignValue, New); |
447 | continue; |
448 | } |
449 | |
450 | if (const auto *AllocAlign = dyn_cast<AllocAlignAttr>(TmplAttr)) { |
451 | instantiateDependentAllocAlignAttr(*this, TemplateArgs, AllocAlign, New); |
452 | continue; |
453 | } |
454 | |
455 | |
456 | if (const auto *EnableIf = dyn_cast<EnableIfAttr>(TmplAttr)) { |
457 | instantiateDependentEnableIfAttr(*this, TemplateArgs, EnableIf, Tmpl, |
458 | cast<FunctionDecl>(New)); |
459 | continue; |
460 | } |
461 | |
462 | if (const auto *DiagnoseIf = dyn_cast<DiagnoseIfAttr>(TmplAttr)) { |
463 | instantiateDependentDiagnoseIfAttr(*this, TemplateArgs, DiagnoseIf, Tmpl, |
464 | cast<FunctionDecl>(New)); |
465 | continue; |
466 | } |
467 | |
468 | if (const CUDALaunchBoundsAttr *CUDALaunchBounds = |
469 | dyn_cast<CUDALaunchBoundsAttr>(TmplAttr)) { |
470 | instantiateDependentCUDALaunchBoundsAttr(*this, TemplateArgs, |
471 | *CUDALaunchBounds, New); |
472 | continue; |
473 | } |
474 | |
475 | if (const ModeAttr *Mode = dyn_cast<ModeAttr>(TmplAttr)) { |
476 | instantiateDependentModeAttr(*this, TemplateArgs, *Mode, New); |
477 | continue; |
478 | } |
479 | |
480 | if (const auto *OMPAttr = dyn_cast<OMPDeclareSimdDeclAttr>(TmplAttr)) { |
481 | instantiateOMPDeclareSimdDeclAttr(*this, TemplateArgs, *OMPAttr, New); |
482 | continue; |
483 | } |
484 | |
485 | if (const AMDGPUFlatWorkGroupSizeAttr *AMDGPUFlatWorkGroupSize = |
486 | dyn_cast<AMDGPUFlatWorkGroupSizeAttr>(TmplAttr)) { |
487 | instantiateDependentAMDGPUFlatWorkGroupSizeAttr( |
488 | *this, TemplateArgs, *AMDGPUFlatWorkGroupSize, New); |
489 | } |
490 | |
491 | if (const AMDGPUWavesPerEUAttr *AMDGPUFlatWorkGroupSize = |
492 | dyn_cast<AMDGPUWavesPerEUAttr>(TmplAttr)) { |
493 | instantiateDependentAMDGPUWavesPerEUAttr(*this, TemplateArgs, |
494 | *AMDGPUFlatWorkGroupSize, New); |
495 | } |
496 | |
497 | |
498 | if (TmplAttr->getKind() == attr::DLLExport || |
499 | TmplAttr->getKind() == attr::DLLImport) { |
500 | if (New->hasAttr<DLLExportAttr>() || New->hasAttr<DLLImportAttr>()) { |
501 | continue; |
502 | } |
503 | } |
504 | |
505 | if (auto ABIAttr = dyn_cast<ParameterABIAttr>(TmplAttr)) { |
506 | AddParameterABIAttr(ABIAttr->getRange(), New, ABIAttr->getABI(), |
507 | ABIAttr->getSpellingListIndex()); |
508 | continue; |
509 | } |
510 | |
511 | if (isa<NSConsumedAttr>(TmplAttr) || isa<OSConsumedAttr>(TmplAttr) || |
512 | isa<CFConsumedAttr>(TmplAttr)) { |
513 | AddXConsumedAttr(New, TmplAttr->getRange(), |
514 | TmplAttr->getSpellingListIndex(), |
515 | attrToRetainOwnershipKind(TmplAttr), |
516 | ); |
517 | continue; |
518 | } |
519 | |
520 | isPackExpansion()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 520, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!TmplAttr->isPackExpansion()); |
521 | if (TmplAttr->isLateParsed() && LateAttrs) { |
522 | |
523 | |
524 | LocalInstantiationScope *Saved = nullptr; |
525 | if (CurrentInstantiationScope) |
526 | Saved = CurrentInstantiationScope->cloneScopes(OuterMostScope); |
527 | LateAttrs->push_back(LateInstantiatedAttribute(TmplAttr, Saved, New)); |
528 | } else { |
529 | |
530 | NamedDecl *ND = dyn_cast<NamedDecl>(New); |
531 | CXXRecordDecl *ThisContext = |
532 | dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext()); |
533 | CXXThisScopeRAII ThisScope(*this, ThisContext, Qualifiers(), |
534 | ND && ND->isCXXInstanceMember()); |
535 | |
536 | Attr *NewAttr = sema::instantiateTemplateAttribute(TmplAttr, Context, |
537 | *this, TemplateArgs); |
538 | if (NewAttr) |
539 | New->addAttr(NewAttr); |
540 | } |
541 | } |
542 | } |
543 | |
544 | |
545 | |
546 | |
547 | |
548 | template<typename DeclT> |
549 | static DeclT *getPreviousDeclForInstantiation(DeclT *D) { |
550 | DeclT *Result = D->getPreviousDecl(); |
551 | |
552 | |
553 | |
554 | |
555 | if (Result && isa<CXXRecordDecl>(D->getDeclContext()) && |
556 | D->getLexicalDeclContext() != Result->getLexicalDeclContext()) |
557 | return nullptr; |
558 | |
559 | return Result; |
560 | } |
561 | |
562 | Decl * |
563 | TemplateDeclInstantiator::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
564 | llvm_unreachable("Translation units cannot be instantiated"); |
565 | } |
566 | |
567 | Decl * |
568 | TemplateDeclInstantiator::(PragmaCommentDecl *D) { |
569 | llvm_unreachable("pragma comment cannot be instantiated"); |
570 | } |
571 | |
572 | Decl *TemplateDeclInstantiator::VisitPragmaDetectMismatchDecl( |
573 | PragmaDetectMismatchDecl *D) { |
574 | llvm_unreachable("pragma comment cannot be instantiated"); |
575 | } |
576 | |
577 | Decl * |
578 | TemplateDeclInstantiator::VisitExternCContextDecl(ExternCContextDecl *D) { |
579 | llvm_unreachable("extern \"C\" context cannot be instantiated"); |
580 | } |
581 | |
582 | Decl * |
583 | TemplateDeclInstantiator::VisitLabelDecl(LabelDecl *D) { |
584 | LabelDecl *Inst = LabelDecl::Create(SemaRef.Context, Owner, D->getLocation(), |
585 | D->getIdentifier()); |
586 | Owner->addDecl(Inst); |
587 | return Inst; |
588 | } |
589 | |
590 | Decl * |
591 | TemplateDeclInstantiator::VisitNamespaceDecl(NamespaceDecl *D) { |
592 | llvm_unreachable("Namespaces cannot be instantiated"); |
593 | } |
594 | |
595 | Decl * |
596 | TemplateDeclInstantiator::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
597 | NamespaceAliasDecl *Inst |
598 | = NamespaceAliasDecl::Create(SemaRef.Context, Owner, |
599 | D->getNamespaceLoc(), |
600 | D->getAliasLoc(), |
601 | D->getIdentifier(), |
602 | D->getQualifierLoc(), |
603 | D->getTargetNameLoc(), |
604 | D->getNamespace()); |
605 | Owner->addDecl(Inst); |
606 | return Inst; |
607 | } |
608 | |
609 | Decl *TemplateDeclInstantiator::InstantiateTypedefNameDecl(TypedefNameDecl *D, |
610 | bool IsTypeAlias) { |
611 | bool Invalid = false; |
612 | TypeSourceInfo *DI = D->getTypeSourceInfo(); |
613 | if (DI->getType()->isInstantiationDependentType() || |
614 | DI->getType()->isVariablyModifiedType()) { |
615 | DI = SemaRef.SubstType(DI, TemplateArgs, |
616 | D->getLocation(), D->getDeclName()); |
617 | if (!DI) { |
618 | Invalid = true; |
619 | DI = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.Context.IntTy); |
620 | } |
621 | } else { |
622 | SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), DI->getType()); |
623 | } |
624 | |
625 | |
626 | |
627 | |
628 | |
629 | const DecltypeType *DT = DI->getType()->getAs<DecltypeType>(); |
630 | CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D->getDeclContext()); |
631 | if (DT && RD && isa<ConditionalOperator>(DT->getUnderlyingExpr()) && |
632 | DT->isReferenceType() && |
633 | RD->getEnclosingNamespaceContext() == SemaRef.getStdNamespace() && |
634 | RD->getIdentifier() && RD->getIdentifier()->isStr("common_type") && |
635 | D->getIdentifier() && D->getIdentifier()->isStr("type") && |
636 | SemaRef.getSourceManager().isInSystemHeader(D->getBeginLoc())) |
637 | |
638 | DI = SemaRef.Context.getTrivialTypeSourceInfo( |
639 | DI->getType().getNonReferenceType()); |
640 | |
641 | |
642 | TypedefNameDecl *Typedef; |
643 | if (IsTypeAlias) |
644 | Typedef = TypeAliasDecl::Create(SemaRef.Context, Owner, D->getBeginLoc(), |
645 | D->getLocation(), D->getIdentifier(), DI); |
646 | else |
647 | Typedef = TypedefDecl::Create(SemaRef.Context, Owner, D->getBeginLoc(), |
648 | D->getLocation(), D->getIdentifier(), DI); |
649 | if (Invalid) |
650 | Typedef->setInvalidDecl(); |
651 | |
652 | |
653 | |
654 | if (const TagType *oldTagType = D->getUnderlyingType()->getAs<TagType>()) { |
655 | TagDecl *oldTag = oldTagType->getDecl(); |
656 | if (oldTag->getTypedefNameForAnonDecl() == D && !Invalid) { |
657 | TagDecl *newTag = DI->getType()->castAs<TagType>()->getDecl(); |
658 | hasNameForLinkage()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 658, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!newTag->hasNameForLinkage()); |
659 | newTag->setTypedefNameForAnonDecl(Typedef); |
660 | } |
661 | } |
662 | |
663 | if (TypedefNameDecl *Prev = getPreviousDeclForInstantiation(D)) { |
664 | NamedDecl *InstPrev = SemaRef.FindInstantiatedDecl(D->getLocation(), Prev, |
665 | TemplateArgs); |
666 | if (!InstPrev) |
667 | return nullptr; |
668 | |
669 | TypedefNameDecl *InstPrevTypedef = cast<TypedefNameDecl>(InstPrev); |
670 | |
671 | |
672 | SemaRef.isIncompatibleTypedef(InstPrevTypedef, Typedef); |
673 | |
674 | Typedef->setPreviousDecl(InstPrevTypedef); |
675 | } |
676 | |
677 | SemaRef.InstantiateAttrs(TemplateArgs, D, Typedef); |
678 | |
679 | Typedef->setAccess(D->getAccess()); |
680 | |
681 | return Typedef; |
682 | } |
683 | |
684 | Decl *TemplateDeclInstantiator::VisitTypedefDecl(TypedefDecl *D) { |
685 | Decl *Typedef = InstantiateTypedefNameDecl(D, ); |
686 | if (Typedef) |
687 | Owner->addDecl(Typedef); |
688 | return Typedef; |
689 | } |
690 | |
691 | Decl *TemplateDeclInstantiator::VisitTypeAliasDecl(TypeAliasDecl *D) { |
692 | Decl *Typedef = InstantiateTypedefNameDecl(D, ); |
693 | if (Typedef) |
694 | Owner->addDecl(Typedef); |
695 | return Typedef; |
696 | } |
697 | |
698 | Decl * |
699 | TemplateDeclInstantiator::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
700 | |
701 | |
702 | LocalInstantiationScope Scope(SemaRef); |
703 | |
704 | TemplateParameterList *TempParams = D->getTemplateParameters(); |
705 | TemplateParameterList *InstParams = SubstTemplateParams(TempParams); |
706 | if (!InstParams) |
707 | return nullptr; |
708 | |
709 | TypeAliasDecl *Pattern = D->getTemplatedDecl(); |
710 | |
711 | TypeAliasTemplateDecl *PrevAliasTemplate = nullptr; |
712 | if (getPreviousDeclForInstantiation<TypedefNameDecl>(Pattern)) { |
713 | DeclContext::lookup_result Found = Owner->lookup(Pattern->getDeclName()); |
714 | if (!Found.empty()) { |
715 | PrevAliasTemplate = dyn_cast<TypeAliasTemplateDecl>(Found.front()); |
716 | } |
717 | } |
718 | |
719 | TypeAliasDecl *AliasInst = cast_or_null<TypeAliasDecl>( |
720 | InstantiateTypedefNameDecl(Pattern, )); |
721 | if (!AliasInst) |
722 | return nullptr; |
723 | |
724 | TypeAliasTemplateDecl *Inst |
725 | = TypeAliasTemplateDecl::Create(SemaRef.Context, Owner, D->getLocation(), |
726 | D->getDeclName(), InstParams, AliasInst); |
727 | AliasInst->setDescribedAliasTemplate(Inst); |
728 | if (PrevAliasTemplate) |
729 | Inst->setPreviousDecl(PrevAliasTemplate); |
730 | |
731 | Inst->setAccess(D->getAccess()); |
732 | |
733 | if (!PrevAliasTemplate) |
734 | Inst->setInstantiatedFromMemberTemplate(D); |
735 | |
736 | Owner->addDecl(Inst); |
737 | |
738 | return Inst; |
739 | } |
740 | |
741 | Decl *TemplateDeclInstantiator::VisitBindingDecl(BindingDecl *D) { |
742 | auto *NewBD = BindingDecl::Create(SemaRef.Context, Owner, D->getLocation(), |
743 | D->getIdentifier()); |
744 | NewBD->setReferenced(D->isReferenced()); |
745 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, NewBD); |
746 | return NewBD; |
747 | } |
748 | |
749 | Decl *TemplateDeclInstantiator::VisitDecompositionDecl(DecompositionDecl *D) { |
750 | |
751 | SmallVector<BindingDecl*, 16> NewBindings; |
752 | for (auto *OldBD : D->bindings()) |
753 | NewBindings.push_back(cast<BindingDecl>(VisitBindingDecl(OldBD))); |
754 | ArrayRef<BindingDecl*> NewBindingArray = NewBindings; |
755 | |
756 | auto *NewDD = cast_or_null<DecompositionDecl>( |
757 | VisitVarDecl(D, , &NewBindingArray)); |
758 | |
759 | if (!NewDD || NewDD->isInvalidDecl()) |
760 | for (auto *NewBD : NewBindings) |
761 | NewBD->setInvalidDecl(); |
762 | |
763 | return NewDD; |
764 | } |
765 | |
766 | Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) { |
767 | return VisitVarDecl(D, ); |
768 | } |
769 | |
770 | Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D, |
771 | bool InstantiatingVarTemplate, |
772 | ArrayRef<BindingDecl*> *Bindings) { |
773 | |
774 | |
775 | TypeSourceInfo *DI = SemaRef.SubstType( |
776 | D->getTypeSourceInfo(), TemplateArgs, D->getTypeSpecStartLoc(), |
777 | D->getDeclName(), ); |
778 | if (!DI) |
779 | return nullptr; |
780 | |
781 | if (DI->getType()->isFunctionType()) { |
782 | SemaRef.Diag(D->getLocation(), diag::err_variable_instantiates_to_function) |
783 | << D->isStaticDataMember() << DI->getType(); |
784 | return nullptr; |
785 | } |
786 | |
787 | DeclContext *DC = Owner; |
788 | if (D->isLocalExternDecl()) |
789 | SemaRef.adjustContextForLocalExternDecl(DC); |
790 | |
791 | |
792 | VarDecl *Var; |
793 | if (Bindings) |
794 | Var = DecompositionDecl::Create(SemaRef.Context, DC, D->getInnerLocStart(), |
795 | D->getLocation(), DI->getType(), DI, |
796 | D->getStorageClass(), *Bindings); |
797 | else |
798 | Var = VarDecl::Create(SemaRef.Context, DC, D->getInnerLocStart(), |
799 | D->getLocation(), D->getIdentifier(), DI->getType(), |
800 | DI, D->getStorageClass()); |
801 | |
802 | |
803 | if (SemaRef.getLangOpts().ObjCAutoRefCount && |
804 | SemaRef.inferObjCARCLifetime(Var)) |
805 | Var->setInvalidDecl(); |
806 | |
807 | |
808 | if (SubstQualifier(D, Var)) |
809 | return nullptr; |
810 | |
811 | SemaRef.BuildVariableInstantiation(Var, D, TemplateArgs, LateAttrs, Owner, |
812 | StartingScope, InstantiatingVarTemplate); |
813 | |
814 | if (D->isNRVOVariable()) { |
815 | QualType ReturnType = cast<FunctionDecl>(DC)->getReturnType(); |
816 | if (SemaRef.isCopyElisionCandidate(ReturnType, Var, Sema::CES_Strict)) |
817 | Var->setNRVOVariable(true); |
818 | } |
819 | |
820 | Var->setImplicit(D->isImplicit()); |
821 | |
822 | if (Var->isStaticLocal()) |
823 | SemaRef.CheckStaticLocalForDllExport(Var); |
824 | |
825 | return Var; |
826 | } |
827 | |
828 | Decl *TemplateDeclInstantiator::VisitAccessSpecDecl(AccessSpecDecl *D) { |
829 | AccessSpecDecl* AD |
830 | = AccessSpecDecl::Create(SemaRef.Context, D->getAccess(), Owner, |
831 | D->getAccessSpecifierLoc(), D->getColonLoc()); |
832 | Owner->addHiddenDecl(AD); |
833 | return AD; |
834 | } |
835 | |
836 | Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) { |
837 | bool Invalid = false; |
838 | TypeSourceInfo *DI = D->getTypeSourceInfo(); |
839 | if (DI->getType()->isInstantiationDependentType() || |
840 | DI->getType()->isVariablyModifiedType()) { |
841 | DI = SemaRef.SubstType(DI, TemplateArgs, |
842 | D->getLocation(), D->getDeclName()); |
843 | if (!DI) { |
844 | DI = D->getTypeSourceInfo(); |
845 | Invalid = true; |
846 | } else if (DI->getType()->isFunctionType()) { |
847 | |
848 | |
849 | |
850 | |
851 | |
852 | |
853 | SemaRef.Diag(D->getLocation(), diag::err_field_instantiates_to_function) |
854 | << DI->getType(); |
855 | Invalid = true; |
856 | } |
857 | } else { |
858 | SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), DI->getType()); |
859 | } |
860 | |
861 | Expr *BitWidth = D->getBitWidth(); |
862 | if (Invalid) |
863 | BitWidth = nullptr; |
864 | else if (BitWidth) { |
865 | |
866 | EnterExpressionEvaluationContext Unevaluated( |
867 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
868 | |
869 | ExprResult InstantiatedBitWidth |
870 | = SemaRef.SubstExpr(BitWidth, TemplateArgs); |
871 | if (InstantiatedBitWidth.isInvalid()) { |
872 | Invalid = true; |
873 | BitWidth = nullptr; |
874 | } else |
875 | BitWidth = InstantiatedBitWidth.getAs<Expr>(); |
876 | } |
877 | |
878 | FieldDecl *Field = SemaRef.CheckFieldDecl(D->getDeclName(), |
879 | DI->getType(), DI, |
880 | cast<RecordDecl>(Owner), |
881 | D->getLocation(), |
882 | D->isMutable(), |
883 | BitWidth, |
884 | D->getInClassInitStyle(), |
885 | D->getInnerLocStart(), |
886 | D->getAccess(), |
887 | nullptr); |
888 | if (!Field) { |
889 | cast<Decl>(Owner)->setInvalidDecl(); |
890 | return nullptr; |
891 | } |
892 | |
893 | SemaRef.InstantiateAttrs(TemplateArgs, D, Field, LateAttrs, StartingScope); |
894 | |
895 | if (Field->hasAttrs()) |
896 | SemaRef.CheckAlignasUnderalignment(Field); |
897 | |
898 | if (Invalid) |
899 | Field->setInvalidDecl(); |
900 | |
901 | if (!Field->getDeclName()) { |
902 | |
903 | SemaRef.Context.setInstantiatedFromUnnamedFieldDecl(Field, D); |
904 | } |
905 | if (CXXRecordDecl *Parent= dyn_cast<CXXRecordDecl>(Field->getDeclContext())) { |
906 | if (Parent->isAnonymousStructOrUnion() && |
907 | Parent->getRedeclContext()->isFunctionOrMethod()) |
908 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Field); |
909 | } |
910 | |
911 | Field->setImplicit(D->isImplicit()); |
912 | Field->setAccess(D->getAccess()); |
913 | Owner->addDecl(Field); |
914 | |
915 | return Field; |
916 | } |
917 | |
918 | Decl *TemplateDeclInstantiator::VisitMSPropertyDecl(MSPropertyDecl *D) { |
919 | bool Invalid = false; |
920 | TypeSourceInfo *DI = D->getTypeSourceInfo(); |
921 | |
922 | if (DI->getType()->isVariablyModifiedType()) { |
923 | SemaRef.Diag(D->getLocation(), diag::err_property_is_variably_modified) |
924 | << D; |
925 | Invalid = true; |
926 | } else if (DI->getType()->isInstantiationDependentType()) { |
927 | DI = SemaRef.SubstType(DI, TemplateArgs, |
928 | D->getLocation(), D->getDeclName()); |
929 | if (!DI) { |
930 | DI = D->getTypeSourceInfo(); |
931 | Invalid = true; |
932 | } else if (DI->getType()->isFunctionType()) { |
933 | |
934 | |
935 | |
936 | |
937 | |
938 | |
939 | SemaRef.Diag(D->getLocation(), diag::err_field_instantiates_to_function) |
940 | << DI->getType(); |
941 | Invalid = true; |
942 | } |
943 | } else { |
944 | SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), DI->getType()); |
945 | } |
946 | |
947 | MSPropertyDecl *Property = MSPropertyDecl::Create( |
948 | SemaRef.Context, Owner, D->getLocation(), D->getDeclName(), DI->getType(), |
949 | DI, D->getBeginLoc(), D->getGetterId(), D->getSetterId()); |
950 | |
951 | SemaRef.InstantiateAttrs(TemplateArgs, D, Property, LateAttrs, |
952 | StartingScope); |
953 | |
954 | if (Invalid) |
955 | Property->setInvalidDecl(); |
956 | |
957 | Property->setAccess(D->getAccess()); |
958 | Owner->addDecl(Property); |
959 | |
960 | return Property; |
961 | } |
962 | |
963 | Decl *TemplateDeclInstantiator::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
964 | NamedDecl **NamedChain = |
965 | new (SemaRef.Context)NamedDecl*[D->getChainingSize()]; |
966 | |
967 | int i = 0; |
968 | for (auto *PI : D->chain()) { |
969 | NamedDecl *Next = SemaRef.FindInstantiatedDecl(D->getLocation(), PI, |
970 | TemplateArgs); |
971 | if (!Next) |
972 | return nullptr; |
973 | |
974 | NamedChain[i++] = Next; |
975 | } |
976 | |
977 | QualType T = cast<FieldDecl>(NamedChain[i-1])->getType(); |
978 | IndirectFieldDecl *IndirectField = IndirectFieldDecl::Create( |
979 | SemaRef.Context, Owner, D->getLocation(), D->getIdentifier(), T, |
980 | {NamedChain, D->getChainingSize()}); |
981 | |
982 | for (const auto *Attr : D->attrs()) |
983 | IndirectField->addAttr(Attr->clone(SemaRef.Context)); |
984 | |
985 | IndirectField->setImplicit(D->isImplicit()); |
986 | IndirectField->setAccess(D->getAccess()); |
987 | Owner->addDecl(IndirectField); |
988 | return IndirectField; |
989 | } |
990 | |
991 | Decl *TemplateDeclInstantiator::VisitFriendDecl(FriendDecl *D) { |
992 | |
993 | |
994 | if (TypeSourceInfo *Ty = D->getFriendType()) { |
995 | TypeSourceInfo *InstTy; |
996 | |
997 | |
998 | |
999 | |
1000 | if (D->isUnsupportedFriend()) { |
1001 | InstTy = Ty; |
1002 | } else { |
1003 | InstTy = SemaRef.SubstType(Ty, TemplateArgs, |
1004 | D->getLocation(), DeclarationName()); |
1005 | } |
1006 | if (!InstTy) |
1007 | return nullptr; |
1008 | |
1009 | FriendDecl *FD = SemaRef.CheckFriendTypeDecl(D->getBeginLoc(), |
1010 | D->getFriendLoc(), InstTy); |
1011 | if (!FD) |
1012 | return nullptr; |
1013 | |
1014 | FD->setAccess(AS_public); |
1015 | FD->setUnsupportedFriend(D->isUnsupportedFriend()); |
1016 | Owner->addDecl(FD); |
1017 | return FD; |
1018 | } |
1019 | |
1020 | NamedDecl *ND = D->getFriendDecl(); |
1021 | (0) . __assert_fail ("ND && \"friend decl must be a decl or a type!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 1021, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(ND && "friend decl must be a decl or a type!"); |
1022 | |
1023 | |
1024 | |
1025 | |
1026 | |
1027 | Decl *NewND = Visit(ND); |
1028 | if (!NewND) return nullptr; |
1029 | |
1030 | FriendDecl *FD = |
1031 | FriendDecl::Create(SemaRef.Context, Owner, D->getLocation(), |
1032 | cast<NamedDecl>(NewND), D->getFriendLoc()); |
1033 | FD->setAccess(AS_public); |
1034 | FD->setUnsupportedFriend(D->isUnsupportedFriend()); |
1035 | Owner->addDecl(FD); |
1036 | return FD; |
1037 | } |
1038 | |
1039 | Decl *TemplateDeclInstantiator::VisitStaticAssertDecl(StaticAssertDecl *D) { |
1040 | Expr *AssertExpr = D->getAssertExpr(); |
1041 | |
1042 | |
1043 | EnterExpressionEvaluationContext Unevaluated( |
1044 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
1045 | |
1046 | ExprResult InstantiatedAssertExpr |
1047 | = SemaRef.SubstExpr(AssertExpr, TemplateArgs); |
1048 | if (InstantiatedAssertExpr.isInvalid()) |
1049 | return nullptr; |
1050 | |
1051 | return SemaRef.BuildStaticAssertDeclaration(D->getLocation(), |
1052 | InstantiatedAssertExpr.get(), |
1053 | D->getMessage(), |
1054 | D->getRParenLoc(), |
1055 | D->isFailed()); |
1056 | } |
1057 | |
1058 | Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) { |
1059 | EnumDecl *PrevDecl = nullptr; |
1060 | if (EnumDecl *PatternPrev = getPreviousDeclForInstantiation(D)) { |
1061 | NamedDecl *Prev = SemaRef.FindInstantiatedDecl(D->getLocation(), |
1062 | PatternPrev, |
1063 | TemplateArgs); |
1064 | if (!Prev) return nullptr; |
1065 | PrevDecl = cast<EnumDecl>(Prev); |
1066 | } |
1067 | |
1068 | EnumDecl *Enum = |
1069 | EnumDecl::Create(SemaRef.Context, Owner, D->getBeginLoc(), |
1070 | D->getLocation(), D->getIdentifier(), PrevDecl, |
1071 | D->isScoped(), D->isScopedUsingClassTag(), D->isFixed()); |
1072 | if (D->isFixed()) { |
1073 | if (TypeSourceInfo *TI = D->getIntegerTypeSourceInfo()) { |
1074 | |
1075 | |
1076 | |
1077 | SourceLocation UnderlyingLoc = TI->getTypeLoc().getBeginLoc(); |
1078 | TypeSourceInfo *NewTI = SemaRef.SubstType(TI, TemplateArgs, UnderlyingLoc, |
1079 | DeclarationName()); |
1080 | if (!NewTI || SemaRef.CheckEnumUnderlyingType(NewTI)) |
1081 | Enum->setIntegerType(SemaRef.Context.IntTy); |
1082 | else |
1083 | Enum->setIntegerTypeSourceInfo(NewTI); |
1084 | } else { |
1085 | (0) . __assert_fail ("!D->getIntegerType()->isDependentType() && \"Dependent type without type source info\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 1086, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!D->getIntegerType()->isDependentType() |
1086 | (0) . __assert_fail ("!D->getIntegerType()->isDependentType() && \"Dependent type without type source info\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 1086, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> && "Dependent type without type source info"); |
1087 | Enum->setIntegerType(D->getIntegerType()); |
1088 | } |
1089 | } |
1090 | |
1091 | SemaRef.InstantiateAttrs(TemplateArgs, D, Enum); |
1092 | |
1093 | Enum->setInstantiationOfMemberEnum(D, TSK_ImplicitInstantiation); |
1094 | Enum->setAccess(D->getAccess()); |
1095 | |
1096 | SemaRef.Context.setManglingNumber(Enum, SemaRef.Context.getManglingNumber(D)); |
1097 | |
1098 | |
1099 | if (DeclaratorDecl *DD = SemaRef.Context.getDeclaratorForUnnamedTagDecl(D)) |
1100 | SemaRef.Context.addDeclaratorForUnnamedTagDecl(Enum, DD); |
1101 | |
1102 | |
1103 | if (TypedefNameDecl *TND = SemaRef.Context.getTypedefNameForUnnamedTagDecl(D)) |
1104 | SemaRef.Context.addTypedefNameForUnnamedTagDecl(Enum, TND); |
1105 | if (SubstQualifier(D, Enum)) return nullptr; |
1106 | Owner->addDecl(Enum); |
1107 | |
1108 | EnumDecl *Def = D->getDefinition(); |
1109 | if (Def && Def != D) { |
1110 | |
1111 | |
1112 | |
1113 | if (TypeSourceInfo *TI = Def->getIntegerTypeSourceInfo()) { |
1114 | SourceLocation UnderlyingLoc = TI->getTypeLoc().getBeginLoc(); |
1115 | QualType DefnUnderlying = |
1116 | SemaRef.SubstType(TI->getType(), TemplateArgs, |
1117 | UnderlyingLoc, DeclarationName()); |
1118 | SemaRef.CheckEnumRedeclaration(Def->getLocation(), Def->isScoped(), |
1119 | DefnUnderlying, , Enum); |
1120 | } |
1121 | } |
1122 | |
1123 | |
1124 | |
1125 | |
1126 | |
1127 | |
1128 | |
1129 | |
1130 | if (isDeclWithinFunction(D) ? D == Def : Def && !Enum->isScoped()) { |
1131 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Enum); |
1132 | InstantiateEnumDefinition(Enum, Def); |
1133 | } |
1134 | |
1135 | return Enum; |
1136 | } |
1137 | |
1138 | void TemplateDeclInstantiator::InstantiateEnumDefinition( |
1139 | EnumDecl *Enum, EnumDecl *Pattern) { |
1140 | Enum->startDefinition(); |
1141 | |
1142 | |
1143 | Enum->setLocation(Pattern->getLocation()); |
1144 | |
1145 | SmallVector<Decl*, 4> Enumerators; |
1146 | |
1147 | EnumConstantDecl *LastEnumConst = nullptr; |
1148 | for (auto *EC : Pattern->enumerators()) { |
1149 | |
1150 | ExprResult Value((Expr *)nullptr); |
1151 | if (Expr *UninstValue = EC->getInitExpr()) { |
1152 | |
1153 | EnterExpressionEvaluationContext Unevaluated( |
1154 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
1155 | |
1156 | Value = SemaRef.SubstExpr(UninstValue, TemplateArgs); |
1157 | } |
1158 | |
1159 | |
1160 | bool isInvalid = false; |
1161 | if (Value.isInvalid()) { |
1162 | Value = nullptr; |
1163 | isInvalid = true; |
1164 | } |
1165 | |
1166 | EnumConstantDecl *EnumConst |
1167 | = SemaRef.CheckEnumConstant(Enum, LastEnumConst, |
1168 | EC->getLocation(), EC->getIdentifier(), |
1169 | Value.get()); |
1170 | |
1171 | if (isInvalid) { |
1172 | if (EnumConst) |
1173 | EnumConst->setInvalidDecl(); |
1174 | Enum->setInvalidDecl(); |
1175 | } |
1176 | |
1177 | if (EnumConst) { |
1178 | SemaRef.InstantiateAttrs(TemplateArgs, EC, EnumConst); |
1179 | |
1180 | EnumConst->setAccess(Enum->getAccess()); |
1181 | Enum->addDecl(EnumConst); |
1182 | Enumerators.push_back(EnumConst); |
1183 | LastEnumConst = EnumConst; |
1184 | |
1185 | if (Pattern->getDeclContext()->isFunctionOrMethod() && |
1186 | !Enum->isScoped()) { |
1187 | |
1188 | |
1189 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(EC, EnumConst); |
1190 | } |
1191 | } |
1192 | } |
1193 | |
1194 | SemaRef.ActOnEnumBody(Enum->getLocation(), Enum->getBraceRange(), Enum, |
1195 | Enumerators, nullptr, ParsedAttributesView()); |
1196 | } |
1197 | |
1198 | Decl *TemplateDeclInstantiator::VisitEnumConstantDecl(EnumConstantDecl *D) { |
1199 | llvm_unreachable("EnumConstantDecls can only occur within EnumDecls."); |
1200 | } |
1201 | |
1202 | Decl * |
1203 | TemplateDeclInstantiator::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) { |
1204 | llvm_unreachable("BuiltinTemplateDecls cannot be instantiated."); |
1205 | } |
1206 | |
1207 | Decl *TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
1208 | bool isFriend = (D->getFriendObjectKind() != Decl::FOK_None); |
1209 | |
1210 | |
1211 | |
1212 | LocalInstantiationScope Scope(SemaRef); |
1213 | TemplateParameterList *TempParams = D->getTemplateParameters(); |
1214 | TemplateParameterList *InstParams = SubstTemplateParams(TempParams); |
1215 | if (!InstParams) |
1216 | return nullptr; |
1217 | |
1218 | CXXRecordDecl *Pattern = D->getTemplatedDecl(); |
1219 | |
1220 | |
1221 | |
1222 | |
1223 | NestedNameSpecifierLoc QualifierLoc = Pattern->getQualifierLoc(); |
1224 | if (QualifierLoc) { |
1225 | QualifierLoc = SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc, |
1226 | TemplateArgs); |
1227 | if (!QualifierLoc) |
1228 | return nullptr; |
1229 | } |
1230 | |
1231 | CXXRecordDecl *PrevDecl = nullptr; |
1232 | ClassTemplateDecl *PrevClassTemplate = nullptr; |
1233 | |
1234 | if (!isFriend && getPreviousDeclForInstantiation(Pattern)) { |
1235 | DeclContext::lookup_result Found = Owner->lookup(Pattern->getDeclName()); |
1236 | if (!Found.empty()) { |
1237 | PrevClassTemplate = dyn_cast<ClassTemplateDecl>(Found.front()); |
1238 | if (PrevClassTemplate) |
1239 | PrevDecl = PrevClassTemplate->getTemplatedDecl(); |
1240 | } |
1241 | } |
1242 | |
1243 | |
1244 | |
1245 | |
1246 | |
1247 | DeclContext *DC = Owner; |
1248 | if (isFriend) { |
1249 | if (QualifierLoc) { |
1250 | CXXScopeSpec SS; |
1251 | SS.Adopt(QualifierLoc); |
1252 | DC = SemaRef.computeDeclContext(SS); |
1253 | if (!DC) return nullptr; |
1254 | } else { |
1255 | DC = SemaRef.FindInstantiatedContext(Pattern->getLocation(), |
1256 | Pattern->getDeclContext(), |
1257 | TemplateArgs); |
1258 | } |
1259 | |
1260 | |
1261 | |
1262 | LookupResult R(SemaRef, Pattern->getDeclName(), Pattern->getLocation(), |
1263 | Sema::LookupOrdinaryName, |
1264 | SemaRef.forRedeclarationInCurContext()); |
1265 | SemaRef.LookupQualifiedName(R, DC); |
1266 | |
1267 | if (R.isSingleResult()) { |
1268 | PrevClassTemplate = R.getAsSingle<ClassTemplateDecl>(); |
1269 | if (PrevClassTemplate) |
1270 | PrevDecl = PrevClassTemplate->getTemplatedDecl(); |
1271 | } |
1272 | |
1273 | if (!PrevClassTemplate && QualifierLoc) { |
1274 | SemaRef.Diag(Pattern->getLocation(), diag::err_not_tag_in_scope) |
1275 | << D->getTemplatedDecl()->getTagKind() << Pattern->getDeclName() << DC |
1276 | << QualifierLoc.getSourceRange(); |
1277 | return nullptr; |
1278 | } |
1279 | |
1280 | bool AdoptedPreviousTemplateParams = false; |
1281 | if (PrevClassTemplate) { |
1282 | bool Complain = true; |
1283 | |
1284 | |
1285 | |
1286 | |
1287 | |
1288 | |
1289 | |
1290 | if (isFriend && Pattern->getIdentifier() && |
1291 | Pattern->getIdentifier()->isStr("_Map_base") && |
1292 | DC->isNamespace() && |
1293 | cast<NamespaceDecl>(DC)->getIdentifier() && |
1294 | cast<NamespaceDecl>(DC)->getIdentifier()->isStr("__detail")) { |
1295 | DeclContext *DCParent = DC->getParent(); |
1296 | if (DCParent->isNamespace() && |
1297 | cast<NamespaceDecl>(DCParent)->getIdentifier() && |
1298 | cast<NamespaceDecl>(DCParent)->getIdentifier()->isStr("tr1")) { |
1299 | if (cast<Decl>(DCParent)->isInStdNamespace()) |
1300 | Complain = false; |
1301 | } |
1302 | } |
1303 | |
1304 | TemplateParameterList *PrevParams |
1305 | = PrevClassTemplate->getMostRecentDecl()->getTemplateParameters(); |
1306 | |
1307 | |
1308 | if (!SemaRef.TemplateParameterListsAreEqual(InstParams, PrevParams, |
1309 | Complain, |
1310 | Sema::TPL_TemplateMatch)) { |
1311 | if (Complain) |
1312 | return nullptr; |
1313 | |
1314 | AdoptedPreviousTemplateParams = true; |
1315 | InstParams = PrevParams; |
1316 | } |
1317 | |
1318 | |
1319 | |
1320 | if (!AdoptedPreviousTemplateParams && |
1321 | SemaRef.CheckTemplateParameterList(InstParams, PrevParams, |
1322 | Sema::TPC_ClassTemplate)) |
1323 | return nullptr; |
1324 | } |
1325 | } |
1326 | |
1327 | CXXRecordDecl *RecordInst = CXXRecordDecl::Create( |
1328 | SemaRef.Context, Pattern->getTagKind(), DC, Pattern->getBeginLoc(), |
1329 | Pattern->getLocation(), Pattern->getIdentifier(), PrevDecl, |
1330 | ); |
1331 | |
1332 | if (QualifierLoc) |
1333 | RecordInst->setQualifierInfo(QualifierLoc); |
1334 | |
1335 | SemaRef.InstantiateAttrsForDecl(TemplateArgs, Pattern, RecordInst, LateAttrs, |
1336 | StartingScope); |
1337 | |
1338 | ClassTemplateDecl *Inst |
1339 | = ClassTemplateDecl::Create(SemaRef.Context, DC, D->getLocation(), |
1340 | D->getIdentifier(), InstParams, RecordInst); |
1341 | isDependentContext())", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 1341, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!(isFriend && Owner->isDependentContext())); |
1342 | Inst->setPreviousDecl(PrevClassTemplate); |
1343 | |
1344 | RecordInst->setDescribedClassTemplate(Inst); |
1345 | |
1346 | if (isFriend) { |
1347 | if (PrevClassTemplate) |
1348 | Inst->setAccess(PrevClassTemplate->getAccess()); |
1349 | else |
1350 | Inst->setAccess(D->getAccess()); |
1351 | |
1352 | Inst->setObjectOfFriendDecl(); |
1353 | |
1354 | |
1355 | } else { |
1356 | Inst->setAccess(D->getAccess()); |
1357 | if (!PrevClassTemplate) |
1358 | Inst->setInstantiatedFromMemberTemplate(D); |
1359 | } |
1360 | |
1361 | |
1362 | SemaRef.Context.getInjectedClassNameType(RecordInst, |
1363 | Inst->getInjectedClassNameSpecialization()); |
1364 | |
1365 | |
1366 | if (isFriend) { |
1367 | DC->makeDeclVisibleInContext(Inst); |
1368 | Inst->setLexicalDeclContext(Owner); |
1369 | RecordInst->setLexicalDeclContext(Owner); |
1370 | return Inst; |
1371 | } |
1372 | |
1373 | if (D->isOutOfLine()) { |
1374 | Inst->setLexicalDeclContext(D->getLexicalDeclContext()); |
1375 | RecordInst->setLexicalDeclContext(D->getLexicalDeclContext()); |
1376 | } |
1377 | |
1378 | Owner->addDecl(Inst); |
1379 | |
1380 | if (!PrevClassTemplate) { |
1381 | |
1382 | |
1383 | |
1384 | SmallVector<ClassTemplatePartialSpecializationDecl *, 4> PartialSpecs; |
1385 | D->getPartialSpecializations(PartialSpecs); |
1386 | for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) |
1387 | if (PartialSpecs[I]->getFirstDecl()->isOutOfLine()) |
1388 | OutOfLinePartialSpecs.push_back(std::make_pair(Inst, PartialSpecs[I])); |
1389 | } |
1390 | |
1391 | return Inst; |
1392 | } |
1393 | |
1394 | Decl * |
1395 | TemplateDeclInstantiator::VisitClassTemplatePartialSpecializationDecl( |
1396 | ClassTemplatePartialSpecializationDecl *D) { |
1397 | ClassTemplateDecl *ClassTemplate = D->getSpecializedTemplate(); |
1398 | |
1399 | |
1400 | |
1401 | DeclContext::lookup_result Found |
1402 | = Owner->lookup(ClassTemplate->getDeclName()); |
1403 | if (Found.empty()) |
1404 | return nullptr; |
1405 | |
1406 | ClassTemplateDecl *InstClassTemplate |
1407 | = dyn_cast<ClassTemplateDecl>(Found.front()); |
1408 | if (!InstClassTemplate) |
1409 | return nullptr; |
1410 | |
1411 | if (ClassTemplatePartialSpecializationDecl *Result |
1412 | = InstClassTemplate->findPartialSpecInstantiatedFromMember(D)) |
1413 | return Result; |
1414 | |
1415 | return InstantiateClassTemplatePartialSpecialization(InstClassTemplate, D); |
1416 | } |
1417 | |
1418 | Decl *TemplateDeclInstantiator::VisitVarTemplateDecl(VarTemplateDecl *D) { |
1419 | (0) . __assert_fail ("D->getTemplatedDecl()->isStaticDataMember() && \"Only static data member templates are allowed.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 1420, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(D->getTemplatedDecl()->isStaticDataMember() && |
1420 | (0) . __assert_fail ("D->getTemplatedDecl()->isStaticDataMember() && \"Only static data member templates are allowed.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 1420, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Only static data member templates are allowed."); |
1421 | |
1422 | |
1423 | |
1424 | LocalInstantiationScope Scope(SemaRef); |
1425 | TemplateParameterList *TempParams = D->getTemplateParameters(); |
1426 | TemplateParameterList *InstParams = SubstTemplateParams(TempParams); |
1427 | if (!InstParams) |
1428 | return nullptr; |
1429 | |
1430 | VarDecl *Pattern = D->getTemplatedDecl(); |
1431 | VarTemplateDecl *PrevVarTemplate = nullptr; |
1432 | |
1433 | if (getPreviousDeclForInstantiation(Pattern)) { |
1434 | DeclContext::lookup_result Found = Owner->lookup(Pattern->getDeclName()); |
1435 | if (!Found.empty()) |
1436 | PrevVarTemplate = dyn_cast<VarTemplateDecl>(Found.front()); |
1437 | } |
1438 | |
1439 | VarDecl *VarInst = |
1440 | cast_or_null<VarDecl>(VisitVarDecl(Pattern, |
1441 | )); |
1442 | if (!VarInst) return nullptr; |
1443 | |
1444 | DeclContext *DC = Owner; |
1445 | |
1446 | VarTemplateDecl *Inst = VarTemplateDecl::Create( |
1447 | SemaRef.Context, DC, D->getLocation(), D->getIdentifier(), InstParams, |
1448 | VarInst); |
1449 | VarInst->setDescribedVarTemplate(Inst); |
1450 | Inst->setPreviousDecl(PrevVarTemplate); |
1451 | |
1452 | Inst->setAccess(D->getAccess()); |
1453 | if (!PrevVarTemplate) |
1454 | Inst->setInstantiatedFromMemberTemplate(D); |
1455 | |
1456 | if (D->isOutOfLine()) { |
1457 | Inst->setLexicalDeclContext(D->getLexicalDeclContext()); |
1458 | VarInst->setLexicalDeclContext(D->getLexicalDeclContext()); |
1459 | } |
1460 | |
1461 | Owner->addDecl(Inst); |
1462 | |
1463 | if (!PrevVarTemplate) { |
1464 | |
1465 | |
1466 | |
1467 | SmallVector<VarTemplatePartialSpecializationDecl *, 4> PartialSpecs; |
1468 | D->getPartialSpecializations(PartialSpecs); |
1469 | for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) |
1470 | if (PartialSpecs[I]->getFirstDecl()->isOutOfLine()) |
1471 | OutOfLineVarPartialSpecs.push_back( |
1472 | std::make_pair(Inst, PartialSpecs[I])); |
1473 | } |
1474 | |
1475 | return Inst; |
1476 | } |
1477 | |
1478 | Decl *TemplateDeclInstantiator::VisitVarTemplatePartialSpecializationDecl( |
1479 | VarTemplatePartialSpecializationDecl *D) { |
1480 | (0) . __assert_fail ("D->isStaticDataMember() && \"Only static data member templates are allowed.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 1481, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(D->isStaticDataMember() && |
1481 | (0) . __assert_fail ("D->isStaticDataMember() && \"Only static data member templates are allowed.\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 1481, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Only static data member templates are allowed."); |
1482 | |
1483 | VarTemplateDecl *VarTemplate = D->getSpecializedTemplate(); |
1484 | |
1485 | |
1486 | DeclContext::lookup_result Found = Owner->lookup(VarTemplate->getDeclName()); |
1487 | (0) . __assert_fail ("!Found.empty() && \"Instantiation found nothing?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 1487, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!Found.empty() && "Instantiation found nothing?"); |
1488 | |
1489 | VarTemplateDecl *InstVarTemplate = dyn_cast<VarTemplateDecl>(Found.front()); |
1490 | (0) . __assert_fail ("InstVarTemplate && \"Instantiation did not find a variable template?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 1490, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(InstVarTemplate && "Instantiation did not find a variable template?"); |
1491 | |
1492 | if (VarTemplatePartialSpecializationDecl *Result = |
1493 | InstVarTemplate->findPartialSpecInstantiatedFromMember(D)) |
1494 | return Result; |
1495 | |
1496 | return InstantiateVarTemplatePartialSpecialization(InstVarTemplate, D); |
1497 | } |
1498 | |
1499 | Decl * |
1500 | TemplateDeclInstantiator::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
1501 | |
1502 | |
1503 | |
1504 | |
1505 | LocalInstantiationScope Scope(SemaRef); |
1506 | |
1507 | TemplateParameterList *TempParams = D->getTemplateParameters(); |
1508 | TemplateParameterList *InstParams = SubstTemplateParams(TempParams); |
1509 | if (!InstParams) |
1510 | return nullptr; |
1511 | |
1512 | FunctionDecl *Instantiated = nullptr; |
1513 | if (CXXMethodDecl *DMethod = dyn_cast<CXXMethodDecl>(D->getTemplatedDecl())) |
1514 | Instantiated = cast_or_null<FunctionDecl>(VisitCXXMethodDecl(DMethod, |
1515 | InstParams)); |
1516 | else |
1517 | Instantiated = cast_or_null<FunctionDecl>(VisitFunctionDecl( |
1518 | D->getTemplatedDecl(), |
1519 | InstParams)); |
1520 | |
1521 | if (!Instantiated) |
1522 | return nullptr; |
1523 | |
1524 | |
1525 | |
1526 | FunctionTemplateDecl *InstTemplate |
1527 | = Instantiated->getDescribedFunctionTemplate(); |
1528 | InstTemplate->setAccess(D->getAccess()); |
1529 | (0) . __assert_fail ("InstTemplate && \"VisitFunctionDecl/CXXMethodDecl didn't create a template!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 1530, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(InstTemplate && |
1530 | (0) . __assert_fail ("InstTemplate && \"VisitFunctionDecl/CXXMethodDecl didn't create a template!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 1530, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "VisitFunctionDecl/CXXMethodDecl didn't create a template!"); |
1531 | |
1532 | bool isFriend = (InstTemplate->getFriendObjectKind() != Decl::FOK_None); |
1533 | |
1534 | |
1535 | |
1536 | if (!InstTemplate->getInstantiatedFromMemberTemplate() && |
1537 | !(isFriend && !D->getTemplatedDecl()->isThisDeclarationADefinition())) |
1538 | InstTemplate->setInstantiatedFromMemberTemplate(D); |
1539 | |
1540 | |
1541 | if (!isFriend) { |
1542 | Owner->addDecl(InstTemplate); |
1543 | } else if (InstTemplate->getDeclContext()->isRecord() && |
1544 | !getPreviousDeclForInstantiation(D)) { |
1545 | SemaRef.CheckFriendAccess(InstTemplate); |
1546 | } |
1547 | |
1548 | return InstTemplate; |
1549 | } |
1550 | |
1551 | Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) { |
1552 | CXXRecordDecl *PrevDecl = nullptr; |
1553 | if (D->isInjectedClassName()) |
1554 | PrevDecl = cast<CXXRecordDecl>(Owner); |
1555 | else if (CXXRecordDecl *PatternPrev = getPreviousDeclForInstantiation(D)) { |
1556 | NamedDecl *Prev = SemaRef.FindInstantiatedDecl(D->getLocation(), |
1557 | PatternPrev, |
1558 | TemplateArgs); |
1559 | if (!Prev) return nullptr; |
1560 | PrevDecl = cast<CXXRecordDecl>(Prev); |
1561 | } |
1562 | |
1563 | CXXRecordDecl *Record = CXXRecordDecl::Create( |
1564 | SemaRef.Context, D->getTagKind(), Owner, D->getBeginLoc(), |
1565 | D->getLocation(), D->getIdentifier(), PrevDecl); |
1566 | |
1567 | |
1568 | if (SubstQualifier(D, Record)) |
1569 | return nullptr; |
1570 | |
1571 | SemaRef.InstantiateAttrsForDecl(TemplateArgs, D, Record, LateAttrs, |
1572 | StartingScope); |
1573 | |
1574 | Record->setImplicit(D->isImplicit()); |
1575 | |
1576 | |
1577 | |
1578 | if (D->getAccess() != AS_none) |
1579 | Record->setAccess(D->getAccess()); |
1580 | if (!D->isInjectedClassName()) |
1581 | Record->setInstantiationOfMemberClass(D, TSK_ImplicitInstantiation); |
1582 | |
1583 | |
1584 | |
1585 | if (D->getFriendObjectKind()) |
1586 | Record->setObjectOfFriendDecl(); |
1587 | |
1588 | |
1589 | if (D->isAnonymousStructOrUnion()) |
1590 | Record->setAnonymousStructOrUnion(true); |
1591 | |
1592 | if (D->isLocalClass()) |
1593 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Record); |
1594 | |
1595 | |
1596 | SemaRef.Context.setManglingNumber(Record, |
1597 | SemaRef.Context.getManglingNumber(D)); |
1598 | |
1599 | |
1600 | |
1601 | if (DeclaratorDecl *DD = SemaRef.Context.getDeclaratorForUnnamedTagDecl(D)) |
1602 | SemaRef.Context.addDeclaratorForUnnamedTagDecl(Record, DD); |
1603 | |
1604 | |
1605 | |
1606 | if (TypedefNameDecl *TND = SemaRef.Context.getTypedefNameForUnnamedTagDecl(D)) |
1607 | SemaRef.Context.addTypedefNameForUnnamedTagDecl(Record, TND); |
1608 | |
1609 | Owner->addDecl(Record); |
1610 | |
1611 | |
1612 | |
1613 | if (D->isCompleteDefinition() && D->isLocalClass()) { |
1614 | Sema::LocalEagerInstantiationScope LocalInstantiations(SemaRef); |
1615 | |
1616 | SemaRef.InstantiateClass(D->getLocation(), Record, D, TemplateArgs, |
1617 | TSK_ImplicitInstantiation, |
1618 | ); |
1619 | |
1620 | |
1621 | |
1622 | if (!D->isCXXClassMember()) |
1623 | SemaRef.InstantiateClassMembers(D->getLocation(), Record, TemplateArgs, |
1624 | TSK_ImplicitInstantiation); |
1625 | |
1626 | |
1627 | |
1628 | LocalInstantiations.perform(); |
1629 | } |
1630 | |
1631 | SemaRef.DiagnoseUnusedNestedTypedefs(Record); |
1632 | |
1633 | return Record; |
1634 | } |
1635 | |
1636 | |
1637 | |
1638 | |
1639 | |
1640 | |
1641 | |
1642 | static QualType adjustFunctionTypeForInstantiation(ASTContext &Context, |
1643 | FunctionDecl *D, |
1644 | TypeSourceInfo *TInfo) { |
1645 | const FunctionProtoType *OrigFunc |
1646 | = D->getType()->castAs<FunctionProtoType>(); |
1647 | const FunctionProtoType *NewFunc |
1648 | = TInfo->getType()->castAs<FunctionProtoType>(); |
1649 | if (OrigFunc->getExtInfo() == NewFunc->getExtInfo()) |
1650 | return TInfo->getType(); |
1651 | |
1652 | FunctionProtoType::ExtProtoInfo NewEPI = NewFunc->getExtProtoInfo(); |
1653 | NewEPI.ExtInfo = OrigFunc->getExtInfo(); |
1654 | return Context.getFunctionType(NewFunc->getReturnType(), |
1655 | NewFunc->getParamTypes(), NewEPI); |
1656 | } |
1657 | |
1658 | |
1659 | |
1660 | |
1661 | |
1662 | |
1663 | Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D, |
1664 | TemplateParameterList *TemplateParams) { |
1665 | |
1666 | |
1667 | FunctionTemplateDecl *FunctionTemplate = D->getDescribedFunctionTemplate(); |
1668 | if (FunctionTemplate && !TemplateParams) { |
1669 | ArrayRef<TemplateArgument> Innermost = TemplateArgs.getInnermost(); |
1670 | |
1671 | void *InsertPos = nullptr; |
1672 | FunctionDecl *SpecFunc |
1673 | = FunctionTemplate->findSpecialization(Innermost, InsertPos); |
1674 | |
1675 | |
1676 | if (SpecFunc) |
1677 | return SpecFunc; |
1678 | } |
1679 | |
1680 | bool isFriend; |
1681 | if (FunctionTemplate) |
1682 | isFriend = (FunctionTemplate->getFriendObjectKind() != Decl::FOK_None); |
1683 | else |
1684 | isFriend = (D->getFriendObjectKind() != Decl::FOK_None); |
1685 | |
1686 | bool MergeWithParentScope = (TemplateParams != nullptr) || |
1687 | Owner->isFunctionOrMethod() || |
1688 | !(isa<Decl>(Owner) && |
1689 | cast<Decl>(Owner)->isDefinedOutsideFunctionOrMethod()); |
1690 | LocalInstantiationScope Scope(SemaRef, MergeWithParentScope); |
1691 | |
1692 | SmallVector<ParmVarDecl *, 4> Params; |
1693 | TypeSourceInfo *TInfo = SubstFunctionType(D, Params); |
1694 | if (!TInfo) |
1695 | return nullptr; |
1696 | QualType T = adjustFunctionTypeForInstantiation(SemaRef.Context, D, TInfo); |
1697 | |
1698 | NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc(); |
1699 | if (QualifierLoc) { |
1700 | QualifierLoc = SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc, |
1701 | TemplateArgs); |
1702 | if (!QualifierLoc) |
1703 | return nullptr; |
1704 | } |
1705 | |
1706 | |
1707 | |
1708 | |
1709 | DeclContext *DC; |
1710 | if (D->isLocalExternDecl()) { |
1711 | DC = Owner; |
1712 | SemaRef.adjustContextForLocalExternDecl(DC); |
1713 | } else if (isFriend && QualifierLoc) { |
1714 | CXXScopeSpec SS; |
1715 | SS.Adopt(QualifierLoc); |
1716 | DC = SemaRef.computeDeclContext(SS); |
1717 | if (!DC) return nullptr; |
1718 | } else { |
1719 | DC = SemaRef.FindInstantiatedContext(D->getLocation(), D->getDeclContext(), |
1720 | TemplateArgs); |
1721 | } |
1722 | |
1723 | DeclarationNameInfo NameInfo |
1724 | = SemaRef.SubstDeclarationNameInfo(D->getNameInfo(), TemplateArgs); |
1725 | |
1726 | FunctionDecl *Function; |
1727 | if (auto *DGuide = dyn_cast<CXXDeductionGuideDecl>(D)) { |
1728 | Function = CXXDeductionGuideDecl::Create( |
1729 | SemaRef.Context, DC, D->getInnerLocStart(), DGuide->isExplicit(), |
1730 | NameInfo, T, TInfo, D->getSourceRange().getEnd()); |
1731 | if (DGuide->isCopyDeductionCandidate()) |
1732 | cast<CXXDeductionGuideDecl>(Function)->setIsCopyDeductionCandidate(); |
1733 | Function->setAccess(D->getAccess()); |
1734 | } else { |
1735 | Function = FunctionDecl::Create( |
1736 | SemaRef.Context, DC, D->getInnerLocStart(), NameInfo, T, TInfo, |
1737 | D->getCanonicalDecl()->getStorageClass(), D->isInlineSpecified(), |
1738 | D->hasWrittenPrototype(), D->isConstexpr()); |
1739 | Function->setRangeEnd(D->getSourceRange().getEnd()); |
1740 | } |
1741 | |
1742 | if (D->isInlined()) |
1743 | Function->setImplicitlyInline(); |
1744 | |
1745 | if (QualifierLoc) |
1746 | Function->setQualifierInfo(QualifierLoc); |
1747 | |
1748 | if (D->isLocalExternDecl()) |
1749 | Function->setLocalExternDecl(); |
1750 | |
1751 | DeclContext *LexicalDC = Owner; |
1752 | if (!isFriend && D->isOutOfLine() && !D->isLocalExternDecl()) { |
1753 | getDeclContext()->isFileContext()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 1753, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(D->getDeclContext()->isFileContext()); |
1754 | LexicalDC = D->getDeclContext(); |
1755 | } |
1756 | |
1757 | Function->setLexicalDeclContext(LexicalDC); |
1758 | |
1759 | |
1760 | for (unsigned P = 0; P < Params.size(); ++P) |
1761 | if (Params[P]) |
1762 | Params[P]->setOwningFunction(Function); |
1763 | Function->setParams(Params); |
1764 | |
1765 | if (TemplateParams) { |
1766 | |
1767 | |
1768 | |
1769 | |
1770 | |
1771 | |
1772 | |
1773 | |
1774 | |
1775 | |
1776 | |
1777 | |
1778 | |
1779 | |
1780 | FunctionTemplate = FunctionTemplateDecl::Create(SemaRef.Context, DC, |
1781 | Function->getLocation(), |
1782 | Function->getDeclName(), |
1783 | TemplateParams, Function); |
1784 | Function->setDescribedFunctionTemplate(FunctionTemplate); |
1785 | |
1786 | FunctionTemplate->setLexicalDeclContext(LexicalDC); |
1787 | |
1788 | if (isFriend && D->isThisDeclarationADefinition()) { |
1789 | FunctionTemplate->setInstantiatedFromMemberTemplate( |
1790 | D->getDescribedFunctionTemplate()); |
1791 | } |
1792 | } else if (FunctionTemplate) { |
1793 | |
1794 | ArrayRef<TemplateArgument> Innermost = TemplateArgs.getInnermost(); |
1795 | Function->setFunctionTemplateSpecialization(FunctionTemplate, |
1796 | TemplateArgumentList::CreateCopy(SemaRef.Context, |
1797 | Innermost), |
1798 | ); |
1799 | } else if (isFriend && D->isThisDeclarationADefinition()) { |
1800 | |
1801 | |
1802 | |
1803 | Function->setInstantiationOfMemberFunction(D, TSK_ImplicitInstantiation); |
1804 | } |
1805 | |
1806 | if (isFriend) |
1807 | Function->setObjectOfFriendDecl(); |
1808 | |
1809 | if (InitFunctionInstantiation(Function, D)) |
1810 | Function->setInvalidDecl(); |
1811 | |
1812 | bool IsExplicitSpecialization = false; |
1813 | |
1814 | LookupResult Previous( |
1815 | SemaRef, Function->getDeclName(), SourceLocation(), |
1816 | D->isLocalExternDecl() ? Sema::LookupRedeclarationWithLinkage |
1817 | : Sema::LookupOrdinaryName, |
1818 | D->isLocalExternDecl() ? Sema::ForExternalRedeclaration |
1819 | : SemaRef.forRedeclarationInCurContext()); |
1820 | |
1821 | if (DependentFunctionTemplateSpecializationInfo *Info |
1822 | = D->getDependentSpecializationInfo()) { |
1823 | (0) . __assert_fail ("isFriend && \"non-friend has dependent specialization info?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 1823, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isFriend && "non-friend has dependent specialization info?"); |
1824 | |
1825 | |
1826 | TemplateArgumentListInfo ExplicitArgs(Info->getLAngleLoc(), |
1827 | Info->getRAngleLoc()); |
1828 | if (SemaRef.Subst(Info->getTemplateArgs(), Info->getNumTemplateArgs(), |
1829 | ExplicitArgs, TemplateArgs)) |
1830 | return nullptr; |
1831 | |
1832 | |
1833 | for (unsigned I = 0, E = Info->getNumTemplates(); I != E; ++I) { |
1834 | Decl *Temp = SemaRef.FindInstantiatedDecl(D->getLocation(), |
1835 | Info->getTemplate(I), |
1836 | TemplateArgs); |
1837 | if (!Temp) return nullptr; |
1838 | |
1839 | Previous.addDecl(cast<FunctionTemplateDecl>(Temp)); |
1840 | } |
1841 | |
1842 | if (SemaRef.CheckFunctionTemplateSpecialization(Function, |
1843 | &ExplicitArgs, |
1844 | Previous)) |
1845 | Function->setInvalidDecl(); |
1846 | |
1847 | IsExplicitSpecialization = true; |
1848 | } else if (const ASTTemplateArgumentListInfo *Info = |
1849 | D->getTemplateSpecializationArgsAsWritten()) { |
1850 | |
1851 | SemaRef.LookupQualifiedName(Previous, DC); |
1852 | |
1853 | |
1854 | TemplateArgumentListInfo ExplicitArgs(Info->getLAngleLoc(), |
1855 | Info->getRAngleLoc()); |
1856 | if (SemaRef.Subst(Info->getTemplateArgs(), Info->getNumTemplateArgs(), |
1857 | ExplicitArgs, TemplateArgs)) |
1858 | return nullptr; |
1859 | |
1860 | if (SemaRef.CheckFunctionTemplateSpecialization(Function, |
1861 | &ExplicitArgs, |
1862 | Previous)) |
1863 | Function->setInvalidDecl(); |
1864 | |
1865 | IsExplicitSpecialization = true; |
1866 | } else if (TemplateParams || !FunctionTemplate) { |
1867 | |
1868 | |
1869 | |
1870 | SemaRef.LookupQualifiedName(Previous, DC); |
1871 | |
1872 | |
1873 | |
1874 | |
1875 | |
1876 | if (Previous.isSingleTagDecl()) |
1877 | Previous.clear(); |
1878 | } |
1879 | |
1880 | SemaRef.CheckFunctionDeclaration( nullptr, Function, Previous, |
1881 | IsExplicitSpecialization); |
1882 | |
1883 | NamedDecl *PrincipalDecl = (TemplateParams |
1884 | ? cast<NamedDecl>(FunctionTemplate) |
1885 | : Function); |
1886 | |
1887 | |
1888 | |
1889 | if (isFriend) { |
1890 | Function->setObjectOfFriendDecl(); |
1891 | if (FunctionTemplateDecl *FT = Function->getDescribedFunctionTemplate()) |
1892 | FT->setObjectOfFriendDecl(); |
1893 | DC->makeDeclVisibleInContext(PrincipalDecl); |
1894 | |
1895 | bool QueuedInstantiation = false; |
1896 | |
1897 | |
1898 | |
1899 | |
1900 | |
1901 | |
1902 | |
1903 | if (D->isThisDeclarationADefinition()) { |
1904 | SemaRef.CheckForFunctionRedefinition(Function); |
1905 | if (!Function->isInvalidDecl()) { |
1906 | for (auto R : Function->redecls()) { |
1907 | if (R == Function) |
1908 | continue; |
1909 | |
1910 | |
1911 | |
1912 | if (!QueuedInstantiation && R->isUsed(false)) { |
1913 | if (MemberSpecializationInfo *MSInfo = |
1914 | Function->getMemberSpecializationInfo()) { |
1915 | if (MSInfo->getPointOfInstantiation().isInvalid()) { |
1916 | SourceLocation Loc = R->getLocation(); |
1917 | MSInfo->setPointOfInstantiation(Loc); |
1918 | SemaRef.PendingLocalImplicitInstantiations.push_back( |
1919 | std::make_pair(Function, Loc)); |
1920 | QueuedInstantiation = true; |
1921 | } |
1922 | } |
1923 | } |
1924 | } |
1925 | } |
1926 | } |
1927 | |
1928 | |
1929 | |
1930 | |
1931 | |
1932 | if (TemplateParams && FunctionTemplate->getPreviousDecl()) { |
1933 | SemaRef.CheckTemplateParameterList( |
1934 | TemplateParams, |
1935 | FunctionTemplate->getPreviousDecl()->getTemplateParameters(), |
1936 | Function->isThisDeclarationADefinition() |
1937 | ? Sema::TPC_FriendFunctionTemplateDefinition |
1938 | : Sema::TPC_FriendFunctionTemplate); |
1939 | } |
1940 | } |
1941 | |
1942 | if (Function->isLocalExternDecl() && !Function->getPreviousDecl()) |
1943 | DC->makeDeclVisibleInContext(PrincipalDecl); |
1944 | |
1945 | if (Function->isOverloadedOperator() && !DC->isRecord() && |
1946 | PrincipalDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
1947 | PrincipalDecl->setNonMemberOperator(); |
1948 | |
1949 | (0) . __assert_fail ("!D->isDefaulted() && \"only methods should be defaulted\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 1949, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!D->isDefaulted() && "only methods should be defaulted"); |
1950 | return Function; |
1951 | } |
1952 | |
1953 | Decl * |
1954 | TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D, |
1955 | TemplateParameterList *TemplateParams, |
1956 | bool IsClassScopeSpecialization) { |
1957 | FunctionTemplateDecl *FunctionTemplate = D->getDescribedFunctionTemplate(); |
1958 | if (FunctionTemplate && !TemplateParams) { |
1959 | |
1960 | |
1961 | |
1962 | ArrayRef<TemplateArgument> Innermost = TemplateArgs.getInnermost(); |
1963 | |
1964 | void *InsertPos = nullptr; |
1965 | FunctionDecl *SpecFunc |
1966 | = FunctionTemplate->findSpecialization(Innermost, InsertPos); |
1967 | |
1968 | |
1969 | if (SpecFunc) |
1970 | return SpecFunc; |
1971 | } |
1972 | |
1973 | bool isFriend; |
1974 | if (FunctionTemplate) |
1975 | isFriend = (FunctionTemplate->getFriendObjectKind() != Decl::FOK_None); |
1976 | else |
1977 | isFriend = (D->getFriendObjectKind() != Decl::FOK_None); |
1978 | |
1979 | bool MergeWithParentScope = (TemplateParams != nullptr) || |
1980 | !(isa<Decl>(Owner) && |
1981 | cast<Decl>(Owner)->isDefinedOutsideFunctionOrMethod()); |
1982 | LocalInstantiationScope Scope(SemaRef, MergeWithParentScope); |
1983 | |
1984 | |
1985 | SmallVector<TemplateParameterList *, 4> TempParamLists; |
1986 | unsigned NumTempParamLists = 0; |
1987 | if (isFriend && (NumTempParamLists = D->getNumTemplateParameterLists())) { |
1988 | TempParamLists.resize(NumTempParamLists); |
1989 | for (unsigned I = 0; I != NumTempParamLists; ++I) { |
1990 | TemplateParameterList *TempParams = D->getTemplateParameterList(I); |
1991 | TemplateParameterList *InstParams = SubstTemplateParams(TempParams); |
1992 | if (!InstParams) |
1993 | return nullptr; |
1994 | TempParamLists[I] = InstParams; |
1995 | } |
1996 | } |
1997 | |
1998 | SmallVector<ParmVarDecl *, 4> Params; |
1999 | TypeSourceInfo *TInfo = SubstFunctionType(D, Params); |
2000 | if (!TInfo) |
2001 | return nullptr; |
2002 | QualType T = adjustFunctionTypeForInstantiation(SemaRef.Context, D, TInfo); |
2003 | |
2004 | NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc(); |
2005 | if (QualifierLoc) { |
2006 | QualifierLoc = SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc, |
2007 | TemplateArgs); |
2008 | if (!QualifierLoc) |
2009 | return nullptr; |
2010 | } |
2011 | |
2012 | DeclContext *DC = Owner; |
2013 | if (isFriend) { |
2014 | if (QualifierLoc) { |
2015 | CXXScopeSpec SS; |
2016 | SS.Adopt(QualifierLoc); |
2017 | DC = SemaRef.computeDeclContext(SS); |
2018 | |
2019 | if (DC && SemaRef.RequireCompleteDeclContext(SS, DC)) |
2020 | return nullptr; |
2021 | } else { |
2022 | DC = SemaRef.FindInstantiatedContext(D->getLocation(), |
2023 | D->getDeclContext(), |
2024 | TemplateArgs); |
2025 | } |
2026 | if (!DC) return nullptr; |
2027 | } |
2028 | |
2029 | |
2030 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DC); |
2031 | CXXMethodDecl *Method = nullptr; |
2032 | |
2033 | SourceLocation StartLoc = D->getInnerLocStart(); |
2034 | DeclarationNameInfo NameInfo |
2035 | = SemaRef.SubstDeclarationNameInfo(D->getNameInfo(), TemplateArgs); |
2036 | if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) { |
2037 | Method = CXXConstructorDecl::Create(SemaRef.Context, Record, |
2038 | StartLoc, NameInfo, T, TInfo, |
2039 | Constructor->isExplicit(), |
2040 | Constructor->isInlineSpecified(), |
2041 | false, Constructor->isConstexpr()); |
2042 | Method->setRangeEnd(Constructor->getEndLoc()); |
2043 | } else if (CXXDestructorDecl *Destructor = dyn_cast<CXXDestructorDecl>(D)) { |
2044 | Method = CXXDestructorDecl::Create(SemaRef.Context, Record, |
2045 | StartLoc, NameInfo, T, TInfo, |
2046 | Destructor->isInlineSpecified(), |
2047 | false); |
2048 | Method->setRangeEnd(Destructor->getEndLoc()); |
2049 | } else if (CXXConversionDecl *Conversion = dyn_cast<CXXConversionDecl>(D)) { |
2050 | Method = CXXConversionDecl::Create( |
2051 | SemaRef.Context, Record, StartLoc, NameInfo, T, TInfo, |
2052 | Conversion->isInlineSpecified(), Conversion->isExplicit(), |
2053 | Conversion->isConstexpr(), Conversion->getEndLoc()); |
2054 | } else { |
2055 | StorageClass SC = D->isStatic() ? SC_Static : SC_None; |
2056 | Method = CXXMethodDecl::Create(SemaRef.Context, Record, StartLoc, NameInfo, |
2057 | T, TInfo, SC, D->isInlineSpecified(), |
2058 | D->isConstexpr(), D->getEndLoc()); |
2059 | } |
2060 | |
2061 | if (D->isInlined()) |
2062 | Method->setImplicitlyInline(); |
2063 | |
2064 | if (QualifierLoc) |
2065 | Method->setQualifierInfo(QualifierLoc); |
2066 | |
2067 | if (TemplateParams) { |
2068 | |
2069 | |
2070 | |
2071 | |
2072 | |
2073 | |
2074 | |
2075 | |
2076 | |
2077 | |
2078 | |
2079 | |
2080 | |
2081 | FunctionTemplate = FunctionTemplateDecl::Create(SemaRef.Context, Record, |
2082 | Method->getLocation(), |
2083 | Method->getDeclName(), |
2084 | TemplateParams, Method); |
2085 | if (isFriend) { |
2086 | FunctionTemplate->setLexicalDeclContext(Owner); |
2087 | FunctionTemplate->setObjectOfFriendDecl(); |
2088 | } else if (D->isOutOfLine()) |
2089 | FunctionTemplate->setLexicalDeclContext(D->getLexicalDeclContext()); |
2090 | Method->setDescribedFunctionTemplate(FunctionTemplate); |
2091 | } else if (FunctionTemplate) { |
2092 | |
2093 | ArrayRef<TemplateArgument> Innermost = TemplateArgs.getInnermost(); |
2094 | Method->setFunctionTemplateSpecialization(FunctionTemplate, |
2095 | TemplateArgumentList::CreateCopy(SemaRef.Context, |
2096 | Innermost), |
2097 | ); |
2098 | } else if (!isFriend) { |
2099 | |
2100 | Method->setInstantiationOfMemberFunction(D, TSK_ImplicitInstantiation); |
2101 | } |
2102 | |
2103 | |
2104 | |
2105 | |
2106 | if (isFriend) { |
2107 | if (NumTempParamLists) |
2108 | Method->setTemplateParameterListsInfo( |
2109 | SemaRef.Context, |
2110 | llvm::makeArrayRef(TempParamLists.data(), NumTempParamLists)); |
2111 | |
2112 | Method->setLexicalDeclContext(Owner); |
2113 | Method->setObjectOfFriendDecl(); |
2114 | } else if (D->isOutOfLine()) |
2115 | Method->setLexicalDeclContext(D->getLexicalDeclContext()); |
2116 | |
2117 | |
2118 | for (unsigned P = 0; P < Params.size(); ++P) |
2119 | Params[P]->setOwningFunction(Method); |
2120 | Method->setParams(Params); |
2121 | |
2122 | if (InitMethodInstantiation(Method, D)) |
2123 | Method->setInvalidDecl(); |
2124 | |
2125 | LookupResult Previous(SemaRef, NameInfo, Sema::LookupOrdinaryName, |
2126 | Sema::ForExternalRedeclaration); |
2127 | |
2128 | bool IsExplicitSpecialization = false; |
2129 | |
2130 | |
2131 | |
2132 | if (DependentFunctionTemplateSpecializationInfo *Info |
2133 | = D->getDependentSpecializationInfo()) { |
2134 | (0) . __assert_fail ("isFriend && \"non-friend has dependent specialization info?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 2134, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isFriend && "non-friend has dependent specialization info?"); |
2135 | |
2136 | |
2137 | TemplateArgumentListInfo ExplicitArgs(Info->getLAngleLoc(), |
2138 | Info->getRAngleLoc()); |
2139 | if (SemaRef.Subst(Info->getTemplateArgs(), Info->getNumTemplateArgs(), |
2140 | ExplicitArgs, TemplateArgs)) |
2141 | return nullptr; |
2142 | |
2143 | |
2144 | for (unsigned I = 0, E = Info->getNumTemplates(); I != E; ++I) { |
2145 | Decl *Temp = SemaRef.FindInstantiatedDecl(D->getLocation(), |
2146 | Info->getTemplate(I), |
2147 | TemplateArgs); |
2148 | if (!Temp) return nullptr; |
2149 | |
2150 | Previous.addDecl(cast<FunctionTemplateDecl>(Temp)); |
2151 | } |
2152 | |
2153 | if (SemaRef.CheckFunctionTemplateSpecialization(Method, |
2154 | &ExplicitArgs, |
2155 | Previous)) |
2156 | Method->setInvalidDecl(); |
2157 | |
2158 | IsExplicitSpecialization = true; |
2159 | } else if (const ASTTemplateArgumentListInfo *Info = |
2160 | D->getTemplateSpecializationArgsAsWritten()) { |
2161 | SemaRef.LookupQualifiedName(Previous, DC); |
2162 | |
2163 | TemplateArgumentListInfo ExplicitArgs(Info->getLAngleLoc(), |
2164 | Info->getRAngleLoc()); |
2165 | if (SemaRef.Subst(Info->getTemplateArgs(), Info->getNumTemplateArgs(), |
2166 | ExplicitArgs, TemplateArgs)) |
2167 | return nullptr; |
2168 | |
2169 | if (SemaRef.CheckFunctionTemplateSpecialization(Method, |
2170 | &ExplicitArgs, |
2171 | Previous)) |
2172 | Method->setInvalidDecl(); |
2173 | |
2174 | IsExplicitSpecialization = true; |
2175 | } else if (!FunctionTemplate || TemplateParams || isFriend) { |
2176 | SemaRef.LookupQualifiedName(Previous, Record); |
2177 | |
2178 | |
2179 | |
2180 | |
2181 | |
2182 | if (Previous.isSingleTagDecl()) |
2183 | Previous.clear(); |
2184 | } |
2185 | |
2186 | if (!IsClassScopeSpecialization) |
2187 | SemaRef.CheckFunctionDeclaration(nullptr, Method, Previous, |
2188 | IsExplicitSpecialization); |
2189 | |
2190 | if (D->isPure()) |
2191 | SemaRef.CheckPureMethod(Method, SourceRange()); |
2192 | |
2193 | |
2194 | |
2195 | |
2196 | if (isFriend && Method->getPreviousDecl()) |
2197 | Method->setAccess(Method->getPreviousDecl()->getAccess()); |
2198 | else |
2199 | Method->setAccess(D->getAccess()); |
2200 | if (FunctionTemplate) |
2201 | FunctionTemplate->setAccess(Method->getAccess()); |
2202 | |
2203 | SemaRef.CheckOverrideControl(Method); |
2204 | |
2205 | |
2206 | if (D->isExplicitlyDefaulted()) |
2207 | SemaRef.SetDeclDefaulted(Method, Method->getLocation()); |
2208 | if (D->isDeletedAsWritten()) |
2209 | SemaRef.SetDeclDeleted(Method, Method->getLocation()); |
2210 | |
2211 | |
2212 | if (FunctionTemplate) { |
2213 | |
2214 | |
2215 | |
2216 | } else if (Method->isInvalidDecl() && !Previous.empty()) { |
2217 | |
2218 | |
2219 | |
2220 | } else if (isFriend) { |
2221 | |
2222 | |
2223 | if (!D->getPreviousDecl()) |
2224 | SemaRef.CheckFriendAccess(Method); |
2225 | |
2226 | Record->makeDeclVisibleInContext(Method); |
2227 | |
2228 | |
2229 | |
2230 | |
2231 | } else if (!IsClassScopeSpecialization) { |
2232 | Owner->addDecl(Method); |
2233 | } |
2234 | |
2235 | |
2236 | |
2237 | if (Method->hasAttr<UsedAttr>()) { |
2238 | if (const auto *A = dyn_cast<CXXRecordDecl>(Owner)) { |
2239 | SourceLocation Loc; |
2240 | if (const MemberSpecializationInfo *MSInfo = |
2241 | A->getMemberSpecializationInfo()) |
2242 | Loc = MSInfo->getPointOfInstantiation(); |
2243 | else if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(A)) |
2244 | Loc = Spec->getPointOfInstantiation(); |
2245 | SemaRef.MarkFunctionReferenced(Loc, Method); |
2246 | } |
2247 | } |
2248 | |
2249 | return Method; |
2250 | } |
2251 | |
2252 | Decl *TemplateDeclInstantiator::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
2253 | return VisitCXXMethodDecl(D); |
2254 | } |
2255 | |
2256 | Decl *TemplateDeclInstantiator::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
2257 | return VisitCXXMethodDecl(D); |
2258 | } |
2259 | |
2260 | Decl *TemplateDeclInstantiator::VisitCXXConversionDecl(CXXConversionDecl *D) { |
2261 | return VisitCXXMethodDecl(D); |
2262 | } |
2263 | |
2264 | Decl *TemplateDeclInstantiator::VisitParmVarDecl(ParmVarDecl *D) { |
2265 | return SemaRef.SubstParmVarDecl(D, TemplateArgs, 0, None, |
2266 | false); |
2267 | } |
2268 | |
2269 | Decl *TemplateDeclInstantiator::VisitTemplateTypeParmDecl( |
2270 | TemplateTypeParmDecl *D) { |
2271 | |
2272 | getTypeForDecl()->isTemplateTypeParmType()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 2272, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(D->getTypeForDecl()->isTemplateTypeParmType()); |
2273 | |
2274 | TemplateTypeParmDecl *Inst = TemplateTypeParmDecl::Create( |
2275 | SemaRef.Context, Owner, D->getBeginLoc(), D->getLocation(), |
2276 | D->getDepth() - TemplateArgs.getNumSubstitutedLevels(), D->getIndex(), |
2277 | D->getIdentifier(), D->wasDeclaredWithTypename(), D->isParameterPack()); |
2278 | Inst->setAccess(AS_public); |
2279 | |
2280 | if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) { |
2281 | TypeSourceInfo *InstantiatedDefaultArg = |
2282 | SemaRef.SubstType(D->getDefaultArgumentInfo(), TemplateArgs, |
2283 | D->getDefaultArgumentLoc(), D->getDeclName()); |
2284 | if (InstantiatedDefaultArg) |
2285 | Inst->setDefaultArgument(InstantiatedDefaultArg); |
2286 | } |
2287 | |
2288 | |
2289 | |
2290 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Inst); |
2291 | |
2292 | return Inst; |
2293 | } |
2294 | |
2295 | Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl( |
2296 | NonTypeTemplateParmDecl *D) { |
2297 | |
2298 | TypeLoc TL = D->getTypeSourceInfo()->getTypeLoc(); |
2299 | SmallVector<TypeSourceInfo *, 4> ExpandedParameterPackTypesAsWritten; |
2300 | SmallVector<QualType, 4> ExpandedParameterPackTypes; |
2301 | bool IsExpandedParameterPack = false; |
2302 | TypeSourceInfo *DI; |
2303 | QualType T; |
2304 | bool Invalid = false; |
2305 | |
2306 | if (D->isExpandedParameterPack()) { |
2307 | |
2308 | |
2309 | ExpandedParameterPackTypes.reserve(D->getNumExpansionTypes()); |
2310 | ExpandedParameterPackTypesAsWritten.reserve(D->getNumExpansionTypes()); |
2311 | for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) { |
2312 | TypeSourceInfo *NewDI = |
2313 | SemaRef.SubstType(D->getExpansionTypeSourceInfo(I), TemplateArgs, |
2314 | D->getLocation(), D->getDeclName()); |
2315 | if (!NewDI) |
2316 | return nullptr; |
2317 | |
2318 | QualType NewT = |
2319 | SemaRef.CheckNonTypeTemplateParameterType(NewDI, D->getLocation()); |
2320 | if (NewT.isNull()) |
2321 | return nullptr; |
2322 | |
2323 | ExpandedParameterPackTypesAsWritten.push_back(NewDI); |
2324 | ExpandedParameterPackTypes.push_back(NewT); |
2325 | } |
2326 | |
2327 | IsExpandedParameterPack = true; |
2328 | DI = D->getTypeSourceInfo(); |
2329 | T = DI->getType(); |
2330 | } else if (D->isPackExpansion()) { |
2331 | |
2332 | |
2333 | |
2334 | PackExpansionTypeLoc Expansion = TL.castAs<PackExpansionTypeLoc>(); |
2335 | TypeLoc Pattern = Expansion.getPatternLoc(); |
2336 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
2337 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
2338 | |
2339 | |
2340 | |
2341 | bool Expand = true; |
2342 | bool RetainExpansion = false; |
2343 | Optional<unsigned> OrigNumExpansions |
2344 | = Expansion.getTypePtr()->getNumExpansions(); |
2345 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
2346 | if (SemaRef.CheckParameterPacksForExpansion(Expansion.getEllipsisLoc(), |
2347 | Pattern.getSourceRange(), |
2348 | Unexpanded, |
2349 | TemplateArgs, |
2350 | Expand, RetainExpansion, |
2351 | NumExpansions)) |
2352 | return nullptr; |
2353 | |
2354 | if (Expand) { |
2355 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
2356 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); |
2357 | TypeSourceInfo *NewDI = SemaRef.SubstType(Pattern, TemplateArgs, |
2358 | D->getLocation(), |
2359 | D->getDeclName()); |
2360 | if (!NewDI) |
2361 | return nullptr; |
2362 | |
2363 | QualType NewT = |
2364 | SemaRef.CheckNonTypeTemplateParameterType(NewDI, D->getLocation()); |
2365 | if (NewT.isNull()) |
2366 | return nullptr; |
2367 | |
2368 | ExpandedParameterPackTypesAsWritten.push_back(NewDI); |
2369 | ExpandedParameterPackTypes.push_back(NewT); |
2370 | } |
2371 | |
2372 | |
2373 | |
2374 | |
2375 | IsExpandedParameterPack = true; |
2376 | DI = D->getTypeSourceInfo(); |
2377 | T = DI->getType(); |
2378 | } else { |
2379 | |
2380 | |
2381 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, -1); |
2382 | TypeSourceInfo *NewPattern = SemaRef.SubstType(Pattern, TemplateArgs, |
2383 | D->getLocation(), |
2384 | D->getDeclName()); |
2385 | if (!NewPattern) |
2386 | return nullptr; |
2387 | |
2388 | SemaRef.CheckNonTypeTemplateParameterType(NewPattern, D->getLocation()); |
2389 | DI = SemaRef.CheckPackExpansion(NewPattern, Expansion.getEllipsisLoc(), |
2390 | NumExpansions); |
2391 | if (!DI) |
2392 | return nullptr; |
2393 | |
2394 | T = DI->getType(); |
2395 | } |
2396 | } else { |
2397 | |
2398 | DI = SemaRef.SubstType(D->getTypeSourceInfo(), TemplateArgs, |
2399 | D->getLocation(), D->getDeclName()); |
2400 | if (!DI) |
2401 | return nullptr; |
2402 | |
2403 | |
2404 | T = SemaRef.CheckNonTypeTemplateParameterType(DI, D->getLocation()); |
2405 | if (T.isNull()) { |
2406 | T = SemaRef.Context.IntTy; |
2407 | Invalid = true; |
2408 | } |
2409 | } |
2410 | |
2411 | NonTypeTemplateParmDecl *Param; |
2412 | if (IsExpandedParameterPack) |
2413 | Param = NonTypeTemplateParmDecl::Create( |
2414 | SemaRef.Context, Owner, D->getInnerLocStart(), D->getLocation(), |
2415 | D->getDepth() - TemplateArgs.getNumSubstitutedLevels(), |
2416 | D->getPosition(), D->getIdentifier(), T, DI, ExpandedParameterPackTypes, |
2417 | ExpandedParameterPackTypesAsWritten); |
2418 | else |
2419 | Param = NonTypeTemplateParmDecl::Create( |
2420 | SemaRef.Context, Owner, D->getInnerLocStart(), D->getLocation(), |
2421 | D->getDepth() - TemplateArgs.getNumSubstitutedLevels(), |
2422 | D->getPosition(), D->getIdentifier(), T, D->isParameterPack(), DI); |
2423 | |
2424 | Param->setAccess(AS_public); |
2425 | if (Invalid) |
2426 | Param->setInvalidDecl(); |
2427 | |
2428 | if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) { |
2429 | EnterExpressionEvaluationContext ConstantEvaluated( |
2430 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
2431 | ExprResult Value = SemaRef.SubstExpr(D->getDefaultArgument(), TemplateArgs); |
2432 | if (!Value.isInvalid()) |
2433 | Param->setDefaultArgument(Value.get()); |
2434 | } |
2435 | |
2436 | |
2437 | |
2438 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Param); |
2439 | return Param; |
2440 | } |
2441 | |
2442 | static void collectUnexpandedParameterPacks( |
2443 | Sema &S, |
2444 | TemplateParameterList *Params, |
2445 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded) { |
2446 | for (const auto &P : *Params) { |
2447 | if (P->isTemplateParameterPack()) |
2448 | continue; |
2449 | if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P)) |
2450 | S.collectUnexpandedParameterPacks(NTTP->getTypeSourceInfo()->getTypeLoc(), |
2451 | Unexpanded); |
2452 | if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(P)) |
2453 | collectUnexpandedParameterPacks(S, TTP->getTemplateParameters(), |
2454 | Unexpanded); |
2455 | } |
2456 | } |
2457 | |
2458 | Decl * |
2459 | TemplateDeclInstantiator::VisitTemplateTemplateParmDecl( |
2460 | TemplateTemplateParmDecl *D) { |
2461 | |
2462 | TemplateParameterList *TempParams = D->getTemplateParameters(); |
2463 | TemplateParameterList *InstParams; |
2464 | SmallVector<TemplateParameterList*, 8> ExpandedParams; |
2465 | |
2466 | bool IsExpandedParameterPack = false; |
2467 | |
2468 | if (D->isExpandedParameterPack()) { |
2469 | |
2470 | |
2471 | |
2472 | ExpandedParams.reserve(D->getNumExpansionTemplateParameters()); |
2473 | for (unsigned I = 0, N = D->getNumExpansionTemplateParameters(); |
2474 | I != N; ++I) { |
2475 | LocalInstantiationScope Scope(SemaRef); |
2476 | TemplateParameterList *Expansion = |
2477 | SubstTemplateParams(D->getExpansionTemplateParameters(I)); |
2478 | if (!Expansion) |
2479 | return nullptr; |
2480 | ExpandedParams.push_back(Expansion); |
2481 | } |
2482 | |
2483 | IsExpandedParameterPack = true; |
2484 | InstParams = TempParams; |
2485 | } else if (D->isPackExpansion()) { |
2486 | |
2487 | |
2488 | |
2489 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
2490 | collectUnexpandedParameterPacks(SemaRef, D->getTemplateParameters(), |
2491 | Unexpanded); |
2492 | |
2493 | |
2494 | |
2495 | bool Expand = true; |
2496 | bool RetainExpansion = false; |
2497 | Optional<unsigned> NumExpansions; |
2498 | if (SemaRef.CheckParameterPacksForExpansion(D->getLocation(), |
2499 | TempParams->getSourceRange(), |
2500 | Unexpanded, |
2501 | TemplateArgs, |
2502 | Expand, RetainExpansion, |
2503 | NumExpansions)) |
2504 | return nullptr; |
2505 | |
2506 | if (Expand) { |
2507 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
2508 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); |
2509 | LocalInstantiationScope Scope(SemaRef); |
2510 | TemplateParameterList *Expansion = SubstTemplateParams(TempParams); |
2511 | if (!Expansion) |
2512 | return nullptr; |
2513 | ExpandedParams.push_back(Expansion); |
2514 | } |
2515 | |
2516 | |
2517 | |
2518 | |
2519 | IsExpandedParameterPack = true; |
2520 | InstParams = TempParams; |
2521 | } else { |
2522 | |
2523 | |
2524 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, -1); |
2525 | |
2526 | LocalInstantiationScope Scope(SemaRef); |
2527 | InstParams = SubstTemplateParams(TempParams); |
2528 | if (!InstParams) |
2529 | return nullptr; |
2530 | } |
2531 | } else { |
2532 | |
2533 | |
2534 | LocalInstantiationScope Scope(SemaRef); |
2535 | InstParams = SubstTemplateParams(TempParams); |
2536 | if (!InstParams) |
2537 | return nullptr; |
2538 | } |
2539 | |
2540 | |
2541 | TemplateTemplateParmDecl *Param; |
2542 | if (IsExpandedParameterPack) |
2543 | Param = TemplateTemplateParmDecl::Create( |
2544 | SemaRef.Context, Owner, D->getLocation(), |
2545 | D->getDepth() - TemplateArgs.getNumSubstitutedLevels(), |
2546 | D->getPosition(), D->getIdentifier(), InstParams, ExpandedParams); |
2547 | else |
2548 | Param = TemplateTemplateParmDecl::Create( |
2549 | SemaRef.Context, Owner, D->getLocation(), |
2550 | D->getDepth() - TemplateArgs.getNumSubstitutedLevels(), |
2551 | D->getPosition(), D->isParameterPack(), D->getIdentifier(), InstParams); |
2552 | if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) { |
2553 | NestedNameSpecifierLoc QualifierLoc = |
2554 | D->getDefaultArgument().getTemplateQualifierLoc(); |
2555 | QualifierLoc = |
2556 | SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc, TemplateArgs); |
2557 | TemplateName TName = SemaRef.SubstTemplateName( |
2558 | QualifierLoc, D->getDefaultArgument().getArgument().getAsTemplate(), |
2559 | D->getDefaultArgument().getTemplateNameLoc(), TemplateArgs); |
2560 | if (!TName.isNull()) |
2561 | Param->setDefaultArgument( |
2562 | SemaRef.Context, |
2563 | TemplateArgumentLoc(TemplateArgument(TName), |
2564 | D->getDefaultArgument().getTemplateQualifierLoc(), |
2565 | D->getDefaultArgument().getTemplateNameLoc())); |
2566 | } |
2567 | Param->setAccess(AS_public); |
2568 | |
2569 | |
2570 | |
2571 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Param); |
2572 | |
2573 | return Param; |
2574 | } |
2575 | |
2576 | Decl *TemplateDeclInstantiator::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
2577 | |
2578 | |
2579 | |
2580 | UsingDirectiveDecl *Inst |
2581 | = UsingDirectiveDecl::Create(SemaRef.Context, Owner, D->getLocation(), |
2582 | D->getNamespaceKeyLocation(), |
2583 | D->getQualifierLoc(), |
2584 | D->getIdentLocation(), |
2585 | D->getNominatedNamespace(), |
2586 | D->getCommonAncestor()); |
2587 | |
2588 | |
2589 | |
2590 | if (!Owner->isFunctionOrMethod()) |
2591 | Owner->addDecl(Inst); |
2592 | |
2593 | return Inst; |
2594 | } |
2595 | |
2596 | Decl *TemplateDeclInstantiator::VisitUsingDecl(UsingDecl *D) { |
2597 | |
2598 | |
2599 | |
2600 | |
2601 | |
2602 | |
2603 | |
2604 | |
2605 | |
2606 | NestedNameSpecifierLoc QualifierLoc |
2607 | = SemaRef.SubstNestedNameSpecifierLoc(D->getQualifierLoc(), |
2608 | TemplateArgs); |
2609 | if (!QualifierLoc) |
2610 | return nullptr; |
2611 | |
2612 | |
2613 | |
2614 | |
2615 | DeclarationNameInfo NameInfo = D->getNameInfo(); |
2616 | if (NameInfo.getName().getNameKind() == DeclarationName::CXXConstructorName) |
2617 | if (auto *RD = dyn_cast<CXXRecordDecl>(SemaRef.CurContext)) |
2618 | NameInfo.setName(SemaRef.Context.DeclarationNames.getCXXConstructorName( |
2619 | SemaRef.Context.getCanonicalType(SemaRef.Context.getRecordType(RD)))); |
2620 | |
2621 | |
2622 | |
2623 | |
2624 | bool CheckRedeclaration = Owner->isRecord(); |
2625 | |
2626 | LookupResult Prev(SemaRef, NameInfo, Sema::LookupUsingDeclName, |
2627 | Sema::ForVisibleRedeclaration); |
2628 | |
2629 | UsingDecl *NewUD = UsingDecl::Create(SemaRef.Context, Owner, |
2630 | D->getUsingLoc(), |
2631 | QualifierLoc, |
2632 | NameInfo, |
2633 | D->hasTypename()); |
2634 | |
2635 | CXXScopeSpec SS; |
2636 | SS.Adopt(QualifierLoc); |
2637 | if (CheckRedeclaration) { |
2638 | Prev.setHideTags(false); |
2639 | SemaRef.LookupQualifiedName(Prev, Owner); |
2640 | |
2641 | |
2642 | if (SemaRef.CheckUsingDeclRedeclaration(D->getUsingLoc(), |
2643 | D->hasTypename(), SS, |
2644 | D->getLocation(), Prev)) |
2645 | NewUD->setInvalidDecl(); |
2646 | |
2647 | } |
2648 | |
2649 | if (!NewUD->isInvalidDecl() && |
2650 | SemaRef.CheckUsingDeclQualifier(D->getUsingLoc(), D->hasTypename(), |
2651 | SS, NameInfo, D->getLocation())) |
2652 | NewUD->setInvalidDecl(); |
2653 | |
2654 | SemaRef.Context.setInstantiatedFromUsingDecl(NewUD, D); |
2655 | NewUD->setAccess(D->getAccess()); |
2656 | Owner->addDecl(NewUD); |
2657 | |
2658 | |
2659 | if (NewUD->isInvalidDecl()) |
2660 | return NewUD; |
2661 | |
2662 | if (NameInfo.getName().getNameKind() == DeclarationName::CXXConstructorName) |
2663 | SemaRef.CheckInheritingConstructorUsingDecl(NewUD); |
2664 | |
2665 | bool isFunctionScope = Owner->isFunctionOrMethod(); |
2666 | |
2667 | |
2668 | for (auto *Shadow : D->shadows()) { |
2669 | |
2670 | |
2671 | NamedDecl *OldTarget = Shadow->getTargetDecl(); |
2672 | if (auto *CUSD = dyn_cast<ConstructorUsingShadowDecl>(Shadow)) |
2673 | if (auto *BaseShadow = CUSD->getNominatedBaseClassShadowDecl()) |
2674 | OldTarget = BaseShadow; |
2675 | |
2676 | NamedDecl *InstTarget = |
2677 | cast_or_null<NamedDecl>(SemaRef.FindInstantiatedDecl( |
2678 | Shadow->getLocation(), OldTarget, TemplateArgs)); |
2679 | if (!InstTarget) |
2680 | return nullptr; |
2681 | |
2682 | UsingShadowDecl *PrevDecl = nullptr; |
2683 | if (CheckRedeclaration) { |
2684 | if (SemaRef.CheckUsingShadowDecl(NewUD, InstTarget, Prev, PrevDecl)) |
2685 | continue; |
2686 | } else if (UsingShadowDecl *OldPrev = |
2687 | getPreviousDeclForInstantiation(Shadow)) { |
2688 | PrevDecl = cast_or_null<UsingShadowDecl>(SemaRef.FindInstantiatedDecl( |
2689 | Shadow->getLocation(), OldPrev, TemplateArgs)); |
2690 | } |
2691 | |
2692 | UsingShadowDecl *InstShadow = |
2693 | SemaRef.BuildUsingShadowDecl(, NewUD, InstTarget, |
2694 | PrevDecl); |
2695 | SemaRef.Context.setInstantiatedFromUsingShadowDecl(InstShadow, Shadow); |
2696 | |
2697 | if (isFunctionScope) |
2698 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(Shadow, InstShadow); |
2699 | } |
2700 | |
2701 | return NewUD; |
2702 | } |
2703 | |
2704 | Decl *TemplateDeclInstantiator::VisitUsingShadowDecl(UsingShadowDecl *D) { |
2705 | |
2706 | return nullptr; |
2707 | } |
2708 | |
2709 | Decl *TemplateDeclInstantiator::VisitConstructorUsingShadowDecl( |
2710 | ConstructorUsingShadowDecl *D) { |
2711 | |
2712 | return nullptr; |
2713 | } |
2714 | |
2715 | template <typename T> |
2716 | Decl *TemplateDeclInstantiator::instantiateUnresolvedUsingDecl( |
2717 | T *D, bool InstantiatingPackElement) { |
2718 | |
2719 | if (D->isPackExpansion() && !InstantiatingPackElement) { |
2720 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
2721 | SemaRef.collectUnexpandedParameterPacks(D->getQualifierLoc(), Unexpanded); |
2722 | SemaRef.collectUnexpandedParameterPacks(D->getNameInfo(), Unexpanded); |
2723 | |
2724 | |
2725 | |
2726 | bool Expand = true; |
2727 | bool RetainExpansion = false; |
2728 | Optional<unsigned> NumExpansions; |
2729 | if (SemaRef.CheckParameterPacksForExpansion( |
2730 | D->getEllipsisLoc(), D->getSourceRange(), Unexpanded, TemplateArgs, |
2731 | Expand, RetainExpansion, NumExpansions)) |
2732 | return nullptr; |
2733 | |
2734 | |
2735 | |
2736 | (0) . __assert_fail ("!RetainExpansion && \"should never need to retain an expansion for UsingPackDecl\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 2737, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!RetainExpansion && |
2737 | (0) . __assert_fail ("!RetainExpansion && \"should never need to retain an expansion for UsingPackDecl\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 2737, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "should never need to retain an expansion for UsingPackDecl"); |
2738 | |
2739 | if (!Expand) { |
2740 | |
2741 | |
2742 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, -1); |
2743 | return instantiateUnresolvedUsingDecl(D, true); |
2744 | } |
2745 | |
2746 | |
2747 | |
2748 | |
2749 | |
2750 | |
2751 | |
2752 | |
2753 | if (D->getDeclContext()->isFunctionOrMethod() && *NumExpansions > 1) { |
2754 | SemaRef.Diag(D->getEllipsisLoc(), |
2755 | diag::err_using_decl_redeclaration_expansion); |
2756 | return nullptr; |
2757 | } |
2758 | |
2759 | |
2760 | SmallVector<NamedDecl*, 8> Expansions; |
2761 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
2762 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); |
2763 | Decl *Slice = instantiateUnresolvedUsingDecl(D, true); |
2764 | if (!Slice) |
2765 | return nullptr; |
2766 | |
2767 | |
2768 | |
2769 | |
2770 | Expansions.push_back(cast<NamedDecl>(Slice)); |
2771 | } |
2772 | |
2773 | auto *NewD = SemaRef.BuildUsingPackDecl(D, Expansions); |
2774 | if (isDeclWithinFunction(D)) |
2775 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, NewD); |
2776 | return NewD; |
2777 | } |
2778 | |
2779 | UnresolvedUsingTypenameDecl *TD = dyn_cast<UnresolvedUsingTypenameDecl>(D); |
2780 | SourceLocation TypenameLoc = TD ? TD->getTypenameLoc() : SourceLocation(); |
2781 | |
2782 | NestedNameSpecifierLoc QualifierLoc |
2783 | = SemaRef.SubstNestedNameSpecifierLoc(D->getQualifierLoc(), |
2784 | TemplateArgs); |
2785 | if (!QualifierLoc) |
2786 | return nullptr; |
2787 | |
2788 | CXXScopeSpec SS; |
2789 | SS.Adopt(QualifierLoc); |
2790 | |
2791 | DeclarationNameInfo NameInfo |
2792 | = SemaRef.SubstDeclarationNameInfo(D->getNameInfo(), TemplateArgs); |
2793 | |
2794 | |
2795 | |
2796 | bool InstantiatingSlice = D->getEllipsisLoc().isValid() && |
2797 | SemaRef.ArgumentPackSubstitutionIndex != -1; |
2798 | SourceLocation EllipsisLoc = |
2799 | InstantiatingSlice ? SourceLocation() : D->getEllipsisLoc(); |
2800 | |
2801 | NamedDecl *UD = SemaRef.BuildUsingDeclaration( |
2802 | nullptr, D->getAccess(), D->getUsingLoc(), |
2803 | TD, TypenameLoc, SS, NameInfo, EllipsisLoc, |
2804 | ParsedAttributesView(), |
2805 | true); |
2806 | if (UD) |
2807 | SemaRef.Context.setInstantiatedFromUsingDecl(UD, D); |
2808 | |
2809 | return UD; |
2810 | } |
2811 | |
2812 | Decl *TemplateDeclInstantiator::VisitUnresolvedUsingTypenameDecl( |
2813 | UnresolvedUsingTypenameDecl *D) { |
2814 | return instantiateUnresolvedUsingDecl(D); |
2815 | } |
2816 | |
2817 | Decl *TemplateDeclInstantiator::VisitUnresolvedUsingValueDecl( |
2818 | UnresolvedUsingValueDecl *D) { |
2819 | return instantiateUnresolvedUsingDecl(D); |
2820 | } |
2821 | |
2822 | Decl *TemplateDeclInstantiator::VisitUsingPackDecl(UsingPackDecl *D) { |
2823 | SmallVector<NamedDecl*, 8> Expansions; |
2824 | for (auto *UD : D->expansions()) { |
2825 | if (NamedDecl *NewUD = |
2826 | SemaRef.FindInstantiatedDecl(D->getLocation(), UD, TemplateArgs)) |
2827 | Expansions.push_back(NewUD); |
2828 | else |
2829 | return nullptr; |
2830 | } |
2831 | |
2832 | auto *NewD = SemaRef.BuildUsingPackDecl(D, Expansions); |
2833 | if (isDeclWithinFunction(D)) |
2834 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, NewD); |
2835 | return NewD; |
2836 | } |
2837 | |
2838 | Decl *TemplateDeclInstantiator::VisitClassScopeFunctionSpecializationDecl( |
2839 | ClassScopeFunctionSpecializationDecl *Decl) { |
2840 | CXXMethodDecl *OldFD = Decl->getSpecialization(); |
2841 | CXXMethodDecl *NewFD = |
2842 | cast_or_null<CXXMethodDecl>(VisitCXXMethodDecl(OldFD, nullptr, true)); |
2843 | if (!NewFD) |
2844 | return nullptr; |
2845 | |
2846 | TemplateArgumentListInfo ExplicitTemplateArgs; |
2847 | TemplateArgumentListInfo *ExplicitTemplateArgsPtr = nullptr; |
2848 | if (Decl->hasExplicitTemplateArgs()) { |
2849 | if (SemaRef.Subst(Decl->templateArgs().getArgumentArray(), |
2850 | Decl->templateArgs().size(), ExplicitTemplateArgs, |
2851 | TemplateArgs)) |
2852 | return nullptr; |
2853 | ExplicitTemplateArgsPtr = &ExplicitTemplateArgs; |
2854 | } |
2855 | |
2856 | LookupResult Previous(SemaRef, NewFD->getNameInfo(), Sema::LookupOrdinaryName, |
2857 | Sema::ForExternalRedeclaration); |
2858 | SemaRef.LookupQualifiedName(Previous, SemaRef.CurContext); |
2859 | if (SemaRef.CheckFunctionTemplateSpecialization( |
2860 | NewFD, ExplicitTemplateArgsPtr, Previous)) { |
2861 | NewFD->setInvalidDecl(); |
2862 | return NewFD; |
2863 | } |
2864 | |
2865 | |
2866 | FunctionDecl *Specialization = cast<FunctionDecl>(Previous.getFoundDecl()); |
2867 | (0) . __assert_fail ("Specialization && \"Class scope Specialization is null\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 2867, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Specialization && "Class scope Specialization is null"); |
2868 | SemaRef.Context.setClassScopeSpecializationPattern(Specialization, OldFD); |
2869 | |
2870 | |
2871 | |
2872 | return NewFD; |
2873 | } |
2874 | |
2875 | Decl *TemplateDeclInstantiator::VisitOMPThreadPrivateDecl( |
2876 | OMPThreadPrivateDecl *D) { |
2877 | SmallVector<Expr *, 5> Vars; |
2878 | for (auto *I : D->varlists()) { |
2879 | Expr *Var = SemaRef.SubstExpr(I, TemplateArgs).get(); |
2880 | (0) . __assert_fail ("isa(Var) && \"threadprivate arg is not a DeclRefExpr\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 2880, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isa<DeclRefExpr>(Var) && "threadprivate arg is not a DeclRefExpr"); |
2881 | Vars.push_back(Var); |
2882 | } |
2883 | |
2884 | OMPThreadPrivateDecl *TD = |
2885 | SemaRef.CheckOMPThreadPrivateDecl(D->getLocation(), Vars); |
2886 | |
2887 | TD->setAccess(AS_public); |
2888 | Owner->addDecl(TD); |
2889 | |
2890 | return TD; |
2891 | } |
2892 | |
2893 | Decl *TemplateDeclInstantiator::VisitOMPAllocateDecl(OMPAllocateDecl *D) { |
2894 | SmallVector<Expr *, 5> Vars; |
2895 | for (auto *I : D->varlists()) { |
2896 | Expr *Var = SemaRef.SubstExpr(I, TemplateArgs).get(); |
2897 | (0) . __assert_fail ("isa(Var) && \"allocate arg is not a DeclRefExpr\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 2897, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isa<DeclRefExpr>(Var) && "allocate arg is not a DeclRefExpr"); |
2898 | Vars.push_back(Var); |
2899 | } |
2900 | SmallVector<OMPClause *, 4> Clauses; |
2901 | |
2902 | for (OMPClause *C : D->clauselists()) { |
2903 | auto *AC = cast<OMPAllocatorClause>(C); |
2904 | ExprResult NewE = SemaRef.SubstExpr(AC->getAllocator(), TemplateArgs); |
2905 | if (!NewE.isUsable()) |
2906 | continue; |
2907 | OMPClause *IC = SemaRef.ActOnOpenMPAllocatorClause( |
2908 | NewE.get(), AC->getBeginLoc(), AC->getLParenLoc(), AC->getEndLoc()); |
2909 | Clauses.push_back(IC); |
2910 | } |
2911 | |
2912 | Sema::DeclGroupPtrTy Res = SemaRef.ActOnOpenMPAllocateDirective( |
2913 | D->getLocation(), Vars, Clauses, Owner); |
2914 | if (Res.get().isNull()) |
2915 | return nullptr; |
2916 | return Res.get().getSingleDecl(); |
2917 | } |
2918 | |
2919 | Decl *TemplateDeclInstantiator::VisitOMPRequiresDecl(OMPRequiresDecl *D) { |
2920 | llvm_unreachable( |
2921 | "Requires directive cannot be instantiated within a dependent context"); |
2922 | } |
2923 | |
2924 | Decl *TemplateDeclInstantiator::VisitOMPDeclareReductionDecl( |
2925 | OMPDeclareReductionDecl *D) { |
2926 | |
2927 | const bool RequiresInstantiation = |
2928 | D->getType()->isDependentType() || |
2929 | D->getType()->isInstantiationDependentType() || |
2930 | D->getType()->containsUnexpandedParameterPack(); |
2931 | QualType SubstReductionType; |
2932 | if (RequiresInstantiation) { |
2933 | SubstReductionType = SemaRef.ActOnOpenMPDeclareReductionType( |
2934 | D->getLocation(), |
2935 | ParsedType::make(SemaRef.SubstType( |
2936 | D->getType(), TemplateArgs, D->getLocation(), DeclarationName()))); |
2937 | } else { |
2938 | SubstReductionType = D->getType(); |
2939 | } |
2940 | if (SubstReductionType.isNull()) |
2941 | return nullptr; |
2942 | bool IsCorrect = !SubstReductionType.isNull(); |
2943 | |
2944 | std::pair<QualType, SourceLocation> ReductionTypes[] = { |
2945 | std::make_pair(SubstReductionType, D->getLocation())}; |
2946 | auto *PrevDeclInScope = D->getPrevDeclInScope(); |
2947 | if (PrevDeclInScope && !PrevDeclInScope->isInvalidDecl()) { |
2948 | PrevDeclInScope = cast<OMPDeclareReductionDecl>( |
2949 | SemaRef.CurrentInstantiationScope->findInstantiationOf(PrevDeclInScope) |
2950 | ->get<Decl *>()); |
2951 | } |
2952 | auto DRD = SemaRef.ActOnOpenMPDeclareReductionDirectiveStart( |
2953 | , Owner, D->getDeclName(), ReductionTypes, D->getAccess(), |
2954 | PrevDeclInScope); |
2955 | auto *NewDRD = cast<OMPDeclareReductionDecl>(DRD.get().getSingleDecl()); |
2956 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, NewDRD); |
2957 | if (!RequiresInstantiation) { |
2958 | if (Expr *Combiner = D->getCombiner()) { |
2959 | NewDRD->setCombinerData(D->getCombinerIn(), D->getCombinerOut()); |
2960 | NewDRD->setCombiner(Combiner); |
2961 | if (Expr *Init = D->getInitializer()) { |
2962 | NewDRD->setInitializerData(D->getInitOrig(), D->getInitPriv()); |
2963 | NewDRD->setInitializer(Init, D->getInitializerKind()); |
2964 | } |
2965 | } |
2966 | (void)SemaRef.ActOnOpenMPDeclareReductionDirectiveEnd( |
2967 | , DRD, IsCorrect && !D->isInvalidDecl()); |
2968 | return NewDRD; |
2969 | } |
2970 | Expr *SubstCombiner = nullptr; |
2971 | Expr *SubstInitializer = nullptr; |
2972 | |
2973 | if (D->getCombiner()) { |
2974 | SemaRef.ActOnOpenMPDeclareReductionCombinerStart( |
2975 | , NewDRD); |
2976 | SemaRef.CurrentInstantiationScope->InstantiatedLocal( |
2977 | cast<DeclRefExpr>(D->getCombinerIn())->getDecl(), |
2978 | cast<DeclRefExpr>(NewDRD->getCombinerIn())->getDecl()); |
2979 | SemaRef.CurrentInstantiationScope->InstantiatedLocal( |
2980 | cast<DeclRefExpr>(D->getCombinerOut())->getDecl(), |
2981 | cast<DeclRefExpr>(NewDRD->getCombinerOut())->getDecl()); |
2982 | auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(Owner); |
2983 | Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, Qualifiers(), |
2984 | ThisContext); |
2985 | SubstCombiner = SemaRef.SubstExpr(D->getCombiner(), TemplateArgs).get(); |
2986 | SemaRef.ActOnOpenMPDeclareReductionCombinerEnd(NewDRD, SubstCombiner); |
2987 | |
2988 | if (D->getInitializer()) { |
2989 | VarDecl *OmpPrivParm = |
2990 | SemaRef.ActOnOpenMPDeclareReductionInitializerStart( |
2991 | , NewDRD); |
2992 | SemaRef.CurrentInstantiationScope->InstantiatedLocal( |
2993 | cast<DeclRefExpr>(D->getInitOrig())->getDecl(), |
2994 | cast<DeclRefExpr>(NewDRD->getInitOrig())->getDecl()); |
2995 | SemaRef.CurrentInstantiationScope->InstantiatedLocal( |
2996 | cast<DeclRefExpr>(D->getInitPriv())->getDecl(), |
2997 | cast<DeclRefExpr>(NewDRD->getInitPriv())->getDecl()); |
2998 | if (D->getInitializerKind() == OMPDeclareReductionDecl::CallInit) { |
2999 | SubstInitializer = |
3000 | SemaRef.SubstExpr(D->getInitializer(), TemplateArgs).get(); |
3001 | } else { |
3002 | IsCorrect = IsCorrect && OmpPrivParm->hasInit(); |
3003 | } |
3004 | SemaRef.ActOnOpenMPDeclareReductionInitializerEnd( |
3005 | NewDRD, SubstInitializer, OmpPrivParm); |
3006 | } |
3007 | IsCorrect = |
3008 | IsCorrect && SubstCombiner && |
3009 | (!D->getInitializer() || |
3010 | (D->getInitializerKind() == OMPDeclareReductionDecl::CallInit && |
3011 | SubstInitializer) || |
3012 | (D->getInitializerKind() != OMPDeclareReductionDecl::CallInit && |
3013 | !SubstInitializer && !SubstInitializer)); |
3014 | } else { |
3015 | IsCorrect = false; |
3016 | } |
3017 | |
3018 | (void)SemaRef.ActOnOpenMPDeclareReductionDirectiveEnd(, DRD, |
3019 | IsCorrect); |
3020 | |
3021 | return NewDRD; |
3022 | } |
3023 | |
3024 | Decl * |
3025 | TemplateDeclInstantiator::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) { |
3026 | |
3027 | const bool RequiresInstantiation = |
3028 | D->getType()->isDependentType() || |
3029 | D->getType()->isInstantiationDependentType() || |
3030 | D->getType()->containsUnexpandedParameterPack(); |
3031 | QualType SubstMapperTy; |
3032 | DeclarationName VN = D->getVarName(); |
3033 | if (RequiresInstantiation) { |
3034 | SubstMapperTy = SemaRef.ActOnOpenMPDeclareMapperType( |
3035 | D->getLocation(), |
3036 | ParsedType::make(SemaRef.SubstType(D->getType(), TemplateArgs, |
3037 | D->getLocation(), VN))); |
3038 | } else { |
3039 | SubstMapperTy = D->getType(); |
3040 | } |
3041 | if (SubstMapperTy.isNull()) |
3042 | return nullptr; |
3043 | |
3044 | auto *PrevDeclInScope = D->getPrevDeclInScope(); |
3045 | if (PrevDeclInScope && !PrevDeclInScope->isInvalidDecl()) { |
3046 | PrevDeclInScope = cast<OMPDeclareMapperDecl>( |
3047 | SemaRef.CurrentInstantiationScope->findInstantiationOf(PrevDeclInScope) |
3048 | ->get<Decl *>()); |
3049 | } |
3050 | OMPDeclareMapperDecl *NewDMD = SemaRef.ActOnOpenMPDeclareMapperDirectiveStart( |
3051 | , Owner, D->getDeclName(), SubstMapperTy, D->getLocation(), |
3052 | VN, D->getAccess(), PrevDeclInScope); |
3053 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, NewDMD); |
3054 | SmallVector<OMPClause *, 6> Clauses; |
3055 | bool IsCorrect = true; |
3056 | if (!RequiresInstantiation) { |
3057 | |
3058 | NewDMD->setMapperVarRef(D->getMapperVarRef()); |
3059 | |
3060 | for (OMPClause *C : D->clauselists()) |
3061 | Clauses.push_back(C); |
3062 | } else { |
3063 | |
3064 | DeclarationNameInfo DirName; |
3065 | SemaRef.StartOpenMPDSABlock(OMPD_declare_mapper, DirName, , |
3066 | (*D->clauselist_begin())->getBeginLoc()); |
3067 | SemaRef.ActOnOpenMPDeclareMapperDirectiveVarDecl( |
3068 | NewDMD, , SubstMapperTy, D->getLocation(), VN); |
3069 | SemaRef.CurrentInstantiationScope->InstantiatedLocal( |
3070 | cast<DeclRefExpr>(D->getMapperVarRef())->getDecl(), |
3071 | cast<DeclRefExpr>(NewDMD->getMapperVarRef())->getDecl()); |
3072 | auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(Owner); |
3073 | Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, Qualifiers(), |
3074 | ThisContext); |
3075 | |
3076 | for (OMPClause *C : D->clauselists()) { |
3077 | auto *OldC = cast<OMPMapClause>(C); |
3078 | SmallVector<Expr *, 4> NewVars; |
3079 | for (Expr *OE : OldC->varlists()) { |
3080 | Expr *NE = SemaRef.SubstExpr(OE, TemplateArgs).get(); |
3081 | if (!NE) { |
3082 | IsCorrect = false; |
3083 | break; |
3084 | } |
3085 | NewVars.push_back(NE); |
3086 | } |
3087 | if (!IsCorrect) |
3088 | break; |
3089 | NestedNameSpecifierLoc NewQualifierLoc = |
3090 | SemaRef.SubstNestedNameSpecifierLoc(OldC->getMapperQualifierLoc(), |
3091 | TemplateArgs); |
3092 | CXXScopeSpec SS; |
3093 | SS.Adopt(NewQualifierLoc); |
3094 | DeclarationNameInfo NewNameInfo = SemaRef.SubstDeclarationNameInfo( |
3095 | OldC->getMapperIdInfo(), TemplateArgs); |
3096 | OMPVarListLocTy Locs(OldC->getBeginLoc(), OldC->getLParenLoc(), |
3097 | OldC->getEndLoc()); |
3098 | OMPClause *NewC = SemaRef.ActOnOpenMPMapClause( |
3099 | OldC->getMapTypeModifiers(), OldC->getMapTypeModifiersLoc(), SS, |
3100 | NewNameInfo, OldC->getMapType(), OldC->isImplicitMapType(), |
3101 | OldC->getMapLoc(), OldC->getColonLoc(), NewVars, Locs); |
3102 | Clauses.push_back(NewC); |
3103 | } |
3104 | SemaRef.EndOpenMPDSABlock(nullptr); |
3105 | } |
3106 | (void)SemaRef.ActOnOpenMPDeclareMapperDirectiveEnd(NewDMD, , |
3107 | Clauses); |
3108 | if (!IsCorrect) |
3109 | return nullptr; |
3110 | return NewDMD; |
3111 | } |
3112 | |
3113 | Decl *TemplateDeclInstantiator::VisitOMPCapturedExprDecl( |
3114 | OMPCapturedExprDecl * ) { |
3115 | llvm_unreachable("Should not be met in templates"); |
3116 | } |
3117 | |
3118 | Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D) { |
3119 | return VisitFunctionDecl(D, nullptr); |
3120 | } |
3121 | |
3122 | Decl * |
3123 | TemplateDeclInstantiator::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) { |
3124 | Decl *Inst = VisitFunctionDecl(D, nullptr); |
3125 | if (Inst && !D->getDescribedFunctionTemplate()) |
3126 | Owner->addDecl(Inst); |
3127 | return Inst; |
3128 | } |
3129 | |
3130 | Decl *TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D) { |
3131 | return VisitCXXMethodDecl(D, nullptr); |
3132 | } |
3133 | |
3134 | Decl *TemplateDeclInstantiator::VisitRecordDecl(RecordDecl *D) { |
3135 | llvm_unreachable("There are only CXXRecordDecls in C++"); |
3136 | } |
3137 | |
3138 | Decl * |
3139 | TemplateDeclInstantiator::VisitClassTemplateSpecializationDecl( |
3140 | ClassTemplateSpecializationDecl *D) { |
3141 | |
3142 | |
3143 | ClassTemplateDecl *ClassTemplate = D->getSpecializedTemplate(); |
3144 | (0) . __assert_fail ("ClassTemplate->getDeclContext()->isRecord() && D->getTemplateSpecializationKind() == TSK_ExplicitSpecialization && \"can only instantiate an explicit specialization \" \"for a member class template\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 3147, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(ClassTemplate->getDeclContext()->isRecord() && |
3145 | (0) . __assert_fail ("ClassTemplate->getDeclContext()->isRecord() && D->getTemplateSpecializationKind() == TSK_ExplicitSpecialization && \"can only instantiate an explicit specialization \" \"for a member class template\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 3147, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> D->getTemplateSpecializationKind() == TSK_ExplicitSpecialization && |
3146 | (0) . __assert_fail ("ClassTemplate->getDeclContext()->isRecord() && D->getTemplateSpecializationKind() == TSK_ExplicitSpecialization && \"can only instantiate an explicit specialization \" \"for a member class template\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 3147, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "can only instantiate an explicit specialization " |
3147 | (0) . __assert_fail ("ClassTemplate->getDeclContext()->isRecord() && D->getTemplateSpecializationKind() == TSK_ExplicitSpecialization && \"can only instantiate an explicit specialization \" \"for a member class template\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 3147, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "for a member class template"); |
3148 | |
3149 | |
3150 | |
3151 | DeclContext::lookup_result Found |
3152 | = Owner->lookup(ClassTemplate->getDeclName()); |
3153 | if (Found.empty()) |
3154 | return nullptr; |
3155 | ClassTemplateDecl *InstClassTemplate |
3156 | = dyn_cast<ClassTemplateDecl>(Found.front()); |
3157 | if (!InstClassTemplate) |
3158 | return nullptr; |
3159 | |
3160 | |
3161 | |
3162 | TemplateSpecializationTypeLoc Loc = D->getTypeAsWritten()->getTypeLoc(). |
3163 | castAs<TemplateSpecializationTypeLoc>(); |
3164 | TemplateArgumentListInfo InstTemplateArgs(Loc.getLAngleLoc(), |
3165 | Loc.getRAngleLoc()); |
3166 | SmallVector<TemplateArgumentLoc, 4> ArgLocs; |
3167 | for (unsigned I = 0; I != Loc.getNumArgs(); ++I) |
3168 | ArgLocs.push_back(Loc.getArgLoc(I)); |
3169 | if (SemaRef.Subst(ArgLocs.data(), ArgLocs.size(), |
3170 | InstTemplateArgs, TemplateArgs)) |
3171 | return nullptr; |
3172 | |
3173 | |
3174 | |
3175 | SmallVector<TemplateArgument, 4> Converted; |
3176 | if (SemaRef.CheckTemplateArgumentList(InstClassTemplate, |
3177 | D->getLocation(), |
3178 | InstTemplateArgs, |
3179 | false, |
3180 | Converted)) |
3181 | return nullptr; |
3182 | |
3183 | |
3184 | |
3185 | void *InsertPos = nullptr; |
3186 | ClassTemplateSpecializationDecl *PrevDecl = |
3187 | InstClassTemplate->findSpecialization(Converted, InsertPos); |
3188 | |
3189 | |
3190 | |
3191 | bool Ignored; |
3192 | if (PrevDecl && |
3193 | SemaRef.CheckSpecializationInstantiationRedecl(D->getLocation(), |
3194 | D->getSpecializationKind(), |
3195 | PrevDecl, |
3196 | PrevDecl->getSpecializationKind(), |
3197 | PrevDecl->getPointOfInstantiation(), |
3198 | Ignored)) |
3199 | return nullptr; |
3200 | |
3201 | |
3202 | |
3203 | |
3204 | |
3205 | |
3206 | |
3207 | |
3208 | |
3209 | |
3210 | |
3211 | |
3212 | |
3213 | if (PrevDecl && PrevDecl->getDefinition() && |
3214 | D->isThisDeclarationADefinition()) { |
3215 | SemaRef.Diag(D->getLocation(), diag::err_redefinition) << PrevDecl; |
3216 | SemaRef.Diag(PrevDecl->getDefinition()->getLocation(), |
3217 | diag::note_previous_definition); |
3218 | return nullptr; |
3219 | } |
3220 | |
3221 | |
3222 | ClassTemplateSpecializationDecl *InstD = |
3223 | ClassTemplateSpecializationDecl::Create( |
3224 | SemaRef.Context, D->getTagKind(), Owner, D->getBeginLoc(), |
3225 | D->getLocation(), InstClassTemplate, Converted, PrevDecl); |
3226 | |
3227 | |
3228 | |
3229 | if (!PrevDecl) |
3230 | InstClassTemplate->AddSpecialization(InstD, InsertPos); |
3231 | |
3232 | |
3233 | if (SubstQualifier(D, InstD)) |
3234 | return nullptr; |
3235 | |
3236 | |
3237 | |
3238 | QualType CanonType = SemaRef.Context.getTemplateSpecializationType( |
3239 | TemplateName(InstClassTemplate), Converted, |
3240 | SemaRef.Context.getRecordType(InstD)); |
3241 | |
3242 | |
3243 | |
3244 | |
3245 | |
3246 | |
3247 | |
3248 | |
3249 | TypeSourceInfo *WrittenTy = SemaRef.Context.getTemplateSpecializationTypeInfo( |
3250 | TemplateName(InstClassTemplate), D->getLocation(), InstTemplateArgs, |
3251 | CanonType); |
3252 | |
3253 | InstD->setAccess(D->getAccess()); |
3254 | InstD->setInstantiationOfMemberClass(D, TSK_ImplicitInstantiation); |
3255 | InstD->setSpecializationKind(D->getSpecializationKind()); |
3256 | InstD->setTypeAsWritten(WrittenTy); |
3257 | InstD->setExternLoc(D->getExternLoc()); |
3258 | InstD->setTemplateKeywordLoc(D->getTemplateKeywordLoc()); |
3259 | |
3260 | Owner->addDecl(InstD); |
3261 | |
3262 | |
3263 | |
3264 | |
3265 | if (D->isThisDeclarationADefinition() && |
3266 | SemaRef.InstantiateClass(D->getLocation(), InstD, D, TemplateArgs, |
3267 | TSK_ImplicitInstantiation, |
3268 | )) |
3269 | return nullptr; |
3270 | |
3271 | return InstD; |
3272 | } |
3273 | |
3274 | Decl *TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl( |
3275 | VarTemplateSpecializationDecl *D) { |
3276 | |
3277 | TemplateArgumentListInfo VarTemplateArgsInfo; |
3278 | VarTemplateDecl *VarTemplate = D->getSpecializedTemplate(); |
3279 | (0) . __assert_fail ("VarTemplate && \"A template specialization without specialized template?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 3280, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(VarTemplate && |
3280 | (0) . __assert_fail ("VarTemplate && \"A template specialization without specialized template?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 3280, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "A template specialization without specialized template?"); |
3281 | |
3282 | |
3283 | const TemplateArgumentListInfo &TemplateArgsInfo = D->getTemplateArgsInfo(); |
3284 | VarTemplateArgsInfo.setLAngleLoc(TemplateArgsInfo.getLAngleLoc()); |
3285 | VarTemplateArgsInfo.setRAngleLoc(TemplateArgsInfo.getRAngleLoc()); |
3286 | |
3287 | if (SemaRef.Subst(TemplateArgsInfo.getArgumentArray(), |
3288 | TemplateArgsInfo.size(), VarTemplateArgsInfo, TemplateArgs)) |
3289 | return nullptr; |
3290 | |
3291 | |
3292 | SmallVector<TemplateArgument, 4> Converted; |
3293 | if (SemaRef.CheckTemplateArgumentList( |
3294 | VarTemplate, VarTemplate->getBeginLoc(), |
3295 | const_cast<TemplateArgumentListInfo &>(VarTemplateArgsInfo), false, |
3296 | Converted)) |
3297 | return nullptr; |
3298 | |
3299 | |
3300 | |
3301 | void *InsertPos = nullptr; |
3302 | if (VarTemplateSpecializationDecl *VarSpec = VarTemplate->findSpecialization( |
3303 | Converted, InsertPos)) |
3304 | |
3305 | return VarSpec; |
3306 | |
3307 | return VisitVarTemplateSpecializationDecl(VarTemplate, D, InsertPos, |
3308 | VarTemplateArgsInfo, Converted); |
3309 | } |
3310 | |
3311 | Decl *TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl( |
3312 | VarTemplateDecl *VarTemplate, VarDecl *D, void *InsertPos, |
3313 | const TemplateArgumentListInfo &TemplateArgsInfo, |
3314 | ArrayRef<TemplateArgument> Converted) { |
3315 | |
3316 | |
3317 | TypeSourceInfo *DI = |
3318 | SemaRef.SubstType(D->getTypeSourceInfo(), TemplateArgs, |
3319 | D->getTypeSpecStartLoc(), D->getDeclName()); |
3320 | if (!DI) |
3321 | return nullptr; |
3322 | |
3323 | if (DI->getType()->isFunctionType()) { |
3324 | SemaRef.Diag(D->getLocation(), diag::err_variable_instantiates_to_function) |
3325 | << D->isStaticDataMember() << DI->getType(); |
3326 | return nullptr; |
3327 | } |
3328 | |
3329 | |
3330 | VarTemplateSpecializationDecl *Var = VarTemplateSpecializationDecl::Create( |
3331 | SemaRef.Context, Owner, D->getInnerLocStart(), D->getLocation(), |
3332 | VarTemplate, DI->getType(), DI, D->getStorageClass(), Converted); |
3333 | Var->setTemplateArgsInfo(TemplateArgsInfo); |
3334 | if (InsertPos) |
3335 | VarTemplate->AddSpecialization(Var, InsertPos); |
3336 | |
3337 | |
3338 | if (SubstQualifier(D, Var)) |
3339 | return nullptr; |
3340 | |
3341 | SemaRef.BuildVariableInstantiation(Var, D, TemplateArgs, LateAttrs, |
3342 | Owner, StartingScope); |
3343 | |
3344 | return Var; |
3345 | } |
3346 | |
3347 | Decl *TemplateDeclInstantiator::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) { |
3348 | llvm_unreachable("@defs is not supported in Objective-C++"); |
3349 | } |
3350 | |
3351 | Decl *TemplateDeclInstantiator::VisitFriendTemplateDecl(FriendTemplateDecl *D) { |
3352 | |
3353 | unsigned DiagID = SemaRef.getDiagnostics().getCustomDiagID( |
3354 | DiagnosticsEngine::Error, |
3355 | "cannot instantiate %0 yet"); |
3356 | SemaRef.Diag(D->getLocation(), DiagID) |
3357 | << D->getDeclKindName(); |
3358 | |
3359 | return nullptr; |
3360 | } |
3361 | |
3362 | Decl *TemplateDeclInstantiator::VisitDecl(Decl *D) { |
3363 | llvm_unreachable("Unexpected decl"); |
3364 | } |
3365 | |
3366 | Decl *Sema::SubstDecl(Decl *D, DeclContext *Owner, |
3367 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
3368 | TemplateDeclInstantiator Instantiator(*this, Owner, TemplateArgs); |
3369 | if (D->isInvalidDecl()) |
3370 | return nullptr; |
3371 | |
3372 | return Instantiator.Visit(D); |
3373 | } |
3374 | |
3375 | |
3376 | |
3377 | |
3378 | |
3379 | |
3380 | |
3381 | TemplateParameterList * |
3382 | TemplateDeclInstantiator::SubstTemplateParams(TemplateParameterList *L) { |
3383 | |
3384 | bool Invalid = false; |
3385 | |
3386 | unsigned N = L->size(); |
3387 | typedef SmallVector<NamedDecl *, 8> ParamVector; |
3388 | ParamVector Params; |
3389 | Params.reserve(N); |
3390 | for (auto &P : *L) { |
3391 | NamedDecl *D = cast_or_null<NamedDecl>(Visit(P)); |
3392 | Params.push_back(D); |
3393 | Invalid = Invalid || !D || D->isInvalidDecl(); |
3394 | } |
3395 | |
3396 | |
3397 | if (Invalid) |
3398 | return nullptr; |
3399 | |
3400 | |
3401 | Expr *const UninstantiatedRequiresClause = L->getRequiresClause(); |
3402 | |
3403 | TemplateParameterList *InstL |
3404 | = TemplateParameterList::Create(SemaRef.Context, L->getTemplateLoc(), |
3405 | L->getLAngleLoc(), Params, |
3406 | L->getRAngleLoc(), |
3407 | UninstantiatedRequiresClause); |
3408 | return InstL; |
3409 | } |
3410 | |
3411 | TemplateParameterList * |
3412 | Sema::SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner, |
3413 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
3414 | TemplateDeclInstantiator Instantiator(*this, Owner, TemplateArgs); |
3415 | return Instantiator.SubstTemplateParams(Params); |
3416 | } |
3417 | |
3418 | |
3419 | |
3420 | |
3421 | |
3422 | |
3423 | |
3424 | |
3425 | |
3426 | |
3427 | |
3428 | |
3429 | ClassTemplatePartialSpecializationDecl * |
3430 | TemplateDeclInstantiator::InstantiateClassTemplatePartialSpecialization( |
3431 | ClassTemplateDecl *ClassTemplate, |
3432 | ClassTemplatePartialSpecializationDecl *PartialSpec) { |
3433 | |
3434 | |
3435 | |
3436 | LocalInstantiationScope Scope(SemaRef); |
3437 | |
3438 | |
3439 | |
3440 | TemplateParameterList *TempParams = PartialSpec->getTemplateParameters(); |
3441 | TemplateParameterList *InstParams = SubstTemplateParams(TempParams); |
3442 | if (!InstParams) |
3443 | return nullptr; |
3444 | |
3445 | |
3446 | |
3447 | const ASTTemplateArgumentListInfo *TemplArgInfo |
3448 | = PartialSpec->getTemplateArgsAsWritten(); |
3449 | TemplateArgumentListInfo InstTemplateArgs(TemplArgInfo->LAngleLoc, |
3450 | TemplArgInfo->RAngleLoc); |
3451 | if (SemaRef.Subst(TemplArgInfo->getTemplateArgs(), |
3452 | TemplArgInfo->NumTemplateArgs, |
3453 | InstTemplateArgs, TemplateArgs)) |
3454 | return nullptr; |
3455 | |
3456 | |
3457 | |
3458 | SmallVector<TemplateArgument, 4> Converted; |
3459 | if (SemaRef.CheckTemplateArgumentList(ClassTemplate, |
3460 | PartialSpec->getLocation(), |
3461 | InstTemplateArgs, |
3462 | false, |
3463 | Converted)) |
3464 | return nullptr; |
3465 | |
3466 | |
3467 | if (SemaRef.CheckTemplatePartialSpecializationArgs( |
3468 | PartialSpec->getLocation(), ClassTemplate, InstTemplateArgs.size(), |
3469 | Converted)) |
3470 | return nullptr; |
3471 | |
3472 | |
3473 | |
3474 | void *InsertPos = nullptr; |
3475 | ClassTemplateSpecializationDecl *PrevDecl |
3476 | = ClassTemplate->findPartialSpecialization(Converted, InsertPos); |
3477 | |
3478 | |
3479 | |
3480 | QualType CanonType |
3481 | = SemaRef.Context.getTemplateSpecializationType(TemplateName(ClassTemplate), |
3482 | Converted); |
3483 | |
3484 | |
3485 | |
3486 | |
3487 | |
3488 | |
3489 | |
3490 | |
3491 | TypeSourceInfo *WrittenTy |
3492 | = SemaRef.Context.getTemplateSpecializationTypeInfo( |
3493 | TemplateName(ClassTemplate), |
3494 | PartialSpec->getLocation(), |
3495 | InstTemplateArgs, |
3496 | CanonType); |
3497 | |
3498 | if (PrevDecl) { |
3499 | |
3500 | |
3501 | |
3502 | |
3503 | |
3504 | |
3505 | |
3506 | |
3507 | |
3508 | |
3509 | |
3510 | |
3511 | |
3512 | |
3513 | |
3514 | SemaRef.Diag(PartialSpec->getLocation(), diag::err_partial_spec_redeclared) |
3515 | << WrittenTy->getType(); |
3516 | SemaRef.Diag(PrevDecl->getLocation(), diag::note_prev_partial_spec_here) |
3517 | << SemaRef.Context.getTypeDeclType(PrevDecl); |
3518 | return nullptr; |
3519 | } |
3520 | |
3521 | |
3522 | |
3523 | ClassTemplatePartialSpecializationDecl *InstPartialSpec = |
3524 | ClassTemplatePartialSpecializationDecl::Create( |
3525 | SemaRef.Context, PartialSpec->getTagKind(), Owner, |
3526 | PartialSpec->getBeginLoc(), PartialSpec->getLocation(), InstParams, |
3527 | ClassTemplate, Converted, InstTemplateArgs, CanonType, nullptr); |
3528 | |
3529 | if (SubstQualifier(PartialSpec, InstPartialSpec)) |
3530 | return nullptr; |
3531 | |
3532 | InstPartialSpec->setInstantiatedFromMember(PartialSpec); |
3533 | InstPartialSpec->setTypeAsWritten(WrittenTy); |
3534 | |
3535 | |
3536 | SemaRef.CheckTemplatePartialSpecialization(InstPartialSpec); |
3537 | |
3538 | |
3539 | |
3540 | ClassTemplate->AddPartialSpecialization(InstPartialSpec, |
3541 | ); |
3542 | return InstPartialSpec; |
3543 | } |
3544 | |
3545 | |
3546 | |
3547 | |
3548 | |
3549 | |
3550 | |
3551 | |
3552 | |
3553 | |
3554 | |
3555 | |
3556 | VarTemplatePartialSpecializationDecl * |
3557 | TemplateDeclInstantiator::InstantiateVarTemplatePartialSpecialization( |
3558 | VarTemplateDecl *VarTemplate, |
3559 | VarTemplatePartialSpecializationDecl *PartialSpec) { |
3560 | |
3561 | |
3562 | |
3563 | LocalInstantiationScope Scope(SemaRef); |
3564 | |
3565 | |
3566 | |
3567 | TemplateParameterList *TempParams = PartialSpec->getTemplateParameters(); |
3568 | TemplateParameterList *InstParams = SubstTemplateParams(TempParams); |
3569 | if (!InstParams) |
3570 | return nullptr; |
3571 | |
3572 | |
3573 | |
3574 | const ASTTemplateArgumentListInfo *TemplArgInfo |
3575 | = PartialSpec->getTemplateArgsAsWritten(); |
3576 | TemplateArgumentListInfo InstTemplateArgs(TemplArgInfo->LAngleLoc, |
3577 | TemplArgInfo->RAngleLoc); |
3578 | if (SemaRef.Subst(TemplArgInfo->getTemplateArgs(), |
3579 | TemplArgInfo->NumTemplateArgs, |
3580 | InstTemplateArgs, TemplateArgs)) |
3581 | return nullptr; |
3582 | |
3583 | |
3584 | |
3585 | SmallVector<TemplateArgument, 4> Converted; |
3586 | if (SemaRef.CheckTemplateArgumentList(VarTemplate, PartialSpec->getLocation(), |
3587 | InstTemplateArgs, false, Converted)) |
3588 | return nullptr; |
3589 | |
3590 | |
3591 | if (SemaRef.CheckTemplatePartialSpecializationArgs( |
3592 | PartialSpec->getLocation(), VarTemplate, InstTemplateArgs.size(), |
3593 | Converted)) |
3594 | return nullptr; |
3595 | |
3596 | |
3597 | |
3598 | void *InsertPos = nullptr; |
3599 | VarTemplateSpecializationDecl *PrevDecl = |
3600 | VarTemplate->findPartialSpecialization(Converted, InsertPos); |
3601 | |
3602 | |
3603 | |
3604 | QualType CanonType = SemaRef.Context.getTemplateSpecializationType( |
3605 | TemplateName(VarTemplate), Converted); |
3606 | |
3607 | |
3608 | |
3609 | |
3610 | |
3611 | |
3612 | |
3613 | |
3614 | TypeSourceInfo *WrittenTy = SemaRef.Context.getTemplateSpecializationTypeInfo( |
3615 | TemplateName(VarTemplate), PartialSpec->getLocation(), InstTemplateArgs, |
3616 | CanonType); |
3617 | |
3618 | if (PrevDecl) { |
3619 | |
3620 | |
3621 | |
3622 | |
3623 | |
3624 | |
3625 | |
3626 | |
3627 | |
3628 | |
3629 | |
3630 | |
3631 | |
3632 | |
3633 | |
3634 | SemaRef.Diag(PartialSpec->getLocation(), |
3635 | diag::err_var_partial_spec_redeclared) |
3636 | << WrittenTy->getType(); |
3637 | SemaRef.Diag(PrevDecl->getLocation(), |
3638 | diag::note_var_prev_partial_spec_here); |
3639 | return nullptr; |
3640 | } |
3641 | |
3642 | |
3643 | TypeSourceInfo *DI = SemaRef.SubstType( |
3644 | PartialSpec->getTypeSourceInfo(), TemplateArgs, |
3645 | PartialSpec->getTypeSpecStartLoc(), PartialSpec->getDeclName()); |
3646 | if (!DI) |
3647 | return nullptr; |
3648 | |
3649 | if (DI->getType()->isFunctionType()) { |
3650 | SemaRef.Diag(PartialSpec->getLocation(), |
3651 | diag::err_variable_instantiates_to_function) |
3652 | << PartialSpec->isStaticDataMember() << DI->getType(); |
3653 | return nullptr; |
3654 | } |
3655 | |
3656 | |
3657 | VarTemplatePartialSpecializationDecl *InstPartialSpec = |
3658 | VarTemplatePartialSpecializationDecl::Create( |
3659 | SemaRef.Context, Owner, PartialSpec->getInnerLocStart(), |
3660 | PartialSpec->getLocation(), InstParams, VarTemplate, DI->getType(), |
3661 | DI, PartialSpec->getStorageClass(), Converted, InstTemplateArgs); |
3662 | |
3663 | |
3664 | if (SubstQualifier(PartialSpec, InstPartialSpec)) |
3665 | return nullptr; |
3666 | |
3667 | InstPartialSpec->setInstantiatedFromMember(PartialSpec); |
3668 | InstPartialSpec->setTypeAsWritten(WrittenTy); |
3669 | |
3670 | |
3671 | SemaRef.CheckTemplatePartialSpecialization(InstPartialSpec); |
3672 | |
3673 | |
3674 | |
3675 | VarTemplate->AddPartialSpecialization(InstPartialSpec, ); |
3676 | |
3677 | SemaRef.BuildVariableInstantiation(InstPartialSpec, PartialSpec, TemplateArgs, |
3678 | LateAttrs, Owner, StartingScope); |
3679 | |
3680 | return InstPartialSpec; |
3681 | } |
3682 | |
3683 | TypeSourceInfo* |
3684 | TemplateDeclInstantiator::SubstFunctionType(FunctionDecl *D, |
3685 | SmallVectorImpl<ParmVarDecl *> &Params) { |
3686 | TypeSourceInfo *OldTInfo = D->getTypeSourceInfo(); |
3687 | (0) . __assert_fail ("OldTInfo && \"substituting function without type source info\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 3687, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(OldTInfo && "substituting function without type source info"); |
3688 | (0) . __assert_fail ("Params.empty() && \"parameter vector is non-empty at start\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 3688, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Params.empty() && "parameter vector is non-empty at start"); |
3689 | |
3690 | CXXRecordDecl *ThisContext = nullptr; |
3691 | Qualifiers ThisTypeQuals; |
3692 | if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) { |
3693 | ThisContext = cast<CXXRecordDecl>(Owner); |
3694 | ThisTypeQuals = Method->getMethodQualifiers(); |
3695 | } |
3696 | |
3697 | TypeSourceInfo *NewTInfo |
3698 | = SemaRef.SubstFunctionDeclType(OldTInfo, TemplateArgs, |
3699 | D->getTypeSpecStartLoc(), |
3700 | D->getDeclName(), |
3701 | ThisContext, ThisTypeQuals); |
3702 | if (!NewTInfo) |
3703 | return nullptr; |
3704 | |
3705 | TypeLoc OldTL = OldTInfo->getTypeLoc().IgnoreParens(); |
3706 | if (FunctionProtoTypeLoc OldProtoLoc = OldTL.getAs<FunctionProtoTypeLoc>()) { |
3707 | if (NewTInfo != OldTInfo) { |
3708 | |
3709 | TypeLoc NewTL = NewTInfo->getTypeLoc().IgnoreParens(); |
3710 | FunctionProtoTypeLoc NewProtoLoc = NewTL.castAs<FunctionProtoTypeLoc>(); |
3711 | unsigned NewIdx = 0; |
3712 | for (unsigned OldIdx = 0, NumOldParams = OldProtoLoc.getNumParams(); |
3713 | OldIdx != NumOldParams; ++OldIdx) { |
3714 | ParmVarDecl *OldParam = OldProtoLoc.getParam(OldIdx); |
3715 | LocalInstantiationScope *Scope = SemaRef.CurrentInstantiationScope; |
3716 | |
3717 | Optional<unsigned> NumArgumentsInExpansion; |
3718 | if (OldParam->isParameterPack()) |
3719 | NumArgumentsInExpansion = |
3720 | SemaRef.getNumArgumentsInExpansion(OldParam->getType(), |
3721 | TemplateArgs); |
3722 | if (!NumArgumentsInExpansion) { |
3723 | |
3724 | |
3725 | ParmVarDecl *NewParam = NewProtoLoc.getParam(NewIdx++); |
3726 | Params.push_back(NewParam); |
3727 | Scope->InstantiatedLocal(OldParam, NewParam); |
3728 | } else { |
3729 | |
3730 | Scope->MakeInstantiatedLocalArgPack(OldParam); |
3731 | for (unsigned I = 0; I != *NumArgumentsInExpansion; ++I) { |
3732 | ParmVarDecl *NewParam = NewProtoLoc.getParam(NewIdx++); |
3733 | Params.push_back(NewParam); |
3734 | Scope->InstantiatedLocalPackArg(OldParam, NewParam); |
3735 | } |
3736 | } |
3737 | } |
3738 | } else { |
3739 | |
3740 | |
3741 | |
3742 | const FunctionProtoType *OldProto = |
3743 | cast<FunctionProtoType>(OldProtoLoc.getType()); |
3744 | for (unsigned i = 0, i_end = OldProtoLoc.getNumParams(); i != i_end; |
3745 | ++i) { |
3746 | ParmVarDecl *OldParam = OldProtoLoc.getParam(i); |
3747 | if (!OldParam) { |
3748 | Params.push_back(SemaRef.BuildParmVarDeclForTypedef( |
3749 | D, D->getLocation(), OldProto->getParamType(i))); |
3750 | continue; |
3751 | } |
3752 | |
3753 | ParmVarDecl *Parm = |
3754 | cast_or_null<ParmVarDecl>(VisitParmVarDecl(OldParam)); |
3755 | if (!Parm) |
3756 | return nullptr; |
3757 | Params.push_back(Parm); |
3758 | } |
3759 | } |
3760 | } else { |
3761 | |
3762 | |
3763 | |
3764 | |
3765 | |
3766 | |
3767 | |
3768 | |
3769 | |
3770 | |
3771 | SmallVector<QualType, 4> ParamTypes; |
3772 | Sema::ExtParameterInfoBuilder ExtParamInfos; |
3773 | if (SemaRef.SubstParmTypes(D->getLocation(), D->parameters(), nullptr, |
3774 | TemplateArgs, ParamTypes, &Params, |
3775 | ExtParamInfos)) |
3776 | return nullptr; |
3777 | } |
3778 | |
3779 | return NewTInfo; |
3780 | } |
3781 | |
3782 | |
3783 | |
3784 | |
3785 | static bool addInstantiatedParametersToScope(Sema &S, FunctionDecl *Function, |
3786 | const FunctionDecl *PatternDecl, |
3787 | LocalInstantiationScope &Scope, |
3788 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
3789 | unsigned FParamIdx = 0; |
3790 | for (unsigned I = 0, N = PatternDecl->getNumParams(); I != N; ++I) { |
3791 | const ParmVarDecl *PatternParam = PatternDecl->getParamDecl(I); |
3792 | if (!PatternParam->isParameterPack()) { |
3793 | |
3794 | getNumParams()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 3794, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(FParamIdx < Function->getNumParams()); |
3795 | ParmVarDecl *FunctionParam = Function->getParamDecl(FParamIdx); |
3796 | FunctionParam->setDeclName(PatternParam->getDeclName()); |
3797 | |
3798 | |
3799 | |
3800 | |
3801 | |
3802 | |
3803 | if (!PatternDecl->getType()->isDependentType()) { |
3804 | QualType T = S.SubstType(PatternParam->getType(), TemplateArgs, |
3805 | FunctionParam->getLocation(), |
3806 | FunctionParam->getDeclName()); |
3807 | if (T.isNull()) |
3808 | return true; |
3809 | FunctionParam->setType(T); |
3810 | } |
3811 | |
3812 | Scope.InstantiatedLocal(PatternParam, FunctionParam); |
3813 | ++FParamIdx; |
3814 | continue; |
3815 | } |
3816 | |
3817 | |
3818 | Scope.MakeInstantiatedLocalArgPack(PatternParam); |
3819 | Optional<unsigned> NumArgumentsInExpansion |
3820 | = S.getNumArgumentsInExpansion(PatternParam->getType(), TemplateArgs); |
3821 | if (NumArgumentsInExpansion) { |
3822 | QualType PatternType = |
3823 | PatternParam->getType()->castAs<PackExpansionType>()->getPattern(); |
3824 | for (unsigned Arg = 0; Arg < *NumArgumentsInExpansion; ++Arg) { |
3825 | ParmVarDecl *FunctionParam = Function->getParamDecl(FParamIdx); |
3826 | FunctionParam->setDeclName(PatternParam->getDeclName()); |
3827 | if (!PatternDecl->getType()->isDependentType()) { |
3828 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(S, Arg); |
3829 | QualType T = S.SubstType(PatternType, TemplateArgs, |
3830 | FunctionParam->getLocation(), |
3831 | FunctionParam->getDeclName()); |
3832 | if (T.isNull()) |
3833 | return true; |
3834 | FunctionParam->setType(T); |
3835 | } |
3836 | |
3837 | Scope.InstantiatedLocalPackArg(PatternParam, FunctionParam); |
3838 | ++FParamIdx; |
3839 | } |
3840 | } |
3841 | } |
3842 | |
3843 | return false; |
3844 | } |
3845 | |
3846 | void Sema::InstantiateExceptionSpec(SourceLocation PointOfInstantiation, |
3847 | FunctionDecl *Decl) { |
3848 | const FunctionProtoType *Proto = Decl->getType()->castAs<FunctionProtoType>(); |
3849 | if (Proto->getExceptionSpecType() != EST_Uninstantiated) |
3850 | return; |
3851 | |
3852 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Decl, |
3853 | InstantiatingTemplate::ExceptionSpecification()); |
3854 | if (Inst.isInvalid()) { |
3855 | |
3856 | |
3857 | UpdateExceptionSpec(Decl, EST_None); |
3858 | return; |
3859 | } |
3860 | if (Inst.isAlreadyInstantiating()) { |
3861 | |
3862 | |
3863 | Diag(PointOfInstantiation, diag::err_exception_spec_cycle) << Decl; |
3864 | UpdateExceptionSpec(Decl, EST_None); |
3865 | return; |
3866 | } |
3867 | |
3868 | |
3869 | |
3870 | Sema::ContextRAII savedContext(*this, Decl); |
3871 | LocalInstantiationScope Scope(*this); |
3872 | |
3873 | MultiLevelTemplateArgumentList TemplateArgs = |
3874 | getTemplateInstantiationArgs(Decl, nullptr, ); |
3875 | |
3876 | FunctionDecl *Template = Proto->getExceptionSpecTemplate(); |
3877 | if (addInstantiatedParametersToScope(*this, Decl, Template, Scope, |
3878 | TemplateArgs)) { |
3879 | UpdateExceptionSpec(Decl, EST_None); |
3880 | return; |
3881 | } |
3882 | |
3883 | SubstExceptionSpec(Decl, Template->getType()->castAs<FunctionProtoType>(), |
3884 | TemplateArgs); |
3885 | } |
3886 | |
3887 | |
3888 | |
3889 | |
3890 | |
3891 | bool |
3892 | TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New, |
3893 | FunctionDecl *Tmpl) { |
3894 | if (Tmpl->isDeleted()) |
3895 | New->setDeletedAsWritten(); |
3896 | |
3897 | New->setImplicit(Tmpl->isImplicit()); |
3898 | |
3899 | |
3900 | SemaRef.Context.setManglingNumber(New, |
3901 | SemaRef.Context.getManglingNumber(Tmpl)); |
3902 | |
3903 | |
3904 | |
3905 | |
3906 | |
3907 | |
3908 | |
3909 | |
3910 | |
3911 | typedef Sema::CodeSynthesisContext ActiveInstType; |
3912 | ActiveInstType &ActiveInst = SemaRef.CodeSynthesisContexts.back(); |
3913 | if (ActiveInst.Kind == ActiveInstType::ExplicitTemplateArgumentSubstitution || |
3914 | ActiveInst.Kind == ActiveInstType::DeducedTemplateArgumentSubstitution) { |
3915 | if (FunctionTemplateDecl *FunTmpl |
3916 | = dyn_cast<FunctionTemplateDecl>(ActiveInst.Entity)) { |
3917 | (0) . __assert_fail ("FunTmpl->getTemplatedDecl() == Tmpl && \"Deduction from the wrong function template?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 3918, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(FunTmpl->getTemplatedDecl() == Tmpl && |
3918 | (0) . __assert_fail ("FunTmpl->getTemplatedDecl() == Tmpl && \"Deduction from the wrong function template?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 3918, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Deduction from the wrong function template?"); |
3919 | (void) FunTmpl; |
3920 | atTemplateEnd(SemaRef.TemplateInstCallbacks, SemaRef, ActiveInst); |
3921 | ActiveInst.Kind = ActiveInstType::TemplateInstantiation; |
3922 | ActiveInst.Entity = New; |
3923 | atTemplateBegin(SemaRef.TemplateInstCallbacks, SemaRef, ActiveInst); |
3924 | } |
3925 | } |
3926 | |
3927 | const FunctionProtoType *Proto = Tmpl->getType()->getAs<FunctionProtoType>(); |
3928 | (0) . __assert_fail ("Proto && \"Function template without prototype?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 3928, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Proto && "Function template without prototype?"); |
3929 | |
3930 | if (Proto->hasExceptionSpec() || Proto->getNoReturnAttr()) { |
3931 | FunctionProtoType::ExtProtoInfo EPI = Proto->getExtProtoInfo(); |
3932 | |
3933 | |
3934 | |
3935 | |
3936 | |
3937 | if (SemaRef.getLangOpts().CPlusPlus11 && |
3938 | EPI.ExceptionSpec.Type != EST_None && |
3939 | EPI.ExceptionSpec.Type != EST_DynamicNone && |
3940 | EPI.ExceptionSpec.Type != EST_BasicNoexcept && |
3941 | !Tmpl->isLexicallyWithinFunctionOrMethod()) { |
3942 | FunctionDecl *ExceptionSpecTemplate = Tmpl; |
3943 | if (EPI.ExceptionSpec.Type == EST_Uninstantiated) |
3944 | ExceptionSpecTemplate = EPI.ExceptionSpec.SourceTemplate; |
3945 | ExceptionSpecificationType NewEST = EST_Uninstantiated; |
3946 | if (EPI.ExceptionSpec.Type == EST_Unevaluated) |
3947 | NewEST = EST_Unevaluated; |
3948 | |
3949 | |
3950 | const FunctionProtoType *NewProto |
3951 | = New->getType()->getAs<FunctionProtoType>(); |
3952 | (0) . __assert_fail ("NewProto && \"Template instantiation without function prototype?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 3952, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(NewProto && "Template instantiation without function prototype?"); |
3953 | EPI = NewProto->getExtProtoInfo(); |
3954 | EPI.ExceptionSpec.Type = NewEST; |
3955 | EPI.ExceptionSpec.SourceDecl = New; |
3956 | EPI.ExceptionSpec.SourceTemplate = ExceptionSpecTemplate; |
3957 | New->setType(SemaRef.Context.getFunctionType( |
3958 | NewProto->getReturnType(), NewProto->getParamTypes(), EPI)); |
3959 | } else { |
3960 | Sema::ContextRAII SwitchContext(SemaRef, New); |
3961 | SemaRef.SubstExceptionSpec(New, Proto, TemplateArgs); |
3962 | } |
3963 | } |
3964 | |
3965 | |
3966 | const FunctionDecl *Definition = Tmpl; |
3967 | Tmpl->isDefined(Definition); |
3968 | |
3969 | SemaRef.InstantiateAttrs(TemplateArgs, Definition, New, |
3970 | LateAttrs, StartingScope); |
3971 | |
3972 | return false; |
3973 | } |
3974 | |
3975 | |
3976 | |
3977 | |
3978 | |
3979 | |
3980 | bool |
3981 | TemplateDeclInstantiator::InitMethodInstantiation(CXXMethodDecl *New, |
3982 | CXXMethodDecl *Tmpl) { |
3983 | if (InitFunctionInstantiation(New, Tmpl)) |
3984 | return true; |
3985 | |
3986 | if (isa<CXXDestructorDecl>(New) && SemaRef.getLangOpts().CPlusPlus11) |
3987 | SemaRef.AdjustDestructorExceptionSpec(cast<CXXDestructorDecl>(New)); |
3988 | |
3989 | New->setAccess(Tmpl->getAccess()); |
3990 | if (Tmpl->isVirtualAsWritten()) |
3991 | New->setVirtualAsWritten(true); |
3992 | |
3993 | |
3994 | return false; |
3995 | } |
3996 | |
3997 | |
3998 | |
3999 | |
4000 | |
4001 | |
4002 | FunctionDecl * |
4003 | Sema::InstantiateFunctionDeclaration(FunctionTemplateDecl *FTD, |
4004 | const TemplateArgumentList *Args, |
4005 | SourceLocation Loc) { |
4006 | FunctionDecl *FD = FTD->getTemplatedDecl(); |
4007 | |
4008 | sema::TemplateDeductionInfo Info(Loc); |
4009 | InstantiatingTemplate Inst( |
4010 | *this, Loc, FTD, Args->asArray(), |
4011 | CodeSynthesisContext::ExplicitTemplateArgumentSubstitution, Info); |
4012 | if (Inst.isInvalid()) |
4013 | return nullptr; |
4014 | |
4015 | ContextRAII SavedContext(*this, FD); |
4016 | MultiLevelTemplateArgumentList MArgs(*Args); |
4017 | |
4018 | return cast_or_null<FunctionDecl>(SubstDecl(FD, FD->getParent(), MArgs)); |
4019 | } |
4020 | |
4021 | |
4022 | |
4023 | |
4024 | |
4025 | static void InstantiateDefaultCtorDefaultArgs(Sema &S, |
4026 | CXXConstructorDecl *Ctor) { |
4027 | isDefaultConstructor()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 4028, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(S.Context.getTargetInfo().getCXXABI().isMicrosoft() && |
4028 | isDefaultConstructor()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 4028, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> Ctor->isDefaultConstructor()); |
4029 | unsigned NumParams = Ctor->getNumParams(); |
4030 | if (NumParams == 0) |
4031 | return; |
4032 | DLLExportAttr *Attr = Ctor->getAttr<DLLExportAttr>(); |
4033 | if (!Attr) |
4034 | return; |
4035 | for (unsigned I = 0; I != NumParams; ++I) { |
4036 | (void)S.CheckCXXDefaultArgExpr(Attr->getLocation(), Ctor, |
4037 | Ctor->getParamDecl(I)); |
4038 | S.DiscardCleanupsInEvaluationContext(); |
4039 | } |
4040 | } |
4041 | |
4042 | |
4043 | |
4044 | |
4045 | |
4046 | |
4047 | |
4048 | |
4049 | |
4050 | |
4051 | |
4052 | |
4053 | |
4054 | |
4055 | |
4056 | |
4057 | |
4058 | |
4059 | void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, |
4060 | FunctionDecl *Function, |
4061 | bool Recursive, |
4062 | bool DefinitionRequired, |
4063 | bool AtEndOfTU) { |
4064 | if (Function->isInvalidDecl() || Function->isDefined() || |
4065 | isa<CXXDeductionGuideDecl>(Function)) |
4066 | return; |
4067 | |
4068 | |
4069 | |
4070 | TemplateSpecializationKind TSK = Function->getTemplateSpecializationKind(); |
4071 | if (TSK == TSK_ExplicitSpecialization && |
4072 | !Function->getClassScopeSpecializationPattern()) |
4073 | return; |
4074 | |
4075 | |
4076 | const FunctionDecl *PatternDecl = Function->getTemplateInstantiationPattern(); |
4077 | (0) . __assert_fail ("PatternDecl && \"instantiating a non-template\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 4077, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(PatternDecl && "instantiating a non-template"); |
4078 | |
4079 | const FunctionDecl *PatternDef = PatternDecl->getDefinition(); |
4080 | Stmt *Pattern = nullptr; |
4081 | if (PatternDef) { |
4082 | Pattern = PatternDef->getBody(PatternDef); |
4083 | PatternDecl = PatternDef; |
4084 | if (PatternDef->willHaveBody()) |
4085 | PatternDef = nullptr; |
4086 | } |
4087 | |
4088 | |
4089 | |
4090 | if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Function, |
4091 | Function->getInstantiatedFromMemberFunction(), |
4092 | PatternDecl, PatternDef, TSK, |
4093 | )) { |
4094 | if (DefinitionRequired) |
4095 | Function->setInvalidDecl(); |
4096 | else if (TSK == TSK_ExplicitInstantiationDefinition) { |
4097 | |
4098 | |
4099 | assert(!Recursive); |
4100 | Function->setInstantiationIsPending(true); |
4101 | PendingInstantiations.push_back( |
4102 | std::make_pair(Function, PointOfInstantiation)); |
4103 | } else if (TSK == TSK_ImplicitInstantiation) { |
4104 | if (AtEndOfTU && !getDiagnostics().hasErrorOccurred() && |
4105 | !getSourceManager().isInSystemHeader(PatternDecl->getBeginLoc())) { |
4106 | Diag(PointOfInstantiation, diag::warn_func_template_missing) |
4107 | << Function; |
4108 | Diag(PatternDecl->getLocation(), diag::note_forward_template_decl); |
4109 | if (getLangOpts().CPlusPlus11) |
4110 | Diag(PointOfInstantiation, diag::note_inst_declaration_hint) |
4111 | << Function; |
4112 | } |
4113 | } |
4114 | |
4115 | return; |
4116 | } |
4117 | |
4118 | |
4119 | if (PatternDecl->isLateTemplateParsed() && |
4120 | !LateTemplateParser) { |
4121 | Function->setInstantiationIsPending(true); |
4122 | LateParsedInstantiations.push_back( |
4123 | std::make_pair(Function, PointOfInstantiation)); |
4124 | return; |
4125 | } |
4126 | |
4127 | |
4128 | |
4129 | |
4130 | |
4131 | |
4132 | GlobalEagerInstantiationScope GlobalInstantiations(*this, |
4133 | ); |
4134 | LocalEagerInstantiationScope LocalInstantiations(*this); |
4135 | |
4136 | |
4137 | |
4138 | if (!Pattern && PatternDecl->isLateTemplateParsed() && |
4139 | LateTemplateParser) { |
4140 | |
4141 | if (PatternDecl->isFromASTFile()) |
4142 | ExternalSource->ReadLateParsedTemplates(LateParsedTemplateMap); |
4143 | |
4144 | auto LPTIter = LateParsedTemplateMap.find(PatternDecl); |
4145 | (0) . __assert_fail ("LPTIter != LateParsedTemplateMap.end() && \"missing LateParsedTemplate\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 4146, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(LPTIter != LateParsedTemplateMap.end() && |
4146 | (0) . __assert_fail ("LPTIter != LateParsedTemplateMap.end() && \"missing LateParsedTemplate\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 4146, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "missing LateParsedTemplate"); |
4147 | LateTemplateParser(OpaqueParser, *LPTIter->second); |
4148 | Pattern = PatternDecl->getBody(PatternDecl); |
4149 | } |
4150 | |
4151 | |
4152 | (0) . __assert_fail ("(Pattern || PatternDecl->isDefaulted() || PatternDecl->hasSkippedBody()) && \"unexpected kind of function template definition\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 4154, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((Pattern || PatternDecl->isDefaulted() || |
4153 | (0) . __assert_fail ("(Pattern || PatternDecl->isDefaulted() || PatternDecl->hasSkippedBody()) && \"unexpected kind of function template definition\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 4154, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> PatternDecl->hasSkippedBody()) && |
4154 | (0) . __assert_fail ("(Pattern || PatternDecl->isDefaulted() || PatternDecl->hasSkippedBody()) && \"unexpected kind of function template definition\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 4154, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "unexpected kind of function template definition"); |
4155 | |
4156 | |
4157 | |
4158 | |
4159 | |
4160 | |
4161 | if (TSK == TSK_ExplicitInstantiationDeclaration && |
4162 | !PatternDecl->isInlined() && |
4163 | !PatternDecl->getReturnType()->getContainedAutoType()) |
4164 | return; |
4165 | |
4166 | if (PatternDecl->isInlined()) { |
4167 | |
4168 | |
4169 | for (auto *D = Function->getMostRecentDecl(); ; |
4170 | D = D->getPreviousDecl()) { |
4171 | D->setImplicitlyInline(); |
4172 | if (D == Function) |
4173 | break; |
4174 | } |
4175 | } |
4176 | |
4177 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Function); |
4178 | if (Inst.isInvalid() || Inst.isAlreadyInstantiating()) |
4179 | return; |
4180 | PrettyDeclStackTraceEntry CrashInfo(Context, Function, SourceLocation(), |
4181 | "instantiating function definition"); |
4182 | |
4183 | |
4184 | |
4185 | Function->setVisibleDespiteOwningModule(); |
4186 | |
4187 | |
4188 | Function->setInnerLocStart(PatternDecl->getInnerLocStart()); |
4189 | |
4190 | EnterExpressionEvaluationContext EvalContext( |
4191 | *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); |
4192 | |
4193 | |
4194 | |
4195 | |
4196 | |
4197 | bool MergeWithParentScope = false; |
4198 | if (CXXRecordDecl *Rec = dyn_cast<CXXRecordDecl>(Function->getDeclContext())) |
4199 | MergeWithParentScope = Rec->isLocalClass(); |
4200 | |
4201 | LocalInstantiationScope Scope(*this, MergeWithParentScope); |
4202 | |
4203 | if (PatternDecl->isDefaulted()) |
4204 | SetDeclDefaulted(Function, PatternDecl->getLocation()); |
4205 | else { |
4206 | MultiLevelTemplateArgumentList TemplateArgs = |
4207 | getTemplateInstantiationArgs(Function, nullptr, false, PatternDecl); |
4208 | |
4209 | |
4210 | |
4211 | |
4212 | |
4213 | SubstQualifier(*this, PatternDecl, Function, TemplateArgs); |
4214 | |
4215 | ActOnStartOfFunctionDef(nullptr, Function); |
4216 | |
4217 | |
4218 | |
4219 | Sema::ContextRAII savedContext(*this, Function); |
4220 | |
4221 | if (addInstantiatedParametersToScope(*this, Function, PatternDecl, Scope, |
4222 | TemplateArgs)) |
4223 | return; |
4224 | |
4225 | StmtResult Body; |
4226 | if (PatternDecl->hasSkippedBody()) { |
4227 | ActOnSkippedFunctionBody(Function); |
4228 | Body = nullptr; |
4229 | } else { |
4230 | if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(Function)) { |
4231 | |
4232 | InstantiateMemInitializers(Ctor, cast<CXXConstructorDecl>(PatternDecl), |
4233 | TemplateArgs); |
4234 | |
4235 | |
4236 | |
4237 | if (Context.getTargetInfo().getCXXABI().isMicrosoft() && |
4238 | Ctor->isDefaultConstructor()) { |
4239 | InstantiateDefaultCtorDefaultArgs(*this, Ctor); |
4240 | } |
4241 | } |
4242 | |
4243 | |
4244 | Body = SubstStmt(Pattern, TemplateArgs); |
4245 | |
4246 | if (Body.isInvalid()) |
4247 | Function->setInvalidDecl(); |
4248 | } |
4249 | |
4250 | |
4251 | ActOnFinishFunctionBody(Function, Body.get(), ); |
4252 | |
4253 | PerformDependentDiagnostics(PatternDecl, TemplateArgs); |
4254 | |
4255 | if (auto *Listener = getASTMutationListener()) |
4256 | Listener->FunctionDefinitionInstantiated(Function); |
4257 | |
4258 | savedContext.pop(); |
4259 | } |
4260 | |
4261 | DeclGroupRef DG(Function); |
4262 | Consumer.HandleTopLevelDecl(DG); |
4263 | |
4264 | |
4265 | |
4266 | LocalInstantiations.perform(); |
4267 | Scope.Exit(); |
4268 | GlobalInstantiations.perform(); |
4269 | } |
4270 | |
4271 | VarTemplateSpecializationDecl *Sema::BuildVarTemplateInstantiation( |
4272 | VarTemplateDecl *VarTemplate, VarDecl *FromVar, |
4273 | const TemplateArgumentList &TemplateArgList, |
4274 | const TemplateArgumentListInfo &TemplateArgsInfo, |
4275 | SmallVectorImpl<TemplateArgument> &Converted, |
4276 | SourceLocation PointOfInstantiation, void *InsertPos, |
4277 | LateInstantiatedAttrVec *LateAttrs, |
4278 | LocalInstantiationScope *StartingScope) { |
4279 | if (FromVar->isInvalidDecl()) |
4280 | return nullptr; |
4281 | |
4282 | InstantiatingTemplate Inst(*this, PointOfInstantiation, FromVar); |
4283 | if (Inst.isInvalid()) |
4284 | return nullptr; |
4285 | |
4286 | MultiLevelTemplateArgumentList TemplateArgLists; |
4287 | TemplateArgLists.addOuterTemplateArguments(&TemplateArgList); |
4288 | |
4289 | |
4290 | |
4291 | |
4292 | |
4293 | |
4294 | |
4295 | |
4296 | |
4297 | |
4298 | bool IsMemberSpec = false; |
4299 | if (VarTemplatePartialSpecializationDecl *PartialSpec = |
4300 | dyn_cast<VarTemplatePartialSpecializationDecl>(FromVar)) |
4301 | IsMemberSpec = PartialSpec->isMemberSpecialization(); |
4302 | else if (VarTemplateDecl *FromTemplate = FromVar->getDescribedVarTemplate()) |
4303 | IsMemberSpec = FromTemplate->isMemberSpecialization(); |
4304 | if (!IsMemberSpec) |
4305 | FromVar = FromVar->getFirstDecl(); |
4306 | |
4307 | MultiLevelTemplateArgumentList MultiLevelList(TemplateArgList); |
4308 | TemplateDeclInstantiator Instantiator(*this, FromVar->getDeclContext(), |
4309 | MultiLevelList); |
4310 | |
4311 | |
4312 | |
4313 | return cast_or_null<VarTemplateSpecializationDecl>( |
4314 | Instantiator.VisitVarTemplateSpecializationDecl( |
4315 | VarTemplate, FromVar, InsertPos, TemplateArgsInfo, Converted)); |
4316 | } |
4317 | |
4318 | |
4319 | |
4320 | VarTemplateSpecializationDecl *Sema::CompleteVarTemplateSpecializationDecl( |
4321 | VarTemplateSpecializationDecl *VarSpec, VarDecl *PatternDecl, |
4322 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
4323 | (0) . __assert_fail ("PatternDecl->isThisDeclarationADefinition() && \"don't have a definition to instantiate from\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 4324, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(PatternDecl->isThisDeclarationADefinition() && |
4324 | (0) . __assert_fail ("PatternDecl->isThisDeclarationADefinition() && \"don't have a definition to instantiate from\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 4324, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "don't have a definition to instantiate from"); |
4325 | |
4326 | |
4327 | TypeSourceInfo *DI = |
4328 | SubstType(PatternDecl->getTypeSourceInfo(), TemplateArgs, |
4329 | PatternDecl->getTypeSpecStartLoc(), PatternDecl->getDeclName()); |
4330 | if (!DI) |
4331 | return nullptr; |
4332 | |
4333 | |
4334 | VarSpec->setType(DI->getType()); |
4335 | |
4336 | |
4337 | VarSpec->setCompleteDefinition(); |
4338 | |
4339 | |
4340 | InstantiateVariableInitializer(VarSpec, PatternDecl, TemplateArgs); |
4341 | |
4342 | return VarSpec; |
4343 | } |
4344 | |
4345 | |
4346 | |
4347 | |
4348 | void Sema::BuildVariableInstantiation( |
4349 | VarDecl *NewVar, VarDecl *OldVar, |
4350 | const MultiLevelTemplateArgumentList &TemplateArgs, |
4351 | LateInstantiatedAttrVec *LateAttrs, DeclContext *Owner, |
4352 | LocalInstantiationScope *StartingScope, |
4353 | bool InstantiatingVarTemplate) { |
4354 | |
4355 | |
4356 | |
4357 | |
4358 | |
4359 | |
4360 | if (OldVar->isLocalExternDecl()) { |
4361 | NewVar->setLocalExternDecl(); |
4362 | NewVar->setLexicalDeclContext(Owner); |
4363 | } else if (OldVar->isOutOfLine()) |
4364 | NewVar->setLexicalDeclContext(OldVar->getLexicalDeclContext()); |
4365 | NewVar->setTSCSpec(OldVar->getTSCSpec()); |
4366 | NewVar->setInitStyle(OldVar->getInitStyle()); |
4367 | NewVar->setCXXForRangeDecl(OldVar->isCXXForRangeDecl()); |
4368 | NewVar->setObjCForDecl(OldVar->isObjCForDecl()); |
4369 | NewVar->setConstexpr(OldVar->isConstexpr()); |
4370 | NewVar->setInitCapture(OldVar->isInitCapture()); |
4371 | NewVar->setPreviousDeclInSameBlockScope( |
4372 | OldVar->isPreviousDeclInSameBlockScope()); |
4373 | NewVar->setAccess(OldVar->getAccess()); |
4374 | |
4375 | if (!OldVar->isStaticDataMember()) { |
4376 | if (OldVar->isUsed(false)) |
4377 | NewVar->setIsUsed(); |
4378 | NewVar->setReferenced(OldVar->isReferenced()); |
4379 | } |
4380 | |
4381 | InstantiateAttrs(TemplateArgs, OldVar, NewVar, LateAttrs, StartingScope); |
4382 | |
4383 | LookupResult Previous( |
4384 | *this, NewVar->getDeclName(), NewVar->getLocation(), |
4385 | NewVar->isLocalExternDecl() ? Sema::LookupRedeclarationWithLinkage |
4386 | : Sema::LookupOrdinaryName, |
4387 | NewVar->isLocalExternDecl() ? Sema::ForExternalRedeclaration |
4388 | : forRedeclarationInCurContext()); |
4389 | |
4390 | if (NewVar->isLocalExternDecl() && OldVar->getPreviousDecl() && |
4391 | (!OldVar->getPreviousDecl()->getDeclContext()->isDependentContext() || |
4392 | OldVar->getPreviousDecl()->getDeclContext()==OldVar->getDeclContext())) { |
4393 | |
4394 | |
4395 | if (NamedDecl *NewPrev = FindInstantiatedDecl( |
4396 | NewVar->getLocation(), OldVar->getPreviousDecl(), TemplateArgs)) |
4397 | Previous.addDecl(NewPrev); |
4398 | } else if (!isa<VarTemplateSpecializationDecl>(NewVar) && |
4399 | OldVar->hasLinkage()) |
4400 | LookupQualifiedName(Previous, NewVar->getDeclContext(), false); |
4401 | CheckVariableDeclaration(NewVar, Previous); |
4402 | |
4403 | if (!InstantiatingVarTemplate) { |
4404 | NewVar->getLexicalDeclContext()->addHiddenDecl(NewVar); |
4405 | if (!NewVar->isLocalExternDecl() || !NewVar->getPreviousDecl()) |
4406 | NewVar->getDeclContext()->makeDeclVisibleInContext(NewVar); |
4407 | } |
4408 | |
4409 | if (!OldVar->isOutOfLine()) { |
4410 | if (NewVar->getDeclContext()->isFunctionOrMethod()) |
4411 | CurrentInstantiationScope->InstantiatedLocal(OldVar, NewVar); |
4412 | } |
4413 | |
4414 | |
4415 | |
4416 | if (NewVar->isStaticDataMember() && !InstantiatingVarTemplate) |
4417 | NewVar->setInstantiationOfStaticDataMember(OldVar, |
4418 | TSK_ImplicitInstantiation); |
4419 | |
4420 | |
4421 | Context.setManglingNumber(NewVar, Context.getManglingNumber(OldVar)); |
4422 | Context.setStaticLocalNumber(NewVar, Context.getStaticLocalNumber(OldVar)); |
4423 | |
4424 | |
4425 | |
4426 | |
4427 | if ((!isa<VarTemplateSpecializationDecl>(NewVar) && |
4428 | !InstantiatingVarTemplate && |
4429 | !(OldVar->isInline() && OldVar->isThisDeclarationADefinition() && |
4430 | !NewVar->isThisDeclarationADefinition())) || |
4431 | NewVar->getType()->isUndeducedType()) |
4432 | InstantiateVariableInitializer(NewVar, OldVar, TemplateArgs); |
4433 | |
4434 | |
4435 | |
4436 | if (!NewVar->isInvalidDecl() && |
4437 | NewVar->getDeclContext()->isFunctionOrMethod() && |
4438 | OldVar->getType()->isDependentType()) |
4439 | DiagnoseUnusedDecl(NewVar); |
4440 | } |
4441 | |
4442 | |
4443 | void Sema::InstantiateVariableInitializer( |
4444 | VarDecl *Var, VarDecl *OldVar, |
4445 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
4446 | if (ASTMutationListener *L = getASTContext().getASTMutationListener()) |
4447 | L->VariableDefinitionInstantiated(Var); |
4448 | |
4449 | |
4450 | |
4451 | |
4452 | if (OldVar->isInlineSpecified()) |
4453 | Var->setInlineSpecified(); |
4454 | else if (OldVar->isInline()) |
4455 | Var->setImplicitlyInline(); |
4456 | |
4457 | if (OldVar->getInit()) { |
4458 | EnterExpressionEvaluationContext Evaluated( |
4459 | *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated, Var); |
4460 | |
4461 | |
4462 | ExprResult Init; |
4463 | |
4464 | { |
4465 | ContextRAII SwitchContext(*this, Var->getDeclContext()); |
4466 | Init = SubstInitializer(OldVar->getInit(), TemplateArgs, |
4467 | OldVar->getInitStyle() == VarDecl::CallInit); |
4468 | } |
4469 | |
4470 | if (!Init.isInvalid()) { |
4471 | Expr *InitExpr = Init.get(); |
4472 | |
4473 | if (Var->hasAttr<DLLImportAttr>() && |
4474 | (!InitExpr || |
4475 | !InitExpr->isConstantInitializer(getASTContext(), false))) { |
4476 | |
4477 | } else if (InitExpr) { |
4478 | bool DirectInit = OldVar->isDirectInit(); |
4479 | AddInitializerToDecl(Var, InitExpr, DirectInit); |
4480 | } else |
4481 | ActOnUninitializedDecl(Var); |
4482 | } else { |
4483 | |
4484 | |
4485 | Var->setInvalidDecl(); |
4486 | } |
4487 | } else { |
4488 | |
4489 | |
4490 | if (Var->isStaticDataMember() && !Var->isInline()) { |
4491 | if (!Var->isOutOfLine()) |
4492 | return; |
4493 | |
4494 | |
4495 | |
4496 | if (OldVar->getFirstDecl()->hasInit()) |
4497 | return; |
4498 | } |
4499 | |
4500 | |
4501 | if (Var->isCXXForRangeDecl() || Var->isObjCForDecl()) |
4502 | return; |
4503 | |
4504 | ActOnUninitializedDecl(Var); |
4505 | } |
4506 | |
4507 | if (getLangOpts().CUDA) |
4508 | checkAllowedCUDAInitializer(Var); |
4509 | } |
4510 | |
4511 | |
4512 | |
4513 | |
4514 | |
4515 | |
4516 | |
4517 | |
4518 | |
4519 | |
4520 | |
4521 | |
4522 | |
4523 | |
4524 | |
4525 | |
4526 | void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation, |
4527 | VarDecl *Var, bool Recursive, |
4528 | bool DefinitionRequired, bool AtEndOfTU) { |
4529 | if (Var->isInvalidDecl()) |
4530 | return; |
4531 | |
4532 | VarTemplateSpecializationDecl *VarSpec = |
4533 | dyn_cast<VarTemplateSpecializationDecl>(Var); |
4534 | VarDecl *PatternDecl = nullptr, *Def = nullptr; |
4535 | MultiLevelTemplateArgumentList TemplateArgs = |
4536 | getTemplateInstantiationArgs(Var); |
4537 | |
4538 | if (VarSpec) { |
4539 | |
4540 | |
4541 | bool InstantiationDependent = false; |
4542 | (0) . __assert_fail ("!TemplateSpecializationType..anyDependentTemplateArguments( VarSpec->getTemplateArgsInfo(), InstantiationDependent) && \"Only instantiate variable template specializations that are \" \"not type-dependent\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 4545, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!TemplateSpecializationType::anyDependentTemplateArguments( |
4543 | (0) . __assert_fail ("!TemplateSpecializationType..anyDependentTemplateArguments( VarSpec->getTemplateArgsInfo(), InstantiationDependent) && \"Only instantiate variable template specializations that are \" \"not type-dependent\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 4545, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> VarSpec->getTemplateArgsInfo(), InstantiationDependent) && |
4544 | (0) . __assert_fail ("!TemplateSpecializationType..anyDependentTemplateArguments( VarSpec->getTemplateArgsInfo(), InstantiationDependent) && \"Only instantiate variable template specializations that are \" \"not type-dependent\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 4545, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Only instantiate variable template specializations that are " |
4545 | (0) . __assert_fail ("!TemplateSpecializationType..anyDependentTemplateArguments( VarSpec->getTemplateArgsInfo(), InstantiationDependent) && \"Only instantiate variable template specializations that are \" \"not type-dependent\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 4545, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "not type-dependent"); |
4546 | (void)InstantiationDependent; |
4547 | |
4548 | |
4549 | |
4550 | |
4551 | (0) . __assert_fail ("VarSpec->getSpecializedTemplate() && \"Specialization without specialized template?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 4552, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(VarSpec->getSpecializedTemplate() && |
4552 | (0) . __assert_fail ("VarSpec->getSpecializedTemplate() && \"Specialization without specialized template?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 4552, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Specialization without specialized template?"); |
4553 | llvm::PointerUnion<VarTemplateDecl *, |
4554 | VarTemplatePartialSpecializationDecl *> PatternPtr = |
4555 | VarSpec->getSpecializedTemplateOrPartial(); |
4556 | if (PatternPtr.is<VarTemplatePartialSpecializationDecl *>()) { |
4557 | VarTemplatePartialSpecializationDecl *Tmpl = |
4558 | PatternPtr.get<VarTemplatePartialSpecializationDecl *>(); |
4559 | while (VarTemplatePartialSpecializationDecl *From = |
4560 | Tmpl->getInstantiatedFromMember()) { |
4561 | if (Tmpl->isMemberSpecialization()) |
4562 | break; |
4563 | |
4564 | Tmpl = From; |
4565 | } |
4566 | PatternDecl = Tmpl; |
4567 | } else { |
4568 | VarTemplateDecl *Tmpl = PatternPtr.get<VarTemplateDecl *>(); |
4569 | while (VarTemplateDecl *From = |
4570 | Tmpl->getInstantiatedFromMemberTemplate()) { |
4571 | if (Tmpl->isMemberSpecialization()) |
4572 | break; |
4573 | |
4574 | Tmpl = From; |
4575 | } |
4576 | PatternDecl = Tmpl->getTemplatedDecl(); |
4577 | } |
4578 | |
4579 | |
4580 | |
4581 | |
4582 | |
4583 | |
4584 | |
4585 | |
4586 | |
4587 | if (PatternDecl->isStaticDataMember() && |
4588 | (PatternDecl = PatternDecl->getFirstDecl())->hasInit() && |
4589 | !Var->hasInit()) { |
4590 | |
4591 | |
4592 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Var); |
4593 | if (Inst.isInvalid() || Inst.isAlreadyInstantiating()) |
4594 | return; |
4595 | PrettyDeclStackTraceEntry CrashInfo(Context, Var, SourceLocation(), |
4596 | "instantiating variable initializer"); |
4597 | |
4598 | |
4599 | |
4600 | Var->setVisibleDespiteOwningModule(); |
4601 | |
4602 | |
4603 | |
4604 | |
4605 | GlobalEagerInstantiationScope GlobalInstantiations(*this, |
4606 | ); |
4607 | LocalInstantiationScope Local(*this); |
4608 | LocalEagerInstantiationScope LocalInstantiations(*this); |
4609 | |
4610 | |
4611 | |
4612 | ContextRAII PreviousContext(*this, Var->getDeclContext()); |
4613 | InstantiateVariableInitializer(Var, PatternDecl, TemplateArgs); |
4614 | PreviousContext.pop(); |
4615 | |
4616 | |
4617 | |
4618 | LocalInstantiations.perform(); |
4619 | Local.Exit(); |
4620 | GlobalInstantiations.perform(); |
4621 | } |
4622 | |
4623 | |
4624 | Def = PatternDecl->getDefinition(getASTContext()); |
4625 | } else { |
4626 | |
4627 | (0) . __assert_fail ("Var->isStaticDataMember() && \"not a static data member?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 4627, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Var->isStaticDataMember() && "not a static data member?"); |
4628 | PatternDecl = Var->getInstantiatedFromStaticDataMember(); |
4629 | |
4630 | (0) . __assert_fail ("PatternDecl && \"data member was not instantiated from a template?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 4630, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(PatternDecl && "data member was not instantiated from a template?"); |
4631 | (0) . __assert_fail ("PatternDecl->isStaticDataMember() && \"not a static data member?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 4631, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(PatternDecl->isStaticDataMember() && "not a static data member?"); |
4632 | Def = PatternDecl->getDefinition(); |
4633 | } |
4634 | |
4635 | TemplateSpecializationKind TSK = Var->getTemplateSpecializationKind(); |
4636 | |
4637 | |
4638 | |
4639 | |
4640 | |
4641 | if (!Def && !DefinitionRequired) { |
4642 | if (TSK == TSK_ExplicitInstantiationDefinition) { |
4643 | PendingInstantiations.push_back( |
4644 | std::make_pair(Var, PointOfInstantiation)); |
4645 | } else if (TSK == TSK_ImplicitInstantiation) { |
4646 | |
4647 | if (AtEndOfTU && !getDiagnostics().hasErrorOccurred() && |
4648 | !getSourceManager().isInSystemHeader(PatternDecl->getBeginLoc())) { |
4649 | Diag(PointOfInstantiation, diag::warn_var_template_missing) |
4650 | << Var; |
4651 | Diag(PatternDecl->getLocation(), diag::note_forward_template_decl); |
4652 | if (getLangOpts().CPlusPlus11) |
4653 | Diag(PointOfInstantiation, diag::note_inst_declaration_hint) << Var; |
4654 | } |
4655 | return; |
4656 | } |
4657 | |
4658 | } |
4659 | |
4660 | |
4661 | |
4662 | |
4663 | if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Var, |
4664 | , |
4665 | PatternDecl, Def, TSK, |
4666 | )) |
4667 | return; |
4668 | |
4669 | |
4670 | |
4671 | if (TSK == TSK_ExplicitSpecialization) |
4672 | return; |
4673 | |
4674 | |
4675 | |
4676 | |
4677 | |
4678 | |
4679 | if (TSK == TSK_ExplicitInstantiationDeclaration && |
4680 | !Var->isUsableInConstantExpressions(getASTContext())) |
4681 | return; |
4682 | |
4683 | |
4684 | struct PassToConsumerRAII { |
4685 | ASTConsumer &Consumer; |
4686 | VarDecl *Var; |
4687 | |
4688 | PassToConsumerRAII(ASTConsumer &Consumer, VarDecl *Var) |
4689 | : Consumer(Consumer), Var(Var) { } |
4690 | |
4691 | ~PassToConsumerRAII() { |
4692 | Consumer.HandleCXXStaticMemberVarInstantiation(Var); |
4693 | } |
4694 | } PassToConsumerRAII(Consumer, Var); |
4695 | |
4696 | |
4697 | if (VarDecl *Def = Var->getDefinition()) { |
4698 | |
4699 | |
4700 | Def->setTemplateSpecializationKind(Var->getTemplateSpecializationKind(), |
4701 | PointOfInstantiation); |
4702 | return; |
4703 | } |
4704 | |
4705 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Var); |
4706 | if (Inst.isInvalid() || Inst.isAlreadyInstantiating()) |
4707 | return; |
4708 | PrettyDeclStackTraceEntry CrashInfo(Context, Var, SourceLocation(), |
4709 | "instantiating variable definition"); |
4710 | |
4711 | |
4712 | |
4713 | |
4714 | GlobalEagerInstantiationScope GlobalInstantiations(*this, |
4715 | ); |
4716 | |
4717 | |
4718 | |
4719 | ContextRAII PreviousContext(*this, Var->getDeclContext()); |
4720 | LocalInstantiationScope Local(*this); |
4721 | |
4722 | LocalEagerInstantiationScope LocalInstantiations(*this); |
4723 | |
4724 | VarDecl *OldVar = Var; |
4725 | if (Def->isStaticDataMember() && !Def->isOutOfLine()) { |
4726 | |
4727 | |
4728 | InstantiateVariableInitializer(Var, Def, TemplateArgs); |
4729 | } else if (!VarSpec) { |
4730 | Var = cast_or_null<VarDecl>(SubstDecl(Def, Var->getDeclContext(), |
4731 | TemplateArgs)); |
4732 | } else if (Var->isStaticDataMember() && |
4733 | Var->getLexicalDeclContext()->isRecord()) { |
4734 | |
4735 | |
4736 | |
4737 | TemplateDeclInstantiator Instantiator(*this, Var->getDeclContext(), |
4738 | TemplateArgs); |
4739 | Var = cast_or_null<VarDecl>(Instantiator.VisitVarTemplateSpecializationDecl( |
4740 | VarSpec->getSpecializedTemplate(), Def, nullptr, |
4741 | VarSpec->getTemplateArgsInfo(), VarSpec->getTemplateArgs().asArray())); |
4742 | if (Var) { |
4743 | llvm::PointerUnion<VarTemplateDecl *, |
4744 | VarTemplatePartialSpecializationDecl *> PatternPtr = |
4745 | VarSpec->getSpecializedTemplateOrPartial(); |
4746 | if (VarTemplatePartialSpecializationDecl *Partial = |
4747 | PatternPtr.dyn_cast<VarTemplatePartialSpecializationDecl *>()) |
4748 | cast<VarTemplateSpecializationDecl>(Var)->setInstantiationOf( |
4749 | Partial, &VarSpec->getTemplateInstantiationArgs()); |
4750 | |
4751 | |
4752 | LookupResult R(*this, Var->getDeclName(), Var->getLocation(), |
4753 | LookupOrdinaryName, forRedeclarationInCurContext()); |
4754 | R.addDecl(OldVar); |
4755 | MergeVarDecl(Var, R); |
4756 | |
4757 | |
4758 | InstantiateVariableInitializer(Var, Def, TemplateArgs); |
4759 | } |
4760 | } else |
4761 | |
4762 | |
4763 | Var = CompleteVarTemplateSpecializationDecl(VarSpec, Def, TemplateArgs); |
4764 | |
4765 | PreviousContext.pop(); |
4766 | |
4767 | if (Var) { |
4768 | PassToConsumerRAII.Var = Var; |
4769 | Var->setTemplateSpecializationKind(OldVar->getTemplateSpecializationKind(), |
4770 | OldVar->getPointOfInstantiation()); |
4771 | } |
4772 | |
4773 | |
4774 | |
4775 | LocalInstantiations.perform(); |
4776 | Local.Exit(); |
4777 | GlobalInstantiations.perform(); |
4778 | } |
4779 | |
4780 | void |
4781 | Sema::InstantiateMemInitializers(CXXConstructorDecl *New, |
4782 | const CXXConstructorDecl *Tmpl, |
4783 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
4784 | |
4785 | SmallVector<CXXCtorInitializer*, 4> NewInits; |
4786 | bool AnyErrors = Tmpl->isInvalidDecl(); |
4787 | |
4788 | |
4789 | for (const auto *Init : Tmpl->inits()) { |
4790 | |
4791 | |
4792 | if (!Init->isWritten()) |
4793 | continue; |
4794 | |
4795 | SourceLocation EllipsisLoc; |
4796 | |
4797 | if (Init->isPackExpansion()) { |
4798 | |
4799 | TypeLoc BaseTL = Init->getTypeSourceInfo()->getTypeLoc(); |
4800 | SmallVector<UnexpandedParameterPack, 4> Unexpanded; |
4801 | collectUnexpandedParameterPacks(BaseTL, Unexpanded); |
4802 | collectUnexpandedParameterPacks(Init->getInit(), Unexpanded); |
4803 | bool ShouldExpand = false; |
4804 | bool RetainExpansion = false; |
4805 | Optional<unsigned> NumExpansions; |
4806 | if (CheckParameterPacksForExpansion(Init->getEllipsisLoc(), |
4807 | BaseTL.getSourceRange(), |
4808 | Unexpanded, |
4809 | TemplateArgs, ShouldExpand, |
4810 | RetainExpansion, |
4811 | NumExpansions)) { |
4812 | AnyErrors = true; |
4813 | New->setInvalidDecl(); |
4814 | continue; |
4815 | } |
4816 | (0) . __assert_fail ("ShouldExpand && \"Partial instantiation of base initializer?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 4816, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(ShouldExpand && "Partial instantiation of base initializer?"); |
4817 | |
4818 | |
4819 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
4820 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, I); |
4821 | |
4822 | |
4823 | ExprResult TempInit = SubstInitializer(Init->getInit(), TemplateArgs, |
4824 | ); |
4825 | if (TempInit.isInvalid()) { |
4826 | AnyErrors = true; |
4827 | break; |
4828 | } |
4829 | |
4830 | |
4831 | TypeSourceInfo *BaseTInfo = SubstType(Init->getTypeSourceInfo(), |
4832 | TemplateArgs, |
4833 | Init->getSourceLocation(), |
4834 | New->getDeclName()); |
4835 | if (!BaseTInfo) { |
4836 | AnyErrors = true; |
4837 | break; |
4838 | } |
4839 | |
4840 | |
4841 | MemInitResult NewInit = BuildBaseInitializer(BaseTInfo->getType(), |
4842 | BaseTInfo, TempInit.get(), |
4843 | New->getParent(), |
4844 | SourceLocation()); |
4845 | if (NewInit.isInvalid()) { |
4846 | AnyErrors = true; |
4847 | break; |
4848 | } |
4849 | |
4850 | NewInits.push_back(NewInit.get()); |
4851 | } |
4852 | |
4853 | continue; |
4854 | } |
4855 | |
4856 | |
4857 | ExprResult TempInit = SubstInitializer(Init->getInit(), TemplateArgs, |
4858 | ); |
4859 | if (TempInit.isInvalid()) { |
4860 | AnyErrors = true; |
4861 | continue; |
4862 | } |
4863 | |
4864 | MemInitResult NewInit; |
4865 | if (Init->isDelegatingInitializer() || Init->isBaseInitializer()) { |
4866 | TypeSourceInfo *TInfo = SubstType(Init->getTypeSourceInfo(), |
4867 | TemplateArgs, |
4868 | Init->getSourceLocation(), |
4869 | New->getDeclName()); |
4870 | if (!TInfo) { |
4871 | AnyErrors = true; |
4872 | New->setInvalidDecl(); |
4873 | continue; |
4874 | } |
4875 | |
4876 | if (Init->isBaseInitializer()) |
4877 | NewInit = BuildBaseInitializer(TInfo->getType(), TInfo, TempInit.get(), |
4878 | New->getParent(), EllipsisLoc); |
4879 | else |
4880 | NewInit = BuildDelegatingInitializer(TInfo, TempInit.get(), |
4881 | cast<CXXRecordDecl>(CurContext->getParent())); |
4882 | } else if (Init->isMemberInitializer()) { |
4883 | FieldDecl *Member = cast_or_null<FieldDecl>(FindInstantiatedDecl( |
4884 | Init->getMemberLocation(), |
4885 | Init->getMember(), |
4886 | TemplateArgs)); |
4887 | if (!Member) { |
4888 | AnyErrors = true; |
4889 | New->setInvalidDecl(); |
4890 | continue; |
4891 | } |
4892 | |
4893 | NewInit = BuildMemberInitializer(Member, TempInit.get(), |
4894 | Init->getSourceLocation()); |
4895 | } else if (Init->isIndirectMemberInitializer()) { |
4896 | IndirectFieldDecl *IndirectMember = |
4897 | cast_or_null<IndirectFieldDecl>(FindInstantiatedDecl( |
4898 | Init->getMemberLocation(), |
4899 | Init->getIndirectMember(), TemplateArgs)); |
4900 | |
4901 | if (!IndirectMember) { |
4902 | AnyErrors = true; |
4903 | New->setInvalidDecl(); |
4904 | continue; |
4905 | } |
4906 | |
4907 | NewInit = BuildMemberInitializer(IndirectMember, TempInit.get(), |
4908 | Init->getSourceLocation()); |
4909 | } |
4910 | |
4911 | if (NewInit.isInvalid()) { |
4912 | AnyErrors = true; |
4913 | New->setInvalidDecl(); |
4914 | } else { |
4915 | NewInits.push_back(NewInit.get()); |
4916 | } |
4917 | } |
4918 | |
4919 | |
4920 | ActOnMemInitializers(New, |
4921 | |
4922 | SourceLocation(), |
4923 | NewInits, |
4924 | AnyErrors); |
4925 | } |
4926 | |
4927 | |
4928 | |
4929 | static bool isInstantiationOf(ClassTemplateDecl *Pattern, |
4930 | ClassTemplateDecl *Instance) { |
4931 | Pattern = Pattern->getCanonicalDecl(); |
4932 | |
4933 | do { |
4934 | Instance = Instance->getCanonicalDecl(); |
4935 | if (Pattern == Instance) return true; |
4936 | Instance = Instance->getInstantiatedFromMemberTemplate(); |
4937 | } while (Instance); |
4938 | |
4939 | return false; |
4940 | } |
4941 | |
4942 | static bool isInstantiationOf(FunctionTemplateDecl *Pattern, |
4943 | FunctionTemplateDecl *Instance) { |
4944 | Pattern = Pattern->getCanonicalDecl(); |
4945 | |
4946 | do { |
4947 | Instance = Instance->getCanonicalDecl(); |
4948 | if (Pattern == Instance) return true; |
4949 | Instance = Instance->getInstantiatedFromMemberTemplate(); |
4950 | } while (Instance); |
4951 | |
4952 | return false; |
4953 | } |
4954 | |
4955 | static bool |
4956 | isInstantiationOf(ClassTemplatePartialSpecializationDecl *Pattern, |
4957 | ClassTemplatePartialSpecializationDecl *Instance) { |
4958 | Pattern |
4959 | = cast<ClassTemplatePartialSpecializationDecl>(Pattern->getCanonicalDecl()); |
4960 | do { |
4961 | Instance = cast<ClassTemplatePartialSpecializationDecl>( |
4962 | Instance->getCanonicalDecl()); |
4963 | if (Pattern == Instance) |
4964 | return true; |
4965 | Instance = Instance->getInstantiatedFromMember(); |
4966 | } while (Instance); |
4967 | |
4968 | return false; |
4969 | } |
4970 | |
4971 | static bool isInstantiationOf(CXXRecordDecl *Pattern, |
4972 | CXXRecordDecl *Instance) { |
4973 | Pattern = Pattern->getCanonicalDecl(); |
4974 | |
4975 | do { |
4976 | Instance = Instance->getCanonicalDecl(); |
4977 | if (Pattern == Instance) return true; |
4978 | Instance = Instance->getInstantiatedFromMemberClass(); |
4979 | } while (Instance); |
4980 | |
4981 | return false; |
4982 | } |
4983 | |
4984 | static bool isInstantiationOf(FunctionDecl *Pattern, |
4985 | FunctionDecl *Instance) { |
4986 | Pattern = Pattern->getCanonicalDecl(); |
4987 | |
4988 | do { |
4989 | Instance = Instance->getCanonicalDecl(); |
4990 | if (Pattern == Instance) return true; |
4991 | Instance = Instance->getInstantiatedFromMemberFunction(); |
4992 | } while (Instance); |
4993 | |
4994 | return false; |
4995 | } |
4996 | |
4997 | static bool isInstantiationOf(EnumDecl *Pattern, |
4998 | EnumDecl *Instance) { |
4999 | Pattern = Pattern->getCanonicalDecl(); |
5000 | |
5001 | do { |
5002 | Instance = Instance->getCanonicalDecl(); |
5003 | if (Pattern == Instance) return true; |
5004 | Instance = Instance->getInstantiatedFromMemberEnum(); |
5005 | } while (Instance); |
5006 | |
5007 | return false; |
5008 | } |
5009 | |
5010 | static bool isInstantiationOf(UsingShadowDecl *Pattern, |
5011 | UsingShadowDecl *Instance, |
5012 | ASTContext &C) { |
5013 | return declaresSameEntity(C.getInstantiatedFromUsingShadowDecl(Instance), |
5014 | Pattern); |
5015 | } |
5016 | |
5017 | static bool isInstantiationOf(UsingDecl *Pattern, UsingDecl *Instance, |
5018 | ASTContext &C) { |
5019 | return declaresSameEntity(C.getInstantiatedFromUsingDecl(Instance), Pattern); |
5020 | } |
5021 | |
5022 | template<typename T> |
5023 | static bool isInstantiationOfUnresolvedUsingDecl(T *Pattern, Decl *Other, |
5024 | ASTContext &Ctx) { |
5025 | |
5026 | |
5027 | |
5028 | |
5029 | |
5030 | |
5031 | bool OtherIsPackExpansion; |
5032 | NamedDecl *OtherFrom; |
5033 | if (auto *OtherUUD = dyn_cast<T>(Other)) { |
5034 | OtherIsPackExpansion = OtherUUD->isPackExpansion(); |
5035 | OtherFrom = Ctx.getInstantiatedFromUsingDecl(OtherUUD); |
5036 | } else if (auto *OtherUPD = dyn_cast<UsingPackDecl>(Other)) { |
5037 | OtherIsPackExpansion = true; |
5038 | OtherFrom = OtherUPD->getInstantiatedFromUsingDecl(); |
5039 | } else if (auto *OtherUD = dyn_cast<UsingDecl>(Other)) { |
5040 | OtherIsPackExpansion = false; |
5041 | OtherFrom = Ctx.getInstantiatedFromUsingDecl(OtherUD); |
5042 | } else { |
5043 | return false; |
5044 | } |
5045 | return Pattern->isPackExpansion() == OtherIsPackExpansion && |
5046 | declaresSameEntity(OtherFrom, Pattern); |
5047 | } |
5048 | |
5049 | static bool isInstantiationOfStaticDataMember(VarDecl *Pattern, |
5050 | VarDecl *Instance) { |
5051 | isStaticDataMember()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 5051, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Instance->isStaticDataMember()); |
5052 | |
5053 | Pattern = Pattern->getCanonicalDecl(); |
5054 | |
5055 | do { |
5056 | Instance = Instance->getCanonicalDecl(); |
5057 | if (Pattern == Instance) return true; |
5058 | Instance = Instance->getInstantiatedFromStaticDataMember(); |
5059 | } while (Instance); |
5060 | |
5061 | return false; |
5062 | } |
5063 | |
5064 | |
5065 | |
5066 | static bool isInstantiationOf(ASTContext &Ctx, NamedDecl *D, Decl *Other) { |
5067 | if (auto *UUD = dyn_cast<UnresolvedUsingTypenameDecl>(D)) |
5068 | return isInstantiationOfUnresolvedUsingDecl(UUD, Other, Ctx); |
5069 | |
5070 | if (auto *UUD = dyn_cast<UnresolvedUsingValueDecl>(D)) |
5071 | return isInstantiationOfUnresolvedUsingDecl(UUD, Other, Ctx); |
5072 | |
5073 | if (D->getKind() != Other->getKind()) |
5074 | return false; |
5075 | |
5076 | if (auto *Record = dyn_cast<CXXRecordDecl>(Other)) |
5077 | return isInstantiationOf(cast<CXXRecordDecl>(D), Record); |
5078 | |
5079 | if (auto *Function = dyn_cast<FunctionDecl>(Other)) |
5080 | return isInstantiationOf(cast<FunctionDecl>(D), Function); |
5081 | |
5082 | if (auto *Enum = dyn_cast<EnumDecl>(Other)) |
5083 | return isInstantiationOf(cast<EnumDecl>(D), Enum); |
5084 | |
5085 | if (auto *Var = dyn_cast<VarDecl>(Other)) |
5086 | if (Var->isStaticDataMember()) |
5087 | return isInstantiationOfStaticDataMember(cast<VarDecl>(D), Var); |
5088 | |
5089 | if (auto *Temp = dyn_cast<ClassTemplateDecl>(Other)) |
5090 | return isInstantiationOf(cast<ClassTemplateDecl>(D), Temp); |
5091 | |
5092 | if (auto *Temp = dyn_cast<FunctionTemplateDecl>(Other)) |
5093 | return isInstantiationOf(cast<FunctionTemplateDecl>(D), Temp); |
5094 | |
5095 | if (auto *PartialSpec = |
5096 | dyn_cast<ClassTemplatePartialSpecializationDecl>(Other)) |
5097 | return isInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(D), |
5098 | PartialSpec); |
5099 | |
5100 | if (auto *Field = dyn_cast<FieldDecl>(Other)) { |
5101 | if (!Field->getDeclName()) { |
5102 | |
5103 | return declaresSameEntity(Ctx.getInstantiatedFromUnnamedFieldDecl(Field), |
5104 | cast<FieldDecl>(D)); |
5105 | } |
5106 | } |
5107 | |
5108 | if (auto *Using = dyn_cast<UsingDecl>(Other)) |
5109 | return isInstantiationOf(cast<UsingDecl>(D), Using, Ctx); |
5110 | |
5111 | if (auto *Shadow = dyn_cast<UsingShadowDecl>(Other)) |
5112 | return isInstantiationOf(cast<UsingShadowDecl>(D), Shadow, Ctx); |
5113 | |
5114 | return D->getDeclName() && |
5115 | D->getDeclName() == cast<NamedDecl>(Other)->getDeclName(); |
5116 | } |
5117 | |
5118 | template<typename ForwardIterator> |
5119 | static NamedDecl *findInstantiationOf(ASTContext &Ctx, |
5120 | NamedDecl *D, |
5121 | ForwardIterator first, |
5122 | ForwardIterator last) { |
5123 | for (; first != last; ++first) |
5124 | if (isInstantiationOf(Ctx, D, *first)) |
5125 | return cast<NamedDecl>(*first); |
5126 | |
5127 | return nullptr; |
5128 | } |
5129 | |
5130 | |
5131 | |
5132 | |
5133 | |
5134 | DeclContext *Sema::FindInstantiatedContext(SourceLocation Loc, DeclContext* DC, |
5135 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
5136 | if (NamedDecl *D = dyn_cast<NamedDecl>(DC)) { |
5137 | Decl* ID = FindInstantiatedDecl(Loc, D, TemplateArgs, true); |
5138 | return cast_or_null<DeclContext>(ID); |
5139 | } else return DC; |
5140 | } |
5141 | |
5142 | |
5143 | |
5144 | |
5145 | |
5146 | |
5147 | |
5148 | |
5149 | |
5150 | |
5151 | |
5152 | |
5153 | |
5154 | |
5155 | |
5156 | |
5157 | |
5158 | |
5159 | |
5160 | |
5161 | |
5162 | |
5163 | |
5164 | |
5165 | |
5166 | |
5167 | |
5168 | NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, |
5169 | const MultiLevelTemplateArgumentList &TemplateArgs, |
5170 | bool FindingInstantiatedContext) { |
5171 | DeclContext *ParentDC = D->getDeclContext(); |
5172 | |
5173 | |
5174 | |
5175 | |
5176 | |
5177 | |
5178 | |
5179 | |
5180 | |
5181 | |
5182 | |
5183 | |
5184 | |
5185 | |
5186 | |
5187 | |
5188 | if (isa<ParmVarDecl>(D) && !ParentDC->isDependentContext() && |
5189 | !cast<ParmVarDecl>(D)->getType()->isInstantiationDependentType()) |
5190 | return D; |
5191 | if (isa<ParmVarDecl>(D) || isa<NonTypeTemplateParmDecl>(D) || |
5192 | isa<TemplateTypeParmDecl>(D) || isa<TemplateTemplateParmDecl>(D) || |
5193 | ((ParentDC->isFunctionOrMethod() || |
5194 | isa<OMPDeclareReductionDecl>(ParentDC) || |
5195 | isa<OMPDeclareMapperDecl>(ParentDC)) && |
5196 | ParentDC->isDependentContext()) || |
5197 | (isa<CXXRecordDecl>(D) && cast<CXXRecordDecl>(D)->isLambda())) { |
5198 | |
5199 | |
5200 | if (CurrentInstantiationScope) { |
5201 | if (auto Found = CurrentInstantiationScope->findInstantiationOf(D)) { |
5202 | if (Decl *FD = Found->dyn_cast<Decl *>()) |
5203 | return cast<NamedDecl>(FD); |
5204 | |
5205 | int PackIdx = ArgumentPackSubstitutionIndex; |
5206 | (0) . __assert_fail ("PackIdx != -1 && \"found declaration pack but not pack expanding\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 5207, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(PackIdx != -1 && |
5207 | (0) . __assert_fail ("PackIdx != -1 && \"found declaration pack but not pack expanding\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 5207, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "found declaration pack but not pack expanding"); |
5208 | typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack; |
5209 | return cast<NamedDecl>((*Found->get<DeclArgumentPack *>())[PackIdx]); |
5210 | } |
5211 | } |
5212 | |
5213 | |
5214 | |
5215 | |
5216 | if (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D) || |
5217 | isa<TemplateTemplateParmDecl>(D)) |
5218 | return D; |
5219 | |
5220 | if (D->isInvalidDecl()) |
5221 | return nullptr; |
5222 | |
5223 | |
5224 | |
5225 | |
5226 | |
5227 | |
5228 | |
5229 | |
5230 | |
5231 | |
5232 | |
5233 | |
5234 | |
5235 | |
5236 | bool NeedInstantiate = false; |
5237 | if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) |
5238 | NeedInstantiate = RD->isLocalClass(); |
5239 | else |
5240 | NeedInstantiate = isa<EnumDecl>(D); |
5241 | if (NeedInstantiate) { |
5242 | Decl *Inst = SubstDecl(D, CurContext, TemplateArgs); |
5243 | CurrentInstantiationScope->InstantiatedLocal(D, Inst); |
5244 | return cast<TypeDecl>(Inst); |
5245 | } |
5246 | |
5247 | |
5248 | |
5249 | (D)", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 5249, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isa<LabelDecl>(D)); |
5250 | |
5251 | Decl *Inst = SubstDecl(D, CurContext, TemplateArgs); |
5252 | (0) . __assert_fail ("Inst && \"Failed to instantiate label??\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 5252, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Inst && "Failed to instantiate label??"); |
5253 | |
5254 | CurrentInstantiationScope->InstantiatedLocal(D, Inst); |
5255 | return cast<LabelDecl>(Inst); |
5256 | } |
5257 | |
5258 | |
5259 | |
5260 | if (VarTemplateSpecializationDecl *VarSpec = |
5261 | dyn_cast<VarTemplateSpecializationDecl>(D)) { |
5262 | bool InstantiationDependent = false; |
5263 | const TemplateArgumentListInfo &VarTemplateArgs = |
5264 | VarSpec->getTemplateArgsInfo(); |
5265 | if (TemplateSpecializationType::anyDependentTemplateArguments( |
5266 | VarTemplateArgs, InstantiationDependent)) |
5267 | D = cast<NamedDecl>( |
5268 | SubstDecl(D, VarSpec->getDeclContext(), TemplateArgs)); |
5269 | return D; |
5270 | } |
5271 | |
5272 | if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) { |
5273 | if (!Record->isDependentContext()) |
5274 | return D; |
5275 | |
5276 | |
5277 | |
5278 | ClassTemplateDecl *ClassTemplate = Record->getDescribedClassTemplate(); |
5279 | if (ClassTemplate) |
5280 | ClassTemplate = ClassTemplate->getCanonicalDecl(); |
5281 | else if (ClassTemplatePartialSpecializationDecl *PartialSpec |
5282 | = dyn_cast<ClassTemplatePartialSpecializationDecl>(Record)) |
5283 | ClassTemplate = PartialSpec->getSpecializedTemplate()->getCanonicalDecl(); |
5284 | |
5285 | |
5286 | |
5287 | DeclContext *DC = CurContext; |
5288 | while (!DC->isFileContext()) { |
5289 | |
5290 | |
5291 | if (DC->Equals(Record)) |
5292 | return Record; |
5293 | |
5294 | if (CXXRecordDecl *InstRecord = dyn_cast<CXXRecordDecl>(DC)) { |
5295 | |
5296 | |
5297 | if (ClassTemplateSpecializationDecl *InstSpec |
5298 | = dyn_cast<ClassTemplateSpecializationDecl>(InstRecord)){ |
5299 | ClassTemplateDecl *SpecTemplate = InstSpec->getSpecializedTemplate(); |
5300 | if (ClassTemplate && isInstantiationOf(ClassTemplate, SpecTemplate)) |
5301 | return InstRecord; |
5302 | } |
5303 | |
5304 | |
5305 | if (isInstantiationOf(Record, InstRecord)) |
5306 | return InstRecord; |
5307 | } |
5308 | |
5309 | |
5310 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(DC)) { |
5311 | if (FD->getFriendObjectKind() && FD->getDeclContext()->isFileContext()){ |
5312 | DC = FD->getLexicalDeclContext(); |
5313 | continue; |
5314 | } |
5315 | |
5316 | |
5317 | auto *Guide = dyn_cast<CXXDeductionGuideDecl>(FD); |
5318 | if (Guide && Guide->isImplicit()) { |
5319 | TemplateDecl *TD = Guide->getDeducedTemplate(); |
5320 | |
5321 | TemplateArgumentListInfo Args(Loc, Loc); |
5322 | for (TemplateArgument Arg : TemplateArgs.getInnermost().take_front( |
5323 | TD->getTemplateParameters()->size())) { |
5324 | ArrayRef<TemplateArgument> Unpacked(Arg); |
5325 | if (Arg.getKind() == TemplateArgument::Pack) |
5326 | Unpacked = Arg.pack_elements(); |
5327 | for (TemplateArgument UnpackedArg : Unpacked) |
5328 | Args.addArgument( |
5329 | getTrivialTemplateArgumentLoc(UnpackedArg, QualType(), Loc)); |
5330 | } |
5331 | QualType T = CheckTemplateIdType(TemplateName(TD), Loc, Args); |
5332 | if (T.isNull()) |
5333 | return nullptr; |
5334 | auto *SubstRecord = T->getAsCXXRecordDecl(); |
5335 | (0) . __assert_fail ("SubstRecord && \"class template id not a class type?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 5335, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(SubstRecord && "class template id not a class type?"); |
5336 | |
5337 | |
5338 | |
5339 | |
5340 | |
5341 | if (FindingInstantiatedContext && |
5342 | usesPartialOrExplicitSpecialization( |
5343 | Loc, cast<ClassTemplateSpecializationDecl>(SubstRecord))) { |
5344 | Diag(Loc, diag::err_specialization_not_primary_template) |
5345 | << T << (SubstRecord->getTemplateSpecializationKind() == |
5346 | TSK_ExplicitSpecialization); |
5347 | return nullptr; |
5348 | } |
5349 | DC = SubstRecord; |
5350 | continue; |
5351 | } |
5352 | } |
5353 | |
5354 | DC = DC->getParent(); |
5355 | } |
5356 | |
5357 | |
5358 | |
5359 | } |
5360 | |
5361 | if (!ParentDC->isDependentContext()) |
5362 | return D; |
5363 | |
5364 | ParentDC = FindInstantiatedContext(Loc, ParentDC, TemplateArgs); |
5365 | if (!ParentDC) |
5366 | return nullptr; |
5367 | |
5368 | if (ParentDC != D->getDeclContext()) { |
5369 | |
5370 | |
5371 | |
5372 | |
5373 | |
5374 | |
5375 | bool IsBeingInstantiated = false; |
5376 | if (CXXRecordDecl *Spec = dyn_cast<CXXRecordDecl>(ParentDC)) { |
5377 | if (!Spec->isDependentContext()) { |
5378 | QualType T = Context.getTypeDeclType(Spec); |
5379 | const RecordType *Tag = T->getAs<RecordType>(); |
5380 | (0) . __assert_fail ("Tag && \"type of non-dependent record is not a RecordType\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 5380, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tag && "type of non-dependent record is not a RecordType"); |
5381 | if (Tag->isBeingDefined()) |
5382 | IsBeingInstantiated = true; |
5383 | if (!Tag->isBeingDefined() && |
5384 | RequireCompleteType(Loc, T, diag::err_incomplete_type)) |
5385 | return nullptr; |
5386 | |
5387 | ParentDC = Tag->getDecl(); |
5388 | } |
5389 | } |
5390 | |
5391 | NamedDecl *Result = nullptr; |
5392 | |
5393 | |
5394 | if (auto Name = D->getDeclName()) { |
5395 | DeclarationNameInfo NameInfo(Name, D->getLocation()); |
5396 | Name = SubstDeclarationNameInfo(NameInfo, TemplateArgs).getName(); |
5397 | if (!Name) |
5398 | return nullptr; |
5399 | DeclContext::lookup_result Found = ParentDC->lookup(Name); |
5400 | Result = findInstantiationOf(Context, D, Found.begin(), Found.end()); |
5401 | } else { |
5402 | |
5403 | |
5404 | |
5405 | |
5406 | |
5407 | |
5408 | |
5409 | |
5410 | Result = findInstantiationOf(Context, D, |
5411 | ParentDC->decls_begin(), |
5412 | ParentDC->decls_end()); |
5413 | } |
5414 | |
5415 | if (!Result) { |
5416 | if (isa<UsingShadowDecl>(D)) { |
5417 | |
5418 | } else if (Diags.hasErrorOccurred()) { |
5419 | |
5420 | |
5421 | |
5422 | } else if (IsBeingInstantiated) { |
5423 | |
5424 | |
5425 | |
5426 | |
5427 | |
5428 | Diag(Loc, diag::err_member_not_yet_instantiated) |
5429 | << D->getDeclName() |
5430 | << Context.getTypeDeclType(cast<CXXRecordDecl>(ParentDC)); |
5431 | Diag(D->getLocation(), diag::note_non_instantiated_member_here); |
5432 | } else if (EnumConstantDecl *ED = dyn_cast<EnumConstantDecl>(D)) { |
5433 | |
5434 | |
5435 | |
5436 | EnumDecl *Enum = cast<EnumDecl>(ED->getLexicalDeclContext()); |
5437 | EnumDecl *Spec = cast<EnumDecl>(FindInstantiatedDecl(Loc, Enum, |
5438 | TemplateArgs)); |
5439 | getTemplateSpecializationKind() == TSK_ExplicitSpecialization", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 5440, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Spec->getTemplateSpecializationKind() == |
5440 | getTemplateSpecializationKind() == TSK_ExplicitSpecialization", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 5440, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> TSK_ExplicitSpecialization); |
5441 | Diag(Loc, diag::err_enumerator_does_not_exist) |
5442 | << D->getDeclName() |
5443 | << Context.getTypeDeclType(cast<TypeDecl>(Spec->getDeclContext())); |
5444 | Diag(Spec->getLocation(), diag::note_enum_specialized_here) |
5445 | << Context.getTypeDeclType(Spec); |
5446 | } else { |
5447 | |
5448 | llvm_unreachable("Unable to find instantiation of declaration!"); |
5449 | } |
5450 | } |
5451 | |
5452 | D = Result; |
5453 | } |
5454 | |
5455 | return D; |
5456 | } |
5457 | |
5458 | |
5459 | |
5460 | void Sema::PerformPendingInstantiations(bool LocalOnly) { |
5461 | while (!PendingLocalImplicitInstantiations.empty() || |
5462 | (!LocalOnly && !PendingInstantiations.empty())) { |
5463 | PendingImplicitInstantiation Inst; |
5464 | |
5465 | if (PendingLocalImplicitInstantiations.empty()) { |
5466 | Inst = PendingInstantiations.front(); |
5467 | PendingInstantiations.pop_front(); |
5468 | } else { |
5469 | Inst = PendingLocalImplicitInstantiations.front(); |
5470 | PendingLocalImplicitInstantiations.pop_front(); |
5471 | } |
5472 | |
5473 | |
5474 | if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Inst.first)) { |
5475 | bool DefinitionRequired = Function->getTemplateSpecializationKind() == |
5476 | TSK_ExplicitInstantiationDefinition; |
5477 | if (Function->isMultiVersion()) { |
5478 | getASTContext().forEachMultiversionedFunctionVersion( |
5479 | Function, [this, Inst, DefinitionRequired](FunctionDecl *CurFD) { |
5480 | InstantiateFunctionDefinition( Inst.second, CurFD, true, |
5481 | DefinitionRequired, true); |
5482 | if (CurFD->isDefined()) |
5483 | CurFD->setInstantiationIsPending(false); |
5484 | }); |
5485 | } else { |
5486 | InstantiateFunctionDefinition( Inst.second, Function, true, |
5487 | DefinitionRequired, true); |
5488 | if (Function->isDefined()) |
5489 | Function->setInstantiationIsPending(false); |
5490 | } |
5491 | continue; |
5492 | } |
5493 | |
5494 | |
5495 | VarDecl *Var = cast<VarDecl>(Inst.first); |
5496 | |
5497 | (0) . __assert_fail ("(Var->isStaticDataMember() || isa(Var)) && \"Not a static data member, nor a variable template\" \" specialization?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 5500, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((Var->isStaticDataMember() || |
5498 | (0) . __assert_fail ("(Var->isStaticDataMember() || isa(Var)) && \"Not a static data member, nor a variable template\" \" specialization?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 5500, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> isa<VarTemplateSpecializationDecl>(Var)) && |
5499 | (0) . __assert_fail ("(Var->isStaticDataMember() || isa(Var)) && \"Not a static data member, nor a variable template\" \" specialization?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 5500, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Not a static data member, nor a variable template" |
5500 | (0) . __assert_fail ("(Var->isStaticDataMember() || isa(Var)) && \"Not a static data member, nor a variable template\" \" specialization?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp", 5500, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> " specialization?"); |
5501 | |
5502 | |
5503 | |
5504 | if (Var->getMostRecentDecl()->isInvalidDecl()) |
5505 | continue; |
5506 | |
5507 | |
5508 | |
5509 | switch (Var->getMostRecentDecl()->getTemplateSpecializationKind()) { |
5510 | case TSK_Undeclared: |
5511 | llvm_unreachable("Cannot instantitiate an undeclared specialization."); |
5512 | case TSK_ExplicitInstantiationDeclaration: |
5513 | case TSK_ExplicitSpecialization: |
5514 | continue; |
5515 | case TSK_ExplicitInstantiationDefinition: |
5516 | |
5517 | |
5518 | if (Var != Var->getMostRecentDecl()) |
5519 | continue; |
5520 | break; |
5521 | case TSK_ImplicitInstantiation: |
5522 | break; |
5523 | } |
5524 | |
5525 | PrettyDeclStackTraceEntry CrashInfo(Context, Var, SourceLocation(), |
5526 | "instantiating variable definition"); |
5527 | bool DefinitionRequired = Var->getTemplateSpecializationKind() == |
5528 | TSK_ExplicitInstantiationDefinition; |
5529 | |
5530 | |
5531 | |
5532 | InstantiateVariableDefinition( Inst.second, Var, true, |
5533 | DefinitionRequired, true); |
5534 | } |
5535 | } |
5536 | |
5537 | void Sema::PerformDependentDiagnostics(const DeclContext *Pattern, |
5538 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
5539 | for (auto DD : Pattern->ddiags()) { |
5540 | switch (DD->getKind()) { |
5541 | case DependentDiagnostic::Access: |
5542 | HandleDependentAccessCheck(*DD, TemplateArgs); |
5543 | break; |
5544 | } |
5545 | } |
5546 | } |
5547 | |