clang 8.0.0

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