clang  15.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/ASTConsumer.h"
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/ASTLambda.h"
17 #include "clang/AST/DeclTemplate.h"
18 #include "clang/AST/Expr.h"
20 #include "clang/AST/TypeVisitor.h"
22 #include "clang/Basic/Stack.h"
23 #include "clang/Basic/TargetInfo.h"
24 #include "clang/Sema/DeclSpec.h"
26 #include "clang/Sema/Lookup.h"
27 #include "clang/Sema/SemaConcept.h"
29 #include "clang/Sema/Template.h"
32 #include "llvm/Support/TimeProfiler.h"
33 
34 using namespace clang;
35 using namespace sema;
36 
37 //===----------------------------------------------------------------------===/
38 // Template Instantiation Support
39 //===----------------------------------------------------------------------===/
40 
41 /// Retrieve the template argument list(s) that should be used to
42 /// instantiate the definition of the given declaration.
43 ///
44 /// \param D the declaration for which we are computing template instantiation
45 /// arguments.
46 ///
47 /// \param Innermost if non-NULL, the innermost template argument list.
48 ///
49 /// \param RelativeToPrimary true if we should get the template
50 /// arguments relative to the primary template, even when we're
51 /// dealing with a specialization. This is only relevant for function
52 /// template specializations.
53 ///
54 /// \param Pattern If non-NULL, indicates the pattern from which we will be
55 /// instantiating the definition of the given declaration, \p D. This is
56 /// used to determine the proper set of template instantiation arguments for
57 /// friend function template specializations.
59  const NamedDecl *D, const TemplateArgumentList *Innermost,
60  bool RelativeToPrimary, const FunctionDecl *Pattern) {
61  // Accumulate the set of template argument lists in this structure.
63 
64  if (Innermost)
65  Result.addOuterTemplateArguments(Innermost);
66 
67  const auto *Ctx = dyn_cast<DeclContext>(D);
68  if (!Ctx) {
69  Ctx = D->getDeclContext();
70 
71  // Add template arguments from a variable template instantiation. For a
72  // class-scope explicit specialization, there are no template arguments
73  // at this level, but there may be enclosing template arguments.
74  const auto *Spec = dyn_cast<VarTemplateSpecializationDecl>(D);
75  if (Spec && !Spec->isClassScopeExplicitSpecialization()) {
76  // We're done when we hit an explicit specialization.
77  if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization &&
78  !isa<VarTemplatePartialSpecializationDecl>(Spec))
79  return Result;
80 
81  Result.addOuterTemplateArguments(&Spec->getTemplateInstantiationArgs());
82 
83  // If this variable template specialization was instantiated from a
84  // specialized member that is a variable template, we're done.
85  assert(Spec->getSpecializedTemplate() && "No variable template?");
86  llvm::PointerUnion<VarTemplateDecl*,
90  Specialized.dyn_cast<VarTemplatePartialSpecializationDecl *>()) {
91  if (Partial->isMemberSpecialization())
92  return Result;
93  } else {
94  VarTemplateDecl *Tmpl = Specialized.get<VarTemplateDecl *>();
95  if (Tmpl->isMemberSpecialization())
96  return Result;
97  }
98  }
99 
100  // If we have a template template parameter with translation unit context,
101  // then we're performing substitution into a default template argument of
102  // this template template parameter before we've constructed the template
103  // that will own this template template parameter. In this case, we
104  // use empty template parameter lists for all of the outer templates
105  // to avoid performing any substitutions.
106  if (Ctx->isTranslationUnit()) {
107  if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
108  for (unsigned I = 0, N = TTP->getDepth() + 1; I != N; ++I)
109  Result.addOuterTemplateArguments(None);
110  return Result;
111  }
112  }
113  }
114 
115  while (!Ctx->isFileContext()) {
116  // Add template arguments from a class template instantiation.
117  const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(Ctx);
118  if (Spec && !Spec->isClassScopeExplicitSpecialization()) {
119  // We're done when we hit an explicit specialization.
120  if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization &&
121  !isa<ClassTemplatePartialSpecializationDecl>(Spec))
122  break;
123 
124  Result.addOuterTemplateArguments(&Spec->getTemplateInstantiationArgs());
125 
126  // If this class template specialization was instantiated from a
127  // specialized member that is a class template, we're done.
128  assert(Spec->getSpecializedTemplate() && "No class template?");
129  if (Spec->getSpecializedTemplate()->isMemberSpecialization())
130  break;
131  }
132  // Add template arguments from a function template specialization.
133  else if (const auto *Function = dyn_cast<FunctionDecl>(Ctx)) {
134  if (!RelativeToPrimary &&
135  Function->getTemplateSpecializationKindForInstantiation() ==
137  break;
138 
139  if (!RelativeToPrimary && Function->getTemplateSpecializationKind() ==
141  // This is an implicit instantiation of an explicit specialization. We
142  // don't get any template arguments from this function but might get
143  // some from an enclosing template.
144  } else if (const TemplateArgumentList *TemplateArgs
145  = Function->getTemplateSpecializationArgs()) {
146  // Add the template arguments for this specialization.
147  Result.addOuterTemplateArguments(TemplateArgs);
148 
149  // If this function was instantiated from a specialized member that is
150  // a function template, we're done.
151  assert(Function->getPrimaryTemplate() && "No function template?");
152  if (Function->getPrimaryTemplate()->isMemberSpecialization())
153  break;
154 
155  // If this function is a generic lambda specialization, we are done.
157  break;
158 
159  } else if (Function->getDescribedFunctionTemplate()) {
160  assert(Result.getNumSubstitutedLevels() == 0 &&
161  "Outer template not instantiated?");
162  }
163 
164  // If this is a friend declaration and it declares an entity at
165  // namespace scope, take arguments from its lexical parent
166  // instead of its semantic parent, unless of course the pattern we're
167  // instantiating actually comes from the file's context!
168  if (Function->getFriendObjectKind() &&
169  Function->getDeclContext()->isFileContext() &&
170  (!Pattern || !Pattern->getLexicalDeclContext()->isFileContext())) {
171  Ctx = Function->getLexicalDeclContext();
172  RelativeToPrimary = false;
173  continue;
174  }
175  } else if (const auto *Rec = dyn_cast<CXXRecordDecl>(Ctx)) {
176  if (ClassTemplateDecl *ClassTemplate = Rec->getDescribedClassTemplate()) {
177  assert(Result.getNumSubstitutedLevels() == 0 &&
178  "Outer template not instantiated?");
179  if (ClassTemplate->isMemberSpecialization())
180  break;
181  }
182  }
183 
184  Ctx = Ctx->getParent();
185  RelativeToPrimary = false;
186  }
187 
188  return Result;
189 }
190 
192  switch (Kind) {
193  case TemplateInstantiation:
194  case ExceptionSpecInstantiation:
195  case DefaultTemplateArgumentInstantiation:
196  case DefaultFunctionArgumentInstantiation:
197  case ExplicitTemplateArgumentSubstitution:
198  case DeducedTemplateArgumentSubstitution:
199  case PriorTemplateArgumentSubstitution:
200  case ConstraintsCheck:
201  case NestedRequirementConstraintsCheck:
202  return true;
203 
204  case RequirementInstantiation:
205  case DefaultTemplateArgumentChecking:
206  case DeclaringSpecialMember:
207  case DeclaringImplicitEqualityComparison:
208  case DefiningSynthesizedFunction:
209  case ExceptionSpecEvaluation:
210  case ConstraintSubstitution:
211  case ParameterMappingSubstitution:
212  case ConstraintNormalization:
213  case RewritingOperatorAsSpaceship:
214  case InitializingStructuredBinding:
215  case MarkingClassDllexported:
216  case BuildingBuiltinDumpStructCall:
217  return false;
218 
219  // This function should never be called when Kind's value is Memoization.
220  case Memoization:
221  break;
222  }
223 
224  llvm_unreachable("Invalid SynthesisKind!");
225 }
226 
229  SourceLocation PointOfInstantiation, SourceRange InstantiationRange,
230  Decl *Entity, NamedDecl *Template, ArrayRef<TemplateArgument> TemplateArgs,
231  sema::TemplateDeductionInfo *DeductionInfo)
232  : SemaRef(SemaRef) {
233  // Don't allow further instantiation if a fatal error and an uncompilable
234  // error have occurred. Any diagnostics we might have raised will not be
235  // visible, and we do not need to construct a correct AST.
236  if (SemaRef.Diags.hasFatalErrorOccurred() &&
237  SemaRef.hasUncompilableErrorOccurred()) {
238  Invalid = true;
239  return;
240  }
241  Invalid = CheckInstantiationDepth(PointOfInstantiation, InstantiationRange);
242  if (!Invalid) {
244  Inst.Kind = Kind;
245  Inst.PointOfInstantiation = PointOfInstantiation;
246  Inst.Entity = Entity;
247  Inst.Template = Template;
248  Inst.TemplateArgs = TemplateArgs.data();
249  Inst.NumTemplateArgs = TemplateArgs.size();
250  Inst.DeductionInfo = DeductionInfo;
251  Inst.InstantiationRange = InstantiationRange;
252  SemaRef.pushCodeSynthesisContext(Inst);
253 
254  AlreadyInstantiating = !Inst.Entity ? false :
256  .insert({Inst.Entity->getCanonicalDecl(), Inst.Kind})
257  .second;
258  atTemplateBegin(SemaRef.TemplateInstCallbacks, SemaRef, Inst);
259  }
260 }
261 
263  Sema &SemaRef, SourceLocation PointOfInstantiation, Decl *Entity,
264  SourceRange InstantiationRange)
265  : InstantiatingTemplate(SemaRef,
266  CodeSynthesisContext::TemplateInstantiation,
267  PointOfInstantiation, InstantiationRange, Entity) {}
268 
270  Sema &SemaRef, SourceLocation PointOfInstantiation, FunctionDecl *Entity,
271  ExceptionSpecification, SourceRange InstantiationRange)
273  SemaRef, CodeSynthesisContext::ExceptionSpecInstantiation,
274  PointOfInstantiation, InstantiationRange, Entity) {}
275 
277  Sema &SemaRef, SourceLocation PointOfInstantiation, TemplateParameter Param,
278  TemplateDecl *Template, ArrayRef<TemplateArgument> TemplateArgs,
279  SourceRange InstantiationRange)
281  SemaRef,
282  CodeSynthesisContext::DefaultTemplateArgumentInstantiation,
283  PointOfInstantiation, InstantiationRange, getAsNamedDecl(Param),
284  Template, TemplateArgs) {}
285 
287  Sema &SemaRef, SourceLocation PointOfInstantiation,
288  FunctionTemplateDecl *FunctionTemplate,
289  ArrayRef<TemplateArgument> TemplateArgs,
291  sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange)
292  : InstantiatingTemplate(SemaRef, Kind, PointOfInstantiation,
293  InstantiationRange, FunctionTemplate, nullptr,
294  TemplateArgs, &DeductionInfo) {
295  assert(
298 }
299 
301  Sema &SemaRef, SourceLocation PointOfInstantiation,
302  TemplateDecl *Template,
303  ArrayRef<TemplateArgument> TemplateArgs,
304  sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange)
306  SemaRef,
307  CodeSynthesisContext::DeducedTemplateArgumentSubstitution,
308  PointOfInstantiation, InstantiationRange, Template, nullptr,
309  TemplateArgs, &DeductionInfo) {}
310 
312  Sema &SemaRef, SourceLocation PointOfInstantiation,
314  ArrayRef<TemplateArgument> TemplateArgs,
315  sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange)
317  SemaRef,
318  CodeSynthesisContext::DeducedTemplateArgumentSubstitution,
319  PointOfInstantiation, InstantiationRange, PartialSpec, nullptr,
320  TemplateArgs, &DeductionInfo) {}
321 
323  Sema &SemaRef, SourceLocation PointOfInstantiation,
325  ArrayRef<TemplateArgument> TemplateArgs,
326  sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange)
328  SemaRef,
329  CodeSynthesisContext::DeducedTemplateArgumentSubstitution,
330  PointOfInstantiation, InstantiationRange, PartialSpec, nullptr,
331  TemplateArgs, &DeductionInfo) {}
332 
334  Sema &SemaRef, SourceLocation PointOfInstantiation, ParmVarDecl *Param,
335  ArrayRef<TemplateArgument> TemplateArgs, SourceRange InstantiationRange)
337  SemaRef,
338  CodeSynthesisContext::DefaultFunctionArgumentInstantiation,
339  PointOfInstantiation, InstantiationRange, Param, nullptr,
340  TemplateArgs) {}
341 
343  Sema &SemaRef, SourceLocation PointOfInstantiation, NamedDecl *Template,
345  SourceRange InstantiationRange)
347  SemaRef,
348  CodeSynthesisContext::PriorTemplateArgumentSubstitution,
349  PointOfInstantiation, InstantiationRange, Param, Template,
350  TemplateArgs) {}
351 
353  Sema &SemaRef, SourceLocation PointOfInstantiation, NamedDecl *Template,
355  SourceRange InstantiationRange)
357  SemaRef,
358  CodeSynthesisContext::PriorTemplateArgumentSubstitution,
359  PointOfInstantiation, InstantiationRange, Param, Template,
360  TemplateArgs) {}
361 
363  Sema &SemaRef, SourceLocation PointOfInstantiation, TemplateDecl *Template,
364  NamedDecl *Param, ArrayRef<TemplateArgument> TemplateArgs,
365  SourceRange InstantiationRange)
367  SemaRef, CodeSynthesisContext::DefaultTemplateArgumentChecking,
368  PointOfInstantiation, InstantiationRange, Param, Template,
369  TemplateArgs) {}
370 
372  Sema &SemaRef, SourceLocation PointOfInstantiation,
374  SourceRange InstantiationRange)
376  SemaRef, CodeSynthesisContext::RequirementInstantiation,
377  PointOfInstantiation, InstantiationRange, /*Entity=*/nullptr,
378  /*Template=*/nullptr, /*TemplateArgs=*/None, &DeductionInfo) {}
379 
380 
382  Sema &SemaRef, SourceLocation PointOfInstantiation,
384  SourceRange InstantiationRange)
386  SemaRef, CodeSynthesisContext::NestedRequirementConstraintsCheck,
387  PointOfInstantiation, InstantiationRange, /*Entity=*/nullptr,
388  /*Template=*/nullptr, /*TemplateArgs=*/None) {}
389 
390 
392  Sema &SemaRef, SourceLocation PointOfInstantiation,
393  ConstraintsCheck, NamedDecl *Template,
394  ArrayRef<TemplateArgument> TemplateArgs, SourceRange InstantiationRange)
397  PointOfInstantiation, InstantiationRange, Template, nullptr,
398  TemplateArgs) {}
399 
401  Sema &SemaRef, SourceLocation PointOfInstantiation,
403  sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange)
406  PointOfInstantiation, InstantiationRange, Template, nullptr,
407  {}, &DeductionInfo) {}
408 
410  Sema &SemaRef, SourceLocation PointOfInstantiation,
412  SourceRange InstantiationRange)
415  PointOfInstantiation, InstantiationRange, Template) {}
416 
418  Sema &SemaRef, SourceLocation PointOfInstantiation,
420  SourceRange InstantiationRange)
423  PointOfInstantiation, InstantiationRange, Template) {}
424 
428 
429  CodeSynthesisContexts.push_back(Ctx);
430 
431  if (!Ctx.isInstantiationRecord())
433 
434  // Check to see if we're low on stack space. We can't do anything about this
435  // from here, but we can at least warn the user.
438 }
439 
441  auto &Active = CodeSynthesisContexts.back();
442  if (!Active.isInstantiationRecord()) {
443  assert(NonInstantiationEntries > 0);
445  }
446 
447  InNonInstantiationSFINAEContext = Active.SavedInNonInstantiationSFINAEContext;
448 
449  // Name lookup no longer looks in this template's defining module.
450  assert(CodeSynthesisContexts.size() >=
452  "forgot to remove a lookup module for a template instantiation");
453  if (CodeSynthesisContexts.size() ==
456  LookupModulesCache.erase(M);
458  }
459 
460  // If we've left the code synthesis context for the current context stack,
461  // stop remembering that we've emitted that stack.
462  if (CodeSynthesisContexts.size() ==
465 
466  CodeSynthesisContexts.pop_back();
467 }
468 
470  if (!Invalid) {
471  if (!AlreadyInstantiating) {
472  auto &Active = SemaRef.CodeSynthesisContexts.back();
473  if (Active.Entity)
474  SemaRef.InstantiatingSpecializations.erase(
475  {Active.Entity->getCanonicalDecl(), Active.Kind});
476  }
477 
478  atTemplateEnd(SemaRef.TemplateInstCallbacks, SemaRef,
479  SemaRef.CodeSynthesisContexts.back());
480 
481  SemaRef.popCodeSynthesisContext();
482  Invalid = true;
483  }
484 }
485 
488  std::string Result;
489  llvm::raw_string_ostream OS(Result);
490  llvm::ListSeparator Comma;
491  for (const Expr *Arg : Args) {
492  OS << Comma;
493  Arg->IgnoreParens()->printPretty(OS, nullptr,
495  }
496  return Result;
497 }
498 
499 bool Sema::InstantiatingTemplate::CheckInstantiationDepth(
500  SourceLocation PointOfInstantiation,
501  SourceRange InstantiationRange) {
502  assert(SemaRef.NonInstantiationEntries <=
503  SemaRef.CodeSynthesisContexts.size());
504  if ((SemaRef.CodeSynthesisContexts.size() -
505  SemaRef.NonInstantiationEntries)
506  <= SemaRef.getLangOpts().InstantiationDepth)
507  return false;
508 
509  SemaRef.Diag(PointOfInstantiation,
510  diag::err_template_recursion_depth_exceeded)
511  << SemaRef.getLangOpts().InstantiationDepth
512  << InstantiationRange;
513  SemaRef.Diag(PointOfInstantiation, diag::note_template_recursion_depth)
514  << SemaRef.getLangOpts().InstantiationDepth;
515  return true;
516 }
517 
518 /// Prints the current instantiation stack through a series of
519 /// notes.
521  // Determine which template instantiations to skip, if any.
522  unsigned SkipStart = CodeSynthesisContexts.size(), SkipEnd = SkipStart;
523  unsigned Limit = Diags.getTemplateBacktraceLimit();
524  if (Limit && Limit < CodeSynthesisContexts.size()) {
525  SkipStart = Limit / 2 + Limit % 2;
526  SkipEnd = CodeSynthesisContexts.size() - Limit / 2;
527  }
528 
529  // FIXME: In all of these cases, we need to show the template arguments
530  unsigned InstantiationIdx = 0;
532  Active = CodeSynthesisContexts.rbegin(),
533  ActiveEnd = CodeSynthesisContexts.rend();
534  Active != ActiveEnd;
535  ++Active, ++InstantiationIdx) {
536  // Skip this instantiation?
537  if (InstantiationIdx >= SkipStart && InstantiationIdx < SkipEnd) {
538  if (InstantiationIdx == SkipStart) {
539  // Note that we're skipping instantiations.
540  Diags.Report(Active->PointOfInstantiation,
541  diag::note_instantiation_contexts_suppressed)
542  << unsigned(CodeSynthesisContexts.size() - Limit);
543  }
544  continue;
545  }
546 
547  switch (Active->Kind) {
549  Decl *D = Active->Entity;
550  if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) {
551  unsigned DiagID = diag::note_template_member_class_here;
552  if (isa<ClassTemplateSpecializationDecl>(Record))
553  DiagID = diag::note_template_class_instantiation_here;
554  Diags.Report(Active->PointOfInstantiation, DiagID)
555  << Record << Active->InstantiationRange;
556  } else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
557  unsigned DiagID;
558  if (Function->getPrimaryTemplate())
559  DiagID = diag::note_function_template_spec_here;
560  else
561  DiagID = diag::note_template_member_function_here;
562  Diags.Report(Active->PointOfInstantiation, DiagID)
563  << Function
564  << Active->InstantiationRange;
565  } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
566  Diags.Report(Active->PointOfInstantiation,
567  VD->isStaticDataMember()?
568  diag::note_template_static_data_member_def_here
569  : diag::note_template_variable_def_here)
570  << VD
571  << Active->InstantiationRange;
572  } else if (EnumDecl *ED = dyn_cast<EnumDecl>(D)) {
573  Diags.Report(Active->PointOfInstantiation,
574  diag::note_template_enum_def_here)
575  << ED
576  << Active->InstantiationRange;
577  } else if (FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
578  Diags.Report(Active->PointOfInstantiation,
579  diag::note_template_nsdmi_here)
580  << FD << Active->InstantiationRange;
581  } else {
582  Diags.Report(Active->PointOfInstantiation,
583  diag::note_template_type_alias_instantiation_here)
584  << cast<TypeAliasTemplateDecl>(D)
585  << Active->InstantiationRange;
586  }
587  break;
588  }
589 
591  TemplateDecl *Template = cast<TemplateDecl>(Active->Template);
592  SmallString<128> TemplateArgsStr;
593  llvm::raw_svector_ostream OS(TemplateArgsStr);
594  Template->printName(OS);
595  printTemplateArgumentList(OS, Active->template_arguments(),
597  Diags.Report(Active->PointOfInstantiation,
598  diag::note_default_arg_instantiation_here)
599  << OS.str()
600  << Active->InstantiationRange;
601  break;
602  }
603 
605  FunctionTemplateDecl *FnTmpl = cast<FunctionTemplateDecl>(Active->Entity);
606  Diags.Report(Active->PointOfInstantiation,
607  diag::note_explicit_template_arg_substitution_here)
608  << FnTmpl
610  Active->TemplateArgs,
611  Active->NumTemplateArgs)
612  << Active->InstantiationRange;
613  break;
614  }
615 
617  if (FunctionTemplateDecl *FnTmpl =
618  dyn_cast<FunctionTemplateDecl>(Active->Entity)) {
619  Diags.Report(Active->PointOfInstantiation,
620  diag::note_function_template_deduction_instantiation_here)
621  << FnTmpl
622  << getTemplateArgumentBindingsText(FnTmpl->getTemplateParameters(),
623  Active->TemplateArgs,
624  Active->NumTemplateArgs)
625  << Active->InstantiationRange;
626  } else {
627  bool IsVar = isa<VarTemplateDecl>(Active->Entity) ||
628  isa<VarTemplateSpecializationDecl>(Active->Entity);
629  bool IsTemplate = false;
630  TemplateParameterList *Params;
631  if (auto *D = dyn_cast<TemplateDecl>(Active->Entity)) {
632  IsTemplate = true;
633  Params = D->getTemplateParameters();
634  } else if (auto *D = dyn_cast<ClassTemplatePartialSpecializationDecl>(
635  Active->Entity)) {
636  Params = D->getTemplateParameters();
637  } else if (auto *D = dyn_cast<VarTemplatePartialSpecializationDecl>(
638  Active->Entity)) {
639  Params = D->getTemplateParameters();
640  } else {
641  llvm_unreachable("unexpected template kind");
642  }
643 
644  Diags.Report(Active->PointOfInstantiation,
645  diag::note_deduced_template_arg_substitution_here)
646  << IsVar << IsTemplate << cast<NamedDecl>(Active->Entity)
647  << getTemplateArgumentBindingsText(Params, Active->TemplateArgs,
648  Active->NumTemplateArgs)
649  << Active->InstantiationRange;
650  }
651  break;
652  }
653 
655  ParmVarDecl *Param = cast<ParmVarDecl>(Active->Entity);
656  FunctionDecl *FD = cast<FunctionDecl>(Param->getDeclContext());
657 
658  SmallString<128> TemplateArgsStr;
659  llvm::raw_svector_ostream OS(TemplateArgsStr);
660  FD->printName(OS);
661  printTemplateArgumentList(OS, Active->template_arguments(),
663  Diags.Report(Active->PointOfInstantiation,
664  diag::note_default_function_arg_instantiation_here)
665  << OS.str()
666  << Active->InstantiationRange;
667  break;
668  }
669 
671  NamedDecl *Parm = cast<NamedDecl>(Active->Entity);
672  std::string Name;
673  if (!Parm->getName().empty())
674  Name = std::string(" '") + Parm->getName().str() + "'";
675 
676  TemplateParameterList *TemplateParams = nullptr;
677  if (TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template))
678  TemplateParams = Template->getTemplateParameters();
679  else
680  TemplateParams =
681  cast<ClassTemplatePartialSpecializationDecl>(Active->Template)
682  ->getTemplateParameters();
683  Diags.Report(Active->PointOfInstantiation,
684  diag::note_prior_template_arg_substitution)
685  << isa<TemplateTemplateParmDecl>(Parm)
686  << Name
687  << getTemplateArgumentBindingsText(TemplateParams,
688  Active->TemplateArgs,
689  Active->NumTemplateArgs)
690  << Active->InstantiationRange;
691  break;
692  }
693 
695  TemplateParameterList *TemplateParams = nullptr;
696  if (TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template))
697  TemplateParams = Template->getTemplateParameters();
698  else
699  TemplateParams =
700  cast<ClassTemplatePartialSpecializationDecl>(Active->Template)
701  ->getTemplateParameters();
702 
703  Diags.Report(Active->PointOfInstantiation,
704  diag::note_template_default_arg_checking)
705  << getTemplateArgumentBindingsText(TemplateParams,
706  Active->TemplateArgs,
707  Active->NumTemplateArgs)
708  << Active->InstantiationRange;
709  break;
710  }
711 
713  Diags.Report(Active->PointOfInstantiation,
714  diag::note_evaluating_exception_spec_here)
715  << cast<FunctionDecl>(Active->Entity);
716  break;
717 
719  Diags.Report(Active->PointOfInstantiation,
720  diag::note_template_exception_spec_instantiation_here)
721  << cast<FunctionDecl>(Active->Entity)
722  << Active->InstantiationRange;
723  break;
724 
726  Diags.Report(Active->PointOfInstantiation,
727  diag::note_template_requirement_instantiation_here)
728  << Active->InstantiationRange;
729  break;
730 
732  Diags.Report(Active->PointOfInstantiation,
733  diag::note_nested_requirement_here)
734  << Active->InstantiationRange;
735  break;
736 
738  Diags.Report(Active->PointOfInstantiation,
739  diag::note_in_declaration_of_implicit_special_member)
740  << cast<CXXRecordDecl>(Active->Entity) << Active->SpecialMember;
741  break;
742 
744  Diags.Report(Active->Entity->getLocation(),
745  diag::note_in_declaration_of_implicit_equality_comparison);
746  break;
747 
749  // FIXME: For synthesized functions that are not defaulted,
750  // produce a note.
751  auto *FD = dyn_cast<FunctionDecl>(Active->Entity);
754  if (DFK.isSpecialMember()) {
755  auto *MD = cast<CXXMethodDecl>(FD);
756  Diags.Report(Active->PointOfInstantiation,
757  diag::note_member_synthesized_at)
758  << MD->isExplicitlyDefaulted() << DFK.asSpecialMember()
759  << Context.getTagDeclType(MD->getParent());
760  } else if (DFK.isComparison()) {
761  Diags.Report(Active->PointOfInstantiation,
762  diag::note_comparison_synthesized_at)
763  << (int)DFK.asComparison()
765  cast<CXXRecordDecl>(FD->getLexicalDeclContext()));
766  }
767  break;
768  }
769 
771  Diags.Report(Active->Entity->getLocation(),
772  diag::note_rewriting_operator_as_spaceship);
773  break;
774 
776  Diags.Report(Active->PointOfInstantiation,
777  diag::note_in_binding_decl_init)
778  << cast<BindingDecl>(Active->Entity);
779  break;
780 
782  Diags.Report(Active->PointOfInstantiation,
783  diag::note_due_to_dllexported_class)
784  << cast<CXXRecordDecl>(Active->Entity) << !getLangOpts().CPlusPlus11;
785  break;
786 
788  Diags.Report(Active->PointOfInstantiation,
789  diag::note_building_builtin_dump_struct_call)
791  *this,
792  llvm::makeArrayRef(Active->CallArgs, Active->NumCallArgs));
793  break;
794 
796  break;
797 
799  unsigned DiagID = 0;
800  if (!Active->Entity) {
801  Diags.Report(Active->PointOfInstantiation,
802  diag::note_nested_requirement_here)
803  << Active->InstantiationRange;
804  break;
805  }
806  if (isa<ConceptDecl>(Active->Entity))
807  DiagID = diag::note_concept_specialization_here;
808  else if (isa<TemplateDecl>(Active->Entity))
809  DiagID = diag::note_checking_constraints_for_template_id_here;
810  else if (isa<VarTemplatePartialSpecializationDecl>(Active->Entity))
811  DiagID = diag::note_checking_constraints_for_var_spec_id_here;
812  else if (isa<ClassTemplatePartialSpecializationDecl>(Active->Entity))
813  DiagID = diag::note_checking_constraints_for_class_spec_id_here;
814  else {
815  assert(isa<FunctionDecl>(Active->Entity));
816  DiagID = diag::note_checking_constraints_for_function_here;
817  }
818  SmallString<128> TemplateArgsStr;
819  llvm::raw_svector_ostream OS(TemplateArgsStr);
820  cast<NamedDecl>(Active->Entity)->printName(OS);
821  if (!isa<FunctionDecl>(Active->Entity)) {
822  printTemplateArgumentList(OS, Active->template_arguments(),
824  }
825  Diags.Report(Active->PointOfInstantiation, DiagID) << OS.str()
826  << Active->InstantiationRange;
827  break;
828  }
830  Diags.Report(Active->PointOfInstantiation,
831  diag::note_constraint_substitution_here)
832  << Active->InstantiationRange;
833  break;
835  Diags.Report(Active->PointOfInstantiation,
836  diag::note_constraint_normalization_here)
837  << cast<NamedDecl>(Active->Entity)->getName()
838  << Active->InstantiationRange;
839  break;
841  Diags.Report(Active->PointOfInstantiation,
842  diag::note_parameter_mapping_substitution_here)
843  << Active->InstantiationRange;
844  break;
845  }
846  }
847 }
848 
851  return Optional<TemplateDeductionInfo *>(nullptr);
852 
854  Active = CodeSynthesisContexts.rbegin(),
855  ActiveEnd = CodeSynthesisContexts.rend();
856  Active != ActiveEnd;
857  ++Active)
858  {
859  switch (Active->Kind) {
861  // An instantiation of an alias template may or may not be a SFINAE
862  // context, depending on what else is on the stack.
863  if (isa<TypeAliasTemplateDecl>(Active->Entity))
864  break;
865  LLVM_FALLTHROUGH;
872  // This is a template instantiation, so there is no SFINAE.
873  return None;
874 
879  // A default template argument instantiation and substitution into
880  // template parameters with arguments for prior parameters may or may
881  // not be a SFINAE context; look further up the stack.
882  break;
883 
888  // We're either substituting explicitly-specified template arguments,
889  // deduced template arguments, a constraint expression or a requirement
890  // in a requires expression, so SFINAE applies.
891  assert(Active->DeductionInfo && "Missing deduction info pointer");
892  return Active->DeductionInfo;
893 
900  // This happens in a context unrelated to template instantiation, so
901  // there is no SFINAE.
902  return None;
903 
905  // FIXME: This should not be treated as a SFINAE context, because
906  // we will cache an incorrect exception specification. However, clang
907  // bootstrap relies this! See PR31692.
908  break;
909 
911  break;
912  }
913 
914  // The inner context was transparent for SFINAE. If it occurred within a
915  // non-instantiation SFINAE context, then SFINAE applies.
916  if (Active->SavedInNonInstantiationSFINAEContext)
917  return Optional<TemplateDeductionInfo *>(nullptr);
918  }
919 
920  return None;
921 }
922 
923 //===----------------------------------------------------------------------===/
924 // Template Instantiation for Types
925 //===----------------------------------------------------------------------===/
926 namespace {
927  class TemplateInstantiator : public TreeTransform<TemplateInstantiator> {
928  const MultiLevelTemplateArgumentList &TemplateArgs;
929  SourceLocation Loc;
930  DeclarationName Entity;
931 
932  public:
933  typedef TreeTransform<TemplateInstantiator> inherited;
934 
935  TemplateInstantiator(Sema &SemaRef,
936  const MultiLevelTemplateArgumentList &TemplateArgs,
937  SourceLocation Loc,
938  DeclarationName Entity)
939  : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc),
940  Entity(Entity) { }
941 
942  /// Determine whether the given type \p T has already been
943  /// transformed.
944  ///
945  /// For the purposes of template instantiation, a type has already been
946  /// transformed if it is NULL or if it is not dependent.
947  bool AlreadyTransformed(QualType T);
948 
949  /// Returns the location of the entity being instantiated, if known.
950  SourceLocation getBaseLocation() { return Loc; }
951 
952  /// Returns the name of the entity being instantiated, if any.
953  DeclarationName getBaseEntity() { return Entity; }
954 
955  /// Sets the "base" location and entity when that
956  /// information is known based on another transformation.
957  void setBase(SourceLocation Loc, DeclarationName Entity) {
958  this->Loc = Loc;
959  this->Entity = Entity;
960  }
961 
962  unsigned TransformTemplateDepth(unsigned Depth) {
963  return TemplateArgs.getNewDepth(Depth);
964  }
965 
966  bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
967  SourceRange PatternRange,
969  bool &ShouldExpand, bool &RetainExpansion,
970  Optional<unsigned> &NumExpansions) {
971  return getSema().CheckParameterPacksForExpansion(EllipsisLoc,
972  PatternRange, Unexpanded,
973  TemplateArgs,
974  ShouldExpand,
975  RetainExpansion,
976  NumExpansions);
977  }
978 
979  void ExpandingFunctionParameterPack(ParmVarDecl *Pack) {
981  }
982 
983  TemplateArgument ForgetPartiallySubstitutedPack() {
984  TemplateArgument Result;
985  if (NamedDecl *PartialPack
987  MultiLevelTemplateArgumentList &TemplateArgs
988  = const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs);
989  unsigned Depth, Index;
990  std::tie(Depth, Index) = getDepthAndIndex(PartialPack);
991  if (TemplateArgs.hasTemplateArgument(Depth, Index)) {
992  Result = TemplateArgs(Depth, Index);
993  TemplateArgs.setArgument(Depth, Index, TemplateArgument());
994  }
995  }
996 
997  return Result;
998  }
999 
1000  void RememberPartiallySubstitutedPack(TemplateArgument Arg) {
1001  if (Arg.isNull())
1002  return;
1003 
1004  if (NamedDecl *PartialPack
1006  MultiLevelTemplateArgumentList &TemplateArgs
1007  = const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs);
1008  unsigned Depth, Index;
1009  std::tie(Depth, Index) = getDepthAndIndex(PartialPack);
1010  TemplateArgs.setArgument(Depth, Index, Arg);
1011  }
1012  }
1013 
1014  /// Transform the given declaration by instantiating a reference to
1015  /// this declaration.
1016  Decl *TransformDecl(SourceLocation Loc, Decl *D);
1017 
1018  void transformAttrs(Decl *Old, Decl *New) {
1019  SemaRef.InstantiateAttrs(TemplateArgs, Old, New);
1020  }
1021 
1022  void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> NewDecls) {
1023  if (Old->isParameterPack()) {
1025  for (auto *New : NewDecls)
1027  Old, cast<VarDecl>(New));
1028  return;
1029  }
1030 
1031  assert(NewDecls.size() == 1 &&
1032  "should only have multiple expansions for a pack");
1033  Decl *New = NewDecls.front();
1034 
1035  // If we've instantiated the call operator of a lambda or the call
1036  // operator template of a generic lambda, update the "instantiation of"
1037  // information.
1038  auto *NewMD = dyn_cast<CXXMethodDecl>(New);
1039  if (NewMD && isLambdaCallOperator(NewMD)) {
1040  auto *OldMD = dyn_cast<CXXMethodDecl>(Old);
1041  if (auto *NewTD = NewMD->getDescribedFunctionTemplate())
1042  NewTD->setInstantiatedFromMemberTemplate(
1043  OldMD->getDescribedFunctionTemplate());
1044  else
1045  NewMD->setInstantiationOfMemberFunction(OldMD,
1047  }
1048 
1049  SemaRef.CurrentInstantiationScope->InstantiatedLocal(Old, New);
1050 
1051  // We recreated a local declaration, but not by instantiating it. There
1052  // may be pending dependent diagnostics to produce.
1053  if (auto *DC = dyn_cast<DeclContext>(Old))
1054  SemaRef.PerformDependentDiagnostics(DC, TemplateArgs);
1055  }
1056 
1057  /// Transform the definition of the given declaration by
1058  /// instantiating it.
1059  Decl *TransformDefinition(SourceLocation Loc, Decl *D);
1060 
1061  /// Transform the first qualifier within a scope by instantiating the
1062  /// declaration.
1063  NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc);
1064 
1065  /// Rebuild the exception declaration and register the declaration
1066  /// as an instantiated local.
1067  VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
1069  SourceLocation StartLoc,
1070  SourceLocation NameLoc,
1071  IdentifierInfo *Name);
1072 
1073  /// Rebuild the Objective-C exception declaration and register the
1074  /// declaration as an instantiated local.
1075  VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1076  TypeSourceInfo *TSInfo, QualType T);
1077 
1078  /// Check for tag mismatches when instantiating an
1079  /// elaborated type.
1080  QualType RebuildElaboratedType(SourceLocation KeywordLoc,
1081  ElaboratedTypeKeyword Keyword,
1082  NestedNameSpecifierLoc QualifierLoc,
1083  QualType T);
1084 
1085  TemplateName
1086  TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
1087  SourceLocation NameLoc,
1088  QualType ObjectType = QualType(),
1089  NamedDecl *FirstQualifierInScope = nullptr,
1090  bool AllowInjectedClassName = false);
1091 
1092  const LoopHintAttr *TransformLoopHintAttr(const LoopHintAttr *LH);
1093 
1094  ExprResult TransformPredefinedExpr(PredefinedExpr *E);
1095  ExprResult TransformDeclRefExpr(DeclRefExpr *E);
1096  ExprResult TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E);
1097 
1098  ExprResult TransformTemplateParmRefExpr(DeclRefExpr *E,
1100  ExprResult TransformSubstNonTypeTemplateParmPackExpr(
1102  ExprResult TransformSubstNonTypeTemplateParmExpr(
1104 
1105  /// Rebuild a DeclRefExpr for a VarDecl reference.
1106  ExprResult RebuildVarDeclRefExpr(VarDecl *PD, SourceLocation Loc);
1107 
1108  /// Transform a reference to a function or init-capture parameter pack.
1109  ExprResult TransformFunctionParmPackRefExpr(DeclRefExpr *E, VarDecl *PD);
1110 
1111  /// Transform a FunctionParmPackExpr which was built when we couldn't
1112  /// expand a function parameter pack reference which refers to an expanded
1113  /// pack.
1114  ExprResult TransformFunctionParmPackExpr(FunctionParmPackExpr *E);
1115 
1116  QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
1117  FunctionProtoTypeLoc TL) {
1118  // Call the base version; it will forward to our overridden version below.
1119  return inherited::TransformFunctionProtoType(TLB, TL);
1120  }
1121 
1122  template<typename Fn>
1123  QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
1125  CXXRecordDecl *ThisContext,
1126  Qualifiers ThisTypeQuals,
1127  Fn TransformExceptionSpec);
1128 
1129  ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
1130  int indexAdjustment,
1131  Optional<unsigned> NumExpansions,
1132  bool ExpectParameterPack);
1133 
1134  /// Transforms a template type parameter type by performing
1135  /// substitution of the corresponding template type argument.
1136  QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB,
1138 
1139  /// Transforms an already-substituted template type parameter pack
1140  /// into either itself (if we aren't substituting into its pack expansion)
1141  /// or the appropriate substituted argument.
1142  QualType TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB,
1144 
1145  ExprResult TransformLambdaExpr(LambdaExpr *E) {
1146  LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true);
1147  return inherited::TransformLambdaExpr(E);
1148  }
1149 
1150  ExprResult TransformRequiresExpr(RequiresExpr *E) {
1151  LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true);
1152  return inherited::TransformRequiresExpr(E);
1153  }
1154 
1155  bool TransformRequiresExprRequirements(
1158  bool SatisfactionDetermined = false;
1159  for (concepts::Requirement *Req : Reqs) {
1160  concepts::Requirement *TransReq = nullptr;
1161  if (!SatisfactionDetermined) {
1162  if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
1163  TransReq = TransformTypeRequirement(TypeReq);
1164  else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
1165  TransReq = TransformExprRequirement(ExprReq);
1166  else
1167  TransReq = TransformNestedRequirement(
1168  cast<concepts::NestedRequirement>(Req));
1169  if (!TransReq)
1170  return true;
1171  if (!TransReq->isDependent() && !TransReq->isSatisfied())
1172  // [expr.prim.req]p6
1173  // [...] The substitution and semantic constraint checking
1174  // proceeds in lexical order and stops when a condition that
1175  // determines the result of the requires-expression is
1176  // encountered. [..]
1177  SatisfactionDetermined = true;
1178  } else
1179  TransReq = Req;
1180  Transformed.push_back(TransReq);
1181  }
1182  return false;
1183  }
1184 
1185  TemplateParameterList *TransformTemplateParameterList(
1186  TemplateParameterList *OrigTPL) {
1187  if (!OrigTPL || !OrigTPL->size()) return OrigTPL;
1188 
1189  DeclContext *Owner = OrigTPL->getParam(0)->getDeclContext();
1190  TemplateDeclInstantiator DeclInstantiator(getSema(),
1191  /* DeclContext *Owner */ Owner, TemplateArgs);
1192  return DeclInstantiator.SubstTemplateParams(OrigTPL);
1193  }
1194 
1196  TransformTypeRequirement(concepts::TypeRequirement *Req);
1198  TransformExprRequirement(concepts::ExprRequirement *Req);
1200  TransformNestedRequirement(concepts::NestedRequirement *Req);
1201 
1202  private:
1203  ExprResult transformNonTypeTemplateParmRef(NonTypeTemplateParmDecl *parm,
1204  SourceLocation loc,
1206  };
1207 }
1208 
1209 bool TemplateInstantiator::AlreadyTransformed(QualType T) {
1210  if (T.isNull())
1211  return true;
1212 
1214  return false;
1215 
1216  getSema().MarkDeclarationsReferencedInType(Loc, T);
1217  return true;
1218 }
1219 
1220 static TemplateArgument
1222  assert(S.ArgumentPackSubstitutionIndex >= 0);
1223  assert(S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size());
1225  if (Arg.isPackExpansion())
1226  Arg = Arg.getPackExpansionPattern();
1227  return Arg;
1228 }
1229 
1230 Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) {
1231  if (!D)
1232  return nullptr;
1233 
1234  if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
1235  if (TTP->getDepth() < TemplateArgs.getNumLevels()) {
1236  // If the corresponding template argument is NULL or non-existent, it's
1237  // because we are performing instantiation from explicitly-specified
1238  // template arguments in a function template, but there were some
1239  // arguments left unspecified.
1240  if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(),
1241  TTP->getPosition()))
1242  return D;
1243 
1244  TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());
1245 
1246  if (TTP->isParameterPack()) {
1247  assert(Arg.getKind() == TemplateArgument::Pack &&
1248  "Missing argument pack");
1249  Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1250  }
1251 
1252  TemplateName Template = Arg.getAsTemplate().getNameToSubstitute();
1253  assert(!Template.isNull() && Template.getAsTemplateDecl() &&
1254  "Wrong kind of template template argument");
1255  return Template.getAsTemplateDecl();
1256  }
1257 
1258  // Fall through to find the instantiated declaration for this template
1259  // template parameter.
1260  }
1261 
1262  return SemaRef.FindInstantiatedDecl(Loc, cast<NamedDecl>(D), TemplateArgs);
1263 }
1264 
1265 Decl *TemplateInstantiator::TransformDefinition(SourceLocation Loc, Decl *D) {
1266  Decl *Inst = getSema().SubstDecl(D, getSema().CurContext, TemplateArgs);
1267  if (!Inst)
1268  return nullptr;
1269 
1270  getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst);
1271  return Inst;
1272 }
1273 
1274 NamedDecl *
1275 TemplateInstantiator::TransformFirstQualifierInScope(NamedDecl *D,
1276  SourceLocation Loc) {
1277  // If the first part of the nested-name-specifier was a template type
1278  // parameter, instantiate that type parameter down to a tag type.
1279  if (TemplateTypeParmDecl *TTPD = dyn_cast_or_null<TemplateTypeParmDecl>(D)) {
1280  const TemplateTypeParmType *TTP
1281  = cast<TemplateTypeParmType>(getSema().Context.getTypeDeclType(TTPD));
1282 
1283  if (TTP->getDepth() < TemplateArgs.getNumLevels()) {
1284  // FIXME: This needs testing w/ member access expressions.
1285  TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getIndex());
1286 
1287  if (TTP->isParameterPack()) {
1288  assert(Arg.getKind() == TemplateArgument::Pack &&
1289  "Missing argument pack");
1290 
1291  if (getSema().ArgumentPackSubstitutionIndex == -1)
1292  return nullptr;
1293 
1294  Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1295  }
1296 
1297  QualType T = Arg.getAsType();
1298  if (T.isNull())
1299  return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
1300 
1301  if (const TagType *Tag = T->getAs<TagType>())
1302  return Tag->getDecl();
1303 
1304  // The resulting type is not a tag; complain.
1305  getSema().Diag(Loc, diag::err_nested_name_spec_non_tag) << T;
1306  return nullptr;
1307  }
1308  }
1309 
1310  return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
1311 }
1312 
1313 VarDecl *
1314 TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl,
1316  SourceLocation StartLoc,
1317  SourceLocation NameLoc,
1318  IdentifierInfo *Name) {
1319  VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, Declarator,
1320  StartLoc, NameLoc, Name);
1321  if (Var)
1322  getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
1323  return Var;
1324 }
1325 
1326 VarDecl *TemplateInstantiator::RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1327  TypeSourceInfo *TSInfo,
1328  QualType T) {
1329  VarDecl *Var = inherited::RebuildObjCExceptionDecl(ExceptionDecl, TSInfo, T);
1330  if (Var)
1331  getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
1332  return Var;
1333 }
1334 
1335 QualType
1336 TemplateInstantiator::RebuildElaboratedType(SourceLocation KeywordLoc,
1337  ElaboratedTypeKeyword Keyword,
1338  NestedNameSpecifierLoc QualifierLoc,
1339  QualType T) {
1340  if (const TagType *TT = T->getAs<TagType>()) {
1341  TagDecl* TD = TT->getDecl();
1342 
1343  SourceLocation TagLocation = KeywordLoc;
1344 
1345  IdentifierInfo *Id = TD->getIdentifier();
1346 
1347  // TODO: should we even warn on struct/class mismatches for this? Seems
1348  // like it's likely to produce a lot of spurious errors.
1349  if (Id && Keyword != ETK_None && Keyword != ETK_Typename) {
1351  if (!SemaRef.isAcceptableTagRedeclaration(TD, Kind, /*isDefinition*/false,
1352  TagLocation, Id)) {
1353  SemaRef.Diag(TagLocation, diag::err_use_with_wrong_tag)
1354  << Id
1355  << FixItHint::CreateReplacement(SourceRange(TagLocation),
1356  TD->getKindName());
1357  SemaRef.Diag(TD->getLocation(), diag::note_previous_use);
1358  }
1359  }
1360  }
1361 
1362  return inherited::RebuildElaboratedType(KeywordLoc, Keyword, QualifierLoc, T);
1363 }
1364 
1365 TemplateName TemplateInstantiator::TransformTemplateName(
1366  CXXScopeSpec &SS, TemplateName Name, SourceLocation NameLoc,
1367  QualType ObjectType, NamedDecl *FirstQualifierInScope,
1368  bool AllowInjectedClassName) {
1369  if (TemplateTemplateParmDecl *TTP
1370  = dyn_cast_or_null<TemplateTemplateParmDecl>(Name.getAsTemplateDecl())) {
1371  if (TTP->getDepth() < TemplateArgs.getNumLevels()) {
1372  // If the corresponding template argument is NULL or non-existent, it's
1373  // because we are performing instantiation from explicitly-specified
1374  // template arguments in a function template, but there were some
1375  // arguments left unspecified.
1376  if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(),
1377  TTP->getPosition()))
1378  return Name;
1379 
1380  TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());
1381 
1382  if (TemplateArgs.isRewrite()) {
1383  // We're rewriting the template parameter as a reference to another
1384  // template parameter.
1385  if (Arg.getKind() == TemplateArgument::Pack) {
1386  assert(Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() &&
1387  "unexpected pack arguments in template rewrite");
1388  Arg = Arg.pack_begin()->getPackExpansionPattern();
1389  }
1390  assert(Arg.getKind() == TemplateArgument::Template &&
1391  "unexpected nontype template argument kind in template rewrite");
1392  return Arg.getAsTemplate();
1393  }
1394 
1395  if (TTP->isParameterPack()) {
1396  assert(Arg.getKind() == TemplateArgument::Pack &&
1397  "Missing argument pack");
1398 
1399  if (getSema().ArgumentPackSubstitutionIndex == -1) {
1400  // We have the template argument pack to substitute, but we're not
1401  // actually expanding the enclosing pack expansion yet. So, just
1402  // keep the entire argument pack.
1403  return getSema().Context.getSubstTemplateTemplateParmPack(TTP, Arg);
1404  }
1405 
1406  Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1407  }
1408 
1409  TemplateName Template = Arg.getAsTemplate().getNameToSubstitute();
1410  assert(!Template.isNull() && "Null template template argument");
1411  assert(!Template.getAsQualifiedTemplateName() &&
1412  "template decl to substitute is qualified?");
1413 
1414  Template = getSema().Context.getSubstTemplateTemplateParm(TTP, Template);
1415  return Template;
1416  }
1417  }
1418 
1420  = Name.getAsSubstTemplateTemplateParmPack()) {
1421  if (getSema().ArgumentPackSubstitutionIndex == -1)
1422  return Name;
1423 
1424  TemplateArgument Arg = SubstPack->getArgumentPack();
1425  Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1426  return Arg.getAsTemplate().getNameToSubstitute();
1427  }
1428 
1429  return inherited::TransformTemplateName(SS, Name, NameLoc, ObjectType,
1430  FirstQualifierInScope,
1431  AllowInjectedClassName);
1432 }
1433 
1434 ExprResult
1435 TemplateInstantiator::TransformPredefinedExpr(PredefinedExpr *E) {
1436  if (!E->isTypeDependent())
1437  return E;
1438 
1439  return getSema().BuildPredefinedExpr(E->getLocation(), E->getIdentKind());
1440 }
1441 
1442 ExprResult
1443 TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E,
1444  NonTypeTemplateParmDecl *NTTP) {
1445  // If the corresponding template argument is NULL or non-existent, it's
1446  // because we are performing instantiation from explicitly-specified
1447  // template arguments in a function template, but there were some
1448  // arguments left unspecified.
1449  if (!TemplateArgs.hasTemplateArgument(NTTP->getDepth(),
1450  NTTP->getPosition()))
1451  return E;
1452 
1453  TemplateArgument Arg = TemplateArgs(NTTP->getDepth(), NTTP->getPosition());
1454 
1455  if (TemplateArgs.isRewrite()) {
1456  // We're rewriting the template parameter as a reference to another
1457  // template parameter.
1458  if (Arg.getKind() == TemplateArgument::Pack) {
1459  assert(Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() &&
1460  "unexpected pack arguments in template rewrite");
1461  Arg = Arg.pack_begin()->getPackExpansionPattern();
1462  }
1463  assert(Arg.getKind() == TemplateArgument::Expression &&
1464  "unexpected nontype template argument kind in template rewrite");
1465  // FIXME: This can lead to the same subexpression appearing multiple times
1466  // in a complete expression.
1467  return Arg.getAsExpr();
1468  }
1469 
1470  if (NTTP->isParameterPack()) {
1471  assert(Arg.getKind() == TemplateArgument::Pack &&
1472  "Missing argument pack");
1473 
1474  if (getSema().ArgumentPackSubstitutionIndex == -1) {
1475  // We have an argument pack, but we can't select a particular argument
1476  // out of it yet. Therefore, we'll build an expression to hold on to that
1477  // argument pack.
1478  QualType TargetType = SemaRef.SubstType(NTTP->getType(), TemplateArgs,
1479  E->getLocation(),
1480  NTTP->getDeclName());
1481  if (TargetType.isNull())
1482  return ExprError();
1483 
1484  QualType ExprType = TargetType.getNonLValueExprType(SemaRef.Context);
1485  if (TargetType->isRecordType())
1486  ExprType.addConst();
1487 
1488  return new (SemaRef.Context) SubstNonTypeTemplateParmPackExpr(
1489  ExprType, TargetType->isReferenceType() ? VK_LValue : VK_PRValue,
1490  NTTP, E->getLocation(), Arg);
1491  }
1492 
1493  Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1494  }
1495 
1496  return transformNonTypeTemplateParmRef(NTTP, E->getLocation(), Arg);
1497 }
1498 
1499 const LoopHintAttr *
1500 TemplateInstantiator::TransformLoopHintAttr(const LoopHintAttr *LH) {
1501  Expr *TransformedExpr = getDerived().TransformExpr(LH->getValue()).get();
1502 
1503  if (TransformedExpr == LH->getValue())
1504  return LH;
1505 
1506  // Generate error if there is a problem with the value.
1507  if (getSema().CheckLoopHintExpr(TransformedExpr, LH->getLocation()))
1508  return LH;
1509 
1510  // Create new LoopHintValueAttr with integral expression in place of the
1511  // non-type template parameter.
1512  return LoopHintAttr::CreateImplicit(getSema().Context, LH->getOption(),
1513  LH->getState(), TransformedExpr, *LH);
1514 }
1515 
1516 ExprResult TemplateInstantiator::transformNonTypeTemplateParmRef(
1518  SourceLocation loc,
1520  ExprResult result;
1521 
1522  // Determine the substituted parameter type. We can usually infer this from
1523  // the template argument, but not always.
1524  auto SubstParamType = [&] {
1525  QualType T;
1526  if (parm->isExpandedParameterPack())
1528  else
1529  T = parm->getType();
1530  if (parm->isParameterPack() && isa<PackExpansionType>(T))
1531  T = cast<PackExpansionType>(T)->getPattern();
1532  return SemaRef.SubstType(T, TemplateArgs, loc, parm->getDeclName());
1533  };
1534 
1535  bool refParam = false;
1536 
1537  // The template argument itself might be an expression, in which case we just
1538  // return that expression. This happens when substituting into an alias
1539  // template.
1540  if (arg.getKind() == TemplateArgument::Expression) {
1541  Expr *argExpr = arg.getAsExpr();
1542  result = argExpr;
1543  if (argExpr->isLValue()) {
1544  if (argExpr->getType()->isRecordType()) {
1545  // Check whether the parameter was actually a reference.
1546  QualType paramType = SubstParamType();
1547  if (paramType.isNull())
1548  return ExprError();
1549  refParam = paramType->isReferenceType();
1550  } else {
1551  refParam = true;
1552  }
1553  }
1554  } else if (arg.getKind() == TemplateArgument::Declaration ||
1555  arg.getKind() == TemplateArgument::NullPtr) {
1556  ValueDecl *VD;
1557  if (arg.getKind() == TemplateArgument::Declaration) {
1558  VD = arg.getAsDecl();
1559 
1560  // Find the instantiation of the template argument. This is
1561  // required for nested templates.
1562  VD = cast_or_null<ValueDecl>(
1563  getSema().FindInstantiatedDecl(loc, VD, TemplateArgs));
1564  if (!VD)
1565  return ExprError();
1566  } else {
1567  // Propagate NULL template argument.
1568  VD = nullptr;
1569  }
1570 
1571  QualType paramType = VD ? arg.getParamTypeForDecl() : arg.getNullPtrType();
1572  assert(!paramType.isNull() && "type substitution failed for param type");
1573  assert(!paramType->isDependentType() && "param type still dependent");
1574  result = SemaRef.BuildExpressionFromDeclTemplateArgument(arg, paramType, loc);
1575  refParam = paramType->isReferenceType();
1576  } else {
1577  result = SemaRef.BuildExpressionFromIntegralTemplateArgument(arg, loc);
1578  assert(result.isInvalid() ||
1579  SemaRef.Context.hasSameType(result.get()->getType(),
1580  arg.getIntegralType()));
1581  }
1582 
1583  if (result.isInvalid())
1584  return ExprError();
1585 
1586  Expr *resultExpr = result.get();
1587  return new (SemaRef.Context) SubstNonTypeTemplateParmExpr(
1588  resultExpr->getType(), resultExpr->getValueKind(), loc, parm, refParam,
1589  resultExpr);
1590 }
1591 
1592 ExprResult
1593 TemplateInstantiator::TransformSubstNonTypeTemplateParmPackExpr(
1595  if (getSema().ArgumentPackSubstitutionIndex == -1) {
1596  // We aren't expanding the parameter pack, so just return ourselves.
1597  return E;
1598  }
1599 
1600  TemplateArgument Arg = E->getArgumentPack();
1601  Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1602  return transformNonTypeTemplateParmRef(E->getParameterPack(),
1604  Arg);
1605 }
1606 
1607 ExprResult
1608 TemplateInstantiator::TransformSubstNonTypeTemplateParmExpr(
1610  ExprResult SubstReplacement = E->getReplacement();
1611  if (!isa<ConstantExpr>(SubstReplacement.get()))
1612  SubstReplacement = TransformExpr(E->getReplacement());
1613  if (SubstReplacement.isInvalid())
1614  return true;
1615  QualType SubstType = TransformType(E->getParameterType(getSema().Context));
1616  if (SubstType.isNull())
1617  return true;
1618  // The type may have been previously dependent and not now, which means we
1619  // might have to implicit cast the argument to the new type, for example:
1620  // template<auto T, decltype(T) U>
1621  // concept C = sizeof(U) == 4;
1622  // void foo() requires C<2, 'a'> { }
1623  // When normalizing foo(), we first form the normalized constraints of C:
1624  // AtomicExpr(sizeof(U) == 4,
1625  // U=SubstNonTypeTemplateParmExpr(Param=U,
1626  // Expr=DeclRef(U),
1627  // Type=decltype(T)))
1628  // Then we substitute T = 2, U = 'a' into the parameter mapping, and need to
1629  // produce:
1630  // AtomicExpr(sizeof(U) == 4,
1631  // U=SubstNonTypeTemplateParmExpr(Param=U,
1632  // Expr=ImpCast(
1633  // decltype(2),
1634  // SubstNTTPE(Param=U, Expr='a',
1635  // Type=char)),
1636  // Type=decltype(2)))
1637  // The call to CheckTemplateArgument here produces the ImpCast.
1638  TemplateArgument Converted;
1639  if (SemaRef.CheckTemplateArgument(E->getParameter(), SubstType,
1640  SubstReplacement.get(),
1641  Converted).isInvalid())
1642  return true;
1643  return transformNonTypeTemplateParmRef(E->getParameter(),
1644  E->getExprLoc(), Converted);
1645 }
1646 
1647 ExprResult TemplateInstantiator::RebuildVarDeclRefExpr(VarDecl *PD,
1648  SourceLocation Loc) {
1649  DeclarationNameInfo NameInfo(PD->getDeclName(), Loc);
1650  return getSema().BuildDeclarationNameExpr(CXXScopeSpec(), NameInfo, PD);
1651 }
1652 
1653 ExprResult
1654 TemplateInstantiator::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
1655  if (getSema().ArgumentPackSubstitutionIndex != -1) {
1656  // We can expand this parameter pack now.
1658  VarDecl *VD = cast_or_null<VarDecl>(TransformDecl(E->getExprLoc(), D));
1659  if (!VD)
1660  return ExprError();
1661  return RebuildVarDeclRefExpr(VD, E->getExprLoc());
1662  }
1663 
1664  QualType T = TransformType(E->getType());
1665  if (T.isNull())
1666  return ExprError();
1667 
1668  // Transform each of the parameter expansions into the corresponding
1669  // parameters in the instantiation of the function decl.
1671  Vars.reserve(E->getNumExpansions());
1672  for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end();
1673  I != End; ++I) {
1674  VarDecl *D = cast_or_null<VarDecl>(TransformDecl(E->getExprLoc(), *I));
1675  if (!D)
1676  return ExprError();
1677  Vars.push_back(D);
1678  }
1679 
1680  auto *PackExpr =
1682  E->getParameterPackLocation(), Vars);
1683  getSema().MarkFunctionParmPackReferenced(PackExpr);
1684  return PackExpr;
1685 }
1686 
1687 ExprResult
1688 TemplateInstantiator::TransformFunctionParmPackRefExpr(DeclRefExpr *E,
1689  VarDecl *PD) {
1690  typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
1691  llvm::PointerUnion<Decl *, DeclArgumentPack *> *Found
1692  = getSema().CurrentInstantiationScope->findInstantiationOf(PD);
1693  assert(Found && "no instantiation for parameter pack");
1694 
1695  Decl *TransformedDecl;
1696  if (DeclArgumentPack *Pack = Found->dyn_cast<DeclArgumentPack *>()) {
1697  // If this is a reference to a function parameter pack which we can
1698  // substitute but can't yet expand, build a FunctionParmPackExpr for it.
1699  if (getSema().ArgumentPackSubstitutionIndex == -1) {
1700  QualType T = TransformType(E->getType());
1701  if (T.isNull())
1702  return ExprError();
1703  auto *PackExpr = FunctionParmPackExpr::Create(getSema().Context, T, PD,
1704  E->getExprLoc(), *Pack);
1705  getSema().MarkFunctionParmPackReferenced(PackExpr);
1706  return PackExpr;
1707  }
1708 
1709  TransformedDecl = (*Pack)[getSema().ArgumentPackSubstitutionIndex];
1710  } else {
1711  TransformedDecl = Found->get<Decl*>();
1712  }
1713 
1714  // We have either an unexpanded pack or a specific expansion.
1715  return RebuildVarDeclRefExpr(cast<VarDecl>(TransformedDecl), E->getExprLoc());
1716 }
1717 
1718 ExprResult
1719 TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) {
1720  NamedDecl *D = E->getDecl();
1721 
1722  // Handle references to non-type template parameters and non-type template
1723  // parameter packs.
1724  if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
1725  if (NTTP->getDepth() < TemplateArgs.getNumLevels())
1726  return TransformTemplateParmRefExpr(E, NTTP);
1727 
1728  // We have a non-type template parameter that isn't fully substituted;
1729  // FindInstantiatedDecl will find it in the local instantiation scope.
1730  }
1731 
1732  // Handle references to function parameter packs.
1733  if (VarDecl *PD = dyn_cast<VarDecl>(D))
1734  if (PD->isParameterPack())
1735  return TransformFunctionParmPackRefExpr(E, PD);
1736 
1737  return inherited::TransformDeclRefExpr(E);
1738 }
1739 
1740 ExprResult TemplateInstantiator::TransformCXXDefaultArgExpr(
1741  CXXDefaultArgExpr *E) {
1742  assert(!cast<FunctionDecl>(E->getParam()->getDeclContext())->
1743  getDescribedFunctionTemplate() &&
1744  "Default arg expressions are never formed in dependent cases.");
1745  return SemaRef.BuildCXXDefaultArgExpr(E->getUsedLocation(),
1746  cast<FunctionDecl>(E->getParam()->getDeclContext()),
1747  E->getParam());
1748 }
1749 
1750 template<typename Fn>
1751 QualType TemplateInstantiator::TransformFunctionProtoType(TypeLocBuilder &TLB,
1753  CXXRecordDecl *ThisContext,
1754  Qualifiers ThisTypeQuals,
1755  Fn TransformExceptionSpec) {
1756  // We need a local instantiation scope for this function prototype.
1757  LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true);
1758  return inherited::TransformFunctionProtoType(
1759  TLB, TL, ThisContext, ThisTypeQuals, TransformExceptionSpec);
1760 }
1761 
1762 ParmVarDecl *
1763 TemplateInstantiator::TransformFunctionTypeParam(ParmVarDecl *OldParm,
1764  int indexAdjustment,
1765  Optional<unsigned> NumExpansions,
1766  bool ExpectParameterPack) {
1767  auto NewParm =
1768  SemaRef.SubstParmVarDecl(OldParm, TemplateArgs, indexAdjustment,
1769  NumExpansions, ExpectParameterPack);
1770  if (NewParm && SemaRef.getLangOpts().OpenCL)
1771  SemaRef.deduceOpenCLAddressSpace(NewParm);
1772  return NewParm;
1773 }
1774 
1775 QualType
1776 TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB,
1778  const TemplateTypeParmType *T = TL.getTypePtr();
1779  if (T->getDepth() < TemplateArgs.getNumLevels()) {
1780  // Replace the template type parameter with its corresponding
1781  // template argument.
1782 
1783  // If the corresponding template argument is NULL or doesn't exist, it's
1784  // because we are performing instantiation from explicitly-specified
1785  // template arguments in a function template class, but there were some
1786  // arguments left unspecified.
1787  if (!TemplateArgs.hasTemplateArgument(T->getDepth(), T->getIndex())) {
1789  = TLB.push<TemplateTypeParmTypeLoc>(TL.getType());
1790  NewTL.setNameLoc(TL.getNameLoc());
1791  return TL.getType();
1792  }
1793 
1794  TemplateArgument Arg = TemplateArgs(T->getDepth(), T->getIndex());
1795 
1796  if (TemplateArgs.isRewrite()) {
1797  // We're rewriting the template parameter as a reference to another
1798  // template parameter.
1799  if (Arg.getKind() == TemplateArgument::Pack) {
1800  assert(Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() &&
1801  "unexpected pack arguments in template rewrite");
1802  Arg = Arg.pack_begin()->getPackExpansionPattern();
1803  }
1804  assert(Arg.getKind() == TemplateArgument::Type &&
1805  "unexpected nontype template argument kind in template rewrite");
1806  QualType NewT = Arg.getAsType();
1807  assert(isa<TemplateTypeParmType>(NewT) &&
1808  "type parm not rewritten to type parm");
1809  auto NewTL = TLB.push<TemplateTypeParmTypeLoc>(NewT);
1810  NewTL.setNameLoc(TL.getNameLoc());
1811  return NewT;
1812  }
1813 
1814  if (T->isParameterPack()) {
1815  assert(Arg.getKind() == TemplateArgument::Pack &&
1816  "Missing argument pack");
1817 
1818  if (getSema().ArgumentPackSubstitutionIndex == -1) {
1819  // We have the template argument pack, but we're not expanding the
1820  // enclosing pack expansion yet. Just save the template argument
1821  // pack for later substitution.
1822  QualType Result
1823  = getSema().Context.getSubstTemplateTypeParmPackType(T, Arg);
1825  = TLB.push<SubstTemplateTypeParmPackTypeLoc>(Result);
1826  NewTL.setNameLoc(TL.getNameLoc());
1827  return Result;
1828  }
1829 
1830  Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1831  }
1832 
1833  assert(Arg.getKind() == TemplateArgument::Type &&
1834  "Template argument kind mismatch");
1835 
1836  QualType Replacement = Arg.getAsType();
1837 
1838  // TODO: only do this uniquing once, at the start of instantiation.
1839  QualType Result
1840  = getSema().Context.getSubstTemplateTypeParmType(T, Replacement);
1842  = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
1843  NewTL.setNameLoc(TL.getNameLoc());
1844  return Result;
1845  }
1846 
1847  // The template type parameter comes from an inner template (e.g.,
1848  // the template parameter list of a member template inside the
1849  // template we are instantiating). Create a new template type
1850  // parameter with the template "level" reduced by one.
1851  TemplateTypeParmDecl *NewTTPDecl = nullptr;
1852  if (TemplateTypeParmDecl *OldTTPDecl = T->getDecl())
1853  NewTTPDecl = cast_or_null<TemplateTypeParmDecl>(
1854  TransformDecl(TL.getNameLoc(), OldTTPDecl));
1855 
1856  QualType Result = getSema().Context.getTemplateTypeParmType(
1857  T->getDepth() - TemplateArgs.getNumSubstitutedLevels(), T->getIndex(),
1858  T->isParameterPack(), NewTTPDecl);
1860  NewTL.setNameLoc(TL.getNameLoc());
1861  return Result;
1862 }
1863 
1864 QualType
1865 TemplateInstantiator::TransformSubstTemplateTypeParmPackType(
1866  TypeLocBuilder &TLB,
1868  if (getSema().ArgumentPackSubstitutionIndex == -1) {
1869  // We aren't expanding the parameter pack, so just return ourselves.
1872  NewTL.setNameLoc(TL.getNameLoc());
1873  return TL.getType();
1874  }
1875 
1877  Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1878  QualType Result = Arg.getAsType();
1879 
1880  Result = getSema().Context.getSubstTemplateTypeParmType(
1882  Result);
1884  = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
1885  NewTL.setNameLoc(TL.getNameLoc());
1886  return Result;
1887 }
1888 
1889 template<typename EntityPrinter>
1891 createSubstDiag(Sema &S, TemplateDeductionInfo &Info, EntityPrinter Printer) {
1892  SmallString<128> Message;
1893  SourceLocation ErrorLoc;
1894  if (Info.hasSFINAEDiagnostic()) {
1897  Info.takeSFINAEDiagnostic(PDA);
1898  PDA.second.EmitToString(S.getDiagnostics(), Message);
1899  ErrorLoc = PDA.first;
1900  } else {
1901  ErrorLoc = Info.getLocation();
1902  }
1903  char *MessageBuf = new (S.Context) char[Message.size()];
1904  std::copy(Message.begin(), Message.end(), MessageBuf);
1905  SmallString<128> Entity;
1906  llvm::raw_svector_ostream OS(Entity);
1907  Printer(OS);
1908  char *EntityBuf = new (S.Context) char[Entity.size()];
1909  std::copy(Entity.begin(), Entity.end(), EntityBuf);
1911  StringRef(EntityBuf, Entity.size()), ErrorLoc,
1912  StringRef(MessageBuf, Message.size())};
1913 }
1914 
1916 TemplateInstantiator::TransformTypeRequirement(concepts::TypeRequirement *Req) {
1917  if (!Req->isDependent() && !AlwaysRebuild())
1918  return Req;
1919  if (Req->isSubstitutionFailure()) {
1920  if (AlwaysRebuild())
1921  return RebuildTypeRequirement(
1922  Req->getSubstitutionDiagnostic());
1923  return Req;
1924  }
1925 
1926  Sema::SFINAETrap Trap(SemaRef);
1928  Sema::InstantiatingTemplate TypeInst(SemaRef,
1929  Req->getType()->getTypeLoc().getBeginLoc(), Req, Info,
1930  Req->getType()->getTypeLoc().getSourceRange());
1931  if (TypeInst.isInvalid())
1932  return nullptr;
1933  TypeSourceInfo *TransType = TransformType(Req->getType());
1934  if (!TransType || Trap.hasErrorOccurred())
1935  return RebuildTypeRequirement(createSubstDiag(SemaRef, Info,
1936  [&] (llvm::raw_ostream& OS) {
1937  Req->getType()->getType().print(OS, SemaRef.getPrintingPolicy());
1938  }));
1939  return RebuildTypeRequirement(TransType);
1940 }
1941 
1943 TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) {
1944  if (!Req->isDependent() && !AlwaysRebuild())
1945  return Req;
1946 
1947  Sema::SFINAETrap Trap(SemaRef);
1948 
1949  llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *>
1950  TransExpr;
1951  if (Req->isExprSubstitutionFailure())
1952  TransExpr = Req->getExprSubstitutionDiagnostic();
1953  else {
1954  Expr *E = Req->getExpr();
1956  Sema::InstantiatingTemplate ExprInst(SemaRef, E->getBeginLoc(), Req, Info,
1957  E->getSourceRange());
1958  if (ExprInst.isInvalid())
1959  return nullptr;
1960  ExprResult TransExprRes = TransformExpr(E);
1961  if (!TransExprRes.isInvalid() && !Trap.hasErrorOccurred() &&
1962  TransExprRes.get()->hasPlaceholderType())
1963  TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get());
1964  if (TransExprRes.isInvalid() || Trap.hasErrorOccurred())
1965  TransExpr = createSubstDiag(SemaRef, Info, [&](llvm::raw_ostream &OS) {
1966  E->printPretty(OS, nullptr, SemaRef.getPrintingPolicy());
1967  });
1968  else
1969  TransExpr = TransExprRes.get();
1970  }
1971 
1973  const auto &RetReq = Req->getReturnTypeRequirement();
1974  if (RetReq.isEmpty())
1975  TransRetReq.emplace();
1976  else if (RetReq.isSubstitutionFailure())
1977  TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
1978  else if (RetReq.isTypeConstraint()) {
1979  TemplateParameterList *OrigTPL =
1980  RetReq.getTypeConstraintTemplateParameterList();
1981  TemplateDeductionInfo Info(OrigTPL->getTemplateLoc());
1982  Sema::InstantiatingTemplate TPLInst(SemaRef, OrigTPL->getTemplateLoc(),
1983  Req, Info, OrigTPL->getSourceRange());
1984  if (TPLInst.isInvalid())
1985  return nullptr;
1986  TemplateParameterList *TPL =
1987  TransformTemplateParameterList(OrigTPL);
1988  if (!TPL)
1989  TransRetReq.emplace(createSubstDiag(SemaRef, Info,
1990  [&] (llvm::raw_ostream& OS) {
1991  RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint()
1992  ->printPretty(OS, nullptr, SemaRef.getPrintingPolicy());
1993  }));
1994  else {
1995  TPLInst.Clear();
1996  TransRetReq.emplace(TPL);
1997  }
1998  }
1999  assert(TransRetReq.hasValue() &&
2000  "All code paths leading here must set TransRetReq");
2001  if (Expr *E = TransExpr.dyn_cast<Expr *>())
2002  return RebuildExprRequirement(E, Req->isSimple(), Req->getNoexceptLoc(),
2003  std::move(*TransRetReq));
2004  return RebuildExprRequirement(
2006  Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
2007 }
2008 
2010 TemplateInstantiator::TransformNestedRequirement(
2012  if (!Req->isDependent() && !AlwaysRebuild())
2013  return Req;
2014  if (Req->isSubstitutionFailure()) {
2015  if (AlwaysRebuild())
2016  return RebuildNestedRequirement(
2017  Req->getSubstitutionDiagnostic());
2018  return Req;
2019  }
2020  Sema::InstantiatingTemplate ReqInst(SemaRef,
2021  Req->getConstraintExpr()->getBeginLoc(), Req,
2023  Req->getConstraintExpr()->getSourceRange());
2024 
2025  ExprResult TransConstraint;
2027  {
2030  Sema::SFINAETrap Trap(SemaRef);
2031  Sema::InstantiatingTemplate ConstrInst(SemaRef,
2032  Req->getConstraintExpr()->getBeginLoc(), Req, Info,
2033  Req->getConstraintExpr()->getSourceRange());
2034  if (ConstrInst.isInvalid())
2035  return nullptr;
2036  TransConstraint = TransformExpr(Req->getConstraintExpr());
2037  if (TransConstraint.isInvalid() || Trap.hasErrorOccurred())
2038  return RebuildNestedRequirement(createSubstDiag(SemaRef, Info,
2039  [&] (llvm::raw_ostream& OS) {
2040  Req->getConstraintExpr()->printPretty(OS, nullptr,
2041  SemaRef.getPrintingPolicy());
2042  }));
2043  }
2044  return RebuildNestedRequirement(TransConstraint.get());
2045 }
2046 
2047 
2048 /// Perform substitution on the type T with a given set of template
2049 /// arguments.
2050 ///
2051 /// This routine substitutes the given template arguments into the
2052 /// type T and produces the instantiated type.
2053 ///
2054 /// \param T the type into which the template arguments will be
2055 /// substituted. If this type is not dependent, it will be returned
2056 /// immediately.
2057 ///
2058 /// \param Args the template arguments that will be
2059 /// substituted for the top-level template parameters within T.
2060 ///
2061 /// \param Loc the location in the source code where this substitution
2062 /// is being performed. It will typically be the location of the
2063 /// declarator (if we're instantiating the type of some declaration)
2064 /// or the location of the type in the source code (if, e.g., we're
2065 /// instantiating the type of a cast expression).
2066 ///
2067 /// \param Entity the name of the entity associated with a declaration
2068 /// being instantiated (if any). May be empty to indicate that there
2069 /// is no such entity (if, e.g., this is a type that occurs as part of
2070 /// a cast expression) or that the entity has no name (e.g., an
2071 /// unnamed function parameter).
2072 ///
2073 /// \param AllowDeducedTST Whether a DeducedTemplateSpecializationType is
2074 /// acceptable as the top level type of the result.
2075 ///
2076 /// \returns If the instantiation succeeds, the instantiated
2077 /// type. Otherwise, produces diagnostics and returns a NULL type.
2079  const MultiLevelTemplateArgumentList &Args,
2080  SourceLocation Loc,
2081  DeclarationName Entity,
2082  bool AllowDeducedTST) {
2083  assert(!CodeSynthesisContexts.empty() &&
2084  "Cannot perform an instantiation without some context on the "
2085  "instantiation stack");
2086 
2087  if (!T->getType()->isInstantiationDependentType() &&
2089  return T;
2090 
2091  TemplateInstantiator Instantiator(*this, Args, Loc, Entity);
2092  return AllowDeducedTST ? Instantiator.TransformTypeWithDeducedTST(T)
2093  : Instantiator.TransformType(T);
2094 }
2095 
2097  const MultiLevelTemplateArgumentList &Args,
2098  SourceLocation Loc,
2099  DeclarationName Entity) {
2100  assert(!CodeSynthesisContexts.empty() &&
2101  "Cannot perform an instantiation without some context on the "
2102  "instantiation stack");
2103 
2104  if (TL.getType().isNull())
2105  return nullptr;
2106 
2107  if (!TL.getType()->isInstantiationDependentType() &&
2108  !TL.getType()->isVariablyModifiedType()) {
2109  // FIXME: Make a copy of the TypeLoc data here, so that we can
2110  // return a new TypeSourceInfo. Inefficient!
2111  TypeLocBuilder TLB;
2112  TLB.pushFullCopy(TL);
2113  return TLB.getTypeSourceInfo(Context, TL.getType());
2114  }
2115 
2116  TemplateInstantiator Instantiator(*this, Args, Loc, Entity);
2117  TypeLocBuilder TLB;
2118  TLB.reserve(TL.getFullDataSize());
2119  QualType Result = Instantiator.TransformType(TLB, TL);
2120  if (Result.isNull())
2121  return nullptr;
2122 
2123  return TLB.getTypeSourceInfo(Context, Result);
2124 }
2125 
2126 /// Deprecated form of the above.
2128  const MultiLevelTemplateArgumentList &TemplateArgs,
2129  SourceLocation Loc, DeclarationName Entity) {
2130  assert(!CodeSynthesisContexts.empty() &&
2131  "Cannot perform an instantiation without some context on the "
2132  "instantiation stack");
2133 
2134  // If T is not a dependent type or a variably-modified type, there
2135  // is nothing to do.
2137  return T;
2138 
2139  TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity);
2140  return Instantiator.TransformType(T);
2141 }
2142 
2144  if (T->getType()->isInstantiationDependentType() ||
2146  return true;
2147 
2148  TypeLoc TL = T->getTypeLoc().IgnoreParens();
2149  if (!TL.getAs<FunctionProtoTypeLoc>())
2150  return false;
2151 
2153  for (ParmVarDecl *P : FP.getParams()) {
2154  // This must be synthesized from a typedef.
2155  if (!P) continue;
2156 
2157  // If there are any parameters, a new TypeSourceInfo that refers to the
2158  // instantiated parameters must be built.
2159  return true;
2160  }
2161 
2162  return false;
2163 }
2164 
2165 /// A form of SubstType intended specifically for instantiating the
2166 /// type of a FunctionDecl. Its purpose is solely to force the
2167 /// instantiation of default-argument expressions and to avoid
2168 /// instantiating an exception-specification.
2170  const MultiLevelTemplateArgumentList &Args,
2171  SourceLocation Loc,
2172  DeclarationName Entity,
2173  CXXRecordDecl *ThisContext,
2174  Qualifiers ThisTypeQuals) {
2175  assert(!CodeSynthesisContexts.empty() &&
2176  "Cannot perform an instantiation without some context on the "
2177  "instantiation stack");
2178 
2180  return T;
2181 
2182  TemplateInstantiator Instantiator(*this, Args, Loc, Entity);
2183 
2184  TypeLocBuilder TLB;
2185 
2186  TypeLoc TL = T->getTypeLoc();
2187  TLB.reserve(TL.getFullDataSize());
2188 
2189  QualType Result;
2190 
2191  if (FunctionProtoTypeLoc Proto =
2193  // Instantiate the type, other than its exception specification. The
2194  // exception specification is instantiated in InitFunctionInstantiation
2195  // once we've built the FunctionDecl.
2196  // FIXME: Set the exception specification to EST_Uninstantiated here,
2197  // instead of rebuilding the function type again later.
2198  Result = Instantiator.TransformFunctionProtoType(
2199  TLB, Proto, ThisContext, ThisTypeQuals,
2201  bool &Changed) { return false; });
2202  } else {
2203  Result = Instantiator.TransformType(TLB, TL);
2204  }
2205  if (Result.isNull())
2206  return nullptr;
2207 
2208  return TLB.getTypeSourceInfo(Context, Result);
2209 }
2210 
2213  SmallVectorImpl<QualType> &ExceptionStorage,
2214  const MultiLevelTemplateArgumentList &Args) {
2215  assert(ESI.Type != EST_Uninstantiated);
2216 
2217  bool Changed = false;
2218  TemplateInstantiator Instantiator(*this, Args, Loc, DeclarationName());
2219  return Instantiator.TransformExceptionSpec(Loc, ESI, ExceptionStorage,
2220  Changed);
2221 }
2222 
2224  const MultiLevelTemplateArgumentList &Args) {
2226  Proto->getExtProtoInfo().ExceptionSpec;
2227 
2228  SmallVector<QualType, 4> ExceptionStorage;
2230  ESI, ExceptionStorage, Args))
2231  // On error, recover by dropping the exception specification.
2232  ESI.Type = EST_None;
2233 
2234  UpdateExceptionSpec(New, ESI);
2235 }
2236 
2237 namespace {
2238 
2239  struct GetContainedInventedTypeParmVisitor :
2240  public TypeVisitor<GetContainedInventedTypeParmVisitor,
2241  TemplateTypeParmDecl *> {
2242  using TypeVisitor<GetContainedInventedTypeParmVisitor,
2243  TemplateTypeParmDecl *>::Visit;
2244 
2245  TemplateTypeParmDecl *Visit(QualType T) {
2246  if (T.isNull())
2247  return nullptr;
2248  return Visit(T.getTypePtr());
2249  }
2250  // The deduced type itself.
2251  TemplateTypeParmDecl *VisitTemplateTypeParmType(
2252  const TemplateTypeParmType *T) {
2253  if (!T->getDecl() || !T->getDecl()->isImplicit())
2254  return nullptr;
2255  return T->getDecl();
2256  }
2257 
2258  // Only these types can contain 'auto' types, and subsequently be replaced
2259  // by references to invented parameters.
2260 
2261  TemplateTypeParmDecl *VisitElaboratedType(const ElaboratedType *T) {
2262  return Visit(T->getNamedType());
2263  }
2264 
2265  TemplateTypeParmDecl *VisitPointerType(const PointerType *T) {
2266  return Visit(T->getPointeeType());
2267  }
2268 
2269  TemplateTypeParmDecl *VisitBlockPointerType(const BlockPointerType *T) {
2270  return Visit(T->getPointeeType());
2271  }
2272 
2273  TemplateTypeParmDecl *VisitReferenceType(const ReferenceType *T) {
2274  return Visit(T->getPointeeTypeAsWritten());
2275  }
2276 
2277  TemplateTypeParmDecl *VisitMemberPointerType(const MemberPointerType *T) {
2278  return Visit(T->getPointeeType());
2279  }
2280 
2281  TemplateTypeParmDecl *VisitArrayType(const ArrayType *T) {
2282  return Visit(T->getElementType());
2283  }
2284 
2285  TemplateTypeParmDecl *VisitDependentSizedExtVectorType(
2286  const DependentSizedExtVectorType *T) {
2287  return Visit(T->getElementType());
2288  }
2289 
2290  TemplateTypeParmDecl *VisitVectorType(const VectorType *T) {
2291  return Visit(T->getElementType());
2292  }
2293 
2294  TemplateTypeParmDecl *VisitFunctionProtoType(const FunctionProtoType *T) {
2295  return VisitFunctionType(T);
2296  }
2297 
2298  TemplateTypeParmDecl *VisitFunctionType(const FunctionType *T) {
2299  return Visit(T->getReturnType());
2300  }
2301 
2302  TemplateTypeParmDecl *VisitParenType(const ParenType *T) {
2303  return Visit(T->getInnerType());
2304  }
2305 
2306  TemplateTypeParmDecl *VisitAttributedType(const AttributedType *T) {
2307  return Visit(T->getModifiedType());
2308  }
2309 
2310  TemplateTypeParmDecl *VisitMacroQualifiedType(const MacroQualifiedType *T) {
2311  return Visit(T->getUnderlyingType());
2312  }
2313 
2314  TemplateTypeParmDecl *VisitAdjustedType(const AdjustedType *T) {
2315  return Visit(T->getOriginalType());
2316  }
2317 
2318  TemplateTypeParmDecl *VisitPackExpansionType(const PackExpansionType *T) {
2319  return Visit(T->getPattern());
2320  }
2321  };
2322 
2323 } // namespace
2324 
2326  TemplateTypeParmDecl *Inst, const TypeConstraint *TC,
2327  const MultiLevelTemplateArgumentList &TemplateArgs) {
2328  const ASTTemplateArgumentListInfo *TemplArgInfo =
2330  TemplateArgumentListInfo InstArgs;
2331 
2332  if (TemplArgInfo) {
2333  InstArgs.setLAngleLoc(TemplArgInfo->LAngleLoc);
2334  InstArgs.setRAngleLoc(TemplArgInfo->RAngleLoc);
2335  if (SubstTemplateArguments(TemplArgInfo->arguments(), TemplateArgs,
2336  InstArgs))
2337  return true;
2338  }
2339  return AttachTypeConstraint(
2341  TC->getNamedConcept(), &InstArgs, Inst,
2342  Inst->isParameterPack()
2343  ? cast<CXXFoldExpr>(TC->getImmediatelyDeclaredConstraint())
2344  ->getEllipsisLoc()
2345  : SourceLocation());
2346 }
2347 
2349  const MultiLevelTemplateArgumentList &TemplateArgs,
2350  int indexAdjustment,
2351  Optional<unsigned> NumExpansions,
2352  bool ExpectParameterPack) {
2353  TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2354  TypeSourceInfo *NewDI = nullptr;
2355 
2356  TypeLoc OldTL = OldDI->getTypeLoc();
2357  if (PackExpansionTypeLoc ExpansionTL = OldTL.getAs<PackExpansionTypeLoc>()) {
2358 
2359  // We have a function parameter pack. Substitute into the pattern of the
2360  // expansion.
2361  NewDI = SubstType(ExpansionTL.getPatternLoc(), TemplateArgs,
2362  OldParm->getLocation(), OldParm->getDeclName());
2363  if (!NewDI)
2364  return nullptr;
2365 
2366  if (NewDI->getType()->containsUnexpandedParameterPack()) {
2367  // We still have unexpanded parameter packs, which means that
2368  // our function parameter is still a function parameter pack.
2369  // Therefore, make its type a pack expansion type.
2370  NewDI = CheckPackExpansion(NewDI, ExpansionTL.getEllipsisLoc(),
2371  NumExpansions);
2372  } else if (ExpectParameterPack) {
2373  // We expected to get a parameter pack but didn't (because the type
2374  // itself is not a pack expansion type), so complain. This can occur when
2375  // the substitution goes through an alias template that "loses" the
2376  // pack expansion.
2377  Diag(OldParm->getLocation(),
2378  diag::err_function_parameter_pack_without_parameter_packs)
2379  << NewDI->getType();
2380  return nullptr;
2381  }
2382  } else {
2383  NewDI = SubstType(OldDI, TemplateArgs, OldParm->getLocation(),
2384  OldParm->getDeclName());
2385  }
2386 
2387  if (!NewDI)
2388  return nullptr;
2389 
2390  if (NewDI->getType()->isVoidType()) {
2391  Diag(OldParm->getLocation(), diag::err_param_with_void_type);
2392  return nullptr;
2393  }
2394 
2395  // In abbreviated templates, TemplateTypeParmDecls with possible
2396  // TypeConstraints are created when the parameter list is originally parsed.
2397  // The TypeConstraints can therefore reference other functions parameters in
2398  // the abbreviated function template, which is why we must instantiate them
2399  // here, when the instantiated versions of those referenced parameters are in
2400  // scope.
2401  if (TemplateTypeParmDecl *TTP =
2402  GetContainedInventedTypeParmVisitor().Visit(OldDI->getType())) {
2403  if (const TypeConstraint *TC = TTP->getTypeConstraint()) {
2404  auto *Inst = cast_or_null<TemplateTypeParmDecl>(
2405  FindInstantiatedDecl(TTP->getLocation(), TTP, TemplateArgs));
2406  // We will first get here when instantiating the abbreviated function
2407  // template's described function, but we might also get here later.
2408  // Make sure we do not instantiate the TypeConstraint more than once.
2409  if (Inst && !Inst->getTypeConstraint()) {
2410  // TODO: Concepts: do not instantiate the constraint (delayed constraint
2411  // substitution)
2412  if (SubstTypeConstraint(Inst, TC, TemplateArgs))
2413  return nullptr;
2414  }
2415  }
2416  }
2417 
2419  OldParm->getInnerLocStart(),
2420  OldParm->getLocation(),
2421  OldParm->getIdentifier(),
2422  NewDI->getType(), NewDI,
2423  OldParm->getStorageClass());
2424  if (!NewParm)
2425  return nullptr;
2426 
2427  // Mark the (new) default argument as uninstantiated (if any).
2428  if (OldParm->hasUninstantiatedDefaultArg()) {
2429  Expr *Arg = OldParm->getUninstantiatedDefaultArg();
2430  NewParm->setUninstantiatedDefaultArg(Arg);
2431  } else if (OldParm->hasUnparsedDefaultArg()) {
2432  NewParm->setUnparsedDefaultArg();
2433  UnparsedDefaultArgInstantiations[OldParm].push_back(NewParm);
2434  } else if (Expr *Arg = OldParm->getDefaultArg()) {
2435  FunctionDecl *OwningFunc = cast<FunctionDecl>(OldParm->getDeclContext());
2436  if (OwningFunc->isInLocalScopeForInstantiation()) {
2437  // Instantiate default arguments for methods of local classes (DR1484)
2438  // and non-defining declarations.
2439  Sema::ContextRAII SavedContext(*this, OwningFunc);
2440  LocalInstantiationScope Local(*this, true);
2441  ExprResult NewArg = SubstExpr(Arg, TemplateArgs);
2442  if (NewArg.isUsable()) {
2443  // It would be nice if we still had this.
2444  SourceLocation EqualLoc = NewArg.get()->getBeginLoc();
2445  ExprResult Result =
2446  ConvertParamDefaultArgument(NewParm, NewArg.get(), EqualLoc);
2447  if (Result.isInvalid())
2448  return nullptr;
2449 
2450  SetParamDefaultArgument(NewParm, Result.getAs<Expr>(), EqualLoc);
2451  }
2452  } else {
2453  // FIXME: if we non-lazily instantiated non-dependent default args for
2454  // non-dependent parameter types we could remove a bunch of duplicate
2455  // conversion warnings for such arguments.
2456  NewParm->setUninstantiatedDefaultArg(Arg);
2457  }
2458  }
2459 
2461 
2462  if (OldParm->isParameterPack() && !NewParm->isParameterPack()) {
2463  // Add the new parameter to the instantiated parameter pack.
2465  } else {
2466  // Introduce an Old -> New mapping
2467  CurrentInstantiationScope->InstantiatedLocal(OldParm, NewParm);
2468  }
2469 
2470  // FIXME: OldParm may come from a FunctionProtoType, in which case CurContext
2471  // can be anything, is this right ?
2472  NewParm->setDeclContext(CurContext);
2473 
2474  NewParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
2475  OldParm->getFunctionScopeIndex() + indexAdjustment);
2476 
2477  InstantiateAttrs(TemplateArgs, OldParm, NewParm);
2478 
2479  return NewParm;
2480 }
2481 
2482 /// Substitute the given template arguments into the given set of
2483 /// parameters, producing the set of parameter types that would be generated
2484 /// from such a substitution.
2487  const FunctionProtoType::ExtParameterInfo *ExtParamInfos,
2488  const MultiLevelTemplateArgumentList &TemplateArgs,
2489  SmallVectorImpl<QualType> &ParamTypes,
2490  SmallVectorImpl<ParmVarDecl *> *OutParams,
2491  ExtParameterInfoBuilder &ParamInfos) {
2492  assert(!CodeSynthesisContexts.empty() &&
2493  "Cannot perform an instantiation without some context on the "
2494  "instantiation stack");
2495 
2496  TemplateInstantiator Instantiator(*this, TemplateArgs, Loc,
2497  DeclarationName());
2498  return Instantiator.TransformFunctionTypeParams(
2499  Loc, Params, nullptr, ExtParamInfos, ParamTypes, OutParams, ParamInfos);
2500 }
2501 
2502 /// Perform substitution on the base class specifiers of the
2503 /// given class template specialization.
2504 ///
2505 /// Produces a diagnostic and returns true on error, returns false and
2506 /// attaches the instantiated base classes to the class template
2507 /// specialization if successful.
2508 bool
2510  CXXRecordDecl *Pattern,
2511  const MultiLevelTemplateArgumentList &TemplateArgs) {
2512  bool Invalid = false;
2513  SmallVector<CXXBaseSpecifier*, 4> InstantiatedBases;
2514  for (const auto &Base : Pattern->bases()) {
2515  if (!Base.getType()->isDependentType()) {
2516  if (const CXXRecordDecl *RD = Base.getType()->getAsCXXRecordDecl()) {
2517  if (RD->isInvalidDecl())
2518  Instantiation->setInvalidDecl();
2519  }
2520  InstantiatedBases.push_back(new (Context) CXXBaseSpecifier(Base));
2521  continue;
2522  }
2523 
2524  SourceLocation EllipsisLoc;
2525  TypeSourceInfo *BaseTypeLoc;
2526  if (Base.isPackExpansion()) {
2527  // This is a pack expansion. See whether we should expand it now, or
2528  // wait until later.
2530  collectUnexpandedParameterPacks(Base.getTypeSourceInfo()->getTypeLoc(),
2531  Unexpanded);
2532  bool ShouldExpand = false;
2533  bool RetainExpansion = false;
2534  Optional<unsigned> NumExpansions;
2535  if (CheckParameterPacksForExpansion(Base.getEllipsisLoc(),
2536  Base.getSourceRange(),
2537  Unexpanded,
2538  TemplateArgs, ShouldExpand,
2539  RetainExpansion,
2540  NumExpansions)) {
2541  Invalid = true;
2542  continue;
2543  }
2544 
2545  // If we should expand this pack expansion now, do so.
2546  if (ShouldExpand) {
2547  for (unsigned I = 0; I != *NumExpansions; ++I) {
2548  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, I);
2549 
2550  TypeSourceInfo *BaseTypeLoc = SubstType(Base.getTypeSourceInfo(),
2551  TemplateArgs,
2552  Base.getSourceRange().getBegin(),
2553  DeclarationName());
2554  if (!BaseTypeLoc) {
2555  Invalid = true;
2556  continue;
2557  }
2558 
2559  if (CXXBaseSpecifier *InstantiatedBase
2560  = CheckBaseSpecifier(Instantiation,
2561  Base.getSourceRange(),
2562  Base.isVirtual(),
2563  Base.getAccessSpecifierAsWritten(),
2564  BaseTypeLoc,
2565  SourceLocation()))
2566  InstantiatedBases.push_back(InstantiatedBase);
2567  else
2568  Invalid = true;
2569  }
2570 
2571  continue;
2572  }
2573 
2574  // The resulting base specifier will (still) be a pack expansion.
2575  EllipsisLoc = Base.getEllipsisLoc();
2576  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, -1);
2577  BaseTypeLoc = SubstType(Base.getTypeSourceInfo(),
2578  TemplateArgs,
2579  Base.getSourceRange().getBegin(),
2580  DeclarationName());
2581  } else {
2582  BaseTypeLoc = SubstType(Base.getTypeSourceInfo(),
2583  TemplateArgs,
2584  Base.getSourceRange().getBegin(),
2585  DeclarationName());
2586  }
2587 
2588  if (!BaseTypeLoc) {
2589  Invalid = true;
2590  continue;
2591  }
2592 
2593  if (CXXBaseSpecifier *InstantiatedBase
2594  = CheckBaseSpecifier(Instantiation,
2595  Base.getSourceRange(),
2596  Base.isVirtual(),
2597  Base.getAccessSpecifierAsWritten(),
2598  BaseTypeLoc,
2599  EllipsisLoc))
2600  InstantiatedBases.push_back(InstantiatedBase);
2601  else
2602  Invalid = true;
2603  }
2604 
2605  if (!Invalid && AttachBaseSpecifiers(Instantiation, InstantiatedBases))
2606  Invalid = true;
2607 
2608  return Invalid;
2609 }
2610 
2611 // Defined via #include from SemaTemplateInstantiateDecl.cpp
2612 namespace clang {
2613  namespace sema {
2615  const MultiLevelTemplateArgumentList &TemplateArgs);
2617  const Attr *At, ASTContext &C, Sema &S,
2618  const MultiLevelTemplateArgumentList &TemplateArgs);
2619  }
2620 }
2621 
2622 /// Instantiate the definition of a class from a given pattern.
2623 ///
2624 /// \param PointOfInstantiation The point of instantiation within the
2625 /// source code.
2626 ///
2627 /// \param Instantiation is the declaration whose definition is being
2628 /// instantiated. This will be either a class template specialization
2629 /// or a member class of a class template specialization.
2630 ///
2631 /// \param Pattern is the pattern from which the instantiation
2632 /// occurs. This will be either the declaration of a class template or
2633 /// the declaration of a member class of a class template.
2634 ///
2635 /// \param TemplateArgs The template arguments to be substituted into
2636 /// the pattern.
2637 ///
2638 /// \param TSK the kind of implicit or explicit instantiation to perform.
2639 ///
2640 /// \param Complain whether to complain if the class cannot be instantiated due
2641 /// to the lack of a definition.
2642 ///
2643 /// \returns true if an error occurred, false otherwise.
2644 bool
2646  CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern,
2647  const MultiLevelTemplateArgumentList &TemplateArgs,
2649  bool Complain) {
2650  CXXRecordDecl *PatternDef
2651  = cast_or_null<CXXRecordDecl>(Pattern->getDefinition());
2652  if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Instantiation,
2653  Instantiation->getInstantiatedFromMemberClass(),
2654  Pattern, PatternDef, TSK, Complain))
2655  return true;
2656 
2657  llvm::TimeTraceScope TimeScope("InstantiateClass", [&]() {
2658  std::string Name;
2659  llvm::raw_string_ostream OS(Name);
2660  Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
2661  /*Qualified=*/true);
2662  return Name;
2663  });
2664 
2665  Pattern = PatternDef;
2666 
2667  // Record the point of instantiation.
2668  if (MemberSpecializationInfo *MSInfo
2669  = Instantiation->getMemberSpecializationInfo()) {
2670  MSInfo->setTemplateSpecializationKind(TSK);
2671  MSInfo->setPointOfInstantiation(PointOfInstantiation);
2672  } else if (ClassTemplateSpecializationDecl *Spec
2673  = dyn_cast<ClassTemplateSpecializationDecl>(Instantiation)) {
2674  Spec->setTemplateSpecializationKind(TSK);
2675  Spec->setPointOfInstantiation(PointOfInstantiation);
2676  }
2677 
2678  InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation);
2679  if (Inst.isInvalid())
2680  return true;
2681  assert(!Inst.isAlreadyInstantiating() && "should have been caught by caller");
2682  PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(),
2683  "instantiating class definition");
2684 
2685  // Enter the scope of this instantiation. We don't use
2686  // PushDeclContext because we don't have a scope.
2687  ContextRAII SavedContext(*this, Instantiation);
2690 
2691  // If this is an instantiation of a local class, merge this local
2692  // instantiation scope with the enclosing scope. Otherwise, every
2693  // instantiation of a class has its own local instantiation scope.
2694  bool MergeWithParentScope = !Instantiation->isDefinedOutsideFunctionOrMethod();
2695  LocalInstantiationScope Scope(*this, MergeWithParentScope);
2696 
2697  // Some class state isn't processed immediately but delayed till class
2698  // instantiation completes. We may not be ready to handle any delayed state
2699  // already on the stack as it might correspond to a different class, so save
2700  // it now and put it back later.
2701  SavePendingParsedClassStateRAII SavedPendingParsedClassState(*this);
2702 
2703  // Pull attributes from the pattern onto the instantiation.
2704  InstantiateAttrs(TemplateArgs, Pattern, Instantiation);
2705 
2706  // Start the definition of this instantiation.
2707  Instantiation->startDefinition();
2708 
2709  // The instantiation is visible here, even if it was first declared in an
2710  // unimported module.
2711  Instantiation->setVisibleDespiteOwningModule();
2712 
2713  // FIXME: This loses the as-written tag kind for an explicit instantiation.
2714  Instantiation->setTagKind(Pattern->getTagKind());
2715 
2716  // Do substitution on the base class specifiers.
2717  if (SubstBaseSpecifiers(Instantiation, Pattern, TemplateArgs))
2718  Instantiation->setInvalidDecl();
2719 
2720  TemplateDeclInstantiator Instantiator(*this, Instantiation, TemplateArgs);
2721  SmallVector<Decl*, 4> Fields;
2722  // Delay instantiation of late parsed attributes.
2723  LateInstantiatedAttrVec LateAttrs;
2724  Instantiator.enableLateAttributeInstantiation(&LateAttrs);
2725 
2726  bool MightHaveConstexprVirtualFunctions = false;
2727  for (auto *Member : Pattern->decls()) {
2728  // Don't instantiate members not belonging in this semantic context.
2729  // e.g. for:
2730  // @code
2731  // template <int i> class A {
2732  // class B *g;
2733  // };
2734  // @endcode
2735  // 'class B' has the template as lexical context but semantically it is
2736  // introduced in namespace scope.
2737  if (Member->getDeclContext() != Pattern)
2738  continue;
2739 
2740  // BlockDecls can appear in a default-member-initializer. They must be the
2741  // child of a BlockExpr, so we only know how to instantiate them from there.
2742  // Similarly, lambda closure types are recreated when instantiating the
2743  // corresponding LambdaExpr.
2744  if (isa<BlockDecl>(Member) ||
2745  (isa<CXXRecordDecl>(Member) && cast<CXXRecordDecl>(Member)->isLambda()))
2746  continue;
2747 
2748  if (Member->isInvalidDecl()) {
2749  Instantiation->setInvalidDecl();
2750  continue;
2751  }
2752 
2753  Decl *NewMember = Instantiator.Visit(Member);
2754  if (NewMember) {
2755  if (FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) {
2756  Fields.push_back(Field);
2757  } else if (EnumDecl *Enum = dyn_cast<EnumDecl>(NewMember)) {
2758  // C++11 [temp.inst]p1: The implicit instantiation of a class template
2759  // specialization causes the implicit instantiation of the definitions
2760  // of unscoped member enumerations.
2761  // Record a point of instantiation for this implicit instantiation.
2762  if (TSK == TSK_ImplicitInstantiation && !Enum->isScoped() &&
2763  Enum->isCompleteDefinition()) {
2764  MemberSpecializationInfo *MSInfo =Enum->getMemberSpecializationInfo();
2765  assert(MSInfo && "no spec info for member enum specialization");
2767  MSInfo->setPointOfInstantiation(PointOfInstantiation);
2768  }
2769  } else if (StaticAssertDecl *SA = dyn_cast<StaticAssertDecl>(NewMember)) {
2770  if (SA->isFailed()) {
2771  // A static_assert failed. Bail out; instantiating this
2772  // class is probably not meaningful.
2773  Instantiation->setInvalidDecl();
2774  break;
2775  }
2776  } else if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewMember)) {
2777  if (MD->isConstexpr() && !MD->getFriendObjectKind() &&
2778  (MD->isVirtualAsWritten() || Instantiation->getNumBases()))
2779  MightHaveConstexprVirtualFunctions = true;
2780  }
2781 
2782  if (NewMember->isInvalidDecl())
2783  Instantiation->setInvalidDecl();
2784  } else {
2785  // FIXME: Eventually, a NULL return will mean that one of the
2786  // instantiations was a semantic disaster, and we'll want to mark the
2787  // declaration invalid.
2788  // For now, we expect to skip some members that we can't yet handle.
2789  }
2790  }
2791 
2792  // Finish checking fields.
2793  ActOnFields(nullptr, Instantiation->getLocation(), Instantiation, Fields,
2795  CheckCompletedCXXClass(nullptr, Instantiation);
2796 
2797  // Default arguments are parsed, if not instantiated. We can go instantiate
2798  // default arg exprs for default constructors if necessary now. Unless we're
2799  // parsing a class, in which case wait until that's finished.
2800  if (ParsingClassDepth == 0)
2802 
2803  // Instantiate late parsed attributes, and attach them to their decls.
2804  // See Sema::InstantiateAttrs
2805  for (LateInstantiatedAttrVec::iterator I = LateAttrs.begin(),
2806  E = LateAttrs.end(); I != E; ++I) {
2807  assert(CurrentInstantiationScope == Instantiator.getStartingScope());
2808  CurrentInstantiationScope = I->Scope;
2809 
2810  // Allow 'this' within late-parsed attributes.
2811  auto *ND = cast<NamedDecl>(I->NewDecl);
2812  auto *ThisContext = dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext());
2813  CXXThisScopeRAII ThisScope(*this, ThisContext, Qualifiers(),
2814  ND->isCXXInstanceMember());
2815 
2816  Attr *NewAttr =
2817  instantiateTemplateAttribute(I->TmplAttr, Context, *this, TemplateArgs);
2818  if (NewAttr)
2819  I->NewDecl->addAttr(NewAttr);
2821  Instantiator.getStartingScope());
2822  }
2823  Instantiator.disableLateAttributeInstantiation();
2824  LateAttrs.clear();
2825 
2826  ActOnFinishDelayedMemberInitializers(Instantiation);
2827 
2828  // FIXME: We should do something similar for explicit instantiations so they
2829  // end up in the right module.
2830  if (TSK == TSK_ImplicitInstantiation) {
2831  Instantiation->setLocation(Pattern->getLocation());
2832  Instantiation->setLocStart(Pattern->getInnerLocStart());
2833  Instantiation->setBraceRange(Pattern->getBraceRange());
2834  }
2835 
2836  if (!Instantiation->isInvalidDecl()) {
2837  // Perform any dependent diagnostics from the pattern.
2838  if (Pattern->isDependentContext())
2839  PerformDependentDiagnostics(Pattern, TemplateArgs);
2840 
2841  // Instantiate any out-of-line class template partial
2842  // specializations now.
2844  P = Instantiator.delayed_partial_spec_begin(),
2845  PEnd = Instantiator.delayed_partial_spec_end();
2846  P != PEnd; ++P) {
2848  P->first, P->second)) {
2849  Instantiation->setInvalidDecl();
2850  break;
2851  }
2852  }
2853 
2854  // Instantiate any out-of-line variable template partial
2855  // specializations now.
2857  P = Instantiator.delayed_var_partial_spec_begin(),
2858  PEnd = Instantiator.delayed_var_partial_spec_end();
2859  P != PEnd; ++P) {
2861  P->first, P->second)) {
2862  Instantiation->setInvalidDecl();
2863  break;
2864  }
2865  }
2866  }
2867 
2868  // Exit the scope of this instantiation.
2869  SavedContext.pop();
2870 
2871  if (!Instantiation->isInvalidDecl()) {
2872  // Always emit the vtable for an explicit instantiation definition
2873  // of a polymorphic class template specialization. Otherwise, eagerly
2874  // instantiate only constexpr virtual functions in preparation for their use
2875  // in constant evaluation.
2877  MarkVTableUsed(PointOfInstantiation, Instantiation, true);
2878  else if (MightHaveConstexprVirtualFunctions)
2879  MarkVirtualMembersReferenced(PointOfInstantiation, Instantiation,
2880  /*ConstexprOnly*/ true);
2881  }
2882 
2883  Consumer.HandleTagDeclDefinition(Instantiation);
2884 
2885  return Instantiation->isInvalidDecl();
2886 }
2887 
2888 /// Instantiate the definition of an enum from a given pattern.
2889 ///
2890 /// \param PointOfInstantiation The point of instantiation within the
2891 /// source code.
2892 /// \param Instantiation is the declaration whose definition is being
2893 /// instantiated. This will be a member enumeration of a class
2894 /// temploid specialization, or a local enumeration within a
2895 /// function temploid specialization.
2896 /// \param Pattern The templated declaration from which the instantiation
2897 /// occurs.
2898 /// \param TemplateArgs The template arguments to be substituted into
2899 /// the pattern.
2900 /// \param TSK The kind of implicit or explicit instantiation to perform.
2901 ///
2902 /// \return \c true if an error occurred, \c false otherwise.
2903 bool Sema::InstantiateEnum(SourceLocation PointOfInstantiation,
2904  EnumDecl *Instantiation, EnumDecl *Pattern,
2905  const MultiLevelTemplateArgumentList &TemplateArgs,
2907  EnumDecl *PatternDef = Pattern->getDefinition();
2908  if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Instantiation,
2909  Instantiation->getInstantiatedFromMemberEnum(),
2910  Pattern, PatternDef, TSK,/*Complain*/true))
2911  return true;
2912  Pattern = PatternDef;
2913 
2914  // Record the point of instantiation.
2915  if (MemberSpecializationInfo *MSInfo
2916  = Instantiation->getMemberSpecializationInfo()) {
2917  MSInfo->setTemplateSpecializationKind(TSK);
2918  MSInfo->setPointOfInstantiation(PointOfInstantiation);
2919  }
2920 
2921  InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation);
2922  if (Inst.isInvalid())
2923  return true;
2924  if (Inst.isAlreadyInstantiating())
2925  return false;
2926  PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(),
2927  "instantiating enum definition");
2928 
2929  // The instantiation is visible here, even if it was first declared in an
2930  // unimported module.
2931  Instantiation->setVisibleDespiteOwningModule();
2932 
2933  // Enter the scope of this instantiation. We don't use
2934  // PushDeclContext because we don't have a scope.
2935  ContextRAII SavedContext(*this, Instantiation);
2938 
2939  LocalInstantiationScope Scope(*this, /*MergeWithParentScope*/true);
2940 
2941  // Pull attributes from the pattern onto the instantiation.
2942  InstantiateAttrs(TemplateArgs, Pattern, Instantiation);
2943 
2944  TemplateDeclInstantiator Instantiator(*this, Instantiation, TemplateArgs);
2945  Instantiator.InstantiateEnumDefinition(Instantiation, Pattern);
2946 
2947  // Exit the scope of this instantiation.
2948  SavedContext.pop();
2949 
2950  return Instantiation->isInvalidDecl();
2951 }
2952 
2953 
2954 /// Instantiate the definition of a field from the given pattern.
2955 ///
2956 /// \param PointOfInstantiation The point of instantiation within the
2957 /// source code.
2958 /// \param Instantiation is the declaration whose definition is being
2959 /// instantiated. This will be a class of a class temploid
2960 /// specialization, or a local enumeration within a function temploid
2961 /// specialization.
2962 /// \param Pattern The templated declaration from which the instantiation
2963 /// occurs.
2964 /// \param TemplateArgs The template arguments to be substituted into
2965 /// the pattern.
2966 ///
2967 /// \return \c true if an error occurred, \c false otherwise.
2969  SourceLocation PointOfInstantiation, FieldDecl *Instantiation,
2970  FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs) {
2971  // If there is no initializer, we don't need to do anything.
2972  if (!Pattern->hasInClassInitializer())
2973  return false;
2974 
2975  assert(Instantiation->getInClassInitStyle() ==
2976  Pattern->getInClassInitStyle() &&
2977  "pattern and instantiation disagree about init style");
2978 
2979  // Error out if we haven't parsed the initializer of the pattern yet because
2980  // we are waiting for the closing brace of the outer class.
2981  Expr *OldInit = Pattern->getInClassInitializer();
2982  if (!OldInit) {
2983  RecordDecl *PatternRD = Pattern->getParent();
2984  RecordDecl *OutermostClass = PatternRD->getOuterLexicalRecordContext();
2985  Diag(PointOfInstantiation,
2986  diag::err_default_member_initializer_not_yet_parsed)
2987  << OutermostClass << Pattern;
2988  Diag(Pattern->getEndLoc(),
2989  diag::note_default_member_initializer_not_yet_parsed);
2990  Instantiation->setInvalidDecl();
2991  return true;
2992  }
2993 
2994  InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation);
2995  if (Inst.isInvalid())
2996  return true;
2997  if (Inst.isAlreadyInstantiating()) {
2998  // Error out if we hit an instantiation cycle for this initializer.
2999  Diag(PointOfInstantiation, diag::err_default_member_initializer_cycle)
3000  << Instantiation;
3001  return true;
3002  }
3003  PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(),
3004  "instantiating default member init");
3005 
3006  // Enter the scope of this instantiation. We don't use PushDeclContext because
3007  // we don't have a scope.
3008  ContextRAII SavedContext(*this, Instantiation->getParent());
3011 
3012  LocalInstantiationScope Scope(*this, true);
3013 
3014  // Instantiate the initializer.
3016  CXXThisScopeRAII ThisScope(*this, Instantiation->getParent(), Qualifiers());
3017 
3018  ExprResult NewInit = SubstInitializer(OldInit, TemplateArgs,
3019  /*CXXDirectInit=*/false);
3020  Expr *Init = NewInit.get();
3021  assert((!Init || !isa<ParenListExpr>(Init)) && "call-style init in class");
3023  Instantiation, Init ? Init->getBeginLoc() : SourceLocation(), Init);
3024 
3025  if (auto *L = getASTMutationListener())
3026  L->DefaultMemberInitializerInstantiated(Instantiation);
3027 
3028  // Return true if the in-class initializer is still missing.
3029  return !Instantiation->getInClassInitializer();
3030 }
3031 
3032 namespace {
3033  /// A partial specialization whose template arguments have matched
3034  /// a given template-id.
3035  struct PartialSpecMatchResult {
3037  TemplateArgumentList *Args;
3038  };
3039 }
3040 
3042  SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec) {
3043  if (ClassTemplateSpec->getTemplateSpecializationKind() ==
3045  return true;
3046 
3048  ClassTemplateSpec->getSpecializedTemplate()
3049  ->getPartialSpecializations(PartialSpecs);
3050  for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) {
3051  TemplateDeductionInfo Info(Loc);
3052  if (!DeduceTemplateArguments(PartialSpecs[I],
3053  ClassTemplateSpec->getTemplateArgs(), Info))
3054  return true;
3055  }
3056 
3057  return false;
3058 }
3059 
3060 /// Get the instantiation pattern to use to instantiate the definition of a
3061 /// given ClassTemplateSpecializationDecl (either the pattern of the primary
3062 /// template or of a partial specialization).
3065  Sema &S, SourceLocation PointOfInstantiation,
3066  ClassTemplateSpecializationDecl *ClassTemplateSpec,
3068  Sema::InstantiatingTemplate Inst(S, PointOfInstantiation, ClassTemplateSpec);
3069  if (Inst.isInvalid())
3070  return {/*Invalid=*/true};
3071  if (Inst.isAlreadyInstantiating())
3072  return {/*Invalid=*/false};
3073 
3074  llvm::PointerUnion<ClassTemplateDecl *,
3076  Specialized = ClassTemplateSpec->getSpecializedTemplateOrPartial();
3077  if (!Specialized.is<ClassTemplatePartialSpecializationDecl *>()) {
3078  // Find best matching specialization.
3079  ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate();
3080 
3081  // C++ [temp.class.spec.match]p1:
3082  // When a class template is used in a context that requires an
3083  // instantiation of the class, it is necessary to determine
3084  // whether the instantiation is to be generated using the primary
3085  // template or one of the partial specializations. This is done by
3086  // matching the template arguments of the class template
3087  // specialization with the template argument lists of the partial
3088  // specializations.
3089  typedef PartialSpecMatchResult MatchResult;
3092  Template->getPartialSpecializations(PartialSpecs);
3093  TemplateSpecCandidateSet FailedCandidates(PointOfInstantiation);
3094  for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) {
3095  ClassTemplatePartialSpecializationDecl *Partial = PartialSpecs[I];
3096  TemplateDeductionInfo Info(FailedCandidates.getLocation());
3098  Partial, ClassTemplateSpec->getTemplateArgs(), Info)) {
3099  // Store the failed-deduction information for use in diagnostics, later.
3100  // TODO: Actually use the failed-deduction info?
3101  FailedCandidates.addCandidate().set(
3102  DeclAccessPair::make(Template, AS_public), Partial,
3103  MakeDeductionFailureInfo(S.Context, Result, Info));
3104  (void)Result;
3105  } else {
3106  Matched.push_back(PartialSpecMatchResult());
3107  Matched.back().Partial = Partial;
3108  Matched.back().Args = Info.take();
3109  }
3110  }
3111 
3112  // If we're dealing with a member template where the template parameters
3113  // have been instantiated, this provides the original template parameters
3114  // from which the member template's parameters were instantiated.
3115 
3116  if (Matched.size() >= 1) {
3117  SmallVectorImpl<MatchResult>::iterator Best = Matched.begin();
3118  if (Matched.size() == 1) {
3119  // -- If exactly one matching specialization is found, the
3120  // instantiation is generated from that specialization.
3121  // We don't need to do anything for this.
3122  } else {
3123  // -- If more than one matching specialization is found, the
3124  // partial order rules (14.5.4.2) are used to determine
3125  // whether one of the specializations is more specialized
3126  // than the others. If none of the specializations is more
3127  // specialized than all of the other matching
3128  // specializations, then the use of the class template is
3129  // ambiguous and the program is ill-formed.
3130  for (SmallVectorImpl<MatchResult>::iterator P = Best + 1,
3131  PEnd = Matched.end();
3132  P != PEnd; ++P) {
3134  P->Partial, Best->Partial, PointOfInstantiation) ==
3135  P->Partial)
3136  Best = P;
3137  }
3138 
3139  // Determine if the best partial specialization is more specialized than
3140  // the others.
3141  bool Ambiguous = false;
3142  for (SmallVectorImpl<MatchResult>::iterator P = Matched.begin(),
3143  PEnd = Matched.end();
3144  P != PEnd; ++P) {
3145  if (P != Best && S.getMoreSpecializedPartialSpecialization(
3146  P->Partial, Best->Partial,
3147  PointOfInstantiation) != Best->Partial) {
3148  Ambiguous = true;
3149  break;
3150  }
3151  }
3152 
3153  if (Ambiguous) {
3154  // Partial ordering did not produce a clear winner. Complain.
3155  Inst.Clear();
3156  ClassTemplateSpec->setInvalidDecl();
3157  S.Diag(PointOfInstantiation,
3158  diag::err_partial_spec_ordering_ambiguous)
3159  << ClassTemplateSpec;
3160 
3161  // Print the matching partial specializations.
3162  for (SmallVectorImpl<MatchResult>::iterator P = Matched.begin(),
3163  PEnd = Matched.end();
3164  P != PEnd; ++P)
3165  S.Diag(P->Partial->getLocation(), diag::note_partial_spec_match)
3167  P->Partial->getTemplateParameters(), *P->Args);
3168 
3169  return {/*Invalid=*/true};
3170  }
3171  }
3172 
3173  ClassTemplateSpec->setInstantiationOf(Best->Partial, Best->Args);
3174  } else {
3175  // -- If no matches are found, the instantiation is generated
3176  // from the primary template.
3177  }
3178  }
3179 
3180  CXXRecordDecl *Pattern = nullptr;
3181  Specialized = ClassTemplateSpec->getSpecializedTemplateOrPartial();
3182  if (auto *PartialSpec =
3183  Specialized.dyn_cast<ClassTemplatePartialSpecializationDecl *>()) {
3184  // Instantiate using the best class template partial specialization.
3185  while (PartialSpec->getInstantiatedFromMember()) {
3186  // If we've found an explicit specialization of this class template,
3187  // stop here and use that as the pattern.
3188  if (PartialSpec->isMemberSpecialization())
3189  break;
3190 
3191  PartialSpec = PartialSpec->getInstantiatedFromMember();
3192  }
3193  Pattern = PartialSpec;
3194  } else {
3195  ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate();
3196  while (Template->getInstantiatedFromMemberTemplate()) {
3197  // If we've found an explicit specialization of this class template,
3198  // stop here and use that as the pattern.
3199  if (Template->isMemberSpecialization())
3200  break;
3201 
3202  Template = Template->getInstantiatedFromMemberTemplate();
3203  }
3204  Pattern = Template->getTemplatedDecl();
3205  }
3206 
3207  return Pattern;
3208 }
3209 
3211  SourceLocation PointOfInstantiation,
3212  ClassTemplateSpecializationDecl *ClassTemplateSpec,
3213  TemplateSpecializationKind TSK, bool Complain) {
3214  // Perform the actual instantiation on the canonical declaration.
3215  ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>(
3216  ClassTemplateSpec->getCanonicalDecl());
3217  if (ClassTemplateSpec->isInvalidDecl())
3218  return true;
3219 
3221  getPatternForClassTemplateSpecialization(*this, PointOfInstantiation,
3222  ClassTemplateSpec, TSK);
3223  if (!Pattern.isUsable())
3224  return Pattern.isInvalid();
3225 
3226  return InstantiateClass(
3227  PointOfInstantiation, ClassTemplateSpec, Pattern.get(),
3228  getTemplateInstantiationArgs(ClassTemplateSpec), TSK, Complain);
3229 }
3230 
3231 /// Instantiates the definitions of all of the member
3232 /// of the given class, which is an instantiation of a class template
3233 /// or a member class of a template.
3234 void
3236  CXXRecordDecl *Instantiation,
3237  const MultiLevelTemplateArgumentList &TemplateArgs,
3239  // FIXME: We need to notify the ASTMutationListener that we did all of these
3240  // things, in case we have an explicit instantiation definition in a PCM, a
3241  // module, or preamble, and the declaration is in an imported AST.
3242  assert(
3245  (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) &&
3246  "Unexpected template specialization kind!");
3247  for (auto *D : Instantiation->decls()) {
3248  bool SuppressNew = false;
3249  if (auto *Function = dyn_cast<FunctionDecl>(D)) {
3250  if (FunctionDecl *Pattern =
3251  Function->getInstantiatedFromMemberFunction()) {
3252 
3253  if (Function->getTrailingRequiresClause()) {
3254  ConstraintSatisfaction Satisfaction;
3255  if (CheckFunctionConstraints(Function, Satisfaction) ||
3256  !Satisfaction.IsSatisfied) {
3257  continue;
3258  }
3259  }
3260 
3261  if (Function->hasAttr<ExcludeFromExplicitInstantiationAttr>())
3262  continue;
3263 
3264  MemberSpecializationInfo *MSInfo =
3265  Function->getMemberSpecializationInfo();
3266  assert(MSInfo && "No member specialization information?");
3267  if (MSInfo->getTemplateSpecializationKind()
3269  continue;
3270 
3271  if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK,
3272  Function,
3274  MSInfo->getPointOfInstantiation(),
3275  SuppressNew) ||
3276  SuppressNew)
3277  continue;
3278 
3279  // C++11 [temp.explicit]p8:
3280  // An explicit instantiation definition that names a class template
3281  // specialization explicitly instantiates the class template
3282  // specialization and is only an explicit instantiation definition
3283  // of members whose definition is visible at the point of
3284  // instantiation.
3285  if (TSK == TSK_ExplicitInstantiationDefinition && !Pattern->isDefined())
3286  continue;
3287 
3288  Function->setTemplateSpecializationKind(TSK, PointOfInstantiation);
3289 
3290  if (Function->isDefined()) {
3291  // Let the ASTConsumer know that this function has been explicitly
3292  // instantiated now, and its linkage might have changed.
3294  } else if (TSK == TSK_ExplicitInstantiationDefinition) {
3295  InstantiateFunctionDefinition(PointOfInstantiation, Function);
3296  } else if (TSK == TSK_ImplicitInstantiation) {
3298  std::make_pair(Function, PointOfInstantiation));
3299  }
3300  }
3301  } else if (auto *Var = dyn_cast<VarDecl>(D)) {
3302  if (isa<VarTemplateSpecializationDecl>(Var))
3303  continue;
3304 
3305  if (Var->isStaticDataMember()) {
3306  if (Var->hasAttr<ExcludeFromExplicitInstantiationAttr>())
3307  continue;
3308 
3310  assert(MSInfo && "No member specialization information?");
3311  if (MSInfo->getTemplateSpecializationKind()
3313  continue;
3314 
3315  if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK,
3316  Var,
3318  MSInfo->getPointOfInstantiation(),
3319  SuppressNew) ||
3320  SuppressNew)
3321  continue;
3322 
3324  // C++0x [temp.explicit]p8:
3325  // An explicit instantiation definition that names a class template
3326  // specialization explicitly instantiates the class template
3327  // specialization and is only an explicit instantiation definition
3328  // of members whose definition is visible at the point of
3329  // instantiation.
3331  continue;
3332 
3333  Var->setTemplateSpecializationKind(TSK, PointOfInstantiation);
3334  InstantiateVariableDefinition(PointOfInstantiation, Var);
3335  } else {
3336  Var->setTemplateSpecializationKind(TSK, PointOfInstantiation);
3337  }
3338  }
3339  } else if (auto *Record = dyn_cast<CXXRecordDecl>(D)) {
3340  if (Record->hasAttr<ExcludeFromExplicitInstantiationAttr>())
3341  continue;
3342 
3343  // Always skip the injected-class-name, along with any
3344  // redeclarations of nested classes, since both would cause us
3345  // to try to instantiate the members of a class twice.
3346  // Skip closure types; they'll get instantiated when we instantiate
3347  // the corresponding lambda-expression.
3348  if (Record->isInjectedClassName() || Record->getPreviousDecl() ||
3349  Record->isLambda())
3350  continue;
3351 
3352  MemberSpecializationInfo *MSInfo = Record->getMemberSpecializationInfo();
3353  assert(MSInfo && "No member specialization information?");
3354 
3355  if (MSInfo->getTemplateSpecializationKind()
3357  continue;
3358 
3359  if (Context.getTargetInfo().getTriple().isOSWindows() &&
3361  // On Windows, explicit instantiation decl of the outer class doesn't
3362  // affect the inner class. Typically extern template declarations are
3363  // used in combination with dll import/export annotations, but those
3364  // are not propagated from the outer class templates to inner classes.
3365  // Therefore, do not instantiate inner classes on this platform, so
3366  // that users don't end up with undefined symbols during linking.
3367  continue;
3368  }
3369 
3370  if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK,
3371  Record,
3373  MSInfo->getPointOfInstantiation(),
3374  SuppressNew) ||
3375  SuppressNew)
3376  continue;
3377 
3378  CXXRecordDecl *Pattern = Record->getInstantiatedFromMemberClass();
3379  assert(Pattern && "Missing instantiated-from-template information");
3380 
3381  if (!Record->getDefinition()) {
3382  if (!Pattern->getDefinition()) {
3383  // C++0x [temp.explicit]p8:
3384  // An explicit instantiation definition that names a class template
3385  // specialization explicitly instantiates the class template
3386  // specialization and is only an explicit instantiation definition
3387  // of members whose definition is visible at the point of
3388  // instantiation.
3390  MSInfo->setTemplateSpecializationKind(TSK);
3391  MSInfo->setPointOfInstantiation(PointOfInstantiation);
3392  }
3393 
3394  continue;
3395  }
3396 
3397  InstantiateClass(PointOfInstantiation, Record, Pattern,
3398  TemplateArgs,
3399  TSK);
3400  } else {
3402  Record->getTemplateSpecializationKind() ==
3404  Record->setTemplateSpecializationKind(TSK);
3405  MarkVTableUsed(PointOfInstantiation, Record, true);
3406  }
3407  }
3408 
3409  Pattern = cast_or_null<CXXRecordDecl>(Record->getDefinition());
3410  if (Pattern)
3411  InstantiateClassMembers(PointOfInstantiation, Pattern, TemplateArgs,
3412  TSK);
3413  } else if (auto *Enum = dyn_cast<EnumDecl>(D)) {
3414  MemberSpecializationInfo *MSInfo = Enum->getMemberSpecializationInfo();
3415  assert(MSInfo && "No member specialization information?");
3416 
3417  if (MSInfo->getTemplateSpecializationKind()
3419  continue;
3420 
3422  PointOfInstantiation, TSK, Enum,
3424  MSInfo->getPointOfInstantiation(), SuppressNew) ||
3425  SuppressNew)
3426  continue;
3427 
3428  if (Enum->getDefinition())
3429  continue;
3430 
3431  EnumDecl *Pattern = Enum->getTemplateInstantiationPattern();
3432  assert(Pattern && "Missing instantiated-from-template information");
3433 
3435  if (!Pattern->getDefinition())
3436  continue;
3437 
3438  InstantiateEnum(PointOfInstantiation, Enum, Pattern, TemplateArgs, TSK);
3439  } else {
3440  MSInfo->setTemplateSpecializationKind(TSK);
3441  MSInfo->setPointOfInstantiation(PointOfInstantiation);
3442  }
3443  } else if (auto *Field = dyn_cast<FieldDecl>(D)) {
3444  // No need to instantiate in-class initializers during explicit
3445  // instantiation.
3446  if (Field->hasInClassInitializer() && TSK == TSK_ImplicitInstantiation) {
3447  CXXRecordDecl *ClassPattern =
3448  Instantiation->getTemplateInstantiationPattern();
3450  ClassPattern->lookup(Field->getDeclName());
3451  FieldDecl *Pattern = Lookup.find_first<FieldDecl>();
3452  assert(Pattern);
3453  InstantiateInClassInitializer(PointOfInstantiation, Field, Pattern,
3454  TemplateArgs);
3455  }
3456  }
3457  }
3458 }
3459 
3460 /// Instantiate the definitions of all of the members of the
3461 /// given class template specialization, which was named as part of an
3462 /// explicit instantiation.
3463 void
3465  SourceLocation PointOfInstantiation,
3466  ClassTemplateSpecializationDecl *ClassTemplateSpec,
3468  // C++0x [temp.explicit]p7:
3469  // An explicit instantiation that names a class template
3470  // specialization is an explicit instantion of the same kind
3471  // (declaration or definition) of each of its members (not
3472  // including members inherited from base classes) that has not
3473  // been previously explicitly specialized in the translation unit
3474  // containing the explicit instantiation, except as described
3475  // below.
3476  InstantiateClassMembers(PointOfInstantiation, ClassTemplateSpec,
3477  getTemplateInstantiationArgs(ClassTemplateSpec),
3478  TSK);
3479 }
3480 
3481 StmtResult
3483  if (!S)
3484  return S;
3485 
3486  TemplateInstantiator Instantiator(*this, TemplateArgs,
3487  SourceLocation(),
3488  DeclarationName());
3489  return Instantiator.TransformStmt(S);
3490 }
3491 
3494  const MultiLevelTemplateArgumentList &TemplateArgs,
3495  TemplateArgumentListInfo &Out) {
3496  TemplateInstantiator Instantiator(*this, TemplateArgs,
3497  SourceLocation(),
3498  DeclarationName());
3499  return Instantiator.TransformTemplateArguments(Args.begin(), Args.end(),
3500  Out);
3501 }
3502 
3503 ExprResult
3505  if (!E)
3506  return E;
3507 
3508  TemplateInstantiator Instantiator(*this, TemplateArgs,
3509  SourceLocation(),
3510  DeclarationName());
3511  return Instantiator.TransformExpr(E);
3512 }
3513 
3515  const MultiLevelTemplateArgumentList &TemplateArgs,
3516  bool CXXDirectInit) {
3517  TemplateInstantiator Instantiator(*this, TemplateArgs,
3518  SourceLocation(),
3519  DeclarationName());
3520  return Instantiator.TransformInitializer(Init, CXXDirectInit);
3521 }
3522 
3523 bool Sema::SubstExprs(ArrayRef<Expr *> Exprs, bool IsCall,
3524  const MultiLevelTemplateArgumentList &TemplateArgs,
3525  SmallVectorImpl<Expr *> &Outputs) {
3526  if (Exprs.empty())
3527  return false;
3528 
3529  TemplateInstantiator Instantiator(*this, TemplateArgs,
3530  SourceLocation(),
3531  DeclarationName());
3532  return Instantiator.TransformExprs(Exprs.data(), Exprs.size(),
3533  IsCall, Outputs);
3534 }
3535 
3538  const MultiLevelTemplateArgumentList &TemplateArgs) {
3539  if (!NNS)
3540  return NestedNameSpecifierLoc();
3541 
3542  TemplateInstantiator Instantiator(*this, TemplateArgs, NNS.getBeginLoc(),
3543  DeclarationName());
3544  return Instantiator.TransformNestedNameSpecifierLoc(NNS);
3545 }
3546 
3547 /// Do template substitution on declaration name info.
3550  const MultiLevelTemplateArgumentList &TemplateArgs) {
3551  TemplateInstantiator Instantiator(*this, TemplateArgs, NameInfo.getLoc(),
3552  NameInfo.getName());
3553  return Instantiator.TransformDeclarationNameInfo(NameInfo);
3554 }
3555 
3558  TemplateName Name, SourceLocation Loc,
3559  const MultiLevelTemplateArgumentList &TemplateArgs) {
3560  TemplateInstantiator Instantiator(*this, TemplateArgs, Loc,
3561  DeclarationName());
3562  CXXScopeSpec SS;
3563  SS.Adopt(QualifierLoc);
3564  return Instantiator.TransformTemplateName(SS, Name, Loc);
3565 }
3566 
3567 static const Decl *getCanonicalParmVarDecl(const Decl *D) {
3568  // When storing ParmVarDecls in the local instantiation scope, we always
3569  // want to use the ParmVarDecl from the canonical function declaration,
3570  // since the map is then valid for any redeclaration or definition of that
3571  // function.
3572  if (const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(D)) {
3573  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) {
3574  unsigned i = PV->getFunctionScopeIndex();
3575  // This parameter might be from a freestanding function type within the
3576  // function and isn't necessarily referring to one of FD's parameters.
3577  if (i < FD->getNumParams() && FD->getParamDecl(i) == PV)
3578  return FD->getCanonicalDecl()->getParamDecl(i);
3579  }
3580  }
3581  return D;
3582 }
3583 
3584 
3585 llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *
3587  D = getCanonicalParmVarDecl(D);
3588  for (LocalInstantiationScope *Current = this; Current;
3589  Current = Current->Outer) {
3590 
3591  // Check if we found something within this scope.
3592  const Decl *CheckD = D;
3593  do {
3594  LocalDeclsMap::iterator Found = Current->LocalDecls.find(CheckD);
3595  if (Found != Current->LocalDecls.end())
3596  return &Found->second;
3597 
3598  // If this is a tag declaration, it's possible that we need to look for
3599  // a previous declaration.
3600  if (const TagDecl *Tag = dyn_cast<TagDecl>(CheckD))
3601  CheckD = Tag->getPreviousDecl();
3602  else
3603  CheckD = nullptr;
3604  } while (CheckD);
3605 
3606  // If we aren't combined with our outer scope, we're done.
3607  if (!Current->CombineWithOuterScope)
3608  break;
3609  }
3610 
3611  // If we're performing a partial substitution during template argument
3612  // deduction, we may not have values for template parameters yet.
3613  if (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D) ||
3614  isa<TemplateTemplateParmDecl>(D))
3615  return nullptr;
3616 
3617  // Local types referenced prior to definition may require instantiation.
3618  if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D))
3619  if (RD->isLocalClass())
3620  return nullptr;
3621 
3622  // Enumeration types referenced prior to definition may appear as a result of
3623  // error recovery.
3624  if (isa<EnumDecl>(D))
3625  return nullptr;
3626 
3627  // Materialized typedefs/type alias for implicit deduction guides may require
3628  // instantiation.
3629  if (isa<TypedefNameDecl>(D) &&
3630  isa<CXXDeductionGuideDecl>(D->getDeclContext()))
3631  return nullptr;
3632 
3633  // If we didn't find the decl, then we either have a sema bug, or we have a
3634  // forward reference to a label declaration. Return null to indicate that
3635  // we have an uninstantiated label.
3636  assert(isa<LabelDecl>(D) && "declaration not instantiated in this scope");
3637  return nullptr;
3638 }
3639 
3641  D = getCanonicalParmVarDecl(D);
3642  llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
3643  if (Stored.isNull()) {
3644 #ifndef NDEBUG
3645  // It should not be present in any surrounding scope either.
3646  LocalInstantiationScope *Current = this;
3647  while (Current->CombineWithOuterScope && Current->Outer) {
3648  Current = Current->Outer;
3649  assert(Current->LocalDecls.find(D) == Current->LocalDecls.end() &&
3650  "Instantiated local in inner and outer scopes");
3651  }
3652 #endif
3653  Stored = Inst;
3654  } else if (DeclArgumentPack *Pack = Stored.dyn_cast<DeclArgumentPack *>()) {
3655  Pack->push_back(cast<VarDecl>(Inst));
3656  } else {
3657  assert(Stored.get<Decl *>() == Inst && "Already instantiated this local");
3658  }
3659 }
3660 
3662  VarDecl *Inst) {
3663  D = getCanonicalParmVarDecl(D);
3664  DeclArgumentPack *Pack = LocalDecls[D].get<DeclArgumentPack *>();
3665  Pack->push_back(Inst);
3666 }
3667 
3669 #ifndef NDEBUG
3670  // This should be the first time we've been told about this decl.
3671  for (LocalInstantiationScope *Current = this;
3672  Current && Current->CombineWithOuterScope; Current = Current->Outer)
3673  assert(Current->LocalDecls.find(D) == Current->LocalDecls.end() &&
3674  "Creating local pack after instantiation of local");
3675 #endif
3676 
3677  D = getCanonicalParmVarDecl(D);
3678  llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
3679  DeclArgumentPack *Pack = new DeclArgumentPack;
3680  Stored = Pack;
3681  ArgumentPacks.push_back(Pack);
3682 }
3683 
3685  for (DeclArgumentPack *Pack : ArgumentPacks)
3686  if (llvm::is_contained(*Pack, D))
3687  return true;
3688  return false;
3689 }
3690 
3692  const TemplateArgument *ExplicitArgs,
3693  unsigned NumExplicitArgs) {
3694  assert((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) &&
3695  "Already have a partially-substituted pack");
3696  assert((!PartiallySubstitutedPack
3697  || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) &&
3698  "Wrong number of arguments in partially-substituted pack");
3699  PartiallySubstitutedPack = Pack;
3700  ArgsInPartiallySubstitutedPack = ExplicitArgs;
3701  NumArgsInPartiallySubstitutedPack = NumExplicitArgs;
3702 }
3703 
3705  const TemplateArgument **ExplicitArgs,
3706  unsigned *NumExplicitArgs) const {
3707  if (ExplicitArgs)
3708  *ExplicitArgs = nullptr;
3709  if (NumExplicitArgs)
3710  *NumExplicitArgs = 0;
3711 
3712  for (const LocalInstantiationScope *Current = this; Current;
3713  Current = Current->Outer) {
3714  if (Current->PartiallySubstitutedPack) {
3715  if (ExplicitArgs)
3716  *ExplicitArgs = Current->ArgsInPartiallySubstitutedPack;
3717  if (NumExplicitArgs)
3718  *NumExplicitArgs = Current->NumArgsInPartiallySubstitutedPack;
3719 
3720  return Current->PartiallySubstitutedPack;
3721  }
3722 
3723  if (!Current->CombineWithOuterScope)
3724  break;
3725  }
3726 
3727  return nullptr;
3728 }
clang::ElaboratedTypeKeyword
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition: Type.h:5403
clang::DeclaratorDecl::getInnerLocStart
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition: Decl.h:769
clang::sema::TemplateDeductionInfo::take
TemplateArgumentList * take()
Take ownership of the deduced template argument list.
Definition: TemplateDeduction.h:95
clang::TagDecl::getKindName
StringRef getKindName() const
Definition: Decl.h:3541
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:422
clang::SubstNonTypeTemplateParmExpr
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:4262
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:162
clang::concepts::ExprRequirement::getExprSubstitutionDiagnostic
SubstitutionDiagnostic * getExprSubstitutionDiagnostic() const
Definition: ExprConcepts.h:386
clang::Type::isRecordType
bool isRecordType() const
Definition: Type.h:6838
clang::Sema::warnStackExhausted
void warnStackExhausted(SourceLocation Loc)
Warn that the stack is nearly exhausted.
Definition: Sema.cpp:510
NeedsInstantiationAsFunctionType
static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T)
Definition: SemaTemplateInstantiate.cpp:2143
clang::isLambdaCallOperator
bool isLambdaCallOperator(const CXXMethodDecl *MD)
Definition: ASTLambda.h:27
clang::Sema::InstantiatingTemplate::ParameterMappingSubstitution
Definition: Sema.h:9202
clang::ParenType::getInnerType
QualType getInnerType() const
Definition: Type.h:2636
clang::ParmVarDecl::setUnparsedDefaultArg
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition: Decl.h:1809
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:2645
clang::Sema::CheckPlaceholderExpr
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
Definition: SemaExpr.cpp:20438
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:1569
clang::TemplateDeclInstantiator::delayed_var_partial_spec_begin
delayed_var_partial_spec_iterator delayed_var_partial_spec_begin()
Definition: Template.h:572
clang::Sema::UnparsedDefaultArgInstantiations
UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations
A mapping from parameters with unparsed default arguments to the set of instantiations of each parame...
Definition: Sema.h:1443
clang::Sema::SubstDeclarationNameInfo
DeclarationNameInfo SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, const MultiLevelTemplateArgumentList &TemplateArgs)
Do template substitution on declaration name info.
Definition: SemaTemplateInstantiate.cpp:3549
clang::DeclContext::decls
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:2131
clang::Decl::setDeclContext
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition: DeclBase.cpp:327
clang::DeclRefExpr::getLocation
SourceLocation getLocation() const
Definition: Expr.h:1303
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:2771
clang::Sema::deduceOpenCLAddressSpace
void deduceOpenCLAddressSpace(ValueDecl *decl)
Definition: SemaDecl.cpp:6679
clang::TypeSourceInfo::getType
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:6482
clang::concepts::TypeRequirement::getSubstitutionDiagnostic
SubstitutionDiagnostic * getSubstitutionDiagnostic() const
Definition: ExprConcepts.h:238
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:4702
clang::MemberSpecializationInfo
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:620
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:425
clang::CXXScopeSpec::Adopt
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition: DeclSpec.cpp:131
clang::TemplateTypeParmType::getDecl
TemplateTypeParmDecl * getDecl() const
Definition: Type.h:4878
clang::Sema::CXXThisScopeRAII
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Definition: Sema.h:6368
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:2485
clang::SubstTemplateTypeParmPackType::getArgumentPack
TemplateArgument getArgumentPack() const
Definition: Type.cpp:3656
createSubstDiag
static concepts::Requirement::SubstitutionDiagnostic * createSubstDiag(Sema &S, TemplateDeductionInfo &Info, EntityPrinter Printer)
Definition: SemaTemplateInstantiate.cpp:1891
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:1356
clang::Decl::hasAttr
bool hasAttr() const
Definition: DeclBase.h:542
clang::CXXRecordDecl::getMemberSpecializationInfo
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization,...
Definition: DeclCXX.cpp:1796
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:13825
convertCallArgsToString
static std::string convertCallArgsToString(Sema &S, llvm::ArrayRef< const Expr * > Args)
Definition: SemaTemplateInstantiate.cpp:486
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:5386
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:9047
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:4329
clang::FunctionParmPackExpr::getParameterPack
VarDecl * getParameterPack() const
Get the parameter pack which this expression refers to.
Definition: ExprCXX.h:4426
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:8895
clang::Sema::CodeSynthesisContext::PointOfInstantiation
SourceLocation PointOfInstantiation
The point of instantiation or synthesis within the source code.
Definition: Sema.h:8921
clang::TemplateSpecCandidateSet::getLocation
SourceLocation getLocation() const
Definition: TemplateDeduction.h:335
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:1215
clang::ClassTemplateSpecializationDecl::getSpecializedTemplate
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
Definition: DeclTemplate.cpp:965
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:5994
clang::TypeLocBuilder::getTypeSourceInfo
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
Definition: TypeLocBuilder.h:101
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:152
clang::CXXRecordDecl::getDefinition
CXXRecordDecl * getDefinition() const
Definition: DeclCXX.h:542
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:675
clang::NonTypeTemplateParmDecl
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
Definition: DeclTemplate.h:1401
clang::TemplateName::getAsTemplateDecl
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known.
Definition: TemplateName.cpp:108
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:185
clang::ClassTemplateDecl::getInstantiatedFromMemberTemplate
ClassTemplateDecl * getInstantiatedFromMemberTemplate() const
Definition: DeclTemplate.h:2370
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:5380
clang::concepts::Requirement::SubstitutionDiagnostic
Definition: ExprConcepts.h:161
clang::FieldDecl
Represents a member of a struct/union/class.
Definition: Decl.h:2855
clang::TagDecl::setBraceRange
void setBraceRange(SourceRange R)
Definition: Decl.h:3430
clang::RequiresExpr
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
Definition: ExprConcepts.h:475
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:3002
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:562
clang::ParmVarDecl
Represents a parameter to a function.
Definition: Decl.h:1680
clang::Sema::Diag
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: Sema.cpp:1871
clang::ParmVarDecl::getDefaultArg
Expr * getDefaultArg()
Definition: Decl.cpp:2863
int
__device__ int
Definition: __clang_hip_libdevice_declares.h:63
clang::Sema::ContextRAII::pop
void pop()
Definition: Sema.h:1011
clang::concepts::NestedRequirement::getSubstitutionDiagnostic
SubstitutionDiagnostic * getSubstitutionDiagnostic() const
Definition: ExprConcepts.h:441
clang::Sema::CodeSynthesisContexts
SmallVector< CodeSynthesisContext, 16 > CodeSynthesisContexts
List of active code synthesis contexts.
Definition: Sema.h:8982
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:2014
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:1888
clang::NonTypeTemplateParmDecl::getExpansionType
QualType getExpansionType(unsigned I) const
Retrieve a particular expansion type within an expanded parameter pack.
Definition: DeclTemplate.h:1561
clang::Sema::CheckTemplateArgument
bool CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg, NamedDecl *Template, SourceLocation TemplateLoc, SourceLocation RAngleLoc, unsigned ArgumentPackIndex, SmallVectorImpl< TemplateArgument > &Converted, CheckTemplateArgumentKind CTAK=CTAK_Specified)
Check that the given template argument corresponds to the given template parameter.
Definition: SemaTemplate.cpp:5373
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:580
clang::concepts::ExprRequirement::getExpr
Expr * getExpr() const
Definition: ExprConcepts.h:393
llvm::Optional
Definition: LLVM.h:40
clang::Sema::PrintInstantiationStack
void PrintInstantiationStack()
Prints the current instantiation stack through a series of notes.
Definition: SemaTemplateInstantiate.cpp:520
TypeVisitor.h
clang::TypeLoc::getEndLoc
SourceLocation getEndLoc() const
Get the end source location.
Definition: TypeLoc.cpp:228
clang::Sema::ActOnFields
void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl, ArrayRef< Decl * > Fields, SourceLocation LBrac, SourceLocation RBrac, const ParsedAttributesView &AttrList)
Definition: SemaDecl.cpp:17760
clang::TagType
Definition: Type.h:4623
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:6741
clang::Type::isVoidType
bool isVoidType() const
Definition: Type.h:7037
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:4029
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:3064
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:2122
clang::LocalInstantiationScope::deleteScopes
static void deleteScopes(LocalInstantiationScope *Scope, LocalInstantiationScope *Outermost)
deletes the given scope, and all otuer scopes, down to the given outermost scope.
Definition: Template.h:403
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:9039
clang::CXXScopeSpec
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:64
clang::ClassTemplatePartialSpecializationDecl
Definition: DeclTemplate.h:2092
clang::ReferenceType::getPointeeTypeAsWritten
QualType getPointeeTypeAsWritten() const
Definition: Type.h:2780
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:9031
clang::TemplateDeclInstantiator::disableLateAttributeInstantiation
void disableLateAttributeInstantiation()
Definition: Template.h:551
ASTLambda.h
clang::concepts::Requirement::isSatisfied
bool isSatisfied() const
Definition: ExprConcepts.h:178
clang::FunctionParmPackExpr::Create
static FunctionParmPackExpr * Create(const ASTContext &Context, QualType T, VarDecl *ParamPack, SourceLocation NameLoc, ArrayRef< VarDecl * > Params)
Definition: ExprCXX.cpp:1614
print
void print(llvm::raw_ostream &OS, const Pointer &P, ASTContext &Ctx, QualType Ty)
Definition: InterpFrame.cpp:62
clang::TypeDecl::setLocStart
void setLocStart(SourceLocation L)
Definition: Decl.h:3186
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:1748
clang::FunctionType
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3559
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:180
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:1078
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:7603
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:640
clang::Sema::CodeSynthesisContextLookupModules
SmallVector< Module *, 16 > CodeSynthesisContextLookupModules
Extra modules inspected when performing a lookup during a template instantiation.
Definition: Sema.h:8993
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:4540
clang::EnumDecl
Represents an enum.
Definition: Decl.h:3628
clang::Sema::Context
ASTContext & Context
Definition: Sema.h:410
clang::Sema::InstantiatingTemplate::isAlreadyInstantiating
bool isAlreadyInstantiating() const
Determine whether we are already instantiating this specialization in some surrounding active instant...
Definition: Sema.h:9233
clang::PredefinedExpr::getIdentKind
IdentKind getIdentKind() const
Definition: Expr.h:2007
clang::Sema::CodeSynthesisContext::SynthesisKind
SynthesisKind
The kind of template instantiation we are performing.
Definition: Sema.h:8818
clang::ExprError
ExprResult ExprError()
Definition: Ownership.h:278
clang::SubstTemplateTypeParmPackType::getReplacedParameter
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
Definition: Type.h:4983
clang::Sema::SFINAETrap
RAII class used to determine whether SFINAE has trapped any errors that occur during template argumen...
Definition: Sema.h:9303
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:17854
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:8828
clang::Sema::InstantiatingTemplate::ConstraintsCheck
Definition: Sema.h:9178
clang::Sema::getLangOpts
const LangOptions & getLangOpts() const
Definition: Sema.h:1607
clang::ClassTemplateDecl::getPartialSpecializations
llvm::FoldingSetVector< ClassTemplatePartialSpecializationDecl > & getPartialSpecializations() const
Retrieve the set of partial specializations of this class template.
Definition: DeclTemplate.cpp:479
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:668
clang::FunctionParmPackExpr
Represents a reference to a function parameter pack or init-capture pack that has been substituted bu...
Definition: ExprCXX.h:4397
clang::Sema::CodeSynthesisContext::ConstraintSubstitution
@ ConstraintSubstitution
Definition: Sema.h:8888
clang::TagDecl::setTagKind
void setTagKind(TagKind TK)
Definition: Decl.h:3549
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::ParmVarDecl::setScopeInfo
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition: Decl.h:1713
clang::Decl::getLexicalDeclContext
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition: DeclBase.h:852
clang::Sema::SubstTemplateName
TemplateName SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, SourceLocation Loc, const MultiLevelTemplateArgumentList &TemplateArgs)
Definition: SemaTemplateInstantiate.cpp:3557
clang::VarDecl::isParameterPack
bool isParameterPack() const
Determine whether this variable is actually a function parameter pack or init-capture pack.
Definition: Decl.cpp:2558
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:8934
clang::FunctionTemplateDecl
Declaration of a template function.
Definition: DeclTemplate.h:979
clang::FunctionParmPackExpr::begin
iterator begin() const
Definition: ExprCXX.h:4434
clang::concepts::NestedRequirement::getConstraintExpr
Expr * getConstraintExpr() const
Definition: ExprConcepts.h:448
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:1789
clang::TypeLocBuilder::push
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
Definition: TypeLocBuilder.h:93
clang::Type::isReferenceType
bool isReferenceType() const
Definition: Type.h:6760
clang::PackExpansionTypeLoc
Definition: TypeLoc.h:2498
clang::TSK_ExplicitInstantiationDeclaration
@ TSK_ExplicitInstantiationDeclaration
This template specialization was instantiated from a template due to an explicit instantiation declar...
Definition: Specifiers.h:187
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:5729
clang::Sema::NonInstantiationEntries
unsigned NonInstantiationEntries
The number of CodeSynthesisContexts that are not template instantiations and, therefore,...
Definition: Sema.h:9023
clang::Sema::BuildCXXDefaultArgExpr
ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, ParmVarDecl *Param)
BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating the default expr if needed.
Definition: SemaExpr.cpp:5907
clang::ConceptReference::getTemplateArgsAsWritten
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Definition: ASTConcept.h:156
clang::Sema::getTemplateInstantiationArgs
MultiLevelTemplateArgumentList getTemplateInstantiationArgs(const NamedDecl *D, const TemplateArgumentList *Innermost=nullptr, bool RelativeToPrimary=false, const FunctionDecl *Pattern=nullptr)
Retrieve the template argument list(s) that should be used to instantiate the definition of the given...
Definition: SemaTemplateInstantiate.cpp:58
clang::ElaboratedType
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:5479
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:8929
clang::TypeWithKeyword::getTagTypeKindForKeyword
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition: Type.cpp:2876
clang::VarDecl::getInstantiatedFromStaticDataMember
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization,...
Definition: Decl.cpp:2644
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:2727
clang::Sema::CodeSynthesisContext::ExceptionSpecInstantiation
@ ExceptionSpecInstantiation
We are instantiating the exception specification for a function template which was deferred until it ...
Definition: Sema.h:8861
clang::SubstTemplateTypeParmPackTypeLoc
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:849
clang::Module
Describes a module or submodule.
Definition: Module.h:96
clang::ClassTemplateSpecializationDecl::getTemplateArgs
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
Definition: DeclTemplate.h:1908
clang::TemplateParameterList::getParam
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:138
DeclTemplate.h
clang::PackExpansionType
Represents a pack expansion of types.
Definition: Type.h:5708
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:191
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:1611
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:9053
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:3158
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:2635
clang::TagTypeKind
TagTypeKind
The kind of a tag type.
Definition: Type.h:5384
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:13504
clang::DiagnosticsEngine::hasFatalErrorOccurred
bool hasFatalErrorOccurred() const
Definition: Diagnostic.h:844
clang::FunctionParmPackExpr::getNumExpansions
unsigned getNumExpansions() const
Get the number of parameters in this parameter pack.
Definition: ExprCXX.h:4438
clang::TemplateTypeParmType::getIndex
unsigned getIndex() const
Definition: Type.h:4875
Id
int Id
Definition: ASTDiff.cpp:191
clang::FunctionProtoType::ExceptionSpecInfo
Holds information about the various types of exception specification.
Definition: Type.h:3955
clang::Sema::hasUncompilableErrorOccurred
bool hasUncompilableErrorOccurred() const
Whether uncompilable error has occurred.
Definition: Sema.cpp:1579
clang::SubstNonTypeTemplateParmPackExpr::getParameterPack
NonTypeTemplateParmDecl * getParameterPack() const
Retrieve the non-type template parameter pack being substituted.
Definition: ExprCXX.h:4357
clang::LambdaExpr
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1865
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:3238
MatchResult
MatchFinder::MatchResult MatchResult
Definition: RangeSelector.cpp:30
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:7493
clang::SubstNonTypeTemplateParmExpr::getReplacement
Expr * getReplacement() const
Definition: ExprCXX.h:4294
PrettyDeclStackTrace.h
clang::Sema::CodeSynthesisContext::TemplateInstantiation
@ TemplateInstantiation
We are instantiating a template declaration.
Definition: Sema.h:8821
clang::AS_public
@ AS_public
Definition: Specifiers.h:109
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:9453
clang::VectorType
Represents a GCC generic vector type.
Definition: Type.h:3242
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:2762
clang::VarDecl::isStaticDataMember
bool isStaticDataMember() const
Determines whether this is a static data member.
Definition: Decl.h:1198
clang::Sema::CodeSynthesisContext::RequirementInstantiation
@ RequirementInstantiation
We are instantiating a requirement of a requires expression.
Definition: Sema.h:8864
clang::Sema::InstantiatingTemplate::ConstraintSubstitution
Definition: Sema.h:9187
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:208
clang::TemplateDeclInstantiator
Definition: Template.h:463
clang::Sema::InstantiateAttrs
void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, const Decl *Pattern, Decl *Inst, LateInstantiatedAttrVec *LateAttrs=nullptr, LocalInstantiationScope *OuterMostScope=nullptr)
Definition: SemaTemplateInstantiateDecl.cpp:692
clang::ArrayType
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:2896
clang::DeclaratorContext::Member
@ Member
LangOptions.h
clang::MemberPointerType::getPointeeType
QualType getPointeeType() const
Definition: Type.h:2860
getCanonicalParmVarDecl
static const Decl * getCanonicalParmVarDecl(const Decl *D)
Definition: SemaTemplateInstantiate.cpp:3567
Depth
int Depth
Definition: ASTDiff.cpp:191
clang::EnumDecl::getDefinition
EnumDecl * getDefinition() const
Definition: Decl.h:3731
clang::concepts::NestedRequirement
A requires-expression requirement which is satisfied when a general constraint expression is satisfie...
Definition: ExprConcepts.h:407
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7243
clang::CXXRecordDecl::getNumBases
unsigned getNumBases() const
Retrieves the number of base classes of this class.
Definition: DeclCXX.h:590
clang::Decl::isInvalidDecl
bool isInvalidDecl() const
Definition: DeclBase.h:553
clang::TemplateSpecCandidate::set
void set(DeclAccessPair Found, Decl *Spec, DeductionFailureInfo Info)
Definition: TemplateDeduction.h:302
clang::Sema::SubstTemplateArguments
bool SubstTemplateArguments(ArrayRef< TemplateArgumentLoc > Args, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateArgumentListInfo &Outputs)
Definition: SemaTemplateInstantiate.cpp:3492
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:651
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:149
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::CodeSynthesisContext::DeducedTemplateArgumentSubstitution
@ DeducedTemplateArgumentSubstitution
We are substituting template argument determined as part of template argument deduction for either a ...
Definition: Sema.h:8844
clang::Sema::Diags
DiagnosticsEngine & Diags
Definition: Sema.h:412
clang::ParmVarDecl::hasUnparsedDefaultArg
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition: Decl.h:1797
clang::Decl::getCanonicalDecl
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:910
clang::EnumDecl::getMemberSpecializationInfo
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition: Decl.h:3882
clang::MacroQualifiedType
Sugar type that represents a type that was qualified by a qualifier written as a macro invocation.
Definition: Type.h:4425
clang::Sema::InstantiatingTemplate::isInvalid
bool isInvalid() const
Determines whether we have exceeded the maximum recursive template instantiations.
Definition: Sema.h:9229
clang::DeclRefExpr::getDecl
ValueDecl * getDecl()
Definition: Expr.h:1295
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:3464
clang::TemplateSpecCandidateSet
TemplateSpecCandidateSet - A set of generalized overload candidates, used in template specializations...
Definition: TemplateDeduction.h:316
clang::FieldDecl::hasInClassInitializer
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition: Decl.h:2995
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:8816
llvm::SmallString< 128 >
clang::TemplateTemplateParmDecl
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
Definition: DeclTemplate.h:1618
clang::Sema::getDefaultedFunctionKind
DefaultedFunctionKind getDefaultedFunctionKind(const FunctionDecl *FD)
Determine the kind of defaulting that would be done for a given function.
Definition: SemaDeclCXX.cpp:6515
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:3504
clang::ParmVarDecl::setUninstantiatedDefaultArg
void setUninstantiatedDefaultArg(Expr *arg)
Definition: Decl.cpp:2900
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:874
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:8868
getPackSubstitutedTemplateArgument
static TemplateArgument getPackSubstitutedTemplateArgument(Sema &S, TemplateArgument Arg)
Definition: SemaTemplateInstantiate.cpp:1221
clang::TagDecl
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3348
clang::TemplateParameterList
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:69
clang::TSK_ExplicitInstantiationDefinition
@ TSK_ExplicitInstantiationDefinition
This template specialization was instantiated from a template due to an explicit instantiation defini...
Definition: Specifiers.h:191
clang::MacroQualifiedType::getUnderlyingType
QualType getUnderlyingType() const
Definition: Type.h:4441
clang::MultiLevelTemplateArgumentList::getNumLevels
unsigned getNumLevels() const
Determine the number of levels in this template argument list.
Definition: Template.h:114
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:804
clang::Type::isVariablyModifiedType
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
Definition: Type.h:2203
clang::CXXRecordDecl::bases
base_class_range bases()
Definition: DeclCXX.h:596
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:2940
clang::DeclContextLookupResult::find_first
T * find_first() const
Definition: DeclBase.h:1330
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::SubstTemplateTemplateParmPackStorage
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:135
clang::CXXDefaultArgExpr
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1241
clang::Sema::InstantiatingTemplate::ConstraintNormalization
Definition: Sema.h:9196
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:4784
clang::concepts::TypeRequirement::isSubstitutionFailure
bool isSubstitutionFailure() const
Definition: ExprConcepts.h:234
clang::BlockPointerType
Pointer to a block type.
Definition: Type.h:2733
clang::Sema::InstantiatingSpecializations
llvm::DenseSet< std::pair< Decl *, unsigned > > InstantiatingSpecializations
Specializations whose definitions are currently being instantiated.
Definition: Sema.h:8985
clang::Sema::getASTMutationListener
ASTMutationListener * getASTMutationListener() const
Definition: Sema.cpp:548
clang::TemplateTypeParmDecl
Declaration of a template type parameter.
Definition: DeclTemplate.h:1196
clang::ParmVarDecl::getFunctionScopeDepth
unsigned getFunctionScopeDepth() const
Definition: Decl.h:1730
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:1984
clang::AdjustedType
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons.
Definition: Type.h:2682
clang::TemplateParameterList::getTemplateLoc
SourceLocation getTemplateLoc() const
Definition: DeclTemplate.h:193
clang::TypeLocBuilder
Definition: TypeLocBuilder.h:22
clang::TemplateName::isNull
bool isNull() const
Determine whether this template name is NULL.
Definition: TemplateName.cpp:82
clang::Decl::isImplicit
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:558
clang::MemberSpecializationInfo::getPointOfInstantiation
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
Definition: DeclTemplate.h:660
clang::ConstraintSatisfaction::IsSatisfied
bool IsSatisfied
Definition: ASTConcept.h:46
clang::TypeLocBuilder::reserve
void reserve(size_t Requested)
Ensures that this buffer has at least as much capacity as described.
Definition: TypeLocBuilder.h:56
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:419
clang::Sema::DefaultedFunctionKind::isSpecialMember
bool isSpecialMember() const
Definition: Sema.h:3237
clang::ETK_None
@ ETK_None
No keyword precedes the qualified type name.
Definition: Type.h:5424
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:8837
clang::ParmVarDecl::setHasInheritedDefaultArg
void setHasInheritedDefaultArg(bool I=true)
Definition: Decl.h:1817
clang::TemplateTypeParmType
Definition: Type.h:4833
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:2968
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:15833
clang::VK_LValue
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:124
clang::ParmVarDecl::getUninstantiatedDefaultArg
Expr * getUninstantiatedDefaultArg()
Definition: Decl.cpp:2905
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:262
clang::TemplateName::getAsQualifiedTemplateName
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
Definition: TemplateName.cpp:163
clang::Sema::CheckLoopHintExpr
bool CheckLoopHintExpr(Expr *E, SourceLocation Loc)
Definition: SemaExpr.cpp:3712
clang::TemplateDeclInstantiator::delayed_var_partial_spec_end
delayed_var_partial_spec_iterator delayed_var_partial_spec_end()
Definition: Template.h:584
clang::TargetInfo::getTriple
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:1160
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:568
clang::Decl::setLocation
void setLocation(SourceLocation L)
Definition: DeclBase.h:426
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:17695
clang::Sema::CodeSynthesisContext::Memoization
@ Memoization
Added for Template instantiation observation.
Definition: Sema.h:8914
clang::EnumDecl::getInstantiatedFromMemberEnum
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition: Decl.cpp:4566
clang::Sema::CodeSynthesisContext::DefaultFunctionArgumentInstantiation
@ DefaultFunctionArgumentInstantiation
We are instantiating a default argument for a function.
Definition: Sema.h:8833
clang::Sema::SetParamDefaultArgument
void SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, SourceLocation EqualLoc)
Definition: SemaDeclCXX.cpp:286
clang::sema::TemplateDeductionInfo::hasSFINAEDiagnostic
bool hasSFINAEDiagnostic() const
Is a SFINAE diagnostic available?
Definition: TemplateDeduction.h:135
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:8574
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:2185
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:8998
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:2193
clang::VK_PRValue
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:120
clang::TemplateSpecializationKind
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:173
clang::Sema::DefaultedFunctionKind
For a defaulted function, the kind of defaulted function that it is.
Definition: Sema.h:3224
clang::TagDecl::startDefinition
void startDefinition()
Starts the definition of this tag declaration.
Definition: Decl.cpp:4382
clang::Decl::getPreviousDecl
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
Definition: DeclBase.h:993
clang::LocalInstantiationScope::getPartiallySubstitutedPack
NamedDecl * getPartiallySubstitutedPack(const TemplateArgument **ExplicitArgs=nullptr, unsigned *NumExplicitArgs=nullptr) const
Retrieve the partially-substitued template parameter pack.
Definition: SemaTemplateInstantiate.cpp:3704
clang::TypeLoc::getFullDataSize
unsigned getFullDataSize() const
Returns the size of the type source info data block.
Definition: TypeLoc.h:163
clang::getAsNamedDecl
NamedDecl * getAsNamedDecl(TemplateParameter P)
Definition: DeclTemplate.h:3362
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:149
clang::StaticAssertDecl
Represents a C++11 static_assert declaration.
Definition: DeclCXX.h:3930
clang::Sema::SubstStmt
StmtResult SubstStmt(Stmt *S, const MultiLevelTemplateArgumentList &TemplateArgs)
Definition: SemaTemplateInstantiate.cpp:3482
clang::PredefinedExpr::getLocation
SourceLocation getLocation() const
Definition: Expr.h:2011
clang::concepts::TypeRequirement
A requires-expression requirement which queries the existence of a type name or type template special...
Definition: ExprConcepts.h:203
clang::Sema::ExtParameterInfoBuilder
A helper class for building up ExtParameterInfos.
Definition: Sema.h:9478
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:8725
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:5523
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:623
clang::ClassTemplateDecl
Declaration of a class template.
Definition: DeclTemplate.h:2264
clang::ValueDecl
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:674
clang::Sema::SubstFunctionDeclType
TypeSourceInfo * SubstFunctionDeclType(TypeSourceInfo *T, const MultiLevelTemplateArgumentList &TemplateArgs, SourceLocation Loc, DeclarationName Entity, CXXRecordDecl *ThisContext, Qualifiers ThisTypeQuals)
A form of SubstType intended specifically for instantiating the type of a FunctionDecl.
Definition: SemaTemplateInstantiate.cpp:2169
clang::TemplateName
Represents a C++ template name within the type system.
Definition: TemplateName.h:192
clang::VarDecl::getStorageClass
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1083
clang::Sema::CodeSynthesisContext::DeclaringSpecialMember
@ DeclaringSpecialMember
We are declaring an implicit special member function.
Definition: Sema.h:8871
clang::SubstNonTypeTemplateParmExpr::getParameter
NonTypeTemplateParmDecl * getParameter() const
Definition: ExprCXX.h:4296
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:5813
clang::FunctionProtoType
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3898
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:247
clang::ASTContext::getPrintingPolicy
const clang::PrintingPolicy & getPrintingPolicy() const
Definition: ASTContext.h:708
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:400
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:1550
clang::BlockPointerType::getPointeeType
QualType getPointeeType() const
Definition: Type.h:2745
clang::VarTemplatePartialSpecializationDecl
Definition: DeclTemplate.h:2942
clang::TemplateDeclInstantiator::InstantiateEnumDefinition
void InstantiateEnumDefinition(EnumDecl *Enum, EnumDecl *Pattern)
Definition: SemaTemplateInstantiateDecl.cpp:1488
clang::VarDecl::getDefinition
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition: Decl.cpp:2271
clang::QualType::isNull
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:740
llvm::ArrayRef
Definition: LLVM.h:34
clang::FunctionParmPackExpr::iterator
VarDecl *const * iterator
Iterators over the parameters which the parameter pack expanded into.
Definition: ExprCXX.h:4433
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:13356
clang::ParmVarDecl::getFunctionScopeIndex
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition: Decl.h:1740
clang::Sema::PerformDependentDiagnostics
void PerformDependentDiagnostics(const DeclContext *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs)
Definition: SemaTemplateInstantiateDecl.cpp:6370
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:3585
clang::DeclGroupRef
Definition: DeclGroup.h:51
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:612
clang::Sema::Consumer
ASTConsumer & Consumer
Definition: Sema.h:411
ASTMutationListener.h
clang::DeclContext::getOuterLexicalRecordContext
RecordDecl * getOuterLexicalRecordContext()
Retrieve the outermost lexically enclosing record context.
Definition: DeclBase.cpp:1819
clang::Sema::popCodeSynthesisContext
void popCodeSynthesisContext()
Definition: SemaTemplateInstantiate.cpp:440
clang::Sema
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:354
clang::DependentSizedExtVectorType::getElementType
QualType getElementType() const
Definition: Type.h:3218
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:1171
clang::Sema::CodeSynthesisContext::ConstraintsCheck
@ ConstraintsCheck
Definition: Sema.h:8885
clang::Sema::SubstInitializer
ExprResult SubstInitializer(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs, bool CXXDirectInit)
Definition: SemaTemplateInstantiate.cpp:3514
clang::ClassTemplateDecl::getTemplatedDecl
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
Definition: DeclTemplate.h:2312
clang::TSK_ExplicitSpecialization
@ TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp....
Definition: Specifiers.h:183
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:786
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:245
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:8853
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:8965
clang::TemplateArgumentList
A template argument list.
Definition: DeclTemplate.h:237
clang::DeclContext::isFileContext
bool isFileContext() const
Definition: DeclBase.h:1946
clang::Sema::ContextRAII
A RAII object to temporarily push a declaration context.
Definition: Sema.h:985
clang::TemplateParameterList::size
unsigned size() const
Definition: DeclTemplate.h:129
clang::Sema::CurrentInstantiationScope
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
Definition: Sema.h:9361
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:84
clang::ASTContext::getTargetInfo
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:768
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:2903
clang::FieldDecl::getInClassInitStyle
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition: Decl.h:2988
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:130
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:2836
clang::Sema::InstantiatingTemplate
A stack object to be created when performing template instantiation.
Definition: Sema.h:9090
clang::TemplateTypeParmDecl::isParameterPack
bool isParameterPack() const
Returns whether this is a parameter pack.
Definition: DeclTemplate.cpp:686
clang::MemberPointerType
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:2844
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::Sema::CodeSynthesisContext::ConstraintNormalization
@ ConstraintNormalization
Definition: Sema.h:8891
clang::SubstNonTypeTemplateParmPackExpr::getParameterPackLocation
SourceLocation getParameterPackLocation() const
Retrieve the location of the parameter pack name.
Definition: ExprCXX.h:4360
clang::TemplateParameterList::getSourceRange
SourceRange getSourceRange() const LLVM_READONLY
Definition: DeclTemplate.h:197
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:1497
clang::Sema::CodeSynthesisContext::DeclaringImplicitEqualityComparison
@ DeclaringImplicitEqualityComparison
We are declaring an implicit 'operator==' for a defaulted 'operator<=>'.
Definition: Sema.h:8875
clang::FunctionProtoType::ExceptionSpecInfo::Type
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:3957
clang::CXXRecordDecl::setTemplateSpecializationKind
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition: DeclCXX.cpp:1829
clang::FunctionProtoType::ExtProtoInfo::ExceptionSpec
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:3987
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:3691
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:513
clang::Sema::CodeSynthesisContext::ExceptionSpecEvaluation
@ ExceptionSpecEvaluation
We are computing the exception specification for a defaulted special member function.
Definition: Sema.h:8857
clang::PredefinedExpr
[C99 6.4.2.2] - A predefined identifier such as func.
Definition: Expr.h:1959
clang::PointerType
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2653
clang::Sema::CodeSynthesisContext::SavedInNonInstantiationSFINAEContext
bool SavedInNonInstantiationSFINAEContext
Was the enclosing context a non-instantiation SFINAE context?
Definition: Sema.h:8918
clang::Sema::InNonInstantiationSFINAEContext
bool InNonInstantiationSFINAEContext
Whether we are in a SFINAE context that is not associated with template instantiation.
Definition: Sema.h:9014
clang::MultiLevelTemplateArgumentList::getNumSubstitutedLevels
unsigned getNumSubstitutedLevels() const
Determine the number of substituted levels in this template argument list.
Definition: Template.h:120
clang::Sema::CodeSynthesisContext::InitializingStructuredBinding
@ InitializingStructuredBinding
We are initializing a structured binding.
Definition: Sema.h:8901
clang::Decl::isParameterPack
bool isParameterPack() const
Whether this declaration is a parameter pack.
Definition: DeclBase.cpp:211
clang::Sema::CheckParameter
ParmVarDecl * CheckParameter(DeclContext *DC, SourceLocation StartLoc, SourceLocation NameLoc, IdentifierInfo *Name, QualType T, TypeSourceInfo *TSInfo, StorageClass SC)
Definition: SemaDecl.cpp:14237
clang::TemplateArgument::Type
@ Type
The template argument is a type.
Definition: TemplateBase.h:70
clang::TemplateTypeParmType::getDepth
unsigned getDepth() const
Definition: Type.h:4874
clang::Sema::usesPartialOrExplicitSpecialization
bool usesPartialOrExplicitSpecialization(SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec)
Definition: SemaTemplateInstantiate.cpp:3041
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:3047
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:1818
clang::CXXDefaultArgExpr::getUsedLocation
SourceLocation getUsedLocation() const
Retrieve the location where this default argument was actually used.
Definition: ExprCXX.h:1287
clang
Definition: CalledOnceCheck.h:17
clang::TemplateArgumentListInfo::setRAngleLoc
void setRAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:583
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:1658
clang::VectorType::getElementType
QualType getElementType() const
Definition: Type.h:3283
clang::TemplateArgument::getPackExpansionPattern
TemplateArgument getPackExpansionPattern() const
When the template argument is a pack expansion, returns the pattern of the pack expansion.
Definition: TemplateBase.cpp:394
clang::FunctionParmPackExpr::getExpansion
VarDecl * getExpansion(unsigned I) const
Get an expansion of the parameter pack by index.
Definition: ExprCXX.h:4441
clang::sema::TemplateDeductionInfo::takeSFINAEDiagnostic
void takeSFINAEDiagnostic(PartialDiagnosticAt &PD)
Take ownership of the SFINAE diagnostic.
Definition: TemplateDeduction.h:102
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:1515
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:69
clang::TemplateArgument::getAsTemplate
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:292
clang::TemplateSpecCandidateSet::addCandidate
TemplateSpecCandidate & addCandidate()
Add a new candidate with NumConversions conversion sequence slots to the overload set.
Definition: TemplateDeduction.h:351
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:501
clang::ParmVarDecl::hasUninstantiatedDefaultArg
bool hasUninstantiatedDefaultArg() const
Definition: Decl.h:1801
clang::Declarator
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1804
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:1276
clang::Attr
Attr - This represents one attribute.
Definition: Attr.h:41
clang::TypeSourceInfo
A container of type source information.
Definition: Type.h:6471
clang::FunctionType::getReturnType
QualType getReturnType() const
Definition: Type.h:3822
clang::TemplateDeclInstantiator::InstantiateVarTemplatePartialSpecialization
VarTemplatePartialSpecializationDecl * InstantiateVarTemplatePartialSpecialization(VarTemplateDecl *VarTemplate, VarTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a variable template partial specialization.
Definition: SemaTemplateInstantiateDecl.cpp:4182
clang::LocalInstantiationScope
A stack-allocated class that identifies which local variable declaration instantiations are present i...
Definition: Template.h:270
clang::NamedDecl::getDeclName
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:311
clang::Sema::SubstNestedNameSpecifierLoc
NestedNameSpecifierLoc SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, const MultiLevelTemplateArgumentList &TemplateArgs)
Definition: SemaTemplateInstantiate.cpp:3537
clang::Sema::ActOnStartCXXInClassMemberInitializer
void ActOnStartCXXInClassMemberInitializer()
Enter a new C++ default initializer scope.
Definition: SemaDeclCXX.cpp:3987
clang::NamedDecl::printName
virtual void printName(raw_ostream &os) const
Pretty-print the unqualified name of this declaration.
Definition: Decl.cpp:1601
unsigned
clang::Sema::CheckFunctionConstraints
bool CheckFunctionConstraints(const FunctionDecl *FD, ConstraintSatisfaction &Satisfaction, SourceLocation UsageLoc=SourceLocation())
Check whether the given function decl's trailing requires clause is satisfied, if any.
Definition: SemaConcept.cpp:356
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:8908
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:849
clang::concepts::ExprRequirement::getNoexceptLoc
SourceLocation getNoexceptLoc() const
Definition: ExprConcepts.h:368
clang::Sema::CodeSynthesisContext::RewritingOperatorAsSpaceship
@ RewritingOperatorAsSpaceship
We are rewriting a comparison operator in terms of an operator<=>.
Definition: Sema.h:8898
clang::LocalInstantiationScope::InstantiatedLocalPackArg
void InstantiatedLocalPackArg(const Decl *D, VarDecl *Inst)
Definition: SemaTemplateInstantiate.cpp:3661
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:2078
clang::TemplateDeclInstantiator::delayed_partial_spec_iterator
SmallVectorImpl< std::pair< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > >::iterator delayed_partial_spec_iterator
Definition: Template.h:559
clang::Sema::ConvertParamDefaultArgument
ExprResult ConvertParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, SourceLocation EqualLoc)
Definition: SemaDeclCXX.cpp:258
clang::Decl::isDefinedOutsideFunctionOrMethod
bool isDefinedOutsideFunctionOrMethod() const
isDefinedOutsideFunctionOrMethod - This predicate returns true if this scoped decl is defined outside...
Definition: DeclBase.h:883
clang::FunctionParmPackExpr::end
iterator end() const
Definition: ExprCXX.h:4435
clang::DeclContextLookupResult
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1301
clang::TypeSpecTypeLoc::setNameLoc
void setNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:527
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:136
clang::QualType::getTypePtr
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6500
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:2499
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:5421
clang::TemplateDeclInstantiator::InstantiateClassTemplatePartialSpecialization
ClassTemplatePartialSpecializationDecl * InstantiateClassTemplatePartialSpecialization(ClassTemplateDecl *ClassTemplate, ClassTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a class template partial specialization.
Definition: SemaTemplateInstantiateDecl.cpp:4055
clang::ReferenceType
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2764
clang::Sema::DefaultedFunctionKind::asComparison
DefaultedComparisonKind asComparison() const
Definition: Sema.h:3247
clang::PointerType::getPointeeType
QualType getPointeeType() const
Definition: Type.h:2663
clang::ConceptReference::getConceptNameInfo
const DeclarationNameInfo & getConceptNameInfo() const
Definition: ASTConcept.h:140
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: Diagnostic.h:625
clang::Decl::setInvalidDecl
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
Definition: DeclBase.cpp:132
clang::TemplateArgument::pack_size
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:371
clang::MultiLevelTemplateArgumentList::isRewrite
bool isRewrite() const
Determine whether we are rewriting template parameters rather than substituting for them.
Definition: Template.h:108
clang::Sema::InstantiateClassTemplateSpecialization
bool InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK, bool Complain=true)
Definition: SemaTemplateInstantiate.cpp:3210
clang::ASTContext::hasSameType
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2524
clang::TemplateDeclInstantiator::getStartingScope
LocalInstantiationScope * getStartingScope() const
Definition: Template.h:556
clang::ASTTemplateArgumentListInfo
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:612
clang::TypeLoc::castAs
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type.
Definition: TypeLoc.h:77
llvm::SmallVectorImpl
Definition: Randstruct.h:18
clang::SubstNonTypeTemplateParmPackExpr::getArgumentPack
TemplateArgument getArgumentPack() const
Retrieve the template argument pack containing the substituted template arguments.
Definition: ExprCXX.cpp:1596
clang::Sema::SubstTypeConstraint
bool SubstTypeConstraint(TemplateTypeParmDecl *Inst, const TypeConstraint *TC, const MultiLevelTemplateArgumentList &TemplateArgs)
Definition: SemaTemplateInstantiate.cpp:2325
clang::NonTypeTemplateParmDecl::getPosition
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
Definition: DeclTemplate.h:1179
clang::ValueDecl::getType
QualType getType() const
Definition: Decl.h:685
clang::MemberSpecializationInfo::getTemplateSpecializationKind
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
Definition: DeclTemplate.h:642
clang::NestedNameSpecifierLoc::getBeginLoc
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
Definition: NestedNameSpecifier.h:299
clang::Sema::getPrintingPolicy
PrintingPolicy getPrintingPolicy() const
Retrieve a suitable printing policy for diagnostics.
Definition: Sema.h:3100
clang::VarTemplateDecl
Declaration of a variable template.
Definition: DeclTemplate.h:3096
clang::ArrayType::getElementType
QualType getElementType() const
Definition: Type.h:2917
clang::RedeclarableTemplateDecl::isMemberSpecialization
bool isMemberSpecialization() const
Determines whether this template was a specialization of a member template.
Definition: DeclTemplate.h:890
clang::ParsedAttributesView
Definition: ParsedAttr.h:898
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::Sema::CodeSynthesisContext::Entity
Decl * Entity
The entity that is being synthesized.
Definition: Sema.h:8924
clang::getDepthAndIndex
std::pair< unsigned, unsigned > getDepthAndIndex(NamedDecl *ND)
Retrieve the depth and index of a template parameter.
Definition: SemaInternal.h:65
clang::TemplateTypeParmType::isParameterPack
bool isParameterPack() const
Definition: Type.h:4876
clang::concepts::ExprRequirement
A requires-expression requirement which queries the validity and properties of an expression ('simple...
Definition: ExprConcepts.h:258
clang::FunctionParmPackExpr::getParameterPackLocation
SourceLocation getParameterPackLocation() const
Get the location of the parameter pack.
Definition: ExprCXX.h:4429
clang::concepts::NestedRequirement::isSubstitutionFailure
bool isSubstitutionFailure() const
Definition: ExprConcepts.h:437
clang::Sema::DefaultedFunctionKind::asSpecialMember
CXXSpecialMember asSpecialMember() const
Definition: Sema.h:3246
clang::Sema::SubstExceptionSpec
void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, const MultiLevelTemplateArgumentList &Args)
Definition: SemaTemplateInstantiate.cpp:2223
clang::TSK_ImplicitInstantiation
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
Definition: Specifiers.h:179
clang::QualType::addConst
void addConst()
Add the const type qualifier to this QualType.
Definition: Type.h:846
clang::FunctionProtoType::getExtProtoInfo
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:4119
clang::DeclarationNameInfo::getLoc
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
Definition: DeclarationName.h:796
clang::Sema::CheckPackExpansion
TypeSourceInfo * CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc, Optional< unsigned > NumExpansions)
Construct a pack expansion type from the pattern of the pack expansion.
Definition: SemaTemplateVariadic.cpp:605
clang::DeclarationNameInfo
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
Definition: DeclarationName.h:767
clang::ClassTemplateSpecializationDecl
Represents a class template specialization, which refers to a class template with a given set of temp...
Definition: DeclTemplate.h:1820
clang::Decl::isInLocalScopeForInstantiation
bool isInLocalScopeForInstantiation() const
Determine whether a substitution into this declaration would occur as part of a substitution into a d...
Definition: DeclBase.cpp:367
clang::Sema::SubstExprs
bool SubstExprs(ArrayRef< Expr * > Exprs, bool IsCall, const MultiLevelTemplateArgumentList &TemplateArgs, SmallVectorImpl< Expr * > &Outputs)
Substitute the given template arguments into a list of expressions, expanding pack expansions if requ...
Definition: SemaTemplateInstantiate.cpp:3523
clang::LocalInstantiationScope::isLocalPackExpansion
bool isLocalPackExpansion(const Decl *D)
Determine whether D is a pack expansion created in this scope.
Definition: SemaTemplateInstantiate.cpp:3684
clang::concepts::ExprRequirement::isExprSubstitutionFailure
bool isExprSubstitutionFailure() const
Definition: ExprConcepts.h:372
clang::DependentSizedExtVectorType
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:3202
clang::AttributedType::getModifiedType
QualType getModifiedType() const
Definition: Type.h:4724
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:425
clang::CXXRecordDecl::getTemplateInstantiationPattern
const CXXRecordDecl * getTemplateInstantiationPattern() const
Retrieve the record declaration from which this record could be instantiated.
Definition: DeclCXX.cpp:1843
clang::Sema::CodeSynthesisContext::Kind
enum clang::Sema::CodeSynthesisContext::SynthesisKind Kind
clang::concepts::ExprRequirement::isSimple
bool isSimple() const
Definition: ExprConcepts.h:364
clang::DeclRefExpr
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1223
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1872
clang::ASTTemplateArgumentListInfo::RAngleLoc
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
Definition: TemplateBase.h:626
clang::RecordDecl
Represents a struct/union/class.
Definition: Decl.h:3901
clang::TemplateParameter
llvm::PointerUnion< TemplateTypeParmDecl *, NonTypeTemplateParmDecl *, TemplateTemplateParmDecl * > TemplateParameter
Stores a template parameter of any kind.
Definition: DeclTemplate.h:63
clang::MemberSpecializationInfo::setPointOfInstantiation
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
Definition: DeclTemplate.h:665
clang::SubstNonTypeTemplateParmExpr::getParameterType
QualType getParameterType(const ASTContext &Ctx) const
Determine the substituted type of the template parameter.
Definition: ExprCXX.cpp:1577
clang::Sema::CodeSynthesisContext::PriorTemplateArgumentSubstitution
@ PriorTemplateArgumentSubstitution
We are substituting prior template arguments into a new template parameter.
Definition: Sema.h:8849
clang::Sema::CodeSynthesisContext::DefiningSynthesizedFunction
@ DefiningSynthesizedFunction
We are defining a synthesized function (such as a defaulted special member).
Definition: Sema.h:8879
SemaConcept.h
clang::TypeConstraint
Definition: ASTConcept.h:167
clang::Sema::CodeSynthesisContext::CodeSynthesisContext
CodeSynthesisContext()
Definition: Sema.h:8967
clang::ActionResult::isUsable
bool isUsable() const
Definition: Ownership.h:166
clang::concepts::Requirement::isDependent
bool isDependent() const
Definition: ExprConcepts.h:191
clang::Sema::CodeSynthesisContext::DeductionInfo
sema::TemplateDeductionInfo * DeductionInfo
The template deduction info object associated with the substitution or checking of explicit or deduce...
Definition: Sema.h:8960
clang::AdjustedType::getOriginalType
QualType getOriginalType() const
Definition: Type.h:2695
clang::LocalInstantiationScope::MakeInstantiatedLocalArgPack
void MakeInstantiatedLocalArgPack(const Decl *D)
Definition: SemaTemplateInstantiate.cpp:3668
clang::DeclaratorDecl::getTypeSourceInfo
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:755
clang::FixItHint::CreateReplacement
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
Definition: Diagnostic.h:134
clang::ParmVarDecl::hasInheritedDefaultArg
bool hasInheritedDefaultArg() const
Definition: Decl.h:1813
clang::Sema::CodeSynthesisContext::MarkingClassDllexported
@ MarkingClassDllexported
We are marking a class as __dllexport.
Definition: Sema.h:8904
clang::Sema::SubstBaseSpecifiers
bool SubstBaseSpecifiers(CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs)
Perform substitution on the base class specifiers of the given class template specialization.
Definition: SemaTemplateInstantiate.cpp:2509
clang::ParenType
Sugar for parentheses used when specifying types.
Definition: Type.h:2627
clang::Sema::getTemplateArgumentBindingsText
std::string getTemplateArgumentBindingsText(const TemplateParameterList *Params, const TemplateArgumentList &Args)
Produces a formatted string that describes the binding of template parameters to template arguments.
Definition: SemaTemplate.cpp:10911
clang::concepts::ExprRequirement::getReturnTypeRequirement
const ReturnTypeRequirement & getReturnTypeRequirement() const
Definition: ExprConcepts.h:376
Stack.h
clang::Sema::InstantiatingTemplate::ExceptionSpecification
Definition: Sema.h:9098
clang::LocalInstantiationScope::findInstantiationOf
llvm::PointerUnion< Decl *, DeclArgumentPack * > * findInstantiationOf(const Decl *D)
Find the instantiation of the declaration D within the current instantiation scope.
Definition: SemaTemplateInstantiate.cpp:3586
clang::Sema::InstantiateClassMembers
void InstantiateClassMembers(SourceLocation PointOfInstantiation, CXXRecordDecl *Instantiation, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateSpecializationKind TSK)
Instantiates the definitions of all of the member of the given class, which is an instantiation of a ...
Definition: SemaTemplateInstantiate.cpp:3235
clang::TemplateArgument::getAsType
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:268
clang::DiagnosticsEngine::Report
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1536
clang::TypeSourceInfo::getTypeLoc
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:244
clang::TemplateArgument::Pack
@ Pack
The template argument is actually a parameter pack.
Definition: TemplateBase.h:100
Initialization.h
clang::Sema::InstantiatingTemplate::Clear
void Clear()
Note that we have finished instantiating this template.
Definition: SemaTemplateInstantiate.cpp:469
clang::CXXMethodDecl
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1968
clang::Sema::SubstParmVarDecl
ParmVarDecl * SubstParmVarDecl(ParmVarDecl *D, const MultiLevelTemplateArgumentList &TemplateArgs, int indexAdjustment, Optional< unsigned > NumExpansions, bool ExpectParameterPack)
Definition: SemaTemplateInstantiate.cpp:2348
clang::Decl::getDeclContext
DeclContext * getDeclContext()
Definition: DeclBase.h:434
clang::Sema::ExpressionEvaluationContext::PotentiallyEvaluated
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
clang::TemplateDeclInstantiator::enableLateAttributeInstantiation
void enableLateAttributeInstantiation(Sema::LateInstantiatedAttrVec *LA)
Definition: Template.h:545
clang::NamedDecl::getName
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:274
clang::LocalInstantiationScope::InstantiatedLocal
void InstantiatedLocal(const Decl *D, Decl *Inst)
Definition: SemaTemplateInstantiate.cpp:3640