clang  16.0.0git
SemaTemplateInstantiate.cpp
Go to the documentation of this file.
1 //===------- SemaTemplateInstantiate.cpp - C++ Template Instantiation ------===/
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //===----------------------------------------------------------------------===/
7 //
8 // This file implements C++ template instantiation.
9 //
10 //===----------------------------------------------------------------------===/
11 
12 #include "TreeTransform.h"
13 #include "clang/AST/ASTConcept.h"
14 #include "clang/AST/ASTConsumer.h"
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/ASTLambda.h"
18 #include "clang/AST/DeclTemplate.h"
19 #include "clang/AST/Expr.h"
20 #include "clang/AST/ExprConcepts.h"
22 #include "clang/AST/TypeVisitor.h"
24 #include "clang/Basic/Stack.h"
25 #include "clang/Basic/TargetInfo.h"
26 #include "clang/Sema/DeclSpec.h"
28 #include "clang/Sema/Lookup.h"
29 #include "clang/Sema/SemaConcept.h"
31 #include "clang/Sema/Template.h"
34 #include "llvm/Support/TimeProfiler.h"
35 
36 using namespace clang;
37 using namespace sema;
38 
39 //===----------------------------------------------------------------------===/
40 // Template Instantiation Support
41 //===----------------------------------------------------------------------===/
42 
43 namespace {
45 struct Response {
46  const Decl *NextDecl = nullptr;
47  bool IsDone = false;
48  bool ClearRelativeToPrimary = true;
49  static Response Done() {
50  Response R;
51  R.IsDone = true;
52  return R;
53  }
54  static Response ChangeDecl(const Decl *ND) {
55  Response R;
56  R.NextDecl = ND;
57  return R;
58  }
59  static Response ChangeDecl(const DeclContext *Ctx) {
60  Response R;
61  R.NextDecl = Decl::castFromDeclContext(Ctx);
62  return R;
63  }
64 
65  static Response UseNextDecl(const Decl *CurDecl) {
66  return ChangeDecl(CurDecl->getDeclContext());
67  }
68 
69  static Response DontClearRelativeToPrimaryNextDecl(const Decl *CurDecl) {
70  Response R = Response::UseNextDecl(CurDecl);
71  R.ClearRelativeToPrimary = false;
72  return R;
73  }
74 };
75 // Add template arguments from a variable template instantiation.
76 Response
77 HandleVarTemplateSpec(const VarTemplateSpecializationDecl *VarTemplSpec,
79  bool SkipForSpecialization) {
80  // For a class-scope explicit specialization, there are no template arguments
81  // at this level, but there may be enclosing template arguments.
82  if (VarTemplSpec->isClassScopeExplicitSpecialization())
83  return Response::DontClearRelativeToPrimaryNextDecl(VarTemplSpec);
84 
85  // We're done when we hit an explicit specialization.
86  if (VarTemplSpec->getSpecializationKind() == TSK_ExplicitSpecialization &&
87  !isa<VarTemplatePartialSpecializationDecl>(VarTemplSpec))
88  return Response::Done();
89 
90  // If this variable template specialization was instantiated from a
91  // specialized member that is a variable template, we're done.
92  assert(VarTemplSpec->getSpecializedTemplate() && "No variable template?");
93  llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
94  Specialized = VarTemplSpec->getSpecializedTemplateOrPartial();
96  Specialized.dyn_cast<VarTemplatePartialSpecializationDecl *>()) {
97  if (!SkipForSpecialization)
98  Result.addOuterTemplateArguments(
99  Partial, VarTemplSpec->getTemplateInstantiationArgs().asArray(),
100  /*Final=*/false);
101  if (Partial->isMemberSpecialization())
102  return Response::Done();
103  } else {
104  VarTemplateDecl *Tmpl = Specialized.get<VarTemplateDecl *>();
105  if (!SkipForSpecialization)
106  Result.addOuterTemplateArguments(
107  Tmpl, VarTemplSpec->getTemplateInstantiationArgs().asArray(),
108  /*Final=*/false);
109  if (Tmpl->isMemberSpecialization())
110  return Response::Done();
111  }
112  return Response::DontClearRelativeToPrimaryNextDecl(VarTemplSpec);
113 }
114 
115 // If we have a template template parameter with translation unit context,
116 // then we're performing substitution into a default template argument of
117 // this template template parameter before we've constructed the template
118 // that will own this template template parameter. In this case, we
119 // use empty template parameter lists for all of the outer templates
120 // to avoid performing any substitutions.
121 Response
122 HandleDefaultTempArgIntoTempTempParam(const TemplateTemplateParmDecl *TTP,
124  for (unsigned I = 0, N = TTP->getDepth() + 1; I != N; ++I)
125  Result.addOuterTemplateArguments(None);
126  return Response::Done();
127 }
128 
129 // Add template arguments from a class template instantiation.
130 Response
131 HandleClassTemplateSpec(const ClassTemplateSpecializationDecl *ClassTemplSpec,
133  bool SkipForSpecialization) {
134  if (!ClassTemplSpec->isClassScopeExplicitSpecialization()) {
135  // We're done when we hit an explicit specialization.
136  if (ClassTemplSpec->getSpecializationKind() == TSK_ExplicitSpecialization &&
137  !isa<ClassTemplatePartialSpecializationDecl>(ClassTemplSpec))
138  return Response::Done();
139 
140  if (!SkipForSpecialization)
141  Result.addOuterTemplateArguments(
142  const_cast<ClassTemplateSpecializationDecl *>(ClassTemplSpec),
143  ClassTemplSpec->getTemplateInstantiationArgs().asArray(),
144  /*Final=*/false);
145 
146  // If this class template specialization was instantiated from a
147  // specialized member that is a class template, we're done.
148  assert(ClassTemplSpec->getSpecializedTemplate() && "No class template?");
149  if (ClassTemplSpec->getSpecializedTemplate()->isMemberSpecialization())
150  return Response::Done();
151  }
152  return Response::UseNextDecl(ClassTemplSpec);
153 }
154 
155 Response HandleFunction(const FunctionDecl *Function,
157  const FunctionDecl *Pattern, bool RelativeToPrimary,
158  bool ForConstraintInstantiation) {
159  // Add template arguments from a function template specialization.
160  if (!RelativeToPrimary &&
161  Function->getTemplateSpecializationKindForInstantiation() ==
163  return Response::Done();
164 
165  if (!RelativeToPrimary &&
166  Function->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) {
167  // This is an implicit instantiation of an explicit specialization. We
168  // don't get any template arguments from this function but might get
169  // some from an enclosing template.
170  return Response::UseNextDecl(Function);
171  } else if (const TemplateArgumentList *TemplateArgs =
172  Function->getTemplateSpecializationArgs()) {
173  // Add the template arguments for this specialization.
174  Result.addOuterTemplateArguments(const_cast<FunctionDecl *>(Function),
175  TemplateArgs->asArray(),
176  /*Final=*/false);
177 
178  // If this function was instantiated from a specialized member that is
179  // a function template, we're done.
180  assert(Function->getPrimaryTemplate() && "No function template?");
181  if (Function->getPrimaryTemplate()->isMemberSpecialization())
182  return Response::Done();
183 
184  // If this function is a generic lambda specialization, we are done.
185  if (!ForConstraintInstantiation &&
187  return Response::Done();
188 
189  } else if (Function->getDescribedFunctionTemplate()) {
190  assert(
191  (ForConstraintInstantiation || Result.getNumSubstitutedLevels() == 0) &&
192  "Outer template not instantiated?");
193  }
194  // If this is a friend or local declaration and it declares an entity at
195  // namespace scope, take arguments from its lexical parent
196  // instead of its semantic parent, unless of course the pattern we're
197  // instantiating actually comes from the file's context!
198  if ((Function->getFriendObjectKind() || Function->isLocalExternDecl()) &&
199  Function->getNonTransparentDeclContext()->isFileContext() &&
200  (!Pattern || !Pattern->getLexicalDeclContext()->isFileContext())) {
201  return Response::ChangeDecl(Function->getLexicalDeclContext());
202  }
203  return Response::UseNextDecl(Function);
204 }
205 
206 Response HandleRecordDecl(const CXXRecordDecl *Rec,
208  ASTContext &Context,
209  bool ForConstraintInstantiation) {
210  if (ClassTemplateDecl *ClassTemplate = Rec->getDescribedClassTemplate()) {
211  assert(
212  (ForConstraintInstantiation || Result.getNumSubstitutedLevels() == 0) &&
213  "Outer template not instantiated?");
214  if (ClassTemplate->isMemberSpecialization())
215  return Response::Done();
216  if (ForConstraintInstantiation) {
217  QualType RecordType = Context.getTypeDeclType(Rec);
218  QualType Injected = cast<InjectedClassNameType>(RecordType)
219  ->getInjectedSpecializationType();
220  const auto *InjectedType = cast<TemplateSpecializationType>(Injected);
221  Result.addOuterTemplateArguments(const_cast<CXXRecordDecl *>(Rec),
222  InjectedType->template_arguments(),
223  /*Final=*/false);
224  }
225  }
226 
227  bool IsFriend = Rec->getFriendObjectKind() ||
228  (Rec->getDescribedClassTemplate() &&
230  if (ForConstraintInstantiation && IsFriend &&
232  return Response::ChangeDecl(Rec->getLexicalDeclContext());
233  }
234 
235  // This is to make sure we pick up the VarTemplateSpecializationDecl that this
236  // lambda is defined inside of.
237  if (Rec->isLambda())
238  if (const Decl *LCD = Rec->getLambdaContextDecl())
239  return Response::ChangeDecl(LCD);
240 
241  return Response::UseNextDecl(Rec);
242 }
243 
244 Response HandleImplicitConceptSpecializationDecl(
247  Result.addOuterTemplateArguments(
248  const_cast<ImplicitConceptSpecializationDecl *>(CSD),
249  CSD->getTemplateArguments(),
250  /*Final=*/false);
251  return Response::UseNextDecl(CSD);
252 }
253 
254 Response HandleGenericDeclContext(const Decl *CurDecl) {
255  return Response::UseNextDecl(CurDecl);
256 }
257 } // namespace TemplateInstArgsHelpers
258 } // namespace
259 
260 /// Retrieve the template argument list(s) that should be used to
261 /// instantiate the definition of the given declaration.
262 ///
263 /// \param ND the declaration for which we are computing template instantiation
264 /// arguments.
265 ///
266 /// \param Innermost if non-NULL, specifies a template argument list for the
267 /// template declaration passed as ND.
268 ///
269 /// \param RelativeToPrimary true if we should get the template
270 /// arguments relative to the primary template, even when we're
271 /// dealing with a specialization. This is only relevant for function
272 /// template specializations.
273 ///
274 /// \param Pattern If non-NULL, indicates the pattern from which we will be
275 /// instantiating the definition of the given declaration, \p ND. This is
276 /// used to determine the proper set of template instantiation arguments for
277 /// friend function template specializations.
278 ///
279 /// \param ForConstraintInstantiation when collecting arguments,
280 /// ForConstraintInstantiation indicates we should continue looking when
281 /// encountering a lambda generic call operator, and continue looking for
282 /// arguments on an enclosing class template.
283 
285  const NamedDecl *ND, bool Final, const TemplateArgumentList *Innermost,
286  bool RelativeToPrimary, const FunctionDecl *Pattern,
287  bool ForConstraintInstantiation, bool SkipForSpecialization) {
288  assert(ND && "Can't find arguments for a decl if one isn't provided");
289  // Accumulate the set of template argument lists in this structure.
291 
292  if (Innermost)
293  Result.addOuterTemplateArguments(const_cast<NamedDecl *>(ND),
294  Innermost->asArray(), Final);
295 
296  const Decl *CurDecl = ND;
297 
298  while (!CurDecl->isFileContextDecl()) {
299  using namespace TemplateInstArgsHelpers;
300  Response R;
301  if (const auto *VarTemplSpec =
302  dyn_cast<VarTemplateSpecializationDecl>(CurDecl)) {
303  R = HandleVarTemplateSpec(VarTemplSpec, Result, SkipForSpecialization);
304  } else if (const auto *ClassTemplSpec =
305  dyn_cast<ClassTemplateSpecializationDecl>(CurDecl)) {
306  R = HandleClassTemplateSpec(ClassTemplSpec, Result,
307  SkipForSpecialization);
308  } else if (const auto *Function = dyn_cast<FunctionDecl>(CurDecl)) {
309  R = HandleFunction(Function, Result, Pattern, RelativeToPrimary,
310  ForConstraintInstantiation);
311  } else if (const auto *Rec = dyn_cast<CXXRecordDecl>(CurDecl)) {
312  R = HandleRecordDecl(Rec, Result, Context, ForConstraintInstantiation);
313  } else if (const auto *CSD =
314  dyn_cast<ImplicitConceptSpecializationDecl>(CurDecl)) {
315  R = HandleImplicitConceptSpecializationDecl(CSD, Result);
316  } else if (!isa<DeclContext>(CurDecl)) {
317  R = Response::DontClearRelativeToPrimaryNextDecl(CurDecl);
318  if (CurDecl->getDeclContext()->isTranslationUnit()) {
319  if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl)) {
320  R = HandleDefaultTempArgIntoTempTempParam(TTP, Result);
321  }
322  }
323  } else {
324  R = HandleGenericDeclContext(CurDecl);
325  }
326 
327  if (R.IsDone)
328  return Result;
329  if (R.ClearRelativeToPrimary)
330  RelativeToPrimary = false;
331  assert(R.NextDecl);
332  CurDecl = R.NextDecl;
333  }
334 
335  return Result;
336 }
337 
339  switch (Kind) {
340  case TemplateInstantiation:
341  case ExceptionSpecInstantiation:
342  case DefaultTemplateArgumentInstantiation:
343  case DefaultFunctionArgumentInstantiation:
344  case ExplicitTemplateArgumentSubstitution:
345  case DeducedTemplateArgumentSubstitution:
346  case PriorTemplateArgumentSubstitution:
347  case ConstraintsCheck:
348  case NestedRequirementConstraintsCheck:
349  return true;
350 
351  case RequirementInstantiation:
352  case RequirementParameterInstantiation:
353  case DefaultTemplateArgumentChecking:
354  case DeclaringSpecialMember:
355  case DeclaringImplicitEqualityComparison:
356  case DefiningSynthesizedFunction:
357  case ExceptionSpecEvaluation:
358  case ConstraintSubstitution:
359  case ParameterMappingSubstitution:
360  case ConstraintNormalization:
361  case RewritingOperatorAsSpaceship:
362  case InitializingStructuredBinding:
363  case MarkingClassDllexported:
364  case BuildingBuiltinDumpStructCall:
365  return false;
366 
367  // This function should never be called when Kind's value is Memoization.
368  case Memoization:
369  break;
370  }
371 
372  llvm_unreachable("Invalid SynthesisKind!");
373 }
374 
377  SourceLocation PointOfInstantiation, SourceRange InstantiationRange,
378  Decl *Entity, NamedDecl *Template, ArrayRef<TemplateArgument> TemplateArgs,
379  sema::TemplateDeductionInfo *DeductionInfo)
380  : SemaRef(SemaRef) {
381  // Don't allow further instantiation if a fatal error and an uncompilable
382  // error have occurred. Any diagnostics we might have raised will not be
383  // visible, and we do not need to construct a correct AST.
384  if (SemaRef.Diags.hasFatalErrorOccurred() &&
385  SemaRef.hasUncompilableErrorOccurred()) {
386  Invalid = true;
387  return;
388  }
389  Invalid = CheckInstantiationDepth(PointOfInstantiation, InstantiationRange);
390  if (!Invalid) {
392  Inst.Kind = Kind;
393  Inst.PointOfInstantiation = PointOfInstantiation;
394  Inst.Entity = Entity;
395  Inst.Template = Template;
396  Inst.TemplateArgs = TemplateArgs.data();
397  Inst.NumTemplateArgs = TemplateArgs.size();
398  Inst.DeductionInfo = DeductionInfo;
399  Inst.InstantiationRange = InstantiationRange;
400  SemaRef.pushCodeSynthesisContext(Inst);
401 
402  AlreadyInstantiating = !Inst.Entity ? false :
404  .insert({Inst.Entity->getCanonicalDecl(), Inst.Kind})
405  .second;
406  atTemplateBegin(SemaRef.TemplateInstCallbacks, SemaRef, Inst);
407  }
408 }
409 
411  Sema &SemaRef, SourceLocation PointOfInstantiation, Decl *Entity,
412  SourceRange InstantiationRange)
413  : InstantiatingTemplate(SemaRef,
414  CodeSynthesisContext::TemplateInstantiation,
415  PointOfInstantiation, InstantiationRange, Entity) {}
416 
418  Sema &SemaRef, SourceLocation PointOfInstantiation, FunctionDecl *Entity,
419  ExceptionSpecification, SourceRange InstantiationRange)
421  SemaRef, CodeSynthesisContext::ExceptionSpecInstantiation,
422  PointOfInstantiation, InstantiationRange, Entity) {}
423 
425  Sema &SemaRef, SourceLocation PointOfInstantiation, TemplateParameter Param,
426  TemplateDecl *Template, ArrayRef<TemplateArgument> TemplateArgs,
427  SourceRange InstantiationRange)
429  SemaRef,
430  CodeSynthesisContext::DefaultTemplateArgumentInstantiation,
431  PointOfInstantiation, InstantiationRange, getAsNamedDecl(Param),
432  Template, TemplateArgs) {}
433 
435  Sema &SemaRef, SourceLocation PointOfInstantiation,
436  FunctionTemplateDecl *FunctionTemplate,
437  ArrayRef<TemplateArgument> TemplateArgs,
439  sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange)
440  : InstantiatingTemplate(SemaRef, Kind, PointOfInstantiation,
441  InstantiationRange, FunctionTemplate, nullptr,
442  TemplateArgs, &DeductionInfo) {
443  assert(
446 }
447 
449  Sema &SemaRef, SourceLocation PointOfInstantiation,
450  TemplateDecl *Template,
451  ArrayRef<TemplateArgument> TemplateArgs,
452  sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange)
454  SemaRef,
455  CodeSynthesisContext::DeducedTemplateArgumentSubstitution,
456  PointOfInstantiation, InstantiationRange, Template, nullptr,
457  TemplateArgs, &DeductionInfo) {}
458 
460  Sema &SemaRef, SourceLocation PointOfInstantiation,
462  ArrayRef<TemplateArgument> TemplateArgs,
463  sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange)
465  SemaRef,
466  CodeSynthesisContext::DeducedTemplateArgumentSubstitution,
467  PointOfInstantiation, InstantiationRange, PartialSpec, nullptr,
468  TemplateArgs, &DeductionInfo) {}
469 
471  Sema &SemaRef, SourceLocation PointOfInstantiation,
473  ArrayRef<TemplateArgument> TemplateArgs,
474  sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange)
476  SemaRef,
477  CodeSynthesisContext::DeducedTemplateArgumentSubstitution,
478  PointOfInstantiation, InstantiationRange, PartialSpec, nullptr,
479  TemplateArgs, &DeductionInfo) {}
480 
482  Sema &SemaRef, SourceLocation PointOfInstantiation, ParmVarDecl *Param,
483  ArrayRef<TemplateArgument> TemplateArgs, SourceRange InstantiationRange)
485  SemaRef,
486  CodeSynthesisContext::DefaultFunctionArgumentInstantiation,
487  PointOfInstantiation, InstantiationRange, Param, nullptr,
488  TemplateArgs) {}
489 
491  Sema &SemaRef, SourceLocation PointOfInstantiation, NamedDecl *Template,
493  SourceRange InstantiationRange)
495  SemaRef,
496  CodeSynthesisContext::PriorTemplateArgumentSubstitution,
497  PointOfInstantiation, InstantiationRange, Param, Template,
498  TemplateArgs) {}
499 
501  Sema &SemaRef, SourceLocation PointOfInstantiation, NamedDecl *Template,
503  SourceRange InstantiationRange)
505  SemaRef,
506  CodeSynthesisContext::PriorTemplateArgumentSubstitution,
507  PointOfInstantiation, InstantiationRange, Param, Template,
508  TemplateArgs) {}
509 
511  Sema &SemaRef, SourceLocation PointOfInstantiation, TemplateDecl *Template,
512  NamedDecl *Param, ArrayRef<TemplateArgument> TemplateArgs,
513  SourceRange InstantiationRange)
515  SemaRef, CodeSynthesisContext::DefaultTemplateArgumentChecking,
516  PointOfInstantiation, InstantiationRange, Param, Template,
517  TemplateArgs) {}
518 
520  Sema &SemaRef, SourceLocation PointOfInstantiation,
522  SourceRange InstantiationRange)
524  SemaRef, CodeSynthesisContext::RequirementInstantiation,
525  PointOfInstantiation, InstantiationRange, /*Entity=*/nullptr,
526  /*Template=*/nullptr, /*TemplateArgs=*/None, &DeductionInfo) {}
527 
528 
530  Sema &SemaRef, SourceLocation PointOfInstantiation,
532  SourceRange InstantiationRange)
534  SemaRef, CodeSynthesisContext::NestedRequirementConstraintsCheck,
535  PointOfInstantiation, InstantiationRange, /*Entity=*/nullptr,
536  /*Template=*/nullptr, /*TemplateArgs=*/None) {}
537 
539  Sema &SemaRef, SourceLocation PointOfInstantiation, const RequiresExpr *RE,
540  sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange)
542  SemaRef, CodeSynthesisContext::RequirementParameterInstantiation,
543  PointOfInstantiation, InstantiationRange, /*Entity=*/nullptr,
544  /*Template=*/nullptr, /*TemplateArgs=*/None, &DeductionInfo) {}
545 
547  Sema &SemaRef, SourceLocation PointOfInstantiation,
548  ConstraintsCheck, NamedDecl *Template,
549  ArrayRef<TemplateArgument> TemplateArgs, SourceRange InstantiationRange)
552  PointOfInstantiation, InstantiationRange, Template, nullptr,
553  TemplateArgs) {}
554 
556  Sema &SemaRef, SourceLocation PointOfInstantiation,
558  sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange)
561  PointOfInstantiation, InstantiationRange, Template, nullptr,
562  {}, &DeductionInfo) {}
563 
565  Sema &SemaRef, SourceLocation PointOfInstantiation,
567  SourceRange InstantiationRange)
570  PointOfInstantiation, InstantiationRange, Template) {}
571 
573  Sema &SemaRef, SourceLocation PointOfInstantiation,
575  SourceRange InstantiationRange)
578  PointOfInstantiation, InstantiationRange, Template) {}
579 
580 
584 
585  CodeSynthesisContexts.push_back(Ctx);
586 
587  if (!Ctx.isInstantiationRecord())
589 
590  // Check to see if we're low on stack space. We can't do anything about this
591  // from here, but we can at least warn the user.
594 }
595 
597  auto &Active = CodeSynthesisContexts.back();
598  if (!Active.isInstantiationRecord()) {
599  assert(NonInstantiationEntries > 0);
601  }
602 
603  InNonInstantiationSFINAEContext = Active.SavedInNonInstantiationSFINAEContext;
604 
605  // Name lookup no longer looks in this template's defining module.
606  assert(CodeSynthesisContexts.size() >=
608  "forgot to remove a lookup module for a template instantiation");
609  if (CodeSynthesisContexts.size() ==
612  LookupModulesCache.erase(M);
614  }
615 
616  // If we've left the code synthesis context for the current context stack,
617  // stop remembering that we've emitted that stack.
618  if (CodeSynthesisContexts.size() ==
621 
622  CodeSynthesisContexts.pop_back();
623 }
624 
626  if (!Invalid) {
627  if (!AlreadyInstantiating) {
628  auto &Active = SemaRef.CodeSynthesisContexts.back();
629  if (Active.Entity)
630  SemaRef.InstantiatingSpecializations.erase(
631  {Active.Entity->getCanonicalDecl(), Active.Kind});
632  }
633 
634  atTemplateEnd(SemaRef.TemplateInstCallbacks, SemaRef,
635  SemaRef.CodeSynthesisContexts.back());
636 
637  SemaRef.popCodeSynthesisContext();
638  Invalid = true;
639  }
640 }
641 
644  std::string Result;
645  llvm::raw_string_ostream OS(Result);
646  llvm::ListSeparator Comma;
647  for (const Expr *Arg : Args) {
648  OS << Comma;
649  Arg->IgnoreParens()->printPretty(OS, nullptr,
651  }
652  return Result;
653 }
654 
655 bool Sema::InstantiatingTemplate::CheckInstantiationDepth(
656  SourceLocation PointOfInstantiation,
657  SourceRange InstantiationRange) {
658  assert(SemaRef.NonInstantiationEntries <=
659  SemaRef.CodeSynthesisContexts.size());
660  if ((SemaRef.CodeSynthesisContexts.size() -
661  SemaRef.NonInstantiationEntries)
662  <= SemaRef.getLangOpts().InstantiationDepth)
663  return false;
664 
665  SemaRef.Diag(PointOfInstantiation,
666  diag::err_template_recursion_depth_exceeded)
667  << SemaRef.getLangOpts().InstantiationDepth
668  << InstantiationRange;
669  SemaRef.Diag(PointOfInstantiation, diag::note_template_recursion_depth)
670  << SemaRef.getLangOpts().InstantiationDepth;
671  return true;
672 }
673 
674 /// Prints the current instantiation stack through a series of
675 /// notes.
677  // Determine which template instantiations to skip, if any.
678  unsigned SkipStart = CodeSynthesisContexts.size(), SkipEnd = SkipStart;
679  unsigned Limit = Diags.getTemplateBacktraceLimit();
680  if (Limit && Limit < CodeSynthesisContexts.size()) {
681  SkipStart = Limit / 2 + Limit % 2;
682  SkipEnd = CodeSynthesisContexts.size() - Limit / 2;
683  }
684 
685  // FIXME: In all of these cases, we need to show the template arguments
686  unsigned InstantiationIdx = 0;
688  Active = CodeSynthesisContexts.rbegin(),
689  ActiveEnd = CodeSynthesisContexts.rend();
690  Active != ActiveEnd;
691  ++Active, ++InstantiationIdx) {
692  // Skip this instantiation?
693  if (InstantiationIdx >= SkipStart && InstantiationIdx < SkipEnd) {
694  if (InstantiationIdx == SkipStart) {
695  // Note that we're skipping instantiations.
696  Diags.Report(Active->PointOfInstantiation,
697  diag::note_instantiation_contexts_suppressed)
698  << unsigned(CodeSynthesisContexts.size() - Limit);
699  }
700  continue;
701  }
702 
703  switch (Active->Kind) {
705  Decl *D = Active->Entity;
706  if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) {
707  unsigned DiagID = diag::note_template_member_class_here;
708  if (isa<ClassTemplateSpecializationDecl>(Record))
709  DiagID = diag::note_template_class_instantiation_here;
710  Diags.Report(Active->PointOfInstantiation, DiagID)
711  << Record << Active->InstantiationRange;
712  } else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
713  unsigned DiagID;
714  if (Function->getPrimaryTemplate())
715  DiagID = diag::note_function_template_spec_here;
716  else
717  DiagID = diag::note_template_member_function_here;
718  Diags.Report(Active->PointOfInstantiation, DiagID)
719  << Function
720  << Active->InstantiationRange;
721  } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
722  Diags.Report(Active->PointOfInstantiation,
723  VD->isStaticDataMember()?
724  diag::note_template_static_data_member_def_here
725  : diag::note_template_variable_def_here)
726  << VD
727  << Active->InstantiationRange;
728  } else if (EnumDecl *ED = dyn_cast<EnumDecl>(D)) {
729  Diags.Report(Active->PointOfInstantiation,
730  diag::note_template_enum_def_here)
731  << ED
732  << Active->InstantiationRange;
733  } else if (FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
734  Diags.Report(Active->PointOfInstantiation,
735  diag::note_template_nsdmi_here)
736  << FD << Active->InstantiationRange;
737  } else {
738  Diags.Report(Active->PointOfInstantiation,
739  diag::note_template_type_alias_instantiation_here)
740  << cast<TypeAliasTemplateDecl>(D)
741  << Active->InstantiationRange;
742  }
743  break;
744  }
745 
747  TemplateDecl *Template = cast<TemplateDecl>(Active->Template);
748  SmallString<128> TemplateArgsStr;
749  llvm::raw_svector_ostream OS(TemplateArgsStr);
750  Template->printName(OS, getPrintingPolicy());
751  printTemplateArgumentList(OS, Active->template_arguments(),
753  Diags.Report(Active->PointOfInstantiation,
754  diag::note_default_arg_instantiation_here)
755  << OS.str()
756  << Active->InstantiationRange;
757  break;
758  }
759 
761  FunctionTemplateDecl *FnTmpl = cast<FunctionTemplateDecl>(Active->Entity);
762  Diags.Report(Active->PointOfInstantiation,
763  diag::note_explicit_template_arg_substitution_here)
764  << FnTmpl
766  Active->TemplateArgs,
767  Active->NumTemplateArgs)
768  << Active->InstantiationRange;
769  break;
770  }
771 
773  if (FunctionTemplateDecl *FnTmpl =
774  dyn_cast<FunctionTemplateDecl>(Active->Entity)) {
775  Diags.Report(Active->PointOfInstantiation,
776  diag::note_function_template_deduction_instantiation_here)
777  << FnTmpl
778  << getTemplateArgumentBindingsText(FnTmpl->getTemplateParameters(),
779  Active->TemplateArgs,
780  Active->NumTemplateArgs)
781  << Active->InstantiationRange;
782  } else {
783  bool IsVar = isa<VarTemplateDecl>(Active->Entity) ||
784  isa<VarTemplateSpecializationDecl>(Active->Entity);
785  bool IsTemplate = false;
786  TemplateParameterList *Params;
787  if (auto *D = dyn_cast<TemplateDecl>(Active->Entity)) {
788  IsTemplate = true;
789  Params = D->getTemplateParameters();
790  } else if (auto *D = dyn_cast<ClassTemplatePartialSpecializationDecl>(
791  Active->Entity)) {
792  Params = D->getTemplateParameters();
793  } else if (auto *D = dyn_cast<VarTemplatePartialSpecializationDecl>(
794  Active->Entity)) {
795  Params = D->getTemplateParameters();
796  } else {
797  llvm_unreachable("unexpected template kind");
798  }
799 
800  Diags.Report(Active->PointOfInstantiation,
801  diag::note_deduced_template_arg_substitution_here)
802  << IsVar << IsTemplate << cast<NamedDecl>(Active->Entity)
803  << getTemplateArgumentBindingsText(Params, Active->TemplateArgs,
804  Active->NumTemplateArgs)
805  << Active->InstantiationRange;
806  }
807  break;
808  }
809 
811  ParmVarDecl *Param = cast<ParmVarDecl>(Active->Entity);
812  FunctionDecl *FD = cast<FunctionDecl>(Param->getDeclContext());
813 
814  SmallString<128> TemplateArgsStr;
815  llvm::raw_svector_ostream OS(TemplateArgsStr);
816  FD->printName(OS, getPrintingPolicy());
817  printTemplateArgumentList(OS, Active->template_arguments(),
819  Diags.Report(Active->PointOfInstantiation,
820  diag::note_default_function_arg_instantiation_here)
821  << OS.str()
822  << Active->InstantiationRange;
823  break;
824  }
825 
827  NamedDecl *Parm = cast<NamedDecl>(Active->Entity);
828  std::string Name;
829  if (!Parm->getName().empty())
830  Name = std::string(" '") + Parm->getName().str() + "'";
831 
832  TemplateParameterList *TemplateParams = nullptr;
833  if (TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template))
834  TemplateParams = Template->getTemplateParameters();
835  else
836  TemplateParams =
837  cast<ClassTemplatePartialSpecializationDecl>(Active->Template)
838  ->getTemplateParameters();
839  Diags.Report(Active->PointOfInstantiation,
840  diag::note_prior_template_arg_substitution)
841  << isa<TemplateTemplateParmDecl>(Parm)
842  << Name
843  << getTemplateArgumentBindingsText(TemplateParams,
844  Active->TemplateArgs,
845  Active->NumTemplateArgs)
846  << Active->InstantiationRange;
847  break;
848  }
849 
851  TemplateParameterList *TemplateParams = nullptr;
852  if (TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template))
853  TemplateParams = Template->getTemplateParameters();
854  else
855  TemplateParams =
856  cast<ClassTemplatePartialSpecializationDecl>(Active->Template)
857  ->getTemplateParameters();
858 
859  Diags.Report(Active->PointOfInstantiation,
860  diag::note_template_default_arg_checking)
861  << getTemplateArgumentBindingsText(TemplateParams,
862  Active->TemplateArgs,
863  Active->NumTemplateArgs)
864  << Active->InstantiationRange;
865  break;
866  }
867 
869  Diags.Report(Active->PointOfInstantiation,
870  diag::note_evaluating_exception_spec_here)
871  << cast<FunctionDecl>(Active->Entity);
872  break;
873 
875  Diags.Report(Active->PointOfInstantiation,
876  diag::note_template_exception_spec_instantiation_here)
877  << cast<FunctionDecl>(Active->Entity)
878  << Active->InstantiationRange;
879  break;
880 
882  Diags.Report(Active->PointOfInstantiation,
883  diag::note_template_requirement_instantiation_here)
884  << Active->InstantiationRange;
885  break;
887  Diags.Report(Active->PointOfInstantiation,
888  diag::note_template_requirement_params_instantiation_here)
889  << Active->InstantiationRange;
890  break;
891 
893  Diags.Report(Active->PointOfInstantiation,
894  diag::note_nested_requirement_here)
895  << Active->InstantiationRange;
896  break;
897 
899  Diags.Report(Active->PointOfInstantiation,
900  diag::note_in_declaration_of_implicit_special_member)
901  << cast<CXXRecordDecl>(Active->Entity) << Active->SpecialMember;
902  break;
903 
905  Diags.Report(Active->Entity->getLocation(),
906  diag::note_in_declaration_of_implicit_equality_comparison);
907  break;
908 
910  // FIXME: For synthesized functions that are not defaulted,
911  // produce a note.
912  auto *FD = dyn_cast<FunctionDecl>(Active->Entity);
915  if (DFK.isSpecialMember()) {
916  auto *MD = cast<CXXMethodDecl>(FD);
917  Diags.Report(Active->PointOfInstantiation,
918  diag::note_member_synthesized_at)
919  << MD->isExplicitlyDefaulted() << DFK.asSpecialMember()
920  << Context.getTagDeclType(MD->getParent());
921  } else if (DFK.isComparison()) {
922  Diags.Report(Active->PointOfInstantiation,
923  diag::note_comparison_synthesized_at)
924  << (int)DFK.asComparison()
926  cast<CXXRecordDecl>(FD->getLexicalDeclContext()));
927  }
928  break;
929  }
930 
932  Diags.Report(Active->Entity->getLocation(),
933  diag::note_rewriting_operator_as_spaceship);
934  break;
935 
937  Diags.Report(Active->PointOfInstantiation,
938  diag::note_in_binding_decl_init)
939  << cast<BindingDecl>(Active->Entity);
940  break;
941 
943  Diags.Report(Active->PointOfInstantiation,
944  diag::note_due_to_dllexported_class)
945  << cast<CXXRecordDecl>(Active->Entity) << !getLangOpts().CPlusPlus11;
946  break;
947 
949  Diags.Report(Active->PointOfInstantiation,
950  diag::note_building_builtin_dump_struct_call)
952  *this,
953  llvm::makeArrayRef(Active->CallArgs, Active->NumCallArgs));
954  break;
955 
957  break;
958 
960  unsigned DiagID = 0;
961  if (!Active->Entity) {
962  Diags.Report(Active->PointOfInstantiation,
963  diag::note_nested_requirement_here)
964  << Active->InstantiationRange;
965  break;
966  }
967  if (isa<ConceptDecl>(Active->Entity))
968  DiagID = diag::note_concept_specialization_here;
969  else if (isa<TemplateDecl>(Active->Entity))
970  DiagID = diag::note_checking_constraints_for_template_id_here;
971  else if (isa<VarTemplatePartialSpecializationDecl>(Active->Entity))
972  DiagID = diag::note_checking_constraints_for_var_spec_id_here;
973  else if (isa<ClassTemplatePartialSpecializationDecl>(Active->Entity))
974  DiagID = diag::note_checking_constraints_for_class_spec_id_here;
975  else {
976  assert(isa<FunctionDecl>(Active->Entity));
977  DiagID = diag::note_checking_constraints_for_function_here;
978  }
979  SmallString<128> TemplateArgsStr;
980  llvm::raw_svector_ostream OS(TemplateArgsStr);
981  cast<NamedDecl>(Active->Entity)->printName(OS, getPrintingPolicy());
982  if (!isa<FunctionDecl>(Active->Entity)) {
983  printTemplateArgumentList(OS, Active->template_arguments(),
985  }
986  Diags.Report(Active->PointOfInstantiation, DiagID) << OS.str()
987  << Active->InstantiationRange;
988  break;
989  }
991  Diags.Report(Active->PointOfInstantiation,
992  diag::note_constraint_substitution_here)
993  << Active->InstantiationRange;
994  break;
996  Diags.Report(Active->PointOfInstantiation,
997  diag::note_constraint_normalization_here)
998  << cast<NamedDecl>(Active->Entity)->getName()
999  << Active->InstantiationRange;
1000  break;
1002  Diags.Report(Active->PointOfInstantiation,
1003  diag::note_parameter_mapping_substitution_here)
1004  << Active->InstantiationRange;
1005  break;
1006  }
1007  }
1008 }
1009 
1012  return Optional<TemplateDeductionInfo *>(nullptr);
1013 
1015  Active = CodeSynthesisContexts.rbegin(),
1016  ActiveEnd = CodeSynthesisContexts.rend();
1017  Active != ActiveEnd;
1018  ++Active)
1019  {
1020  switch (Active->Kind) {
1022  // An instantiation of an alias template may or may not be a SFINAE
1023  // context, depending on what else is on the stack.
1024  if (isa<TypeAliasTemplateDecl>(Active->Entity))
1025  break;
1026  [[fallthrough]];
1033  // This is a template instantiation, so there is no SFINAE.
1034  return None;
1035 
1040  // A default template argument instantiation and substitution into
1041  // template parameters with arguments for prior parameters may or may
1042  // not be a SFINAE context; look further up the stack.
1043  break;
1044 
1050  // We're either substituting explicitly-specified template arguments,
1051  // deduced template arguments, a constraint expression or a requirement
1052  // in a requires expression, so SFINAE applies.
1053  assert(Active->DeductionInfo && "Missing deduction info pointer");
1054  return Active->DeductionInfo;
1055 
1062  // This happens in a context unrelated to template instantiation, so
1063  // there is no SFINAE.
1064  return None;
1065 
1067  // FIXME: This should not be treated as a SFINAE context, because
1068  // we will cache an incorrect exception specification. However, clang
1069  // bootstrap relies this! See PR31692.
1070  break;
1071 
1073  break;
1074  }
1075 
1076  // The inner context was transparent for SFINAE. If it occurred within a
1077  // non-instantiation SFINAE context, then SFINAE applies.
1078  if (Active->SavedInNonInstantiationSFINAEContext)
1079  return Optional<TemplateDeductionInfo *>(nullptr);
1080  }
1081 
1082  return None;
1083 }
1084 
1085 //===----------------------------------------------------------------------===/
1086 // Template Instantiation for Types
1087 //===----------------------------------------------------------------------===/
1088 namespace {
1089  class TemplateInstantiator : public TreeTransform<TemplateInstantiator> {
1090  const MultiLevelTemplateArgumentList &TemplateArgs;
1091  SourceLocation Loc;
1092  DeclarationName Entity;
1093  bool EvaluateConstraints = true;
1094 
1095  public:
1096  typedef TreeTransform<TemplateInstantiator> inherited;
1097 
1098  TemplateInstantiator(Sema &SemaRef,
1099  const MultiLevelTemplateArgumentList &TemplateArgs,
1100  SourceLocation Loc, DeclarationName Entity)
1101  : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc),
1102  Entity(Entity) {}
1103 
1104  void setEvaluateConstraints(bool B) {
1105  EvaluateConstraints = B;
1106  }
1107  bool getEvaluateConstraints() {
1108  return EvaluateConstraints;
1109  }
1110 
1111  /// Determine whether the given type \p T has already been
1112  /// transformed.
1113  ///
1114  /// For the purposes of template instantiation, a type has already been
1115  /// transformed if it is NULL or if it is not dependent.
1116  bool AlreadyTransformed(QualType T);
1117 
1118  /// Returns the location of the entity being instantiated, if known.
1119  SourceLocation getBaseLocation() { return Loc; }
1120 
1121  /// Returns the name of the entity being instantiated, if any.
1122  DeclarationName getBaseEntity() { return Entity; }
1123 
1124  /// Sets the "base" location and entity when that
1125  /// information is known based on another transformation.
1126  void setBase(SourceLocation Loc, DeclarationName Entity) {
1127  this->Loc = Loc;
1128  this->Entity = Entity;
1129  }
1130 
1131  unsigned TransformTemplateDepth(unsigned Depth) {
1132  return TemplateArgs.getNewDepth(Depth);
1133  }
1134 
1135  Optional<unsigned> getPackIndex(TemplateArgument Pack) {
1136  int Index = getSema().ArgumentPackSubstitutionIndex;
1137  if (Index == -1)
1138  return None;
1139  return Pack.pack_size() - 1 - Index;
1140  }
1141 
1142  bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
1143  SourceRange PatternRange,
1145  bool &ShouldExpand, bool &RetainExpansion,
1146  Optional<unsigned> &NumExpansions) {
1147  return getSema().CheckParameterPacksForExpansion(EllipsisLoc,
1148  PatternRange, Unexpanded,
1149  TemplateArgs,
1150  ShouldExpand,
1151  RetainExpansion,
1152  NumExpansions);
1153  }
1154 
1155  void ExpandingFunctionParameterPack(ParmVarDecl *Pack) {
1157  }
1158 
1159  TemplateArgument ForgetPartiallySubstitutedPack() {
1160  TemplateArgument Result;
1161  if (NamedDecl *PartialPack
1163  MultiLevelTemplateArgumentList &TemplateArgs
1164  = const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs);
1165  unsigned Depth, Index;
1166  std::tie(Depth, Index) = getDepthAndIndex(PartialPack);
1167  if (TemplateArgs.hasTemplateArgument(Depth, Index)) {
1168  Result = TemplateArgs(Depth, Index);
1169  TemplateArgs.setArgument(Depth, Index, TemplateArgument());
1170  }
1171  }
1172 
1173  return Result;
1174  }
1175 
1176  void RememberPartiallySubstitutedPack(TemplateArgument Arg) {
1177  if (Arg.isNull())
1178  return;
1179 
1180  if (NamedDecl *PartialPack
1182  MultiLevelTemplateArgumentList &TemplateArgs
1183  = const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs);
1184  unsigned Depth, Index;
1185  std::tie(Depth, Index) = getDepthAndIndex(PartialPack);
1186  TemplateArgs.setArgument(Depth, Index, Arg);
1187  }
1188  }
1189 
1190  /// Transform the given declaration by instantiating a reference to
1191  /// this declaration.
1192  Decl *TransformDecl(SourceLocation Loc, Decl *D);
1193 
1194  void transformAttrs(Decl *Old, Decl *New) {
1195  SemaRef.InstantiateAttrs(TemplateArgs, Old, New);
1196  }
1197 
1198  void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> NewDecls) {
1199  if (Old->isParameterPack()) {
1201  for (auto *New : NewDecls)
1203  Old, cast<VarDecl>(New));
1204  return;
1205  }
1206 
1207  assert(NewDecls.size() == 1 &&
1208  "should only have multiple expansions for a pack");
1209  Decl *New = NewDecls.front();
1210 
1211  // If we've instantiated the call operator of a lambda or the call
1212  // operator template of a generic lambda, update the "instantiation of"
1213  // information.
1214  auto *NewMD = dyn_cast<CXXMethodDecl>(New);
1215  if (NewMD && isLambdaCallOperator(NewMD)) {
1216  auto *OldMD = dyn_cast<CXXMethodDecl>(Old);
1217  if (auto *NewTD = NewMD->getDescribedFunctionTemplate())
1218  NewTD->setInstantiatedFromMemberTemplate(
1219  OldMD->getDescribedFunctionTemplate());
1220  else
1221  NewMD->setInstantiationOfMemberFunction(OldMD,
1223  }
1224 
1225  SemaRef.CurrentInstantiationScope->InstantiatedLocal(Old, New);
1226 
1227  // We recreated a local declaration, but not by instantiating it. There
1228  // may be pending dependent diagnostics to produce.
1229  if (auto *DC = dyn_cast<DeclContext>(Old))
1230  SemaRef.PerformDependentDiagnostics(DC, TemplateArgs);
1231  }
1232 
1233  /// Transform the definition of the given declaration by
1234  /// instantiating it.
1235  Decl *TransformDefinition(SourceLocation Loc, Decl *D);
1236 
1237  /// Transform the first qualifier within a scope by instantiating the
1238  /// declaration.
1239  NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc);
1240 
1241  /// Rebuild the exception declaration and register the declaration
1242  /// as an instantiated local.
1243  VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1245  SourceLocation StartLoc,
1246  SourceLocation NameLoc,
1247  IdentifierInfo *Name);
1248 
1249  /// Rebuild the Objective-C exception declaration and register the
1250  /// declaration as an instantiated local.
1251  VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1252  TypeSourceInfo *TSInfo, QualType T);
1253 
1254  /// Check for tag mismatches when instantiating an
1255  /// elaborated type.
1256  QualType RebuildElaboratedType(SourceLocation KeywordLoc,
1257  ElaboratedTypeKeyword Keyword,
1258  NestedNameSpecifierLoc QualifierLoc,
1259  QualType T);
1260 
1261  TemplateName
1262  TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
1263  SourceLocation NameLoc,
1264  QualType ObjectType = QualType(),
1265  NamedDecl *FirstQualifierInScope = nullptr,
1266  bool AllowInjectedClassName = false);
1267 
1268  const LoopHintAttr *TransformLoopHintAttr(const LoopHintAttr *LH);
1269 
1270  ExprResult TransformPredefinedExpr(PredefinedExpr *E);
1271  ExprResult TransformDeclRefExpr(DeclRefExpr *E);
1272  ExprResult TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E);
1273 
1274  ExprResult TransformTemplateParmRefExpr(DeclRefExpr *E,
1276  ExprResult TransformSubstNonTypeTemplateParmPackExpr(
1278  ExprResult TransformSubstNonTypeTemplateParmExpr(
1280 
1281  /// Rebuild a DeclRefExpr for a VarDecl reference.
1282  ExprResult RebuildVarDeclRefExpr(VarDecl *PD, SourceLocation Loc);
1283 
1284  /// Transform a reference to a function or init-capture parameter pack.
1285  ExprResult TransformFunctionParmPackRefExpr(DeclRefExpr *E, VarDecl *PD);
1286 
1287  /// Transform a FunctionParmPackExpr which was built when we couldn't
1288  /// expand a function parameter pack reference which refers to an expanded
1289  /// pack.
1290  ExprResult TransformFunctionParmPackExpr(FunctionParmPackExpr *E);
1291 
1292  QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
1293  FunctionProtoTypeLoc TL) {
1294  // Call the base version; it will forward to our overridden version below.
1295  return inherited::TransformFunctionProtoType(TLB, TL);
1296  }
1297 
1298  template<typename Fn>
1299  QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
1301  CXXRecordDecl *ThisContext,
1302  Qualifiers ThisTypeQuals,
1303  Fn TransformExceptionSpec);
1304 
1305  ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
1306  int indexAdjustment,
1307  Optional<unsigned> NumExpansions,
1308  bool ExpectParameterPack);
1309 
1310  using inherited::TransformTemplateTypeParmType;
1311  /// Transforms a template type parameter type by performing
1312  /// substitution of the corresponding template type argument.
1313  QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB,
1315  bool SuppressObjCLifetime);
1316 
1317  QualType BuildSubstTemplateTypeParmType(
1318  TypeLocBuilder &TLB, bool SuppressObjCLifetime, bool Final,
1319  Decl *AssociatedDecl, unsigned Index, Optional<unsigned> PackIndex,
1320  TemplateArgument Arg, SourceLocation NameLoc);
1321 
1322  /// Transforms an already-substituted template type parameter pack
1323  /// into either itself (if we aren't substituting into its pack expansion)
1324  /// or the appropriate substituted argument.
1325  using inherited::TransformSubstTemplateTypeParmPackType;
1326  QualType
1327  TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB,
1329  bool SuppressObjCLifetime);
1330 
1331  ExprResult TransformLambdaExpr(LambdaExpr *E) {
1332  LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true);
1334  ExprResult Result = inherited::TransformLambdaExpr(E);
1335  if (Result.isInvalid())
1336  return Result;
1337 
1338  CXXMethodDecl *MD = Result.getAs<LambdaExpr>()->getCallOperator();
1339  for (ParmVarDecl *PVD : MD->parameters()) {
1340  if (!PVD->hasDefaultArg())
1341  continue;
1342  Expr *UninstExpr = PVD->getUninstantiatedDefaultArg();
1343  // FIXME: Obtain the source location for the '=' token.
1344  SourceLocation EqualLoc = UninstExpr->getBeginLoc();
1345  if (SemaRef.SubstDefaultArgument(EqualLoc, PVD, TemplateArgs)) {
1346  // If substitution fails, the default argument is set to a
1347  // RecoveryExpr that wraps the uninstantiated default argument so
1348  // that downstream diagnostics are omitted.
1349  ExprResult ErrorResult = SemaRef.CreateRecoveryExpr(
1350  UninstExpr->getBeginLoc(), UninstExpr->getEndLoc(),
1351  { UninstExpr }, UninstExpr->getType());
1352  if (ErrorResult.isUsable())
1353  PVD->setDefaultArg(ErrorResult.get());
1354  }
1355  }
1356 
1357  return Result;
1358  }
1359 
1360  ExprResult TransformRequiresExpr(RequiresExpr *E) {
1361  LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true);
1362  return inherited::TransformRequiresExpr(E);
1363  }
1364 
1365  bool TransformRequiresExprRequirements(
1368  bool SatisfactionDetermined = false;
1369  for (concepts::Requirement *Req : Reqs) {
1370  concepts::Requirement *TransReq = nullptr;
1371  if (!SatisfactionDetermined) {
1372  if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
1373  TransReq = TransformTypeRequirement(TypeReq);
1374  else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
1375  TransReq = TransformExprRequirement(ExprReq);
1376  else
1377  TransReq = TransformNestedRequirement(
1378  cast<concepts::NestedRequirement>(Req));
1379  if (!TransReq)
1380  return true;
1381  if (!TransReq->isDependent() && !TransReq->isSatisfied())
1382  // [expr.prim.req]p6
1383  // [...] The substitution and semantic constraint checking
1384  // proceeds in lexical order and stops when a condition that
1385  // determines the result of the requires-expression is
1386  // encountered. [..]
1387  SatisfactionDetermined = true;
1388  } else
1389  TransReq = Req;
1390  Transformed.push_back(TransReq);
1391  }
1392  return false;
1393  }
1394 
1395  TemplateParameterList *TransformTemplateParameterList(
1396  TemplateParameterList *OrigTPL) {
1397  if (!OrigTPL || !OrigTPL->size()) return OrigTPL;
1398 
1399  DeclContext *Owner = OrigTPL->getParam(0)->getDeclContext();
1400  TemplateDeclInstantiator DeclInstantiator(getSema(),
1401  /* DeclContext *Owner */ Owner, TemplateArgs);
1402  DeclInstantiator.setEvaluateConstraints(EvaluateConstraints);
1403  return DeclInstantiator.SubstTemplateParams(OrigTPL);
1404  }
1405 
1407  TransformTypeRequirement(concepts::TypeRequirement *Req);
1409  TransformExprRequirement(concepts::ExprRequirement *Req);
1411  TransformNestedRequirement(concepts::NestedRequirement *Req);
1412  ExprResult TransformRequiresTypeParams(
1413  SourceLocation KWLoc, SourceLocation RBraceLoc, const RequiresExpr *RE,
1415  SmallVectorImpl<QualType> &PTypes,
1416  SmallVectorImpl<ParmVarDecl *> &TransParams,
1418 
1419  private:
1420  ExprResult transformNonTypeTemplateParmRef(
1421  Decl *AssociatedDecl, const NonTypeTemplateParmDecl *parm,
1423  };
1424 }
1425 
1426 bool TemplateInstantiator::AlreadyTransformed(QualType T) {
1427  if (T.isNull())
1428  return true;
1429 
1431  return false;
1432 
1433  getSema().MarkDeclarationsReferencedInType(Loc, T);
1434  return true;
1435 }
1436 
1437 static TemplateArgument
1439  assert(S.ArgumentPackSubstitutionIndex >= 0);
1440  assert(S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size());
1442  if (Arg.isPackExpansion())
1443  Arg = Arg.getPackExpansionPattern();
1444  return Arg;
1445 }
1446 
1447 Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) {
1448  if (!D)
1449  return nullptr;
1450 
1451  if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
1452  if (TTP->getDepth() < TemplateArgs.getNumLevels()) {
1453  // If the corresponding template argument is NULL or non-existent, it's
1454  // because we are performing instantiation from explicitly-specified
1455  // template arguments in a function template, but there were some
1456  // arguments left unspecified.
1457  if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(),
1458  TTP->getPosition()))
1459  return D;
1460 
1461  TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());
1462 
1463  if (TTP->isParameterPack()) {
1464  assert(Arg.getKind() == TemplateArgument::Pack &&
1465  "Missing argument pack");
1466  Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1467  }
1468 
1469  TemplateName Template = Arg.getAsTemplate().getNameToSubstitute();
1470  assert(!Template.isNull() && Template.getAsTemplateDecl() &&
1471  "Wrong kind of template template argument");
1472  return Template.getAsTemplateDecl();
1473  }
1474 
1475  // Fall through to find the instantiated declaration for this template
1476  // template parameter.
1477  }
1478 
1479  return SemaRef.FindInstantiatedDecl(Loc, cast<NamedDecl>(D), TemplateArgs);
1480 }
1481 
1482 Decl *TemplateInstantiator::TransformDefinition(SourceLocation Loc, Decl *D) {
1483  Decl *Inst = getSema().SubstDecl(D, getSema().CurContext, TemplateArgs);
1484  if (!Inst)
1485  return nullptr;
1486 
1487  getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst);
1488  return Inst;
1489 }
1490 
1491 NamedDecl *
1492 TemplateInstantiator::TransformFirstQualifierInScope(NamedDecl *D,
1493  SourceLocation Loc) {
1494  // If the first part of the nested-name-specifier was a template type
1495  // parameter, instantiate that type parameter down to a tag type.
1496  if (TemplateTypeParmDecl *TTPD = dyn_cast_or_null<TemplateTypeParmDecl>(D)) {
1497  const TemplateTypeParmType *TTP
1498  = cast<TemplateTypeParmType>(getSema().Context.getTypeDeclType(TTPD));
1499 
1500  if (TTP->getDepth() < TemplateArgs.getNumLevels()) {
1501  // FIXME: This needs testing w/ member access expressions.
1502  TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getIndex());
1503 
1504  if (TTP->isParameterPack()) {
1505  assert(Arg.getKind() == TemplateArgument::Pack &&
1506  "Missing argument pack");
1507 
1508  if (getSema().ArgumentPackSubstitutionIndex == -1)
1509  return nullptr;
1510 
1511  Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1512  }
1513 
1514  QualType T = Arg.getAsType();
1515  if (T.isNull())
1516  return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
1517 
1518  if (const TagType *Tag = T->getAs<TagType>())
1519  return Tag->getDecl();
1520 
1521  // The resulting type is not a tag; complain.
1522  getSema().Diag(Loc, diag::err_nested_name_spec_non_tag) << T;
1523  return nullptr;
1524  }
1525  }
1526 
1527  return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
1528 }
1529 
1530 VarDecl *
1531 TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl,
1533  SourceLocation StartLoc,
1534  SourceLocation NameLoc,
1535  IdentifierInfo *Name) {
1536  VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, Declarator,
1537  StartLoc, NameLoc, Name);
1538  if (Var)
1539  getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
1540  return Var;
1541 }
1542 
1543 VarDecl *TemplateInstantiator::RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1544  TypeSourceInfo *TSInfo,
1545  QualType T) {
1546  VarDecl *Var = inherited::RebuildObjCExceptionDecl(ExceptionDecl, TSInfo, T);
1547  if (Var)
1548  getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
1549  return Var;
1550 }
1551 
1552 QualType
1553 TemplateInstantiator::RebuildElaboratedType(SourceLocation KeywordLoc,
1554  ElaboratedTypeKeyword Keyword,
1555  NestedNameSpecifierLoc QualifierLoc,
1556  QualType T) {
1557  if (const TagType *TT = T->getAs<TagType>()) {
1558  TagDecl* TD = TT->getDecl();
1559 
1560  SourceLocation TagLocation = KeywordLoc;
1561 
1562  IdentifierInfo *Id = TD->getIdentifier();
1563 
1564  // TODO: should we even warn on struct/class mismatches for this? Seems
1565  // like it's likely to produce a lot of spurious errors.
1566  if (Id && Keyword != ETK_None && Keyword != ETK_Typename) {
1568  if (!SemaRef.isAcceptableTagRedeclaration(TD, Kind, /*isDefinition*/false,
1569  TagLocation, Id)) {
1570  SemaRef.Diag(TagLocation, diag::err_use_with_wrong_tag)
1571  << Id
1572  << FixItHint::CreateReplacement(SourceRange(TagLocation),
1573  TD->getKindName());
1574  SemaRef.Diag(TD->getLocation(), diag::note_previous_use);
1575  }
1576  }
1577  }
1578 
1579  return inherited::RebuildElaboratedType(KeywordLoc, Keyword, QualifierLoc, T);
1580 }
1581 
1582 TemplateName TemplateInstantiator::TransformTemplateName(
1583  CXXScopeSpec &SS, TemplateName Name, SourceLocation NameLoc,
1584  QualType ObjectType, NamedDecl *FirstQualifierInScope,
1585  bool AllowInjectedClassName) {
1586  if (TemplateTemplateParmDecl *TTP
1587  = dyn_cast_or_null<TemplateTemplateParmDecl>(Name.getAsTemplateDecl())) {
1588  if (TTP->getDepth() < TemplateArgs.getNumLevels()) {
1589  // If the corresponding template argument is NULL or non-existent, it's
1590  // because we are performing instantiation from explicitly-specified
1591  // template arguments in a function template, but there were some
1592  // arguments left unspecified.
1593  if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(),
1594  TTP->getPosition()))
1595  return Name;
1596 
1597  TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());
1598 
1599  if (TemplateArgs.isRewrite()) {
1600  // We're rewriting the template parameter as a reference to another
1601  // template parameter.
1602  if (Arg.getKind() == TemplateArgument::Pack) {
1603  assert(Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() &&
1604  "unexpected pack arguments in template rewrite");
1605  Arg = Arg.pack_begin()->getPackExpansionPattern();
1606  }
1607  assert(Arg.getKind() == TemplateArgument::Template &&
1608  "unexpected nontype template argument kind in template rewrite");
1609  return Arg.getAsTemplate();
1610  }
1611 
1612  auto [AssociatedDecl, Final] =
1613  TemplateArgs.getAssociatedDecl(TTP->getDepth());
1614  Optional<unsigned> PackIndex;
1615  if (TTP->isParameterPack()) {
1616  assert(Arg.getKind() == TemplateArgument::Pack &&
1617  "Missing argument pack");
1618 
1619  if (getSema().ArgumentPackSubstitutionIndex == -1) {
1620  // We have the template argument pack to substitute, but we're not
1621  // actually expanding the enclosing pack expansion yet. So, just
1622  // keep the entire argument pack.
1623  return getSema().Context.getSubstTemplateTemplateParmPack(
1624  Arg, AssociatedDecl, TTP->getIndex(), Final);
1625  }
1626 
1627  PackIndex = getPackIndex(Arg);
1628  Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1629  }
1630 
1631  TemplateName Template = Arg.getAsTemplate().getNameToSubstitute();
1632  assert(!Template.isNull() && "Null template template argument");
1633  assert(!Template.getAsQualifiedTemplateName() &&
1634  "template decl to substitute is qualified?");
1635 
1636  if (Final)
1637  return Template;
1638  return getSema().Context.getSubstTemplateTemplateParm(
1639  Template, AssociatedDecl, TTP->getIndex(), PackIndex);
1640  }
1641  }
1642 
1644  = Name.getAsSubstTemplateTemplateParmPack()) {
1645  if (getSema().ArgumentPackSubstitutionIndex == -1)
1646  return Name;
1647 
1648  TemplateArgument Pack = SubstPack->getArgumentPack();
1649  TemplateName Template =
1651  if (SubstPack->getFinal())
1652  return Template;
1653  return getSema().Context.getSubstTemplateTemplateParm(
1654  Template.getNameToSubstitute(), SubstPack->getAssociatedDecl(),
1655  SubstPack->getIndex(), getPackIndex(Pack));
1656  }
1657 
1658  return inherited::TransformTemplateName(SS, Name, NameLoc, ObjectType,
1659  FirstQualifierInScope,
1660  AllowInjectedClassName);
1661 }
1662 
1663 ExprResult
1664 TemplateInstantiator::TransformPredefinedExpr(PredefinedExpr *E) {
1665  if (!E->isTypeDependent())
1666  return E;
1667 
1668  return getSema().BuildPredefinedExpr(E->getLocation(), E->getIdentKind());
1669 }
1670 
1671 ExprResult
1672 TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E,
1673  NonTypeTemplateParmDecl *NTTP) {
1674  // If the corresponding template argument is NULL or non-existent, it's
1675  // because we are performing instantiation from explicitly-specified
1676  // template arguments in a function template, but there were some
1677  // arguments left unspecified.
1678  if (!TemplateArgs.hasTemplateArgument(NTTP->getDepth(),
1679  NTTP->getPosition()))
1680  return E;
1681 
1682  TemplateArgument Arg = TemplateArgs(NTTP->getDepth(), NTTP->getPosition());
1683 
1684  if (TemplateArgs.isRewrite()) {
1685  // We're rewriting the template parameter as a reference to another
1686  // template parameter.
1687  if (Arg.getKind() == TemplateArgument::Pack) {
1688  assert(Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() &&
1689  "unexpected pack arguments in template rewrite");
1690  Arg = Arg.pack_begin()->getPackExpansionPattern();
1691  }
1692  assert(Arg.getKind() == TemplateArgument::Expression &&
1693  "unexpected nontype template argument kind in template rewrite");
1694  // FIXME: This can lead to the same subexpression appearing multiple times
1695  // in a complete expression.
1696  return Arg.getAsExpr();
1697  }
1698 
1699  auto [AssociatedDecl, _] = TemplateArgs.getAssociatedDecl(NTTP->getDepth());
1700  Optional<unsigned> PackIndex;
1701  if (NTTP->isParameterPack()) {
1702  assert(Arg.getKind() == TemplateArgument::Pack &&
1703  "Missing argument pack");
1704 
1705  if (getSema().ArgumentPackSubstitutionIndex == -1) {
1706  // We have an argument pack, but we can't select a particular argument
1707  // out of it yet. Therefore, we'll build an expression to hold on to that
1708  // argument pack.
1709  QualType TargetType = SemaRef.SubstType(NTTP->getType(), TemplateArgs,
1710  E->getLocation(),
1711  NTTP->getDeclName());
1712  if (TargetType.isNull())
1713  return ExprError();
1714 
1715  QualType ExprType = TargetType.getNonLValueExprType(SemaRef.Context);
1716  if (TargetType->isRecordType())
1717  ExprType.addConst();
1718  // FIXME: Pass in Final.
1719  return new (SemaRef.Context) SubstNonTypeTemplateParmPackExpr(
1720  ExprType, TargetType->isReferenceType() ? VK_LValue : VK_PRValue,
1721  E->getLocation(), Arg, AssociatedDecl, NTTP->getPosition());
1722  }
1723  PackIndex = getPackIndex(Arg);
1724  Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1725  }
1726  // FIXME: Don't put subst node on Final replacement.
1727  return transformNonTypeTemplateParmRef(AssociatedDecl, NTTP, E->getLocation(),
1728  Arg, PackIndex);
1729 }
1730 
1731 const LoopHintAttr *
1732 TemplateInstantiator::TransformLoopHintAttr(const LoopHintAttr *LH) {
1733  Expr *TransformedExpr = getDerived().TransformExpr(LH->getValue()).get();
1734 
1735  if (TransformedExpr == LH->getValue())
1736  return LH;
1737 
1738  // Generate error if there is a problem with the value.
1739  if (getSema().CheckLoopHintExpr(TransformedExpr, LH->getLocation()))
1740  return LH;
1741 
1742  // Create new LoopHintValueAttr with integral expression in place of the
1743  // non-type template parameter.
1744  return LoopHintAttr::CreateImplicit(getSema().Context, LH->getOption(),
1745  LH->getState(), TransformedExpr, *LH);
1746 }
1747 
1748 ExprResult TemplateInstantiator::transformNonTypeTemplateParmRef(
1749  Decl *AssociatedDecl, const NonTypeTemplateParmDecl *parm,
1751  ExprResult result;
1752 
1753  // Determine the substituted parameter type. We can usually infer this from
1754  // the template argument, but not always.
1755  auto SubstParamType = [&] {
1756  QualType T;
1757  if (parm->isExpandedParameterPack())
1759  else
1760  T = parm->getType();
1761  if (parm->isParameterPack() && isa<PackExpansionType>(T))
1762  T = cast<PackExpansionType>(T)->getPattern();
1763  return SemaRef.SubstType(T, TemplateArgs, loc, parm->getDeclName());
1764  };
1765 
1766  bool refParam = false;
1767 
1768  // The template argument itself might be an expression, in which case we just
1769  // return that expression. This happens when substituting into an alias
1770  // template.
1771  if (arg.getKind() == TemplateArgument::Expression) {
1772  Expr *argExpr = arg.getAsExpr();
1773  result = argExpr;
1774  if (argExpr->isLValue()) {
1775  if (argExpr->getType()->isRecordType()) {
1776  // Check whether the parameter was actually a reference.
1777  QualType paramType = SubstParamType();
1778  if (paramType.isNull())
1779  return ExprError();
1780  refParam = paramType->isReferenceType();
1781  } else {
1782  refParam = true;
1783  }
1784  }
1785  } else if (arg.getKind() == TemplateArgument::Declaration ||
1786  arg.getKind() == TemplateArgument::NullPtr) {
1787  ValueDecl *VD;
1788  if (arg.getKind() == TemplateArgument::Declaration) {
1789  VD = arg.getAsDecl();
1790 
1791  // Find the instantiation of the template argument. This is
1792  // required for nested templates.
1793  VD = cast_or_null<ValueDecl>(
1794  getSema().FindInstantiatedDecl(loc, VD, TemplateArgs));
1795  if (!VD)
1796  return ExprError();
1797  } else {
1798  // Propagate NULL template argument.
1799  VD = nullptr;
1800  }
1801 
1802  QualType paramType = VD ? arg.getParamTypeForDecl() : arg.getNullPtrType();
1803  assert(!paramType.isNull() && "type substitution failed for param type");
1804  assert(!paramType->isDependentType() && "param type still dependent");
1805  result = SemaRef.BuildExpressionFromDeclTemplateArgument(arg, paramType, loc);
1806  refParam = paramType->isReferenceType();
1807  } else {
1808  result = SemaRef.BuildExpressionFromIntegralTemplateArgument(arg, loc);
1809  assert(result.isInvalid() ||
1810  SemaRef.Context.hasSameType(result.get()->getType(),
1811  arg.getIntegralType()));
1812  }
1813 
1814  if (result.isInvalid())
1815  return ExprError();
1816 
1817  Expr *resultExpr = result.get();
1818  // FIXME: Don't put subst node on final replacement.
1819  return new (SemaRef.Context) SubstNonTypeTemplateParmExpr(
1820  resultExpr->getType(), resultExpr->getValueKind(), loc, resultExpr,
1821  AssociatedDecl, parm->getIndex(), PackIndex, refParam);
1822 }
1823 
1824 ExprResult
1825 TemplateInstantiator::TransformSubstNonTypeTemplateParmPackExpr(
1827  if (getSema().ArgumentPackSubstitutionIndex == -1) {
1828  // We aren't expanding the parameter pack, so just return ourselves.
1829  return E;
1830  }
1831 
1832  TemplateArgument Pack = E->getArgumentPack();
1834  // FIXME: Don't put subst node on final replacement.
1835  return transformNonTypeTemplateParmRef(
1837  E->getParameterPackLocation(), Arg, getPackIndex(Pack));
1838 }
1839 
1840 ExprResult
1841 TemplateInstantiator::TransformSubstNonTypeTemplateParmExpr(
1843  ExprResult SubstReplacement = E->getReplacement();
1844  if (!isa<ConstantExpr>(SubstReplacement.get()))
1845  SubstReplacement = TransformExpr(E->getReplacement());
1846  if (SubstReplacement.isInvalid())
1847  return true;
1848  QualType SubstType = TransformType(E->getParameterType(getSema().Context));
1849  if (SubstType.isNull())
1850  return true;
1851  // The type may have been previously dependent and not now, which means we
1852  // might have to implicit cast the argument to the new type, for example:
1853  // template<auto T, decltype(T) U>
1854  // concept C = sizeof(U) == 4;
1855  // void foo() requires C<2, 'a'> { }
1856  // When normalizing foo(), we first form the normalized constraints of C:
1857  // AtomicExpr(sizeof(U) == 4,
1858  // U=SubstNonTypeTemplateParmExpr(Param=U,
1859  // Expr=DeclRef(U),
1860  // Type=decltype(T)))
1861  // Then we substitute T = 2, U = 'a' into the parameter mapping, and need to
1862  // produce:
1863  // AtomicExpr(sizeof(U) == 4,
1864  // U=SubstNonTypeTemplateParmExpr(Param=U,
1865  // Expr=ImpCast(
1866  // decltype(2),
1867  // SubstNTTPE(Param=U, Expr='a',
1868  // Type=char)),
1869  // Type=decltype(2)))
1870  // The call to CheckTemplateArgument here produces the ImpCast.
1871  TemplateArgument SugaredConverted, CanonicalConverted;
1872  if (SemaRef
1874  SubstReplacement.get(), SugaredConverted,
1875  CanonicalConverted, Sema::CTAK_Specified)
1876  .isInvalid())
1877  return true;
1878  return transformNonTypeTemplateParmRef(E->getAssociatedDecl(),
1879  E->getParameter(), E->getExprLoc(),
1880  SugaredConverted, E->getPackIndex());
1881 }
1882 
1883 ExprResult TemplateInstantiator::RebuildVarDeclRefExpr(VarDecl *PD,
1884  SourceLocation Loc) {
1885  DeclarationNameInfo NameInfo(PD->getDeclName(), Loc);
1886  return getSema().BuildDeclarationNameExpr(CXXScopeSpec(), NameInfo, PD);
1887 }
1888 
1889 ExprResult
1890 TemplateInstantiator::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
1891  if (getSema().ArgumentPackSubstitutionIndex != -1) {
1892  // We can expand this parameter pack now.
1894  VarDecl *VD = cast_or_null<VarDecl>(TransformDecl(E->getExprLoc(), D));
1895  if (!VD)
1896  return ExprError();
1897  return RebuildVarDeclRefExpr(VD, E->getExprLoc());
1898  }
1899 
1900  QualType T = TransformType(E->getType());
1901  if (T.isNull())
1902  return ExprError();
1903 
1904  // Transform each of the parameter expansions into the corresponding
1905  // parameters in the instantiation of the function decl.
1907  Vars.reserve(E->getNumExpansions());
1908  for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end();
1909  I != End; ++I) {
1910  VarDecl *D = cast_or_null<VarDecl>(TransformDecl(E->getExprLoc(), *I));
1911  if (!D)
1912  return ExprError();
1913  Vars.push_back(D);
1914  }
1915 
1916  auto *PackExpr =
1918  E->getParameterPackLocation(), Vars);
1919  getSema().MarkFunctionParmPackReferenced(PackExpr);
1920  return PackExpr;
1921 }
1922 
1923 ExprResult
1924 TemplateInstantiator::TransformFunctionParmPackRefExpr(DeclRefExpr *E,
1925  VarDecl *PD) {
1926  typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
1927  llvm::PointerUnion<Decl *, DeclArgumentPack *> *Found
1928  = getSema().CurrentInstantiationScope->findInstantiationOf(PD);
1929  assert(Found && "no instantiation for parameter pack");
1930 
1931  Decl *TransformedDecl;
1932  if (DeclArgumentPack *Pack = Found->dyn_cast<DeclArgumentPack *>()) {
1933  // If this is a reference to a function parameter pack which we can
1934  // substitute but can't yet expand, build a FunctionParmPackExpr for it.
1935  if (getSema().ArgumentPackSubstitutionIndex == -1) {
1936  QualType T = TransformType(E->getType());
1937  if (T.isNull())
1938  return ExprError();
1939  auto *PackExpr = FunctionParmPackExpr::Create(getSema().Context, T, PD,
1940  E->getExprLoc(), *Pack);
1941  getSema().MarkFunctionParmPackReferenced(PackExpr);
1942  return PackExpr;
1943  }
1944 
1945  TransformedDecl = (*Pack)[getSema().ArgumentPackSubstitutionIndex];
1946  } else {
1947  TransformedDecl = Found->get<Decl*>();
1948  }
1949 
1950  // We have either an unexpanded pack or a specific expansion.
1951  return RebuildVarDeclRefExpr(cast<VarDecl>(TransformedDecl), E->getExprLoc());
1952 }
1953 
1954 ExprResult
1955 TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) {
1956  NamedDecl *D = E->getDecl();
1957 
1958  // Handle references to non-type template parameters and non-type template
1959  // parameter packs.
1960  if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
1961  if (NTTP->getDepth() < TemplateArgs.getNumLevels())
1962  return TransformTemplateParmRefExpr(E, NTTP);
1963 
1964  // We have a non-type template parameter that isn't fully substituted;
1965  // FindInstantiatedDecl will find it in the local instantiation scope.
1966  }
1967 
1968  // Handle references to function parameter packs.
1969  if (VarDecl *PD = dyn_cast<VarDecl>(D))
1970  if (PD->isParameterPack())
1971  return TransformFunctionParmPackRefExpr(E, PD);
1972 
1973  return inherited::TransformDeclRefExpr(E);
1974 }
1975 
1976 ExprResult TemplateInstantiator::TransformCXXDefaultArgExpr(
1977  CXXDefaultArgExpr *E) {
1978  assert(!cast<FunctionDecl>(E->getParam()->getDeclContext())->
1979  getDescribedFunctionTemplate() &&
1980  "Default arg expressions are never formed in dependent cases.");
1981  return SemaRef.BuildCXXDefaultArgExpr(E->getUsedLocation(),
1982  cast<FunctionDecl>(E->getParam()->getDeclContext()),
1983  E->getParam());
1984 }
1985 
1986 template<typename Fn>
1987 QualType TemplateInstantiator::TransformFunctionProtoType(TypeLocBuilder &TLB,
1989  CXXRecordDecl *ThisContext,
1990  Qualifiers ThisTypeQuals,
1991  Fn TransformExceptionSpec) {
1992  // We need a local instantiation scope for this function prototype.
1993  LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true);
1994  return inherited::TransformFunctionProtoType(
1995  TLB, TL, ThisContext, ThisTypeQuals, TransformExceptionSpec);
1996 }
1997 
1998 ParmVarDecl *
1999 TemplateInstantiator::TransformFunctionTypeParam(ParmVarDecl *OldParm,
2000  int indexAdjustment,
2001  Optional<unsigned> NumExpansions,
2002  bool ExpectParameterPack) {
2003  auto NewParm = SemaRef.SubstParmVarDecl(
2004  OldParm, TemplateArgs, indexAdjustment, NumExpansions,
2005  ExpectParameterPack, EvaluateConstraints);
2006  if (NewParm && SemaRef.getLangOpts().OpenCL)
2007  SemaRef.deduceOpenCLAddressSpace(NewParm);
2008  return NewParm;
2009 }
2010 
2011 QualType TemplateInstantiator::BuildSubstTemplateTypeParmType(
2012  TypeLocBuilder &TLB, bool SuppressObjCLifetime, bool Final,
2013  Decl *AssociatedDecl, unsigned Index, Optional<unsigned> PackIndex,
2014  TemplateArgument Arg, SourceLocation NameLoc) {
2015  QualType Replacement = Arg.getAsType();
2016 
2017  // If the template parameter had ObjC lifetime qualifiers,
2018  // then any such qualifiers on the replacement type are ignored.
2019  if (SuppressObjCLifetime) {
2020  Qualifiers RQs;
2021  RQs = Replacement.getQualifiers();
2022  RQs.removeObjCLifetime();
2023  Replacement =
2024  SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), RQs);
2025  }
2026 
2027  if (Final) {
2028  TLB.pushTrivial(SemaRef.Context, Replacement, NameLoc);
2029  return Replacement;
2030  }
2031  // TODO: only do this uniquing once, at the start of instantiation.
2032  QualType Result = getSema().Context.getSubstTemplateTypeParmType(
2033  Replacement, AssociatedDecl, Index, PackIndex);
2035  TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
2036  NewTL.setNameLoc(NameLoc);
2037  return Result;
2038 }
2039 
2040 QualType
2041 TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB,
2043  bool SuppressObjCLifetime) {
2044  const TemplateTypeParmType *T = TL.getTypePtr();
2045  if (T->getDepth() < TemplateArgs.getNumLevels()) {
2046  // Replace the template type parameter with its corresponding
2047  // template argument.
2048 
2049  // If the corresponding template argument is NULL or doesn't exist, it's
2050  // because we are performing instantiation from explicitly-specified
2051  // template arguments in a function template class, but there were some
2052  // arguments left unspecified.
2053  if (!TemplateArgs.hasTemplateArgument(T->getDepth(), T->getIndex())) {
2055  = TLB.push<TemplateTypeParmTypeLoc>(TL.getType());
2056  NewTL.setNameLoc(TL.getNameLoc());
2057  return TL.getType();
2058  }
2059 
2060  TemplateArgument Arg = TemplateArgs(T->getDepth(), T->getIndex());
2061 
2062  if (TemplateArgs.isRewrite()) {
2063  // We're rewriting the template parameter as a reference to another
2064  // template parameter.
2065  if (Arg.getKind() == TemplateArgument::Pack) {
2066  assert(Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() &&
2067  "unexpected pack arguments in template rewrite");
2068  Arg = Arg.pack_begin()->getPackExpansionPattern();
2069  }
2070  assert(Arg.getKind() == TemplateArgument::Type &&
2071  "unexpected nontype template argument kind in template rewrite");
2072  QualType NewT = Arg.getAsType();
2073  assert(isa<TemplateTypeParmType>(NewT) &&
2074  "type parm not rewritten to type parm");
2075  auto NewTL = TLB.push<TemplateTypeParmTypeLoc>(NewT);
2076  NewTL.setNameLoc(TL.getNameLoc());
2077  return NewT;
2078  }
2079 
2080  auto [AssociatedDecl, Final] =
2081  TemplateArgs.getAssociatedDecl(T->getDepth());
2082  Optional<unsigned> PackIndex;
2083  if (T->isParameterPack()) {
2084  assert(Arg.getKind() == TemplateArgument::Pack &&
2085  "Missing argument pack");
2086 
2087  if (getSema().ArgumentPackSubstitutionIndex == -1) {
2088  // We have the template argument pack, but we're not expanding the
2089  // enclosing pack expansion yet. Just save the template argument
2090  // pack for later substitution.
2091  QualType Result = getSema().Context.getSubstTemplateTypeParmPackType(
2092  AssociatedDecl, T->getIndex(), Final, Arg);
2094  = TLB.push<SubstTemplateTypeParmPackTypeLoc>(Result);
2095  NewTL.setNameLoc(TL.getNameLoc());
2096  return Result;
2097  }
2098 
2099  // PackIndex starts from last element.
2100  PackIndex = getPackIndex(Arg);
2101  Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
2102  }
2103 
2104  assert(Arg.getKind() == TemplateArgument::Type &&
2105  "Template argument kind mismatch");
2106 
2107  return BuildSubstTemplateTypeParmType(TLB, SuppressObjCLifetime, Final,
2108  AssociatedDecl, T->getIndex(),
2109  PackIndex, Arg, TL.getNameLoc());
2110  }
2111 
2112  // The template type parameter comes from an inner template (e.g.,
2113  // the template parameter list of a member template inside the
2114  // template we are instantiating). Create a new template type
2115  // parameter with the template "level" reduced by one.
2116  TemplateTypeParmDecl *NewTTPDecl = nullptr;
2117  if (TemplateTypeParmDecl *OldTTPDecl = T->getDecl())
2118  NewTTPDecl = cast_or_null<TemplateTypeParmDecl>(
2119  TransformDecl(TL.getNameLoc(), OldTTPDecl));
2120  QualType Result = getSema().Context.getTemplateTypeParmType(
2121  T->getDepth() - TemplateArgs.getNumSubstitutedLevels(), T->getIndex(),
2122  T->isParameterPack(), NewTTPDecl);
2124  NewTL.setNameLoc(TL.getNameLoc());
2125  return Result;
2126 }
2127 
2128 QualType TemplateInstantiator::TransformSubstTemplateTypeParmPackType(
2130  bool SuppressObjCLifetime) {
2131  const SubstTemplateTypeParmPackType *T = TL.getTypePtr();
2132 
2133  Decl *NewReplaced = TransformDecl(TL.getNameLoc(), T->getAssociatedDecl());
2134 
2135  if (getSema().ArgumentPackSubstitutionIndex == -1) {
2136  // We aren't expanding the parameter pack, so just return ourselves.
2137  QualType Result = TL.getType();
2138  if (NewReplaced != T->getAssociatedDecl())
2139  Result = getSema().Context.getSubstTemplateTypeParmPackType(
2140  NewReplaced, T->getIndex(), T->getFinal(), T->getArgumentPack());
2143  NewTL.setNameLoc(TL.getNameLoc());
2144  return Result;
2145  }
2146 
2147  TemplateArgument Pack = T->getArgumentPack();
2149  return BuildSubstTemplateTypeParmType(
2150  TLB, SuppressObjCLifetime, T->getFinal(), NewReplaced, T->getIndex(),
2151  getPackIndex(Pack), Arg, TL.getNameLoc());
2152 }
2153 
2154 template<typename EntityPrinter>
2156 createSubstDiag(Sema &S, TemplateDeductionInfo &Info, EntityPrinter Printer) {
2157  SmallString<128> Message;
2158  SourceLocation ErrorLoc;
2159  if (Info.hasSFINAEDiagnostic()) {
2162  Info.takeSFINAEDiagnostic(PDA);
2163  PDA.second.EmitToString(S.getDiagnostics(), Message);
2164  ErrorLoc = PDA.first;
2165  } else {
2166  ErrorLoc = Info.getLocation();
2167  }
2168  char *MessageBuf = new (S.Context) char[Message.size()];
2169  std::copy(Message.begin(), Message.end(), MessageBuf);
2170  SmallString<128> Entity;
2171  llvm::raw_svector_ostream OS(Entity);
2172  Printer(OS);
2173  char *EntityBuf = new (S.Context) char[Entity.size()];
2174  std::copy(Entity.begin(), Entity.end(), EntityBuf);
2176  StringRef(EntityBuf, Entity.size()), ErrorLoc,
2177  StringRef(MessageBuf, Message.size())};
2178 }
2179 
2180 ExprResult TemplateInstantiator::TransformRequiresTypeParams(
2181  SourceLocation KWLoc, SourceLocation RBraceLoc, const RequiresExpr *RE,
2183  SmallVectorImpl<QualType> &PTypes,
2184  SmallVectorImpl<ParmVarDecl *> &TransParams,
2186 
2187  TemplateDeductionInfo Info(KWLoc);
2188  Sema::InstantiatingTemplate TypeInst(SemaRef, KWLoc,
2189  RE, Info,
2190  SourceRange{KWLoc, RBraceLoc});
2191  Sema::SFINAETrap Trap(SemaRef);
2192 
2193  unsigned ErrorIdx;
2194  if (getDerived().TransformFunctionTypeParams(
2195  KWLoc, Params, /*ParamTypes=*/nullptr, /*ParamInfos=*/nullptr, PTypes,
2196  &TransParams, PInfos, &ErrorIdx) ||
2197  Trap.hasErrorOccurred()) {
2199  ParmVarDecl *FailedDecl = Params[ErrorIdx];
2200  // Add a 'failed' Requirement to contain the error that caused the failure
2201  // here.
2202  TransReqs.push_back(RebuildTypeRequirement(createSubstDiag(
2203  SemaRef, Info, [&](llvm::raw_ostream &OS) { OS << *FailedDecl; })));
2204  return getDerived().RebuildRequiresExpr(KWLoc, Body, TransParams, TransReqs,
2205  RBraceLoc);
2206  }
2207 
2208  return ExprResult{};
2209 }
2210 
2212 TemplateInstantiator::TransformTypeRequirement(concepts::TypeRequirement *Req) {
2213  if (!Req->isDependent() && !AlwaysRebuild())
2214  return Req;
2215  if (Req->isSubstitutionFailure()) {
2216  if (AlwaysRebuild())
2217  return RebuildTypeRequirement(
2218  Req->getSubstitutionDiagnostic());
2219  return Req;
2220  }
2221 
2222  Sema::SFINAETrap Trap(SemaRef);
2224  Sema::InstantiatingTemplate TypeInst(SemaRef,
2225  Req->getType()->getTypeLoc().getBeginLoc(), Req, Info,
2226  Req->getType()->getTypeLoc().getSourceRange());
2227  if (TypeInst.isInvalid())
2228  return nullptr;
2229  TypeSourceInfo *TransType = TransformType(Req->getType());
2230  if (!TransType || Trap.hasErrorOccurred())
2231  return RebuildTypeRequirement(createSubstDiag(SemaRef, Info,
2232  [&] (llvm::raw_ostream& OS) {
2233  Req->getType()->getType().print(OS, SemaRef.getPrintingPolicy());
2234  }));
2235  return RebuildTypeRequirement(TransType);
2236 }
2237 
2239 TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) {
2240  if (!Req->isDependent() && !AlwaysRebuild())
2241  return Req;
2242 
2243  Sema::SFINAETrap Trap(SemaRef);
2244 
2245  llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *>
2246  TransExpr;
2247  if (Req->isExprSubstitutionFailure())
2248  TransExpr = Req->getExprSubstitutionDiagnostic();
2249  else {
2250  Expr *E = Req->getExpr();
2252  Sema::InstantiatingTemplate ExprInst(SemaRef, E->getBeginLoc(), Req, Info,
2253  E->getSourceRange());
2254  if (ExprInst.isInvalid())
2255  return nullptr;
2256  ExprResult TransExprRes = TransformExpr(E);
2257  if (!TransExprRes.isInvalid() && !Trap.hasErrorOccurred() &&
2258  TransExprRes.get()->hasPlaceholderType())
2259  TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get());
2260  if (TransExprRes.isInvalid() || Trap.hasErrorOccurred())
2261  TransExpr = createSubstDiag(SemaRef, Info, [&](llvm::raw_ostream &OS) {
2262  E->printPretty(OS, nullptr, SemaRef.getPrintingPolicy());
2263  });
2264  else
2265  TransExpr = TransExprRes.get();
2266  }
2267 
2269  const auto &RetReq = Req->getReturnTypeRequirement();
2270  if (RetReq.isEmpty())
2271  TransRetReq.emplace();
2272  else if (RetReq.isSubstitutionFailure())
2273  TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
2274  else if (RetReq.isTypeConstraint()) {
2275  TemplateParameterList *OrigTPL =
2276  RetReq.getTypeConstraintTemplateParameterList();
2277  TemplateDeductionInfo Info(OrigTPL->getTemplateLoc());
2278  Sema::InstantiatingTemplate TPLInst(SemaRef, OrigTPL->getTemplateLoc(),
2279  Req, Info, OrigTPL->getSourceRange());
2280  if (TPLInst.isInvalid())
2281  return nullptr;
2282  TemplateParameterList *TPL = TransformTemplateParameterList(OrigTPL);
2283  if (!TPL)
2284  TransRetReq.emplace(createSubstDiag(SemaRef, Info,
2285  [&] (llvm::raw_ostream& OS) {
2286  RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint()
2287  ->printPretty(OS, nullptr, SemaRef.getPrintingPolicy());
2288  }));
2289  else {
2290  TPLInst.Clear();
2291  TransRetReq.emplace(TPL);
2292  }
2293  }
2294  assert(TransRetReq && "All code paths leading here must set TransRetReq");
2295  if (Expr *E = TransExpr.dyn_cast<Expr *>())
2296  return RebuildExprRequirement(E, Req->isSimple(), Req->getNoexceptLoc(),
2297  std::move(*TransRetReq));
2298  return RebuildExprRequirement(
2300  Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
2301 }
2302 
2304 TemplateInstantiator::TransformNestedRequirement(
2306  if (!Req->isDependent() && !AlwaysRebuild())
2307  return Req;
2308  if (Req->isSubstitutionFailure()) {
2309  if (AlwaysRebuild())
2310  return RebuildNestedRequirement(
2311  Req->getSubstitutionDiagnostic());
2312  return Req;
2313  }
2314  Sema::InstantiatingTemplate ReqInst(SemaRef,
2315  Req->getConstraintExpr()->getBeginLoc(), Req,
2317  Req->getConstraintExpr()->getSourceRange());
2318 
2319  ExprResult TransConstraint;
2320  ConstraintSatisfaction Satisfaction;
2322  {
2325  Sema::SFINAETrap Trap(SemaRef);
2326  Sema::InstantiatingTemplate ConstrInst(SemaRef,
2327  Req->getConstraintExpr()->getBeginLoc(), Req, Info,
2328  Req->getConstraintExpr()->getSourceRange());
2329  if (ConstrInst.isInvalid())
2330  return nullptr;
2331  TransConstraint = TransformExpr(Req->getConstraintExpr());
2332  if (!TransConstraint.isInvalid()) {
2333  bool CheckSucceeded =
2334  SemaRef.CheckConstraintExpression(TransConstraint.get());
2335  (void)CheckSucceeded;
2336  assert((CheckSucceeded || Trap.hasErrorOccurred()) &&
2337  "CheckConstraintExpression failed, but "
2338  "did not produce a SFINAE error");
2339  }
2340  // Use version of CheckConstraintSatisfaction that does no substitutions.
2341  if (!TransConstraint.isInvalid() &&
2342  !TransConstraint.get()->isInstantiationDependent() &&
2343  !Trap.hasErrorOccurred()) {
2344  bool CheckFailed = SemaRef.CheckConstraintSatisfaction(
2345  TransConstraint.get(), Satisfaction);
2346  (void)CheckFailed;
2347  assert((!CheckFailed || Trap.hasErrorOccurred()) &&
2348  "CheckConstraintSatisfaction failed, "
2349  "but did not produce a SFINAE error");
2350  }
2351  if (TransConstraint.isInvalid() || Trap.hasErrorOccurred())
2352  return RebuildNestedRequirement(createSubstDiag(SemaRef, Info,
2353  [&] (llvm::raw_ostream& OS) {
2354  Req->getConstraintExpr()->printPretty(OS, nullptr,
2355  SemaRef.getPrintingPolicy());
2356  }));
2357  }
2358  if (TransConstraint.get()->isInstantiationDependent())
2359  return new (SemaRef.Context)
2360  concepts::NestedRequirement(TransConstraint.get());
2361  return new (SemaRef.Context) concepts::NestedRequirement(
2362  SemaRef.Context, TransConstraint.get(), Satisfaction);
2363 }
2364 
2365 
2366 /// Perform substitution on the type T with a given set of template
2367 /// arguments.
2368 ///
2369 /// This routine substitutes the given template arguments into the
2370 /// type T and produces the instantiated type.
2371 ///
2372 /// \param T the type into which the template arguments will be
2373 /// substituted. If this type is not dependent, it will be returned
2374 /// immediately.
2375 ///
2376 /// \param Args the template arguments that will be
2377 /// substituted for the top-level template parameters within T.
2378 ///
2379 /// \param Loc the location in the source code where this substitution
2380 /// is being performed. It will typically be the location of the
2381 /// declarator (if we're instantiating the type of some declaration)
2382 /// or the location of the type in the source code (if, e.g., we're
2383 /// instantiating the type of a cast expression).
2384 ///
2385 /// \param Entity the name of the entity associated with a declaration
2386 /// being instantiated (if any). May be empty to indicate that there
2387 /// is no such entity (if, e.g., this is a type that occurs as part of
2388 /// a cast expression) or that the entity has no name (e.g., an
2389 /// unnamed function parameter).
2390 ///
2391 /// \param AllowDeducedTST Whether a DeducedTemplateSpecializationType is
2392 /// acceptable as the top level type of the result.
2393 ///
2394 /// \returns If the instantiation succeeds, the instantiated
2395 /// type. Otherwise, produces diagnostics and returns a NULL type.
2397  const MultiLevelTemplateArgumentList &Args,
2398  SourceLocation Loc,
2399  DeclarationName Entity,
2400  bool AllowDeducedTST) {
2401  assert(!CodeSynthesisContexts.empty() &&
2402  "Cannot perform an instantiation without some context on the "
2403  "instantiation stack");
2404 
2405  if (!T->getType()->isInstantiationDependentType() &&
2407  return T;
2408 
2409  TemplateInstantiator Instantiator(*this, Args, Loc, Entity);
2410  return AllowDeducedTST ? Instantiator.TransformTypeWithDeducedTST(T)
2411  : Instantiator.TransformType(T);
2412 }
2413 
2415  const MultiLevelTemplateArgumentList &Args,
2416  SourceLocation Loc,
2417  DeclarationName Entity) {
2418  assert(!CodeSynthesisContexts.empty() &&
2419  "Cannot perform an instantiation without some context on the "
2420  "instantiation stack");
2421 
2422  if (TL.getType().isNull())
2423  return nullptr;
2424 
2425  if (!TL.getType()->isInstantiationDependentType() &&
2426  !TL.getType()->isVariablyModifiedType()) {
2427  // FIXME: Make a copy of the TypeLoc data here, so that we can
2428  // return a new TypeSourceInfo. Inefficient!
2429  TypeLocBuilder TLB;
2430  TLB.pushFullCopy(TL);
2431  return TLB.getTypeSourceInfo(Context, TL.getType());
2432  }
2433 
2434  TemplateInstantiator Instantiator(*this, Args, Loc, Entity);
2435  TypeLocBuilder TLB;
2436  TLB.reserve(TL.getFullDataSize());
2437  QualType Result = Instantiator.TransformType(TLB, TL);
2438  if (Result.isNull())
2439  return nullptr;
2440 
2441  return TLB.getTypeSourceInfo(Context, Result);
2442 }
2443 
2444 /// Deprecated form of the above.
2446  const MultiLevelTemplateArgumentList &TemplateArgs,
2447  SourceLocation Loc, DeclarationName Entity) {
2448  assert(!CodeSynthesisContexts.empty() &&
2449  "Cannot perform an instantiation without some context on the "
2450  "instantiation stack");
2451 
2452  // If T is not a dependent type or a variably-modified type, there
2453  // is nothing to do.
2455  return T;
2456 
2457  TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity);
2458  return Instantiator.TransformType(T);
2459 }
2460 
2462  if (T->getType()->isInstantiationDependentType() ||
2464  return true;
2465 
2466  TypeLoc TL = T->getTypeLoc().IgnoreParens();
2467  if (!TL.getAs<FunctionProtoTypeLoc>())
2468  return false;
2469 
2471  for (ParmVarDecl *P : FP.getParams()) {
2472  // This must be synthesized from a typedef.
2473  if (!P) continue;
2474 
2475  // If there are any parameters, a new TypeSourceInfo that refers to the
2476  // instantiated parameters must be built.
2477  return true;
2478  }
2479 
2480  return false;
2481 }
2482 
2483 /// A form of SubstType intended specifically for instantiating the
2484 /// type of a FunctionDecl. Its purpose is solely to force the
2485 /// instantiation of default-argument expressions and to avoid
2486 /// instantiating an exception-specification.
2488  const MultiLevelTemplateArgumentList &Args,
2489  SourceLocation Loc,
2490  DeclarationName Entity,
2491  CXXRecordDecl *ThisContext,
2492  Qualifiers ThisTypeQuals,
2493  bool EvaluateConstraints) {
2494  assert(!CodeSynthesisContexts.empty() &&
2495  "Cannot perform an instantiation without some context on the "
2496  "instantiation stack");
2497 
2499  return T;
2500 
2501  TemplateInstantiator Instantiator(*this, Args, Loc, Entity);
2502  Instantiator.setEvaluateConstraints(EvaluateConstraints);
2503 
2504  TypeLocBuilder TLB;
2505 
2506  TypeLoc TL = T->getTypeLoc();
2507  TLB.reserve(TL.getFullDataSize());
2508 
2509  QualType Result;
2510 
2511  if (FunctionProtoTypeLoc Proto =
2513  // Instantiate the type, other than its exception specification. The
2514  // exception specification is instantiated in InitFunctionInstantiation
2515  // once we've built the FunctionDecl.
2516  // FIXME: Set the exception specification to EST_Uninstantiated here,
2517  // instead of rebuilding the function type again later.
2518  Result = Instantiator.TransformFunctionProtoType(
2519  TLB, Proto, ThisContext, ThisTypeQuals,
2521  bool &Changed) { return false; });
2522  } else {
2523  Result = Instantiator.TransformType(TLB, TL);
2524  }
2525  if (Result.isNull())
2526  return nullptr;
2527 
2528  return TLB.getTypeSourceInfo(Context, Result);
2529 }
2530 
2533  SmallVectorImpl<QualType> &ExceptionStorage,
2534  const MultiLevelTemplateArgumentList &Args) {
2535  assert(ESI.Type != EST_Uninstantiated);
2536 
2537  bool Changed = false;
2538  TemplateInstantiator Instantiator(*this, Args, Loc, DeclarationName());
2539  return Instantiator.TransformExceptionSpec(Loc, ESI, ExceptionStorage,
2540  Changed);
2541 }
2542 
2544  const MultiLevelTemplateArgumentList &Args) {
2546  Proto->getExtProtoInfo().ExceptionSpec;
2547 
2548  SmallVector<QualType, 4> ExceptionStorage;
2550  ESI, ExceptionStorage, Args))
2551  // On error, recover by dropping the exception specification.
2552  ESI.Type = EST_None;
2553 
2554  UpdateExceptionSpec(New, ESI);
2555 }
2556 
2557 namespace {
2558 
2559  struct GetContainedInventedTypeParmVisitor :
2560  public TypeVisitor<GetContainedInventedTypeParmVisitor,
2561  TemplateTypeParmDecl *> {
2562  using TypeVisitor<GetContainedInventedTypeParmVisitor,
2563  TemplateTypeParmDecl *>::Visit;
2564 
2565  TemplateTypeParmDecl *Visit(QualType T) {
2566  if (T.isNull())
2567  return nullptr;
2568  return Visit(T.getTypePtr());
2569  }
2570  // The deduced type itself.
2571  TemplateTypeParmDecl *VisitTemplateTypeParmType(
2572  const TemplateTypeParmType *T) {
2573  if (!T->getDecl() || !T->getDecl()->isImplicit())
2574  return nullptr;
2575  return T->getDecl();
2576  }
2577 
2578  // Only these types can contain 'auto' types, and subsequently be replaced
2579  // by references to invented parameters.
2580 
2581  TemplateTypeParmDecl *VisitElaboratedType(const ElaboratedType *T) {
2582  return Visit(T->getNamedType());
2583  }
2584 
2585  TemplateTypeParmDecl *VisitPointerType(const PointerType *T) {
2586  return Visit(T->getPointeeType());
2587  }
2588 
2589  TemplateTypeParmDecl *VisitBlockPointerType(const BlockPointerType *T) {
2590  return Visit(T->getPointeeType());
2591  }
2592 
2593  TemplateTypeParmDecl *VisitReferenceType(const ReferenceType *T) {
2594  return Visit(T->getPointeeTypeAsWritten());
2595  }
2596 
2597  TemplateTypeParmDecl *VisitMemberPointerType(const MemberPointerType *T) {
2598  return Visit(T->getPointeeType());
2599  }
2600 
2601  TemplateTypeParmDecl *VisitArrayType(const ArrayType *T) {
2602  return Visit(T->getElementType());
2603  }
2604 
2605  TemplateTypeParmDecl *VisitDependentSizedExtVectorType(
2606  const DependentSizedExtVectorType *T) {
2607  return Visit(T->getElementType());
2608  }
2609 
2610  TemplateTypeParmDecl *VisitVectorType(const VectorType *T) {
2611  return Visit(T->getElementType());
2612  }
2613 
2614  TemplateTypeParmDecl *VisitFunctionProtoType(const FunctionProtoType *T) {
2615  return VisitFunctionType(T);
2616  }
2617 
2618  TemplateTypeParmDecl *VisitFunctionType(const FunctionType *T) {
2619  return Visit(T->getReturnType());
2620  }
2621 
2622  TemplateTypeParmDecl *VisitParenType(const ParenType *T) {
2623  return Visit(T->getInnerType());
2624  }
2625 
2626  TemplateTypeParmDecl *VisitAttributedType(const AttributedType *T) {
2627  return Visit(T->getModifiedType());
2628  }
2629 
2630  TemplateTypeParmDecl *VisitMacroQualifiedType(const MacroQualifiedType *T) {
2631  return Visit(T->getUnderlyingType());
2632  }
2633 
2634  TemplateTypeParmDecl *VisitAdjustedType(const AdjustedType *T) {
2635  return Visit(T->getOriginalType());
2636  }
2637 
2638  TemplateTypeParmDecl *VisitPackExpansionType(const PackExpansionType *T) {
2639  return Visit(T->getPattern());
2640  }
2641  };
2642 
2643 } // namespace
2644 
2646  TemplateTypeParmDecl *Inst, const TypeConstraint *TC,
2647  const MultiLevelTemplateArgumentList &TemplateArgs,
2648  bool EvaluateConstraints) {
2649  const ASTTemplateArgumentListInfo *TemplArgInfo =
2651 
2652  if (!EvaluateConstraints) {
2654  TC->getConceptNameInfo(), TC->getNamedConcept(),
2655  TC->getNamedConcept(), TemplArgInfo,
2657  return false;
2658  }
2659 
2660  TemplateArgumentListInfo InstArgs;
2661 
2662  if (TemplArgInfo) {
2663  InstArgs.setLAngleLoc(TemplArgInfo->LAngleLoc);
2664  InstArgs.setRAngleLoc(TemplArgInfo->RAngleLoc);
2665  if (SubstTemplateArguments(TemplArgInfo->arguments(), TemplateArgs,
2666  InstArgs))
2667  return true;
2668  }
2669  return AttachTypeConstraint(
2671  TC->getNamedConcept(), &InstArgs, Inst,
2672  Inst->isParameterPack()
2673  ? cast<CXXFoldExpr>(TC->getImmediatelyDeclaredConstraint())
2674  ->getEllipsisLoc()
2675  : SourceLocation());
2676 }
2677 
2678 ParmVarDecl *
2680  const MultiLevelTemplateArgumentList &TemplateArgs,
2681  int indexAdjustment, Optional<unsigned> NumExpansions,
2682  bool ExpectParameterPack, bool EvaluateConstraint) {
2683  TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2684  TypeSourceInfo *NewDI = nullptr;
2685 
2686  TypeLoc OldTL = OldDI->getTypeLoc();
2687  if (PackExpansionTypeLoc ExpansionTL = OldTL.getAs<PackExpansionTypeLoc>()) {
2688 
2689  // We have a function parameter pack. Substitute into the pattern of the
2690  // expansion.
2691  NewDI = SubstType(ExpansionTL.getPatternLoc(), TemplateArgs,
2692  OldParm->getLocation(), OldParm->getDeclName());
2693  if (!NewDI)
2694  return nullptr;
2695 
2696  if (NewDI->getType()->containsUnexpandedParameterPack()) {
2697  // We still have unexpanded parameter packs, which means that
2698  // our function parameter is still a function parameter pack.
2699  // Therefore, make its type a pack expansion type.
2700  NewDI = CheckPackExpansion(NewDI, ExpansionTL.getEllipsisLoc(),
2701  NumExpansions);
2702  } else if (ExpectParameterPack) {
2703  // We expected to get a parameter pack but didn't (because the type
2704  // itself is not a pack expansion type), so complain. This can occur when
2705  // the substitution goes through an alias template that "loses" the
2706  // pack expansion.
2707  Diag(OldParm->getLocation(),
2708  diag::err_function_parameter_pack_without_parameter_packs)
2709  << NewDI->getType();
2710  return nullptr;
2711  }
2712  } else {
2713  NewDI = SubstType(OldDI, TemplateArgs, OldParm->getLocation(),
2714  OldParm->getDeclName());
2715  }
2716 
2717  if (!NewDI)
2718  return nullptr;
2719 
2720  if (NewDI->getType()->isVoidType()) {
2721  Diag(OldParm->getLocation(), diag::err_param_with_void_type);
2722  return nullptr;
2723  }
2724 
2725  // In abbreviated templates, TemplateTypeParmDecls with possible
2726  // TypeConstraints are created when the parameter list is originally parsed.
2727  // The TypeConstraints can therefore reference other functions parameters in
2728  // the abbreviated function template, which is why we must instantiate them
2729  // here, when the instantiated versions of those referenced parameters are in
2730  // scope.
2731  if (TemplateTypeParmDecl *TTP =
2732  GetContainedInventedTypeParmVisitor().Visit(OldDI->getType())) {
2733  if (const TypeConstraint *TC = TTP->getTypeConstraint()) {
2734  auto *Inst = cast_or_null<TemplateTypeParmDecl>(
2735  FindInstantiatedDecl(TTP->getLocation(), TTP, TemplateArgs));
2736  // We will first get here when instantiating the abbreviated function
2737  // template's described function, but we might also get here later.
2738  // Make sure we do not instantiate the TypeConstraint more than once.
2739  if (Inst && !Inst->getTypeConstraint()) {
2740  if (SubstTypeConstraint(Inst, TC, TemplateArgs, EvaluateConstraint))
2741  return nullptr;
2742  }
2743  }
2744  }
2745 
2747  OldParm->getInnerLocStart(),
2748  OldParm->getLocation(),
2749  OldParm->getIdentifier(),
2750  NewDI->getType(), NewDI,
2751  OldParm->getStorageClass());
2752  if (!NewParm)
2753  return nullptr;
2754 
2755  // Mark the (new) default argument as uninstantiated (if any).
2756  if (OldParm->hasUninstantiatedDefaultArg()) {
2757  Expr *Arg = OldParm->getUninstantiatedDefaultArg();
2758  NewParm->setUninstantiatedDefaultArg(Arg);
2759  } else if (OldParm->hasUnparsedDefaultArg()) {
2760  NewParm->setUnparsedDefaultArg();
2761  UnparsedDefaultArgInstantiations[OldParm].push_back(NewParm);
2762  } else if (Expr *Arg = OldParm->getDefaultArg()) {
2763  // Default arguments cannot be substituted until the declaration context
2764  // for the associated function or lambda capture class is available.
2765  // This is necessary for cases like the following where construction of
2766  // the lambda capture class for the outer lambda is dependent on the
2767  // parameter types but where the default argument is dependent on the
2768  // outer lambda's declaration context.
2769  // template <typename T>
2770  // auto f() {
2771  // return [](T = []{ return T{}; }()) { return 0; };
2772  // }
2773  NewParm->setUninstantiatedDefaultArg(Arg);
2774  }
2775 
2777 
2778  if (OldParm->isParameterPack() && !NewParm->isParameterPack()) {
2779  // Add the new parameter to the instantiated parameter pack.
2781  } else {
2782  // Introduce an Old -> New mapping
2783  CurrentInstantiationScope->InstantiatedLocal(OldParm, NewParm);
2784  }
2785 
2786  // FIXME: OldParm may come from a FunctionProtoType, in which case CurContext
2787  // can be anything, is this right ?
2788  NewParm->setDeclContext(CurContext);
2789 
2790  NewParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
2791  OldParm->getFunctionScopeIndex() + indexAdjustment);
2792 
2793  InstantiateAttrs(TemplateArgs, OldParm, NewParm);
2794 
2795  return NewParm;
2796 }
2797 
2798 /// Substitute the given template arguments into the given set of
2799 /// parameters, producing the set of parameter types that would be generated
2800 /// from such a substitution.
2803  const FunctionProtoType::ExtParameterInfo *ExtParamInfos,
2804  const MultiLevelTemplateArgumentList &TemplateArgs,
2805  SmallVectorImpl<QualType> &ParamTypes,
2806  SmallVectorImpl<ParmVarDecl *> *OutParams,
2807  ExtParameterInfoBuilder &ParamInfos) {
2808  assert(!CodeSynthesisContexts.empty() &&
2809  "Cannot perform an instantiation without some context on the "
2810  "instantiation stack");
2811 
2812  TemplateInstantiator Instantiator(*this, TemplateArgs, Loc,
2813  DeclarationName());
2814  return Instantiator.TransformFunctionTypeParams(
2815  Loc, Params, nullptr, ExtParamInfos, ParamTypes, OutParams, ParamInfos);
2816 }
2817 
2818 /// Substitute the given template arguments into the default argument.
2820  SourceLocation Loc,
2821  ParmVarDecl *Param,
2822  const MultiLevelTemplateArgumentList &TemplateArgs,
2823  bool ForCallExpr) {
2824  FunctionDecl *FD = cast<FunctionDecl>(Param->getDeclContext());
2825  Expr *PatternExpr = Param->getUninstantiatedDefaultArg();
2826 
2829 
2830  InstantiatingTemplate Inst(*this, Loc, Param, TemplateArgs.getInnermost());
2831  if (Inst.isInvalid())
2832  return true;
2833  if (Inst.isAlreadyInstantiating()) {
2834  Diag(Param->getBeginLoc(), diag::err_recursive_default_argument) << FD;
2835  Param->setInvalidDecl();
2836  return true;
2837  }
2838 
2839  ExprResult Result;
2840  {
2841  // C++ [dcl.fct.default]p5:
2842  // The names in the [default argument] expression are bound, and
2843  // the semantic constraints are checked, at the point where the
2844  // default argument expression appears.
2845  ContextRAII SavedContext(*this, FD);
2846  std::unique_ptr<LocalInstantiationScope> LIS;
2847 
2848  if (ForCallExpr) {
2849  // When instantiating a default argument due to use in a call expression,
2850  // an instantiation scope that includes the parameters of the callee is
2851  // required to satisfy references from the default argument. For example:
2852  // template<typename T> void f(T a, int = decltype(a)());
2853  // void g() { f(0); }
2854  LIS = std::make_unique<LocalInstantiationScope>(*this);
2856  /*ForDefinition*/ false);
2857  if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
2858  return true;
2859  }
2860 
2861  runWithSufficientStackSpace(Loc, [&] {
2862  Result = SubstInitializer(PatternExpr, TemplateArgs,
2863  /*DirectInit*/false);
2864  });
2865  }
2866  if (Result.isInvalid())
2867  return true;
2868 
2869  if (ForCallExpr) {
2870  // Check the expression as an initializer for the parameter.
2871  InitializedEntity Entity
2874  Param->getLocation(),
2875  /*FIXME:EqualLoc*/ PatternExpr->getBeginLoc());
2876  Expr *ResultE = Result.getAs<Expr>();
2877 
2878  InitializationSequence InitSeq(*this, Entity, Kind, ResultE);
2879  Result = InitSeq.Perform(*this, Entity, Kind, ResultE);
2880  if (Result.isInvalid())
2881  return true;
2882 
2883  Result =
2884  ActOnFinishFullExpr(Result.getAs<Expr>(), Param->getOuterLocStart(),
2885  /*DiscardedValue*/ false);
2886  } else {
2887  // FIXME: Obtain the source location for the '=' token.
2888  SourceLocation EqualLoc = PatternExpr->getBeginLoc();
2889  Result = ConvertParamDefaultArgument(Param, Result.getAs<Expr>(), EqualLoc);
2890  }
2891  if (Result.isInvalid())
2892  return true;
2893 
2894  // Remember the instantiated default argument.
2895  Param->setDefaultArg(Result.getAs<Expr>());
2896 
2897  return false;
2898 }
2899 
2900 /// Perform substitution on the base class specifiers of the
2901 /// given class template specialization.
2902 ///
2903 /// Produces a diagnostic and returns true on error, returns false and
2904 /// attaches the instantiated base classes to the class template
2905 /// specialization if successful.
2906 bool
2908  CXXRecordDecl *Pattern,
2909  const MultiLevelTemplateArgumentList &TemplateArgs) {
2910  bool Invalid = false;
2911  SmallVector<CXXBaseSpecifier*, 4> InstantiatedBases;
2912  for (const auto &Base : Pattern->bases()) {
2913  if (!Base.getType()->isDependentType()) {
2914  if (const CXXRecordDecl *RD = Base.getType()->getAsCXXRecordDecl()) {
2915  if (RD->isInvalidDecl())
2916  Instantiation->setInvalidDecl();
2917  }
2918  InstantiatedBases.push_back(new (Context) CXXBaseSpecifier(Base));
2919  continue;
2920  }
2921 
2922  SourceLocation EllipsisLoc;
2923  TypeSourceInfo *BaseTypeLoc;
2924  if (Base.isPackExpansion()) {
2925  // This is a pack expansion. See whether we should expand it now, or
2926  // wait until later.
2928  collectUnexpandedParameterPacks(Base.getTypeSourceInfo()->getTypeLoc(),
2929  Unexpanded);
2930  bool ShouldExpand = false;
2931  bool RetainExpansion = false;
2932  Optional<unsigned> NumExpansions;
2933  if (CheckParameterPacksForExpansion(Base.getEllipsisLoc(),
2934  Base.getSourceRange(),
2935  Unexpanded,
2936  TemplateArgs, ShouldExpand,
2937  RetainExpansion,
2938  NumExpansions)) {
2939  Invalid = true;
2940  continue;
2941  }
2942 
2943  // If we should expand this pack expansion now, do so.
2944  if (ShouldExpand) {
2945  for (unsigned I = 0; I != *NumExpansions; ++I) {
2946  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, I);
2947 
2948  TypeSourceInfo *BaseTypeLoc = SubstType(Base.getTypeSourceInfo(),
2949  TemplateArgs,
2950  Base.getSourceRange().getBegin(),
2951  DeclarationName());
2952  if (!BaseTypeLoc) {
2953  Invalid = true;
2954  continue;
2955  }
2956 
2957  if (CXXBaseSpecifier *InstantiatedBase
2958  = CheckBaseSpecifier(Instantiation,
2959  Base.getSourceRange(),
2960  Base.isVirtual(),
2961  Base.getAccessSpecifierAsWritten(),
2962  BaseTypeLoc,
2963  SourceLocation()))
2964  InstantiatedBases.push_back(InstantiatedBase);
2965  else
2966  Invalid = true;
2967  }
2968 
2969  continue;
2970  }
2971 
2972  // The resulting base specifier will (still) be a pack expansion.
2973  EllipsisLoc = Base.getEllipsisLoc();
2974  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, -1);
2975  BaseTypeLoc = SubstType(Base.getTypeSourceInfo(),
2976  TemplateArgs,
2977  Base.getSourceRange().getBegin(),
2978  DeclarationName());
2979  } else {
2980  BaseTypeLoc = SubstType(Base.getTypeSourceInfo(),
2981  TemplateArgs,
2982  Base.getSourceRange().getBegin(),
2983  DeclarationName());
2984  }
2985 
2986  if (!BaseTypeLoc) {
2987  Invalid = true;
2988  continue;
2989  }
2990 
2991  if (CXXBaseSpecifier *InstantiatedBase
2992  = CheckBaseSpecifier(Instantiation,
2993  Base.getSourceRange(),
2994  Base.isVirtual(),
2995  Base.getAccessSpecifierAsWritten(),
2996  BaseTypeLoc,
2997  EllipsisLoc))
2998  InstantiatedBases.push_back(InstantiatedBase);
2999  else
3000  Invalid = true;
3001  }
3002 
3003  if (!Invalid && AttachBaseSpecifiers(Instantiation, InstantiatedBases))
3004  Invalid = true;
3005 
3006  return Invalid;
3007 }
3008 
3009 // Defined via #include from SemaTemplateInstantiateDecl.cpp
3010 namespace clang {
3011  namespace sema {
3013  const MultiLevelTemplateArgumentList &TemplateArgs);
3015  const Attr *At, ASTContext &C, Sema &S,
3016  const MultiLevelTemplateArgumentList &TemplateArgs);
3017  }
3018 }
3019 
3020 /// Instantiate the definition of a class from a given pattern.
3021 ///
3022 /// \param PointOfInstantiation The point of instantiation within the
3023 /// source code.
3024 ///
3025 /// \param Instantiation is the declaration whose definition is being
3026 /// instantiated. This will be either a class template specialization
3027 /// or a member class of a class template specialization.
3028 ///
3029 /// \param Pattern is the pattern from which the instantiation
3030 /// occurs. This will be either the declaration of a class template or
3031 /// the declaration of a member class of a class template.
3032 ///
3033 /// \param TemplateArgs The template arguments to be substituted into
3034 /// the pattern.
3035 ///
3036 /// \param TSK the kind of implicit or explicit instantiation to perform.
3037 ///
3038 /// \param Complain whether to complain if the class cannot be instantiated due
3039 /// to the lack of a definition.
3040 ///
3041 /// \returns true if an error occurred, false otherwise.
3042 bool
3044  CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern,
3045  const MultiLevelTemplateArgumentList &TemplateArgs,
3047  bool Complain) {
3048  CXXRecordDecl *PatternDef
3049  = cast_or_null<CXXRecordDecl>(Pattern->getDefinition());
3050  if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Instantiation,
3051  Instantiation->getInstantiatedFromMemberClass(),
3052  Pattern, PatternDef, TSK, Complain))
3053  return true;
3054 
3055  llvm::TimeTraceScope TimeScope("InstantiateClass", [&]() {
3056  std::string Name;
3057  llvm::raw_string_ostream OS(Name);
3058  Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
3059  /*Qualified=*/true);
3060  return Name;
3061  });
3062 
3063  Pattern = PatternDef;
3064 
3065  // Record the point of instantiation.
3066  if (MemberSpecializationInfo *MSInfo
3067  = Instantiation->getMemberSpecializationInfo()) {
3068  MSInfo->setTemplateSpecializationKind(TSK);
3069  MSInfo->setPointOfInstantiation(PointOfInstantiation);
3070  } else if (ClassTemplateSpecializationDecl *Spec
3071  = dyn_cast<ClassTemplateSpecializationDecl>(Instantiation)) {
3072  Spec->setTemplateSpecializationKind(TSK);
3073  Spec->setPointOfInstantiation(PointOfInstantiation);
3074  }
3075 
3076  InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation);
3077  if (Inst.isInvalid())
3078  return true;
3079  assert(!Inst.isAlreadyInstantiating() && "should have been caught by caller");
3080  PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(),
3081  "instantiating class definition");
3082 
3083  // Enter the scope of this instantiation. We don't use
3084  // PushDeclContext because we don't have a scope.
3085  ContextRAII SavedContext(*this, Instantiation);
3088 
3089  // If this is an instantiation of a local class, merge this local
3090  // instantiation scope with the enclosing scope. Otherwise, every
3091  // instantiation of a class has its own local instantiation scope.
3092  bool MergeWithParentScope = !Instantiation->isDefinedOutsideFunctionOrMethod();
3093  LocalInstantiationScope Scope(*this, MergeWithParentScope);
3094 
3095  // Some class state isn't processed immediately but delayed till class
3096  // instantiation completes. We may not be ready to handle any delayed state
3097  // already on the stack as it might correspond to a different class, so save
3098  // it now and put it back later.
3099  SavePendingParsedClassStateRAII SavedPendingParsedClassState(*this);
3100 
3101  // Pull attributes from the pattern onto the instantiation.
3102  InstantiateAttrs(TemplateArgs, Pattern, Instantiation);
3103 
3104  // Start the definition of this instantiation.
3105  Instantiation->startDefinition();
3106 
3107  // The instantiation is visible here, even if it was first declared in an
3108  // unimported module.
3109  Instantiation->setVisibleDespiteOwningModule();
3110 
3111  // FIXME: This loses the as-written tag kind for an explicit instantiation.
3112  Instantiation->setTagKind(Pattern->getTagKind());
3113 
3114  // Do substitution on the base class specifiers.
3115  if (SubstBaseSpecifiers(Instantiation, Pattern, TemplateArgs))
3116  Instantiation->setInvalidDecl();
3117 
3118  TemplateDeclInstantiator Instantiator(*this, Instantiation, TemplateArgs);
3119  Instantiator.setEvaluateConstraints(false);
3120  SmallVector<Decl*, 4> Fields;
3121  // Delay instantiation of late parsed attributes.
3122  LateInstantiatedAttrVec LateAttrs;
3123  Instantiator.enableLateAttributeInstantiation(&LateAttrs);
3124 
3125  bool MightHaveConstexprVirtualFunctions = false;
3126  for (auto *Member : Pattern->decls()) {
3127  // Don't instantiate members not belonging in this semantic context.
3128  // e.g. for:
3129  // @code
3130  // template <int i> class A {
3131  // class B *g;
3132  // };
3133  // @endcode
3134  // 'class B' has the template as lexical context but semantically it is
3135  // introduced in namespace scope.
3136  if (Member->getDeclContext() != Pattern)
3137  continue;
3138 
3139  // BlockDecls can appear in a default-member-initializer. They must be the
3140  // child of a BlockExpr, so we only know how to instantiate them from there.
3141  // Similarly, lambda closure types are recreated when instantiating the
3142  // corresponding LambdaExpr.
3143  if (isa<BlockDecl>(Member) ||
3144  (isa<CXXRecordDecl>(Member) && cast<CXXRecordDecl>(Member)->isLambda()))
3145  continue;
3146 
3147  if (Member->isInvalidDecl()) {
3148  Instantiation->setInvalidDecl();
3149  continue;
3150  }
3151 
3152  Decl *NewMember = Instantiator.Visit(Member);
3153  if (NewMember) {
3154  if (FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) {
3155  Fields.push_back(Field);
3156  } else if (EnumDecl *Enum = dyn_cast<EnumDecl>(NewMember)) {
3157  // C++11 [temp.inst]p1: The implicit instantiation of a class template
3158  // specialization causes the implicit instantiation of the definitions
3159  // of unscoped member enumerations.
3160  // Record a point of instantiation for this implicit instantiation.
3161  if (TSK == TSK_ImplicitInstantiation && !Enum->isScoped() &&
3162  Enum->isCompleteDefinition()) {
3163  MemberSpecializationInfo *MSInfo =Enum->getMemberSpecializationInfo();
3164  assert(MSInfo && "no spec info for member enum specialization");
3166  MSInfo->setPointOfInstantiation(PointOfInstantiation);
3167  }
3168  } else if (StaticAssertDecl *SA = dyn_cast<StaticAssertDecl>(NewMember)) {
3169  if (SA->isFailed()) {
3170  // A static_assert failed. Bail out; instantiating this
3171  // class is probably not meaningful.
3172  Instantiation->setInvalidDecl();
3173  break;
3174  }
3175  } else if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewMember)) {
3176  if (MD->isConstexpr() && !MD->getFriendObjectKind() &&
3177  (MD->isVirtualAsWritten() || Instantiation->getNumBases()))
3178  MightHaveConstexprVirtualFunctions = true;
3179  }
3180 
3181  if (NewMember->isInvalidDecl())
3182  Instantiation->setInvalidDecl();
3183  } else {
3184  // FIXME: Eventually, a NULL return will mean that one of the
3185  // instantiations was a semantic disaster, and we'll want to mark the
3186  // declaration invalid.
3187  // For now, we expect to skip some members that we can't yet handle.
3188  }
3189  }
3190 
3191  // Finish checking fields.
3192  ActOnFields(nullptr, Instantiation->getLocation(), Instantiation, Fields,
3194  CheckCompletedCXXClass(nullptr, Instantiation);
3195 
3196  // Default arguments are parsed, if not instantiated. We can go instantiate
3197  // default arg exprs for default constructors if necessary now. Unless we're
3198  // parsing a class, in which case wait until that's finished.
3199  if (ParsingClassDepth == 0)
3201 
3202  // Instantiate late parsed attributes, and attach them to their decls.
3203  // See Sema::InstantiateAttrs
3204  for (LateInstantiatedAttrVec::iterator I = LateAttrs.begin(),
3205  E = LateAttrs.end(); I != E; ++I) {
3206  assert(CurrentInstantiationScope == Instantiator.getStartingScope());
3207  CurrentInstantiationScope = I->Scope;
3208 
3209  // Allow 'this' within late-parsed attributes.
3210  auto *ND = cast<NamedDecl>(I->NewDecl);
3211  auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext());
3212  CXXThisScopeRAII ThisScope(*this, ThisContext, Qualifiers(),
3213  ND->isCXXInstanceMember());
3214 
3215  Attr *NewAttr =
3216  instantiateTemplateAttribute(I->TmplAttr, Context, *this, TemplateArgs);
3217  if (NewAttr)
3218  I->NewDecl->addAttr(NewAttr);
3220  Instantiator.getStartingScope());
3221  }
3222  Instantiator.disableLateAttributeInstantiation();
3223  LateAttrs.clear();
3224 
3225  ActOnFinishDelayedMemberInitializers(Instantiation);
3226 
3227  // FIXME: We should do something similar for explicit instantiations so they
3228  // end up in the right module.
3229  if (TSK == TSK_ImplicitInstantiation) {
3230  Instantiation->setLocation(Pattern->getLocation());
3231  Instantiation->setLocStart(Pattern->getInnerLocStart());
3232  Instantiation->setBraceRange(Pattern->getBraceRange());
3233  }
3234 
3235  if (!Instantiation->isInvalidDecl()) {
3236  // Perform any dependent diagnostics from the pattern.
3237  if (Pattern->isDependentContext())
3238  PerformDependentDiagnostics(Pattern, TemplateArgs);
3239 
3240  // Instantiate any out-of-line class template partial
3241  // specializations now.
3243  P = Instantiator.delayed_partial_spec_begin(),
3244  PEnd = Instantiator.delayed_partial_spec_end();
3245  P != PEnd; ++P) {
3247  P->first, P->second)) {
3248  Instantiation->setInvalidDecl();
3249  break;
3250  }
3251  }
3252 
3253  // Instantiate any out-of-line variable template partial
3254  // specializations now.
3256  P = Instantiator.delayed_var_partial_spec_begin(),
3257  PEnd = Instantiator.delayed_var_partial_spec_end();
3258  P != PEnd; ++P) {
3260  P->first, P->second)) {
3261  Instantiation->setInvalidDecl();
3262  break;
3263  }
3264  }
3265  }
3266 
3267  // Exit the scope of this instantiation.
3268  SavedContext.pop();
3269 
3270  if (!Instantiation->isInvalidDecl()) {
3271  // Always emit the vtable for an explicit instantiation definition
3272  // of a polymorphic class template specialization. Otherwise, eagerly
3273  // instantiate only constexpr virtual functions in preparation for their use
3274  // in constant evaluation.
3276  MarkVTableUsed(PointOfInstantiation, Instantiation, true);
3277  else if (MightHaveConstexprVirtualFunctions)
3278  MarkVirtualMembersReferenced(PointOfInstantiation, Instantiation,
3279  /*ConstexprOnly*/ true);
3280  }
3281 
3282  Consumer.HandleTagDeclDefinition(Instantiation);
3283 
3284  return Instantiation->isInvalidDecl();
3285 }
3286 
3287 /// Instantiate the definition of an enum from a given pattern.
3288 ///
3289 /// \param PointOfInstantiation The point of instantiation within the
3290 /// source code.
3291 /// \param Instantiation is the declaration whose definition is being
3292 /// instantiated. This will be a member enumeration of a class
3293 /// temploid specialization, or a local enumeration within a
3294 /// function temploid specialization.
3295 /// \param Pattern The templated declaration from which the instantiation
3296 /// occurs.
3297 /// \param TemplateArgs The template arguments to be substituted into
3298 /// the pattern.
3299 /// \param TSK The kind of implicit or explicit instantiation to perform.
3300 ///
3301 /// \return \c true if an error occurred, \c false otherwise.
3302 bool Sema::InstantiateEnum(SourceLocation PointOfInstantiation,
3303  EnumDecl *Instantiation, EnumDecl *Pattern,
3304  const MultiLevelTemplateArgumentList &TemplateArgs,
3306  EnumDecl *PatternDef = Pattern->getDefinition();
3307  if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Instantiation,
3308  Instantiation->getInstantiatedFromMemberEnum(),
3309  Pattern, PatternDef, TSK,/*Complain*/true))
3310  return true;
3311  Pattern = PatternDef;
3312 
3313  // Record the point of instantiation.
3314  if (MemberSpecializationInfo *MSInfo
3315  = Instantiation->getMemberSpecializationInfo()) {
3316  MSInfo->setTemplateSpecializationKind(TSK);
3317  MSInfo->setPointOfInstantiation(PointOfInstantiation);
3318  }
3319 
3320  InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation);
3321  if (Inst.isInvalid())
3322  return true;
3323  if (Inst.isAlreadyInstantiating())
3324  return false;
3325  PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(),
3326  "instantiating enum definition");
3327 
3328  // The instantiation is visible here, even if it was first declared in an
3329  // unimported module.
3330  Instantiation->setVisibleDespiteOwningModule();
3331 
3332  // Enter the scope of this instantiation. We don't use
3333  // PushDeclContext because we don't have a scope.
3334  ContextRAII SavedContext(*this, Instantiation);
3337 
3338  LocalInstantiationScope Scope(*this, /*MergeWithParentScope*/true);
3339 
3340  // Pull attributes from the pattern onto the instantiation.
3341  InstantiateAttrs(TemplateArgs, Pattern, Instantiation);
3342 
3343  TemplateDeclInstantiator Instantiator(*this, Instantiation, TemplateArgs);
3344  Instantiator.InstantiateEnumDefinition(Instantiation, Pattern);
3345 
3346  // Exit the scope of this instantiation.
3347  SavedContext.pop();
3348 
3349  return Instantiation->isInvalidDecl();
3350 }
3351 
3352 
3353 /// Instantiate the definition of a field from the given pattern.
3354 ///
3355 /// \param PointOfInstantiation The point of instantiation within the
3356 /// source code.
3357 /// \param Instantiation is the declaration whose definition is being
3358 /// instantiated. This will be a class of a class temploid
3359 /// specialization, or a local enumeration within a function temploid
3360 /// specialization.
3361 /// \param Pattern The templated declaration from which the instantiation
3362 /// occurs.
3363 /// \param TemplateArgs The template arguments to be substituted into
3364 /// the pattern.
3365 ///
3366 /// \return \c true if an error occurred, \c false otherwise.
3368  SourceLocation PointOfInstantiation, FieldDecl *Instantiation,
3369  FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs) {
3370  // If there is no initializer, we don't need to do anything.
3371  if (!Pattern->hasInClassInitializer())
3372  return false;
3373 
3374  assert(Instantiation->getInClassInitStyle() ==
3375  Pattern->getInClassInitStyle() &&
3376  "pattern and instantiation disagree about init style");
3377 
3378  // Error out if we haven't parsed the initializer of the pattern yet because
3379  // we are waiting for the closing brace of the outer class.
3380  Expr *OldInit = Pattern->getInClassInitializer();
3381  if (!OldInit) {
3382  RecordDecl *PatternRD = Pattern->getParent();
3383  RecordDecl *OutermostClass = PatternRD->getOuterLexicalRecordContext();
3384  Diag(PointOfInstantiation,
3385  diag::err_default_member_initializer_not_yet_parsed)
3386  << OutermostClass << Pattern;
3387  Diag(Pattern->getEndLoc(),
3388  diag::note_default_member_initializer_not_yet_parsed);
3389  Instantiation->setInvalidDecl();
3390  return true;
3391  }
3392 
3393  InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation);
3394  if (Inst.isInvalid())
3395  return true;
3396  if (Inst.isAlreadyInstantiating()) {
3397  // Error out if we hit an instantiation cycle for this initializer.
3398  Diag(PointOfInstantiation, diag::err_default_member_initializer_cycle)
3399  << Instantiation;
3400  return true;
3401  }
3402  PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(),
3403  "instantiating default member init");
3404 
3405  // Enter the scope of this instantiation. We don't use PushDeclContext because
3406  // we don't have a scope.
3407  ContextRAII SavedContext(*this, Instantiation->getParent());
3410 
3411  LocalInstantiationScope Scope(*this, true);
3412 
3413  // Instantiate the initializer.
3415  CXXThisScopeRAII ThisScope(*this, Instantiation->getParent(), Qualifiers());
3416 
3417  ExprResult NewInit = SubstInitializer(OldInit, TemplateArgs,
3418  /*CXXDirectInit=*/false);
3419  Expr *Init = NewInit.get();
3420  assert((!Init || !isa<ParenListExpr>(Init)) && "call-style init in class");
3422  Instantiation, Init ? Init->getBeginLoc() : SourceLocation(), Init);
3423 
3424  if (auto *L = getASTMutationListener())
3425  L->DefaultMemberInitializerInstantiated(Instantiation);
3426 
3427  // Return true if the in-class initializer is still missing.
3428  return !Instantiation->getInClassInitializer();
3429 }
3430 
3431 namespace {
3432  /// A partial specialization whose template arguments have matched
3433  /// a given template-id.
3434  struct PartialSpecMatchResult {
3436  TemplateArgumentList *Args;
3437  };
3438 }
3439 
3441  SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec) {
3442  if (ClassTemplateSpec->getTemplateSpecializationKind() ==
3444  return true;
3445 
3447  ClassTemplateSpec->getSpecializedTemplate()
3448  ->getPartialSpecializations(PartialSpecs);
3449  for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) {
3450  TemplateDeductionInfo Info(Loc);
3451  if (!DeduceTemplateArguments(PartialSpecs[I],
3452  ClassTemplateSpec->getTemplateArgs(), Info))
3453  return true;
3454  }
3455 
3456  return false;
3457 }
3458 
3459 /// Get the instantiation pattern to use to instantiate the definition of a
3460 /// given ClassTemplateSpecializationDecl (either the pattern of the primary
3461 /// template or of a partial specialization).
3464  Sema &S, SourceLocation PointOfInstantiation,
3465  ClassTemplateSpecializationDecl *ClassTemplateSpec,
3467  Sema::InstantiatingTemplate Inst(S, PointOfInstantiation, ClassTemplateSpec);
3468  if (Inst.isInvalid())
3469  return {/*Invalid=*/true};
3470  if (Inst.isAlreadyInstantiating())
3471  return {/*Invalid=*/false};
3472 
3473  llvm::PointerUnion<ClassTemplateDecl *,
3475  Specialized = ClassTemplateSpec->getSpecializedTemplateOrPartial();
3476  if (!Specialized.is<ClassTemplatePartialSpecializationDecl *>()) {
3477  // Find best matching specialization.
3478  ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate();
3479 
3480  // C++ [temp.class.spec.match]p1:
3481  // When a class template is used in a context that requires an
3482  // instantiation of the class, it is necessary to determine
3483  // whether the instantiation is to be generated using the primary
3484  // template or one of the partial specializations. This is done by
3485  // matching the template arguments of the class template
3486  // specialization with the template argument lists of the partial
3487  // specializations.
3488  typedef PartialSpecMatchResult MatchResult;
3491  Template->getPartialSpecializations(PartialSpecs);
3492  TemplateSpecCandidateSet FailedCandidates(PointOfInstantiation);
3493  for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) {
3494  ClassTemplatePartialSpecializationDecl *Partial = PartialSpecs[I];
3495  TemplateDeductionInfo Info(FailedCandidates.getLocation());
3497  Partial, ClassTemplateSpec->getTemplateArgs(), Info)) {
3498  // Store the failed-deduction information for use in diagnostics, later.
3499  // TODO: Actually use the failed-deduction info?
3500  FailedCandidates.addCandidate().set(
3501  DeclAccessPair::make(Template, AS_public), Partial,
3502  MakeDeductionFailureInfo(S.Context, Result, Info));
3503  (void)Result;
3504  } else {
3505  Matched.push_back(PartialSpecMatchResult());
3506  Matched.back().Partial = Partial;
3507  Matched.back().Args = Info.takeCanonical();
3508  }
3509  }
3510 
3511  // If we're dealing with a member template where the template parameters
3512  // have been instantiated, this provides the original template parameters
3513  // from which the member template's parameters were instantiated.
3514 
3515  if (Matched.size() >= 1) {
3516  SmallVectorImpl<MatchResult>::iterator Best = Matched.begin();
3517  if (Matched.size() == 1) {
3518  // -- If exactly one matching specialization is found, the
3519  // instantiation is generated from that specialization.
3520  // We don't need to do anything for this.
3521  } else {
3522  // -- If more than one matching specialization is found, the
3523  // partial order rules (14.5.4.2) are used to determine
3524  // whether one of the specializations is more specialized
3525  // than the others. If none of the specializations is more
3526  // specialized than all of the other matching
3527  // specializations, then the use of the class template is
3528  // ambiguous and the program is ill-formed.
3529  for (SmallVectorImpl<MatchResult>::iterator P = Best + 1,
3530  PEnd = Matched.end();
3531  P != PEnd; ++P) {
3533  P->Partial, Best->Partial, PointOfInstantiation) ==
3534  P->Partial)
3535  Best = P;
3536  }
3537 
3538  // Determine if the best partial specialization is more specialized than
3539  // the others.
3540  bool Ambiguous = false;
3541  for (SmallVectorImpl<MatchResult>::iterator P = Matched.begin(),
3542  PEnd = Matched.end();
3543  P != PEnd; ++P) {
3544  if (P != Best && S.getMoreSpecializedPartialSpecialization(
3545  P->Partial, Best->Partial,
3546  PointOfInstantiation) != Best->Partial) {
3547  Ambiguous = true;
3548  break;
3549  }
3550  }
3551 
3552  if (Ambiguous) {
3553  // Partial ordering did not produce a clear winner. Complain.
3554  Inst.Clear();
3555  ClassTemplateSpec->setInvalidDecl();
3556  S.Diag(PointOfInstantiation,
3557  diag::err_partial_spec_ordering_ambiguous)
3558  << ClassTemplateSpec;
3559 
3560  // Print the matching partial specializations.
3561  for (SmallVectorImpl<MatchResult>::iterator P = Matched.begin(),
3562  PEnd = Matched.end();
3563  P != PEnd; ++P)
3564  S.Diag(P->Partial->getLocation(), diag::note_partial_spec_match)
3566  P->Partial->getTemplateParameters(), *P->Args);
3567 
3568  return {/*Invalid=*/true};
3569  }
3570  }
3571 
3572  ClassTemplateSpec->setInstantiationOf(Best->Partial, Best->Args);
3573  } else {
3574  // -- If no matches are found, the instantiation is generated
3575  // from the primary template.
3576  }
3577  }
3578 
3579  CXXRecordDecl *Pattern = nullptr;
3580  Specialized = ClassTemplateSpec->getSpecializedTemplateOrPartial();
3581  if (auto *PartialSpec =
3582  Specialized.dyn_cast<ClassTemplatePartialSpecializationDecl *>()) {
3583  // Instantiate using the best class template partial specialization.
3584  while (PartialSpec->getInstantiatedFromMember()) {
3585  // If we've found an explicit specialization of this class template,
3586  // stop here and use that as the pattern.
3587  if (PartialSpec->isMemberSpecialization())
3588  break;
3589 
3590  PartialSpec = PartialSpec->getInstantiatedFromMember();
3591  }
3592  Pattern = PartialSpec;
3593  } else {
3594  ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate();
3595  while (Template->getInstantiatedFromMemberTemplate()) {
3596  // If we've found an explicit specialization of this class template,
3597  // stop here and use that as the pattern.
3598  if (Template->isMemberSpecialization())
3599  break;
3600 
3601  Template = Template->getInstantiatedFromMemberTemplate();
3602  }
3603  Pattern = Template->getTemplatedDecl();
3604  }
3605 
3606  return Pattern;
3607 }
3608 
3610  SourceLocation PointOfInstantiation,
3611  ClassTemplateSpecializationDecl *ClassTemplateSpec,
3612  TemplateSpecializationKind TSK, bool Complain) {
3613  // Perform the actual instantiation on the canonical declaration.
3614  ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>(
3615  ClassTemplateSpec->getCanonicalDecl());
3616  if (ClassTemplateSpec->isInvalidDecl())
3617  return true;
3618 
3620  getPatternForClassTemplateSpecialization(*this, PointOfInstantiation,
3621  ClassTemplateSpec, TSK);
3622  if (!Pattern.isUsable())
3623  return Pattern.isInvalid();
3624 
3625  return InstantiateClass(
3626  PointOfInstantiation, ClassTemplateSpec, Pattern.get(),
3627  getTemplateInstantiationArgs(ClassTemplateSpec), TSK, Complain);
3628 }
3629 
3630 /// Instantiates the definitions of all of the member
3631 /// of the given class, which is an instantiation of a class template
3632 /// or a member class of a template.
3633 void
3635  CXXRecordDecl *Instantiation,
3636  const MultiLevelTemplateArgumentList &TemplateArgs,
3638  // FIXME: We need to notify the ASTMutationListener that we did all of these
3639  // things, in case we have an explicit instantiation definition in a PCM, a
3640  // module, or preamble, and the declaration is in an imported AST.
3641  assert(
3644  (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) &&
3645  "Unexpected template specialization kind!");
3646  for (auto *D : Instantiation->decls()) {
3647  bool SuppressNew = false;
3648  if (auto *Function = dyn_cast<FunctionDecl>(D)) {
3649  if (FunctionDecl *Pattern =
3650  Function->getInstantiatedFromMemberFunction()) {
3651 
3652  if (Function->isIneligibleOrNotSelected())
3653  continue;
3654 
3655  if (Function->getTrailingRequiresClause()) {
3656  ConstraintSatisfaction Satisfaction;
3657  if (CheckFunctionConstraints(Function, Satisfaction) ||
3658  !Satisfaction.IsSatisfied) {
3659  continue;
3660  }
3661  }
3662 
3663  if (Function->hasAttr<ExcludeFromExplicitInstantiationAttr>())
3664  continue;
3665 
3666  MemberSpecializationInfo *MSInfo =
3667  Function->getMemberSpecializationInfo();
3668  assert(MSInfo && "No member specialization information?");
3669  if (MSInfo->getTemplateSpecializationKind()
3671  continue;
3672 
3673  if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK,
3674  Function,
3676  MSInfo->getPointOfInstantiation(),
3677  SuppressNew) ||
3678  SuppressNew)
3679  continue;
3680 
3681  // C++11 [temp.explicit]p8:
3682  // An explicit instantiation definition that names a class template
3683  // specialization explicitly instantiates the class template
3684  // specialization and is only an explicit instantiation definition
3685  // of members whose definition is visible at the point of
3686  // instantiation.
3687  if (TSK == TSK_ExplicitInstantiationDefinition && !Pattern->isDefined())
3688  continue;
3689 
3690  Function->setTemplateSpecializationKind(TSK, PointOfInstantiation);
3691 
3692  if (Function->isDefined()) {
3693  // Let the ASTConsumer know that this function has been explicitly
3694  // instantiated now, and its linkage might have changed.
3696  } else if (TSK == TSK_ExplicitInstantiationDefinition) {
3697  InstantiateFunctionDefinition(PointOfInstantiation, Function);
3698  } else if (TSK == TSK_ImplicitInstantiation) {
3700  std::make_pair(Function, PointOfInstantiation));
3701  }
3702  }
3703  } else if (auto *Var = dyn_cast<VarDecl>(D)) {
3704  if (isa<VarTemplateSpecializationDecl>(Var))
3705  continue;
3706 
3707  if (Var->isStaticDataMember()) {
3708  if (Var->hasAttr<ExcludeFromExplicitInstantiationAttr>())
3709  continue;
3710 
3712  assert(MSInfo && "No member specialization information?");
3713  if (MSInfo->getTemplateSpecializationKind()
3715  continue;
3716 
3717  if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK,
3718  Var,
3720  MSInfo->getPointOfInstantiation(),
3721  SuppressNew) ||
3722  SuppressNew)
3723  continue;
3724 
3726  // C++0x [temp.explicit]p8:
3727  // An explicit instantiation definition that names a class template
3728  // specialization explicitly instantiates the class template
3729  // specialization and is only an explicit instantiation definition
3730  // of members whose definition is visible at the point of
3731  // instantiation.
3733  continue;
3734 
3735  Var->setTemplateSpecializationKind(TSK, PointOfInstantiation);
3736  InstantiateVariableDefinition(PointOfInstantiation, Var);
3737  } else {
3738  Var->setTemplateSpecializationKind(TSK, PointOfInstantiation);
3739  }
3740  }
3741  } else if (auto *Record = dyn_cast<CXXRecordDecl>(D)) {
3742  if (Record->hasAttr<ExcludeFromExplicitInstantiationAttr>())
3743  continue;
3744 
3745  // Always skip the injected-class-name, along with any
3746  // redeclarations of nested classes, since both would cause us
3747  // to try to instantiate the members of a class twice.
3748  // Skip closure types; they'll get instantiated when we instantiate
3749  // the corresponding lambda-expression.
3750  if (Record->isInjectedClassName() || Record->getPreviousDecl() ||
3751  Record->isLambda())
3752  continue;
3753 
3754  MemberSpecializationInfo *MSInfo = Record->getMemberSpecializationInfo();
3755  assert(MSInfo && "No member specialization information?");
3756 
3757  if (MSInfo->getTemplateSpecializationKind()
3759  continue;
3760 
3761  if (Context.getTargetInfo().getTriple().isOSWindows() &&
3763  // On Windows, explicit instantiation decl of the outer class doesn't
3764  // affect the inner class. Typically extern template declarations are
3765  // used in combination with dll import/export annotations, but those
3766  // are not propagated from the outer class templates to inner classes.
3767  // Therefore, do not instantiate inner classes on this platform, so
3768  // that users don't end up with undefined symbols during linking.
3769  continue;
3770  }
3771 
3772  if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK,
3773  Record,
3775  MSInfo->getPointOfInstantiation(),
3776  SuppressNew) ||
3777  SuppressNew)
3778  continue;
3779 
3780  CXXRecordDecl *Pattern = Record->getInstantiatedFromMemberClass();
3781  assert(Pattern && "Missing instantiated-from-template information");
3782 
3783  if (!Record->getDefinition()) {
3784  if (!Pattern->getDefinition()) {
3785  // C++0x [temp.explicit]p8:
3786  // An explicit instantiation definition that names a class template
3787  // specialization explicitly instantiates the class template
3788  // specialization and is only an explicit instantiation definition
3789  // of members whose definition is visible at the point of
3790  // instantiation.
3792  MSInfo->setTemplateSpecializationKind(TSK);
3793  MSInfo->setPointOfInstantiation(PointOfInstantiation);
3794  }
3795 
3796  continue;
3797  }
3798 
3799  InstantiateClass(PointOfInstantiation, Record, Pattern,
3800  TemplateArgs,
3801  TSK);
3802  } else {
3804  Record->getTemplateSpecializationKind() ==
3806  Record->setTemplateSpecializationKind(TSK);
3807  MarkVTableUsed(PointOfInstantiation, Record, true);
3808  }
3809  }
3810 
3811  Pattern = cast_or_null<CXXRecordDecl>(Record->getDefinition());
3812  if (Pattern)
3813  InstantiateClassMembers(PointOfInstantiation, Pattern, TemplateArgs,
3814  TSK);
3815  } else if (auto *Enum = dyn_cast<EnumDecl>(D)) {
3816  MemberSpecializationInfo *MSInfo = Enum->getMemberSpecializationInfo();
3817  assert(MSInfo && "No member specialization information?");
3818 
3819  if (MSInfo->getTemplateSpecializationKind()
3821  continue;
3822 
3824  PointOfInstantiation, TSK, Enum,
3826  MSInfo->getPointOfInstantiation(), SuppressNew) ||
3827  SuppressNew)
3828  continue;
3829 
3830  if (Enum->getDefinition())
3831  continue;
3832 
3833  EnumDecl *Pattern = Enum->getTemplateInstantiationPattern();
3834  assert(Pattern && "Missing instantiated-from-template information");
3835 
3837  if (!Pattern->getDefinition())
3838  continue;
3839 
3840  InstantiateEnum(PointOfInstantiation, Enum, Pattern, TemplateArgs, TSK);
3841  } else {
3842  MSInfo->setTemplateSpecializationKind(TSK);
3843  MSInfo->setPointOfInstantiation(PointOfInstantiation);
3844  }
3845  } else if (auto *Field = dyn_cast<FieldDecl>(D)) {
3846  // No need to instantiate in-class initializers during explicit
3847  // instantiation.
3848  if (Field->hasInClassInitializer() && TSK == TSK_ImplicitInstantiation) {
3849  CXXRecordDecl *ClassPattern =
3850  Instantiation->getTemplateInstantiationPattern();
3852  ClassPattern->lookup(Field->getDeclName());
3853  FieldDecl *Pattern = Lookup.find_first<FieldDecl>();
3854  assert(Pattern);
3855  InstantiateInClassInitializer(PointOfInstantiation, Field, Pattern,
3856  TemplateArgs);
3857  }
3858  }
3859  }
3860 }
3861 
3862 /// Instantiate the definitions of all of the members of the
3863 /// given class template specialization, which was named as part of an
3864 /// explicit instantiation.
3865 void
3867  SourceLocation PointOfInstantiation,
3868  ClassTemplateSpecializationDecl *ClassTemplateSpec,
3870  // C++0x [temp.explicit]p7:
3871  // An explicit instantiation that names a class template
3872  // specialization is an explicit instantion of the same kind
3873  // (declaration or definition) of each of its members (not
3874  // including members inherited from base classes) that has not
3875  // been previously explicitly specialized in the translation unit
3876  // containing the explicit instantiation, except as described
3877  // below.
3878  InstantiateClassMembers(PointOfInstantiation, ClassTemplateSpec,
3879  getTemplateInstantiationArgs(ClassTemplateSpec),
3880  TSK);
3881 }
3882 
3883 StmtResult
3885  if (!S)
3886  return S;
3887 
3888  TemplateInstantiator Instantiator(*this, TemplateArgs,
3889  SourceLocation(),
3890  DeclarationName());
3891  return Instantiator.TransformStmt(S);
3892 }
3893 
3896  const MultiLevelTemplateArgumentList &TemplateArgs,
3897  TemplateArgumentListInfo &Out) {
3898  TemplateInstantiator Instantiator(*this, TemplateArgs, SourceLocation(),
3899  DeclarationName());
3900  return Instantiator.TransformTemplateArguments(Args.begin(), Args.end(), Out);
3901 }
3902 
3903 ExprResult
3905  if (!E)
3906  return E;
3907 
3908  TemplateInstantiator Instantiator(*this, TemplateArgs,
3909  SourceLocation(),
3910  DeclarationName());
3911  return Instantiator.TransformExpr(E);
3912 }
3913 
3914 ExprResult
3916  const MultiLevelTemplateArgumentList &TemplateArgs) {
3917  if (!E)
3918  return E;
3919 
3920  // This is where we need to make sure we 'know' constraint checking needs to
3921  // happen.
3922  TemplateInstantiator Instantiator(*this, TemplateArgs, SourceLocation(),
3923  DeclarationName());
3924  return Instantiator.TransformExpr(E);
3925 }
3926 
3928  const MultiLevelTemplateArgumentList &TemplateArgs,
3929  bool CXXDirectInit) {
3930  TemplateInstantiator Instantiator(*this, TemplateArgs, SourceLocation(),
3931  DeclarationName());
3932  return Instantiator.TransformInitializer(Init, CXXDirectInit);
3933 }
3934 
3935 bool Sema::SubstExprs(ArrayRef<Expr *> Exprs, bool IsCall,
3936  const MultiLevelTemplateArgumentList &TemplateArgs,
3937  SmallVectorImpl<Expr *> &Outputs) {
3938  if (Exprs.empty())
3939  return false;
3940 
3941  TemplateInstantiator Instantiator(*this, TemplateArgs,
3942  SourceLocation(),
3943  DeclarationName());
3944  return Instantiator.TransformExprs(Exprs.data(), Exprs.size(),
3945  IsCall, Outputs);
3946 }
3947 
3950  const MultiLevelTemplateArgumentList &TemplateArgs) {
3951  if (!NNS)
3952  return NestedNameSpecifierLoc();
3953 
3954  TemplateInstantiator Instantiator(*this, TemplateArgs, NNS.getBeginLoc(),
3955  DeclarationName());
3956  return Instantiator.TransformNestedNameSpecifierLoc(NNS);
3957 }
3958 
3959 /// Do template substitution on declaration name info.
3962  const MultiLevelTemplateArgumentList &TemplateArgs) {
3963  TemplateInstantiator Instantiator(*this, TemplateArgs, NameInfo.getLoc(),
3964  NameInfo.getName());
3965  return Instantiator.TransformDeclarationNameInfo(NameInfo);
3966 }
3967 
3970  TemplateName Name, SourceLocation Loc,
3971  const MultiLevelTemplateArgumentList &TemplateArgs) {
3972  TemplateInstantiator Instantiator(*this, TemplateArgs, Loc,
3973  DeclarationName());
3974  CXXScopeSpec SS;
3975  SS.Adopt(QualifierLoc);
3976  return Instantiator.TransformTemplateName(SS, Name, Loc);
3977 }
3978 
3979 static const Decl *getCanonicalParmVarDecl(const Decl *D) {
3980  // When storing ParmVarDecls in the local instantiation scope, we always
3981  // want to use the ParmVarDecl from the canonical function declaration,
3982  // since the map is then valid for any redeclaration or definition of that
3983  // function.
3984  if (const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(D)) {
3985  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) {
3986  unsigned i = PV->getFunctionScopeIndex();
3987  // This parameter might be from a freestanding function type within the
3988  // function and isn't necessarily referring to one of FD's parameters.
3989  if (i < FD->getNumParams() && FD->getParamDecl(i) == PV)
3990  return FD->getCanonicalDecl()->getParamDecl(i);
3991  }
3992  }
3993  return D;
3994 }
3995 
3996 
3997 llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *
3999  D = getCanonicalParmVarDecl(D);
4000  for (LocalInstantiationScope *Current = this; Current;
4001  Current = Current->Outer) {
4002 
4003  // Check if we found something within this scope.
4004  const Decl *CheckD = D;
4005  do {
4006  LocalDeclsMap::iterator Found = Current->LocalDecls.find(CheckD);
4007  if (Found != Current->LocalDecls.end())
4008  return &Found->second;
4009 
4010  // If this is a tag declaration, it's possible that we need to look for
4011  // a previous declaration.
4012  if (const TagDecl *Tag = dyn_cast<TagDecl>(CheckD))
4013  CheckD = Tag->getPreviousDecl();
4014  else
4015  CheckD = nullptr;
4016  } while (CheckD);
4017 
4018  // If we aren't combined with our outer scope, we're done.
4019  if (!Current->CombineWithOuterScope)
4020  break;
4021  }
4022 
4023  // If we're performing a partial substitution during template argument
4024  // deduction, we may not have values for template parameters yet.
4025  if (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D) ||
4026  isa<TemplateTemplateParmDecl>(D))
4027  return nullptr;
4028 
4029  // Local types referenced prior to definition may require instantiation.
4030  if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D))
4031  if (RD->isLocalClass())
4032  return nullptr;
4033 
4034  // Enumeration types referenced prior to definition may appear as a result of
4035  // error recovery.
4036  if (isa<EnumDecl>(D))
4037  return nullptr;
4038 
4039  // Materialized typedefs/type alias for implicit deduction guides may require
4040  // instantiation.
4041  if (isa<TypedefNameDecl>(D) &&
4042  isa<CXXDeductionGuideDecl>(D->getDeclContext()))
4043  return nullptr;
4044 
4045  // If we didn't find the decl, then we either have a sema bug, or we have a
4046  // forward reference to a label declaration. Return null to indicate that
4047  // we have an uninstantiated label.
4048  assert(isa<LabelDecl>(D) && "declaration not instantiated in this scope");
4049  return nullptr;
4050 }
4051 
4053  D = getCanonicalParmVarDecl(D);
4054  llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
4055  if (Stored.isNull()) {
4056 #ifndef NDEBUG
4057  // It should not be present in any surrounding scope either.
4058  LocalInstantiationScope *Current = this;
4059  while (Current->CombineWithOuterScope && Current->Outer) {
4060  Current = Current->Outer;
4061  assert(Current->LocalDecls.find(D) == Current->LocalDecls.end() &&
4062  "Instantiated local in inner and outer scopes");
4063  }
4064 #endif
4065  Stored = Inst;
4066  } else if (DeclArgumentPack *Pack = Stored.dyn_cast<DeclArgumentPack *>()) {
4067  Pack->push_back(cast<VarDecl>(Inst));
4068  } else {
4069  assert(Stored.get<Decl *>() == Inst && "Already instantiated this local");
4070  }
4071 }
4072 
4074  VarDecl *Inst) {
4075  D = getCanonicalParmVarDecl(D);
4076  DeclArgumentPack *Pack = LocalDecls[D].get<DeclArgumentPack *>();
4077  Pack->push_back(Inst);
4078 }
4079 
4081 #ifndef NDEBUG
4082  // This should be the first time we've been told about this decl.
4083  for (LocalInstantiationScope *Current = this;
4084  Current && Current->CombineWithOuterScope; Current = Current->Outer)
4085  assert(Current->LocalDecls.find(D) == Current->LocalDecls.end() &&
4086  "Creating local pack after instantiation of local");
4087 #endif
4088 
4089  D = getCanonicalParmVarDecl(D);
4090  llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
4091  DeclArgumentPack *Pack = new DeclArgumentPack;
4092  Stored = Pack;
4093  ArgumentPacks.push_back(Pack);
4094 }
4095 
4097  for (DeclArgumentPack *Pack : ArgumentPacks)
4098  if (llvm::is_contained(*Pack, D))
4099  return true;
4100  return false;
4101 }
4102 
4104  const TemplateArgument *ExplicitArgs,
4105  unsigned NumExplicitArgs) {
4106  assert((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) &&
4107  "Already have a partially-substituted pack");
4108  assert((!PartiallySubstitutedPack
4109  || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) &&
4110  "Wrong number of arguments in partially-substituted pack");
4111  PartiallySubstitutedPack = Pack;
4112  ArgsInPartiallySubstitutedPack = ExplicitArgs;
4113  NumArgsInPartiallySubstitutedPack = NumExplicitArgs;
4114 }
4115 
4117  const TemplateArgument **ExplicitArgs,
4118  unsigned *NumExplicitArgs) const {
4119  if (ExplicitArgs)
4120  *ExplicitArgs = nullptr;
4121  if (NumExplicitArgs)
4122  *NumExplicitArgs = 0;
4123 
4124  for (const LocalInstantiationScope *Current = this; Current;
4125  Current = Current->Outer) {
4126  if (Current->PartiallySubstitutedPack) {
4127  if (ExplicitArgs)
4128  *ExplicitArgs = Current->ArgsInPartiallySubstitutedPack;
4129  if (NumExplicitArgs)
4130  *NumExplicitArgs = Current->NumArgsInPartiallySubstitutedPack;
4131 
4132  return Current->PartiallySubstitutedPack;
4133  }
4134 
4135  if (!Current->CombineWithOuterScope)
4136  break;
4137  }
4138 
4139  return nullptr;
4140 }
clang::ElaboratedTypeKeyword
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition: Type.h:5552
clang::DeclaratorDecl::getInnerLocStart
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition: Decl.h:801
clang::TagDecl::getKindName
StringRef getKindName() const
Definition: Decl.h:3616
clang::ASTConsumer::HandleTagDeclDefinition
virtual void HandleTagDeclDefinition(TagDecl *D)
HandleTagDeclDefinition - This callback is invoked each time a TagDecl (e.g.
Definition: ASTConsumer.h:72
clang::Sema::CurContext
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:421
clang::SubstNonTypeTemplateParmExpr
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:4269
clang::Expr::getValueKind
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:430
clang::MultiLevelTemplateArgumentList::setArgument
void setArgument(unsigned Depth, unsigned Index, TemplateArgument Arg)
Clear out a specific template argument.
Definition: Template.h:196
clang::ASTContext::getQualifiedType
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:2139
clang::concepts::ExprRequirement::getExprSubstitutionDiagnostic
SubstitutionDiagnostic * getExprSubstitutionDiagnostic() const
Definition: ExprConcepts.h:382
clang::Type::isRecordType
bool isRecordType() const
Definition: Type.h:6973
clang::Sema::warnStackExhausted
void warnStackExhausted(SourceLocation Loc)
Warn that the stack is nearly exhausted.
Definition: Sema.cpp:494
NeedsInstantiationAsFunctionType
static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T)
Definition: SemaTemplateInstantiate.cpp:2461
clang::TypeLocBuilder::pushTrivial
void pushTrivial(ASTContext &Context, QualType T, SourceLocation Loc)
Pushes 'T' with all locations pointing to 'Loc'.
Definition: TypeLocBuilder.cpp:44
clang::isLambdaCallOperator
bool isLambdaCallOperator(const CXXMethodDecl *MD)
Definition: ASTLambda.h:27
clang::Sema::InstantiatingTemplate::ParameterMappingSubstitution
Definition: Sema.h:9526
clang::ParenType::getInnerType
QualType getInnerType() const
Definition: Type.h:2752
clang::Sema::runWithSufficientStackSpace
void runWithSufficientStackSpace(SourceLocation Loc, llvm::function_ref< void()> Fn)
Run some code with "sufficient" stack space.
Definition: Sema.cpp:502
clang::ParmVarDecl::setUnparsedDefaultArg
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition: Decl.h:1841
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:3043
clang::Sema::CheckPlaceholderExpr
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
Definition: SemaExpr.cpp:20703
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:1583
clang::TemplateDeclInstantiator::delayed_var_partial_spec_begin
delayed_var_partial_spec_iterator delayed_var_partial_spec_begin()
Definition: Template.h:643
clang::Sema::UnparsedDefaultArgInstantiations
UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations
A mapping from parameters with unparsed default arguments to the set of instantiations of each parame...
Definition: Sema.h:1461
clang::Sema::SubstDeclarationNameInfo
DeclarationNameInfo SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, const MultiLevelTemplateArgumentList &TemplateArgs)
Do template substitution on declaration name info.
Definition: SemaTemplateInstantiate.cpp:3961
clang::DeclContext::decls
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:2178
clang::Decl::setDeclContext
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition: DeclBase.cpp:336
clang::Sema::SubstConstraintExpr
ExprResult SubstConstraintExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs)
Definition: SemaTemplateInstantiate.cpp:3915
clang::DeclRefExpr::getLocation
SourceLocation getLocation() const
Definition: Expr.h:1312
TreeTransform.h
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:2792
clang::Sema::deduceOpenCLAddressSpace
void deduceOpenCLAddressSpace(ValueDecl *decl)
Definition: SemaDecl.cpp:6868
clang::TypeSourceInfo::getType
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:6604
clang::concepts::TypeRequirement::getSubstitutionDiagnostic
SubstitutionDiagnostic * getSubstitutionDiagnostic() const
Definition: ExprConcepts.h:234
clang::FunctionTypeLoc::getParams
ArrayRef< ParmVarDecl * > getParams() const
Definition: TypeLoc.h:1449
clang::AttributedType
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:4871
clang::MemberSpecializationInfo
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:630
clang::isStackNearlyExhausted
bool isStackNearlyExhausted()
Determine whether the stack is nearly exhausted.
Definition: Stack.cpp:46
clang::Sema::pushCodeSynthesisContext
void pushCodeSynthesisContext(CodeSynthesisContext Ctx)
Definition: SemaTemplateInstantiate.cpp:581
clang::CXXScopeSpec::Adopt
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition: DeclSpec.cpp:132
clang::TemplateTypeParmType::getDecl
TemplateTypeParmDecl * getDecl() const
Definition: Type.h:5047
clang::Sema::CXXThisScopeRAII
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Definition: Sema.h:6596
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:2801
clang::DeclaratorDecl::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:810
clang::SubstTemplateTypeParmPackType::getArgumentPack
TemplateArgument getArgumentPack() const
Definition: Type.cpp:3698
createSubstDiag
static concepts::Requirement::SubstitutionDiagnostic * createSubstDiag(Sema &S, TemplateDeductionInfo &Info, EntityPrinter Printer)
Definition: SemaTemplateInstantiate.cpp:2156
clang::Expr::isLValue
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
Definition: Expr.h:270
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:210
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1389
clang::Decl::hasAttr
bool hasAttr() const
Definition: DeclBase.h:560
clang::CXXRecordDecl::getMemberSpecializationInfo
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization,...
Definition: DeclCXX.cpp:1825
clang::NonTypeTemplateParmDecl::getIndex
unsigned getIndex() const
Get the index of the template parameter within its parameter list.
Definition: DeclTemplate.h:1196
clang::PartialDiagnostic::NullDiagnostic
Definition: PartialDiagnostic.h:40
clang::TemplateArgument::pack_begin
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
Definition: TemplateBase.h:351
clang::Sema::ActOnFinishCXXNonNestedClass
void ActOnFinishCXXNonNestedClass()
Definition: SemaDeclCXX.cpp:13911
convertCallArgsToString
static std::string convertCallArgsToString(Sema &S, llvm::ArrayRef< const Expr * > Args)
Definition: SemaTemplateInstantiate.cpp:642
clang::getDepthAndIndex
std::pair< unsigned, unsigned > getDepthAndIndex(const NamedDecl *ND)
Retrieve the depth and index of a template parameter.
Definition: SemaInternal.h:65
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:5402
clang::FunctionDecl::isConstexpr
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
Definition: Decl.h:2354
clang::TypeLocBuilder::pushFullCopy
void pushFullCopy(TypeLoc L)
Pushes a copy of the given TypeLoc onto this builder.
Definition: TypeLocBuilder.cpp:18
clang::Sema::ArgumentPackSubstitutionIndex
int ArgumentPackSubstitutionIndex
The current index into pack expansion arguments that will be used for substitution of parameter packs...
Definition: Sema.h:9371
SemaInternal.h
clang::SubstNonTypeTemplateParmPackExpr
Represents a reference to a non-type template parameter pack that has been substituted with a non-tem...
Definition: ExprCXX.h:4354
clang::FunctionParmPackExpr::getParameterPack
VarDecl * getParameterPack() const
Get the parameter pack which this expression refers to.
Definition: ExprCXX.h:4460
llvm::SmallVector
Definition: LLVM.h:38
Lookup.h
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::Sema::CodeSynthesisContext::ParameterMappingSubstitution
@ ParameterMappingSubstitution
Definition: Sema.h:9219
clang::Sema::CodeSynthesisContext::PointOfInstantiation
SourceLocation PointOfInstantiation
The point of instantiation or synthesis within the source code.
Definition: Sema.h:9245
clang::QualType::getQualifiers
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:6662
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:2865
clang::TemplateSpecCandidateSet::getLocation
SourceLocation getLocation() const
Definition: TemplateDeduction.h:345
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:247
clang::Sema::AttachTypeConstraint
bool AttachTypeConstraint(NestedNameSpecifierLoc NS, DeclarationNameInfo NameInfo, ConceptDecl *NamedConcept, const TemplateArgumentListInfo *TemplateArgs, TemplateTypeParmDecl *ConstrainedParameter, SourceLocation EllipsisLoc)
Attach a type-constraint to a template parameter.
Definition: SemaTemplate.cpp:1217
clang::ClassTemplateSpecializationDecl::getSpecializedTemplate
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
Definition: DeclTemplate.cpp:986
clang::TreeTransform
A semantic tree transformation that allows one to transform one abstract syntax tree into another.
Definition: TreeTransform.h:101
TargetInfo.h
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:6020
clang::TypeLocBuilder::getTypeSourceInfo
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
Definition: TypeLocBuilder.h:107
clang::Stmt::getSourceRange
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:324
clang::ConceptReference::getNamedConcept
ConceptDecl * getNamedConcept() const
Definition: ASTConcept.h:154
clang::CXXRecordDecl::getDefinition
CXXRecordDecl * getDefinition() const
Definition: DeclCXX.h:543
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:737
clang::NonTypeTemplateParmDecl
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
Definition: DeclTemplate.h:1410
clang::TemplateName::getAsTemplateDecl
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known.
Definition: TemplateName.cpp:146
clang::EST_None
@ EST_None
no exception specification
Definition: ExceptionSpecificationType.h:21
clang::TypeConstraint::getImmediatelyDeclaredConstraint
Expr * getImmediatelyDeclaredConstraint() const
Get the immediately-declared constraint expression introduced by this type-constraint,...
Definition: ASTConcept.h:187
clang::Sema::SubstTypeConstraint
bool SubstTypeConstraint(TemplateTypeParmDecl *Inst, const TypeConstraint *TC, const MultiLevelTemplateArgumentList &TemplateArgs, bool EvaluateConstraint)
Definition: SemaTemplateInstantiate.cpp:2645
clang::ClassTemplateDecl::getInstantiatedFromMemberTemplate
ClassTemplateDecl * getInstantiatedFromMemberTemplate() const
Definition: DeclTemplate.h:2379
clang::Sema::getMoreSpecializedPartialSpecialization
ClassTemplatePartialSpecializationDecl * getMoreSpecializedPartialSpecialization(ClassTemplatePartialSpecializationDecl *PS1, ClassTemplatePartialSpecializationDecl *PS2, SourceLocation Loc)
Returns the more specialized class template partial specialization according to the rules of partial ...
Definition: SemaTemplateDeduction.cpp:5674
clang::concepts::Requirement::SubstitutionDiagnostic
Definition: ExprConcepts.h:157
clang::FieldDecl
Represents a member of a struct/union/class.
Definition: Decl.h:2930
clang::ClassTemplateSpecializationDecl::getSpecializationKind
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
Definition: DeclTemplate.h:1927
clang::TagDecl::setBraceRange
void setBraceRange(SourceRange R)
Definition: Decl.h:3505
clang::RequiresExpr
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
Definition: ExprConcepts.h:471
clang::FieldDecl::getInClassInitializer
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition: Decl.h:3077
clang::Qualifiers
The collection of all-type qualifiers we support.
Definition: Type.h:147
clang::TemplateDeclInstantiator::delayed_var_partial_spec_iterator
SmallVectorImpl< std::pair< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > >::iterator delayed_var_partial_spec_iterator
Definition: Template.h:633
clang::ParmVarDecl
Represents a parameter to a function.
Definition: Decl.h:1712
clang::Sema::Diag
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: Sema.cpp:1881
clang::ParmVarDecl::getDefaultArg
Expr * getDefaultArg()
Definition: Decl.cpp:2884
int
__device__ int
Definition: __clang_hip_libdevice_declares.h:63
clang::Sema::ContextRAII::pop
void pop()
Definition: Sema.h:1020
clang::concepts::NestedRequirement::getSubstitutionDiagnostic
SubstitutionDiagnostic * getSubstitutionDiagnostic() const
Definition: ExprConcepts.h:437
clang::Sema::CodeSynthesisContexts
SmallVector< CodeSynthesisContext, 16 > CodeSynthesisContexts
List of active code synthesis contexts.
Definition: Sema.h:9306
clang::TemplateArgument::Declaration
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
Definition: TemplateBase.h:74
clang::ClassTemplateSpecializationDecl::setInstantiationOf
void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs)
Note that this class template specialization is actually an instantiation of the given class template...
Definition: DeclTemplate.h:2023
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:2004
clang::NonTypeTemplateParmDecl::getExpansionType
QualType getExpansionType(unsigned I) const
Retrieve a particular expansion type within an expanded parameter pack.
Definition: DeclTemplate.h:1570
clang::ImplicitConceptSpecializationDecl::getTemplateArguments
ArrayRef< TemplateArgument > getTemplateArguments() const
Definition: DeclTemplate.h:3327
clang::MultiLevelTemplateArgumentList::getAssociatedDecl
std::pair< Decl *, bool > getAssociatedDecl(unsigned Depth) const
A template-like entity which owns the whole pattern being substituted.
Definition: Template.h:163
clang::TemplateDeclInstantiator::delayed_partial_spec_end
delayed_partial_spec_iterator delayed_partial_spec_end()
Return an iterator to the end of the set of "delayed" partial specializations, which must be passed t...
Definition: Template.h:651
clang::concepts::ExprRequirement::getExpr
Expr * getExpr() const
Definition: ExprConcepts.h:389
llvm::Optional
Definition: LLVM.h:40
clang::Sema::PrintInstantiationStack
void PrintInstantiationStack()
Prints the current instantiation stack through a series of notes.
Definition: SemaTemplateInstantiate.cpp:676
TypeVisitor.h
clang::TypeLoc::getEndLoc
SourceLocation getEndLoc() const
Get the end source location.
Definition: TypeLoc.cpp:234
clang::Sema::ActOnFields
void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl, ArrayRef< Decl * > Fields, SourceLocation LBrac, SourceLocation RBrac, const ParsedAttributesView &AttrList)
Definition: SemaDecl.cpp:18320
clang::TagType
Definition: Type.h:4792
clang::Sema::CheckCompletedCXXClass
void CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record)
Perform semantic checks on a class definition that has been completing, introducing implicitly-declar...
Definition: SemaDeclCXX.cpp:6768
clang::Type::isVoidType
bool isVoidType() const
Definition: Type.h:7180
clang::Sema::ActOnFinishCXXInClassMemberInitializer
void ActOnFinishCXXInClassMemberInitializer(Decl *VarDecl, SourceLocation EqualLoc, Expr *Init)
This is invoked after parsing an in-class initializer for a non-static C++ class member,...
Definition: SemaDeclCXX.cpp:4045
clang::TypeSpecTypeLoc::getNameLoc
SourceLocation getNameLoc() const
Definition: TypeLoc.h:523
clang::TemplateArgument::isNull
bool isNull() const
Determine whether this template argument has no value.
Definition: TemplateBase.h:247
getPatternForClassTemplateSpecialization
static ActionResult< CXXRecordDecl * > getPatternForClassTemplateSpecialization(Sema &S, SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK)
Get the instantiation pattern to use to instantiate the definition of a given ClassTemplateSpecializa...
Definition: SemaTemplateInstantiate.cpp:3463
DeclSpec.h
clang::printTemplateArgumentList
void printTemplateArgumentList(raw_ostream &OS, ArrayRef< TemplateArgument > Args, const PrintingPolicy &Policy, const TemplateParameterList *TPL=nullptr)
Print a template argument list, including the '<' and '>' enclosing the template arguments.
Definition: TypePrinter.cpp:2152
clang::LocalInstantiationScope::deleteScopes
static void deleteScopes(LocalInstantiationScope *Scope, LocalInstantiationScope *Outermost)
deletes the given scope, and all outer scopes, down to the given outermost scope.
Definition: Template.h:466
clang::DeclaratorDecl::getOuterLocStart
SourceLocation getOuterLocStart() const
Return start of source range taking into account any outer template declarations.
Definition: Decl.cpp:1975
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:9363
clang::CXXScopeSpec
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:65
clang::InitializedEntity::InitializeParameter
static InitializedEntity InitializeParameter(ASTContext &Context, ParmVarDecl *Parm)
Create the initialization entity for a parameter.
Definition: Initialization.h:253
clang::ClassTemplatePartialSpecializationDecl
Definition: DeclTemplate.h:2101
clang::ReferenceType::getPointeeTypeAsWritten
QualType getPointeeTypeAsWritten() const
Definition: Type.h:2896
clang::Sema::CheckFunctionConstraints
bool CheckFunctionConstraints(const FunctionDecl *FD, ConstraintSatisfaction &Satisfaction, SourceLocation UsageLoc=SourceLocation(), bool ForOverloadResolution=false)
Check whether the given function decl's trailing requires clause is satisfied, if any.
Definition: SemaConcept.cpp:583
clang::Sema::LastEmittedCodeSynthesisContextDepth
unsigned LastEmittedCodeSynthesisContextDepth
The depth of the context stack at the point when the most recent error or warning was produced.
Definition: Sema.h:9355
clang::TemplateDeclInstantiator::disableLateAttributeInstantiation
void disableLateAttributeInstantiation()
Definition: Template.h:622
ASTLambda.h
clang::concepts::Requirement::isSatisfied
bool isSatisfied() const
Definition: ExprConcepts.h:174
clang::FunctionParmPackExpr::Create
static FunctionParmPackExpr * Create(const ASTContext &Context, QualType T, VarDecl *ParamPack, SourceLocation NameLoc, ArrayRef< VarDecl * > Params)
Definition: ExprCXX.cpp:1626
print
void print(llvm::raw_ostream &OS, const Pointer &P, ASTContext &Ctx, QualType Ty)
Definition: InterpFrame.cpp:94
clang::InitializationSequence
Describes the sequence of initializations required to initialize a given object or reference with a s...
Definition: Initialization.h:788
clang::TypeDecl::setLocStart
void setLocStart(SourceLocation L)
Definition: Decl.h:3261
clang::NamedDecl::getNameForDiagnostic
virtual void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const
Appends a human-readable name for this declaration into the given stream.
Definition: Decl.cpp:1769
clang::FunctionType
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3675
clang::VarTemplateSpecializationDecl
Represents a variable template specialization, which refers to a variable template with a given set o...
Definition: DeclTemplate.h:2690
clang::TemplateName::getNameToSubstitute
TemplateName getNameToSubstitute() const
Get the template name to substitute when this template name is used as a template template argument.
Definition: TemplateName.cpp:218
clang::TemplateArgument::getAsExpr
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:341
clang::DeclarationName
The name of a declaration.
Definition: DeclarationName.h:144
End
SourceLocation End
Definition: USRLocFinder.cpp:167
clang::ASTContext::getTranslationUnitDecl
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1089
clang::Sema::BuildExpressionFromIntegralTemplateArgument
ExprResult BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, SourceLocation Loc)
Construct a new expression that refers to the given integral template argument with the given source-...
Definition: SemaTemplate.cpp:7889
clang::TemplateArgument::Expression
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
Definition: TemplateBase.h:96
clang::ASTTemplateArgumentListInfo::arguments
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:643
clang::Sema::CodeSynthesisContextLookupModules
SmallVector< Module *, 16 > CodeSynthesisContextLookupModules
Extra modules inspected when performing a lookup during a template instantiation.
Definition: Sema.h:9317
clang::EnumDecl::setTemplateSpecializationKind
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
For an enumeration member that was instantiated from a member enumeration of a templated class,...
Definition: Decl.cpp:4599
clang::CXXRecordDecl::getLambdaContextDecl
Decl * getLambdaContextDecl() const
Retrieve the declaration that provides additional context for a lambda, when the normal declaration c...
Definition: DeclCXX.cpp:1629
clang::EnumDecl
Represents an enum.
Definition: Decl.h:3705
clang::Sema::Context
ASTContext & Context
Definition: Sema.h:409
clang::TemplateTypeParmDecl::setTypeConstraint
void setTypeConstraint(NestedNameSpecifierLoc NNS, DeclarationNameInfo NameInfo, NamedDecl *FoundDecl, ConceptDecl *CD, const ASTTemplateArgumentListInfo *ArgsAsWritten, Expr *ImmediatelyDeclaredConstraint)
Definition: DeclTemplate.cpp:703
clang::Sema::InstantiatingTemplate::isAlreadyInstantiating
bool isAlreadyInstantiating() const
Determine whether we are already instantiating this specialization in some surrounding active instant...
Definition: Sema.h:9562
clang::PredefinedExpr::getIdentKind
IdentKind getIdentKind() const
Definition: Expr.h:2016
clang::Sema::CodeSynthesisContext::SynthesisKind
SynthesisKind
The kind of template instantiation we are performing.
Definition: Sema.h:9139
clang::ExprError
ExprResult ExprError()
Definition: Ownership.h:278
clang::Sema::SFINAETrap
RAII class used to determine whether SFINAE has trapped any errors that occur during template argumen...
Definition: Sema.h:9632
clang::FunctionDecl::isVirtualAsWritten
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition: Decl.h:2235
clang::Sema::MarkVirtualMembersReferenced
void MarkVirtualMembersReferenced(SourceLocation Loc, const CXXRecordDecl *RD, bool ConstexprOnly=false)
MarkVirtualMembersReferenced - Will mark all members of the given CXXRecordDecl referenced.
Definition: SemaDeclCXX.cpp:18114
clang::TypeLoc::getBeginLoc
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:191
clang::Sema::CodeSynthesisContext::DefaultTemplateArgumentInstantiation
@ DefaultTemplateArgumentInstantiation
We are instantiating a default argument for a template parameter.
Definition: Sema.h:9149
clang::Sema::InstantiatingTemplate::ConstraintsCheck
Definition: Sema.h:9502
clang::Sema::getLangOpts
const LangOptions & getLangOpts() const
Definition: Sema.h:1630
clang::ClassTemplateDecl::getPartialSpecializations
llvm::FoldingSetVector< ClassTemplatePartialSpecializationDecl > & getPartialSpecializations() const
Retrieve the set of partial specializations of this class template.
Definition: DeclTemplate.cpp:489
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:686
clang::FunctionParmPackExpr
Represents a reference to a function parameter pack or init-capture pack that has been substituted bu...
Definition: ExprCXX.h:4431
ExprConcepts.h
clang::Sema::CodeSynthesisContext::ConstraintSubstitution
@ ConstraintSubstitution
Definition: Sema.h:9209
clang::CXXRecordDecl::getDescribedClassTemplate
ClassTemplateDecl * getDescribedClassTemplate() const
Retrieves the class template that is described by this class declaration.
Definition: DeclCXX.cpp:1839
clang::TagDecl::setTagKind
void setTagKind(TagKind TK)
Definition: Decl.h:3624
clang::TemplateArgument::NullPtr
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:78
clang::Decl::isFileContextDecl
bool isFileContextDecl() const
Definition: DeclBase.cpp:408
clang::ParmVarDecl::setScopeInfo
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition: Decl.h:1745
clang::Decl::getLexicalDeclContext
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition: DeclBase.h:883
clang::Sema::SubstTemplateName
TemplateName SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, SourceLocation Loc, const MultiLevelTemplateArgumentList &TemplateArgs)
Definition: SemaTemplateInstantiate.cpp:3969
clang::VarDecl::isParameterPack
bool isParameterPack() const
Determine whether this variable is actually a function parameter pack or init-capture pack.
Definition: Decl.cpp:2579
clang::Sema::CodeSynthesisContext::TemplateArgs
const TemplateArgument * TemplateArgs
The list of template arguments we are substituting, if they are not part of the entity.
Definition: Sema.h:9258
clang::FunctionTemplateDecl
Declaration of a template function.
Definition: DeclTemplate.h:1006
clang::FunctionParmPackExpr::begin
iterator begin() const
Definition: ExprCXX.h:4468
clang::concepts::NestedRequirement::getConstraintExpr
Expr * getConstraintExpr() const
Definition: ExprConcepts.h:444
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:1818
clang::TypeLocBuilder::push
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
Definition: TypeLocBuilder.h:99
clang::Type::isReferenceType
bool isReferenceType() const
Definition: Type.h:6895
clang::PackExpansionTypeLoc
Definition: TypeLoc.h:2521
clang::TSK_ExplicitInstantiationDeclaration
@ TSK_ExplicitInstantiationDeclaration
This template specialization was instantiated from a template due to an explicit instantiation declar...
Definition: Specifiers.h:190
Template.h
clang::PackExpansionType::getPattern
QualType getPattern() const
Retrieve the pattern of this pack expansion, which is the type that will be repeatedly instantiated w...
Definition: Type.h:5851
clang::Sema::NonInstantiationEntries
unsigned NonInstantiationEntries
The number of CodeSynthesisContexts that are not template instantiations and, therefore,...
Definition: Sema.h:9347
clang::Sema::BuildCXXDefaultArgExpr
ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, ParmVarDecl *Param)
BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating the default expr if needed.
Definition: SemaExpr.cpp:5912
clang::ConceptReference::getTemplateArgsAsWritten
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Definition: ASTConcept.h:158
clang::ElaboratedType
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:5628
clang::Expr::isTypeDependent
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition: Expr.h:185
clang::Sema::CodeSynthesisContext::Template
NamedDecl * Template
The template (or partial specialization) in which we are performing the instantiation,...
Definition: Sema.h:9253
clang::TypeWithKeyword::getTagTypeKindForKeyword
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition: Type.cpp:2844
clang::VarDecl::getInstantiatedFromStaticDataMember
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization,...
Definition: Decl.cpp:2665
clang::RecordType
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4816
clang::TemplateArgument::getKind
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:244
clang::Sema::AttachBaseSpecifiers
bool AttachBaseSpecifiers(CXXRecordDecl *Class, MutableArrayRef< CXXBaseSpecifier * > Bases)
Performs the actual work of attaching the given base class specifiers to a C++ class.
Definition: SemaDeclCXX.cpp:2743
clang::Sema::CTAK_Specified
@ CTAK_Specified
The template argument was specified in the code or was instantiated with some deduced template argume...
Definition: Sema.h:8265
clang::Sema::CodeSynthesisContext::ExceptionSpecInstantiation
@ ExceptionSpecInstantiation
We are instantiating the exception specification for a function template which was deferred until it ...
Definition: Sema.h:9182
clang::SubstTemplateTypeParmPackTypeLoc
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:849
clang::Module
Describes a module or submodule.
Definition: Module.h:98
clang::ClassTemplateSpecializationDecl::getTemplateArgs
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
Definition: DeclTemplate.h:1917
clang::TemplateParameterList::getParam
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:139
DeclTemplate.h
clang::PackExpansionType
Represents a pack expansion of types.
Definition: Type.h:5830
clang::Sema::CodeSynthesisContext::isInstantiationRecord
bool isInstantiationRecord() const
Determines whether this template is an actual instantiation that should be counted toward the maximum...
Definition: SemaTemplateInstantiate.cpp:338
clang::RequiresExprBodyDecl
Represents the body of a requires-expression.
Definition: DeclCXX.h:1961
clang::PartialDiagnosticAt
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs.
Definition: PartialDiagnostic.h:205
clang::Sema::getDiagnostics
DiagnosticsEngine & getDiagnostics() const
Definition: Sema.h:1634
clang::TemplateArgumentListInfo
A convenient class for passing around template argument information.
Definition: TemplateBase.h:563
clang::Sema::ArgumentPackSubstitutionIndexRAII
RAII object used to change the argument pack substitution index within a Sema object.
Definition: Sema.h:9377
clang::QualType::getNonLValueExprType
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type.
Definition: Type.cpp:3126
clang::DeclAccessPair::make
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
Definition: DeclAccessPair.h:35
clang::Stmt::printPretty
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
Definition: StmtPrinter.cpp:2737
clang::TagTypeKind
TagTypeKind
The kind of a tag type.
Definition: Type.h:5533
clang::Sema::UpdateExceptionSpec
void UpdateExceptionSpec(FunctionDecl *FD, const FunctionProtoType::ExceptionSpecInfo &ESI)
Definition: SemaExceptionSpec.cpp:242
clang::Sema::ActOnFinishDelayedMemberInitializers
void ActOnFinishDelayedMemberInitializers(Decl *Record)
Definition: SemaDeclCXX.cpp:13590
clang::DiagnosticsEngine::hasFatalErrorOccurred
bool hasFatalErrorOccurred() const
Definition: Diagnostic.h:845
clang::FunctionParmPackExpr::getNumExpansions
unsigned getNumExpansions() const
Get the number of parameters in this parameter pack.
Definition: ExprCXX.h:4472
clang::TemplateTypeParmType::getIndex
unsigned getIndex() const
Definition: Type.h:5044
Id
int Id
Definition: ASTDiff.cpp:189
clang::FunctionProtoType::ExceptionSpecInfo
Holds information about the various types of exception specification.
Definition: Type.h:4073
clang::Sema::hasUncompilableErrorOccurred
bool hasUncompilableErrorOccurred() const
Whether uncompilable error has occurred.
Definition: Sema.cpp:1589
clang::XRayInstrKind::None
constexpr XRayInstrMask None
Definition: XRayInstr.h:38
clang::Sema::CodeSynthesisContext::RequirementParameterInstantiation
@ RequirementParameterInstantiation
Definition: Sema.h:9215
clang::LambdaExpr
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1872
clang::Scope
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
clang::Sema::DefaultedFunctionKind::isComparison
bool isComparison() const
Definition: Sema.h:3363
MatchResult
MatchFinder::MatchResult MatchResult
Definition: RangeSelector.cpp:30
clang::FunctionDecl::getTemplateInstantiationPattern
FunctionDecl * getTemplateInstantiationPattern(bool ForDefinition=true) const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
Definition: Decl.cpp:3867
clang::SubstNonTypeTemplateParmPackExpr::getAssociatedDecl
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: ExprCXX.h:4384
clang::Sema::BuildExpressionFromDeclTemplateArgument
ExprResult BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, QualType ParamType, SourceLocation Loc)
Given a non-type template argument that refers to a declaration and the type of its corresponding non...
Definition: SemaTemplate.cpp:7779
clang::SubstNonTypeTemplateParmExpr::getReplacement
Expr * getReplacement() const
Definition: ExprCXX.h:4307
PrettyDeclStackTrace.h
clang::ParmVarDecl::setDefaultArg
void setDefaultArg(Expr *defarg)
Definition: Decl.cpp:2897
clang::Sema::CodeSynthesisContext::TemplateInstantiation
@ TemplateInstantiation
We are instantiating a template declaration.
Definition: Sema.h:9142
clang::AS_public
@ AS_public
Definition: Specifiers.h:112
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:9782
clang::VectorType
Represents a GCC generic vector type.
Definition: Type.h:3358
clang::VarDecl::getMemberSpecializationInfo
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization,...
Definition: Decl.cpp:2783
clang::VarDecl::isStaticDataMember
bool isStaticDataMember() const
Determines whether this is a static data member.
Definition: Decl.h:1230
clang::Sema::CodeSynthesisContext::RequirementInstantiation
@ RequirementInstantiation
We are instantiating a requirement of a requires expression.
Definition: Sema.h:9185
clang::Sema::InstantiatingTemplate::ConstraintSubstitution
Definition: Sema.h:9511
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:209
clang::TemplateDeclInstantiator
Definition: Template.h:526
clang::Sema::InstantiateAttrs
void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, const Decl *Pattern, Decl *Inst, LateInstantiatedAttrVec *LateAttrs=nullptr, LocalInstantiationScope *OuterMostScope=nullptr)
Definition: SemaTemplateInstantiateDecl.cpp:695
clang::ArrayType
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3012
clang::DeclaratorContext::Member
@ Member
LangOptions.h
clang::MemberPointerType::getPointeeType
QualType getPointeeType() const
Definition: Type.h:2976
getCanonicalParmVarDecl
static const Decl * getCanonicalParmVarDecl(const Decl *D)
Definition: SemaTemplateInstantiate.cpp:3979
Depth
int Depth
Definition: ASTDiff.cpp:189
clang::EnumDecl::getDefinition
EnumDecl * getDefinition() const
Definition: Decl.h:3808
clang::concepts::NestedRequirement
A requires-expression requirement which is satisfied when a general constraint expression is satisfie...
Definition: ExprConcepts.h:403
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7386
TemplateInstArgsHelpers
Definition: SemaTemplateInstantiate.cpp:44
clang::CXXRecordDecl::getNumBases
unsigned getNumBases() const
Retrieves the number of base classes of this class.
Definition: DeclCXX.h:591
clang::Decl::isInvalidDecl
bool isInvalidDecl() const
Definition: DeclBase.h:571
clang::TemplateSpecCandidate::set
void set(DeclAccessPair Found, Decl *Spec, DeductionFailureInfo Info)
Definition: TemplateDeduction.h:312
clang::Sema::SubstTemplateArguments
bool SubstTemplateArguments(ArrayRef< TemplateArgumentLoc > Args, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateArgumentListInfo &Outputs)
Definition: SemaTemplateInstantiate.cpp:3894
clang::sema::instantiateTemplateAttribute
Attr * instantiateTemplateAttribute(const Attr *At, ASTContext &C, Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs)
clang::TemplateArgument
Represents a template argument.
Definition: TemplateBase.h:61
clang::atTemplateEnd
void atTemplateEnd(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema, const Sema::CodeSynthesisContext &Inst)
Definition: TemplateInstCallback.h:71
clang::MemberSpecializationInfo::setTemplateSpecializationKind
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the template specialization kind.
Definition: DeclTemplate.h:661
TemplateInstCallback.h
clang::concepts::Requirement
A static requirement that can be used in a requires-expression to check properties of types and expre...
Definition: ExprConcepts.h:145
clang::sema::instantiateTemplateAttributeForDecl
Attr * instantiateTemplateAttributeForDecl(const Attr *At, ASTContext &C, Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs)
clang::MultiLevelTemplateArgumentList
Data structure that captures multiple levels of template argument lists for use in template instantia...
Definition: Template.h:75
clang::sema::TemplateDeductionInfo::takeCanonical
TemplateArgumentList * takeCanonical()
Definition: TemplateDeduction.h:100
clang::Sema::CodeSynthesisContext::DeducedTemplateArgumentSubstitution
@ DeducedTemplateArgumentSubstitution
We are substituting template argument determined as part of template argument deduction for either a ...
Definition: Sema.h:9165
clang::Sema::CheckTemplateArgument
bool CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg, NamedDecl *Template, SourceLocation TemplateLoc, SourceLocation RAngleLoc, unsigned ArgumentPackIndex, SmallVectorImpl< TemplateArgument > &SugaredConverted, SmallVectorImpl< TemplateArgument > &CanonicalConverted, CheckTemplateArgumentKind CTAK)
Check that the given template argument corresponds to the given template parameter.
Definition: SemaTemplate.cpp:5536
clang::Sema::Diags
DiagnosticsEngine & Diags
Definition: Sema.h:411
clang::ParmVarDecl::hasUnparsedDefaultArg
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition: Decl.h:1829
clang::Decl::getCanonicalDecl
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:943
clang::EnumDecl::getMemberSpecializationInfo
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition: Decl.h:3964
clang::MacroQualifiedType
Sugar type that represents a type that was qualified by a qualifier written as a macro invocation.
Definition: Type.h:4571
clang::Stmt::getEndLoc
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:348
clang::Sema::InstantiatingTemplate::isInvalid
bool isInvalid() const
Determines whether we have exceeded the maximum recursive template instantiations.
Definition: Sema.h:9558
clang::DeclContext::isTranslationUnit
bool isTranslationUnit() const
Definition: DeclBase.h:1998
clang::DeclRefExpr::getDecl
ValueDecl * getDecl()
Definition: Expr.h:1304
clang::Sema::InstantiateClassTemplateSpecializationMembers
void InstantiateClassTemplateSpecializationMembers(SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK)
Instantiate the definitions of all of the members of the given class template specialization,...
Definition: SemaTemplateInstantiate.cpp:3866
clang::TemplateSpecCandidateSet
TemplateSpecCandidateSet - A set of generalized overload candidates, used in template specializations...
Definition: TemplateDeduction.h:326
clang::FieldDecl::hasInClassInitializer
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition: Decl.h:3070
Expr.h
clang::Sema::CodeSynthesisContext
A context in which code is being synthesized (where a source location alone is not sufficient to iden...
Definition: Sema.h:9137
llvm::SmallString< 128 >
clang::TemplateTemplateParmDecl
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
Definition: DeclTemplate.h:1627
clang::Sema::getDefaultedFunctionKind
DefaultedFunctionKind getDefaultedFunctionKind(const FunctionDecl *FD)
Determine the kind of defaulting that would be done for a given function.
Definition: SemaDeclCXX.cpp:6541
clang::TemplateArgumentListInfo::setLAngleLoc
void setLAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:582
ASTContext.h
clang::Sema::SubstExpr
ExprResult SubstExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs)
Definition: SemaTemplateInstantiate.cpp:3904
clang::Sema::SubstParmVarDecl
ParmVarDecl * SubstParmVarDecl(ParmVarDecl *D, const MultiLevelTemplateArgumentList &TemplateArgs, int indexAdjustment, Optional< unsigned > NumExpansions, bool ExpectParameterPack, bool EvaluateConstraints=true)
Definition: SemaTemplateInstantiate.cpp:2679
clang::ParmVarDecl::setUninstantiatedDefaultArg
void setUninstantiatedDefaultArg(Expr *arg)
Definition: Decl.cpp:2922
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:906
clang::atTemplateBegin
void atTemplateBegin(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema, const Sema::CodeSynthesisContext &Inst)
Definition: TemplateInstCallback.h:61
clang::Sema::CodeSynthesisContext::NestedRequirementConstraintsCheck
@ NestedRequirementConstraintsCheck
We are checking the satisfaction of a nested requirement of a requires expression.
Definition: Sema.h:9189
getPackSubstitutedTemplateArgument
static TemplateArgument getPackSubstitutedTemplateArgument(Sema &S, TemplateArgument Arg)
Definition: SemaTemplateInstantiate.cpp:1438
clang::TagDecl
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3423
clang::TemplateParameterList
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:70
clang::TSK_ExplicitInstantiationDefinition
@ TSK_ExplicitInstantiationDefinition
This template specialization was instantiated from a template due to an explicit instantiation defini...
Definition: Specifiers.h:194
clang::TemplateDeclInstantiator::setEvaluateConstraints
void setEvaluateConstraints(bool B)
Definition: Template.h:559
clang::MacroQualifiedType::getUnderlyingType
QualType getUnderlyingType() const
Definition: Type.h:4587
clang::MultiLevelTemplateArgumentList::getNumLevels
unsigned getNumLevels() const
Determine the number of levels in this template argument list.
Definition: Template.h:122
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:835
clang::Type::isVariablyModifiedType
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
Definition: Type.h:2322
clang::CXXRecordDecl::bases
base_class_range bases()
Definition: DeclCXX.h:597
clang::Decl::getNonTransparentDeclContext
DeclContext * getNonTransparentDeclContext()
Return the non transparent context.
Definition: DeclBase.cpp:1050
clang::Sema::DeduceTemplateArguments
TemplateDeductionResult DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, const TemplateArgumentList &TemplateArgs, sema::TemplateDeductionInfo &Info)
Perform template argument deduction to determine whether the given template arguments match the given...
Definition: SemaTemplateDeduction.cpp:3046
clang::DeclContextLookupResult::find_first
T * find_first() const
Definition: DeclBase.h:1363
clang::NestedNameSpecifierLoc
A C++ nested-name-specifier augmented with source location information.
Definition: NestedNameSpecifier.h:243
clang::TypeVisitor
An operation on a type.
Definition: TypeVisitor.h:64
Base
clang::TemplateArgument::isPackExpansion
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
Definition: TemplateBase.cpp:247
clang::ClassTemplateSpecializationDecl::getTemplateInstantiationArgs
const TemplateArgumentList & getTemplateInstantiationArgs() const
Retrieve the set of template arguments that should be used to instantiate members of the class templa...
Definition: DeclTemplate.h:2012
clang::SubstTemplateTemplateParmPackStorage
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:139
clang::SubstTemplateTypeParmPackType
Represents the result of substituting a set of types for a template type parameter pack.
Definition: Type.h:5154
clang::CXXDefaultArgExpr
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1248
ASTConcept.h
This file provides AST data structures related to concepts.
clang::Sema::InstantiatingTemplate::ConstraintNormalization
Definition: Sema.h:9520
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:4797
clang::concepts::TypeRequirement::isSubstitutionFailure
bool isSubstitutionFailure() const
Definition: ExprConcepts.h:230
clang::BlockPointerType
Pointer to a block type.
Definition: Type.h:2849
clang::Sema::InstantiatingSpecializations
llvm::DenseSet< std::pair< Decl *, unsigned > > InstantiatingSpecializations
Specializations whose definitions are currently being instantiated.
Definition: Sema.h:9309
clang::Sema::getASTMutationListener
ASTMutationListener * getASTMutationListener() const
Definition: Sema.cpp:532
clang::TemplateTypeParmDecl
Declaration of a template type parameter.
Definition: DeclTemplate.h:1205
clang::ParmVarDecl::getFunctionScopeDepth
unsigned getFunctionScopeDepth() const
Definition: Decl.h:1762
clang::ClassTemplateSpecializationDecl::getSpecializedTemplateOrPartial
llvm::PointerUnion< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > getSpecializedTemplateOrPartial() const
Retrieve the class template or class template partial specialization which was specialized by this.
Definition: DeclTemplate.h:1993
clang::AdjustedType
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons.
Definition: Type.h:2798
clang::TemplateParameterList::getTemplateLoc
SourceLocation getTemplateLoc() const
Definition: DeclTemplate.h:194
clang::TypeLocBuilder
Definition: TypeLocBuilder.h:22
clang::TemplateName::isNull
bool isNull() const
Determine whether this template name is NULL.
Definition: TemplateName.cpp:120
clang::Decl::isImplicit
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:576
clang::MemberSpecializationInfo::getPointOfInstantiation
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
Definition: DeclTemplate.h:670
clang::ConstraintSatisfaction::IsSatisfied
bool IsSatisfied
Definition: ASTConcept.h:46
clang::Sema::ConstraintEvalRAII
Definition: Sema.h:9877
clang::TypeLocBuilder::reserve
void reserve(size_t Requested)
Ensures that this buffer has at least as much capacity as described.
Definition: TypeLocBuilder.h:57
clang::ASTConsumer::HandleTopLevelDecl
virtual bool HandleTopLevelDecl(DeclGroupRef D)
HandleTopLevelDecl - Handle the specified top-level declaration.
Definition: ASTConsumer.cpp:18
clang::TemplateDecl::getTemplateParameters
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:427
clang::Sema::DefaultedFunctionKind::isSpecialMember
bool isSpecialMember() const
Definition: Sema.h:3362
clang::ETK_None
@ ETK_None
No keyword precedes the qualified type name.
Definition: Type.h:5573
clang::QualType::getUnqualifiedType
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:6715
clang::DeclarationNameInfo::getName
DeclarationName getName() const
getName - Returns the embedded declaration name.
Definition: DeclarationName.h:790
clang::isGenericLambdaCallOperatorOrStaticInvokerSpecialization
bool isGenericLambdaCallOperatorOrStaticInvokerSpecialization(const DeclContext *DC)
Definition: ASTLambda.h:67
clang::Sema::CodeSynthesisContext::ExplicitTemplateArgumentSubstitution
@ ExplicitTemplateArgumentSubstitution
We are substituting explicit template arguments provided for a function template.
Definition: Sema.h:9158
clang::ParmVarDecl::setHasInheritedDefaultArg
void setHasInheritedDefaultArg(bool I=true)
Definition: Decl.h:1849
clang::TemplateArgumentList::asArray
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Definition: DeclTemplate.h:291
clang::Decl::castFromDeclContext
static Decl * castFromDeclContext(const DeclContext *)
Definition: DeclBase.cpp:930
clang::TemplateTypeParmType
Definition: Type.h:5002
clang::Sema::InstantiateInClassInitializer
bool InstantiateInClassInitializer(SourceLocation PointOfInstantiation, FieldDecl *Instantiation, FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs)
Instantiate the definition of a field from the given pattern.
Definition: SemaTemplateInstantiate.cpp:3367
clang::Sema::isAcceptableTagRedeclaration
bool isAcceptableTagRedeclaration(const TagDecl *Previous, TagTypeKind NewTag, bool isDefinition, SourceLocation NewTagLoc, const IdentifierInfo *Name)
Determine whether a tag with a given kind is acceptable as a redeclaration of the given tag declarati...
Definition: SemaDecl.cpp:16194
clang::VK_LValue
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:127
clang::Sema::getTemplateInstantiationArgs
MultiLevelTemplateArgumentList getTemplateInstantiationArgs(const NamedDecl *D, bool Final=false, const TemplateArgumentList *Innermost=nullptr, bool RelativeToPrimary=false, const FunctionDecl *Pattern=nullptr, bool ForConstraintInstantiation=false, bool SkipForSpecialization=false)
Retrieve the template argument list(s) that should be used to instantiate the definition of the given...
Definition: SemaTemplateInstantiate.cpp:284
clang::ParmVarDecl::getUninstantiatedDefaultArg
Expr * getUninstantiatedDefaultArg()
Definition: Decl.cpp:2927
clang::Sema::InstantiatingTemplate::InstantiatingTemplate
InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, Decl *Entity, SourceRange InstantiationRange=SourceRange())
Note that we are instantiating a class template, function template, variable template,...
Definition: SemaTemplateInstantiate.cpp:410
clang::TemplateName::getAsQualifiedTemplateName
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
Definition: TemplateName.cpp:201
clang::Sema::CheckLoopHintExpr
bool CheckLoopHintExpr(Expr *E, SourceLocation Loc)
Definition: SemaExpr.cpp:3715
clang::TemplateDeclInstantiator::delayed_var_partial_spec_end
delayed_var_partial_spec_iterator delayed_var_partial_spec_end()
Definition: Template.h:655
clang::TargetInfo::getTriple
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:1195
clang::TemplateDeclInstantiator::delayed_partial_spec_begin
delayed_partial_spec_iterator delayed_partial_spec_begin()
Return an iterator to the beginning of the set of "delayed" partial specializations,...
Definition: Template.h:639
clang::Decl::setLocation
void setLocation(SourceLocation L)
Definition: DeclBase.h:433
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
clang::Sema::MarkVTableUsed
void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, bool DefinitionRequired=false)
Note that the vtable for the given class was used at the given location.
Definition: SemaDeclCXX.cpp:17955
clang::Sema::CodeSynthesisContext::Memoization
@ Memoization
Added for Template instantiation observation.
Definition: Sema.h:9238
clang::EnumDecl::getInstantiatedFromMemberEnum
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition: Decl.cpp:4625
clang::Sema::CodeSynthesisContext::DefaultFunctionArgumentInstantiation
@ DefaultFunctionArgumentInstantiation
We are instantiating a default argument for a function.
Definition: Sema.h:9154
clang::sema::TemplateDeductionInfo::hasSFINAEDiagnostic
bool hasSFINAEDiagnostic() const
Is a SFINAE diagnostic available?
Definition: TemplateDeduction.h:145
clang::declvisitor::Base::Visit
RetTy Visit(PTR(Decl) D)
Definition: DeclVisitor.h:37
clang::EST_Uninstantiated
@ EST_Uninstantiated
not instantiated yet
Definition: ExceptionSpecificationType.h:31
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
clang::SubstTemplateTypeParmTypeLoc
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:842
clang::Sema::TemplateDeductionResult
TemplateDeductionResult
Describes the result of template argument deduction.
Definition: Sema.h:8900
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:2304
clang::Sema::LookupModulesCache
llvm::DenseSet< Module * > LookupModulesCache
Cache of additional modules that should be used for name lookup within the current template instantia...
Definition: Sema.h:9322
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:2312
clang::VK_PRValue
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:123
clang::TemplateSpecializationKind
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:176
clang::Sema::DefaultedFunctionKind
For a defaulted function, the kind of defaulted function that it is.
Definition: Sema.h:3349
clang::TagDecl::startDefinition
void startDefinition()
Starts the definition of this tag declaration.
Definition: Decl.cpp:4424
clang::Decl::getPreviousDecl
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
Definition: DeclBase.h:1026
clang::Decl::getFriendObjectKind
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Definition: DeclBase.h:1185
clang::LocalInstantiationScope::getPartiallySubstitutedPack
NamedDecl * getPartiallySubstitutedPack(const TemplateArgument **ExplicitArgs=nullptr, unsigned *NumExplicitArgs=nullptr) const
Retrieve the partially-substitued template parameter pack.
Definition: SemaTemplateInstantiate.cpp:4116
clang::TypeLoc::getFullDataSize
unsigned getFullDataSize() const
Returns the size of the type source info data block.
Definition: TypeLoc.h:163
clang::SubstNonTypeTemplateParmPackExpr::getParameterPack
NonTypeTemplateParmDecl * getParameterPack() const
Retrieve the non-type template parameter pack being substituted.
Definition: ExprCXX.cpp:1603
clang::Sema::ActOnFinishFullExpr
ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue)
Definition: Sema.h:6830
clang::getAsNamedDecl
NamedDecl * getAsNamedDecl(TemplateParameter P)
Definition: DeclTemplate.h:3411
false
#define false
Definition: stdbool.h:22
clang::MultiLevelTemplateArgumentList::hasTemplateArgument
bool hasTemplateArgument(unsigned Depth, unsigned Index) const
Determine whether there is a non-NULL template argument at the given depth and index.
Definition: Template.h:174
clang::StaticAssertDecl
Represents a C++11 static_assert declaration.
Definition: DeclCXX.h:3959
clang::Sema::SubstStmt
StmtResult SubstStmt(Stmt *S, const MultiLevelTemplateArgumentList &TemplateArgs)
Definition: SemaTemplateInstantiate.cpp:3884
clang::PredefinedExpr::getLocation
SourceLocation getLocation() const
Definition: Expr.h:2020
clang::concepts::TypeRequirement
A requires-expression requirement which queries the existence of a type name or type template special...
Definition: ExprConcepts.h:199
clang::Sema::ExtParameterInfoBuilder
A helper class for building up ExtParameterInfos.
Definition: Sema.h:9807
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:9055
clang::ActionResult::get
PtrTy get() const
Definition: Ownership.h:169
clang::ElaboratedType::getNamedType
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:5669
clang::NamedDecl::getIdentifier
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:268
clang::ASTTemplateArgumentListInfo::LAngleLoc
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
Definition: TemplateBase.h:626
clang::ClassTemplateDecl
Declaration of a class template.
Definition: DeclTemplate.h:2273
clang::ValueDecl
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:701
clang::SubstTemplateTypeParmPackType::getFinal
bool getFinal() const
Definition: Type.cpp:3685
clang::TemplateName
Represents a C++ template name within the type system.
Definition: TemplateName.h:201
clang::VarDecl::getStorageClass
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1115
clang::Sema::CodeSynthesisContext::DeclaringSpecialMember
@ DeclaringSpecialMember
We are declaring an implicit special member function.
Definition: Sema.h:9192
clang::ImplicitConceptSpecializationDecl
Definition: DeclTemplate.h:3309
clang::ASTContext::getTagDeclType
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl.
Definition: ASTContext.cpp:5923
clang::FunctionProtoType
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4016
clang::Expr::getExprLoc
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:329
clang::ASTContext::getPrintingPolicy
const clang::PrintingPolicy & getPrintingPolicy() const
Definition: ASTContext.h:713
clang::TypeLoc::getAs
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition: TypeLoc.h:88
TemplateDeduction.h
clang::TemplateDecl
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:408
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:1559
clang::BlockPointerType::getPointeeType
QualType getPointeeType() const
Definition: Type.h:2861
clang::VarTemplatePartialSpecializationDecl
Definition: DeclTemplate.h:2952
clang::TemplateDeclInstantiator::InstantiateEnumDefinition
void InstantiateEnumDefinition(EnumDecl *Enum, EnumDecl *Pattern)
Definition: SemaTemplateInstantiateDecl.cpp:1498
clang::VarDecl::getDefinition
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition: Decl.cpp:2292
clang::QualType::isNull
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:802
llvm::ArrayRef< TemplateArgument >
clang::FunctionParmPackExpr::iterator
VarDecl *const * iterator
Iterators over the parameters which the parameter pack expanded into.
Definition: ExprCXX.h:4467
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
clang::PrettyDeclStackTraceEntry
PrettyDeclStackTraceEntry - If a crash occurs in the parser while parsing something related to a decl...
Definition: PrettyDeclStackTrace.h:29
clang::EnterExpressionEvaluationContext
RAII object that enters a new expression evaluation context.
Definition: Sema.h:13804
clang::ParmVarDecl::getFunctionScopeIndex
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition: Decl.h:1772
clang::Sema::PerformDependentDiagnostics
void PerformDependentDiagnostics(const DeclContext *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs)
Definition: SemaTemplateInstantiateDecl.cpp:6398
clang::TypeLoc
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:58
clang::FunctionType::ExtParameterInfo
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
Definition: Type.h:3701
clang::DeclGroupRef
Definition: DeclGroup.h:51
clang::MultiLevelTemplateArgumentList::getInnermost
const ArgList & getInnermost() const
Retrieve the innermost template argument list.
Definition: Template.h:250
clang::MakeDeductionFailureInfo
DeductionFailureInfo MakeDeductionFailureInfo(ASTContext &Context, Sema::TemplateDeductionResult TDK, sema::TemplateDeductionInfo &Info)
Convert from Sema's representation of template deduction information to the form used in overload-can...
Definition: SemaOverload.cpp:616
clang::Sema::Consumer
ASTConsumer & Consumer
Definition: Sema.h:410
ASTMutationListener.h
clang::DeclContext::getOuterLexicalRecordContext
RecordDecl * getOuterLexicalRecordContext()
Retrieve the outermost lexically enclosing record context.
Definition: DeclBase.cpp:1854
clang::Sema::popCodeSynthesisContext
void popCodeSynthesisContext()
Definition: SemaTemplateInstantiate.cpp:596
clang::Sema
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:358
clang::DependentSizedExtVectorType::getElementType
QualType getElementType() const
Definition: Type.h:3334
clang::ActionResult::isInvalid
bool isInvalid() const
Definition: Ownership.h:165
clang::TypeLoc::getType
QualType getType() const
Get the type for which this source info wrapper provides information.
Definition: TypeLoc.h:132
clang::NonTypeTemplateParmDecl::getDepth
unsigned getDepth() const
Get the nesting depth of the template parameter.
Definition: DeclTemplate.h:1180
clang::Sema::CodeSynthesisContext::ConstraintsCheck
@ ConstraintsCheck
Definition: Sema.h:9206
clang::Sema::SubstInitializer
ExprResult SubstInitializer(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs, bool CXXDirectInit)
Definition: SemaTemplateInstantiate.cpp:3927
clang::ClassTemplateDecl::getTemplatedDecl
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
Definition: DeclTemplate.h:2321
clang::TSK_ExplicitSpecialization
@ TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp....
Definition: Specifiers.h:186
clang::Sema::DiagnoseUninstantiableTemplate
bool DiagnoseUninstantiableTemplate(SourceLocation PointOfInstantiation, NamedDecl *Instantiation, bool InstantiatedFromMember, const NamedDecl *Pattern, const NamedDecl *PatternDef, TemplateSpecializationKind TSK, bool Complain=true)
Determine whether we would be unable to instantiate this template (because it either has no definitio...
Definition: SemaTemplate.cpp:787
clang::sema::TemplateDeductionInfo::getLocation
SourceLocation getLocation() const
Returns the location at which template argument is occurring.
Definition: TemplateDeduction.h:79
clang::concepts::TypeRequirement::getType
TypeSourceInfo * getType() const
Definition: ExprConcepts.h:241
clang::Sema::CodeSynthesisContext::DefaultTemplateArgumentChecking
@ DefaultTemplateArgumentChecking
We are checking the validity of a default template argument that has been used when naming a template...
Definition: Sema.h:9174
clang::TemplateTypeParmTypeLoc
Wrapper for template type parameters.
Definition: TypeLoc.h:743
ASTConsumer.h
clang::Sema::CodeSynthesisContext::InstantiationRange
SourceRange InstantiationRange
The source range that covers the construct that cause the instantiation, e.g., the template-id that c...
Definition: Sema.h:9289
clang::TemplateArgumentList
A template argument list.
Definition: DeclTemplate.h:238
clang::DeclContext::isFileContext
bool isFileContext() const
Definition: DeclBase.h:1993
clang::Sema::ContextRAII
A RAII object to temporarily push a declaration context.
Definition: Sema.h:994
clang::TemplateParameterList::size
unsigned size() const
Definition: DeclTemplate.h:130
clang::Sema::CurrentInstantiationScope
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
Definition: Sema.h:9690
clang::sema::TemplateDeductionInfo
Provides information about an attempted template argument deduction, whose success or failure was des...
Definition: TemplateDeduction.h:42
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:85
clang::ASTContext::getTargetInfo
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:773
clang::Sema::InstantiateEnum
bool InstantiateEnum(SourceLocation PointOfInstantiation, EnumDecl *Instantiation, EnumDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateSpecializationKind TSK)
Instantiate the definition of an enum from a given pattern.
Definition: SemaTemplateInstantiate.cpp:3302
clang::FieldDecl::getInClassInitStyle
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition: Decl.h:3063
clang::MultiLevelTemplateArgumentList::getNewDepth
unsigned getNewDepth(unsigned OldDepth) const
Determine how many of the OldDepth outermost template parameter lists would be removed by substitutin...
Definition: Template.h:144
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:2846
clang::Sema::InstantiatingTemplate
A stack object to be created when performing template instantiation.
Definition: Sema.h:9414
clang::TemplateTypeParmDecl::isParameterPack
bool isParameterPack() const
Returns whether this is a parameter pack.
Definition: DeclTemplate.cpp:699
clang::MemberPointerType
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:2960
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::Sema::CodeSynthesisContext::ConstraintNormalization
@ ConstraintNormalization
Definition: Sema.h:9212
clang::SubstNonTypeTemplateParmPackExpr::getParameterPackLocation
SourceLocation getParameterPackLocation() const
Retrieve the location of the parameter pack name.
Definition: ExprCXX.h:4394
clang::TemplateParameterList::getSourceRange
SourceRange getSourceRange() const LLVM_READONLY
Definition: DeclTemplate.h:198
clang::InitializationKind
Describes the kind of initialization being performed, along with location information for tokens rela...
Definition: Initialization.h:566
clang::ActionResult
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc.
Definition: Ownership.h:152
clang::CXXRecordDecl::isLocalClass
const FunctionDecl * isLocalClass() const
If the class is a local class [class.local], returns the enclosing function declaration.
Definition: DeclCXX.h:1512
clang::Sema::CodeSynthesisContext::DeclaringImplicitEqualityComparison
@ DeclaringImplicitEqualityComparison
We are declaring an implicit 'operator==' for a defaulted 'operator<=>'.
Definition: Sema.h:9196
clang::FunctionProtoType::ExceptionSpecInfo::Type
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:4075
clang::CXXRecordDecl::setTemplateSpecializationKind
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition: DeclCXX.cpp:1858
clang::FunctionProtoType::ExtProtoInfo::ExceptionSpec
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:4105
clang::LocalInstantiationScope::SetPartiallySubstitutedPack
void SetPartiallySubstitutedPack(NamedDecl *Pack, const TemplateArgument *ExplicitArgs, unsigned NumExplicitArgs)
Note that the given parameter pack has been partially substituted via explicit specification of templ...
Definition: SemaTemplateInstantiate.cpp:4103
clang::Sema::ExpressionEvaluationContext::ConstantEvaluated
@ ConstantEvaluated
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
clang::TypeLoc::IgnoreParens
TypeLoc IgnoreParens() const
Definition: TypeLoc.h:1183
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:531
clang::Sema::CodeSynthesisContext::ExceptionSpecEvaluation
@ ExceptionSpecEvaluation
We are computing the exception specification for a defaulted special member function.
Definition: Sema.h:9178
clang::PredefinedExpr
[C99 6.4.2.2] - A predefined identifier such as func.
Definition: Expr.h:1968
clang::PointerType
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2769
clang::Sema::CodeSynthesisContext::SavedInNonInstantiationSFINAEContext
bool SavedInNonInstantiationSFINAEContext
Was the enclosing context a non-instantiation SFINAE context?
Definition: Sema.h:9242
clang::Sema::InNonInstantiationSFINAEContext
bool InNonInstantiationSFINAEContext
Whether we are in a SFINAE context that is not associated with template instantiation.
Definition: Sema.h:9338
clang::SubstTemplateTypeParmPackType::getIndex
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: Type.h:5180
clang::MultiLevelTemplateArgumentList::getNumSubstitutedLevels
unsigned getNumSubstitutedLevels() const
Determine the number of substituted levels in this template argument list.
Definition: Template.h:128
clang::Sema::CodeSynthesisContext::InitializingStructuredBinding
@ InitializingStructuredBinding
We are initializing a structured binding.
Definition: Sema.h:9225
clang::Decl::isParameterPack
bool isParameterPack() const
Whether this declaration is a parameter pack.
Definition: DeclBase.cpp:220
clang::Sema::CheckParameter
ParmVarDecl * CheckParameter(DeclContext *DC, SourceLocation StartLoc, SourceLocation NameLoc, IdentifierInfo *Name, QualType T, TypeSourceInfo *TSInfo, StorageClass SC)
Definition: SemaDecl.cpp:14577
clang::TemplateArgument::Type
@ Type
The template argument is a type.
Definition: TemplateBase.h:70
clang::TemplateTypeParmType::getDepth
unsigned getDepth() const
Definition: Type.h:5043
clang::Sema::usesPartialOrExplicitSpecialization
bool usesPartialOrExplicitSpecialization(SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec)
Definition: SemaTemplateInstantiate.cpp:3440
clang::FieldDecl::getParent
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
Definition: Decl.h:3122
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:1847
clang::CXXDefaultArgExpr::getUsedLocation
SourceLocation getUsedLocation() const
Retrieve the location where this default argument was actually used.
Definition: ExprCXX.h:1294
clang
Definition: CalledOnceCheck.h:17
clang::VarTemplateSpecializationDecl::isClassScopeExplicitSpecialization
bool isClassScopeExplicitSpecialization() const
Definition: DeclTemplate.h:2801
clang::TemplateArgumentListInfo::setRAngleLoc
void setRAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:583
clang::Sema::CreateRecoveryExpr
ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, ArrayRef< Expr * > SubExprs, QualType T=QualType())
Attempts to produce a RecoveryExpr after some AST node cannot be created.
Definition: SemaExpr.cpp:20926
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:1692
clang::VectorType::getElementType
QualType getElementType() const
Definition: Type.h:3399
clang::TemplateArgument::getPackExpansionPattern
TemplateArgument getPackExpansionPattern() const
When the template argument is a pack expansion, returns the pattern of the pack expansion.
Definition: TemplateBase.cpp:384
clang::FunctionParmPackExpr::getExpansion
VarDecl * getExpansion(unsigned I) const
Get an expansion of the parameter pack by index.
Definition: ExprCXX.h:4475
clang::ClassTemplateSpecializationDecl::isClassScopeExplicitSpecialization
bool isClassScopeExplicitSpecialization() const
Is this an explicit specialization at class scope (within the class that owns the primary template)?...
Definition: DeclTemplate.h:1944
clang::sema::TemplateDeductionInfo::takeSFINAEDiagnostic
void takeSFINAEDiagnostic(PartialDiagnosticAt &PD)
Take ownership of the SFINAE diagnostic.
Definition: TemplateDeduction.h:107
clang::TemplateArgument::Template
@ Template
The template argument is a template name that was provided for a template template parameter.
Definition: TemplateBase.h:86
clang::NonTypeTemplateParmDecl::isParameterPack
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
Definition: DeclTemplate.h:1524
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:71
clang::TemplateArgument::getAsTemplate
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:292
clang::Sema::SubstDefaultArgument
bool SubstDefaultArgument(SourceLocation Loc, ParmVarDecl *Param, const MultiLevelTemplateArgumentList &TemplateArgs, bool ForCallExpr=false)
Substitute the given template arguments into the default argument.
Definition: SemaTemplateInstantiate.cpp:2819
clang::TemplateSpecCandidateSet::addCandidate
TemplateSpecCandidate & addCandidate()
Add a new candidate with NumConversions conversion sequence slots to the overload set.
Definition: TemplateDeduction.h:361
std::arg
__DEVICE__ _Tp arg(const std::complex< _Tp > &__c)
Definition: complex_cmath.h:40
clang::CXXRecordDecl::getCanonicalDecl
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:502
clang::ParmVarDecl::hasUninstantiatedDefaultArg
bool hasUninstantiatedDefaultArg() const
Definition: Decl.h:1833
clang::Declarator
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1834
clang::Expr::getType
QualType getType() const
Definition: Expr.h:141
clang::CXXBaseSpecifier
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
clang::CXXDefaultArgExpr::getParam
const ParmVarDecl * getParam() const
Definition: ExprCXX.h:1283
clang::Attr
Attr - This represents one attribute.
Definition: Attr.h:40
clang::TypeSourceInfo
A container of type source information.
Definition: Type.h:6593
clang::FunctionType::getReturnType
QualType getReturnType() const
Definition: Type.h:3940
clang::TemplateDeclInstantiator::InstantiateVarTemplatePartialSpecialization
VarTemplatePartialSpecializationDecl * InstantiateVarTemplatePartialSpecialization(VarTemplateDecl *VarTemplate, VarTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a variable template partial specialization.
Definition: SemaTemplateInstantiateDecl.cpp:4247
clang::LocalInstantiationScope
A stack-allocated class that identifies which local variable declaration instantiations are present i...
Definition: Template.h:333
clang::NamedDecl::getDeclName
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:313
clang::Sema::SubstNestedNameSpecifierLoc
NestedNameSpecifierLoc SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, const MultiLevelTemplateArgumentList &TemplateArgs)
Definition: SemaTemplateInstantiate.cpp:3949
clang::Sema::CheckConstraintSatisfaction
bool CheckConstraintSatisfaction(const NamedDecl *Template, ArrayRef< const Expr * > ConstraintExprs, const MultiLevelTemplateArgumentList &TemplateArgLists, SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction)
Check whether the given list of constraint expressions are satisfied (as if in a 'conjunction') given...
Definition: Sema.h:7313
clang::Sema::ActOnStartCXXInClassMemberInitializer
void ActOnStartCXXInClassMemberInitializer()
Enter a new C++ default initializer scope.
Definition: SemaDeclCXX.cpp:4003
unsigned
clang::Stmt::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:336
clang::Sema::CodeSynthesisContext::BuildingBuiltinDumpStructCall
@ BuildingBuiltinDumpStructCall
We are building an implied call from __builtin_dump_struct.
Definition: Sema.h:9232
clang::SubstNonTypeTemplateParmExpr::getPackIndex
Optional< unsigned > getPackIndex() const
Definition: ExprCXX.h:4317
clang::Sema::isSFINAEContext
Optional< sema::TemplateDeductionInfo * > isSFINAEContext() const
Determines whether we are currently in a context where template argument substitution failures are no...
Definition: SemaTemplateInstantiate.cpp:1010
clang::InitializedEntity
Describes an entity that is being initialized.
Definition: Initialization.h:47
clang::concepts::ExprRequirement::getNoexceptLoc
SourceLocation getNoexceptLoc() const
Definition: ExprConcepts.h:364
clang::Sema::CodeSynthesisContext::RewritingOperatorAsSpaceship
@ RewritingOperatorAsSpaceship
We are rewriting a comparison operator in terms of an operator<=>.
Definition: Sema.h:9222
clang::LocalInstantiationScope::InstantiatedLocalPackArg
void InstantiatedLocalPackArg(const Decl *D, VarDecl *Inst)
Definition: SemaTemplateInstantiate.cpp:4073
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:2396
clang::TemplateDeclInstantiator::delayed_partial_spec_iterator
SmallVectorImpl< std::pair< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > >::iterator delayed_partial_spec_iterator
Definition: Template.h:630
clang::NamedDecl::printName
virtual void printName(raw_ostream &OS, const PrintingPolicy &Policy) const
Pretty-print the unqualified name of this declaration.
Definition: Decl.cpp:1618
clang::Sema::ConvertParamDefaultArgument
ExprResult ConvertParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, SourceLocation EqualLoc)
Definition: SemaDeclCXX.cpp:274
clang::VarTemplateSpecializationDecl::getSpecializedTemplate
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
Definition: DeclTemplate.cpp:1388
clang::Qualifiers::removeObjCLifetime
void removeObjCLifetime()
Definition: Type.h:358
clang::Decl::isDefinedOutsideFunctionOrMethod
bool isDefinedOutsideFunctionOrMethod() const
isDefinedOutsideFunctionOrMethod - This predicate returns true if this scoped decl is defined outside...
Definition: DeclBase.h:914
clang::FunctionParmPackExpr::end
iterator end() const
Definition: ExprCXX.h:4469
clang::DeclContextLookupResult
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1334
clang::TypeSpecTypeLoc::setNameLoc
void setNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:527
clang::SubstNonTypeTemplateParmExpr::getParameter
NonTypeTemplateParmDecl * getParameter() const
Definition: ExprCXX.cpp:1577
clang::TypeLoc::getSourceRange
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
Definition: TypeLoc.h:152
clang::ConstraintSatisfaction
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition: ASTConcept.h:28
clang::ConceptReference::getNestedNameSpecifierLoc
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
Definition: ASTConcept.h:138
clang::QualType::getTypePtr
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6622
clang::Sema::CheckBaseSpecifier
CXXBaseSpecifier * CheckBaseSpecifier(CXXRecordDecl *Class, SourceRange SpecifierRange, bool Virtual, AccessSpecifier Access, TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
ActOnBaseSpecifier - Parsed a base specifier.
Definition: SemaDeclCXX.cpp:2515
clang::InheritingConcreteTypeLoc::getTypePtr
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:502
clang::ETK_Typename
@ ETK_Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
Definition: Type.h:5570
clang::SubstTemplateTypeParmPackType::getAssociatedDecl
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: Type.cpp:3681
clang::TemplateDeclInstantiator::InstantiateClassTemplatePartialSpecialization
ClassTemplatePartialSpecializationDecl * InstantiateClassTemplatePartialSpecialization(ClassTemplateDecl *ClassTemplate, ClassTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a class template partial specialization.
Definition: SemaTemplateInstantiateDecl.cpp:4122
clang::ReferenceType
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2880
clang::Sema::DefaultedFunctionKind::asComparison
DefaultedComparisonKind asComparison() const
Definition: Sema.h:3372
clang::PointerType::getPointeeType
QualType getPointeeType() const
Definition: Type.h:2779
clang::ConceptReference::getConceptNameInfo
const DeclarationNameInfo & getConceptNameInfo() const
Definition: ASTConcept.h:142
clang::FunctionProtoTypeLoc
Definition: TypeLoc.h:1498
clang::DiagnosticsEngine::getTemplateBacktraceLimit
unsigned getTemplateBacktraceLimit() const
Retrieve the maximum number of template instantiation notes to emit along with a given diagnostic.
Definition: