clang  10.0.0svn
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 
13 #include "TreeTransform.h"
14 #include "clang/AST/ASTConsumer.h"
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/ASTLambda.h"
18 #include "clang/AST/DeclTemplate.h"
19 #include "clang/AST/Expr.h"
22 #include "clang/Basic/Stack.h"
23 #include "clang/Sema/DeclSpec.h"
25 #include "clang/Sema/Lookup.h"
26 #include "clang/Sema/Template.h"
29 #include "llvm/Support/TimeProfiler.h"
30 
31 using namespace clang;
32 using namespace sema;
33 
34 //===----------------------------------------------------------------------===/
35 // Template Instantiation Support
36 //===----------------------------------------------------------------------===/
37 
38 /// Retrieve the template argument list(s) that should be used to
39 /// instantiate the definition of the given declaration.
40 ///
41 /// \param D the declaration for which we are computing template instantiation
42 /// arguments.
43 ///
44 /// \param Innermost if non-NULL, the innermost template argument list.
45 ///
46 /// \param RelativeToPrimary true if we should get the template
47 /// arguments relative to the primary template, even when we're
48 /// dealing with a specialization. This is only relevant for function
49 /// template specializations.
50 ///
51 /// \param Pattern If non-NULL, indicates the pattern from which we will be
52 /// instantiating the definition of the given declaration, \p D. This is
53 /// used to determine the proper set of template instantiation arguments for
54 /// friend function template specializations.
57  const TemplateArgumentList *Innermost,
58  bool RelativeToPrimary,
59  const FunctionDecl *Pattern) {
60  // Accumulate the set of template argument lists in this structure.
62 
63  if (Innermost)
64  Result.addOuterTemplateArguments(Innermost);
65 
66  DeclContext *Ctx = dyn_cast<DeclContext>(D);
67  if (!Ctx) {
68  Ctx = D->getDeclContext();
69 
70  // Add template arguments from a variable template instantiation. For a
71  // class-scope explicit specialization, there are no template arguments
72  // at this level, but there may be enclosing template arguments.
74  dyn_cast<VarTemplateSpecializationDecl>(D);
75  if (Spec && !Spec->isClassScopeExplicitSpecialization()) {
76  // We're done when we hit an explicit specialization.
78  !isa<VarTemplatePartialSpecializationDecl>(Spec))
79  return Result;
80 
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 (TemplateTemplateParmDecl *TTP
108  = dyn_cast<TemplateTemplateParmDecl>(D)) {
109  for (unsigned I = 0, N = TTP->getDepth() + 1; I != N; ++I)
110  Result.addOuterTemplateArguments(None);
111  return Result;
112  }
113  }
114  }
115 
116  while (!Ctx->isFileContext()) {
117  // Add template arguments from a class template instantiation.
119  = dyn_cast<ClassTemplateSpecializationDecl>(Ctx);
120  if (Spec && !Spec->isClassScopeExplicitSpecialization()) {
121  // We're done when we hit an explicit specialization.
123  !isa<ClassTemplatePartialSpecializationDecl>(Spec))
124  break;
125 
127 
128  // If this class template specialization was instantiated from a
129  // specialized member that is a class template, we're done.
130  assert(Spec->getSpecializedTemplate() && "No class template?");
132  break;
133  }
134  // Add template arguments from a function template specialization.
135  else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Ctx)) {
136  if (!RelativeToPrimary &&
137  Function->getTemplateSpecializationKindForInstantiation() ==
139  break;
140 
141  if (const TemplateArgumentList *TemplateArgs
142  = Function->getTemplateSpecializationArgs()) {
143  // Add the template arguments for this specialization.
144  Result.addOuterTemplateArguments(TemplateArgs);
145 
146  // If this function was instantiated from a specialized member that is
147  // a function template, we're done.
148  assert(Function->getPrimaryTemplate() && "No function template?");
149  if (Function->getPrimaryTemplate()->isMemberSpecialization())
150  break;
151 
152  // If this function is a generic lambda specialization, we are done.
154  break;
155 
156  } else if (FunctionTemplateDecl *FunTmpl
157  = Function->getDescribedFunctionTemplate()) {
158  // Add the "injected" template arguments.
159  Result.addOuterTemplateArguments(FunTmpl->getInjectedTemplateArgs());
160  }
161 
162  // If this is a friend declaration and it declares an entity at
163  // namespace scope, take arguments from its lexical parent
164  // instead of its semantic parent, unless of course the pattern we're
165  // instantiating actually comes from the file's context!
166  if (Function->getFriendObjectKind() &&
167  Function->getDeclContext()->isFileContext() &&
168  (!Pattern || !Pattern->getLexicalDeclContext()->isFileContext())) {
169  Ctx = Function->getLexicalDeclContext();
170  RelativeToPrimary = false;
171  continue;
172  }
173  } else if (CXXRecordDecl *Rec = dyn_cast<CXXRecordDecl>(Ctx)) {
174  if (ClassTemplateDecl *ClassTemplate = Rec->getDescribedClassTemplate()) {
175  QualType T = ClassTemplate->getInjectedClassNameSpecialization();
176  const TemplateSpecializationType *TST =
177  cast<TemplateSpecializationType>(Context.getCanonicalType(T));
179  llvm::makeArrayRef(TST->getArgs(), TST->getNumArgs()));
180  if (ClassTemplate->isMemberSpecialization())
181  break;
182  }
183  }
184 
185  Ctx = Ctx->getParent();
186  RelativeToPrimary = false;
187  }
188 
189  return Result;
190 }
191 
193  switch (Kind) {
194  case TemplateInstantiation:
195  case ExceptionSpecInstantiation:
196  case DefaultTemplateArgumentInstantiation:
197  case DefaultFunctionArgumentInstantiation:
198  case ExplicitTemplateArgumentSubstitution:
199  case DeducedTemplateArgumentSubstitution:
200  case PriorTemplateArgumentSubstitution:
201  return true;
202 
203  case DefaultTemplateArgumentChecking:
204  case DeclaringSpecialMember:
205  case DefiningSynthesizedFunction:
206  case ExceptionSpecEvaluation:
207  return false;
208 
209  // This function should never be called when Kind's value is Memoization.
210  case Memoization:
211  break;
212  }
213 
214  llvm_unreachable("Invalid SynthesisKind!");
215 }
216 
219  SourceLocation PointOfInstantiation, SourceRange InstantiationRange,
220  Decl *Entity, NamedDecl *Template, ArrayRef<TemplateArgument> TemplateArgs,
221  sema::TemplateDeductionInfo *DeductionInfo)
222  : SemaRef(SemaRef) {
223  // Don't allow further instantiation if a fatal error and an uncompilable
224  // error have occurred. Any diagnostics we might have raised will not be
225  // visible, and we do not need to construct a correct AST.
226  if (SemaRef.Diags.hasFatalErrorOccurred() &&
228  Invalid = true;
229  return;
230  }
231  Invalid = CheckInstantiationDepth(PointOfInstantiation, InstantiationRange);
232  if (!Invalid) {
234  Inst.Kind = Kind;
235  Inst.PointOfInstantiation = PointOfInstantiation;
236  Inst.Entity = Entity;
237  Inst.Template = Template;
238  Inst.TemplateArgs = TemplateArgs.data();
239  Inst.NumTemplateArgs = TemplateArgs.size();
240  Inst.DeductionInfo = DeductionInfo;
241  Inst.InstantiationRange = InstantiationRange;
242  SemaRef.pushCodeSynthesisContext(Inst);
243 
244  AlreadyInstantiating =
246  .insert(std::make_pair(Inst.Entity->getCanonicalDecl(), Inst.Kind))
247  .second;
248  atTemplateBegin(SemaRef.TemplateInstCallbacks, SemaRef, Inst);
249  }
250 }
251 
253  Sema &SemaRef, SourceLocation PointOfInstantiation, Decl *Entity,
254  SourceRange InstantiationRange)
255  : InstantiatingTemplate(SemaRef,
256  CodeSynthesisContext::TemplateInstantiation,
257  PointOfInstantiation, InstantiationRange, Entity) {}
258 
260  Sema &SemaRef, SourceLocation PointOfInstantiation, FunctionDecl *Entity,
261  ExceptionSpecification, SourceRange InstantiationRange)
263  SemaRef, CodeSynthesisContext::ExceptionSpecInstantiation,
264  PointOfInstantiation, InstantiationRange, Entity) {}
265 
267  Sema &SemaRef, SourceLocation PointOfInstantiation, TemplateParameter Param,
268  TemplateDecl *Template, ArrayRef<TemplateArgument> TemplateArgs,
269  SourceRange InstantiationRange)
271  SemaRef,
272  CodeSynthesisContext::DefaultTemplateArgumentInstantiation,
273  PointOfInstantiation, InstantiationRange, getAsNamedDecl(Param),
274  Template, TemplateArgs) {}
275 
277  Sema &SemaRef, SourceLocation PointOfInstantiation,
278  FunctionTemplateDecl *FunctionTemplate,
279  ArrayRef<TemplateArgument> TemplateArgs,
281  sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange)
282  : InstantiatingTemplate(SemaRef, Kind, PointOfInstantiation,
283  InstantiationRange, FunctionTemplate, nullptr,
284  TemplateArgs, &DeductionInfo) {
285  assert(
288 }
289 
291  Sema &SemaRef, SourceLocation PointOfInstantiation,
292  TemplateDecl *Template,
293  ArrayRef<TemplateArgument> TemplateArgs,
294  sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange)
296  SemaRef,
297  CodeSynthesisContext::DeducedTemplateArgumentSubstitution,
298  PointOfInstantiation, InstantiationRange, Template, nullptr,
299  TemplateArgs, &DeductionInfo) {}
300 
302  Sema &SemaRef, SourceLocation PointOfInstantiation,
304  ArrayRef<TemplateArgument> TemplateArgs,
305  sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange)
307  SemaRef,
308  CodeSynthesisContext::DeducedTemplateArgumentSubstitution,
309  PointOfInstantiation, InstantiationRange, PartialSpec, nullptr,
310  TemplateArgs, &DeductionInfo) {}
311 
313  Sema &SemaRef, SourceLocation PointOfInstantiation,
315  ArrayRef<TemplateArgument> TemplateArgs,
316  sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange)
318  SemaRef,
319  CodeSynthesisContext::DeducedTemplateArgumentSubstitution,
320  PointOfInstantiation, InstantiationRange, PartialSpec, nullptr,
321  TemplateArgs, &DeductionInfo) {}
322 
324  Sema &SemaRef, SourceLocation PointOfInstantiation, ParmVarDecl *Param,
325  ArrayRef<TemplateArgument> TemplateArgs, SourceRange InstantiationRange)
327  SemaRef,
328  CodeSynthesisContext::DefaultFunctionArgumentInstantiation,
329  PointOfInstantiation, InstantiationRange, Param, nullptr,
330  TemplateArgs) {}
331 
333  Sema &SemaRef, SourceLocation PointOfInstantiation, NamedDecl *Template,
335  SourceRange InstantiationRange)
337  SemaRef,
338  CodeSynthesisContext::PriorTemplateArgumentSubstitution,
339  PointOfInstantiation, InstantiationRange, Param, Template,
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, TemplateDecl *Template,
354  NamedDecl *Param, ArrayRef<TemplateArgument> TemplateArgs,
355  SourceRange InstantiationRange)
357  SemaRef, CodeSynthesisContext::DefaultTemplateArgumentChecking,
358  PointOfInstantiation, InstantiationRange, Param, Template,
359  TemplateArgs) {}
360 
364 
365  CodeSynthesisContexts.push_back(Ctx);
366 
367  if (!Ctx.isInstantiationRecord())
369 
370  // Check to see if we're low on stack space. We can't do anything about this
371  // from here, but we can at least warn the user.
374 }
375 
377  auto &Active = CodeSynthesisContexts.back();
378  if (!Active.isInstantiationRecord()) {
379  assert(NonInstantiationEntries > 0);
381  }
382 
383  InNonInstantiationSFINAEContext = Active.SavedInNonInstantiationSFINAEContext;
384 
385  // Name lookup no longer looks in this template's defining module.
386  assert(CodeSynthesisContexts.size() >=
388  "forgot to remove a lookup module for a template instantiation");
389  if (CodeSynthesisContexts.size() ==
392  LookupModulesCache.erase(M);
394  }
395 
396  // If we've left the code synthesis context for the current context stack,
397  // stop remembering that we've emitted that stack.
398  if (CodeSynthesisContexts.size() ==
401 
402  CodeSynthesisContexts.pop_back();
403 }
404 
406  if (!Invalid) {
407  if (!AlreadyInstantiating) {
408  auto &Active = SemaRef.CodeSynthesisContexts.back();
409  SemaRef.InstantiatingSpecializations.erase(
410  std::make_pair(Active.Entity, Active.Kind));
411  }
412 
413  atTemplateEnd(SemaRef.TemplateInstCallbacks, SemaRef,
414  SemaRef.CodeSynthesisContexts.back());
415 
416  SemaRef.popCodeSynthesisContext();
417  Invalid = true;
418  }
419 }
420 
421 bool Sema::InstantiatingTemplate::CheckInstantiationDepth(
422  SourceLocation PointOfInstantiation,
423  SourceRange InstantiationRange) {
424  assert(SemaRef.NonInstantiationEntries <=
425  SemaRef.CodeSynthesisContexts.size());
426  if ((SemaRef.CodeSynthesisContexts.size() -
427  SemaRef.NonInstantiationEntries)
428  <= SemaRef.getLangOpts().InstantiationDepth)
429  return false;
430 
431  SemaRef.Diag(PointOfInstantiation,
432  diag::err_template_recursion_depth_exceeded)
433  << SemaRef.getLangOpts().InstantiationDepth
434  << InstantiationRange;
435  SemaRef.Diag(PointOfInstantiation, diag::note_template_recursion_depth)
436  << SemaRef.getLangOpts().InstantiationDepth;
437  return true;
438 }
439 
440 /// Prints the current instantiation stack through a series of
441 /// notes.
443  // Determine which template instantiations to skip, if any.
444  unsigned SkipStart = CodeSynthesisContexts.size(), SkipEnd = SkipStart;
445  unsigned Limit = Diags.getTemplateBacktraceLimit();
446  if (Limit && Limit < CodeSynthesisContexts.size()) {
447  SkipStart = Limit / 2 + Limit % 2;
448  SkipEnd = CodeSynthesisContexts.size() - Limit / 2;
449  }
450 
451  // FIXME: In all of these cases, we need to show the template arguments
452  unsigned InstantiationIdx = 0;
454  Active = CodeSynthesisContexts.rbegin(),
455  ActiveEnd = CodeSynthesisContexts.rend();
456  Active != ActiveEnd;
457  ++Active, ++InstantiationIdx) {
458  // Skip this instantiation?
459  if (InstantiationIdx >= SkipStart && InstantiationIdx < SkipEnd) {
460  if (InstantiationIdx == SkipStart) {
461  // Note that we're skipping instantiations.
462  Diags.Report(Active->PointOfInstantiation,
463  diag::note_instantiation_contexts_suppressed)
464  << unsigned(CodeSynthesisContexts.size() - Limit);
465  }
466  continue;
467  }
468 
469  switch (Active->Kind) {
471  Decl *D = Active->Entity;
472  if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) {
473  unsigned DiagID = diag::note_template_member_class_here;
474  if (isa<ClassTemplateSpecializationDecl>(Record))
475  DiagID = diag::note_template_class_instantiation_here;
476  Diags.Report(Active->PointOfInstantiation, DiagID)
477  << Record << Active->InstantiationRange;
478  } else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
479  unsigned DiagID;
480  if (Function->getPrimaryTemplate())
481  DiagID = diag::note_function_template_spec_here;
482  else
483  DiagID = diag::note_template_member_function_here;
484  Diags.Report(Active->PointOfInstantiation, DiagID)
485  << Function
486  << Active->InstantiationRange;
487  } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
488  Diags.Report(Active->PointOfInstantiation,
489  VD->isStaticDataMember()?
490  diag::note_template_static_data_member_def_here
491  : diag::note_template_variable_def_here)
492  << VD
493  << Active->InstantiationRange;
494  } else if (EnumDecl *ED = dyn_cast<EnumDecl>(D)) {
495  Diags.Report(Active->PointOfInstantiation,
496  diag::note_template_enum_def_here)
497  << ED
498  << Active->InstantiationRange;
499  } else if (FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
500  Diags.Report(Active->PointOfInstantiation,
501  diag::note_template_nsdmi_here)
502  << FD << Active->InstantiationRange;
503  } else {
504  Diags.Report(Active->PointOfInstantiation,
505  diag::note_template_type_alias_instantiation_here)
506  << cast<TypeAliasTemplateDecl>(D)
507  << Active->InstantiationRange;
508  }
509  break;
510  }
511 
513  TemplateDecl *Template = cast<TemplateDecl>(Active->Template);
514  SmallVector<char, 128> TemplateArgsStr;
515  llvm::raw_svector_ostream OS(TemplateArgsStr);
516  Template->printName(OS);
517  printTemplateArgumentList(OS, Active->template_arguments(),
519  Diags.Report(Active->PointOfInstantiation,
520  diag::note_default_arg_instantiation_here)
521  << OS.str()
522  << Active->InstantiationRange;
523  break;
524  }
525 
527  FunctionTemplateDecl *FnTmpl = cast<FunctionTemplateDecl>(Active->Entity);
528  Diags.Report(Active->PointOfInstantiation,
529  diag::note_explicit_template_arg_substitution_here)
530  << FnTmpl
532  Active->TemplateArgs,
533  Active->NumTemplateArgs)
534  << Active->InstantiationRange;
535  break;
536  }
537 
539  if (FunctionTemplateDecl *FnTmpl =
540  dyn_cast<FunctionTemplateDecl>(Active->Entity)) {
541  Diags.Report(Active->PointOfInstantiation,
542  diag::note_function_template_deduction_instantiation_here)
543  << FnTmpl
544  << getTemplateArgumentBindingsText(FnTmpl->getTemplateParameters(),
545  Active->TemplateArgs,
546  Active->NumTemplateArgs)
547  << Active->InstantiationRange;
548  } else {
549  bool IsVar = isa<VarTemplateDecl>(Active->Entity) ||
550  isa<VarTemplateSpecializationDecl>(Active->Entity);
551  bool IsTemplate = false;
552  TemplateParameterList *Params;
553  if (auto *D = dyn_cast<TemplateDecl>(Active->Entity)) {
554  IsTemplate = true;
555  Params = D->getTemplateParameters();
556  } else if (auto *D = dyn_cast<ClassTemplatePartialSpecializationDecl>(
557  Active->Entity)) {
558  Params = D->getTemplateParameters();
559  } else if (auto *D = dyn_cast<VarTemplatePartialSpecializationDecl>(
560  Active->Entity)) {
561  Params = D->getTemplateParameters();
562  } else {
563  llvm_unreachable("unexpected template kind");
564  }
565 
566  Diags.Report(Active->PointOfInstantiation,
567  diag::note_deduced_template_arg_substitution_here)
568  << IsVar << IsTemplate << cast<NamedDecl>(Active->Entity)
569  << getTemplateArgumentBindingsText(Params, Active->TemplateArgs,
570  Active->NumTemplateArgs)
571  << Active->InstantiationRange;
572  }
573  break;
574  }
575 
577  ParmVarDecl *Param = cast<ParmVarDecl>(Active->Entity);
578  FunctionDecl *FD = cast<FunctionDecl>(Param->getDeclContext());
579 
580  SmallVector<char, 128> TemplateArgsStr;
581  llvm::raw_svector_ostream OS(TemplateArgsStr);
582  FD->printName(OS);
583  printTemplateArgumentList(OS, Active->template_arguments(),
585  Diags.Report(Active->PointOfInstantiation,
586  diag::note_default_function_arg_instantiation_here)
587  << OS.str()
588  << Active->InstantiationRange;
589  break;
590  }
591 
593  NamedDecl *Parm = cast<NamedDecl>(Active->Entity);
594  std::string Name;
595  if (!Parm->getName().empty())
596  Name = std::string(" '") + Parm->getName().str() + "'";
597 
598  TemplateParameterList *TemplateParams = nullptr;
599  if (TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template))
600  TemplateParams = Template->getTemplateParameters();
601  else
602  TemplateParams =
603  cast<ClassTemplatePartialSpecializationDecl>(Active->Template)
604  ->getTemplateParameters();
605  Diags.Report(Active->PointOfInstantiation,
606  diag::note_prior_template_arg_substitution)
607  << isa<TemplateTemplateParmDecl>(Parm)
608  << Name
609  << getTemplateArgumentBindingsText(TemplateParams,
610  Active->TemplateArgs,
611  Active->NumTemplateArgs)
612  << Active->InstantiationRange;
613  break;
614  }
615 
617  TemplateParameterList *TemplateParams = nullptr;
618  if (TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template))
619  TemplateParams = Template->getTemplateParameters();
620  else
621  TemplateParams =
622  cast<ClassTemplatePartialSpecializationDecl>(Active->Template)
623  ->getTemplateParameters();
624 
625  Diags.Report(Active->PointOfInstantiation,
626  diag::note_template_default_arg_checking)
627  << getTemplateArgumentBindingsText(TemplateParams,
628  Active->TemplateArgs,
629  Active->NumTemplateArgs)
630  << Active->InstantiationRange;
631  break;
632  }
633 
635  Diags.Report(Active->PointOfInstantiation,
636  diag::note_evaluating_exception_spec_here)
637  << cast<FunctionDecl>(Active->Entity);
638  break;
639 
641  Diags.Report(Active->PointOfInstantiation,
642  diag::note_template_exception_spec_instantiation_here)
643  << cast<FunctionDecl>(Active->Entity)
644  << Active->InstantiationRange;
645  break;
646 
648  Diags.Report(Active->PointOfInstantiation,
649  diag::note_in_declaration_of_implicit_special_member)
650  << cast<CXXRecordDecl>(Active->Entity) << Active->SpecialMember;
651  break;
652 
654  // FIXME: For synthesized members other than special members, produce a note.
655  auto *MD = dyn_cast<CXXMethodDecl>(Active->Entity);
656  auto CSM = MD ? getSpecialMember(MD) : CXXInvalid;
657  if (CSM != CXXInvalid) {
658  Diags.Report(Active->PointOfInstantiation,
659  diag::note_member_synthesized_at)
660  << CSM << Context.getTagDeclType(MD->getParent());
661  }
662  break;
663  }
664 
666  break;
667  }
668  }
669 }
670 
673  return Optional<TemplateDeductionInfo *>(nullptr);
674 
676  Active = CodeSynthesisContexts.rbegin(),
677  ActiveEnd = CodeSynthesisContexts.rend();
678  Active != ActiveEnd;
679  ++Active)
680  {
681  switch (Active->Kind) {
683  // An instantiation of an alias template may or may not be a SFINAE
684  // context, depending on what else is on the stack.
685  if (isa<TypeAliasTemplateDecl>(Active->Entity))
686  break;
687  LLVM_FALLTHROUGH;
690  // This is a template instantiation, so there is no SFINAE.
691  return None;
692 
696  // A default template argument instantiation and substitution into
697  // template parameters with arguments for prior parameters may or may
698  // not be a SFINAE context; look further up the stack.
699  break;
700 
703  // We're either substitution explicitly-specified template arguments
704  // or deduced template arguments, so SFINAE applies.
705  assert(Active->DeductionInfo && "Missing deduction info pointer");
706  return Active->DeductionInfo;
707 
710  // This happens in a context unrelated to template instantiation, so
711  // there is no SFINAE.
712  return None;
713 
715  // FIXME: This should not be treated as a SFINAE context, because
716  // we will cache an incorrect exception specification. However, clang
717  // bootstrap relies this! See PR31692.
718  break;
719 
721  break;
722  }
723 
724  // The inner context was transparent for SFINAE. If it occurred within a
725  // non-instantiation SFINAE context, then SFINAE applies.
726  if (Active->SavedInNonInstantiationSFINAEContext)
727  return Optional<TemplateDeductionInfo *>(nullptr);
728  }
729 
730  return None;
731 }
732 
733 //===----------------------------------------------------------------------===/
734 // Template Instantiation for Types
735 //===----------------------------------------------------------------------===/
736 namespace {
737  class TemplateInstantiator : public TreeTransform<TemplateInstantiator> {
738  const MultiLevelTemplateArgumentList &TemplateArgs;
739  SourceLocation Loc;
740  DeclarationName Entity;
741 
742  public:
743  typedef TreeTransform<TemplateInstantiator> inherited;
744 
745  TemplateInstantiator(Sema &SemaRef,
746  const MultiLevelTemplateArgumentList &TemplateArgs,
747  SourceLocation Loc,
748  DeclarationName Entity)
749  : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc),
750  Entity(Entity) { }
751 
752  /// Determine whether the given type \p T has already been
753  /// transformed.
754  ///
755  /// For the purposes of template instantiation, a type has already been
756  /// transformed if it is NULL or if it is not dependent.
757  bool AlreadyTransformed(QualType T);
758 
759  /// Returns the location of the entity being instantiated, if known.
760  SourceLocation getBaseLocation() { return Loc; }
761 
762  /// Returns the name of the entity being instantiated, if any.
763  DeclarationName getBaseEntity() { return Entity; }
764 
765  /// Sets the "base" location and entity when that
766  /// information is known based on another transformation.
767  void setBase(SourceLocation Loc, DeclarationName Entity) {
768  this->Loc = Loc;
769  this->Entity = Entity;
770  }
771 
772  bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
773  SourceRange PatternRange,
775  bool &ShouldExpand, bool &RetainExpansion,
776  Optional<unsigned> &NumExpansions) {
777  return getSema().CheckParameterPacksForExpansion(EllipsisLoc,
778  PatternRange, Unexpanded,
779  TemplateArgs,
780  ShouldExpand,
781  RetainExpansion,
782  NumExpansions);
783  }
784 
785  void ExpandingFunctionParameterPack(ParmVarDecl *Pack) {
787  }
788 
789  TemplateArgument ForgetPartiallySubstitutedPack() {
791  if (NamedDecl *PartialPack
793  MultiLevelTemplateArgumentList &TemplateArgs
794  = const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs);
795  unsigned Depth, Index;
796  std::tie(Depth, Index) = getDepthAndIndex(PartialPack);
797  if (TemplateArgs.hasTemplateArgument(Depth, Index)) {
798  Result = TemplateArgs(Depth, Index);
799  TemplateArgs.setArgument(Depth, Index, TemplateArgument());
800  }
801  }
802 
803  return Result;
804  }
805 
806  void RememberPartiallySubstitutedPack(TemplateArgument Arg) {
807  if (Arg.isNull())
808  return;
809 
810  if (NamedDecl *PartialPack
812  MultiLevelTemplateArgumentList &TemplateArgs
813  = const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs);
814  unsigned Depth, Index;
815  std::tie(Depth, Index) = getDepthAndIndex(PartialPack);
816  TemplateArgs.setArgument(Depth, Index, Arg);
817  }
818  }
819 
820  /// Transform the given declaration by instantiating a reference to
821  /// this declaration.
822  Decl *TransformDecl(SourceLocation Loc, Decl *D);
823 
824  void transformAttrs(Decl *Old, Decl *New) {
825  SemaRef.InstantiateAttrs(TemplateArgs, Old, New);
826  }
827 
828  void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> NewDecls) {
829  if (Old->isParameterPack()) {
831  for (auto *New : NewDecls)
833  Old, cast<VarDecl>(New));
834  return;
835  }
836 
837  assert(NewDecls.size() == 1 &&
838  "should only have multiple expansions for a pack");
839  Decl *New = NewDecls.front();
840 
841  // If we've instantiated the call operator of a lambda or the call
842  // operator template of a generic lambda, update the "instantiation of"
843  // information.
844  auto *NewMD = dyn_cast<CXXMethodDecl>(New);
845  if (NewMD && isLambdaCallOperator(NewMD)) {
846  auto *OldMD = dyn_cast<CXXMethodDecl>(Old);
847  if (auto *NewTD = NewMD->getDescribedFunctionTemplate())
848  NewTD->setInstantiatedFromMemberTemplate(
849  OldMD->getDescribedFunctionTemplate());
850  else
853  }
854 
855  SemaRef.CurrentInstantiationScope->InstantiatedLocal(Old, New);
856 
857  // We recreated a local declaration, but not by instantiating it. There
858  // may be pending dependent diagnostics to produce.
859  if (auto *DC = dyn_cast<DeclContext>(Old))
860  SemaRef.PerformDependentDiagnostics(DC, TemplateArgs);
861  }
862 
863  /// Transform the definition of the given declaration by
864  /// instantiating it.
865  Decl *TransformDefinition(SourceLocation Loc, Decl *D);
866 
867  /// Transform the first qualifier within a scope by instantiating the
868  /// declaration.
869  NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc);
870 
871  /// Rebuild the exception declaration and register the declaration
872  /// as an instantiated local.
873  VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
875  SourceLocation StartLoc,
876  SourceLocation NameLoc,
877  IdentifierInfo *Name);
878 
879  /// Rebuild the Objective-C exception declaration and register the
880  /// declaration as an instantiated local.
881  VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
882  TypeSourceInfo *TSInfo, QualType T);
883 
884  /// Check for tag mismatches when instantiating an
885  /// elaborated type.
886  QualType RebuildElaboratedType(SourceLocation KeywordLoc,
887  ElaboratedTypeKeyword Keyword,
888  NestedNameSpecifierLoc QualifierLoc,
889  QualType T);
890 
892  TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
893  SourceLocation NameLoc,
894  QualType ObjectType = QualType(),
895  NamedDecl *FirstQualifierInScope = nullptr,
896  bool AllowInjectedClassName = false);
897 
898  const LoopHintAttr *TransformLoopHintAttr(const LoopHintAttr *LH);
899 
900  ExprResult TransformPredefinedExpr(PredefinedExpr *E);
901  ExprResult TransformDeclRefExpr(DeclRefExpr *E);
902  ExprResult TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E);
903 
904  ExprResult TransformTemplateParmRefExpr(DeclRefExpr *E,
906  ExprResult TransformSubstNonTypeTemplateParmPackExpr(
908 
909  /// Rebuild a DeclRefExpr for a VarDecl reference.
910  ExprResult RebuildVarDeclRefExpr(VarDecl *PD, SourceLocation Loc);
911 
912  /// Transform a reference to a function or init-capture parameter pack.
913  ExprResult TransformFunctionParmPackRefExpr(DeclRefExpr *E, VarDecl *PD);
914 
915  /// Transform a FunctionParmPackExpr which was built when we couldn't
916  /// expand a function parameter pack reference which refers to an expanded
917  /// pack.
918  ExprResult TransformFunctionParmPackExpr(FunctionParmPackExpr *E);
919 
920  QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
922  // Call the base version; it will forward to our overridden version below.
923  return inherited::TransformFunctionProtoType(TLB, TL);
924  }
925 
926  template<typename Fn>
927  QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
929  CXXRecordDecl *ThisContext,
930  Qualifiers ThisTypeQuals,
931  Fn TransformExceptionSpec);
932 
933  ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
934  int indexAdjustment,
935  Optional<unsigned> NumExpansions,
936  bool ExpectParameterPack);
937 
938  /// Transforms a template type parameter type by performing
939  /// substitution of the corresponding template type argument.
940  QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB,
942 
943  /// Transforms an already-substituted template type parameter pack
944  /// into either itself (if we aren't substituting into its pack expansion)
945  /// or the appropriate substituted argument.
946  QualType TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB,
948 
949  ExprResult TransformLambdaExpr(LambdaExpr *E) {
950  LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true);
952  }
953 
954  TemplateParameterList *TransformTemplateParameterList(
955  TemplateParameterList *OrigTPL) {
956  if (!OrigTPL || !OrigTPL->size()) return OrigTPL;
957 
958  DeclContext *Owner = OrigTPL->getParam(0)->getDeclContext();
959  TemplateDeclInstantiator DeclInstantiator(getSema(),
960  /* DeclContext *Owner */ Owner, TemplateArgs);
961  return DeclInstantiator.SubstTemplateParams(OrigTPL);
962  }
963  private:
964  ExprResult transformNonTypeTemplateParmRef(NonTypeTemplateParmDecl *parm,
965  SourceLocation loc,
966  TemplateArgument arg);
967  };
968 }
969 
970 bool TemplateInstantiator::AlreadyTransformed(QualType T) {
971  if (T.isNull())
972  return true;
973 
975  return false;
976 
977  getSema().MarkDeclarationsReferencedInType(Loc, T);
978  return true;
979 }
980 
981 static TemplateArgument
983  assert(S.ArgumentPackSubstitutionIndex >= 0);
984  assert(S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size());
986  if (Arg.isPackExpansion())
987  Arg = Arg.getPackExpansionPattern();
988  return Arg;
989 }
990 
991 Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) {
992  if (!D)
993  return nullptr;
994 
995  if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
996  if (TTP->getDepth() < TemplateArgs.getNumLevels()) {
997  // If the corresponding template argument is NULL or non-existent, it's
998  // because we are performing instantiation from explicitly-specified
999  // template arguments in a function template, but there were some
1000  // arguments left unspecified.
1001  if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(),
1002  TTP->getPosition()))
1003  return D;
1004 
1005  TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());
1006 
1007  if (TTP->isParameterPack()) {
1008  assert(Arg.getKind() == TemplateArgument::Pack &&
1009  "Missing argument pack");
1010  Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1011  }
1012 
1013  TemplateName Template = Arg.getAsTemplate().getNameToSubstitute();
1014  assert(!Template.isNull() && Template.getAsTemplateDecl() &&
1015  "Wrong kind of template template argument");
1016  return Template.getAsTemplateDecl();
1017  }
1018 
1019  // Fall through to find the instantiated declaration for this template
1020  // template parameter.
1021  }
1022 
1023  return SemaRef.FindInstantiatedDecl(Loc, cast<NamedDecl>(D), TemplateArgs);
1024 }
1025 
1026 Decl *TemplateInstantiator::TransformDefinition(SourceLocation Loc, Decl *D) {
1027  Decl *Inst = getSema().SubstDecl(D, getSema().CurContext, TemplateArgs);
1028  if (!Inst)
1029  return nullptr;
1030 
1031  getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst);
1032  return Inst;
1033 }
1034 
1035 NamedDecl *
1036 TemplateInstantiator::TransformFirstQualifierInScope(NamedDecl *D,
1037  SourceLocation Loc) {
1038  // If the first part of the nested-name-specifier was a template type
1039  // parameter, instantiate that type parameter down to a tag type.
1040  if (TemplateTypeParmDecl *TTPD = dyn_cast_or_null<TemplateTypeParmDecl>(D)) {
1041  const TemplateTypeParmType *TTP
1042  = cast<TemplateTypeParmType>(getSema().Context.getTypeDeclType(TTPD));
1043 
1044  if (TTP->getDepth() < TemplateArgs.getNumLevels()) {
1045  // FIXME: This needs testing w/ member access expressions.
1046  TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getIndex());
1047 
1048  if (TTP->isParameterPack()) {
1049  assert(Arg.getKind() == TemplateArgument::Pack &&
1050  "Missing argument pack");
1051 
1052  if (getSema().ArgumentPackSubstitutionIndex == -1)
1053  return nullptr;
1054 
1055  Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1056  }
1057 
1058  QualType T = Arg.getAsType();
1059  if (T.isNull())
1060  return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
1061 
1062  if (const TagType *Tag = T->getAs<TagType>())
1063  return Tag->getDecl();
1064 
1065  // The resulting type is not a tag; complain.
1066  getSema().Diag(Loc, diag::err_nested_name_spec_non_tag) << T;
1067  return nullptr;
1068  }
1069  }
1070 
1071  return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
1072 }
1073 
1074 VarDecl *
1075 TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl,
1077  SourceLocation StartLoc,
1078  SourceLocation NameLoc,
1079  IdentifierInfo *Name) {
1080  VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, Declarator,
1081  StartLoc, NameLoc, Name);
1082  if (Var)
1083  getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
1084  return Var;
1085 }
1086 
1087 VarDecl *TemplateInstantiator::RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1088  TypeSourceInfo *TSInfo,
1089  QualType T) {
1090  VarDecl *Var = inherited::RebuildObjCExceptionDecl(ExceptionDecl, TSInfo, T);
1091  if (Var)
1092  getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
1093  return Var;
1094 }
1095 
1096 QualType
1097 TemplateInstantiator::RebuildElaboratedType(SourceLocation KeywordLoc,
1098  ElaboratedTypeKeyword Keyword,
1099  NestedNameSpecifierLoc QualifierLoc,
1100  QualType T) {
1101  if (const TagType *TT = T->getAs<TagType>()) {
1102  TagDecl* TD = TT->getDecl();
1103 
1104  SourceLocation TagLocation = KeywordLoc;
1105 
1106  IdentifierInfo *Id = TD->getIdentifier();
1107 
1108  // TODO: should we even warn on struct/class mismatches for this? Seems
1109  // like it's likely to produce a lot of spurious errors.
1110  if (Id && Keyword != ETK_None && Keyword != ETK_Typename) {
1112  if (!SemaRef.isAcceptableTagRedeclaration(TD, Kind, /*isDefinition*/false,
1113  TagLocation, Id)) {
1114  SemaRef.Diag(TagLocation, diag::err_use_with_wrong_tag)
1115  << Id
1116  << FixItHint::CreateReplacement(SourceRange(TagLocation),
1117  TD->getKindName());
1118  SemaRef.Diag(TD->getLocation(), diag::note_previous_use);
1119  }
1120  }
1121  }
1122 
1124  Keyword,
1125  QualifierLoc,
1126  T);
1127 }
1128 
1129 TemplateName TemplateInstantiator::TransformTemplateName(
1130  CXXScopeSpec &SS, TemplateName Name, SourceLocation NameLoc,
1131  QualType ObjectType, NamedDecl *FirstQualifierInScope,
1132  bool AllowInjectedClassName) {
1133  if (TemplateTemplateParmDecl *TTP
1134  = dyn_cast_or_null<TemplateTemplateParmDecl>(Name.getAsTemplateDecl())) {
1135  if (TTP->getDepth() < TemplateArgs.getNumLevels()) {
1136  // If the corresponding template argument is NULL or non-existent, it's
1137  // because we are performing instantiation from explicitly-specified
1138  // template arguments in a function template, but there were some
1139  // arguments left unspecified.
1140  if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(),
1141  TTP->getPosition()))
1142  return Name;
1143 
1144  TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());
1145 
1146  if (TTP->isParameterPack()) {
1147  assert(Arg.getKind() == TemplateArgument::Pack &&
1148  "Missing argument pack");
1149 
1150  if (getSema().ArgumentPackSubstitutionIndex == -1) {
1151  // We have the template argument pack to substitute, but we're not
1152  // actually expanding the enclosing pack expansion yet. So, just
1153  // keep the entire argument pack.
1154  return getSema().Context.getSubstTemplateTemplateParmPack(TTP, Arg);
1155  }
1156 
1157  Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1158  }
1159 
1160  TemplateName Template = Arg.getAsTemplate().getNameToSubstitute();
1161  assert(!Template.isNull() && "Null template template argument");
1162  assert(!Template.getAsQualifiedTemplateName() &&
1163  "template decl to substitute is qualified?");
1164 
1165  Template = getSema().Context.getSubstTemplateTemplateParm(TTP, Template);
1166  return Template;
1167  }
1168  }
1169 
1172  if (getSema().ArgumentPackSubstitutionIndex == -1)
1173  return Name;
1174 
1175  TemplateArgument Arg = SubstPack->getArgumentPack();
1176  Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1177  return Arg.getAsTemplate().getNameToSubstitute();
1178  }
1179 
1180  return inherited::TransformTemplateName(SS, Name, NameLoc, ObjectType,
1181  FirstQualifierInScope,
1182  AllowInjectedClassName);
1183 }
1184 
1185 ExprResult
1186 TemplateInstantiator::TransformPredefinedExpr(PredefinedExpr *E) {
1187  if (!E->isTypeDependent())
1188  return E;
1189 
1190  return getSema().BuildPredefinedExpr(E->getLocation(), E->getIdentKind());
1191 }
1192 
1193 ExprResult
1194 TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E,
1195  NonTypeTemplateParmDecl *NTTP) {
1196  // If the corresponding template argument is NULL or non-existent, it's
1197  // because we are performing instantiation from explicitly-specified
1198  // template arguments in a function template, but there were some
1199  // arguments left unspecified.
1200  if (!TemplateArgs.hasTemplateArgument(NTTP->getDepth(),
1201  NTTP->getPosition()))
1202  return E;
1203 
1204  TemplateArgument Arg = TemplateArgs(NTTP->getDepth(), NTTP->getPosition());
1205 
1206  if (TemplateArgs.getNumLevels() != TemplateArgs.getNumSubstitutedLevels()) {
1207  // We're performing a partial substitution, so the substituted argument
1208  // could be dependent. As a result we can't create a SubstNonType*Expr
1209  // node now, since that represents a fully-substituted argument.
1210  // FIXME: We should have some AST representation for this.
1211  if (Arg.getKind() == TemplateArgument::Pack) {
1212  // FIXME: This won't work for alias templates.
1213  assert(Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() &&
1214  "unexpected pack arguments in partial substitution");
1215  Arg = Arg.pack_begin()->getPackExpansionPattern();
1216  }
1217  assert(Arg.getKind() == TemplateArgument::Expression &&
1218  "unexpected nontype template argument kind in partial substitution");
1219  return Arg.getAsExpr();
1220  }
1221 
1222  if (NTTP->isParameterPack()) {
1223  assert(Arg.getKind() == TemplateArgument::Pack &&
1224  "Missing argument pack");
1225 
1226  if (getSema().ArgumentPackSubstitutionIndex == -1) {
1227  // We have an argument pack, but we can't select a particular argument
1228  // out of it yet. Therefore, we'll build an expression to hold on to that
1229  // argument pack.
1230  QualType TargetType = SemaRef.SubstType(NTTP->getType(), TemplateArgs,
1231  E->getLocation(),
1232  NTTP->getDeclName());
1233  if (TargetType.isNull())
1234  return ExprError();
1235 
1236  return new (SemaRef.Context) SubstNonTypeTemplateParmPackExpr(
1237  TargetType.getNonLValueExprType(SemaRef.Context),
1238  TargetType->isReferenceType() ? VK_LValue : VK_RValue, NTTP,
1239  E->getLocation(), Arg);
1240  }
1241 
1242  Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1243  }
1244 
1245  return transformNonTypeTemplateParmRef(NTTP, E->getLocation(), Arg);
1246 }
1247 
1248 const LoopHintAttr *
1249 TemplateInstantiator::TransformLoopHintAttr(const LoopHintAttr *LH) {
1250  Expr *TransformedExpr = getDerived().TransformExpr(LH->getValue()).get();
1251 
1252  if (TransformedExpr == LH->getValue())
1253  return LH;
1254 
1255  // Generate error if there is a problem with the value.
1256  if (getSema().CheckLoopHintExpr(TransformedExpr, LH->getLocation()))
1257  return LH;
1258 
1259  // Create new LoopHintValueAttr with integral expression in place of the
1260  // non-type template parameter.
1261  return LoopHintAttr::CreateImplicit(getSema().Context, LH->getOption(),
1262  LH->getState(), TransformedExpr, *LH);
1263 }
1264 
1265 ExprResult TemplateInstantiator::transformNonTypeTemplateParmRef(
1267  SourceLocation loc,
1268  TemplateArgument arg) {
1269  ExprResult result;
1270  QualType type;
1271 
1272  // The template argument itself might be an expression, in which
1273  // case we just return that expression.
1274  if (arg.getKind() == TemplateArgument::Expression) {
1275  Expr *argExpr = arg.getAsExpr();
1276  result = argExpr;
1277  type = argExpr->getType();
1278 
1279  } else if (arg.getKind() == TemplateArgument::Declaration ||
1281  ValueDecl *VD;
1282  if (arg.getKind() == TemplateArgument::Declaration) {
1283  VD = arg.getAsDecl();
1284 
1285  // Find the instantiation of the template argument. This is
1286  // required for nested templates.
1287  VD = cast_or_null<ValueDecl>(
1288  getSema().FindInstantiatedDecl(loc, VD, TemplateArgs));
1289  if (!VD)
1290  return ExprError();
1291  } else {
1292  // Propagate NULL template argument.
1293  VD = nullptr;
1294  }
1295 
1296  // Derive the type we want the substituted decl to have. This had
1297  // better be non-dependent, or these checks will have serious problems.
1298  if (parm->isExpandedParameterPack()) {
1299  type = parm->getExpansionType(SemaRef.ArgumentPackSubstitutionIndex);
1300  } else if (parm->isParameterPack() &&
1301  isa<PackExpansionType>(parm->getType())) {
1302  type = SemaRef.SubstType(
1303  cast<PackExpansionType>(parm->getType())->getPattern(),
1304  TemplateArgs, loc, parm->getDeclName());
1305  } else {
1306  type = SemaRef.SubstType(VD ? arg.getParamTypeForDecl() : arg.getNullPtrType(),
1307  TemplateArgs, loc, parm->getDeclName());
1308  }
1309  assert(!type.isNull() && "type substitution failed for param type");
1310  assert(!type->isDependentType() && "param type still dependent");
1311  result = SemaRef.BuildExpressionFromDeclTemplateArgument(arg, type, loc);
1312 
1313  if (!result.isInvalid()) type = result.get()->getType();
1314  } else {
1315  result = SemaRef.BuildExpressionFromIntegralTemplateArgument(arg, loc);
1316 
1317  // Note that this type can be different from the type of 'result',
1318  // e.g. if it's an enum type.
1319  type = arg.getIntegralType();
1320  }
1321  if (result.isInvalid()) return ExprError();
1322 
1323  Expr *resultExpr = result.get();
1324  return new (SemaRef.Context) SubstNonTypeTemplateParmExpr(
1325  type, resultExpr->getValueKind(), loc, parm, resultExpr);
1326 }
1327 
1328 ExprResult
1329 TemplateInstantiator::TransformSubstNonTypeTemplateParmPackExpr(
1331  if (getSema().ArgumentPackSubstitutionIndex == -1) {
1332  // We aren't expanding the parameter pack, so just return ourselves.
1333  return E;
1334  }
1335 
1336  TemplateArgument Arg = E->getArgumentPack();
1337  Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1338  return transformNonTypeTemplateParmRef(E->getParameterPack(),
1340  Arg);
1341 }
1342 
1343 ExprResult TemplateInstantiator::RebuildVarDeclRefExpr(VarDecl *PD,
1344  SourceLocation Loc) {
1345  DeclarationNameInfo NameInfo(PD->getDeclName(), Loc);
1346  return getSema().BuildDeclarationNameExpr(CXXScopeSpec(), NameInfo, PD);
1347 }
1348 
1349 ExprResult
1350 TemplateInstantiator::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
1351  if (getSema().ArgumentPackSubstitutionIndex != -1) {
1352  // We can expand this parameter pack now.
1354  VarDecl *VD = cast_or_null<VarDecl>(TransformDecl(E->getExprLoc(), D));
1355  if (!VD)
1356  return ExprError();
1357  return RebuildVarDeclRefExpr(VD, E->getExprLoc());
1358  }
1359 
1360  QualType T = TransformType(E->getType());
1361  if (T.isNull())
1362  return ExprError();
1363 
1364  // Transform each of the parameter expansions into the corresponding
1365  // parameters in the instantiation of the function decl.
1367  Vars.reserve(E->getNumExpansions());
1368  for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end();
1369  I != End; ++I) {
1370  VarDecl *D = cast_or_null<VarDecl>(TransformDecl(E->getExprLoc(), *I));
1371  if (!D)
1372  return ExprError();
1373  Vars.push_back(D);
1374  }
1375 
1376  auto *PackExpr =
1378  E->getParameterPackLocation(), Vars);
1379  getSema().MarkFunctionParmPackReferenced(PackExpr);
1380  return PackExpr;
1381 }
1382 
1383 ExprResult
1384 TemplateInstantiator::TransformFunctionParmPackRefExpr(DeclRefExpr *E,
1385  VarDecl *PD) {
1386  typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
1387  llvm::PointerUnion<Decl *, DeclArgumentPack *> *Found
1388  = getSema().CurrentInstantiationScope->findInstantiationOf(PD);
1389  assert(Found && "no instantiation for parameter pack");
1390 
1391  Decl *TransformedDecl;
1392  if (DeclArgumentPack *Pack = Found->dyn_cast<DeclArgumentPack *>()) {
1393  // If this is a reference to a function parameter pack which we can
1394  // substitute but can't yet expand, build a FunctionParmPackExpr for it.
1395  if (getSema().ArgumentPackSubstitutionIndex == -1) {
1396  QualType T = TransformType(E->getType());
1397  if (T.isNull())
1398  return ExprError();
1399  auto *PackExpr = FunctionParmPackExpr::Create(getSema().Context, T, PD,
1400  E->getExprLoc(), *Pack);
1401  getSema().MarkFunctionParmPackReferenced(PackExpr);
1402  return PackExpr;
1403  }
1404 
1405  TransformedDecl = (*Pack)[getSema().ArgumentPackSubstitutionIndex];
1406  } else {
1407  TransformedDecl = Found->get<Decl*>();
1408  }
1409 
1410  // We have either an unexpanded pack or a specific expansion.
1411  return RebuildVarDeclRefExpr(cast<VarDecl>(TransformedDecl), E->getExprLoc());
1412 }
1413 
1414 ExprResult
1415 TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) {
1416  NamedDecl *D = E->getDecl();
1417 
1418  // Handle references to non-type template parameters and non-type template
1419  // parameter packs.
1420  if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
1421  if (NTTP->getDepth() < TemplateArgs.getNumLevels())
1422  return TransformTemplateParmRefExpr(E, NTTP);
1423 
1424  // We have a non-type template parameter that isn't fully substituted;
1425  // FindInstantiatedDecl will find it in the local instantiation scope.
1426  }
1427 
1428  // Handle references to function parameter packs.
1429  if (VarDecl *PD = dyn_cast<VarDecl>(D))
1430  if (PD->isParameterPack())
1431  return TransformFunctionParmPackRefExpr(E, PD);
1432 
1434 }
1435 
1436 ExprResult TemplateInstantiator::TransformCXXDefaultArgExpr(
1437  CXXDefaultArgExpr *E) {
1438  assert(!cast<FunctionDecl>(E->getParam()->getDeclContext())->
1439  getDescribedFunctionTemplate() &&
1440  "Default arg expressions are never formed in dependent cases.");
1441  return SemaRef.BuildCXXDefaultArgExpr(E->getUsedLocation(),
1442  cast<FunctionDecl>(E->getParam()->getDeclContext()),
1443  E->getParam());
1444 }
1445 
1446 template<typename Fn>
1447 QualType TemplateInstantiator::TransformFunctionProtoType(TypeLocBuilder &TLB,
1449  CXXRecordDecl *ThisContext,
1450  Qualifiers ThisTypeQuals,
1451  Fn TransformExceptionSpec) {
1452  // We need a local instantiation scope for this function prototype.
1453  LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true);
1454  return inherited::TransformFunctionProtoType(
1455  TLB, TL, ThisContext, ThisTypeQuals, TransformExceptionSpec);
1456 }
1457 
1458 ParmVarDecl *
1459 TemplateInstantiator::TransformFunctionTypeParam(ParmVarDecl *OldParm,
1460  int indexAdjustment,
1461  Optional<unsigned> NumExpansions,
1462  bool ExpectParameterPack) {
1463  return SemaRef.SubstParmVarDecl(OldParm, TemplateArgs, indexAdjustment,
1464  NumExpansions, ExpectParameterPack);
1465 }
1466 
1467 QualType
1468 TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB,
1470  const TemplateTypeParmType *T = TL.getTypePtr();
1471  if (T->getDepth() < TemplateArgs.getNumLevels()) {
1472  // Replace the template type parameter with its corresponding
1473  // template argument.
1474 
1475  // If the corresponding template argument is NULL or doesn't exist, it's
1476  // because we are performing instantiation from explicitly-specified
1477  // template arguments in a function template class, but there were some
1478  // arguments left unspecified.
1479  if (!TemplateArgs.hasTemplateArgument(T->getDepth(), T->getIndex())) {
1481  = TLB.push<TemplateTypeParmTypeLoc>(TL.getType());
1482  NewTL.setNameLoc(TL.getNameLoc());
1483  return TL.getType();
1484  }
1485 
1486  TemplateArgument Arg = TemplateArgs(T->getDepth(), T->getIndex());
1487 
1488  if (T->isParameterPack()) {
1489  assert(Arg.getKind() == TemplateArgument::Pack &&
1490  "Missing argument pack");
1491 
1492  if (getSema().ArgumentPackSubstitutionIndex == -1) {
1493  // We have the template argument pack, but we're not expanding the
1494  // enclosing pack expansion yet. Just save the template argument
1495  // pack for later substitution.
1497  = getSema().Context.getSubstTemplateTypeParmPackType(T, Arg);
1500  NewTL.setNameLoc(TL.getNameLoc());
1501  return Result;
1502  }
1503 
1504  Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1505  }
1506 
1507  assert(Arg.getKind() == TemplateArgument::Type &&
1508  "Template argument kind mismatch");
1509 
1510  QualType Replacement = Arg.getAsType();
1511 
1512  // TODO: only do this uniquing once, at the start of instantiation.
1514  = getSema().Context.getSubstTemplateTypeParmType(T, Replacement);
1517  NewTL.setNameLoc(TL.getNameLoc());
1518  return Result;
1519  }
1520 
1521  // The template type parameter comes from an inner template (e.g.,
1522  // the template parameter list of a member template inside the
1523  // template we are instantiating). Create a new template type
1524  // parameter with the template "level" reduced by one.
1525  TemplateTypeParmDecl *NewTTPDecl = nullptr;
1526  if (TemplateTypeParmDecl *OldTTPDecl = T->getDecl())
1527  NewTTPDecl = cast_or_null<TemplateTypeParmDecl>(
1528  TransformDecl(TL.getNameLoc(), OldTTPDecl));
1529 
1530  QualType Result = getSema().Context.getTemplateTypeParmType(
1531  T->getDepth() - TemplateArgs.getNumSubstitutedLevels(), T->getIndex(),
1532  T->isParameterPack(), NewTTPDecl);
1534  NewTL.setNameLoc(TL.getNameLoc());
1535  return Result;
1536 }
1537 
1538 QualType
1539 TemplateInstantiator::TransformSubstTemplateTypeParmPackType(
1540  TypeLocBuilder &TLB,
1542  if (getSema().ArgumentPackSubstitutionIndex == -1) {
1543  // We aren't expanding the parameter pack, so just return ourselves.
1546  NewTL.setNameLoc(TL.getNameLoc());
1547  return TL.getType();
1548  }
1549 
1551  Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1552  QualType Result = Arg.getAsType();
1553 
1554  Result = getSema().Context.getSubstTemplateTypeParmType(
1556  Result);
1559  NewTL.setNameLoc(TL.getNameLoc());
1560  return Result;
1561 }
1562 
1563 /// Perform substitution on the type T with a given set of template
1564 /// arguments.
1565 ///
1566 /// This routine substitutes the given template arguments into the
1567 /// type T and produces the instantiated type.
1568 ///
1569 /// \param T the type into which the template arguments will be
1570 /// substituted. If this type is not dependent, it will be returned
1571 /// immediately.
1572 ///
1573 /// \param Args the template arguments that will be
1574 /// substituted for the top-level template parameters within T.
1575 ///
1576 /// \param Loc the location in the source code where this substitution
1577 /// is being performed. It will typically be the location of the
1578 /// declarator (if we're instantiating the type of some declaration)
1579 /// or the location of the type in the source code (if, e.g., we're
1580 /// instantiating the type of a cast expression).
1581 ///
1582 /// \param Entity the name of the entity associated with a declaration
1583 /// being instantiated (if any). May be empty to indicate that there
1584 /// is no such entity (if, e.g., this is a type that occurs as part of
1585 /// a cast expression) or that the entity has no name (e.g., an
1586 /// unnamed function parameter).
1587 ///
1588 /// \param AllowDeducedTST Whether a DeducedTemplateSpecializationType is
1589 /// acceptable as the top level type of the result.
1590 ///
1591 /// \returns If the instantiation succeeds, the instantiated
1592 /// type. Otherwise, produces diagnostics and returns a NULL type.
1594  const MultiLevelTemplateArgumentList &Args,
1595  SourceLocation Loc,
1596  DeclarationName Entity,
1597  bool AllowDeducedTST) {
1598  assert(!CodeSynthesisContexts.empty() &&
1599  "Cannot perform an instantiation without some context on the "
1600  "instantiation stack");
1601 
1602  if (!T->getType()->isInstantiationDependentType() &&
1604  return T;
1605 
1606  TemplateInstantiator Instantiator(*this, Args, Loc, Entity);
1607  return AllowDeducedTST ? Instantiator.TransformTypeWithDeducedTST(T)
1608  : Instantiator.TransformType(T);
1609 }
1610 
1612  const MultiLevelTemplateArgumentList &Args,
1613  SourceLocation Loc,
1614  DeclarationName Entity) {
1615  assert(!CodeSynthesisContexts.empty() &&
1616  "Cannot perform an instantiation without some context on the "
1617  "instantiation stack");
1618 
1619  if (TL.getType().isNull())
1620  return nullptr;
1621 
1622  if (!TL.getType()->isInstantiationDependentType() &&
1623  !TL.getType()->isVariablyModifiedType()) {
1624  // FIXME: Make a copy of the TypeLoc data here, so that we can
1625  // return a new TypeSourceInfo. Inefficient!
1626  TypeLocBuilder TLB;
1627  TLB.pushFullCopy(TL);
1628  return TLB.getTypeSourceInfo(Context, TL.getType());
1629  }
1630 
1631  TemplateInstantiator Instantiator(*this, Args, Loc, Entity);
1632  TypeLocBuilder TLB;
1633  TLB.reserve(TL.getFullDataSize());
1634  QualType Result = Instantiator.TransformType(TLB, TL);
1635  if (Result.isNull())
1636  return nullptr;
1637 
1638  return TLB.getTypeSourceInfo(Context, Result);
1639 }
1640 
1641 /// Deprecated form of the above.
1643  const MultiLevelTemplateArgumentList &TemplateArgs,
1644  SourceLocation Loc, DeclarationName Entity) {
1645  assert(!CodeSynthesisContexts.empty() &&
1646  "Cannot perform an instantiation without some context on the "
1647  "instantiation stack");
1648 
1649  // If T is not a dependent type or a variably-modified type, there
1650  // is nothing to do.
1652  return T;
1653 
1654  TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity);
1655  return Instantiator.TransformType(T);
1656 }
1657 
1659  if (T->getType()->isInstantiationDependentType() ||
1661  return true;
1662 
1663  TypeLoc TL = T->getTypeLoc().IgnoreParens();
1664  if (!TL.getAs<FunctionProtoTypeLoc>())
1665  return false;
1666 
1668  for (ParmVarDecl *P : FP.getParams()) {
1669  // This must be synthesized from a typedef.
1670  if (!P) continue;
1671 
1672  // If there are any parameters, a new TypeSourceInfo that refers to the
1673  // instantiated parameters must be built.
1674  return true;
1675  }
1676 
1677  return false;
1678 }
1679 
1680 /// A form of SubstType intended specifically for instantiating the
1681 /// type of a FunctionDecl. Its purpose is solely to force the
1682 /// instantiation of default-argument expressions and to avoid
1683 /// instantiating an exception-specification.
1685  const MultiLevelTemplateArgumentList &Args,
1686  SourceLocation Loc,
1687  DeclarationName Entity,
1688  CXXRecordDecl *ThisContext,
1689  Qualifiers ThisTypeQuals) {
1690  assert(!CodeSynthesisContexts.empty() &&
1691  "Cannot perform an instantiation without some context on the "
1692  "instantiation stack");
1693 
1695  return T;
1696 
1697  TemplateInstantiator Instantiator(*this, Args, Loc, Entity);
1698 
1699  TypeLocBuilder TLB;
1700 
1701  TypeLoc TL = T->getTypeLoc();
1702  TLB.reserve(TL.getFullDataSize());
1703 
1704  QualType Result;
1705 
1706  if (FunctionProtoTypeLoc Proto =
1708  // Instantiate the type, other than its exception specification. The
1709  // exception specification is instantiated in InitFunctionInstantiation
1710  // once we've built the FunctionDecl.
1711  // FIXME: Set the exception specification to EST_Uninstantiated here,
1712  // instead of rebuilding the function type again later.
1713  Result = Instantiator.TransformFunctionProtoType(
1714  TLB, Proto, ThisContext, ThisTypeQuals,
1716  bool &Changed) { return false; });
1717  } else {
1718  Result = Instantiator.TransformType(TLB, TL);
1719  }
1720  if (Result.isNull())
1721  return nullptr;
1722 
1723  return TLB.getTypeSourceInfo(Context, Result);
1724 }
1725 
1728  SmallVectorImpl<QualType> &ExceptionStorage,
1729  const MultiLevelTemplateArgumentList &Args) {
1730  assert(ESI.Type != EST_Uninstantiated);
1731 
1732  bool Changed = false;
1733  TemplateInstantiator Instantiator(*this, Args, Loc, DeclarationName());
1734  return Instantiator.TransformExceptionSpec(Loc, ESI, ExceptionStorage,
1735  Changed);
1736 }
1737 
1739  const MultiLevelTemplateArgumentList &Args) {
1741  Proto->getExtProtoInfo().ExceptionSpec;
1742 
1743  SmallVector<QualType, 4> ExceptionStorage;
1745  ESI, ExceptionStorage, Args))
1746  // On error, recover by dropping the exception specification.
1747  ESI.Type = EST_None;
1748 
1749  UpdateExceptionSpec(New, ESI);
1750 }
1751 
1753  const MultiLevelTemplateArgumentList &TemplateArgs,
1754  int indexAdjustment,
1755  Optional<unsigned> NumExpansions,
1756  bool ExpectParameterPack) {
1757  TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
1758  TypeSourceInfo *NewDI = nullptr;
1759 
1760  TypeLoc OldTL = OldDI->getTypeLoc();
1761  if (PackExpansionTypeLoc ExpansionTL = OldTL.getAs<PackExpansionTypeLoc>()) {
1762 
1763  // We have a function parameter pack. Substitute into the pattern of the
1764  // expansion.
1765  NewDI = SubstType(ExpansionTL.getPatternLoc(), TemplateArgs,
1766  OldParm->getLocation(), OldParm->getDeclName());
1767  if (!NewDI)
1768  return nullptr;
1769 
1770  if (NewDI->getType()->containsUnexpandedParameterPack()) {
1771  // We still have unexpanded parameter packs, which means that
1772  // our function parameter is still a function parameter pack.
1773  // Therefore, make its type a pack expansion type.
1774  NewDI = CheckPackExpansion(NewDI, ExpansionTL.getEllipsisLoc(),
1775  NumExpansions);
1776  } else if (ExpectParameterPack) {
1777  // We expected to get a parameter pack but didn't (because the type
1778  // itself is not a pack expansion type), so complain. This can occur when
1779  // the substitution goes through an alias template that "loses" the
1780  // pack expansion.
1781  Diag(OldParm->getLocation(),
1782  diag::err_function_parameter_pack_without_parameter_packs)
1783  << NewDI->getType();
1784  return nullptr;
1785  }
1786  } else {
1787  NewDI = SubstType(OldDI, TemplateArgs, OldParm->getLocation(),
1788  OldParm->getDeclName());
1789  }
1790 
1791  if (!NewDI)
1792  return nullptr;
1793 
1794  if (NewDI->getType()->isVoidType()) {
1795  Diag(OldParm->getLocation(), diag::err_param_with_void_type);
1796  return nullptr;
1797  }
1798 
1800  OldParm->getInnerLocStart(),
1801  OldParm->getLocation(),
1802  OldParm->getIdentifier(),
1803  NewDI->getType(), NewDI,
1804  OldParm->getStorageClass());
1805  if (!NewParm)
1806  return nullptr;
1807 
1808  // Mark the (new) default argument as uninstantiated (if any).
1809  if (OldParm->hasUninstantiatedDefaultArg()) {
1810  Expr *Arg = OldParm->getUninstantiatedDefaultArg();
1811  NewParm->setUninstantiatedDefaultArg(Arg);
1812  } else if (OldParm->hasUnparsedDefaultArg()) {
1813  NewParm->setUnparsedDefaultArg();
1814  UnparsedDefaultArgInstantiations[OldParm].push_back(NewParm);
1815  } else if (Expr *Arg = OldParm->getDefaultArg()) {
1816  FunctionDecl *OwningFunc = cast<FunctionDecl>(OldParm->getDeclContext());
1817  if (OwningFunc->isLexicallyWithinFunctionOrMethod()) {
1818  // Instantiate default arguments for methods of local classes (DR1484)
1819  // and non-defining declarations.
1820  Sema::ContextRAII SavedContext(*this, OwningFunc);
1821  LocalInstantiationScope Local(*this, true);
1822  ExprResult NewArg = SubstExpr(Arg, TemplateArgs);
1823  if (NewArg.isUsable()) {
1824  // It would be nice if we still had this.
1825  SourceLocation EqualLoc = NewArg.get()->getBeginLoc();
1826  SetParamDefaultArgument(NewParm, NewArg.get(), EqualLoc);
1827  }
1828  } else {
1829  // FIXME: if we non-lazily instantiated non-dependent default args for
1830  // non-dependent parameter types we could remove a bunch of duplicate
1831  // conversion warnings for such arguments.
1832  NewParm->setUninstantiatedDefaultArg(Arg);
1833  }
1834  }
1835 
1837 
1838  if (OldParm->isParameterPack() && !NewParm->isParameterPack()) {
1839  // Add the new parameter to the instantiated parameter pack.
1841  } else {
1842  // Introduce an Old -> New mapping
1843  CurrentInstantiationScope->InstantiatedLocal(OldParm, NewParm);
1844  }
1845 
1846  // FIXME: OldParm may come from a FunctionProtoType, in which case CurContext
1847  // can be anything, is this right ?
1848  NewParm->setDeclContext(CurContext);
1849 
1850  NewParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
1851  OldParm->getFunctionScopeIndex() + indexAdjustment);
1852 
1853  InstantiateAttrs(TemplateArgs, OldParm, NewParm);
1854 
1855  return NewParm;
1856 }
1857 
1858 /// Substitute the given template arguments into the given set of
1859 /// parameters, producing the set of parameter types that would be generated
1860 /// from such a substitution.
1863  const FunctionProtoType::ExtParameterInfo *ExtParamInfos,
1864  const MultiLevelTemplateArgumentList &TemplateArgs,
1865  SmallVectorImpl<QualType> &ParamTypes,
1866  SmallVectorImpl<ParmVarDecl *> *OutParams,
1867  ExtParameterInfoBuilder &ParamInfos) {
1868  assert(!CodeSynthesisContexts.empty() &&
1869  "Cannot perform an instantiation without some context on the "
1870  "instantiation stack");
1871 
1872  TemplateInstantiator Instantiator(*this, TemplateArgs, Loc,
1873  DeclarationName());
1874  return Instantiator.TransformFunctionTypeParams(
1875  Loc, Params, nullptr, ExtParamInfos, ParamTypes, OutParams, ParamInfos);
1876 }
1877 
1878 /// Perform substitution on the base class specifiers of the
1879 /// given class template specialization.
1880 ///
1881 /// Produces a diagnostic and returns true on error, returns false and
1882 /// attaches the instantiated base classes to the class template
1883 /// specialization if successful.
1884 bool
1886  CXXRecordDecl *Pattern,
1887  const MultiLevelTemplateArgumentList &TemplateArgs) {
1888  bool Invalid = false;
1889  SmallVector<CXXBaseSpecifier*, 4> InstantiatedBases;
1890  for (const auto &Base : Pattern->bases()) {
1891  if (!Base.getType()->isDependentType()) {
1892  if (const CXXRecordDecl *RD = Base.getType()->getAsCXXRecordDecl()) {
1893  if (RD->isInvalidDecl())
1894  Instantiation->setInvalidDecl();
1895  }
1896  InstantiatedBases.push_back(new (Context) CXXBaseSpecifier(Base));
1897  continue;
1898  }
1899 
1900  SourceLocation EllipsisLoc;
1901  TypeSourceInfo *BaseTypeLoc;
1902  if (Base.isPackExpansion()) {
1903  // This is a pack expansion. See whether we should expand it now, or
1904  // wait until later.
1906  collectUnexpandedParameterPacks(Base.getTypeSourceInfo()->getTypeLoc(),
1907  Unexpanded);
1908  bool ShouldExpand = false;
1909  bool RetainExpansion = false;
1910  Optional<unsigned> NumExpansions;
1911  if (CheckParameterPacksForExpansion(Base.getEllipsisLoc(),
1912  Base.getSourceRange(),
1913  Unexpanded,
1914  TemplateArgs, ShouldExpand,
1915  RetainExpansion,
1916  NumExpansions)) {
1917  Invalid = true;
1918  continue;
1919  }
1920 
1921  // If we should expand this pack expansion now, do so.
1922  if (ShouldExpand) {
1923  for (unsigned I = 0; I != *NumExpansions; ++I) {
1924  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, I);
1925 
1926  TypeSourceInfo *BaseTypeLoc = SubstType(Base.getTypeSourceInfo(),
1927  TemplateArgs,
1928  Base.getSourceRange().getBegin(),
1929  DeclarationName());
1930  if (!BaseTypeLoc) {
1931  Invalid = true;
1932  continue;
1933  }
1934 
1935  if (CXXBaseSpecifier *InstantiatedBase
1936  = CheckBaseSpecifier(Instantiation,
1937  Base.getSourceRange(),
1938  Base.isVirtual(),
1939  Base.getAccessSpecifierAsWritten(),
1940  BaseTypeLoc,
1941  SourceLocation()))
1942  InstantiatedBases.push_back(InstantiatedBase);
1943  else
1944  Invalid = true;
1945  }
1946 
1947  continue;
1948  }
1949 
1950  // The resulting base specifier will (still) be a pack expansion.
1951  EllipsisLoc = Base.getEllipsisLoc();
1952  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, -1);
1953  BaseTypeLoc = SubstType(Base.getTypeSourceInfo(),
1954  TemplateArgs,
1955  Base.getSourceRange().getBegin(),
1956  DeclarationName());
1957  } else {
1958  BaseTypeLoc = SubstType(Base.getTypeSourceInfo(),
1959  TemplateArgs,
1960  Base.getSourceRange().getBegin(),
1961  DeclarationName());
1962  }
1963 
1964  if (!BaseTypeLoc) {
1965  Invalid = true;
1966  continue;
1967  }
1968 
1969  if (CXXBaseSpecifier *InstantiatedBase
1970  = CheckBaseSpecifier(Instantiation,
1971  Base.getSourceRange(),
1972  Base.isVirtual(),
1973  Base.getAccessSpecifierAsWritten(),
1974  BaseTypeLoc,
1975  EllipsisLoc))
1976  InstantiatedBases.push_back(InstantiatedBase);
1977  else
1978  Invalid = true;
1979  }
1980 
1981  if (!Invalid && AttachBaseSpecifiers(Instantiation, InstantiatedBases))
1982  Invalid = true;
1983 
1984  return Invalid;
1985 }
1986 
1987 // Defined via #include from SemaTemplateInstantiateDecl.cpp
1988 namespace clang {
1989  namespace sema {
1991  const MultiLevelTemplateArgumentList &TemplateArgs);
1993  const Attr *At, ASTContext &C, Sema &S,
1994  const MultiLevelTemplateArgumentList &TemplateArgs);
1995  }
1996 }
1997 
1998 /// Instantiate the definition of a class from a given pattern.
1999 ///
2000 /// \param PointOfInstantiation The point of instantiation within the
2001 /// source code.
2002 ///
2003 /// \param Instantiation is the declaration whose definition is being
2004 /// instantiated. This will be either a class template specialization
2005 /// or a member class of a class template specialization.
2006 ///
2007 /// \param Pattern is the pattern from which the instantiation
2008 /// occurs. This will be either the declaration of a class template or
2009 /// the declaration of a member class of a class template.
2010 ///
2011 /// \param TemplateArgs The template arguments to be substituted into
2012 /// the pattern.
2013 ///
2014 /// \param TSK the kind of implicit or explicit instantiation to perform.
2015 ///
2016 /// \param Complain whether to complain if the class cannot be instantiated due
2017 /// to the lack of a definition.
2018 ///
2019 /// \returns true if an error occurred, false otherwise.
2020 bool
2022  CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern,
2023  const MultiLevelTemplateArgumentList &TemplateArgs,
2025  bool Complain) {
2026  CXXRecordDecl *PatternDef
2027  = cast_or_null<CXXRecordDecl>(Pattern->getDefinition());
2028  if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Instantiation,
2029  Instantiation->getInstantiatedFromMemberClass(),
2030  Pattern, PatternDef, TSK, Complain))
2031  return true;
2032 
2033  llvm::TimeTraceScope TimeScope("InstantiateClass", [&]() {
2034  std::string Name;
2035  llvm::raw_string_ostream OS(Name);
2036  Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
2037  /*Qualified=*/true);
2038  return Name;
2039  });
2040 
2041  Pattern = PatternDef;
2042 
2043  // Record the point of instantiation.
2044  if (MemberSpecializationInfo *MSInfo
2045  = Instantiation->getMemberSpecializationInfo()) {
2046  MSInfo->setTemplateSpecializationKind(TSK);
2047  MSInfo->setPointOfInstantiation(PointOfInstantiation);
2048  } else if (ClassTemplateSpecializationDecl *Spec
2049  = dyn_cast<ClassTemplateSpecializationDecl>(Instantiation)) {
2050  Spec->setTemplateSpecializationKind(TSK);
2051  Spec->setPointOfInstantiation(PointOfInstantiation);
2052  }
2053 
2054  InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation);
2055  if (Inst.isInvalid())
2056  return true;
2057  assert(!Inst.isAlreadyInstantiating() && "should have been caught by caller");
2058  PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(),
2059  "instantiating class definition");
2060 
2061  // Enter the scope of this instantiation. We don't use
2062  // PushDeclContext because we don't have a scope.
2063  ContextRAII SavedContext(*this, Instantiation);
2066 
2067  // If this is an instantiation of a local class, merge this local
2068  // instantiation scope with the enclosing scope. Otherwise, every
2069  // instantiation of a class has its own local instantiation scope.
2070  bool MergeWithParentScope = !Instantiation->isDefinedOutsideFunctionOrMethod();
2071  LocalInstantiationScope Scope(*this, MergeWithParentScope);
2072 
2073  // Some class state isn't processed immediately but delayed till class
2074  // instantiation completes. We may not be ready to handle any delayed state
2075  // already on the stack as it might correspond to a different class, so save
2076  // it now and put it back later.
2077  SavePendingParsedClassStateRAII SavedPendingParsedClassState(*this);
2078 
2079  // Pull attributes from the pattern onto the instantiation.
2080  InstantiateAttrs(TemplateArgs, Pattern, Instantiation);
2081 
2082  // Start the definition of this instantiation.
2083  Instantiation->startDefinition();
2084 
2085  // The instantiation is visible here, even if it was first declared in an
2086  // unimported module.
2087  Instantiation->setVisibleDespiteOwningModule();
2088 
2089  // FIXME: This loses the as-written tag kind for an explicit instantiation.
2090  Instantiation->setTagKind(Pattern->getTagKind());
2091 
2092  // Do substitution on the base class specifiers.
2093  if (SubstBaseSpecifiers(Instantiation, Pattern, TemplateArgs))
2094  Instantiation->setInvalidDecl();
2095 
2096  TemplateDeclInstantiator Instantiator(*this, Instantiation, TemplateArgs);
2097  SmallVector<Decl*, 4> Fields;
2098  // Delay instantiation of late parsed attributes.
2099  LateInstantiatedAttrVec LateAttrs;
2100  Instantiator.enableLateAttributeInstantiation(&LateAttrs);
2101 
2102  bool MightHaveConstexprVirtualFunctions = false;
2103  for (auto *Member : Pattern->decls()) {
2104  // Don't instantiate members not belonging in this semantic context.
2105  // e.g. for:
2106  // @code
2107  // template <int i> class A {
2108  // class B *g;
2109  // };
2110  // @endcode
2111  // 'class B' has the template as lexical context but semantically it is
2112  // introduced in namespace scope.
2113  if (Member->getDeclContext() != Pattern)
2114  continue;
2115 
2116  // BlockDecls can appear in a default-member-initializer. They must be the
2117  // child of a BlockExpr, so we only know how to instantiate them from there.
2118  if (isa<BlockDecl>(Member))
2119  continue;
2120 
2121  if (Member->isInvalidDecl()) {
2122  Instantiation->setInvalidDecl();
2123  continue;
2124  }
2125 
2126  Decl *NewMember = Instantiator.Visit(Member);
2127  if (NewMember) {
2128  if (FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) {
2129  Fields.push_back(Field);
2130  } else if (EnumDecl *Enum = dyn_cast<EnumDecl>(NewMember)) {
2131  // C++11 [temp.inst]p1: The implicit instantiation of a class template
2132  // specialization causes the implicit instantiation of the definitions
2133  // of unscoped member enumerations.
2134  // Record a point of instantiation for this implicit instantiation.
2135  if (TSK == TSK_ImplicitInstantiation && !Enum->isScoped() &&
2136  Enum->isCompleteDefinition()) {
2137  MemberSpecializationInfo *MSInfo =Enum->getMemberSpecializationInfo();
2138  assert(MSInfo && "no spec info for member enum specialization");
2140  MSInfo->setPointOfInstantiation(PointOfInstantiation);
2141  }
2142  } else if (StaticAssertDecl *SA = dyn_cast<StaticAssertDecl>(NewMember)) {
2143  if (SA->isFailed()) {
2144  // A static_assert failed. Bail out; instantiating this
2145  // class is probably not meaningful.
2146  Instantiation->setInvalidDecl();
2147  break;
2148  }
2149  } else if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewMember)) {
2150  if (MD->isConstexpr() && !MD->getFriendObjectKind() &&
2151  (MD->isVirtualAsWritten() || Instantiation->getNumBases()))
2152  MightHaveConstexprVirtualFunctions = true;
2153  }
2154 
2155  if (NewMember->isInvalidDecl())
2156  Instantiation->setInvalidDecl();
2157  } else {
2158  // FIXME: Eventually, a NULL return will mean that one of the
2159  // instantiations was a semantic disaster, and we'll want to mark the
2160  // declaration invalid.
2161  // For now, we expect to skip some members that we can't yet handle.
2162  }
2163  }
2164 
2165  // Finish checking fields.
2166  ActOnFields(nullptr, Instantiation->getLocation(), Instantiation, Fields,
2168  CheckCompletedCXXClass(Instantiation);
2169 
2170  // Default arguments are parsed, if not instantiated. We can go instantiate
2171  // default arg exprs for default constructors if necessary now.
2172  ActOnFinishCXXNonNestedClass(Instantiation);
2173 
2174  // Instantiate late parsed attributes, and attach them to their decls.
2175  // See Sema::InstantiateAttrs
2176  for (LateInstantiatedAttrVec::iterator I = LateAttrs.begin(),
2177  E = LateAttrs.end(); I != E; ++I) {
2178  assert(CurrentInstantiationScope == Instantiator.getStartingScope());
2179  CurrentInstantiationScope = I->Scope;
2180 
2181  // Allow 'this' within late-parsed attributes.
2182  NamedDecl *ND = dyn_cast<NamedDecl>(I->NewDecl);
2183  CXXRecordDecl *ThisContext =
2184  dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext());
2185  CXXThisScopeRAII ThisScope(*this, ThisContext, Qualifiers(),
2186  ND && ND->isCXXInstanceMember());
2187 
2188  Attr *NewAttr =
2189  instantiateTemplateAttribute(I->TmplAttr, Context, *this, TemplateArgs);
2190  I->NewDecl->addAttr(NewAttr);
2192  Instantiator.getStartingScope());
2193  }
2194  Instantiator.disableLateAttributeInstantiation();
2195  LateAttrs.clear();
2196 
2197  ActOnFinishDelayedMemberInitializers(Instantiation);
2198 
2199  // FIXME: We should do something similar for explicit instantiations so they
2200  // end up in the right module.
2201  if (TSK == TSK_ImplicitInstantiation) {
2202  Instantiation->setLocation(Pattern->getLocation());
2203  Instantiation->setLocStart(Pattern->getInnerLocStart());
2204  Instantiation->setBraceRange(Pattern->getBraceRange());
2205  }
2206 
2207  if (!Instantiation->isInvalidDecl()) {
2208  // Perform any dependent diagnostics from the pattern.
2209  PerformDependentDiagnostics(Pattern, TemplateArgs);
2210 
2211  // Instantiate any out-of-line class template partial
2212  // specializations now.
2214  P = Instantiator.delayed_partial_spec_begin(),
2215  PEnd = Instantiator.delayed_partial_spec_end();
2216  P != PEnd; ++P) {
2218  P->first, P->second)) {
2219  Instantiation->setInvalidDecl();
2220  break;
2221  }
2222  }
2223 
2224  // Instantiate any out-of-line variable template partial
2225  // specializations now.
2227  P = Instantiator.delayed_var_partial_spec_begin(),
2228  PEnd = Instantiator.delayed_var_partial_spec_end();
2229  P != PEnd; ++P) {
2231  P->first, P->second)) {
2232  Instantiation->setInvalidDecl();
2233  break;
2234  }
2235  }
2236  }
2237 
2238  // Exit the scope of this instantiation.
2239  SavedContext.pop();
2240 
2241  if (!Instantiation->isInvalidDecl()) {
2242  Consumer.HandleTagDeclDefinition(Instantiation);
2243 
2244  // Always emit the vtable for an explicit instantiation definition
2245  // of a polymorphic class template specialization. Otherwise, eagerly
2246  // instantiate only constexpr virtual functions in preparation for their use
2247  // in constant evaluation.
2249  MarkVTableUsed(PointOfInstantiation, Instantiation, true);
2250  else if (MightHaveConstexprVirtualFunctions)
2251  MarkVirtualMembersReferenced(PointOfInstantiation, Instantiation,
2252  /*ConstexprOnly*/ true);
2253  }
2254 
2255  return Instantiation->isInvalidDecl();
2256 }
2257 
2258 /// Instantiate the definition of an enum from a given pattern.
2259 ///
2260 /// \param PointOfInstantiation The point of instantiation within the
2261 /// source code.
2262 /// \param Instantiation is the declaration whose definition is being
2263 /// instantiated. This will be a member enumeration of a class
2264 /// temploid specialization, or a local enumeration within a
2265 /// function temploid specialization.
2266 /// \param Pattern The templated declaration from which the instantiation
2267 /// occurs.
2268 /// \param TemplateArgs The template arguments to be substituted into
2269 /// the pattern.
2270 /// \param TSK The kind of implicit or explicit instantiation to perform.
2271 ///
2272 /// \return \c true if an error occurred, \c false otherwise.
2273 bool Sema::InstantiateEnum(SourceLocation PointOfInstantiation,
2274  EnumDecl *Instantiation, EnumDecl *Pattern,
2275  const MultiLevelTemplateArgumentList &TemplateArgs,
2277  EnumDecl *PatternDef = Pattern->getDefinition();
2278  if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Instantiation,
2279  Instantiation->getInstantiatedFromMemberEnum(),
2280  Pattern, PatternDef, TSK,/*Complain*/true))
2281  return true;
2282  Pattern = PatternDef;
2283 
2284  // Record the point of instantiation.
2285  if (MemberSpecializationInfo *MSInfo
2286  = Instantiation->getMemberSpecializationInfo()) {
2287  MSInfo->setTemplateSpecializationKind(TSK);
2288  MSInfo->setPointOfInstantiation(PointOfInstantiation);
2289  }
2290 
2291  InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation);
2292  if (Inst.isInvalid())
2293  return true;
2294  if (Inst.isAlreadyInstantiating())
2295  return false;
2296  PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(),
2297  "instantiating enum definition");
2298 
2299  // The instantiation is visible here, even if it was first declared in an
2300  // unimported module.
2301  Instantiation->setVisibleDespiteOwningModule();
2302 
2303  // Enter the scope of this instantiation. We don't use
2304  // PushDeclContext because we don't have a scope.
2305  ContextRAII SavedContext(*this, Instantiation);
2308 
2309  LocalInstantiationScope Scope(*this, /*MergeWithParentScope*/true);
2310 
2311  // Pull attributes from the pattern onto the instantiation.
2312  InstantiateAttrs(TemplateArgs, Pattern, Instantiation);
2313 
2314  TemplateDeclInstantiator Instantiator(*this, Instantiation, TemplateArgs);
2315  Instantiator.InstantiateEnumDefinition(Instantiation, Pattern);
2316 
2317  // Exit the scope of this instantiation.
2318  SavedContext.pop();
2319 
2320  return Instantiation->isInvalidDecl();
2321 }
2322 
2323 
2324 /// Instantiate the definition of a field from the given pattern.
2325 ///
2326 /// \param PointOfInstantiation The point of instantiation within the
2327 /// source code.
2328 /// \param Instantiation is the declaration whose definition is being
2329 /// instantiated. This will be a class of a class temploid
2330 /// specialization, or a local enumeration within a function temploid
2331 /// specialization.
2332 /// \param Pattern The templated declaration from which the instantiation
2333 /// occurs.
2334 /// \param TemplateArgs The template arguments to be substituted into
2335 /// the pattern.
2336 ///
2337 /// \return \c true if an error occurred, \c false otherwise.
2339  SourceLocation PointOfInstantiation, FieldDecl *Instantiation,
2340  FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs) {
2341  // If there is no initializer, we don't need to do anything.
2342  if (!Pattern->hasInClassInitializer())
2343  return false;
2344 
2345  assert(Instantiation->getInClassInitStyle() ==
2346  Pattern->getInClassInitStyle() &&
2347  "pattern and instantiation disagree about init style");
2348 
2349  // Error out if we haven't parsed the initializer of the pattern yet because
2350  // we are waiting for the closing brace of the outer class.
2351  Expr *OldInit = Pattern->getInClassInitializer();
2352  if (!OldInit) {
2353  RecordDecl *PatternRD = Pattern->getParent();
2354  RecordDecl *OutermostClass = PatternRD->getOuterLexicalRecordContext();
2355  Diag(PointOfInstantiation,
2356  diag::err_in_class_initializer_not_yet_parsed)
2357  << OutermostClass << Pattern;
2358  Diag(Pattern->getEndLoc(), diag::note_in_class_initializer_not_yet_parsed);
2359  Instantiation->setInvalidDecl();
2360  return true;
2361  }
2362 
2363  InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation);
2364  if (Inst.isInvalid())
2365  return true;
2366  if (Inst.isAlreadyInstantiating()) {
2367  // Error out if we hit an instantiation cycle for this initializer.
2368  Diag(PointOfInstantiation, diag::err_in_class_initializer_cycle)
2369  << Instantiation;
2370  return true;
2371  }
2372  PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(),
2373  "instantiating default member init");
2374 
2375  // Enter the scope of this instantiation. We don't use PushDeclContext because
2376  // we don't have a scope.
2377  ContextRAII SavedContext(*this, Instantiation->getParent());
2380 
2381  LocalInstantiationScope Scope(*this, true);
2382 
2383  // Instantiate the initializer.
2385  CXXThisScopeRAII ThisScope(*this, Instantiation->getParent(), Qualifiers());
2386 
2387  ExprResult NewInit = SubstInitializer(OldInit, TemplateArgs,
2388  /*CXXDirectInit=*/false);
2389  Expr *Init = NewInit.get();
2390  assert((!Init || !isa<ParenListExpr>(Init)) && "call-style init in class");
2392  Instantiation, Init ? Init->getBeginLoc() : SourceLocation(), Init);
2393 
2394  if (auto *L = getASTMutationListener())
2395  L->DefaultMemberInitializerInstantiated(Instantiation);
2396 
2397  // Return true if the in-class initializer is still missing.
2398  return !Instantiation->getInClassInitializer();
2399 }
2400 
2401 namespace {
2402  /// A partial specialization whose template arguments have matched
2403  /// a given template-id.
2404  struct PartialSpecMatchResult {
2406  TemplateArgumentList *Args;
2407  };
2408 }
2409 
2411  SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec) {
2412  if (ClassTemplateSpec->getTemplateSpecializationKind() ==
2414  return true;
2415 
2417  ClassTemplateSpec->getSpecializedTemplate()
2418  ->getPartialSpecializations(PartialSpecs);
2419  for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) {
2420  TemplateDeductionInfo Info(Loc);
2421  if (!DeduceTemplateArguments(PartialSpecs[I],
2422  ClassTemplateSpec->getTemplateArgs(), Info))
2423  return true;
2424  }
2425 
2426  return false;
2427 }
2428 
2429 /// Get the instantiation pattern to use to instantiate the definition of a
2430 /// given ClassTemplateSpecializationDecl (either the pattern of the primary
2431 /// template or of a partial specialization).
2432 static CXXRecordDecl *
2434  Sema &S, SourceLocation PointOfInstantiation,
2435  ClassTemplateSpecializationDecl *ClassTemplateSpec,
2436  TemplateSpecializationKind TSK, bool Complain) {
2437  Sema::InstantiatingTemplate Inst(S, PointOfInstantiation, ClassTemplateSpec);
2438  if (Inst.isInvalid() || Inst.isAlreadyInstantiating())
2439  return nullptr;
2440 
2441  llvm::PointerUnion<ClassTemplateDecl *,
2443  Specialized = ClassTemplateSpec->getSpecializedTemplateOrPartial();
2444  if (!Specialized.is<ClassTemplatePartialSpecializationDecl *>()) {
2445  // Find best matching specialization.
2446  ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate();
2447 
2448  // C++ [temp.class.spec.match]p1:
2449  // When a class template is used in a context that requires an
2450  // instantiation of the class, it is necessary to determine
2451  // whether the instantiation is to be generated using the primary
2452  // template or one of the partial specializations. This is done by
2453  // matching the template arguments of the class template
2454  // specialization with the template argument lists of the partial
2455  // specializations.
2456  typedef PartialSpecMatchResult MatchResult;
2459  Template->getPartialSpecializations(PartialSpecs);
2460  TemplateSpecCandidateSet FailedCandidates(PointOfInstantiation);
2461  for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) {
2462  ClassTemplatePartialSpecializationDecl *Partial = PartialSpecs[I];
2463  TemplateDeductionInfo Info(FailedCandidates.getLocation());
2465  Partial, ClassTemplateSpec->getTemplateArgs(), Info)) {
2466  // Store the failed-deduction information for use in diagnostics, later.
2467  // TODO: Actually use the failed-deduction info?
2468  FailedCandidates.addCandidate().set(
2469  DeclAccessPair::make(Template, AS_public), Partial,
2471  (void)Result;
2472  } else {
2473  Matched.push_back(PartialSpecMatchResult());
2474  Matched.back().Partial = Partial;
2475  Matched.back().Args = Info.take();
2476  }
2477  }
2478 
2479  // If we're dealing with a member template where the template parameters
2480  // have been instantiated, this provides the original template parameters
2481  // from which the member template's parameters were instantiated.
2482 
2483  if (Matched.size() >= 1) {
2484  SmallVectorImpl<MatchResult>::iterator Best = Matched.begin();
2485  if (Matched.size() == 1) {
2486  // -- If exactly one matching specialization is found, the
2487  // instantiation is generated from that specialization.
2488  // We don't need to do anything for this.
2489  } else {
2490  // -- If more than one matching specialization is found, the
2491  // partial order rules (14.5.4.2) are used to determine
2492  // whether one of the specializations is more specialized
2493  // than the others. If none of the specializations is more
2494  // specialized than all of the other matching
2495  // specializations, then the use of the class template is
2496  // ambiguous and the program is ill-formed.
2497  for (SmallVectorImpl<MatchResult>::iterator P = Best + 1,
2498  PEnd = Matched.end();
2499  P != PEnd; ++P) {
2501  P->Partial, Best->Partial, PointOfInstantiation) ==
2502  P->Partial)
2503  Best = P;
2504  }
2505 
2506  // Determine if the best partial specialization is more specialized than
2507  // the others.
2508  bool Ambiguous = false;
2509  for (SmallVectorImpl<MatchResult>::iterator P = Matched.begin(),
2510  PEnd = Matched.end();
2511  P != PEnd; ++P) {
2512  if (P != Best && S.getMoreSpecializedPartialSpecialization(
2513  P->Partial, Best->Partial,
2514  PointOfInstantiation) != Best->Partial) {
2515  Ambiguous = true;
2516  break;
2517  }
2518  }
2519 
2520  if (Ambiguous) {
2521  // Partial ordering did not produce a clear winner. Complain.
2522  Inst.Clear();
2523  ClassTemplateSpec->setInvalidDecl();
2524  S.Diag(PointOfInstantiation,
2525  diag::err_partial_spec_ordering_ambiguous)
2526  << ClassTemplateSpec;
2527 
2528  // Print the matching partial specializations.
2529  for (SmallVectorImpl<MatchResult>::iterator P = Matched.begin(),
2530  PEnd = Matched.end();
2531  P != PEnd; ++P)
2532  S.Diag(P->Partial->getLocation(), diag::note_partial_spec_match)
2534  P->Partial->getTemplateParameters(), *P->Args);
2535 
2536  return nullptr;
2537  }
2538  }
2539 
2540  ClassTemplateSpec->setInstantiationOf(Best->Partial, Best->Args);
2541  } else {
2542  // -- If no matches are found, the instantiation is generated
2543  // from the primary template.
2544  }
2545  }
2546 
2547  CXXRecordDecl *Pattern = nullptr;
2548  Specialized = ClassTemplateSpec->getSpecializedTemplateOrPartial();
2549  if (auto *PartialSpec =
2550  Specialized.dyn_cast<ClassTemplatePartialSpecializationDecl *>()) {
2551  // Instantiate using the best class template partial specialization.
2552  while (PartialSpec->getInstantiatedFromMember()) {
2553  // If we've found an explicit specialization of this class template,
2554  // stop here and use that as the pattern.
2555  if (PartialSpec->isMemberSpecialization())
2556  break;
2557 
2558  PartialSpec = PartialSpec->getInstantiatedFromMember();
2559  }
2560  Pattern = PartialSpec;
2561  } else {
2562  ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate();
2563  while (Template->getInstantiatedFromMemberTemplate()) {
2564  // If we've found an explicit specialization of this class template,
2565  // stop here and use that as the pattern.
2566  if (Template->isMemberSpecialization())
2567  break;
2568 
2569  Template = Template->getInstantiatedFromMemberTemplate();
2570  }
2571  Pattern = Template->getTemplatedDecl();
2572  }
2573 
2574  return Pattern;
2575 }
2576 
2578  SourceLocation PointOfInstantiation,
2579  ClassTemplateSpecializationDecl *ClassTemplateSpec,
2580  TemplateSpecializationKind TSK, bool Complain) {
2581  // Perform the actual instantiation on the canonical declaration.
2582  ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>(
2583  ClassTemplateSpec->getCanonicalDecl());
2584  if (ClassTemplateSpec->isInvalidDecl())
2585  return true;
2586 
2588  *this, PointOfInstantiation, ClassTemplateSpec, TSK, Complain);
2589  if (!Pattern)
2590  return true;
2591 
2592  return InstantiateClass(PointOfInstantiation, ClassTemplateSpec, Pattern,
2593  getTemplateInstantiationArgs(ClassTemplateSpec), TSK,
2594  Complain);
2595 }
2596 
2597 /// Instantiates the definitions of all of the member
2598 /// of the given class, which is an instantiation of a class template
2599 /// or a member class of a template.
2600 void
2602  CXXRecordDecl *Instantiation,
2603  const MultiLevelTemplateArgumentList &TemplateArgs,
2605  // FIXME: We need to notify the ASTMutationListener that we did all of these
2606  // things, in case we have an explicit instantiation definition in a PCM, a
2607  // module, or preamble, and the declaration is in an imported AST.
2608  assert(
2611  (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) &&
2612  "Unexpected template specialization kind!");
2613  for (auto *D : Instantiation->decls()) {
2614  bool SuppressNew = false;
2615  if (auto *Function = dyn_cast<FunctionDecl>(D)) {
2616  if (FunctionDecl *Pattern =
2617  Function->getInstantiatedFromMemberFunction()) {
2618 
2619  if (Function->hasAttr<ExcludeFromExplicitInstantiationAttr>())
2620  continue;
2621 
2622  MemberSpecializationInfo *MSInfo =
2623  Function->getMemberSpecializationInfo();
2624  assert(MSInfo && "No member specialization information?");
2625  if (MSInfo->getTemplateSpecializationKind()
2627  continue;
2628 
2629  if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK,
2630  Function,
2632  MSInfo->getPointOfInstantiation(),
2633  SuppressNew) ||
2634  SuppressNew)
2635  continue;
2636 
2637  // C++11 [temp.explicit]p8:
2638  // An explicit instantiation definition that names a class template
2639  // specialization explicitly instantiates the class template
2640  // specialization and is only an explicit instantiation definition
2641  // of members whose definition is visible at the point of
2642  // instantiation.
2643  if (TSK == TSK_ExplicitInstantiationDefinition && !Pattern->isDefined())
2644  continue;
2645 
2646  Function->setTemplateSpecializationKind(TSK, PointOfInstantiation);
2647 
2648  if (Function->isDefined()) {
2649  // Let the ASTConsumer know that this function has been explicitly
2650  // instantiated now, and its linkage might have changed.
2652  } else if (TSK == TSK_ExplicitInstantiationDefinition) {
2653  InstantiateFunctionDefinition(PointOfInstantiation, Function);
2654  } else if (TSK == TSK_ImplicitInstantiation) {
2656  std::make_pair(Function, PointOfInstantiation));
2657  }
2658  }
2659  } else if (auto *Var = dyn_cast<VarDecl>(D)) {
2660  if (isa<VarTemplateSpecializationDecl>(Var))
2661  continue;
2662 
2663  if (Var->isStaticDataMember()) {
2664  if (Var->hasAttr<ExcludeFromExplicitInstantiationAttr>())
2665  continue;
2666 
2667  MemberSpecializationInfo *MSInfo = Var->getMemberSpecializationInfo();
2668  assert(MSInfo && "No member specialization information?");
2669  if (MSInfo->getTemplateSpecializationKind()
2671  continue;
2672 
2673  if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK,
2674  Var,
2676  MSInfo->getPointOfInstantiation(),
2677  SuppressNew) ||
2678  SuppressNew)
2679  continue;
2680 
2682  // C++0x [temp.explicit]p8:
2683  // An explicit instantiation definition that names a class template
2684  // specialization explicitly instantiates the class template
2685  // specialization and is only an explicit instantiation definition
2686  // of members whose definition is visible at the point of
2687  // instantiation.
2688  if (!Var->getInstantiatedFromStaticDataMember()->getDefinition())
2689  continue;
2690 
2691  Var->setTemplateSpecializationKind(TSK, PointOfInstantiation);
2692  InstantiateVariableDefinition(PointOfInstantiation, Var);
2693  } else {
2694  Var->setTemplateSpecializationKind(TSK, PointOfInstantiation);
2695  }
2696  }
2697  } else if (auto *Record = dyn_cast<CXXRecordDecl>(D)) {
2698  if (Record->hasAttr<ExcludeFromExplicitInstantiationAttr>())
2699  continue;
2700 
2701  // Always skip the injected-class-name, along with any
2702  // redeclarations of nested classes, since both would cause us
2703  // to try to instantiate the members of a class twice.
2704  // Skip closure types; they'll get instantiated when we instantiate
2705  // the corresponding lambda-expression.
2706  if (Record->isInjectedClassName() || Record->getPreviousDecl() ||
2707  Record->isLambda())
2708  continue;
2709 
2710  MemberSpecializationInfo *MSInfo = Record->getMemberSpecializationInfo();
2711  assert(MSInfo && "No member specialization information?");
2712 
2713  if (MSInfo->getTemplateSpecializationKind()
2715  continue;
2716 
2717  if (Context.getTargetInfo().getTriple().isOSWindows() &&
2719  // On Windows, explicit instantiation decl of the outer class doesn't
2720  // affect the inner class. Typically extern template declarations are
2721  // used in combination with dll import/export annotations, but those
2722  // are not propagated from the outer class templates to inner classes.
2723  // Therefore, do not instantiate inner classes on this platform, so
2724  // that users don't end up with undefined symbols during linking.
2725  continue;
2726  }
2727 
2728  if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK,
2729  Record,
2731  MSInfo->getPointOfInstantiation(),
2732  SuppressNew) ||
2733  SuppressNew)
2734  continue;
2735 
2736  CXXRecordDecl *Pattern = Record->getInstantiatedFromMemberClass();
2737  assert(Pattern && "Missing instantiated-from-template information");
2738 
2739  if (!Record->getDefinition()) {
2740  if (!Pattern->getDefinition()) {
2741  // C++0x [temp.explicit]p8:
2742  // An explicit instantiation definition that names a class template
2743  // specialization explicitly instantiates the class template
2744  // specialization and is only an explicit instantiation definition
2745  // of members whose definition is visible at the point of
2746  // instantiation.
2748  MSInfo->setTemplateSpecializationKind(TSK);
2749  MSInfo->setPointOfInstantiation(PointOfInstantiation);
2750  }
2751 
2752  continue;
2753  }
2754 
2755  InstantiateClass(PointOfInstantiation, Record, Pattern,
2756  TemplateArgs,
2757  TSK);
2758  } else {
2760  Record->getTemplateSpecializationKind() ==
2762  Record->setTemplateSpecializationKind(TSK);
2763  MarkVTableUsed(PointOfInstantiation, Record, true);
2764  }
2765  }
2766 
2767  Pattern = cast_or_null<CXXRecordDecl>(Record->getDefinition());
2768  if (Pattern)
2769  InstantiateClassMembers(PointOfInstantiation, Pattern, TemplateArgs,
2770  TSK);
2771  } else if (auto *Enum = dyn_cast<EnumDecl>(D)) {
2772  MemberSpecializationInfo *MSInfo = Enum->getMemberSpecializationInfo();
2773  assert(MSInfo && "No member specialization information?");
2774 
2775  if (MSInfo->getTemplateSpecializationKind()
2777  continue;
2778 
2780  PointOfInstantiation, TSK, Enum,
2782  MSInfo->getPointOfInstantiation(), SuppressNew) ||
2783  SuppressNew)
2784  continue;
2785 
2786  if (Enum->getDefinition())
2787  continue;
2788 
2789  EnumDecl *Pattern = Enum->getTemplateInstantiationPattern();
2790  assert(Pattern && "Missing instantiated-from-template information");
2791 
2793  if (!Pattern->getDefinition())
2794  continue;
2795 
2796  InstantiateEnum(PointOfInstantiation, Enum, Pattern, TemplateArgs, TSK);
2797  } else {
2798  MSInfo->setTemplateSpecializationKind(TSK);
2799  MSInfo->setPointOfInstantiation(PointOfInstantiation);
2800  }
2801  } else if (auto *Field = dyn_cast<FieldDecl>(D)) {
2802  // No need to instantiate in-class initializers during explicit
2803  // instantiation.
2804  if (Field->hasInClassInitializer() && TSK == TSK_ImplicitInstantiation) {
2805  CXXRecordDecl *ClassPattern =
2806  Instantiation->getTemplateInstantiationPattern();
2808  ClassPattern->lookup(Field->getDeclName());
2809  FieldDecl *Pattern = cast<FieldDecl>(Lookup.front());
2810  InstantiateInClassInitializer(PointOfInstantiation, Field, Pattern,
2811  TemplateArgs);
2812  }
2813  }
2814  }
2815 }
2816 
2817 /// Instantiate the definitions of all of the members of the
2818 /// given class template specialization, which was named as part of an
2819 /// explicit instantiation.
2820 void
2822  SourceLocation PointOfInstantiation,
2823  ClassTemplateSpecializationDecl *ClassTemplateSpec,
2825  // C++0x [temp.explicit]p7:
2826  // An explicit instantiation that names a class template
2827  // specialization is an explicit instantion of the same kind
2828  // (declaration or definition) of each of its members (not
2829  // including members inherited from base classes) that has not
2830  // been previously explicitly specialized in the translation unit
2831  // containing the explicit instantiation, except as described
2832  // below.
2833  InstantiateClassMembers(PointOfInstantiation, ClassTemplateSpec,
2834  getTemplateInstantiationArgs(ClassTemplateSpec),
2835  TSK);
2836 }
2837 
2838 StmtResult
2840  if (!S)
2841  return S;
2842 
2843  TemplateInstantiator Instantiator(*this, TemplateArgs,
2844  SourceLocation(),
2845  DeclarationName());
2846  return Instantiator.TransformStmt(S);
2847 }
2848 
2849 ExprResult
2851  if (!E)
2852  return E;
2853 
2854  TemplateInstantiator Instantiator(*this, TemplateArgs,
2855  SourceLocation(),
2856  DeclarationName());
2857  return Instantiator.TransformExpr(E);
2858 }
2859 
2861  const MultiLevelTemplateArgumentList &TemplateArgs,
2862  bool CXXDirectInit) {
2863  TemplateInstantiator Instantiator(*this, TemplateArgs,
2864  SourceLocation(),
2865  DeclarationName());
2866  return Instantiator.TransformInitializer(Init, CXXDirectInit);
2867 }
2868 
2869 bool Sema::SubstExprs(ArrayRef<Expr *> Exprs, bool IsCall,
2870  const MultiLevelTemplateArgumentList &TemplateArgs,
2871  SmallVectorImpl<Expr *> &Outputs) {
2872  if (Exprs.empty())
2873  return false;
2874 
2875  TemplateInstantiator Instantiator(*this, TemplateArgs,
2876  SourceLocation(),
2877  DeclarationName());
2878  return Instantiator.TransformExprs(Exprs.data(), Exprs.size(),
2879  IsCall, Outputs);
2880 }
2881 
2884  const MultiLevelTemplateArgumentList &TemplateArgs) {
2885  if (!NNS)
2886  return NestedNameSpecifierLoc();
2887 
2888  TemplateInstantiator Instantiator(*this, TemplateArgs, NNS.getBeginLoc(),
2889  DeclarationName());
2890  return Instantiator.TransformNestedNameSpecifierLoc(NNS);
2891 }
2892 
2893 /// Do template substitution on declaration name info.
2896  const MultiLevelTemplateArgumentList &TemplateArgs) {
2897  TemplateInstantiator Instantiator(*this, TemplateArgs, NameInfo.getLoc(),
2898  NameInfo.getName());
2899  return Instantiator.TransformDeclarationNameInfo(NameInfo);
2900 }
2901 
2904  TemplateName Name, SourceLocation Loc,
2905  const MultiLevelTemplateArgumentList &TemplateArgs) {
2906  TemplateInstantiator Instantiator(*this, TemplateArgs, Loc,
2907  DeclarationName());
2908  CXXScopeSpec SS;
2909  SS.Adopt(QualifierLoc);
2910  return Instantiator.TransformTemplateName(SS, Name, Loc);
2911 }
2912 
2913 bool Sema::Subst(const TemplateArgumentLoc *Args, unsigned NumArgs,
2915  const MultiLevelTemplateArgumentList &TemplateArgs) {
2916  TemplateInstantiator Instantiator(*this, TemplateArgs, SourceLocation(),
2917  DeclarationName());
2918 
2919  return Instantiator.TransformTemplateArguments(Args, NumArgs, Result);
2920 }
2921 
2922 static const Decl *getCanonicalParmVarDecl(const Decl *D) {
2923  // When storing ParmVarDecls in the local instantiation scope, we always
2924  // want to use the ParmVarDecl from the canonical function declaration,
2925  // since the map is then valid for any redeclaration or definition of that
2926  // function.
2927  if (const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(D)) {
2928  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) {
2929  unsigned i = PV->getFunctionScopeIndex();
2930  // This parameter might be from a freestanding function type within the
2931  // function and isn't necessarily referring to one of FD's parameters.
2932  if (i < FD->getNumParams() && FD->getParamDecl(i) == PV)
2933  return FD->getCanonicalDecl()->getParamDecl(i);
2934  }
2935  }
2936  return D;
2937 }
2938 
2939 
2940 llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *
2942  D = getCanonicalParmVarDecl(D);
2943  for (LocalInstantiationScope *Current = this; Current;
2944  Current = Current->Outer) {
2945 
2946  // Check if we found something within this scope.
2947  const Decl *CheckD = D;
2948  do {
2949  LocalDeclsMap::iterator Found = Current->LocalDecls.find(CheckD);
2950  if (Found != Current->LocalDecls.end())
2951  return &Found->second;
2952 
2953  // If this is a tag declaration, it's possible that we need to look for
2954  // a previous declaration.
2955  if (const TagDecl *Tag = dyn_cast<TagDecl>(CheckD))
2956  CheckD = Tag->getPreviousDecl();
2957  else
2958  CheckD = nullptr;
2959  } while (CheckD);
2960 
2961  // If we aren't combined with our outer scope, we're done.
2962  if (!Current->CombineWithOuterScope)
2963  break;
2964  }
2965 
2966  // If we're performing a partial substitution during template argument
2967  // deduction, we may not have values for template parameters yet.
2968  if (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D) ||
2969  isa<TemplateTemplateParmDecl>(D))
2970  return nullptr;
2971 
2972  // Local types referenced prior to definition may require instantiation.
2973  if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D))
2974  if (RD->isLocalClass())
2975  return nullptr;
2976 
2977  // Enumeration types referenced prior to definition may appear as a result of
2978  // error recovery.
2979  if (isa<EnumDecl>(D))
2980  return nullptr;
2981 
2982  // If we didn't find the decl, then we either have a sema bug, or we have a
2983  // forward reference to a label declaration. Return null to indicate that
2984  // we have an uninstantiated label.
2985  assert(isa<LabelDecl>(D) && "declaration not instantiated in this scope");
2986  return nullptr;
2987 }
2988 
2990  D = getCanonicalParmVarDecl(D);
2991  llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
2992  if (Stored.isNull()) {
2993 #ifndef NDEBUG
2994  // It should not be present in any surrounding scope either.
2995  LocalInstantiationScope *Current = this;
2996  while (Current->CombineWithOuterScope && Current->Outer) {
2997  Current = Current->Outer;
2998  assert(Current->LocalDecls.find(D) == Current->LocalDecls.end() &&
2999  "Instantiated local in inner and outer scopes");
3000  }
3001 #endif
3002  Stored = Inst;
3003  } else if (DeclArgumentPack *Pack = Stored.dyn_cast<DeclArgumentPack *>()) {
3004  Pack->push_back(cast<VarDecl>(Inst));
3005  } else {
3006  assert(Stored.get<Decl *>() == Inst && "Already instantiated this local");
3007  }
3008 }
3009 
3011  VarDecl *Inst) {
3012  D = getCanonicalParmVarDecl(D);
3013  DeclArgumentPack *Pack = LocalDecls[D].get<DeclArgumentPack *>();
3014  Pack->push_back(Inst);
3015 }
3016 
3018 #ifndef NDEBUG
3019  // This should be the first time we've been told about this decl.
3020  for (LocalInstantiationScope *Current = this;
3021  Current && Current->CombineWithOuterScope; Current = Current->Outer)
3022  assert(Current->LocalDecls.find(D) == Current->LocalDecls.end() &&
3023  "Creating local pack after instantiation of local");
3024 #endif
3025 
3026  D = getCanonicalParmVarDecl(D);
3027  llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
3028  DeclArgumentPack *Pack = new DeclArgumentPack;
3029  Stored = Pack;
3030  ArgumentPacks.push_back(Pack);
3031 }
3032 
3034  const TemplateArgument *ExplicitArgs,
3035  unsigned NumExplicitArgs) {
3036  assert((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) &&
3037  "Already have a partially-substituted pack");
3038  assert((!PartiallySubstitutedPack
3039  || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) &&
3040  "Wrong number of arguments in partially-substituted pack");
3041  PartiallySubstitutedPack = Pack;
3042  ArgsInPartiallySubstitutedPack = ExplicitArgs;
3043  NumArgsInPartiallySubstitutedPack = NumExplicitArgs;
3044 }
3045 
3047  const TemplateArgument **ExplicitArgs,
3048  unsigned *NumExplicitArgs) const {
3049  if (ExplicitArgs)
3050  *ExplicitArgs = nullptr;
3051  if (NumExplicitArgs)
3052  *NumExplicitArgs = 0;
3053 
3054  for (const LocalInstantiationScope *Current = this; Current;
3055  Current = Current->Outer) {
3056  if (Current->PartiallySubstitutedPack) {
3057  if (ExplicitArgs)
3058  *ExplicitArgs = Current->ArgsInPartiallySubstitutedPack;
3059  if (NumExplicitArgs)
3060  *NumExplicitArgs = Current->NumArgsInPartiallySubstitutedPack;
3061 
3062  return Current->PartiallySubstitutedPack;
3063  }
3064 
3065  if (!Current->CombineWithOuterScope)
3066  break;
3067  }
3068 
3069  return nullptr;
3070 }
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
ExprResult BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, SourceLocation Loc)
Construct a new expression that refers to the given integral template argument with the given source-...
Defines the clang::ASTContext interface.
unsigned getTemplateBacktraceLimit() const
Retrieve the maximum number of template instantiation notes to emit along with a given diagnostic...
Definition: Diagnostic.h:569
void ActOnFinishDelayedMemberInitializers(Decl *Record)
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition: Decl.h:1605
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 ...
We are defining a synthesized function (such as a defaulted special member).
Definition: Sema.h:7564
Represents a function declaration or definition.
Definition: Decl.h:1756
delayed_var_partial_spec_iterator delayed_var_partial_spec_begin()
Definition: Template.h:515
no exception specification
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:498
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
SourceLocation getUsedLocation() const
Retrieve the location where this default argument was actually used.
Definition: ExprCXX.h:1157
A (possibly-)qualified type.
Definition: Type.h:643
ASTConsumer & Consumer
Definition: Sema.h:375
TemplateDeductionResult
Describes the result of template argument deduction.
Definition: Sema.h:7285
void InstantiatedLocal(const Decl *D, Decl *Inst)
base_class_range bases()
Definition: DeclCXX.h:779
void UpdateExceptionSpec(FunctionDecl *FD, const FunctionProtoType::ExceptionSpecInfo &ESI)
unsigned getNumBases() const
Retrieves the number of base classes of this class.
Definition: DeclCXX.h:773
llvm::PointerUnion3< TemplateTypeParmDecl *, NonTypeTemplateParmDecl *, TemplateTemplateParmDecl * > TemplateParameter
Stores a template parameter of any kind.
Definition: DeclTemplate.h:61
A stack-allocated class that identifies which local variable declaration instantiations are present i...
Definition: Template.h:227
std::vector< std::unique_ptr< TemplateInstantiationCallback > > TemplateInstCallbacks
The template instantiation callbacks to trace or track instantiations (objects can be chained)...
Definition: Sema.h:7687
VarDecl * getParameterPack() const
Get the parameter pack which this expression refers to.
Definition: ExprCXX.h:4272
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition: Decl.h:2748
void addOuterTemplateArguments(const TemplateArgumentList *TemplateArgs)
Add a new outermost level to the multi-level template argument list.
Definition: Template.h:133
Decl * Entity
The entity that is being synthesized.
Definition: Sema.h:7580
Stmt - This represents one statement.
Definition: Stmt.h:66
bool isGenericLambdaCallOperatorSpecialization(const CXXMethodDecl *MD)
Definition: ASTLambda.h:38
ExprResult SubstInitializer(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs, bool CXXDirectInit)
Provides information about an attempted template argument deduction, whose success or failure was des...
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:991
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1019
ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, ParmVarDecl *Param)
BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating the default expr if needed...
Definition: SemaExpr.cpp:4896
The template argument is an expression, and we&#39;ve not resolved it to one of the other forms yet...
Definition: TemplateBase.h:86
std::string getTemplateArgumentBindingsText(const TemplateParameterList *Params, const TemplateArgumentList &Args)
Produces a formatted string that describes the binding of template parameters to template arguments...
bool isInstantiationRecord() const
Determines whether this template is an actual instantiation that should be counted toward the maximum...
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition: Sema.h:1380
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:88
llvm::PointerUnion< Decl *, DeclArgumentPack * > * findInstantiationOf(const Decl *D)
Find the instantiation of the declaration D within the current instantiation scope.
Defines the C++ template declaration subclasses.
StringRef P
SmallVector< CodeSynthesisContext, 16 > CodeSynthesisContexts
List of active code synthesis contexts.
Definition: Sema.h:7630
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration, or NULL if there is no previous declaration.
Definition: DeclBase.h:960
SmallVector< Module *, 16 > CodeSynthesisContextLookupModules
Extra modules inspected when performing a lookup during a template instantiation. ...
Definition: Sema.h:7641
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined...
Definition: Decl.h:2804
bool InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK, bool Complain=true)
std::deque< PendingImplicitInstantiation > PendingLocalImplicitInstantiations
The queue of implicit template instantiations that are required and must be performed within the curr...
Definition: Sema.h:8044
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1290
Declaration of a variable template.
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Definition: TemplateBase.h:63
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:132
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:703
A container of type source information.
Definition: Decl.h:86
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...
IdentKind getIdentKind() const
Definition: Expr.h:1921
bool isStackNearlyExhausted()
Determine whether the stack is nearly exhausted.
Definition: Stack.cpp:46
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...
We are instantiating a default argument for a template parameter.
Definition: Sema.h:7524
VarTemplatePartialSpecializationDecl * InstantiateVarTemplatePartialSpecialization(VarTemplateDecl *VarTemplate, VarTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a variable template partial specialization.
TemplateTypeParmDecl * getDecl() const
Definition: Type.h:4643
void SetPartiallySubstitutedPack(NamedDecl *Pack, const TemplateArgument *ExplicitArgs, unsigned NumExplicitArgs)
Note that the given parameter pack has been partially substituted via explicit specification of templ...
TemplateName SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, SourceLocation Loc, const MultiLevelTemplateArgumentList &TemplateArgs)
unsigned NonInstantiationEntries
The number of CodeSynthesisContexts that are not template instantiations and, therefore, should not be counted as part of the instantiation depth.
Definition: Sema.h:7671
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition: Decl.h:2755
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.
SourceLocation getEndLoc() const
Get the end source location.
Definition: TypeLoc.cpp:226
LocalInstantiationScope * getStartingScope() const
Definition: Template.h:499
void ActOnFinishCXXNonNestedClass(Decl *D)
This file provides some common utility functions for processing Lambda related AST Constructs...
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition: DeclSpec.cpp:124
unsigned getDepth() const
Get the nesting depth of the template parameter.
RAII object that enters a new expression evaluation context.
Definition: Sema.h:11360
Represents a variable declaration or definition.
Definition: Decl.h:812
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1775
MatchFinder::MatchResult MatchResult
DiagnosticsEngine & Diags
Definition: Sema.h:376
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6857
PrintingPolicy getPrintingPolicy() const
Retrieve a suitable printing policy for diagnostics.
Definition: Sema.h:2369
bool hasInheritedDefaultArg() const
Definition: Decl.h:1698
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:2028
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
Represents a variable template specialization, which refers to a variable template with a given set o...
RAII object used to temporarily allow the C++ &#39;this&#39; expression to be used, with the given qualifiers...
Definition: Sema.h:5386
reference front() const
Definition: DeclBase.h:1242
bool isInvalidDecl() const
Definition: DeclBase.h:553
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:67
A context in which code is being synthesized (where a source location alone is not sufficient to iden...
Definition: Sema.h:7512
bool isParameterPack() const
Whether this declaration is a parameter pack.
Definition: DeclBase.cpp:211
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
Definition: DeclTemplate.h:686
Represents a parameter to a function.
Definition: Decl.h:1572
QualType getIntegralType() const
Retrieve the type of the integral value.
Definition: TemplateBase.h:314
iterator begin() const
Definition: ExprCXX.h:4280
const TemplateArgument * TemplateArgs
The list of template arguments we are substituting, if they are not part of the entity.
Definition: Sema.h:7589
The collection of all-type qualifiers we support.
Definition: Type.h:137
const FunctionDecl * isLocalClass() const
If the class is a local class [class.local], returns the enclosing function declaration.
Definition: DeclCXX.h:1614
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition: DeclCXX.cpp:1676
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:269
bool isLexicallyWithinFunctionOrMethod() const
Returns true if this declaration lexically is inside a function.
Definition: DeclBase.cpp:335
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:56
Represents a struct/union/class.
Definition: Decl.h:3634
A semantic tree transformation that allows one to transform one abstract syntax tree into another...
Definition: TreeTransform.h:95
enum clang::Sema::CodeSynthesisContext::SynthesisKind Kind
llvm::PointerUnion< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > getSpecializedTemplateOrPartial() const
Retrieve the variable template or variable template partial specialization which was specialized by t...
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:297
void PrintInstantiationStack()
Prints the current instantiation stack through a series of notes.
One of these records is kept for each identifier that is lexed.
Represents a class template specialization, which refers to a class template with a given set of temp...
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
Definition: Sema.h:7960
TemplateArgument getPackExpansionPattern() const
When the template argument is a pack expansion, returns the pattern of the pack expansion.
TemplateName getNameToSubstitute() const
Get the template name to substitute when this template name is used as a template template argument...
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:329
void setUninstantiatedDefaultArg(Expr *arg)
Definition: Decl.cpp:2707
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:160
A C++ nested-name-specifier augmented with source location information.
NestedNameSpecifierLoc SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, const MultiLevelTemplateArgumentList &TemplateArgs)
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1195
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
NamedDecl * getPartiallySubstitutedPack(const TemplateArgument **ExplicitArgs=nullptr, unsigned *NumExplicitArgs=nullptr) const
Retrieve the partially-substitued template parameter pack.
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:274
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:14453
Represents a member of a struct/union/class.
Definition: Decl.h:2615
The current expression is potentially evaluated at run time, which means that code may be generated t...
void setArgument(unsigned Depth, unsigned Index, TemplateArgument Arg)
Clear out a specific template argument.
Definition: Template.h:122
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition: Decl.h:1625
void setVisibleDespiteOwningModule()
Set that this declaration is globally visible, even if it came from a module that is not visible...
Definition: DeclBase.h:780
NamedDecl * Template
The template (or partial specialization) in which we are performing the instantiation, for substitutions of prior template arguments.
Definition: Sema.h:7585
void startDefinition()
Starts the definition of this tag declaration.
Definition: Decl.cpp:4046
bool usesPartialOrExplicitSpecialization(SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec)
bool isReferenceType() const
Definition: Type.h:6402
bool isDefinedOutsideFunctionOrMethod() const
isDefinedOutsideFunctionOrMethod - This predicate returns true if this scoped decl is defined outside...
Definition: DeclBase.h:855
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
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...
DeclarationNameInfo SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, const MultiLevelTemplateArgumentList &TemplateArgs)
Do template substitution on declaration name info.
void set(DeclAccessPair Found, Decl *Spec, DeductionFailureInfo Info)
Represents a reference to a non-type template parameter pack that has been substituted with a non-tem...
Definition: ExprCXX.h:4175
delayed_var_partial_spec_iterator delayed_var_partial_spec_end()
Definition: Template.h:527
QualType getParamTypeForDecl() const
Definition: TemplateBase.h:268
Describes a module or submodule.
Definition: Module.h:64
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:125
We are instantiating the exception specification for a function template which was deferred until it ...
Definition: Sema.h:7557
unsigned getNumExpansions() const
Get the number of parameters in this parameter pack.
Definition: ExprCXX.h:4284
void setNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:523
PtrTy get() const
Definition: Ownership.h:170
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
TemplateArgument getArgumentPack() const
Retrieve the template argument pack containing the substituted template arguments.
Definition: ExprCXX.cpp:1547
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:4204
TemplateSpecCandidateSet - A set of generalized overload candidates, used in template specializations...
SourceLocation getParameterPackLocation() const
Retrieve the location of the parameter pack name.
Definition: ExprCXX.h:4206
A convenient class for passing around template argument information.
Definition: TemplateBase.h:554
static TemplateArgument getPackSubstitutedTemplateArgument(Sema &S, TemplateArgument Arg)
StmtResult SubstStmt(Stmt *S, const MultiLevelTemplateArgumentList &TemplateArgs)
bool isMemberSpecialization() const
Determines whether this template was a specialization of a member template.
Definition: DeclTemplate.h:936
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
Definition: TemplateBase.h:274
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:414
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:840
llvm::DenseSet< Module * > LookupModulesCache
Cache of additional modules that should be used for name lookup within the current template instantia...
Definition: Sema.h:7646
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:1862
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:833
unsigned LastEmittedCodeSynthesisContextDepth
The depth of the context stack at the point when the most recent error or warning was produced...
Definition: Sema.h:7679
SourceLocation PointOfInstantiation
The point of instantiation or synthesis within the source code.
Definition: Sema.h:7577
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization...
Definition: Decl.h:3615
void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs)
Note that this class template specialization is actually an instantiation of the given class template...
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
bool SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, SourceLocation EqualLoc)
InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, Decl *Entity, SourceRange InstantiationRange=SourceRange())
Note that we are instantiating a class template, function template, variable template, alias template, or a member thereof.
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:684
const TemplateArgument * getArgs() const
Retrieve the template arguments.
Definition: Type.h:4983
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition: Decl.h:1682
CXXBaseSpecifier * CheckBaseSpecifier(CXXRecordDecl *Class, SourceRange SpecifierRange, bool Virtual, AccessSpecifier Access, TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
ActOnBaseSpecifier - Parsed a base specifier.
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:63
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
Definition: DeclBase.h:828
QualType getExpansionType(unsigned I) const
Retrieve a particular expansion type within an expanded parameter pack.
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1727
const LangOptions & getLangOpts() const
Definition: Sema.h:1293
bool isTypeDependent() const
isTypeDependent - Determines whether this expression is type-dependent (C++ [temp.dep.expr]), which means that its type could change from one template instantiation to the next.
Definition: Expr.h:176
bool isLambdaCallOperator(const CXXMethodDecl *MD)
Definition: ASTLambda.h:27
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1111
void setLocStart(SourceLocation L)
Definition: Decl.h:2943
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:877
RAII object used to change the argument pack substitution index within a Sema object.
Definition: Sema.h:7701
void warnStackExhausted(SourceLocation Loc)
Warn that the stack is nearly exhausted.
Definition: Sema.cpp:390
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
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.
A helper class for building up ExtParameterInfos.
Definition: Sema.h:8069
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1609
bool isExpandedParameterPack() const
Whether this parameter is a non-type template parameter pack that has a known list of different types...
bool SubstBaseSpecifiers(CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs)
Perform substitution on the base class specifiers of the given class template specialization.
We are substituting explicit template arguments provided for a function template. ...
Definition: Sema.h:7533
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.
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:328
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3725
bool InstantiateEnum(SourceLocation PointOfInstantiation, EnumDecl *Instantiation, EnumDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateSpecializationKind TSK)
Instantiate the definition of an enum from a given pattern.
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
Definition: DeclCXX.cpp:1665
std::pair< unsigned, unsigned > getDepthAndIndex(NamedDecl *ND)
Retrieve the depth and index of a template parameter.
Definition: SemaInternal.h:65
static FunctionParmPackExpr * Create(const ASTContext &Context, QualType T, VarDecl *ParamPack, SourceLocation NameLoc, ArrayRef< VarDecl *> Params)
Definition: ExprCXX.cpp:1564
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...
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
SourceLocation getLocation() const
Definition: Expr.h:1225
void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl, ArrayRef< Decl *> Fields, SourceLocation LBrac, SourceLocation RBrac, const ParsedAttributesView &AttrList)
Definition: SemaDecl.cpp:16349
We are instantiating a template declaration.
Definition: Sema.h:7517
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Definition: TemplateBase.h:263
Added for Template instantiation observation.
Definition: Sema.h:7570
bool InstantiateInClassInitializer(SourceLocation PointOfInstantiation, FieldDecl *Instantiation, FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs)
Instantiate the definition of a field from the given pattern.
delayed_partial_spec_iterator delayed_partial_spec_begin()
Return an iterator to the beginning of the set of "delayed" partial specializations, which must be passed to InstantiateClassTemplatePartialSpecialization once the class definition has been completed.
Definition: Template.h:511
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:436
TypeSourceInfo * CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc, Optional< unsigned > NumExpansions)
Construct a pack expansion type from the pattern of the pack expansion.
unsigned getFunctionScopeDepth() const
Definition: Decl.h:1619
MultiLevelTemplateArgumentList getTemplateInstantiationArgs(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...
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:636
This represents one expression.
Definition: Expr.h:108
Defines the clang::LangOptions interface.
StringRef getKindName() const
Definition: Decl.h:3280
SourceLocation End
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
Definition: Type.h:5144
int Id
Definition: ASTDiff.cpp:190
void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, const Decl *Pattern, Decl *Inst, LateInstantiatedAttrVec *LateAttrs=nullptr, LocalInstantiationScope *OuterMostScope=nullptr)
bool hasUncompilableErrorOccurred() const
Errors that actually prevent compilation, not those that are upgraded from a warning by -Werror...
Definition: Diagnostic.h:751
Declaration of a template type parameter.
unsigned getIndex() const
Definition: Type.h:4640
ClassTemplatePartialSpecializationDecl * InstantiateClassTemplatePartialSpecialization(ClassTemplateDecl *ClassTemplate, ClassTemplatePartialSpecializationDecl *PartialSpec)
Instantiate the declaration of a class template partial specialization.
void PerformDependentDiagnostics(const DeclContext *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs)
This file defines the classes used to store parsed information about declaration-specifiers and decla...
bool isInvalid() const
Determines whether we have exceeded the maximum recursive template instantiations.
Definition: Sema.h:7834
We are substituting template argument determined as part of template argument deduction for either a ...
Definition: Sema.h:7540
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition: Type.h:5126
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:67
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
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...
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition: TypeLoc.h:86
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
Definition: DeclBase.cpp:132
const CXXRecordDecl * getTemplateInstantiationPattern() const
Retrieve the record declaration from which this record could be instantiated.
Definition: DeclCXX.cpp:1690
bool InNonInstantiationSFINAEContext
Whether we are in a SFINAE context that is not associated with template instantiation.
Definition: Sema.h:7662
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl...
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
bool isFileContext() const
Definition: DeclBase.h:1849
ParmVarDecl * SubstParmVarDecl(ParmVarDecl *D, const MultiLevelTemplateArgumentList &TemplateArgs, int indexAdjustment, Optional< unsigned > NumExpansions, bool ExpectParameterPack)
DeclContext * getDeclContext()
Definition: DeclBase.h:438
CXXRecordDecl * getDefinition() const
Definition: DeclCXX.h:725
void ActOnFinishCXXInClassMemberInitializer(Decl *VarDecl, SourceLocation EqualLoc, Expr *Init)
This is invoked after parsing an in-class initializer for a non-static C++ class member, and after instantiating an in-class initializer in a class template.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
Represents a C++ template name within the type system.
Definition: TemplateName.h:187
EnumDecl * getDefinition() const
Definition: Decl.h:3468
llvm::PointerUnion< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > getSpecializedTemplateOrPartial() const
Retrieve the class template or class template partial specialization which was specialized by this...
void printTemplateArgumentList(raw_ostream &OS, ArrayRef< TemplateArgument > Args, const PrintingPolicy &Policy)
Print a template argument list, including the &#39;<&#39; and &#39;>&#39; enclosing the template arguments.
int Depth
Definition: ASTDiff.cpp:190
QualType getType() const
Definition: Expr.h:137
void CheckCompletedCXXClass(CXXRecordDecl *Record)
Perform semantic checks on a class definition that has been completing, introducing implicitly-declar...
llvm::FoldingSetVector< ClassTemplatePartialSpecializationDecl > & getPartialSpecializations()
Retrieve the set of partial specializations of this class template.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1779
Data structure that captures multiple levels of template argument lists for use in template instantia...
Definition: Template.h:64
bool isInvalid() const
Definition: Ownership.h:166
void setLocation(SourceLocation L)
Definition: DeclBase.h:430
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization, retrieves the member specialization information.
Definition: DeclCXX.cpp:1643
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:4115
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
ValueDecl * getDecl()
Definition: Expr.h:1217
SourceLocation getLocation() const
Definition: Expr.h:1925
bool isUsable() const
Definition: Ownership.h:167
The result type of a method or function.
This template specialization was implicitly instantiated from a template.
Definition: Specifiers.h:181
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:708
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition: DeclBase.cpp:295
NamedDecl * FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, const MultiLevelTemplateArgumentList &TemplateArgs, bool FindingInstantiatedContext=false)
Find the instantiation of the given declaration within the current instantiation. ...
PrettyDeclStackTraceEntry - If a crash occurs in the parser while parsing something related to a decl...
Attr * instantiateTemplateAttribute(const Attr *At, ASTContext &C, Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs)
ClassTemplateDecl * getInstantiatedFromMemberTemplate() const
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition: Decl.cpp:4230
static void deleteScopes(LocalInstantiationScope *Scope, LocalInstantiationScope *Outermost)
deletes the given scope, and all otuer scopes, down to the given outermost scope. ...
Definition: Template.h:360
virtual void printName(raw_ostream &os) const
Definition: Decl.cpp:1544
void ActOnStartCXXInClassMemberInitializer()
Enter a new C++ default initializer scope.
void pushCodeSynthesisContext(CodeSynthesisContext Ctx)
We are declaring an implicit special member function.
Definition: Sema.h:7560
Kind
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Definition: Ownership.h:153
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:3781
TypeLoc IgnoreParens() const
Definition: TypeLoc.h:1162
A stack object to be created when performing template instantiation.
Definition: Sema.h:7738
Attr * instantiateTemplateAttributeForDecl(const Attr *At, ASTContext &C, Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs)
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:3938
bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, TemplateArgumentListInfo &Result, const MultiLevelTemplateArgumentList &TemplateArgs)
Encodes a location in the source.
We are computing the exception specification for a defaulted special member function.
Definition: Sema.h:7553
void atTemplateBegin(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema, const Sema::CodeSynthesisContext &Inst)
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
Definition: Type.h:2127
void setBraceRange(SourceRange R)
Definition: Decl.h:3187
sema::TemplateDeductionInfo * DeductionInfo
The template deduction info object associated with the substitution or checking of explicit or deduce...
Definition: Sema.h:7608
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:130
DeclarationName getName() const
getName - Returns the embedded declaration name.
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3105
TemplateArgument getArgumentPack() const
Definition: Type.cpp:3348
TemplateParameterList * SubstTemplateParams(TemplateParameterList *List)
Instantiates a nested template parameter list in the current instantiation context.
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set...
Definition: Decl.h:2762
SynthesisKind
The kind of template instantiation we are performing.
Definition: Sema.h:7514
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2068
VarDecl * getExpansion(unsigned I) const
Get an expansion of the parameter pack by index.
Definition: ExprCXX.h:4287
We are checking the validity of a default template argument that has been used when naming a template...
Definition: Sema.h:7549
bool isParameterPack() const
Definition: Type.h:4641
void reserve(size_t Requested)
Ensures that this buffer has at least as much capacity as described.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:359
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
Definition: Type.h:4751
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
static const Decl * getCanonicalParmVarDecl(const Decl *D)
TemplateDeductionResult DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, const TemplateArgumentList &TemplateArgs, sema::TemplateDeductionInfo &Info)
Perform template argument deduction to determine whether the given template arguments match the given...
void setTagKind(TagKind TK)
Definition: Decl.h:3288
void InstantiateEnumDefinition(EnumDecl *Enum, EnumDecl *Pattern)
llvm::DenseSet< std::pair< Decl *, unsigned > > InstantiatingSpecializations
Specializations whose definitions are currently being instantiated.
Definition: Sema.h:7633
bool hasUninstantiatedDefaultArg() const
Definition: Decl.h:1686
void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, bool DefinitionRequired=false)
Note that the vtable for the given class was used at the given location.
This template specialization was instantiated from a template due to an explicit instantiation defini...
Definition: Specifiers.h:193
Represents a C++11 static_assert declaration.
Definition: DeclCXX.h:3830
DeductionFailureInfo MakeDeductionFailureInfo(ASTContext &Context, Sema::TemplateDeductionResult TDK, sema::TemplateDeductionInfo &Info)
Convert from Sema&#39;s representation of template deduction information to the form used in overload-can...
ArrayRef< ParmVarDecl * > getParams() const
Definition: TypeLoc.h:1428
unsigned getFullDataSize() const
Returns the size of the type source info data block.
Definition: TypeLoc.h:161
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:109
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition: Type.cpp:2608
void InstantiatedLocalPackArg(const Decl *D, VarDecl *Inst)
void setHasInheritedDefaultArg(bool I=true)
Definition: Decl.h:1702
const TemplateArgumentList & getTemplateInstantiationArgs() const
Retrieve the set of template arguments that should be used to instantiate the initializer of the vari...
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
Definition: Type.h:2117
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:215
CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD)
getSpecialMember - get the special member enum for a method.
Definition: SemaDecl.cpp:2945
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the template specialization kind.
Definition: DeclTemplate.h:695
SourceLocation getLocation() const
void InstantiateClassTemplateSpecializationMembers(SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK)
Instantiate the definitions of all of the members of the given class template specialization, which was named as part of an explicit instantiation.
Represents a reference to a function parameter pack or init-capture pack that has been substituted bu...
Definition: ExprCXX.h:4243
Represents a template argument.
Definition: TemplateBase.h:50
void collectUnexpandedParameterPacks(TemplateArgument Arg, SmallVectorImpl< UnexpandedParameterPack > &Unexpanded)
Collect the set of unexpanded parameter packs within the given template argument. ...
TagTypeKind
The kind of a tag type.
Definition: Type.h:5107
bool isNull() const
Determine whether this template name is NULL.
Dataflow Directional Tag Classes.
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:1654
int ArgumentPackSubstitutionIndex
The current index into pack expansion arguments that will be used for substitution of parameter packs...
Definition: Sema.h:7695
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
Definition: Sema.h:7595
[C99 6.4.2.2] - A predefined identifier such as func.
Definition: Expr.h:1873
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1271
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:403
ASTMutationListener * getASTMutationListener() const
Definition: Sema.cpp:428
NonTypeTemplateParmDecl * getParameterPack() const
Retrieve the non-type template parameter pack being substituted.
Definition: ExprCXX.h:4203
QualType getType() const
Get the type for which this source info wrapper provides information.
Definition: TypeLoc.h:130
We are instantiating a default argument for a function.
Definition: Sema.h:7529
QualType RebuildElaboratedType(SourceLocation KeywordLoc, ElaboratedTypeKeyword Keyword, NestedNameSpecifierLoc QualifierLoc, QualType Named)
Build a new qualified name type.
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:523
Interesting information about a specific parameter that can&#39;t simply be reflected in parameter&#39;s type...
Definition: Type.h:3419
This template specialization was instantiated from a template due to an explicit instantiation declar...
Definition: Specifiers.h:189
RecordDecl * getOuterLexicalRecordContext()
Retrieve the outermost lexically enclosing record context.
Definition: DeclBase.cpp:1770
VarDecl *const * iterator
Iterators over the parameters which the parameter pack expanded into.
Definition: ExprCXX.h:4279
The name of a declaration.
Expr * getDefaultArg()
Definition: Decl.cpp:2670
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.
void setInstantiationOfMemberFunction(FunctionDecl *FD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member function FD.
Definition: Decl.h:2452
SourceRange InstantiationRange
The source range that covers the construct that cause the instantiation, e.g., the template-id that c...
Definition: Sema.h:7613
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:1636
bool isClassScopeExplicitSpecialization() const
Is this an explicit specialization at class scope (within the class that owns the primary template)...
Represents an enum.
Definition: Decl.h:3367
bool isParameterPack() const
Determine whether this variable is actually a function parameter pack or init-capture pack...
Definition: Decl.cpp:2436
SourceLocation getParameterPackLocation() const
Get the location of the parameter pack.
Definition: ExprCXX.h:4275
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:175
TemplateSpecCandidate & addCandidate()
Add a new candidate with NumConversions conversion sequence slots to the overload set...
Optional< sema::TemplateDeductionInfo * > isSFINAEContext() const
Determines whether we are currently in a context where template argument substitution failures are no...
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
Definition: TemplateBase.h:339
ParmVarDecl * CheckParameter(DeclContext *DC, SourceLocation StartLoc, SourceLocation NameLoc, IdentifierInfo *Name, QualType T, TypeSourceInfo *TSInfo, StorageClass SC)
Definition: SemaDecl.cpp:13093
bool isNull() const
Determine whether this template argument has no value.
Definition: TemplateBase.h:237
iterator end() const
Definition: ExprCXX.h:4281
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:449
RetTy Visit(PTR(Decl) D)
Definition: DeclVisitor.h:37
unsigned getNumArgs() const
Retrieve the number of template arguments.
Definition: Type.h:4988
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition: Decl.h:1694
Expr * getUninstantiatedDefaultArg()
Definition: Decl.cpp:2712
void MarkVirtualMembersReferenced(SourceLocation Loc, const CXXRecordDecl *RD, bool ConstexprOnly=false)
MarkVirtualMembersReferenced - Will mark all members of the given CXXRecordDecl referenced.
This template specialization was declared or defined by an explicit specialization (C++ [temp...
Definition: Specifiers.h:185
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:715
UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations
A mapping from parameters with unparsed default arguments to the set of instantiations of each parame...
Definition: Sema.h:1182
The template argument is a type.
Definition: TemplateBase.h:59
Holds information about the various types of exception specification.
Definition: Type.h:3779
SmallVectorImpl< std::pair< VarTemplateDecl *, VarTemplatePartialSpecializationDecl * > >::iterator delayed_var_partial_spec_iterator
Definition: Template.h:505
void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, const MultiLevelTemplateArgumentList &Args)
The template argument is actually a parameter pack.
Definition: TemplateBase.h:90
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type...
Definition: Type.cpp:2866
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
bool SavedInNonInstantiationSFINAEContext
Was the enclosing context a non-instantiation SFINAE context?
Definition: Sema.h:7574
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2286
bool isAlreadyInstantiating() const
Determine whether we are already instantiating this specialization in some surrounding active instant...
Definition: Sema.h:7838
A template argument list.
Definition: DeclTemplate.h:214
bool hasFatalErrorOccurred() const
Definition: Diagnostic.h:754
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:240
ExprResult SubstExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs)
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:234
unsigned getDepth() const
Definition: Type.h:4639
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1005
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
bool isVoidType() const
Definition: Type.h:6649
static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T)
bool AttachBaseSpecifiers(CXXRecordDecl *Class, MutableArrayRef< CXXBaseSpecifier *> Bases)
Performs the actual work of attaching the given base class specifiers to a C++ class.
void enableLateAttributeInstantiation(Sema::LateInstantiatedAttrVec *LA)
Definition: Template.h:488
void Clear()
Note that we have finished instantiating this template.
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:664
void atTemplateEnd(TemplateInstantiationCallbackPtrs &Callbacks, const Sema &TheSema, const Sema::CodeSynthesisContext &Inst)
SmallVectorImpl< std::pair< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > >::iterator delayed_partial_spec_iterator
Definition: Template.h:502
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:386
Declaration of a class template.
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:129
SourceLocation getNameLoc() const
Definition: TypeLoc.h:519
We are substituting prior template arguments into a new template parameter.
Definition: Sema.h:7545
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:275
ExprResult ExprError()
Definition: Ownership.h:279
ClassTemplatePartialSpecializationDecl * getMoreSpecializedPartialSpecialization(ClassTemplatePartialSpecializationDecl *PS1, ClassTemplatePartialSpecializationDecl *PS2, SourceLocation Loc)
Returns the more specialized class template partial specialization according to the rules of partial ...
const ParmVarDecl * getParam() const
Definition: ExprCXX.h:1146
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2111
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:256
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1141
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:4917
Defines utilities for dealing with stack allocation and stack space.
virtual bool HandleTopLevelDecl(DeclGroupRef D)
HandleTopLevelDecl - Handle the specified top-level declaration.
Definition: ASTConsumer.cpp:18
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.
QualType getType() const
Definition: Decl.h:647
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:129
Wrapper for template type parameters.
Definition: TypeLoc.h:734
A trivial tuple used to represent a source range.
ASTContext & Context
Definition: Sema.h:374
This represents a decl that may have a name.
Definition: Decl.h:248
bool isTranslationUnit() const
Definition: DeclBase.h:1854
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type...
Definition: TypeLoc.h:75
NamedDecl * getAsNamedDecl(TemplateParameter P)
const TemplateArgumentList & getTemplateInstantiationArgs() const
Retrieve the set of template arguments that should be used to instantiate members of the class templa...
No keyword precedes the qualified type name.
Definition: Type.h:5147
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:280
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
Definition: DeclTemplate.h:704
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
Definition: DeclTemplate.h:709
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...
void pushFullCopy(TypeLoc L)
Pushes a copy of the given TypeLoc onto this builder.
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition: Decl.h:729
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:3811
Declaration of a template function.
Attr - This represents one attribute.
Definition: Attr.h:45
SourceLocation getLocation() const
Definition: DeclBase.h:429
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:97
virtual void HandleTagDeclDefinition(TagDecl *D)
HandleTagDeclDefinition - This callback is invoked each time a TagDecl (e.g.
Definition: ASTConsumer.h:72
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
Definition: Decl.cpp:1772
A RAII object to temporarily push a declaration context.
Definition: Sema.h:774
static CXXRecordDecl * getPatternForClassTemplateSpecialization(Sema &S, SourceLocation PointOfInstantiation, ClassTemplateSpecializationDecl *ClassTemplateSpec, TemplateSpecializationKind TSK, bool Complain)
Get the instantiation pattern to use to instantiate the definition of a given ClassTemplateSpecializa...