clang  7.0.0svn
SemaTemplateVariadic.cpp
Go to the documentation of this file.
1 //===------- SemaTemplateVariadic.cpp - C++ Variadic Templates ------------===/
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //===----------------------------------------------------------------------===/
8 //
9 // This file implements semantic analysis for C++0x variadic templates.
10 //===----------------------------------------------------------------------===/
11 
12 #include "clang/Sema/Sema.h"
13 #include "TypeLocBuilder.h"
14 #include "clang/AST/Expr.h"
16 #include "clang/AST/TypeLoc.h"
17 #include "clang/Sema/Lookup.h"
19 #include "clang/Sema/ScopeInfo.h"
21 #include "clang/Sema/Template.h"
22 
23 using namespace clang;
24 
25 //----------------------------------------------------------------------------
26 // Visitor that collects unexpanded parameter packs
27 //----------------------------------------------------------------------------
28 
29 /// Retrieve the depth and index of a parameter pack.
30 static std::pair<unsigned, unsigned>
32  if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(ND))
33  return std::make_pair(TTP->getDepth(), TTP->getIndex());
34 
35  if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(ND))
36  return std::make_pair(NTTP->getDepth(), NTTP->getIndex());
37 
38  TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(ND);
39  return std::make_pair(TTP->getDepth(), TTP->getIndex());
40 }
41 
42 namespace {
43  /// A class that collects unexpanded parameter packs.
44  class CollectUnexpandedParameterPacksVisitor :
45  public RecursiveASTVisitor<CollectUnexpandedParameterPacksVisitor>
46  {
48  inherited;
49 
51 
52  bool InLambda = false;
53  unsigned DepthLimit = (unsigned)-1;
54 
55  void addUnexpanded(NamedDecl *ND, SourceLocation Loc = SourceLocation()) {
56  if (auto *PVD = dyn_cast<ParmVarDecl>(ND)) {
57  // For now, the only problematic case is a generic lambda's templated
58  // call operator, so we don't need to look for all the other ways we
59  // could have reached a dependent parameter pack.
60  auto *FD = dyn_cast<FunctionDecl>(PVD->getDeclContext());
61  auto *FTD = FD ? FD->getDescribedFunctionTemplate() : nullptr;
62  if (FTD && FTD->getTemplateParameters()->getDepth() >= DepthLimit)
63  return;
64  } else if (getDepthAndIndex(ND).first >= DepthLimit)
65  return;
66 
67  Unexpanded.push_back({ND, Loc});
68  }
69  void addUnexpanded(const TemplateTypeParmType *T,
71  if (T->getDepth() < DepthLimit)
72  Unexpanded.push_back({T, Loc});
73  }
74 
75  public:
76  explicit CollectUnexpandedParameterPacksVisitor(
78  : Unexpanded(Unexpanded) {}
79 
80  bool shouldWalkTypesOfTypeLocs() const { return false; }
81 
82  //------------------------------------------------------------------------
83  // Recording occurrences of (unexpanded) parameter packs.
84  //------------------------------------------------------------------------
85 
86  /// Record occurrences of template type parameter packs.
87  bool VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
88  if (TL.getTypePtr()->isParameterPack())
89  addUnexpanded(TL.getTypePtr(), TL.getNameLoc());
90  return true;
91  }
92 
93  /// Record occurrences of template type parameter packs
94  /// when we don't have proper source-location information for
95  /// them.
96  ///
97  /// Ideally, this routine would never be used.
98  bool VisitTemplateTypeParmType(TemplateTypeParmType *T) {
99  if (T->isParameterPack())
100  addUnexpanded(T);
101 
102  return true;
103  }
104 
105  /// Record occurrences of function and non-type template
106  /// parameter packs in an expression.
107  bool VisitDeclRefExpr(DeclRefExpr *E) {
108  if (E->getDecl()->isParameterPack())
109  addUnexpanded(E->getDecl(), E->getLocation());
110 
111  return true;
112  }
113 
114  /// Record occurrences of template template parameter packs.
115  bool TraverseTemplateName(TemplateName Template) {
116  if (auto *TTP = dyn_cast_or_null<TemplateTemplateParmDecl>(
117  Template.getAsTemplateDecl())) {
118  if (TTP->isParameterPack())
119  addUnexpanded(TTP);
120  }
121 
122  return inherited::TraverseTemplateName(Template);
123  }
124 
125  /// Suppress traversal into Objective-C container literal
126  /// elements that are pack expansions.
127  bool TraverseObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
129  return true;
130 
131  for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
133  if (Element.isPackExpansion())
134  continue;
135 
136  TraverseStmt(Element.Key);
137  TraverseStmt(Element.Value);
138  }
139  return true;
140  }
141  //------------------------------------------------------------------------
142  // Pruning the search for unexpanded parameter packs.
143  //------------------------------------------------------------------------
144 
145  /// Suppress traversal into statements and expressions that
146  /// do not contain unexpanded parameter packs.
147  bool TraverseStmt(Stmt *S) {
148  Expr *E = dyn_cast_or_null<Expr>(S);
149  if ((E && E->containsUnexpandedParameterPack()) || InLambda)
150  return inherited::TraverseStmt(S);
151 
152  return true;
153  }
154 
155  /// Suppress traversal into types that do not contain
156  /// unexpanded parameter packs.
157  bool TraverseType(QualType T) {
158  if ((!T.isNull() && T->containsUnexpandedParameterPack()) || InLambda)
159  return inherited::TraverseType(T);
160 
161  return true;
162  }
163 
164  /// Suppress traversal into types with location information
165  /// that do not contain unexpanded parameter packs.
166  bool TraverseTypeLoc(TypeLoc TL) {
167  if ((!TL.getType().isNull() &&
169  InLambda)
170  return inherited::TraverseTypeLoc(TL);
171 
172  return true;
173  }
174 
175  /// Suppress traversal of parameter packs.
176  bool TraverseDecl(Decl *D) {
177  // A function parameter pack is a pack expansion, so cannot contain
178  // an unexpanded parameter pack. Likewise for a template parameter
179  // pack that contains any references to other packs.
180  if (D->isParameterPack())
181  return true;
182 
183  return inherited::TraverseDecl(D);
184  }
185 
186  /// Suppress traversal of pack-expanded attributes.
187  bool TraverseAttr(Attr *A) {
188  if (A->isPackExpansion())
189  return true;
190 
191  return inherited::TraverseAttr(A);
192  }
193 
194  /// Suppress traversal of pack expansion expressions and types.
195  ///@{
196  bool TraversePackExpansionType(PackExpansionType *T) { return true; }
197  bool TraversePackExpansionTypeLoc(PackExpansionTypeLoc TL) { return true; }
198  bool TraversePackExpansionExpr(PackExpansionExpr *E) { return true; }
199  bool TraverseCXXFoldExpr(CXXFoldExpr *E) { return true; }
200 
201  ///@}
202 
203  /// Suppress traversal of using-declaration pack expansion.
204  bool TraverseUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
205  if (D->isPackExpansion())
206  return true;
207 
208  return inherited::TraverseUnresolvedUsingValueDecl(D);
209  }
210 
211  /// Suppress traversal of using-declaration pack expansion.
212  bool TraverseUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) {
213  if (D->isPackExpansion())
214  return true;
215 
216  return inherited::TraverseUnresolvedUsingTypenameDecl(D);
217  }
218 
219  /// Suppress traversal of template argument pack expansions.
220  bool TraverseTemplateArgument(const TemplateArgument &Arg) {
221  if (Arg.isPackExpansion())
222  return true;
223 
224  return inherited::TraverseTemplateArgument(Arg);
225  }
226 
227  /// Suppress traversal of template argument pack expansions.
228  bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc) {
229  if (ArgLoc.getArgument().isPackExpansion())
230  return true;
231 
232  return inherited::TraverseTemplateArgumentLoc(ArgLoc);
233  }
234 
235  /// Suppress traversal of base specifier pack expansions.
236  bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier &Base) {
237  if (Base.isPackExpansion())
238  return true;
239 
240  return inherited::TraverseCXXBaseSpecifier(Base);
241  }
242 
243  /// Suppress traversal of mem-initializer pack expansions.
244  bool TraverseConstructorInitializer(CXXCtorInitializer *Init) {
245  if (Init->isPackExpansion())
246  return true;
247 
248  return inherited::TraverseConstructorInitializer(Init);
249  }
250 
251  /// Note whether we're traversing a lambda containing an unexpanded
252  /// parameter pack. In this case, the unexpanded pack can occur anywhere,
253  /// including all the places where we normally wouldn't look. Within a
254  /// lambda, we don't propagate the 'contains unexpanded parameter pack' bit
255  /// outside an expression.
256  bool TraverseLambdaExpr(LambdaExpr *Lambda) {
257  // The ContainsUnexpandedParameterPack bit on a lambda is always correct,
258  // even if it's contained within another lambda.
259  if (!Lambda->containsUnexpandedParameterPack())
260  return true;
261 
262  bool WasInLambda = InLambda;
263  unsigned OldDepthLimit = DepthLimit;
264 
265  InLambda = true;
266  if (auto *TPL = Lambda->getTemplateParameterList())
267  DepthLimit = TPL->getDepth();
268 
269  inherited::TraverseLambdaExpr(Lambda);
270 
271  InLambda = WasInLambda;
272  DepthLimit = OldDepthLimit;
273  return true;
274  }
275 
276  /// Suppress traversal within pack expansions in lambda captures.
277  bool TraverseLambdaCapture(LambdaExpr *Lambda, const LambdaCapture *C,
278  Expr *Init) {
279  if (C->isPackExpansion())
280  return true;
281 
282  return inherited::TraverseLambdaCapture(Lambda, C, Init);
283  }
284  };
285 }
286 
287 /// Determine whether it's possible for an unexpanded parameter pack to
288 /// be valid in this location. This only happens when we're in a declaration
289 /// that is nested within an expression that could be expanded, such as a
290 /// lambda-expression within a function call.
291 ///
292 /// This is conservatively correct, but may claim that some unexpanded packs are
293 /// permitted when they are not.
295  for (auto *SI : FunctionScopes)
296  if (isa<sema::LambdaScopeInfo>(SI))
297  return true;
298  return false;
299 }
300 
301 /// Diagnose all of the unexpanded parameter packs in the given
302 /// vector.
303 bool
307  if (Unexpanded.empty())
308  return false;
309 
310  // If we are within a lambda expression and referencing a pack that is not
311  // a parameter of the lambda itself, that lambda contains an unexpanded
312  // parameter pack, and we are done.
313  // FIXME: Store 'Unexpanded' on the lambda so we don't need to recompute it
314  // later.
315  SmallVector<UnexpandedParameterPack, 4> LambdaParamPackReferences;
316  for (unsigned N = FunctionScopes.size(); N; --N) {
317  sema::FunctionScopeInfo *Func = FunctionScopes[N-1];
318  // We do not permit pack expansion that would duplicate a statement
319  // expression, not even within a lambda.
320  // FIXME: We could probably support this for statement expressions that do
321  // not contain labels, and for pack expansions that expand both the stmt
322  // expr and the enclosing lambda.
323  if (std::any_of(
324  Func->CompoundScopes.begin(), Func->CompoundScopes.end(),
325  [](sema::CompoundScopeInfo &CSI) { return CSI.IsStmtExpr; }))
326  break;
327 
328  if (auto *LSI = dyn_cast<sema::LambdaScopeInfo>(Func)) {
329  if (N == FunctionScopes.size()) {
330  for (auto &Param : Unexpanded) {
331  auto *PD = dyn_cast_or_null<ParmVarDecl>(
332  Param.first.dyn_cast<NamedDecl *>());
333  if (PD && PD->getDeclContext() == LSI->CallOperator)
334  LambdaParamPackReferences.push_back(Param);
335  }
336  }
337 
338  // If we have references to a parameter pack of the innermost enclosing
339  // lambda, only diagnose those ones. We don't know whether any other
340  // unexpanded parameters referenced herein are actually unexpanded;
341  // they might be expanded at an outer level.
342  if (!LambdaParamPackReferences.empty()) {
343  Unexpanded = LambdaParamPackReferences;
344  break;
345  }
346 
347  LSI->ContainsUnexpandedParameterPack = true;
348  return false;
349  }
350  }
351 
354  llvm::SmallPtrSet<IdentifierInfo *, 4> NamesKnown;
355 
356  for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
357  IdentifierInfo *Name = nullptr;
358  if (const TemplateTypeParmType *TTP
359  = Unexpanded[I].first.dyn_cast<const TemplateTypeParmType *>())
360  Name = TTP->getIdentifier();
361  else
362  Name = Unexpanded[I].first.get<NamedDecl *>()->getIdentifier();
363 
364  if (Name && NamesKnown.insert(Name).second)
365  Names.push_back(Name);
366 
367  if (Unexpanded[I].second.isValid())
368  Locations.push_back(Unexpanded[I].second);
369  }
370 
371  DiagnosticBuilder DB = Diag(Loc, diag::err_unexpanded_parameter_pack)
372  << (int)UPPC << (int)Names.size();
373  for (size_t I = 0, E = std::min(Names.size(), (size_t)2); I != E; ++I)
374  DB << Names[I];
375 
376  for (unsigned I = 0, N = Locations.size(); I != N; ++I)
377  DB << SourceRange(Locations[I]);
378  return true;
379 }
380 
382  TypeSourceInfo *T,
384  // C++0x [temp.variadic]p5:
385  // An appearance of a name of a parameter pack that is not expanded is
386  // ill-formed.
388  return false;
389 
391  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(
392  T->getTypeLoc());
393  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
394  return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
395 }
396 
399  // C++0x [temp.variadic]p5:
400  // An appearance of a name of a parameter pack that is not expanded is
401  // ill-formed.
403  return false;
404 
406  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(E);
407  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
408  return DiagnoseUnexpandedParameterPacks(E->getLocStart(), UPPC, Unexpanded);
409 }
410 
413  // C++0x [temp.variadic]p5:
414  // An appearance of a name of a parameter pack that is not expanded is
415  // ill-formed.
416  if (!SS.getScopeRep() ||
418  return false;
419 
421  CollectUnexpandedParameterPacksVisitor(Unexpanded)
422  .TraverseNestedNameSpecifier(SS.getScopeRep());
423  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
425  UPPC, Unexpanded);
426 }
427 
430  // C++0x [temp.variadic]p5:
431  // An appearance of a name of a parameter pack that is not expanded is
432  // ill-formed.
433  switch (NameInfo.getName().getNameKind()) {
442  return false;
443 
447  // FIXME: We shouldn't need this null check!
448  if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
449  return DiagnoseUnexpandedParameterPack(NameInfo.getLoc(), TSInfo, UPPC);
450 
452  return false;
453 
454  break;
455  }
456 
458  CollectUnexpandedParameterPacksVisitor(Unexpanded)
459  .TraverseType(NameInfo.getName().getCXXNameType());
460  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
461  return DiagnoseUnexpandedParameterPacks(NameInfo.getLoc(), UPPC, Unexpanded);
462 }
463 
465  TemplateName Template,
467 
468  if (Template.isNull() || !Template.containsUnexpandedParameterPack())
469  return false;
470 
472  CollectUnexpandedParameterPacksVisitor(Unexpanded)
473  .TraverseTemplateName(Template);
474  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
475  return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
476 }
477 
480  if (Arg.getArgument().isNull() ||
482  return false;
483 
485  CollectUnexpandedParameterPacksVisitor(Unexpanded)
486  .TraverseTemplateArgumentLoc(Arg);
487  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
488  return DiagnoseUnexpandedParameterPacks(Arg.getLocation(), UPPC, Unexpanded);
489 }
490 
493  CollectUnexpandedParameterPacksVisitor(Unexpanded)
494  .TraverseTemplateArgument(Arg);
495 }
496 
499  CollectUnexpandedParameterPacksVisitor(Unexpanded)
500  .TraverseTemplateArgumentLoc(Arg);
501 }
502 
505  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(T);
506 }
507 
510  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(TL);
511 }
512 
516  CollectUnexpandedParameterPacksVisitor(Unexpanded)
517  .TraverseNestedNameSpecifierLoc(NNS);
518 }
519 
521  const DeclarationNameInfo &NameInfo,
523  CollectUnexpandedParameterPacksVisitor(Unexpanded)
524  .TraverseDeclarationNameInfo(NameInfo);
525 }
526 
527 
530  SourceLocation EllipsisLoc) {
531  if (Arg.isInvalid())
532  return Arg;
533 
534  switch (Arg.getKind()) {
536  TypeResult Result = ActOnPackExpansion(Arg.getAsType(), EllipsisLoc);
537  if (Result.isInvalid())
538  return ParsedTemplateArgument();
539 
540  return ParsedTemplateArgument(Arg.getKind(), Result.get().getAsOpaquePtr(),
541  Arg.getLocation());
542  }
543 
545  ExprResult Result = ActOnPackExpansion(Arg.getAsExpr(), EllipsisLoc);
546  if (Result.isInvalid())
547  return ParsedTemplateArgument();
548 
549  return ParsedTemplateArgument(Arg.getKind(), Result.get(),
550  Arg.getLocation());
551  }
552 
555  SourceRange R(Arg.getLocation());
556  if (Arg.getScopeSpec().isValid())
557  R.setBegin(Arg.getScopeSpec().getBeginLoc());
558  Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
559  << R;
560  return ParsedTemplateArgument();
561  }
562 
563  return Arg.getTemplatePackExpansion(EllipsisLoc);
564  }
565  llvm_unreachable("Unhandled template argument kind?");
566 }
567 
569  SourceLocation EllipsisLoc) {
570  TypeSourceInfo *TSInfo;
571  GetTypeFromParser(Type, &TSInfo);
572  if (!TSInfo)
573  return true;
574 
575  TypeSourceInfo *TSResult = CheckPackExpansion(TSInfo, EllipsisLoc, None);
576  if (!TSResult)
577  return true;
578 
579  return CreateParsedType(TSResult->getType(), TSResult);
580 }
581 
584  Optional<unsigned> NumExpansions) {
585  // Create the pack expansion type and source-location information.
586  QualType Result = CheckPackExpansion(Pattern->getType(),
587  Pattern->getTypeLoc().getSourceRange(),
588  EllipsisLoc, NumExpansions);
589  if (Result.isNull())
590  return nullptr;
591 
592  TypeLocBuilder TLB;
593  TLB.pushFullCopy(Pattern->getTypeLoc());
595  TL.setEllipsisLoc(EllipsisLoc);
596 
597  return TLB.getTypeSourceInfo(Context, Result);
598 }
599 
601  SourceLocation EllipsisLoc,
602  Optional<unsigned> NumExpansions) {
603  // C++0x [temp.variadic]p5:
604  // The pattern of a pack expansion shall name one or more
605  // parameter packs that are not expanded by a nested pack
606  // expansion.
607  if (!Pattern->containsUnexpandedParameterPack()) {
608  Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
609  << PatternRange;
610  return QualType();
611  }
612 
613  return Context.getPackExpansionType(Pattern, NumExpansions);
614 }
615 
617  return CheckPackExpansion(Pattern, EllipsisLoc, None);
618 }
619 
621  Optional<unsigned> NumExpansions) {
622  if (!Pattern)
623  return ExprError();
624 
625  // C++0x [temp.variadic]p5:
626  // The pattern of a pack expansion shall name one or more
627  // parameter packs that are not expanded by a nested pack
628  // expansion.
629  if (!Pattern->containsUnexpandedParameterPack()) {
630  Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
631  << Pattern->getSourceRange();
632  return ExprError();
633  }
634 
635  // Create the pack expansion expression and source-location information.
636  return new (Context)
637  PackExpansionExpr(Context.DependentTy, Pattern, EllipsisLoc, NumExpansions);
638 }
639 
641  SourceLocation EllipsisLoc, SourceRange PatternRange,
643  const MultiLevelTemplateArgumentList &TemplateArgs, bool &ShouldExpand,
644  bool &RetainExpansion, Optional<unsigned> &NumExpansions) {
645  ShouldExpand = true;
646  RetainExpansion = false;
647  std::pair<IdentifierInfo *, SourceLocation> FirstPack;
648  bool HaveFirstPack = false;
649  Optional<unsigned> NumPartialExpansions;
650  SourceLocation PartiallySubstitutedPackLoc;
651 
652  for (ArrayRef<UnexpandedParameterPack>::iterator i = Unexpanded.begin(),
653  end = Unexpanded.end();
654  i != end; ++i) {
655  // Compute the depth and index for this parameter pack.
656  unsigned Depth = 0, Index = 0;
657  IdentifierInfo *Name;
658  bool IsFunctionParameterPack = false;
659 
660  if (const TemplateTypeParmType *TTP
661  = i->first.dyn_cast<const TemplateTypeParmType *>()) {
662  Depth = TTP->getDepth();
663  Index = TTP->getIndex();
664  Name = TTP->getIdentifier();
665  } else {
666  NamedDecl *ND = i->first.get<NamedDecl *>();
667  if (isa<ParmVarDecl>(ND))
668  IsFunctionParameterPack = true;
669  else
670  std::tie(Depth, Index) = getDepthAndIndex(ND);
671 
672  Name = ND->getIdentifier();
673  }
674 
675  // Determine the size of this argument pack.
676  unsigned NewPackSize;
677  if (IsFunctionParameterPack) {
678  // Figure out whether we're instantiating to an argument pack or not.
679  typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
680 
681  llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation
682  = CurrentInstantiationScope->findInstantiationOf(
683  i->first.get<NamedDecl *>());
684  if (Instantiation->is<DeclArgumentPack *>()) {
685  // We could expand this function parameter pack.
686  NewPackSize = Instantiation->get<DeclArgumentPack *>()->size();
687  } else {
688  // We can't expand this function parameter pack, so we can't expand
689  // the pack expansion.
690  ShouldExpand = false;
691  continue;
692  }
693  } else {
694  // If we don't have a template argument at this depth/index, then we
695  // cannot expand the pack expansion. Make a note of this, but we still
696  // want to check any parameter packs we *do* have arguments for.
697  if (Depth >= TemplateArgs.getNumLevels() ||
698  !TemplateArgs.hasTemplateArgument(Depth, Index)) {
699  ShouldExpand = false;
700  continue;
701  }
702 
703  // Determine the size of the argument pack.
704  NewPackSize = TemplateArgs(Depth, Index).pack_size();
705  }
706 
707  // C++0x [temp.arg.explicit]p9:
708  // Template argument deduction can extend the sequence of template
709  // arguments corresponding to a template parameter pack, even when the
710  // sequence contains explicitly specified template arguments.
711  if (!IsFunctionParameterPack && CurrentInstantiationScope) {
712  if (NamedDecl *PartialPack
713  = CurrentInstantiationScope->getPartiallySubstitutedPack()){
714  unsigned PartialDepth, PartialIndex;
715  std::tie(PartialDepth, PartialIndex) = getDepthAndIndex(PartialPack);
716  if (PartialDepth == Depth && PartialIndex == Index) {
717  RetainExpansion = true;
718  // We don't actually know the new pack size yet.
719  NumPartialExpansions = NewPackSize;
720  PartiallySubstitutedPackLoc = i->second;
721  continue;
722  }
723  }
724  }
725 
726  if (!NumExpansions) {
727  // The is the first pack we've seen for which we have an argument.
728  // Record it.
729  NumExpansions = NewPackSize;
730  FirstPack.first = Name;
731  FirstPack.second = i->second;
732  HaveFirstPack = true;
733  continue;
734  }
735 
736  if (NewPackSize != *NumExpansions) {
737  // C++0x [temp.variadic]p5:
738  // All of the parameter packs expanded by a pack expansion shall have
739  // the same number of arguments specified.
740  if (HaveFirstPack)
741  Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict)
742  << FirstPack.first << Name << *NumExpansions << NewPackSize
743  << SourceRange(FirstPack.second) << SourceRange(i->second);
744  else
745  Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_multilevel)
746  << Name << *NumExpansions << NewPackSize
747  << SourceRange(i->second);
748  return true;
749  }
750  }
751 
752  // If we're performing a partial expansion but we also have a full expansion,
753  // expand to the number of common arguments. For example, given:
754  //
755  // template<typename ...T> struct A {
756  // template<typename ...U> void f(pair<T, U>...);
757  // };
758  //
759  // ... a call to 'A<int, int>().f<int>' should expand the pack once and
760  // retain an expansion.
761  if (NumPartialExpansions) {
762  if (NumExpansions && *NumExpansions < *NumPartialExpansions) {
763  NamedDecl *PartialPack =
764  CurrentInstantiationScope->getPartiallySubstitutedPack();
765  Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_partial)
766  << PartialPack << *NumPartialExpansions << *NumExpansions
767  << SourceRange(PartiallySubstitutedPackLoc);
768  return true;
769  }
770 
771  NumExpansions = NumPartialExpansions;
772  }
773 
774  return false;
775 }
776 
778  const MultiLevelTemplateArgumentList &TemplateArgs) {
779  QualType Pattern = cast<PackExpansionType>(T)->getPattern();
781  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(Pattern);
782 
784  for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
785  // Compute the depth and index for this parameter pack.
786  unsigned Depth;
787  unsigned Index;
788 
789  if (const TemplateTypeParmType *TTP
790  = Unexpanded[I].first.dyn_cast<const TemplateTypeParmType *>()) {
791  Depth = TTP->getDepth();
792  Index = TTP->getIndex();
793  } else {
794  NamedDecl *ND = Unexpanded[I].first.get<NamedDecl *>();
795  if (isa<ParmVarDecl>(ND)) {
796  // Function parameter pack.
797  typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
798 
799  llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation
800  = CurrentInstantiationScope->findInstantiationOf(
801  Unexpanded[I].first.get<NamedDecl *>());
802  if (Instantiation->is<Decl*>())
803  // The pattern refers to an unexpanded pack. We're not ready to expand
804  // this pack yet.
805  return None;
806 
807  unsigned Size = Instantiation->get<DeclArgumentPack *>()->size();
808  assert((!Result || *Result == Size) && "inconsistent pack sizes");
809  Result = Size;
810  continue;
811  }
812 
813  std::tie(Depth, Index) = getDepthAndIndex(ND);
814  }
815  if (Depth >= TemplateArgs.getNumLevels() ||
816  !TemplateArgs.hasTemplateArgument(Depth, Index))
817  // The pattern refers to an unknown template argument. We're not ready to
818  // expand this pack yet.
819  return None;
820 
821  // Determine the size of the argument pack.
822  unsigned Size = TemplateArgs(Depth, Index).pack_size();
823  assert((!Result || *Result == Size) && "inconsistent pack sizes");
824  Result = Size;
825  }
826 
827  return Result;
828 }
829 
831  const DeclSpec &DS = D.getDeclSpec();
832  switch (DS.getTypeSpecType()) {
833  case TST_typename:
834  case TST_typeofType:
835  case TST_underlyingType:
836  case TST_atomic: {
837  QualType T = DS.getRepAsType().get();
838  if (!T.isNull() && T->containsUnexpandedParameterPack())
839  return true;
840  break;
841  }
842 
843  case TST_typeofExpr:
844  case TST_decltype:
845  if (DS.getRepAsExpr() &&
847  return true;
848  break;
849 
850  case TST_unspecified:
851  case TST_void:
852  case TST_char:
853  case TST_wchar:
854  case TST_char8:
855  case TST_char16:
856  case TST_char32:
857  case TST_int:
858  case TST_int128:
859  case TST_half:
860  case TST_float:
861  case TST_double:
862  case TST_Accum:
863  case TST_Fract:
864  case TST_Float16:
865  case TST_float128:
866  case TST_bool:
867  case TST_decimal32:
868  case TST_decimal64:
869  case TST_decimal128:
870  case TST_enum:
871  case TST_union:
872  case TST_struct:
873  case TST_interface:
874  case TST_class:
875  case TST_auto:
876  case TST_auto_type:
877  case TST_decltype_auto:
878 #define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t:
879 #include "clang/Basic/OpenCLImageTypes.def"
880  case TST_unknown_anytype:
881  case TST_error:
882  break;
883  }
884 
885  for (unsigned I = 0, N = D.getNumTypeObjects(); I != N; ++I) {
886  const DeclaratorChunk &Chunk = D.getTypeObject(I);
887  switch (Chunk.Kind) {
893  // These declarator chunks cannot contain any parameter packs.
894  break;
895 
897  if (Chunk.Arr.NumElts &&
899  return true;
900  break;
902  for (unsigned i = 0, e = Chunk.Fun.NumParams; i != e; ++i) {
903  ParmVarDecl *Param = cast<ParmVarDecl>(Chunk.Fun.Params[i].Param);
904  QualType ParamTy = Param->getType();
905  assert(!ParamTy.isNull() && "Couldn't parse type?");
906  if (ParamTy->containsUnexpandedParameterPack()) return true;
907  }
908 
909  if (Chunk.Fun.getExceptionSpecType() == EST_Dynamic) {
910  for (unsigned i = 0; i != Chunk.Fun.getNumExceptions(); ++i) {
911  if (Chunk.Fun.Exceptions[i]
912  .Ty.get()
914  return true;
915  }
916  } else if (isComputedNoexcept(Chunk.Fun.getExceptionSpecType()) &&
918  return true;
919 
920  if (Chunk.Fun.hasTrailingReturnType()) {
921  QualType T = Chunk.Fun.getTrailingReturnType().get();
922  if (!T.isNull() && T->containsUnexpandedParameterPack())
923  return true;
924  }
925  break;
926 
928  if (Chunk.Mem.Scope().getScopeRep() &&
930  return true;
931  break;
932  }
933  }
934 
935  return false;
936 }
937 
938 namespace {
939 
940 // Callback to only accept typo corrections that refer to parameter packs.
941 class ParameterPackValidatorCCC : public CorrectionCandidateCallback {
942  public:
943  bool ValidateCandidate(const TypoCorrection &candidate) override {
944  NamedDecl *ND = candidate.getCorrectionDecl();
945  return ND && ND->isParameterPack();
946  }
947 };
948 
949 }
950 
951 /// Called when an expression computing the size of a parameter pack
952 /// is parsed.
953 ///
954 /// \code
955 /// template<typename ...Types> struct count {
956 /// static const unsigned value = sizeof...(Types);
957 /// };
958 /// \endcode
959 ///
960 //
961 /// \param OpLoc The location of the "sizeof" keyword.
962 /// \param Name The name of the parameter pack whose size will be determined.
963 /// \param NameLoc The source location of the name of the parameter pack.
964 /// \param RParenLoc The location of the closing parentheses.
966  SourceLocation OpLoc,
967  IdentifierInfo &Name,
968  SourceLocation NameLoc,
969  SourceLocation RParenLoc) {
970  // C++0x [expr.sizeof]p5:
971  // The identifier in a sizeof... expression shall name a parameter pack.
972  LookupResult R(*this, &Name, NameLoc, LookupOrdinaryName);
973  LookupName(R, S);
974 
975  NamedDecl *ParameterPack = nullptr;
976  switch (R.getResultKind()) {
977  case LookupResult::Found:
978  ParameterPack = R.getFoundDecl();
979  break;
980 
983  if (TypoCorrection Corrected =
984  CorrectTypo(R.getLookupNameInfo(), R.getLookupKind(), S, nullptr,
985  llvm::make_unique<ParameterPackValidatorCCC>(),
986  CTK_ErrorRecovery)) {
987  diagnoseTypo(Corrected,
988  PDiag(diag::err_sizeof_pack_no_pack_name_suggest) << &Name,
989  PDiag(diag::note_parameter_pack_here));
990  ParameterPack = Corrected.getCorrectionDecl();
991  }
992 
995  break;
996 
998  DiagnoseAmbiguousLookup(R);
999  return ExprError();
1000  }
1001 
1002  if (!ParameterPack || !ParameterPack->isParameterPack()) {
1003  Diag(NameLoc, diag::err_sizeof_pack_no_pack_name)
1004  << &Name;
1005  return ExprError();
1006  }
1007 
1008  MarkAnyDeclReferenced(OpLoc, ParameterPack, true);
1009 
1010  return SizeOfPackExpr::Create(Context, OpLoc, ParameterPack, NameLoc,
1011  RParenLoc);
1012 }
1013 
1016  TemplateArgumentLoc OrigLoc,
1017  SourceLocation &Ellipsis, Optional<unsigned> &NumExpansions) const {
1018  const TemplateArgument &Argument = OrigLoc.getArgument();
1019  assert(Argument.isPackExpansion());
1020  switch (Argument.getKind()) {
1021  case TemplateArgument::Type: {
1022  // FIXME: We shouldn't ever have to worry about missing
1023  // type-source info!
1024  TypeSourceInfo *ExpansionTSInfo = OrigLoc.getTypeSourceInfo();
1025  if (!ExpansionTSInfo)
1026  ExpansionTSInfo = Context.getTrivialTypeSourceInfo(Argument.getAsType(),
1027  Ellipsis);
1028  PackExpansionTypeLoc Expansion =
1029  ExpansionTSInfo->getTypeLoc().castAs<PackExpansionTypeLoc>();
1030  Ellipsis = Expansion.getEllipsisLoc();
1031 
1032  TypeLoc Pattern = Expansion.getPatternLoc();
1033  NumExpansions = Expansion.getTypePtr()->getNumExpansions();
1034 
1035  // We need to copy the TypeLoc because TemplateArgumentLocs store a
1036  // TypeSourceInfo.
1037  // FIXME: Find some way to avoid the copy?
1038  TypeLocBuilder TLB;
1039  TLB.pushFullCopy(Pattern);
1040  TypeSourceInfo *PatternTSInfo =
1041  TLB.getTypeSourceInfo(Context, Pattern.getType());
1042  return TemplateArgumentLoc(TemplateArgument(Pattern.getType()),
1043  PatternTSInfo);
1044  }
1045 
1047  PackExpansionExpr *Expansion
1048  = cast<PackExpansionExpr>(Argument.getAsExpr());
1049  Expr *Pattern = Expansion->getPattern();
1050  Ellipsis = Expansion->getEllipsisLoc();
1051  NumExpansions = Expansion->getNumExpansions();
1052  return TemplateArgumentLoc(Pattern, Pattern);
1053  }
1054 
1056  Ellipsis = OrigLoc.getTemplateEllipsisLoc();
1057  NumExpansions = Argument.getNumTemplateExpansions();
1058  return TemplateArgumentLoc(Argument.getPackExpansionPattern(),
1059  OrigLoc.getTemplateQualifierLoc(),
1060  OrigLoc.getTemplateNameLoc());
1061 
1068  return TemplateArgumentLoc();
1069  }
1070 
1071  llvm_unreachable("Invalid TemplateArgument Kind!");
1072 }
1073 
1075  assert(Arg.containsUnexpandedParameterPack());
1076 
1077  // If this is a substituted pack, grab that pack. If not, we don't know
1078  // the size yet.
1079  // FIXME: We could find a size in more cases by looking for a substituted
1080  // pack anywhere within this argument, but that's not necessary in the common
1081  // case for 'sizeof...(A)' handling.
1082  TemplateArgument Pack;
1083  switch (Arg.getKind()) {
1085  if (auto *Subst = Arg.getAsType()->getAs<SubstTemplateTypeParmPackType>())
1086  Pack = Subst->getArgumentPack();
1087  else
1088  return None;
1089  break;
1090 
1092  if (auto *Subst =
1093  dyn_cast<SubstNonTypeTemplateParmPackExpr>(Arg.getAsExpr()))
1094  Pack = Subst->getArgumentPack();
1095  else if (auto *Subst = dyn_cast<FunctionParmPackExpr>(Arg.getAsExpr())) {
1096  for (ParmVarDecl *PD : *Subst)
1097  if (PD->isParameterPack())
1098  return None;
1099  return Subst->getNumExpansions();
1100  } else
1101  return None;
1102  break;
1103 
1107  Pack = Subst->getArgumentPack();
1108  else
1109  return None;
1110  break;
1111 
1118  return None;
1119  }
1120 
1121  // Check that no argument in the pack is itself a pack expansion.
1122  for (TemplateArgument Elem : Pack.pack_elements()) {
1123  // There's no point recursing in this case; we would have already
1124  // expanded this pack expansion into the enclosing pack if we could.
1125  if (Elem.isPackExpansion())
1126  return None;
1127  }
1128  return Pack.pack_size();
1129 }
1130 
1131 static void CheckFoldOperand(Sema &S, Expr *E) {
1132  if (!E)
1133  return;
1134 
1135  E = E->IgnoreImpCasts();
1136  auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
1137  if ((OCE && OCE->isInfixBinaryOp()) || isa<BinaryOperator>(E) ||
1138  isa<AbstractConditionalOperator>(E)) {
1139  S.Diag(E->getExprLoc(), diag::err_fold_expression_bad_operand)
1140  << E->getSourceRange()
1142  << FixItHint::CreateInsertion(E->getLocEnd(), ")");
1143  }
1144 }
1145 
1147  tok::TokenKind Operator,
1148  SourceLocation EllipsisLoc, Expr *RHS,
1149  SourceLocation RParenLoc) {
1150  // LHS and RHS must be cast-expressions. We allow an arbitrary expression
1151  // in the parser and reduce down to just cast-expressions here.
1152  CheckFoldOperand(*this, LHS);
1153  CheckFoldOperand(*this, RHS);
1154 
1155  auto DiscardOperands = [&] {
1156  CorrectDelayedTyposInExpr(LHS);
1157  CorrectDelayedTyposInExpr(RHS);
1158  };
1159 
1160  // [expr.prim.fold]p3:
1161  // In a binary fold, op1 and op2 shall be the same fold-operator, and
1162  // either e1 shall contain an unexpanded parameter pack or e2 shall contain
1163  // an unexpanded parameter pack, but not both.
1164  if (LHS && RHS &&
1167  DiscardOperands();
1168  return Diag(EllipsisLoc,
1170  ? diag::err_fold_expression_packs_both_sides
1171  : diag::err_pack_expansion_without_parameter_packs)
1172  << LHS->getSourceRange() << RHS->getSourceRange();
1173  }
1174 
1175  // [expr.prim.fold]p2:
1176  // In a unary fold, the cast-expression shall contain an unexpanded
1177  // parameter pack.
1178  if (!LHS || !RHS) {
1179  Expr *Pack = LHS ? LHS : RHS;
1180  assert(Pack && "fold expression with neither LHS nor RHS");
1181  DiscardOperands();
1182  if (!Pack->containsUnexpandedParameterPack())
1183  return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
1184  << Pack->getSourceRange();
1185  }
1186 
1187  BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
1188  return BuildCXXFoldExpr(LParenLoc, LHS, Opc, EllipsisLoc, RHS, RParenLoc);
1189 }
1190 
1192  BinaryOperatorKind Operator,
1193  SourceLocation EllipsisLoc, Expr *RHS,
1194  SourceLocation RParenLoc) {
1195  return new (Context) CXXFoldExpr(Context.DependentTy, LParenLoc, LHS,
1196  Operator, EllipsisLoc, RHS, RParenLoc);
1197 }
1198 
1200  BinaryOperatorKind Operator) {
1201  // [temp.variadic]p9:
1202  // If N is zero for a unary fold-expression, the value of the expression is
1203  // && -> true
1204  // || -> false
1205  // , -> void()
1206  // if the operator is not listed [above], the instantiation is ill-formed.
1207  //
1208  // Note that we need to use something like int() here, not merely 0, to
1209  // prevent the result from being a null pointer constant.
1210  QualType ScalarType;
1211  switch (Operator) {
1212  case BO_LOr:
1213  return ActOnCXXBoolLiteral(EllipsisLoc, tok::kw_false);
1214  case BO_LAnd:
1215  return ActOnCXXBoolLiteral(EllipsisLoc, tok::kw_true);
1216  case BO_Comma:
1217  ScalarType = Context.VoidTy;
1218  break;
1219 
1220  default:
1221  return Diag(EllipsisLoc, diag::err_fold_expression_empty)
1222  << BinaryOperator::getOpcodeStr(Operator);
1223  }
1224 
1225  return new (Context) CXXScalarValueInitExpr(
1226  ScalarType, Context.getTrivialTypeSourceInfo(ScalarType, EllipsisLoc),
1227  EllipsisLoc);
1228 }
ParsedType getTrailingReturnType() const
Get the trailing-return-type for this function declarator.
Definition: DeclSpec.h:1461
A call to an overloaded operator written using operator syntax.
Definition: ExprCXX.h:78
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
Represents a function declaration or definition.
Definition: Decl.h:1714
Name lookup found a set of overloaded functions that met the criteria.
Definition: Lookup.h:64
UnexpandedParameterPackContext
The context in which an unexpanded parameter pack is being diagnosed.
Definition: Sema.h:6553
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
ObjCDictionaryElement getKeyValueElement(unsigned Index) const
Definition: ExprObjC.h:344
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:497
PtrTy get() const
Definition: Ownership.h:81
A (possibly-)qualified type.
Definition: Type.h:655
Simple class containing the result of Sema::CorrectTypo.
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:404
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Definition: opencl-c.h:60
const DeclaratorChunk & getTypeObject(unsigned i) const
Return the specified TypeInfo from this declarator.
Definition: DeclSpec.h:2163
static std::pair< unsigned, unsigned > getDepthAndIndex(NamedDecl *ND)
Retrieve the depth and index of a parameter pack.
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:526
Stmt - This represents one statement.
Definition: Stmt.h:66
The template argument is an expression, and we&#39;ve not resolved it to one of the other forms yet...
Definition: TemplateBase.h:87
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition: Sema.h:1281
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Expr * getAsExpr() const
Retrieve the non-type template argument&#39;s expression.
bool isPackExpansion() const
Determine whether this is a pack expansion.
Definition: DeclCXX.h:3720
The base class of the type hierarchy.
Definition: Type.h:1428
One instance of this struct is used for each type in a declarator that is parsed. ...
Definition: DeclSpec.h:1134
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Definition: TemplateBase.h:64
A container of type source information.
Definition: Decl.h:86
bool isPackExpansion() const
Determine whether this capture is a pack expansion, which captures a function parameter pack...
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:26
bool isPackExpansion() const
Determine whether this initializer is a pack expansion.
Definition: DeclCXX.h:2349
Retains information about a function, method, or block that is currently being parsed.
Definition: ScopeInfo.h:96
unsigned getDepth() const
Get the nesting depth of the template parameter.
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1749
QualType getCXXNameType() const
getCXXNameType - If this name is one of the C++ names (of a constructor, destructor, or conversion function), return the type associated with that name.
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6519
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:57
void setBegin(SourceLocation b)
bool isParameterPack() const
Whether this declaration is a parameter pack.
Definition: DeclBase.cpp:211
unsigned getNumExceptions() const
Get the number of dynamic exception specifications.
Definition: DeclSpec.h:1444
Represents a parameter to a function.
Definition: Decl.h:1533
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:269
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:56
Expr * IgnoreImpCasts() LLVM_READONLY
IgnoreImpCasts - Skip past any implicit casts which might surround this expression.
Definition: Expr.h:2949
Expr * NoexceptExpr
Pointer to the expression in the noexcept-specifier of this function, if it has one.
Definition: DeclSpec.h:1328
One of these records is kept for each identifier that is lexed.
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
Definition: Lookup.h:74
TemplateArgument getPackExpansionPattern() const
When the template argument is a pack expansion, returns the pattern of the pack expansion.
An element in an Objective-C dictionary literal.
Definition: ExprObjC.h:239
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:330
A C++ nested-name-specifier augmented with source location information.
TypeSourceInfo * getTypeSourceInfo() const
Definition: TemplateBase.h:501
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:72
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
SourceLocation getLocation() const
Retrieve the location of the template argument.
SourceLocation getLocation() const
Definition: TemplateBase.h:482
const DeclarationNameInfo & getLookupNameInfo() const
Gets the name info to look up.
Definition: Lookup.h:231
Optional< unsigned > getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce...
Represents the result of substituting a set of types for a template type parameter pack...
Definition: Type.h:4466
A non-type template parameter, stored as an expression.
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...
LookupResultKind getResultKind() const
Definition: Lookup.h:310
ParsedType getAsType() const
Retrieve the template type argument&#39;s type.
No entity found met the criteria within the current instantiation,, but there were dependent base cla...
Definition: Lookup.h:56
StringRef getOpcodeStr() const
Definition: Expr.h:3129
BinaryOperatorKind
Represents the results of name lookup.
Definition: Lookup.h:47
PtrTy get() const
Definition: Ownership.h:174
bool DiagnoseUnexpandedParameterPacks(SourceLocation Loc, UnexpandedParameterPackContext UPPC, ArrayRef< UnexpandedParameterPack > Unexpanded)
Diagnose unexpanded parameter packs.
ArrayTypeInfo Arr
Definition: DeclSpec.h:1500
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:3279
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
Definition: DeclSpec.h:2159
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:1711
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:538
ExprResult ActOnCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS, tok::TokenKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc)
Handle a C++1z fold-expression: ( expr op ... op expr ).
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
unsigned getIndex() const
Get the index of the template parameter within its parameter list.
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:63
enum clang::DeclaratorChunk::@196 Kind
Optional< unsigned > getFullyPackExpandedSize(TemplateArgument Arg)
Given a template argument that contains an unexpanded parameter pack, but which has already been subs...
Expr * Key
The key for the dictionary element.
Definition: ExprObjC.h:241
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1584
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
NameKind getNameKind() const
getNameKind - Determine what kind of name this is.
Contains information about the compound statement currently being parsed.
Definition: ScopeInfo.h:66
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:277
bool containsUnexpandedParameterPack() const
Determines whether this template name contains an unexpanded parameter pack (for C++0x variadic templ...
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1042
SourceLocation getLocEnd() const LLVM_READONLY
Definition: Stmt.cpp:291
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
Definition: DeclSpec.h:1278
SourceLocation getLocation() const
Definition: Expr.h:1065
SourceRange getRange() const
Definition: DeclSpec.h:68
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location, which defaults to the empty location.
TST getTypeSpecType() const
Definition: DeclSpec.h:483
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type...
Definition: ExprCXX.h:1806
TypeSourceInfo * CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc, Optional< unsigned > NumExpansions)
Construct a pack expansion type from the pattern of the pack expansion.
Expr - This represents one expression.
Definition: Expr.h:106
bool containsUnexpandedParameterPacks(Declarator &D)
Determine whether the given declarator contains any unexpanded parameter packs.
bool isPackExpansion() const
Definition: Attr.h:105
Declaration of a template type parameter.
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:68
bool isPackExpansion() const
Determine whether this is a pack expansion.
Definition: DeclCXX.h:3630
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
Definition: ExprObjC.h:288
SourceLocation getBeginLoc() const
Definition: DeclSpec.h:72
SourceLocation getEllipsisLoc() const
Definition: TypeLoc.h:2245
TypeSourceInfo * getNamedTypeInfo() const
getNamedTypeInfo - Returns the source type info associated to the name.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
Represents a C++ template name within the type system.
Definition: TemplateName.h:178
Defines the clang::TypeLoc interface and its subclasses.
int Depth
Definition: ASTDiff.cpp:191
void setEllipsisLoc(SourceLocation Loc)
Definition: TypeLoc.h:2249
Represents a folding of a pack over an operator.
Definition: ExprCXX.h:4150
Data structure that captures multiple levels of template argument lists for use in template instantia...
Definition: Template.h:65
bool isInvalid() const
Definition: Ownership.h:170
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
ValueDecl * getDecl()
Definition: Expr.h:1057
The result type of a method or function.
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:720
ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, SourceLocation EllipsisLoc)
Invoked when parsing a template argument followed by an ellipsis, which creates a pack expansion...
static StringRef getIdentifier(const Token &Tok)
TypeAndRange * Exceptions
Pointer to a new[]&#39;d array of TypeAndRange objects that contain the types in the function&#39;s dynamic e...
Definition: DeclSpec.h:1324
NestedNameSpecifier * getScopeRep() const
Retrieve the representation of the nested-name-specifier.
Definition: DeclSpec.h:76
QualType getPackExpansionType(QualType Pattern, Optional< unsigned > NumExpansions)
const CXXScopeSpec & getScopeSpec() const
Retrieve the nested-name-specifier that precedes the template name in a template template argument...
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
static bool DiagnoseUnexpandedParameterPacks(Sema &S, TemplateTemplateParmDecl *TTP)
Check for unexpanded parameter packs within the template parameters of a template template parameter...
bool containsUnexpandedParameterPack() const
Whether this nested-name-specifier contains an unexpanded parameter pack (for C++11 variadic template...
TypeLoc getPatternLoc() const
Definition: TypeLoc.h:2261
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Definition: Ownership.h:157
Represents the parsed form of a C++ template argument.
Encodes a location in the source.
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:121
unsigned getNumElements() const
getNumElements - Return number of elements of objective-c dictionary literal.
Definition: ExprObjC.h:342
DeclarationName getName() const
getName - Returns the embedded declaration name.
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis that describes this pack expansion.
Definition: ExprCXX.h:3692
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, Optional< unsigned > Length=None, ArrayRef< TemplateArgument > PartialArgs=None)
Definition: ExprCXX.cpp:1312
FunctionTypeInfo Fun
Definition: DeclSpec.h:1501
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3576
KindType getKind() const
Determine what kind of template argument we have.
bool isPackExpansion() const
Determine whether this base specifier is a pack expansion.
Definition: DeclCXX.h:252
bool isParameterPack() const
Definition: Type.h:4374
Name lookup found an unresolvable value declaration and cannot yet complete.
Definition: Lookup.h:69
MemberPointerTypeInfo Mem
Definition: DeclSpec.h:1503
CanQualType VoidTy
Definition: ASTContext.h:998
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
bool hasTrailingReturnType() const
Determine whether this function declarator had a trailing-return-type.
Definition: DeclSpec.h:1458
No entity found met the criteria.
Definition: Lookup.h:51
A template type parameter, stored as a type.
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:110
Optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:5189
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:216
Expr * Value
The value of the dictionary element.
Definition: ExprObjC.h:244
Represents a pack expansion of types.
Definition: Type.h:5158
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:354
Represents a template argument.
Definition: TemplateBase.h:51
void collectUnexpandedParameterPacks(TemplateArgument Arg, SmallVectorImpl< UnexpandedParameterPack > &Unexpanded)
Collect the set of unexpanded parameter packs within the given template argument. ...
bool isNull() const
Determine whether this template name is NULL.
Dataflow Directional Tag Classes.
bool containsUnexpandedParameterPack() const
Whether this template argument contains an unexpanded parameter pack.
ParsedTemplateTy getAsTemplate() const
Retrieve the template template argument&#39;s template name.
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:493
QualType getType() const
Get the type for which this source info wrapper provides information.
Definition: TypeLoc.h:130
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:80
bool isInvalid() const
Determine whether the given template argument is invalid.
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3672
NamedDecl * getCorrectionDecl() const
Gets the pointer to the declaration of the typo correction.
NamedDecl * getFoundDecl() const
Fetch the unique decl found by this lookup.
Definition: Lookup.h:506
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:3656
static void CheckFoldOperand(Sema &S, Expr *E)
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
TemplateParameterList * getTemplateParameterList() const
If this is a generic lambda expression, retrieve the template parameter list associated with it...
Definition: ExprCXX.cpp:1007
ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, BinaryOperatorKind Operator)
bool isNull() const
Determine whether this template argument has no value.
Definition: TemplateBase.h:238
bool isValid() const
A scope specifier is present, and it refers to a real scope.
Definition: DeclSpec.h:196
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
Definition: TypeLoc.h:150
Name lookup found a single declaration that met the criteria.
Definition: Lookup.h:60
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:450
ParsedTemplateArgument getTemplatePackExpansion(SourceLocation EllipsisLoc) const
Retrieve a pack expansion of the given template template argument.
ExprResult BuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc)
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2250
CanQualType DependentTy
Definition: ASTContext.h:1027
unsigned getNumLevels() const
Determine the number of levels in this template argument list.
Definition: Template.h:89
The template argument is a type.
Definition: TemplateBase.h:60
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
Definition: Diagnostic.h:92
ExceptionSpecificationType getExceptionSpecType() const
Get the type of exception specification this function has.
Definition: DeclSpec.h:1439
Sema::LookupNameKind getLookupKind() const
Gets the kind of lookup to perform.
Definition: Lookup.h:251
The template argument is actually a parameter pack.
Definition: TemplateBase.h:91
Represents a base class of a C++ class.
Definition: DeclCXX.h:192
bool isUnexpandedParameterPackPermitted()
Determine whether an unexpanded parameter pack might be permitted in this location.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:239
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:235
unsigned getDepth() const
Definition: Type.h:4372
bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, UnexpandedParameterPackContext UPPC)
If the given type contains an unexpanded parameter pack, diagnose the error.
Captures information about "declaration specifiers".
Definition: DeclSpec.h:228
The template argument is a template name that was provided for a template template parameter...
Definition: TemplateBase.h:76
Expr * NumElts
This is the size of the array, or null if [] or [*] was specified.
Definition: DeclSpec.h:1198
bool isPackExpansion() const
Determines whether this dictionary element is a pack expansion.
Definition: ExprObjC.h:254
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
Definition: DeclSpec.h:1838
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates)...
Definition: Expr.h:214
Optional< unsigned > getNumExpansions() const
Determine the number of expansions that will be produced when this pack expansion is instantiated...
Definition: ExprCXX.h:3696
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:266
ParsedType getRepAsType() const
Definition: DeclSpec.h:492
SourceLocation getNameLoc() const
Definition: TypeLoc.h:518
Expr * getPattern()
Retrieve the pattern of the pack expansion.
Definition: ExprCXX.h:3685
ExprResult ExprError()
Definition: Ownership.h:283
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:257
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:972
Optional< unsigned > getNumArgumentsInExpansion(QualType T, const MultiLevelTemplateArgumentList &TemplateArgs)
Determine the number of arguments in the given pack expansion type.
__DEVICE__ int min(int __a, int __b)
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:532
SmallVector< CompoundScopeInfo, 4 > CompoundScopes
The stack of currently active compound stamement scopes in the function.
Definition: ScopeInfo.h:199
QualType getType() const
Definition: Decl.h:647
TemplateArgumentLoc getTemplateArgumentPackExpansionPattern(TemplateArgumentLoc OrigLoc, SourceLocation &Ellipsis, Optional< unsigned > &NumExpansions) const
Returns the pattern of the pack expansion for a template argument.
Wrapper for template type parameters.
Definition: TypeLoc.h:733
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
Definition: Decl.h:248
Expr * getRepAsExpr() const
Definition: DeclSpec.h:500
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type...
Definition: TypeLoc.h:75
A template template argument, stored as a template name.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:281
void pushFullCopy(TypeLoc L)
Pushes a copy of the given TypeLoc onto this builder.
ExprResult ActOnSizeofParameterPackExpr(Scope *S, SourceLocation OpLoc, IdentifierInfo &Name, SourceLocation NameLoc, SourceLocation RParenLoc)
Called when an expression computing the size of a parameter pack is parsed.
SourceLocation getLocStart() const LLVM_READONLY
Definition: Stmt.cpp:278
SourceLocation getBegin() const
ParamInfo * Params
Params - This is a pointer to a new[]&#39;d array of ParamInfo objects that describe the parameters speci...
Definition: DeclSpec.h:1318
Attr - This represents one attribute.
Definition: Attr.h:43
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:97