clang  9.0.0svn
SemaTemplateVariadic.cpp
Go to the documentation of this file.
1 //===------- SemaTemplateVariadic.cpp - C++ Variadic Templates ------------===/
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //===----------------------------------------------------------------------===/
7 //
8 // This file implements semantic analysis for C++0x variadic templates.
9 //===----------------------------------------------------------------------===/
10 
11 #include "clang/Sema/Sema.h"
12 #include "TypeLocBuilder.h"
13 #include "clang/AST/Expr.h"
15 #include "clang/AST/TypeLoc.h"
16 #include "clang/Sema/Lookup.h"
18 #include "clang/Sema/ScopeInfo.h"
20 #include "clang/Sema/Template.h"
21 
22 using namespace clang;
23 
24 //----------------------------------------------------------------------------
25 // Visitor that collects unexpanded parameter packs
26 //----------------------------------------------------------------------------
27 
28 namespace {
29  /// A class that collects unexpanded parameter packs.
30  class CollectUnexpandedParameterPacksVisitor :
31  public RecursiveASTVisitor<CollectUnexpandedParameterPacksVisitor>
32  {
34  inherited;
35 
37 
38  bool InLambda = false;
39  unsigned DepthLimit = (unsigned)-1;
40 
41  void addUnexpanded(NamedDecl *ND, SourceLocation Loc = SourceLocation()) {
42  if (auto *PVD = dyn_cast<ParmVarDecl>(ND)) {
43  // For now, the only problematic case is a generic lambda's templated
44  // call operator, so we don't need to look for all the other ways we
45  // could have reached a dependent parameter pack.
46  auto *FD = dyn_cast<FunctionDecl>(PVD->getDeclContext());
47  auto *FTD = FD ? FD->getDescribedFunctionTemplate() : nullptr;
48  if (FTD && FTD->getTemplateParameters()->getDepth() >= DepthLimit)
49  return;
50  } else if (getDepthAndIndex(ND).first >= DepthLimit)
51  return;
52 
53  Unexpanded.push_back({ND, Loc});
54  }
55  void addUnexpanded(const TemplateTypeParmType *T,
57  if (T->getDepth() < DepthLimit)
58  Unexpanded.push_back({T, Loc});
59  }
60 
61  public:
62  explicit CollectUnexpandedParameterPacksVisitor(
64  : Unexpanded(Unexpanded) {}
65 
66  bool shouldWalkTypesOfTypeLocs() const { return false; }
67 
68  //------------------------------------------------------------------------
69  // Recording occurrences of (unexpanded) parameter packs.
70  //------------------------------------------------------------------------
71 
72  /// Record occurrences of template type parameter packs.
73  bool VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
74  if (TL.getTypePtr()->isParameterPack())
75  addUnexpanded(TL.getTypePtr(), TL.getNameLoc());
76  return true;
77  }
78 
79  /// Record occurrences of template type parameter packs
80  /// when we don't have proper source-location information for
81  /// them.
82  ///
83  /// Ideally, this routine would never be used.
84  bool VisitTemplateTypeParmType(TemplateTypeParmType *T) {
85  if (T->isParameterPack())
86  addUnexpanded(T);
87 
88  return true;
89  }
90 
91  /// Record occurrences of function and non-type template
92  /// parameter packs in an expression.
93  bool VisitDeclRefExpr(DeclRefExpr *E) {
94  if (E->getDecl()->isParameterPack())
95  addUnexpanded(E->getDecl(), E->getLocation());
96 
97  return true;
98  }
99 
100  /// Record occurrences of template template parameter packs.
101  bool TraverseTemplateName(TemplateName Template) {
102  if (auto *TTP = dyn_cast_or_null<TemplateTemplateParmDecl>(
103  Template.getAsTemplateDecl())) {
104  if (TTP->isParameterPack())
105  addUnexpanded(TTP);
106  }
107 
108  return inherited::TraverseTemplateName(Template);
109  }
110 
111  /// Suppress traversal into Objective-C container literal
112  /// elements that are pack expansions.
113  bool TraverseObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
115  return true;
116 
117  for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
119  if (Element.isPackExpansion())
120  continue;
121 
122  TraverseStmt(Element.Key);
123  TraverseStmt(Element.Value);
124  }
125  return true;
126  }
127  //------------------------------------------------------------------------
128  // Pruning the search for unexpanded parameter packs.
129  //------------------------------------------------------------------------
130 
131  /// Suppress traversal into statements and expressions that
132  /// do not contain unexpanded parameter packs.
133  bool TraverseStmt(Stmt *S) {
134  Expr *E = dyn_cast_or_null<Expr>(S);
135  if ((E && E->containsUnexpandedParameterPack()) || InLambda)
136  return inherited::TraverseStmt(S);
137 
138  return true;
139  }
140 
141  /// Suppress traversal into types that do not contain
142  /// unexpanded parameter packs.
143  bool TraverseType(QualType T) {
144  if ((!T.isNull() && T->containsUnexpandedParameterPack()) || InLambda)
145  return inherited::TraverseType(T);
146 
147  return true;
148  }
149 
150  /// Suppress traversal into types with location information
151  /// that do not contain unexpanded parameter packs.
152  bool TraverseTypeLoc(TypeLoc TL) {
153  if ((!TL.getType().isNull() &&
155  InLambda)
156  return inherited::TraverseTypeLoc(TL);
157 
158  return true;
159  }
160 
161  /// Suppress traversal of parameter packs.
162  bool TraverseDecl(Decl *D) {
163  // A function parameter pack is a pack expansion, so cannot contain
164  // an unexpanded parameter pack. Likewise for a template parameter
165  // pack that contains any references to other packs.
166  if (D && D->isParameterPack())
167  return true;
168 
169  return inherited::TraverseDecl(D);
170  }
171 
172  /// Suppress traversal of pack-expanded attributes.
173  bool TraverseAttr(Attr *A) {
174  if (A->isPackExpansion())
175  return true;
176 
177  return inherited::TraverseAttr(A);
178  }
179 
180  /// Suppress traversal of pack expansion expressions and types.
181  ///@{
182  bool TraversePackExpansionType(PackExpansionType *T) { return true; }
183  bool TraversePackExpansionTypeLoc(PackExpansionTypeLoc TL) { return true; }
184  bool TraversePackExpansionExpr(PackExpansionExpr *E) { return true; }
185  bool TraverseCXXFoldExpr(CXXFoldExpr *E) { return true; }
186 
187  ///@}
188 
189  /// Suppress traversal of using-declaration pack expansion.
190  bool TraverseUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
191  if (D->isPackExpansion())
192  return true;
193 
194  return inherited::TraverseUnresolvedUsingValueDecl(D);
195  }
196 
197  /// Suppress traversal of using-declaration pack expansion.
198  bool TraverseUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) {
199  if (D->isPackExpansion())
200  return true;
201 
202  return inherited::TraverseUnresolvedUsingTypenameDecl(D);
203  }
204 
205  /// Suppress traversal of template argument pack expansions.
206  bool TraverseTemplateArgument(const TemplateArgument &Arg) {
207  if (Arg.isPackExpansion())
208  return true;
209 
210  return inherited::TraverseTemplateArgument(Arg);
211  }
212 
213  /// Suppress traversal of template argument pack expansions.
214  bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc) {
215  if (ArgLoc.getArgument().isPackExpansion())
216  return true;
217 
218  return inherited::TraverseTemplateArgumentLoc(ArgLoc);
219  }
220 
221  /// Suppress traversal of base specifier pack expansions.
222  bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier &Base) {
223  if (Base.isPackExpansion())
224  return true;
225 
226  return inherited::TraverseCXXBaseSpecifier(Base);
227  }
228 
229  /// Suppress traversal of mem-initializer pack expansions.
230  bool TraverseConstructorInitializer(CXXCtorInitializer *Init) {
231  if (Init->isPackExpansion())
232  return true;
233 
234  return inherited::TraverseConstructorInitializer(Init);
235  }
236 
237  /// Note whether we're traversing a lambda containing an unexpanded
238  /// parameter pack. In this case, the unexpanded pack can occur anywhere,
239  /// including all the places where we normally wouldn't look. Within a
240  /// lambda, we don't propagate the 'contains unexpanded parameter pack' bit
241  /// outside an expression.
242  bool TraverseLambdaExpr(LambdaExpr *Lambda) {
243  // The ContainsUnexpandedParameterPack bit on a lambda is always correct,
244  // even if it's contained within another lambda.
245  if (!Lambda->containsUnexpandedParameterPack())
246  return true;
247 
248  bool WasInLambda = InLambda;
249  unsigned OldDepthLimit = DepthLimit;
250 
251  InLambda = true;
252  if (auto *TPL = Lambda->getTemplateParameterList())
253  DepthLimit = TPL->getDepth();
254 
255  inherited::TraverseLambdaExpr(Lambda);
256 
257  InLambda = WasInLambda;
258  DepthLimit = OldDepthLimit;
259  return true;
260  }
261 
262  /// Suppress traversal within pack expansions in lambda captures.
263  bool TraverseLambdaCapture(LambdaExpr *Lambda, const LambdaCapture *C,
264  Expr *Init) {
265  if (C->isPackExpansion())
266  return true;
267 
268  return inherited::TraverseLambdaCapture(Lambda, C, Init);
269  }
270  };
271 }
272 
273 /// Determine whether it's possible for an unexpanded parameter pack to
274 /// be valid in this location. This only happens when we're in a declaration
275 /// that is nested within an expression that could be expanded, such as a
276 /// lambda-expression within a function call.
277 ///
278 /// This is conservatively correct, but may claim that some unexpanded packs are
279 /// permitted when they are not.
281  for (auto *SI : FunctionScopes)
282  if (isa<sema::LambdaScopeInfo>(SI))
283  return true;
284  return false;
285 }
286 
287 /// Diagnose all of the unexpanded parameter packs in the given
288 /// vector.
289 bool
293  if (Unexpanded.empty())
294  return false;
295 
296  // If we are within a lambda expression and referencing a pack that is not
297  // a parameter of the lambda itself, that lambda contains an unexpanded
298  // parameter pack, and we are done.
299  // FIXME: Store 'Unexpanded' on the lambda so we don't need to recompute it
300  // later.
301  SmallVector<UnexpandedParameterPack, 4> LambdaParamPackReferences;
302  for (unsigned N = FunctionScopes.size(); N; --N) {
303  sema::FunctionScopeInfo *Func = FunctionScopes[N-1];
304  // We do not permit pack expansion that would duplicate a statement
305  // expression, not even within a lambda.
306  // FIXME: We could probably support this for statement expressions that do
307  // not contain labels, and for pack expansions that expand both the stmt
308  // expr and the enclosing lambda.
309  if (std::any_of(
310  Func->CompoundScopes.begin(), Func->CompoundScopes.end(),
311  [](sema::CompoundScopeInfo &CSI) { return CSI.IsStmtExpr; }))
312  break;
313 
314  if (auto *LSI = dyn_cast<sema::LambdaScopeInfo>(Func)) {
315  if (N == FunctionScopes.size()) {
316  for (auto &Param : Unexpanded) {
317  auto *PD = dyn_cast_or_null<ParmVarDecl>(
318  Param.first.dyn_cast<NamedDecl *>());
319  if (PD && PD->getDeclContext() == LSI->CallOperator)
320  LambdaParamPackReferences.push_back(Param);
321  }
322  }
323 
324  // If we have references to a parameter pack of the innermost enclosing
325  // lambda, only diagnose those ones. We don't know whether any other
326  // unexpanded parameters referenced herein are actually unexpanded;
327  // they might be expanded at an outer level.
328  if (!LambdaParamPackReferences.empty()) {
329  Unexpanded = LambdaParamPackReferences;
330  break;
331  }
332 
333  LSI->ContainsUnexpandedParameterPack = true;
334  return false;
335  }
336  }
337 
340  llvm::SmallPtrSet<IdentifierInfo *, 4> NamesKnown;
341 
342  for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
343  IdentifierInfo *Name = nullptr;
344  if (const TemplateTypeParmType *TTP
345  = Unexpanded[I].first.dyn_cast<const TemplateTypeParmType *>())
346  Name = TTP->getIdentifier();
347  else
348  Name = Unexpanded[I].first.get<NamedDecl *>()->getIdentifier();
349 
350  if (Name && NamesKnown.insert(Name).second)
351  Names.push_back(Name);
352 
353  if (Unexpanded[I].second.isValid())
354  Locations.push_back(Unexpanded[I].second);
355  }
356 
357  DiagnosticBuilder DB = Diag(Loc, diag::err_unexpanded_parameter_pack)
358  << (int)UPPC << (int)Names.size();
359  for (size_t I = 0, E = std::min(Names.size(), (size_t)2); I != E; ++I)
360  DB << Names[I];
361 
362  for (unsigned I = 0, N = Locations.size(); I != N; ++I)
363  DB << SourceRange(Locations[I]);
364  return true;
365 }
366 
368  TypeSourceInfo *T,
370  // C++0x [temp.variadic]p5:
371  // An appearance of a name of a parameter pack that is not expanded is
372  // ill-formed.
374  return false;
375 
377  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(
378  T->getTypeLoc());
379  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
380  return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
381 }
382 
385  // C++0x [temp.variadic]p5:
386  // An appearance of a name of a parameter pack that is not expanded is
387  // ill-formed.
389  return false;
390 
392  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(E);
393  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
394  return DiagnoseUnexpandedParameterPacks(E->getBeginLoc(), UPPC, Unexpanded);
395 }
396 
399  // C++0x [temp.variadic]p5:
400  // An appearance of a name of a parameter pack that is not expanded is
401  // ill-formed.
402  if (!SS.getScopeRep() ||
404  return false;
405 
407  CollectUnexpandedParameterPacksVisitor(Unexpanded)
408  .TraverseNestedNameSpecifier(SS.getScopeRep());
409  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
411  UPPC, Unexpanded);
412 }
413 
416  // C++0x [temp.variadic]p5:
417  // An appearance of a name of a parameter pack that is not expanded is
418  // ill-formed.
419  switch (NameInfo.getName().getNameKind()) {
428  return false;
429 
433  // FIXME: We shouldn't need this null check!
434  if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
435  return DiagnoseUnexpandedParameterPack(NameInfo.getLoc(), TSInfo, UPPC);
436 
438  return false;
439 
440  break;
441  }
442 
444  CollectUnexpandedParameterPacksVisitor(Unexpanded)
445  .TraverseType(NameInfo.getName().getCXXNameType());
446  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
447  return DiagnoseUnexpandedParameterPacks(NameInfo.getLoc(), UPPC, Unexpanded);
448 }
449 
451  TemplateName Template,
453 
454  if (Template.isNull() || !Template.containsUnexpandedParameterPack())
455  return false;
456 
458  CollectUnexpandedParameterPacksVisitor(Unexpanded)
459  .TraverseTemplateName(Template);
460  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
461  return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
462 }
463 
466  if (Arg.getArgument().isNull() ||
468  return false;
469 
471  CollectUnexpandedParameterPacksVisitor(Unexpanded)
472  .TraverseTemplateArgumentLoc(Arg);
473  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
474  return DiagnoseUnexpandedParameterPacks(Arg.getLocation(), UPPC, Unexpanded);
475 }
476 
479  CollectUnexpandedParameterPacksVisitor(Unexpanded)
480  .TraverseTemplateArgument(Arg);
481 }
482 
485  CollectUnexpandedParameterPacksVisitor(Unexpanded)
486  .TraverseTemplateArgumentLoc(Arg);
487 }
488 
491  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(T);
492 }
493 
496  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(TL);
497 }
498 
502  CollectUnexpandedParameterPacksVisitor(Unexpanded)
503  .TraverseNestedNameSpecifierLoc(NNS);
504 }
505 
507  const DeclarationNameInfo &NameInfo,
509  CollectUnexpandedParameterPacksVisitor(Unexpanded)
510  .TraverseDeclarationNameInfo(NameInfo);
511 }
512 
513 
516  SourceLocation EllipsisLoc) {
517  if (Arg.isInvalid())
518  return Arg;
519 
520  switch (Arg.getKind()) {
522  TypeResult Result = ActOnPackExpansion(Arg.getAsType(), EllipsisLoc);
523  if (Result.isInvalid())
524  return ParsedTemplateArgument();
525 
526  return ParsedTemplateArgument(Arg.getKind(), Result.get().getAsOpaquePtr(),
527  Arg.getLocation());
528  }
529 
531  ExprResult Result = ActOnPackExpansion(Arg.getAsExpr(), EllipsisLoc);
532  if (Result.isInvalid())
533  return ParsedTemplateArgument();
534 
535  return ParsedTemplateArgument(Arg.getKind(), Result.get(),
536  Arg.getLocation());
537  }
538 
541  SourceRange R(Arg.getLocation());
542  if (Arg.getScopeSpec().isValid())
543  R.setBegin(Arg.getScopeSpec().getBeginLoc());
544  Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
545  << R;
546  return ParsedTemplateArgument();
547  }
548 
549  return Arg.getTemplatePackExpansion(EllipsisLoc);
550  }
551  llvm_unreachable("Unhandled template argument kind?");
552 }
553 
555  SourceLocation EllipsisLoc) {
556  TypeSourceInfo *TSInfo;
557  GetTypeFromParser(Type, &TSInfo);
558  if (!TSInfo)
559  return true;
560 
561  TypeSourceInfo *TSResult = CheckPackExpansion(TSInfo, EllipsisLoc, None);
562  if (!TSResult)
563  return true;
564 
565  return CreateParsedType(TSResult->getType(), TSResult);
566 }
567 
570  Optional<unsigned> NumExpansions) {
571  // Create the pack expansion type and source-location information.
572  QualType Result = CheckPackExpansion(Pattern->getType(),
573  Pattern->getTypeLoc().getSourceRange(),
574  EllipsisLoc, NumExpansions);
575  if (Result.isNull())
576  return nullptr;
577 
578  TypeLocBuilder TLB;
579  TLB.pushFullCopy(Pattern->getTypeLoc());
581  TL.setEllipsisLoc(EllipsisLoc);
582 
583  return TLB.getTypeSourceInfo(Context, Result);
584 }
585 
587  SourceLocation EllipsisLoc,
588  Optional<unsigned> NumExpansions) {
589  // C++0x [temp.variadic]p5:
590  // The pattern of a pack expansion shall name one or more
591  // parameter packs that are not expanded by a nested pack
592  // expansion.
593  if (!Pattern->containsUnexpandedParameterPack()) {
594  Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
595  << PatternRange;
596  return QualType();
597  }
598 
599  return Context.getPackExpansionType(Pattern, NumExpansions);
600 }
601 
603  return CheckPackExpansion(Pattern, EllipsisLoc, None);
604 }
605 
607  Optional<unsigned> NumExpansions) {
608  if (!Pattern)
609  return ExprError();
610 
611  // C++0x [temp.variadic]p5:
612  // The pattern of a pack expansion shall name one or more
613  // parameter packs that are not expanded by a nested pack
614  // expansion.
615  if (!Pattern->containsUnexpandedParameterPack()) {
616  Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
617  << Pattern->getSourceRange();
618  return ExprError();
619  }
620 
621  // Create the pack expansion expression and source-location information.
622  return new (Context)
623  PackExpansionExpr(Context.DependentTy, Pattern, EllipsisLoc, NumExpansions);
624 }
625 
627  SourceLocation EllipsisLoc, SourceRange PatternRange,
629  const MultiLevelTemplateArgumentList &TemplateArgs, bool &ShouldExpand,
630  bool &RetainExpansion, Optional<unsigned> &NumExpansions) {
631  ShouldExpand = true;
632  RetainExpansion = false;
633  std::pair<IdentifierInfo *, SourceLocation> FirstPack;
634  bool HaveFirstPack = false;
635  Optional<unsigned> NumPartialExpansions;
636  SourceLocation PartiallySubstitutedPackLoc;
637 
638  for (ArrayRef<UnexpandedParameterPack>::iterator i = Unexpanded.begin(),
639  end = Unexpanded.end();
640  i != end; ++i) {
641  // Compute the depth and index for this parameter pack.
642  unsigned Depth = 0, Index = 0;
643  IdentifierInfo *Name;
644  bool IsFunctionParameterPack = false;
645 
646  if (const TemplateTypeParmType *TTP
647  = i->first.dyn_cast<const TemplateTypeParmType *>()) {
648  Depth = TTP->getDepth();
649  Index = TTP->getIndex();
650  Name = TTP->getIdentifier();
651  } else {
652  NamedDecl *ND = i->first.get<NamedDecl *>();
653  if (isa<ParmVarDecl>(ND))
654  IsFunctionParameterPack = true;
655  else
656  std::tie(Depth, Index) = getDepthAndIndex(ND);
657 
658  Name = ND->getIdentifier();
659  }
660 
661  // Determine the size of this argument pack.
662  unsigned NewPackSize;
663  if (IsFunctionParameterPack) {
664  // Figure out whether we're instantiating to an argument pack or not.
665  typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
666 
667  llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation
668  = CurrentInstantiationScope->findInstantiationOf(
669  i->first.get<NamedDecl *>());
670  if (Instantiation->is<DeclArgumentPack *>()) {
671  // We could expand this function parameter pack.
672  NewPackSize = Instantiation->get<DeclArgumentPack *>()->size();
673  } else {
674  // We can't expand this function parameter pack, so we can't expand
675  // the pack expansion.
676  ShouldExpand = false;
677  continue;
678  }
679  } else {
680  // If we don't have a template argument at this depth/index, then we
681  // cannot expand the pack expansion. Make a note of this, but we still
682  // want to check any parameter packs we *do* have arguments for.
683  if (Depth >= TemplateArgs.getNumLevels() ||
684  !TemplateArgs.hasTemplateArgument(Depth, Index)) {
685  ShouldExpand = false;
686  continue;
687  }
688 
689  // Determine the size of the argument pack.
690  NewPackSize = TemplateArgs(Depth, Index).pack_size();
691  }
692 
693  // C++0x [temp.arg.explicit]p9:
694  // Template argument deduction can extend the sequence of template
695  // arguments corresponding to a template parameter pack, even when the
696  // sequence contains explicitly specified template arguments.
697  if (!IsFunctionParameterPack && CurrentInstantiationScope) {
698  if (NamedDecl *PartialPack
699  = CurrentInstantiationScope->getPartiallySubstitutedPack()){
700  unsigned PartialDepth, PartialIndex;
701  std::tie(PartialDepth, PartialIndex) = getDepthAndIndex(PartialPack);
702  if (PartialDepth == Depth && PartialIndex == Index) {
703  RetainExpansion = true;
704  // We don't actually know the new pack size yet.
705  NumPartialExpansions = NewPackSize;
706  PartiallySubstitutedPackLoc = i->second;
707  continue;
708  }
709  }
710  }
711 
712  if (!NumExpansions) {
713  // The is the first pack we've seen for which we have an argument.
714  // Record it.
715  NumExpansions = NewPackSize;
716  FirstPack.first = Name;
717  FirstPack.second = i->second;
718  HaveFirstPack = true;
719  continue;
720  }
721 
722  if (NewPackSize != *NumExpansions) {
723  // C++0x [temp.variadic]p5:
724  // All of the parameter packs expanded by a pack expansion shall have
725  // the same number of arguments specified.
726  if (HaveFirstPack)
727  Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict)
728  << FirstPack.first << Name << *NumExpansions << NewPackSize
729  << SourceRange(FirstPack.second) << SourceRange(i->second);
730  else
731  Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_multilevel)
732  << Name << *NumExpansions << NewPackSize
733  << SourceRange(i->second);
734  return true;
735  }
736  }
737 
738  // If we're performing a partial expansion but we also have a full expansion,
739  // expand to the number of common arguments. For example, given:
740  //
741  // template<typename ...T> struct A {
742  // template<typename ...U> void f(pair<T, U>...);
743  // };
744  //
745  // ... a call to 'A<int, int>().f<int>' should expand the pack once and
746  // retain an expansion.
747  if (NumPartialExpansions) {
748  if (NumExpansions && *NumExpansions < *NumPartialExpansions) {
749  NamedDecl *PartialPack =
750  CurrentInstantiationScope->getPartiallySubstitutedPack();
751  Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_partial)
752  << PartialPack << *NumPartialExpansions << *NumExpansions
753  << SourceRange(PartiallySubstitutedPackLoc);
754  return true;
755  }
756 
757  NumExpansions = NumPartialExpansions;
758  }
759 
760  return false;
761 }
762 
764  const MultiLevelTemplateArgumentList &TemplateArgs) {
765  QualType Pattern = cast<PackExpansionType>(T)->getPattern();
767  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(Pattern);
768 
770  for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
771  // Compute the depth and index for this parameter pack.
772  unsigned Depth;
773  unsigned Index;
774 
775  if (const TemplateTypeParmType *TTP
776  = Unexpanded[I].first.dyn_cast<const TemplateTypeParmType *>()) {
777  Depth = TTP->getDepth();
778  Index = TTP->getIndex();
779  } else {
780  NamedDecl *ND = Unexpanded[I].first.get<NamedDecl *>();
781  if (isa<ParmVarDecl>(ND)) {
782  // Function parameter pack.
783  typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
784 
785  llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation
786  = CurrentInstantiationScope->findInstantiationOf(
787  Unexpanded[I].first.get<NamedDecl *>());
788  if (Instantiation->is<Decl*>())
789  // The pattern refers to an unexpanded pack. We're not ready to expand
790  // this pack yet.
791  return None;
792 
793  unsigned Size = Instantiation->get<DeclArgumentPack *>()->size();
794  assert((!Result || *Result == Size) && "inconsistent pack sizes");
795  Result = Size;
796  continue;
797  }
798 
799  std::tie(Depth, Index) = getDepthAndIndex(ND);
800  }
801  if (Depth >= TemplateArgs.getNumLevels() ||
802  !TemplateArgs.hasTemplateArgument(Depth, Index))
803  // The pattern refers to an unknown template argument. We're not ready to
804  // expand this pack yet.
805  return None;
806 
807  // Determine the size of the argument pack.
808  unsigned Size = TemplateArgs(Depth, Index).pack_size();
809  assert((!Result || *Result == Size) && "inconsistent pack sizes");
810  Result = Size;
811  }
812 
813  return Result;
814 }
815 
817  const DeclSpec &DS = D.getDeclSpec();
818  switch (DS.getTypeSpecType()) {
819  case TST_typename:
820  case TST_typeofType:
821  case TST_underlyingType:
822  case TST_atomic: {
823  QualType T = DS.getRepAsType().get();
824  if (!T.isNull() && T->containsUnexpandedParameterPack())
825  return true;
826  break;
827  }
828 
829  case TST_typeofExpr:
830  case TST_decltype:
831  if (DS.getRepAsExpr() &&
833  return true;
834  break;
835 
836  case TST_unspecified:
837  case TST_void:
838  case TST_char:
839  case TST_wchar:
840  case TST_char8:
841  case TST_char16:
842  case TST_char32:
843  case TST_int:
844  case TST_int128:
845  case TST_half:
846  case TST_float:
847  case TST_double:
848  case TST_Accum:
849  case TST_Fract:
850  case TST_Float16:
851  case TST_float128:
852  case TST_bool:
853  case TST_decimal32:
854  case TST_decimal64:
855  case TST_decimal128:
856  case TST_enum:
857  case TST_union:
858  case TST_struct:
859  case TST_interface:
860  case TST_class:
861  case TST_auto:
862  case TST_auto_type:
863  case TST_decltype_auto:
864 #define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t:
865 #include "clang/Basic/OpenCLImageTypes.def"
866  case TST_unknown_anytype:
867  case TST_error:
868  break;
869  }
870 
871  for (unsigned I = 0, N = D.getNumTypeObjects(); I != N; ++I) {
872  const DeclaratorChunk &Chunk = D.getTypeObject(I);
873  switch (Chunk.Kind) {
879  // These declarator chunks cannot contain any parameter packs.
880  break;
881 
883  if (Chunk.Arr.NumElts &&
885  return true;
886  break;
888  for (unsigned i = 0, e = Chunk.Fun.NumParams; i != e; ++i) {
889  ParmVarDecl *Param = cast<ParmVarDecl>(Chunk.Fun.Params[i].Param);
890  QualType ParamTy = Param->getType();
891  assert(!ParamTy.isNull() && "Couldn't parse type?");
892  if (ParamTy->containsUnexpandedParameterPack()) return true;
893  }
894 
895  if (Chunk.Fun.getExceptionSpecType() == EST_Dynamic) {
896  for (unsigned i = 0; i != Chunk.Fun.getNumExceptions(); ++i) {
897  if (Chunk.Fun.Exceptions[i]
898  .Ty.get()
900  return true;
901  }
902  } else if (isComputedNoexcept(Chunk.Fun.getExceptionSpecType()) &&
904  return true;
905 
906  if (Chunk.Fun.hasTrailingReturnType()) {
907  QualType T = Chunk.Fun.getTrailingReturnType().get();
908  if (!T.isNull() && T->containsUnexpandedParameterPack())
909  return true;
910  }
911  break;
912 
914  if (Chunk.Mem.Scope().getScopeRep() &&
916  return true;
917  break;
918  }
919  }
920 
921  return false;
922 }
923 
924 namespace {
925 
926 // Callback to only accept typo corrections that refer to parameter packs.
927 class ParameterPackValidatorCCC : public CorrectionCandidateCallback {
928  public:
929  bool ValidateCandidate(const TypoCorrection &candidate) override {
930  NamedDecl *ND = candidate.getCorrectionDecl();
931  return ND && ND->isParameterPack();
932  }
933 };
934 
935 }
936 
937 /// Called when an expression computing the size of a parameter pack
938 /// is parsed.
939 ///
940 /// \code
941 /// template<typename ...Types> struct count {
942 /// static const unsigned value = sizeof...(Types);
943 /// };
944 /// \endcode
945 ///
946 //
947 /// \param OpLoc The location of the "sizeof" keyword.
948 /// \param Name The name of the parameter pack whose size will be determined.
949 /// \param NameLoc The source location of the name of the parameter pack.
950 /// \param RParenLoc The location of the closing parentheses.
952  SourceLocation OpLoc,
953  IdentifierInfo &Name,
954  SourceLocation NameLoc,
955  SourceLocation RParenLoc) {
956  // C++0x [expr.sizeof]p5:
957  // The identifier in a sizeof... expression shall name a parameter pack.
958  LookupResult R(*this, &Name, NameLoc, LookupOrdinaryName);
959  LookupName(R, S);
960 
961  NamedDecl *ParameterPack = nullptr;
962  switch (R.getResultKind()) {
963  case LookupResult::Found:
964  ParameterPack = R.getFoundDecl();
965  break;
966 
969  if (TypoCorrection Corrected =
970  CorrectTypo(R.getLookupNameInfo(), R.getLookupKind(), S, nullptr,
971  llvm::make_unique<ParameterPackValidatorCCC>(),
972  CTK_ErrorRecovery)) {
973  diagnoseTypo(Corrected,
974  PDiag(diag::err_sizeof_pack_no_pack_name_suggest) << &Name,
975  PDiag(diag::note_parameter_pack_here));
976  ParameterPack = Corrected.getCorrectionDecl();
977  }
978  break;
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:1479
A call to an overloaded operator written using operator syntax.
Definition: ExprCXX.h:77
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
Represents a function declaration or definition.
Definition: Decl.h:1737
Name lookup found a set of overloaded functions that met the criteria.
Definition: Lookup.h:63
UnexpandedParameterPackContext
The context in which an unexpanded parameter pack is being diagnosed.
Definition: Sema.h:6673
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:337
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:495
PtrTy get() const
Definition: Ownership.h:80
A (possibly-)qualified type.
Definition: Type.h:634
Simple class containing the result of Sema::CorrectTypo.
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:402
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Definition: opencl-c.h:67
const DeclaratorChunk & getTypeObject(unsigned i) const
Return the specified TypeInfo from this declarator.
Definition: DeclSpec.h:2178
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:531
Stmt - This represents one statement.
Definition: Stmt.h:65
The template argument is an expression, and we&#39;ve not resolved it to one of the other forms yet...
Definition: TemplateBase.h:86
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition: Sema.h:1343
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:3722
The base class of the type hierarchy.
Definition: Type.h:1409
One instance of this struct is used for each type in a declarator that is parsed. ...
Definition: DeclSpec.h:1147
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Definition: TemplateBase.h:63
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:25
bool isPackExpansion() const
Determine whether this initializer is a pack expansion.
Definition: DeclCXX.h:2365
Retains information about a function, method, or block that is currently being parsed.
Definition: ScopeInfo.h:96
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1764
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6761
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:56
void setBegin(SourceLocation b)
bool isParameterPack() const
Whether this declaration is a parameter pack.
Definition: DeclBase.cpp:210
unsigned getNumExceptions() const
Get the number of dynamic exception specifications.
Definition: DeclSpec.h:1462
Represents a parameter to a function.
Definition: Decl.h:1549
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:269
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:56
Expr * 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:73
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:238
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:329
A C++ nested-name-specifier augmented with source location information.
TypeSourceInfo * getTypeSourceInfo() const
Definition: TemplateBase.h:506
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:71
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:263
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:487
const DeclarationNameInfo & getLookupNameInfo() const
Gets the name info to look up.
Definition: Lookup.h:233
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:4664
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:321
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:55
StringRef getOpcodeStr() const
Definition: Expr.h:3369
BinaryOperatorKind
Represents the results of name lookup.
Definition: Lookup.h:46
PtrTy get() const
Definition: Ownership.h:170
bool DiagnoseUnexpandedParameterPacks(SourceLocation Loc, UnexpandedParameterPackContext UPPC, ArrayRef< UnexpandedParameterPack > Unexpanded)
Diagnose unexpanded parameter packs.
ArrayTypeInfo Arr
Definition: DeclSpec.h:1518
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:3353
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
Definition: DeclSpec.h:2174
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:1833
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:545
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:62
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:240
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1648
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point...
Definition: Expr.cpp:2703
Contains information about the compound statement currently being parsed.
Definition: ScopeInfo.h:66
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:313
bool containsUnexpandedParameterPack() const
Determines whether this template name contains an unexpanded parameter pack (for C++0x variadic templ...
enum clang::DeclaratorChunk::@215 Kind
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:104
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
Definition: DeclSpec.h:1287
SourceLocation getLocation() const
Definition: Expr.h:1155
SourceRange getRange() const
Definition: DeclSpec.h:67
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:482
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type...
Definition: ExprCXX.h:1870
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:108
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:67
bool isPackExpansion() const
Determine whether this is a pack expansion.
Definition: DeclCXX.h:3632
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
Definition: ExprObjC.h:281
SourceLocation getBeginLoc() const
Definition: DeclSpec.h:71
SourceLocation getEllipsisLoc() const
Definition: TypeLoc.h:2175
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:190
void setEllipsisLoc(SourceLocation Loc)
Definition: TypeLoc.h:2179
Represents a folding of a pack over an operator.
Definition: ExprCXX.h:4265
Data structure that captures multiple levels of template argument lists for use in template instantia...
Definition: Template.h:64
bool isInvalid() const
Definition: Ownership.h:166
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
ValueDecl * getDecl()
Definition: Expr.h:1147
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:699
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:276
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:75
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:2191
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Definition: Ownership.h:153
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:335
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:3807
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, Optional< unsigned > Length=None, ArrayRef< TemplateArgument > PartialArgs=None)
Definition: ExprCXX.cpp:1503
FunctionTypeInfo Fun
Definition: DeclSpec.h:1519
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3578
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:4572
Name lookup found an unresolvable value declaration and cannot yet complete.
Definition: Lookup.h:68
MemberPointerTypeInfo Mem
Definition: DeclSpec.h:1521
CanQualType VoidTy
Definition: ASTContext.h:1015
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:24
bool hasTrailingReturnType() const
Determine whether this function declarator had a trailing-return-type.
Definition: DeclSpec.h:1476
No entity found met the criteria.
Definition: Lookup.h:50
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:109
Optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:5385
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:214
Expr * Value
The value of the dictionary element.
Definition: ExprObjC.h:243
Represents a pack expansion of types.
Definition: Type.h:5360
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:353
Represents a template argument.
Definition: TemplateBase.h:50
void collectUnexpandedParameterPacks(TemplateArgument Arg, SmallVectorImpl< UnexpandedParameterPack > &Unexpanded)
Collect the set of unexpanded parameter packs within the given template argument. ...
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:498
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:79
bool isInvalid() const
Determine whether the given template argument is invalid.
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3674
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:517
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:3771
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:1204
ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, BinaryOperatorKind Operator)
bool isNull() const
Determine whether this template argument has no value.
Definition: TemplateBase.h:237
bool isValid() const
A scope specifier is present, and it refers to a real scope.
Definition: DeclSpec.h:195
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:59
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:449
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:2263
CanQualType DependentTy
Definition: ASTContext.h:1044
unsigned getNumLevels() const
Determine the number of levels in this template argument list.
Definition: Template.h:88
The template argument is a type.
Definition: TemplateBase.h:59
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:91
ExceptionSpecificationType getExceptionSpecType() const
Get the type of exception specification this function has.
Definition: DeclSpec.h:1457
Sema::LookupNameKind getLookupKind() const
Gets the kind of lookup to perform.
Definition: Lookup.h:253
The template argument is actually a parameter pack.
Definition: TemplateBase.h:90
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:237
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:234
unsigned getDepth() const
Definition: Type.h:4570
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:227
The template argument is a template name that was provided for a template template parameter...
Definition: TemplateBase.h:75
Expr * NumElts
This is the size of the array, or null if [] or [*] was specified.
Definition: DeclSpec.h:1211
bool isPackExpansion() const
Determines whether this dictionary element is a pack expansion.
Definition: ExprObjC.h:253
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
Definition: DeclSpec.h:1853
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates)...
Definition: Expr.h:216
Optional< unsigned > getNumExpansions() const
Determine the number of expansions that will be produced when this pack expansion is instantiated...
Definition: ExprCXX.h:3811
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:251
ParsedType getRepAsType() const
Definition: DeclSpec.h:491
SourceLocation getNameLoc() const
Definition: TypeLoc.h:516
Expr * getPattern()
Retrieve the pattern of the pack expansion.
Definition: ExprCXX.h:3800
ExprResult ExprError()
Definition: Ownership.h:279
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:256
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1074
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:203
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:731
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:499
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:280
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:1312
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