clang  5.0.0
SemaTemplateVariadic.cpp
Go to the documentation of this file.
1 //===------- SemaTemplateVariadic.cpp - C++ Variadic Templates ------------===/
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //===----------------------------------------------------------------------===/
8 //
9 // This file implements semantic analysis for C++0x variadic templates.
10 //===----------------------------------------------------------------------===/
11 
12 #include "clang/Sema/Sema.h"
13 #include "TypeLocBuilder.h"
14 #include "clang/AST/Expr.h"
16 #include "clang/AST/TypeLoc.h"
17 #include "clang/Sema/Lookup.h"
19 #include "clang/Sema/ScopeInfo.h"
21 #include "clang/Sema/Template.h"
22 
23 using namespace clang;
24 
25 //----------------------------------------------------------------------------
26 // Visitor that collects unexpanded parameter packs
27 //----------------------------------------------------------------------------
28 
29 namespace {
30  /// \brief A class that collects unexpanded parameter packs.
31  class CollectUnexpandedParameterPacksVisitor :
32  public RecursiveASTVisitor<CollectUnexpandedParameterPacksVisitor>
33  {
35  inherited;
36 
38 
39  bool InLambda;
40 
41  public:
42  explicit CollectUnexpandedParameterPacksVisitor(
44  : Unexpanded(Unexpanded), InLambda(false) { }
45 
46  bool shouldWalkTypesOfTypeLocs() const { return false; }
47 
48  //------------------------------------------------------------------------
49  // Recording occurrences of (unexpanded) parameter packs.
50  //------------------------------------------------------------------------
51 
52  /// \brief Record occurrences of template type parameter packs.
53  bool VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
54  if (TL.getTypePtr()->isParameterPack())
55  Unexpanded.push_back(std::make_pair(TL.getTypePtr(), TL.getNameLoc()));
56  return true;
57  }
58 
59  /// \brief Record occurrences of template type parameter packs
60  /// when we don't have proper source-location information for
61  /// them.
62  ///
63  /// Ideally, this routine would never be used.
64  bool VisitTemplateTypeParmType(TemplateTypeParmType *T) {
65  if (T->isParameterPack())
66  Unexpanded.push_back(std::make_pair(T, SourceLocation()));
67 
68  return true;
69  }
70 
71  /// \brief Record occurrences of function and non-type template
72  /// parameter packs in an expression.
73  bool VisitDeclRefExpr(DeclRefExpr *E) {
74  if (E->getDecl()->isParameterPack())
75  Unexpanded.push_back(std::make_pair(E->getDecl(), E->getLocation()));
76 
77  return true;
78  }
79 
80  /// \brief Record occurrences of template template parameter packs.
81  bool TraverseTemplateName(TemplateName Template) {
82  if (TemplateTemplateParmDecl *TTP
83  = dyn_cast_or_null<TemplateTemplateParmDecl>(
84  Template.getAsTemplateDecl()))
85  if (TTP->isParameterPack())
86  Unexpanded.push_back(std::make_pair(TTP, SourceLocation()));
87 
88  return inherited::TraverseTemplateName(Template);
89  }
90 
91  /// \brief Suppress traversal into Objective-C container literal
92  /// elements that are pack expansions.
93  bool TraverseObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
95  return true;
96 
97  for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
99  if (Element.isPackExpansion())
100  continue;
101 
102  TraverseStmt(Element.Key);
103  TraverseStmt(Element.Value);
104  }
105  return true;
106  }
107  //------------------------------------------------------------------------
108  // Pruning the search for unexpanded parameter packs.
109  //------------------------------------------------------------------------
110 
111  /// \brief Suppress traversal into statements and expressions that
112  /// do not contain unexpanded parameter packs.
113  bool TraverseStmt(Stmt *S) {
114  Expr *E = dyn_cast_or_null<Expr>(S);
115  if ((E && E->containsUnexpandedParameterPack()) || InLambda)
116  return inherited::TraverseStmt(S);
117 
118  return true;
119  }
120 
121  /// \brief Suppress traversal into types that do not contain
122  /// unexpanded parameter packs.
123  bool TraverseType(QualType T) {
124  if ((!T.isNull() && T->containsUnexpandedParameterPack()) || InLambda)
125  return inherited::TraverseType(T);
126 
127  return true;
128  }
129 
130  /// \brief Suppress traversel into types with location information
131  /// that do not contain unexpanded parameter packs.
132  bool TraverseTypeLoc(TypeLoc TL) {
133  if ((!TL.getType().isNull() &&
135  InLambda)
136  return inherited::TraverseTypeLoc(TL);
137 
138  return true;
139  }
140 
141  /// \brief Suppress traversal of non-parameter declarations, since
142  /// they cannot contain unexpanded parameter packs.
143  bool TraverseDecl(Decl *D) {
144  if ((D && isa<ParmVarDecl>(D)) || InLambda)
145  return inherited::TraverseDecl(D);
146 
147  return true;
148  }
149 
150  /// \brief Suppress traversal of template argument pack expansions.
151  bool TraverseTemplateArgument(const TemplateArgument &Arg) {
152  if (Arg.isPackExpansion())
153  return true;
154 
155  return inherited::TraverseTemplateArgument(Arg);
156  }
157 
158  /// \brief Suppress traversal of template argument pack expansions.
159  bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc) {
160  if (ArgLoc.getArgument().isPackExpansion())
161  return true;
162 
163  return inherited::TraverseTemplateArgumentLoc(ArgLoc);
164  }
165 
166  /// \brief Note whether we're traversing a lambda containing an unexpanded
167  /// parameter pack. In this case, the unexpanded pack can occur anywhere,
168  /// including all the places where we normally wouldn't look. Within a
169  /// lambda, we don't propagate the 'contains unexpanded parameter pack' bit
170  /// outside an expression.
171  bool TraverseLambdaExpr(LambdaExpr *Lambda) {
172  // The ContainsUnexpandedParameterPack bit on a lambda is always correct,
173  // even if it's contained within another lambda.
174  if (!Lambda->containsUnexpandedParameterPack())
175  return true;
176 
177  bool WasInLambda = InLambda;
178  InLambda = true;
179 
180  // If any capture names a function parameter pack, that pack is expanded
181  // when the lambda is expanded.
183  E = Lambda->capture_end();
184  I != E; ++I) {
185  if (I->capturesVariable()) {
186  VarDecl *VD = I->getCapturedVar();
187  if (VD->isParameterPack())
188  Unexpanded.push_back(std::make_pair(VD, I->getLocation()));
189  }
190  }
191 
192  inherited::TraverseLambdaExpr(Lambda);
193 
194  InLambda = WasInLambda;
195  return true;
196  }
197  };
198 }
199 
200 /// \brief Determine whether it's possible for an unexpanded parameter pack to
201 /// be valid in this location. This only happens when we're in a declaration
202 /// that is nested within an expression that could be expanded, such as a
203 /// lambda-expression within a function call.
204 ///
205 /// This is conservatively correct, but may claim that some unexpanded packs are
206 /// permitted when they are not.
208  for (auto *SI : FunctionScopes)
209  if (isa<sema::LambdaScopeInfo>(SI))
210  return true;
211  return false;
212 }
213 
214 /// \brief Diagnose all of the unexpanded parameter packs in the given
215 /// vector.
216 bool
220  if (Unexpanded.empty())
221  return false;
222 
223  // If we are within a lambda expression, that lambda contains an unexpanded
224  // parameter pack, and we are done.
225  // FIXME: Store 'Unexpanded' on the lambda so we don't need to recompute it
226  // later.
227  for (unsigned N = FunctionScopes.size(); N; --N) {
228  if (sema::LambdaScopeInfo *LSI =
229  dyn_cast<sema::LambdaScopeInfo>(FunctionScopes[N-1])) {
230  LSI->ContainsUnexpandedParameterPack = true;
231  return false;
232  }
233  }
234 
237  llvm::SmallPtrSet<IdentifierInfo *, 4> NamesKnown;
238 
239  for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
240  IdentifierInfo *Name = nullptr;
241  if (const TemplateTypeParmType *TTP
242  = Unexpanded[I].first.dyn_cast<const TemplateTypeParmType *>())
243  Name = TTP->getIdentifier();
244  else
245  Name = Unexpanded[I].first.get<NamedDecl *>()->getIdentifier();
246 
247  if (Name && NamesKnown.insert(Name).second)
248  Names.push_back(Name);
249 
250  if (Unexpanded[I].second.isValid())
251  Locations.push_back(Unexpanded[I].second);
252  }
253 
254  DiagnosticBuilder DB = Diag(Loc, diag::err_unexpanded_parameter_pack)
255  << (int)UPPC << (int)Names.size();
256  for (size_t I = 0, E = std::min(Names.size(), (size_t)2); I != E; ++I)
257  DB << Names[I];
258 
259  for (unsigned I = 0, N = Locations.size(); I != N; ++I)
260  DB << SourceRange(Locations[I]);
261  return true;
262 }
263 
265  TypeSourceInfo *T,
267  // C++0x [temp.variadic]p5:
268  // An appearance of a name of a parameter pack that is not expanded is
269  // ill-formed.
271  return false;
272 
274  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(
275  T->getTypeLoc());
276  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
277  return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
278 }
279 
282  // C++0x [temp.variadic]p5:
283  // An appearance of a name of a parameter pack that is not expanded is
284  // ill-formed.
286  return false;
287 
289  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(E);
290  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
291  return DiagnoseUnexpandedParameterPacks(E->getLocStart(), UPPC, Unexpanded);
292 }
293 
296  // C++0x [temp.variadic]p5:
297  // An appearance of a name of a parameter pack that is not expanded is
298  // ill-formed.
299  if (!SS.getScopeRep() ||
301  return false;
302 
304  CollectUnexpandedParameterPacksVisitor(Unexpanded)
305  .TraverseNestedNameSpecifier(SS.getScopeRep());
306  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
308  UPPC, Unexpanded);
309 }
310 
313  // C++0x [temp.variadic]p5:
314  // An appearance of a name of a parameter pack that is not expanded is
315  // ill-formed.
316  switch (NameInfo.getName().getNameKind()) {
325  return false;
326 
330  // FIXME: We shouldn't need this null check!
331  if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
332  return DiagnoseUnexpandedParameterPack(NameInfo.getLoc(), TSInfo, UPPC);
333 
335  return false;
336 
337  break;
338  }
339 
341  CollectUnexpandedParameterPacksVisitor(Unexpanded)
342  .TraverseType(NameInfo.getName().getCXXNameType());
343  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
344  return DiagnoseUnexpandedParameterPacks(NameInfo.getLoc(), UPPC, Unexpanded);
345 }
346 
348  TemplateName Template,
350 
351  if (Template.isNull() || !Template.containsUnexpandedParameterPack())
352  return false;
353 
355  CollectUnexpandedParameterPacksVisitor(Unexpanded)
356  .TraverseTemplateName(Template);
357  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
358  return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
359 }
360 
363  if (Arg.getArgument().isNull() ||
365  return false;
366 
368  CollectUnexpandedParameterPacksVisitor(Unexpanded)
369  .TraverseTemplateArgumentLoc(Arg);
370  assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
371  return DiagnoseUnexpandedParameterPacks(Arg.getLocation(), UPPC, Unexpanded);
372 }
373 
376  CollectUnexpandedParameterPacksVisitor(Unexpanded)
377  .TraverseTemplateArgument(Arg);
378 }
379 
382  CollectUnexpandedParameterPacksVisitor(Unexpanded)
383  .TraverseTemplateArgumentLoc(Arg);
384 }
385 
388  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(T);
389 }
390 
393  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(TL);
394 }
395 
399  CollectUnexpandedParameterPacksVisitor(Unexpanded)
400  .TraverseNestedNameSpecifierLoc(NNS);
401 }
402 
404  const DeclarationNameInfo &NameInfo,
406  CollectUnexpandedParameterPacksVisitor(Unexpanded)
407  .TraverseDeclarationNameInfo(NameInfo);
408 }
409 
410 
413  SourceLocation EllipsisLoc) {
414  if (Arg.isInvalid())
415  return Arg;
416 
417  switch (Arg.getKind()) {
419  TypeResult Result = ActOnPackExpansion(Arg.getAsType(), EllipsisLoc);
420  if (Result.isInvalid())
421  return ParsedTemplateArgument();
422 
423  return ParsedTemplateArgument(Arg.getKind(), Result.get().getAsOpaquePtr(),
424  Arg.getLocation());
425  }
426 
428  ExprResult Result = ActOnPackExpansion(Arg.getAsExpr(), EllipsisLoc);
429  if (Result.isInvalid())
430  return ParsedTemplateArgument();
431 
432  return ParsedTemplateArgument(Arg.getKind(), Result.get(),
433  Arg.getLocation());
434  }
435 
438  SourceRange R(Arg.getLocation());
439  if (Arg.getScopeSpec().isValid())
440  R.setBegin(Arg.getScopeSpec().getBeginLoc());
441  Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
442  << R;
443  return ParsedTemplateArgument();
444  }
445 
446  return Arg.getTemplatePackExpansion(EllipsisLoc);
447  }
448  llvm_unreachable("Unhandled template argument kind?");
449 }
450 
452  SourceLocation EllipsisLoc) {
453  TypeSourceInfo *TSInfo;
454  GetTypeFromParser(Type, &TSInfo);
455  if (!TSInfo)
456  return true;
457 
458  TypeSourceInfo *TSResult = CheckPackExpansion(TSInfo, EllipsisLoc, None);
459  if (!TSResult)
460  return true;
461 
462  return CreateParsedType(TSResult->getType(), TSResult);
463 }
464 
467  Optional<unsigned> NumExpansions) {
468  // Create the pack expansion type and source-location information.
470  Pattern->getTypeLoc().getSourceRange(),
471  EllipsisLoc, NumExpansions);
472  if (Result.isNull())
473  return nullptr;
474 
475  TypeLocBuilder TLB;
476  TLB.pushFullCopy(Pattern->getTypeLoc());
478  TL.setEllipsisLoc(EllipsisLoc);
479 
480  return TLB.getTypeSourceInfo(Context, Result);
481 }
482 
484  SourceLocation EllipsisLoc,
485  Optional<unsigned> NumExpansions) {
486  // C++0x [temp.variadic]p5:
487  // The pattern of a pack expansion shall name one or more
488  // parameter packs that are not expanded by a nested pack
489  // expansion.
490  if (!Pattern->containsUnexpandedParameterPack()) {
491  Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
492  << PatternRange;
493  return QualType();
494  }
495 
496  return Context.getPackExpansionType(Pattern, NumExpansions);
497 }
498 
500  return CheckPackExpansion(Pattern, EllipsisLoc, None);
501 }
502 
504  Optional<unsigned> NumExpansions) {
505  if (!Pattern)
506  return ExprError();
507 
508  // C++0x [temp.variadic]p5:
509  // The pattern of a pack expansion shall name one or more
510  // parameter packs that are not expanded by a nested pack
511  // expansion.
512  if (!Pattern->containsUnexpandedParameterPack()) {
513  Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
514  << Pattern->getSourceRange();
515  return ExprError();
516  }
517 
518  // Create the pack expansion expression and source-location information.
519  return new (Context)
520  PackExpansionExpr(Context.DependentTy, Pattern, EllipsisLoc, NumExpansions);
521 }
522 
523 /// \brief Retrieve the depth and index of a parameter pack.
524 static std::pair<unsigned, unsigned>
526  if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(ND))
527  return std::make_pair(TTP->getDepth(), TTP->getIndex());
528 
529  if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(ND))
530  return std::make_pair(NTTP->getDepth(), NTTP->getIndex());
531 
532  TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(ND);
533  return std::make_pair(TTP->getDepth(), TTP->getIndex());
534 }
535 
537  SourceLocation EllipsisLoc, SourceRange PatternRange,
539  const MultiLevelTemplateArgumentList &TemplateArgs, bool &ShouldExpand,
540  bool &RetainExpansion, Optional<unsigned> &NumExpansions) {
541  ShouldExpand = true;
542  RetainExpansion = false;
543  std::pair<IdentifierInfo *, SourceLocation> FirstPack;
544  bool HaveFirstPack = false;
545 
546  for (ArrayRef<UnexpandedParameterPack>::iterator i = Unexpanded.begin(),
547  end = Unexpanded.end();
548  i != end; ++i) {
549  // Compute the depth and index for this parameter pack.
550  unsigned Depth = 0, Index = 0;
552  bool IsFunctionParameterPack = false;
553 
554  if (const TemplateTypeParmType *TTP
555  = i->first.dyn_cast<const TemplateTypeParmType *>()) {
556  Depth = TTP->getDepth();
557  Index = TTP->getIndex();
558  Name = TTP->getIdentifier();
559  } else {
560  NamedDecl *ND = i->first.get<NamedDecl *>();
561  if (isa<ParmVarDecl>(ND))
562  IsFunctionParameterPack = true;
563  else
564  std::tie(Depth, Index) = getDepthAndIndex(ND);
565 
566  Name = ND->getIdentifier();
567  }
568 
569  // Determine the size of this argument pack.
570  unsigned NewPackSize;
571  if (IsFunctionParameterPack) {
572  // Figure out whether we're instantiating to an argument pack or not.
573  typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
574 
575  llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation
577  i->first.get<NamedDecl *>());
578  if (Instantiation->is<DeclArgumentPack *>()) {
579  // We could expand this function parameter pack.
580  NewPackSize = Instantiation->get<DeclArgumentPack *>()->size();
581  } else {
582  // We can't expand this function parameter pack, so we can't expand
583  // the pack expansion.
584  ShouldExpand = false;
585  continue;
586  }
587  } else {
588  // If we don't have a template argument at this depth/index, then we
589  // cannot expand the pack expansion. Make a note of this, but we still
590  // want to check any parameter packs we *do* have arguments for.
591  if (Depth >= TemplateArgs.getNumLevels() ||
592  !TemplateArgs.hasTemplateArgument(Depth, Index)) {
593  ShouldExpand = false;
594  continue;
595  }
596 
597  // Determine the size of the argument pack.
598  NewPackSize = TemplateArgs(Depth, Index).pack_size();
599  }
600 
601  // C++0x [temp.arg.explicit]p9:
602  // Template argument deduction can extend the sequence of template
603  // arguments corresponding to a template parameter pack, even when the
604  // sequence contains explicitly specified template arguments.
605  if (!IsFunctionParameterPack && CurrentInstantiationScope) {
606  if (NamedDecl *PartialPack
608  unsigned PartialDepth, PartialIndex;
609  std::tie(PartialDepth, PartialIndex) = getDepthAndIndex(PartialPack);
610  if (PartialDepth == Depth && PartialIndex == Index)
611  RetainExpansion = true;
612  }
613  }
614 
615  if (!NumExpansions) {
616  // The is the first pack we've seen for which we have an argument.
617  // Record it.
618  NumExpansions = NewPackSize;
619  FirstPack.first = Name;
620  FirstPack.second = i->second;
621  HaveFirstPack = true;
622  continue;
623  }
624 
625  if (NewPackSize != *NumExpansions) {
626  // C++0x [temp.variadic]p5:
627  // All of the parameter packs expanded by a pack expansion shall have
628  // the same number of arguments specified.
629  if (HaveFirstPack)
630  Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict)
631  << FirstPack.first << Name << *NumExpansions << NewPackSize
632  << SourceRange(FirstPack.second) << SourceRange(i->second);
633  else
634  Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_multilevel)
635  << Name << *NumExpansions << NewPackSize
636  << SourceRange(i->second);
637  return true;
638  }
639  }
640 
641  return false;
642 }
643 
645  const MultiLevelTemplateArgumentList &TemplateArgs) {
646  QualType Pattern = cast<PackExpansionType>(T)->getPattern();
648  CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(Pattern);
649 
651  for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
652  // Compute the depth and index for this parameter pack.
653  unsigned Depth;
654  unsigned Index;
655 
656  if (const TemplateTypeParmType *TTP
657  = Unexpanded[I].first.dyn_cast<const TemplateTypeParmType *>()) {
658  Depth = TTP->getDepth();
659  Index = TTP->getIndex();
660  } else {
661  NamedDecl *ND = Unexpanded[I].first.get<NamedDecl *>();
662  if (isa<ParmVarDecl>(ND)) {
663  // Function parameter pack.
664  typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
665 
666  llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation
668  Unexpanded[I].first.get<NamedDecl *>());
669  if (Instantiation->is<Decl*>())
670  // The pattern refers to an unexpanded pack. We're not ready to expand
671  // this pack yet.
672  return None;
673 
674  unsigned Size = Instantiation->get<DeclArgumentPack *>()->size();
675  assert((!Result || *Result == Size) && "inconsistent pack sizes");
676  Result = Size;
677  continue;
678  }
679 
680  std::tie(Depth, Index) = getDepthAndIndex(ND);
681  }
682  if (Depth >= TemplateArgs.getNumLevels() ||
683  !TemplateArgs.hasTemplateArgument(Depth, Index))
684  // The pattern refers to an unknown template argument. We're not ready to
685  // expand this pack yet.
686  return None;
687 
688  // Determine the size of the argument pack.
689  unsigned Size = TemplateArgs(Depth, Index).pack_size();
690  assert((!Result || *Result == Size) && "inconsistent pack sizes");
691  Result = Size;
692  }
693 
694  return Result;
695 }
696 
698  const DeclSpec &DS = D.getDeclSpec();
699  switch (DS.getTypeSpecType()) {
700  case TST_typename:
701  case TST_typeofType:
702  case TST_underlyingType:
703  case TST_atomic: {
704  QualType T = DS.getRepAsType().get();
705  if (!T.isNull() && T->containsUnexpandedParameterPack())
706  return true;
707  break;
708  }
709 
710  case TST_typeofExpr:
711  case TST_decltype:
712  if (DS.getRepAsExpr() &&
714  return true;
715  break;
716 
717  case TST_unspecified:
718  case TST_void:
719  case TST_char:
720  case TST_wchar:
721  case TST_char16:
722  case TST_char32:
723  case TST_int:
724  case TST_int128:
725  case TST_half:
726  case TST_float:
727  case TST_double:
728  case TST_float128:
729  case TST_bool:
730  case TST_decimal32:
731  case TST_decimal64:
732  case TST_decimal128:
733  case TST_enum:
734  case TST_union:
735  case TST_struct:
736  case TST_interface:
737  case TST_class:
738  case TST_auto:
739  case TST_auto_type:
740  case TST_decltype_auto:
741 #define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t:
742 #include "clang/Basic/OpenCLImageTypes.def"
743  case TST_unknown_anytype:
744  case TST_error:
745  break;
746  }
747 
748  for (unsigned I = 0, N = D.getNumTypeObjects(); I != N; ++I) {
749  const DeclaratorChunk &Chunk = D.getTypeObject(I);
750  switch (Chunk.Kind) {
756  // These declarator chunks cannot contain any parameter packs.
757  break;
758 
760  if (Chunk.Arr.NumElts &&
762  return true;
763  break;
765  for (unsigned i = 0, e = Chunk.Fun.NumParams; i != e; ++i) {
766  ParmVarDecl *Param = cast<ParmVarDecl>(Chunk.Fun.Params[i].Param);
767  QualType ParamTy = Param->getType();
768  assert(!ParamTy.isNull() && "Couldn't parse type?");
769  if (ParamTy->containsUnexpandedParameterPack()) return true;
770  }
771 
772  if (Chunk.Fun.getExceptionSpecType() == EST_Dynamic) {
773  for (unsigned i = 0; i != Chunk.Fun.getNumExceptions(); ++i) {
774  if (Chunk.Fun.Exceptions[i]
775  .Ty.get()
777  return true;
778  }
779  } else if (Chunk.Fun.getExceptionSpecType() == EST_ComputedNoexcept &&
781  return true;
782 
783  if (Chunk.Fun.hasTrailingReturnType()) {
784  QualType T = Chunk.Fun.getTrailingReturnType().get();
785  if (!T.isNull() && T->containsUnexpandedParameterPack())
786  return true;
787  }
788  break;
789 
791  if (Chunk.Mem.Scope().getScopeRep() &&
793  return true;
794  break;
795  }
796  }
797 
798  return false;
799 }
800 
801 namespace {
802 
803 // Callback to only accept typo corrections that refer to parameter packs.
804 class ParameterPackValidatorCCC : public CorrectionCandidateCallback {
805  public:
806  bool ValidateCandidate(const TypoCorrection &candidate) override {
807  NamedDecl *ND = candidate.getCorrectionDecl();
808  return ND && ND->isParameterPack();
809  }
810 };
811 
812 }
813 
814 /// \brief Called when an expression computing the size of a parameter pack
815 /// is parsed.
816 ///
817 /// \code
818 /// template<typename ...Types> struct count {
819 /// static const unsigned value = sizeof...(Types);
820 /// };
821 /// \endcode
822 ///
823 //
824 /// \param OpLoc The location of the "sizeof" keyword.
825 /// \param Name The name of the parameter pack whose size will be determined.
826 /// \param NameLoc The source location of the name of the parameter pack.
827 /// \param RParenLoc The location of the closing parentheses.
829  SourceLocation OpLoc,
831  SourceLocation NameLoc,
832  SourceLocation RParenLoc) {
833  // C++0x [expr.sizeof]p5:
834  // The identifier in a sizeof... expression shall name a parameter pack.
835  LookupResult R(*this, &Name, NameLoc, LookupOrdinaryName);
836  LookupName(R, S);
837 
838  NamedDecl *ParameterPack = nullptr;
839  switch (R.getResultKind()) {
840  case LookupResult::Found:
841  ParameterPack = R.getFoundDecl();
842  break;
843 
846  if (TypoCorrection Corrected =
847  CorrectTypo(R.getLookupNameInfo(), R.getLookupKind(), S, nullptr,
848  llvm::make_unique<ParameterPackValidatorCCC>(),
850  diagnoseTypo(Corrected,
851  PDiag(diag::err_sizeof_pack_no_pack_name_suggest) << &Name,
852  PDiag(diag::note_parameter_pack_here));
853  ParameterPack = Corrected.getCorrectionDecl();
854  }
855 
858  break;
859 
862  return ExprError();
863  }
864 
865  if (!ParameterPack || !ParameterPack->isParameterPack()) {
866  Diag(NameLoc, diag::err_sizeof_pack_no_pack_name)
867  << &Name;
868  return ExprError();
869  }
870 
871  MarkAnyDeclReferenced(OpLoc, ParameterPack, true);
872 
873  return SizeOfPackExpr::Create(Context, OpLoc, ParameterPack, NameLoc,
874  RParenLoc);
875 }
876 
879  TemplateArgumentLoc OrigLoc,
880  SourceLocation &Ellipsis, Optional<unsigned> &NumExpansions) const {
881  const TemplateArgument &Argument = OrigLoc.getArgument();
882  assert(Argument.isPackExpansion());
883  switch (Argument.getKind()) {
884  case TemplateArgument::Type: {
885  // FIXME: We shouldn't ever have to worry about missing
886  // type-source info!
887  TypeSourceInfo *ExpansionTSInfo = OrigLoc.getTypeSourceInfo();
888  if (!ExpansionTSInfo)
889  ExpansionTSInfo = Context.getTrivialTypeSourceInfo(Argument.getAsType(),
890  Ellipsis);
891  PackExpansionTypeLoc Expansion =
892  ExpansionTSInfo->getTypeLoc().castAs<PackExpansionTypeLoc>();
893  Ellipsis = Expansion.getEllipsisLoc();
894 
895  TypeLoc Pattern = Expansion.getPatternLoc();
896  NumExpansions = Expansion.getTypePtr()->getNumExpansions();
897 
898  // We need to copy the TypeLoc because TemplateArgumentLocs store a
899  // TypeSourceInfo.
900  // FIXME: Find some way to avoid the copy?
901  TypeLocBuilder TLB;
902  TLB.pushFullCopy(Pattern);
903  TypeSourceInfo *PatternTSInfo =
904  TLB.getTypeSourceInfo(Context, Pattern.getType());
905  return TemplateArgumentLoc(TemplateArgument(Pattern.getType()),
906  PatternTSInfo);
907  }
908 
910  PackExpansionExpr *Expansion
911  = cast<PackExpansionExpr>(Argument.getAsExpr());
912  Expr *Pattern = Expansion->getPattern();
913  Ellipsis = Expansion->getEllipsisLoc();
914  NumExpansions = Expansion->getNumExpansions();
915  return TemplateArgumentLoc(Pattern, Pattern);
916  }
917 
919  Ellipsis = OrigLoc.getTemplateEllipsisLoc();
920  NumExpansions = Argument.getNumTemplateExpansions();
922  OrigLoc.getTemplateQualifierLoc(),
923  OrigLoc.getTemplateNameLoc());
924 
931  return TemplateArgumentLoc();
932  }
933 
934  llvm_unreachable("Invalid TemplateArgument Kind!");
935 }
936 
938  assert(Arg.containsUnexpandedParameterPack());
939 
940  // If this is a substituted pack, grab that pack. If not, we don't know
941  // the size yet.
942  // FIXME: We could find a size in more cases by looking for a substituted
943  // pack anywhere within this argument, but that's not necessary in the common
944  // case for 'sizeof...(A)' handling.
945  TemplateArgument Pack;
946  switch (Arg.getKind()) {
948  if (auto *Subst = Arg.getAsType()->getAs<SubstTemplateTypeParmPackType>())
949  Pack = Subst->getArgumentPack();
950  else
951  return None;
952  break;
953 
955  if (auto *Subst =
956  dyn_cast<SubstNonTypeTemplateParmPackExpr>(Arg.getAsExpr()))
957  Pack = Subst->getArgumentPack();
958  else if (auto *Subst = dyn_cast<FunctionParmPackExpr>(Arg.getAsExpr())) {
959  for (ParmVarDecl *PD : *Subst)
960  if (PD->isParameterPack())
961  return None;
962  return Subst->getNumExpansions();
963  } else
964  return None;
965  break;
966 
970  Pack = Subst->getArgumentPack();
971  else
972  return None;
973  break;
974 
981  return None;
982  }
983 
984  // Check that no argument in the pack is itself a pack expansion.
985  for (TemplateArgument Elem : Pack.pack_elements()) {
986  // There's no point recursing in this case; we would have already
987  // expanded this pack expansion into the enclosing pack if we could.
988  if (Elem.isPackExpansion())
989  return None;
990  }
991  return Pack.pack_size();
992 }
993 
994 static void CheckFoldOperand(Sema &S, Expr *E) {
995  if (!E)
996  return;
997 
998  E = E->IgnoreImpCasts();
999  auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
1000  if ((OCE && OCE->isInfixBinaryOp()) || isa<BinaryOperator>(E) ||
1001  isa<AbstractConditionalOperator>(E)) {
1002  S.Diag(E->getExprLoc(), diag::err_fold_expression_bad_operand)
1003  << E->getSourceRange()
1005  << FixItHint::CreateInsertion(E->getLocEnd(), ")");
1006  }
1007 }
1008 
1010  tok::TokenKind Operator,
1011  SourceLocation EllipsisLoc, Expr *RHS,
1012  SourceLocation RParenLoc) {
1013  // LHS and RHS must be cast-expressions. We allow an arbitrary expression
1014  // in the parser and reduce down to just cast-expressions here.
1015  CheckFoldOperand(*this, LHS);
1016  CheckFoldOperand(*this, RHS);
1017 
1018  auto DiscardOperands = [&] {
1021  };
1022 
1023  // [expr.prim.fold]p3:
1024  // In a binary fold, op1 and op2 shall be the same fold-operator, and
1025  // either e1 shall contain an unexpanded parameter pack or e2 shall contain
1026  // an unexpanded parameter pack, but not both.
1027  if (LHS && RHS &&
1030  DiscardOperands();
1031  return Diag(EllipsisLoc,
1033  ? diag::err_fold_expression_packs_both_sides
1034  : diag::err_pack_expansion_without_parameter_packs)
1035  << LHS->getSourceRange() << RHS->getSourceRange();
1036  }
1037 
1038  // [expr.prim.fold]p2:
1039  // In a unary fold, the cast-expression shall contain an unexpanded
1040  // parameter pack.
1041  if (!LHS || !RHS) {
1042  Expr *Pack = LHS ? LHS : RHS;
1043  assert(Pack && "fold expression with neither LHS nor RHS");
1044  DiscardOperands();
1045  if (!Pack->containsUnexpandedParameterPack())
1046  return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
1047  << Pack->getSourceRange();
1048  }
1049 
1050  BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
1051  return BuildCXXFoldExpr(LParenLoc, LHS, Opc, EllipsisLoc, RHS, RParenLoc);
1052 }
1053 
1055  BinaryOperatorKind Operator,
1056  SourceLocation EllipsisLoc, Expr *RHS,
1057  SourceLocation RParenLoc) {
1058  return new (Context) CXXFoldExpr(Context.DependentTy, LParenLoc, LHS,
1059  Operator, EllipsisLoc, RHS, RParenLoc);
1060 }
1061 
1063  BinaryOperatorKind Operator) {
1064  // [temp.variadic]p9:
1065  // If N is zero for a unary fold-expression, the value of the expression is
1066  // && -> true
1067  // || -> false
1068  // , -> void()
1069  // if the operator is not listed [above], the instantiation is ill-formed.
1070  //
1071  // Note that we need to use something like int() here, not merely 0, to
1072  // prevent the result from being a null pointer constant.
1073  QualType ScalarType;
1074  switch (Operator) {
1075  case BO_LOr:
1076  return ActOnCXXBoolLiteral(EllipsisLoc, tok::kw_false);
1077  case BO_LAnd:
1078  return ActOnCXXBoolLiteral(EllipsisLoc, tok::kw_true);
1079  case BO_Comma:
1080  ScalarType = Context.VoidTy;
1081  break;
1082 
1083  default:
1084  return Diag(EllipsisLoc, diag::err_fold_expression_empty)
1085  << BinaryOperator::getOpcodeStr(Operator);
1086  }
1087 
1088  return new (Context) CXXScalarValueInitExpr(
1089  ScalarType, Context.getTrivialTypeSourceInfo(ScalarType, EllipsisLoc),
1090  EllipsisLoc);
1091 }
A call to an overloaded operator written using operator syntax.
Definition: ExprCXX.h:52
ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo)
Package the given type and TSI into a ParsedType.
Definition: SemaType.cpp:5437
Name lookup found a set of overloaded functions that met the criteria.
Definition: Lookup.h:49
UnexpandedParameterPackContext
The context in which an unexpanded parameter pack is being diagnosed.
Definition: Sema.h:6422
TemplateArgument getPackExpansionPattern() const
When the template argument is a pack expansion, returns the pattern of the pack expansion.
bool containsUnexpandedParameterPack() const
Whether this nested-name-specifier contains an unexpanded parameter pack (for C++11 variadic template...
A (possibly-)qualified type.
Definition: Type.h:616
Simple class containing the result of Sema::CorrectTypo.
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates)...
Definition: Expr.h:213
bool isInvalid() const
Definition: Ownership.h:159
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Definition: opencl-c.h:60
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc...
Definition: Sema.h:2954
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
Definition: Decl.h:232
static std::pair< unsigned, unsigned > getDepthAndIndex(NamedDecl *ND)
Retrieve the depth and index of a parameter pack.
bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation=false)
Perform unqualified name lookup starting from a given scope.
ParsedType getAsType() const
Retrieve the template type argument's type.
Stmt - This represents one statement.
Definition: Stmt.h:60
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
The template argument is an expression, and we've not resolved it to one of the other forms yet...
Definition: TemplateBase.h:69
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:330
bool hasTemplateArgument(unsigned Depth, unsigned Index) const
Determine whether there is a non-NULL template argument at the given depth and index.
Definition: Template.h:87
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition: Sema.h:1243
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:81
TypeLoc getPatternLoc() const
Definition: TypeLoc.h:2118
llvm::PointerUnion< Decl *, DeclArgumentPack * > * findInstantiationOf(const Decl *D)
Find the instantiation of the declaration D within the current instantiation scope.
PtrTy get() const
Definition: Ownership.h:163
The base class of the type hierarchy.
Definition: Type.h:1303
One instance of this struct is used for each type in a declarator that is parsed. ...
Definition: DeclSpec.h:1133
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Definition: TemplateBase.h:51
A container of type source information.
Definition: Decl.h:62
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:306
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:26
capture_iterator capture_begin() const
Retrieve an iterator pointing to the first lambda capture.
Definition: ExprCXX.cpp:940
ParsedType getTrailingReturnType() const
Get the trailing-return-type for this function declarator.
Definition: DeclSpec.h:1462
ObjCDictionaryElement getKeyValueElement(unsigned Index) const
Definition: ExprObjC.h:309
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:758
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
Definition: SemaInternal.h:25
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1733
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:46
SourceLocation getLocation() const
Retrieve the location of the template argument.
void setBegin(SourceLocation b)
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:1575
ParmVarDecl - Represents a parameter to a function.
Definition: Decl.h:1434
SourceLocation getLocation() const
Definition: Expr.h:1046
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:40
Expr * IgnoreImpCasts() LLVM_READONLY
IgnoreImpCasts - Skip past any implicit casts which might surround this expression.
Definition: Expr.h:2847
Expr * NoexceptExpr
Pointer to the expression in the noexcept-specifier of this function, if it has one.
Definition: DeclSpec.h:1329
DeclarationName getName() const
getName - Returns the embedded declaration name.
One of these records is kept for each identifier that is lexed.
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
Definition: Sema.h:7419
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
Definition: Lookup.h:59
An element in an Objective-C dictionary literal.
Definition: ExprObjC.h:212
A C++ nested-name-specifier augmented with source location information.
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:57
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 getLocation() const
Fetches the primary location of the argument.
Definition: TemplateBase.h:460
Represents the result of substituting a set of types for a template type parameter pack...
Definition: Type.h:4117
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...
TypeSourceInfo * getTypeSourceInfo() const
Definition: TemplateBase.h:479
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:516
No entity found met the criteria within the current instantiation,, but there were dependent base cla...
Definition: Lookup.h:41
TypeSourceInfo * getNamedTypeInfo() const
getNamedTypeInfo - Returns the source type info associated to the name.
bool containsUnexpandedParameterPack() const
Whether this template argument contains an unexpanded parameter pack.
BinaryOperatorKind
Represents the results of name lookup.
Definition: Lookup.h:32
bool DiagnoseUnexpandedParameterPacks(SourceLocation Loc, UnexpandedParameterPackContext UPPC, ArrayRef< UnexpandedParameterPack > Unexpanded)
Diagnose unexpanded parameter packs.
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
Definition: DeclSpec.h:2152
ArrayTypeInfo Arr
Definition: DeclSpec.h:1502
ParsedTemplateTy getAsTemplate() const
Retrieve the template template argument's template name.
KindType getKind() const
Determine what kind of template argument we have.
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:504
capture_iterator capture_end() const
Retrieve an iterator pointing past the end of the sequence of lambda captures.
Definition: ExprCXX.cpp:944
ExprResult ActOnCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS, tok::TokenKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc)
Handle a C++1z fold-expression: ( expr op ... op expr ).
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:39
void DiagnoseAmbiguousLookup(LookupResult &Result)
Produce a diagnostic describing the ambiguity that resulted from name lookup.
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:63
enum clang::DeclaratorChunk::@196 Kind
Optional< unsigned > getFullyPackExpandedSize(TemplateArgument Arg)
Given a template argument that contains an unexpanded parameter pack, but which has already been subs...
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:510
Expr * Key
The key for the dictionary element.
Definition: ExprObjC.h:214
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1519
A class that does preordor or postorder depth-first traversal on the entire Clang AST and visits each...
ParsedTemplateArgument getTemplatePackExpansion(SourceLocation EllipsisLoc) const
Retrieve a pack expansion of the given template template argument.
detail::InMemoryDirectory::const_iterator I
QualType getType() const
Definition: Decl.h:589
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type...
Definition: TypeLoc.h:53
SourceRange getRange() const
Definition: DeclSpec.h:68
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
Optional< unsigned > getNumExpansions() const
Determine the number of expansions that will be produced when this pack expansion is instantiated...
Definition: ExprCXX.h:3605
Optional< unsigned > getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce...
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:269
TemplateArgumentLoc getTemplateArgumentPackExpansionPattern(TemplateArgumentLoc OrigLoc, SourceLocation &Ellipsis, Optional< unsigned > &NumExpansions) const
Returns the pattern of the pack expansion for a template argument.
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:953
TST getTypeSpecType() const
Definition: DeclSpec.h:480
const DeclarationNameInfo & getLookupNameInfo() const
Gets the name info to look up.
Definition: Lookup.h:239
bool containsUnexpandedParameterPack() const
Determines whether this template name contains an unexpanded parameter pack (for C++0x variadic templ...
void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool MightBeOdrUse)
Perform marking for a reference to an arbitrary declaration.
Definition: SemaExpr.cpp:14636
SourceLocation getLocEnd() const LLVM_READONLY
Definition: Stmt.cpp:270
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
Definition: DeclSpec.h:1279
bool isPackExpansion() const
Determines whether this dictionary element is a pack expansion.
Definition: ExprObjC.h:227
NameKind getNameKind() const
getNameKind - Determine what kind of name this is.
int * Depth
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type...
Definition: ExprCXX.h:1740
TypeSourceInfo * CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc, Optional< unsigned > NumExpansions)
Construct a pack expansion type from the pattern of the pack expansion.
Expr - This represents one expression.
Definition: Expr.h:105
bool containsUnexpandedParameterPacks(Declarator &D)
Determine whether the given declarator contains any unexpanded parameter packs.
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:54
NamedDecl * getFoundDecl() const
Fetch the unique decl found by this lookup.
Definition: Lookup.h:503
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:213
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
Definition: ExprObjC.h:257
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
Represents a C++ template name within the type system.
Definition: TemplateName.h:176
char __ovld __cnfn min(char x, char y)
Returns y if y < x, otherwise it returns x.
Defines the clang::TypeLoc interface and its subclasses.
QualType getType() const
Get the type for which this source info wrapper provides information.
Definition: TypeLoc.h:114
SmallVector< sema::FunctionScopeInfo *, 4 > FunctionScopes
Stack containing information about each of the nested function, block, and method scopes that are cur...
Definition: Sema.h:516
void setEllipsisLoc(SourceLocation Loc)
Definition: TypeLoc.h:2106
QualType getCXXNameType() const
getCXXNameType - If this name is one of the C++ names (of a constructor, destructor, or conversion function), return the type associated with that name.
Represents a folding of a pack over an operator.
Definition: ExprCXX.h:4055
Data structure that captures multiple levels of template argument lists for use in template instantia...
Definition: Template.h:42
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
ExceptionSpecificationType getExceptionSpecType() const
Get the type of exception specification this function has.
Definition: DeclSpec.h:1440
ValueDecl * getDecl()
Definition: Expr.h:1038
bool hasTrailingReturnType() const
Determine whether this function declarator had a trailing-return-type.
Definition: DeclSpec.h:1459
The result type of a method or function.
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)
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:480
TypeAndRange * Exceptions
Pointer to a new[]'d array of TypeAndRange objects that contain the types in the function's dynamic e...
Definition: DeclSpec.h:1325
NestedNameSpecifier * getScopeRep() const
Retrieve the representation of the nested-name-specifier.
Definition: DeclSpec.h:76
QualType getPackExpansionType(QualType Pattern, Optional< unsigned > NumExpansions)
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:222
#define false
Definition: stdbool.h:33
NamedDecl * getPartiallySubstitutedPack(const TemplateArgument **ExplicitArgs=nullptr, unsigned *NumExplicitArgs=nullptr) const
Retrieve the partially-substitued template parameter pack.
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Definition: Ownership.h:145
Represents the parsed form of a C++ template argument.
bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, TemplateArgumentListInfo &Result, const MultiLevelTemplateArgumentList &TemplateArgs)
unsigned getNumLevels() const
Determine the number of levels in this template argument list.
Definition: Template.h:66
Encodes a location in the source.
Expr * getAsExpr() const
Retrieve the non-type template argument's expression.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:259
Expr * getRepAsExpr() const
Definition: DeclSpec.h:496
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:119
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, Optional< unsigned > Length=None, ArrayRef< TemplateArgument > PartialArgs=None)
Definition: ExprCXX.cpp:1295
FunctionTypeInfo Fun
Definition: DeclSpec.h:1503
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.
ParsedType getRepAsType() const
Definition: DeclSpec.h:488
SourceLocation getNameLoc() const
Definition: TypeLoc.h:502
Name lookup found an unresolvable value declaration and cannot yet complete.
Definition: Lookup.h:54
MemberPointerTypeInfo Mem
Definition: DeclSpec.h:1505
CanQualType VoidTy
Definition: ASTContext.h:963
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
SourceLocation getBegin() const
SourceLocation getBeginLoc() const
Definition: DeclSpec.h:72
No entity found met the criteria.
Definition: Lookup.h:36
PtrTy get() const
Definition: Ownership.h:74
A template type parameter, stored as a type.
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:70
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:216
Expr * Value
The value of the dictionary element.
Definition: ExprObjC.h:217
void diagnoseTypo(const TypoCorrection &Correction, const PartialDiagnostic &TypoDiag, bool ErrorRecovery=true)
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis that describes this pack expansion.
Definition: ExprCXX.h:3601
Represents a template argument.
Definition: TemplateBase.h:40
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:235
void collectUnexpandedParameterPacks(TemplateArgument Arg, SmallVectorImpl< UnexpandedParameterPack > &Unexpanded)
Collect the set of unexpanded parameter packs within the given template argument. ...
const CXXScopeSpec & getScopeSpec() const
Retrieve the nested-name-specifier that precedes the template name in a template template argument...
StringRef getOpcodeStr() const
Definition: Expr.h:3027
StringRef Name
Definition: USRFinder.cpp:123
Sema::LookupNameKind getLookupKind() const
Gets the kind of lookup to perform.
Definition: Lookup.h:259
SourceLocation getEllipsisLoc() const
Definition: TypeLoc.h:2102
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:63
bool isParameterPack() const
Definition: Type.h:4026
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:3565
bool isNull() const
Determine whether this template argument has no value.
Definition: TemplateBase.h:216
detail::InMemoryDirectory::const_iterator E
static void CheckFoldOperand(Sema &S, Expr *E)
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, BinaryOperatorKind Operator)
unsigned getDepth() const
Get the nesting depth of the template parameter.
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
Definition: TypeLoc.h:134
Name lookup found a single declaration that met the criteria.
Definition: Lookup.h:45
NamedDecl * getCorrectionDecl() const
Gets the pointer to the declaration of the typo correction.
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:428
unsigned getNumExceptions() const
Get the number of dynamic exception specifications.
Definition: DeclSpec.h:1445
ExprResult BuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc)
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:6042
ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind)
ActOnCXXBoolLiteral - Parse {true,false} literals.
CanQualType DependentTy
Definition: ASTContext.h:979
bool isNull() const
Determine whether this template name is NULL.
bool isInvalid() const
Determine whether the given template argument is invalid.
The template argument is a type.
Definition: TemplateBase.h:48
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
Definition: Diagnostic.h:90
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:386
The template argument is actually a parameter pack.
Definition: TemplateBase.h:72
bool isUnexpandedParameterPackPermitted()
Determine whether an unexpanded parameter pack might be permitted in this location.
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
Definition: SemaType.cpp:2468
bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, UnexpandedParameterPackContext UPPC)
If the given type contains an unexpanded parameter pack, diagnose the error.
Captures information about "declaration specifiers".
Definition: DeclSpec.h:228
The template argument is a template name that was provided for a template template parameter...
Definition: TemplateBase.h:60
Expr * NumElts
This is the size of the array, or null if [] or [*] was specified.
Definition: DeclSpec.h:1199
ExprResult CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl=nullptr, llvm::function_ref< ExprResult(Expr *)> Filter=[](Expr *E) -> ExprResult{return E;})
Process any TypoExprs in the given Expr and its children, generating diagnostics as appropriate and r...
LookupResultKind getResultKind() const
Definition: Lookup.h:307
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:245
Expr * getPattern()
Retrieve the pattern of the pack expansion.
Definition: ExprCXX.h:3594
ExprResult ExprError()
Definition: Ownership.h:268
bool isValid() const
A scope specifier is present, and it refers to a real scope.
Definition: DeclSpec.h:196
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:953
Optional< unsigned > getNumArgumentsInExpansion(QualType T, const MultiLevelTemplateArgumentList &TemplateArgs)
Determine the number of arguments in the given pack expansion type.
const DeclaratorChunk & getTypeObject(unsigned i) const
Return the specified TypeInfo from this declarator.
Definition: DeclSpec.h:2156
Wrapper for template type parameters.
Definition: TypeLoc.h:706
bool isParameterPack() const
Whether this declaration is a parameter pack.
Definition: DeclBase.cpp:192
A trivial tuple used to represent a source range.
ASTContext & Context
Definition: Sema.h:305
TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, Sema::LookupNameKind LookupKind, Scope *S, CXXScopeSpec *SS, std::unique_ptr< CorrectionCandidateCallback > CCC, CorrectTypoKind Mode, DeclContext *MemberContext=nullptr, bool EnteringContext=false, const ObjCObjectPointerType *OPT=nullptr, bool RecordFailure=true)
Try to "correct" a typo in the source code by finding visible declarations whose names are similar to...
NamedDecl - This represents a decl with a name.
Definition: Decl.h:213
A template template argument, stored as a template name.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:683
void pushFullCopy(TypeLoc L)
Pushes a copy of the given TypeLoc onto this builder.
ExprResult ActOnSizeofParameterPackExpr(Scope *S, SourceLocation OpLoc, IdentifierInfo &Name, SourceLocation NameLoc, SourceLocation RParenLoc)
Called when an expression computing the size of a parameter pack is parsed.
SourceLocation getLocStart() const LLVM_READONLY
Definition: Stmt.cpp:257
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:471
Optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:4818
unsigned getNumElements() const
getNumElements - Return number of elements of objective-c dictionary literal.
Definition: ExprObjC.h:307
ParamInfo * Params
Params - This is a pointer to a new[]'d array of ParamInfo objects that describe the parameters speci...
Definition: DeclSpec.h:1319
unsigned getIndex() const
Get the index of the template parameter within its parameter list.
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
Definition: DeclSpec.h:1849