clang 10.0.0git

SemaTemplateInstantiateDecl.cpp
Go to the documentation of this file.
1 //===--- SemaTemplateInstantiateDecl.cpp - C++ Template Decl Instantiation ===/
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //===----------------------------------------------------------------------===/
7 //
8 // This file implements C++ template instantiation for declarations.
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 #include "llvm/Support/TimeProfiler.h"
27
28 using namespace clang;
29
30 static bool isDeclWithinFunction(const Decl *D) {
31 const DeclContext *DC = D->getDeclContext();
32 if (DC->isFunctionOrMethod())
33 return true;
34
35 if (DC->isRecord())
36 return cast<CXXRecordDecl>(DC)->isLocalClass();
37
38 return false;
39 }
40
41 template<typename DeclT>
42 static bool SubstQualifier(Sema &SemaRef, const DeclT *OldDecl, DeclT *NewDecl,
43 const MultiLevelTemplateArgumentList &TemplateArgs) {
44 if (!OldDecl->getQualifierLoc())
45 return false;
46
47 assert((NewDecl->getFriendObjectKind() ||
48 !OldDecl->getLexicalDeclContext()->isDependentContext()) &&
49 "non-friend with qualified name defined in dependent context");
50 Sema::ContextRAII SavedContext(
51 SemaRef,
52 const_cast<DeclContext *>(NewDecl->getFriendObjectKind()
53 ? NewDecl->getLexicalDeclContext()
54 : OldDecl->getLexicalDeclContext()));
55
56 NestedNameSpecifierLoc NewQualifierLoc
57 = SemaRef.SubstNestedNameSpecifierLoc(OldDecl->getQualifierLoc(),
58 TemplateArgs);
59
60 if (!NewQualifierLoc)
61 return true;
62
63 NewDecl->setQualifierInfo(NewQualifierLoc);
64 return false;
65 }
66
67 bool TemplateDeclInstantiator::SubstQualifier(const DeclaratorDecl *OldDecl,
68 DeclaratorDecl *NewDecl) {
69 return ::SubstQualifier(SemaRef, OldDecl, NewDecl, TemplateArgs);
70 }
71
72 bool TemplateDeclInstantiator::SubstQualifier(const TagDecl *OldDecl,
73 TagDecl *NewDecl) {
74 return ::SubstQualifier(SemaRef, OldDecl, NewDecl, TemplateArgs);
75 }
76
77 // Include attribute instantiation code.
78 #include "clang/Sema/AttrTemplateInstantiate.inc"
79
80 static void instantiateDependentAlignedAttr(
81 Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
82 const AlignedAttr *Aligned, Decl *New, bool IsPackExpansion) {
83 if (Aligned->isAlignmentExpr()) {
84 // The alignment expression is a constant expression.
85 EnterExpressionEvaluationContext Unevaluated(
86 S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
87 ExprResult Result = S.SubstExpr(Aligned->getAlignmentExpr(), TemplateArgs);
88 if (!Result.isInvalid())
89 S.AddAlignedAttr(New, *Aligned, Result.getAs<Expr>(), IsPackExpansion);
90 } else {
91 TypeSourceInfo *Result = S.SubstType(Aligned->getAlignmentType(),
92 TemplateArgs, Aligned->getLocation(),
93 DeclarationName());
94 if (Result)
95 S.AddAlignedAttr(New, *Aligned, Result, IsPackExpansion);
96 }
97 }
98
99 static void instantiateDependentAlignedAttr(
100 Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
101 const AlignedAttr *Aligned, Decl *New) {
102 if (!Aligned->isPackExpansion()) {
103 instantiateDependentAlignedAttr(S, TemplateArgs, Aligned, New, false);
104 return;
105 }
106
107 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
108 if (Aligned->isAlignmentExpr())
109 S.collectUnexpandedParameterPacks(Aligned->getAlignmentExpr(),
110 Unexpanded);
111 else
112 S.collectUnexpandedParameterPacks(Aligned->getAlignmentType()->getTypeLoc(),
113 Unexpanded);
114 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
115
116 // Determine whether we can expand this attribute pack yet.
117 bool Expand = true, RetainExpansion = false;
118 Optional<unsigned> NumExpansions;
119 // FIXME: Use the actual location of the ellipsis.
120 SourceLocation EllipsisLoc = Aligned->getLocation();
121 if (S.CheckParameterPacksForExpansion(EllipsisLoc, Aligned->getRange(),
122 Unexpanded, TemplateArgs, Expand,
123 RetainExpansion, NumExpansions))
124 return;
125
126 if (!Expand) {
127 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(S, -1);
128 instantiateDependentAlignedAttr(S, TemplateArgs, Aligned, New, true);
129 } else {
130 for (unsigned I = 0; I != *NumExpansions; ++I) {
131 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(S, I);
132 instantiateDependentAlignedAttr(S, TemplateArgs, Aligned, New, false);
133 }
134 }
135 }
136
137 static void instantiateDependentAssumeAlignedAttr(
138 Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
139 const AssumeAlignedAttr *Aligned, Decl *New) {
140 // The alignment expression is a constant expression.
141 EnterExpressionEvaluationContext Unevaluated(
142 S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
143
144 Expr *E, *OE = nullptr;
145 ExprResult Result = S.SubstExpr(Aligned->getAlignment(), TemplateArgs);
146 if (Result.isInvalid())
147 return;
148 E = Result.getAs<Expr>();
149
150 if (Aligned->getOffset()) {
151 Result = S.SubstExpr(Aligned->getOffset(), TemplateArgs);
152 if (Result.isInvalid())
153 return;
154 OE = Result.getAs<Expr>();
155 }
156
157 S.AddAssumeAlignedAttr(New, *Aligned, E, OE);
158 }
159
160 static void instantiateDependentAlignValueAttr(
161 Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
162 const AlignValueAttr *Aligned, Decl *New) {
163 // The alignment expression is a constant expression.
164 EnterExpressionEvaluationContext Unevaluated(
165 S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
166 ExprResult Result = S.SubstExpr(Aligned->getAlignment(), TemplateArgs);
167 if (!Result.isInvalid())
168 S.AddAlignValueAttr(New, *Aligned, Result.getAs<Expr>());
169 }
170
171 static void instantiateDependentAllocAlignAttr(
172 Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
173 const AllocAlignAttr *Align, Decl *New) {
174 Expr *Param = IntegerLiteral::Create(
175 S.getASTContext(),
176 llvm::APInt(64, Align->getParamIndex().getSourceIndex()),
177 S.getASTContext().UnsignedLongLongTy, Align->getLocation());
178 S.AddAllocAlignAttr(New, *Align, Param);
179 }
180
181 static Expr *instantiateDependentFunctionAttrCondition(
182 Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
183 const Attr *A, Expr *OldCond, const Decl *Tmpl, FunctionDecl *New) {
184 Expr *Cond = nullptr;
185 {
186 Sema::ContextRAII SwitchContext(S, New);
187 EnterExpressionEvaluationContext Unevaluated(
188 S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
189 ExprResult Result = S.SubstExpr(OldCond, TemplateArgs);
190 if (Result.isInvalid())
191 return nullptr;
192 Cond = Result.getAs<Expr>();
193 }
194 if (!Cond->isTypeDependent()) {
195 ExprResult Converted = S.PerformContextuallyConvertToBool(Cond);
196 if (Converted.isInvalid())
197 return nullptr;
198 Cond = Converted.get();
199 }
200
201 SmallVector<PartialDiagnosticAt, 8> Diags;
202 if (OldCond->isValueDependent() && !Cond->isValueDependent() &&
203 !Expr::isPotentialConstantExprUnevaluated(Cond, New, Diags)) {
204 S.Diag(A->getLocation(), diag::err_attr_cond_never_constant_expr) << A;
205 for (const auto &P : Diags)
206 S.Diag(P.first, P.second);
207 return nullptr;
208 }
209 return Cond;
210 }
211
212 static void instantiateDependentEnableIfAttr(
213 Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
214 const EnableIfAttr *EIA, const Decl *Tmpl, FunctionDecl *New) {
215 Expr *Cond = instantiateDependentFunctionAttrCondition(
216 S, TemplateArgs, EIA, EIA->getCond(), Tmpl, New);
217
218 if (Cond)
219 New->addAttr(new (S.getASTContext()) EnableIfAttr(S.getASTContext(), *EIA,
220 Cond, EIA->getMessage()));
221 }
222
223 static void instantiateDependentDiagnoseIfAttr(
224 Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
225 const DiagnoseIfAttr *DIA, const Decl *Tmpl, FunctionDecl *New) {
226 Expr *Cond = instantiateDependentFunctionAttrCondition(
227 S, TemplateArgs, DIA, DIA->getCond(), Tmpl, New);
228
229 if (Cond)
230 New->addAttr(new (S.getASTContext()) DiagnoseIfAttr(
231 S.getASTContext(), *DIA, Cond, DIA->getMessage(),
232 DIA->getDiagnosticType(), DIA->getArgDependent(), New));
233 }
234
235 // Constructs and adds to New a new instance of CUDALaunchBoundsAttr using
236 // template A as the base and arguments from TemplateArgs.
237 static void instantiateDependentCUDALaunchBoundsAttr(
238 Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
239 const CUDALaunchBoundsAttr &Attr, Decl *New) {
240 // The alignment expression is a constant expression.
241 EnterExpressionEvaluationContext Unevaluated(
242 S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
243
244 ExprResult Result = S.SubstExpr(Attr.getMaxThreads(), TemplateArgs);
245 if (Result.isInvalid())
246 return;
247 Expr *MaxThreads = Result.getAs<Expr>();
248
249 Expr *MinBlocks = nullptr;
250 if (Attr.getMinBlocks()) {
251 Result = S.SubstExpr(Attr.getMinBlocks(), TemplateArgs);
252 if (Result.isInvalid())
253 return;
254 MinBlocks = Result.getAs<Expr>();
255 }
256
257 S.AddLaunchBoundsAttr(New, Attr, MaxThreads, MinBlocks);
258 }
259
260 static void
261 instantiateDependentModeAttr(Sema &S,
262 const MultiLevelTemplateArgumentList &TemplateArgs,
263 const ModeAttr &Attr, Decl *New) {
264 S.AddModeAttr(New, Attr, Attr.getMode(),
265 /*InInstantiation=*/true);
266 }
267
268 /// Instantiation of 'declare simd' attribute and its arguments.
269 static void instantiateOMPDeclareSimdDeclAttr(
270 Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
271 const OMPDeclareSimdDeclAttr &Attr, Decl *New) {
272 // Allow 'this' in clauses with varlists.
273 if (auto *FTD = dyn_cast<FunctionTemplateDecl>(New))
274 New = FTD->getTemplatedDecl();
275 auto *FD = cast<FunctionDecl>(New);
276 auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(FD->getDeclContext());
277 SmallVector<Expr *, 4> Uniforms, Aligneds, Alignments, Linears, Steps;
278 SmallVector<unsigned, 4> LinModifiers;
279
280 auto SubstExpr = [&](Expr *E) -> ExprResult {
281 if (auto *DRE = dyn_cast<DeclRefExpr>(E->IgnoreParenImpCasts()))
282 if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) {
283 Sema::ContextRAII SavedContext(S, FD);
284 LocalInstantiationScope Local(S);
285 if (FD->getNumParams() > PVD->getFunctionScopeIndex())
286 Local.InstantiatedLocal(
287 PVD, FD->getParamDecl(PVD->getFunctionScopeIndex()));
288 return S.SubstExpr(E, TemplateArgs);
289 }
290 Sema::CXXThisScopeRAII ThisScope(S, ThisContext, Qualifiers(),
291 FD->isCXXInstanceMember());
292 return S.SubstExpr(E, TemplateArgs);
293 };
294
295 // Substitute a single OpenMP clause, which is a potentially-evaluated
296 // full-expression.
297 auto Subst = [&](Expr *E) -> ExprResult {
298 EnterExpressionEvaluationContext Evaluated(
299 S, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
300 ExprResult Res = SubstExpr(E);
301 if (Res.isInvalid())
302 return Res;
303 return S.ActOnFinishFullExpr(Res.get(), false);
304 };
305
306 ExprResult Simdlen;
307 if (auto *E = Attr.getSimdlen())
308 Simdlen = Subst(E);
309
310 if (Attr.uniforms_size() > 0) {
311 for(auto *E : Attr.uniforms()) {
312 ExprResult Inst = Subst(E);
313 if (Inst.isInvalid())
314 continue;
315 Uniforms.push_back(Inst.get());
316 }
317 }
318
319 auto AI = Attr.alignments_begin();
320 for (auto *E : Attr.aligneds()) {
321 ExprResult Inst = Subst(E);
322 if (Inst.isInvalid())
323 continue;
324 Aligneds.push_back(Inst.get());
325 Inst = ExprEmpty();
326 if (*AI)
327 Inst = S.SubstExpr(*AI, TemplateArgs);
328 Alignments.push_back(Inst.get());
329 ++AI;
330 }
331
332 auto SI = Attr.steps_begin();
333 for (auto *E : Attr.linears()) {
334 ExprResult Inst = Subst(E);
335 if (Inst.isInvalid())
336 continue;
337 Linears.push_back(Inst.get());
338 Inst = ExprEmpty();
339 if (*SI)
340 Inst = S.SubstExpr(*SI, TemplateArgs);
341 Steps.push_back(Inst.get());
342 ++SI;
343 }
344 LinModifiers.append(Attr.modifiers_begin(), Attr.modifiers_end());
345 (void)S.ActOnOpenMPDeclareSimdDirective(
346 S.ConvertDeclToDeclGroup(New), Attr.getBranchState(), Simdlen.get(),
347 Uniforms, Aligneds, Alignments, Linears, LinModifiers, Steps,
348 Attr.getRange());
349 }
350
351 /// Instantiation of 'declare variant' attribute and its arguments.
352 static void instantiateOMPDeclareVariantAttr(
353 Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
354 const OMPDeclareVariantAttr &Attr, Decl *New) {
355 // Allow 'this' in clauses with varlists.
356 if (auto *FTD = dyn_cast<FunctionTemplateDecl>(New))
357 New = FTD->getTemplatedDecl();
358 auto *FD = cast<FunctionDecl>(New);
359 auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(FD->getDeclContext());
360
361 auto &&SubstExpr = [FD, ThisContext, &S, &TemplateArgs](Expr *E) {
362 if (auto *DRE = dyn_cast<DeclRefExpr>(E->IgnoreParenImpCasts()))
363 if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) {
364 Sema::ContextRAII SavedContext(S, FD);
365 LocalInstantiationScope Local(S);
366 if (FD->getNumParams() > PVD->getFunctionScopeIndex())
367 Local.InstantiatedLocal(
368 PVD, FD->getParamDecl(PVD->getFunctionScopeIndex()));
369 return S.SubstExpr(E, TemplateArgs);
370 }
371 Sema::CXXThisScopeRAII ThisScope(S, ThisContext, Qualifiers(),
372 FD->isCXXInstanceMember());
373 return S.SubstExpr(E, TemplateArgs);
374 };
375
376 // Substitute a single OpenMP clause, which is a potentially-evaluated
377 // full-expression.
378 auto &&Subst = [&SubstExpr, &S](Expr *E) {
379 EnterExpressionEvaluationContext Evaluated(
380 S, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
381 ExprResult Res = SubstExpr(E);
382 if (Res.isInvalid())
383 return Res;
384 return S.ActOnFinishFullExpr(Res.get(), false);
385 };
386
387 ExprResult VariantFuncRef;
388 if (Expr *E = Attr.getVariantFuncRef()) {
389 // Do not mark function as is used to prevent its emission if this is the
390 // only place where it is used.
391 EnterExpressionEvaluationContext Unevaluated(
392 S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
393 VariantFuncRef = Subst(E);
394 }
395
396 // Check function/variant ref.
397 Optional<std::pair<FunctionDecl *, Expr *>> DeclVarData =
398 S.checkOpenMPDeclareVariantFunction(
399 S.ConvertDeclToDeclGroup(New), VariantFuncRef.get(), Attr.getRange());
400 if (!DeclVarData)
401 return;
402 SmallVector<Sema::OMPCtxSelectorData, 4> Data;
403 for (unsigned I = 0, E = Attr.scores_size(); I < E; ++I) {
404 ExprResult Score;
405 if (Expr *E = *std::next(Attr.scores_begin(), I))
406 Score = Subst(E);
407 // Instantiate the attribute.
408 auto CtxSet = static_cast<OpenMPContextSelectorSetKind>(
409 *std::next(Attr.ctxSelectorSets_begin(), I));
410 auto Ctx = static_cast<OpenMPContextSelectorKind>(
411 *std::next(Attr.ctxSelectors_begin(), I));
412 switch (CtxSet) {
413 case OMP_CTX_SET_implementation:
414 switch (Ctx) {
415 case OMP_CTX_vendor:
416 Data.emplace_back(CtxSet, Ctx, Score, Attr.implVendors());
417 break;
418 case OMP_CTX_kind:
419 case OMP_CTX_unknown:
420 llvm_unreachable("Unexpected context selector kind.");
421 }
422 break;
423 case OMP_CTX_SET_device:
424 switch (Ctx) {
425 case OMP_CTX_kind:
426 Data.emplace_back(CtxSet, Ctx, Score, Attr.deviceKinds());
427 break;
428 case OMP_CTX_vendor:
429 case OMP_CTX_unknown:
430 llvm_unreachable("Unexpected context selector kind.");
431 }
432 break;
433 case OMP_CTX_SET_unknown:
434 llvm_unreachable("Unexpected context selector set kind.");
435 }
436 }
437 S.ActOnOpenMPDeclareVariantDirective(DeclVarData.getValue().first,
438 DeclVarData.getValue().second,
439 Attr.getRange(), Data);
440 }
441
442 static void instantiateDependentAMDGPUFlatWorkGroupSizeAttr(
443 Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
444 const AMDGPUFlatWorkGroupSizeAttr &Attr, Decl *New) {
445 // Both min and max expression are constant expressions.
446 EnterExpressionEvaluationContext Unevaluated(
447 S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
448
449 ExprResult Result = S.SubstExpr(Attr.getMin(), TemplateArgs);
450 if (Result.isInvalid())
451 return;
452 Expr *MinExpr = Result.getAs<Expr>();
453
454 Result = S.SubstExpr(Attr.getMax(), TemplateArgs);
455 if (Result.isInvalid())
456 return;
457 Expr *MaxExpr = Result.getAs<Expr>();
458
459 S.addAMDGPUFlatWorkGroupSizeAttr(New, Attr, MinExpr, MaxExpr);
460 }
461
462 static ExplicitSpecifier
463 instantiateExplicitSpecifier(Sema &S,
464 const MultiLevelTemplateArgumentList &TemplateArgs,
465 ExplicitSpecifier ES, FunctionDecl *New) {
466 if (!ES.getExpr())
467 return ES;
468 Expr *OldCond = ES.getExpr();
469 Expr *Cond = nullptr;
470 {
471 EnterExpressionEvaluationContext Unevaluated(
472 S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
473 ExprResult SubstResult = S.SubstExpr(OldCond, TemplateArgs);
474 if (SubstResult.isInvalid()) {
475 return ExplicitSpecifier::Invalid();
476 }
477 Cond = SubstResult.get();
478 }
479 ExplicitSpecifier Result(Cond, ES.getKind());
480 if (!Cond->isTypeDependent())
481 S.tryResolveExplicitSpecifier(Result);
482 return Result;
483 }
484
485 static void instantiateDependentAMDGPUWavesPerEUAttr(
486 Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
487 const AMDGPUWavesPerEUAttr &Attr, Decl *New) {
488 // Both min and max expression are constant expressions.
489 EnterExpressionEvaluationContext Unevaluated(
490 S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
491
492 ExprResult Result = S.SubstExpr(Attr.getMin(), TemplateArgs);
493 if (Result.isInvalid())
494 return;
495 Expr *MinExpr = Result.getAs<Expr>();
496
497 Expr *MaxExpr = nullptr;
498 if (auto Max = Attr.getMax()) {
499 Result = S.SubstExpr(Max, TemplateArgs);
500 if (Result.isInvalid())
501 return;
502 MaxExpr = Result.getAs<Expr>();
503 }
504
505 S.addAMDGPUWavesPerEUAttr(New, Attr, MinExpr, MaxExpr);
506 }
507
508 void Sema::InstantiateAttrsForDecl(
509 const MultiLevelTemplateArgumentList &TemplateArgs, const Decl *Tmpl,
510 Decl *New, LateInstantiatedAttrVec *LateAttrs,
511 LocalInstantiationScope *OuterMostScope) {
512 if (NamedDecl *ND = dyn_cast<NamedDecl>(New)) {
513 for (const auto *TmplAttr : Tmpl->attrs()) {
514 // FIXME: If any of the special case versions from InstantiateAttrs become
515 // applicable to template declaration, we'll need to add them here.
516 CXXThisScopeRAII ThisScope(
517 *this, dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext()),
518 Qualifiers(), ND->isCXXInstanceMember());
519
520 Attr *NewAttr = sema::instantiateTemplateAttributeForDecl(
521 TmplAttr, Context, *this, TemplateArgs);
522 if (NewAttr)
523 New->addAttr(NewAttr);
524 }
525 }
526 }
527
528 static Sema::RetainOwnershipKind
529 attrToRetainOwnershipKind(const Attr *A) {
530 switch (A->getKind()) {
531 case clang::attr::CFConsumed:
532 return Sema::RetainOwnershipKind::CF;
533 case clang::attr::OSConsumed:
534 return Sema::RetainOwnershipKind::OS;
535 case clang::attr::NSConsumed:
536 return Sema::RetainOwnershipKind::NS;
537 default:
538 llvm_unreachable("Wrong argument supplied");
539 }
540 }
541
542 void Sema::InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
543 const Decl *Tmpl, Decl *New,
544 LateInstantiatedAttrVec *LateAttrs,
545 LocalInstantiationScope *OuterMostScope) {
546 for (const auto *TmplAttr : Tmpl->attrs()) {
547 // FIXME: This should be generalized to more than just the AlignedAttr.
548 const AlignedAttr *Aligned = dyn_cast<AlignedAttr>(TmplAttr);
549 if (Aligned && Aligned->isAlignmentDependent()) {
550 instantiateDependentAlignedAttr(*this, TemplateArgs, Aligned, New);
551 continue;
552 }
553
554 if (const auto *AssumeAligned = dyn_cast<AssumeAlignedAttr>(TmplAttr)) {
555 instantiateDependentAssumeAlignedAttr(*this, TemplateArgs, AssumeAligned, New);
556 continue;
557 }
558
559 if (const auto *AlignValue = dyn_cast<AlignValueAttr>(TmplAttr)) {
560 instantiateDependentAlignValueAttr(*this, TemplateArgs, AlignValue, New);
561 continue;
562 }
563
564 if (const auto *AllocAlign = dyn_cast<AllocAlignAttr>(TmplAttr)) {
565 instantiateDependentAllocAlignAttr(*this, TemplateArgs, AllocAlign, New);
566 continue;
567 }
568
569
570 if (const auto *EnableIf = dyn_cast<EnableIfAttr>(TmplAttr)) {
571 instantiateDependentEnableIfAttr(*this, TemplateArgs, EnableIf, Tmpl,
572 cast<FunctionDecl>(New));
573 continue;
574 }
575
576 if (const auto *DiagnoseIf = dyn_cast<DiagnoseIfAttr>(TmplAttr)) {
577 instantiateDependentDiagnoseIfAttr(*this, TemplateArgs, DiagnoseIf, Tmpl,
578 cast<FunctionDecl>(New));
579 continue;
580 }
581
582 if (const auto *CUDALaunchBounds =
583 dyn_cast<CUDALaunchBoundsAttr>(TmplAttr)) {
584 instantiateDependentCUDALaunchBoundsAttr(*this, TemplateArgs,
585 *CUDALaunchBounds, New);
586 continue;
587 }
588
589 if (const auto *Mode = dyn_cast<ModeAttr>(TmplAttr)) {
590 instantiateDependentModeAttr(*this, TemplateArgs, *Mode, New);
591 continue;
592 }
593
594 if (const auto *OMPAttr = dyn_cast<OMPDeclareSimdDeclAttr>(TmplAttr)) {
595 instantiateOMPDeclareSimdDeclAttr(*this, TemplateArgs, *OMPAttr, New);
596 continue;
597 }
598
599 if (const auto *OMPAttr = dyn_cast<OMPDeclareVariantAttr>(TmplAttr)) {
600 instantiateOMPDeclareVariantAttr(*this, TemplateArgs, *OMPAttr, New);
601 continue;
602 }
603
604 if (const auto *AMDGPUFlatWorkGroupSize =
605 dyn_cast<AMDGPUFlatWorkGroupSizeAttr>(TmplAttr)) {
606 instantiateDependentAMDGPUFlatWorkGroupSizeAttr(
607 *this, TemplateArgs, *AMDGPUFlatWorkGroupSize, New);
608 }
609
610 if (const auto *AMDGPUFlatWorkGroupSize =
611 dyn_cast<AMDGPUWavesPerEUAttr>(TmplAttr)) {
612 instantiateDependentAMDGPUWavesPerEUAttr(*this, TemplateArgs,
613 *AMDGPUFlatWorkGroupSize, New);
614 }
615
616 // Existing DLL attribute on the instantiation takes precedence.
617 if (TmplAttr->getKind() == attr::DLLExport ||
618 TmplAttr->getKind() == attr::DLLImport) {
619 if (New->hasAttr<DLLExportAttr>() || New->hasAttr<DLLImportAttr>()) {
620 continue;
621 }
622 }
623
624 if (const auto *ABIAttr = dyn_cast<ParameterABIAttr>(TmplAttr)) {
625 AddParameterABIAttr(New, *ABIAttr, ABIAttr->getABI());
626 continue;
627 }
628
629 if (isa<NSConsumedAttr>(TmplAttr) || isa<OSConsumedAttr>(TmplAttr) ||
630 isa<CFConsumedAttr>(TmplAttr)) {
631 AddXConsumedAttr(New, *TmplAttr, attrToRetainOwnershipKind(TmplAttr),
632 /*template instantiation=*/true);
633 continue;
634 }
635
636 if (auto *A = dyn_cast<PointerAttr>(TmplAttr)) {
637 if (!New->hasAttr<PointerAttr>())
638 New->addAttr(A->clone(Context));
639 continue;
640 }
641
642 if (auto *A = dyn_cast<OwnerAttr>(TmplAttr)) {
643 if (!New->hasAttr<OwnerAttr>())
644 New->addAttr(A->clone(Context));
645 continue;
646 }
647
648 assert(!TmplAttr->isPackExpansion());
649 if (TmplAttr->isLateParsed() && LateAttrs) {
650 // Late parsed attributes must be instantiated and attached after the
651 // enclosing class has been instantiated. See Sema::InstantiateClass.
652 LocalInstantiationScope *Saved = nullptr;
653 if (CurrentInstantiationScope)
654 Saved = CurrentInstantiationScope->cloneScopes(OuterMostScope);
655 LateAttrs->push_back(LateInstantiatedAttribute(TmplAttr, Saved, New));
656 } else {
657 // Allow 'this' within late-parsed attributes.
658 auto *ND = cast<NamedDecl>(New);
659 auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext());
660 CXXThisScopeRAII ThisScope(*this, ThisContext, Qualifiers(),
661 ND->isCXXInstanceMember());
662
663 Attr *NewAttr = sema::instantiateTemplateAttribute(TmplAttr, Context,
664 *this, TemplateArgs);
665 if (NewAttr)
666 New->addAttr(NewAttr);
667 }
668 }
669 }
670
671 /// Get the previous declaration of a declaration for the purposes of template
672 /// instantiation. If this finds a previous declaration, then the previous
673 /// declaration of the instantiation of D should be an instantiation of the
674 /// result of this function.
675 template<typename DeclT>
676 static DeclT *getPreviousDeclForInstantiation(DeclT *D) {
677 DeclT *Result = D->getPreviousDecl();
678
679 // If the declaration is within a class, and the previous declaration was
680 // merged from a different definition of that class, then we don't have a
681 // previous declaration for the purpose of template instantiation.
682 if (Result && isa<CXXRecordDecl>(D->getDeclContext()) &&
683 D->getLexicalDeclContext() != Result->getLexicalDeclContext())
684 return nullptr;
685
686 return Result;
687 }
688
689 Decl *
690 TemplateDeclInstantiator::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
691 llvm_unreachable("Translation units cannot be instantiated");
692 }
693
694 Decl *
695 TemplateDeclInstantiator::VisitPragmaCommentDecl(PragmaCommentDecl *D) {
696 llvm_unreachable("pragma comment cannot be instantiated");
697 }
698
699 Decl *TemplateDeclInstantiator::VisitPragmaDetectMismatchDecl(
700 PragmaDetectMismatchDecl *D) {
701 llvm_unreachable("pragma comment cannot be instantiated");
702 }
703
704 Decl *
705 TemplateDeclInstantiator::VisitExternCContextDecl(ExternCContextDecl *D) {
706 llvm_unreachable("extern \"C\" context cannot be instantiated");
707 }
708
709 Decl *
710 TemplateDeclInstantiator::VisitLabelDecl(LabelDecl *D) {
711 LabelDecl *Inst = LabelDecl::Create(SemaRef.Context, Owner, D->getLocation(),
712 D->getIdentifier());
713 Owner->addDecl(Inst);
714 return Inst;
715 }
716
717 Decl *
718 TemplateDeclInstantiator::VisitNamespaceDecl(NamespaceDecl *D) {
719 llvm_unreachable("Namespaces cannot be instantiated");
720 }
721
722 Decl *
723 TemplateDeclInstantiator::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
724 NamespaceAliasDecl *Inst
725 = NamespaceAliasDecl::Create(SemaRef.Context, Owner,
726 D->getNamespaceLoc(),
727 D->getAliasLoc(),
728 D->getIdentifier(),
729 D->getQualifierLoc(),
730 D->getTargetNameLoc(),
731 D->getNamespace());
732 Owner->addDecl(Inst);
733 return Inst;
734 }
735
736 Decl *TemplateDeclInstantiator::InstantiateTypedefNameDecl(TypedefNameDecl *D,
737 bool IsTypeAlias) {
738 bool Invalid = false;
739 TypeSourceInfo *DI = D->getTypeSourceInfo();
740 if (DI->getType()->isInstantiationDependentType() ||
741 DI->getType()->isVariablyModifiedType()) {
742 DI = SemaRef.SubstType(DI, TemplateArgs,
743 D->getLocation(), D->getDeclName());
744 if (!DI) {
745 Invalid = true;
746 DI = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.Context.IntTy);
747 }
748 } else {
749 SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), DI->getType());
750 }
751
752 // HACK: g++ has a bug where it gets the value kind of ?: wrong.
753 // libstdc++ relies upon this bug in its implementation of common_type.
754 // If we happen to be processing that implementation, fake up the g++ ?:
755 // semantics. See LWG issue 2141 for more information on the bug.
756 const DecltypeType *DT = DI->getType()->getAs<DecltypeType>();
757 CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D->getDeclContext());
758 if (DT && RD && isa<ConditionalOperator>(DT->getUnderlyingExpr()) &&
759 DT->isReferenceType() &&
760 RD->getEnclosingNamespaceContext() == SemaRef.getStdNamespace() &&
761 RD->getIdentifier() && RD->getIdentifier()->isStr("common_type") &&
762 D->getIdentifier() && D->getIdentifier()->isStr("type") &&
763 SemaRef.getSourceManager().isInSystemHeader(D->getBeginLoc()))
764 // Fold it to the (non-reference) type which g++ would have produced.
765 DI = SemaRef.Context.getTrivialTypeSourceInfo(
766 DI->getType().getNonReferenceType());
767
768 // Create the new typedef
769 TypedefNameDecl *Typedef;
770 if (IsTypeAlias)
771 Typedef = TypeAliasDecl::Create(SemaRef.Context, Owner, D->getBeginLoc(),
772 D->getLocation(), D->getIdentifier(), DI);
773 else
774 Typedef = TypedefDecl::Create(SemaRef.Context, Owner, D->getBeginLoc(),
775 D->getLocation(), D->getIdentifier(), DI);
776 if (Invalid)
777 Typedef->setInvalidDecl();
778
779 // If the old typedef was the name for linkage purposes of an anonymous
780 // tag decl, re-establish that relationship for the new typedef.
781 if (const TagType *oldTagType = D->getUnderlyingType()->getAs<TagType>()) {
782 TagDecl *oldTag = oldTagType->getDecl();
783 if (oldTag->getTypedefNameForAnonDecl() == D && !Invalid) {
784 TagDecl *newTag = DI->getType()->castAs<TagType>()->getDecl();
785 assert(!newTag->hasNameForLinkage());
786 newTag->setTypedefNameForAnonDecl(Typedef);
787 }
788 }
789
790 if (TypedefNameDecl *Prev = getPreviousDeclForInstantiation(D)) {
791 NamedDecl *InstPrev = SemaRef.FindInstantiatedDecl(D->getLocation(), Prev,
792 TemplateArgs);
793 if (!InstPrev)
794 return nullptr;
795
796 TypedefNameDecl *InstPrevTypedef = cast<TypedefNameDecl>(InstPrev);
797
798 // If the typedef types are not identical, reject them.
799 SemaRef.isIncompatibleTypedef(InstPrevTypedef, Typedef);
800
801 Typedef->setPreviousDecl(InstPrevTypedef);
802 }
803
804 SemaRef.InstantiateAttrs(TemplateArgs, D, Typedef);
805
806 if (D->getUnderlyingType()->getAs<DependentNameType>())
807 SemaRef.inferGslPointerAttribute(Typedef);
808
809 Typedef->setAccess(D->getAccess());
810
811 return Typedef;
812 }
813
814 Decl *TemplateDeclInstantiator::VisitTypedefDecl(TypedefDecl *D) {
815 Decl *Typedef = InstantiateTypedefNameDecl(D, /*IsTypeAlias=*/false);
816 if (Typedef)
817 Owner->addDecl(Typedef);
818 return Typedef;
819 }
820
821 Decl *TemplateDeclInstantiator::VisitTypeAliasDecl(TypeAliasDecl *D) {
822 Decl *Typedef = InstantiateTypedefNameDecl(D, /*IsTypeAlias=*/true);
823 if (Typedef)
824 Owner->addDecl(Typedef);
825 return Typedef;
826 }
827
828 Decl *
829 TemplateDeclInstantiator::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
830 // Create a local instantiation scope for this type alias template, which
831 // will contain the instantiations of the template parameters.
832 LocalInstantiationScope Scope(SemaRef);
833
834 TemplateParameterList *TempParams = D->getTemplateParameters();
835 TemplateParameterList *InstParams = SubstTemplateParams(TempParams);
836 if (!InstParams)
837 return nullptr;
838
839 TypeAliasDecl *Pattern = D->getTemplatedDecl();
840
841 TypeAliasTemplateDecl *PrevAliasTemplate = nullptr;
842 if (getPreviousDeclForInstantiation<TypedefNameDecl>(Pattern)) {
843 DeclContext::lookup_result Found = Owner->lookup(Pattern->getDeclName());
844 if (!Found.empty()) {
845 PrevAliasTemplate = dyn_cast<TypeAliasTemplateDecl>(Found.front());
846 }
847 }
848
849 TypeAliasDecl *AliasInst = cast_or_null<TypeAliasDecl>(
850 InstantiateTypedefNameDecl(Pattern, /*IsTypeAlias=*/true));
851 if (!AliasInst)
852 return nullptr;
853
854 TypeAliasTemplateDecl *Inst
855 = TypeAliasTemplateDecl::Create(SemaRef.Context, Owner, D->getLocation(),
856 D->getDeclName(), InstParams, AliasInst);
857 AliasInst->setDescribedAliasTemplate(Inst);
858 if (PrevAliasTemplate)
859 Inst->setPreviousDecl(PrevAliasTemplate);
860
861 Inst->setAccess(D->getAccess());
862
863 if (!PrevAliasTemplate)
864 Inst->setInstantiatedFromMemberTemplate(D);
865
866 Owner->addDecl(Inst);
867
868 return Inst;
869 }
870
871 Decl *TemplateDeclInstantiator::VisitBindingDecl(BindingDecl *D) {
872 auto *NewBD = BindingDecl::Create(SemaRef.Context, Owner, D->getLocation(),
873 D->getIdentifier());
874 NewBD->setReferenced(D->isReferenced());
875 SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, NewBD);
876 return NewBD;
877 }
878
879 Decl *TemplateDeclInstantiator::VisitDecompositionDecl(DecompositionDecl *D) {
880 // Transform the bindings first.
881 SmallVector<BindingDecl*, 16> NewBindings;
882 for (auto *OldBD : D->bindings())
883 NewBindings.push_back(cast<BindingDecl>(VisitBindingDecl(OldBD)));
884 ArrayRef<BindingDecl*> NewBindingArray = NewBindings;
885
886 auto *NewDD = cast_or_null<DecompositionDecl>(
887 VisitVarDecl(D, /*InstantiatingVarTemplate=*/false, &NewBindingArray));
888
889 if (!NewDD || NewDD->isInvalidDecl())
890 for (auto *NewBD : NewBindings)
891 NewBD->setInvalidDecl();
892
893 return NewDD;
894 }
895
896 Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) {
897 return VisitVarDecl(D, /*InstantiatingVarTemplate=*/false);
898 }
899
900 Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D,
901 bool InstantiatingVarTemplate,
902 ArrayRef<BindingDecl*> *Bindings) {
903
904 // Do substitution on the type of the declaration
905 TypeSourceInfo *DI = SemaRef.SubstType(
906 D->getTypeSourceInfo(), TemplateArgs, D->getTypeSpecStartLoc(),
907 D->getDeclName(), /*AllowDeducedTST*/true);
908 if (!DI)
909 return nullptr;
910
911 if (DI->getType()->isFunctionType()) {
912 SemaRef.Diag(D->getLocation(), diag::err_variable_instantiates_to_function)
913 << D->isStaticDataMember() << DI->getType();
914 return nullptr;
915 }
916
917 DeclContext *DC = Owner;
918 if (D->isLocalExternDecl())
919 SemaRef.adjustContextForLocalExternDecl(DC);
920
921 // Build the instantiated declaration.
922 VarDecl *Var;
923 if (Bindings)
924 Var = DecompositionDecl::Create(SemaRef.Context, DC, D->getInnerLocStart(),
925 D->getLocation(), DI->getType(), DI,
926 D->getStorageClass(), *Bindings);
927 else
928 Var = VarDecl::Create(SemaRef.Context, DC, D->getInnerLocStart(),
929 D->getLocation(), D->getIdentifier(), DI->getType(),
930 DI, D->getStorageClass());
931
932 // In ARC, infer 'retaining' for variables of retainable type.
933 if (SemaRef.getLangOpts().ObjCAutoRefCount &&
934 SemaRef.inferObjCARCLifetime(Var))
935 Var->setInvalidDecl();
936
937 if (SemaRef.getLangOpts().OpenCL)
938 SemaRef.deduceOpenCLAddressSpace(Var);
939
940 // Substitute the nested name specifier, if any.
941 if (SubstQualifier(D, Var))
942 return nullptr;
943
944 SemaRef.BuildVariableInstantiation(Var, D, TemplateArgs, LateAttrs, Owner,
945 StartingScope, InstantiatingVarTemplate);
946
947 if (D->isNRVOVariable()) {
948 QualType ReturnType = cast<FunctionDecl>(DC)->getReturnType();
949 if (SemaRef.isCopyElisionCandidate(ReturnType, Var, Sema::CES_Strict))
950 Var->setNRVOVariable(true);
951 }
952
953 Var->setImplicit(D->isImplicit());
954
955 if (Var->isStaticLocal())
956 SemaRef.CheckStaticLocalForDllExport(Var);
957
958 return Var;
959 }
960
961 Decl *TemplateDeclInstantiator::VisitAccessSpecDecl(AccessSpecDecl *D) {
962 AccessSpecDecl* AD
963 = AccessSpecDecl::Create(SemaRef.Context, D->getAccess(), Owner,
964 D->getAccessSpecifierLoc(), D->getColonLoc());
965 Owner->addHiddenDecl(AD);
966 return AD;
967 }
968
969 Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) {
970 bool Invalid = false;
971 TypeSourceInfo *DI = D->getTypeSourceInfo();
972 if (DI->getType()->isInstantiationDependentType() ||
973 DI->getType()->isVariablyModifiedType()) {
974 DI = SemaRef.SubstType(DI, TemplateArgs,
975 D->getLocation(), D->getDeclName());
976 if (!DI) {
977 DI = D->getTypeSourceInfo();
978 Invalid = true;
979 } else if (DI->getType()->isFunctionType()) {
980 // C++ [temp.arg.type]p3:
981 // If a declaration acquires a function type through a type
982 // dependent on a template-parameter and this causes a
983 // declaration that does not use the syntactic form of a
984 // function declarator to have function type, the program is
985 // ill-formed.
986 SemaRef.Diag(D->getLocation(), diag::err_field_instantiates_to_function)
987 << DI->getType();
988 Invalid = true;
989 }
990 } else {
991 SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), DI->getType());
992 }
993
994 Expr *BitWidth = D->getBitWidth();
995 if (Invalid)
996 BitWidth = nullptr;
997 else if (BitWidth) {
998 // The bit-width expression is a constant expression.
999 EnterExpressionEvaluationContext Unevaluated(
1000 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
1001
1002 ExprResult InstantiatedBitWidth
1003 = SemaRef.SubstExpr(BitWidth, TemplateArgs);
1004 if (InstantiatedBitWidth.isInvalid()) {
1005 Invalid = true;
1006 BitWidth = nullptr;
1007 } else
1008 BitWidth = InstantiatedBitWidth.getAs<Expr>();
1009 }
1010
1011 FieldDecl *Field = SemaRef.CheckFieldDecl(D->getDeclName(),
1012 DI->getType(), DI,
1013 cast<RecordDecl>(Owner),
1014 D->getLocation(),
1015 D->isMutable(),
1016 BitWidth,
1017 D->getInClassInitStyle(),
1018 D->getInnerLocStart(),
1019 D->getAccess(),
1020 nullptr);
1021 if (!Field) {
1022 cast<Decl>(Owner)->setInvalidDecl();
1023 return nullptr;
1024 }
1025
1026 SemaRef.InstantiateAttrs(TemplateArgs, D, Field, LateAttrs, StartingScope);
1027
1028 if (Field->hasAttrs())
1029 SemaRef.CheckAlignasUnderalignment(Field);
1030
1031 if (Invalid)
1032 Field->setInvalidDecl();
1033
1034 if (!Field->getDeclName()) {
1035 // Keep track of where this decl came from.
1036 SemaRef.Context.setInstantiatedFromUnnamedFieldDecl(Field, D);
1037 }
1038 if (CXXRecordDecl *Parent= dyn_cast<CXXRecordDecl>(Field->getDeclContext())) {
1039 if (Parent->isAnonymousStructOrUnion() &&
1040 Parent->getRedeclContext()->isFunctionOrMethod())
1041 SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Field);
1042 }
1043
1044 Field->setImplicit(D->isImplicit());
1045 Field->setAccess(D->getAccess());
1046 Owner->addDecl(Field);
1047
1048 return Field;
1049 }
1050
1051 Decl *TemplateDeclInstantiator::VisitMSPropertyDecl(MSPropertyDecl *D) {
1052 bool Invalid = false;
1053 TypeSourceInfo *DI = D->getTypeSourceInfo();
1054
1055 if (DI->getType()->isVariablyModifiedType()) {
1056 SemaRef.Diag(D->getLocation(), diag::err_property_is_variably_modified)
1057 << D;
1058 Invalid = true;
1059 } else if (DI->getType()->isInstantiationDependentType()) {
1060 DI = SemaRef.SubstType(DI, TemplateArgs,
1061 D->getLocation(), D->getDeclName());
1062 if (!DI) {
1063 DI = D->getTypeSourceInfo();
1064 Invalid = true;
1065 } else if (DI->getType()->isFunctionType()) {
1066 // C++ [temp.arg.type]p3:
1067 // If a declaration acquires a function type through a type
1068 // dependent on a template-parameter and this causes a
1069 // declaration that does not use the syntactic form of a
1070 // function declarator to have function type, the program is
1071 // ill-formed.
1072 SemaRef.Diag(D->getLocation(), diag::err_field_instantiates_to_function)
1073 << DI->getType();
1074 Invalid = true;
1075 }
1076 } else {
1077 SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), DI->getType());
1078 }
1079
1080 MSPropertyDecl *Property = MSPropertyDecl::Create(
1081 SemaRef.Context, Owner, D->getLocation(), D->getDeclName(), DI->getType(),
1082 DI, D->getBeginLoc(), D->getGetterId(), D->getSetterId());
1083
1084 SemaRef.InstantiateAttrs(TemplateArgs, D, Property, LateAttrs,
1085 StartingScope);
1086
1087 if (Invalid)
1088 Property->setInvalidDecl();
1089
1090 Property->setAccess(D->getAccess());
1091 Owner->addDecl(Property);
1092
1093 return Property;
1094 }
1095
1096 Decl *TemplateDeclInstantiator::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
1097 NamedDecl **NamedChain =
1098 new (SemaRef.Context)NamedDecl*[D->getChainingSize()];
1099
1100 int i = 0;
1101 for (auto *PI : D->chain()) {
1102 NamedDecl *Next = SemaRef.FindInstantiatedDecl(D->getLocation(), PI,
1103 TemplateArgs);
1104 if (!Next)
1105 return nullptr;
1106
1107 NamedChain[i++] = Next;
1108 }
1109
1110 QualType T = cast<FieldDecl>(NamedChain[i-1])->getType();
1111 IndirectFieldDecl *IndirectField = IndirectFieldDecl::Create(
1112 SemaRef.Context, Owner, D->getLocation(), D->getIdentifier(), T,
1113 {NamedChain, D->getChainingSize()});
1114
1115 for (const auto *Attr : D->attrs())
1116 IndirectField->addAttr(Attr->clone(SemaRef.Context));
1117
1118 IndirectField->setImplicit(D->isImplicit());
1119 IndirectField->setAccess(D->getAccess());
1120 Owner->addDecl(IndirectField);
1121 return IndirectField;
1122 }
1123
1124 Decl *TemplateDeclInstantiator::VisitFriendDecl(FriendDecl *D) {
1125 // Handle friend type expressions by simply substituting template
1126 // parameters into the pattern type and checking the result.
1127 if (TypeSourceInfo *Ty = D->getFriendType()) {
1128 TypeSourceInfo *InstTy;
1129 // If this is an unsupported friend, don't bother substituting template
1130 // arguments into it. The actual type referred to won't be used by any
1131 // parts of Clang, and may not be valid for instantiating. Just use the
1132 // same info for the instantiated friend.
1133 if (D->isUnsupportedFriend()) {
1134 InstTy = Ty;
1135 } else {
1136 InstTy = SemaRef.SubstType(Ty, TemplateArgs,
1137 D->getLocation(), DeclarationName());
1138 }
1139 if (!InstTy)
1140 return nullptr;
1141
1142 FriendDecl *FD = SemaRef.CheckFriendTypeDecl(D->getBeginLoc(),
1143 D->getFriendLoc(), InstTy);
1144 if (!FD)
1145 return nullptr;
1146
1147 FD->setAccess(AS_public);
1148 FD->setUnsupportedFriend(D->isUnsupportedFriend());
1149 Owner->addDecl(FD);
1150 return FD;
1151 }
1152
1153 NamedDecl *ND = D->getFriendDecl();
1154 assert(ND && "friend decl must be a decl or a type!");
1155
1156 // All of the Visit implementations for the various potential friend
1157 // declarations have to be carefully written to work for friend
1158 // objects, with the most important detail being that the target
1159 // decl should almost certainly not be placed in Owner.
1160 Decl *NewND = Visit(ND);
1161 if (!NewND) return nullptr;
1162
1163 FriendDecl *FD =
1164 FriendDecl::Create(SemaRef.Context, Owner, D->getLocation(),
1165 cast<NamedDecl>(NewND), D->getFriendLoc());
1166 FD->setAccess(AS_public);
1167 FD->setUnsupportedFriend(D->isUnsupportedFriend());
1168 Owner->addDecl(FD);
1169 return FD;
1170 }
1171
1172 Decl *TemplateDeclInstantiator::VisitStaticAssertDecl(StaticAssertDecl *D) {
1173 Expr *AssertExpr = D->getAssertExpr();
1174
1175 // The expression in a static assertion is a constant expression.
1176 EnterExpressionEvaluationContext Unevaluated(
1177 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
1178
1179 ExprResult InstantiatedAssertExpr
1180 = SemaRef.SubstExpr(AssertExpr, TemplateArgs);
1181 if (InstantiatedAssertExpr.isInvalid())
1182 return nullptr;
1183
1184 return SemaRef.BuildStaticAssertDeclaration(D->getLocation(),
1185 InstantiatedAssertExpr.get(),
1186 D->getMessage(),
1187 D->getRParenLoc(),
1188 D->isFailed());
1189 }
1190
1191 Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) {
1192 EnumDecl *PrevDecl = nullptr;
1193 if (EnumDecl *PatternPrev = getPreviousDeclForInstantiation(D)) {
1194 NamedDecl *Prev = SemaRef.FindInstantiatedDecl(D->getLocation(),
1195 PatternPrev,
1196 TemplateArgs);
1197 if (!Prev) return nullptr;
1198 PrevDecl = cast<EnumDecl>(Prev);
1199 }
1200
1201 EnumDecl *Enum =
1202 EnumDecl::Create(SemaRef.Context, Owner, D->getBeginLoc(),
1203 D->getLocation(), D->getIdentifier(), PrevDecl,
1204 D->isScoped(), D->isScopedUsingClassTag(), D->isFixed());
1205 if (D->isFixed()) {
1206 if (TypeSourceInfo *TI = D->getIntegerTypeSourceInfo()) {
1207 // If we have type source information for the underlying type, it means it
1208 // has been explicitly set by the user. Perform substitution on it before
1209 // moving on.
1210 SourceLocation UnderlyingLoc = TI->getTypeLoc().getBeginLoc();
1211 TypeSourceInfo *NewTI = SemaRef.SubstType(TI, TemplateArgs, UnderlyingLoc,
1212 DeclarationName());
1213 if (!NewTI || SemaRef.CheckEnumUnderlyingType(NewTI))
1214 Enum->setIntegerType(SemaRef.Context.IntTy);
1215 else
1216 Enum->setIntegerTypeSourceInfo(NewTI);
1217 } else {
1218 assert(!D->getIntegerType()->isDependentType()
1219 && "Dependent type without type source info");
1220 Enum->setIntegerType(D->getIntegerType());
1221 }
1222 }
1223
1224 SemaRef.InstantiateAttrs(TemplateArgs, D, Enum);
1225
1226 Enum->setInstantiationOfMemberEnum(D, TSK_ImplicitInstantiation);
1227 Enum->setAccess(D->getAccess());
1228 // Forward the mangling number from the template to the instantiated decl.
1229 SemaRef.Context.setManglingNumber(Enum, SemaRef.Context.getManglingNumber(D));
1230 // See if the old tag was defined along with a declarator.
1231 // If it did, mark the new tag as being associated with that declarator.
1232 if (DeclaratorDecl *DD = SemaRef.Context.getDeclaratorForUnnamedTagDecl(D))
1233 SemaRef.Context.addDeclaratorForUnnamedTagDecl(Enum, DD);
1234 // See if the old tag was defined along with a typedef.
1235 // If it did, mark the new tag as being associated with that typedef.
1236 if (TypedefNameDecl *TND = SemaRef.Context.getTypedefNameForUnnamedTagDecl(D))
1237 SemaRef.Context.addTypedefNameForUnnamedTagDecl(Enum, TND);
1238 if (SubstQualifier(D, Enum)) return nullptr;
1239 Owner->addDecl(Enum);
1240
1241 EnumDecl *Def = D->getDefinition();
1242 if (Def && Def != D) {
1243 // If this is an out-of-line definition of an enum member template, check
1244 // that the underlying types match in the instantiation of both
1245 // declarations.
1246 if (TypeSourceInfo *TI = Def->getIntegerTypeSourceInfo()) {
1247 SourceLocation UnderlyingLoc = TI->getTypeLoc().getBeginLoc();
1248 QualType DefnUnderlying =
1249 SemaRef.SubstType(TI->getType(), TemplateArgs,
1250 UnderlyingLoc, DeclarationName());
1251 SemaRef.CheckEnumRedeclaration(Def->getLocation(), Def->isScoped(),
1252 DefnUnderlying, /*IsFixed=*/true, Enum);
1253 }
1254 }
1255
1256 // C++11 [temp.inst]p1: The implicit instantiation of a class template
1257 // specialization causes the implicit instantiation of the declarations, but
1258 // not the definitions of scoped member enumerations.
1259 //
1260 // DR1484 clarifies that enumeration definitions inside of a template
1261 // declaration aren't considered entities that can be separately instantiated
1262 // from the rest of the entity they are declared inside of.
1263 if (isDeclWithinFunction(D) ? D == Def : Def && !Enum->isScoped()) {
1264 SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Enum);
1265 InstantiateEnumDefinition(Enum, Def);
1266 }
1267
1268 return Enum;
1269 }
1270
1271 void TemplateDeclInstantiator::InstantiateEnumDefinition(
1272 EnumDecl *Enum, EnumDecl *Pattern) {
1273 Enum->startDefinition();
1274
1275 // Update the location to refer to the definition.
1276 Enum->setLocation(Pattern->getLocation());
1277
1278 SmallVector<Decl*, 4> Enumerators;
1279
1280 EnumConstantDecl *LastEnumConst = nullptr;
1281 for (auto *EC : Pattern->enumerators()) {
1282 // The specified value for the enumerator.
1283 ExprResult Value((Expr *)nullptr);
1284 if (Expr *UninstValue = EC->getInitExpr()) {
1285 // The enumerator's value expression is a constant expression.
1286 EnterExpressionEvaluationContext Unevaluated(
1287 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
1288
1289 Value = SemaRef.SubstExpr(UninstValue, TemplateArgs);
1290 }
1291
1292 // Drop the initial value and continue.
1293 bool isInvalid = false;
1294 if (Value.isInvalid()) {
1295 Value = nullptr;
1296 isInvalid = true;
1297 }
1298
1299 EnumConstantDecl *EnumConst
1300 = SemaRef.CheckEnumConstant(Enum, LastEnumConst,
1301 EC->getLocation(), EC->getIdentifier(),
1302 Value.get());
1303
1304 if (isInvalid) {
1305 if (EnumConst)
1306 EnumConst->setInvalidDecl();
1307 Enum->setInvalidDecl();
1308 }
1309
1310 if (EnumConst) {
1311 SemaRef.InstantiateAttrs(TemplateArgs, EC, EnumConst);
1312
1313 EnumConst->setAccess(Enum->getAccess());
1314 Enum->addDecl(EnumConst);
1315 Enumerators.push_back(EnumConst);
1316 LastEnumConst = EnumConst;
1317
1318 if (Pattern->getDeclContext()->isFunctionOrMethod() &&
1319 !Enum->isScoped()) {
1320 // If the enumeration is within a function or method, record the enum
1321 // constant as a local.
1322 SemaRef.CurrentInstantiationScope->InstantiatedLocal(EC, EnumConst);
1323 }
1324 }
1325 }
1326
1327 SemaRef.ActOnEnumBody(Enum->getLocation(), Enum->getBraceRange(), Enum,
1328 Enumerators, nullptr, ParsedAttributesView());
1329 }
1330
1331 Decl *TemplateDeclInstantiator::VisitEnumConstantDecl(EnumConstantDecl *D) {
1332 llvm_unreachable("EnumConstantDecls can only occur within EnumDecls.");
1333 }
1334
1335 Decl *
1336 TemplateDeclInstantiator::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) {
1337 llvm_unreachable("BuiltinTemplateDecls cannot be instantiated.");
1338 }
1339
1340 Decl *TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) {
1341 bool isFriend = (D->getFriendObjectKind() != Decl::FOK_None);
1342
1343 // Create a local instantiation scope for this class template, which
1344 // will contain the instantiations of the template parameters.
1345 LocalInstantiationScope Scope(SemaRef);
1346 TemplateParameterList *TempParams = D->getTemplateParameters();
1347 TemplateParameterList *InstParams = SubstTemplateParams(TempParams);
1348 if (!InstParams)
1349 return nullptr;
1350
1351 CXXRecordDecl *Pattern = D->getTemplatedDecl();
1352
1353 // Instantiate the qualifier. We have to do this first in case
1354 // we're a friend declaration, because if we are then we need to put
1355 // the new declaration in the appropriate context.
1356 NestedNameSpecifierLoc QualifierLoc = Pattern->getQualifierLoc();
1357 if (QualifierLoc) {
1358 QualifierLoc = SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc,
1359 TemplateArgs);
1360 if (!QualifierLoc)
1361 return nullptr;
1362 }
1363
1364 CXXRecordDecl *PrevDecl = nullptr;
1365 ClassTemplateDecl *PrevClassTemplate = nullptr;
1366
1367 if (!isFriend && getPreviousDeclForInstantiation(Pattern)) {
1368 DeclContext::lookup_result Found = Owner->lookup(Pattern->getDeclName());
1369 if (!Found.empty()) {
1370 PrevClassTemplate = dyn_cast<ClassTemplateDecl>(Found.front());
1371 if (PrevClassTemplate)
1372 PrevDecl = PrevClassTemplate->getTemplatedDecl();
1373 }
1374 }
1375
1376 // If this isn't a friend, then it's a member template, in which
1377 // case we just want to build the instantiation in the
1378 // specialization. If it is a friend, we want to build it in
1379 // the appropriate context.
1380 DeclContext *DC = Owner;
1381 if (isFriend) {
1382 if (QualifierLoc) {
1383 CXXScopeSpec SS;
1384 SS.Adopt(QualifierLoc);
1385 DC = SemaRef.computeDeclContext(SS);
1386 if (!DC) return nullptr;
1387 } else {
1388 DC = SemaRef.FindInstantiatedContext(Pattern->getLocation(),
1389 Pattern->getDeclContext(),
1390 TemplateArgs);
1391 }
1392
1393 // Look for a previous declaration of the template in the owning
1394 // context.
1395 LookupResult R(SemaRef, Pattern->getDeclName(), Pattern->getLocation(),
1396 Sema::LookupOrdinaryName,
1397 SemaRef.forRedeclarationInCurContext());
1398 SemaRef.LookupQualifiedName(R, DC);
1399
1400 if (R.isSingleResult()) {
1401 PrevClassTemplate = R.getAsSingle<ClassTemplateDecl>();
1402 if (PrevClassTemplate)
1403 PrevDecl = PrevClassTemplate->getTemplatedDecl();
1404 }
1405
1406 if (!PrevClassTemplate && QualifierLoc) {
1407 SemaRef.Diag(Pattern->getLocation(), diag::err_not_tag_in_scope)
1408 << D->getTemplatedDecl()->getTagKind() << Pattern->getDeclName() << DC
1409 << QualifierLoc.getSourceRange();
1410 return nullptr;
1411 }
1412
1413 bool AdoptedPreviousTemplateParams = false;
1414 if (PrevClassTemplate) {
1415 bool Complain = true;
1416
1417 // HACK: libstdc++ 4.2.1 contains an ill-formed friend class
1418 // template for struct std::tr1::__detail::_Map_base, where the
1419 // template parameters of the friend declaration don't match the
1420 // template parameters of the original declaration. In this one
1421 // case, we don't complain about the ill-formed friend
1422 // declaration.
1423 if (isFriend && Pattern->getIdentifier() &&
1424 Pattern->getIdentifier()->isStr("_Map_base") &&
1425 DC->isNamespace() &&
1426 cast<NamespaceDecl>(DC)->getIdentifier() &&
1427 cast<NamespaceDecl>(DC)->getIdentifier()->isStr("__detail")) {
1428 DeclContext *DCParent = DC->getParent();
1429 if (DCParent->isNamespace() &&
1430 cast<NamespaceDecl>(DCParent)->getIdentifier() &&
1431 cast<NamespaceDecl>(DCParent)->getIdentifier()->isStr("tr1")) {
1432 if (cast<Decl>(DCParent)->isInStdNamespace())
1433 Complain = false;
1434 }
1435 }
1436
1437 TemplateParameterList *PrevParams
1438 = PrevClassTemplate->getMostRecentDecl()->getTemplateParameters();
1439
1440 // Make sure the parameter lists match.
1441 if (!SemaRef.TemplateParameterListsAreEqual(InstParams, PrevParams,
1442 Complain,
1443 Sema::TPL_TemplateMatch)) {
1444 if (Complain)
1445 return nullptr;
1446
1447 AdoptedPreviousTemplateParams = true;
1448 InstParams = PrevParams;
1449 }
1450
1451 // Do some additional validation, then merge default arguments
1452 // from the existing declarations.
1453 if (!AdoptedPreviousTemplateParams &&
1454 SemaRef.CheckTemplateParameterList(InstParams, PrevParams,
1455 Sema::TPC_ClassTemplate))
1456 return nullptr;
1457 }
1458 }
1459
1460 CXXRecordDecl *RecordInst = CXXRecordDecl::Create(
1461 SemaRef.Context, Pattern->getTagKind(), DC, Pattern->getBeginLoc(),
1462 Pattern->getLocation(), Pattern->getIdentifier(), PrevDecl,
1463 /*DelayTypeCreation=*/true);
1464
1465 if (QualifierLoc)
1466 RecordInst->setQualifierInfo(QualifierLoc);
1467
1468 SemaRef.InstantiateAttrsForDecl(TemplateArgs, Pattern, RecordInst, LateAttrs,
1469 StartingScope);
1470
1471 ClassTemplateDecl *Inst
1472 = ClassTemplateDecl::Create(SemaRef.Context, DC, D->getLocation(),
1473 D->getIdentifier(), InstParams, RecordInst);
1474 assert(!(isFriend && Owner->isDependentContext()));
1475 Inst->setPreviousDecl(PrevClassTemplate);
1476
1477 RecordInst->setDescribedClassTemplate(Inst);
1478
1479 if (isFriend) {
1480 if (PrevClassTemplate)
1481 Inst->setAccess(PrevClassTemplate->getAccess());
1482 else
1483 Inst->setAccess(D->getAccess());
1484
1485 Inst->setObjectOfFriendDecl();
1486 // TODO: do we want to track the instantiation progeny of this
1487 // friend target decl?
1488 } else {
1489 Inst->setAccess(D->getAccess());
1490 if (!PrevClassTemplate)
1491 Inst->setInstantiatedFromMemberTemplate(D);
1492 }
1493
1494 // Trigger creation of the type for the instantiation.
1495 SemaRef.Context.getInjectedClassNameType(RecordInst,
1496 Inst->getInjectedClassNameSpecialization());
1497
1498 // Finish handling of friends.
1499 if (isFriend) {
1500 DC->makeDeclVisibleInContext(Inst);
1501 Inst->setLexicalDeclContext(Owner);
1502 RecordInst->setLexicalDeclContext(Owner);
1503 return Inst;
1504 }
1505
1506 if (D->isOutOfLine()) {
1507 Inst->setLexicalDeclContext(D->getLexicalDeclContext());
1508 RecordInst->setLexicalDeclContext(D->getLexicalDeclContext());
1509 }
1510
1511 Owner->addDecl(Inst);
1512
1513 if (!PrevClassTemplate) {
1514 // Queue up any out-of-line partial specializations of this member
1515 // class template; the client will force their instantiation once
1516 // the enclosing class has been instantiated.
1517 SmallVector<ClassTemplatePartialSpecializationDecl *, 4> PartialSpecs;
1518 D->getPartialSpecializations(PartialSpecs);
1519 for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I)
1520 if (PartialSpecs[I]->getFirstDecl()->isOutOfLine())
1521 OutOfLinePartialSpecs.push_back(std::make_pair(Inst, PartialSpecs[I]));
1522 }
1523
1524 return Inst;
1525 }
1526
1527 Decl *
1528 TemplateDeclInstantiator::VisitClassTemplatePartialSpecializationDecl(
1529 ClassTemplatePartialSpecializationDecl *D) {
1530 ClassTemplateDecl *ClassTemplate = D->getSpecializedTemplate();
1531
1532 // Lookup the already-instantiated declaration in the instantiation
1533 // of the class template and return that.
1534 DeclContext::lookup_result Found
1535 = Owner->lookup(ClassTemplate->getDeclName());
1536 if (Found.empty())
1537 return nullptr;
1538
1539 ClassTemplateDecl *InstClassTemplate
1540 = dyn_cast<ClassTemplateDecl>(Found.front());
1541 if (!InstClassTemplate)
1542 return nullptr;
1543
1544 if (ClassTemplatePartialSpecializationDecl *Result
1545 = InstClassTemplate->findPartialSpecInstantiatedFromMember(D))
1546 return Result;
1547
1548 return InstantiateClassTemplatePartialSpecialization(InstClassTemplate, D);
1549 }
1550
1551 Decl *TemplateDeclInstantiator::VisitVarTemplateDecl(VarTemplateDecl *D) {
1552 assert(D->getTemplatedDecl()->isStaticDataMember() &&
1553 "Only static data member templates are allowed.");
1554
1555 // Create a local instantiation scope for this variable template, which
1556 // will contain the instantiations of the template parameters.
1557 LocalInstantiationScope Scope(SemaRef);
1558 TemplateParameterList *TempParams = D->getTemplateParameters();
1559 TemplateParameterList *InstParams = SubstTemplateParams(TempParams);
1560 if (!InstParams)
1561 return nullptr;
1562
1563 VarDecl *Pattern = D->getTemplatedDecl();
1564 VarTemplateDecl *PrevVarTemplate = nullptr;
1565
1566 if (getPreviousDeclForInstantiation(Pattern)) {
1567 DeclContext::lookup_result Found = Owner->lookup(Pattern->getDeclName());
1568 if (!Found.empty())
1569 PrevVarTemplate = dyn_cast<VarTemplateDecl>(Found.front());
1570 }
1571
1572 VarDecl *VarInst =
1573 cast_or_null<VarDecl>(VisitVarDecl(Pattern,
1574 /*InstantiatingVarTemplate=*/true));
1575 if (!VarInst) return nullptr;
1576
1577 DeclContext *DC = Owner;
1578
1579 VarTemplateDecl *Inst = VarTemplateDecl::Create(
1580 SemaRef.Context, DC, D->getLocation(), D->getIdentifier(), InstParams,
1581 VarInst);
1582 VarInst->setDescribedVarTemplate(Inst);
1583 Inst->setPreviousDecl(PrevVarTemplate);
1584
1585 Inst->setAccess(D->getAccess());
1586 if (!PrevVarTemplate)
1587 Inst->setInstantiatedFromMemberTemplate(D);
1588
1589 if (D->isOutOfLine()) {
1590 Inst->setLexicalDeclContext(D->getLexicalDeclContext());
1591 VarInst->setLexicalDeclContext(D->getLexicalDeclContext());
1592 }
1593
1594 Owner->addDecl(Inst);
1595
1596 if (!PrevVarTemplate) {
1597 // Queue up any out-of-line partial specializations of this member
1598 // variable template; the client will force their instantiation once
1599 // the enclosing class has been instantiated.
1600 SmallVector<VarTemplatePartialSpecializationDecl *, 4> PartialSpecs;
1601 D->getPartialSpecializations(PartialSpecs);
1602 for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I)
1603 if (PartialSpecs[I]->getFirstDecl()->isOutOfLine())
1604 OutOfLineVarPartialSpecs.push_back(
1605 std::make_pair(Inst, PartialSpecs[I]));
1606 }
1607
1608 return Inst;
1609 }
1610
1611 Decl *TemplateDeclInstantiator::VisitVarTemplatePartialSpecializationDecl(
1612 VarTemplatePartialSpecializationDecl *D) {
1613 assert(D->isStaticDataMember() &&
1614 "Only static data member templates are allowed.");
1615
1616 VarTemplateDecl *VarTemplate = D->getSpecializedTemplate();
1617
1618 // Lookup the already-instantiated declaration and return that.
1619 DeclContext::lookup_result Found = Owner->lookup(VarTemplate->getDeclName());
1620 assert(!Found.empty() && "Instantiation found nothing?");
1621
1622 VarTemplateDecl *InstVarTemplate = dyn_cast<VarTemplateDecl>(Found.front());
1623 assert(InstVarTemplate && "Instantiation did not find a variable template?");
1624
1625 if (VarTemplatePartialSpecializationDecl *Result =
1626 InstVarTemplate->findPartialSpecInstantiatedFromMember(D))
1627 return Result;
1628
1629 return InstantiateVarTemplatePartialSpecialization(InstVarTemplate, D);
1630 }
1631
1632 Decl *
1633 TemplateDeclInstantiator::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
1634 // Create a local instantiation scope for this function template, which
1635 // will contain the instantiations of the template parameters and then get
1636 // merged with the local instantiation scope for the function template
1637 // itself.
1638 LocalInstantiationScope Scope(SemaRef);
1639
1640 TemplateParameterList *TempParams = D->getTemplateParameters();
1641 TemplateParameterList *InstParams = SubstTemplateParams(TempParams);
1642 if (!InstParams)
1643 return nullptr;
1644
1645 FunctionDecl *Instantiated = nullptr;
1646 if (CXXMethodDecl *DMethod = dyn_cast<CXXMethodDecl>(D->getTemplatedDecl()))
1647 Instantiated = cast_or_null<FunctionDecl>(VisitCXXMethodDecl(DMethod,
1648 InstParams));
1649 else
1650 Instantiated = cast_or_null<FunctionDecl>(VisitFunctionDecl(
1651 D->getTemplatedDecl(),
1652 InstParams));
1653
1654 if (!Instantiated)
1655 return nullptr;
1656
1657 // Link the instantiated function template declaration to the function
1658 // template from which it was instantiated.
1659 FunctionTemplateDecl *InstTemplate
1660 = Instantiated->getDescribedFunctionTemplate();
1661 InstTemplate->setAccess(D->getAccess());
1662 assert(InstTemplate &&
1663 "VisitFunctionDecl/CXXMethodDecl didn't create a template!");
1664
1665 bool isFriend = (InstTemplate->getFriendObjectKind() != Decl::FOK_None);
1666
1667 // Link the instantiation back to the pattern *unless* this is a
1668 // non-definition friend declaration.
1669 if (!InstTemplate->getInstantiatedFromMemberTemplate() &&
1670 !(isFriend && !D->getTemplatedDecl()->isThisDeclarationADefinition()))
1671 InstTemplate->setInstantiatedFromMemberTemplate(D);
1672
1673 // Make declarations visible in the appropriate context.
1674 if (!isFriend) {
1675 Owner->addDecl(InstTemplate);
1676 } else if (InstTemplate->getDeclContext()->isRecord() &&
1677 !getPreviousDeclForInstantiation(D)) {
1678 SemaRef.CheckFriendAccess(InstTemplate);
1679 }
1680
1681 return InstTemplate;
1682 }
1683
1684 Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) {
1685 CXXRecordDecl *PrevDecl = nullptr;
1686 if (D->isInjectedClassName())
1687 PrevDecl = cast<CXXRecordDecl>(Owner);
1688 else if (CXXRecordDecl *PatternPrev = getPreviousDeclForInstantiation(D)) {
1689 NamedDecl *Prev = SemaRef.FindInstantiatedDecl(D->getLocation(),
1690 PatternPrev,
1691 TemplateArgs);
1692 if (!Prev) return nullptr;
1693 PrevDecl = cast<CXXRecordDecl>(Prev);
1694 }
1695
1696 CXXRecordDecl *Record = CXXRecordDecl::Create(
1697 SemaRef.Context, D->getTagKind(), Owner, D->getBeginLoc(),
1698 D->getLocation(), D->getIdentifier(), PrevDecl);
1699
1700 // Substitute the nested name specifier, if any.
1701 if (SubstQualifier(D, Record))
1702 return nullptr;
1703
1704 SemaRef.InstantiateAttrsForDecl(TemplateArgs, D, Record, LateAttrs,
1705 StartingScope);
1706
1707 Record->setImplicit(D->isImplicit());
1708 // FIXME: Check against AS_none is an ugly hack to work around the issue that
1709 // the tag decls introduced by friend class declarations don't have an access
1710 // specifier. Remove once this area of the code gets sorted out.
1711 if (D->getAccess() != AS_none)
1712 Record->setAccess(D->getAccess());
1713 if (!D->isInjectedClassName())
1714 Record->setInstantiationOfMemberClass(D, TSK_ImplicitInstantiation);
1715
1716 // If the original function was part of a friend declaration,
1717 // inherit its namespace state.
1718 if (D->getFriendObjectKind())
1719 Record->setObjectOfFriendDecl();
1720
1721 // Make sure that anonymous structs and unions are recorded.
1722 if (D->isAnonymousStructOrUnion())
1723 Record->setAnonymousStructOrUnion(true);
1724
1725 if (D->isLocalClass())
1726 SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Record);
1727
1728 // Forward the mangling number from the template to the instantiated decl.
1729 SemaRef.Context.setManglingNumber(Record,
1730 SemaRef.Context.getManglingNumber(D));
1731
1732 // See if the old tag was defined along with a declarator.
1733 // If it did, mark the new tag as being associated with that declarator.
1734 if (DeclaratorDecl *DD = SemaRef.Context.getDeclaratorForUnnamedTagDecl(D))
1735 SemaRef.Context.addDeclaratorForUnnamedTagDecl(Record, DD);
1736
1737 // See if the old tag was defined along with a typedef.
1738 // If it did, mark the new tag as being associated with that typedef.
1739 if (TypedefNameDecl *TND = SemaRef.Context.getTypedefNameForUnnamedTagDecl(D))
1740 SemaRef.Context.addTypedefNameForUnnamedTagDecl(Record, TND);
1741
1742 Owner->addDecl(Record);
1743
1744 // DR1484 clarifies that the members of a local class are instantiated as part
1745 // of the instantiation of their enclosing entity.
1746 if (D->isCompleteDefinition() && D->isLocalClass()) {
1747 Sema::LocalEagerInstantiationScope LocalInstantiations(SemaRef);
1748
1749 SemaRef.InstantiateClass(D->getLocation(), Record, D, TemplateArgs,
1750 TSK_ImplicitInstantiation,
1751 /*Complain=*/true);
1752
1753 // For nested local classes, we will instantiate the members when we
1754 // reach the end of the outermost (non-nested) local class.
1755 if (!D->isCXXClassMember())
1756 SemaRef.InstantiateClassMembers(D->getLocation(), Record, TemplateArgs,
1757 TSK_ImplicitInstantiation);
1758
1759 // This class may have local implicit instantiations that need to be
1760 // performed within this scope.
1761 LocalInstantiations.perform();
1762 }
1763
1764 SemaRef.DiagnoseUnusedNestedTypedefs(Record);
1765
1766 return Record;
1767 }
1768
1769 /// Adjust the given function type for an instantiation of the
1770 /// given declaration, to cope with modifications to the function's type that
1771 /// aren't reflected in the type-source information.
1772 ///
1773 /// \param D The declaration we're instantiating.
1774 /// \param TInfo The already-instantiated type.
1775 static QualType adjustFunctionTypeForInstantiation(ASTContext &Context,
1776 FunctionDecl *D,
1777 TypeSourceInfo *TInfo) {
1778 const FunctionProtoType *OrigFunc
1779 = D->getType()->castAs<FunctionProtoType>();
1780 const FunctionProtoType *NewFunc
1781 = TInfo->getType()->castAs<FunctionProtoType>();
1782 if (OrigFunc->getExtInfo() == NewFunc->getExtInfo())
1783 return TInfo->getType();
1784
1785 FunctionProtoType::ExtProtoInfo NewEPI = NewFunc->getExtProtoInfo();
1786 NewEPI.ExtInfo = OrigFunc->getExtInfo();
1787 return Context.getFunctionType(NewFunc->getReturnType(),
1788 NewFunc->getParamTypes(), NewEPI);
1789 }
1790
1791 /// Normal class members are of more specific types and therefore
1792 /// don't make it here. This function serves three purposes:
1793 /// 1) instantiating function templates
1794 /// 2) substituting friend declarations
1795 /// 3) substituting deduction guide declarations for nested class templates
1796 Decl *TemplateDeclInstantiator::VisitFunctionDecl(
1797 FunctionDecl *D, TemplateParameterList *TemplateParams,
1798 RewriteKind FunctionRewriteKind) {
1799 // Check whether there is already a function template specialization for
1800 // this declaration.
1801 FunctionTemplateDecl *FunctionTemplate = D->getDescribedFunctionTemplate();
1802 if (FunctionTemplate && !TemplateParams) {
1803 ArrayRef<TemplateArgument> Innermost = TemplateArgs.getInnermost();
1804
1805 void *InsertPos = nullptr;
1806 FunctionDecl *SpecFunc
1807 = FunctionTemplate->findSpecialization(Innermost, InsertPos);
1808
1809 // If we already have a function template specialization, return it.
1810 if (SpecFunc)
1811 return SpecFunc;
1812 }
1813
1814 bool isFriend;
1815 if (FunctionTemplate)
1816 isFriend = (FunctionTemplate->getFriendObjectKind() != Decl::FOK_None);
1817 else
1818 isFriend = (D->getFriendObjectKind() != Decl::FOK_None);
1819
1820 bool MergeWithParentScope = (TemplateParams != nullptr) ||
1821 Owner->isFunctionOrMethod() ||
1822 !(isa<Decl>(Owner) &&
1823 cast<Decl>(Owner)->isDefinedOutsideFunctionOrMethod());
1824 LocalInstantiationScope Scope(SemaRef, MergeWithParentScope);
1825
1826 ExplicitSpecifier InstantiatedExplicitSpecifier;
1827 if (auto *DGuide = dyn_cast<CXXDeductionGuideDecl>(D)) {
1828 InstantiatedExplicitSpecifier = instantiateExplicitSpecifier(
1829 SemaRef, TemplateArgs, DGuide->getExplicitSpecifier(), DGuide);
1830 if (InstantiatedExplicitSpecifier.isInvalid())
1831 return nullptr;
1832 }
1833
1834 SmallVector<ParmVarDecl *, 4> Params;
1835 TypeSourceInfo *TInfo = SubstFunctionType(D, Params);
1836 if (!TInfo)
1837 return nullptr;
1838 QualType T = adjustFunctionTypeForInstantiation(SemaRef.Context, D, TInfo);
1839
1840 NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc();
1841 if (QualifierLoc) {
1842 QualifierLoc = SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc,
1843 TemplateArgs);
1844 if (!QualifierLoc)
1845 return nullptr;
1846 }
1847
1848 // FIXME: Concepts: Do not substitute into constraint expressions
1849 Expr *TrailingRequiresClause = D->getTrailingRequiresClause();
1850 if (TrailingRequiresClause) {
1851 EnterExpressionEvaluationContext ConstantEvaluated(
1852 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
1853 ExprResult SubstRC = SemaRef.SubstExpr(TrailingRequiresClause,
1854 TemplateArgs);
1855 if (SubstRC.isInvalid())
1856 return nullptr;
1857 TrailingRequiresClause = SubstRC.get();
1858 if (!SemaRef.CheckConstraintExpression(TrailingRequiresClause))
1859 return nullptr;
1860 }
1861
1862 // If we're instantiating a local function declaration, put the result
1863 // in the enclosing namespace; otherwise we need to find the instantiated
1864 // context.
1865 DeclContext *DC;
1866 if (D->isLocalExternDecl()) {
1867 DC = Owner;
1868 SemaRef.adjustContextForLocalExternDecl(DC);
1869 } else if (isFriend && QualifierLoc) {
1870 CXXScopeSpec SS;
1871 SS.Adopt(QualifierLoc);
1872 DC = SemaRef.computeDeclContext(SS);
1873 if (!DC) return nullptr;
1874 } else {
1875 DC = SemaRef.FindInstantiatedContext(D->getLocation(), D->getDeclContext(),
1876 TemplateArgs);
1877 }
1878
1879 DeclarationNameInfo NameInfo
1880 = SemaRef.SubstDeclarationNameInfo(D->getNameInfo(), TemplateArgs);
1881
1882 if (FunctionRewriteKind != RewriteKind::None)
1883 adjustForRewrite(FunctionRewriteKind, D, T, TInfo, NameInfo);
1884
1885 FunctionDecl *Function;
1886 if (auto *DGuide = dyn_cast<CXXDeductionGuideDecl>(D)) {
1887 Function = CXXDeductionGuideDecl::Create(
1888 SemaRef.Context, DC, D->getInnerLocStart(),
1889 InstantiatedExplicitSpecifier, NameInfo, T, TInfo,
1890 D->getSourceRange().getEnd());
1891 if (DGuide->isCopyDeductionCandidate())
1892 cast<CXXDeductionGuideDecl>(Function)->setIsCopyDeductionCandidate();
1893 Function->setAccess(D->getAccess());
1894 } else {
1895 Function = FunctionDecl::Create(
1896 SemaRef.Context, DC, D->getInnerLocStart(), NameInfo, T, TInfo,
1897 D->getCanonicalDecl()->getStorageClass(), D->isInlineSpecified(),
1898 D->hasWrittenPrototype(), D->getConstexprKind(),
1899 TrailingRequiresClause);
1900 Function->setRangeEnd(D->getSourceRange().getEnd());
1901 }
1902
1903 if (D->isInlined())
1904 Function->setImplicitlyInline();
1905
1906 if (QualifierLoc)
1907 Function->setQualifierInfo(QualifierLoc);
1908
1909 if (D->isLocalExternDecl())
1910 Function->setLocalExternDecl();
1911
1912 DeclContext *LexicalDC = Owner;
1913 if (!isFriend && D->isOutOfLine() && !D->isLocalExternDecl()) {
1914 assert(D->getDeclContext()->isFileContext());
1915 LexicalDC = D->getDeclContext();
1916 }
1917
1918 Function->setLexicalDeclContext(LexicalDC);
1919
1920 // Attach the parameters
1921 for (unsigned P = 0; P < Params.size(); ++P)
1922 if (Params[P])
1923 Params[P]->setOwningFunction(Function);
1924 Function->setParams(Params);
1925
1926 if (TrailingRequiresClause)
1927 Function->setTrailingRequiresClause(TrailingRequiresClause);
1928
1929 if (TemplateParams) {
1930 // Our resulting instantiation is actually a function template, since we
1931 // are substituting only the outer template parameters. For example, given
1932 //
1933 // template<typename T>
1934 // struct X {
1935 // template<typename U> friend void f(T, U);
1936 // };
1937 //
1938 // X<int> x;
1939 //
1940 // We are instantiating the friend function template "f" within X<int>,
1941 // which means substituting int for T, but leaving "f" as a friend function
1942 // template.
1943 // Build the function template itself.
1944 FunctionTemplate = FunctionTemplateDecl::Create(SemaRef.Context, DC,
1945 Function->getLocation(),
1946 Function->getDeclName(),
1947 TemplateParams, Function);
1948 Function->setDescribedFunctionTemplate(FunctionTemplate);
1949
1950 FunctionTemplate->setLexicalDeclContext(LexicalDC);
1951
1952 if (isFriend && D->isThisDeclarationADefinition()) {
1953 FunctionTemplate->setInstantiatedFromMemberTemplate(
1954 D->getDescribedFunctionTemplate());
1955 }
1956 } else if (FunctionTemplate) {
1957 // Record this function template specialization.
1958 ArrayRef<TemplateArgument> Innermost = TemplateArgs.getInnermost();
1959 Function->setFunctionTemplateSpecialization(FunctionTemplate,
1960 TemplateArgumentList::CreateCopy(SemaRef.Context,
1961 Innermost),
1962 /*InsertPos=*/nullptr);
1963 } else if (isFriend && D->isThisDeclarationADefinition()) {
1964 // Do not connect the friend to the template unless it's actually a
1965 // definition. We don't want non-template functions to be marked as being
1966 // template instantiations.
1967 Function->setInstantiationOfMemberFunction(D, TSK_ImplicitInstantiation);
1968 }
1969
1970 if (isFriend)
1971 Function->setObjectOfFriendDecl();
1972
1973 if (InitFunctionInstantiation(Function, D))
1974 Function->setInvalidDecl();
1975
1976 bool IsExplicitSpecialization = false;
1977
1978 LookupResult Previous(
1979 SemaRef, Function->getDeclName(), SourceLocation(),
1980 D->isLocalExternDecl() ? Sema::LookupRedeclarationWithLinkage
1981 : Sema::LookupOrdinaryName,
1982 D->isLocalExternDecl() ? Sema::ForExternalRedeclaration
1983 : SemaRef.forRedeclarationInCurContext());
1984
1985 if (DependentFunctionTemplateSpecializationInfo *Info
1986 = D->getDependentSpecializationInfo()) {
1987 assert(isFriend && "non-friend has dependent specialization info?");
1988
1989 // Instantiate the explicit template arguments.
1990 TemplateArgumentListInfo ExplicitArgs(Info->getLAngleLoc(),
1991 Info->getRAngleLoc());
1992 if (SemaRef.Subst(Info->getTemplateArgs(), Info->getNumTemplateArgs(),
1993 ExplicitArgs, TemplateArgs))
1994 return nullptr;
1995
1996 // Map the candidate templates to their instantiations.
1997 for (unsigned I = 0, E = Info->getNumTemplates(); I != E; ++I) {
1998 Decl *Temp = SemaRef.FindInstantiatedDecl(D->getLocation(),
1999 Info->getTemplate(I),
2000 TemplateArgs);
2001 if (!Temp) return nullptr;
2002
2003 Previous.addDecl(cast<FunctionTemplateDecl>(Temp));
2004 }
2005
2006 if (SemaRef.CheckFunctionTemplateSpecialization(Function,
2007 &ExplicitArgs,
2008 Previous))
2009 Function->setInvalidDecl();
2010
2011 IsExplicitSpecialization = true;
2012 } else if (const ASTTemplateArgumentListInfo *Info =
2013 D->getTemplateSpecializationArgsAsWritten()) {
2014 // The name of this function was written as a template-id.
2015 SemaRef.LookupQualifiedName(Previous, DC);
2016
2017 // Instantiate the explicit template arguments.
2018 TemplateArgumentListInfo ExplicitArgs(Info->getLAngleLoc(),
2019 Info->getRAngleLoc());
2020 if (SemaRef.Subst(Info->getTemplateArgs(), Info->getNumTemplateArgs(),
2021 ExplicitArgs, TemplateArgs))
2022 return nullptr;
2023
2024 if (SemaRef.CheckFunctionTemplateSpecialization(Function,
2025 &ExplicitArgs,
2026 Previous))
2027 Function->setInvalidDecl();
2028
2029 IsExplicitSpecialization = true;
2030 } else if (TemplateParams || !FunctionTemplate) {
2031 // Look only into the namespace where the friend would be declared to
2032 // find a previous declaration. This is the innermost enclosing namespace,
2033 // as described in ActOnFriendFunctionDecl.
2034 SemaRef.LookupQualifiedName(Previous, DC);
2035
2036 // In C++, the previous declaration we find might be a tag type
2037 // (class or enum). In this case, the new declaration will hide the
2038 // tag type. Note that this does does not apply if we're declaring a
2039 // typedef (C++ [dcl.typedef]p4).
2040 if (Previous.isSingleTagDecl())
2041 Previous.clear();
2042 }
2043
2044 SemaRef.CheckFunctionDeclaration(/*Scope*/ nullptr, Function, Previous,
2045 IsExplicitSpecialization);
2046
2047 NamedDecl *PrincipalDecl = (TemplateParams
2048 ? cast<NamedDecl>(FunctionTemplate)
2049 : Function);
2050
2051 // If the original function was part of a friend declaration,
2052 // inherit its namespace state and add it to the owner.
2053 if (isFriend) {
2054 Function->setObjectOfFriendDecl();
2055 if (FunctionTemplateDecl *FT = Function->getDescribedFunctionTemplate())
2056 FT->setObjectOfFriendDecl();
2057 DC->makeDeclVisibleInContext(PrincipalDecl);
2058
2059 bool QueuedInstantiation = false;
2060
2061 // C++11 [temp.friend]p4 (DR329):
2062 // When a function is defined in a friend function declaration in a class
2063 // template, the function is instantiated when the function is odr-used.
2064 // The same restrictions on multiple declarations and definitions that
2065 // apply to non-template function declarations and definitions also apply
2066 // to these implicit definitions.
2067 if (D->isThisDeclarationADefinition()) {
2068 SemaRef.CheckForFunctionRedefinition(Function);
2069 if (!Function->isInvalidDecl()) {
2070 for (auto R : Function->redecls()) {
2071 if (R == Function)
2072 continue;
2073
2074 // If some prior declaration of this function has been used, we need
2075 // to instantiate its definition.
2076 if (!QueuedInstantiation && R->isUsed(false)) {
2077 if (MemberSpecializationInfo *MSInfo =
2078 Function->getMemberSpecializationInfo()) {
2079 if (MSInfo->getPointOfInstantiation().isInvalid()) {
2080 SourceLocation Loc = R->getLocation(); // FIXME
2081 MSInfo->setPointOfInstantiation(Loc);
2082 SemaRef.PendingLocalImplicitInstantiations.push_back(
2083 std::make_pair(Function, Loc));
2084 QueuedInstantiation = true;
2085 }
2086 }
2087 }
2088 }
2089 }
2090 }
2091
2092 // Check the template parameter list against the previous declaration. The
2093 // goal here is to pick up default arguments added since the friend was
2094 // declared; we know the template parameter lists match, since otherwise
2095 // we would not have picked this template as the previous declaration.
2096 if (TemplateParams && FunctionTemplate->getPreviousDecl()) {
2097 SemaRef.CheckTemplateParameterList(
2098 TemplateParams,
2099 FunctionTemplate->getPreviousDecl()->getTemplateParameters(),
2100 Function->isThisDeclarationADefinition()
2101 ? Sema::TPC_FriendFunctionTemplateDefinition
2102 : Sema::TPC_FriendFunctionTemplate);
2103 }
2104 }
2105
2106 if (D->isExplicitlyDefaulted()) {
2107 if (SubstDefaultedFunction(Function, D))
2108 return nullptr;
2109 }
2110 if (D->isDeleted())
2111 SemaRef.SetDeclDeleted(Function, D->getLocation());
2112
2113 if (Function->isLocalExternDecl() && !Function->getPreviousDecl())
2114 DC->makeDeclVisibleInContext(PrincipalDecl);
2115
2116 if (Function->isOverloadedOperator() && !DC->isRecord() &&
2117 PrincipalDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
2118 PrincipalDecl->setNonMemberOperator();
2119
2120 return Function;
2121 }
2122
2123 Decl *TemplateDeclInstantiator::VisitCXXMethodDecl(
2124 CXXMethodDecl *D, TemplateParameterList *TemplateParams,
2125 Optional<const ASTTemplateArgumentListInfo *> ClassScopeSpecializationArgs,
2126 RewriteKind FunctionRewriteKind) {
2127 FunctionTemplateDecl *FunctionTemplate = D->getDescribedFunctionTemplate();
2128 if (FunctionTemplate && !TemplateParams) {
2129 // We are creating a function template specialization from a function
2130 // template. Check whether there is already a function template
2131 // specialization for this particular set of template arguments.
2132 ArrayRef<TemplateArgument> Innermost = TemplateArgs.getInnermost();
2133
2134 void *InsertPos = nullptr;
2135 FunctionDecl *SpecFunc
2136 = FunctionTemplate->findSpecialization(Innermost, InsertPos);
2137
2138 // If we already have a function template specialization, return it.
2139 if (SpecFunc)
2140 return SpecFunc;
2141 }
2142
2143 bool isFriend;
2144 if (FunctionTemplate)
2145 isFriend = (FunctionTemplate->getFriendObjectKind() != Decl::FOK_None);
2146 else
2147 isFriend = (D->getFriendObjectKind() != Decl::FOK_None);
2148
2149 bool MergeWithParentScope = (TemplateParams != nullptr) ||
2150 !(isa<Decl>(Owner) &&
2151 cast<Decl>(Owner)->isDefinedOutsideFunctionOrMethod());
2152 LocalInstantiationScope Scope(SemaRef, MergeWithParentScope);
2153
2154 // Instantiate enclosing template arguments for friends.
2155 SmallVector<TemplateParameterList *, 4> TempParamLists;
2156 unsigned NumTempParamLists = 0;
2157 if (isFriend && (NumTempParamLists = D->getNumTemplateParameterLists())) {
2158 TempParamLists.resize(NumTempParamLists);
2159 for (unsigned I = 0; I != NumTempParamLists; ++I) {
2160 TemplateParameterList *TempParams = D->getTemplateParameterList(I);
2161 TemplateParameterList *InstParams = SubstTemplateParams(TempParams);
2162 if (!InstParams)
2163 return nullptr;
2164 TempParamLists[I] = InstParams;
2165 }
2166 }
2167
2168 ExplicitSpecifier InstantiatedExplicitSpecifier =
2169 instantiateExplicitSpecifier(SemaRef, TemplateArgs,
2170 ExplicitSpecifier::getFromDecl(D), D);
2171 if (InstantiatedExplicitSpecifier.isInvalid())
2172 return nullptr;
2173
2174 SmallVector<ParmVarDecl *, 4> Params;
2175 TypeSourceInfo *TInfo = SubstFunctionType(D, Params);
2176 if (!TInfo)
2177 return nullptr;
2178 QualType T = adjustFunctionTypeForInstantiation(SemaRef.Context, D, TInfo);
2179
2180 NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc();
2181 if (QualifierLoc) {
2182 QualifierLoc = SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc,
2183 TemplateArgs);
2184 if (!QualifierLoc)
2185 return nullptr;
2186 }
2187
2188 // FIXME: Concepts: Do not substitute into constraint expressions
2189 Expr *TrailingRequiresClause = D->getTrailingRequiresClause();
2190 if (TrailingRequiresClause) {
2191 EnterExpressionEvaluationContext ConstantEvaluated(
2192 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
2193 ExprResult SubstRC = SemaRef.SubstExpr(TrailingRequiresClause,
2194 TemplateArgs);
2195 if (SubstRC.isInvalid())
2196 return nullptr;
2197 TrailingRequiresClause = SubstRC.get();
2198 if (!SemaRef.CheckConstraintExpression(TrailingRequiresClause))
2199 return nullptr;
2200 }
2201
2202 DeclContext *DC = Owner;
2203 if (isFriend) {
2204 if (QualifierLoc) {
2205 CXXScopeSpec SS;
2206 SS.Adopt(QualifierLoc);
2207 DC = SemaRef.computeDeclContext(SS);
2208
2209 if (DC && SemaRef.RequireCompleteDeclContext(SS, DC))
2210 return nullptr;
2211 } else {
2212 DC = SemaRef.FindInstantiatedContext(D->getLocation(),
2213 D->getDeclContext(),
2214 TemplateArgs);
2215 }
2216 if (!DC) return nullptr;
2217 }
2218
2219 DeclarationNameInfo NameInfo
2220 = SemaRef.SubstDeclarationNameInfo(D->getNameInfo(), TemplateArgs);
2221
2222 if (FunctionRewriteKind != RewriteKind::None)
2223 adjustForRewrite(FunctionRewriteKind, D, T, TInfo, NameInfo);
2224
2225 // Build the instantiated method declaration.
2226 CXXRecordDecl *Record = cast<CXXRecordDecl>(DC);
2227 CXXMethodDecl *Method = nullptr;
2228
2229 SourceLocation StartLoc = D->getInnerLocStart();
2230 if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) {
2231 Method = CXXConstructorDecl::Create(
2232 SemaRef.Context, Record, StartLoc, NameInfo, T, TInfo,
2233 InstantiatedExplicitSpecifier, Constructor->isInlineSpecified(), false,
2234 Constructor->getConstexprKind(), InheritedConstructor(),
2235 TrailingRequiresClause);
2236 Method->setRangeEnd(Constructor->getEndLoc());
2237 } else if (CXXDestructorDecl *Destructor = dyn_cast<CXXDestructorDecl>(D)) {
2238 Method = CXXDestructorDecl::Create(
2239 SemaRef.Context, Record, StartLoc, NameInfo, T, TInfo,
2240 Destructor->isInlineSpecified(), false, Destructor->getConstexprKind(),
2241 TrailingRequiresClause);
2242 Method->setRangeEnd(Destructor->getEndLoc());
2243 } else if (CXXConversionDecl *Conversion = dyn_cast<CXXConversionDecl>(D)) {
2244 Method = CXXConversionDecl::Create(
2245 SemaRef.Context, Record, StartLoc, NameInfo, T, TInfo,
2246 Conversion->isInlineSpecified(), InstantiatedExplicitSpecifier,
2247 Conversion->getConstexprKind(), Conversion->getEndLoc(),
2248 TrailingRequiresClause);
2249 } else {
2250 StorageClass SC = D->isStatic() ? SC_Static : SC_None;
2251 Method = CXXMethodDecl::Create(SemaRef.Context, Record, StartLoc, NameInfo,
2252 T, TInfo, SC, D->isInlineSpecified(),
2253 D->getConstexprKind(), D->getEndLoc(),
2254 TrailingRequiresClause);
2255 }
2256
2257 if (D->isInlined())
2258 Method->setImplicitlyInline();
2259
2260 if (QualifierLoc)
2261 Method->setQualifierInfo(QualifierLoc);
2262
2263 if (TemplateParams) {
2264 // Our resulting instantiation is actually a function template, since we
2265 // are substituting only the outer template parameters. For example, given
2266 //
2267 // template<typename T>
2268 // struct X {
2269 // template<typename U> void f(T, U);
2270 // };
2271 //
2272 // X<int> x;
2273 //
2274 // We are instantiating the member template "f" within X<int>, which means
2275 // substituting int for T, but leaving "f" as a member function template.
2276 // Build the function template itself.
2277 FunctionTemplate = FunctionTemplateDecl::Create(SemaRef.Context, Record,
2278 Method->getLocation(),
2279 Method->getDeclName(),
2280 TemplateParams, Method);
2281 if (isFriend) {
2282 FunctionTemplate->setLexicalDeclContext(Owner);
2283 FunctionTemplate->setObjectOfFriendDecl();
2284 } else if (D->isOutOfLine())
2285 FunctionTemplate->setLexicalDeclContext(D->getLexicalDeclContext());
2286 Method->setDescribedFunctionTemplate(FunctionTemplate);
2287 } else if (FunctionTemplate) {
2288 // Record this function template specialization.
2289 ArrayRef<TemplateArgument> Innermost = TemplateArgs.getInnermost();
2290 Method->setFunctionTemplateSpecialization(FunctionTemplate,
2291 TemplateArgumentList::CreateCopy(SemaRef.Context,
2292 Innermost),
2293 /*InsertPos=*/nullptr);
2294 } else if (!isFriend) {
2295 // Record that this is an instantiation of a member function.
2296 Method->setInstantiationOfMemberFunction(D, TSK_ImplicitInstantiation);
2297 }
2298
2299 // If we are instantiating a member function defined
2300 // out-of-line, the instantiation will have the same lexical
2301 // context (which will be a namespace scope) as the template.
2302 if (isFriend) {
2303 if (NumTempParamLists)
2304 Method->setTemplateParameterListsInfo(
2305 SemaRef.Context,
2306 llvm::makeArrayRef(TempParamLists.data(), NumTempParamLists));
2307
2308 Method->setLexicalDeclContext(Owner);
2309 Method->setObjectOfFriendDecl();
2310 } else if (D->isOutOfLine())
2311 Method->setLexicalDeclContext(D->getLexicalDeclContext());
2312
2313 // Attach the parameters
2314 for (unsigned P = 0; P < Params.size(); ++P)
2315 Params[P]->setOwningFunction(Method);
2316 Method->setParams(Params);
2317
2318 if (InitMethodInstantiation(Method, D))
2319 Method->setInvalidDecl();
2320
2321 LookupResult Previous(SemaRef, NameInfo, Sema::LookupOrdinaryName,
2322 Sema::ForExternalRedeclaration);
2323
2324 bool IsExplicitSpecialization = false;
2325
2326 // If the name of this function was written as a template-id, instantiate
2327 // the explicit template arguments.
2328 if (DependentFunctionTemplateSpecializationInfo *Info
2329 = D->getDependentSpecializationInfo()) {
2330 assert(isFriend && "non-friend has dependent specialization info?");
2331
2332 // Instantiate the explicit template arguments.
2333 TemplateArgumentListInfo ExplicitArgs(Info->getLAngleLoc(),
2334 Info->getRAngleLoc());
2335 if (SemaRef.Subst(Info->getTemplateArgs(), Info->getNumTemplateArgs(),
2336 ExplicitArgs, TemplateArgs))
2337 return nullptr;
2338
2339 // Map the candidate templates to their instantiations.
2340 for (unsigned I = 0, E = Info->getNumTemplates(); I != E; ++I) {
2341 Decl *Temp = SemaRef.FindInstantiatedDecl(D->getLocation(),
2342 Info->getTemplate(I),
2343 TemplateArgs);
2344 if (!Temp) return nullptr;
2345
2346 Previous.addDecl(cast<FunctionTemplateDecl>(Temp));
2347 }
2348
2349 if (SemaRef.CheckFunctionTemplateSpecialization(Method,
2350 &ExplicitArgs,
2351 Previous))
2352 Method->setInvalidDecl();
2353
2354 IsExplicitSpecialization = true;
2355 } else if (const ASTTemplateArgumentListInfo *Info =
2356 ClassScopeSpecializationArgs.getValueOr(
2357 D->getTemplateSpecializationArgsAsWritten())) {
2358 SemaRef.LookupQualifiedName(Previous, DC);
2359
2360 TemplateArgumentListInfo ExplicitArgs(Info->getLAngleLoc(),
2361 Info->getRAngleLoc());
2362 if (SemaRef.Subst(Info->getTemplateArgs(), Info->getNumTemplateArgs(),
2363 ExplicitArgs, TemplateArgs))
2364 return nullptr;
2365
2366 if (SemaRef.CheckFunctionTemplateSpecialization(Method,
2367 &ExplicitArgs,
2368 Previous))
2369 Method->setInvalidDecl();
2370
2371 IsExplicitSpecialization = true;
2372 } else if (ClassScopeSpecializationArgs) {
2373 // Class-scope explicit specialization written without explicit template
2374 // arguments.
2375 SemaRef.LookupQualifiedName(Previous, DC);
2376 if (SemaRef.CheckFunctionTemplateSpecialization(Method, nullptr, Previous))
2377 Method->setInvalidDecl();
2378
2379 IsExplicitSpecialization = true;
2380 } else if (!FunctionTemplate || TemplateParams || isFriend) {
2381 SemaRef.LookupQualifiedName(Previous, Record);
2382
2383 // In C++, the previous declaration we find might be a tag type
2384 // (class or enum). In this case, the new declaration will hide the
2385 // tag type. Note that this does does not apply if we're declaring a
2386 // typedef (C++ [dcl.typedef]p4).
2387 if (Previous.isSingleTagDecl())
2388 Previous.clear();
2389 }
2390
2391 SemaRef.CheckFunctionDeclaration(nullptr, Method, Previous,
2392 IsExplicitSpecialization);
2393
2394 if (D->isPure())
2395 SemaRef.CheckPureMethod(Method, SourceRange());
2396
2397 // Propagate access. For a non-friend declaration, the access is
2398 // whatever we're propagating from. For a friend, it should be the
2399 // previous declaration we just found.
2400 if (isFriend && Method->getPreviousDecl())
2401 Method->setAccess(Method->getPreviousDecl()->getAccess());
2402 else
2403 Method->setAccess(D->getAccess());
2404 if (FunctionTemplate)
2405 FunctionTemplate->setAccess(Method->getAccess());
2406
2407 SemaRef.CheckOverrideControl(Method);
2408
2409 // If a function is defined as defaulted or deleted, mark it as such now.
2410 if (D->isExplicitlyDefaulted()) {
2411 if (SubstDefaultedFunction(Method, D))
2412 return nullptr;
2413 }
2414 if (D->isDeletedAsWritten())
2415 SemaRef.SetDeclDeleted(Method, Method->getLocation());
2416
2417 // If this is an explicit specialization, mark the implicitly-instantiated
2418 // template specialization as being an explicit specialization too.
2419 // FIXME: Is this necessary?
2420 if (IsExplicitSpecialization && !isFriend)
2421 SemaRef.CompleteMemberSpecialization(Method, Previous);
2422
2423 // If there's a function template, let our caller handle it.
2424 if (FunctionTemplate) {
2425 // do nothing
2426
2427 // Don't hide a (potentially) valid declaration with an invalid one.
2428 } else if (Method->isInvalidDecl() && !Previous.empty()) {
2429 // do nothing
2430
2431 // Otherwise, check access to friends and make them visible.
2432 } else if (isFriend) {
2433 // We only need to re-check access for methods which we didn't
2434 // manage to match during parsing.
2435 if (!D->getPreviousDecl())
2436 SemaRef.CheckFriendAccess(Method);
2437
2438 Record->makeDeclVisibleInContext(Method);
2439
2440 // Otherwise, add the declaration. We don't need to do this for
2441 // class-scope specializations because we'll have matched them with
2442 // the appropriate template.
2443 } else {
2444 Owner->addDecl(Method);
2445 }
2446
2447 // PR17480: Honor the used attribute to instantiate member function
2448 // definitions
2449 if (Method->hasAttr<UsedAttr>()) {
2450 if (const auto *A = dyn_cast<CXXRecordDecl>(Owner)) {
2451 SourceLocation Loc;
2452 if (const MemberSpecializationInfo *MSInfo =
2453 A->getMemberSpecializationInfo())
2454 Loc = MSInfo->getPointOfInstantiation();
2455 else if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(A))
2456 Loc = Spec->getPointOfInstantiation();
2457 SemaRef.MarkFunctionReferenced(Loc, Method);
2458 }
2459 }
2460
2461 return Method;
2462 }
2463
2464 Decl *TemplateDeclInstantiator::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
2465 return VisitCXXMethodDecl(D);
2466 }
2467
2468 Decl *TemplateDeclInstantiator::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
2469 return VisitCXXMethodDecl(D);
2470 }
2471
2472 Decl *TemplateDeclInstantiator::VisitCXXConversionDecl(CXXConversionDecl *D) {
2473 return VisitCXXMethodDecl(D);
2474 }
2475
2476 Decl *TemplateDeclInstantiator::VisitParmVarDecl(ParmVarDecl *D) {
2477 return SemaRef.SubstParmVarDecl(D, TemplateArgs, /*indexAdjustment*/ 0, None,
2478 /*ExpectParameterPack=*/ false);
2479 }
2480
2481 Decl *TemplateDeclInstantiator::VisitTemplateTypeParmDecl(
2482 TemplateTypeParmDecl *D) {
2483 // TODO: don't always clone when decls are refcounted.
2484 assert(D->getTypeForDecl()->isTemplateTypeParmType());
2485
2486 Optional<unsigned> NumExpanded;
2487
2488 if (const TypeConstraint *TC = D->getTypeConstraint()) {
2489 if (D->isPackExpansion() && !D->isExpandedParameterPack()) {
2490 assert(TC->getTemplateArgsAsWritten() &&
2491 "type parameter can only be an expansion when explicit arguments "
2492 "are specified");
2493 // The template type parameter pack's type is a pack expansion of types.
2494 // Determine whether we need to expand this parameter pack into separate
2495 // types.
2496 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2497 for (auto &ArgLoc : TC->getTemplateArgsAsWritten()->arguments())
2498 SemaRef.collectUnexpandedParameterPacks(ArgLoc, Unexpanded);
2499
2500 // Determine whether the set of unexpanded parameter packs can and should
2501 // be expanded.
2502 bool Expand = true;
2503 bool RetainExpansion = false;
2504 if (SemaRef.CheckParameterPacksForExpansion(
2505 cast<CXXFoldExpr>(TC->getImmediatelyDeclaredConstraint())
2506 ->getEllipsisLoc(),
2507 SourceRange(TC->getConceptNameLoc(),
2508 TC->hasExplicitTemplateArgs() ?
2509 TC->getTemplateArgsAsWritten()->getRAngleLoc() :
2510 TC->getConceptNameInfo().getEndLoc()),
2511 Unexpanded, TemplateArgs, Expand, RetainExpansion, NumExpanded))
2512 return nullptr;
2513 }
2514 }
2515
2516 TemplateTypeParmDecl *Inst = TemplateTypeParmDecl::Create(
2517 SemaRef.Context, Owner, D->getBeginLoc(), D->getLocation(),
2518 D->getDepth() - TemplateArgs.getNumSubstitutedLevels(), D->getIndex(),
2519 D->getIdentifier(), D->wasDeclaredWithTypename(), D->isParameterPack(),
2520 D->hasTypeConstraint(), NumExpanded);
2521
2522 Inst->setAccess(AS_public);
2523 Inst->setImplicit(D->isImplicit());
2524 if (auto *TC = D->getTypeConstraint()) {
2525 // TODO: Concepts: do not instantiate the constraint (delayed constraint
2526 // substitution)
2527 const ASTTemplateArgumentListInfo *TemplArgInfo
2528 = TC->getTemplateArgsAsWritten();
2529 TemplateArgumentListInfo InstArgs;
2530
2531 if (TemplArgInfo) {
2532 InstArgs.setLAngleLoc(TemplArgInfo->LAngleLoc);
2533 InstArgs.setRAngleLoc(TemplArgInfo->RAngleLoc);
2534 if (SemaRef.Subst(TemplArgInfo->getTemplateArgs(),
2535 TemplArgInfo->NumTemplateArgs,
2536 InstArgs, TemplateArgs))
2537 return nullptr;
2538 }
2539 if (SemaRef.AttachTypeConstraint(
2540 TC->getNestedNameSpecifierLoc(), TC->getConceptNameInfo(),
2541 TC->getNamedConcept(), &InstArgs, Inst,
2542 D->isParameterPack()
2543 ? cast<CXXFoldExpr>(TC->getImmediatelyDeclaredConstraint())
2544 ->getEllipsisLoc()
2545 : SourceLocation()))
2546 return nullptr;
2547 }
2548 if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) {
2549 TypeSourceInfo *InstantiatedDefaultArg =
2550 SemaRef.SubstType(D->getDefaultArgumentInfo(), TemplateArgs,
2551 D->getDefaultArgumentLoc(), D->getDeclName());
2552 if (InstantiatedDefaultArg)
2553 Inst->setDefaultArgument(InstantiatedDefaultArg);
2554 }
2555
2556 // Introduce this template parameter's instantiation into the instantiation
2557 // scope.
2558 SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Inst);
2559
2560 return Inst;
2561 }
2562
2563 Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl(
2564 NonTypeTemplateParmDecl *D) {
2565 // Substitute into the type of the non-type template parameter.
2566 TypeLoc TL = D->getTypeSourceInfo()->getTypeLoc();
2567 SmallVector<TypeSourceInfo *, 4> ExpandedParameterPackTypesAsWritten;
2568 SmallVector<QualType, 4> ExpandedParameterPackTypes;
2569 bool IsExpandedParameterPack = false;
2570 TypeSourceInfo *DI;
2571 QualType T;
2572 bool Invalid = false;
2573
2574 if (D->isExpandedParameterPack()) {
2575 // The non-type template parameter pack is an already-expanded pack
2576 // expansion of types. Substitute into each of the expanded types.
2577 ExpandedParameterPackTypes.reserve(D->getNumExpansionTypes());
2578 ExpandedParameterPackTypesAsWritten.reserve(D->getNumExpansionTypes());
2579 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
2580 TypeSourceInfo *NewDI =
2581 SemaRef.SubstType(D->getExpansionTypeSourceInfo(I), TemplateArgs,
2582 D->getLocation(), D->getDeclName());
2583 if (!NewDI)
2584 return nullptr;
2585
2586 QualType NewT =
2587 SemaRef.CheckNonTypeTemplateParameterType(NewDI, D->getLocation());
2588 if (NewT.isNull())
2589 return nullptr;
2590
2591 ExpandedParameterPackTypesAsWritten.push_back(NewDI);
2592 ExpandedParameterPackTypes.push_back(NewT);
2593 }
2594
2595 IsExpandedParameterPack = true;
2596 DI = D->getTypeSourceInfo();
2597 T = DI->getType();
2598 } else if (D->isPackExpansion()) {
2599 // The non-type template parameter pack's type is a pack expansion of types.
2600 // Determine whether we need to expand this parameter pack into separate
2601 // types.
2602 PackExpansionTypeLoc Expansion = TL.castAs<PackExpansionTypeLoc>();
2603 TypeLoc Pattern = Expansion.getPatternLoc();
2604 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2605 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
2606
2607 // Determine whether the set of unexpanded parameter packs can and should
2608 // be expanded.
2609 bool Expand = true;
2610 bool RetainExpansion = false;
2611 Optional<unsigned> OrigNumExpansions
2612 = Expansion.getTypePtr()->getNumExpansions();
2613 Optional<unsigned> NumExpansions = OrigNumExpansions;
2614 if (SemaRef.CheckParameterPacksForExpansion(Expansion.getEllipsisLoc(),
2615 Pattern.getSourceRange(),
2616 Unexpanded,
2617 TemplateArgs,
2618 Expand, RetainExpansion,
2619 NumExpansions))
2620 return nullptr;
2621
2622 if (Expand) {
2623 for (unsigned I = 0; I != *NumExpansions; ++I) {
2624 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
2625 TypeSourceInfo *NewDI = SemaRef.SubstType(Pattern, TemplateArgs,
2626 D->getLocation(),
2627 D->getDeclName());
2628 if (!NewDI)
2629 return nullptr;
2630
2631 QualType NewT =
2632 SemaRef.CheckNonTypeTemplateParameterType(NewDI, D->getLocation());
2633 if (NewT.isNull())
2634 return nullptr;
2635
2636 ExpandedParameterPackTypesAsWritten.push_back(NewDI);
2637 ExpandedParameterPackTypes.push_back(NewT);
2638 }
2639
2640 // Note that we have an expanded parameter pack. The "type" of this
2641 // expanded parameter pack is the original expansion type, but callers
2642 // will end up using the expanded parameter pack types for type-checking.
2643 IsExpandedParameterPack = true;
2644 DI = D->getTypeSourceInfo();
2645 T = DI->getType();
2646 } else {
2647 // We cannot fully expand the pack expansion now, so substitute into the
2648 // pattern and create a new pack expansion type.
2649 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, -1);
2650 TypeSourceInfo *NewPattern = SemaRef.SubstType(Pattern, TemplateArgs,
2651 D->getLocation(),
2652 D->getDeclName());
2653 if (!NewPattern)
2654 return nullptr;
2655
2656 SemaRef.CheckNonTypeTemplateParameterType(NewPattern, D->getLocation());
2657 DI = SemaRef.CheckPackExpansion(NewPattern, Expansion.getEllipsisLoc(),
2658 NumExpansions);
2659 if (!DI)
2660 return nullptr;
2661
2662 T = DI->getType();
2663 }
2664 } else {
2665 // Simple case: substitution into a parameter that is not a parameter pack.
2666 DI = SemaRef.SubstType(D->getTypeSourceInfo(), TemplateArgs,
2667 D->getLocation(), D->getDeclName());
2668 if (!DI)
2669 return nullptr;
2670
2671 // Check that this type is acceptable for a non-type template parameter.
2672 T = SemaRef.CheckNonTypeTemplateParameterType(DI, D->getLocation());
2673 if (T.isNull()) {
2674 T = SemaRef.Context.IntTy;
2675 Invalid = true;
2676 }
2677 }
2678
2679 NonTypeTemplateParmDecl *Param;
2680 if (IsExpandedParameterPack)
2681 Param = NonTypeTemplateParmDecl::Create(
2682 SemaRef.Context, Owner, D->getInnerLocStart(), D->getLocation(),
2683 D->getDepth() - TemplateArgs.getNumSubstitutedLevels(),
2684 D->getPosition(), D->getIdentifier(), T, DI, ExpandedParameterPackTypes,
2685 ExpandedParameterPackTypesAsWritten);
2686 else
2687 Param = NonTypeTemplateParmDecl::Create(
2688 SemaRef.Context, Owner, D->getInnerLocStart(), D->getLocation(),
2689 D->getDepth() - TemplateArgs.getNumSubstitutedLevels(),
2690 D->getPosition(), D->getIdentifier(), T, D->isParameterPack(), DI);
2691
2692 if (AutoTypeLoc AutoLoc = DI->getTypeLoc().getContainedAutoTypeLoc())
2693 if (AutoLoc.isConstrained())
2694 if (SemaRef.AttachTypeConstraint(
2695 AutoLoc, Param,
2696 IsExpandedParameterPack
2697 ? DI->getTypeLoc().getAs<PackExpansionTypeLoc>()
2698 .getEllipsisLoc()
2699 : SourceLocation()))
2700 Invalid = true;
2701
2702 Param->setAccess(AS_public);
2703 Param->setImplicit(D->isImplicit());
2704 if (Invalid)
2705 Param->setInvalidDecl();
2706
2707 if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) {
2708 EnterExpressionEvaluationContext ConstantEvaluated(
2709 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
2710 ExprResult Value = SemaRef.SubstExpr(D->getDefaultArgument(), TemplateArgs);
2711 if (!Value.isInvalid())
2712 Param->setDefaultArgument(Value.get());
2713 }
2714
2715 // Introduce this template parameter's instantiation into the instantiation
2716 // scope.
2717 SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Param);
2718 return Param;
2719 }
2720
2721 static void collectUnexpandedParameterPacks(
2722 Sema &S,
2723 TemplateParameterList *Params,
2724 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded) {
2725 for (const auto &P : *Params) {
2726 if (P->isTemplateParameterPack())
2727 continue;
2728 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P))
2729 S.collectUnexpandedParameterPacks(NTTP->getTypeSourceInfo()->getTypeLoc(),
2730 Unexpanded);
2731 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(P))
2732 collectUnexpandedParameterPacks(S, TTP->getTemplateParameters(),
2733 Unexpanded);
2734 }
2735 }
2736
2737 Decl *
2738 TemplateDeclInstantiator::VisitTemplateTemplateParmDecl(
2739 TemplateTemplateParmDecl *D) {
2740 // Instantiate the template parameter list of the template template parameter.
2741 TemplateParameterList *TempParams = D->getTemplateParameters();
2742 TemplateParameterList *InstParams;
2743 SmallVector<TemplateParameterList*, 8> ExpandedParams;
2744
2745 bool IsExpandedParameterPack = false;
2746
2747 if (D->isExpandedParameterPack()) {
2748 // The template template parameter pack is an already-expanded pack
2749 // expansion of template parameters. Substitute into each of the expanded
2750 // parameters.
2751 ExpandedParams.reserve(D->getNumExpansionTemplateParameters());
2752 for (unsigned I = 0, N = D->getNumExpansionTemplateParameters();
2753 I != N; ++I) {
2754 LocalInstantiationScope Scope(SemaRef);
2755 TemplateParameterList *Expansion =
2756 SubstTemplateParams(D->getExpansionTemplateParameters(I));
2757 if (!Expansion)
2758 return nullptr;
2759 ExpandedParams.push_back(Expansion);
2760 }
2761
2762 IsExpandedParameterPack = true;
2763 InstParams = TempParams;
2764 } else if (D->isPackExpansion()) {
2765 // The template template parameter pack expands to a pack of template
2766 // template parameters. Determine whether we need to expand this parameter
2767 // pack into separate parameters.
2768 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2769 collectUnexpandedParameterPacks(SemaRef, D->getTemplateParameters(),
2770 Unexpanded);
2771
2772 // Determine whether the set of unexpanded parameter packs can and should
2773 // be expanded.
2774 bool Expand = true;
2775 bool RetainExpansion = false;
2776 Optional<unsigned> NumExpansions;
2777 if (SemaRef.CheckParameterPacksForExpansion(D->getLocation(),
2778 TempParams->getSourceRange(),
2779 Unexpanded,
2780 TemplateArgs,
2781 Expand, RetainExpansion,
2782 NumExpansions))
2783 return nullptr;
2784
2785 if (Expand) {
2786 for (unsigned I = 0; I != *NumExpansions; ++I) {
2787 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
2788 LocalInstantiationScope Scope(SemaRef);
2789 TemplateParameterList *Expansion = SubstTemplateParams(TempParams);
2790 if (!Expansion)
2791 return nullptr;
2792 ExpandedParams.push_back(Expansion);
2793 }
2794
2795 // Note that we have an expanded parameter pack. The "type" of this
2796 // expanded parameter pack is the original expansion type, but callers
2797 // will end up using the expanded parameter pack types for type-checking.
2798 IsExpandedParameterPack = true;
2799 InstParams = TempParams;
2800 } else {
2801 // We cannot fully expand the pack expansion now, so just substitute
2802 // into the pattern.
2803 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, -1);
2804
2805 LocalInstantiationScope Scope(SemaRef);
2806 InstParams = SubstTemplateParams(TempParams);
2807 if (!InstParams)
2808 return nullptr;
2809 }
2810 } else {
2811 // Perform the actual substitution of template parameters within a new,
2812 // local instantiation scope.
2813 LocalInstantiationScope Scope(SemaRef);
2814 InstParams = SubstTemplateParams(TempParams);
2815 if (!InstParams)
2816 return nullptr;
2817 }
2818
2819 // Build the template template parameter.
2820 TemplateTemplateParmDecl *Param;
2821 if (IsExpandedParameterPack)
2822 Param = TemplateTemplateParmDecl::Create(
2823 SemaRef.Context, Owner, D->getLocation(),
2824 D->getDepth() - TemplateArgs.getNumSubstitutedLevels(),
2825 D->getPosition(), D->getIdentifier(), InstParams, ExpandedParams);
2826 else
2827 Param = TemplateTemplateParmDecl::Create(
2828 SemaRef.Context, Owner, D->getLocation(),
2829 D->getDepth() - TemplateArgs.getNumSubstitutedLevels(),
2830 D->getPosition(), D->isParameterPack(), D->getIdentifier(), InstParams);
2831 if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) {
2832 NestedNameSpecifierLoc QualifierLoc =
2833 D->getDefaultArgument().getTemplateQualifierLoc();
2834 QualifierLoc =
2835 SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc, TemplateArgs);
2836 TemplateName TName = SemaRef.SubstTemplateName(
2837 QualifierLoc, D->getDefaultArgument().getArgument().getAsTemplate(),
2838 D->getDefaultArgument().getTemplateNameLoc(), TemplateArgs);
2839 if (!TName.isNull())
2840 Param->setDefaultArgument(
2841 SemaRef.Context,
2842 TemplateArgumentLoc(TemplateArgument(TName),
2843 D->getDefaultArgument().getTemplateQualifierLoc(),
2844 D->getDefaultArgument().getTemplateNameLoc()));
2845 }
2846 Param->setAccess(AS_public);
2847 Param->setImplicit(D->isImplicit());
2848
2849 // Introduce this template parameter's instantiation into the instantiation
2850 // scope.
2851 SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Param);
2852
2853 return Param;
2854 }
2855
2856 Decl *TemplateDeclInstantiator::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
2857 // Using directives are never dependent (and never contain any types or
2858 // expressions), so they require no explicit instantiation work.
2859
2860 UsingDirectiveDecl *Inst
2861 = UsingDirectiveDecl::Create(SemaRef.Context, Owner, D->getLocation(),
2862 D->getNamespaceKeyLocation(),
2863 D->getQualifierLoc(),
2864 D->getIdentLocation(),
2865 D->getNominatedNamespace(),
2866 D->getCommonAncestor());
2867
2868 // Add the using directive to its declaration context
2869 // only if this is not a function or method.
2870 if (!Owner->isFunctionOrMethod())
2871 Owner->addDecl(Inst);
2872
2873 return Inst;
2874 }
2875
2876 Decl *TemplateDeclInstantiator::VisitUsingDecl(UsingDecl *D) {
2877
2878 // The nested name specifier may be dependent, for example
2879 // template <typename T> struct t {
2880 // struct s1 { T f1(); };
2881 // struct s2 : s1 { using s1::f1; };
2882 // };
2883 // template struct t<int>;
2884 // Here, in using s1::f1, s1 refers to t<T>::s1;
2885 // we need to substitute for t<int>::s1.
2886 NestedNameSpecifierLoc QualifierLoc
2887 = SemaRef.SubstNestedNameSpecifierLoc(D->getQualifierLoc(),
2888 TemplateArgs);
2889 if (!QualifierLoc)
2890 return nullptr;
2891
2892 // For an inheriting constructor declaration, the name of the using
2893 // declaration is the name of a constructor in this class, not in the
2894 // base class.
2895 DeclarationNameInfo NameInfo = D->getNameInfo();
2896 if (NameInfo.getName().getNameKind() == DeclarationName::CXXConstructorName)
2897 if (auto *RD = dyn_cast<CXXRecordDecl>(SemaRef.CurContext))
2898 NameInfo.setName(SemaRef.Context.DeclarationNames.getCXXConstructorName(
2899 SemaRef.Context.getCanonicalType(SemaRef.Context.getRecordType(RD))));
2900
2901 // We only need to do redeclaration lookups if we're in a class
2902 // scope (in fact, it's not really even possible in non-class
2903 // scopes).
2904 bool CheckRedeclaration = Owner->isRecord();
2905
2906 LookupResult Prev(SemaRef, NameInfo, Sema::LookupUsingDeclName,
2907 Sema::ForVisibleRedeclaration);
2908
2909 UsingDecl *NewUD = UsingDecl::Create(SemaRef.Context, Owner,
2910 D->getUsingLoc(),
2911 QualifierLoc,
2912 NameInfo,
2913 D->hasTypename());
2914
2915 CXXScopeSpec SS;
2916 SS.Adopt(QualifierLoc);
2917 if (CheckRedeclaration) {
2918 Prev.setHideTags(false);
2919 SemaRef.LookupQualifiedName(Prev, Owner);
2920
2921 // Check for invalid redeclarations.
2922 if (SemaRef.CheckUsingDeclRedeclaration(D->getUsingLoc(),
2923 D->hasTypename(), SS,
2924 D->getLocation(), Prev))
2925 NewUD->setInvalidDecl();
2926
2927 }
2928
2929 if (!NewUD->isInvalidDecl() &&
2930 SemaRef.CheckUsingDeclQualifier(D->getUsingLoc(), D->hasTypename(),
2931 SS, NameInfo, D->getLocation()))
2932 NewUD->setInvalidDecl();
2933
2934 SemaRef.Context.setInstantiatedFromUsingDecl(NewUD, D);
2935 NewUD->setAccess(D->getAccess());
2936 Owner->addDecl(NewUD);
2937
2938 // Don't process the shadow decls for an invalid decl.
2939 if (NewUD->isInvalidDecl())
2940 return NewUD;
2941
2942 if (NameInfo.getName().getNameKind() == DeclarationName::CXXConstructorName)
2943 SemaRef.CheckInheritingConstructorUsingDecl(NewUD);
2944
2945 bool isFunctionScope = Owner->isFunctionOrMethod();
2946
2947 // Process the shadow decls.
2948 for (auto *Shadow : D->shadows()) {
2949 // FIXME: UsingShadowDecl doesn't preserve its immediate target, so
2950 // reconstruct it in the case where it matters.
2951 NamedDecl *OldTarget = Shadow->getTargetDecl();
2952 if (auto *CUSD = dyn_cast<ConstructorUsingShadowDecl>(Shadow))
2953 if (auto *BaseShadow = CUSD->getNominatedBaseClassShadowDecl())
2954 OldTarget = BaseShadow;
2955
2956 NamedDecl *InstTarget =
2957 cast_or_null<NamedDecl>(SemaRef.FindInstantiatedDecl(
2958 Shadow->getLocation(), OldTarget, TemplateArgs));
2959 if (!InstTarget)
2960 return nullptr;
2961
2962 UsingShadowDecl *PrevDecl = nullptr;
2963 if (CheckRedeclaration) {
2964 if (SemaRef.CheckUsingShadowDecl(NewUD, InstTarget, Prev, PrevDecl))
2965 continue;
2966 } else if (UsingShadowDecl *OldPrev =
2967 getPreviousDeclForInstantiation(Shadow)) {
2968 PrevDecl = cast_or_null<UsingShadowDecl>(SemaRef.FindInstantiatedDecl(
2969 Shadow->getLocation(), OldPrev, TemplateArgs));
2970 }
2971
2972 UsingShadowDecl *InstShadow =
2973 SemaRef.BuildUsingShadowDecl(/*Scope*/nullptr, NewUD, InstTarget,
2974 PrevDecl);
2975 SemaRef.Context.setInstantiatedFromUsingShadowDecl(InstShadow, Shadow);
2976
2977 if (isFunctionScope)
2978 SemaRef.CurrentInstantiationScope->InstantiatedLocal(Shadow, InstShadow);
2979 }
2980
2981 return NewUD;
2982 }
2983
2984 Decl *TemplateDeclInstantiator::VisitUsingShadowDecl(UsingShadowDecl *D) {
2985 // Ignore these; we handle them in bulk when processing the UsingDecl.
2986 return nullptr;
2987 }
2988
2989 Decl *TemplateDeclInstantiator::VisitConstructorUsingShadowDecl(
2990 ConstructorUsingShadowDecl *D) {
2991 // Ignore these; we handle them in bulk when processing the UsingDecl.
2992 return nullptr;
2993 }
2994
2995 template <typename T>
2996 Decl *TemplateDeclInstantiator::instantiateUnresolvedUsingDecl(
2997 T *D, bool InstantiatingPackElement) {
2998 // If this is a pack expansion, expand it now.
2999 if (D->isPackExpansion() && !InstantiatingPackElement) {
3000 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3001 SemaRef.collectUnexpandedParameterPacks(D->getQualifierLoc(), Unexpanded);
3002 SemaRef.collectUnexpandedParameterPacks(D->getNameInfo(), Unexpanded);
3003
3004 // Determine whether the set of unexpanded parameter packs can and should
3005 // be expanded.
3006 bool Expand = true;
3007 bool RetainExpansion = false;
3008 Optional<unsigned> NumExpansions;
3009 if (SemaRef.CheckParameterPacksForExpansion(
3010 D->getEllipsisLoc(), D->getSourceRange(), Unexpanded, TemplateArgs,
3011 Expand, RetainExpansion, NumExpansions))
3012 return nullptr;
3013
3014 // This declaration cannot appear within a function template signature,
3015 // so we can't have a partial argument list for a parameter pack.
3016 assert(!RetainExpansion &&
3017 "should never need to retain an expansion for UsingPackDecl");
3018
3019 if (!Expand) {
3020 // We cannot fully expand the pack expansion now, so substitute into the
3021 // pattern and create a new pack expansion.
3022 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, -1);
3023 return instantiateUnresolvedUsingDecl(D, true);
3024 }
3025
3026 // Within a function, we don't have any normal way to check for conflicts
3027 // between shadow declarations from different using declarations in the
3028 // same pack expansion, but this is always ill-formed because all expansions
3029 // must produce (conflicting) enumerators.
3030 //
3031 // Sadly we can't just reject this in the template definition because it
3032 // could be valid if the pack is empty or has exactly one expansion.
3033 if (D->getDeclContext()->isFunctionOrMethod() && *NumExpansions > 1) {
3034 SemaRef.Diag(D->getEllipsisLoc(),
3035 diag::err_using_decl_redeclaration_expansion);
3036 return nullptr;
3037 }
3038
3039 // Instantiate the slices of this pack and build a UsingPackDecl.
3040 SmallVector<NamedDecl*, 8> Expansions;
3041 for (unsigned I = 0; I != *NumExpansions; ++I) {
3042 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
3043 Decl *Slice = instantiateUnresolvedUsingDecl(D, true);
3044 if (!Slice)
3045 return nullptr;
3046 // Note that we can still get unresolved using declarations here, if we
3047 // had arguments for all packs but the pattern also contained other
3048 // template arguments (this only happens during partial substitution, eg
3049 // into the body of a generic lambda in a function template).
3050 Expansions.push_back(cast<NamedDecl>(Slice));
3051 }
3052
3053 auto *NewD = SemaRef.BuildUsingPackDecl(D, Expansions);
3054 if (isDeclWithinFunction(D))
3055 SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, NewD);
3056 return NewD;
3057 }
3058
3059 UnresolvedUsingTypenameDecl *TD = dyn_cast<UnresolvedUsingTypenameDecl>(D);
3060 SourceLocation TypenameLoc = TD ? TD->getTypenameLoc() : SourceLocation();
3061
3062 NestedNameSpecifierLoc QualifierLoc
3063 = SemaRef.SubstNestedNameSpecifierLoc(D->getQualifierLoc(),
3064 TemplateArgs);
3065 if (!QualifierLoc)
3066 return nullptr;
3067
3068 CXXScopeSpec SS;
3069 SS.Adopt(QualifierLoc);
3070
3071 DeclarationNameInfo NameInfo
3072 = SemaRef.SubstDeclarationNameInfo(D->getNameInfo(), TemplateArgs);
3073
3074 // Produce a pack expansion only if we're not instantiating a particular
3075 // slice of a pack expansion.
3076 bool InstantiatingSlice = D->getEllipsisLoc().isValid() &&
3077 SemaRef.ArgumentPackSubstitutionIndex != -1;
3078 SourceLocation EllipsisLoc =
3079 InstantiatingSlice ? SourceLocation() : D->getEllipsisLoc();
3080
3081 NamedDecl *UD = SemaRef.BuildUsingDeclaration(
3082 /*Scope*/ nullptr, D->getAccess(), D->getUsingLoc(),
3083 /*HasTypename*/ TD, TypenameLoc, SS, NameInfo, EllipsisLoc,
3084 ParsedAttributesView(),
3085 /*IsInstantiation*/ true);
3086 if (UD)
3087 SemaRef.Context.setInstantiatedFromUsingDecl(UD, D);
3088
3089 return UD;
3090 }
3091
3092 Decl *TemplateDeclInstantiator::VisitUnresolvedUsingTypenameDecl(
3093 UnresolvedUsingTypenameDecl *D) {
3094 return instantiateUnresolvedUsingDecl(D);
3095 }
3096
3097 Decl *TemplateDeclInstantiator::VisitUnresolvedUsingValueDecl(
3098 UnresolvedUsingValueDecl *D) {
3099 return instantiateUnresolvedUsingDecl(D);
3100 }
3101
3102 Decl *TemplateDeclInstantiator::VisitUsingPackDecl(UsingPackDecl *D) {
3103 SmallVector<NamedDecl*, 8> Expansions;
3104 for (auto *UD : D->expansions()) {
3105 if (NamedDecl *NewUD =
3106 SemaRef.FindInstantiatedDecl(D->getLocation(), UD, TemplateArgs))
3107 Expansions.push_back(NewUD);
3108 else
3109 return nullptr;
3110 }
3111
3112 auto *NewD = SemaRef.BuildUsingPackDecl(D, Expansions);
3113 if (isDeclWithinFunction(D))
3114 SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, NewD);
3115 return NewD;
3116 }
3117
3118 Decl *TemplateDeclInstantiator::VisitClassScopeFunctionSpecializationDecl(
3119 ClassScopeFunctionSpecializationDecl *Decl) {
3120 CXXMethodDecl *OldFD = Decl->getSpecialization();
3121 return cast_or_null<CXXMethodDecl>(
3122 VisitCXXMethodDecl(OldFD, nullptr, Decl->getTemplateArgsAsWritten()));
3123 }
3124
3125 Decl *TemplateDeclInstantiator::VisitOMPThreadPrivateDecl(
3126 OMPThreadPrivateDecl *D) {
3127 SmallVector<Expr *, 5> Vars;
3128 for (auto *I : D->varlists()) {
3129 Expr *Var = SemaRef.SubstExpr(I, TemplateArgs).get();
3130 assert(isa<DeclRefExpr>(Var) && "threadprivate arg is not a DeclRefExpr");
3131 Vars.push_back(Var);
3132 }
3133
3134 OMPThreadPrivateDecl *TD =
3135 SemaRef.CheckOMPThreadPrivateDecl(D->getLocation(), Vars);
3136
3137 TD->setAccess(AS_public);
3138 Owner->addDecl(TD);
3139
3140 return TD;
3141 }
3142
3143 Decl *TemplateDeclInstantiator::VisitOMPAllocateDecl(OMPAllocateDecl *D) {
3144 SmallVector<Expr *, 5> Vars;
3145 for (auto *I : D->varlists()) {
3146 Expr *Var = SemaRef.SubstExpr(I, TemplateArgs).get();
3147 assert(isa<DeclRefExpr>(Var) && "allocate arg is not a DeclRefExpr");
3148 Vars.push_back(Var);
3149 }
3150 SmallVector<OMPClause *, 4> Clauses;
3151 // Copy map clauses from the original mapper.
3152 for (OMPClause *C : D->clauselists()) {
3153 auto *AC = cast<OMPAllocatorClause>(C);
3154 ExprResult NewE = SemaRef.SubstExpr(AC->getAllocator(), TemplateArgs);
3155 if (!NewE.isUsable())
3156 continue;
3157 OMPClause *IC = SemaRef.ActOnOpenMPAllocatorClause(
3158 NewE.get(), AC->getBeginLoc(), AC->getLParenLoc(), AC->getEndLoc());
3159 Clauses.push_back(IC);
3160 }
3161
3162 Sema::DeclGroupPtrTy Res = SemaRef.ActOnOpenMPAllocateDirective(
3163 D->getLocation(), Vars, Clauses, Owner);
3164 if (Res.get().isNull())
3165 return nullptr;
3166 return Res.get().getSingleDecl();
3167 }
3168
3169 Decl *TemplateDeclInstantiator::VisitOMPRequiresDecl(OMPRequiresDecl *D) {
3170 llvm_unreachable(
3171 "Requires directive cannot be instantiated within a dependent context");
3172 }
3173
3174 Decl *TemplateDeclInstantiator::VisitOMPDeclareReductionDecl(
3175 OMPDeclareReductionDecl *D) {
3176 // Instantiate type and check if it is allowed.
3177 const bool RequiresInstantiation =
3178 D->getType()->isDependentType() ||
3179 D->getType()->isInstantiationDependentType() ||
3180 D->getType()->containsUnexpandedParameterPack();
3181 QualType SubstReductionType;
3182 if (RequiresInstantiation) {
3183 SubstReductionType = SemaRef.ActOnOpenMPDeclareReductionType(
3184 D->getLocation(),
3185 ParsedType::make(SemaRef.SubstType(
3186 D->getType(), TemplateArgs, D->getLocation(), DeclarationName())));
3187 } else {
3188 SubstReductionType = D->getType();
3189 }
3190 if (SubstReductionType.isNull())
3191 return nullptr;
3192 Expr *Combiner = D->getCombiner();
3193 Expr *Init = D->getInitializer();
3194 bool IsCorrect = true;
3195 // Create instantiated copy.
3196 std::pair<QualType, SourceLocation> ReductionTypes[] = {
3197 std::make_pair(SubstReductionType, D->getLocation())};
3198 auto *PrevDeclInScope = D->getPrevDeclInScope();
3199 if (PrevDeclInScope && !PrevDeclInScope->isInvalidDecl()) {
3200 PrevDeclInScope = cast<OMPDeclareReductionDecl>(
3201 SemaRef.CurrentInstantiationScope->findInstantiationOf(PrevDeclInScope)
3202 ->get<Decl *>());
3203 }
3204 auto DRD = SemaRef.ActOnOpenMPDeclareReductionDirectiveStart(
3205 /*S=*/nullptr, Owner, D->getDeclName(), ReductionTypes, D->getAccess(),
3206 PrevDeclInScope);
3207 auto *NewDRD = cast<OMPDeclareReductionDecl>(DRD.get().getSingleDecl());
3208 SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, NewDRD);
3209 Expr *SubstCombiner = nullptr;
3210 Expr *SubstInitializer = nullptr;
3211 // Combiners instantiation sequence.
3212 if (Combiner) {
3213 SemaRef.ActOnOpenMPDeclareReductionCombinerStart(
3214 /*S=*/nullptr, NewDRD);
3215 SemaRef.CurrentInstantiationScope->InstantiatedLocal(
3216 cast<DeclRefExpr>(D->getCombinerIn())->getDecl(),
3217 cast<DeclRefExpr>(NewDRD->getCombinerIn())->getDecl());
3218 SemaRef.CurrentInstantiationScope->InstantiatedLocal(
3219 cast<DeclRefExpr>(D->getCombinerOut())->getDecl(),
3220 cast<DeclRefExpr>(NewDRD->getCombinerOut())->getDecl());
3221 auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(Owner);
3222 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, Qualifiers(),
3223 ThisContext);
3224 SubstCombiner = SemaRef.SubstExpr(Combiner, TemplateArgs).get();
3225 SemaRef.ActOnOpenMPDeclareReductionCombinerEnd(NewDRD, SubstCombiner);
3226 }
3227 // Initializers instantiation sequence.
3228 if (Init) {
3229 VarDecl *OmpPrivParm = SemaRef.ActOnOpenMPDeclareReductionInitializerStart(
3230 /*S=*/nullptr, NewDRD);
3231 SemaRef.CurrentInstantiationScope->InstantiatedLocal(
3232 cast<DeclRefExpr>(D->getInitOrig())->getDecl(),
3233 cast<DeclRefExpr>(NewDRD->getInitOrig())->getDecl());
3234 SemaRef.CurrentInstantiationScope->InstantiatedLocal(
3235 cast<DeclRefExpr>(D->getInitPriv())->getDecl(),
3236 cast<DeclRefExpr>(NewDRD->getInitPriv())->getDecl());
3237 if (D->getInitializerKind() == OMPDeclareReductionDecl::CallInit) {
3238 SubstInitializer = SemaRef.SubstExpr(Init, TemplateArgs).get();
3239 } else {
3240 auto *OldPrivParm =
3241 cast<VarDecl>(cast<DeclRefExpr>(D->getInitPriv())->getDecl());
3242 IsCorrect = IsCorrect && OldPrivParm->hasInit();
3243 if (IsCorrect)
3244 SemaRef.InstantiateVariableInitializer(OmpPrivParm, OldPrivParm,
3245 TemplateArgs);
3246 }
3247 SemaRef.ActOnOpenMPDeclareReductionInitializerEnd(NewDRD, SubstInitializer,
3248 OmpPrivParm);
3249 }
3250 IsCorrect = IsCorrect && SubstCombiner &&
3251 (!Init ||
3252 (D->getInitializerKind() == OMPDeclareReductionDecl::CallInit &&
3253 SubstInitializer) ||
3254 (D->getInitializerKind() != OMPDeclareReductionDecl::CallInit &&
3255 !SubstInitializer));
3256
3257 (void)SemaRef.ActOnOpenMPDeclareReductionDirectiveEnd(
3258 /*S=*/nullptr, DRD, IsCorrect && !D->isInvalidDecl());
3259
3260 return NewDRD;
3261 }
3262
3263 Decl *
3264 TemplateDeclInstantiator::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) {
3265 // Instantiate type and check if it is allowed.
3266 const bool RequiresInstantiation =
3267 D->getType()->isDependentType() ||
3268 D->getType()->isInstantiationDependentType() ||
3269 D->getType()->containsUnexpandedParameterPack();
3270 QualType SubstMapperTy;
3271 DeclarationName VN = D->getVarName();
3272 if (RequiresInstantiation) {
3273 SubstMapperTy = SemaRef.ActOnOpenMPDeclareMapperType(
3274 D->getLocation(),
3275 ParsedType::make(SemaRef.SubstType(D->getType(), TemplateArgs,
3276 D->getLocation(), VN)));
3277 } else {
3278 SubstMapperTy = D->getType();
3279 }
3280 if (SubstMapperTy.isNull())
3281 return nullptr;
3282 // Create an instantiated copy of mapper.
3283 auto *PrevDeclInScope = D->getPrevDeclInScope();
3284 if (PrevDeclInScope && !PrevDeclInScope->isInvalidDecl()) {
3285 PrevDeclInScope = cast<OMPDeclareMapperDecl>(
3286 SemaRef.CurrentInstantiationScope->findInstantiationOf(PrevDeclInScope)
3287 ->get<Decl *>());
3288 }
3289 OMPDeclareMapperDecl *NewDMD = SemaRef.ActOnOpenMPDeclareMapperDirectiveStart(
3290 /*S=*/nullptr, Owner, D->getDeclName(), SubstMapperTy, D->getLocation(),
3291 VN, D->getAccess(), PrevDeclInScope);
3292 SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, NewDMD);
3293 SmallVector<OMPClause *, 6> Clauses;
3294 bool IsCorrect = true;
3295 if (!RequiresInstantiation) {
3296 // Copy the mapper variable.
3297 NewDMD->setMapperVarRef(D->getMapperVarRef());
3298 // Copy map clauses from the original mapper.
3299 for (OMPClause *C : D->clauselists())
3300 Clauses.push_back(C);
3301 } else {
3302 // Instantiate the mapper variable.
3303 DeclarationNameInfo DirName;
3304 SemaRef.StartOpenMPDSABlock(llvm::omp::OMPD_declare_mapper, DirName,
3305 /*S=*/nullptr,
3306 (*D->clauselist_begin())->getBeginLoc());
3307 SemaRef.ActOnOpenMPDeclareMapperDirectiveVarDecl(
3308 NewDMD, /*S=*/nullptr, SubstMapperTy, D->getLocation(), VN);
3309 SemaRef.CurrentInstantiationScope->InstantiatedLocal(
3310 cast<DeclRefExpr>(D->getMapperVarRef())->getDecl(),
3311 cast<DeclRefExpr>(NewDMD->getMapperVarRef())->getDecl());
3312 auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(Owner);
3313 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, Qualifiers(),
3314 ThisContext);
3315 // Instantiate map clauses.
3316 for (OMPClause *C : D->clauselists()) {
3317 auto *OldC = cast<OMPMapClause>(C);
3318 SmallVector<Expr *, 4> NewVars;
3319 for (Expr *OE : OldC->varlists()) {
3320 Expr *NE = SemaRef.SubstExpr(OE, TemplateArgs).get();
3321 if (!NE) {
3322 IsCorrect = false;
3323 break;
3324 }
3325 NewVars.push_back(NE);
3326 }
3327 if (!IsCorrect)
3328 break;
3329 NestedNameSpecifierLoc NewQualifierLoc =
3330 SemaRef.SubstNestedNameSpecifierLoc(OldC->getMapperQualifierLoc(),
3331 TemplateArgs);
3332 CXXScopeSpec SS;
3333 SS.Adopt(NewQualifierLoc);
3334 DeclarationNameInfo NewNameInfo = SemaRef.SubstDeclarationNameInfo(
3335 OldC->getMapperIdInfo(), TemplateArgs);
3336 OMPVarListLocTy Locs(OldC->getBeginLoc(), OldC->getLParenLoc(),
3337 OldC->getEndLoc());
3338 OMPClause *NewC = SemaRef.ActOnOpenMPMapClause(
3339 OldC->getMapTypeModifiers(), OldC->getMapTypeModifiersLoc(), SS,
3340 NewNameInfo, OldC->getMapType(), OldC->isImplicitMapType(),
3341 OldC->getMapLoc(), OldC->getColonLoc(), NewVars, Locs);
3342 Clauses.push_back(NewC);
3343 }
3344 SemaRef.EndOpenMPDSABlock(nullptr);
3345 }
3346 (void)SemaRef.ActOnOpenMPDeclareMapperDirectiveEnd(NewDMD, /*S=*/nullptr,
3347 Clauses);
3348 if (!IsCorrect)
3349 return nullptr;
3350 return NewDMD;
3351 }
3352
3353 Decl *TemplateDeclInstantiator::VisitOMPCapturedExprDecl(
3354 OMPCapturedExprDecl * /*D*/) {
3355 llvm_unreachable("Should not be met in templates");
3356 }
3357
3358 Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D) {
3359 return VisitFunctionDecl(D, nullptr);
3360 }
3361
3362 Decl *
3363 TemplateDeclInstantiator::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) {
3364 Decl *Inst = VisitFunctionDecl(D, nullptr);
3365 if (Inst && !D->getDescribedFunctionTemplate())
3366 Owner->addDecl(Inst);
3367 return Inst;
3368 }
3369
3370 Decl *TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D) {
3371 return VisitCXXMethodDecl(D, nullptr);
3372 }
3373
3374 Decl *TemplateDeclInstantiator::VisitRecordDecl(RecordDecl *D) {
3375 llvm_unreachable("There are only CXXRecordDecls in C++");
3376 }
3377
3378 Decl *
3379 TemplateDeclInstantiator::VisitClassTemplateSpecializationDecl(
3380 ClassTemplateSpecializationDecl *D) {
3381 // As a MS extension, we permit class-scope explicit specialization
3382 // of member class templates.
3383 ClassTemplateDecl *ClassTemplate = D->getSpecializedTemplate();
3384 assert(ClassTemplate->getDeclContext()->isRecord() &&
3385 D->getTemplateSpecializationKind() == TSK_ExplicitSpecialization &&
3386 "can only instantiate an explicit specialization "
3387 "for a member class template");
3388
3389 // Lookup the already-instantiated declaration in the instantiation
3390 // of the class template.
3391 ClassTemplateDecl *InstClassTemplate =
3392 cast_or_null<ClassTemplateDecl>(SemaRef.FindInstantiatedDecl(
3393 D->getLocation(), ClassTemplate, TemplateArgs));
3394 if (!InstClassTemplate)
3395 return nullptr;
3396
3397 // Substitute into the template arguments of the class template explicit
3398 // specialization.
3399 TemplateSpecializationTypeLoc Loc = D->getTypeAsWritten()->getTypeLoc().
3400 castAs<TemplateSpecializationTypeLoc>();
3401 TemplateArgumentListInfo InstTemplateArgs(Loc.getLAngleLoc(),
3402 Loc.getRAngleLoc());
3403 SmallVector<TemplateArgumentLoc, 4> ArgLocs;
3404 for (unsigned I = 0; I != Loc.getNumArgs(); ++I)
3405 ArgLocs.push_back(Loc.getArgLoc(I));
3406 if (SemaRef.Subst(ArgLocs.data(), ArgLocs.size(),
3407 InstTemplateArgs, TemplateArgs))
3408 return nullptr;
3409
3410 // Check that the template argument list is well-formed for this
3411 // class template.
3412 SmallVector<TemplateArgument, 4> Converted;
3413 if (SemaRef.CheckTemplateArgumentList(InstClassTemplate,
3414 D->getLocation(),
3415 InstTemplateArgs,
3416 false,
3417 Converted,
3418 /*UpdateArgsWithConversion=*/true))
3419 return nullptr;
3420
3421 // Figure out where to insert this class template explicit specialization
3422 // in the member template's set of class template explicit specializations.
3423 void *InsertPos = nullptr;
3424 ClassTemplateSpecializationDecl *PrevDecl =
3425 InstClassTemplate->findSpecialization(Converted, InsertPos);
3426
3427 // Check whether we've already seen a conflicting instantiation of this
3428 // declaration (for instance, if there was a prior implicit instantiation).
3429 bool Ignored;
3430 if (PrevDecl &&
3431 SemaRef.CheckSpecializationInstantiationRedecl(D->getLocation(),
3432 D->getSpecializationKind(),
3433 PrevDecl,
3434 PrevDecl->getSpecializationKind(),
3435 PrevDecl->getPointOfInstantiation(),
3436 Ignored))
3437 return nullptr;
3438
3439 // If PrevDecl was a definition and D is also a definition, diagnose.
3440 // This happens in cases like:
3441 //
3442 // template<typename T, typename U>
3443 // struct Outer {
3444 // template<typename X> struct Inner;
3445 // template<> struct Inner<T> {};
3446 // template<> struct Inner<U> {};
3447 // };
3448 //
3449 // Outer<int, int> outer; // error: the explicit specializations of Inner
3450 // // have the same signature.
3451 if (PrevDecl && PrevDecl->getDefinition() &&
3452 D->isThisDeclarationADefinition()) {
3453 SemaRef.Diag(D->getLocation(), diag::err_redefinition) << PrevDecl;
3454 SemaRef.Diag(PrevDecl->getDefinition()->getLocation(),
3455 diag::note_previous_definition);
3456 return nullptr;
3457 }
3458
3459 // Create the class template partial specialization declaration.
3460 ClassTemplateSpecializationDecl *InstD =
3461 ClassTemplateSpecializationDecl::Create(
3462 SemaRef.Context, D->getTagKind(), Owner, D->getBeginLoc(),
3463 D->getLocation(), InstClassTemplate, Converted, PrevDecl);
3464
3465 // Add this partial specialization to the set of class template partial
3466 // specializations.
3467 if (!PrevDecl)
3468 InstClassTemplate->AddSpecialization(InstD, InsertPos);
3469
3470 // Substitute the nested name specifier, if any.
3471 if (SubstQualifier(D, InstD))
3472 return nullptr;
3473
3474 // Build the canonical type that describes the converted template
3475 // arguments of the class template explicit specialization.
3476 QualType CanonType = SemaRef.Context.getTemplateSpecializationType(
3477 TemplateName(InstClassTemplate), Converted,
3478 SemaRef.Context.getRecordType(InstD));
3479
3480 // Build the fully-sugared type for this class template
3481 // specialization as the user wrote in the specialization
3482 // itself. This means that we'll pretty-print the type retrieved
3483 // from the specialization's declaration the way that the user
3484 // actually wrote the specialization, rather than formatting the
3485 // name based on the "canonical" representation used to store the
3486 // template arguments in the specialization.
3487 TypeSourceInfo *WrittenTy = SemaRef.Context.getTemplateSpecializationTypeInfo(
3488 TemplateName(InstClassTemplate), D->getLocation(), InstTemplateArgs,
3489 CanonType);
3490
3491 InstD->setAccess(D->getAccess());
3492 InstD->setInstantiationOfMemberClass(D, TSK_ImplicitInstantiation);
3493 InstD->setSpecializationKind(D->getSpecializationKind());
3494 InstD->setTypeAsWritten(WrittenTy);
3495 InstD->setExternLoc(D->getExternLoc());
3496 InstD->setTemplateKeywordLoc(D->getTemplateKeywordLoc());
3497
3498 Owner->addDecl(InstD);
3499
3500 // Instantiate the members of the class-scope explicit specialization eagerly.
3501 // We don't have support for lazy instantiation of an explicit specialization
3502 // yet, and MSVC eagerly instantiates in this case.
3503 // FIXME: This is wrong in standard C++.
3504 if (D->isThisDeclarationADefinition() &&
3505 SemaRef.InstantiateClass(D->getLocation(), InstD, D, TemplateArgs,
3506 TSK_ImplicitInstantiation,
3507 /*Complain=*/true))
3508 return nullptr;
3509
3510 return InstD;
3511 }
3512
3513 Decl *TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl(
3514 VarTemplateSpecializationDecl *D) {
3515
3516 TemplateArgumentListInfo VarTemplateArgsInfo;
3517 VarTemplateDecl *VarTemplate = D->getSpecializedTemplate();
3518 assert(VarTemplate &&
3519 "A template specialization without specialized template?");
3520
3521 VarTemplateDecl *InstVarTemplate =
3522 cast_or_null<VarTemplateDecl>(SemaRef.FindInstantiatedDecl(
3523 D->getLocation(), VarTemplate, TemplateArgs));
3524 if (!InstVarTemplate)
3525 return nullptr;
3526
3527 // Substitute the current template arguments.
3528 const TemplateArgumentListInfo &TemplateArgsInfo = D->getTemplateArgsInfo();
3529 VarTemplateArgsInfo.setLAngleLoc(TemplateArgsInfo.getLAngleLoc());
3530 VarTemplateArgsInfo.setRAngleLoc(TemplateArgsInfo.getRAngleLoc());
3531
3532 if (SemaRef.Subst(TemplateArgsInfo.getArgumentArray(),
3533 TemplateArgsInfo.size(), VarTemplateArgsInfo, TemplateArgs))
3534 return nullptr;
3535
3536 // Check that the template argument list is well-formed for this template.
3537 SmallVector<TemplateArgument, 4> Converted;
3538 if (SemaRef.CheckTemplateArgumentList(InstVarTemplate, D->getLocation(),
3539 VarTemplateArgsInfo, false, Converted,
3540 /*UpdateArgsWithConversion=*/true))
3541 return nullptr;
3542
3543 // Check whether we've already seen a declaration of this specialization.
3544 void *InsertPos = nullptr;
3545 VarTemplateSpecializationDecl *PrevDecl =
3546 InstVarTemplate->findSpecialization(Converted, InsertPos);
3547
3548 // Check whether we've already seen a conflicting instantiation of this
3549 // declaration (for instance, if there was a prior implicit instantiation).
3550 bool Ignored;
3551 if (PrevDecl && SemaRef.CheckSpecializationInstantiationRedecl(
3552 D->getLocation(), D->getSpecializationKind(), PrevDecl,
3553 PrevDecl->getSpecializationKind(),
3554 PrevDecl->getPointOfInstantiation(), Ignored))
3555 return nullptr;
3556
3557 return VisitVarTemplateSpecializationDecl(
3558 InstVarTemplate, D, InsertPos, VarTemplateArgsInfo, Converted, PrevDecl);
3559 }
3560
3561 Decl *TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl(
3562 VarTemplateDecl *VarTemplate, VarDecl *D, void *InsertPos,
3563 const TemplateArgumentListInfo &TemplateArgsInfo,
3564 ArrayRef<TemplateArgument> Converted,
3565 VarTemplateSpecializationDecl *PrevDecl) {
3566
3567 // Do substitution on the type of the declaration
3568 TypeSourceInfo *DI =
3569 SemaRef.SubstType(D->getTypeSourceInfo(), TemplateArgs,
3570 D->getTypeSpecStartLoc(), D->getDeclName());
3571 if (!DI)
3572 return nullptr;
3573
3574 if (DI->getType()->isFunctionType()) {
3575 SemaRef.Diag(D->getLocation(), diag::err_variable_instantiates_to_function)
3576 << D->isStaticDataMember() << DI->getType();
3577 return nullptr;
3578 }
3579
3580 // Build the instantiated declaration
3581 VarTemplateSpecializationDecl *Var = VarTemplateSpecializationDecl::Create(
3582 SemaRef.Context, Owner, D->getInnerLocStart(), D->getLocation(),
3583 VarTemplate, DI->getType(), DI, D->getStorageClass(), Converted);
3584 Var->setTemplateArgsInfo(TemplateArgsInfo);
3585 if (InsertPos)
3586 VarTemplate->AddSpecialization(Var, InsertPos);
3587
3588 // Substitute the nested name specifier, if any.
3589 if (SubstQualifier(D, Var))
3590 return nullptr;
3591
3592 SemaRef.BuildVariableInstantiation(Var, D, TemplateArgs, LateAttrs, Owner,
3593 StartingScope, false, PrevDecl);
3594
3595 return Var;
3596 }
3597
3598 Decl *TemplateDeclInstantiator::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) {
3599 llvm_unreachable("@defs is not supported in Objective-C++");
3600 }
3601
3602 Decl *TemplateDeclInstantiator::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
3603 // FIXME: We need to be able to instantiate FriendTemplateDecls.
3604 unsigned DiagID = SemaRef.getDiagnostics().getCustomDiagID(
3605 DiagnosticsEngine::Error,
3606 "cannot instantiate %0 yet");
3607 SemaRef.Diag(D->getLocation(), DiagID)
3608 << D->getDeclKindName();
3609
3610 return nullptr;
3611 }
3612
3613 Decl *TemplateDeclInstantiator::VisitConceptDecl(ConceptDecl *D) {
3614 llvm_unreachable("Concept definitions cannot reside inside a template");
3615 }
3616
3617 Decl *
3618 TemplateDeclInstantiator::VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D) {
3619 return RequiresExprBodyDecl::Create(SemaRef.Context, D->getDeclContext(),
3620 D->getBeginLoc());
3621 }
3622
3623 Decl *TemplateDeclInstantiator::VisitDecl(Decl *D) {
3624 llvm_unreachable("Unexpected decl");
3625 }
3626
3627 Decl *Sema::SubstDecl(Decl *D, DeclContext *Owner,
3628 const MultiLevelTemplateArgumentList &TemplateArgs) {
3629 TemplateDeclInstantiator Instantiator(*this, Owner, TemplateArgs);
3630 if (D->isInvalidDecl())
3631 return nullptr;
3632
3633 Decl *SubstD;
3634 runWithSufficientStackSpace(D->getLocation(), [&] {
3635 SubstD = Instantiator.Visit(D);
3636 });
3637 return SubstD;
3638 }
3639
3640 void TemplateDeclInstantiator::adjustForRewrite(RewriteKind RK,
3641 FunctionDecl *Orig, QualType &T,
3642 TypeSourceInfo *&TInfo,
3643 DeclarationNameInfo &NameInfo) {
3644 assert(RK == RewriteKind::RewriteSpaceshipAsEqualEqual);
3645
3646 // C++2a [class.compare.default]p3:
3647 // the return type is replaced with bool
3648 auto *FPT = T->castAs<FunctionProtoType>();
3649 T = SemaRef.Context.getFunctionType(
3650 SemaRef.Context.BoolTy, FPT->getParamTypes(), FPT->getExtProtoInfo());
3651
3652 // Update the return type in the source info too. The most straightforward
3653 // way is to create new TypeSourceInfo for the new type. Use the location of
3654 // the '= default' as the location of the new type.
3655 //
3656 // FIXME: Set the correct return type when we initially transform the type,
3657 // rather than delaying it to now.
3658 TypeSourceInfo *NewTInfo =
3659 SemaRef.Context.getTrivialTypeSourceInfo(T, Orig->getEndLoc());
3660 auto OldLoc = TInfo->getTypeLoc().getAsAdjusted<FunctionProtoTypeLoc>();
3661 assert(OldLoc && "type of function is not a function type?");
3662 auto NewLoc = NewTInfo->getTypeLoc().castAs<FunctionProtoTypeLoc>();
3663 for (unsigned I = 0, N = OldLoc.getNumParams(); I != N; ++I)
3664 NewLoc.setParam(I, OldLoc.getParam(I));
3665 TInfo = NewTInfo;
3666
3667 // and the declarator-id is replaced with operator==
3668 NameInfo.setName(
3669 SemaRef.Context.DeclarationNames.getCXXOperatorName(OO_EqualEqual));
3670 }
3671
3672 FunctionDecl *Sema::SubstSpaceshipAsEqualEqual(CXXRecordDecl *RD,
3673 FunctionDecl *Spaceship) {
3674 if (Spaceship->isInvalidDecl())
3675 return nullptr;
3676
3677 // C++2a [class.compare.default]p3:
3678 // an == operator function is declared implicitly [...] with the same
3679 // access and function-definition and in the same class scope as the
3680 // three-way comparison operator function
3681 MultiLevelTemplateArgumentList NoTemplateArgs;
3682 TemplateDeclInstantiator Instantiator(*this, RD, NoTemplateArgs);
3683 Decl *R;
3684 if (auto *MD = dyn_cast<CXXMethodDecl>(Spaceship)) {
3685 R = Instantiator.VisitCXXMethodDecl(
3686 MD, nullptr, None,
3687 TemplateDeclInstantiator::RewriteKind::RewriteSpaceshipAsEqualEqual);
3688 } else {
3689 assert(Spaceship->getFriendObjectKind() &&
3690 "defaulted spaceship is neither a member nor a friend");
3691
3692 R = Instantiator.VisitFunctionDecl(
3693 Spaceship, nullptr,
3694 TemplateDeclInstantiator::RewriteKind::RewriteSpaceshipAsEqualEqual);
3695 if (!R)
3696 return nullptr;
3697
3698 FriendDecl *FD =
3699 FriendDecl::Create(Context, RD, Spaceship->getLocation(),
3700 cast<NamedDecl>(R), Spaceship->getBeginLoc());
3701 FD->setAccess(AS_public);
3702 RD->addDecl(FD);
3703 }
3704 return cast_or_null<FunctionDecl>(R);
3705 }
3706
3707 /// Instantiates a nested template parameter list in the current
3708 /// instantiation context.
3709 ///
3710 /// \param L The parameter list to instantiate
3711 ///
3712 /// \returns NULL if there was an error
3713 TemplateParameterList *
3714 TemplateDeclInstantiator::SubstTemplateParams(TemplateParameterList *L) {
3715 // Get errors for all the parameters before bailing out.
3716 bool Invalid = false;
3717
3718 unsigned N = L->size();
3719 typedef SmallVector<NamedDecl *, 8> ParamVector;
3720 ParamVector Params;
3721 Params.reserve(N);
3722 for (auto &P : *L) {
3723 NamedDecl *D = cast_or_null<NamedDecl>(Visit(P));
3724 Params.push_back(D);
3725 Invalid = Invalid || !D || D->isInvalidDecl();
3726 }
3727
3728 // Clean up if we had an error.
3729 if (Invalid)
3730 return nullptr;
3731
3732 // FIXME: Concepts: Substitution into requires clause should only happen when
3733 // checking satisfaction.
3734 Expr *InstRequiresClause = nullptr;
3735 if (Expr *E = L->getRequiresClause()) {
3736 EnterExpressionEvaluationContext ConstantEvaluated(
3737 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
3738 ExprResult Res = SemaRef.SubstExpr(E, TemplateArgs);
3739 if (Res.isInvalid() || !Res.isUsable()) {
3740 return nullptr;
3741 }
3742 InstRequiresClause = Res.get();
3743 }
3744
3745 TemplateParameterList *InstL
3746 = TemplateParameterList::Create(SemaRef.Context, L->getTemplateLoc(),
3747 L->getLAngleLoc(), Params,
3748 L->getRAngleLoc(), InstRequiresClause);
3749 return InstL;
3750 }
3751
3752 TemplateParameterList *
3753 Sema::SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner,
3754 const MultiLevelTemplateArgumentList &TemplateArgs) {
3755 TemplateDeclInstantiator Instantiator(*this, Owner, TemplateArgs);
3756 return Instantiator.SubstTemplateParams(Params);
3757 }
3758
3759 /// Instantiate the declaration of a class template partial
3760 /// specialization.
3761 ///
3762 /// \param ClassTemplate the (instantiated) class template that is partially
3763 // specialized by the instantiation of \p PartialSpec.
3764 ///
3765 /// \param PartialSpec the (uninstantiated) class template partial
3766 /// specialization that we are instantiating.
3767 ///
3768 /// \returns The instantiated partial specialization, if successful; otherwise,
3769 /// NULL to indicate an error.
3770 ClassTemplatePartialSpecializationDecl *
3771 TemplateDeclInstantiator::InstantiateClassTemplatePartialSpecialization(
3772 ClassTemplateDecl *ClassTemplate,
3773 ClassTemplatePartialSpecializationDecl *PartialSpec) {
3774 // Create a local instantiation scope for this class template partial
3775 // specialization, which will contain the instantiations of the template
3776 // parameters.
3777 LocalInstantiationScope Scope(SemaRef);
3778
3779 // Substitute into the template parameters of the class template partial
3780 // specialization.
3781 TemplateParameterList *TempParams = PartialSpec->getTemplateParameters();
3782 TemplateParameterList *InstParams = SubstTemplateParams(TempParams);
3783 if (!InstParams)
3784 return nullptr;
3785
3786 // Substitute into the template arguments of the class template partial
3787 // specialization.
3788 const ASTTemplateArgumentListInfo *TemplArgInfo
3789 = PartialSpec->getTemplateArgsAsWritten();
3790 TemplateArgumentListInfo InstTemplateArgs(TemplArgInfo->LAngleLoc,
3791 TemplArgInfo->RAngleLoc);
3792 if (SemaRef.Subst(TemplArgInfo->getTemplateArgs(),
3793 TemplArgInfo->NumTemplateArgs,
3794 InstTemplateArgs, TemplateArgs))
3795 return nullptr;
3796
3797 // Check that the template argument list is well-formed for this
3798 // class template.
3799 SmallVector<TemplateArgument, 4> Converted;
3800 if (SemaRef.CheckTemplateArgumentList(ClassTemplate,
3801 PartialSpec->getLocation(),
3802 InstTemplateArgs,
3803 false,
3804 Converted))
3805 return nullptr;
3806
3807 // Check these arguments are valid for a template partial specialization.
3808 if (SemaRef.CheckTemplatePartialSpecializationArgs(
3809 PartialSpec->getLocation(), ClassTemplate, InstTemplateArgs.size(),
3810 Converted))
3811 return nullptr;
3812
3813 // Figure out where to insert this class template partial specialization
3814 // in the member template's set of class template partial specializations.
3815 void *InsertPos = nullptr;
3816 ClassTemplateSpecializationDecl *PrevDecl
3817 = ClassTemplate->findPartialSpecialization(Converted, InstParams,
3818 InsertPos);
3819
3820 // Build the canonical type that describes the converted template
3821 // arguments of the class template partial specialization.
3822 QualType CanonType
3823 = SemaRef.Context.getTemplateSpecializationType(TemplateName(ClassTemplate),
3824 Converted);
3825
3826 // Build the fully-sugared type for this class template
3827 // specialization as the user wrote in the specialization
3828 // itself. This means that we'll pretty-print the type retrieved
3829 // from the specialization's declaration the way that the user
3830 // actually wrote the specialization, rather than formatting the
3831 // name based on the "canonical" representation used to store the
3832 // template arguments in the specialization.
3833 TypeSourceInfo *WrittenTy
3834 = SemaRef.Context.getTemplateSpecializationTypeInfo(
3835 TemplateName(ClassTemplate),
3836 PartialSpec->getLocation(),
3837 InstTemplateArgs,
3838 CanonType);
3839
3840 if (PrevDecl) {
3841 // We've already seen a partial specialization with the same template
3842 // parameters and template arguments. This can happen, for example, when
3843 // substituting the outer template arguments ends up causing two
3844 // class template partial specializations of a member class template
3845 // to have identical forms, e.g.,
3846 //
3847 // template<typename T, typename U>
3848 // struct Outer {
3849 // template<typename X, typename Y> struct Inner;
3850 // template<typename Y> struct Inner<T, Y>;
3851 // template<typename Y> struct Inner<U, Y>;
3852 // };
3853 //
3854 // Outer<int, int> outer; // error: the partial specializations of Inner
3855 // // have the same signature.
3856 SemaRef.Diag(PartialSpec->getLocation(), diag::err_partial_spec_redeclared)
3857 << WrittenTy->getType();
3858 SemaRef.Diag(PrevDecl->getLocation(), diag::note_prev_partial_spec_here)
3859 << SemaRef.Context.getTypeDeclType(PrevDecl);
3860 return nullptr;
3861 }
3862
3863
3864 // Create the class template partial specialization declaration.
3865 ClassTemplatePartialSpecializationDecl *InstPartialSpec =
3866 ClassTemplatePartialSpecializationDecl::Create(
3867 SemaRef.Context, PartialSpec->getTagKind(), Owner,
3868 PartialSpec->getBeginLoc(), PartialSpec->getLocation(), InstParams,
3869 ClassTemplate, Converted, InstTemplateArgs, CanonType, nullptr);
3870 // Substitute the nested name specifier, if any.
3871 if (SubstQualifier(PartialSpec, InstPartialSpec))
3872 return nullptr;
3873
3874 InstPartialSpec->setInstantiatedFromMember(PartialSpec);
3875 InstPartialSpec->setTypeAsWritten(WrittenTy);
3876
3877 // Check the completed partial specialization.
3878 SemaRef.CheckTemplatePartialSpecialization(InstPartialSpec);
3879
3880 // Add this partial specialization to the set of class template partial
3881 // specializations.
3882 ClassTemplate->AddPartialSpecialization(InstPartialSpec,
3883 /*InsertPos=*/nullptr);
3884 return InstPartialSpec;
3885 }
3886
3887 /// Instantiate the declaration of a variable template partial
3888 /// specialization.
3889 ///
3890 /// \param VarTemplate the (instantiated) variable template that is partially
3891 /// specialized by the instantiation of \p PartialSpec.
3892 ///
3893 /// \param PartialSpec the (uninstantiated) variable template partial
3894 /// specialization that we are instantiating.
3895 ///
3896 /// \returns The instantiated partial specialization, if successful; otherwise,
3897 /// NULL to indicate an error.
3898 VarTemplatePartialSpecializationDecl *
3899 TemplateDeclInstantiator::InstantiateVarTemplatePartialSpecialization(
3900 VarTemplateDecl *VarTemplate,
3901 VarTemplatePartialSpecializationDecl *PartialSpec) {
3902 // Create a local instantiation scope for this variable template partial
3903 // specialization, which will contain the instantiations of the template
3904 // parameters.
3905 LocalInstantiationScope Scope(SemaRef);
3906
3907 // Substitute into the template parameters of the variable template partial
3908 // specialization.
3909 TemplateParameterList *TempParams = PartialSpec->getTemplateParameters();
3910 TemplateParameterList *InstParams = SubstTemplateParams(TempParams);
3911 if (!InstParams)
3912 return nullptr;
3913
3914 // Substitute into the template arguments of the variable template partial
3915 // specialization.
3916 const ASTTemplateArgumentListInfo *TemplArgInfo
3917 = PartialSpec->getTemplateArgsAsWritten();
3918 TemplateArgumentListInfo InstTemplateArgs(TemplArgInfo->LAngleLoc,
3919 TemplArgInfo->RAngleLoc);
3920 if (SemaRef.Subst(TemplArgInfo->getTemplateArgs(),
3921 TemplArgInfo->NumTemplateArgs,
3922 InstTemplateArgs, TemplateArgs))
3923 return nullptr;
3924
3925 // Check that the template argument list is well-formed for this
3926 // class template.
3927 SmallVector<TemplateArgument, 4> Converted;
3928 if (SemaRef.CheckTemplateArgumentList(VarTemplate, PartialSpec->getLocation(),
3929 InstTemplateArgs, false, Converted))
3930 return nullptr;
3931
3932 // Check these arguments are valid for a template partial specialization.
3933 if (SemaRef.CheckTemplatePartialSpecializationArgs(
3934 PartialSpec->getLocation(), VarTemplate, InstTemplateArgs.size(),
3935 Converted))
3936 return nullptr;
3937
3938 // Figure out where to insert this variable template partial specialization
3939 // in the member template's set of variable template partial specializations.
3940 void *InsertPos = nullptr;
3941 VarTemplateSpecializationDecl *PrevDecl =
3942 VarTemplate->findPartialSpecialization(Converted, InstParams, InsertPos);
3943
3944 // Build the canonical type that describes the converted template
3945 // arguments of the variable template partial specialization.
3946 QualType CanonType = SemaRef.Context.getTemplateSpecializationType(
3947 TemplateName(VarTemplate), Converted);
3948
3949 // Build the fully-sugared type for this variable template
3950 // specialization as the user wrote in the specialization
3951 // itself. This means that we'll pretty-print the type retrieved
3952 // from the specialization's declaration the way that the user
3953 // actually wrote the specialization, rather than formatting the
3954 // name based on the "canonical" representation used to store the
3955 // template arguments in the specialization.
3956 TypeSourceInfo *WrittenTy = SemaRef.Context.getTemplateSpecializationTypeInfo(
3957 TemplateName(VarTemplate), PartialSpec->getLocation(), InstTemplateArgs,
3958 CanonType);
3959
3960 if (PrevDecl) {
3961 // We've already seen a partial specialization with the same template
3962 // parameters and template arguments. This can happen, for example, when
3963 // substituting the outer template arguments ends up causing two
3964 // variable template partial specializations of a member variable template
3965 // to have identical forms, e.g.,
3966 //
3967 // template<typename T, typename U>
3968 // struct Outer {
3969 // template<typename X, typename Y> pair<X,Y> p;
3970 // template<typename Y> pair<T, Y> p;
3971 // template<typename Y> pair<U, Y> p;
3972 // };
3973 //
3974 // Outer<int, int> outer; // error: the partial specializations of Inner
3975 // // have the same signature.
3976 SemaRef.Diag(PartialSpec->getLocation(),
3977 diag::err_var_partial_spec_redeclared)
3978 << WrittenTy->getType();
3979 SemaRef.Diag(PrevDecl->getLocation(),
3980 diag::note_var_prev_partial_spec_here);
3981 return nullptr;
3982 }
3983
3984 // Do substitution on the type of the declaration
3985 TypeSourceInfo *DI = SemaRef.SubstType(
3986 PartialSpec->getTypeSourceInfo(), TemplateArgs,
3987 PartialSpec->getTypeSpecStartLoc(), PartialSpec->getDeclName());
3988 if (!DI)
3989 return nullptr;
3990
3991 if (DI->getType()->isFunctionType()) {
3992 SemaRef.Diag(PartialSpec->getLocation(),
3993 diag::err_variable_instantiates_to_function)
3994 << PartialSpec->isStaticDataMember() << DI->getType();
3995 return nullptr;
3996 }
3997
3998 // Create the variable template partial specialization declaration.
3999 VarTemplatePartialSpecializationDecl *InstPartialSpec =
4000 VarTemplatePartialSpecializationDecl::Create(
4001 SemaRef.Context, Owner, PartialSpec->getInnerLocStart(),
4002 PartialSpec->getLocation(), InstParams, VarTemplate, DI->getType(),
4003 DI, PartialSpec->getStorageClass(), Converted, InstTemplateArgs);
4004
4005 // Substitute the nested name specifier, if any.
4006 if (SubstQualifier(PartialSpec, InstPartialSpec))
4007 return nullptr;
4008
4009 InstPartialSpec->setInstantiatedFromMember(PartialSpec);
4010 InstPartialSpec->setTypeAsWritten(WrittenTy);
4011
4012 // Check the completed partial specialization.
4013 SemaRef.CheckTemplatePartialSpecialization(InstPartialSpec);
4014
4015 // Add this partial specialization to the set of variable template partial
4016 // specializations. The instantiation of the initializer is not necessary.
4017 VarTemplate->AddPartialSpecialization(InstPartialSpec, /*InsertPos=*/nullptr);
4018
4019 SemaRef.BuildVariableInstantiation(InstPartialSpec, PartialSpec, TemplateArgs,
4020 LateAttrs, Owner, StartingScope);
4021
4022 return InstPartialSpec;
4023 }
4024
4025 TypeSourceInfo*
4026 TemplateDeclInstantiator::SubstFunctionType(FunctionDecl *D,
4027 SmallVectorImpl<ParmVarDecl *> &Params) {
4028 TypeSourceInfo *OldTInfo = D->getTypeSourceInfo();
4029 assert(OldTInfo && "substituting function without type source info");
4030 assert(Params.empty() && "parameter vector is non-empty at start");
4031
4032 CXXRecordDecl *ThisContext = nullptr;
4033 Qualifiers ThisTypeQuals;
4034 if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) {
4035 ThisContext = cast<CXXRecordDecl>(Owner);
4036 ThisTypeQuals = Method->getMethodQualifiers();
4037 }
4038
4039 TypeSourceInfo *NewTInfo
4040 = SemaRef.SubstFunctionDeclType(OldTInfo, TemplateArgs,
4041 D->getTypeSpecStartLoc(),
4042 D->getDeclName(),
4043 ThisContext, ThisTypeQuals);
4044 if (!NewTInfo)
4045 return nullptr;
4046
4047 TypeLoc OldTL = OldTInfo->getTypeLoc().IgnoreParens();
4048 if (FunctionProtoTypeLoc OldProtoLoc = OldTL.getAs<FunctionProtoTypeLoc>()) {
4049 if (NewTInfo != OldTInfo) {
4050 // Get parameters from the new type info.
4051 TypeLoc NewTL = NewTInfo->getTypeLoc().IgnoreParens();
4052 FunctionProtoTypeLoc NewProtoLoc = NewTL.castAs<FunctionProtoTypeLoc>();
4053 unsigned NewIdx = 0;
4054 for (unsigned OldIdx = 0, NumOldParams = OldProtoLoc.getNumParams();
4055 OldIdx != NumOldParams; ++OldIdx) {
4056 ParmVarDecl *OldParam = OldProtoLoc.getParam(OldIdx);
4057 LocalInstantiationScope *Scope = SemaRef.CurrentInstantiationScope;
4058
4059 Optional<unsigned> NumArgumentsInExpansion;
4060 if (OldParam->isParameterPack())
4061 NumArgumentsInExpansion =
4062 SemaRef.getNumArgumentsInExpansion(OldParam->getType(),
4063 TemplateArgs);
4064 if (!NumArgumentsInExpansion) {
4065 // Simple case: normal parameter, or a parameter pack that's
4066 // instantiated to a (still-dependent) parameter pack.
4067 ParmVarDecl *NewParam = NewProtoLoc.getParam(NewIdx++);
4068 Params.push_back(NewParam);
4069 Scope->InstantiatedLocal(OldParam, NewParam);
4070 } else {
4071 // Parameter pack expansion: make the instantiation an argument pack.
4072 Scope->MakeInstantiatedLocalArgPack(OldParam);
4073 for (unsigned I = 0; I != *NumArgumentsInExpansion; ++I) {
4074 ParmVarDecl *NewParam = NewProtoLoc.getParam(NewIdx++);
4075 Params.push_back(NewParam);
4076 Scope->InstantiatedLocalPackArg(OldParam, NewParam);
4077 }
4078 }
4079 }
4080 } else {
4081 // The function type itself was not dependent and therefore no
4082 // substitution occurred. However, we still need to instantiate
4083 // the function parameters themselves.
4084 const FunctionProtoType *OldProto =
4085 cast<FunctionProtoType>(OldProtoLoc.getType());
4086 for (unsigned i = 0, i_end = OldProtoLoc.getNumParams(); i != i_end;
4087 ++i) {
4088 ParmVarDecl *OldParam = OldProtoLoc.getParam(i);
4089 if (!OldParam) {
4090 Params.push_back(SemaRef.BuildParmVarDeclForTypedef(
4091 D, D->getLocation(), OldProto->getParamType(i)));
4092 continue;
4093 }
4094
4095 ParmVarDecl *Parm =
4096 cast_or_null<ParmVarDecl>(VisitParmVarDecl(OldParam));
4097 if (!Parm)
4098 return nullptr;
4099 Params.push_back(Parm);
4100 }
4101 }
4102 } else {
4103 // If the type of this function, after ignoring parentheses, is not
4104 // *directly* a function type, then we're instantiating a function that
4105 // was declared via a typedef or with attributes, e.g.,
4106 //
4107 // typedef int functype(int, int);
4108 // functype func;
4109 // int __cdecl meth(int, int);
4110 //
4111 // In this case, we'll just go instantiate the ParmVarDecls that we
4112 // synthesized in the method declaration.
4113 SmallVector<QualType, 4> ParamTypes;
4114 Sema::ExtParameterInfoBuilder ExtParamInfos;
4115 if (SemaRef.SubstParmTypes(D->getLocation(), D->parameters(), nullptr,
4116 TemplateArgs, ParamTypes, &Params,
4117 ExtParamInfos))
4118 return nullptr;
4119 }
4120
4121 return NewTInfo;
4122 }
4123
4124 /// Introduce the instantiated function parameters into the local
4125 /// instantiation scope, and set the parameter names to those used
4126 /// in the template.
4127 static bool addInstantiatedParametersToScope(Sema &S, FunctionDecl *Function,
4128 const FunctionDecl *PatternDecl,
4129 LocalInstantiationScope &Scope,
4130 const MultiLevelTemplateArgumentList &TemplateArgs) {
4131 unsigned FParamIdx = 0;
4132 for (unsigned I = 0, N = PatternDecl->getNumParams(); I != N; ++I) {
4133 const ParmVarDecl *PatternParam = PatternDecl->getParamDecl(I);
4134 if (!PatternParam->isParameterPack()) {
4135 // Simple case: not a parameter pack.
4136 assert(FParamIdx < Function->getNumParams());
4137 ParmVarDecl *FunctionParam = Function->getParamDecl(FParamIdx);
4138 FunctionParam->setDeclName(PatternParam->getDeclName());
4139 // If the parameter's type is not dependent, update it to match the type
4140 // in the pattern. They can differ in top-level cv-qualifiers, and we want
4141 // the pattern's type here. If the type is dependent, they can't differ,
4142 // per core issue 1668. Substitute into the type from the pattern, in case
4143 // it's instantiation-dependent.
4144 // FIXME: Updating the type to work around this is at best fragile.
4145 if (!PatternDecl->getType()->isDependentType()) {
4146 QualType T = S.SubstType(PatternParam->getType(), TemplateArgs,
4147 FunctionParam->getLocation(),
4148 FunctionParam->getDeclName());
4149 if (T.isNull())
4150 return true;
4151 FunctionParam->setType(T);
4152 }
4153
4154 Scope.InstantiatedLocal(PatternParam, FunctionParam);
4155 ++FParamIdx;
4156 continue;
4157 }
4158
4159 // Expand the parameter pack.
4160 Scope.MakeInstantiatedLocalArgPack(PatternParam);
4161 Optional<unsigned> NumArgumentsInExpansion
4162 = S.getNumArgumentsInExpansion(PatternParam->getType(), TemplateArgs);
4163 if (NumArgumentsInExpansion) {
4164 QualType PatternType =
4165 PatternParam->getType()->castAs<PackExpansionType>()->getPattern();
4166 for (unsigned Arg = 0; Arg < *NumArgumentsInExpansion; ++Arg) {
4167 ParmVarDecl *FunctionParam = Function->getParamDecl(FParamIdx);
4168 FunctionParam->setDeclName(PatternParam->getDeclName());
4169 if (!PatternDecl->getType()->isDependentType()) {
4170 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(S, Arg);
4171 QualType T = S.SubstType(PatternType, TemplateArgs,
4172 FunctionParam->getLocation(),
4173 FunctionParam->getDeclName());
4174 if (T.isNull())
4175 return true;
4176 FunctionParam->setType(T);
4177 }
4178
4179 Scope.InstantiatedLocalPackArg(PatternParam, FunctionParam);
4180 ++FParamIdx;
4181 }
4182 }
4183 }
4184
4185 return false;
4186 }
4187
4188 void Sema::InstantiateExceptionSpec(SourceLocation PointOfInstantiation,
4189 FunctionDecl *Decl) {
4190 const FunctionProtoType *Proto = Decl->getType()->castAs<FunctionProtoType>();
4191 if (Proto->getExceptionSpecType() != EST_Uninstantiated)
4192 return;
4193
4194 InstantiatingTemplate Inst(*this, PointOfInstantiation, Decl,
4195 InstantiatingTemplate::ExceptionSpecification());
4196 if (Inst.isInvalid()) {
4197 // We hit the instantiation depth limit. Clear the exception specification
4198 // so that our callers don't have to cope with EST_Uninstantiated.
4199 UpdateExceptionSpec(Decl, EST_None);
4200 return;
4201 }
4202 if (Inst.isAlreadyInstantiating()) {
4203 // This exception specification indirectly depends on itself. Reject.
4204 // FIXME: Corresponding rule in the standard?
4205 Diag(PointOfInstantiation, diag::err_exception_spec_cycle) << Decl;
4206 UpdateExceptionSpec(Decl, EST_None);
4207 return;
4208 }
4209
4210 // Enter the scope of this instantiation. We don't use
4211 // PushDeclContext because we don't have a scope.
4212 Sema::ContextRAII savedContext(*this, Decl);
4213 LocalInstantiationScope Scope(*this);
4214
4215 MultiLevelTemplateArgumentList TemplateArgs =
4216 getTemplateInstantiationArgs(Decl, nullptr, /*RelativeToPrimary*/true);
4217
4218 FunctionDecl *Template = Proto->getExceptionSpecTemplate();
4219 if (addInstantiatedParametersToScope(*this, Decl, Template, Scope,
4220 TemplateArgs)) {
4221 UpdateExceptionSpec(Decl, EST_None);
4222 return;
4223 }
4224
4225 SubstExceptionSpec(Decl, Template->getType()->castAs<FunctionProtoType>(),
4226 TemplateArgs);
4227 }
4228
4229 bool Sema::CheckInstantiatedFunctionTemplateConstraints(
4230 SourceLocation PointOfInstantiation, FunctionDecl *Decl,
4231 ArrayRef<TemplateArgument> TemplateArgs,
4232 ConstraintSatisfaction &Satisfaction) {
4233 // In most cases we're not going to have constraints, so check for that first.
4234 FunctionTemplateDecl *Template = Decl->getPrimaryTemplate();
4235 // Note - code synthesis context for the constraints check is created
4236 // inside CheckConstraintsSatisfaction.
4237 SmallVector<const Expr *, 3> TemplateAC;
4238 Template->getAssociatedConstraints(TemplateAC);
4239 if (TemplateAC.empty()) {
4240 Satisfaction.IsSatisfied = true;
4241 return false;
4242 }
4243
4244 // Enter the scope of this instantiation. We don't use
4245 // PushDeclContext because we don't have a scope.
4246 Sema::ContextRAII savedContext(*this, Decl);
4247 LocalInstantiationScope Scope(*this);
4248
4249 // If this is not an explicit specialization - we need to get the instantiated
4250 // version of the template arguments and add them to scope for the
4251 // substitution.
4252 if (Decl->isTemplateInstantiation()) {
4253 InstantiatingTemplate Inst(*this, Decl->getPointOfInstantiation(),
4254 InstantiatingTemplate::ConstraintsCheck{}, Decl->getPrimaryTemplate(),
4255 TemplateArgs, SourceRange());
4256 if (Inst.isInvalid())
4257 return true;
4258 MultiLevelTemplateArgumentList MLTAL(
4259 *Decl->getTemplateSpecializationArgs());
4260 if (addInstantiatedParametersToScope(
4261 *this, Decl, Decl->getPrimaryTemplate()->getTemplatedDecl(),
4262 Scope, MLTAL))
4263 return true;
4264 }
4265
4266 return CheckConstraintSatisfaction(Template, TemplateAC, TemplateArgs,
4267 PointOfInstantiation, Satisfaction);
4268 }
4269
4270 /// Initializes the common fields of an instantiation function
4271 /// declaration (New) from the corresponding fields of its template (Tmpl).
4272 ///
4273 /// \returns true if there was an error
4274 bool
4275 TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New,
4276 FunctionDecl *Tmpl) {
4277 New->setImplicit(Tmpl->isImplicit());
4278
4279 // Forward the mangling number from the template to the instantiated decl.
4280 SemaRef.Context.setManglingNumber(New,
4281 SemaRef.Context.getManglingNumber(Tmpl));
4282
4283 // If we are performing substituting explicitly-specified template arguments
4284 // or deduced template arguments into a function template and we reach this
4285 // point, we are now past the point where SFINAE applies and have committed
4286 // to keeping the new function template specialization. We therefore
4287 // convert the active template instantiation for the function template
4288 // into a template instantiation for this specific function template
4289 // specialization, which is not a SFINAE context, so that we diagnose any
4290 // further errors in the declaration itself.
4291 typedef Sema::CodeSynthesisContext ActiveInstType;
4292 ActiveInstType &ActiveInst = SemaRef.CodeSynthesisContexts.back();
4293 if (ActiveInst.Kind == ActiveInstType::ExplicitTemplateArgumentSubstitution ||
4294 ActiveInst.Kind == ActiveInstType::DeducedTemplateArgumentSubstitution) {
4295 if (FunctionTemplateDecl *FunTmpl
4296 = dyn_cast<FunctionTemplateDecl>(ActiveInst.Entity)) {
4297 assert(FunTmpl->getTemplatedDecl() == Tmpl &&
4298 "Deduction from the wrong function template?");
4299 (void) FunTmpl;
4300 atTemplateEnd(SemaRef.TemplateInstCallbacks, SemaRef, ActiveInst);
4301 ActiveInst.Kind = ActiveInstType::TemplateInstantiation;
4302 ActiveInst.Entity = New;
4303 atTemplateBegin(SemaRef.TemplateInstCallbacks, SemaRef, ActiveInst);
4304 }
4305 }
4306
4307 const FunctionProtoType *Proto = Tmpl->getType()->getAs<FunctionProtoType>();
4308 assert(Proto && "Function template without prototype?");
4309
4310 if (Proto->hasExceptionSpec() || Proto->getNoReturnAttr()) {
4311 FunctionProtoType::ExtProtoInfo EPI = Proto->getExtProtoInfo();
4312
4313 // DR1330: In C++11, defer instantiation of a non-trivial
4314 // exception specification.
4315 // DR1484: Local classes and their members are instantiated along with the
4316 // containing function.
4317 if (SemaRef.getLangOpts().CPlusPlus11 &&
4318 EPI.ExceptionSpec.Type != EST_None &&
4319 EPI.ExceptionSpec.Type != EST_DynamicNone &&
4320 EPI.ExceptionSpec.Type != EST_BasicNoexcept &&
4321 !Tmpl->isLexicallyWithinFunctionOrMethod()) {
4322 FunctionDecl *ExceptionSpecTemplate = Tmpl;
4323 if (EPI.ExceptionSpec.Type == EST_Uninstantiated)
4324 ExceptionSpecTemplate = EPI.ExceptionSpec.SourceTemplate;
4325 ExceptionSpecificationType NewEST = EST_Uninstantiated;
4326 if (EPI.ExceptionSpec.Type == EST_Unevaluated)
4327 NewEST = EST_Unevaluated;
4328
4329 // Mark the function has having an uninstantiated exception specification.
4330 const FunctionProtoType *NewProto
4331 = New->getType()->getAs<FunctionProtoType>();
4332 assert(NewProto && "Template instantiation without function prototype?");
4333 EPI = NewProto->getExtProtoInfo();
4334 EPI.ExceptionSpec.Type = NewEST;
4335 EPI.ExceptionSpec.SourceDecl = New;
4336 EPI.ExceptionSpec.SourceTemplate = ExceptionSpecTemplate;
4337 New->setType(SemaRef.Context.getFunctionType(
4338 NewProto->getReturnType(), NewProto->getParamTypes(), EPI));
4339 } else {
4340 Sema::ContextRAII SwitchContext(SemaRef, New);
4341 SemaRef.SubstExceptionSpec(New, Proto, TemplateArgs);
4342 }
4343 }
4344
4345 // Get the definition. Leaves the variable unchanged if undefined.
4346 const FunctionDecl *Definition = Tmpl;
4347 Tmpl->isDefined(Definition);
4348
4349 SemaRef.InstantiateAttrs(TemplateArgs, Definition, New,
4350 LateAttrs, StartingScope);
4351
4352 return false;
4353 }
4354
4355 /// Initializes common fields of an instantiated method
4356 /// declaration (New) from the corresponding fields of its template
4357 /// (Tmpl).
4358 ///
4359 /// \returns true if there was an error
4360 bool
4361 TemplateDeclInstantiator::InitMethodInstantiation(CXXMethodDecl *New,
4362 CXXMethodDecl *Tmpl) {
4363 if (InitFunctionInstantiation(New, Tmpl))
4364 return true;
4365
4366 if (isa<CXXDestructorDecl>(New) && SemaRef.getLangOpts().CPlusPlus11)
4367 SemaRef.AdjustDestructorExceptionSpec(cast<CXXDestructorDecl>(New));
4368
4369 New->setAccess(Tmpl->getAccess());
4370 if (Tmpl->isVirtualAsWritten())
4371 New->setVirtualAsWritten(true);
4372
4373 // FIXME: New needs a pointer to Tmpl
4374 return false;
4375 }
4376
4377 bool TemplateDeclInstantiator::SubstDefaultedFunction(FunctionDecl *New,
4378 FunctionDecl *Tmpl) {
4379 // Transfer across any unqualified lookups.
4380 if (auto *DFI = Tmpl->getDefaultedFunctionInfo()) {
4381 SmallVector<DeclAccessPair, 32> Lookups;
4382 Lookups.reserve(DFI->getUnqualifiedLookups().size());
4383 bool AnyChanged = false;
4384 for (DeclAccessPair DA : DFI->getUnqualifiedLookups()) {
4385 NamedDecl *D = SemaRef.FindInstantiatedDecl(New->getLocation(),
4386 DA.getDecl(), TemplateArgs);
4387 if (!D)
4388 return true;
4389 AnyChanged |= (D != DA.getDecl());
4390 Lookups.push_back(DeclAccessPair::make(D, DA.getAccess()));
4391 }
4392
4393 // It's unlikely that substitution will change any declarations. Don't
4394 // store an unnecessary copy in that case.
4395 New->setDefaultedFunctionInfo(
4396 AnyChanged ? FunctionDecl::DefaultedFunctionInfo::Create(
4397 SemaRef.Context, Lookups)
4398 : DFI);
4399 }
4400
4401 SemaRef.SetDeclDefaulted(New, Tmpl->getLocation());
4402 return false;
4403 }
4404
4405 /// Instantiate (or find existing instantiation of) a function template with a
4406 /// given set of template arguments.
4407 ///
4408 /// Usually this should not be used, and template argument deduction should be
4409 /// used in its place.
4410 FunctionDecl *
4411 Sema::InstantiateFunctionDeclaration(FunctionTemplateDecl *FTD,
4412 const TemplateArgumentList *Args,
4413 SourceLocation Loc) {
4414 FunctionDecl *FD = FTD->getTemplatedDecl();
4415
4416 sema::TemplateDeductionInfo Info(Loc);
4417 InstantiatingTemplate Inst(
4418 *this, Loc, FTD, Args->asArray(),
4419 CodeSynthesisContext::ExplicitTemplateArgumentSubstitution, Info);
4420 if (Inst.isInvalid())
4421 return nullptr;
4422
4423 ContextRAII SavedContext(*this, FD);
4424 MultiLevelTemplateArgumentList MArgs(*Args);
4425
4426 return cast_or_null<FunctionDecl>(SubstDecl(FD, FD->getParent(), MArgs));
4427 }
4428
4429 /// In the MS ABI, we need to instantiate default arguments of dllexported
4430 /// default constructors along with the constructor definition. This allows IR
4431 /// gen to emit a constructor closure which calls the default constructor with
4432 /// its default arguments.
4433 static void InstantiateDefaultCtorDefaultArgs(Sema &S,
4434 CXXConstructorDecl *Ctor) {
4435 assert(S.Context.getTargetInfo().getCXXABI().isMicrosoft() &&
4436 Ctor->isDefaultConstructor());
4437 unsigned NumParams = Ctor->getNumParams();
4438 if (NumParams == 0)
4439 return;
4440 DLLExportAttr *Attr = Ctor->getAttr<DLLExportAttr>();
4441 if (!Attr)
4442 return;
4443 for (unsigned I = 0; I != NumParams; ++I) {
4444 (void)S.CheckCXXDefaultArgExpr(Attr->getLocation(), Ctor,
4445 Ctor->getParamDecl(I));
4446 S.DiscardCleanupsInEvaluationContext();
4447 }
4448 }
4449
4450 /// Instantiate the definition of the given function from its
4451 /// template.
4452 ///
4453 /// \param PointOfInstantiation the point at which the instantiation was
4454 /// required. Note that this is not precisely a "point of instantiation"
4455 /// for the function, but it's close.
4456 ///
4457 /// \param Function the already-instantiated declaration of a
4458 /// function template specialization or member function of a class template
4459 /// specialization.
4460 ///
4461 /// \param Recursive if true, recursively instantiates any functions that
4462 /// are required by this instantiation.
4463 ///
4464 /// \param DefinitionRequired if true, then we are performing an explicit
4465 /// instantiation where the body of the function is required. Complain if
4466 /// there is no such body.
4467 void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
4468 FunctionDecl *Function,
4469 bool Recursive,
4470 bool DefinitionRequired,
4471 bool AtEndOfTU) {
4472 if (Function->isInvalidDecl() || Function->isDefined() ||
4473 isa<CXXDeductionGuideDecl>(Function))
4474 return;
4475
4476 // Never instantiate an explicit specialization except if it is a class scope
4477 // explicit specialization.
4478 TemplateSpecializationKind TSK =
4479 Function->getTemplateSpecializationKindForInstantiation();
4480 if (TSK == TSK_ExplicitSpecialization)
4481 return;
4482
4483 // Find the function body that we'll be substituting.
4484 const FunctionDecl *PatternDecl = Function->getTemplateInstantiationPattern();
4485 assert(PatternDecl && "instantiating a non-template");
4486
4487 const FunctionDecl *PatternDef = PatternDecl->getDefinition();
4488 Stmt *Pattern = nullptr;
4489 if (PatternDef) {
4490 Pattern = PatternDef->getBody(PatternDef);
4491 PatternDecl = PatternDef;
4492 if (PatternDef->willHaveBody())
4493 PatternDef = nullptr;
4494 }
4495
4496 // FIXME: We need to track the instantiation stack in order to know which
4497 // definitions should be visible within this instantiation.
4498 if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Function,
4499 Function->getInstantiatedFromMemberFunction(),
4500 PatternDecl, PatternDef, TSK,
4501 /*Complain*/DefinitionRequired)) {
4502 if (DefinitionRequired)
4503 Function->setInvalidDecl();
4504 else if (TSK == TSK_ExplicitInstantiationDefinition) {
4505 // Try again at the end of the translation unit (at which point a
4506 // definition will be required).
4507 assert(!Recursive);
4508 Function->setInstantiationIsPending(true);
4509 PendingInstantiations.push_back(
4510 std::make_pair(Function, PointOfInstantiation));
4511 } else if (TSK == TSK_ImplicitInstantiation) {
4512 if (AtEndOfTU && !getDiagnostics().hasErrorOccurred() &&
4513 !getSourceManager().isInSystemHeader(PatternDecl->getBeginLoc())) {
4514 Diag(PointOfInstantiation, diag::warn_func_template_missing)
4515 << Function;
4516 Diag(PatternDecl->getLocation(), diag::note_forward_template_decl);
4517 if (getLangOpts().CPlusPlus11)
4518 Diag(PointOfInstantiation, diag::note_inst_declaration_hint)
4519 << Function;
4520 }
4521 }
4522
4523 return;
4524 }
4525
4526 // Postpone late parsed template instantiations.
4527 if (PatternDecl->isLateTemplateParsed() &&
4528 !LateTemplateParser) {
4529 Function->setInstantiationIsPending(true);
4530 LateParsedInstantiations.push_back(
4531 std::make_pair(Function, PointOfInstantiation));
4532 return;
4533 }
4534
4535 llvm::TimeTraceScope TimeScope("InstantiateFunction", [&]() {
4536 std::string Name;
4537 llvm::raw_string_ostream OS(Name);
4538 Function->getNameForDiagnostic(OS, getPrintingPolicy(),
4539 /*Qualified=*/true);
4540 return Name;
4541 });
4542
4543 // If we're performing recursive template instantiation, create our own
4544 // queue of pending implicit instantiations that we will instantiate later,
4545 // while we're still within our own instantiation context.
4546 // This has to happen before LateTemplateParser below is called, so that
4547 // it marks vtables used in late parsed templates as used.
4548 GlobalEagerInstantiationScope GlobalInstantiations(*this,
4549 /*Enabled=*/Recursive);
4550 LocalEagerInstantiationScope LocalInstantiations(*this);
4551
4552 // Call the LateTemplateParser callback if there is a need to late parse
4553 // a templated function definition.
4554 if (!Pattern && PatternDecl->isLateTemplateParsed() &&
4555 LateTemplateParser) {
4556 // FIXME: Optimize to allow individual templates to be deserialized.
4557 if (PatternDecl->isFromASTFile())
4558 ExternalSource->ReadLateParsedTemplates(LateParsedTemplateMap);
4559
4560 auto LPTIter = LateParsedTemplateMap.find(PatternDecl);
4561 assert(LPTIter != LateParsedTemplateMap.end() &&
4562 "missing LateParsedTemplate");
4563 LateTemplateParser(OpaqueParser, *LPTIter->second);
4564 Pattern = PatternDecl->getBody(PatternDecl);
4565 }
4566
4567 // Note, we should never try to instantiate a deleted function template.
4568 assert((Pattern || PatternDecl->isDefaulted() ||
4569 PatternDecl->hasSkippedBody()) &&
4570 "unexpected kind of function template definition");
4571
4572 // C++1y [temp.explicit]p10:
4573 // Except for inline functions, declarations with types deduced from their
4574 // initializer or return value, and class template specializations, other
4575 // explicit instantiation declarations have the effect of suppressing the
4576 // implicit instantiation of the entity to which they refer.
4577 if (TSK == TSK_ExplicitInstantiationDeclaration &&
4578 !PatternDecl->isInlined() &&
4579 !PatternDecl->getReturnType()->getContainedAutoType())
4580 return;
4581
4582 if (PatternDecl->isInlined()) {
4583 // Function, and all later redeclarations of it (from imported modules,
4584 // for instance), are now implicitly inline.
4585 for (auto *D = Function->getMostRecentDecl(); /**/;
4586 D = D->getPreviousDecl()) {
4587 D->setImplicitlyInline();
4588 if (D == Function)
4589 break;
4590 }
4591 }
4592
4593 InstantiatingTemplate Inst(*this, PointOfInstantiation, Function);
4594 if (Inst.isInvalid() || Inst.isAlreadyInstantiating())
4595 return;
4596 PrettyDeclStackTraceEntry CrashInfo(Context, Function, SourceLocation(),
4597 "instantiating function definition");
4598
4599 // The instantiation is visible here, even if it was first declared in an
4600 // unimported module.
4601 Function->setVisibleDespiteOwningModule();
4602
4603 // Copy the inner loc start from the pattern.
4604 Function->setInnerLocStart(PatternDecl->getInnerLocStart());
4605
4606 EnterExpressionEvaluationContext EvalContext(
4607 *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
4608
4609 // Introduce a new scope where local variable instantiations will be
4610 // recorded, unless we're actually a member function within a local
4611 // class, in which case we need to merge our results with the parent
4612 // scope (of the enclosing function).
4613 bool MergeWithParentScope = false;
4614 if (CXXRecordDecl *Rec = dyn_cast<CXXRecordDecl>(Function->getDeclContext()))
4615 MergeWithParentScope = Rec->isLocalClass();
4616
4617 LocalInstantiationScope Scope(*this, MergeWithParentScope);
4618
4619 if (PatternDecl->isDefaulted())
4620 SetDeclDefaulted(Function, PatternDecl->getLocation());
4621 else {
4622 MultiLevelTemplateArgumentList TemplateArgs =
4623 getTemplateInstantiationArgs(Function, nullptr, false, PatternDecl);
4624
4625 // Substitute into the qualifier; we can get a substitution failure here
4626 // through evil use of alias templates.
4627 // FIXME: Is CurContext correct for this? Should we go to the (instantiation
4628 // of the) lexical context of the pattern?
4629 SubstQualifier(*this, PatternDecl, Function, TemplateArgs);
4630
4631 ActOnStartOfFunctionDef(nullptr, Function);
4632
4633 // Enter the scope of this instantiation. We don't use
4634 // PushDeclContext because we don't have a scope.
4635 Sema::ContextRAII savedContext(*this, Function);
4636
4637 if (addInstantiatedParametersToScope(*this, Function, PatternDecl, Scope,
4638 TemplateArgs))
4639 return;
4640
4641 StmtResult Body;
4642 if (PatternDecl->hasSkippedBody()) {
4643 ActOnSkippedFunctionBody(Function);
4644 Body = nullptr;
4645 } else {
4646 if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(Function)) {
4647 // If this is a constructor, instantiate the member initializers.
4648 InstantiateMemInitializers(Ctor, cast<CXXConstructorDecl>(PatternDecl),
4649 TemplateArgs);
4650
4651 // If this is an MS ABI dllexport default constructor, instantiate any
4652 // default arguments.
4653 if (Context.getTargetInfo().getCXXABI().isMicrosoft() &&
4654 Ctor->isDefaultConstructor()) {
4655 InstantiateDefaultCtorDefaultArgs(*this, Ctor);
4656 }
4657 }
4658
4659 // Instantiate the function body.
4660 Body = SubstStmt(Pattern, TemplateArgs);
4661
4662 if (Body.isInvalid())
4663 Function->setInvalidDecl();
4664 }
4665 // FIXME: finishing the function body while in an expression evaluation
4666 // context seems wrong. Investigate more.
4667 ActOnFinishFunctionBody(Function, Body.get(), /*IsInstantiation=*/true);
4668
4669 PerformDependentDiagnostics(PatternDecl, TemplateArgs);
4670
4671 if (auto *Listener = getASTMutationListener())
4672 Listener->FunctionDefinitionInstantiated(Function);
4673
4674 savedContext.pop();
4675 }
4676
4677 DeclGroupRef DG(Function);
4678 Consumer.HandleTopLevelDecl(DG);
4679
4680 // This class may have local implicit instantiations that need to be
4681 // instantiation within this scope.
4682 LocalInstantiations.perform();
4683 Scope.Exit();
4684 GlobalInstantiations.perform();
4685 }
4686
4687 VarTemplateSpecializationDecl *Sema::BuildVarTemplateInstantiation(
4688 VarTemplateDecl *VarTemplate, VarDecl *FromVar,
4689 const TemplateArgumentList &TemplateArgList,
4690 const TemplateArgumentListInfo &TemplateArgsInfo,
4691 SmallVectorImpl<TemplateArgument> &Converted,
4692 SourceLocation PointOfInstantiation, void *InsertPos,
4693 LateInstantiatedAttrVec *LateAttrs,
4694 LocalInstantiationScope *StartingScope) {
4695 if (FromVar->isInvalidDecl())
4696 return nullptr;
4697
4698 InstantiatingTemplate Inst(*this, PointOfInstantiation, FromVar);
4699 if (Inst.isInvalid())
4700 return nullptr;
4701
4702 MultiLevelTemplateArgumentList TemplateArgLists;
4703 TemplateArgLists.addOuterTemplateArguments(&TemplateArgList);
4704
4705 // Instantiate the first declaration of the variable template: for a partial
4706 // specialization of a static data member template, the first declaration may
4707 // or may not be the declaration in the class; if it's in the class, we want
4708 // to instantiate a member in the class (a declaration), and if it's outside,
4709 // we want to instantiate a definition.
4710 //
4711 // If we're instantiating an explicitly-specialized member template or member
4712 // partial specialization, don't do this. The member specialization completely
4713 // replaces the original declaration in this case.
4714 bool IsMemberSpec = false;
4715 if (VarTemplatePartialSpecializationDecl *PartialSpec =
4716 dyn_cast<VarTemplatePartialSpecializationDecl>(FromVar))
4717 IsMemberSpec = PartialSpec->isMemberSpecialization();
4718 else if (VarTemplateDecl *FromTemplate = FromVar->getDescribedVarTemplate())
4719 IsMemberSpec = FromTemplate->isMemberSpecialization();
4720 if (!IsMemberSpec)
4721 FromVar = FromVar->getFirstDecl();
4722
4723 MultiLevelTemplateArgumentList MultiLevelList(TemplateArgList);
4724 TemplateDeclInstantiator Instantiator(*this, FromVar->getDeclContext(),
4725 MultiLevelList);
4726
4727 // TODO: Set LateAttrs and StartingScope ...
4728
4729 return cast_or_null<VarTemplateSpecializationDecl>(
4730 Instantiator.VisitVarTemplateSpecializationDecl(
4731 VarTemplate, FromVar, InsertPos, TemplateArgsInfo, Converted));
4732 }
4733
4734 /// Instantiates a variable template specialization by completing it
4735 /// with appropriate type information and initializer.
4736 VarTemplateSpecializationDecl *Sema::CompleteVarTemplateSpecializationDecl(
4737 VarTemplateSpecializationDecl *VarSpec, VarDecl *PatternDecl,
4738 const MultiLevelTemplateArgumentList &TemplateArgs) {
4739 assert(PatternDecl->isThisDeclarationADefinition() &&
4740 "don't have a definition to instantiate from");
4741
4742 // Do substitution on the type of the declaration
4743 TypeSourceInfo *DI =
4744 SubstType(PatternDecl->getTypeSourceInfo(), TemplateArgs,
4745 PatternDecl->getTypeSpecStartLoc(), PatternDecl->getDeclName());
4746 if (!DI)
4747 return nullptr;
4748
4749 // Update the type of this variable template specialization.
4750 VarSpec->setType(DI->getType());
4751
4752 // Convert the declaration into a definition now.
4753 VarSpec->setCompleteDefinition();
4754
4755 // Instantiate the initializer.
4756 InstantiateVariableInitializer(VarSpec, PatternDecl, TemplateArgs);
4757
4758 return VarSpec;
4759 }
4760
4761 /// BuildVariableInstantiation - Used after a new variable has been created.
4762 /// Sets basic variable data and decides whether to postpone the
4763 /// variable instantiation.
4764 void Sema::BuildVariableInstantiation(
4765 VarDecl *NewVar, VarDecl *OldVar,
4766 const MultiLevelTemplateArgumentList &TemplateArgs,
4767 LateInstantiatedAttrVec *LateAttrs, DeclContext *Owner,
4768 LocalInstantiationScope *StartingScope,
4769 bool InstantiatingVarTemplate,
4770 VarTemplateSpecializationDecl *PrevDeclForVarTemplateSpecialization) {
4771 // Instantiating a partial specialization to produce a partial
4772 // specialization.
4773 bool InstantiatingVarTemplatePartialSpec =
4774 isa<VarTemplatePartialSpecializationDecl>(OldVar) &&
4775 isa<VarTemplatePartialSpecializationDecl>(NewVar);
4776 // Instantiating from a variable template (or partial specialization) to
4777 // produce a variable template specialization.
4778 bool InstantiatingSpecFromTemplate =
4779 isa<VarTemplateSpecializationDecl>(NewVar) &&
4780 (OldVar->getDescribedVarTemplate() ||
4781 isa<VarTemplatePartialSpecializationDecl>(OldVar));
4782
4783 // If we are instantiating a local extern declaration, the
4784 // instantiation belongs lexically to the containing function.
4785 // If we are instantiating a static data member defined
4786 // out-of-line, the instantiation will have the same lexical
4787 // context (which will be a namespace scope) as the template.
4788 if (OldVar->isLocalExternDecl()) {
4789 NewVar->setLocalExternDecl();
4790 NewVar->setLexicalDeclContext(Owner);
4791 } else if (OldVar->isOutOfLine())
4792 NewVar->setLexicalDeclContext(OldVar->getLexicalDeclContext());
4793 NewVar->setTSCSpec(OldVar->getTSCSpec());
4794 NewVar->setInitStyle(OldVar->getInitStyle());
4795 NewVar->setCXXForRangeDecl(OldVar->isCXXForRangeDecl());
4796 NewVar->setObjCForDecl(OldVar->isObjCForDecl());
4797 NewVar->setConstexpr(OldVar->isConstexpr());
4798 NewVar->setInitCapture(OldVar->isInitCapture());
4799 NewVar->setPreviousDeclInSameBlockScope(
4800 OldVar->isPreviousDeclInSameBlockScope());
4801 NewVar->setAccess(OldVar->getAccess());
4802
4803 if (!OldVar->isStaticDataMember()) {
4804 if (OldVar->isUsed(false))
4805 NewVar->setIsUsed();
4806 NewVar->setReferenced(OldVar->isReferenced());
4807 }
4808
4809 InstantiateAttrs(TemplateArgs, OldVar, NewVar, LateAttrs, StartingScope);
4810
4811 LookupResult Previous(
4812 *this, NewVar->getDeclName(), NewVar->getLocation(),
4813 NewVar->isLocalExternDecl() ? Sema::LookupRedeclarationWithLinkage
4814 : Sema::LookupOrdinaryName,
4815 NewVar->isLocalExternDecl() ? Sema::ForExternalRedeclaration
4816 : forRedeclarationInCurContext());
4817
4818 if (NewVar->isLocalExternDecl() && OldVar->getPreviousDecl() &&
4819 (!OldVar->getPreviousDecl()->getDeclContext()->isDependentContext() ||
4820 OldVar->getPreviousDecl()->getDeclContext()==OldVar->getDeclContext())) {
4821 // We have a previous declaration. Use that one, so we merge with the
4822 // right type.
4823 if (NamedDecl *NewPrev = FindInstantiatedDecl(
4824 NewVar->getLocation(), OldVar->getPreviousDecl(), TemplateArgs))
4825 Previous.addDecl(NewPrev);
4826 } else if (!isa<VarTemplateSpecializationDecl>(NewVar) &&
4827 OldVar->hasLinkage()) {
4828 LookupQualifiedName(Previous, NewVar->getDeclContext(), false);
4829 } else if (PrevDeclForVarTemplateSpecialization) {
4830 Previous.addDecl(PrevDeclForVarTemplateSpecialization);
4831 }
4832 CheckVariableDeclaration(NewVar, Previous);
4833
4834 if (!InstantiatingVarTemplate) {
4835 NewVar->getLexicalDeclContext()->addHiddenDecl(NewVar);
4836 if (!NewVar->isLocalExternDecl() || !NewVar->getPreviousDecl())
4837 NewVar->getDeclContext()->makeDeclVisibleInContext(NewVar);
4838 }
4839
4840 if (!OldVar->isOutOfLine()) {
4841 if (NewVar->getDeclContext()->isFunctionOrMethod())
4842 CurrentInstantiationScope->InstantiatedLocal(OldVar, NewVar);
4843 }
4844
4845 // Link instantiations of static data members back to the template from
4846 // which they were instantiated.
4847 //
4848 // Don't do this when instantiating a template (we link the template itself
4849 // back in that case) nor when instantiating a static data member template
4850 // (that's not a member specialization).
4851 if (NewVar->isStaticDataMember() && !InstantiatingVarTemplate &&
4852 !InstantiatingSpecFromTemplate)
4853 NewVar->setInstantiationOfStaticDataMember(OldVar,
4854 TSK_ImplicitInstantiation);
4855
4856 // If the pattern is an (in-class) explicit specialization, then the result
4857 // is also an explicit specialization.
4858 if (VarTemplateSpecializationDecl *OldVTSD =
4859 dyn_cast<VarTemplateSpecializationDecl>(OldVar)) {
4860 if (OldVTSD->getSpecializationKind() == TSK_ExplicitSpecialization &&
4861 !isa<VarTemplatePartialSpecializationDecl>(OldVTSD))
4862 cast<VarTemplateSpecializationDecl>(NewVar)->setSpecializationKind(
4863 TSK_ExplicitSpecialization);
4864 }
4865
4866 // Forward the mangling number from the template to the instantiated decl.
4867 Context.setManglingNumber(NewVar, Context.getManglingNumber(OldVar));
4868 Context.setStaticLocalNumber(NewVar, Context.getStaticLocalNumber(OldVar));
4869
4870 // Figure out whether to eagerly instantiate the initializer.
4871 if (InstantiatingVarTemplate || InstantiatingVarTemplatePartialSpec) {
4872 // We're producing a template. Don't instantiate the initializer yet.
4873 } else if (NewVar->getType()->isUndeducedType()) {
4874 // We need the type to complete the declaration of the variable.
4875 InstantiateVariableInitializer(NewVar, OldVar, TemplateArgs);
4876 } else if (InstantiatingSpecFromTemplate ||
4877 (OldVar->isInline() && OldVar->isThisDeclarationADefinition() &&
4878 !NewVar->isThisDeclarationADefinition())) {
4879 // Delay instantiation of the initializer for variable template
4880 // specializations or inline static data members until a definition of the
4881 // variable is needed.
4882 } else {
4883 InstantiateVariableInitializer(NewVar, OldVar, TemplateArgs);
4884 }
4885
4886 // Diagnose unused local variables with dependent types, where the diagnostic
4887 // will have been deferred.
4888 if (!NewVar->isInvalidDecl() &&
4889 NewVar->getDeclContext()->isFunctionOrMethod() &&
4890 OldVar->getType()->isDependentType())
4891 DiagnoseUnusedDecl(NewVar);
4892 }
4893
4894 /// Instantiate the initializer of a variable.
4895 void Sema::InstantiateVariableInitializer(
4896 VarDecl *Var, VarDecl *OldVar,
4897 const MultiLevelTemplateArgumentList &TemplateArgs) {
4898 if (ASTMutationListener *L = getASTContext().getASTMutationListener())
4899 L->VariableDefinitionInstantiated(Var);
4900
4901 // We propagate the 'inline' flag with the initializer, because it
4902 // would otherwise imply that the variable is a definition for a
4903 // non-static data member.
4904 if (OldVar->isInlineSpecified())
4905 Var->setInlineSpecified();
4906 else if (OldVar->isInline())
4907 Var->setImplicitlyInline();
4908
4909 if (OldVar->getInit()) {
4910 EnterExpressionEvaluationContext Evaluated(
4911 *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated, Var);
4912
4913 // Instantiate the initializer.
4914 ExprResult Init;
4915
4916 {
4917 ContextRAII SwitchContext(*this, Var->getDeclContext());
4918 Init = SubstInitializer(OldVar->getInit(), TemplateArgs,
4919 OldVar->getInitStyle() == VarDecl::CallInit);
4920 }
4921
4922 if (!Init.isInvalid()) {
4923 Expr *InitExpr = Init.get();
4924
4925 if (Var->hasAttr<DLLImportAttr>() &&
4926 (!InitExpr ||
4927 !InitExpr->isConstantInitializer(getASTContext(), false))) {
4928 // Do not dynamically initialize dllimport variables.
4929 } else if (InitExpr) {
4930 bool DirectInit = OldVar->isDirectInit();
4931 AddInitializerToDecl(Var, InitExpr, DirectInit);
4932 } else
4933 ActOnUninitializedDecl(Var);
4934 } else {
4935 // FIXME: Not too happy about invalidating the declaration
4936 // because of a bogus initializer.
4937 Var->setInvalidDecl();
4938 }
4939 } else {
4940 // `inline` variables are a definition and declaration all in one; we won't
4941 // pick up an initializer from anywhere else.
4942 if (Var->isStaticDataMember() && !Var->isInline()) {
4943 if (!Var->isOutOfLine())
4944 return;
4945
4946 // If the declaration inside the class had an initializer, don't add
4947 // another one to the out-of-line definition.
4948 if (OldVar->getFirstDecl()->hasInit())
4949 return;
4950 }
4951
4952 // We'll add an initializer to a for-range declaration later.
4953 if (Var->isCXXForRangeDecl() || Var->isObjCForDecl())
4954 return;
4955
4956 ActOnUninitializedDecl(Var);
4957 }
4958
4959 if (getLangOpts().CUDA)
4960 checkAllowedCUDAInitializer(Var);
4961 }
4962
4963 /// Instantiate the definition of the given variable from its
4964 /// template.
4965 ///
4966 /// \param PointOfInstantiation the point at which the instantiation was
4967 /// required. Note that this is not precisely a "point of instantiation"
4968 /// for the variable, but it's close.
4969 ///
4970 /// \param Var the already-instantiated declaration of a templated variable.
4971 ///
4972 /// \param Recursive if true, recursively instantiates any functions that
4973 /// are required by this instantiation.
4974 ///
4975 /// \param DefinitionRequired if true, then we are performing an explicit
4976 /// instantiation where a definition of the variable is required. Complain
4977 /// if there is no such definition.
4978 void Sema::InstantiateVariableDefinition(SourceLocation PointOfInstantiation,
4979 VarDecl *Var, bool Recursive,
4980 bool DefinitionRequired, bool AtEndOfTU) {
4981 if (Var->isInvalidDecl())
4982 return;
4983
4984 // Never instantiate an explicitly-specialized entity.
4985 TemplateSpecializationKind TSK =
4986 Var->getTemplateSpecializationKindForInstantiation();
4987 if (TSK == TSK_ExplicitSpecialization)
4988 return;
4989
4990 // Find the pattern and the arguments to substitute into it.
4991 VarDecl *PatternDecl = Var->getTemplateInstantiationPattern();
4992 assert(PatternDecl && "no pattern for templated variable");
4993 MultiLevelTemplateArgumentList TemplateArgs =
4994 getTemplateInstantiationArgs(Var);
4995
4996 VarTemplateSpecializationDecl *VarSpec =
4997 dyn_cast<VarTemplateSpecializationDecl>(Var);
4998 if (VarSpec) {
4999 // If this is a variable template specialization, make sure that it is
5000 // non-dependent.
5001 bool InstantiationDependent = false;
5002 assert(!TemplateSpecializationType::anyDependentTemplateArguments(
5003 VarSpec->getTemplateArgsInfo(), InstantiationDependent) &&
5004 "Only instantiate variable template specializations that are "
5005 "not type-dependent");
5006 (void)InstantiationDependent;
5007
5008 // If this is a static data member template, there might be an
5009 // uninstantiated initializer on the declaration. If so, instantiate
5010 // it now.
5011 //
5012 // FIXME: This largely duplicates what we would do below. The difference
5013 // is that along this path we may instantiate an initializer from an
5014 // in-class declaration of the template and instantiate the definition
5015 // from a separate out-of-class definition.
5016 if (PatternDecl->isStaticDataMember() &&
5017 (PatternDecl = PatternDecl->getFirstDecl())->hasInit() &&
5018 !Var->hasInit()) {
5019 // FIXME: Factor out the duplicated instantiation context setup/tear down
5020 // code here.
5021 InstantiatingTemplate Inst(*this, PointOfInstantiation, Var);
5022 if (Inst.isInvalid() || Inst.isAlreadyInstantiating())
5023 return;
5024 PrettyDeclStackTraceEntry CrashInfo(Context, Var, SourceLocation(),
5025 "instantiating variable initializer");
5026
5027 // The instantiation is visible here, even if it was first declared in an
5028 // unimported module.
5029 Var->setVisibleDespiteOwningModule();
5030
5031 // If we're performing recursive template instantiation, create our own
5032 // queue of pending implicit instantiations that we will instantiate
5033 // later, while we're still within our own instantiation context.
5034 GlobalEagerInstantiationScope GlobalInstantiations(*this,
5035 /*Enabled=*/Recursive);
5036 LocalInstantiationScope Local(*this);
5037 LocalEagerInstantiationScope LocalInstantiations(*this);
5038
5039 // Enter the scope of this instantiation. We don't use
5040 // PushDeclContext because we don't have a scope.
5041 ContextRAII PreviousContext(*this, Var->getDeclContext());
5042 InstantiateVariableInitializer(Var, PatternDecl, TemplateArgs);
5043 PreviousContext.pop();
5044
5045 // This variable may have local implicit instantiations that need to be
5046 // instantiated within this scope.
5047 LocalInstantiations.perform();
5048 Local.Exit();
5049 GlobalInstantiations.perform();
5050 }
5051 } else {
5052 assert(Var->isStaticDataMember() && PatternDecl->isStaticDataMember() &&
5053 "not a static data member?");
5054 }
5055
5056 VarDecl *Def = PatternDecl->getDefinition(getASTContext());
5057
5058 // If we don't have a definition of the variable template, we won't perform
5059 // any instantiation. Rather, we rely on the user to instantiate this
5060 // definition (or provide a specialization for it) in another translation
5061 // unit.
5062 if (!Def && !DefinitionRequired) {
5063 if (TSK == TSK_ExplicitInstantiationDefinition) {
5064 PendingInstantiations.push_back(
5065 std::make_pair(Var, PointOfInstantiation));
5066 } else if (TSK == TSK_ImplicitInstantiation) {
5067 // Warn about missing definition at the end of translation unit.
5068 if (AtEndOfTU && !getDiagnostics().hasErrorOccurred() &&
5069 !getSourceManager().isInSystemHeader(PatternDecl->getBeginLoc())) {
5070 Diag(PointOfInstantiation, diag::warn_var_template_missing)
5071 << Var;
5072 Diag(PatternDecl->getLocation(), diag::note_forward_template_decl);
5073 if (getLangOpts().CPlusPlus11)
5074 Diag(PointOfInstantiation, diag::note_inst_declaration_hint) << Var;
5075 }
5076 return;
5077 }
5078 }
5079
5080 // FIXME: We need to track the instantiation stack in order to know which
5081 // definitions should be visible within this instantiation.
5082 // FIXME: Produce diagnostics when Var->getInstantiatedFromStaticDataMember().
5083 if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Var,
5084 /*InstantiatedFromMember*/false,
5085 PatternDecl, Def, TSK,
5086 /*Complain*/DefinitionRequired))
5087 return;
5088
5089 // C++11 [temp.explicit]p10:
5090 // Except for inline functions, const variables of literal types, variables
5091 // of reference types, [...] explicit instantiation declarations
5092 // have the effect of suppressing the implicit instantiation of the entity
5093 // to which they refer.
5094 //
5095 // FIXME: That's not exactly the same as "might be usable in constant
5096 // expressions", which only allows constexpr variables and const integral
5097 // types, not arbitrary const literal types.
5098 if (TSK == TSK_ExplicitInstantiationDeclaration &&
5099 !Var->mightBeUsableInConstantExpressions(getASTContext()))
5100 return;
5101
5102 // Make sure to pass the instantiated variable to the consumer at the end.
5103 struct PassToConsumerRAII {
5104 ASTConsumer &Consumer;
5105 VarDecl *Var;
5106
5107 PassToConsumerRAII(ASTConsumer &Consumer, VarDecl *Var)
5108 : Consumer(Consumer), Var(Var) { }
5109
5110 ~PassToConsumerRAII() {
5111 Consumer.HandleCXXStaticMemberVarInstantiation(Var);
5112 }
5113 } PassToConsumerRAII(Consumer, Var);
5114
5115 // If we already have a definition, we're done.
5116 if (VarDecl *Def = Var->getDefinition()) {
5117 // We may be explicitly instantiating something we've already implicitly
5118 // instantiated.
5119 Def->setTemplateSpecializationKind(Var->getTemplateSpecializationKind(),
5120 PointOfInstantiation);
5121 return;
5122 }
5123
5124 InstantiatingTemplate Inst(*this, PointOfInstantiation, Var);
5125 if (Inst.isInvalid() || Inst.isAlreadyInstantiating())
5126 return;
5127 PrettyDeclStackTraceEntry CrashInfo(Context, Var, SourceLocation(),
5128 "instantiating variable definition");
5129
5130 // If we're performing recursive template instantiation, create our own
5131 // queue of pending implicit instantiations that we will instantiate later,
5132 // while we're still within our own instantiation context.
5133 GlobalEagerInstantiationScope GlobalInstantiations(*this,
5134 /*Enabled=*/Recursive);
5135
5136 // Enter the scope of this instantiation. We don't use
5137 // PushDeclContext because we don't have a scope.
5138 ContextRAII PreviousContext(*this, Var->getDeclContext());
5139 LocalInstantiationScope Local(*this);
5140
5141 LocalEagerInstantiationScope LocalInstantiations(*this);
5142
5143 VarDecl *OldVar = Var;
5144 if (Def->isStaticDataMember() && !Def->isOutOfLine()) {
5145 // We're instantiating an inline static data member whose definition was
5146 // provided inside the class.
5147 InstantiateVariableInitializer(Var, Def, TemplateArgs);
5148 } else if (!VarSpec) {
5149 Var = cast_or_null<VarDecl>(SubstDecl(Def, Var->getDeclContext(),
5150 TemplateArgs));
5151 } else if (Var->isStaticDataMember() &&
5152 Var->getLexicalDeclContext()->isRecord()) {
5153 // We need to instantiate the definition of a static data member template,
5154 // and all we have is the in-class declaration of it. Instantiate a separate
5155 // declaration of the definition.
5156 TemplateDeclInstantiator Instantiator(*this, Var->getDeclContext(),
5157 TemplateArgs);
5158 Var = cast_or_null<VarDecl>(Instantiator.VisitVarTemplateSpecializationDecl(
5159 VarSpec->getSpecializedTemplate(), Def, nullptr,
5160 VarSpec->getTemplateArgsInfo(), VarSpec->getTemplateArgs().asArray()));
5161 if (Var) {
5162 llvm::PointerUnion<VarTemplateDecl *,
5163 VarTemplatePartialSpecializationDecl *> PatternPtr =
5164 VarSpec->getSpecializedTemplateOrPartial();
5165 if (VarTemplatePartialSpecializationDecl *Partial =
5166 PatternPtr.dyn_cast<VarTemplatePartialSpecializationDecl *>())
5167 cast<VarTemplateSpecializationDecl>(Var)->setInstantiationOf(
5168 Partial, &VarSpec->getTemplateInstantiationArgs());
5169
5170 // Merge the definition with the declaration.
5171 LookupResult R(*this, Var->getDeclName(), Var->getLocation(),
5172 LookupOrdinaryName, forRedeclarationInCurContext());
5173 R.addDecl(OldVar);
5174 MergeVarDecl(Var, R);
5175
5176 // Attach the initializer.
5177 InstantiateVariableInitializer(Var, Def, TemplateArgs);
5178 }
5179 } else
5180 // Complete the existing variable's definition with an appropriately
5181 // substituted type and initializer.
5182 Var = CompleteVarTemplateSpecializationDecl(VarSpec, Def, TemplateArgs);
5183
5184 PreviousContext.pop();
5185
5186 if (Var) {
5187 PassToConsumerRAII.Var = Var;
5188 Var->setTemplateSpecializationKind(OldVar->getTemplateSpecializationKind(),
5189 OldVar->getPointOfInstantiation());
5190 }
5191
5192 // This variable may have local implicit instantiations that need to be
5193 // instantiated within this scope.
5194 LocalInstantiations.perform();
5195 Local.Exit();
5196 GlobalInstantiations.perform();
5197 }
5198
5199 void
5200 Sema::InstantiateMemInitializers(CXXConstructorDecl *New,
5201 const CXXConstructorDecl *Tmpl,
5202 const MultiLevelTemplateArgumentList &TemplateArgs) {
5203
5204 SmallVector<CXXCtorInitializer*, 4> NewInits;
5205 bool AnyErrors = Tmpl->isInvalidDecl();
5206
5207 // Instantiate all the initializers.
5208 for (const auto *Init : Tmpl->inits()) {
5209 // Only instantiate written initializers, let Sema re-construct implicit
5210 // ones.
5211 if (!Init->isWritten())
5212 continue;
5213
5214 SourceLocation EllipsisLoc;
5215
5216 if (Init->isPackExpansion()) {
5217 // This is a pack expansion. We should expand it now.
5218 TypeLoc BaseTL = Init->getTypeSourceInfo()->getTypeLoc();
5219 SmallVector<UnexpandedParameterPack, 4> Unexpanded;
5220 collectUnexpandedParameterPacks(BaseTL, Unexpanded);
5221 collectUnexpandedParameterPacks(Init->getInit(), Unexpanded);
5222 bool ShouldExpand = false;
5223 bool RetainExpansion = false;
5224 Optional<unsigned> NumExpansions;
5225 if (CheckParameterPacksForExpansion(Init->getEllipsisLoc(),
5226 BaseTL.getSourceRange(),
5227 Unexpanded,
5228 TemplateArgs, ShouldExpand,
5229 RetainExpansion,
5230 NumExpansions)) {
5231 AnyErrors = true;
5232 New->setInvalidDecl();
5233 continue;
5234 }
5235 assert(ShouldExpand && "Partial instantiation of base initializer?");
5236
5237 // Loop over all of the arguments in the argument pack(s),
5238 for (unsigned I = 0; I != *NumExpansions; ++I) {
5239 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, I);
5240
5241 // Instantiate the initializer.
5242 ExprResult TempInit = SubstInitializer(Init->getInit(), TemplateArgs,
5243 /*CXXDirectInit=*/true);
5244 if (TempInit.isInvalid()) {
5245 AnyErrors = true;
5246 break;
5247 }
5248
5249 // Instantiate the base type.
5250 TypeSourceInfo *BaseTInfo = SubstType(Init->getTypeSourceInfo(),
5251 TemplateArgs,
5252 Init->getSourceLocation(),
5253 New->getDeclName());
5254 if (!BaseTInfo) {
5255 AnyErrors = true;
5256 break;
5257 }
5258
5259 // Build the initializer.
5260 MemInitResult NewInit = BuildBaseInitializer(BaseTInfo->getType(),
5261 BaseTInfo, TempInit.get(),
5262 New->getParent(),
5263 SourceLocation());
5264 if (NewInit.isInvalid()) {
5265 AnyErrors = true;
5266 break;
5267 }
5268
5269 NewInits.push_back(NewInit.get());
5270 }
5271
5272 continue;
5273 }
5274
5275 // Instantiate the initializer.
5276 ExprResult TempInit = SubstInitializer(Init->getInit(), TemplateArgs,
5277 /*CXXDirectInit=*/true);
5278 if (TempInit.isInvalid()) {
5279 AnyErrors = true;
5280 continue;
5281 }
5282
5283 MemInitResult NewInit;
5284 if (Init->isDelegatingInitializer() || Init->isBaseInitializer()) {
5285 TypeSourceInfo *TInfo = SubstType(Init->getTypeSourceInfo(),
5286 TemplateArgs,
5287 Init->getSourceLocation(),
5288 New->getDeclName());
5289 if (!TInfo) {
5290 AnyErrors = true;
5291 New->setInvalidDecl();
5292 continue;
5293 }
5294
5295 if (Init->isBaseInitializer())
5296 NewInit = BuildBaseInitializer(TInfo->getType(), TInfo, TempInit.get(),
5297 New->getParent(), EllipsisLoc);
5298 else
5299 NewInit = BuildDelegatingInitializer(TInfo, TempInit.get(),
5300 cast<CXXRecordDecl>(CurContext->getParent()));
5301 } else if (Init->isMemberInitializer()) {
5302 FieldDecl *Member = cast_or_null<FieldDecl>(FindInstantiatedDecl(
5303 Init->getMemberLocation(),
5304 Init->getMember(),
5305 TemplateArgs));
5306 if (!Member) {
5307 AnyErrors = true;
5308 New->setInvalidDecl();
5309 continue;
5310 }
5311
5312 NewInit = BuildMemberInitializer(Member, TempInit.get(),
5313 Init->getSourceLocation());
5314 } else if (Init->isIndirectMemberInitializer()) {
5315 IndirectFieldDecl *IndirectMember =
5316 cast_or_null<IndirectFieldDecl>(FindInstantiatedDecl(
5317 Init->getMemberLocation(),
5318 Init->getIndirectMember(), TemplateArgs));
5319
5320 if (!IndirectMember) {
5321 AnyErrors = true;
5322 New->setInvalidDecl();
5323 continue;
5324 }
5325
5326 NewInit = BuildMemberInitializer(IndirectMember, TempInit.get(),
5327 Init->getSourceLocation());
5328 }
5329
5330 if (NewInit.isInvalid()) {
5331 AnyErrors = true;
5332 New->setInvalidDecl();
5333 } else {
5334 NewInits.push_back(NewInit.get());
5335 }
5336 }
5337
5338 // Assign all the initializers to the new constructor.
5339 ActOnMemInitializers(New,
5340 /*FIXME: ColonLoc */
5341 SourceLocation(),
5342 NewInits,
5343 AnyErrors);
5344 }
5345
5346 // TODO: this could be templated if the various decl types used the
5347 // same method name.
5348 static bool isInstantiationOf(ClassTemplateDecl *Pattern,
5349 ClassTemplateDecl *Instance) {
5350 Pattern = Pattern->getCanonicalDecl();
5351
5352 do {
5353 Instance = Instance->getCanonicalDecl();
5354 if (Pattern == Instance) return true;
5355 Instance = Instance->getInstantiatedFromMemberTemplate();
5356 } while (Instance);
5357
5358 return false;
5359 }
5360
5361 static bool isInstantiationOf(FunctionTemplateDecl *Pattern,
5362 FunctionTemplateDecl *Instance) {
5363 Pattern = Pattern->getCanonicalDecl();
5364
5365 do {
5366 Instance = Instance->getCanonicalDecl();
5367 if (Pattern == Instance) return true;
5368 Instance = Instance->getInstantiatedFromMemberTemplate();
5369 } while (Instance);
5370
5371 return false;
5372 }
5373
5374 static bool
5375 isInstantiationOf(ClassTemplatePartialSpecializationDecl *Pattern,
5376 ClassTemplatePartialSpecializationDecl *Instance) {
5377 Pattern
5378 = cast<ClassTemplatePartialSpecializationDecl>(Pattern->getCanonicalDecl());
5379 do {
5380 Instance = cast<ClassTemplatePartialSpecializationDecl>(
5381 Instance->getCanonicalDecl());
5382 if (Pattern == Instance)
5383 return true;
5384 Instance = Instance->getInstantiatedFromMember();
5385 } while (Instance);
5386
5387 return false;
5388 }
5389
5390 static bool isInstantiationOf(CXXRecordDecl *Pattern,
5391 CXXRecordDecl *Instance) {
5392 Pattern = Pattern->getCanonicalDecl();
5393
5394 do {
5395 Instance = Instance->getCanonicalDecl();
5396 if (Pattern == Instance) return true;
5397 Instance = Instance->getInstantiatedFromMemberClass();
5398 } while (Instance);
5399
5400 return false;
5401 }
5402
5403 static bool isInstantiationOf(FunctionDecl *Pattern,
5404 FunctionDecl *Instance) {
5405 Pattern = Pattern->getCanonicalDecl();
5406
5407 do {
5408 Instance = Instance->getCanonicalDecl();
5409 if (Pattern == Instance) return true;
5410 Instance = Instance->getInstantiatedFromMemberFunction();
5411 } while (Instance);
5412
5413 return false;
5414 }
5415
5416 static bool isInstantiationOf(EnumDecl *Pattern,
5417 EnumDecl *Instance) {
5418 Pattern = Pattern->getCanonicalDecl();
5419
5420 do {
5421 Instance = Instance->getCanonicalDecl();
5422 if (Pattern == Instance) return true;
5423 Instance = Instance->getInstantiatedFromMemberEnum();
5424 } while (Instance);
5425
5426 return false;
5427 }
5428
5429 static bool isInstantiationOf(UsingShadowDecl *Pattern,
5430 UsingShadowDecl *Instance,
5431 ASTContext &C) {
5432 return declaresSameEntity(C.getInstantiatedFromUsingShadowDecl(Instance),
5433 Pattern);
5434 }
5435
5436 static bool isInstantiationOf(UsingDecl *Pattern, UsingDecl *Instance,
5437 ASTContext &C) {
5438 return declaresSameEntity(C.getInstantiatedFromUsingDecl(Instance), Pattern);
5439 }
5440
5441 template<typename T>
5442 static bool isInstantiationOfUnresolvedUsingDecl(T *Pattern, Decl *Other,
5443 ASTContext &Ctx) {
5444 // An unresolved using declaration can instantiate to an unresolved using
5445 // declaration, or to a using declaration or a using declaration pack.
5446 //
5447 // Multiple declarations can claim to be instantiated from an unresolved
5448 // using declaration if it's a pack expansion. We want the UsingPackDecl
5449 // in that case, not the individual UsingDecls within the pack.
5450 bool OtherIsPackExpansion;
5451 NamedDecl *OtherFrom;
5452 if (auto *OtherUUD = dyn_cast<T>(Other)) {
5453 OtherIsPackExpansion = OtherUUD->isPackExpansion();
5454 OtherFrom = Ctx.getInstantiatedFromUsingDecl(OtherUUD);
5455 } else if (auto *OtherUPD = dyn_cast<UsingPackDecl>(Other)) {
5456 OtherIsPackExpansion = true;
5457 OtherFrom = OtherUPD->getInstantiatedFromUsingDecl();
5458 } else if (auto *OtherUD = dyn_cast<UsingDecl>(Other)) {
5459 OtherIsPackExpansion = false;
5460 OtherFrom = Ctx.getInstantiatedFromUsingDecl(OtherUD);
5461 } else {
5462 return false;
5463 }
5464 return Pattern->isPackExpansion() == OtherIsPackExpansion &&
5465 declaresSameEntity(OtherFrom, Pattern);
5466 }
5467
5468 static bool isInstantiationOfStaticDataMember(VarDecl *Pattern,
5469 VarDecl *Instance) {
5470 assert(Instance->isStaticDataMember());
5471
5472 Pattern = Pattern->getCanonicalDecl();
5473
5474 do {
5475 Instance = Instance->getCanonicalDecl();
5476 if (Pattern == Instance) return true;
5477 Instance = Instance->getInstantiatedFromStaticDataMember();
5478 } while (Instance);
5479
5480 return false;
5481 }
5482
5483 // Other is the prospective instantiation
5484 // D is the prospective pattern
5485 static bool isInstantiationOf(ASTContext &Ctx, NamedDecl *D, Decl *Other) {
5486 if (auto *UUD = dyn_cast<UnresolvedUsingTypenameDecl>(D))
5487 return isInstantiationOfUnresolvedUsingDecl(UUD, Other, Ctx);
5488
5489 if (auto *UUD = dyn_cast<UnresolvedUsingValueDecl>(D))
5490 return isInstantiationOfUnresolvedUsingDecl(UUD, Other, Ctx);
5491
5492 if (D->getKind() != Other->getKind())
5493 return false;
5494
5495 if (auto *Record = dyn_cast<CXXRecordDecl>(Other))
5496 return isInstantiationOf(cast<CXXRecordDecl>(D), Record);
5497
5498 if (auto *Function = dyn_cast<FunctionDecl>(Other))
5499 return isInstantiationOf(cast<FunctionDecl>(D), Function);
5500
5501 if (auto *Enum = dyn_cast<EnumDecl>(Other))
5502 return isInstantiationOf(cast<EnumDecl>(D), Enum);
5503
5504 if (auto *Var = dyn_cast<VarDecl>(Other))
5505 if (Var->isStaticDataMember())
5506 return isInstantiationOfStaticDataMember(cast<VarDecl>(D), Var);
5507
5508 if (auto *Temp = dyn_cast<ClassTemplateDecl>(Other))
5509 return isInstantiationOf(cast<ClassTemplateDecl>(D), Temp);
5510
5511 if (auto *Temp = dyn_cast<FunctionTemplateDecl>(Other))
5512 return isInstantiationOf(cast<FunctionTemplateDecl>(D), Temp);
5513
5514 if (auto *PartialSpec =
5515 dyn_cast<ClassTemplatePartialSpecializationDecl>(Other))
5516 return isInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(D),
5517 PartialSpec);
5518
5519 if (auto *Field = dyn_cast<FieldDecl>(Other)) {
5520 if (!Field->getDeclName()) {
5521 // This is an unnamed field.
5522 return declaresSameEntity(Ctx.getInstantiatedFromUnnamedFieldDecl(Field),
5523 cast<FieldDecl>(D));
5524 }
5525 }
5526
5527 if (auto *Using = dyn_cast<UsingDecl>(Other))
5528 return isInstantiationOf(cast<UsingDecl>(D), Using, Ctx);
5529
5530 if (auto *Shadow = dyn_cast<UsingShadowDecl>(Other))
5531 return isInstantiationOf(cast<UsingShadowDecl>(D), Shadow, Ctx);
5532
5533 return D->getDeclName() &&
5534 D->getDeclName() == cast<NamedDecl>(Other)->getDeclName();
5535 }
5536
5537 template<typename ForwardIterator>
5538 static NamedDecl *findInstantiationOf(ASTContext &Ctx,
5539 NamedDecl *D,
5540 ForwardIterator first,
5541 ForwardIterator last) {
5542 for (; first != last; ++first)
5543 if (isInstantiationOf(Ctx, D, *first))
5544 return cast<NamedDecl>(*first);
5545
5546 return nullptr;
5547 }
5548
5549 /// Finds the instantiation of the given declaration context
5550 /// within the current instantiation.
5551 ///
5552 /// \returns NULL if there was an error
5553 DeclContext *Sema::FindInstantiatedContext(SourceLocation Loc, DeclContext* DC,
5554 const MultiLevelTemplateArgumentList &TemplateArgs) {
5555 if (NamedDecl *D = dyn_cast<NamedDecl>(DC)) {
5556 Decl* ID = FindInstantiatedDecl(Loc, D, TemplateArgs, true);
5557 return cast_or_null<DeclContext>(ID);
5558 } else return DC;
5559 }
5560
5561 /// Find the instantiation of the given declaration within the
5562 /// current instantiation.
5563 ///
5564 /// This routine is intended to be used when \p D is a declaration
5565 /// referenced from within a template, that needs to mapped into the
5566 /// corresponding declaration within an instantiation. For example,
5567 /// given:
5568 ///
5569 /// \code
5570 /// template<typename T>
5571 /// struct X {
5572 /// enum Kind {
5573 /// KnownValue = sizeof(T)
5574 /// };
5575 ///
5576 /// bool getKind() const { return KnownValue; }
5577 /// };
5578 ///
5579 /// template struct X<int>;
5580 /// \endcode
5581 ///
5582 /// In the instantiation of X<int>::getKind(), we need to map the \p
5583 /// EnumConstantDecl for \p KnownValue (which refers to
5584 /// X<T>::<Kind>::KnownValue) to its instantiation (X<int>::<Kind>::KnownValue).
5585 /// \p FindInstantiatedDecl performs this mapping from within the instantiation
5586 /// of X<int>.
5587 NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
5588 const MultiLevelTemplateArgumentList &TemplateArgs,
5589 bool FindingInstantiatedContext) {
5590 DeclContext *ParentDC = D->getDeclContext();
5591 // FIXME: Parmeters of pointer to functions (y below) that are themselves
5592 // parameters (p below) can have their ParentDC set to the translation-unit
5593 // - thus we can not consistently check if the ParentDC of such a parameter
5594 // is Dependent or/and a FunctionOrMethod.
5595 // For e.g. this code, during Template argument deduction tries to
5596 // find an instantiated decl for (T y) when the ParentDC for y is
5597 // the translation unit.
5598 // e.g. template <class T> void Foo(auto (*p)(T y) -> decltype(y())) {}
5599 // float baz(float(*)()) { return 0.0; }
5600 // Foo(baz);
5601 // The better fix here is perhaps to ensure that a ParmVarDecl, by the time
5602 // it gets here, always has a FunctionOrMethod as its ParentDC??
5603 // For now:
5604 // - as long as we have a ParmVarDecl whose parent is non-dependent and
5605 // whose type is not instantiation dependent, do nothing to the decl
5606 // - otherwise find its instantiated decl.
5607 if (isa<ParmVarDecl>(D) && !ParentDC->isDependentContext() &&
5608 !cast<ParmVarDecl>(D)->getType()->isInstantiationDependentType())
5609 return D;
5610 if (isa<ParmVarDecl>(D) || isa<NonTypeTemplateParmDecl>(D) ||
5611 isa<TemplateTypeParmDecl>(D) || isa<TemplateTemplateParmDecl>(D) ||
5612 ((ParentDC->isFunctionOrMethod() ||
5613 isa<OMPDeclareReductionDecl>(ParentDC) ||
5614 isa<OMPDeclareMapperDecl>(ParentDC)) &&
5615 ParentDC->isDependentContext()) ||
5616 (isa<CXXRecordDecl>(D) && cast<CXXRecordDecl>(D)->isLambda())) {
5617 // D is a local of some kind. Look into the map of local
5618 // declarations to their instantiations.
5619 if (CurrentInstantiationScope) {
5620 if (auto Found = CurrentInstantiationScope->findInstantiationOf(D)) {
5621 if (Decl *FD = Found->dyn_cast<Decl *>())
5622 return cast<NamedDecl>(FD);
5623
5624 int PackIdx = ArgumentPackSubstitutionIndex;
5625 assert(PackIdx != -1 &&
5626 "found declaration pack but not pack expanding");
5627 typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
5628 return cast<NamedDecl>((*Found->get<DeclArgumentPack *>())[PackIdx]);
5629 }
5630 }
5631
5632 // If we're performing a partial substitution during template argument
5633 // deduction, we may not have values for template parameters yet. They
5634 // just map to themselves.
5635 if (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D) ||
5636 isa<TemplateTemplateParmDecl>(D))
5637 return D;
5638
5639 if (D->isInvalidDecl())
5640 return nullptr;
5641
5642 // Normally this function only searches for already instantiated declaration
5643 // however we have to make an exclusion for local types used before
5644 // definition as in the code:
5645 //
5646 // template<typename T> void f1() {
5647 // void g1(struct x1);
5648 // struct x1 {};
5649 // }
5650 //
5651 // In this case instantiation of the type of 'g1' requires definition of
5652 // 'x1', which is defined later. Error recovery may produce an enum used
5653 // before definition. In these cases we need to instantiate relevant
5654 // declarations here.
5655 bool NeedInstantiate = false;
5656 if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D))
5657 NeedInstantiate = RD->isLocalClass();
5658 else
5659 NeedInstantiate = isa<EnumDecl>(D);
5660 if (NeedInstantiate) {
5661 Decl *Inst = SubstDecl(D, CurContext, TemplateArgs);
5662 CurrentInstantiationScope->InstantiatedLocal(D, Inst);
5663 return cast<TypeDecl>(Inst);
5664 }
5665
5666 // If we didn't find the decl, then we must have a label decl that hasn't
5667 // been found yet. Lazily instantiate it and return it now.
5668 assert(isa<LabelDecl>(D));
5669
5670 Decl *Inst = SubstDecl(D, CurContext, TemplateArgs);
5671 assert(Inst && "Failed to instantiate label??");
5672
5673 CurrentInstantiationScope->InstantiatedLocal(D, Inst);
5674 return cast<LabelDecl>(Inst);
5675 }
5676
5677 if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) {
5678 if (!Record->isDependentContext())
5679 return D;
5680
5681 // Determine whether this record is the "templated" declaration describing
5682 // a class template or class template partial specialization.
5683 ClassTemplateDecl *ClassTemplate = Record->getDescribedClassTemplate();
5684 if (ClassTemplate)
5685 ClassTemplate = ClassTemplate->getCanonicalDecl();
5686 else if (ClassTemplatePartialSpecializationDecl *PartialSpec
5687 = dyn_cast<ClassTemplatePartialSpecializationDecl>(Record))
5688 ClassTemplate = PartialSpec->getSpecializedTemplate()->getCanonicalDecl();
5689
5690 // Walk the current context to find either the record or an instantiation of
5691 // it.
5692 DeclContext *DC = CurContext;
5693 while (!DC->isFileContext()) {
5694 // If we're performing substitution while we're inside the template
5695 // definition, we'll find our own context. We're done.
5696 if (DC->Equals(Record))
5697 return Record;
5698
5699 if (CXXRecordDecl *InstRecord = dyn_cast<CXXRecordDecl>(DC)) {
5700 // Check whether we're in the process of instantiating a class template
5701 // specialization of the template we're mapping.
5702 if (ClassTemplateSpecializationDecl *InstSpec
5703 = dyn_cast<ClassTemplateSpecializationDecl>(InstRecord)){
5704 ClassTemplateDecl *SpecTemplate = InstSpec->getSpecializedTemplate();
5705 if (ClassTemplate && isInstantiationOf(ClassTemplate, SpecTemplate))
5706 return InstRecord;
5707 }
5708
5709 // Check whether we're in the process of instantiating a member class.
5710 if (isInstantiationOf(Record, InstRecord))
5711 return InstRecord;
5712 }
5713
5714 // Move to the outer template scope.
5715 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(DC)) {
5716 if (FD->getFriendObjectKind() && FD->getDeclContext()->isFileContext()){
5717 DC = FD->getLexicalDeclContext();
5718 continue;
5719 }
5720 // An implicit deduction guide acts as if it's within the class template
5721 // specialization described by its name and first N template params.
5722 auto *Guide = dyn_cast<CXXDeductionGuideDecl>(FD);
5723 if (Guide && Guide->isImplicit()) {
5724 TemplateDecl *TD = Guide->getDeducedTemplate();
5725 // Convert the arguments to an "as-written" list.
5726 TemplateArgumentListInfo Args(Loc, Loc);
5727 for (TemplateArgument Arg : TemplateArgs.getInnermost().take_front(
5728 TD->getTemplateParameters()->size())) {
5729 ArrayRef<TemplateArgument> Unpacked(Arg);
5730 if (Arg.getKind() == TemplateArgument::Pack)
5731 Unpacked = Arg.pack_elements();
5732 for (TemplateArgument UnpackedArg : Unpacked)
5733 Args.addArgument(
5734 getTrivialTemplateArgumentLoc(UnpackedArg, QualType(), Loc));
5735 }
5736 QualType T = CheckTemplateIdType(TemplateName(TD), Loc, Args);
5737 if (T.isNull())
5738 return nullptr;
5739 auto *SubstRecord = T->getAsCXXRecordDecl();
5740 assert(SubstRecord && "class template id not a class type?");
5741 // Check that this template-id names the primary template and not a
5742 // partial or explicit specialization. (In the latter cases, it's
5743 // meaningless to attempt to find an instantiation of D within the
5744 // specialization.)
5745 // FIXME: The standard doesn't say what should happen here.
5746 if (FindingInstantiatedContext &&
5747 usesPartialOrExplicitSpecialization(
5748 Loc, cast<ClassTemplateSpecializationDecl>(SubstRecord))) {
5749 Diag(Loc, diag::err_specialization_not_primary_template)
5750 << T << (SubstRecord->getTemplateSpecializationKind() ==
5751 TSK_ExplicitSpecialization);
5752 return nullptr;
5753 }
5754 DC = SubstRecord;
5755 continue;
5756 }
5757 }
5758
5759 DC = DC->getParent();
5760 }
5761
5762 // Fall through to deal with other dependent record types (e.g.,
5763 // anonymous unions in class templates).
5764 }
5765
5766 if (!ParentDC->isDependentContext())
5767 return D;
5768
5769 ParentDC = FindInstantiatedContext(Loc, ParentDC, TemplateArgs);
5770 if (!ParentDC)
5771 return nullptr;
5772
5773 if (ParentDC != D->getDeclContext()) {
5774 // We performed some kind of instantiation in the parent context,
5775 // so now we need to look into the instantiated parent context to
5776 // find the instantiation of the declaration D.
5777
5778 // If our context used to be dependent, we may need to instantiate
5779 // it before performing lookup into that context.
5780 bool IsBeingInstantiated = false;
5781 if (CXXRecordDecl *Spec = dyn_cast<CXXRecordDecl>(ParentDC)) {
5782 if (!Spec->isDependentContext()) {
5783 QualType T = Context.getTypeDeclType(Spec);
5784 const RecordType *Tag = T->getAs<RecordType>();
5785 assert(Tag && "type of non-dependent record is not a RecordType");
5786 if (Tag->isBeingDefined())
5787 IsBeingInstantiated = true;
5788 if (!Tag->isBeingDefined() &&
5789 RequireCompleteType(Loc, T, diag::err_incomplete_type))
5790 return nullptr;
5791
5792 ParentDC = Tag->getDecl();
5793 }
5794 }
5795
5796 NamedDecl *Result = nullptr;
5797 // FIXME: If the name is a dependent name, this lookup won't necessarily
5798 // find it. Does that ever matter?
5799 if (auto Name = D->getDeclName()) {
5800 DeclarationNameInfo NameInfo(Name, D->getLocation());
5801 DeclarationNameInfo NewNameInfo =
5802 SubstDeclarationNameInfo(NameInfo, TemplateArgs);
5803 Name = NewNameInfo.getName();
5804 if (!Name)
5805 return nullptr;
5806 DeclContext::lookup_result Found = ParentDC->lookup(Name);
5807
5808 if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D)) {
5809 VarTemplateDecl *Templ = cast_or_null<VarTemplateDecl>(
5810 findInstantiationOf(Context, VTSD->getSpecializedTemplate(),
5811 Found.begin(), Found.end()));
5812 if (!Templ)
5813 return nullptr;
5814 Result = getVarTemplateSpecialization(
5815 Templ, &VTSD->getTemplateArgsInfo(), NewNameInfo, SourceLocation());
5816 } else
5817 Result = findInstantiationOf(Context, D, Found.begin(), Found.end());
5818 } else {
5819 // Since we don't have a name for the entity we're looking for,
5820 // our only option is to walk through all of the declarations to
5821 // find that name. This will occur in a few cases:
5822 //
5823 // - anonymous struct/union within a template
5824 // - unnamed class/struct/union/enum within a template
5825 //
5826 // FIXME: Find a better way to find these instantiations!
5827 Result = findInstantiationOf(Context, D,
5828 ParentDC->decls_begin(),
5829 ParentDC->decls_end());
5830 }
5831
5832 if (!Result) {
5833 if (isa<UsingShadowDecl>(D)) {
5834 // UsingShadowDecls can instantiate to nothing because of using hiding.
5835 } else if (Diags.hasErrorOccurred()) {
5836 // We've already complained about something, so most likely this
5837 // declaration failed to instantiate. There's no point in complaining
5838 // further, since this is normal in invalid code.
5839 } else if (IsBeingInstantiated) {
5840 // The class in which this member exists is currently being
5841 // instantiated, and we haven't gotten around to instantiating this
5842 // member yet. This can happen when the code uses forward declarations
5843 // of member classes, and introduces ordering dependencies via
5844 // template instantiation.
5845 Diag(Loc, diag::err_member_not_yet_instantiated)
5846 << D->getDeclName()
5847 << Context.getTypeDeclType(cast<CXXRecordDecl>(ParentDC));
5848 Diag(D->getLocation(), diag::note_non_instantiated_member_here);
5849 } else if (EnumConstantDecl *ED = dyn_cast<EnumConstantDecl>(D)) {
5850 // This enumeration constant was found when the template was defined,
5851 // but can't be found in the instantiation. This can happen if an
5852 // unscoped enumeration member is explicitly specialized.
5853 EnumDecl *Enum = cast<EnumDecl>(ED->getLexicalDeclContext());
5854 EnumDecl *Spec = cast<EnumDecl>(FindInstantiatedDecl(Loc, Enum,
5855 TemplateArgs));
5856 assert(Spec->getTemplateSpecializationKind() ==
5857 TSK_ExplicitSpecialization);
5858 Diag(Loc, diag::err_enumerator_does_not_exist)
5859 << D->getDeclName()
5860 << Context.getTypeDeclType(cast<TypeDecl>(Spec->getDeclContext()));
5861 Diag(Spec->getLocation(), diag::note_enum_specialized_here)
5862 << Context.getTypeDeclType(Spec);
5863 } else {
5864 // We should have found something, but didn't.
5865 llvm_unreachable("Unable to find instantiation of declaration!");
5866 }
5867 }
5868
5869 D = Result;
5870 }
5871
5872 return D;
5873 }
5874
5875 /// Performs template instantiation for all implicit template
5876 /// instantiations we have seen until this point.
5877 void Sema::PerformPendingInstantiations(bool LocalOnly) {
5878 while (!PendingLocalImplicitInstantiations.empty() ||
5879 (!LocalOnly && !PendingInstantiations.empty())) {
5880 PendingImplicitInstantiation Inst;
5881
5882 if (PendingLocalImplicitInstantiations.empty()) {
5883 Inst = PendingInstantiations.front();
5884 PendingInstantiations.pop_front();
5885 } else {
5886 Inst = PendingLocalImplicitInstantiations.front();
5887 PendingLocalImplicitInstantiations.pop_front();
5888 }
5889
5890 // Instantiate function definitions
5891 if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Inst.first)) {
5892 bool DefinitionRequired = Function->getTemplateSpecializationKind() ==
5893 TSK_ExplicitInstantiationDefinition;
5894 if (Function->isMultiVersion()) {
5895 getASTContext().forEachMultiversionedFunctionVersion(
5896 Function, [this, Inst, DefinitionRequired](FunctionDecl *CurFD) {
5897 InstantiateFunctionDefinition(/*FIXME:*/ Inst.second, CurFD, true,
5898 DefinitionRequired, true);
5899 if (CurFD->isDefined())
5900 CurFD->setInstantiationIsPending(false);
5901 });
5902 } else {
5903 InstantiateFunctionDefinition(/*FIXME:*/ Inst.second, Function, true,
5904 DefinitionRequired, true);
5905 if (Function->isDefined())
5906 Function->setInstantiationIsPending(false);
5907 }
5908 continue;
5909 }
5910
5911 // Instantiate variable definitions
5912 VarDecl *Var = cast<VarDecl>(Inst.first);
5913
5914 assert((Var->isStaticDataMember() ||
5915 isa<VarTemplateSpecializationDecl>(Var)) &&
5916 "Not a static data member, nor a variable template"
5917 " specialization?");
5918
5919 // Don't try to instantiate declarations if the most recent redeclaration
5920 // is invalid.
5921 if (Var->getMostRecentDecl()->isInvalidDecl())
5922 continue;
5923
5924 // Check if the most recent declaration has changed the specialization kind
5925 // and removed the need for implicit instantiation.
5926 switch (Var->getMostRecentDecl()
5927 ->getTemplateSpecializationKindForInstantiation()) {
5928 case TSK_Undeclared:
5929 llvm_unreachable("Cannot instantitiate an undeclared specialization.");
5930 case TSK_ExplicitInstantiationDeclaration:
5931 case TSK_ExplicitSpecialization:
5932 continue; // No longer need to instantiate this type.
5933 case TSK_ExplicitInstantiationDefinition:
5934 // We only need an instantiation if the pending instantiation *is* the
5935 // explicit instantiation.
5936 if (Var != Var->getMostRecentDecl())
5937 continue;
5938 break;
5939 case TSK_ImplicitInstantiation:
5940 break;
5941 }
5942
5943 PrettyDeclStackTraceEntry CrashInfo(Context, Var, SourceLocation(),
5944 "instantiating variable definition");
5945 bool DefinitionRequired = Var->getTemplateSpecializationKind() ==
5946 TSK_ExplicitInstantiationDefinition;
5947
5948 // Instantiate static data member definitions or variable template
5949 // specializations.
5950 InstantiateVariableDefinition(/*FIXME:*/ Inst.second, Var, true,
5951 DefinitionRequired, true);
5952 }
5953 }
5954
5955 void Sema::PerformDependentDiagnostics(const DeclContext *Pattern,
5956 const MultiLevelTemplateArgumentList &TemplateArgs) {
5957 for (auto DD : Pattern->ddiags()) {
5958 switch (DD->getKind()) {
5959 case DependentDiagnostic::Access:
5960 HandleDependentAccessCheck(*DD, TemplateArgs);
5961 break;
5962 }
5963 }
5964 }
clang::NonTypeTemplateParmDecl::isPackExpansion
bool isPackExpansion() const
Whether this parameter pack is a pack expansion.
Definition: DeclTemplate.h:1504
clang::VarDecl::getDescribedVarTemplate
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition: Decl.cpp:2580
clang::OMPDeclareMapperDecl::clauselists
clauselist_range clauselists()
Definition: DeclOpenMP.h:270
clang::Sema::ForExternalRedeclaration
The lookup results will be used for redeclaration of a name with external linkage; non-visible lookup...
Definition: Sema.h:3492
clang::Builtin::ID
ID
Definition: Builtins.h:46
ASTContext.h
Defines the clang::ASTContext interface.
clang::FunctionDecl::getDefinition
FunctionDecl * getDefinition()
Get the definition for this declaration.
Definition: Decl.h:2039
clang::Sema::InstantiateClassMembers
void InstantiateClassMembers(SourceLocation PointOfInstantiation, CXXRecordDecl *Instantiation, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateSpecializationKind TSK)
Instantiates the definitions of all of the member of the given class, which is an instantiation of a ...
Definition: SemaTemplateInstantiate.cpp:2959
collectUnexpandedParameterPacks
static void collectUnexpandedParameterPacks(Sema &S, TemplateParameterList *Params, SmallVectorImpl< UnexpandedParameterPack > &Unexpanded)
Definition: SemaTemplateInstantiateDecl.cpp:2721
clang::Sema::ForVisibleRedeclaration
The lookup results will be used for redeclaration of a name, if an entity by that name already exists...
Definition: Sema.h:3488
clang::VarDecl::mightBeUsableInConstantExpressions
bool mightBeUsableInConstantExpressions(ASTContext &C) const
Determine whether this variable&#39;s value might be usable in a constant expression, according to the re...
Definition: Decl.cpp:2292
clang::Decl::setImplicit
void setImplicit(bool I=true)
Definition: DeclBase.h:559
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1783
CheckConstraintSatisfaction
static bool CheckConstraintSatisfaction(Sema &S, const NamedDecl *Template, ArrayRef< const Expr *> ConstraintExprs, ArrayRef< TemplateArgument > TemplateArgs, SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction)
Definition: SemaConcept.cpp:233
clang::Sema::getStdNamespace
NamespaceDecl * getStdNamespace() const
Definition: SemaDeclCXX.cpp:10635
clang::OMPDeclareMapperDecl::getPrevDeclInScope
OMPDeclareMapperDecl * getPrevDeclInScope()
Get reference to previous declare mapper construct in the same scope with the same name...
Definition: DeclOpenMP.cpp:218
Diag
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Definition: LiteralSupport.cpp:77
clang::Sema::PerformContextuallyConvertToBool
ExprResult PerformContextuallyConvertToBool(Expr *From)
PerformContextuallyConvertToBool - Perform a contextual conversion of the expression From to bool (C+...
Definition: SemaOverload.cpp:5439
clang::EST_None
no exception specification
Definition: ExceptionSpecificationType.h:21
clang::Sema::ActOnOpenMPDeclareMapperDirectiveStart
OMPDeclareMapperDecl * ActOnOpenMPDeclareMapperDirectiveStart(Scope *S, DeclContext *DC, DeclarationName Name, QualType MapperType, SourceLocation StartLoc, DeclarationName VN, AccessSpecifier AS, Decl *PrevDeclInScope=nullptr)
Called on start of &#39;#pragma omp declare mapper&#39;.
Definition: SemaOpenMP.cpp:16445
clang::ASTConsumer::HandleCXXStaticMemberVarInstantiation
virtual void HandleCXXStaticMemberVarInstantiation(VarDecl *D)
HandleCXXStaticMemberVarInstantiation - Tell the consumer that this.
Definition: ASTConsumer.h:116
clang::OpaquePtr::get
PtrTy get() const
Definition: Ownership.h:80
clang::Sema::TemplateParameterListsAreEqual
bool TemplateParameterListsAreEqual(TemplateParameterList *New, TemplateParameterList *Old, bool Complain, TemplateParameterListEqualKind Kind, SourceLocation TemplateArgLoc=SourceLocation())
Determine whether the given template parameter lists are equivalent.
Definition: SemaTemplate.cpp:7539
clang::Sema::InstantiateAttrsForDecl
void InstantiateAttrsForDecl(const MultiLevelTemplateArgumentList &TemplateArgs, const Decl *Pattern, Decl *Inst, LateInstantiatedAttrVec *LateAttrs=nullptr, LocalInstantiationScope *OuterMostScope=nullptr)
Definition: SemaTemplateInstantiateDecl.cpp:508
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:654
clang::Sema::ActOnOpenMPDeclareReductionCombinerStart
void ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D)
Initialize declare reduction construct initializer.
Definition: SemaOpenMP.cpp:16272
clang::Decl::getDeclKindName
const char * getDeclKindName() const
Definition: DeclBase.cpp:123
clang::LocalInstantiationScope::InstantiatedLocal
void InstantiatedLocal(const Decl *D, Decl *Inst)
Definition: SemaTemplateInstantiate.cpp:3358
clang::TemplateTypeParmDecl::setDefaultArgument
void setDefaultArgument(TypeSourceInfo *DefArg)
Set the default argument for this template parameter.
Definition: DeclTemplate.h:1270
clang::ClassTemplateSpecializationDecl::setTemplateKeywordLoc
void setTemplateKeywordLoc(SourceLocation Loc)
Sets the location of the template keyword.
Definition: DeclTemplate.h:2033
clang::TemplateDeclInstantiator::VisitVarDecl
Decl * VisitVarDecl(VarDecl *D, bool InstantiatingVarTemplate, ArrayRef< BindingDecl *> *Bindings=nullptr)
Definition: SemaTemplateInstantiateDecl.cpp:896
clang::FunctionDecl::isOverloadedOperator
bool isOverloadedOperator() const
Whether this function declaration represents an C++ overloaded operator, e.g., "operator+".
Definition: Decl.h:2525
clang::ASTConsumer
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
Definition: ASTConsumer.h:33
clang::LocalInstantiationScope
A stack-allocated class that identifies which local variable declaration instantiations are present i...
Definition: Template.h:227
clang::ConcreteTypeLoc::getTypePtr
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:409
clang::Sema::InstantiateExceptionSpec
void InstantiateExceptionSpec(SourceLocation PointOfInstantiation, FunctionDecl *Function)
Definition: SemaTemplateInstantiateDecl.cpp:4188
clang::Sema::EndOpenMPDSABlock
void EndOpenMPDSABlock(Stmt *CurDirective)
Called on end of data sharing attribute block.
Definition: SemaOpenMP.cpp:2239
clang::Sema::TemplateInstCallbacks
std::vector< std::unique_ptr< TemplateInstantiationCallback > > TemplateInstCallbacks
The template instantiation callbacks to trace or track instantiations (objects can be chained)...
Definition: Sema.h:8192
clang::NestedNameSpecifierLoc::getSourceRange
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
Definition: NestedNameSpecifier.cpp:421
clang::TypeAliasTemplateDecl::Create
static TypeAliasTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Create a function template node.
Definition: DeclTemplate.cpp:1070
clang::FunctionTemplateDecl::findSpecialization
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
Definition: DeclTemplate.cpp:350
clang::Sema::LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc...
Definition: Sema.h:3435
clang::TagDecl::getBraceRange
SourceRange getBraceRange() const
Definition: Decl.h:3300
clang::OMPDeclareReductionDecl::CallInit
Definition: DeclOpenMP.h:107
clang::FunctionDecl::willHaveBody
bool willHaveBody() const
True if this function will eventually have a body, once it&#39;s fully parsed.
Definition: Decl.h:2347
clang::DeclarationNameTable::getCXXConstructorName
DeclarationName getCXXConstructorName(CanQualType Ty)
Returns the name of a C++ constructor for the given Type.
Definition: DeclarationName.cpp:298
instantiateDependentAllocAlignAttr
static void instantiateDependentAllocAlignAttr(Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const AllocAlignAttr *Align, Decl *New)
Definition: SemaTemplateInstantiateDecl.cpp:171
clang::FieldDecl::getInClassInitStyle
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition: Decl.h:2862
clang::TemplateArgumentLoc::getTemplateQualifierLoc
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:531
clang::MultiLevelTemplateArgumentList::addOuterTemplateArguments
void addOuterTemplateArguments(const TemplateArgumentList *TemplateArgs)
Add a new outermost level to the multi-level template argument list.
Definition: Template.h:133
clang::ClassScopeFunctionSpecializationDecl::getTemplateArgsAsWritten
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Definition: DeclTemplate.h:2616
clang::DecltypeType::getUnderlyingExpr
Expr * getUnderlyingExpr() const
Definition: Type.h:4380
clang::IndirectFieldDecl::Create
static IndirectFieldDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, llvm::MutableArrayRef< NamedDecl *> CH)
Definition: Decl.cpp:4782
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:66
clang::FieldDecl::getBitWidth
Expr * getBitWidth() const
Definition: Decl.h:2818
clang::Sema::TPL_TemplateMatch
We are matching the template parameter lists of two templates that might be redeclarations.
Definition: Sema.h:7235
clang::Redeclarable::setPreviousDecl
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
Definition: Decl.h:4473
clang::OMPAllocateDecl
This represents &#39;#pragma omp allocate ...&#39; directive.
Definition: DeclOpenMP.h:422
clang::FunctionDecl::getTemplateSpecializationArgsAsWritten
const ASTTemplateArgumentListInfo * getTemplateSpecializationArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
Definition: Decl.cpp:3679
clang::sema::TemplateDeductionInfo
Provides information about an attempted template argument deduction, whose success or failure was des...
Definition: TemplateDeduction.h:42
isDeclWithinFunction
static bool isDeclWithinFunction(const Decl *D)
Definition: SemaTemplateInstantiateDecl.cpp:30
clang::VarTemplateDecl::getTemplatedDecl
VarDecl * getTemplatedDecl() const
Get the underlying variable declarations of the template.
Definition: DeclTemplate.h:3115
clang::OMP_CTX_unknown
Definition: OpenMPKinds.h:33
clang::FunctionDecl::isOutOfLine
bool isOutOfLine() const override
Determine whether this is or was instantiated from an out-of-line definition of a member function...
Definition: Decl.cpp:3845
clang::EnumConstantDecl
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:2941
clang::TemplateTypeParmDecl::isPackExpansion
bool isPackExpansion() const
Whether this parameter pack is a pack expansion.
Definition: DeclTemplate.h:1303
clang::VarDecl::getStorageClass
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1029
clang::TagDecl::setTypedefNameForAnonDecl
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition: Decl.cpp:4145
clang::TypedefDecl
Represents the declaration of a typedef-name via the &#39;typedef&#39; type specifier.
Definition: Decl.h:3173
clang::Sema::CheckTemplatePartialSpecializationArgs
bool CheckTemplatePartialSpecializationArgs(SourceLocation Loc, TemplateDecl *PrimaryTemplate, unsigned NumExplicitArgs, ArrayRef< TemplateArgument > Args)
Check the non-type template arguments of a class template partial specialization according to C++ [te...
Definition: SemaTemplate.cpp:7917
clang::DependentNameType
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:5368
clang::Sema::BuildVarTemplateInstantiation
VarTemplateSpecializationDecl * BuildVarTemplateInstantiation(VarTemplateDecl *VarTemplate, VarDecl *FromVar, const TemplateArgumentList &TemplateArgList, const TemplateArgumentListInfo &TemplateArgsInfo, SmallVectorImpl< TemplateArgument > &Converted, SourceLocation PointOfInstantiation, void *InsertPos, LateInstantiatedAttrVec *LateAttrs=nullptr, LocalInstantiationScope *StartingScope=nullptr)
Definition: SemaTemplateInstantiateDecl.cpp:4687
clang::NonTypeTemplateParmDecl::getNumExpansionTypes
unsigned getNumExpansionTypes() const
Retrieves the number of expansion types in an expanded parameter pack.
Definition: DeclTemplate.h:1536
clang::TemplateTemplateParmDecl::Create
static TemplateTemplateParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation L, unsigned D, unsigned P, bool ParameterPack, IdentifierInfo *Id, TemplateParameterList *Params)
Definition: DeclTemplate.cpp:777
clang::DependentDiagnostic::Access
unsigned Access
Definition: DependentDiagnostic.h:116
clang::LookupResult::isSingleTagDecl
bool isSingleTagDecl() const
Asks if the result is a single tag decl.
Definition: Lookup.h:530
clang::Sema::BuildUsingDeclaration
NamedDecl * BuildUsingDeclaration(Scope *S, AccessSpecifier AS, SourceLocation UsingLoc, bool HasTypenameKeyword, SourceLocation TypenameLoc, CXXScopeSpec &SS, DeclarationNameInfo NameInfo, SourceLocation EllipsisLoc, const ParsedAttributesView &AttrList, bool IsInstantiation)
Builds a using declaration.
Definition: SemaDeclCXX.cpp:11555
clang::TemplateTypeParmDecl::Create
static TemplateTypeParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation KeyLoc, SourceLocation NameLoc, unsigned D, unsigned P, IdentifierInfo *Id, bool Typename, bool ParameterPack, bool HasTypeConstraint=false, Optional< unsigned > NumExpanded=None)
Definition: DeclTemplate.cpp:592
clang::VarTemplateDecl::findPartialSpecialization
VarTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, TemplateParameterList *TPL, void *&InsertPos)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
Definition: DeclTemplate.cpp:1169
clang::TypeDecl::getTypeForDecl
const Type * getTypeForDecl() const
Definition: Decl.h:3053
clang::Sema::Diag
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition: Sema.h:1411
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:88
clang::FunctionDecl::setRangeEnd
void setRangeEnd(SourceLocation E)
Definition: Decl.h:1984
clang::Decl::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:421
instantiateDependentFunctionAttrCondition
static Expr * instantiateDependentFunctionAttrCondition(Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const Attr *A, Expr *OldCond, const Decl *Tmpl, FunctionDecl *New)
Definition: SemaTemplateInstantiateDecl.cpp:181
clang::MSPropertyDecl::getGetterId
IdentifierInfo * getGetterId() const
Definition: DeclCXX.h:3962
clang::VarDecl::getDefinition
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition: Decl.cpp:2194
clang::Sema::addAMDGPUWavesPerEUAttr
void addAMDGPUWavesPerEUAttr(Decl *D, const AttributeCommonInfo &CI, Expr *Min, Expr *Max)
addAMDGPUWavePersEUAttr - Adds an amdgpu_waves_per_eu attribute to a particular declaration.
clang::VarDecl::getTSCSpec
ThreadStorageClassSpecifier getTSCSpec() const
Definition: Decl.h:1038
clang::TemplateDeclInstantiator::adjustForRewrite
void adjustForRewrite(RewriteKind RK, FunctionDecl *Orig, QualType &T, TypeSourceInfo *&TInfo, DeclarationNameInfo &NameInfo)
Definition: SemaTemplateInstantiateDecl.cpp:3640
clang::LocalInstantiationScope::findInstantiationOf
llvm::PointerUnion< Decl *, DeclArgumentPack * > * findInstantiationOf(const Decl *D)
Find the instantiation of the declaration D within the current instantiation scope.
Definition: SemaTemplateInstantiate.cpp:3310
DeclTemplate.h
Defines the C++ template declaration subclasses.
P
StringRef P
Definition: ASTMatchersInternal.cpp:485
clang::FunctionDecl::hasWrittenPrototype
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Definition: Decl.h:2178
clang::TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl
Decl * VisitVarTemplateSpecializationDecl(VarTemplateDecl *VarTemplate, VarDecl *FromVar, void *InsertPos, const TemplateArgumentListInfo &TemplateArgsInfo, ArrayRef< TemplateArgument > Converted, VarTemplateSpecializationDecl *PrevDecl=nullptr)
Definition: SemaTemplateInstantiateDecl.cpp:3513
clang::TemplateDeclInstantiator::InstantiateTypedefNameDecl
Decl * InstantiateTypedefNameDecl(TypedefNameDecl *D, bool IsTypeAlias)
Definition: SemaTemplateInstantiateDecl.cpp:736
clang::Sema::CodeSynthesisContexts
SmallVector< CodeSynthesisContext, 16 > CodeSynthesisContexts
List of active code synthesis contexts.
Definition: Sema.h:8135
clang::Decl::FOK_None
Not a friend object.
Definition: DeclBase.h:1102
clang::Decl::getPreviousDecl
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration, or NULL if there is no previous declaration.
Definition: DeclBase.h:960
clang::QualType::getNonReferenceType
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
Definition: Type.h:6452
clang::Sema::InstantiateFunctionDeclaration
FunctionDecl * InstantiateFunctionDeclaration(FunctionTemplateDecl *FTD, const TemplateArgumentList *Args, SourceLocation Loc)
Instantiate (or find existing instantiation of) a function template with a given set of template argu...
Definition: SemaTemplateInstantiateDecl.cpp:4411
clang::AccessSpecDecl::getColonLoc
SourceLocation getColonLoc() const
The location of the colon following the access specifier.
Definition: DeclCXX.h:107
clang::VarDecl::isCXXForRangeDecl
bool isCXXForRangeDecl() const
Determine whether this variable is the for-range-declaration in a C++0x for-range statement...
Definition: Decl.h:1365
clang::ExplicitSpecifier::getKind
ExplicitSpecKind getKind() const
Definition: DeclCXX.h:1795
clang::TemplateTemplateParmDecl::isExpandedParameterPack
bool isExpandedParameterPack() const
Whether this parameter is a template template parameter pack that has a known list of different templ...
Definition: DeclTemplate.h:1698
clang::Sema::TPC_FriendFunctionTemplate
Definition: Sema.h:6968
clang::Sema::PendingLocalImplicitInstantiations
std::deque< PendingImplicitInstantiation > PendingLocalImplicitInstantiations
The queue of implicit template instantiations that are required and must be performed within the curr...
Definition: Sema.h:8592
clang::VarTemplateDecl
Declaration of a variable template.
Definition: DeclTemplate.h:3070
clang::Sema::ActOnOpenMPDeclareMapperDirectiveVarDecl
void ActOnOpenMPDeclareMapperDirectiveVarDecl(OMPDeclareMapperDecl *DMD, Scope *S, QualType MapperType, SourceLocation StartLoc, DeclarationName VN)
Build the mapper variable of &#39;#pragma omp declare mapper&#39;.
Definition: SemaOpenMP.cpp:16523
clang::NamespaceDecl
Represent a C++ namespace.
Definition: Decl.h:497
clang::Decl::getEndLoc
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:425
clang::ASTContext::getTargetInfo
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:707
clang::FunctionType::getNoReturnAttr
bool getNoReturnAttr() const
Determine whether this function type includes the GNU noreturn attribute.
Definition: Type.h:3688
clang::TypeSourceInfo
A container of type source information.
Definition: Type.h:6227
clang::ExplicitSpecifier
Store information needed for an explicit specifier.
Definition: DeclCXX.h:1787
clang::OpaquePtr
Wrapper for void* pointer.
Definition: Ownership.h:50
clang::VarTemplatePartialSpecializationDecl::getTemplateParameters
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:2968
clang::Sema::PendingImplicitInstantiation
std::pair< ValueDecl *, SourceLocation > PendingImplicitInstantiation
An entity for which implicit template instantiation is required.
Definition: Sema.h:8537
clang::ASTContext::getInstantiatedFromUnnamedFieldDecl
FieldDecl * getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field)
Definition: ASTContext.cpp:1615
clang::OMPDeclareMapperDecl::clauselist_begin
clauselist_iterator clauselist_begin()
Definition: DeclOpenMP.h:276
clang::FunctionDecl::Create
static FunctionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation NLoc, DeclarationName N, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool isInlineSpecified=false, bool hasWrittenPrototype=true, ConstexprSpecKind ConstexprKind=CSK_unspecified, Expr *TrailingRequiresClause=nullptr)
Definition: Decl.h:1955
clang::TemplateTypeParmDecl::getDefaultArgumentInfo
TypeSourceInfo * getDefaultArgumentInfo() const
Retrieves the default argument&#39;s source information, if any.
Definition: DeclTemplate.h:1256
clang::RequiresExprBodyDecl::Create
static RequiresExprBodyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc)
Definition: DeclCXX.cpp:1971
clang::Sema::InstantiatingTemplate::ConstraintsCheck
Definition: Sema.h:8331
clang::FunctionDecl::isDefined
bool isDefined(const FunctionDecl *&Definition) const
Returns true if the function has a definition that does not need to be instantiated.
Definition: Decl.cpp:2883
clang::VarTemplateSpecializationDecl::setTemplateArgsInfo
void setTemplateArgsInfo(const TemplateArgumentListInfo &ArgsInfo)
Definition: DeclTemplate.cpp:1278
clang::FunctionDecl::getNameForDiagnostic
void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const override
Appends a human-readable name for this declaration into the given stream.
Definition: Decl.cpp:2819
clang::VarDecl::setInitStyle
void setInitStyle(InitializationStyle Style)
Definition: Decl.h:1295
clang::TemplateDeclInstantiator::InstantiateVarTemplatePartialSpecialization
VarTemplatePartialSpecializationDecl * InstantiateVarTemplatePartialSpecialization(VarTemplateDecl *VarTemplate, VarTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a variable template partial specialization.
Definition: SemaTemplateInstantiateDecl.cpp:3899
clang::CXXConstructorDecl
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2383
clang::LookupResult::clear
LLVM_ATTRIBUTE_REINITIALIZES void clear()
Clears out any current state.
Definition: Lookup.h:554
clang::DeclaratorDecl::setTrailingRequiresClause
void setTrailingRequiresClause(Expr *TrailingRequiresClause)
Definition: Decl.cpp:1848
clang::Sema::SubstTemplateName
TemplateName SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, SourceLocation Loc, const MultiLevelTemplateArgumentList &TemplateArgs)
Definition: SemaTemplateInstantiate.cpp:3272
clang::Sema::CheckCXXDefaultArgExpr
bool CheckCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, ParmVarDecl *Param)
Instantiate or parse a C++ default argument expression as necessary.
Definition: SemaExpr.cpp:4926
clang::Sema::MarkFunctionReferenced
void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, bool MightBeOdrUse=true)
Mark a function referenced, and check whether it is odr-used (C++ [basic.def.odr]p2, C99 6.9p3)
Definition: SemaExpr.cpp:15521
clang::FunctionDecl::isVirtualAsWritten
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition: Decl.h:2096
clang::Sema::InstantiateVariableDefinition
void InstantiateVariableDefinition(SourceLocation PointOfInstantiation, VarDecl *Var, bool Recursive=false, bool DefinitionRequired=false, bool AtEndOfTU=false)
Instantiate the definition of the given variable from its template.
Definition: SemaTemplateInstantiateDecl.cpp:4978
instantiateDependentEnableIfAttr
static void instantiateDependentEnableIfAttr(Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const EnableIfAttr *EIA, const Decl *Tmpl, FunctionDecl *New)
Definition: SemaTemplateInstantiateDecl.cpp:212
clang::NamespaceAliasDecl::getTargetNameLoc
SourceLocation getTargetNameLoc() const
Returns the location of the identifier in the named namespace.
Definition: DeclCXX.h:3059
clang::TagDecl::isCompleteDefinition
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3324
clang::NonTypeTemplateParmDecl::defaultArgumentWasInherited
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template...
Definition: DeclTemplate.h:1472
clang::ClassTemplatePartialSpecializationDecl::getTemplateParameters
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:2123
clang::PragmaCommentDecl
Represents a #pragma comment line.
Definition: Decl.h:114
Value
Value
Definition: UninitializedValues.cpp:101
clang::CXXConstructorDecl::isDefaultConstructor
bool isDefaultConstructor() const
Whether this constructor is a default constructor (C++ [class.ctor]p5), which can be used to default-...
Definition: DeclCXX.cpp:2520
clang::Sema::BuildUsingPackDecl
NamedDecl * BuildUsingPackDecl(NamedDecl *InstantiatedFrom, ArrayRef< NamedDecl *> Expansions)
Definition: SemaDeclCXX.cpp:11813
clang::Sema::TPC_ClassTemplate
Definition: Sema.h:6963
clang::TemplateTemplateParmDecl::isPackExpansion
bool isPackExpansion() const
Whether this parameter pack is a pack expansion.
Definition: DeclTemplate.h:1675
clang::CXXScopeSpec::Adopt
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition: DeclSpec.cpp:124
clang::TemplateArgumentListInfo::setRAngleLoc
void setRAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:574
clang::TemplateParmPosition::getDepth
unsigned getDepth() const
Get the nesting depth of the template parameter.
Definition: DeclTemplate.h:1160
clang::EnumDecl::enumerators
enumerator_range enumerators() const
Definition: Decl.h:3608
clang::FriendDecl
FriendDecl - Represents the declaration of a friend entity, which can be a function, a type, or a templated function or type.
Definition: DeclFriend.h:53
clang::Sema::SubstSpaceshipAsEqualEqual
FunctionDecl * SubstSpaceshipAsEqualEqual(CXXRecordDecl *RD, FunctionDecl *Spaceship)
Substitute the name and return type of a defaulted &#39;operator<=>&#39; to form an implicit &#39;operator==&#39;...
Definition: SemaTemplateInstantiateDecl.cpp:3672
clang::TemplateTemplateParmDecl::getExpansionTemplateParameters
TemplateParameterList * getExpansionTemplateParameters(unsigned I) const
Retrieve a particular expansion type within an expanded parameter pack.
Definition: DeclTemplate.h:1709
clang::EnterExpressionEvaluationContext
RAII object that enters a new expression evaluation context.
Definition: Sema.h:12029
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:820
clang::Sema::LateInstantiatedAttribute
Definition: Sema.h:8747
clang::FunctionDecl::getReturnType
QualType getReturnType() const
Definition: Decl.h:2445
clang::Sema::TPC_FriendFunctionTemplateDefinition
Definition: Sema.h:6969
clang::TemplateDeclInstantiator::SubstQualifier
bool SubstQualifier(const DeclaratorDecl *OldDecl, DeclaratorDecl *NewDecl)
Definition: SemaTemplateInstantiateDecl.cpp:67
clang::SC_Static
Definition: Specifiers.h:239
clang::SC_None
Definition: Specifiers.h:237
clang::EnumDecl::isFixed
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition: Decl.h:3684
instantiateDependentAlignedAttr
static void instantiateDependentAlignedAttr(Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const AlignedAttr *Aligned, Decl *New, bool IsPackExpansion)
Definition: SemaTemplateInstantiateDecl.cpp:80
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:7002
clang::NonTypeTemplateParmDecl::hasDefaultArgument
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
Definition: DeclTemplate.h:1462
clang::Sema::computeDeclContext
DeclContext * computeDeclContext(QualType T)
Compute the DeclContext that is associated with the given type.
Definition: SemaCXXScopeSpec.cpp:53
clang::ClassTemplateSpecializationDecl::getExternLoc
SourceLocation getExternLoc() const
Gets the location of the extern keyword, if present.
Definition: DeclTemplate.h:2021
clang::FunctionProtoType::ExtProtoInfo
Extra information about a function prototype.
Definition: Type.h:3837
clang::ExternCContextDecl
Declaration context for names declared as extern "C" in C++.
Definition: Decl.h:196
clang::MSPropertyDecl::Create
static MSPropertyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName N, QualType T, TypeSourceInfo *TInfo, SourceLocation StartL, IdentifierInfo *Getter, IdentifierInfo *Setter)
Definition: DeclCXX.cpp:3114
clang::VarTemplateSpecializationDecl
Represents a variable template specialization, which refers to a variable template with a given set o...
Definition: DeclTemplate.h:2655
clang::TemplateSpecializationTypeLoc
Definition: TypeLoc.h:1574
clang::VarTemplateSpecializationDecl::getPointOfInstantiation
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
Definition: DeclTemplate.h:2783
clang::Sema::ActOnFinishFullExpr
ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue)
Definition: Sema.h:5849
clang::Sema::CXXThisScopeRAII
RAII object used to temporarily allow the C++ &#39;this&#39; expression to be used, with the given qualifiers...
Definition: Sema.h:5616
clang::ASTTemplateArgumentListInfo
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:603
instantiateDependentCUDALaunchBoundsAttr
static void instantiateDependentCUDALaunchBoundsAttr(Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const CUDALaunchBoundsAttr &Attr, Decl *New)
Definition: SemaTemplateInstantiateDecl.cpp:237
clang::DeclContextLookupResult::front
reference front() const
Definition: DeclBase.h:1242
clang::Decl::isInvalidDecl
bool isInvalidDecl() const
Definition: DeclBase.h:553
clang::TemplateParameterList
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:69
clang::Sema::CodeSynthesisContext
A context in which code is being synthesized (where a source location alone is not sufficient to iden...
Definition: Sema.h:7987
instantiateDependentAssumeAlignedAttr
static void instantiateDependentAssumeAlignedAttr(Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const AssumeAlignedAttr *Aligned, Decl *New)
Definition: SemaTemplateInstantiateDecl.cpp:137
SemaInternal.h
clang::CXXMethodDecl::isStatic
bool isStatic() const
Definition: DeclCXX.cpp:1983
clang::Sema::LookupRedeclarationWithLinkage
Look up an ordinary name that is going to be redeclared as a name with linkage.
Definition: Sema.h:3464
clang::ParmVarDecl
Represents a parameter to a function.
Definition: Decl.h:1595
clang::AccessSpecDecl::Create
static AccessSpecDecl * Create(ASTContext &C, AccessSpecifier AS, DeclContext *DC, SourceLocation ASLoc, SourceLocation ColonLoc)
Definition: DeclCXX.h:116
ExprCXX.h
Defines the clang::Expr interface and subclasses for C++ expressions.
clang::DependentFunctionTemplateSpecializationInfo
Provides information about a dependent function-template specialization declaration.
Definition: DeclTemplate.h:686
clang::BuiltinTemplateDecl
Represents the builtin template declaration which is used to implement __make_integer_seq and other b...
Definition: DeclTemplate.h:1763
clang::Qualifiers
The collection of all-type qualifiers we support.
Definition: Type.h:143
clang::CXXRecordDecl::isLocalClass
const FunctionDecl * isLocalClass() const
If the class is a local class [class.local], returns the enclosing function declaration.
Definition: DeclCXX.h:1440
clang::Sema::ActOnOpenMPDeclareReductionDirectiveStart
DeclGroupPtrTy ActOnOpenMPDeclareReductionDirectiveStart(Scope *S, DeclContext *DC, DeclarationName Name, ArrayRef< std::pair< QualType, SourceLocation >> ReductionTypes, AccessSpecifier AS, Decl *PrevDeclInScope=nullptr)
Called on start of &#39;#pragma omp declare reduction&#39;.
Definition: SemaOpenMP.cpp:16190
clang::Sema::ActOnOpenMPDeclareSimdDirective
DeclGroupPtrTy ActOnOpenMPDeclareSimdDirective(DeclGroupPtrTy DG, OMPDeclareSimdDeclAttr::BranchStateTy BS, Expr *Simdlen, ArrayRef< Expr *> Uniforms, ArrayRef< Expr *> Aligneds, ArrayRef< Expr *> Alignments, ArrayRef< Expr *> Linears, ArrayRef< unsigned > LinModifiers, ArrayRef< Expr *> Steps, SourceRange SR)
Called on well-formed &#39;#pragma omp declare simd&#39; after parsing of the associated method/function.
Definition: SemaOpenMP.cpp:4995
clang::Sema::MarkDeclarationsReferencedInType
void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T)
Mark all of the declarations referenced within a particular AST node as referenced.
Definition: SemaExpr.cpp:17125
clang::NamedDecl::getIdentifier
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:244
clang::Decl::isLexicallyWithinFunctionOrMethod
bool isLexicallyWithinFunctionOrMethod() const
Returns true if this declaration lexically is inside a function.
Definition: DeclBase.cpp:335
clang::TypeLoc
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:58
clang::Sema::CheckFriendAccess
AccessResult CheckFriendAccess(NamedDecl *D)
Checks access to the target of a friend declaration.
Definition: SemaAccess.cpp:1771
clang::RecordDecl
Represents a struct/union/class.
Definition: Decl.h:3748
clang::Sema::addAMDGPUFlatWorkGroupSizeAttr
void addAMDGPUFlatWorkGroupSizeAttr(Decl *D, const AttributeCommonInfo &CI, Expr *Min, Expr *Max)
addAMDGPUFlatWorkGroupSizeAttr - Adds an amdgpu_flat_work_group_size attribute to a particular declar...
clang::Sema::CheckUsingDeclQualifier
bool CheckUsingDeclQualifier(SourceLocation UsingLoc, bool HasTypename, const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, SourceLocation NameLoc)
Checks that the given nested-name qualifier used in a using decl in the current context is appropriat...
Definition: SemaDeclCXX.cpp:11935
clang::Sema::AddAlignValueAttr
void AddAlignValueAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E)
AddAlignValueAttr - Adds an align_value attribute to a particular declaration.
instantiateOMPDeclareVariantAttr
static void instantiateOMPDeclareVariantAttr(Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const OMPDeclareVariantAttr &Attr, Decl *New)
Instantiation of &#39;declare variant&#39; attribute and its arguments.
Definition: SemaTemplateInstantiateDecl.cpp:352
clang::VarTemplateSpecializationDecl::getSpecializedTemplateOrPartial
llvm::PointerUnion< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > getSpecializedTemplateOrPartial() const
Retrieve the variable template or variable template partial specialization which was specialized by t...
Definition: DeclTemplate.h:2810
clang::InheritedConstructor
Description of a constructor that was inherited from a base class.
Definition: DeclCXX.h:2357
clang::NamedDecl::getDeclName
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:272
clang::EnumDecl::getIntegerTypeSourceInfo
TypeSourceInfo * getIntegerTypeSourceInfo() const
Return the type source info for the underlying integer type, if no type source info exists...
Definition: Decl.h:3651
clang::FunctionProtoType::ExtProtoInfo::ExtInfo
FunctionType::ExtInfo ExtInfo
Definition: Type.h:3838
clang::ClassTemplateSpecializationDecl
Represents a class template specialization, which refers to a class template with a given set of temp...
Definition: DeclTemplate.h:1802
clang::TargetInfo::getCXXABI
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
Definition: TargetInfo.h:1063
clang::Sema::CurrentInstantiationScope
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
Definition: Sema.h:8508
clang::FriendDecl::getFriendType
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition: DeclFriend.h:123
clang::TemplateTypeParmDecl::getDepth
unsigned getDepth() const
Retrieve the depth of the template parameter.
Definition: DeclTemplate.cpp:642
clang::StaticAssertDecl::getMessage
StringLiteral * getMessage()
Definition: DeclCXX.h:3789
clang::TemplateDeclInstantiator::RewriteKind::RewriteSpaceshipAsEqualEqual
clang::IdentifierInfo::isStr
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
Definition: IdentifierTable.h:136
clang::Sema::ActOnOpenMPDeclareMapperDirectiveEnd
DeclGroupPtrTy ActOnOpenMPDeclareMapperDirectiveEnd(OMPDeclareMapperDecl *D, Scope *S, ArrayRef< OMPClause *> ClauseList)
Called at the end of &#39;#pragma omp declare mapper&#39;.
Definition: SemaOpenMP.cpp:16538
clang::ASTContext::setManglingNumber
void setManglingNumber(const NamedDecl *ND, unsigned Number)
Definition: ASTContext.cpp:10407
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:168
clang::NestedNameSpecifierLoc
A C++ nested-name-specifier augmented with source location information.
Definition: NestedNameSpecifier.h:236
clang::ExprEmpty
ExprResult ExprEmpty()
Definition: Ownership.h:285
clang::Sema::SubstNestedNameSpecifierLoc
NestedNameSpecifierLoc SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, const MultiLevelTemplateArgumentList &TemplateArgs)
Definition: SemaTemplateInstantiate.cpp:3252
clang::ClassTemplateSpecializationDecl::getSpecializationKind
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
Definition: DeclTemplate.h:1896
llvm::Optional< unsigned >
clang::FunctionProtoType::getParamTypes
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:3971
clang::DeclContextLookupResult
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1195
clang::NamespaceAliasDecl::getNamespace
NamespaceDecl * getNamespace()
Retrieve the namespace declaration aliased by this directive.
Definition: DeclCXX.h:3040
clang::FunctionDecl::getConstexprKind
ConstexprSpecKind getConstexprKind() const
Definition: Decl.h:2206
clang::ASTContext::setInstantiatedFromUnnamedFieldDecl
void setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, FieldDecl *Tmpl)
Definition: ASTContext.cpp:1624
clang::Sema::CheckEnumUnderlyingType
bool CheckEnumUnderlyingType(TypeSourceInfo *TI)
Check that this is a valid underlying type for an enum declaration.
Definition: SemaDecl.cpp:14553
clang::TemplateSpecializationType::anyDependentTemplateArguments
static bool anyDependentTemplateArguments(ArrayRef< TemplateArgumentLoc > Args, bool &InstantiationDependent)
Determine whether any of the given template arguments are dependent.
Definition: Type.cpp:3428
clang::VarDecl::setObjCForDecl
void setObjCForDecl(bool FRD)
Definition: Decl.h:1379
clang::TemplateTypeParmDecl::isExpandedParameterPack
bool isExpandedParameterPack() const
Whether this parameter is a template type parameter pack that has a known list of different type-cons...
Definition: DeclTemplate.h:1335
clang::DeclarationName::getNameKind
NameKind getNameKind() const
Determine what kind of name this is.
Definition: DeclarationName.h:384
clang::DecompositionDecl::Create
static DecompositionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation LSquareLoc, QualType T, TypeSourceInfo *TInfo, StorageClass S, ArrayRef< BindingDecl *> Bindings)
Definition: DeclCXX.cpp:3074
clang::FunctionDecl::hasSkippedBody
bool hasSkippedBody() const
True if the function was a definition but its body was skipped.
Definition: Decl.h:2341
clang::FieldDecl
Represents a member of a struct/union/class.
Definition: Decl.h:2729
clang::Sema::ExpressionEvaluationContext::PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
clang::TemplateDeclInstantiator::RewriteKind
RewriteKind
Definition: Template.h:476
clang::OMP_CTX_SET_unknown
Definition: OpenMPKinds.h:26
clang::Sema::ConvertDeclToDeclGroup
DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType=nullptr)
Definition: SemaDecl.cpp:55
clang::TemplateArgumentListInfo::size
unsigned size() const
Definition: TemplateBase.h:576
clang::ASTContext::getStaticLocalNumber
unsigned getStaticLocalNumber(const VarDecl *VD) const
Definition: ASTContext.cpp:10422
clang::DeclContext::isNamespace
bool isNamespace() const
Definition: DeclBase.h:1868
clang::OpenMPContextSelectorKind
OpenMPContextSelectorKind
OpenMP context selectors.
Definition: OpenMPKinds.h:30
clang::Decl::setVisibleDespiteOwningModule
void setVisibleDespiteOwningModule()
Set that this declaration is globally visible, even if it came from a module that is not visible...
Definition: DeclBase.h:780
clang::ASTContext::setInstantiatedFromUsingDecl
void setInstantiatedFromUsingDecl(NamedDecl *Inst, NamedDecl *Pattern)
Remember that the using decl Inst is an instantiation of the using decl Pattern of a class template...
Definition: ASTContext.cpp:1585
clang::TagDecl::startDefinition
void startDefinition()
Starts the definition of this tag declaration.
Definition: Decl.cpp:4154
clang::Sema::StartOpenMPDSABlock
void StartOpenMPDSABlock(OpenMPDirectiveKind K, const DeclarationNameInfo &DirName, Scope *CurScope, SourceLocation Loc)
Called on start of new data sharing attribute block.
Definition: SemaOpenMP.cpp:2215
clang::TemplateArgumentList::CreateCopy
static TemplateArgumentList * CreateCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument list that copies the given set of template arguments.
Definition: DeclTemplate.cpp:837
clang::DeclarationNameInfo::setName
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
Definition: DeclarationName.h:716
clang::Type::isReferenceType
bool isReferenceType() const
Definition: Type.h:6516
clang::OMPDeclareReductionDecl::getInitializerKind
InitKind getInitializerKind() const
Get initializer kind.
Definition: DeclOpenMP.h:173
clang::DeclContextLookupResult::end
iterator end() const
Definition: DeclBase.h:1237
clang::FriendDecl::getFriendDecl
NamedDecl * getFriendDecl() const
If this friend declaration doesn&#39;t name a type, return the inner declaration.
Definition: DeclFriend.h:138
clang::Decl::getSourceRange
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
Definition: DeclBase.h:417
clang::ASTContext::setStaticLocalNumber
void setStaticLocalNumber(const VarDecl *VD, unsigned Number)
Definition: ASTContext.cpp:10417
clang::Decl::isInIdentifierNamespace
bool isInIdentifierNamespace(unsigned NS) const
Definition: DeclBase.h:803
clang::TemplateParmPosition::getPosition
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
Definition: DeclTemplate.h:1164
clang::FunctionTypeLoc::getParam
ParmVarDecl * getParam(unsigned i) const
Definition: TypeLoc.h:1432
clang::TypeConstraint
Definition: ASTConcept.h:169
clang::DeclContext::Equals
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC...
Definition: DeclBase.h:1908
clang::Sema::ActOnOpenMPDeclareMapperType
QualType ActOnOpenMPDeclareMapperType(SourceLocation TyLoc, TypeResult ParsedType)
Check if the specified type is allowed to be used in &#39;omp declare mapper&#39; construct.
Definition: SemaOpenMP.cpp:16429
clang::LocalInstantiationScope::Exit
void Exit()
Exit this local instantiation scope early.
Definition: Template.h:307
clang::Sema::CheckParameterPacksForExpansion
bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc, SourceRange PatternRange, ArrayRef< UnexpandedParameterPack > Unexpanded, const MultiLevelTemplateArgumentList &TemplateArgs, bool &ShouldExpand, bool &RetainExpansion, Optional< unsigned > &NumExpansions)
Determine whether we could expand a pack expansion with the given set of parameter packs into separat...
Definition: SemaTemplateVariadic.cpp:645
clang::AccessSpecDecl
Represents an access specifier followed by colon &#39;:&#39;.
Definition: DeclCXX.h:85
clang::Sema::SubstDeclarationNameInfo
DeclarationNameInfo SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, const MultiLevelTemplateArgumentList &TemplateArgs)
Do template substitution on declaration name info.
Definition: SemaTemplateInstantiate.cpp:3264
clang::DeclaratorDecl::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:723
clang::ClassScopeFunctionSpecializationDecl
Declaration of a function specialization at template class scope.
Definition: DeclTemplate.h:2595
instantiateDependentAMDGPUWavesPerEUAttr
static void instantiateDependentAMDGPUWavesPerEUAttr(Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const AMDGPUWavesPerEUAttr &Attr, Decl *New)
Definition: SemaTemplateInstantiateDecl.cpp:485
clang::VarDecl::isPreviousDeclInSameBlockScope
bool isPreviousDeclInSameBlockScope() const
Whether this local extern variable declaration&#39;s previous declaration was declared in the same block ...
Definition: Decl.h:1435
DependentDiagnostic.h
clang::Sema::adjustContextForLocalExternDecl
static bool adjustContextForLocalExternDecl(DeclContext *&DC)
Adjust the DeclContext for a function or variable that might be a function-local external declaration...
Definition: SemaDecl.cpp:6510
llvm::SmallVectorImpl
Definition: LLVM.h:36
clang::ASTContext::getTemplateSpecializationTypeInfo
TypeSourceInfo * getTemplateSpecializationTypeInfo(TemplateName T, SourceLocation TLoc, const TemplateArgumentListInfo &Args, QualType Canon=QualType()) const
Definition: ASTContext.cpp:4310
clang::FunctionDecl::parameters
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2399
clang::Language::CUDA
clang::VarDecl::getPointOfInstantiation
SourceLocation getPointOfInstantiation() const
If this variable is an instantiation of a variable template or a static data member of a class templa...
Definition: Decl.cpp:2570
clang::Sema::InstantiateMemInitializers
void InstantiateMemInitializers(CXXConstructorDecl *New, const CXXConstructorDecl *Tmpl, const MultiLevelTemplateArgumentList &TemplateArgs)
Definition: SemaTemplateInstantiateDecl.cpp:5200
clang::TypeAliasTemplateDecl::getTemplatedDecl
TypeAliasDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Definition: DeclTemplate.h:2532
clang::TemplateSpecializationTypeLoc::getLAngleLoc
SourceLocation getLAngleLoc() const
Definition: TypeLoc.h:1588
clang::OMPDeclareMapperDecl::getMapperVarRef
Expr * getMapperVarRef()
Get the variable declared in the mapper.
Definition: DeclOpenMP.h:282
clang::UsingDecl
Represents a C++ using-declaration.
Definition: DeclCXX.h:3369
clang::FunctionTemplateDecl::getCanonicalDecl
FunctionTemplateDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this template.
Definition: DeclTemplate.h:1047
clang::DecompositionDecl::bindings
ArrayRef< BindingDecl * > bindings() const
Definition: DeclCXX.h:3903
instantiateDependentDiagnoseIfAttr
static void instantiateDependentDiagnoseIfAttr(Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const DiagnoseIfAttr *DIA, const Decl *Tmpl, FunctionDecl *New)
Definition: SemaTemplateInstantiateDecl.cpp:223
clang::OMPDeclareReductionDecl::getInitializer
Expr * getInitializer()
Get initializer expression (if specified) of the declare reduction construct.
Definition: DeclOpenMP.h:170
PrettyDeclStackTrace.h
clang::CXXDeductionGuideDecl::Create
static CXXDeductionGuideDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, SourceLocation EndLocation)
Definition: DeclCXX.cpp:1956
clang::LookupResult
Represents the results of name lookup.
Definition: Lookup.h:46
clang::ActionResult::get
PtrTy get() const
Definition: Ownership.h:170
clang::OpenMPContextSelectorSetKind
OpenMPContextSelectorSetKind
OpenMP context selector sets.
Definition: OpenMPKinds.h:23
clang::FunctionDecl::getBody
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition: Decl.cpp:2894
clang::DeclAccessPair::make
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
Definition: DeclAccessPair.h:35
clang::TagDecl::getTagKind
TagKind getTagKind() const
Definition: Decl.h:3398
clang::Decl::isReferenced
bool isReferenced() const
Whether any declaration of this entity was referenced.
Definition: DeclBase.cpp:423
clang::TemplateArgumentListInfo
A convenient class for passing around template argument information.
Definition: TemplateBase.h:554
clang::VarTemplateSpecializationDecl::getTemplateArgs
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
Definition: DeclTemplate.h:2746
clang::Sema::AddAllocAlignAttr
void AddAllocAlignAttr(Decl *D, const AttributeCommonInfo &CI, Expr *ParamExpr)
AddAllocAlignAttr - Adds an alloc_align attribute to a particular declaration.
clang::FunctionDecl::setDefaultedFunctionInfo
void setDefaultedFunctionInfo(DefaultedFunctionInfo *Info)
Definition: Decl.cpp:2846
clang::Sema::LookupUsingDeclName
Look up all declarations in a scope with the given name, including resolved using declarations...
Definition: Sema.h:3459
clang::TemplateTypeParmDecl::getTypeConstraint
const TypeConstraint * getTypeConstraint() const
Returns the type constraint associated with this template parameter (if any).
Definition: DeclTemplate.h:1345
clang::Sema::CheckUsingShadowDecl
bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target, const LookupResult &PreviousDecls, UsingShadowDecl *&PrevShadow)
Determines whether to create a using shadow decl for a particular decl, given the set of decls existi...
Definition: SemaDeclCXX.cpp:11191
clang::TemplateDeclInstantiator::SubstDefaultedFunction
bool SubstDefaultedFunction(FunctionDecl *New, FunctionDecl *Tmpl)
Definition: SemaTemplateInstantiateDecl.cpp:4377
clang::FunctionDecl::getDescribedFunctionTemplate
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:3561
clang::IndirectFieldDecl::chain
ArrayRef< NamedDecl * > chain() const
Definition: Decl.h:3002
clang::TemplateDeclInstantiator::InitFunctionInstantiation
bool InitFunctionInstantiation(FunctionDecl *New, FunctionDecl *Tmpl)
Initializes the common fields of an instantiation function declaration (New) from the corresponding f...
Definition: SemaTemplateInstantiateDecl.cpp:4275
clang::TypeDecl::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:3056
clang::Type::containsUnexpandedParameterPack
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:1896
clang::VarDecl::getTemplateSpecializationKind
TemplateSpecializationKind getTemplateSpecializationKind() const
If this variable is an instantiation of a variable template or a static data member of a class templa...
Definition: Decl.cpp:2549
clang::Sema::PerformPendingInstantiations
void PerformPendingInstantiations(bool LocalOnly=false)
Performs template instantiation for all implicit template instantiations we have seen until this poin...
Definition: SemaTemplateInstantiateDecl.cpp:5877
clang::ASTTemplateArgumentListInfo::RAngleLoc
SourceLocation RAngleLoc
The source location of the right angle bracket (&#39;>&#39;).
Definition: TemplateBase.h:617
clang::DeclaratorDecl::getQualifierLoc
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition: Decl.h:737
clang::CXXConstructorDecl::inits
init_range inits()
Definition: DeclCXX.h:2475
clang::TemplateTypeParmDecl::getDefaultArgumentLoc
SourceLocation getDefaultArgumentLoc() const
Retrieves the location of the default argument declaration.
Definition: DeclTemplate.cpp:624
clang::ClassTemplatePartialSpecializationDecl::setInstantiatedFromMember
void setInstantiatedFromMember(ClassTemplatePartialSpecializationDecl *PartialSpec)
Definition: DeclTemplate.h:2176
clang::VarDecl::isConstexpr
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition: Decl.h:1412
clang::TemplateArgumentListInfo::getArgumentArray
const TemplateArgumentLoc * getArgumentArray() const
Definition: TemplateBase.h:578
clang::VarTemplateSpecializationDecl::getSpecializedTemplate
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
Definition: DeclTemplate.cpp:1271
clang::ClassTemplateSpecializationDecl::setSpecializationKind
void setSpecializationKind(TemplateSpecializationKind TSK)
Definition: DeclTemplate.h:1926
clang::Scope
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
clang::CXXRecordDecl::getCanonicalDecl
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:492
clang::CXXMethodDecl::Create
static CXXMethodDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool isInline, ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, Expr *TrailingRequiresClause=nullptr)
Definition: DeclCXX.cpp:2054
clang::declaresSameEntity
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition: DeclBase.h:1166
clang::Sema::LocalEagerInstantiationScope::perform
void perform()
Definition: Sema.h:8601
clang::TagDecl::hasNameForLinkage
bool hasNameForLinkage() const
Is this tag type named, either directly or via being defined in a typedef of this type...
Definition: Decl.h:3425
clang::CXXScopeSpec
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:63
clang::TemplateTypeParmDecl::hasDefaultArgument
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
Definition: DeclTemplate.h:1248
clang::Decl::getLexicalDeclContext
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
Definition: DeclBase.h:828
clang::Sema::isIncompatibleTypedef
bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New)
Definition: SemaDecl.cpp:2183
clang::VarDecl::Create
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
Definition: Decl.cpp:1980
clang::Sema::getLangOpts
const LangOptions & getLangOpts() const
Definition: Sema.h:1324
clang::NamespaceAliasDecl::Create
static NamespaceAliasDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation NamespaceLoc, SourceLocation AliasLoc, IdentifierInfo *Alias, NestedNameSpecifierLoc QualifierLoc, SourceLocation IdentLoc, NamedDecl *Namespace)
Definition: DeclCXX.cpp:2802
clang::TemplateSpecializationTypeLoc::getArgLoc
TemplateArgumentLoc getArgLoc(unsigned i) const
Definition: TypeLoc.h:1616
clang::IntegerLiteral::Create
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value &#39;V&#39; and type &#39;type&#39;.
Definition: Expr.cpp:928
clang::Sema::AdjustDestructorExceptionSpec
void AdjustDestructorExceptionSpec(CXXDestructorDecl *Destructor)
Build an exception spec for destructors that don&#39;t have one.
Definition: SemaDeclCXX.cpp:13007
clang::Expr::isTypeDependent
bool isTypeDependent() const
isTypeDependent - Determines whether this expression is type-dependent (C++ [temp.dep.expr]), which means that its type could change from one template instantiation to the next.
Definition: Expr.h:176
clang::FunctionDecl::getInstantiatedFromMemberFunction
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization, retrieves the function from which it was instantiated.
Definition: Decl.cpp:3533
clang::EST_BasicNoexcept
noexcept
Definition: ExceptionSpecificationType.h:26
clang::FunctionTemplateDecl::Create
static FunctionTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Create a function template node.
Definition: DeclTemplate.cpp:316
clang::LookupResult::addDecl
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
Definition: Lookup.h:426
llvm::ArrayRef
Definition: LLVM.h:31
clang::DeclaratorDecl::getTypeSpecStartLoc
SourceLocation getTypeSpecStartLoc() const
Definition: Decl.cpp:1817
clang::ClassTemplateDecl::getTemplatedDecl
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
Definition: DeclTemplate.h:2286
clang::Sema::CheckStaticLocalForDllExport
void CheckStaticLocalForDllExport(VarDecl *VD)
Check if VD needs to be dllexport/dllimport due to being in a dllexport/import function.
Definition: SemaDecl.cpp:12718
clang::TemplateTemplateParmDecl::isParameterPack
bool isParameterPack() const
Whether this template template parameter is a template parameter pack.
Definition: DeclTemplate.h:1669
clang::FunctionProtoType::ExceptionSpecInfo::SourceDecl
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition: Type.h:3823
clang::TemplateSpecializationTypeLoc::getNumArgs
unsigned getNumArgs() const
Definition: TypeLoc.h:1604
clang::BindingDecl
A binding in a decomposition declaration.
Definition: DeclCXX.h:3812
clang::FunctionDecl::getMemberSpecializationInfo
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization, retrieves the member specialization information.
Definition: Decl.cpp:3540
ASTMutationListener.h
clang::Sema::ExpressionEvaluationContext::ConstantEvaluated
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
clang::Decl::IDNS_Ordinary
Ordinary names.
Definition: DeclBase.h:146
Template.h
clang::Sema::ArgumentPackSubstitutionIndexRAII
RAII object used to change the argument pack substitution index within a Sema object.
Definition: Sema.h:8206
clang::RecordDecl::isAnonymousStructOrUnion
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition: Decl.h:3821
clang::Sema::BuildUsingShadowDecl
UsingShadowDecl * BuildUsingShadowDecl(Scope *S, UsingDecl *UD, NamedDecl *Target, UsingShadowDecl *PrevDecl)
Builds a shadow declaration corresponding to a &#39;using&#39; declaration.
Definition: SemaDeclCXX.cpp:11359
clang::Sema::AddModeAttr
void AddModeAttr(Decl *D, const AttributeCommonInfo &CI, IdentifierInfo *Name, bool InInstantiation=false)
AddModeAttr - Adds a mode attribute to a particular declaration.
clang::Sema::InstantiateFunctionDefinition
void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, FunctionDecl *Function, bool Recursive=false, bool DefinitionRequired=false, bool AtEndOfTU=false)
Instantiate the definition of the given function from its template.
Definition: SemaTemplateInstantiateDecl.cpp:4467
clang::Sema::ExtParameterInfoBuilder
A helper class for building up ExtParameterInfos.
Definition: Sema.h:8617
clang::Sema::ActOnOpenMPDeclareReductionInitializerStart
VarDecl * ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D)
Initialize declare reduction construct initializer.
Definition: SemaOpenMP.cpp:16333
clang::AS_none
Definition: Specifiers.h:117
clang::DeclContext::lookup
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1612
clang::StaticAssertDecl::getRParenLoc
SourceLocation getRParenLoc() const
Definition: DeclCXX.h:3794
clang::FunctionDecl::getDefaultedFunctionInfo
DefaultedFunctionInfo * getDefaultedFunctionInfo() const
Definition: Decl.cpp:2855
clang::NonTypeTemplateParmDecl::isExpandedParameterPack
bool isExpandedParameterPack() const
Whether this parameter is a non-type template parameter pack that has a known list of different types...
Definition: DeclTemplate.h:1532
clang::FunctionDecl::getPrimaryTemplate
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
Definition: Decl.cpp:3653
clang::Sema::getDiagnostics
DiagnosticsEngine & getDiagnostics() const
Definition: Sema.h:1328
clang::CXXConstructorDecl::Create
static CXXConstructorDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, ExplicitSpecifier ES, bool isInline, bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, InheritedConstructor Inherited=InheritedConstructor(), Expr *TrailingRequiresClause=nullptr)
Definition: DeclCXX.cpp:2489
Parent
NodeId Parent
Definition: ASTDiff.cpp:191
clang::LocalInstantiationScope::MakeInstantiatedLocalArgPack
void MakeInstantiatedLocalArgPack(const Decl *D)
Definition: SemaTemplateInstantiate.cpp:3386
clang::Decl::hasAttr
bool hasAttr() const
Definition: DeclBase.h:542
clang::Sema::SubstFunctionDeclType
TypeSourceInfo * SubstFunctionDeclType(TypeSourceInfo *T, const MultiLevelTemplateArgumentList &TemplateArgs, SourceLocation Loc, DeclarationName Entity, CXXRecordDecl *ThisContext, Qualifiers ThisTypeQuals)
A form of SubstType intended specifically for instantiating the type of a FunctionDecl.
Definition: SemaTemplateInstantiate.cpp:2040
clang::Sema
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:336
clang::TypeAliasDecl
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition: Decl.h:3193
clang::Type::getAsCXXRecordDecl
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1690
clang::VarTemplateDecl::AddSpecialization
void AddSpecialization(VarTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
Definition: DeclTemplate.cpp:1163
clang::FunctionProtoType
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3754
clang::FunctionDecl::setImplicitlyInline
void setImplicitlyInline(bool I=true)
Flag that this function is implicitly inline.
Definition: Decl.h:2508
clang::UnresolvedUsingTypenameDecl::getTypenameLoc
SourceLocation getTypenameLoc() const
Returns the source location of the &#39;typename&#39; keyword.
Definition: DeclCXX.h:3716
clang::CXXRecordDecl::getTemplateSpecializationKind
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
Definition: DeclCXX.cpp:1700
clang::Sema::inferObjCARCLifetime
bool inferObjCARCLifetime(ValueDecl *decl)
Definition: SemaDecl.cpp:6103
clang::DeclaratorDecl
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:671
clang::ASTContext::DeclarationNames
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:583
clang::Sema::CheckSpecializationInstantiationRedecl
bool CheckSpecializationInstantiationRedecl(SourceLocation NewLoc, TemplateSpecializationKind NewTSK, NamedDecl *PrevDecl, TemplateSpecializationKind PrevTSK, SourceLocation PrevPtOfInstantiation, bool &SuppressNew)
Diagnose cases where we have an explicit template specialization before/after an explicit template in...
Definition: SemaTemplate.cpp:8422
adjustFunctionTypeForInstantiation
static QualType adjustFunctionTypeForInstantiation(ASTContext &Context, FunctionDecl *D, TypeSourceInfo *TInfo)
Adjust the given function type for an instantiation of the given declaration, to cope with modificati...
Definition: SemaTemplateInstantiateDecl.cpp:1775
clang::OMPDeclareMapperDecl::getVarName
DeclarationName getVarName()
Get the name of the variable declared in the mapper.
Definition: DeclOpenMP.h:288
clang::MultiLevelTemplateArgumentList::getNumSubstitutedLevels
unsigned getNumSubstitutedLevels() const
Determine the number of substituted levels in this template argument list.
Definition: Template.h:94
clang::NonTypeTemplateParmDecl::isParameterPack
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
Definition: DeclTemplate.h:1497
clang::VarDecl::isInlineSpecified
bool isInlineSpecified() const
Definition: Decl.h:1397
clang::OMPDeclareReductionDecl::getCombiner
Expr * getCombiner()
Get combiner expression of the declare reduction construct.
Definition: DeclOpenMP.h:152
clang::ConstraintSatisfaction
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition: ASTConcept.h:29
clang::ASTContext::getTrivialTypeSourceInfo
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location, which defaults to the empty location.
Definition: ASTContext.cpp:2816
clang::TypedefNameDecl::getTypeSourceInfo
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:3121
clang::OMPRequiresDecl
This represents &#39;#pragma omp requires...&#39; directive.
Definition: DeclOpenMP.h:345
clang::MultiLevelTemplateArgumentList::getInnermost
const ArgList & getInnermost() const
Retrieve the innermost template argument list.
Definition: Template.h:154
clang::runWithSufficientStackSpace
void runWithSufficientStackSpace(llvm::function_ref< void()> Diag, llvm::function_ref< void()> Fn)
Run a given function on a stack with "sufficient" space.
Definition: Stack.h:40
clang::Sema::CheckAlignasUnderalignment
void CheckAlignasUnderalignment(Decl *D)
clang::TemplateDecl::getTemplateParameters
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:421
clang::Sema::CheckPackExpansion
TypeSourceInfo * CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc, Optional< unsigned > NumExpansions)
Construct a pack expansion type from the pattern of the pack expansion.
Definition: SemaTemplateVariadic.cpp:583
clang::FunctionDecl::isInlineSpecified
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition: Decl.h:2499
clang::Sema::AddAssumeAlignedAttr
void AddAssumeAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, Expr *OE)
AddAssumeAlignedAttr - Adds an assume_aligned attribute to a particular declaration.
clang::ConstructorUsingShadowDecl
Represents a shadow constructor declaration introduced into a class by a C++11 using-declaration that...
Definition: DeclCXX.h:3263
clang::Expr
This represents one expression.
Definition: Expr.h:108
clang::UsingDecl::getQualifierLoc
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition: DeclCXX.h:3409
clang::VarTemplateSpecializationDecl::setCompleteDefinition
void setCompleteDefinition()
Definition: DeclTemplate.h:2792
clang::ASTContext::setInstantiatedFromUsingShadowDecl
void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst, UsingShadowDecl *Pattern)
Definition: ASTContext.cpp:1609
clang::IndirectFieldDecl::getChainingSize
unsigned getChainingSize() const
Definition: Decl.h:3008
clang::NamespaceAliasDecl::getAliasLoc
SourceLocation getAliasLoc() const
Returns the location of the alias name, i.e.
Definition: DeclCXX.h:3053
clang::ClassTemplatePartialSpecializationDecl::Create
static ClassTemplatePartialSpecializationDecl * Create(ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, TemplateParameterList *Params, ClassTemplateDecl *SpecializedTemplate, ArrayRef< TemplateArgument > Args, const TemplateArgumentListInfo &ArgInfos, QualType CanonInjectedType, ClassTemplatePartialSpecializationDecl *PrevDecl)
Definition: DeclTemplate.cpp:1017
clang::RequiresExprBodyDecl
Represents the body of a requires-expression.
Definition: DeclCXX.h:1909
clang::FunctionDecl::isDefaulted
bool isDefaulted() const
Whether this function is defaulted per C++0x.
Definition: Decl.h:2130
clang::ASTContext::addTypedefNameForUnnamedTagDecl
void addTypedefNameForUnnamedTagDecl(TagDecl *TD, TypedefNameDecl *TND)
Definition: ASTContext.cpp:10464
clang::EnumDecl::isScopedUsingClassTag
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:3678
clang::Sema::InstantiateAttrs
void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, const Decl *Pattern, Decl *Inst, LateInstantiatedAttrVec *LateAttrs=nullptr, LocalInstantiationScope *OuterMostScope=nullptr)
Definition: SemaTemplateInstantiateDecl.cpp:542
clang::SourceManager::isInSystemHeader
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
Definition: SourceManager.h:1493
clang::Sema::deduceOpenCLAddressSpace
void deduceOpenCLAddressSpace(ValueDecl *decl)
Definition: SemaDecl.cpp:6147
clang::Sema::ActOnOpenMPDeclareReductionCombinerEnd
void ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner)
Finish current declare reduction construct initializer.
Definition: SemaOpenMP.cpp:16319
Previous
StateNode * Previous
Definition: UnwrappedLineFormatter.cpp:934
clang::TemplateTypeParmDecl
Declaration of a template type parameter.
Definition: DeclTemplate.h:1177
clang::Sema::CheckOMPThreadPrivateDecl
OMPThreadPrivateDecl * CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef< Expr *> VarList)
Builds a new OpenMPThreadPrivateDecl and checks its correctness.
Definition: SemaOpenMP.cpp:2538
clang::TemplateDeclInstantiator::InstantiateClassTemplatePartialSpecialization
ClassTemplatePartialSpecializationDecl * InstantiateClassTemplatePartialSpecialization(ClassTemplateDecl *ClassTemplate, ClassTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a class template partial specialization.
Definition: SemaTemplateInstantiateDecl.cpp:3771
clang::UsingDecl::getNameInfo
DeclarationNameInfo getNameInfo() const
Definition: DeclCXX.h:3416
clang::ASTTemplateArgumentListInfo::NumTemplateArgs
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
Definition: TemplateBase.h:620
clang::LookupResult::setHideTags
void setHideTags(bool Hide)
Sets whether tag declarations should be hidden by non-tag declarations during resolution.
Definition: Lookup.h:288
clang::Sema::PerformDependentDiagnostics
void PerformDependentDiagnostics(const DeclContext *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs)
Definition: SemaTemplateInstantiateDecl.cpp:5955
clang::OMPDeclareReductionDecl::getPrevDeclInScope
OMPDeclareReductionDecl * getPrevDeclInScope()
Get reference to previous declare reduction construct in the same scope with the same name...
Definition: DeclOpenMP.cpp:158
clang::Type::castAs
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7067
clang::Sema::InstantiatingTemplate::isInvalid
bool isInvalid() const
Determines whether we have exceeded the maximum recursive template instantiations.
Definition: Sema.h:8382
clang::TemplateDeclInstantiator
Definition: Template.h:417
clang::TypeLoc::getAs
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition: TypeLoc.h:88
getPreviousDeclForInstantiation
static DeclT * getPreviousDeclForInstantiation(DeclT *D)
Get the previous declaration of a declaration for the purposes of template instantiation.
Definition: SemaTemplateInstantiateDecl.cpp:676
clang::CXXDestructorDecl
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2649
clang::FunctionDecl::isThisDeclarationADefinition
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
Definition: Decl.h:2071
clang::Decl::setInvalidDecl
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
Definition: DeclBase.cpp:132
Lookup.h
clang::Decl::isImplicit
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:558
clang::FunctionDecl::getTemplateSpecializationArgs
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
Definition: Decl.cpp:3669
clang::Sema::CheckTemplateArgumentList
bool CheckTemplateArgumentList(TemplateDecl *Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &TemplateArgs, bool PartialTemplateArgs, SmallVectorImpl< TemplateArgument > &Converted, bool UpdateArgsWithConversions=true, bool *ConstraintsNotSatisfied=nullptr)
Check that the given template arguments can be be provided to the given template, converting the argu...
Definition: SemaTemplate.cpp:5415
clang::Sema::CheckInheritingConstructorUsingDecl
bool CheckInheritingConstructorUsingDecl(UsingDecl *UD)
Additional checks for a using declaration referring to a constructor name.
Definition: SemaDeclCXX.cpp:11827
clang::TemplateDeclInstantiator::VisitFunctionDecl
Decl * VisitFunctionDecl(FunctionDecl *D, TemplateParameterList *TemplateParams, RewriteKind RK=RewriteKind::None)
Normal class members are of more specific types and therefore don&#39;t make it here. ...
Definition: SemaTemplateInstantiateDecl.cpp:1796
clang::ClassTemplateSpecializationDecl::getSpecializedTemplate
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
Definition: DeclTemplate.cpp:925
clang::Decl::isLocalExternDecl
bool isLocalExternDecl()
Determine whether this is a block-scope declaration with linkage.
Definition: DeclBase.h:1060
clang::DeclContext::isFileContext
bool isFileContext() const
Definition: DeclBase.h:1854
clang::DeclaratorDecl::getTemplateParameterList
TemplateParameterList * getTemplateParameterList(unsigned index) const
Definition: Decl.h:763
clang::Sema::SubstParmVarDecl
ParmVarDecl * SubstParmVarDecl(ParmVarDecl *D, const MultiLevelTemplateArgumentList &TemplateArgs, int indexAdjustment, Optional< unsigned > NumExpansions, bool ExpectParameterPack)
Definition: SemaTemplateInstantiate.cpp:2108
clang::Decl::getDeclContext
DeclContext * getDeclContext()
Definition: DeclBase.h:438
clang::CXXRecordDecl::getDefinition
CXXRecordDecl * getDefinition() const
Definition: DeclCXX.h:533
clang::ConstraintSatisfaction::IsSatisfied
bool IsSatisfied
Definition: ASTConcept.h:47
clang::ASTContext::getInstantiatedFromUsingShadowDecl
UsingShadowDecl * getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst)
Definition: ASTContext.cpp:1599
clang::PackExpansionTypeLoc::getEllipsisLoc
SourceLocation getEllipsisLoc() const
Definition: TypeLoc.h:2329
clang::ASTMutationListener
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
Definition: ASTMutationListener.h:46
clang::FunctionDecl::getStorageClass
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:2488
clang::TemplateArgumentList::asArray
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Definition: DeclTemplate.h:293
clang::NonTypeTemplateParmDecl
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
Definition: DeclTemplate.h:1383
DeclVisitor.h
clang::TemplateName
Represents a C++ template name within the type system.
Definition: TemplateName.h:191
clang::DecltypeType
Represents the type decltype(expr) (C++11).
Definition: Type.h:4370
clang::ExplicitSpecifier::getExpr
const Expr * getExpr() const
Definition: DeclCXX.h:1796
clang::EnumDecl::getDefinition
EnumDecl * getDefinition() const
Definition: Decl.h:3582
InstantiateDefaultCtorDefaultArgs
static void InstantiateDefaultCtorDefaultArgs(Sema &S, CXXConstructorDecl *Ctor)
In the MS ABI, we need to instantiate default arguments of dllexported default constructors along wit...
Definition: SemaTemplateInstantiateDecl.cpp:4433
clang::FunctionDecl::DefaultedFunctionInfo::Create
static DefaultedFunctionInfo * Create(ASTContext &Context, ArrayRef< DeclAccessPair > Lookups)
Definition: Decl.cpp:2834
TypeLoc.h
Defines the clang::TypeLoc interface and its subclasses.
clang::FunctionDecl::getDependentSpecializationInfo
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition: Decl.cpp:3725
clang::Sema::ExpressionEvaluationContext::Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7)...
clang::Sema::DiscardCleanupsInEvaluationContext
void DiscardCleanupsInEvaluationContext()
Definition: SemaExpr.cpp:15346
clang::VarDecl::getTemplateInstantiationPattern
VarDecl * getTemplateInstantiationPattern() const
Retrieve the variable declaration from which this variable could be instantiated, if it is an instant...
Definition: Decl.cpp:2484
clang::Type::getContainedAutoType
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type...
Definition: Type.h:2251
clang::VarDecl::setConstexpr
void setConstexpr(bool IC)
Definition: Decl.h:1415
clang::Sema::CheckFieldDecl
FieldDecl * CheckFieldDecl(DeclarationName Name, QualType T, TypeSourceInfo *TInfo, RecordDecl *Record, SourceLocation Loc, bool Mutable, Expr *BitfieldWidth, InClassInitStyle InitStyle, SourceLocation TSSL, AccessSpecifier AS, NamedDecl *PrevDecl, Declarator *D=nullptr)
Build a new FieldDecl and check its well-formedness.
Definition: SemaDecl.cpp:16126
clang::VarTemplatePartialSpecializationDecl::getTemplateArgsAsWritten
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Get the template arguments as written.
Definition: DeclTemplate.h:2973
clang::prec::Spaceship
Definition: OperatorPrecedence.h:38
clang::DeclContext::isFunctionOrMethod
bool isFunctionOrMethod() const
Definition: DeclBase.h:1836
clang::Sema::CheckEnumRedeclaration
bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped, QualType EnumUnderlyingTy, bool IsFixed, const EnumDecl *Prev)
Check whether this is a valid redeclaration of a previous enumeration.
Definition: SemaDecl.cpp:14570
clang::StorageClass
StorageClass
Storage classes.
Definition: Specifiers.h:235
clang::MSPropertyDecl::getSetterId
IdentifierInfo * getSetterId() const
Definition: DeclCXX.h:3964
clang::DeclarationNameTable::getCXXOperatorName
DeclarationName getCXXOperatorName(OverloadedOperatorKind Op)
Get the name of the overloadable C++ operator corresponding to Op.
Definition: DeclarationName.h:639
clang::TypeAliasTemplateDecl
Declaration of an alias template.
Definition: DeclTemplate.h:2511
clang::ClassTemplateDecl::getPartialSpecializations
llvm::FoldingSetVector< ClassTemplatePartialSpecializationDecl > & getPartialSpecializations()
Retrieve the set of partial specializations of this class template.
Definition: DeclTemplate.cpp:443
clang::DeclContext::getParent
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1784
clang::MultiLevelTemplateArgumentList
Data structure that captures multiple levels of template argument lists for use in template instantia...
Definition: Template.h:64
clang::Sema::SetDeclDeleted
void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc)
Definition: SemaDeclCXX.cpp:16285
clang::VarTemplateSpecializationDecl::setTypeAsWritten
void setTypeAsWritten(TypeSourceInfo *T)
Sets the type of this specialization as it was written by the user.
Definition: DeclTemplate.h:2860
clang::ASTContext::getRecordType
QualType getRecordType(const RecordDecl *Decl) const
Definition: ASTContext.cpp:4173
clang::ActionResult::isInvalid
bool isInvalid() const
Definition: Ownership.h:166
clang::SourceRange::getEnd
SourceLocation getEnd() const
Definition: SourceLocation.h:217
clang::TemplateTemplateParmDecl::getNumExpansionTemplateParameters
unsigned getNumExpansionTemplateParameters() const
Retrieves the number of expansion template parameters in an expanded parameter pack.
Definition: DeclTemplate.h:1702
clang::OMPAllocateDecl::clauselists
clauselist_range clauselists()
Definition: DeclOpenMP.h:502
clang::ASTContext::getFunctionType
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
Definition: ASTContext.h:1401
clang::Decl::setLocation
void setLocation(SourceLocation L)
Definition: DeclBase.h:430
clang::TemplateTemplateParmDecl
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
Definition: DeclTemplate.h:1600
clang::ASTContext::addDeclaratorForUnnamedTagDecl
void addDeclaratorForUnnamedTagDecl(TagDecl *TD, DeclaratorDecl *DD)
Definition: ASTContext.cpp:10474
clang::ClassTemplatePartialSpecializationDecl::getInstantiatedFromMember
ClassTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member class template partial specialization from which this particular class template p...
Definition: DeclTemplate.h:2166
clang::DeclContext::isDependentContext
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1091
clang::OMPDeclareReductionDecl::getInitPriv
Expr * getInitPriv()
Get Priv variable of the initializer.
Definition: DeclOpenMP.h:180
ASTConsumer.h
clang::ASTContext::getInstantiatedFromUsingDecl
NamedDecl * getInstantiatedFromUsingDecl(NamedDecl *Inst)
If the given using decl Inst is an instantiation of a (possibly unresolved) using decl from a templat...
Definition: ASTContext.cpp:1576
clang::CXXDeductionGuideDecl
Represents a C++ deduction guide declaration.
Definition: DeclCXX.h:1842
clang::CXXRecordDecl::setDescribedClassTemplate
void setDescribedClassTemplate(ClassTemplateDecl *Template)
Definition: DeclCXX.cpp:1696
clang::ActionResult::isUsable
bool isUsable() const
Definition: Ownership.h:167
clang::CXXConversionDecl
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2713
clang::ASTContext::getTypeDeclType
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Definition: ASTContext.h:1417
clang::ObjCSubstitutionContext::Result
The result type of a method or function.
clang::TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
Definition: Specifiers.h:181
clang::QualType::isNull
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:719
clang::VarDecl::getInitStyle
InitializationStyle getInitStyle() const
The style of initialization for this declaration.
Definition: Decl.h:1309
getIdentifier
static StringRef getIdentifier(const Token &Tok)
Definition: ParsePragma.cpp:1161
instantiateOMPDeclareSimdDeclAttr
static void instantiateOMPDeclareSimdDeclAttr(Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const OMPDeclareSimdDeclAttr &Attr, Decl *New)
Instantiation of &#39;declare simd&#39; attribute and its arguments.
Definition: SemaTemplateInstantiateDecl.cpp:269
instantiateDependentModeAttr
static void instantiateDependentModeAttr(Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const ModeAttr &Attr, Decl *New)
Definition: SemaTemplateInstantiateDecl.cpp:261
clang::StaticAssertDecl::getAssertExpr
Expr * getAssertExpr()
Definition: DeclCXX.h:3786
clang::Sema::FindInstantiatedContext
DeclContext * FindInstantiatedContext(SourceLocation Loc, DeclContext *DC, const MultiLevelTemplateArgumentList &TemplateArgs)
Finds the instantiation of the given declaration context within the current instantiation.
Definition: SemaTemplateInstantiateDecl.cpp:5553
clang::TemplateDeclInstantiator::SubstFunctionType
TypeSourceInfo * SubstFunctionType(FunctionDecl *D, SmallVectorImpl< ParmVarDecl *> &Params)
Definition: SemaTemplateInstantiateDecl.cpp:4026
clang::TypeLoc::getAsAdjusted
T getAsAdjusted() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition: TypeLoc.h:2435
clang::VarDecl::getCanonicalDecl
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:2088
clang::Sema::FindInstantiatedDecl
NamedDecl * FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, const MultiLevelTemplateArgumentList &TemplateArgs, bool FindingInstantiatedContext=false)
Find the instantiation of the given declaration within the current instantiation. ...
Definition: SemaTemplateInstantiateDecl.cpp:5587
clang::VarDecl::isDirectInit
bool isDirectInit() const
Whether the initializer is a direct-initializer (list or call).
Definition: Decl.h:1314
clang::TemplateParameterList::Create
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl *> Params, SourceLocation RAngleLoc, Expr *RequiresClause)
Definition: DeclTemplate.cpp:90
clang::PrettyDeclStackTraceEntry
PrettyDeclStackTraceEntry - If a crash occurs in the parser while parsing something related to a decl...
Definition: PrettyDeclStackTrace.h:30
clang::TemplateTemplateParmDecl::defaultArgumentWasInherited
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template...
Definition: DeclTemplate.h:1731
clang::Decl::getFriendObjectKind
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so...
Definition: DeclBase.h:1111
clang::Redeclarable::getFirstDecl
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Definition: Redeclarable.h:215
clang::CXXRecordDecl::Create
static CXXRecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, CXXRecordDecl *PrevDecl=nullptr, bool DelayTypeCreation=false)
Definition: DeclCXX.cpp:126
clang::sema::instantiateTemplateAttribute
Attr * instantiateTemplateAttribute(const Attr *At, ASTContext &C, Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs)
clang::ClassTemplateDecl::getInstantiatedFromMemberTemplate
ClassTemplateDecl * getInstantiatedFromMemberTemplate() const
Definition: DeclTemplate.h:2344
clang::Sema::AddAlignedAttr
void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, bool IsPackExpansion)
AddAlignedAttr - Adds an aligned attribute to a particular declaration.
clang::EnumDecl::getInstantiatedFromMemberEnum
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition: Decl.cpp:4338
clang::RecordType::getDecl
RecordDecl * getDecl() const
Definition: Type.h:4505
clang::NonTypeTemplateParmDecl::getExpansionTypeSourceInfo
TypeSourceInfo * getExpansionTypeSourceInfo(unsigned I) const
Retrieve a particular expansion type source info within an expanded parameter pack.
Definition: DeclTemplate.h:1552
clang::Sema::CheckForFunctionRedefinition
void CheckForFunctionRedefinition(FunctionDecl *FD, const FunctionDecl *EffectiveDefinition=nullptr, SkipBodyInfo *SkipBody=nullptr)
Definition: SemaDecl.cpp:13485
clang::RecordDecl::isInjectedClassName
bool isInjectedClassName() const
Determines whether this declaration represents the injected class name.
Definition: Decl.cpp:4406
clang::DeclaratorDecl::getTrailingRequiresClause
Expr * getTrailingRequiresClause()
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Definition: Decl.h:747
clang::Sema::RetainOwnershipKind::OS
clang::Sema::RetainOwnershipKind::NS
clang::DeclContext::makeDeclVisibleInContext
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
Definition: DeclBase.cpp:1802
clang::TypeLoc::getContainedAutoTypeLoc
AutoTypeLoc getContainedAutoTypeLoc() const
Get the typeloc of an AutoType whose type will be deduced for a variable with an initializer of this ...
Definition: TypeLoc.cpp:681
clang::PackExpansionTypeLoc::getPatternLoc
TypeLoc getPatternLoc() const
Definition: TypeLoc.h:2345
clang::Sema::CheckTemplateParameterList
bool CheckTemplateParameterList(TemplateParameterList *NewParams, TemplateParameterList *OldParams, TemplateParamListContext TPC, SkipBodyInfo *SkipBody=nullptr)
Checks the validity of a template parameter list, possibly considering the template parameter list fr...
Definition: SemaTemplate.cpp:2429
clang::ActionResult
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Definition: Ownership.h:153
clang::FunctionProtoType::ExceptionSpecInfo::Type
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:3813
clang::TypeLoc::IgnoreParens
TypeLoc IgnoreParens() const
Definition: TypeLoc.h:1151
clang::Redeclarable::getPreviousDecl
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
Definition: Redeclarable.h:203
clang::Sema::InstantiatingTemplate
A stack object to be created when performing template instantiation.
Definition: Sema.h:8243
clang::FunctionProtoType::getExtProtoInfo
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:3975
clang::sema::instantiateTemplateAttributeForDecl
Attr * instantiateTemplateAttributeForDecl(const Attr *At, ASTContext &C, Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs)
clang::ClassTemplateSpecializationDecl::Create
static ClassTemplateSpecializationDecl * Create(ASTContext &Context, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, ClassTemplateDecl *SpecializedTemplate, ArrayRef< TemplateArgument > Args, ClassTemplateSpecializationDecl *PrevDecl)
Definition: DeclTemplate.cpp:884
clang::Sema::Subst
bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, TemplateArgumentListInfo &Result, const MultiLevelTemplateArgumentList &TemplateArgs)
Definition: SemaTemplateInstantiate.cpp:3282
clang::ClassTemplateDecl::findPartialSpecInstantiatedFromMember
ClassTemplatePartialSpecializationDecl * findPartialSpecInstantiatedFromMember(ClassTemplatePartialSpecializationDecl *D)
Find a class template partial specialization which was instantiated from the given member partial spe...
Definition: DeclTemplate.cpp:553
clang::Sema::AddLaunchBoundsAttr
void AddLaunchBoundsAttr(Decl *D, const AttributeCommonInfo &CI, Expr *MaxThreads, Expr *MinBlocks)
AddLaunchBoundsAttr - Adds a launch_bounds attribute to a particular declaration. ...
clang::Sema::getASTContext
ASTContext & getASTContext() const
Definition: Sema.h:1331
clang::FriendDecl::Create
static FriendDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, FriendUnion Friend_, SourceLocation FriendL, ArrayRef< TemplateParameterList *> FriendTypeTPLists=None)
Definition: DeclFriend.cpp:34
clang::Redeclarable::redecls
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: Redeclarable.h:294
clang::TemplateTypeParmDecl::hasTypeConstraint
bool hasTypeConstraint() const
Determine whether this template parameter has a type-constraint.
Definition: DeclTemplate.h:1357
clang::TemplateTypeParmDecl::isParameterPack
bool isParameterPack() const
Returns whether this is a parameter pack.
Definition: DeclTemplate.cpp:650
clang::FunctionTemplateDecl::getTemplatedDecl
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Definition: DeclTemplate.h:1032
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::FunctionType::getReturnType
QualType getReturnType() const
Definition: Type.h:3680
clang::DeclarationName::CXXConstructorName
Definition: DeclarationName.h:206
clang::FunctionDecl::isPure
bool isPure() const
Whether this virtual function is pure, i.e.
Definition: Decl.h:2105
clang::atTemplateBegin
void atTemplateBegin(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema, const Sema::CodeSynthesisContext &Inst)
Definition: TemplateInstCallback.h:61
clang::Sema::CheckPureMethod
bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange)
Mark the given method pure.
Definition: SemaDeclCXX.cpp:16615
clang::OMPDeclareReductionDecl
This represents &#39;#pragma omp declare reduction ...&#39; directive.
Definition: DeclOpenMP.h:102
clang::DeclContext::decls_begin
decl_iterator decls_begin() const
Definition: DeclBase.cpp:1388
clang::OMPCapturedExprDecl
Pseudo declaration for capturing expressions.
Definition: DeclOpenMP.h:312
isInstantiationOfUnresolvedUsingDecl
static bool isInstantiationOfUnresolvedUsingDecl(T *Pattern, Decl *Other, ASTContext &Ctx)
Definition: SemaTemplateInstantiateDecl.cpp:5442
clang::Sema::BuildStaticAssertDeclaration
Decl * BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc, Expr *AssertExpr, StringLiteral *AssertMessageExpr, SourceLocation RParenLoc, bool Failed)
Definition: SemaDeclCXX.cpp:15592
clang::Type::isVariablyModifiedType
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
Definition: Type.h:2166
clang::Attr::clone
Attr * clone(ASTContext &C) const
instantiateExplicitSpecifier
static ExplicitSpecifier instantiateExplicitSpecifier(Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, ExplicitSpecifier ES, FunctionDecl *New)
Definition: SemaTemplateInstantiateDecl.cpp:463
clang::UsingDirectiveDecl::getNamespaceKeyLocation
SourceLocation getNamespaceKeyLocation() const
Returns the location of the namespace keyword.
Definition: DeclCXX.h:2938
clang::Sema::ActOnOpenMPAllocateDirective
DeclGroupPtrTy ActOnOpenMPAllocateDirective(SourceLocation Loc, ArrayRef< Expr *> VarList, ArrayRef< OMPClause *> Clauses, DeclContext *Owner=nullptr)
Called on well-formed &#39;#pragma omp allocate&#39;.
Definition: SemaOpenMP.cpp:2711
clang::ASTContext::getManglingNumber
unsigned getManglingNumber(const NamedDecl *ND) const
Definition: ASTContext.cpp:10412
clang::Sema::ActOnOpenMPAllocatorClause
OMPClause * ActOnOpenMPAllocatorClause(Expr *Allocator, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed &#39;allocator&#39; clause.
Definition: SemaOpenMP.cpp:11786
clang::ClassTemplateSpecializationDecl::setExternLoc
void setExternLoc(SourceLocation Loc)
Sets the location of the extern keyword.
Definition: DeclTemplate.h:2026
clang::DeclarationNameInfo::getName
DeclarationName getName() const
getName - Returns the embedded declaration name.
Definition: DeclarationName.h:713
clang::TemplateTypeParmDecl::wasDeclaredWithTypename
bool wasDeclaredWithTypename() const
Whether this template type parameter was declared with the &#39;typename&#39; keyword.
Definition: DeclTemplate.h:1240
clang::TagDecl
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3219
clang::UsingDecl::getUsingLoc
SourceLocation getUsingLoc() const
Return the source location of the &#39;using&#39; keyword.
Definition: DeclCXX.h:3402
clang::Sema::CheckFunctionTemplateSpecialization
bool CheckFunctionTemplateSpecialization(FunctionDecl *FD, TemplateArgumentListInfo *ExplicitTemplateArgs, LookupResult &Previous, bool QualifiedFriend=false)
Perform semantic analysis for the given function template specialization.
Definition: SemaTemplate.cpp:8664
clang::TemplateDeclInstantiator::SubstTemplateParams
TemplateParameterList * SubstTemplateParams(TemplateParameterList *List)
Instantiates a nested template parameter list in the current instantiation context.
Definition: SemaTemplateInstantiateDecl.cpp:3714
clang::Decl::setReferenced
void setReferenced(bool R=true)
Definition: DeclBase.h:588
clang::LabelDecl
Represents the declaration of a label.
Definition: Decl.h:451
clang::UnresolvedUsingValueDecl
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3588
clang::CXXDeductionGuideDecl::setIsCopyDeductionCandidate
void setIsCopyDeductionCandidate(bool isCDC=true)
Definition: DeclCXX.h:1883
TemplateInstCallback.h
clang::CXXMethodDecl
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1931
clang::AS_public
Definition: Specifiers.h:114
clang::ASTContext::getTypedefNameForUnnamedTagDecl
TypedefNameDecl * getTypedefNameForUnnamedTagDecl(const TagDecl *TD)
Definition: ASTContext.cpp:10470
Initialization.h
clang::FriendDecl::getFriendLoc
SourceLocation getFriendLoc() const
Retrieves the location of the &#39;friend&#39; keyword.
Definition: DeclFriend.h:143
isInstantiationOf
static bool isInstantiationOf(ClassTemplateDecl *Pattern, ClassTemplateDecl *Instance)
Definition: SemaTemplateInstantiateDecl.cpp:5348
clang::FunctionProtoType::hasExceptionSpec
bool hasExceptionSpec() const
Return whether this function has any kind of exception spec.
Definition: Type.h:3995
clang::EnumDecl::getCanonicalDecl
EnumDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.h:3560
clang::Sema::SetDeclDefaulted
void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc)
Definition: SemaDeclCXX.cpp:16352
clang::TemplateDeclInstantiator::VisitDecl
Decl * VisitDecl(Decl *D)
Definition: SemaTemplateInstantiateDecl.cpp:3623
clang::EST_Uninstantiated
not instantiated yet
Definition: ExceptionSpecificationType.h:31
clang::UsingDirectiveDecl::getIdentLocation
SourceLocation getIdentLocation() const
Returns the location of this using declaration&#39;s identifier.
Definition: DeclCXX.h:2941
clang::FunctionDecl::getParamDecl
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:2422
instantiateDependentAlignValueAttr
static void instantiateDependentAlignValueAttr(Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const AlignValueAttr *Aligned, Decl *New)
Definition: SemaTemplateInstantiateDecl.cpp:160
clang::Attr::getLocation
SourceLocation getLocation() const
Definition: Attr.h:92
clang::UsingDirectiveDecl::getQualifierLoc
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition: DeclCXX.h:2908
clang::OMPClause
This is a basic class for representing single OpenMP clause.
Definition: OpenMPClause.h:51
clang::ClassTemplateDecl::getInjectedClassNameSpecialization
QualType getInjectedClassNameSpecialization()
Retrieve the template specialization type of the injected-class-name for this class template...
Definition: DeclTemplate.cpp:565
clang::VarTemplateSpecializationDecl::getSpecializationKind
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
Definition: DeclTemplate.h:2757
clang::EnumDecl::isScoped
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:3675
clang::NamedDecl::setDeclName
void setDeclName(DeclarationName N)
Set the name of this declaration.
Definition: Decl.h:275
clang::Expr::isValueDependent
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
Definition: Expr.h:158
clang::VarTemplateSpecializationDecl::getTemplateArgsInfo
const TemplateArgumentListInfo & getTemplateArgsInfo() const
Definition: DeclTemplate.h:2751
clang::TemplateTemplateParmDecl::hasDefaultArgument
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
Definition: DeclTemplate.h:1718
llvm::SmallVector
Definition: LLVM.h:35
clang::FunctionTemplateDecl::getPreviousDecl
FunctionTemplateDecl * getPreviousDecl()
Retrieve the previous declaration of this function template, or nullptr if no such declaration exists...
Definition: DeclTemplate.h:1058
clang::TemplateParameterList::size
unsigned size() const
Definition: DeclTemplate.h:129
clang::interp::APInt
llvm::APInt APInt
Definition: Integral.h:27
clang::ClassTemplateDecl::getMostRecentDecl
ClassTemplateDecl * getMostRecentDecl()
Definition: DeclTemplate.h:2336
clang::TemplateDeclInstantiator::InstantiateEnumDefinition
void InstantiateEnumDefinition(EnumDecl *Enum, EnumDecl *Pattern)
Definition: SemaTemplateInstantiateDecl.cpp:1271
clang::Decl::isFromASTFile
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
Definition: DeclBase.h:702
clang::FunctionProtoTypeLoc
Definition: TypeLoc.h:1466
clang::OMPDeclareMapperDecl::setMapperVarRef
void setMapperVarRef(Expr *MapperVarRefE)
Set the variable declared in the mapper.
Definition: DeclOpenMP.h:285
clang::ExplicitSpecifier::Invalid
static ExplicitSpecifier Invalid()
Definition: DeclCXX.h:1827
clang::DiagnosticsEngine::getCustomDiagID
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
Definition: Diagnostic.h:782
clang::Sema::CES_Strict
Definition: Sema.h:4247
clang::Decl::isUsed
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required...
Definition: DeclBase.cpp:398
clang::TSK_ExplicitInstantiationDefinition
This template specialization was instantiated from a template due to an explicit instantiation defini...
Definition: Specifiers.h:193
clang::TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared, defined, or instantiated.
Definition: Specifiers.h:178
clang::FunctionTemplateDecl::getInstantiatedFromMemberTemplate
FunctionTemplateDecl * getInstantiatedFromMemberTemplate() const
Definition: DeclTemplate.h:1076
clang::Sema::CheckUsingDeclRedeclaration
bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc, bool HasTypenameKeyword, const CXXScopeSpec &SS, SourceLocation NameLoc, const LookupResult &Previous)
Checks that the given using declaration is not an invalid redeclaration.
Definition: SemaDeclCXX.cpp:11857
clang::ExplicitSpecifier::getFromDecl
static ExplicitSpecifier getFromDecl(FunctionDecl *Function)
Definition: DeclCXX.cpp:1943
clang::TemplateSpecializationTypeLoc::getRAngleLoc
SourceLocation getRAngleLoc() const
Definition: TypeLoc.h:1596
clang::ClassTemplateSpecializationDecl::getTypeAsWritten
TypeSourceInfo * getTypeAsWritten() const
Gets the type of this specialization as it was written by the user, if it was so written.
Definition: DeclTemplate.h:2016
clang::FunctionDecl::isExplicitlyDefaulted
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted per C++0x.
Definition: Decl.h:2135
clang::FunctionDecl::getNameInfo
DeclarationNameInfo getNameInfo() const
Definition: Decl.h:1977
clang::StaticAssertDecl
Represents a C++11 static_assert declaration.
Definition: DeclCXX.h:3763
clang::VarTemplatePartialSpecializationDecl::setInstantiatedFromMember
void setInstantiatedFromMember(VarTemplatePartialSpecializationDecl *PartialSpec)
Definition: DeclTemplate.h:3018
clang::Sema::RequireCompleteDeclContext
bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC)
Require that the context specified by SS be complete.
Definition: SemaCXXScopeSpec.cpp:199
clang::PackExpansionType::getNumExpansions
Optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:5536
clang::LocalInstantiationScope::InstantiatedLocalPackArg
void InstantiatedLocalPackArg(const Decl *D, VarDecl *Inst)
Definition: SemaTemplateInstantiate.cpp:3379
clang::TemplateArgumentListInfo::setLAngleLoc
void setLAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:573
clang::AccessSpecDecl::getAccessSpecifierLoc
SourceLocation getAccessSpecifierLoc() const
The location of the access specifier.
Definition: DeclCXX.h:101
clang::VarTemplateSpecializationDecl::getTemplateInstantiationArgs
const TemplateArgumentList & getTemplateInstantiationArgs() const
Retrieve the set of template arguments that should be used to instantiate the initializer of the vari...
Definition: DeclTemplate.h:2829
clang::EST_DynamicNone
throw()
Definition: ExceptionSpecificationType.h:22
clang::LambdaCaptureInitKind::DirectInit
[a(b)]
clang::TemplateArgumentListInfo::addArgument
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:594
clang::Decl::isOutOfLine
virtual bool isOutOfLine() const
Determine whether this declaration is declared out of line (outside its semantic context).
Definition: Decl.cpp:99
clang::Type::isInstantiationDependentType
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
Definition: Type.h:2156
clang::Type::isTemplateTypeParmType
bool isTemplateTypeParmType() const
Definition: Type.h:6740
clang::FunctionProtoType::getExceptionSpecType
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition: Type.h:3989
clang::OMPDeclareReductionDecl::getInitOrig
Expr * getInitOrig()
Get Orig variable of the initializer.
Definition: DeclOpenMP.h:177
clang::VarTemplatePartialSpecializationDecl
Definition: DeclTemplate.h:2916
clang::FunctionDecl::setVirtualAsWritten
void setVirtualAsWritten(bool V)
State that this function is marked as virtual explicitly.
Definition: Decl.h:2101
clang::PackExpansionType
Represents a pack expansion of types.
Definition: Type.h:5511
clang::TypeAliasDecl::Create
static TypeAliasDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
Definition: Decl.cpp:4853
clang::DeclAccessPair
A POD class for pairing a NamedDecl* with an access specifier.
Definition: DeclAccessPair.h:29
clang::TagDecl::getQualifierLoc
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition: Decl.h:3446
clang::ASTTemplateArgumentListInfo::getTemplateArgs
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments.
Definition: TemplateBase.h:626
clang::DeclContext::ddiags
ddiag_range ddiags() const
Definition: DependentDiagnostic.h:175
clang::VarDecl::setTemplateSpecializationKind
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
For a static data member that was instantiated from a static data member of a class template...
Definition: Decl.cpp:2633
clang::TypedefNameDecl
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3071
clang::TemplateArgument
Represents a template argument.
Definition: TemplateBase.h:50
clang::ASTContext::getTemplateSpecializationType
QualType getTemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon=QualType()) const
Definition: ASTContext.cpp:4356
clang::Sema::collectUnexpandedParameterPacks
void collectUnexpandedParameterPacks(TemplateArgument Arg, SmallVectorImpl< UnexpandedParameterPack > &Unexpanded)
Collect the set of unexpanded parameter packs within the given template argument. ...
Definition: SemaTemplateVariadic.cpp:491
clang::ClassTemplateSpecializationDecl::getTemplateKeywordLoc
SourceLocation getTemplateKeywordLoc() const
Gets the location of the template keyword, if present.
Definition: DeclTemplate.h:2040
clang::ObjCSubstitutionContext::Property
The type of a property.
isInvalid
static bool isInvalid(LocType Loc, bool *Invalid)
Definition: SourceManager.cpp:1199
clang::UsingDirectiveDecl::getNominatedNamespace
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
Definition: DeclCXX.cpp:2729
clang::TemplateName::isNull
bool isNull() const
Determine whether this template name is NULL.
Definition: TemplateName.cpp:78
addInstantiatedParametersToScope
static bool addInstantiatedParametersToScope(Sema &S, FunctionDecl *Function, const FunctionDecl *PatternDecl, LocalInstantiationScope &Scope, const MultiLevelTemplateArgumentList &TemplateArgs)
Introduce the instantiated function parameters into the local instantiation scope, and set the parameter names to those used in the template.
Definition: SemaTemplateInstantiateDecl.cpp:4127
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
clang::Sema::ArgumentPackSubstitutionIndex
int ArgumentPackSubstitutionIndex
The current index into pack expansion arguments that will be used for substitution of parameter packs...
Definition: Sema.h:8200
clang::FunctionType::getExtInfo
ExtInfo getExtInfo() const
Definition: Type.h:3691
clang::ConceptDecl
Definition: DeclTemplate.h:3226
clang::Sema::BuildParmVarDeclForTypedef
ParmVarDecl * BuildParmVarDeclForTypedef(DeclContext *DC, SourceLocation Loc, QualType T)
Synthesizes a variable for a parameter arising from a typedef.
Definition: SemaDecl.cpp:13238
clang::TemplateArgumentLoc::getArgument
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:498
clang::EST_Unevaluated
not evaluated yet, for special member function
Definition: ExceptionSpecificationType.h:30
clang::NonTypeTemplateParmDecl::Create
static NonTypeTemplateParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, unsigned D, unsigned P, IdentifierInfo *Id, QualType T, bool ParameterPack, TypeSourceInfo *TInfo)
Definition: DeclTemplate.cpp:690
clang::FunctionDecl::isLateTemplateParsed
bool isLateTemplateParsed() const
Whether this templated function will be late parsed.
Definition: Decl.h:2109
clang::LocalInstantiationScope::cloneScopes
LocalInstantiationScope * cloneScopes(LocalInstantiationScope *Outermost)
Clone this scope, and all outer scopes, down to the given outermost scope.
Definition: Template.h:320
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1271
clang::Sema::InstantiateVariableInitializer
void InstantiateVariableInitializer(VarDecl *Var, VarDecl *OldVar, const MultiLevelTemplateArgumentList &TemplateArgs)
Instantiate the initializer of a variable.
Definition: SemaTemplateInstantiateDecl.cpp:4895
clang::TemplateDecl
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:402
clang::ClassTemplateDecl::Create
static ClassTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Create a class template node.
Definition: DeclTemplate.cpp:415
clang::interp::NE
bool NE(InterpState &S, CodePtr OpPC)
Definition: Interp.h:223
clang::DeclContext::isRecord
bool isRecord() const
Definition: DeclBase.h:1863
clang::Decl::attrs
attr_range attrs() const
Definition: DeclBase.h:501
clang::IndirectFieldDecl
Represents a field injected from an anonymous union/struct into the parent scope. ...
Definition: Decl.h:2980
clang::ClassTemplatePartialSpecializationDecl
Definition: DeclTemplate.h:2066
clang::TypedefNameDecl::getUnderlyingType
QualType getUnderlyingType() const
Definition: Decl.h:3126
clang::NamespaceAliasDecl::getQualifierLoc
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition: DeclCXX.h:3031
clang::ASTContext::UnsignedLongLongTy
CanQualType UnsignedLongLongTy
Definition: ASTContext.h:1027
clang::UsingDirectiveDecl::getCommonAncestor
DeclContext * getCommonAncestor()
Returns the common ancestor context of this using-directive and its nominated namespace.
Definition: DeclCXX.h:2930
clang::VarDecl::getInit
const Expr * getInit() const
Definition: Decl.h:1229
clang::Decl::getAccess
AccessSpecifier getAccess() const
Definition: DeclBase.h:473
findInstantiationOf
static NamedDecl * findInstantiationOf(ASTContext &Ctx, NamedDecl *D, ForwardIterator first, ForwardIterator last)
Definition: SemaTemplateInstantiateDecl.cpp:5538
clang::DecompositionDecl
A decomposition declaration.
Definition: DeclCXX.h:3869
clang::TSK_ExplicitInstantiationDeclaration
This template specialization was instantiated from a template due to an explicit instantiation declar...
Definition: Specifiers.h:189
clang::TemplateTypeParmDecl::getIndex
unsigned getIndex() const
Retrieve the index of the template parameter.
Definition: DeclTemplate.cpp:646
clang::UnresolvedUsingTypenameDecl
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3684
clang::FunctionDecl::getTemplateInstantiationPattern
FunctionDecl * getTemplateInstantiationPattern() const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
Definition: Decl.cpp:3612
clang::UsingDirectiveDecl::Create
static UsingDirectiveDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, SourceLocation NamespaceLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation IdentLoc, NamedDecl *Nominated, DeclContext *CommonAncestor)
Definition: DeclCXX.cpp:2708
clang::DeclarationName
The name of a declaration.
Definition: DeclarationName.h:145
clang::ParsedAttributesView
Definition: ParsedAttr.h:728
clang::DeclGroupRef
Definition: DeclGroup.h:51
clang::FunctionDecl::setInstantiationIsPending
void setInstantiationIsPending(bool IC)
State that the instantiation of this function is pending.
Definition: Decl.h:2228
clang::Sema::InstantiateClass
bool InstantiateClass(SourceLocation PointOfInstantiation, CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateSpecializationKind TSK, bool Complain=true)
Instantiate the definition of a class from a given pattern.
Definition: SemaTemplateInstantiate.cpp:2377
clang::CXXMethodDecl::getParent
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined...
Definition: DeclCXX.h:2046
clang::Decl::getKind
Kind getKind() const
Definition: DeclBase.h:432
clang::CXXRecordDecl::getInstantiatedFromMemberClass
CXXRecordDecl * getInstantiatedFromMemberClass() const
If this record is an instantiation of a member class, retrieves the member class from which it was in...
Definition: DeclCXX.cpp:1671
clang::Sema::InstantiatingTemplate::ExceptionSpecification
Definition: Sema.h:8251
clang::DeclaratorDecl::getNumTemplateParameterLists
unsigned getNumTemplateParameterLists() const
Definition: Decl.h:759
clang::EnumDecl
Represents an enum.
Definition: Decl.h:3481
clang::ASTTemplateArgumentListInfo::LAngleLoc
SourceLocation LAngleLoc
The source location of the left angle bracket (&#39;<&#39;).
Definition: TemplateBase.h:614
clang::VarDecl::setInlineSpecified
void setInlineSpecified()
Definition: Decl.h:1401
clang::VarDecl::isParameterPack
bool isParameterPack() const
Determine whether this variable is actually a function parameter pack or init-capture pack...
Definition: Decl.cpp:2464
clang::TemplateSpecializationKind
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:175
clang::NonTypeTemplateParmDecl::getDefaultArgument
Expr * getDefaultArgument() const
Retrieve the default argument, if any.
Definition: DeclTemplate.h:1465
clang::Sema::ActOnOpenMPDeclareReductionDirectiveEnd
DeclGroupPtrTy ActOnOpenMPDeclareReductionDirectiveEnd(Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid)
Called at the end of &#39;#pragma omp declare reduction&#39;.
Definition: SemaOpenMP.cpp:16401
clang::VarDecl::isInitCapture
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Definition: Decl.h:1421
clang::TemplateTypeParmDecl::defaultArgumentWasInherited
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template...
Definition: DeclTemplate.h:1265
clang::DeclarationNameInfo
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
Definition: DeclarationName.h:690
clang::VarDecl::setPreviousDeclInSameBlockScope
void setPreviousDeclInSameBlockScope(bool Same)
Definition: Decl.h:1440
clang::FunctionDecl::isTemplateInstantiation
bool isTemplateInstantiation() const
Determines if the given function was instantiated from a function template.
Definition: Decl.cpp:3606
clang::EnumDecl::Create
static EnumDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl, bool IsScoped, bool IsScopedUsingClassTag, bool IsFixed)
Definition: Decl.cpp:4252
clang::VarTemplateDecl::findSpecialization
VarTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
Definition: DeclTemplate.cpp:1158
clang::Sema::CompleteMemberSpecialization
void CompleteMemberSpecialization(NamedDecl *Member, LookupResult &Previous)
Definition: SemaTemplate.cpp:9078
clang::Type::isUndeducedType
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 &#39;auto&#39; typ...
Definition: Type.h:6900
clang::LabelDecl::Create
static LabelDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II)
Definition: Decl.cpp:4649
clang::Decl::setObjectOfFriendDecl
void setObjectOfFriendDecl(bool PerformFriendInjection=false)
Changes the namespace of this declaration to reflect that it&#39;s the object of a friend declaration...
Definition: DeclBase.h:1071
clang::VarDecl::setInitCapture
void setInitCapture(bool IC)
Definition: Decl.h:1424
clang::AutoTypeLoc
Definition: TypeLoc.h:1942
clang::Decl::setLocalExternDecl
void setLocalExternDecl()
Changes the namespace of this declaration to reflect that it&#39;s a function-local extern declaration...
Definition: DeclBase.h:1042
clang::TypeLoc::getSourceRange
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
Definition: TypeLoc.h:152
clang::VarDecl::setImplicitlyInline
void setImplicitlyInline()
Definition: Decl.h:1406
clang::FunctionProtoType::ExceptionSpecInfo::SourceTemplate
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition: Type.h:3827
clang::RecordType
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4495
clang::TemplateArgumentLoc
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:449
clang::Decl::setIsUsed
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
Definition: DeclBase.h:573
clang::declvisitor::Base< std::add_pointer, TemplateDeclInstantiator, Decl * >::Visit
Decl * Visit(PTR(Decl) D)
Definition: DeclVisitor.h:37
clang::TagDecl::setQualifierInfo
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:4200
clang::Sema::AttachTypeConstraint
bool AttachTypeConstraint(NestedNameSpecifierLoc NS, DeclarationNameInfo NameInfo, ConceptDecl *NamedConcept, const TemplateArgumentListInfo *TemplateArgs, TemplateTypeParmDecl *ConstrainedParameter, SourceLocation EllipsisLoc)
Attach a type-constraint to a template parameter.
Definition: SemaTemplate.cpp:1139
clang::RedeclarableTemplateDecl::setInstantiatedFromMemberTemplate
void setInstantiatedFromMemberTemplate(RedeclarableTemplateDecl *TD)
Definition: DeclTemplate.h:939
clang::DiagnosticsEngine::Error
Definition: Diagnostic.h:157
clang::Sema::ContextRAII::pop
void pop()
Definition: Sema.h:816
clang::Sema::GlobalEagerInstantiationScope
Definition: Sema.h:8547
clang::VarDecl::getTemplateSpecializationKindForInstantiation
TemplateSpecializationKind getTemplateSpecializationKindForInstantiation() const
Get the template specialization kind of this variable for the purposes of template instantiation...
Definition: Decl.cpp:2560
clang::TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp...
Definition: Specifiers.h:185
clang::Sema::CheckConstraintExpression
bool CheckConstraintExpression(Expr *CE, Token NextToken=Token(), bool *PossibleNonPrimary=nullptr, bool IsTrailingRequiresClause=false)
Check whether the given expression is a valid constraint expression.
Definition: SemaConcept.cpp:32
clang::Expr::isConstantInitializer
bool isConstantInitializer(ASTContext &Ctx, bool ForRef, const Expr **Culprit=nullptr) const
isConstantInitializer - Returns true if this expression can be emitted to IR as a constant...
Definition: Expr.cpp:3184
clang::Decl::setNonMemberOperator
void setNonMemberOperator()
Specifies that this declaration is a C++ overloaded non-member.
Definition: DeclBase.h:1120
clang::VarTemplatePartialSpecializationDecl::Create
static VarTemplatePartialSpecializationDecl * Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, TemplateParameterList *Params, VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, StorageClass S, ArrayRef< TemplateArgument > Args, const TemplateArgumentListInfo &ArgInfos)
Definition: DeclTemplate.cpp:1308
clang::DeclaratorDecl::setQualifierInfo
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:1829
clang::Decl::getAttr
T * getAttr() const
Definition: DeclBase.h:538
clang::Sema::ActOnEnumBody
void ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange, Decl *EnumDecl, ArrayRef< Decl *> Elements, Scope *S, const ParsedAttributesView &Attr)
Definition: SemaDecl.cpp:17497
clang::Sema::CheckEnumConstant
EnumConstantDecl * CheckEnumConstant(EnumDecl *Enum, EnumConstantDecl *LastEnumConst, SourceLocation IdLoc, IdentifierInfo *Id, Expr *val)
Definition: SemaDecl.cpp:17044
clang::VarDecl::isObjCForDecl
bool isObjCForDecl() const
Determine whether this variable is a for-loop declaration for a for-in statement in Objective-C...
Definition: Decl.h:1375
clang::Type::isFunctionType
bool isFunctionType() const
Definition: Type.h:6500
clang::Sema::GlobalEagerInstantiationScope::perform
void perform()
Definition: Sema.h:8557
clang::Sema::ActOnOpenMPDeclareReductionInitializerEnd
void ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, Expr *Initializer, VarDecl *OmpPrivParm)
Finish current declare reduction construct initializer.
Definition: SemaOpenMP.cpp:16380
clang::VarDecl::setInstantiationOfStaticDataMember
void setInstantiationOfStaticDataMember(VarDecl *VD, TemplateSpecializationKind TSK)
Specify that this variable is an instantiation of the static data member VD.
Definition: Decl.cpp:2661
SubstQualifier
static bool SubstQualifier(Sema &SemaRef, const DeclT *OldDecl, DeclT *NewDecl, const MultiLevelTemplateArgumentList &TemplateArgs)
Definition: SemaTemplateInstantiateDecl.cpp:42
clang::DeclaratorDecl::getTypeSourceInfo
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:700
clang::ASTContext::getDeclaratorForUnnamedTagDecl
DeclaratorDecl * getDeclaratorForUnnamedTagDecl(const TagDecl *TD)
Definition: ASTContext.cpp:10479
clang::ClassTemplateDecl::getCanonicalDecl
ClassTemplateDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this template.
Definition: DeclTemplate.h:2315
clang::ClassTemplateDecl::findPartialSpecialization
ClassTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, TemplateParameterList *TPL, void *&InsertPos)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
Definition: DeclTemplate.cpp:467
clang::Sema::ActOnOpenMPDeclareReductionType
QualType ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, TypeResult ParsedType)
Check if the specified type is allowed to be used in &#39;omp declare reduction&#39; construct.
Definition: SemaOpenMP.cpp:16158
clang::VarDecl::setCXXForRangeDecl
void setCXXForRangeDecl(bool FRD)
Definition: Decl.h:1368
clang::ExceptionSpecificationType
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
Definition: ExceptionSpecificationType.h:20
clang::CXXDestructorDecl::Create
static CXXDestructorDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, bool isInline, bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, Expr *TrailingRequiresClause=nullptr)
Definition: DeclCXX.cpp:2629
clang::DeclContext::addDecl
void addDecl(Decl *D)
Add the declaration D into this context.
Definition: DeclBase.cpp:1524
clang::CXXRecordDecl::setInstantiationOfMemberClass
void setInstantiationOfMemberClass(CXXRecordDecl *RD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member class RD.
Definition: DeclCXX.cpp:1683
clang::Sema::SubstExceptionSpec
void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, const MultiLevelTemplateArgumentList &Args)
Definition: SemaTemplateInstantiate.cpp:2094
clang::TemplateArgument::Pack
The template argument is actually a parameter pack.
Definition: TemplateBase.h:90
clang::FunctionDecl::getTemplateSpecializationKindForInstantiation
TemplateSpecializationKind getTemplateSpecializationKindForInstantiation() const
Determine the kind of template specialization this function represents for the purpose of template in...
Definition: Decl.cpp:3772
clang::CXXConversionDecl::Create
static CXXConversionDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, bool isInline, ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, Expr *TrailingRequiresClause=nullptr)
Definition: DeclCXX.cpp:2662
clang::TagType::isBeingDefined
bool isBeingDefined() const
Determines whether this type is in the process of being defined.
Definition: Type.cpp:3300
clang::TemplateTemplateParmDecl::getDefaultArgument
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
Definition: DeclTemplate.h:1721
clang::UsingDecl::hasTypename
bool hasTypename() const
Return true if the using declaration has &#39;typename&#39;.
Definition: DeclCXX.h:3424
clang::DeclaratorDecl::setInnerLocStart
void setInnerLocStart(SourceLocation L)
Definition: Decl.h:715
clang::BindingDecl::Create
static BindingDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id)
Definition: DeclCXX.cpp:3044
clang::FunctionDecl::isInlined
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
Definition: Decl.h:2513
clang::Sema::LookupQualifiedName
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
Definition: SemaLookup.cpp:2221
clang::Sema::forRedeclarationInCurContext
RedeclarationKind forRedeclarationInCurContext()
Definition: Sema.h:3495
clang::Sema::CheckTemplatePartialSpecialization
void CheckTemplatePartialSpecialization(ClassTemplatePartialSpecializationDecl *Partial)
Definition: SemaTemplate.cpp:4005
clang::ASTContext::getCanonicalType
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2305
clang::Sema::InstantiatingTemplate::isAlreadyInstantiating
bool isAlreadyInstantiating() const
Determine whether we are already instantiating this specialization in some surrounding active instant...
Definition: Sema.h:8386
clang::TemplateArgumentList
A template argument list.
Definition: DeclTemplate.h:239
clang::TypeSourceInfo::getTypeLoc
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:244
clang::Sema::RetainOwnershipKind::CF
clang::Sema::LocalEagerInstantiationScope
Definition: Sema.h:8594
clang::Sema::SubstExpr
ExprResult SubstExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs)
Definition: SemaTemplateInstantiate.cpp:3219
clang::UsingDecl::shadows
shadow_range shadows() const
Definition: DeclCXX.h:3469
clang::FunctionProtoType::getParamType
QualType getParamType(unsigned i) const
Definition: Type.h:3966
clang::VarDecl::CallInit
Call-style initialization (C++98)
Definition: Decl.h:828
clang::ObjCAtDefsFieldDecl
Represents a field declaration created by an @defs(...).
Definition: DeclObjC.h:2026
clang::Sema::CheckNonTypeTemplateParameterType
QualType CheckNonTypeTemplateParameterType(TypeSourceInfo *&TSI, SourceLocation Loc)
Check that the type of a non-type template parameter is well-formed.
Definition: SemaTemplate.cpp:1212
clang::Sema::CheckOverrideControl
void CheckOverrideControl(NamedDecl *D)
CheckOverrideControl - Check C++11 override control semantics.
Definition: SemaDeclCXX.cpp:2968
clang::TagDecl::getTypedefNameForAnonDecl
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3429
clang::Sema::CheckFunctionDeclaration
bool CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, LookupResult &Previous, bool IsMemberSpecialization)
Perform semantic checking of a new function declaration.
Definition: SemaDecl.cpp:10368
clang::FieldDecl::isMutable
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition: Decl.h:2804
clang::TagDecl::isThisDeclarationADefinition
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition: Decl.h:3319
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:253
clang::VarDecl::getInstantiatedFromStaticDataMember
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization, returns the templated static data member from which it was instantiated.
Definition: Decl.cpp:2542
clang::VarDecl::setTSCSpec
void setTSCSpec(ThreadStorageClassSpecifier TSC)
Definition: Decl.h:1034
clang::TemplateDecl::getAssociatedConstraints
void getAssociatedConstraints(llvm::SmallVectorImpl< const Expr *> &AC) const
Get the total constraint-expression associated with this template, including constraint-expressions d...
Definition: DeclTemplate.cpp:204
clang::VarDecl::isNRVOVariable
bool isNRVOVariable() const
Determine whether this local variable can be used with the named return value optimization (NRVO)...
Definition: Decl.h:1355
clang::VarDecl::setDescribedVarTemplate
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition: Decl.cpp:2585
clang::VarDecl::isOutOfLine
bool isOutOfLine() const override
Determine whether this is or was instantiated from an out-of-line definition of a static data member...
Definition: Decl.cpp:2267
clang::Sema::CompleteVarTemplateSpecializationDecl
VarTemplateSpecializationDecl * CompleteVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *VarSpec, VarDecl *PatternDecl, const MultiLevelTemplateArgumentList &TemplateArgs)
Instantiates a variable template specialization by completing it with appropriate type information an...
Definition: SemaTemplateInstantiateDecl.cpp:4736
clang::DeclContext::addHiddenDecl
void addHiddenDecl(Decl *D)
Add the declaration D to this context without modifying any lookup tables.
Definition: DeclBase.cpp:1498
clang::FunctionTypeLoc::setParam
void setParam(unsigned i, ParmVarDecl *VD)
Definition: TypeLoc.h:1433
clang::TypedefDecl::Create
static TypedefDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, TypeSourceInfo *TInfo)
Definition: Decl.cpp:4803
clang::MemberSpecializationInfo
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:622
clang::AttrSyntax::C
clang::Sema::CheckInstantiatedFunctionTemplateConstraints
bool CheckInstantiatedFunctionTemplateConstraints(SourceLocation PointOfInstantiation, FunctionDecl *Decl, ArrayRef< TemplateArgument > TemplateArgs, ConstraintSatisfaction &Satisfaction)
Definition: SemaTemplateInstantiateDecl.cpp:4229
clang::atTemplateEnd
void atTemplateEnd(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema, const Sema::CodeSynthesisContext &Inst)
Definition: TemplateInstCallback.h:71
clang::Sema::CurContext
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:397
clang::FriendDecl::setUnsupportedFriend
void setUnsupportedFriend(bool Unsupported)
Definition: DeclFriend.h:177
clang::StaticAssertDecl::isFailed
bool isFailed() const
Definition: DeclCXX.h:3792
clang::UsingDecl::Create
static UsingDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation UsingL, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword)
Definition: DeclCXX.cpp:2935
clang::VarTemplateDecl::Create
static VarTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, VarDecl *Decl)
Create a variable template node.
Definition: DeclTemplate.cpp:1120
clang::ClassTemplateDecl
Declaration of a class template.
Definition: DeclTemplate.h:2238
Expr.h
clang::Decl::addAttr
void addAttr(Attr *A)
Definition: DeclBase.cpp:832
clang::ClassScopeFunctionSpecializationDecl::getSpecialization
CXXMethodDecl * getSpecialization() const
Definition: DeclTemplate.h:2614
clang::Sema::getSourceManager
SourceManager & getSourceManager() const
Definition: Sema.h:1329
clang::PackExpansionTypeLoc
Definition: TypeLoc.h:2325
clang::OMPDeclareMapperDecl
This represents &#39;#pragma omp declare mapper ...&#39; directive.
Definition: DeclOpenMP.h:217
clang::DeclContextLookupResult::begin
iterator begin() const
Definition: DeclBase.h:1236
clang::ASTContext::getInjectedClassNameType
QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const
getInjectedClassNameType - Return the unique reference to the injected class name type for the specif...
Definition: ASTContext.cpp:4110
isInstantiationOfStaticDataMember
static bool isInstantiationOfStaticDataMember(VarDecl *Pattern, VarDecl *Instance)
Definition: SemaTemplateInstantiateDecl.cpp:5468
clang::TargetCXXABI::isMicrosoft
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
Definition: TargetCXXABI.h:160
clang::OMPAllocateDecl::varlists
varlist_range varlists()
Definition: DeclOpenMP.h:491
clang::FunctionDecl::getSourceRange
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: Decl.cpp:3868
clang::EnumDecl::getIntegerType
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition: Decl.h:3635
clang::FunctionDecl::setDescribedFunctionTemplate
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition: Decl.cpp:3565
clang::Sema::SubstDecl
Decl * SubstDecl(Decl *D, DeclContext *Owner, const MultiLevelTemplateArgumentList &TemplateArgs)
Definition: SemaTemplateInstantiateDecl.cpp:3627
clang::TemplateArgumentListInfo::getLAngleLoc
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:570
clang::Sema::CheckFriendTypeDecl
FriendDecl * CheckFriendTypeDecl(SourceLocation LocStart, SourceLocation FriendLoc, TypeSourceInfo *TSInfo)
Perform semantic analysis of the given friend type declaration.
Definition: SemaDeclCXX.cpp:15671
clang::OMPDeclareReductionDecl::getCombinerIn
Expr * getCombinerIn()
Get In variable of the combiner.
Definition: DeclOpenMP.h:155
clang::ASTContext::IntTy
CanQualType IntTy
Definition: ASTContext.h:1025
attrToRetainOwnershipKind
static Sema::RetainOwnershipKind attrToRetainOwnershipKind(const Attr *A)
Definition: SemaTemplateInstantiateDecl.cpp:529
clang::OpaquePtr< QualType >::make
static OpaquePtr make(QualType P)
Definition: Ownership.h:60
clang::Redeclarable::getMostRecentDecl
decl_type * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
Definition: Redeclarable.h:225
clang::TranslationUnitDecl
The top declaration context.
Definition: Decl.h:82
clang::Type::isDependentType
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2150
clang::TemplateDeclInstantiator::RewriteKind::None
clang::Sema::getNumArgumentsInExpansion
Optional< unsigned > getNumArgumentsInExpansion(QualType T, const MultiLevelTemplateArgumentList &TemplateArgs)
Determine the number of arguments in the given pack expansion type.
Definition: SemaTemplateVariadic.cpp:782
clang::FunctionDecl::isDeleted
bool isDeleted() const
Whether this function has been deleted.
Definition: Decl.h:2259
clang::Sema::inferGslPointerAttribute
void inferGslPointerAttribute(NamedDecl *ND, CXXRecordDecl *UnderlyingRecord)
Add gsl::Pointer attribute to std::container::iterator.
Definition: SemaAttr.cpp:98
clang::TemplateArgumentLoc::getTemplateNameLoc
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:538
clang::Sema::isCopyElisionCandidate
bool isCopyElisionCandidate(QualType ReturnType, const VarDecl *VD, CopyElisionSemanticsKind CESK)
Definition: SemaStmt.cpp:3004
clang::VarDecl::isThisDeclarationADefinition
DefinitionKind isThisDeclarationADefinition(ASTContext &) const
Check whether this declaration is a definition.
Definition: Decl.cpp:2091
clang::Sema::SubstType
TypeSourceInfo * SubstType(TypeSourceInfo *T, const MultiLevelTemplateArgumentList &TemplateArgs, SourceLocation Loc, DeclarationName Entity, bool AllowDeducedTST=false)
Perform substitution on the type T with a given set of template arguments.
Definition: SemaTemplateInstantiate.cpp:1949
clang::OMPVarListLocTy
This structure contains most locations needed for by an OMPVarListClause.
Definition: OpenMPClause.h:172
clang::OMPThreadPrivateDecl::varlists
varlist_range varlists()
Definition: DeclOpenMP.h:77
clang::VarDecl::isStaticDataMember
bool isStaticDataMember() const
Determines whether this is a static data member.
Definition: Decl.h:1144
clang::MSPropertyDecl
An instance of this class represents the declaration of a property member.
Definition: DeclCXX.h:3940
clang::ActionResult::getAs
T * getAs()
Definition: Ownership.h:171
clang::NamespaceAliasDecl::getNamespaceLoc
SourceLocation getNamespaceLoc() const
Returns the location of the namespace keyword.
Definition: DeclCXX.h:3056
clang::Expr::isPotentialConstantExprUnevaluated
static bool isPotentialConstantExprUnevaluated(Expr *E, const FunctionDecl *FD, SmallVectorImpl< PartialDiagnosticAt > &Diags)
isPotentialConstantExprUnevaluted - Return true if this expression might be usable in a constant expr...
Definition: ExprConstant.cpp:14674
clang::Sema::SubstTemplateParams
TemplateParameterList * SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner, const MultiLevelTemplateArgumentList &TemplateArgs)
Definition: SemaTemplateInstantiateDecl.cpp:3753
clang::ValueDecl::getType
QualType getType() const
Definition: Decl.h:630
clang::LookupResult::empty
bool empty() const
Return true if no decls were found.
Definition: Lookup.h:339
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:207
clang::VarTemplateSpecializationDecl::Create
static VarTemplateSpecializationDecl * Create(ASTContext &Context, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo, StorageClass S, ArrayRef< TemplateArgument > Args)
Definition: DeclTemplate.cpp:1242
clang::Decl::setLexicalDeclContext
void setLexicalDeclContext(DeclContext *DC)
Definition: DeclBase.cpp:299
clang::Sema::Context
ASTContext & Context
Definition: Sema.h:385
clang::FunctionDecl::getCanonicalDecl
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:3158
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:223
clang::TagType
Definition: Type.h:4471
clang::FunctionProtoType::getExceptionSpecTemplate
FunctionDecl * getExceptionSpecTemplate() const
If this function type has an uninstantiated exception specification, this is the function whose excep...
Definition: Type.h:4068
clang::TypeLoc::castAs
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type...
Definition: TypeLoc.h:77
clang::Decl::setAccess
void setAccess(AccessSpecifier AS)
Definition: DeclBase.h:468
clang::ASTContext::BoolTy
CanQualType BoolTy
Definition: ASTContext.h:1017
clang::Sema::tryResolveExplicitSpecifier
bool tryResolveExplicitSpecifier(ExplicitSpecifier &ExplicitSpec)
tryResolveExplicitSpecifier - Attempt to resolve the explict specifier.
Definition: SemaDeclCXX.cpp:12431
clang::NamespaceAliasDecl
Represents a C++ namespace alias.
Definition: DeclCXX.h:2967
clang::VarDecl::isInline
bool isInline() const
Whether this variable is (C++1z) inline.
Definition: Decl.h:1394
clang::TemplateArgument::getAsTemplate
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:280
clang::FriendTemplateDecl
Declaration of a friend template.
Definition: DeclTemplate.h:2435
clang::UsingPackDecl::expansions
ArrayRef< NamedDecl * > expansions() const
Get the set of using declarations that this pack expanded into.
Definition: DeclCXX.h:3555
clang::UsingDirectiveDecl
Represents C++ using-directive.
Definition: DeclCXX.h:2863
clang::PragmaDetectMismatchDecl
Represents a #pragma detect_mismatch line.
Definition: Decl.h:148
clang::ClassTemplateSpecializationDecl::setTypeAsWritten
void setTypeAsWritten(TypeSourceInfo *T)
Sets the type of this specialization as it was written by the user.
Definition: DeclTemplate.h:2008
clang::TemplateArgumentListInfo::getRAngleLoc
SourceLocation getRAngleLoc() const
Definition: TemplateBase.h:571
clang::ClassTemplateSpecializationDecl::getPointOfInstantiation
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
Definition: DeclTemplate.h:1931
clang::Attr::getKind
attr::Kind getKind() const
Definition: Attr.h:85
clang::DeclContextLookupResult::empty
bool empty() const
Definition: DeclBase.h:1239
clang::Sema::SubstParmTypes
bool SubstParmTypes(SourceLocation Loc, ArrayRef< ParmVarDecl *> Params, const FunctionProtoType::ExtParameterInfo *ExtParamInfos, const MultiLevelTemplateArgumentList &TemplateArgs, SmallVectorImpl< QualType > &ParamTypes, SmallVectorImpl< ParmVarDecl *> *OutParams, ExtParameterInfoBuilder &ParamInfos)
Substitute the given template arguments into the given set of parameters, producing the set of parame...
Definition: SemaTemplateInstantiate.cpp:2217
clang::OMPDeclareReductionDecl::getCombinerOut
Expr * getCombinerOut()
Get Out variable of the combiner.
Definition: DeclOpenMP.h:158
clang::FunctionDecl::getNumParams
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3242
clang::ValueDecl::setType
void setType(QualType newType)
Definition: Decl.h:631
clang::VarDecl::hasInit
bool hasInit() const
Definition: Decl.cpp:2226
instantiateDependentAMDGPUFlatWorkGroupSizeAttr
static void instantiateDependentAMDGPUFlatWorkGroupSizeAttr(Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const AMDGPUFlatWorkGroupSizeAttr &Attr, Decl *New)
Definition: SemaTemplateInstantiateDecl.cpp:442
clang::ClassTemplatePartialSpecializationDecl::getTemplateArgsAsWritten
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Get the template arguments as written.
Definition: DeclTemplate.h:2142
clang::TemplateParameterList::getSourceRange
SourceRange getSourceRange() const LLVM_READONLY
Definition: DeclTemplate.h:199
clang::DeclaratorDecl::getInnerLocStart
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition: Decl.h:714
clang::ExplicitSpecifier::isInvalid
bool isInvalid() const
Determine if the explicit specifier is invalid.
Definition: DeclCXX.h:1816
clang::TemplateDeclInstantiator::InitMethodInstantiation
bool InitMethodInstantiation(CXXMethodDecl *New, CXXMethodDecl *Tmpl)
Initializes common fields of an instantiated method declaration (New) from the corresponding fields o...
Definition: SemaTemplateInstantiateDecl.cpp:4361
clang::OMPThreadPrivateDecl
This represents &#39;#pragma omp threadprivate ...&#39; directive.
Definition: DeclOpenMP.h:39
clang::Sema::RetainOwnershipKind
RetainOwnershipKind
Definition: Sema.h:9497
clang::FriendDecl::isUnsupportedFriend
bool isUnsupportedFriend() const
Determines if this friend kind is unsupported.
Definition: DeclFriend.h:174
clang::FunctionProtoType::ExtProtoInfo::ExceptionSpec
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:3843
clang::FunctionTemplateDecl
Declaration of a template function.
Definition: DeclTemplate.h:977
clang::NamedDecl::hasLinkage
bool hasLinkage() const
Determine whether this declaration has linkage.
Definition: Decl.cpp:1772
clang::Attr
Attr - This represents one attribute.
Definition: Attr.h:45
clang::FunctionDecl::isDeletedAsWritten
bool isDeletedAsWritten() const
Definition: Decl.h:2263
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:429
clang::TemplateDeclInstantiator::VisitCXXMethodDecl
Decl * VisitCXXMethodDecl(CXXMethodDecl *D, TemplateParameterList *TemplateParams, Optional< const ASTTemplateArgumentListInfo *> ClassScopeSpecializationArgs=llvm::None, RewriteKind RK=RewriteKind::None)
Definition: SemaTemplateInstantiateDecl.cpp:2123
clang::UsingShadowDecl
Represents a shadow declaration introduced into a scope by a (resolved) using declaration.
Definition: DeclCXX.h:3162
clang::UsingPackDecl
Represents a pack of using declarations that a single using-declarator pack-expanded into...
Definition: DeclCXX.h:3519
clang::TypeSourceInfo::getType
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:6238
clang::Sema::BuildVariableInstantiation
void BuildVariableInstantiation(VarDecl *NewVar, VarDecl *OldVar, const MultiLevelTemplateArgumentList &TemplateArgs, LateInstantiatedAttrVec *LateAttrs, DeclContext *Owner, LocalInstantiationScope *StartingScope, bool InstantiatingVarTemplate=false, VarTemplateSpecializationDecl *PrevVTSD=nullptr)
BuildVariableInstantiation - Used after a new variable has been created.
Definition: SemaTemplateInstantiateDecl.cpp:4764
clang::VarTemplateDecl::getPartialSpecializations
llvm::FoldingSetVector< VarTemplatePartialSpecializationDecl > & getPartialSpecializations()
Retrieve the set of partial specializations of this class template.
Definition: DeclTemplate.cpp:1145
clang::DeclContext::decls_end
decl_iterator decls_end() const
Definition: DeclBase.h:2035
clang::FunctionDecl::getPointOfInstantiation
SourceLocation getPointOfInstantiation() const
Retrieve the (first) point of instantiation of a function template specialization or a member of a cl...
Definition: Decl.cpp:3833
clang::Sema::ActOnOpenMPMapClause
OMPClause * ActOnOpenMPMapClause(ArrayRef< OpenMPMapModifierKind > MapTypeModifiers, ArrayRef< SourceLocation > MapTypeModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef< Expr *> VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr *> UnresolvedMappers=llvm::None)
Called on well-formed &#39;map&#39; clause.
Definition: SemaOpenMP.cpp:16117
clang::Sema::ContextRAII
A RAII object to temporarily push a declaration context.
Definition: Sema.h:797
clang::Sema::DiagnoseUnusedNestedTypedefs
void DiagnoseUnusedNestedTypedefs(const RecordDecl *D)
Definition: SemaDecl.cpp:1843