clang  6.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 /// \brief 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  /// \brief 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  /// \brief 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  /// \brief 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  /// \brief 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  /// \brief 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  /// \brief 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  /// \brief 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  /// \brief 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  /// \brief 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  /// \brief 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  /// \brief 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  /// \brief 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  /// \brief 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  /// \brief 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  /// \brief 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  /// \brief 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  /// \brief 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  /// \brief 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  /// \brief 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 /// \brief 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 /// \brief 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  if (sema::LambdaScopeInfo *LSI =
318  dyn_cast<sema::LambdaScopeInfo>(FunctionScopes[N-1])) {
319  if (N == FunctionScopes.size()) {
320  for (auto &Param : Unexpanded) {
321  auto *PD = dyn_cast_or_null<ParmVarDecl>(
322  Param.first.dyn_cast<NamedDecl *>());
323  if (PD && PD->getDeclContext() == LSI->CallOperator)
324  LambdaParamPackReferences.push_back(Param);
325  }
326  }
327 
328  // If we have references to a parameter pack of the innermost enclosing
329  // lambda, only diagnose those ones. We don't know whether any other
330  // unexpanded parameters referenced herein are actually unexpanded;
331  // they might be expanded at an outer level.
332  if (!LambdaParamPackReferences.empty()) {
333  Unexpanded = LambdaParamPackReferences;
334  break;
335  }
336 
337  LSI->ContainsUnexpandedParameterPack = true;
338  return false;
339  }
340  }
341 
344  llvm::SmallPtrSet<IdentifierInfo *, 4> NamesKnown;
345 
346  for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
347  IdentifierInfo *Name = nullptr;
348  if (const TemplateTypeParmType *TTP
349  = Unexpanded[I].first.dyn_cast<const TemplateTypeParmType *>())
350  Name = TTP->getIdentifier();
351  else
352  Name = Unexpanded[I].first.get<NamedDecl *>()->getIdentifier();
353 
354  if (Name && NamesKnown.insert(Name).second)
355  Names.push_back(Name);
356 
357  if (Unexpanded[I].second.isValid())
358  Locations.push_back(Unexpanded[I].second);
359  }
360 
361  DiagnosticBuilder DB = Diag(Loc, diag::err_unexpanded_parameter_pack)
362  << (int)UPPC << (int)Names.size();
363  for (size_t I = 0, E = std::min(Names.size(), (size_t)2); I != E; ++I)
364  DB << Names[I];
365 
366  for (unsigned I = 0, N = Locations.size(); I != N; ++I)
367  DB << SourceRange(Locations[I]);
368  return true;
369 }
370 
372  TypeSourceInfo *T,
374  // C++0x [temp.variadic]p5:
375  // An appearance of a name of a parameter pack that is not expanded is
376  // ill-formed.
378  return false;
379 
381  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(
382  T->getTypeLoc());
383  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
384  return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
385 }
386 
389  // C++0x [temp.variadic]p5:
390  // An appearance of a name of a parameter pack that is not expanded is
391  // ill-formed.
393  return false;
394 
396  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(E);
397  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
398  return DiagnoseUnexpandedParameterPacks(E->getLocStart(), UPPC, Unexpanded);
399 }
400 
403  // C++0x [temp.variadic]p5:
404  // An appearance of a name of a parameter pack that is not expanded is
405  // ill-formed.
406  if (!SS.getScopeRep() ||
408  return false;
409 
411  CollectUnexpandedParameterPacksVisitor(Unexpanded)
412  .TraverseNestedNameSpecifier(SS.getScopeRep());
413  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
415  UPPC, Unexpanded);
416 }
417 
420  // C++0x [temp.variadic]p5:
421  // An appearance of a name of a parameter pack that is not expanded is
422  // ill-formed.
423  switch (NameInfo.getName().getNameKind()) {
432  return false;
433 
437  // FIXME: We shouldn't need this null check!
438  if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
439  return DiagnoseUnexpandedParameterPack(NameInfo.getLoc(), TSInfo, UPPC);
440 
442  return false;
443 
444  break;
445  }
446 
448  CollectUnexpandedParameterPacksVisitor(Unexpanded)
449  .TraverseType(NameInfo.getName().getCXXNameType());
450  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
451  return DiagnoseUnexpandedParameterPacks(NameInfo.getLoc(), UPPC, Unexpanded);
452 }
453 
455  TemplateName Template,
457 
458  if (Template.isNull() || !Template.containsUnexpandedParameterPack())
459  return false;
460 
462  CollectUnexpandedParameterPacksVisitor(Unexpanded)
463  .TraverseTemplateName(Template);
464  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
465  return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
466 }
467 
470  if (Arg.getArgument().isNull() ||
472  return false;
473 
475  CollectUnexpandedParameterPacksVisitor(Unexpanded)
476  .TraverseTemplateArgumentLoc(Arg);
477  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
478  return DiagnoseUnexpandedParameterPacks(Arg.getLocation(), UPPC, Unexpanded);
479 }
480 
483  CollectUnexpandedParameterPacksVisitor(Unexpanded)
484  .TraverseTemplateArgument(Arg);
485 }
486 
489  CollectUnexpandedParameterPacksVisitor(Unexpanded)
490  .TraverseTemplateArgumentLoc(Arg);
491 }
492 
495  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(T);
496 }
497 
500  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(TL);
501 }
502 
506  CollectUnexpandedParameterPacksVisitor(Unexpanded)
507  .TraverseNestedNameSpecifierLoc(NNS);
508 }
509 
511  const DeclarationNameInfo &NameInfo,
513  CollectUnexpandedParameterPacksVisitor(Unexpanded)
514  .TraverseDeclarationNameInfo(NameInfo);
515 }
516 
517 
520  SourceLocation EllipsisLoc) {
521  if (Arg.isInvalid())
522  return Arg;
523 
524  switch (Arg.getKind()) {
526  TypeResult Result = ActOnPackExpansion(Arg.getAsType(), EllipsisLoc);
527  if (Result.isInvalid())
528  return ParsedTemplateArgument();
529 
530  return ParsedTemplateArgument(Arg.getKind(), Result.get().getAsOpaquePtr(),
531  Arg.getLocation());
532  }
533 
535  ExprResult Result = ActOnPackExpansion(Arg.getAsExpr(), EllipsisLoc);
536  if (Result.isInvalid())
537  return ParsedTemplateArgument();
538 
539  return ParsedTemplateArgument(Arg.getKind(), Result.get(),
540  Arg.getLocation());
541  }
542 
545  SourceRange R(Arg.getLocation());
546  if (Arg.getScopeSpec().isValid())
547  R.setBegin(Arg.getScopeSpec().getBeginLoc());
548  Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
549  << R;
550  return ParsedTemplateArgument();
551  }
552 
553  return Arg.getTemplatePackExpansion(EllipsisLoc);
554  }
555  llvm_unreachable("Unhandled template argument kind?");
556 }
557 
559  SourceLocation EllipsisLoc) {
560  TypeSourceInfo *TSInfo;
561  GetTypeFromParser(Type, &TSInfo);
562  if (!TSInfo)
563  return true;
564 
565  TypeSourceInfo *TSResult = CheckPackExpansion(TSInfo, EllipsisLoc, None);
566  if (!TSResult)
567  return true;
568 
569  return CreateParsedType(TSResult->getType(), TSResult);
570 }
571 
574  Optional<unsigned> NumExpansions) {
575  // Create the pack expansion type and source-location information.
576  QualType Result = CheckPackExpansion(Pattern->getType(),
577  Pattern->getTypeLoc().getSourceRange(),
578  EllipsisLoc, NumExpansions);
579  if (Result.isNull())
580  return nullptr;
581 
582  TypeLocBuilder TLB;
583  TLB.pushFullCopy(Pattern->getTypeLoc());
585  TL.setEllipsisLoc(EllipsisLoc);
586 
587  return TLB.getTypeSourceInfo(Context, Result);
588 }
589 
591  SourceLocation EllipsisLoc,
592  Optional<unsigned> NumExpansions) {
593  // C++0x [temp.variadic]p5:
594  // The pattern of a pack expansion shall name one or more
595  // parameter packs that are not expanded by a nested pack
596  // expansion.
597  if (!Pattern->containsUnexpandedParameterPack()) {
598  Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
599  << PatternRange;
600  return QualType();
601  }
602 
603  return Context.getPackExpansionType(Pattern, NumExpansions);
604 }
605 
607  return CheckPackExpansion(Pattern, EllipsisLoc, None);
608 }
609 
611  Optional<unsigned> NumExpansions) {
612  if (!Pattern)
613  return ExprError();
614 
615  // C++0x [temp.variadic]p5:
616  // The pattern of a pack expansion shall name one or more
617  // parameter packs that are not expanded by a nested pack
618  // expansion.
619  if (!Pattern->containsUnexpandedParameterPack()) {
620  Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
621  << Pattern->getSourceRange();
622  return ExprError();
623  }
624 
625  // Create the pack expansion expression and source-location information.
626  return new (Context)
627  PackExpansionExpr(Context.DependentTy, Pattern, EllipsisLoc, NumExpansions);
628 }
629 
631  SourceLocation EllipsisLoc, SourceRange PatternRange,
633  const MultiLevelTemplateArgumentList &TemplateArgs, bool &ShouldExpand,
634  bool &RetainExpansion, Optional<unsigned> &NumExpansions) {
635  ShouldExpand = true;
636  RetainExpansion = false;
637  std::pair<IdentifierInfo *, SourceLocation> FirstPack;
638  bool HaveFirstPack = false;
639 
640  for (ArrayRef<UnexpandedParameterPack>::iterator i = Unexpanded.begin(),
641  end = Unexpanded.end();
642  i != end; ++i) {
643  // Compute the depth and index for this parameter pack.
644  unsigned Depth = 0, Index = 0;
645  IdentifierInfo *Name;
646  bool IsFunctionParameterPack = false;
647 
648  if (const TemplateTypeParmType *TTP
649  = i->first.dyn_cast<const TemplateTypeParmType *>()) {
650  Depth = TTP->getDepth();
651  Index = TTP->getIndex();
652  Name = TTP->getIdentifier();
653  } else {
654  NamedDecl *ND = i->first.get<NamedDecl *>();
655  if (isa<ParmVarDecl>(ND))
656  IsFunctionParameterPack = true;
657  else
658  std::tie(Depth, Index) = getDepthAndIndex(ND);
659 
660  Name = ND->getIdentifier();
661  }
662 
663  // Determine the size of this argument pack.
664  unsigned NewPackSize;
665  if (IsFunctionParameterPack) {
666  // Figure out whether we're instantiating to an argument pack or not.
667  typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
668 
669  llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation
670  = CurrentInstantiationScope->findInstantiationOf(
671  i->first.get<NamedDecl *>());
672  if (Instantiation->is<DeclArgumentPack *>()) {
673  // We could expand this function parameter pack.
674  NewPackSize = Instantiation->get<DeclArgumentPack *>()->size();
675  } else {
676  // We can't expand this function parameter pack, so we can't expand
677  // the pack expansion.
678  ShouldExpand = false;
679  continue;
680  }
681  } else {
682  // If we don't have a template argument at this depth/index, then we
683  // cannot expand the pack expansion. Make a note of this, but we still
684  // want to check any parameter packs we *do* have arguments for.
685  if (Depth >= TemplateArgs.getNumLevels() ||
686  !TemplateArgs.hasTemplateArgument(Depth, Index)) {
687  ShouldExpand = false;
688  continue;
689  }
690 
691  // Determine the size of the argument pack.
692  NewPackSize = TemplateArgs(Depth, Index).pack_size();
693  }
694 
695  // C++0x [temp.arg.explicit]p9:
696  // Template argument deduction can extend the sequence of template
697  // arguments corresponding to a template parameter pack, even when the
698  // sequence contains explicitly specified template arguments.
699  if (!IsFunctionParameterPack && CurrentInstantiationScope) {
700  if (NamedDecl *PartialPack
701  = CurrentInstantiationScope->getPartiallySubstitutedPack()){
702  unsigned PartialDepth, PartialIndex;
703  std::tie(PartialDepth, PartialIndex) = getDepthAndIndex(PartialPack);
704  if (PartialDepth == Depth && PartialIndex == Index)
705  RetainExpansion = true;
706  }
707  }
708 
709  if (!NumExpansions) {
710  // The is the first pack we've seen for which we have an argument.
711  // Record it.
712  NumExpansions = NewPackSize;
713  FirstPack.first = Name;
714  FirstPack.second = i->second;
715  HaveFirstPack = true;
716  continue;
717  }
718 
719  if (NewPackSize != *NumExpansions) {
720  // C++0x [temp.variadic]p5:
721  // All of the parameter packs expanded by a pack expansion shall have
722  // the same number of arguments specified.
723  if (HaveFirstPack)
724  Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict)
725  << FirstPack.first << Name << *NumExpansions << NewPackSize
726  << SourceRange(FirstPack.second) << SourceRange(i->second);
727  else
728  Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_multilevel)
729  << Name << *NumExpansions << NewPackSize
730  << SourceRange(i->second);
731  return true;
732  }
733  }
734 
735  return false;
736 }
737 
739  const MultiLevelTemplateArgumentList &TemplateArgs) {
740  QualType Pattern = cast<PackExpansionType>(T)->getPattern();
742  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(Pattern);
743 
745  for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
746  // Compute the depth and index for this parameter pack.
747  unsigned Depth;
748  unsigned Index;
749 
750  if (const TemplateTypeParmType *TTP
751  = Unexpanded[I].first.dyn_cast<const TemplateTypeParmType *>()) {
752  Depth = TTP->getDepth();
753  Index = TTP->getIndex();
754  } else {
755  NamedDecl *ND = Unexpanded[I].first.get<NamedDecl *>();
756  if (isa<ParmVarDecl>(ND)) {
757  // Function parameter pack.
758  typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
759 
760  llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation
761  = CurrentInstantiationScope->findInstantiationOf(
762  Unexpanded[I].first.get<NamedDecl *>());
763  if (Instantiation->is<Decl*>())
764  // The pattern refers to an unexpanded pack. We're not ready to expand
765  // this pack yet.
766  return None;
767 
768  unsigned Size = Instantiation->get<DeclArgumentPack *>()->size();
769  assert((!Result || *Result == Size) && "inconsistent pack sizes");
770  Result = Size;
771  continue;
772  }
773 
774  std::tie(Depth, Index) = getDepthAndIndex(ND);
775  }
776  if (Depth >= TemplateArgs.getNumLevels() ||
777  !TemplateArgs.hasTemplateArgument(Depth, Index))
778  // The pattern refers to an unknown template argument. We're not ready to
779  // expand this pack yet.
780  return None;
781 
782  // Determine the size of the argument pack.
783  unsigned Size = TemplateArgs(Depth, Index).pack_size();
784  assert((!Result || *Result == Size) && "inconsistent pack sizes");
785  Result = Size;
786  }
787 
788  return Result;
789 }
790 
792  const DeclSpec &DS = D.getDeclSpec();
793  switch (DS.getTypeSpecType()) {
794  case TST_typename:
795  case TST_typeofType:
796  case TST_underlyingType:
797  case TST_atomic: {
798  QualType T = DS.getRepAsType().get();
799  if (!T.isNull() && T->containsUnexpandedParameterPack())
800  return true;
801  break;
802  }
803 
804  case TST_typeofExpr:
805  case TST_decltype:
806  if (DS.getRepAsExpr() &&
808  return true;
809  break;
810 
811  case TST_unspecified:
812  case TST_void:
813  case TST_char:
814  case TST_wchar:
815  case TST_char16:
816  case TST_char32:
817  case TST_int:
818  case TST_int128:
819  case TST_half:
820  case TST_float:
821  case TST_double:
822  case TST_Float16:
823  case TST_float128:
824  case TST_bool:
825  case TST_decimal32:
826  case TST_decimal64:
827  case TST_decimal128:
828  case TST_enum:
829  case TST_union:
830  case TST_struct:
831  case TST_interface:
832  case TST_class:
833  case TST_auto:
834  case TST_auto_type:
835  case TST_decltype_auto:
836 #define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t:
837 #include "clang/Basic/OpenCLImageTypes.def"
838  case TST_unknown_anytype:
839  case TST_error:
840  break;
841  }
842 
843  for (unsigned I = 0, N = D.getNumTypeObjects(); I != N; ++I) {
844  const DeclaratorChunk &Chunk = D.getTypeObject(I);
845  switch (Chunk.Kind) {
851  // These declarator chunks cannot contain any parameter packs.
852  break;
853 
855  if (Chunk.Arr.NumElts &&
857  return true;
858  break;
860  for (unsigned i = 0, e = Chunk.Fun.NumParams; i != e; ++i) {
861  ParmVarDecl *Param = cast<ParmVarDecl>(Chunk.Fun.Params[i].Param);
862  QualType ParamTy = Param->getType();
863  assert(!ParamTy.isNull() && "Couldn't parse type?");
864  if (ParamTy->containsUnexpandedParameterPack()) return true;
865  }
866 
867  if (Chunk.Fun.getExceptionSpecType() == EST_Dynamic) {
868  for (unsigned i = 0; i != Chunk.Fun.getNumExceptions(); ++i) {
869  if (Chunk.Fun.Exceptions[i]
870  .Ty.get()
872  return true;
873  }
874  } else if (Chunk.Fun.getExceptionSpecType() == EST_ComputedNoexcept &&
876  return true;
877 
878  if (Chunk.Fun.hasTrailingReturnType()) {
879  QualType T = Chunk.Fun.getTrailingReturnType().get();
880  if (!T.isNull() && T->containsUnexpandedParameterPack())
881  return true;
882  }
883  break;
884 
886  if (Chunk.Mem.Scope().getScopeRep() &&
888  return true;
889  break;
890  }
891  }
892 
893  return false;
894 }
895 
896 namespace {
897 
898 // Callback to only accept typo corrections that refer to parameter packs.
899 class ParameterPackValidatorCCC : public CorrectionCandidateCallback {
900  public:
901  bool ValidateCandidate(const TypoCorrection &candidate) override {
902  NamedDecl *ND = candidate.getCorrectionDecl();
903  return ND && ND->isParameterPack();
904  }
905 };
906 
907 }
908 
909 /// \brief Called when an expression computing the size of a parameter pack
910 /// is parsed.
911 ///
912 /// \code
913 /// template<typename ...Types> struct count {
914 /// static const unsigned value = sizeof...(Types);
915 /// };
916 /// \endcode
917 ///
918 //
919 /// \param OpLoc The location of the "sizeof" keyword.
920 /// \param Name The name of the parameter pack whose size will be determined.
921 /// \param NameLoc The source location of the name of the parameter pack.
922 /// \param RParenLoc The location of the closing parentheses.
924  SourceLocation OpLoc,
925  IdentifierInfo &Name,
926  SourceLocation NameLoc,
927  SourceLocation RParenLoc) {
928  // C++0x [expr.sizeof]p5:
929  // The identifier in a sizeof... expression shall name a parameter pack.
930  LookupResult R(*this, &Name, NameLoc, LookupOrdinaryName);
931  LookupName(R, S);
932 
933  NamedDecl *ParameterPack = nullptr;
934  switch (R.getResultKind()) {
935  case LookupResult::Found:
936  ParameterPack = R.getFoundDecl();
937  break;
938 
941  if (TypoCorrection Corrected =
942  CorrectTypo(R.getLookupNameInfo(), R.getLookupKind(), S, nullptr,
943  llvm::make_unique<ParameterPackValidatorCCC>(),
944  CTK_ErrorRecovery)) {
945  diagnoseTypo(Corrected,
946  PDiag(diag::err_sizeof_pack_no_pack_name_suggest) << &Name,
947  PDiag(diag::note_parameter_pack_here));
948  ParameterPack = Corrected.getCorrectionDecl();
949  }
950 
953  break;
954 
956  DiagnoseAmbiguousLookup(R);
957  return ExprError();
958  }
959 
960  if (!ParameterPack || !ParameterPack->isParameterPack()) {
961  Diag(NameLoc, diag::err_sizeof_pack_no_pack_name)
962  << &Name;
963  return ExprError();
964  }
965 
966  MarkAnyDeclReferenced(OpLoc, ParameterPack, true);
967 
968  return SizeOfPackExpr::Create(Context, OpLoc, ParameterPack, NameLoc,
969  RParenLoc);
970 }
971 
974  TemplateArgumentLoc OrigLoc,
975  SourceLocation &Ellipsis, Optional<unsigned> &NumExpansions) const {
976  const TemplateArgument &Argument = OrigLoc.getArgument();
977  assert(Argument.isPackExpansion());
978  switch (Argument.getKind()) {
979  case TemplateArgument::Type: {
980  // FIXME: We shouldn't ever have to worry about missing
981  // type-source info!
982  TypeSourceInfo *ExpansionTSInfo = OrigLoc.getTypeSourceInfo();
983  if (!ExpansionTSInfo)
984  ExpansionTSInfo = Context.getTrivialTypeSourceInfo(Argument.getAsType(),
985  Ellipsis);
986  PackExpansionTypeLoc Expansion =
987  ExpansionTSInfo->getTypeLoc().castAs<PackExpansionTypeLoc>();
988  Ellipsis = Expansion.getEllipsisLoc();
989 
990  TypeLoc Pattern = Expansion.getPatternLoc();
991  NumExpansions = Expansion.getTypePtr()->getNumExpansions();
992 
993  // We need to copy the TypeLoc because TemplateArgumentLocs store a
994  // TypeSourceInfo.
995  // FIXME: Find some way to avoid the copy?
996  TypeLocBuilder TLB;
997  TLB.pushFullCopy(Pattern);
998  TypeSourceInfo *PatternTSInfo =
999  TLB.getTypeSourceInfo(Context, Pattern.getType());
1000  return TemplateArgumentLoc(TemplateArgument(Pattern.getType()),
1001  PatternTSInfo);
1002  }
1003 
1005  PackExpansionExpr *Expansion
1006  = cast<PackExpansionExpr>(Argument.getAsExpr());
1007  Expr *Pattern = Expansion->getPattern();
1008  Ellipsis = Expansion->getEllipsisLoc();
1009  NumExpansions = Expansion->getNumExpansions();
1010  return TemplateArgumentLoc(Pattern, Pattern);
1011  }
1012 
1014  Ellipsis = OrigLoc.getTemplateEllipsisLoc();
1015  NumExpansions = Argument.getNumTemplateExpansions();
1016  return TemplateArgumentLoc(Argument.getPackExpansionPattern(),
1017  OrigLoc.getTemplateQualifierLoc(),
1018  OrigLoc.getTemplateNameLoc());
1019 
1026  return TemplateArgumentLoc();
1027  }
1028 
1029  llvm_unreachable("Invalid TemplateArgument Kind!");
1030 }
1031 
1033  assert(Arg.containsUnexpandedParameterPack());
1034 
1035  // If this is a substituted pack, grab that pack. If not, we don't know
1036  // the size yet.
1037  // FIXME: We could find a size in more cases by looking for a substituted
1038  // pack anywhere within this argument, but that's not necessary in the common
1039  // case for 'sizeof...(A)' handling.
1040  TemplateArgument Pack;
1041  switch (Arg.getKind()) {
1043  if (auto *Subst = Arg.getAsType()->getAs<SubstTemplateTypeParmPackType>())
1044  Pack = Subst->getArgumentPack();
1045  else
1046  return None;
1047  break;
1048 
1050  if (auto *Subst =
1051  dyn_cast<SubstNonTypeTemplateParmPackExpr>(Arg.getAsExpr()))
1052  Pack = Subst->getArgumentPack();
1053  else if (auto *Subst = dyn_cast<FunctionParmPackExpr>(Arg.getAsExpr())) {
1054  for (ParmVarDecl *PD : *Subst)
1055  if (PD->isParameterPack())
1056  return None;
1057  return Subst->getNumExpansions();
1058  } else
1059  return None;
1060  break;
1061 
1065  Pack = Subst->getArgumentPack();
1066  else
1067  return None;
1068  break;
1069 
1076  return None;
1077  }
1078 
1079  // Check that no argument in the pack is itself a pack expansion.
1080  for (TemplateArgument Elem : Pack.pack_elements()) {
1081  // There's no point recursing in this case; we would have already
1082  // expanded this pack expansion into the enclosing pack if we could.
1083  if (Elem.isPackExpansion())
1084  return None;
1085  }
1086  return Pack.pack_size();
1087 }
1088 
1089 static void CheckFoldOperand(Sema &S, Expr *E) {
1090  if (!E)
1091  return;
1092 
1093  E = E->IgnoreImpCasts();
1094  auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
1095  if ((OCE && OCE->isInfixBinaryOp()) || isa<BinaryOperator>(E) ||
1096  isa<AbstractConditionalOperator>(E)) {
1097  S.Diag(E->getExprLoc(), diag::err_fold_expression_bad_operand)
1098  << E->getSourceRange()
1100  << FixItHint::CreateInsertion(E->getLocEnd(), ")");
1101  }
1102 }
1103 
1105  tok::TokenKind Operator,
1106  SourceLocation EllipsisLoc, Expr *RHS,
1107  SourceLocation RParenLoc) {
1108  // LHS and RHS must be cast-expressions. We allow an arbitrary expression
1109  // in the parser and reduce down to just cast-expressions here.
1110  CheckFoldOperand(*this, LHS);
1111  CheckFoldOperand(*this, RHS);
1112 
1113  auto DiscardOperands = [&] {
1114  CorrectDelayedTyposInExpr(LHS);
1115  CorrectDelayedTyposInExpr(RHS);
1116  };
1117 
1118  // [expr.prim.fold]p3:
1119  // In a binary fold, op1 and op2 shall be the same fold-operator, and
1120  // either e1 shall contain an unexpanded parameter pack or e2 shall contain
1121  // an unexpanded parameter pack, but not both.
1122  if (LHS && RHS &&
1125  DiscardOperands();
1126  return Diag(EllipsisLoc,
1128  ? diag::err_fold_expression_packs_both_sides
1129  : diag::err_pack_expansion_without_parameter_packs)
1130  << LHS->getSourceRange() << RHS->getSourceRange();
1131  }
1132 
1133  // [expr.prim.fold]p2:
1134  // In a unary fold, the cast-expression shall contain an unexpanded
1135  // parameter pack.
1136  if (!LHS || !RHS) {
1137  Expr *Pack = LHS ? LHS : RHS;
1138  assert(Pack && "fold expression with neither LHS nor RHS");
1139  DiscardOperands();
1140  if (!Pack->containsUnexpandedParameterPack())
1141  return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
1142  << Pack->getSourceRange();
1143  }
1144 
1145  BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
1146  return BuildCXXFoldExpr(LParenLoc, LHS, Opc, EllipsisLoc, RHS, RParenLoc);
1147 }
1148 
1150  BinaryOperatorKind Operator,
1151  SourceLocation EllipsisLoc, Expr *RHS,
1152  SourceLocation RParenLoc) {
1153  return new (Context) CXXFoldExpr(Context.DependentTy, LParenLoc, LHS,
1154  Operator, EllipsisLoc, RHS, RParenLoc);
1155 }
1156 
1158  BinaryOperatorKind Operator) {
1159  // [temp.variadic]p9:
1160  // If N is zero for a unary fold-expression, the value of the expression is
1161  // && -> true
1162  // || -> false
1163  // , -> void()
1164  // if the operator is not listed [above], the instantiation is ill-formed.
1165  //
1166  // Note that we need to use something like int() here, not merely 0, to
1167  // prevent the result from being a null pointer constant.
1168  QualType ScalarType;
1169  switch (Operator) {
1170  case BO_LOr:
1171  return ActOnCXXBoolLiteral(EllipsisLoc, tok::kw_false);
1172  case BO_LAnd:
1173  return ActOnCXXBoolLiteral(EllipsisLoc, tok::kw_true);
1174  case BO_Comma:
1175  ScalarType = Context.VoidTy;
1176  break;
1177 
1178  default:
1179  return Diag(EllipsisLoc, diag::err_fold_expression_empty)
1180  << BinaryOperator::getOpcodeStr(Operator);
1181  }
1182 
1183  return new (Context) CXXScalarValueInitExpr(
1184  ScalarType, Context.getTrivialTypeSourceInfo(ScalarType, EllipsisLoc),
1185  EllipsisLoc);
1186 }
ParsedType getTrailingReturnType() const
Get the trailing-return-type for this function declarator.
Definition: DeclSpec.h:1449
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.
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1698
Name lookup found a set of overloaded functions that met the criteria.
Definition: Lookup.h:49
UnexpandedParameterPackContext
The context in which an unexpanded parameter pack is being diagnosed.
Definition: Sema.h:6482
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:74
A (possibly-)qualified type.
Definition: Type.h:653
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:2143
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:1270
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:3638
The base class of the type hierarchy.
Definition: Type.h:1353
One instance of this struct is used for each type in a declarator that is parsed. ...
Definition: DeclSpec.h:1120
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:2271
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:1720
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:6307
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:213
unsigned getNumExceptions() const
Get the number of dynamic exception specifications.
Definition: DeclSpec.h:1432
ParmVarDecl - Represents a parameter to a function.
Definition: Decl.h:1514
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
Definition: Decl.h:265
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:2865
Expr * NoexceptExpr
Pointer to the expression in the noexcept-specifier of this function, if it has one.
Definition: DeclSpec.h:1316
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:59
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
Fetches the primary location of the argument.
Definition: TemplateBase.h:482
const DeclarationNameInfo & getLookupNameInfo() const
Gets the name info to look up.
Definition: Lookup.h:245
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:4314
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:324
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:41
StringRef getOpcodeStr() const
Definition: Expr.h:3045
BinaryOperatorKind
Represents the results of name lookup.
Definition: Lookup.h:32
PtrTy get() const
Definition: Ownership.h:162
bool DiagnoseUnexpandedParameterPacks(SourceLocation Loc, UnexpandedParameterPackContext UPPC, ArrayRef< UnexpandedParameterPack > Unexpanded)
Diagnose unexpanded parameter packs.
ArrayTypeInfo Arr
Definition: DeclSpec.h:1489
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:3222
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
Definition: DeclSpec.h:2139
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:1635
enum clang::DeclaratorChunk::@198 Kind
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:39
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
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:1580
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.
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:274
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:955
SourceLocation getLocEnd() const LLVM_READONLY
Definition: Stmt.cpp:290
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
Definition: DeclSpec.h:1266
SourceLocation getLocation() const
Definition: Expr.h:1049
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:477
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type...
Definition: ExprCXX.h:1802
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:103
const FunctionProtoType * T
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:3548
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:2242
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
char __ovld __cnfn min(char x, char y)
Returns y if y < x, otherwise it returns x.
Defines the clang::TypeLoc interface and its subclasses.
int Depth
Definition: ASTDiff.cpp:191
void setEllipsisLoc(SourceLocation Loc)
Definition: TypeLoc.h:2246
Represents a folding of a pack over an operator.
Definition: ExprCXX.h:4145
Data structure that captures multiple levels of template argument lists for use in template instantia...
Definition: Template.h:42
bool isInvalid() const
Definition: Ownership.h:158
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:1041
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:719
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:1312
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...
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:2258
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Definition: Ownership.h:144
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:3688
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, Optional< unsigned > Length=None, ArrayRef< TemplateArgument > PartialArgs=None)
Definition: ExprCXX.cpp:1313
FunctionTypeInfo Fun
Definition: DeclSpec.h:1490
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3494
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:251
bool isParameterPack() const
Definition: Type.h:4222
Name lookup found an unresolvable value declaration and cannot yet complete.
Definition: Lookup.h:54
MemberPointerTypeInfo Mem
Definition: DeclSpec.h:1492
CanQualType VoidTy
Definition: ASTContext.h:996
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:1446
No entity found met the criteria.
Definition: Lookup.h:36
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:87
Optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:5027
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:4996
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:3590
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:520
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:3652
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:1008
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:45
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:2172
CanQualType DependentTy
Definition: ASTContext.h:1013
unsigned getNumLevels() const
Determine the number of levels in this template argument list.
Definition: Template.h:66
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:90
ExceptionSpecificationType getExceptionSpecType() const
Get the type of exception specification this function has.
Definition: DeclSpec.h:1427
Sema::LookupNameKind getLookupKind() const
Gets the kind of lookup to perform.
Definition: Lookup.h:265
The template argument is actually a parameter pack.
Definition: TemplateBase.h:91
Represents a base class of a C++ class.
Definition: DeclCXX.h:191
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:4220
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:1186
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:1836
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:3692
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:265
ParsedType getRepAsType() const
Definition: DeclSpec.h:485
SourceLocation getNameLoc() const
Definition: TypeLoc.h:518
Expr * getPattern()
Retrieve the pattern of the pack expansion.
Definition: ExprCXX.h:3681
ExprResult ExprError()
Definition: Ownership.h:267
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:956
Optional< unsigned > getNumArgumentsInExpansion(QualType T, const MultiLevelTemplateArgumentList &TemplateArgs)
Determine the number of arguments in the given pack expansion type.
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:532
QualType getType() const
Definition: Decl.h:639
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.
NamedDecl - This represents a decl with a name.
Definition: Decl.h:245
Expr * getRepAsExpr() const
Definition: DeclSpec.h:493
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:277
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:1306
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