clang 20.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 "TypeLocBuilder.h"
13#include "clang/AST/Expr.h"
14#include "clang/AST/ExprObjC.h"
15#include "clang/AST/TypeLoc.h"
16#include "clang/Sema/Lookup.h"
19#include "clang/Sema/Sema.h"
21#include "clang/Sema/Template.h"
22#include "llvm/Support/SaveAndRestore.h"
23#include <optional>
24
25using namespace clang;
26
27//----------------------------------------------------------------------------
28// Visitor that collects unexpanded parameter packs
29//----------------------------------------------------------------------------
30
31namespace {
32 /// A class that collects unexpanded parameter packs.
33class CollectUnexpandedParameterPacksVisitor
36
37 bool InLambdaOrBlock = false;
38 unsigned DepthLimit = (unsigned)-1;
39
40#ifndef NDEBUG
41 bool ContainsIntermediatePacks = false;
42#endif
43
44 void addUnexpanded(NamedDecl *ND, SourceLocation Loc = SourceLocation()) {
45 if (auto *VD = dyn_cast<VarDecl>(ND)) {
46 // For now, the only problematic case is a generic lambda's templated
47 // call operator, so we don't need to look for all the other ways we
48 // could have reached a dependent parameter pack.
49 auto *FD = dyn_cast<FunctionDecl>(VD->getDeclContext());
50 auto *FTD = FD ? FD->getDescribedFunctionTemplate() : nullptr;
51 if (FTD && FTD->getTemplateParameters()->getDepth() >= DepthLimit)
52 return;
53 } else if (getDepthAndIndex(ND).first >= DepthLimit)
54 return;
55
56 Unexpanded.push_back({ND, Loc});
57 }
58 void addUnexpanded(const TemplateTypeParmType *T,
60 if (T->getDepth() < DepthLimit)
61 Unexpanded.push_back({T, Loc});
62 }
63
64 public:
65 explicit CollectUnexpandedParameterPacksVisitor(
67 : Unexpanded(Unexpanded) {
68 ShouldWalkTypesOfTypeLocs = false;
69
70 // We need this so we can find e.g. attributes on lambdas.
71 ShouldVisitImplicitCode = true;
72 }
73
74 //------------------------------------------------------------------------
75 // Recording occurrences of (unexpanded) parameter packs.
76 //------------------------------------------------------------------------
77
78 /// Record occurrences of template type parameter packs.
79 bool VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) override {
80 if (TL.getTypePtr()->isParameterPack())
81 addUnexpanded(TL.getTypePtr(), TL.getNameLoc());
82 return true;
83 }
84
85 /// Record occurrences of template type parameter packs
86 /// when we don't have proper source-location information for
87 /// them.
88 ///
89 /// Ideally, this routine would never be used.
90 bool VisitTemplateTypeParmType(TemplateTypeParmType *T) override {
91 if (T->isParameterPack())
92 addUnexpanded(T);
93
94 return true;
95 }
96
97 /// Record occurrences of function and non-type template
98 /// parameter packs in an expression.
99 bool VisitDeclRefExpr(DeclRefExpr *E) override {
100 if (E->getDecl()->isParameterPack())
101 addUnexpanded(E->getDecl(), E->getLocation());
102
103 return true;
104 }
105
106 /// Record occurrences of template template parameter packs.
107 bool TraverseTemplateName(TemplateName Template) override {
108 if (auto *TTP = dyn_cast_or_null<TemplateTemplateParmDecl>(
109 Template.getAsTemplateDecl())) {
110 if (TTP->isParameterPack())
111 addUnexpanded(TTP);
112 }
113
114#ifndef NDEBUG
115 ContainsIntermediatePacks |=
117#endif
118
120 }
121
122 /// Suppress traversal into Objective-C container literal
123 /// elements that are pack expansions.
124 bool TraverseObjCDictionaryLiteral(ObjCDictionaryLiteral *E) override {
126 return true;
127
128 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
129 ObjCDictionaryElement Element = E->getKeyValueElement(I);
130 if (Element.isPackExpansion())
131 continue;
132
133 TraverseStmt(Element.Key);
134 TraverseStmt(Element.Value);
135 }
136 return true;
137 }
138 //------------------------------------------------------------------------
139 // Pruning the search for unexpanded parameter packs.
140 //------------------------------------------------------------------------
141
142 /// Suppress traversal into statements and expressions that
143 /// do not contain unexpanded parameter packs.
144 bool TraverseStmt(Stmt *S) override {
145 Expr *E = dyn_cast_or_null<Expr>(S);
146 if ((E && E->containsUnexpandedParameterPack()) || InLambdaOrBlock)
148
149 return true;
150 }
151
152 /// Suppress traversal into types that do not contain
153 /// unexpanded parameter packs.
154 bool TraverseType(QualType T) override {
155 if ((!T.isNull() && T->containsUnexpandedParameterPack()) ||
156 InLambdaOrBlock)
158
159 return true;
160 }
161
162 /// Suppress traversal into types with location information
163 /// that do not contain unexpanded parameter packs.
164 bool TraverseTypeLoc(TypeLoc TL) override {
165 if ((!TL.getType().isNull() &&
167 InLambdaOrBlock)
169
170 return true;
171 }
172
173 /// Suppress traversal of parameter packs.
174 bool TraverseDecl(Decl *D) override {
175 // A function parameter pack is a pack expansion, so cannot contain
176 // an unexpanded parameter pack. Likewise for a template parameter
177 // pack that contains any references to other packs.
178 if (D && D->isParameterPack())
179 return true;
180
182 }
183
184 /// Suppress traversal of pack-expanded attributes.
185 bool TraverseAttr(Attr *A) override {
186 if (A->isPackExpansion())
187 return true;
188
190 }
191
192 /// Suppress traversal of pack expansion expressions and types.
193 ///@{
194 bool TraversePackExpansionType(PackExpansionType *T) override {
195 return true;
196 }
197 bool TraversePackExpansionTypeLoc(PackExpansionTypeLoc TL) override {
198 return true;
199 }
200 bool TraversePackExpansionExpr(PackExpansionExpr *E) override {
201 return true;
202 }
203 bool TraverseCXXFoldExpr(CXXFoldExpr *E) override { return true; }
204 bool TraversePackIndexingExpr(PackIndexingExpr *E) override {
205 return DynamicRecursiveASTVisitor::TraverseStmt(E->getIndexExpr());
206 }
207 bool TraversePackIndexingType(PackIndexingType *E) override {
208 return DynamicRecursiveASTVisitor::TraverseStmt(E->getIndexExpr());
209 }
210 bool TraversePackIndexingTypeLoc(PackIndexingTypeLoc TL) override {
212 }
213
214 ///@}
215
216 /// Suppress traversal of using-declaration pack expansion.
217 bool
218 TraverseUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) override {
219 if (D->isPackExpansion())
220 return true;
221
222 return DynamicRecursiveASTVisitor::TraverseUnresolvedUsingValueDecl(D);
223 }
224
225 /// Suppress traversal of using-declaration pack expansion.
226 bool TraverseUnresolvedUsingTypenameDecl(
227 UnresolvedUsingTypenameDecl *D) override {
228 if (D->isPackExpansion())
229 return true;
230
231 return DynamicRecursiveASTVisitor::TraverseUnresolvedUsingTypenameDecl(D);
232 }
233
234 /// Suppress traversal of template argument pack expansions.
235 bool TraverseTemplateArgument(const TemplateArgument &Arg) override {
236 if (Arg.isPackExpansion())
237 return true;
238
240 }
241
242 /// Suppress traversal of template argument pack expansions.
243 bool
244 TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc) override {
245 if (ArgLoc.getArgument().isPackExpansion())
246 return true;
247
249 }
250
251 /// Suppress traversal of base specifier pack expansions.
252 bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier &Base) override {
253 if (Base.isPackExpansion())
254 return true;
255
257 }
258
259 /// Suppress traversal of mem-initializer pack expansions.
261 if (Init->isPackExpansion())
262 return true;
263
265 }
266
267 /// Note whether we're traversing a lambda containing an unexpanded
268 /// parameter pack. In this case, the unexpanded pack can occur anywhere,
269 /// including all the places where we normally wouldn't look. Within a
270 /// lambda, we don't propagate the 'contains unexpanded parameter pack' bit
271 /// outside an expression.
272 bool TraverseLambdaExpr(LambdaExpr *Lambda) override {
273 // The ContainsUnexpandedParameterPack bit on a lambda is always correct,
274 // even if it's contained within another lambda.
275 if (!Lambda->containsUnexpandedParameterPack())
276 return true;
277
278 SaveAndRestore _(InLambdaOrBlock, true);
279 unsigned OldDepthLimit = DepthLimit;
280
281 if (auto *TPL = Lambda->getTemplateParameterList())
282 DepthLimit = TPL->getDepth();
283
284 DynamicRecursiveASTVisitor::TraverseLambdaExpr(Lambda);
285
286 DepthLimit = OldDepthLimit;
287 return true;
288 }
289
290 /// Analogously for blocks.
291 bool TraverseBlockExpr(BlockExpr *Block) override {
292 if (!Block->containsUnexpandedParameterPack())
293 return true;
294
295 SaveAndRestore _(InLambdaOrBlock, true);
296 DynamicRecursiveASTVisitor::TraverseBlockExpr(Block);
297 return true;
298 }
299
300 /// Suppress traversal within pack expansions in lambda captures.
301 bool TraverseLambdaCapture(LambdaExpr *Lambda, const LambdaCapture *C,
302 Expr *Init) override {
303 if (C->isPackExpansion())
304 return true;
305
307 }
308
309#ifndef NDEBUG
310 bool TraverseFunctionParmPackExpr(FunctionParmPackExpr *) override {
311 ContainsIntermediatePacks = true;
312 return true;
313 }
314
315 bool TraverseSubstNonTypeTemplateParmPackExpr(
317 ContainsIntermediatePacks = true;
318 return true;
319 }
320
321 bool VisitSubstTemplateTypeParmPackType(
323 ContainsIntermediatePacks = true;
324 return true;
325 }
326
327 bool VisitSubstTemplateTypeParmPackTypeLoc(
329 ContainsIntermediatePacks = true;
330 return true;
331 }
332
333 bool containsIntermediatePacks() const { return ContainsIntermediatePacks; }
334#endif
335};
336}
337
338/// Determine whether it's possible for an unexpanded parameter pack to
339/// be valid in this location. This only happens when we're in a declaration
340/// that is nested within an expression that could be expanded, such as a
341/// lambda-expression within a function call.
342///
343/// This is conservatively correct, but may claim that some unexpanded packs are
344/// permitted when they are not.
346 for (auto *SI : FunctionScopes)
347 if (isa<sema::LambdaScopeInfo>(SI))
348 return true;
349 return false;
350}
351
352/// Diagnose all of the unexpanded parameter packs in the given
353/// vector.
354bool
358 if (Unexpanded.empty())
359 return false;
360
361 // If we are within a lambda expression and referencing a pack that is not
362 // declared within the lambda itself, that lambda contains an unexpanded
363 // parameter pack, and we are done. Analogously for blocks.
364 // FIXME: Store 'Unexpanded' on the lambda so we don't need to recompute it
365 // later.
366 SmallVector<UnexpandedParameterPack, 4> ParamPackReferences;
368 for (auto &Pack : Unexpanded) {
369 auto DeclaresThisPack = [&](NamedDecl *LocalPack) {
370 if (auto *TTPT = Pack.first.dyn_cast<const TemplateTypeParmType *>()) {
371 auto *TTPD = dyn_cast<TemplateTypeParmDecl>(LocalPack);
372 return TTPD && TTPD->getTypeForDecl() == TTPT;
373 }
374 return declaresSameEntity(cast<NamedDecl *>(Pack.first), LocalPack);
375 };
376 if (llvm::any_of(CSI->LocalPacks, DeclaresThisPack))
377 ParamPackReferences.push_back(Pack);
378 }
379
380 if (ParamPackReferences.empty()) {
381 // Construct in lambda only references packs declared outside the lambda.
382 // That's OK for now, but the lambda itself is considered to contain an
383 // unexpanded pack in this case, which will require expansion outside the
384 // lambda.
385
386 // We do not permit pack expansion that would duplicate a statement
387 // expression, not even within a lambda.
388 // FIXME: We could probably support this for statement expressions that
389 // do not contain labels.
390 // FIXME: This is insufficient to detect this problem; consider
391 // f( ({ bad: 0; }) + pack ... );
392 bool EnclosingStmtExpr = false;
393 for (unsigned N = FunctionScopes.size(); N; --N) {
395 if (llvm::any_of(
396 Func->CompoundScopes,
397 [](sema::CompoundScopeInfo &CSI) { return CSI.IsStmtExpr; })) {
398 EnclosingStmtExpr = true;
399 break;
400 }
401 // Coumpound-statements outside the lambda are OK for now; we'll check
402 // for those when we finish handling the lambda.
403 if (Func == CSI)
404 break;
405 }
406
407 if (!EnclosingStmtExpr) {
408 CSI->ContainsUnexpandedParameterPack = true;
409 return false;
410 }
411 } else {
412 Unexpanded = ParamPackReferences;
413 }
414 }
415
419
420 for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
421 IdentifierInfo *Name = nullptr;
422 if (const TemplateTypeParmType *TTP
423 = Unexpanded[I].first.dyn_cast<const TemplateTypeParmType *>())
424 Name = TTP->getIdentifier();
425 else
426 Name = cast<NamedDecl *>(Unexpanded[I].first)->getIdentifier();
427
428 if (Name && NamesKnown.insert(Name).second)
429 Names.push_back(Name);
430
431 if (Unexpanded[I].second.isValid())
432 Locations.push_back(Unexpanded[I].second);
433 }
434
435 auto DB = Diag(Loc, diag::err_unexpanded_parameter_pack)
436 << (int)UPPC << (int)Names.size();
437 for (size_t I = 0, E = std::min(Names.size(), (size_t)2); I != E; ++I)
438 DB << Names[I];
439
440 for (unsigned I = 0, N = Locations.size(); I != N; ++I)
441 DB << SourceRange(Locations[I]);
442 return true;
443}
444
448 // C++0x [temp.variadic]p5:
449 // An appearance of a name of a parameter pack that is not expanded is
450 // ill-formed.
451 if (!T->getType()->containsUnexpandedParameterPack())
452 return false;
453
455 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(
456 T->getTypeLoc());
457 assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
458 return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
459}
460
463 // C++0x [temp.variadic]p5:
464 // An appearance of a name of a parameter pack that is not expanded is
465 // ill-formed.
467 return false;
468
470 CollectUnexpandedParameterPacksVisitor Visitor(Unexpanded);
471 Visitor.TraverseStmt(E);
472#ifndef NDEBUG
473 // The expression might contain a type/subexpression that has been substituted
474 // but has the expansion held off, e.g. a FunctionParmPackExpr which a larger
475 // CXXFoldExpr would expand. It's only possible when expanding a lambda as a
476 // pattern of a fold expression, so don't fire on an empty result in that
477 // case.
478 bool LambdaReferencingOuterPacks =
479 getEnclosingLambdaOrBlock() && Visitor.containsIntermediatePacks();
480 assert((!Unexpanded.empty() || LambdaReferencingOuterPacks) &&
481 "Unable to find unexpanded parameter packs");
482#endif
483 return DiagnoseUnexpandedParameterPacks(E->getBeginLoc(), UPPC, Unexpanded);
484}
485
488 return false;
489
491 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(RE);
492 assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
493
494 // We only care about unexpanded references to the RequiresExpr's own
495 // parameter packs.
496 auto Parms = RE->getLocalParameters();
497 llvm::SmallPtrSet<NamedDecl*, 8> ParmSet(Parms.begin(), Parms.end());
499 for (auto Parm : Unexpanded)
500 if (ParmSet.contains(Parm.first.dyn_cast<NamedDecl *>()))
501 UnexpandedParms.push_back(Parm);
502 if (UnexpandedParms.empty())
503 return false;
504
506 UnexpandedParms);
507}
508
511 // C++0x [temp.variadic]p5:
512 // An appearance of a name of a parameter pack that is not expanded is
513 // ill-formed.
514 if (!SS.getScopeRep() ||
516 return false;
517
519 CollectUnexpandedParameterPacksVisitor(Unexpanded)
520 .TraverseNestedNameSpecifier(SS.getScopeRep());
521 assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
523 UPPC, Unexpanded);
524}
525
528 // C++0x [temp.variadic]p5:
529 // An appearance of a name of a parameter pack that is not expanded is
530 // ill-formed.
531 switch (NameInfo.getName().getNameKind()) {
540 return false;
541
545 // FIXME: We shouldn't need this null check!
546 if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
547 return DiagnoseUnexpandedParameterPack(NameInfo.getLoc(), TSInfo, UPPC);
548
550 return false;
551
552 break;
553 }
554
556 CollectUnexpandedParameterPacksVisitor(Unexpanded)
557 .TraverseType(NameInfo.getName().getCXXNameType());
558 assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
559 return DiagnoseUnexpandedParameterPacks(NameInfo.getLoc(), UPPC, Unexpanded);
560}
561
563 TemplateName Template,
565
566 if (Template.isNull() || !Template.containsUnexpandedParameterPack())
567 return false;
568
570 CollectUnexpandedParameterPacksVisitor(Unexpanded)
571 .TraverseTemplateName(Template);
572 assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
573 return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
574}
575
578 if (Arg.getArgument().isNull() ||
580 return false;
581
583 CollectUnexpandedParameterPacksVisitor(Unexpanded)
584 .TraverseTemplateArgumentLoc(Arg);
585 assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
586 return DiagnoseUnexpandedParameterPacks(Arg.getLocation(), UPPC, Unexpanded);
587}
588
591 CollectUnexpandedParameterPacksVisitor(Unexpanded)
592 .TraverseTemplateArgument(Arg);
593}
594
597 CollectUnexpandedParameterPacksVisitor(Unexpanded)
598 .TraverseTemplateArgumentLoc(Arg);
599}
600
603 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(T);
604}
605
608 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(TL);
609}
610
614 CollectUnexpandedParameterPacksVisitor(Unexpanded)
615 .TraverseNestedNameSpecifierLoc(NNS);
616}
617
619 const DeclarationNameInfo &NameInfo,
621 CollectUnexpandedParameterPacksVisitor(Unexpanded)
622 .TraverseDeclarationNameInfo(NameInfo);
623}
624
627 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(E);
628}
629
632 SourceLocation EllipsisLoc) {
633 if (Arg.isInvalid())
634 return Arg;
635
636 switch (Arg.getKind()) {
638 TypeResult Result = ActOnPackExpansion(Arg.getAsType(), EllipsisLoc);
639 if (Result.isInvalid())
640 return ParsedTemplateArgument();
641
642 return ParsedTemplateArgument(Arg.getKind(), Result.get().getAsOpaquePtr(),
643 Arg.getLocation());
644 }
645
647 ExprResult Result = ActOnPackExpansion(Arg.getAsExpr(), EllipsisLoc);
648 if (Result.isInvalid())
649 return ParsedTemplateArgument();
650
651 return ParsedTemplateArgument(Arg.getKind(), Result.get(),
652 Arg.getLocation());
653 }
654
657 SourceRange R(Arg.getLocation());
658 if (Arg.getScopeSpec().isValid())
660 Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
661 << R;
662 return ParsedTemplateArgument();
663 }
664
665 return Arg.getTemplatePackExpansion(EllipsisLoc);
666 }
667 llvm_unreachable("Unhandled template argument kind?");
668}
669
671 SourceLocation EllipsisLoc) {
672 TypeSourceInfo *TSInfo;
673 GetTypeFromParser(Type, &TSInfo);
674 if (!TSInfo)
675 return true;
676
677 TypeSourceInfo *TSResult =
678 CheckPackExpansion(TSInfo, EllipsisLoc, std::nullopt);
679 if (!TSResult)
680 return true;
681
682 return CreateParsedType(TSResult->getType(), TSResult);
683}
684
687 std::optional<unsigned> NumExpansions) {
688 // Create the pack expansion type and source-location information.
690 Pattern->getTypeLoc().getSourceRange(),
691 EllipsisLoc, NumExpansions);
692 if (Result.isNull())
693 return nullptr;
694
695 TypeLocBuilder TLB;
696 TLB.pushFullCopy(Pattern->getTypeLoc());
698 TL.setEllipsisLoc(EllipsisLoc);
699
700 return TLB.getTypeSourceInfo(Context, Result);
701}
702
704 SourceLocation EllipsisLoc,
705 std::optional<unsigned> NumExpansions) {
706 // C++11 [temp.variadic]p5:
707 // The pattern of a pack expansion shall name one or more
708 // parameter packs that are not expanded by a nested pack
709 // expansion.
710 //
711 // A pattern containing a deduced type can't occur "naturally" but arises in
712 // the desugaring of an init-capture pack.
713 if (!Pattern->containsUnexpandedParameterPack() &&
714 !Pattern->getContainedDeducedType()) {
715 Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
716 << PatternRange;
717 return QualType();
718 }
719
720 return Context.getPackExpansionType(Pattern, NumExpansions,
721 /*ExpectPackInType=*/false);
722}
723
725 return CheckPackExpansion(Pattern, EllipsisLoc, std::nullopt);
726}
727
729 std::optional<unsigned> NumExpansions) {
730 if (!Pattern)
731 return ExprError();
732
733 // C++0x [temp.variadic]p5:
734 // The pattern of a pack expansion shall name one or more
735 // parameter packs that are not expanded by a nested pack
736 // expansion.
737 if (!Pattern->containsUnexpandedParameterPack()) {
738 Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
739 << Pattern->getSourceRange();
741 return ExprError();
742 }
743
744 // Create the pack expansion expression and source-location information.
745 return new (Context)
746 PackExpansionExpr(Context.DependentTy, Pattern, EllipsisLoc, NumExpansions);
747}
748
750 SourceLocation EllipsisLoc, SourceRange PatternRange,
752 const MultiLevelTemplateArgumentList &TemplateArgs, bool &ShouldExpand,
753 bool &RetainExpansion, std::optional<unsigned> &NumExpansions) {
754 ShouldExpand = true;
755 RetainExpansion = false;
756 std::pair<IdentifierInfo *, SourceLocation> FirstPack;
757 bool HaveFirstPack = false;
758 std::optional<unsigned> NumPartialExpansions;
759 SourceLocation PartiallySubstitutedPackLoc;
760
761 for (UnexpandedParameterPack ParmPack : Unexpanded) {
762 // Compute the depth and index for this parameter pack.
763 unsigned Depth = 0, Index = 0;
764 IdentifierInfo *Name;
765 bool IsVarDeclPack = false;
766
767 if (const TemplateTypeParmType *TTP =
768 ParmPack.first.dyn_cast<const TemplateTypeParmType *>()) {
769 Depth = TTP->getDepth();
770 Index = TTP->getIndex();
771 Name = TTP->getIdentifier();
772 } else {
773 NamedDecl *ND = cast<NamedDecl *>(ParmPack.first);
774 if (isa<VarDecl>(ND))
775 IsVarDeclPack = true;
776 else
777 std::tie(Depth, Index) = getDepthAndIndex(ND);
778
779 Name = ND->getIdentifier();
780 }
781
782 // Determine the size of this argument pack.
783 unsigned NewPackSize, PendingPackExpansionSize = 0;
784 if (IsVarDeclPack) {
785 // Figure out whether we're instantiating to an argument pack or not.
786 typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
787
788 llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation =
790 cast<NamedDecl *>(ParmPack.first));
791 if (isa<DeclArgumentPack *>(*Instantiation)) {
792 // We could expand this function parameter pack.
793 NewPackSize = cast<DeclArgumentPack *>(*Instantiation)->size();
794 } else {
795 // We can't expand this function parameter pack, so we can't expand
796 // the pack expansion.
797 ShouldExpand = false;
798 continue;
799 }
800 } else {
801 // If we don't have a template argument at this depth/index, then we
802 // cannot expand the pack expansion. Make a note of this, but we still
803 // want to check any parameter packs we *do* have arguments for.
804 if (Depth >= TemplateArgs.getNumLevels() ||
805 !TemplateArgs.hasTemplateArgument(Depth, Index)) {
806 ShouldExpand = false;
807 continue;
808 }
809
810 // Determine the size of the argument pack.
812 TemplateArgs(Depth, Index).getPackAsArray();
813 NewPackSize = Pack.size();
814 PendingPackExpansionSize =
815 llvm::count_if(Pack, [](const TemplateArgument &TA) {
816 if (!TA.isPackExpansion())
817 return false;
818
820 return !TA.getAsType()
823
825 return !cast<PackExpansionExpr>(TA.getAsExpr())
826 ->getNumExpansions();
827
828 return !TA.getNumTemplateExpansions();
829 });
830 }
831
832 // C++0x [temp.arg.explicit]p9:
833 // Template argument deduction can extend the sequence of template
834 // arguments corresponding to a template parameter pack, even when the
835 // sequence contains explicitly specified template arguments.
836 if (!IsVarDeclPack && CurrentInstantiationScope) {
837 if (NamedDecl *PartialPack =
839 unsigned PartialDepth, PartialIndex;
840 std::tie(PartialDepth, PartialIndex) = getDepthAndIndex(PartialPack);
841 if (PartialDepth == Depth && PartialIndex == Index) {
842 RetainExpansion = true;
843 // We don't actually know the new pack size yet.
844 NumPartialExpansions = NewPackSize;
845 PartiallySubstitutedPackLoc = ParmPack.second;
846 continue;
847 }
848 }
849 }
850
851 if (!NumExpansions) {
852 // This is the first pack we've seen for which we have an argument.
853 // Record it.
854 NumExpansions = NewPackSize;
855 FirstPack.first = Name;
856 FirstPack.second = ParmPack.second;
857 HaveFirstPack = true;
858 continue;
859 }
860
861 if (NewPackSize != *NumExpansions) {
862 // In some cases, we might be handling packs with unexpanded template
863 // arguments. For example, this can occur when substituting into a type
864 // alias declaration that uses its injected template parameters as
865 // arguments:
866 //
867 // template <class... Outer> struct S {
868 // template <class... Inner> using Alias = S<void(Outer, Inner)...>;
869 // };
870 //
871 // Consider an instantiation attempt like 'S<int>::Alias<Pack...>', where
872 // Pack comes from another template parameter. 'S<int>' is first
873 // instantiated, expanding the outer pack 'Outer' to <int>. The alias
874 // declaration is accordingly substituted, leaving the template arguments
875 // as unexpanded
876 // '<Pack...>'.
877 //
878 // Since we have no idea of the size of '<Pack...>' until its expansion,
879 // we shouldn't assume its pack size for validation. However if we are
880 // certain that there are extra arguments beyond unexpanded packs, in
881 // which case the pack size is already larger than the previous expansion,
882 // we can complain that before instantiation.
883 unsigned LeastNewPackSize = NewPackSize - PendingPackExpansionSize;
884 if (PendingPackExpansionSize && LeastNewPackSize <= *NumExpansions) {
885 ShouldExpand = false;
886 continue;
887 }
888 // C++0x [temp.variadic]p5:
889 // All of the parameter packs expanded by a pack expansion shall have
890 // the same number of arguments specified.
891 if (HaveFirstPack)
892 Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict)
893 << FirstPack.first << Name << *NumExpansions
894 << (LeastNewPackSize != NewPackSize) << LeastNewPackSize
895 << SourceRange(FirstPack.second) << SourceRange(ParmPack.second);
896 else
897 Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_multilevel)
898 << Name << *NumExpansions << (LeastNewPackSize != NewPackSize)
899 << LeastNewPackSize << SourceRange(ParmPack.second);
900 return true;
901 }
902 }
903
904 // If we're performing a partial expansion but we also have a full expansion,
905 // expand to the number of common arguments. For example, given:
906 //
907 // template<typename ...T> struct A {
908 // template<typename ...U> void f(pair<T, U>...);
909 // };
910 //
911 // ... a call to 'A<int, int>().f<int>' should expand the pack once and
912 // retain an expansion.
913 if (NumPartialExpansions) {
914 if (NumExpansions && *NumExpansions < *NumPartialExpansions) {
915 NamedDecl *PartialPack =
917 Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_partial)
918 << PartialPack << *NumPartialExpansions << *NumExpansions
919 << SourceRange(PartiallySubstitutedPackLoc);
920 return true;
921 }
922
923 NumExpansions = NumPartialExpansions;
924 }
925
926 return false;
927}
928
931 const MultiLevelTemplateArgumentList &TemplateArgs) {
932 std::optional<unsigned> Result;
933 for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
934 // Compute the depth and index for this parameter pack.
935 unsigned Depth;
936 unsigned Index;
937
938 if (const TemplateTypeParmType *TTP =
939 Unexpanded[I].first.dyn_cast<const TemplateTypeParmType *>()) {
940 Depth = TTP->getDepth();
941 Index = TTP->getIndex();
942 } else {
943 NamedDecl *ND = cast<NamedDecl *>(Unexpanded[I].first);
944 if (isa<VarDecl>(ND)) {
945 // Function parameter pack or init-capture pack.
946 typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
947
948 llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation =
950 cast<NamedDecl *>(Unexpanded[I].first));
951 if (isa<Decl *>(*Instantiation))
952 // The pattern refers to an unexpanded pack. We're not ready to expand
953 // this pack yet.
954 return std::nullopt;
955
956 unsigned Size = cast<DeclArgumentPack *>(*Instantiation)->size();
957 assert((!Result || *Result == Size) && "inconsistent pack sizes");
958 Result = Size;
959 continue;
960 }
961
962 std::tie(Depth, Index) = getDepthAndIndex(ND);
963 }
964 if (Depth >= TemplateArgs.getNumLevels() ||
965 !TemplateArgs.hasTemplateArgument(Depth, Index))
966 // The pattern refers to an unknown template argument. We're not ready to
967 // expand this pack yet.
968 return std::nullopt;
969
970 // Determine the size of the argument pack.
971 unsigned Size = TemplateArgs(Depth, Index).pack_size();
972 assert((!Result || *Result == Size) && "inconsistent pack sizes");
973 Result = Size;
974 }
975
976 return Result;
977}
978
979std::optional<unsigned> Sema::getNumArgumentsInExpansion(
980 QualType T, const MultiLevelTemplateArgumentList &TemplateArgs) {
981 QualType Pattern = cast<PackExpansionType>(T)->getPattern();
983 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(Pattern);
984 return getNumArgumentsInExpansionFromUnexpanded(Unexpanded, TemplateArgs);
985}
986
988 const DeclSpec &DS = D.getDeclSpec();
989 switch (DS.getTypeSpecType()) {
991 case TST_typename:
993 case TST_typeofType:
994#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case TST_##Trait:
995#include "clang/Basic/TransformTypeTraits.def"
996 case TST_atomic: {
997 QualType T = DS.getRepAsType().get();
998 if (!T.isNull() && T->containsUnexpandedParameterPack())
999 return true;
1000 break;
1001 }
1002
1004 case TST_typeofExpr:
1005 case TST_decltype:
1006 case TST_bitint:
1007 if (DS.getRepAsExpr() &&
1009 return true;
1010 break;
1011
1012 case TST_unspecified:
1013 case TST_void:
1014 case TST_char:
1015 case TST_wchar:
1016 case TST_char8:
1017 case TST_char16:
1018 case TST_char32:
1019 case TST_int:
1020 case TST_int128:
1021 case TST_half:
1022 case TST_float:
1023 case TST_double:
1024 case TST_Accum:
1025 case TST_Fract:
1026 case TST_Float16:
1027 case TST_float128:
1028 case TST_ibm128:
1029 case TST_bool:
1030 case TST_decimal32:
1031 case TST_decimal64:
1032 case TST_decimal128:
1033 case TST_enum:
1034 case TST_union:
1035 case TST_struct:
1036 case TST_interface:
1037 case TST_class:
1038 case TST_auto:
1039 case TST_auto_type:
1040 case TST_decltype_auto:
1041 case TST_BFloat16:
1042#define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t:
1043#include "clang/Basic/OpenCLImageTypes.def"
1044#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case TST_##Name:
1045#include "clang/Basic/HLSLIntangibleTypes.def"
1047 case TST_error:
1048 break;
1049 }
1050
1051 for (unsigned I = 0, N = D.getNumTypeObjects(); I != N; ++I) {
1052 const DeclaratorChunk &Chunk = D.getTypeObject(I);
1053 switch (Chunk.Kind) {
1059 // These declarator chunks cannot contain any parameter packs.
1060 break;
1061
1063 if (Chunk.Arr.NumElts &&
1065 return true;
1066 break;
1068 for (unsigned i = 0, e = Chunk.Fun.NumParams; i != e; ++i) {
1069 ParmVarDecl *Param = cast<ParmVarDecl>(Chunk.Fun.Params[i].Param);
1070 QualType ParamTy = Param->getType();
1071 assert(!ParamTy.isNull() && "Couldn't parse type?");
1072 if (ParamTy->containsUnexpandedParameterPack()) return true;
1073 }
1074
1075 if (Chunk.Fun.getExceptionSpecType() == EST_Dynamic) {
1076 for (unsigned i = 0; i != Chunk.Fun.getNumExceptions(); ++i) {
1077 if (Chunk.Fun.Exceptions[i]
1078 .Ty.get()
1080 return true;
1081 }
1082 } else if (isComputedNoexcept(Chunk.Fun.getExceptionSpecType()) &&
1084 return true;
1085
1086 if (Chunk.Fun.hasTrailingReturnType()) {
1088 if (!T.isNull() && T->containsUnexpandedParameterPack())
1089 return true;
1090 }
1091 break;
1092
1094 if (Chunk.Mem.Scope().getScopeRep() &&
1096 return true;
1097 break;
1098 }
1099 }
1100
1101 if (Expr *TRC = D.getTrailingRequiresClause())
1102 if (TRC->containsUnexpandedParameterPack())
1103 return true;
1104
1105 return false;
1106}
1107
1108namespace {
1109
1110// Callback to only accept typo corrections that refer to parameter packs.
1111class ParameterPackValidatorCCC final : public CorrectionCandidateCallback {
1112 public:
1113 bool ValidateCandidate(const TypoCorrection &candidate) override {
1114 NamedDecl *ND = candidate.getCorrectionDecl();
1115 return ND && ND->isParameterPack();
1116 }
1117
1118 std::unique_ptr<CorrectionCandidateCallback> clone() override {
1119 return std::make_unique<ParameterPackValidatorCCC>(*this);
1120 }
1121};
1122
1123}
1124
1126 SourceLocation OpLoc,
1127 IdentifierInfo &Name,
1128 SourceLocation NameLoc,
1129 SourceLocation RParenLoc) {
1130 // C++0x [expr.sizeof]p5:
1131 // The identifier in a sizeof... expression shall name a parameter pack.
1132 LookupResult R(*this, &Name, NameLoc, LookupOrdinaryName);
1133 LookupName(R, S);
1134
1135 NamedDecl *ParameterPack = nullptr;
1136 switch (R.getResultKind()) {
1138 ParameterPack = R.getFoundDecl();
1139 break;
1140
1143 ParameterPackValidatorCCC CCC{};
1144 if (TypoCorrection Corrected =
1145 CorrectTypo(R.getLookupNameInfo(), R.getLookupKind(), S, nullptr,
1146 CCC, CTK_ErrorRecovery)) {
1147 diagnoseTypo(Corrected,
1148 PDiag(diag::err_sizeof_pack_no_pack_name_suggest) << &Name,
1149 PDiag(diag::note_parameter_pack_here));
1150 ParameterPack = Corrected.getCorrectionDecl();
1151 }
1152 break;
1153 }
1156 break;
1157
1160 return ExprError();
1161 }
1162
1163 if (!ParameterPack || !ParameterPack->isParameterPack()) {
1164 Diag(NameLoc, diag::err_expected_name_of_pack) << &Name;
1165 return ExprError();
1166 }
1167
1168 MarkAnyDeclReferenced(OpLoc, ParameterPack, true);
1169
1170 return SizeOfPackExpr::Create(Context, OpLoc, ParameterPack, NameLoc,
1171 RParenLoc);
1172}
1173
1174static bool isParameterPack(Expr *PackExpression) {
1175 if (auto *D = dyn_cast<DeclRefExpr>(PackExpression); D) {
1176 ValueDecl *VD = D->getDecl();
1177 return VD->isParameterPack();
1178 }
1179 return false;
1180}
1181
1183 SourceLocation EllipsisLoc,
1184 SourceLocation LSquareLoc,
1185 Expr *IndexExpr,
1186 SourceLocation RSquareLoc) {
1187 bool isParameterPack = ::isParameterPack(PackExpression);
1188 if (!isParameterPack) {
1189 if (!PackExpression->containsErrors()) {
1190 CorrectDelayedTyposInExpr(IndexExpr);
1191 Diag(PackExpression->getBeginLoc(), diag::err_expected_name_of_pack)
1192 << PackExpression;
1193 }
1194 return ExprError();
1195 }
1196 ExprResult Res =
1197 BuildPackIndexingExpr(PackExpression, EllipsisLoc, IndexExpr, RSquareLoc);
1198 if (!Res.isInvalid())
1200 ? diag::warn_cxx23_pack_indexing
1201 : diag::ext_pack_indexing);
1202 return Res;
1203}
1204
1206 SourceLocation EllipsisLoc,
1207 Expr *IndexExpr,
1208 SourceLocation RSquareLoc,
1209 ArrayRef<Expr *> ExpandedExprs,
1210 bool FullySubstituted) {
1211
1212 std::optional<int64_t> Index;
1213 if (!IndexExpr->isInstantiationDependent()) {
1214 llvm::APSInt Value(Context.getIntWidth(Context.getSizeType()));
1215
1217 IndexExpr, Context.getSizeType(), Value, CCEK_ArrayBound);
1218 if (!Res.isUsable())
1219 return ExprError();
1220 Index = Value.getExtValue();
1221 IndexExpr = Res.get();
1222 }
1223
1224 if (Index && FullySubstituted) {
1225 if (*Index < 0 || *Index >= int64_t(ExpandedExprs.size())) {
1226 Diag(PackExpression->getBeginLoc(), diag::err_pack_index_out_of_bound)
1227 << *Index << PackExpression << ExpandedExprs.size();
1228 return ExprError();
1229 }
1230 }
1231
1232 return PackIndexingExpr::Create(getASTContext(), EllipsisLoc, RSquareLoc,
1233 PackExpression, IndexExpr, Index,
1234 ExpandedExprs, FullySubstituted);
1235}
1236
1238 TemplateArgumentLoc OrigLoc, SourceLocation &Ellipsis,
1239 std::optional<unsigned> &NumExpansions) const {
1240 const TemplateArgument &Argument = OrigLoc.getArgument();
1241 assert(Argument.isPackExpansion());
1242 switch (Argument.getKind()) {
1244 // FIXME: We shouldn't ever have to worry about missing
1245 // type-source info!
1246 TypeSourceInfo *ExpansionTSInfo = OrigLoc.getTypeSourceInfo();
1247 if (!ExpansionTSInfo)
1248 ExpansionTSInfo = Context.getTrivialTypeSourceInfo(Argument.getAsType(),
1249 Ellipsis);
1250 PackExpansionTypeLoc Expansion =
1251 ExpansionTSInfo->getTypeLoc().castAs<PackExpansionTypeLoc>();
1252 Ellipsis = Expansion.getEllipsisLoc();
1253
1254 TypeLoc Pattern = Expansion.getPatternLoc();
1255 NumExpansions = Expansion.getTypePtr()->getNumExpansions();
1256
1257 // We need to copy the TypeLoc because TemplateArgumentLocs store a
1258 // TypeSourceInfo.
1259 // FIXME: Find some way to avoid the copy?
1260 TypeLocBuilder TLB;
1261 TLB.pushFullCopy(Pattern);
1262 TypeSourceInfo *PatternTSInfo =
1263 TLB.getTypeSourceInfo(Context, Pattern.getType());
1265 PatternTSInfo);
1266 }
1267
1269 PackExpansionExpr *Expansion
1270 = cast<PackExpansionExpr>(Argument.getAsExpr());
1271 Expr *Pattern = Expansion->getPattern();
1272 Ellipsis = Expansion->getEllipsisLoc();
1273 NumExpansions = Expansion->getNumExpansions();
1274 return TemplateArgumentLoc(Pattern, Pattern);
1275 }
1276
1278 Ellipsis = OrigLoc.getTemplateEllipsisLoc();
1279 NumExpansions = Argument.getNumTemplateExpansions();
1281 OrigLoc.getTemplateQualifierLoc(),
1282 OrigLoc.getTemplateNameLoc());
1283
1291 return TemplateArgumentLoc();
1292 }
1293
1294 llvm_unreachable("Invalid TemplateArgument Kind!");
1295}
1296
1298 assert(Arg.containsUnexpandedParameterPack());
1299
1300 // If this is a substituted pack, grab that pack. If not, we don't know
1301 // the size yet.
1302 // FIXME: We could find a size in more cases by looking for a substituted
1303 // pack anywhere within this argument, but that's not necessary in the common
1304 // case for 'sizeof...(A)' handling.
1305 TemplateArgument Pack;
1306 switch (Arg.getKind()) {
1308 if (auto *Subst = Arg.getAsType()->getAs<SubstTemplateTypeParmPackType>())
1309 Pack = Subst->getArgumentPack();
1310 else
1311 return std::nullopt;
1312 break;
1313
1315 if (auto *Subst =
1316 dyn_cast<SubstNonTypeTemplateParmPackExpr>(Arg.getAsExpr()))
1317 Pack = Subst->getArgumentPack();
1318 else if (auto *Subst = dyn_cast<FunctionParmPackExpr>(Arg.getAsExpr())) {
1319 for (VarDecl *PD : *Subst)
1320 if (PD->isParameterPack())
1321 return std::nullopt;
1322 return Subst->getNumExpansions();
1323 } else
1324 return std::nullopt;
1325 break;
1326
1330 Pack = Subst->getArgumentPack();
1331 else
1332 return std::nullopt;
1333 break;
1334
1342 return std::nullopt;
1343 }
1344
1345 // Check that no argument in the pack is itself a pack expansion.
1346 for (TemplateArgument Elem : Pack.pack_elements()) {
1347 // There's no point recursing in this case; we would have already
1348 // expanded this pack expansion into the enclosing pack if we could.
1349 if (Elem.isPackExpansion())
1350 return std::nullopt;
1351 // Don't guess the size of unexpanded packs. The pack within a template
1352 // argument may have yet to be of a PackExpansion type before we see the
1353 // ellipsis in the annotation stage.
1354 //
1355 // This doesn't mean we would invalidate the optimization: Arg can be an
1356 // unexpanded pack regardless of Elem's dependence. For instance,
1357 // A TemplateArgument that contains either a SubstTemplateTypeParmPackType
1358 // or SubstNonTypeTemplateParmPackExpr is always considered Unexpanded, but
1359 // the underlying TemplateArgument thereof may not.
1360 if (Elem.containsUnexpandedParameterPack())
1361 return std::nullopt;
1362 }
1363 return Pack.pack_size();
1364}
1365
1366static void CheckFoldOperand(Sema &S, Expr *E) {
1367 if (!E)
1368 return;
1369
1370 E = E->IgnoreImpCasts();
1371 auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
1372 if ((OCE && OCE->isInfixBinaryOp()) || isa<BinaryOperator>(E) ||
1373 isa<AbstractConditionalOperator>(E)) {
1374 S.Diag(E->getExprLoc(), diag::err_fold_expression_bad_operand)
1375 << E->getSourceRange()
1378 }
1379}
1380
1382 tok::TokenKind Operator,
1383 SourceLocation EllipsisLoc, Expr *RHS,
1384 SourceLocation RParenLoc) {
1385 // LHS and RHS must be cast-expressions. We allow an arbitrary expression
1386 // in the parser and reduce down to just cast-expressions here.
1387 CheckFoldOperand(*this, LHS);
1388 CheckFoldOperand(*this, RHS);
1389
1390 auto DiscardOperands = [&] {
1393 };
1394
1395 // [expr.prim.fold]p3:
1396 // In a binary fold, op1 and op2 shall be the same fold-operator, and
1397 // either e1 shall contain an unexpanded parameter pack or e2 shall contain
1398 // an unexpanded parameter pack, but not both.
1399 if (LHS && RHS &&
1402 DiscardOperands();
1403 return Diag(EllipsisLoc,
1405 ? diag::err_fold_expression_packs_both_sides
1406 : diag::err_pack_expansion_without_parameter_packs)
1407 << LHS->getSourceRange() << RHS->getSourceRange();
1408 }
1409
1410 // [expr.prim.fold]p2:
1411 // In a unary fold, the cast-expression shall contain an unexpanded
1412 // parameter pack.
1413 if (!LHS || !RHS) {
1414 Expr *Pack = LHS ? LHS : RHS;
1415 assert(Pack && "fold expression with neither LHS nor RHS");
1416 if (!Pack->containsUnexpandedParameterPack()) {
1417 DiscardOperands();
1418 return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
1419 << Pack->getSourceRange();
1420 }
1421 }
1422
1423 BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
1424
1425 // Perform first-phase name lookup now.
1426 UnresolvedLookupExpr *ULE = nullptr;
1427 {
1428 UnresolvedSet<16> Functions;
1429 LookupBinOp(S, EllipsisLoc, Opc, Functions);
1430 if (!Functions.empty()) {
1434 /*NamingClass*/ nullptr, NestedNameSpecifierLoc(),
1435 DeclarationNameInfo(OpName, EllipsisLoc), Functions);
1436 if (Callee.isInvalid())
1437 return ExprError();
1438 ULE = cast<UnresolvedLookupExpr>(Callee.get());
1439 }
1440 }
1441
1442 return BuildCXXFoldExpr(ULE, LParenLoc, LHS, Opc, EllipsisLoc, RHS, RParenLoc,
1443 std::nullopt);
1444}
1445
1447 SourceLocation LParenLoc, Expr *LHS,
1448 BinaryOperatorKind Operator,
1449 SourceLocation EllipsisLoc, Expr *RHS,
1450 SourceLocation RParenLoc,
1451 std::optional<unsigned> NumExpansions) {
1452 return new (Context)
1453 CXXFoldExpr(Context.DependentTy, Callee, LParenLoc, LHS, Operator,
1454 EllipsisLoc, RHS, RParenLoc, NumExpansions);
1455}
1456
1458 BinaryOperatorKind Operator) {
1459 // [temp.variadic]p9:
1460 // If N is zero for a unary fold-expression, the value of the expression is
1461 // && -> true
1462 // || -> false
1463 // , -> void()
1464 // if the operator is not listed [above], the instantiation is ill-formed.
1465 //
1466 // Note that we need to use something like int() here, not merely 0, to
1467 // prevent the result from being a null pointer constant.
1468 QualType ScalarType;
1469 switch (Operator) {
1470 case BO_LOr:
1471 return ActOnCXXBoolLiteral(EllipsisLoc, tok::kw_false);
1472 case BO_LAnd:
1473 return ActOnCXXBoolLiteral(EllipsisLoc, tok::kw_true);
1474 case BO_Comma:
1475 ScalarType = Context.VoidTy;
1476 break;
1477
1478 default:
1479 return Diag(EllipsisLoc, diag::err_fold_expression_empty)
1480 << BinaryOperator::getOpcodeStr(Operator);
1481 }
1482
1483 return new (Context) CXXScalarValueInitExpr(
1484 ScalarType, Context.getTrivialTypeSourceInfo(ScalarType, EllipsisLoc),
1485 EllipsisLoc);
1486}
const Decl * D
Expr * E
const CFGBlock * Block
Definition: HTMLLogger.cpp:152
SourceLocation Loc
Definition: SemaObjC.cpp:759
static void CheckFoldOperand(Sema &S, Expr *E)
static bool isParameterPack(Expr *PackExpression)
Defines the clang::TypeLoc interface and its subclasses.
__device__ int
#define bool
Definition: amdgpuintrin.h:20
unsigned getIntWidth(QualType T) const
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:684
CanQualType DependentTy
Definition: ASTContext.h:1188
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
QualType getPackExpansionType(QualType Pattern, std::optional< unsigned > NumExpansions, bool ExpectPackInType=true) const
Form a pack expansion type with the given pattern.
CanQualType VoidTy
Definition: ASTContext.h:1160
The result of parsing/analyzing an expression, statement etc.
Definition: Ownership.h:153
PtrTy get() const
Definition: Ownership.h:170
bool isInvalid() const
Definition: Ownership.h:166
bool isUsable() const
Definition: Ownership.h:168
Attr - This represents one attribute.
Definition: Attr.h:43
bool isPackExpansion() const
Definition: Attr.h:106
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
Definition: Expr.cpp:2189
StringRef getOpcodeStr() const
Definition: Expr.h:3975
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:6414
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2318
Represents a folding of a pack over an operator.
Definition: ExprCXX.h:4846
An expression "T()" which creates an rvalue of a non-class type T.
Definition: ExprCXX.h:2182
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:74
bool isValid() const
A scope specifier is present, and it refers to a real scope.
Definition: DeclSpec.h:215
SourceRange getRange() const
Definition: DeclSpec.h:80
SourceLocation getBeginLoc() const
Definition: DeclSpec.h:84
NestedNameSpecifier * getScopeRep() const
Retrieve the representation of the nested-name-specifier.
Definition: DeclSpec.h:95
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:421
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1265
Captures information about "declaration specifiers".
Definition: DeclSpec.h:247
TST getTypeSpecType() const
Definition: DeclSpec.h:537
ParsedType getRepAsType() const
Definition: DeclSpec.h:547
Expr * getRepAsExpr() const
Definition: DeclSpec.h:555
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
bool isParameterPack() const
Whether this declaration is a parameter pack.
Definition: DeclBase.cpp:239
DeclarationName getCXXOperatorName(OverloadedOperatorKind Op)
Get the name of the overloadable C++ operator corresponding to Op.
The name of a declaration.
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
NameKind getNameKind() const
Determine what kind of name this is.
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1903
Recursive AST visitor that supports extension via dynamic dispatch.
virtual bool TraverseDecl(Decl *D)
Recursively visit a declaration, by dispatching to Traverse*Decl() based on the argument's dynamic ty...
virtual bool TraverseTypeLoc(TypeLoc TL)
Recursively visit a type with location, by dispatching to Traverse*TypeLoc() based on the argument ty...
virtual bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C, Expr *Init)
Recursively visit a lambda capture.
virtual bool TraverseAttr(Attr *At)
Recursively visit an attribute, by dispatching to Traverse*Attr() based on the argument's dynamic typ...
virtual bool TraverseStmt(Stmt *S)
Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dy...
virtual bool TraverseTemplateArgument(const TemplateArgument &Arg)
Recursively visit a template argument and dispatch to the appropriate method for the argument type.
virtual bool TraverseConstructorInitializer(CXXCtorInitializer *Init)
Recursively visit a constructor initializer.
virtual bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc)
Recursively visit a template argument location and dispatch to the appropriate method for the argumen...
virtual bool TraverseType(QualType T)
Recursively visit a type, by dispatching to Traverse*Type() based on the argument's getTypeClass() pr...
virtual bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier &Base)
Recursively visit a base specifier.
virtual bool TraverseTemplateName(TemplateName Template)
Recursively visit a template name and dispatch to the appropriate method.
This represents one expression.
Definition: Expr.h:110
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates).
Definition: Expr.h:239
bool containsErrors() const
Whether this expression contains subexpressions which had errors, e.g.
Definition: Expr.h:245
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
Definition: Expr.h:221
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3070
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:277
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:101
Represents a reference to a function parameter pack or init-capture pack that has been substituted bu...
Definition: ExprCXX.h:4654
One of these records is kept for each identifier that is lexed.
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:514
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:25
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1954
TemplateParameterList * getTemplateParameterList() const
If this is a generic lambda expression, retrieve the template parameter list associated with it,...
Definition: ExprCXX.cpp:1395
NamedDecl * getPartiallySubstitutedPack(const TemplateArgument **ExplicitArgs=nullptr, unsigned *NumExplicitArgs=nullptr) const
Retrieve the partially-substitued template parameter pack.
llvm::PointerUnion< Decl *, DeclArgumentPack * > * findInstantiationOf(const Decl *D)
Find the instantiation of the declaration D within the current instantiation scope.
Represents the results of name lookup.
Definition: Lookup.h:46
@ FoundOverloaded
Name lookup found a set of overloaded functions that met the criteria.
Definition: Lookup.h:63
@ FoundUnresolvedValue
Name lookup found an unresolvable value declaration and cannot yet complete.
Definition: Lookup.h:68
@ Ambiguous
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
Definition: Lookup.h:73
@ NotFound
No entity found met the criteria.
Definition: Lookup.h:50
@ NotFoundInCurrentInstantiation
No entity found met the criteria within the current instantiation,, but there were dependent base cla...
Definition: Lookup.h:55
@ Found
Name lookup found a single declaration that met the criteria.
Definition: Lookup.h:59
NamedDecl * getFoundDecl() const
Fetch the unique decl found by this lookup.
Definition: Lookup.h:568
Sema::LookupNameKind getLookupKind() const
Gets the kind of lookup to perform.
Definition: Lookup.h:275
LookupResultKind getResultKind() const
Definition: Lookup.h:344
const DeclarationNameInfo & getLookupNameInfo() const
Gets the name info to look up.
Definition: Lookup.h:255
Data structure that captures multiple levels of template argument lists for use in template instantia...
Definition: Template.h:76
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:175
unsigned getNumLevels() const
Determine the number of levels in this template argument list.
Definition: Template.h:123
This represents a decl that may have a name.
Definition: Decl.h:253
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:274
A C++ nested-name-specifier augmented with source location information.
bool containsUnexpandedParameterPack() const
Whether this nested-name-specifier contains an unexpanded parameter pack (for C++11 variadic template...
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
Definition: ExprObjC.h:309
PtrTy get() const
Definition: Ownership.h:80
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:4180
Expr * getPattern()
Retrieve the pattern of the pack expansion.
Definition: ExprCXX.h:4209
std::optional< unsigned > getNumExpansions() const
Determine the number of expansions that will be produced when this pack expansion is instantiated,...
Definition: ExprCXX.h:4220
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis that describes this pack expansion.
Definition: ExprCXX.h:4216
void setEllipsisLoc(SourceLocation Loc)
Definition: TypeLoc.h:2613
SourceLocation getEllipsisLoc() const
Definition: TypeLoc.h:2609
TypeLoc getPatternLoc() const
Definition: TypeLoc.h:2625
Represents a pack expansion of types.
Definition: Type.h:7141
std::optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:7166
static PackIndexingExpr * Create(ASTContext &Context, SourceLocation EllipsisLoc, SourceLocation RSquareLoc, Expr *PackIdExpr, Expr *IndexExpr, std::optional< int64_t > Index, ArrayRef< Expr * > SubstitutedExprs={}, bool FullySubstituted=false)
Definition: ExprCXX.cpp:1717
Expr * getIndexExpr() const
Definition: TypeLoc.h:2139
Represents a parameter to a function.
Definition: Decl.h:1725
Represents the parsed form of a C++ template argument.
KindType getKind() const
Determine what kind of template argument we have.
SourceLocation getLocation() const
Retrieve the location of the template argument.
ParsedTemplateTy getAsTemplate() const
Retrieve the template template argument's template name.
ParsedTemplateArgument getTemplatePackExpansion(SourceLocation EllipsisLoc) const
Retrieve a pack expansion of the given template template argument.
ParsedType getAsType() const
Retrieve the template type argument's type.
@ Type
A template type parameter, stored as a type.
@ Template
A template template argument, stored as a template name.
@ NonType
A non-type template parameter, stored as an expression.
bool isInvalid() const
Determine whether the given template argument is invalid.
Expr * getAsExpr() const
Retrieve the non-type template argument's expression.
const CXXScopeSpec & getScopeSpec() const
Retrieve the nested-name-specifier that precedes the template name in a template template argument.
A (possibly-)qualified type.
Definition: Type.h:929
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:996
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
Definition: ExprConcepts.h:502
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprConcepts.h:578
ArrayRef< ParmVarDecl * > getLocalParameters() const
Definition: ExprConcepts.h:542
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:41
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: SemaBase.cpp:60
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
Definition: SemaBase.cpp:32
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:463
ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo)
Package the given type and TSI into a ParsedType.
Definition: SemaType.cpp:6394
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
Definition: Sema.h:12636
sema::CapturingScopeInfo * getEnclosingLambdaOrBlock() const
Get the innermost lambda or block enclosing the current location, if any.
Definition: Sema.cpp:2386
bool containsUnexpandedParameterPacks(Declarator &D)
Determine whether the given declarator contains any unexpanded parameter packs.
bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc, SourceRange PatternRange, ArrayRef< UnexpandedParameterPack > Unexpanded, const MultiLevelTemplateArgumentList &TemplateArgs, bool &ShouldExpand, bool &RetainExpansion, std::optional< unsigned > &NumExpansions)
Determine whether we could expand a pack expansion with the given set of parameter packs into separat...
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
Definition: Sema.h:8983
SmallVector< sema::FunctionScopeInfo *, 4 > FunctionScopes
Stack containing information about each of the nested function, block, and method scopes that are cur...
Definition: Sema.h:848
ASTContext & Context
Definition: Sema.h:908
TypeSourceInfo * CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc, std::optional< unsigned > NumExpansions)
Construct a pack expansion type from the pattern of the pack expansion.
ExprResult BuildPackIndexingExpr(Expr *PackExpression, SourceLocation EllipsisLoc, Expr *IndexExpr, SourceLocation RSquareLoc, ArrayRef< Expr * > ExpandedExprs={}, bool FullySubstituted=false)
ASTContext & getASTContext() const
Definition: Sema.h:531
bool DiagnoseUnexpandedParameterPackInRequiresExpr(RequiresExpr *RE)
If the given requirees-expression contains an unexpanded reference to one of its own parameter packs,...
void LookupBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, UnresolvedSetImpl &Functions)
Definition: SemaExpr.cpp:15295
TemplateArgumentLoc getTemplateArgumentPackExpansionPattern(TemplateArgumentLoc OrigLoc, SourceLocation &Ellipsis, std::optional< unsigned > &NumExpansions) const
Returns the pattern of the pack expansion for a template argument.
ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, llvm::APSInt &Value, CCEKind CCE)
std::optional< unsigned > getNumArgumentsInExpansionFromUnexpanded(llvm::ArrayRef< UnexpandedParameterPack > Unexpanded, const MultiLevelTemplateArgumentList &TemplateArgs)
UnexpandedParameterPackContext
The context in which an unexpanded parameter pack is being diagnosed.
Definition: Sema.h:13888
@ UPPC_Requirement
Definition: Sema.h:13956
const LangOptions & getLangOpts() const
Definition: Sema.h:524
TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, Sema::LookupNameKind LookupKind, Scope *S, CXXScopeSpec *SS, 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...
bool isUnexpandedParameterPackPermitted()
Determine whether an unexpanded parameter pack might be permitted in this location.
ExprResult BuildCXXFoldExpr(UnresolvedLookupExpr *Callee, SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, std::optional< unsigned > NumExpansions)
void collectUnexpandedParameterPacks(TemplateArgument Arg, SmallVectorImpl< UnexpandedParameterPack > &Unexpanded)
Collect the set of unexpanded parameter packs within the given template argument.
bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, UnexpandedParameterPackContext UPPC)
If the given type contains an unexpanded parameter pack, diagnose the error.
ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind)
ActOnCXXBoolLiteral - Parse {true,false} literals.
void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool MightBeOdrUse)
Perform marking for a reference to an arbitrary declaration.
Definition: SemaExpr.cpp:20059
std::optional< unsigned > getNumArgumentsInExpansion(QualType T, const MultiLevelTemplateArgumentList &TemplateArgs)
Determine the number of arguments in the given pack expansion type.
std::optional< unsigned > getFullyPackExpandedSize(TemplateArgument Arg)
Given a template argument that contains an unexpanded parameter pack, but which has already been subs...
ExprResult ActOnPackIndexingExpr(Scope *S, Expr *PackExpression, SourceLocation EllipsisLoc, SourceLocation LSquareLoc, Expr *IndexExpr, SourceLocation RSquareLoc)
ExprResult CreateUnresolvedLookupExpr(CXXRecordDecl *NamingClass, NestedNameSpecifierLoc NNSLoc, DeclarationNameInfo DNI, const UnresolvedSetImpl &Fns, bool PerformADL=true)
ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, SourceLocation EllipsisLoc)
Invoked when parsing a template argument followed by an ellipsis, which creates a pack expansion.
@ CTK_ErrorRecovery
Definition: Sema.h:9377
@ CCEK_ArrayBound
Array bound in array declarator or new-expression.
Definition: Sema.h:9995
void diagnoseTypo(const TypoCorrection &Correction, const PartialDiagnostic &TypoDiag, bool ErrorRecovery=true)
void DiagnoseAmbiguousLookup(LookupResult &Result)
Produce a diagnostic describing the ambiguity that resulted from name lookup.
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.
ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, BinaryOperatorKind Operator)
ExprResult ActOnCXXFoldExpr(Scope *S, SourceLocation LParenLoc, Expr *LHS, tok::TokenKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc)
Handle a C++1z fold-expression: ( expr op ... op expr ).
bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation=false, bool ForceNoCPlusPlus=false)
Perform unqualified name lookup starting from a given scope.
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
Definition: SemaType.cpp:2750
bool DiagnoseUnexpandedParameterPacks(SourceLocation Loc, UnexpandedParameterPackContext UPPC, ArrayRef< UnexpandedParameterPack > Unexpanded)
Diagnose unexpanded parameter packs.
ExprResult CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl=nullptr, bool RecoverUncorrectedTypos=false, 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...
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, std::optional< unsigned > Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs={})
Definition: ExprCXX.cpp:1693
Encodes a location in the source.
A trivial tuple used to represent a source range.
void setBegin(SourceLocation b)
SourceLocation getBegin() const
Stmt - This represents one statement.
Definition: Stmt.h:84
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:357
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:333
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:345
Represents a reference to a non-type template parameter pack that has been substituted with a non-tem...
Definition: ExprCXX.h:4575
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:149
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:864
Represents the result of substituting a set of types for a template type parameter pack.
Definition: Type.h:6464
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:524
SourceLocation getLocation() const
Definition: TemplateBase.h:563
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:623
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:574
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:616
TypeSourceInfo * getTypeSourceInfo() const
Definition: TemplateBase.h:578
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:609
Represents a template argument.
Definition: TemplateBase.h:61
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:408
std::optional< unsigned > getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce,...
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:319
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:343
bool containsUnexpandedParameterPack() const
Whether this template argument contains an unexpanded parameter pack.
TemplateArgument getPackExpansionPattern() const
When the template argument is a pack expansion, returns the pattern of the pack expansion.
bool isNull() const
Determine whether this template argument has no value.
Definition: TemplateBase.h:298
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:438
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:432
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
Definition: TemplateBase.h:74
@ Template
The template argument is a template name that was provided for a template template parameter.
Definition: TemplateBase.h:93
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
Definition: TemplateBase.h:89
@ Pack
The template argument is actually a parameter pack.
Definition: TemplateBase.h:107
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:97
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:78
@ Type
The template argument is a type.
Definition: TemplateBase.h:70
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:67
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:82
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
Definition: TemplateBase.h:103
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:295
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
Represents a C++ template name within the type system.
Definition: TemplateName.h:220
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
bool isNull() const
Determine whether this template name is NULL.
bool containsUnexpandedParameterPack() const
Determines whether this template name contains an unexpanded parameter pack (for C++0x variadic templ...
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
Wrapper for template type parameters.
Definition: TypeLoc.h:758
bool isParameterPack() const
Definition: Type.h:6344
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
void pushFullCopy(TypeLoc L)
Pushes a copy of the given TypeLoc onto this builder.
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:59
QualType getType() const
Get the type for which this source info wrapper provides information.
Definition: TypeLoc.h:133
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type.
Definition: TypeLoc.h:78
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
Definition: TypeLoc.h:153
A container of type source information.
Definition: Type.h:7902
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:256
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:7913
SourceLocation getNameLoc() const
Definition: TypeLoc.h:535
The base class of the type hierarchy.
Definition: Type.h:1828
DeducedType * getContainedDeducedType() const
Get the DeducedType whose type will be deduced for a variable with an initializer of this type.
Definition: Type.cpp:2045
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:2361
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8731
Simple class containing the result of Sema::CorrectTypo.
NamedDecl * getCorrectionDecl() const
Gets the pointer to the declaration of the typo correction.
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:3203
A set of unresolved declarations.
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3977
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3880
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:671
QualType getType() const
Definition: Decl.h:682
Represents a variable declaration or definition.
Definition: Decl.h:882
Contains information about the compound statement currently being parsed.
Definition: ScopeInfo.h:67
Retains information about a function, method, or block that is currently being parsed.
Definition: ScopeInfo.h:104
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
The JSON file list parser is used to communicate input to InstallAPI.
@ TST_typeof_unqualType
Definition: Specifiers.h:87
@ TST_ibm128
Definition: Specifiers.h:74
@ TST_decimal64
Definition: Specifiers.h:77
@ TST_float
Definition: Specifiers.h:71
@ TST_auto_type
Definition: Specifiers.h:94
@ TST_auto
Definition: Specifiers.h:92
@ TST_typeof_unqualExpr
Definition: Specifiers.h:88
@ TST_decimal32
Definition: Specifiers.h:76
@ TST_int128
Definition: Specifiers.h:64
@ TST_atomic
Definition: Specifiers.h:96
@ TST_half
Definition: Specifiers.h:66
@ TST_decltype
Definition: Specifiers.h:89
@ TST_typename_pack_indexing
Definition: Specifiers.h:97
@ TST_char32
Definition: Specifiers.h:62
@ TST_struct
Definition: Specifiers.h:81
@ TST_typeofType
Definition: Specifiers.h:85
@ TST_bitint
Definition: Specifiers.h:65
@ TST_wchar
Definition: Specifiers.h:59
@ TST_BFloat16
Definition: Specifiers.h:70
@ TST_char16
Definition: Specifiers.h:61
@ TST_char
Definition: Specifiers.h:58
@ TST_unspecified
Definition: Specifiers.h:56
@ TST_class
Definition: Specifiers.h:82
@ TST_union
Definition: Specifiers.h:80
@ TST_Fract
Definition: Specifiers.h:69
@ TST_float128
Definition: Specifiers.h:73
@ TST_double
Definition: Specifiers.h:72
@ TST_Accum
Definition: Specifiers.h:68
@ TST_int
Definition: Specifiers.h:63
@ TST_bool
Definition: Specifiers.h:75
@ TST_typeofExpr
Definition: Specifiers.h:86
@ TST_typename
Definition: Specifiers.h:84
@ TST_void
Definition: Specifiers.h:57
@ TST_unknown_anytype
Definition: Specifiers.h:95
@ TST_enum
Definition: Specifiers.h:79
@ TST_error
Definition: Specifiers.h:104
@ TST_decltype_auto
Definition: Specifiers.h:93
@ TST_interface
Definition: Specifiers.h:83
@ TST_Float16
Definition: Specifiers.h:67
@ TST_char8
Definition: Specifiers.h:60
@ TST_decimal128
Definition: Specifiers.h:78
@ CPlusPlus26
Definition: LangStandard.h:61
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
BinaryOperatorKind
@ Result
The result type of a method or function.
std::pair< unsigned, unsigned > getDepthAndIndex(const NamedDecl *ND)
Retrieve the depth and index of a template parameter.
Definition: SemaInternal.h:61
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
ExprResult ExprError()
Definition: Ownership.h:264
const FunctionProtoType * T
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition: DeclBase.h:1274
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl * >, SourceLocation > UnexpandedParameterPack
Definition: Sema.h:235
@ EST_Dynamic
throw(T1, T2)
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
TypeSourceInfo * getNamedTypeInfo() const
getNamedTypeInfo - Returns the source type info associated to the name.
Expr * NumElts
This is the size of the array, or null if [] or [*] was specified.
Definition: DeclSpec.h:1321
bool hasTrailingReturnType() const
Determine whether this function declarator had a trailing-return-type.
Definition: DeclSpec.h:1586
TypeAndRange * Exceptions
Pointer to a new[]'d array of TypeAndRange objects that contain the types in the function's dynamic e...
Definition: DeclSpec.h:1440
ParamInfo * Params
Params - This is a pointer to a new[]'d array of ParamInfo objects that describe the parameters speci...
Definition: DeclSpec.h:1428
ParsedType getTrailingReturnType() const
Get the trailing-return-type for this function declarator.
Definition: DeclSpec.h:1589
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
Definition: DeclSpec.h:1403
unsigned getNumExceptions() const
Get the number of dynamic exception specifications.
Definition: DeclSpec.h:1572
ExceptionSpecificationType getExceptionSpecType() const
Get the type of exception specification this function has.
Definition: DeclSpec.h:1567
Expr * NoexceptExpr
Pointer to the expression in the noexcept-specifier of this function, if it has one.
Definition: DeclSpec.h:1444
One instance of this struct is used for each type in a declarator that is parsed.
Definition: DeclSpec.h:1251
enum clang::DeclaratorChunk::@222 Kind
MemberPointerTypeInfo Mem
Definition: DeclSpec.h:1644
ArrayTypeInfo Arr
Definition: DeclSpec.h:1641
FunctionTypeInfo Fun
Definition: DeclSpec.h:1642
An element in an Objective-C dictionary literal.
Definition: ExprObjC.h:262