clang  12.0.0git
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 *VD = dyn_cast<VarDecl>(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>(VD->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  // declared within 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  if (auto *LSI = getEnclosingLambda()) {
303  for (auto &Pack : Unexpanded) {
304  auto DeclaresThisPack = [&](NamedDecl *LocalPack) {
305  if (auto *TTPT = Pack.first.dyn_cast<const TemplateTypeParmType *>()) {
306  auto *TTPD = dyn_cast<TemplateTypeParmDecl>(LocalPack);
307  return TTPD && TTPD->getTypeForDecl() == TTPT;
308  }
309  return declaresSameEntity(Pack.first.get<NamedDecl *>(), LocalPack);
310  };
311  if (std::find_if(LSI->LocalPacks.begin(), LSI->LocalPacks.end(),
312  DeclaresThisPack) != LSI->LocalPacks.end())
313  LambdaParamPackReferences.push_back(Pack);
314  }
315 
316  if (LambdaParamPackReferences.empty()) {
317  // Construct in lambda only references packs declared outside the lambda.
318  // That's OK for now, but the lambda itself is considered to contain an
319  // unexpanded pack in this case, which will require expansion outside the
320  // lambda.
321 
322  // We do not permit pack expansion that would duplicate a statement
323  // expression, not even within a lambda.
324  // FIXME: We could probably support this for statement expressions that
325  // do not contain labels.
326  // FIXME: This is insufficient to detect this problem; consider
327  // f( ({ bad: 0; }) + pack ... );
328  bool EnclosingStmtExpr = false;
329  for (unsigned N = FunctionScopes.size(); N; --N) {
330  sema::FunctionScopeInfo *Func = FunctionScopes[N-1];
331  if (std::any_of(
332  Func->CompoundScopes.begin(), Func->CompoundScopes.end(),
333  [](sema::CompoundScopeInfo &CSI) { return CSI.IsStmtExpr; })) {
334  EnclosingStmtExpr = true;
335  break;
336  }
337  // Coumpound-statements outside the lambda are OK for now; we'll check
338  // for those when we finish handling the lambda.
339  if (Func == LSI)
340  break;
341  }
342 
343  if (!EnclosingStmtExpr) {
344  LSI->ContainsUnexpandedParameterPack = true;
345  return false;
346  }
347  } else {
348  Unexpanded = LambdaParamPackReferences;
349  }
350  }
351 
355 
356  for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
357  IdentifierInfo *Name = nullptr;
358  if (const TemplateTypeParmType *TTP
359  = Unexpanded[I].first.dyn_cast<const TemplateTypeParmType *>())
360  Name = TTP->getIdentifier();
361  else
362  Name = Unexpanded[I].first.get<NamedDecl *>()->getIdentifier();
363 
364  if (Name && NamesKnown.insert(Name).second)
365  Names.push_back(Name);
366 
367  if (Unexpanded[I].second.isValid())
368  Locations.push_back(Unexpanded[I].second);
369  }
370 
371  DiagnosticBuilder DB = Diag(Loc, diag::err_unexpanded_parameter_pack)
372  << (int)UPPC << (int)Names.size();
373  for (size_t I = 0, E = std::min(Names.size(), (size_t)2); I != E; ++I)
374  DB << Names[I];
375 
376  for (unsigned I = 0, N = Locations.size(); I != N; ++I)
377  DB << SourceRange(Locations[I]);
378  return true;
379 }
380 
382  TypeSourceInfo *T,
384  // C++0x [temp.variadic]p5:
385  // An appearance of a name of a parameter pack that is not expanded is
386  // ill-formed.
388  return false;
389 
391  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(
392  T->getTypeLoc());
393  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
394  return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
395 }
396 
399  // C++0x [temp.variadic]p5:
400  // An appearance of a name of a parameter pack that is not expanded is
401  // ill-formed.
403  return false;
404 
406  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(E);
407  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
408  return DiagnoseUnexpandedParameterPacks(E->getBeginLoc(), UPPC, Unexpanded);
409 }
410 
413  // C++0x [temp.variadic]p5:
414  // An appearance of a name of a parameter pack that is not expanded is
415  // ill-formed.
416  if (!SS.getScopeRep() ||
418  return false;
419 
421  CollectUnexpandedParameterPacksVisitor(Unexpanded)
422  .TraverseNestedNameSpecifier(SS.getScopeRep());
423  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
425  UPPC, Unexpanded);
426 }
427 
430  // C++0x [temp.variadic]p5:
431  // An appearance of a name of a parameter pack that is not expanded is
432  // ill-formed.
433  switch (NameInfo.getName().getNameKind()) {
442  return false;
443 
447  // FIXME: We shouldn't need this null check!
448  if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
449  return DiagnoseUnexpandedParameterPack(NameInfo.getLoc(), TSInfo, UPPC);
450 
452  return false;
453 
454  break;
455  }
456 
458  CollectUnexpandedParameterPacksVisitor(Unexpanded)
459  .TraverseType(NameInfo.getName().getCXXNameType());
460  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
461  return DiagnoseUnexpandedParameterPacks(NameInfo.getLoc(), UPPC, Unexpanded);
462 }
463 
465  TemplateName Template,
467 
468  if (Template.isNull() || !Template.containsUnexpandedParameterPack())
469  return false;
470 
472  CollectUnexpandedParameterPacksVisitor(Unexpanded)
473  .TraverseTemplateName(Template);
474  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
475  return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
476 }
477 
480  if (Arg.getArgument().isNull() ||
482  return false;
483 
485  CollectUnexpandedParameterPacksVisitor(Unexpanded)
486  .TraverseTemplateArgumentLoc(Arg);
487  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
488  return DiagnoseUnexpandedParameterPacks(Arg.getLocation(), UPPC, Unexpanded);
489 }
490 
493  CollectUnexpandedParameterPacksVisitor(Unexpanded)
494  .TraverseTemplateArgument(Arg);
495 }
496 
499  CollectUnexpandedParameterPacksVisitor(Unexpanded)
500  .TraverseTemplateArgumentLoc(Arg);
501 }
502 
505  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(T);
506 }
507 
510  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(TL);
511 }
512 
516  CollectUnexpandedParameterPacksVisitor(Unexpanded)
517  .TraverseNestedNameSpecifierLoc(NNS);
518 }
519 
521  const DeclarationNameInfo &NameInfo,
523  CollectUnexpandedParameterPacksVisitor(Unexpanded)
524  .TraverseDeclarationNameInfo(NameInfo);
525 }
526 
527 
530  SourceLocation EllipsisLoc) {
531  if (Arg.isInvalid())
532  return Arg;
533 
534  switch (Arg.getKind()) {
536  TypeResult Result = ActOnPackExpansion(Arg.getAsType(), EllipsisLoc);
537  if (Result.isInvalid())
538  return ParsedTemplateArgument();
539 
540  return ParsedTemplateArgument(Arg.getKind(), Result.get().getAsOpaquePtr(),
541  Arg.getLocation());
542  }
543 
545  ExprResult Result = ActOnPackExpansion(Arg.getAsExpr(), EllipsisLoc);
546  if (Result.isInvalid())
547  return ParsedTemplateArgument();
548 
549  return ParsedTemplateArgument(Arg.getKind(), Result.get(),
550  Arg.getLocation());
551  }
552 
555  SourceRange R(Arg.getLocation());
556  if (Arg.getScopeSpec().isValid())
557  R.setBegin(Arg.getScopeSpec().getBeginLoc());
558  Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
559  << R;
560  return ParsedTemplateArgument();
561  }
562 
563  return Arg.getTemplatePackExpansion(EllipsisLoc);
564  }
565  llvm_unreachable("Unhandled template argument kind?");
566 }
567 
569  SourceLocation EllipsisLoc) {
570  TypeSourceInfo *TSInfo;
571  GetTypeFromParser(Type, &TSInfo);
572  if (!TSInfo)
573  return true;
574 
575  TypeSourceInfo *TSResult = CheckPackExpansion(TSInfo, EllipsisLoc, None);
576  if (!TSResult)
577  return true;
578 
579  return CreateParsedType(TSResult->getType(), TSResult);
580 }
581 
584  Optional<unsigned> NumExpansions) {
585  // Create the pack expansion type and source-location information.
586  QualType Result = CheckPackExpansion(Pattern->getType(),
587  Pattern->getTypeLoc().getSourceRange(),
588  EllipsisLoc, NumExpansions);
589  if (Result.isNull())
590  return nullptr;
591 
592  TypeLocBuilder TLB;
593  TLB.pushFullCopy(Pattern->getTypeLoc());
595  TL.setEllipsisLoc(EllipsisLoc);
596 
597  return TLB.getTypeSourceInfo(Context, Result);
598 }
599 
601  SourceLocation EllipsisLoc,
602  Optional<unsigned> NumExpansions) {
603  // C++11 [temp.variadic]p5:
604  // The pattern of a pack expansion shall name one or more
605  // parameter packs that are not expanded by a nested pack
606  // expansion.
607  //
608  // A pattern containing a deduced type can't occur "naturally" but arises in
609  // the desugaring of an init-capture pack.
610  if (!Pattern->containsUnexpandedParameterPack() &&
611  !Pattern->getContainedDeducedType()) {
612  Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
613  << PatternRange;
614  return QualType();
615  }
616 
617  return Context.getPackExpansionType(Pattern, NumExpansions);
618 }
619 
621  return CheckPackExpansion(Pattern, EllipsisLoc, None);
622 }
623 
625  Optional<unsigned> NumExpansions) {
626  if (!Pattern)
627  return ExprError();
628 
629  // C++0x [temp.variadic]p5:
630  // The pattern of a pack expansion shall name one or more
631  // parameter packs that are not expanded by a nested pack
632  // expansion.
633  if (!Pattern->containsUnexpandedParameterPack()) {
634  Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
635  << Pattern->getSourceRange();
636  CorrectDelayedTyposInExpr(Pattern);
637  return ExprError();
638  }
639 
640  // Create the pack expansion expression and source-location information.
641  return new (Context)
642  PackExpansionExpr(Context.DependentTy, Pattern, EllipsisLoc, NumExpansions);
643 }
644 
646  SourceLocation EllipsisLoc, SourceRange PatternRange,
648  const MultiLevelTemplateArgumentList &TemplateArgs, bool &ShouldExpand,
649  bool &RetainExpansion, Optional<unsigned> &NumExpansions) {
650  ShouldExpand = true;
651  RetainExpansion = false;
652  std::pair<IdentifierInfo *, SourceLocation> FirstPack;
653  bool HaveFirstPack = false;
654  Optional<unsigned> NumPartialExpansions;
655  SourceLocation PartiallySubstitutedPackLoc;
656 
657  for (ArrayRef<UnexpandedParameterPack>::iterator i = Unexpanded.begin(),
658  end = Unexpanded.end();
659  i != end; ++i) {
660  // Compute the depth and index for this parameter pack.
661  unsigned Depth = 0, Index = 0;
662  IdentifierInfo *Name;
663  bool IsVarDeclPack = false;
664 
665  if (const TemplateTypeParmType *TTP
666  = i->first.dyn_cast<const TemplateTypeParmType *>()) {
667  Depth = TTP->getDepth();
668  Index = TTP->getIndex();
669  Name = TTP->getIdentifier();
670  } else {
671  NamedDecl *ND = i->first.get<NamedDecl *>();
672  if (isa<VarDecl>(ND))
673  IsVarDeclPack = true;
674  else
675  std::tie(Depth, Index) = getDepthAndIndex(ND);
676 
677  Name = ND->getIdentifier();
678  }
679 
680  // Determine the size of this argument pack.
681  unsigned NewPackSize;
682  if (IsVarDeclPack) {
683  // Figure out whether we're instantiating to an argument pack or not.
684  typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
685 
686  llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation
687  = CurrentInstantiationScope->findInstantiationOf(
688  i->first.get<NamedDecl *>());
689  if (Instantiation->is<DeclArgumentPack *>()) {
690  // We could expand this function parameter pack.
691  NewPackSize = Instantiation->get<DeclArgumentPack *>()->size();
692  } else {
693  // We can't expand this function parameter pack, so we can't expand
694  // the pack expansion.
695  ShouldExpand = false;
696  continue;
697  }
698  } else {
699  // If we don't have a template argument at this depth/index, then we
700  // cannot expand the pack expansion. Make a note of this, but we still
701  // want to check any parameter packs we *do* have arguments for.
702  if (Depth >= TemplateArgs.getNumLevels() ||
703  !TemplateArgs.hasTemplateArgument(Depth, Index)) {
704  ShouldExpand = false;
705  continue;
706  }
707 
708  // Determine the size of the argument pack.
709  NewPackSize = TemplateArgs(Depth, Index).pack_size();
710  }
711 
712  // C++0x [temp.arg.explicit]p9:
713  // Template argument deduction can extend the sequence of template
714  // arguments corresponding to a template parameter pack, even when the
715  // sequence contains explicitly specified template arguments.
716  if (!IsVarDeclPack && CurrentInstantiationScope) {
717  if (NamedDecl *PartialPack
718  = CurrentInstantiationScope->getPartiallySubstitutedPack()){
719  unsigned PartialDepth, PartialIndex;
720  std::tie(PartialDepth, PartialIndex) = getDepthAndIndex(PartialPack);
721  if (PartialDepth == Depth && PartialIndex == Index) {
722  RetainExpansion = true;
723  // We don't actually know the new pack size yet.
724  NumPartialExpansions = NewPackSize;
725  PartiallySubstitutedPackLoc = i->second;
726  continue;
727  }
728  }
729  }
730 
731  if (!NumExpansions) {
732  // The is the first pack we've seen for which we have an argument.
733  // Record it.
734  NumExpansions = NewPackSize;
735  FirstPack.first = Name;
736  FirstPack.second = i->second;
737  HaveFirstPack = true;
738  continue;
739  }
740 
741  if (NewPackSize != *NumExpansions) {
742  // C++0x [temp.variadic]p5:
743  // All of the parameter packs expanded by a pack expansion shall have
744  // the same number of arguments specified.
745  if (HaveFirstPack)
746  Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict)
747  << FirstPack.first << Name << *NumExpansions << NewPackSize
748  << SourceRange(FirstPack.second) << SourceRange(i->second);
749  else
750  Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_multilevel)
751  << Name << *NumExpansions << NewPackSize
752  << SourceRange(i->second);
753  return true;
754  }
755  }
756 
757  // If we're performing a partial expansion but we also have a full expansion,
758  // expand to the number of common arguments. For example, given:
759  //
760  // template<typename ...T> struct A {
761  // template<typename ...U> void f(pair<T, U>...);
762  // };
763  //
764  // ... a call to 'A<int, int>().f<int>' should expand the pack once and
765  // retain an expansion.
766  if (NumPartialExpansions) {
767  if (NumExpansions && *NumExpansions < *NumPartialExpansions) {
768  NamedDecl *PartialPack =
769  CurrentInstantiationScope->getPartiallySubstitutedPack();
770  Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_partial)
771  << PartialPack << *NumPartialExpansions << *NumExpansions
772  << SourceRange(PartiallySubstitutedPackLoc);
773  return true;
774  }
775 
776  NumExpansions = NumPartialExpansions;
777  }
778 
779  return false;
780 }
781 
783  const MultiLevelTemplateArgumentList &TemplateArgs) {
784  QualType Pattern = cast<PackExpansionType>(T)->getPattern();
786  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(Pattern);
787 
789  for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
790  // Compute the depth and index for this parameter pack.
791  unsigned Depth;
792  unsigned Index;
793 
794  if (const TemplateTypeParmType *TTP
795  = Unexpanded[I].first.dyn_cast<const TemplateTypeParmType *>()) {
796  Depth = TTP->getDepth();
797  Index = TTP->getIndex();
798  } else {
799  NamedDecl *ND = Unexpanded[I].first.get<NamedDecl *>();
800  if (isa<VarDecl>(ND)) {
801  // Function parameter pack or init-capture pack.
802  typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
803 
804  llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation
805  = CurrentInstantiationScope->findInstantiationOf(
806  Unexpanded[I].first.get<NamedDecl *>());
807  if (Instantiation->is<Decl*>())
808  // The pattern refers to an unexpanded pack. We're not ready to expand
809  // this pack yet.
810  return None;
811 
812  unsigned Size = Instantiation->get<DeclArgumentPack *>()->size();
813  assert((!Result || *Result == Size) && "inconsistent pack sizes");
814  Result = Size;
815  continue;
816  }
817 
818  std::tie(Depth, Index) = getDepthAndIndex(ND);
819  }
820  if (Depth >= TemplateArgs.getNumLevels() ||
821  !TemplateArgs.hasTemplateArgument(Depth, Index))
822  // The pattern refers to an unknown template argument. We're not ready to
823  // expand this pack yet.
824  return None;
825 
826  // Determine the size of the argument pack.
827  unsigned Size = TemplateArgs(Depth, Index).pack_size();
828  assert((!Result || *Result == Size) && "inconsistent pack sizes");
829  Result = Size;
830  }
831 
832  return Result;
833 }
834 
836  const DeclSpec &DS = D.getDeclSpec();
837  switch (DS.getTypeSpecType()) {
838  case TST_typename:
839  case TST_typeofType:
840  case TST_underlyingType:
841  case TST_atomic: {
842  QualType T = DS.getRepAsType().get();
843  if (!T.isNull() && T->containsUnexpandedParameterPack())
844  return true;
845  break;
846  }
847 
848  case TST_typeofExpr:
849  case TST_decltype:
850  case TST_extint:
851  if (DS.getRepAsExpr() &&
853  return true;
854  break;
855 
856  case TST_unspecified:
857  case TST_void:
858  case TST_char:
859  case TST_wchar:
860  case TST_char8:
861  case TST_char16:
862  case TST_char32:
863  case TST_int:
864  case TST_int128:
865  case TST_half:
866  case TST_float:
867  case TST_double:
868  case TST_Accum:
869  case TST_Fract:
870  case TST_Float16:
871  case TST_float128:
872  case TST_bool:
873  case TST_decimal32:
874  case TST_decimal64:
875  case TST_decimal128:
876  case TST_enum:
877  case TST_union:
878  case TST_struct:
879  case TST_interface:
880  case TST_class:
881  case TST_auto:
882  case TST_auto_type:
883  case TST_decltype_auto:
884  case TST_BFloat16:
885 #define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t:
886 #include "clang/Basic/OpenCLImageTypes.def"
887  case TST_unknown_anytype:
888  case TST_error:
889  break;
890  }
891 
892  for (unsigned I = 0, N = D.getNumTypeObjects(); I != N; ++I) {
893  const DeclaratorChunk &Chunk = D.getTypeObject(I);
894  switch (Chunk.Kind) {
900  // These declarator chunks cannot contain any parameter packs.
901  break;
902 
904  if (Chunk.Arr.NumElts &&
906  return true;
907  break;
909  for (unsigned i = 0, e = Chunk.Fun.NumParams; i != e; ++i) {
910  ParmVarDecl *Param = cast<ParmVarDecl>(Chunk.Fun.Params[i].Param);
911  QualType ParamTy = Param->getType();
912  assert(!ParamTy.isNull() && "Couldn't parse type?");
913  if (ParamTy->containsUnexpandedParameterPack()) return true;
914  }
915 
916  if (Chunk.Fun.getExceptionSpecType() == EST_Dynamic) {
917  for (unsigned i = 0; i != Chunk.Fun.getNumExceptions(); ++i) {
918  if (Chunk.Fun.Exceptions[i]
919  .Ty.get()
921  return true;
922  }
923  } else if (isComputedNoexcept(Chunk.Fun.getExceptionSpecType()) &&
925  return true;
926 
927  if (Chunk.Fun.hasTrailingReturnType()) {
928  QualType T = Chunk.Fun.getTrailingReturnType().get();
929  if (!T.isNull() && T->containsUnexpandedParameterPack())
930  return true;
931  }
932  break;
933 
935  if (Chunk.Mem.Scope().getScopeRep() &&
937  return true;
938  break;
939  }
940  }
941 
942  if (Expr *TRC = D.getTrailingRequiresClause())
943  if (TRC->containsUnexpandedParameterPack())
944  return true;
945 
946  return false;
947 }
948 
949 namespace {
950 
951 // Callback to only accept typo corrections that refer to parameter packs.
952 class ParameterPackValidatorCCC final : public CorrectionCandidateCallback {
953  public:
954  bool ValidateCandidate(const TypoCorrection &candidate) override {
955  NamedDecl *ND = candidate.getCorrectionDecl();
956  return ND && ND->isParameterPack();
957  }
958 
959  std::unique_ptr<CorrectionCandidateCallback> clone() override {
960  return std::make_unique<ParameterPackValidatorCCC>(*this);
961  }
962 };
963 
964 }
965 
966 /// Called when an expression computing the size of a parameter pack
967 /// is parsed.
968 ///
969 /// \code
970 /// template<typename ...Types> struct count {
971 /// static const unsigned value = sizeof...(Types);
972 /// };
973 /// \endcode
974 ///
975 //
976 /// \param OpLoc The location of the "sizeof" keyword.
977 /// \param Name The name of the parameter pack whose size will be determined.
978 /// \param NameLoc The source location of the name of the parameter pack.
979 /// \param RParenLoc The location of the closing parentheses.
981  SourceLocation OpLoc,
982  IdentifierInfo &Name,
983  SourceLocation NameLoc,
984  SourceLocation RParenLoc) {
985  // C++0x [expr.sizeof]p5:
986  // The identifier in a sizeof... expression shall name a parameter pack.
987  LookupResult R(*this, &Name, NameLoc, LookupOrdinaryName);
988  LookupName(R, S);
989 
990  NamedDecl *ParameterPack = nullptr;
991  switch (R.getResultKind()) {
992  case LookupResult::Found:
993  ParameterPack = R.getFoundDecl();
994  break;
995 
998  ParameterPackValidatorCCC CCC{};
999  if (TypoCorrection Corrected =
1000  CorrectTypo(R.getLookupNameInfo(), R.getLookupKind(), S, nullptr,
1001  CCC, CTK_ErrorRecovery)) {
1002  diagnoseTypo(Corrected,
1003  PDiag(diag::err_sizeof_pack_no_pack_name_suggest) << &Name,
1004  PDiag(diag::note_parameter_pack_here));
1005  ParameterPack = Corrected.getCorrectionDecl();
1006  }
1007  break;
1008  }
1011  break;
1012 
1014  DiagnoseAmbiguousLookup(R);
1015  return ExprError();
1016  }
1017 
1018  if (!ParameterPack || !ParameterPack->isParameterPack()) {
1019  Diag(NameLoc, diag::err_sizeof_pack_no_pack_name)
1020  << &Name;
1021  return ExprError();
1022  }
1023 
1024  MarkAnyDeclReferenced(OpLoc, ParameterPack, true);
1025 
1026  return SizeOfPackExpr::Create(Context, OpLoc, ParameterPack, NameLoc,
1027  RParenLoc);
1028 }
1029 
1032  TemplateArgumentLoc OrigLoc,
1033  SourceLocation &Ellipsis, Optional<unsigned> &NumExpansions) const {
1034  const TemplateArgument &Argument = OrigLoc.getArgument();
1035  assert(Argument.isPackExpansion());
1036  switch (Argument.getKind()) {
1037  case TemplateArgument::Type: {
1038  // FIXME: We shouldn't ever have to worry about missing
1039  // type-source info!
1040  TypeSourceInfo *ExpansionTSInfo = OrigLoc.getTypeSourceInfo();
1041  if (!ExpansionTSInfo)
1042  ExpansionTSInfo = Context.getTrivialTypeSourceInfo(Argument.getAsType(),
1043  Ellipsis);
1044  PackExpansionTypeLoc Expansion =
1045  ExpansionTSInfo->getTypeLoc().castAs<PackExpansionTypeLoc>();
1046  Ellipsis = Expansion.getEllipsisLoc();
1047 
1048  TypeLoc Pattern = Expansion.getPatternLoc();
1049  NumExpansions = Expansion.getTypePtr()->getNumExpansions();
1050 
1051  // We need to copy the TypeLoc because TemplateArgumentLocs store a
1052  // TypeSourceInfo.
1053  // FIXME: Find some way to avoid the copy?
1054  TypeLocBuilder TLB;
1055  TLB.pushFullCopy(Pattern);
1056  TypeSourceInfo *PatternTSInfo =
1057  TLB.getTypeSourceInfo(Context, Pattern.getType());
1058  return TemplateArgumentLoc(TemplateArgument(Pattern.getType()),
1059  PatternTSInfo);
1060  }
1061 
1063  PackExpansionExpr *Expansion
1064  = cast<PackExpansionExpr>(Argument.getAsExpr());
1065  Expr *Pattern = Expansion->getPattern();
1066  Ellipsis = Expansion->getEllipsisLoc();
1067  NumExpansions = Expansion->getNumExpansions();
1068  return TemplateArgumentLoc(Pattern, Pattern);
1069  }
1070 
1072  Ellipsis = OrigLoc.getTemplateEllipsisLoc();
1073  NumExpansions = Argument.getNumTemplateExpansions();
1074  return TemplateArgumentLoc(Argument.getPackExpansionPattern(),
1075  OrigLoc.getTemplateQualifierLoc(),
1076  OrigLoc.getTemplateNameLoc());
1077 
1084  return TemplateArgumentLoc();
1085  }
1086 
1087  llvm_unreachable("Invalid TemplateArgument Kind!");
1088 }
1089 
1091  assert(Arg.containsUnexpandedParameterPack());
1092 
1093  // If this is a substituted pack, grab that pack. If not, we don't know
1094  // the size yet.
1095  // FIXME: We could find a size in more cases by looking for a substituted
1096  // pack anywhere within this argument, but that's not necessary in the common
1097  // case for 'sizeof...(A)' handling.
1098  TemplateArgument Pack;
1099  switch (Arg.getKind()) {
1101  if (auto *Subst = Arg.getAsType()->getAs<SubstTemplateTypeParmPackType>())
1102  Pack = Subst->getArgumentPack();
1103  else
1104  return None;
1105  break;
1106 
1108  if (auto *Subst =
1109  dyn_cast<SubstNonTypeTemplateParmPackExpr>(Arg.getAsExpr()))
1110  Pack = Subst->getArgumentPack();
1111  else if (auto *Subst = dyn_cast<FunctionParmPackExpr>(Arg.getAsExpr())) {
1112  for (VarDecl *PD : *Subst)
1113  if (PD->isParameterPack())
1114  return None;
1115  return Subst->getNumExpansions();
1116  } else
1117  return None;
1118  break;
1119 
1123  Pack = Subst->getArgumentPack();
1124  else
1125  return None;
1126  break;
1127 
1134  return None;
1135  }
1136 
1137  // Check that no argument in the pack is itself a pack expansion.
1138  for (TemplateArgument Elem : Pack.pack_elements()) {
1139  // There's no point recursing in this case; we would have already
1140  // expanded this pack expansion into the enclosing pack if we could.
1141  if (Elem.isPackExpansion())
1142  return None;
1143  }
1144  return Pack.pack_size();
1145 }
1146 
1147 static void CheckFoldOperand(Sema &S, Expr *E) {
1148  if (!E)
1149  return;
1150 
1151  E = E->IgnoreImpCasts();
1152  auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
1153  if ((OCE && OCE->isInfixBinaryOp()) || isa<BinaryOperator>(E) ||
1154  isa<AbstractConditionalOperator>(E)) {
1155  S.Diag(E->getExprLoc(), diag::err_fold_expression_bad_operand)
1156  << E->getSourceRange()
1158  << FixItHint::CreateInsertion(E->getEndLoc(), ")");
1159  }
1160 }
1161 
1163  tok::TokenKind Operator,
1164  SourceLocation EllipsisLoc, Expr *RHS,
1165  SourceLocation RParenLoc) {
1166  // LHS and RHS must be cast-expressions. We allow an arbitrary expression
1167  // in the parser and reduce down to just cast-expressions here.
1168  CheckFoldOperand(*this, LHS);
1169  CheckFoldOperand(*this, RHS);
1170 
1171  auto DiscardOperands = [&] {
1172  CorrectDelayedTyposInExpr(LHS);
1173  CorrectDelayedTyposInExpr(RHS);
1174  };
1175 
1176  // [expr.prim.fold]p3:
1177  // In a binary fold, op1 and op2 shall be the same fold-operator, and
1178  // either e1 shall contain an unexpanded parameter pack or e2 shall contain
1179  // an unexpanded parameter pack, but not both.
1180  if (LHS && RHS &&
1183  DiscardOperands();
1184  return Diag(EllipsisLoc,
1186  ? diag::err_fold_expression_packs_both_sides
1187  : diag::err_pack_expansion_without_parameter_packs)
1188  << LHS->getSourceRange() << RHS->getSourceRange();
1189  }
1190 
1191  // [expr.prim.fold]p2:
1192  // In a unary fold, the cast-expression shall contain an unexpanded
1193  // parameter pack.
1194  if (!LHS || !RHS) {
1195  Expr *Pack = LHS ? LHS : RHS;
1196  assert(Pack && "fold expression with neither LHS nor RHS");
1197  DiscardOperands();
1198  if (!Pack->containsUnexpandedParameterPack())
1199  return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
1200  << Pack->getSourceRange();
1201  }
1202 
1203  BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
1204  return BuildCXXFoldExpr(LParenLoc, LHS, Opc, EllipsisLoc, RHS, RParenLoc,
1205  None);
1206 }
1207 
1209  BinaryOperatorKind Operator,
1210  SourceLocation EllipsisLoc, Expr *RHS,
1211  SourceLocation RParenLoc,
1212  Optional<unsigned> NumExpansions) {
1213  return new (Context) CXXFoldExpr(Context.DependentTy, LParenLoc, LHS,
1214  Operator, EllipsisLoc, RHS, RParenLoc,
1215  NumExpansions);
1216 }
1217 
1219  BinaryOperatorKind Operator) {
1220  // [temp.variadic]p9:
1221  // If N is zero for a unary fold-expression, the value of the expression is
1222  // && -> true
1223  // || -> false
1224  // , -> void()
1225  // if the operator is not listed [above], the instantiation is ill-formed.
1226  //
1227  // Note that we need to use something like int() here, not merely 0, to
1228  // prevent the result from being a null pointer constant.
1229  QualType ScalarType;
1230  switch (Operator) {
1231  case BO_LOr:
1232  return ActOnCXXBoolLiteral(EllipsisLoc, tok::kw_false);
1233  case BO_LAnd:
1234  return ActOnCXXBoolLiteral(EllipsisLoc, tok::kw_true);
1235  case BO_Comma:
1236  ScalarType = Context.VoidTy;
1237  break;
1238 
1239  default:
1240  return Diag(EllipsisLoc, diag::err_fold_expression_empty)
1241  << BinaryOperator::getOpcodeStr(Operator);
1242  }
1243 
1244  return new (Context) CXXScalarValueInitExpr(
1245  ScalarType, Context.getTrivialTypeSourceInfo(ScalarType, EllipsisLoc),
1246  EllipsisLoc);
1247 }
ParsedType getTrailingReturnType() const
Get the trailing-return-type for this function declarator.
Definition: DeclSpec.h:1501
A call to an overloaded operator written using operator syntax.
Definition: ExprCXX.h:82
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
Represents a function declaration or definition.
Definition: Decl.h:1783
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:7688
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:362
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:502
PtrTy get() const
Definition: Ownership.h:80
A (possibly-)qualified type.
Definition: Type.h:655
Simple class containing the result of Sema::CorrectTypo.
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:409
const DeclaratorChunk & getTypeObject(unsigned i) const
Return the specified TypeInfo from this declarator.
Definition: DeclSpec.h:2223
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:533
Stmt - This represents one statement.
Definition: Stmt.h:68
The template argument is an expression, and we&#39;ve not resolved it to one of the other forms yet...
Definition: TemplateBase.h:86
const Type * getTypeForDecl() const
Definition: Decl.h:3073
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition: Sema.h:1517
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
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:3761
The base class of the type hierarchy.
Definition: Type.h:1472
One instance of this struct is used for each type in a declarator that is parsed. ...
Definition: DeclSpec.h:1169
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: Type.h:6373
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:2287
Retains information about a function, method, or block that is currently being parsed.
Definition: ScopeInfo.h:98
Represents a variable declaration or definition.
Definition: Decl.h:820
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1791
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:7153
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:1484
Represents a parameter to a function.
Definition: Decl.h:1595
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:244
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:58
Expr * NoexceptExpr
Pointer to the expression in the noexcept-specifier of this function, if it has one.
Definition: DeclSpec.h:1350
ExprResult BuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, Optional< unsigned > NumExpansions)
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:263
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:331
A C++ nested-name-specifier augmented with source location information.
TypeSourceInfo * getTypeSourceInfo() const
Definition: TemplateBase.h:508
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:275
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:489
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:4898
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Definition: opencl-c-base.h:40
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:3709
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.
__device__ int
ArrayTypeInfo Arr
Definition: DeclSpec.h:1542
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:3575
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
Definition: DeclSpec.h:2219
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:1904
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:547
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
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition: DeclBase.h:1198
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:64
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:265
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1822
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:2927
Contains information about the compound statement currently being parsed.
Definition: ScopeInfo.h:68
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:340
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:1062
std::pair< unsigned, unsigned > getDepthAndIndex(NamedDecl *ND)
Retrieve the depth and index of a template parameter.
Definition: SemaInternal.h:65
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
Definition: DeclSpec.h:1309
SourceLocation getLocation() const
Definition: Expr.h:1270
SourceRange getRange() const
Definition: DeclSpec.h:69
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:2047
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:110
__DEVICE__ int min(int __a, int __b)
bool containsUnexpandedParameterPacks(Declarator &D)
Determine whether the given declarator contains any unexpanded parameter packs.
bool isPackExpansion() const
Definition: Attr.h:103
Declaration of a template type parameter.
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:68
bool isPackExpansion() const
Determine whether this is a pack expansion.
Definition: DeclCXX.h:3671
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
Definition: ExprObjC.h:306
SourceLocation getBeginLoc() const
Definition: DeclSpec.h:73
SourceLocation getEllipsisLoc() const
Definition: TypeLoc.h:2392
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:192
Defines the clang::TypeLoc interface and its subclasses.
int Depth
Definition: ASTDiff.cpp:191
void setEllipsisLoc(SourceLocation Loc)
Definition: TypeLoc.h:2396
Represents a folding of a pack over an operator.
Definition: ExprCXX.h:4516
Data structure that captures multiple levels of template argument lists for use in template instantia...
Definition: Template.h:75
bool isInvalid() const
Definition: Ownership.h:166
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
ValueDecl * getDecl()
Definition: Expr.h:1262
The result type of a method or function.
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:720
ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, SourceLocation EllipsisLoc)
Invoked when parsing a template argument followed by an ellipsis, which creates a pack expansion...
static StringRef getIdentifier(const Token &Tok)
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:287
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:1346
NestedNameSpecifier * getScopeRep() const
Retrieve the representation of the nested-name-specifier.
Definition: DeclSpec.h:77
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:2408
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:135
unsigned getNumElements() const
getNumElements - Return number of elements of objective-c dictionary literal.
Definition: ExprObjC.h:360
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:4040
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, Optional< unsigned > Length=None, ArrayRef< TemplateArgument > PartialArgs=None)
Definition: ExprCXX.cpp:1515
FunctionTypeInfo Fun
Definition: DeclSpec.h:1543
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3617
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:206
bool isParameterPack() const
Definition: Type.h:4809
Name lookup found an unresolvable value declaration and cannot yet complete.
Definition: Lookup.h:68
MemberPointerTypeInfo Mem
Definition: DeclSpec.h:1545
CanQualType VoidTy
Definition: ASTContext.h:942
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:1498
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:149
Optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:5634
enum clang::DeclaratorChunk::@208 Kind
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:226
Expr * Value
The value of the dictionary element.
Definition: ExprObjC.h:268
Represents a pack expansion of types.
Definition: Type.h:5610
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:355
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.
DeducedType * getContainedDeducedType() const
Get the DeducedType whose type will be deduced for a variable with an initializer of this type...
Definition: Type.cpp:1884
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:500
QualType getType() const
Get the type for which this source info wrapper provides information.
Definition: TypeLoc.h:132
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:3713
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:4004
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:1230
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:197
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
Definition: TypeLoc.h:152
Name lookup found a single declaration that met the criteria.
Definition: Lookup.h:59
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:451
ParsedTemplateArgument getTemplatePackExpansion(SourceLocation EllipsisLoc) const
Retrieve a pack expansion of the given template template argument.
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2185
CanQualType DependentTy
Definition: ASTContext.h:972
unsigned getNumLevels() const
Determine the number of levels in this template argument list.
Definition: Template.h:114
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:96
ExceptionSpecificationType getExceptionSpecType() const
Get the type of exception specification this function has.
Definition: DeclSpec.h:1479
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:146
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:244
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:234
unsigned getDepth() const
Definition: Type.h:4807
Expr * getTrailingRequiresClause()
Sets a trailing requires clause for this declarator.
Definition: DeclSpec.h:2445
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:229
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:1233
bool isPackExpansion() const
Determines whether this dictionary element is a pack expansion.
Definition: ExprObjC.h:278
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
Definition: DeclSpec.h:1894
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates)...
Definition: Expr.h:233
Optional< unsigned > getNumExpansions() const
Determine the number of expansions that will be produced when this pack expansion is instantiated...
Definition: ExprCXX.h:4044
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:263
ParsedType getRepAsType() const
Definition: DeclSpec.h:492
SourceLocation getNameLoc() const
Definition: TypeLoc.h:523
Expr * getPattern()
Retrieve the pattern of the pack expansion.
Definition: ExprCXX.h:4033
ExprResult ExprError()
Definition: Ownership.h:279
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:258
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1190
Optional< unsigned > getNumArgumentsInExpansion(QualType T, const MultiLevelTemplateArgumentList &TemplateArgs)
Determine the number of arguments in the given pack expansion type.
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:540
SmallVector< CompoundScopeInfo, 4 > CompoundScopes
The stack of currently active compound stamement scopes in the function.
Definition: ScopeInfo.h:207
QualType getType() const
Definition: Decl.h:630
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:734
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
Definition: Decl.h:223
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:77
A template template argument, stored as a template name.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:282
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:1334
Attr - This represents one attribute.
Definition: Attr.h:46
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:6384