clang  8.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 namespace {
30  /// A class that collects unexpanded parameter packs.
31  class CollectUnexpandedParameterPacksVisitor :
32  public RecursiveASTVisitor<CollectUnexpandedParameterPacksVisitor>
33  {
35  inherited;
36 
38 
39  bool InLambda = false;
40  unsigned DepthLimit = (unsigned)-1;
41 
42  void addUnexpanded(NamedDecl *ND, SourceLocation Loc = SourceLocation()) {
43  if (auto *PVD = dyn_cast<ParmVarDecl>(ND)) {
44  // For now, the only problematic case is a generic lambda's templated
45  // call operator, so we don't need to look for all the other ways we
46  // could have reached a dependent parameter pack.
47  auto *FD = dyn_cast<FunctionDecl>(PVD->getDeclContext());
48  auto *FTD = FD ? FD->getDescribedFunctionTemplate() : nullptr;
49  if (FTD && FTD->getTemplateParameters()->getDepth() >= DepthLimit)
50  return;
51  } else if (getDepthAndIndex(ND).first >= DepthLimit)
52  return;
53 
54  Unexpanded.push_back({ND, Loc});
55  }
56  void addUnexpanded(const TemplateTypeParmType *T,
58  if (T->getDepth() < DepthLimit)
59  Unexpanded.push_back({T, Loc});
60  }
61 
62  public:
63  explicit CollectUnexpandedParameterPacksVisitor(
65  : Unexpanded(Unexpanded) {}
66 
67  bool shouldWalkTypesOfTypeLocs() const { return false; }
68 
69  //------------------------------------------------------------------------
70  // Recording occurrences of (unexpanded) parameter packs.
71  //------------------------------------------------------------------------
72 
73  /// Record occurrences of template type parameter packs.
74  bool VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
75  if (TL.getTypePtr()->isParameterPack())
76  addUnexpanded(TL.getTypePtr(), TL.getNameLoc());
77  return true;
78  }
79 
80  /// Record occurrences of template type parameter packs
81  /// when we don't have proper source-location information for
82  /// them.
83  ///
84  /// Ideally, this routine would never be used.
85  bool VisitTemplateTypeParmType(TemplateTypeParmType *T) {
86  if (T->isParameterPack())
87  addUnexpanded(T);
88 
89  return true;
90  }
91 
92  /// Record occurrences of function and non-type template
93  /// parameter packs in an expression.
94  bool VisitDeclRefExpr(DeclRefExpr *E) {
95  if (E->getDecl()->isParameterPack())
96  addUnexpanded(E->getDecl(), E->getLocation());
97 
98  return true;
99  }
100 
101  /// Record occurrences of template template parameter packs.
102  bool TraverseTemplateName(TemplateName Template) {
103  if (auto *TTP = dyn_cast_or_null<TemplateTemplateParmDecl>(
104  Template.getAsTemplateDecl())) {
105  if (TTP->isParameterPack())
106  addUnexpanded(TTP);
107  }
108 
109  return inherited::TraverseTemplateName(Template);
110  }
111 
112  /// Suppress traversal into Objective-C container literal
113  /// elements that are pack expansions.
114  bool TraverseObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
116  return true;
117 
118  for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
120  if (Element.isPackExpansion())
121  continue;
122 
123  TraverseStmt(Element.Key);
124  TraverseStmt(Element.Value);
125  }
126  return true;
127  }
128  //------------------------------------------------------------------------
129  // Pruning the search for unexpanded parameter packs.
130  //------------------------------------------------------------------------
131 
132  /// Suppress traversal into statements and expressions that
133  /// do not contain unexpanded parameter packs.
134  bool TraverseStmt(Stmt *S) {
135  Expr *E = dyn_cast_or_null<Expr>(S);
136  if ((E && E->containsUnexpandedParameterPack()) || InLambda)
137  return inherited::TraverseStmt(S);
138 
139  return true;
140  }
141 
142  /// Suppress traversal into types that do not contain
143  /// unexpanded parameter packs.
144  bool TraverseType(QualType T) {
145  if ((!T.isNull() && T->containsUnexpandedParameterPack()) || InLambda)
146  return inherited::TraverseType(T);
147 
148  return true;
149  }
150 
151  /// Suppress traversal into types with location information
152  /// that do not contain unexpanded parameter packs.
153  bool TraverseTypeLoc(TypeLoc TL) {
154  if ((!TL.getType().isNull() &&
156  InLambda)
157  return inherited::TraverseTypeLoc(TL);
158 
159  return true;
160  }
161 
162  /// Suppress traversal of parameter packs.
163  bool TraverseDecl(Decl *D) {
164  // A function parameter pack is a pack expansion, so cannot contain
165  // an unexpanded parameter pack. Likewise for a template parameter
166  // pack that contains any references to other packs.
167  if (D->isParameterPack())
168  return true;
169 
170  return inherited::TraverseDecl(D);
171  }
172 
173  /// Suppress traversal of pack-expanded attributes.
174  bool TraverseAttr(Attr *A) {
175  if (A->isPackExpansion())
176  return true;
177 
178  return inherited::TraverseAttr(A);
179  }
180 
181  /// Suppress traversal of pack expansion expressions and types.
182  ///@{
183  bool TraversePackExpansionType(PackExpansionType *T) { return true; }
184  bool TraversePackExpansionTypeLoc(PackExpansionTypeLoc TL) { return true; }
185  bool TraversePackExpansionExpr(PackExpansionExpr *E) { return true; }
186  bool TraverseCXXFoldExpr(CXXFoldExpr *E) { return true; }
187 
188  ///@}
189 
190  /// Suppress traversal of using-declaration pack expansion.
191  bool TraverseUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
192  if (D->isPackExpansion())
193  return true;
194 
195  return inherited::TraverseUnresolvedUsingValueDecl(D);
196  }
197 
198  /// Suppress traversal of using-declaration pack expansion.
199  bool TraverseUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) {
200  if (D->isPackExpansion())
201  return true;
202 
203  return inherited::TraverseUnresolvedUsingTypenameDecl(D);
204  }
205 
206  /// Suppress traversal of template argument pack expansions.
207  bool TraverseTemplateArgument(const TemplateArgument &Arg) {
208  if (Arg.isPackExpansion())
209  return true;
210 
211  return inherited::TraverseTemplateArgument(Arg);
212  }
213 
214  /// Suppress traversal of template argument pack expansions.
215  bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc) {
216  if (ArgLoc.getArgument().isPackExpansion())
217  return true;
218 
219  return inherited::TraverseTemplateArgumentLoc(ArgLoc);
220  }
221 
222  /// Suppress traversal of base specifier pack expansions.
223  bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier &Base) {
224  if (Base.isPackExpansion())
225  return true;
226 
227  return inherited::TraverseCXXBaseSpecifier(Base);
228  }
229 
230  /// Suppress traversal of mem-initializer pack expansions.
231  bool TraverseConstructorInitializer(CXXCtorInitializer *Init) {
232  if (Init->isPackExpansion())
233  return true;
234 
235  return inherited::TraverseConstructorInitializer(Init);
236  }
237 
238  /// Note whether we're traversing a lambda containing an unexpanded
239  /// parameter pack. In this case, the unexpanded pack can occur anywhere,
240  /// including all the places where we normally wouldn't look. Within a
241  /// lambda, we don't propagate the 'contains unexpanded parameter pack' bit
242  /// outside an expression.
243  bool TraverseLambdaExpr(LambdaExpr *Lambda) {
244  // The ContainsUnexpandedParameterPack bit on a lambda is always correct,
245  // even if it's contained within another lambda.
246  if (!Lambda->containsUnexpandedParameterPack())
247  return true;
248 
249  bool WasInLambda = InLambda;
250  unsigned OldDepthLimit = DepthLimit;
251 
252  InLambda = true;
253  if (auto *TPL = Lambda->getTemplateParameterList())
254  DepthLimit = TPL->getDepth();
255 
256  inherited::TraverseLambdaExpr(Lambda);
257 
258  InLambda = WasInLambda;
259  DepthLimit = OldDepthLimit;
260  return true;
261  }
262 
263  /// Suppress traversal within pack expansions in lambda captures.
264  bool TraverseLambdaCapture(LambdaExpr *Lambda, const LambdaCapture *C,
265  Expr *Init) {
266  if (C->isPackExpansion())
267  return true;
268 
269  return inherited::TraverseLambdaCapture(Lambda, C, Init);
270  }
271  };
272 }
273 
274 /// Determine whether it's possible for an unexpanded parameter pack to
275 /// be valid in this location. This only happens when we're in a declaration
276 /// that is nested within an expression that could be expanded, such as a
277 /// lambda-expression within a function call.
278 ///
279 /// This is conservatively correct, but may claim that some unexpanded packs are
280 /// permitted when they are not.
282  for (auto *SI : FunctionScopes)
283  if (isa<sema::LambdaScopeInfo>(SI))
284  return true;
285  return false;
286 }
287 
288 /// Diagnose all of the unexpanded parameter packs in the given
289 /// vector.
290 bool
294  if (Unexpanded.empty())
295  return false;
296 
297  // If we are within a lambda expression and referencing a pack that is not
298  // a parameter of the lambda itself, that lambda contains an unexpanded
299  // parameter pack, and we are done.
300  // FIXME: Store 'Unexpanded' on the lambda so we don't need to recompute it
301  // later.
302  SmallVector<UnexpandedParameterPack, 4> LambdaParamPackReferences;
303  for (unsigned N = FunctionScopes.size(); N; --N) {
304  sema::FunctionScopeInfo *Func = FunctionScopes[N-1];
305  // We do not permit pack expansion that would duplicate a statement
306  // expression, not even within a lambda.
307  // FIXME: We could probably support this for statement expressions that do
308  // not contain labels, and for pack expansions that expand both the stmt
309  // expr and the enclosing lambda.
310  if (std::any_of(
311  Func->CompoundScopes.begin(), Func->CompoundScopes.end(),
312  [](sema::CompoundScopeInfo &CSI) { return CSI.IsStmtExpr; }))
313  break;
314 
315  if (auto *LSI = dyn_cast<sema::LambdaScopeInfo>(Func)) {
316  if (N == FunctionScopes.size()) {
317  for (auto &Param : Unexpanded) {
318  auto *PD = dyn_cast_or_null<ParmVarDecl>(
319  Param.first.dyn_cast<NamedDecl *>());
320  if (PD && PD->getDeclContext() == LSI->CallOperator)
321  LambdaParamPackReferences.push_back(Param);
322  }
323  }
324 
325  // If we have references to a parameter pack of the innermost enclosing
326  // lambda, only diagnose those ones. We don't know whether any other
327  // unexpanded parameters referenced herein are actually unexpanded;
328  // they might be expanded at an outer level.
329  if (!LambdaParamPackReferences.empty()) {
330  Unexpanded = LambdaParamPackReferences;
331  break;
332  }
333 
334  LSI->ContainsUnexpandedParameterPack = true;
335  return false;
336  }
337  }
338 
341  llvm::SmallPtrSet<IdentifierInfo *, 4> NamesKnown;
342 
343  for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
344  IdentifierInfo *Name = nullptr;
345  if (const TemplateTypeParmType *TTP
346  = Unexpanded[I].first.dyn_cast<const TemplateTypeParmType *>())
347  Name = TTP->getIdentifier();
348  else
349  Name = Unexpanded[I].first.get<NamedDecl *>()->getIdentifier();
350 
351  if (Name && NamesKnown.insert(Name).second)
352  Names.push_back(Name);
353 
354  if (Unexpanded[I].second.isValid())
355  Locations.push_back(Unexpanded[I].second);
356  }
357 
358  DiagnosticBuilder DB = Diag(Loc, diag::err_unexpanded_parameter_pack)
359  << (int)UPPC << (int)Names.size();
360  for (size_t I = 0, E = std::min(Names.size(), (size_t)2); I != E; ++I)
361  DB << Names[I];
362 
363  for (unsigned I = 0, N = Locations.size(); I != N; ++I)
364  DB << SourceRange(Locations[I]);
365  return true;
366 }
367 
369  TypeSourceInfo *T,
371  // C++0x [temp.variadic]p5:
372  // An appearance of a name of a parameter pack that is not expanded is
373  // ill-formed.
375  return false;
376 
378  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(
379  T->getTypeLoc());
380  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
381  return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
382 }
383 
386  // C++0x [temp.variadic]p5:
387  // An appearance of a name of a parameter pack that is not expanded is
388  // ill-formed.
390  return false;
391 
393  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(E);
394  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
395  return DiagnoseUnexpandedParameterPacks(E->getBeginLoc(), UPPC, Unexpanded);
396 }
397 
400  // C++0x [temp.variadic]p5:
401  // An appearance of a name of a parameter pack that is not expanded is
402  // ill-formed.
403  if (!SS.getScopeRep() ||
405  return false;
406 
408  CollectUnexpandedParameterPacksVisitor(Unexpanded)
409  .TraverseNestedNameSpecifier(SS.getScopeRep());
410  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
412  UPPC, Unexpanded);
413 }
414 
417  // C++0x [temp.variadic]p5:
418  // An appearance of a name of a parameter pack that is not expanded is
419  // ill-formed.
420  switch (NameInfo.getName().getNameKind()) {
429  return false;
430 
434  // FIXME: We shouldn't need this null check!
435  if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
436  return DiagnoseUnexpandedParameterPack(NameInfo.getLoc(), TSInfo, UPPC);
437 
439  return false;
440 
441  break;
442  }
443 
445  CollectUnexpandedParameterPacksVisitor(Unexpanded)
446  .TraverseType(NameInfo.getName().getCXXNameType());
447  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
448  return DiagnoseUnexpandedParameterPacks(NameInfo.getLoc(), UPPC, Unexpanded);
449 }
450 
452  TemplateName Template,
454 
455  if (Template.isNull() || !Template.containsUnexpandedParameterPack())
456  return false;
457 
459  CollectUnexpandedParameterPacksVisitor(Unexpanded)
460  .TraverseTemplateName(Template);
461  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
462  return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
463 }
464 
467  if (Arg.getArgument().isNull() ||
469  return false;
470 
472  CollectUnexpandedParameterPacksVisitor(Unexpanded)
473  .TraverseTemplateArgumentLoc(Arg);
474  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
475  return DiagnoseUnexpandedParameterPacks(Arg.getLocation(), UPPC, Unexpanded);
476 }
477 
480  CollectUnexpandedParameterPacksVisitor(Unexpanded)
481  .TraverseTemplateArgument(Arg);
482 }
483 
486  CollectUnexpandedParameterPacksVisitor(Unexpanded)
487  .TraverseTemplateArgumentLoc(Arg);
488 }
489 
492  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(T);
493 }
494 
497  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(TL);
498 }
499 
503  CollectUnexpandedParameterPacksVisitor(Unexpanded)
504  .TraverseNestedNameSpecifierLoc(NNS);
505 }
506 
508  const DeclarationNameInfo &NameInfo,
510  CollectUnexpandedParameterPacksVisitor(Unexpanded)
511  .TraverseDeclarationNameInfo(NameInfo);
512 }
513 
514 
517  SourceLocation EllipsisLoc) {
518  if (Arg.isInvalid())
519  return Arg;
520 
521  switch (Arg.getKind()) {
523  TypeResult Result = ActOnPackExpansion(Arg.getAsType(), EllipsisLoc);
524  if (Result.isInvalid())
525  return ParsedTemplateArgument();
526 
527  return ParsedTemplateArgument(Arg.getKind(), Result.get().getAsOpaquePtr(),
528  Arg.getLocation());
529  }
530 
532  ExprResult Result = ActOnPackExpansion(Arg.getAsExpr(), EllipsisLoc);
533  if (Result.isInvalid())
534  return ParsedTemplateArgument();
535 
536  return ParsedTemplateArgument(Arg.getKind(), Result.get(),
537  Arg.getLocation());
538  }
539 
542  SourceRange R(Arg.getLocation());
543  if (Arg.getScopeSpec().isValid())
544  R.setBegin(Arg.getScopeSpec().getBeginLoc());
545  Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
546  << R;
547  return ParsedTemplateArgument();
548  }
549 
550  return Arg.getTemplatePackExpansion(EllipsisLoc);
551  }
552  llvm_unreachable("Unhandled template argument kind?");
553 }
554 
556  SourceLocation EllipsisLoc) {
557  TypeSourceInfo *TSInfo;
558  GetTypeFromParser(Type, &TSInfo);
559  if (!TSInfo)
560  return true;
561 
562  TypeSourceInfo *TSResult = CheckPackExpansion(TSInfo, EllipsisLoc, None);
563  if (!TSResult)
564  return true;
565 
566  return CreateParsedType(TSResult->getType(), TSResult);
567 }
568 
571  Optional<unsigned> NumExpansions) {
572  // Create the pack expansion type and source-location information.
573  QualType Result = CheckPackExpansion(Pattern->getType(),
574  Pattern->getTypeLoc().getSourceRange(),
575  EllipsisLoc, NumExpansions);
576  if (Result.isNull())
577  return nullptr;
578 
579  TypeLocBuilder TLB;
580  TLB.pushFullCopy(Pattern->getTypeLoc());
582  TL.setEllipsisLoc(EllipsisLoc);
583 
584  return TLB.getTypeSourceInfo(Context, Result);
585 }
586 
588  SourceLocation EllipsisLoc,
589  Optional<unsigned> NumExpansions) {
590  // C++0x [temp.variadic]p5:
591  // The pattern of a pack expansion shall name one or more
592  // parameter packs that are not expanded by a nested pack
593  // expansion.
594  if (!Pattern->containsUnexpandedParameterPack()) {
595  Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
596  << PatternRange;
597  return QualType();
598  }
599 
600  return Context.getPackExpansionType(Pattern, NumExpansions);
601 }
602 
604  return CheckPackExpansion(Pattern, EllipsisLoc, None);
605 }
606 
608  Optional<unsigned> NumExpansions) {
609  if (!Pattern)
610  return ExprError();
611 
612  // C++0x [temp.variadic]p5:
613  // The pattern of a pack expansion shall name one or more
614  // parameter packs that are not expanded by a nested pack
615  // expansion.
616  if (!Pattern->containsUnexpandedParameterPack()) {
617  Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
618  << Pattern->getSourceRange();
619  return ExprError();
620  }
621 
622  // Create the pack expansion expression and source-location information.
623  return new (Context)
624  PackExpansionExpr(Context.DependentTy, Pattern, EllipsisLoc, NumExpansions);
625 }
626 
628  SourceLocation EllipsisLoc, SourceRange PatternRange,
630  const MultiLevelTemplateArgumentList &TemplateArgs, bool &ShouldExpand,
631  bool &RetainExpansion, Optional<unsigned> &NumExpansions) {
632  ShouldExpand = true;
633  RetainExpansion = false;
634  std::pair<IdentifierInfo *, SourceLocation> FirstPack;
635  bool HaveFirstPack = false;
636  Optional<unsigned> NumPartialExpansions;
637  SourceLocation PartiallySubstitutedPackLoc;
638 
639  for (ArrayRef<UnexpandedParameterPack>::iterator i = Unexpanded.begin(),
640  end = Unexpanded.end();
641  i != end; ++i) {
642  // Compute the depth and index for this parameter pack.
643  unsigned Depth = 0, Index = 0;
644  IdentifierInfo *Name;
645  bool IsFunctionParameterPack = false;
646 
647  if (const TemplateTypeParmType *TTP
648  = i->first.dyn_cast<const TemplateTypeParmType *>()) {
649  Depth = TTP->getDepth();
650  Index = TTP->getIndex();
651  Name = TTP->getIdentifier();
652  } else {
653  NamedDecl *ND = i->first.get<NamedDecl *>();
654  if (isa<ParmVarDecl>(ND))
655  IsFunctionParameterPack = true;
656  else
657  std::tie(Depth, Index) = getDepthAndIndex(ND);
658 
659  Name = ND->getIdentifier();
660  }
661 
662  // Determine the size of this argument pack.
663  unsigned NewPackSize;
664  if (IsFunctionParameterPack) {
665  // Figure out whether we're instantiating to an argument pack or not.
666  typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
667 
668  llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation
669  = CurrentInstantiationScope->findInstantiationOf(
670  i->first.get<NamedDecl *>());
671  if (Instantiation->is<DeclArgumentPack *>()) {
672  // We could expand this function parameter pack.
673  NewPackSize = Instantiation->get<DeclArgumentPack *>()->size();
674  } else {
675  // We can't expand this function parameter pack, so we can't expand
676  // the pack expansion.
677  ShouldExpand = false;
678  continue;
679  }
680  } else {
681  // If we don't have a template argument at this depth/index, then we
682  // cannot expand the pack expansion. Make a note of this, but we still
683  // want to check any parameter packs we *do* have arguments for.
684  if (Depth >= TemplateArgs.getNumLevels() ||
685  !TemplateArgs.hasTemplateArgument(Depth, Index)) {
686  ShouldExpand = false;
687  continue;
688  }
689 
690  // Determine the size of the argument pack.
691  NewPackSize = TemplateArgs(Depth, Index).pack_size();
692  }
693 
694  // C++0x [temp.arg.explicit]p9:
695  // Template argument deduction can extend the sequence of template
696  // arguments corresponding to a template parameter pack, even when the
697  // sequence contains explicitly specified template arguments.
698  if (!IsFunctionParameterPack && CurrentInstantiationScope) {
699  if (NamedDecl *PartialPack
700  = CurrentInstantiationScope->getPartiallySubstitutedPack()){
701  unsigned PartialDepth, PartialIndex;
702  std::tie(PartialDepth, PartialIndex) = getDepthAndIndex(PartialPack);
703  if (PartialDepth == Depth && PartialIndex == Index) {
704  RetainExpansion = true;
705  // We don't actually know the new pack size yet.
706  NumPartialExpansions = NewPackSize;
707  PartiallySubstitutedPackLoc = i->second;
708  continue;
709  }
710  }
711  }
712 
713  if (!NumExpansions) {
714  // The is the first pack we've seen for which we have an argument.
715  // Record it.
716  NumExpansions = NewPackSize;
717  FirstPack.first = Name;
718  FirstPack.second = i->second;
719  HaveFirstPack = true;
720  continue;
721  }
722 
723  if (NewPackSize != *NumExpansions) {
724  // C++0x [temp.variadic]p5:
725  // All of the parameter packs expanded by a pack expansion shall have
726  // the same number of arguments specified.
727  if (HaveFirstPack)
728  Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict)
729  << FirstPack.first << Name << *NumExpansions << NewPackSize
730  << SourceRange(FirstPack.second) << SourceRange(i->second);
731  else
732  Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_multilevel)
733  << Name << *NumExpansions << NewPackSize
734  << SourceRange(i->second);
735  return true;
736  }
737  }
738 
739  // If we're performing a partial expansion but we also have a full expansion,
740  // expand to the number of common arguments. For example, given:
741  //
742  // template<typename ...T> struct A {
743  // template<typename ...U> void f(pair<T, U>...);
744  // };
745  //
746  // ... a call to 'A<int, int>().f<int>' should expand the pack once and
747  // retain an expansion.
748  if (NumPartialExpansions) {
749  if (NumExpansions && *NumExpansions < *NumPartialExpansions) {
750  NamedDecl *PartialPack =
751  CurrentInstantiationScope->getPartiallySubstitutedPack();
752  Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_partial)
753  << PartialPack << *NumPartialExpansions << *NumExpansions
754  << SourceRange(PartiallySubstitutedPackLoc);
755  return true;
756  }
757 
758  NumExpansions = NumPartialExpansions;
759  }
760 
761  return false;
762 }
763 
765  const MultiLevelTemplateArgumentList &TemplateArgs) {
766  QualType Pattern = cast<PackExpansionType>(T)->getPattern();
768  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(Pattern);
769 
771  for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
772  // Compute the depth and index for this parameter pack.
773  unsigned Depth;
774  unsigned Index;
775 
776  if (const TemplateTypeParmType *TTP
777  = Unexpanded[I].first.dyn_cast<const TemplateTypeParmType *>()) {
778  Depth = TTP->getDepth();
779  Index = TTP->getIndex();
780  } else {
781  NamedDecl *ND = Unexpanded[I].first.get<NamedDecl *>();
782  if (isa<ParmVarDecl>(ND)) {
783  // Function parameter pack.
784  typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
785 
786  llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation
787  = CurrentInstantiationScope->findInstantiationOf(
788  Unexpanded[I].first.get<NamedDecl *>());
789  if (Instantiation->is<Decl*>())
790  // The pattern refers to an unexpanded pack. We're not ready to expand
791  // this pack yet.
792  return None;
793 
794  unsigned Size = Instantiation->get<DeclArgumentPack *>()->size();
795  assert((!Result || *Result == Size) && "inconsistent pack sizes");
796  Result = Size;
797  continue;
798  }
799 
800  std::tie(Depth, Index) = getDepthAndIndex(ND);
801  }
802  if (Depth >= TemplateArgs.getNumLevels() ||
803  !TemplateArgs.hasTemplateArgument(Depth, Index))
804  // The pattern refers to an unknown template argument. We're not ready to
805  // expand this pack yet.
806  return None;
807 
808  // Determine the size of the argument pack.
809  unsigned Size = TemplateArgs(Depth, Index).pack_size();
810  assert((!Result || *Result == Size) && "inconsistent pack sizes");
811  Result = Size;
812  }
813 
814  return Result;
815 }
816 
818  const DeclSpec &DS = D.getDeclSpec();
819  switch (DS.getTypeSpecType()) {
820  case TST_typename:
821  case TST_typeofType:
822  case TST_underlyingType:
823  case TST_atomic: {
824  QualType T = DS.getRepAsType().get();
825  if (!T.isNull() && T->containsUnexpandedParameterPack())
826  return true;
827  break;
828  }
829 
830  case TST_typeofExpr:
831  case TST_decltype:
832  if (DS.getRepAsExpr() &&
834  return true;
835  break;
836 
837  case TST_unspecified:
838  case TST_void:
839  case TST_char:
840  case TST_wchar:
841  case TST_char8:
842  case TST_char16:
843  case TST_char32:
844  case TST_int:
845  case TST_int128:
846  case TST_half:
847  case TST_float:
848  case TST_double:
849  case TST_Accum:
850  case TST_Fract:
851  case TST_Float16:
852  case TST_float128:
853  case TST_bool:
854  case TST_decimal32:
855  case TST_decimal64:
856  case TST_decimal128:
857  case TST_enum:
858  case TST_union:
859  case TST_struct:
860  case TST_interface:
861  case TST_class:
862  case TST_auto:
863  case TST_auto_type:
864  case TST_decltype_auto:
865 #define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t:
866 #include "clang/Basic/OpenCLImageTypes.def"
867  case TST_unknown_anytype:
868  case TST_error:
869  break;
870  }
871 
872  for (unsigned I = 0, N = D.getNumTypeObjects(); I != N; ++I) {
873  const DeclaratorChunk &Chunk = D.getTypeObject(I);
874  switch (Chunk.Kind) {
880  // These declarator chunks cannot contain any parameter packs.
881  break;
882 
884  if (Chunk.Arr.NumElts &&
886  return true;
887  break;
889  for (unsigned i = 0, e = Chunk.Fun.NumParams; i != e; ++i) {
890  ParmVarDecl *Param = cast<ParmVarDecl>(Chunk.Fun.Params[i].Param);
891  QualType ParamTy = Param->getType();
892  assert(!ParamTy.isNull() && "Couldn't parse type?");
893  if (ParamTy->containsUnexpandedParameterPack()) return true;
894  }
895 
896  if (Chunk.Fun.getExceptionSpecType() == EST_Dynamic) {
897  for (unsigned i = 0; i != Chunk.Fun.getNumExceptions(); ++i) {
898  if (Chunk.Fun.Exceptions[i]
899  .Ty.get()
901  return true;
902  }
903  } else if (isComputedNoexcept(Chunk.Fun.getExceptionSpecType()) &&
905  return true;
906 
907  if (Chunk.Fun.hasTrailingReturnType()) {
908  QualType T = Chunk.Fun.getTrailingReturnType().get();
909  if (!T.isNull() && T->containsUnexpandedParameterPack())
910  return true;
911  }
912  break;
913 
915  if (Chunk.Mem.Scope().getScopeRep() &&
917  return true;
918  break;
919  }
920  }
921 
922  return false;
923 }
924 
925 namespace {
926 
927 // Callback to only accept typo corrections that refer to parameter packs.
928 class ParameterPackValidatorCCC : public CorrectionCandidateCallback {
929  public:
930  bool ValidateCandidate(const TypoCorrection &candidate) override {
931  NamedDecl *ND = candidate.getCorrectionDecl();
932  return ND && ND->isParameterPack();
933  }
934 };
935 
936 }
937 
938 /// Called when an expression computing the size of a parameter pack
939 /// is parsed.
940 ///
941 /// \code
942 /// template<typename ...Types> struct count {
943 /// static const unsigned value = sizeof...(Types);
944 /// };
945 /// \endcode
946 ///
947 //
948 /// \param OpLoc The location of the "sizeof" keyword.
949 /// \param Name The name of the parameter pack whose size will be determined.
950 /// \param NameLoc The source location of the name of the parameter pack.
951 /// \param RParenLoc The location of the closing parentheses.
953  SourceLocation OpLoc,
954  IdentifierInfo &Name,
955  SourceLocation NameLoc,
956  SourceLocation RParenLoc) {
957  // C++0x [expr.sizeof]p5:
958  // The identifier in a sizeof... expression shall name a parameter pack.
959  LookupResult R(*this, &Name, NameLoc, LookupOrdinaryName);
960  LookupName(R, S);
961 
962  NamedDecl *ParameterPack = nullptr;
963  switch (R.getResultKind()) {
964  case LookupResult::Found:
965  ParameterPack = R.getFoundDecl();
966  break;
967 
970  if (TypoCorrection Corrected =
971  CorrectTypo(R.getLookupNameInfo(), R.getLookupKind(), S, nullptr,
972  llvm::make_unique<ParameterPackValidatorCCC>(),
973  CTK_ErrorRecovery)) {
974  diagnoseTypo(Corrected,
975  PDiag(diag::err_sizeof_pack_no_pack_name_suggest) << &Name,
976  PDiag(diag::note_parameter_pack_here));
977  ParameterPack = Corrected.getCorrectionDecl();
978  }
979 
982  break;
983 
985  DiagnoseAmbiguousLookup(R);
986  return ExprError();
987  }
988 
989  if (!ParameterPack || !ParameterPack->isParameterPack()) {
990  Diag(NameLoc, diag::err_sizeof_pack_no_pack_name)
991  << &Name;
992  return ExprError();
993  }
994 
995  MarkAnyDeclReferenced(OpLoc, ParameterPack, true);
996 
997  return SizeOfPackExpr::Create(Context, OpLoc, ParameterPack, NameLoc,
998  RParenLoc);
999 }
1000 
1003  TemplateArgumentLoc OrigLoc,
1004  SourceLocation &Ellipsis, Optional<unsigned> &NumExpansions) const {
1005  const TemplateArgument &Argument = OrigLoc.getArgument();
1006  assert(Argument.isPackExpansion());
1007  switch (Argument.getKind()) {
1008  case TemplateArgument::Type: {
1009  // FIXME: We shouldn't ever have to worry about missing
1010  // type-source info!
1011  TypeSourceInfo *ExpansionTSInfo = OrigLoc.getTypeSourceInfo();
1012  if (!ExpansionTSInfo)
1013  ExpansionTSInfo = Context.getTrivialTypeSourceInfo(Argument.getAsType(),
1014  Ellipsis);
1015  PackExpansionTypeLoc Expansion =
1016  ExpansionTSInfo->getTypeLoc().castAs<PackExpansionTypeLoc>();
1017  Ellipsis = Expansion.getEllipsisLoc();
1018 
1019  TypeLoc Pattern = Expansion.getPatternLoc();
1020  NumExpansions = Expansion.getTypePtr()->getNumExpansions();
1021 
1022  // We need to copy the TypeLoc because TemplateArgumentLocs store a
1023  // TypeSourceInfo.
1024  // FIXME: Find some way to avoid the copy?
1025  TypeLocBuilder TLB;
1026  TLB.pushFullCopy(Pattern);
1027  TypeSourceInfo *PatternTSInfo =
1028  TLB.getTypeSourceInfo(Context, Pattern.getType());
1029  return TemplateArgumentLoc(TemplateArgument(Pattern.getType()),
1030  PatternTSInfo);
1031  }
1032 
1034  PackExpansionExpr *Expansion
1035  = cast<PackExpansionExpr>(Argument.getAsExpr());
1036  Expr *Pattern = Expansion->getPattern();
1037  Ellipsis = Expansion->getEllipsisLoc();
1038  NumExpansions = Expansion->getNumExpansions();
1039  return TemplateArgumentLoc(Pattern, Pattern);
1040  }
1041 
1043  Ellipsis = OrigLoc.getTemplateEllipsisLoc();
1044  NumExpansions = Argument.getNumTemplateExpansions();
1045  return TemplateArgumentLoc(Argument.getPackExpansionPattern(),
1046  OrigLoc.getTemplateQualifierLoc(),
1047  OrigLoc.getTemplateNameLoc());
1048 
1055  return TemplateArgumentLoc();
1056  }
1057 
1058  llvm_unreachable("Invalid TemplateArgument Kind!");
1059 }
1060 
1062  assert(Arg.containsUnexpandedParameterPack());
1063 
1064  // If this is a substituted pack, grab that pack. If not, we don't know
1065  // the size yet.
1066  // FIXME: We could find a size in more cases by looking for a substituted
1067  // pack anywhere within this argument, but that's not necessary in the common
1068  // case for 'sizeof...(A)' handling.
1069  TemplateArgument Pack;
1070  switch (Arg.getKind()) {
1072  if (auto *Subst = Arg.getAsType()->getAs<SubstTemplateTypeParmPackType>())
1073  Pack = Subst->getArgumentPack();
1074  else
1075  return None;
1076  break;
1077 
1079  if (auto *Subst =
1080  dyn_cast<SubstNonTypeTemplateParmPackExpr>(Arg.getAsExpr()))
1081  Pack = Subst->getArgumentPack();
1082  else if (auto *Subst = dyn_cast<FunctionParmPackExpr>(Arg.getAsExpr())) {
1083  for (ParmVarDecl *PD : *Subst)
1084  if (PD->isParameterPack())
1085  return None;
1086  return Subst->getNumExpansions();
1087  } else
1088  return None;
1089  break;
1090 
1094  Pack = Subst->getArgumentPack();
1095  else
1096  return None;
1097  break;
1098 
1105  return None;
1106  }
1107 
1108  // Check that no argument in the pack is itself a pack expansion.
1109  for (TemplateArgument Elem : Pack.pack_elements()) {
1110  // There's no point recursing in this case; we would have already
1111  // expanded this pack expansion into the enclosing pack if we could.
1112  if (Elem.isPackExpansion())
1113  return None;
1114  }
1115  return Pack.pack_size();
1116 }
1117 
1118 static void CheckFoldOperand(Sema &S, Expr *E) {
1119  if (!E)
1120  return;
1121 
1122  E = E->IgnoreImpCasts();
1123  auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
1124  if ((OCE && OCE->isInfixBinaryOp()) || isa<BinaryOperator>(E) ||
1125  isa<AbstractConditionalOperator>(E)) {
1126  S.Diag(E->getExprLoc(), diag::err_fold_expression_bad_operand)
1127  << E->getSourceRange()
1129  << FixItHint::CreateInsertion(E->getEndLoc(), ")");
1130  }
1131 }
1132 
1134  tok::TokenKind Operator,
1135  SourceLocation EllipsisLoc, Expr *RHS,
1136  SourceLocation RParenLoc) {
1137  // LHS and RHS must be cast-expressions. We allow an arbitrary expression
1138  // in the parser and reduce down to just cast-expressions here.
1139  CheckFoldOperand(*this, LHS);
1140  CheckFoldOperand(*this, RHS);
1141 
1142  auto DiscardOperands = [&] {
1143  CorrectDelayedTyposInExpr(LHS);
1144  CorrectDelayedTyposInExpr(RHS);
1145  };
1146 
1147  // [expr.prim.fold]p3:
1148  // In a binary fold, op1 and op2 shall be the same fold-operator, and
1149  // either e1 shall contain an unexpanded parameter pack or e2 shall contain
1150  // an unexpanded parameter pack, but not both.
1151  if (LHS && RHS &&
1154  DiscardOperands();
1155  return Diag(EllipsisLoc,
1157  ? diag::err_fold_expression_packs_both_sides
1158  : diag::err_pack_expansion_without_parameter_packs)
1159  << LHS->getSourceRange() << RHS->getSourceRange();
1160  }
1161 
1162  // [expr.prim.fold]p2:
1163  // In a unary fold, the cast-expression shall contain an unexpanded
1164  // parameter pack.
1165  if (!LHS || !RHS) {
1166  Expr *Pack = LHS ? LHS : RHS;
1167  assert(Pack && "fold expression with neither LHS nor RHS");
1168  DiscardOperands();
1169  if (!Pack->containsUnexpandedParameterPack())
1170  return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
1171  << Pack->getSourceRange();
1172  }
1173 
1174  BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
1175  return BuildCXXFoldExpr(LParenLoc, LHS, Opc, EllipsisLoc, RHS, RParenLoc);
1176 }
1177 
1179  BinaryOperatorKind Operator,
1180  SourceLocation EllipsisLoc, Expr *RHS,
1181  SourceLocation RParenLoc) {
1182  return new (Context) CXXFoldExpr(Context.DependentTy, LParenLoc, LHS,
1183  Operator, EllipsisLoc, RHS, RParenLoc);
1184 }
1185 
1187  BinaryOperatorKind Operator) {
1188  // [temp.variadic]p9:
1189  // If N is zero for a unary fold-expression, the value of the expression is
1190  // && -> true
1191  // || -> false
1192  // , -> void()
1193  // if the operator is not listed [above], the instantiation is ill-formed.
1194  //
1195  // Note that we need to use something like int() here, not merely 0, to
1196  // prevent the result from being a null pointer constant.
1197  QualType ScalarType;
1198  switch (Operator) {
1199  case BO_LOr:
1200  return ActOnCXXBoolLiteral(EllipsisLoc, tok::kw_false);
1201  case BO_LAnd:
1202  return ActOnCXXBoolLiteral(EllipsisLoc, tok::kw_true);
1203  case BO_Comma:
1204  ScalarType = Context.VoidTy;
1205  break;
1206 
1207  default:
1208  return Diag(EllipsisLoc, diag::err_fold_expression_empty)
1209  << BinaryOperator::getOpcodeStr(Operator);
1210  }
1211 
1212  return new (Context) CXXScalarValueInitExpr(
1213  ScalarType, Context.getTrivialTypeSourceInfo(ScalarType, EllipsisLoc),
1214  EllipsisLoc);
1215 }
ParsedType getTrailingReturnType() const
Get the trailing-return-type for this function declarator.
Definition: DeclSpec.h:1460
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:1732
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:6555
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:496
PtrTy get() const
Definition: Ownership.h:81
A (possibly-)qualified type.
Definition: Type.h:642
Simple class containing the result of Sema::CorrectTypo.
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:403
__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:2162
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:532
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:1290
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:87
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:3709
The base class of the type hierarchy.
Definition: Type.h:1415
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:2352
Retains information about a function, method, or block that is currently being parsed.
Definition: ScopeInfo.h:97
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1748
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6682
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:1443
Represents a parameter to a function.
Definition: Decl.h:1551
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:57
Expr * IgnoreImpCasts() LLVM_READONLY
IgnoreImpCasts - Skip past any implicit casts which might surround this expression.
Definition: Expr.h:2977
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:507
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.
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:280
NameKind getNameKind() const
Determine what kind of name this is.
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:488
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:4634
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:3162
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:1499
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:3350
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
Definition: DeclSpec.h:2158
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:1837
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:544
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
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:1611
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
Contains information about the compound statement currently being parsed.
Definition: ScopeInfo.h:67
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:278
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
std::pair< unsigned, unsigned > getDepthAndIndex(NamedDecl *ND)
Retrieve the depth and index of a template parameter.
Definition: SemaInternal.h:105
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
Definition: DeclSpec.h:1278
SourceLocation getLocation() const
Definition: Expr.h:1064
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.
enum clang::DeclaratorChunk::@209 Kind
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:1833
TypeSourceInfo * CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc, Optional< unsigned > NumExpansions)
Construct a pack expansion type from the pattern of the pack expansion.
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function)...
This represents one expression.
Definition: Expr.h:105
bool containsUnexpandedParameterPacks(Declarator &D)
Determine whether the given declarator contains any unexpanded parameter packs.
bool isPackExpansion() const
Definition: Attr.h:105
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:3619
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:2176
TypeSourceInfo * getNamedTypeInfo() const
getNamedTypeInfo - Returns the source type info associated to the name.
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:2180
Represents a folding of a pack over an operator.
Definition: ExprCXX.h:4187
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
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
ValueDecl * getDecl()
Definition: Expr.h:1056
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:707
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)
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:293
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:2192
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:3729
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, Optional< unsigned > Length=None, ArrayRef< TemplateArgument > PartialArgs=None)
Definition: ExprCXX.cpp:1328
FunctionTypeInfo Fun
Definition: DeclSpec.h:1500
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3565
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:4542
Name lookup found an unresolvable value declaration and cannot yet complete.
Definition: Lookup.h:69
MemberPointerTypeInfo Mem
Definition: DeclSpec.h:1502
CanQualType VoidTy
Definition: ASTContext.h:1025
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:1457
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:5353
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:5328
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:499
QualType getType() const
Get the type for which this source info wrapper provides information.
Definition: TypeLoc.h:131
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:3661
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:3693
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:1023
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:151
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:2253
CanQualType DependentTy
Definition: ASTContext.h:1054
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:1438
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:238
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:235
unsigned getDepth() const
Definition: Type.h:4540
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:1837
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates)...
Definition: Expr.h:213
Optional< unsigned > getNumExpansions() const
Determine the number of expansions that will be produced when this pack expansion is instantiated...
Definition: ExprCXX.h:3733
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:268
ParsedType getRepAsType() const
Definition: DeclSpec.h:492
SourceLocation getNameLoc() const
Definition: TypeLoc.h:517
Expr * getPattern()
Retrieve the pattern of the pack expansion.
Definition: ExprCXX.h:3722
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:971
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:538
SmallVector< CompoundScopeInfo, 4 > CompoundScopes
The stack of currently active compound stamement scopes in the function.
Definition: ScopeInfo.h:204
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:732
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:76
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 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