clang 21.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 (auto *BD = dyn_cast<BindingDecl>(ND)) {
54 Expr *E = BD->getBinding();
55 if (auto *RP = cast_if_present<ResolvedUnexpandedPackExpr>(E)) {
56 addUnexpanded(RP);
57 return;
58 }
59 } else if (getDepthAndIndex(ND).first >= DepthLimit) {
60 return;
61 }
62
63 Unexpanded.push_back({ND, Loc});
64 }
65
66 void addUnexpanded(const TemplateTypeParmType *T,
68 if (T->getDepth() < DepthLimit)
69 Unexpanded.push_back({T, Loc});
70 }
71
72 void addUnexpanded(ResolvedUnexpandedPackExpr *E) {
73 Unexpanded.push_back({E, E->getBeginLoc()});
74 }
75
76 public:
77 explicit CollectUnexpandedParameterPacksVisitor(
79 : Unexpanded(Unexpanded) {
80 ShouldWalkTypesOfTypeLocs = false;
81
82 // We need this so we can find e.g. attributes on lambdas.
83 ShouldVisitImplicitCode = true;
84 }
85
86 //------------------------------------------------------------------------
87 // Recording occurrences of (unexpanded) parameter packs.
88 //------------------------------------------------------------------------
89
90 /// Record occurrences of template type parameter packs.
91 bool VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) override {
92 if (TL.getTypePtr()->isParameterPack())
93 addUnexpanded(TL.getTypePtr(), TL.getNameLoc());
94 return true;
95 }
96
97 /// Record occurrences of template type parameter packs
98 /// when we don't have proper source-location information for
99 /// them.
100 ///
101 /// Ideally, this routine would never be used.
102 bool VisitTemplateTypeParmType(TemplateTypeParmType *T) override {
103 if (T->isParameterPack())
104 addUnexpanded(T);
105
106 return true;
107 }
108
109 /// Record occurrences of function and non-type template
110 /// parameter packs in an expression.
111 bool VisitDeclRefExpr(DeclRefExpr *E) override {
112 if (E->getDecl()->isParameterPack())
113 addUnexpanded(E->getDecl(), E->getLocation());
114
115 return true;
116 }
117
118 bool
119 VisitResolvedUnexpandedPackExpr(ResolvedUnexpandedPackExpr *E) override {
120 addUnexpanded(E);
121 return true;
122 }
123
124 /// Record occurrences of template template parameter packs.
125 bool TraverseTemplateName(TemplateName Template) override {
126 if (auto *TTP = dyn_cast_or_null<TemplateTemplateParmDecl>(
127 Template.getAsTemplateDecl())) {
128 if (TTP->isParameterPack())
129 addUnexpanded(TTP);
130 }
131
132#ifndef NDEBUG
133 ContainsIntermediatePacks |=
135#endif
136
138 }
139
140 /// Suppress traversal into Objective-C container literal
141 /// elements that are pack expansions.
142 bool TraverseObjCDictionaryLiteral(ObjCDictionaryLiteral *E) override {
144 return true;
145
146 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
147 ObjCDictionaryElement Element = E->getKeyValueElement(I);
148 if (Element.isPackExpansion())
149 continue;
150
151 TraverseStmt(Element.Key);
152 TraverseStmt(Element.Value);
153 }
154 return true;
155 }
156 //------------------------------------------------------------------------
157 // Pruning the search for unexpanded parameter packs.
158 //------------------------------------------------------------------------
159
160 /// Suppress traversal into statements and expressions that
161 /// do not contain unexpanded parameter packs.
162 bool TraverseStmt(Stmt *S) override {
163 Expr *E = dyn_cast_or_null<Expr>(S);
164 if ((E && E->containsUnexpandedParameterPack()) || InLambdaOrBlock)
166
167 return true;
168 }
169
170 /// Suppress traversal into types that do not contain
171 /// unexpanded parameter packs.
172 bool TraverseType(QualType T) override {
173 if ((!T.isNull() && T->containsUnexpandedParameterPack()) ||
174 InLambdaOrBlock)
176
177 return true;
178 }
179
180 /// Suppress traversal into types with location information
181 /// that do not contain unexpanded parameter packs.
182 bool TraverseTypeLoc(TypeLoc TL) override {
183 if ((!TL.getType().isNull() &&
185 InLambdaOrBlock)
187
188 return true;
189 }
190
191 /// Suppress traversal of parameter packs.
192 bool TraverseDecl(Decl *D) override {
193 // A function parameter pack is a pack expansion, so cannot contain
194 // an unexpanded parameter pack. Likewise for a template parameter
195 // pack that contains any references to other packs.
196 if (D && D->isParameterPack())
197 return true;
198
200 }
201
202 /// Suppress traversal of pack-expanded attributes.
203 bool TraverseAttr(Attr *A) override {
204 if (A->isPackExpansion())
205 return true;
206
208 }
209
210 /// Suppress traversal of pack expansion expressions and types.
211 ///@{
212 bool TraversePackExpansionType(PackExpansionType *T) override {
213 return true;
214 }
215 bool TraversePackExpansionTypeLoc(PackExpansionTypeLoc TL) override {
216 return true;
217 }
218 bool TraversePackExpansionExpr(PackExpansionExpr *E) override {
219 return true;
220 }
221 bool TraverseCXXFoldExpr(CXXFoldExpr *E) override { return true; }
222 bool TraversePackIndexingExpr(PackIndexingExpr *E) override {
223 return DynamicRecursiveASTVisitor::TraverseStmt(E->getIndexExpr());
224 }
225 bool TraversePackIndexingType(PackIndexingType *E) override {
226 return DynamicRecursiveASTVisitor::TraverseStmt(E->getIndexExpr());
227 }
228 bool TraversePackIndexingTypeLoc(PackIndexingTypeLoc TL) override {
230 }
231
232 ///@}
233
234 /// Suppress traversal of using-declaration pack expansion.
235 bool
236 TraverseUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) override {
237 if (D->isPackExpansion())
238 return true;
239
240 return DynamicRecursiveASTVisitor::TraverseUnresolvedUsingValueDecl(D);
241 }
242
243 /// Suppress traversal of using-declaration pack expansion.
244 bool TraverseUnresolvedUsingTypenameDecl(
245 UnresolvedUsingTypenameDecl *D) override {
246 if (D->isPackExpansion())
247 return true;
248
249 return DynamicRecursiveASTVisitor::TraverseUnresolvedUsingTypenameDecl(D);
250 }
251
252 /// Suppress traversal of template argument pack expansions.
253 bool TraverseTemplateArgument(const TemplateArgument &Arg) override {
254 if (Arg.isPackExpansion())
255 return true;
256
258 }
259
260 /// Suppress traversal of template argument pack expansions.
261 bool
262 TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc) override {
263 if (ArgLoc.getArgument().isPackExpansion())
264 return true;
265
267 }
268
269 /// Suppress traversal of base specifier pack expansions.
270 bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier &Base) override {
271 if (Base.isPackExpansion())
272 return true;
273
275 }
276
277 /// Suppress traversal of mem-initializer pack expansions.
279 if (Init->isPackExpansion())
280 return true;
281
283 }
284
285 /// Note whether we're traversing a lambda containing an unexpanded
286 /// parameter pack. In this case, the unexpanded pack can occur anywhere,
287 /// including all the places where we normally wouldn't look. Within a
288 /// lambda, we don't propagate the 'contains unexpanded parameter pack' bit
289 /// outside an expression.
290 bool TraverseLambdaExpr(LambdaExpr *Lambda) override {
291 // The ContainsUnexpandedParameterPack bit on a lambda is always correct,
292 // even if it's contained within another lambda.
293 if (!Lambda->containsUnexpandedParameterPack())
294 return true;
295
296 SaveAndRestore _(InLambdaOrBlock, true);
297 unsigned OldDepthLimit = DepthLimit;
298
299 if (auto *TPL = Lambda->getTemplateParameterList())
300 DepthLimit = TPL->getDepth();
301
302 DynamicRecursiveASTVisitor::TraverseLambdaExpr(Lambda);
303
304 DepthLimit = OldDepthLimit;
305 return true;
306 }
307
308 /// Analogously for blocks.
309 bool TraverseBlockExpr(BlockExpr *Block) override {
310 if (!Block->containsUnexpandedParameterPack())
311 return true;
312
313 SaveAndRestore _(InLambdaOrBlock, true);
314 DynamicRecursiveASTVisitor::TraverseBlockExpr(Block);
315 return true;
316 }
317
318 /// Suppress traversal within pack expansions in lambda captures.
319 bool TraverseLambdaCapture(LambdaExpr *Lambda, const LambdaCapture *C,
320 Expr *Init) override {
321 if (C->isPackExpansion())
322 return true;
323
325 }
326
327#ifndef NDEBUG
328 bool TraverseFunctionParmPackExpr(FunctionParmPackExpr *) override {
329 ContainsIntermediatePacks = true;
330 return true;
331 }
332
333 bool TraverseSubstNonTypeTemplateParmPackExpr(
335 ContainsIntermediatePacks = true;
336 return true;
337 }
338
339 bool VisitSubstTemplateTypeParmPackType(
341 ContainsIntermediatePacks = true;
342 return true;
343 }
344
345 bool VisitSubstTemplateTypeParmPackTypeLoc(
347 ContainsIntermediatePacks = true;
348 return true;
349 }
350
351 bool containsIntermediatePacks() const { return ContainsIntermediatePacks; }
352#endif
353};
354}
355
356/// Determine whether it's possible for an unexpanded parameter pack to
357/// be valid in this location. This only happens when we're in a declaration
358/// that is nested within an expression that could be expanded, such as a
359/// lambda-expression within a function call.
360///
361/// This is conservatively correct, but may claim that some unexpanded packs are
362/// permitted when they are not.
364 for (auto *SI : FunctionScopes)
365 if (isa<sema::LambdaScopeInfo>(SI))
366 return true;
367 return false;
368}
369
370/// Diagnose all of the unexpanded parameter packs in the given
371/// vector.
372bool
376 if (Unexpanded.empty())
377 return false;
378
379 // If we are within a lambda expression and referencing a pack that is not
380 // declared within the lambda itself, that lambda contains an unexpanded
381 // parameter pack, and we are done. Analogously for blocks.
382 // FIXME: Store 'Unexpanded' on the lambda so we don't need to recompute it
383 // later.
384 SmallVector<UnexpandedParameterPack, 4> ParamPackReferences;
386 for (auto &Pack : Unexpanded) {
387 auto DeclaresThisPack = [&](NamedDecl *LocalPack) {
388 if (auto *TTPT = Pack.first.dyn_cast<const TemplateTypeParmType *>()) {
389 auto *TTPD = dyn_cast<TemplateTypeParmDecl>(LocalPack);
390 return TTPD && TTPD->getTypeForDecl() == TTPT;
391 }
392 return declaresSameEntity(cast<NamedDecl *>(Pack.first), LocalPack);
393 };
394 if (llvm::any_of(CSI->LocalPacks, DeclaresThisPack))
395 ParamPackReferences.push_back(Pack);
396 }
397
398 if (ParamPackReferences.empty()) {
399 // Construct in lambda only references packs declared outside the lambda.
400 // That's OK for now, but the lambda itself is considered to contain an
401 // unexpanded pack in this case, which will require expansion outside the
402 // lambda.
403
404 // We do not permit pack expansion that would duplicate a statement
405 // expression, not even within a lambda.
406 // FIXME: We could probably support this for statement expressions that
407 // do not contain labels.
408 // FIXME: This is insufficient to detect this problem; consider
409 // f( ({ bad: 0; }) + pack ... );
410 bool EnclosingStmtExpr = false;
411 for (unsigned N = FunctionScopes.size(); N; --N) {
413 if (llvm::any_of(
414 Func->CompoundScopes,
415 [](sema::CompoundScopeInfo &CSI) { return CSI.IsStmtExpr; })) {
416 EnclosingStmtExpr = true;
417 break;
418 }
419 // Coumpound-statements outside the lambda are OK for now; we'll check
420 // for those when we finish handling the lambda.
421 if (Func == CSI)
422 break;
423 }
424
425 if (!EnclosingStmtExpr) {
426 CSI->ContainsUnexpandedParameterPack = true;
427 return false;
428 }
429 } else {
430 Unexpanded = ParamPackReferences;
431 }
432 }
433
437
438 for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
439 IdentifierInfo *Name = nullptr;
440 if (const TemplateTypeParmType *TTP
441 = Unexpanded[I].first.dyn_cast<const TemplateTypeParmType *>())
442 Name = TTP->getIdentifier();
443 else if (NamedDecl *ND = Unexpanded[I].first.dyn_cast<NamedDecl *>())
444 Name = ND->getIdentifier();
445
446 if (Name && NamesKnown.insert(Name).second)
447 Names.push_back(Name);
448
449 if (Unexpanded[I].second.isValid())
450 Locations.push_back(Unexpanded[I].second);
451 }
452
453 auto DB = Diag(Loc, diag::err_unexpanded_parameter_pack)
454 << (int)UPPC << (int)Names.size();
455 for (size_t I = 0, E = std::min(Names.size(), (size_t)2); I != E; ++I)
456 DB << Names[I];
457
458 for (unsigned I = 0, N = Locations.size(); I != N; ++I)
459 DB << SourceRange(Locations[I]);
460 return true;
461}
462
466 // C++0x [temp.variadic]p5:
467 // An appearance of a name of a parameter pack that is not expanded is
468 // ill-formed.
469 if (!T->getType()->containsUnexpandedParameterPack())
470 return false;
471
473 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(
474 T->getTypeLoc());
475 assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
476 return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
477}
478
481 // C++0x [temp.variadic]p5:
482 // An appearance of a name of a parameter pack that is not expanded is
483 // ill-formed.
485 return false;
486
488 CollectUnexpandedParameterPacksVisitor Visitor(Unexpanded);
489 Visitor.TraverseStmt(E);
490#ifndef NDEBUG
491 // The expression might contain a type/subexpression that has been substituted
492 // but has the expansion held off, e.g. a FunctionParmPackExpr which a larger
493 // CXXFoldExpr would expand. It's only possible when expanding a lambda as a
494 // pattern of a fold expression, so don't fire on an empty result in that
495 // case.
496 bool LambdaReferencingOuterPacks =
497 getEnclosingLambdaOrBlock() && Visitor.containsIntermediatePacks();
498 assert((!Unexpanded.empty() || LambdaReferencingOuterPacks) &&
499 "Unable to find unexpanded parameter packs");
500#endif
501 return DiagnoseUnexpandedParameterPacks(E->getBeginLoc(), UPPC, Unexpanded);
502}
503
506 return false;
507
509 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(RE);
510 assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
511
512 // We only care about unexpanded references to the RequiresExpr's own
513 // parameter packs.
514 auto Parms = RE->getLocalParameters();
515 llvm::SmallPtrSet<NamedDecl*, 8> ParmSet(Parms.begin(), Parms.end());
517 for (auto Parm : Unexpanded)
518 if (ParmSet.contains(Parm.first.dyn_cast<NamedDecl *>()))
519 UnexpandedParms.push_back(Parm);
520 if (UnexpandedParms.empty())
521 return false;
522
524 UnexpandedParms);
525}
526
529 // C++0x [temp.variadic]p5:
530 // An appearance of a name of a parameter pack that is not expanded is
531 // ill-formed.
532 if (!SS.getScopeRep() ||
534 return false;
535
537 CollectUnexpandedParameterPacksVisitor(Unexpanded)
538 .TraverseNestedNameSpecifier(SS.getScopeRep());
539 assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
541 UPPC, Unexpanded);
542}
543
546 // C++0x [temp.variadic]p5:
547 // An appearance of a name of a parameter pack that is not expanded is
548 // ill-formed.
549 switch (NameInfo.getName().getNameKind()) {
558 return false;
559
563 // FIXME: We shouldn't need this null check!
564 if (TypeSourceInfo *TSInfo = NameInfo.getNamedTypeInfo())
565 return DiagnoseUnexpandedParameterPack(NameInfo.getLoc(), TSInfo, UPPC);
566
568 return false;
569
570 break;
571 }
572
574 CollectUnexpandedParameterPacksVisitor(Unexpanded)
575 .TraverseType(NameInfo.getName().getCXXNameType());
576 assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
577 return DiagnoseUnexpandedParameterPacks(NameInfo.getLoc(), UPPC, Unexpanded);
578}
579
581 TemplateName Template,
583
584 if (Template.isNull() || !Template.containsUnexpandedParameterPack())
585 return false;
586
588 CollectUnexpandedParameterPacksVisitor(Unexpanded)
589 .TraverseTemplateName(Template);
590 assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
591 return DiagnoseUnexpandedParameterPacks(Loc, UPPC, Unexpanded);
592}
593
596 if (Arg.getArgument().isNull() ||
598 return false;
599
601 CollectUnexpandedParameterPacksVisitor(Unexpanded)
602 .TraverseTemplateArgumentLoc(Arg);
603 assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");
604 return DiagnoseUnexpandedParameterPacks(Arg.getLocation(), UPPC, Unexpanded);
605}
606
609 CollectUnexpandedParameterPacksVisitor(Unexpanded)
610 .TraverseTemplateArgument(Arg);
611}
612
615 CollectUnexpandedParameterPacksVisitor(Unexpanded)
616 .TraverseTemplateArgumentLoc(Arg);
617}
618
621 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(T);
622}
623
626 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(TL);
627}
628
632 CollectUnexpandedParameterPacksVisitor(Unexpanded)
633 .TraverseNestedNameSpecifierLoc(NNS);
634}
635
637 const DeclarationNameInfo &NameInfo,
639 CollectUnexpandedParameterPacksVisitor(Unexpanded)
640 .TraverseDeclarationNameInfo(NameInfo);
641}
642
645 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(E);
646}
647
650 SourceLocation EllipsisLoc) {
651 if (Arg.isInvalid())
652 return Arg;
653
654 switch (Arg.getKind()) {
656 TypeResult Result = ActOnPackExpansion(Arg.getAsType(), EllipsisLoc);
657 if (Result.isInvalid())
658 return ParsedTemplateArgument();
659
660 return ParsedTemplateArgument(Arg.getKind(), Result.get().getAsOpaquePtr(),
661 Arg.getLocation());
662 }
663
665 ExprResult Result = ActOnPackExpansion(Arg.getAsExpr(), EllipsisLoc);
666 if (Result.isInvalid())
667 return ParsedTemplateArgument();
668
669 return ParsedTemplateArgument(Arg.getKind(), Result.get(),
670 Arg.getLocation());
671 }
672
675 SourceRange R(Arg.getLocation());
676 if (Arg.getScopeSpec().isValid())
678 Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
679 << R;
680 return ParsedTemplateArgument();
681 }
682
683 return Arg.getTemplatePackExpansion(EllipsisLoc);
684 }
685 llvm_unreachable("Unhandled template argument kind?");
686}
687
689 SourceLocation EllipsisLoc) {
690 TypeSourceInfo *TSInfo;
691 GetTypeFromParser(Type, &TSInfo);
692 if (!TSInfo)
693 return true;
694
695 TypeSourceInfo *TSResult =
696 CheckPackExpansion(TSInfo, EllipsisLoc, std::nullopt);
697 if (!TSResult)
698 return true;
699
700 return CreateParsedType(TSResult->getType(), TSResult);
701}
702
705 std::optional<unsigned> NumExpansions) {
706 // Create the pack expansion type and source-location information.
708 Pattern->getTypeLoc().getSourceRange(),
709 EllipsisLoc, NumExpansions);
710 if (Result.isNull())
711 return nullptr;
712
713 TypeLocBuilder TLB;
714 TLB.pushFullCopy(Pattern->getTypeLoc());
716 TL.setEllipsisLoc(EllipsisLoc);
717
718 return TLB.getTypeSourceInfo(Context, Result);
719}
720
722 SourceLocation EllipsisLoc,
723 std::optional<unsigned> NumExpansions) {
724 // C++11 [temp.variadic]p5:
725 // The pattern of a pack expansion shall name one or more
726 // parameter packs that are not expanded by a nested pack
727 // expansion.
728 //
729 // A pattern containing a deduced type can't occur "naturally" but arises in
730 // the desugaring of an init-capture pack.
731 if (!Pattern->containsUnexpandedParameterPack() &&
732 !Pattern->getContainedDeducedType()) {
733 Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
734 << PatternRange;
735 return QualType();
736 }
737
738 return Context.getPackExpansionType(Pattern, NumExpansions,
739 /*ExpectPackInType=*/false);
740}
741
743 return CheckPackExpansion(Pattern, EllipsisLoc, std::nullopt);
744}
745
747 std::optional<unsigned> NumExpansions) {
748 if (!Pattern)
749 return ExprError();
750
751 // C++0x [temp.variadic]p5:
752 // The pattern of a pack expansion shall name one or more
753 // parameter packs that are not expanded by a nested pack
754 // expansion.
755 if (!Pattern->containsUnexpandedParameterPack()) {
756 Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
757 << Pattern->getSourceRange();
759 return ExprError();
760 }
761
762 // Create the pack expansion expression and source-location information.
763 return new (Context)
764 PackExpansionExpr(Context.DependentTy, Pattern, EllipsisLoc, NumExpansions);
765}
766
768 SourceLocation EllipsisLoc, SourceRange PatternRange,
770 const MultiLevelTemplateArgumentList &TemplateArgs, bool &ShouldExpand,
771 bool &RetainExpansion, std::optional<unsigned> &NumExpansions) {
772 ShouldExpand = true;
773 RetainExpansion = false;
774 std::pair<IdentifierInfo *, SourceLocation> FirstPack;
775 bool HaveFirstPack = false;
776 std::optional<unsigned> NumPartialExpansions;
777 SourceLocation PartiallySubstitutedPackLoc;
778 typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
779
780 for (UnexpandedParameterPack ParmPack : Unexpanded) {
781 // Compute the depth and index for this parameter pack.
782 unsigned Depth = 0, Index = 0;
783 IdentifierInfo *Name;
784 bool IsVarDeclPack = false;
785 ResolvedUnexpandedPackExpr *ResolvedPack = nullptr;
786
787 if (const TemplateTypeParmType *TTP =
788 ParmPack.first.dyn_cast<const TemplateTypeParmType *>()) {
789 Depth = TTP->getDepth();
790 Index = TTP->getIndex();
791 Name = TTP->getIdentifier();
792 } else if (auto *RP =
793 ParmPack.first.dyn_cast<ResolvedUnexpandedPackExpr *>()) {
794 ResolvedPack = RP;
795 } else {
796 NamedDecl *ND = cast<NamedDecl *>(ParmPack.first);
797 if (isa<VarDecl>(ND))
798 IsVarDeclPack = true;
799 else if (isa<BindingDecl>(ND)) {
800 // Find the instantiated BindingDecl and check it for a resolved pack.
801 llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation =
803 Decl *B = cast<Decl *>(*Instantiation);
804 Expr *BindingExpr = cast<BindingDecl>(B)->getBinding();
805 ResolvedPack = cast_if_present<ResolvedUnexpandedPackExpr>(BindingExpr);
806 if (!ResolvedPack) {
807 ShouldExpand = false;
808 continue;
809 }
810 } else
811 std::tie(Depth, Index) = getDepthAndIndex(ND);
812
813 Name = ND->getIdentifier();
814 }
815
816 // Determine the size of this argument pack.
817 unsigned NewPackSize, PendingPackExpansionSize = 0;
818 if (IsVarDeclPack) {
819 // Figure out whether we're instantiating to an argument pack or not.
820 llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation =
822 cast<NamedDecl *>(ParmPack.first));
823 if (isa<DeclArgumentPack *>(*Instantiation)) {
824 // We could expand this function parameter pack.
825 NewPackSize = cast<DeclArgumentPack *>(*Instantiation)->size();
826 } else {
827 // We can't expand this function parameter pack, so we can't expand
828 // the pack expansion.
829 ShouldExpand = false;
830 continue;
831 }
832 } else if (ResolvedPack) {
833 NewPackSize = ResolvedPack->getNumExprs();
834 } else {
835 // If we don't have a template argument at this depth/index, then we
836 // cannot expand the pack expansion. Make a note of this, but we still
837 // want to check any parameter packs we *do* have arguments for.
838 if (Depth >= TemplateArgs.getNumLevels() ||
839 !TemplateArgs.hasTemplateArgument(Depth, Index)) {
840 ShouldExpand = false;
841 continue;
842 }
843
844 // Determine the size of the argument pack.
846 TemplateArgs(Depth, Index).getPackAsArray();
847 NewPackSize = Pack.size();
848 PendingPackExpansionSize =
849 llvm::count_if(Pack, [](const TemplateArgument &TA) {
850 if (!TA.isPackExpansion())
851 return false;
852
854 return !TA.getAsType()
857
859 return !cast<PackExpansionExpr>(TA.getAsExpr())
860 ->getNumExpansions();
861
862 return !TA.getNumTemplateExpansions();
863 });
864 }
865
866 // C++0x [temp.arg.explicit]p9:
867 // Template argument deduction can extend the sequence of template
868 // arguments corresponding to a template parameter pack, even when the
869 // sequence contains explicitly specified template arguments.
870 if (!IsVarDeclPack && !ResolvedPack && CurrentInstantiationScope) {
871 if (NamedDecl *PartialPack =
873 unsigned PartialDepth, PartialIndex;
874 std::tie(PartialDepth, PartialIndex) = getDepthAndIndex(PartialPack);
875 if (PartialDepth == Depth && PartialIndex == Index) {
876 RetainExpansion = true;
877 // We don't actually know the new pack size yet.
878 NumPartialExpansions = NewPackSize;
879 PartiallySubstitutedPackLoc = ParmPack.second;
880 continue;
881 }
882 }
883 }
884
885 if (!NumExpansions) {
886 // This is the first pack we've seen for which we have an argument.
887 // Record it.
888 NumExpansions = NewPackSize;
889 FirstPack.first = Name;
890 FirstPack.second = ParmPack.second;
891 HaveFirstPack = true;
892 continue;
893 }
894
895 if (NewPackSize != *NumExpansions) {
896 // In some cases, we might be handling packs with unexpanded template
897 // arguments. For example, this can occur when substituting into a type
898 // alias declaration that uses its injected template parameters as
899 // arguments:
900 //
901 // template <class... Outer> struct S {
902 // template <class... Inner> using Alias = S<void(Outer, Inner)...>;
903 // };
904 //
905 // Consider an instantiation attempt like 'S<int>::Alias<Pack...>', where
906 // Pack comes from another template parameter. 'S<int>' is first
907 // instantiated, expanding the outer pack 'Outer' to <int>. The alias
908 // declaration is accordingly substituted, leaving the template arguments
909 // as unexpanded
910 // '<Pack...>'.
911 //
912 // Since we have no idea of the size of '<Pack...>' until its expansion,
913 // we shouldn't assume its pack size for validation. However if we are
914 // certain that there are extra arguments beyond unexpanded packs, in
915 // which case the pack size is already larger than the previous expansion,
916 // we can complain that before instantiation.
917 unsigned LeastNewPackSize = NewPackSize - PendingPackExpansionSize;
918 if (PendingPackExpansionSize && LeastNewPackSize <= *NumExpansions) {
919 ShouldExpand = false;
920 continue;
921 }
922 // C++0x [temp.variadic]p5:
923 // All of the parameter packs expanded by a pack expansion shall have
924 // the same number of arguments specified.
925 if (HaveFirstPack)
926 Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict)
927 << FirstPack.first << Name << *NumExpansions
928 << (LeastNewPackSize != NewPackSize) << LeastNewPackSize
929 << SourceRange(FirstPack.second) << SourceRange(ParmPack.second);
930 else
931 Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_multilevel)
932 << Name << *NumExpansions << (LeastNewPackSize != NewPackSize)
933 << LeastNewPackSize << SourceRange(ParmPack.second);
934 return true;
935 }
936 }
937
938 // If we're performing a partial expansion but we also have a full expansion,
939 // expand to the number of common arguments. For example, given:
940 //
941 // template<typename ...T> struct A {
942 // template<typename ...U> void f(pair<T, U>...);
943 // };
944 //
945 // ... a call to 'A<int, int>().f<int>' should expand the pack once and
946 // retain an expansion.
947 if (NumPartialExpansions) {
948 if (NumExpansions && *NumExpansions < *NumPartialExpansions) {
949 NamedDecl *PartialPack =
951 Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_partial)
952 << PartialPack << *NumPartialExpansions << *NumExpansions
953 << SourceRange(PartiallySubstitutedPackLoc);
954 return true;
955 }
956
957 NumExpansions = NumPartialExpansions;
958 }
959
960 return false;
961}
962
965 const MultiLevelTemplateArgumentList &TemplateArgs) {
966 std::optional<unsigned> Result;
967 for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
968 // Compute the depth and index for this parameter pack.
969 unsigned Depth;
970 unsigned Index;
971
972 if (const TemplateTypeParmType *TTP =
973 Unexpanded[I].first.dyn_cast<const TemplateTypeParmType *>()) {
974 Depth = TTP->getDepth();
975 Index = TTP->getIndex();
976 } else if (auto *PE = Unexpanded[I]
977 .first.dyn_cast<ResolvedUnexpandedPackExpr *>()) {
978 unsigned Size = PE->getNumExprs();
979 assert((!Result || *Result == Size) && "inconsistent pack sizes");
980 Result = Size;
981 continue;
982 } else {
983 NamedDecl *ND = cast<NamedDecl *>(Unexpanded[I].first);
984 if (isa<VarDecl>(ND)) {
985 // Function parameter pack or init-capture pack.
986 typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
987
988 llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation =
990 cast<NamedDecl *>(Unexpanded[I].first));
991 if (isa<Decl *>(*Instantiation))
992 // The pattern refers to an unexpanded pack. We're not ready to expand
993 // this pack yet.
994 return std::nullopt;
995
996 unsigned Size = cast<DeclArgumentPack *>(*Instantiation)->size();
997 assert((!Result || *Result == Size) && "inconsistent pack sizes");
998 Result = Size;
999 continue;
1000 }
1001
1002 std::tie(Depth, Index) = getDepthAndIndex(ND);
1003 }
1004 if (Depth >= TemplateArgs.getNumLevels() ||
1005 !TemplateArgs.hasTemplateArgument(Depth, Index))
1006 // The pattern refers to an unknown template argument. We're not ready to
1007 // expand this pack yet.
1008 return std::nullopt;
1009
1010 // Determine the size of the argument pack.
1011 unsigned Size = TemplateArgs(Depth, Index).pack_size();
1012 assert((!Result || *Result == Size) && "inconsistent pack sizes");
1013 Result = Size;
1014 }
1015
1016 return Result;
1017}
1018
1019std::optional<unsigned> Sema::getNumArgumentsInExpansion(
1020 QualType T, const MultiLevelTemplateArgumentList &TemplateArgs) {
1021 QualType Pattern = cast<PackExpansionType>(T)->getPattern();
1023 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(Pattern);
1024 return getNumArgumentsInExpansionFromUnexpanded(Unexpanded, TemplateArgs);
1025}
1026
1028 const DeclSpec &DS = D.getDeclSpec();
1029 switch (DS.getTypeSpecType()) {
1031 case TST_typename:
1033 case TST_typeofType:
1034#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case TST_##Trait:
1035#include "clang/Basic/TransformTypeTraits.def"
1036 case TST_atomic: {
1037 QualType T = DS.getRepAsType().get();
1038 if (!T.isNull() && T->containsUnexpandedParameterPack())
1039 return true;
1040 break;
1041 }
1042
1044 case TST_typeofExpr:
1045 case TST_decltype:
1046 case TST_bitint:
1047 if (DS.getRepAsExpr() &&
1049 return true;
1050 break;
1051
1052 case TST_unspecified:
1053 case TST_void:
1054 case TST_char:
1055 case TST_wchar:
1056 case TST_char8:
1057 case TST_char16:
1058 case TST_char32:
1059 case TST_int:
1060 case TST_int128:
1061 case TST_half:
1062 case TST_float:
1063 case TST_double:
1064 case TST_Accum:
1065 case TST_Fract:
1066 case TST_Float16:
1067 case TST_float128:
1068 case TST_ibm128:
1069 case TST_bool:
1070 case TST_decimal32:
1071 case TST_decimal64:
1072 case TST_decimal128:
1073 case TST_enum:
1074 case TST_union:
1075 case TST_struct:
1076 case TST_interface:
1077 case TST_class:
1078 case TST_auto:
1079 case TST_auto_type:
1080 case TST_decltype_auto:
1081 case TST_BFloat16:
1082#define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t:
1083#include "clang/Basic/OpenCLImageTypes.def"
1084#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case TST_##Name:
1085#include "clang/Basic/HLSLIntangibleTypes.def"
1087 case TST_error:
1088 break;
1089 }
1090
1091 for (unsigned I = 0, N = D.getNumTypeObjects(); I != N; ++I) {
1092 const DeclaratorChunk &Chunk = D.getTypeObject(I);
1093 switch (Chunk.Kind) {
1099 // These declarator chunks cannot contain any parameter packs.
1100 break;
1101
1103 if (Chunk.Arr.NumElts &&
1105 return true;
1106 break;
1108 for (unsigned i = 0, e = Chunk.Fun.NumParams; i != e; ++i) {
1109 ParmVarDecl *Param = cast<ParmVarDecl>(Chunk.Fun.Params[i].Param);
1110 QualType ParamTy = Param->getType();
1111 assert(!ParamTy.isNull() && "Couldn't parse type?");
1112 if (ParamTy->containsUnexpandedParameterPack()) return true;
1113 }
1114
1115 if (Chunk.Fun.getExceptionSpecType() == EST_Dynamic) {
1116 for (unsigned i = 0; i != Chunk.Fun.getNumExceptions(); ++i) {
1117 if (Chunk.Fun.Exceptions[i]
1118 .Ty.get()
1120 return true;
1121 }
1122 } else if (isComputedNoexcept(Chunk.Fun.getExceptionSpecType()) &&
1124 return true;
1125
1126 if (Chunk.Fun.hasTrailingReturnType()) {
1128 if (!T.isNull() && T->containsUnexpandedParameterPack())
1129 return true;
1130 }
1131 break;
1132
1134 if (Chunk.Mem.Scope().getScopeRep() &&
1136 return true;
1137 break;
1138 }
1139 }
1140
1141 if (Expr *TRC = D.getTrailingRequiresClause())
1142 if (TRC->containsUnexpandedParameterPack())
1143 return true;
1144
1145 return false;
1146}
1147
1148namespace {
1149
1150// Callback to only accept typo corrections that refer to parameter packs.
1151class ParameterPackValidatorCCC final : public CorrectionCandidateCallback {
1152 public:
1153 bool ValidateCandidate(const TypoCorrection &candidate) override {
1154 NamedDecl *ND = candidate.getCorrectionDecl();
1155 return ND && ND->isParameterPack();
1156 }
1157
1158 std::unique_ptr<CorrectionCandidateCallback> clone() override {
1159 return std::make_unique<ParameterPackValidatorCCC>(*this);
1160 }
1161};
1162
1163}
1164
1166 SourceLocation OpLoc,
1167 IdentifierInfo &Name,
1168 SourceLocation NameLoc,
1169 SourceLocation RParenLoc) {
1170 // C++0x [expr.sizeof]p5:
1171 // The identifier in a sizeof... expression shall name a parameter pack.
1172 LookupResult R(*this, &Name, NameLoc, LookupOrdinaryName);
1173 LookupName(R, S);
1174
1175 NamedDecl *ParameterPack = nullptr;
1176 switch (R.getResultKind()) {
1178 ParameterPack = R.getFoundDecl();
1179 break;
1180
1183 ParameterPackValidatorCCC CCC{};
1184 if (TypoCorrection Corrected =
1185 CorrectTypo(R.getLookupNameInfo(), R.getLookupKind(), S, nullptr,
1186 CCC, CTK_ErrorRecovery)) {
1187 diagnoseTypo(Corrected,
1188 PDiag(diag::err_sizeof_pack_no_pack_name_suggest) << &Name,
1189 PDiag(diag::note_parameter_pack_here));
1190 ParameterPack = Corrected.getCorrectionDecl();
1191 }
1192 break;
1193 }
1196 break;
1197
1200 return ExprError();
1201 }
1202
1203 if (!ParameterPack || !ParameterPack->isParameterPack()) {
1204 Diag(NameLoc, diag::err_expected_name_of_pack) << &Name;
1205 return ExprError();
1206 }
1207
1208 MarkAnyDeclReferenced(OpLoc, ParameterPack, true);
1209
1210 std::optional<unsigned> Length;
1211 if (auto *RP = ResolvedUnexpandedPackExpr::getFromDecl(ParameterPack))
1212 Length = RP->getNumExprs();
1213
1214 return SizeOfPackExpr::Create(Context, OpLoc, ParameterPack, NameLoc,
1215 RParenLoc, Length);
1216}
1217
1218static bool isParameterPack(Expr *PackExpression) {
1219 if (auto *D = dyn_cast<DeclRefExpr>(PackExpression); D) {
1220 ValueDecl *VD = D->getDecl();
1221 return VD->isParameterPack();
1222 }
1223 return false;
1224}
1225
1227 SourceLocation EllipsisLoc,
1228 SourceLocation LSquareLoc,
1229 Expr *IndexExpr,
1230 SourceLocation RSquareLoc) {
1231 bool isParameterPack = ::isParameterPack(PackExpression);
1232 if (!isParameterPack) {
1233 if (!PackExpression->containsErrors()) {
1234 CorrectDelayedTyposInExpr(IndexExpr);
1235 Diag(PackExpression->getBeginLoc(), diag::err_expected_name_of_pack)
1236 << PackExpression;
1237 }
1238 return ExprError();
1239 }
1240 ExprResult Res =
1241 BuildPackIndexingExpr(PackExpression, EllipsisLoc, IndexExpr, RSquareLoc);
1242 if (!Res.isInvalid())
1244 ? diag::warn_cxx23_pack_indexing
1245 : diag::ext_pack_indexing);
1246 return Res;
1247}
1248
1250 SourceLocation EllipsisLoc,
1251 Expr *IndexExpr,
1252 SourceLocation RSquareLoc,
1253 ArrayRef<Expr *> ExpandedExprs,
1254 bool FullySubstituted) {
1255
1256 std::optional<int64_t> Index;
1257 if (!IndexExpr->isInstantiationDependent()) {
1258 llvm::APSInt Value(Context.getIntWidth(Context.getSizeType()));
1259
1261 IndexExpr, Context.getSizeType(), Value, CCEK_ArrayBound);
1262 if (!Res.isUsable())
1263 return ExprError();
1264 Index = Value.getExtValue();
1265 IndexExpr = Res.get();
1266 }
1267
1268 if (Index && FullySubstituted) {
1269 if (*Index < 0 || *Index >= int64_t(ExpandedExprs.size())) {
1270 Diag(PackExpression->getBeginLoc(), diag::err_pack_index_out_of_bound)
1271 << *Index << PackExpression << ExpandedExprs.size();
1272 return ExprError();
1273 }
1274 }
1275
1276 return PackIndexingExpr::Create(getASTContext(), EllipsisLoc, RSquareLoc,
1277 PackExpression, IndexExpr, Index,
1278 ExpandedExprs, FullySubstituted);
1279}
1280
1282 TemplateArgumentLoc OrigLoc, SourceLocation &Ellipsis,
1283 std::optional<unsigned> &NumExpansions) const {
1284 const TemplateArgument &Argument = OrigLoc.getArgument();
1285 assert(Argument.isPackExpansion());
1286 switch (Argument.getKind()) {
1288 // FIXME: We shouldn't ever have to worry about missing
1289 // type-source info!
1290 TypeSourceInfo *ExpansionTSInfo = OrigLoc.getTypeSourceInfo();
1291 if (!ExpansionTSInfo)
1292 ExpansionTSInfo = Context.getTrivialTypeSourceInfo(Argument.getAsType(),
1293 Ellipsis);
1294 PackExpansionTypeLoc Expansion =
1295 ExpansionTSInfo->getTypeLoc().castAs<PackExpansionTypeLoc>();
1296 Ellipsis = Expansion.getEllipsisLoc();
1297
1298 TypeLoc Pattern = Expansion.getPatternLoc();
1299 NumExpansions = Expansion.getTypePtr()->getNumExpansions();
1300
1301 // We need to copy the TypeLoc because TemplateArgumentLocs store a
1302 // TypeSourceInfo.
1303 // FIXME: Find some way to avoid the copy?
1304 TypeLocBuilder TLB;
1305 TLB.pushFullCopy(Pattern);
1306 TypeSourceInfo *PatternTSInfo =
1307 TLB.getTypeSourceInfo(Context, Pattern.getType());
1309 PatternTSInfo);
1310 }
1311
1313 PackExpansionExpr *Expansion
1314 = cast<PackExpansionExpr>(Argument.getAsExpr());
1315 Expr *Pattern = Expansion->getPattern();
1316 Ellipsis = Expansion->getEllipsisLoc();
1317 NumExpansions = Expansion->getNumExpansions();
1318 return TemplateArgumentLoc(Pattern, Pattern);
1319 }
1320
1322 Ellipsis = OrigLoc.getTemplateEllipsisLoc();
1323 NumExpansions = Argument.getNumTemplateExpansions();
1325 OrigLoc.getTemplateQualifierLoc(),
1326 OrigLoc.getTemplateNameLoc());
1327
1335 return TemplateArgumentLoc();
1336 }
1337
1338 llvm_unreachable("Invalid TemplateArgument Kind!");
1339}
1340
1342 assert(Arg.containsUnexpandedParameterPack());
1343
1344 // If this is a substituted pack, grab that pack. If not, we don't know
1345 // the size yet.
1346 // FIXME: We could find a size in more cases by looking for a substituted
1347 // pack anywhere within this argument, but that's not necessary in the common
1348 // case for 'sizeof...(A)' handling.
1349 TemplateArgument Pack;
1350 switch (Arg.getKind()) {
1352 if (auto *Subst = Arg.getAsType()->getAs<SubstTemplateTypeParmPackType>())
1353 Pack = Subst->getArgumentPack();
1354 else
1355 return std::nullopt;
1356 break;
1357
1359 if (auto *Subst =
1360 dyn_cast<SubstNonTypeTemplateParmPackExpr>(Arg.getAsExpr()))
1361 Pack = Subst->getArgumentPack();
1362 else if (auto *Subst = dyn_cast<FunctionParmPackExpr>(Arg.getAsExpr())) {
1363 for (VarDecl *PD : *Subst)
1364 if (PD->isParameterPack())
1365 return std::nullopt;
1366 return Subst->getNumExpansions();
1367 } else
1368 return std::nullopt;
1369 break;
1370
1374 Pack = Subst->getArgumentPack();
1375 else
1376 return std::nullopt;
1377 break;
1378
1386 return std::nullopt;
1387 }
1388
1389 // Check that no argument in the pack is itself a pack expansion.
1390 for (TemplateArgument Elem : Pack.pack_elements()) {
1391 // There's no point recursing in this case; we would have already
1392 // expanded this pack expansion into the enclosing pack if we could.
1393 if (Elem.isPackExpansion())
1394 return std::nullopt;
1395 // Don't guess the size of unexpanded packs. The pack within a template
1396 // argument may have yet to be of a PackExpansion type before we see the
1397 // ellipsis in the annotation stage.
1398 //
1399 // This doesn't mean we would invalidate the optimization: Arg can be an
1400 // unexpanded pack regardless of Elem's dependence. For instance,
1401 // A TemplateArgument that contains either a SubstTemplateTypeParmPackType
1402 // or SubstNonTypeTemplateParmPackExpr is always considered Unexpanded, but
1403 // the underlying TemplateArgument thereof may not.
1404 if (Elem.containsUnexpandedParameterPack())
1405 return std::nullopt;
1406 }
1407 return Pack.pack_size();
1408}
1409
1410static void CheckFoldOperand(Sema &S, Expr *E) {
1411 if (!E)
1412 return;
1413
1414 E = E->IgnoreImpCasts();
1415 auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
1416 if ((OCE && OCE->isInfixBinaryOp()) || isa<BinaryOperator>(E) ||
1417 isa<AbstractConditionalOperator>(E)) {
1418 S.Diag(E->getExprLoc(), diag::err_fold_expression_bad_operand)
1419 << E->getSourceRange()
1422 }
1423}
1424
1426 tok::TokenKind Operator,
1427 SourceLocation EllipsisLoc, Expr *RHS,
1428 SourceLocation RParenLoc) {
1429 // LHS and RHS must be cast-expressions. We allow an arbitrary expression
1430 // in the parser and reduce down to just cast-expressions here.
1431 CheckFoldOperand(*this, LHS);
1432 CheckFoldOperand(*this, RHS);
1433
1434 auto DiscardOperands = [&] {
1437 };
1438
1439 // [expr.prim.fold]p3:
1440 // In a binary fold, op1 and op2 shall be the same fold-operator, and
1441 // either e1 shall contain an unexpanded parameter pack or e2 shall contain
1442 // an unexpanded parameter pack, but not both.
1443 if (LHS && RHS &&
1446 DiscardOperands();
1447 return Diag(EllipsisLoc,
1449 ? diag::err_fold_expression_packs_both_sides
1450 : diag::err_pack_expansion_without_parameter_packs)
1451 << LHS->getSourceRange() << RHS->getSourceRange();
1452 }
1453
1454 // [expr.prim.fold]p2:
1455 // In a unary fold, the cast-expression shall contain an unexpanded
1456 // parameter pack.
1457 if (!LHS || !RHS) {
1458 Expr *Pack = LHS ? LHS : RHS;
1459 assert(Pack && "fold expression with neither LHS nor RHS");
1460 if (!Pack->containsUnexpandedParameterPack()) {
1461 DiscardOperands();
1462 return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
1463 << Pack->getSourceRange();
1464 }
1465 }
1466
1467 BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
1468
1469 // Perform first-phase name lookup now.
1470 UnresolvedLookupExpr *ULE = nullptr;
1471 {
1472 UnresolvedSet<16> Functions;
1473 LookupBinOp(S, EllipsisLoc, Opc, Functions);
1474 if (!Functions.empty()) {
1478 /*NamingClass*/ nullptr, NestedNameSpecifierLoc(),
1479 DeclarationNameInfo(OpName, EllipsisLoc), Functions);
1480 if (Callee.isInvalid())
1481 return ExprError();
1482 ULE = cast<UnresolvedLookupExpr>(Callee.get());
1483 }
1484 }
1485
1486 return BuildCXXFoldExpr(ULE, LParenLoc, LHS, Opc, EllipsisLoc, RHS, RParenLoc,
1487 std::nullopt);
1488}
1489
1491 SourceLocation LParenLoc, Expr *LHS,
1492 BinaryOperatorKind Operator,
1493 SourceLocation EllipsisLoc, Expr *RHS,
1494 SourceLocation RParenLoc,
1495 std::optional<unsigned> NumExpansions) {
1496 return new (Context)
1497 CXXFoldExpr(Context.DependentTy, Callee, LParenLoc, LHS, Operator,
1498 EllipsisLoc, RHS, RParenLoc, NumExpansions);
1499}
1500
1502 BinaryOperatorKind Operator) {
1503 // [temp.variadic]p9:
1504 // If N is zero for a unary fold-expression, the value of the expression is
1505 // && -> true
1506 // || -> false
1507 // , -> void()
1508 // if the operator is not listed [above], the instantiation is ill-formed.
1509 //
1510 // Note that we need to use something like int() here, not merely 0, to
1511 // prevent the result from being a null pointer constant.
1512 QualType ScalarType;
1513 switch (Operator) {
1514 case BO_LOr:
1515 return ActOnCXXBoolLiteral(EllipsisLoc, tok::kw_false);
1516 case BO_LAnd:
1517 return ActOnCXXBoolLiteral(EllipsisLoc, tok::kw_true);
1518 case BO_Comma:
1519 ScalarType = Context.VoidTy;
1520 break;
1521
1522 default:
1523 return Diag(EllipsisLoc, diag::err_fold_expression_empty)
1524 << BinaryOperator::getOpcodeStr(Operator);
1525 }
1526
1527 return new (Context) CXXScalarValueInitExpr(
1528 ScalarType, Context.getTrivialTypeSourceInfo(ScalarType, EllipsisLoc),
1529 EllipsisLoc);
1530}
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:2195
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:2357
Represents a folding of a pack over an operator.
Definition: ExprCXX.h:4844
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:422
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:247
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:1904
Recursive AST visitor that supports extension via dynamic dispatch.
virtual bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc)
Recursively visit a template argument location and dispatch to the appropriate method for the argumen...
virtual bool TraverseConstructorInitializer(MaybeConst< CXXCtorInitializer > *Init)
Recursively visit a constructor initializer.
virtual bool TraverseDecl(MaybeConst< Decl > *D)
Recursively visit a declaration, by dispatching to Traverse*Decl() based on the argument's dynamic ty...
virtual bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier &Base)
Recursively visit a base specifier.
virtual bool TraverseStmt(MaybeConst< Stmt > *S)
Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dy...
virtual bool TraverseAttr(MaybeConst< Attr > *At)
Recursively visit an attribute, by dispatching to Traverse*Attr() based on the argument's dynamic typ...
virtual bool TraverseTypeLoc(TypeLoc TL)
Recursively visit a type with location, by dispatching to Traverse*TypeLoc() based on the argument ty...
virtual bool TraverseType(QualType T)
Recursively visit a type, by dispatching to Traverse*Type() based on the argument's getTypeClass() pr...
virtual bool TraverseTemplateName(TemplateName Template)
Recursively visit a template name and dispatch to the appropriate method.
virtual bool TraverseLambdaCapture(MaybeConst< LambdaExpr > *LE, const LambdaCapture *C, MaybeConst< Expr > *Init)
Recursively visit a lambda capture.
virtual bool TraverseTemplateArgument(const TemplateArgument &Arg)
Recursively visit a template argument and dispatch to the appropriate method for the argument type.
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:3076
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:276
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:4652
One of these records is kept for each identifier that is lexed.
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:515
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:2614
SourceLocation getEllipsisLoc() const
Definition: TypeLoc.h:2610
TypeLoc getPatternLoc() const
Definition: TypeLoc.h:2626
Represents a pack expansion of types.
Definition: Type.h:7147
std::optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:7172
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:2140
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
static ResolvedUnexpandedPackExpr * getFromDecl(Decl *)
Definition: ExprCXX.cpp:2012
unsigned getNumExprs() const
Definition: ExprCXX.h:5345
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:466
ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo)
Package the given type and TSI into a ParsedType.
Definition: SemaType.cpp:6395
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
Definition: Sema.h:12675
sema::CapturingScopeInfo * getEnclosingLambdaOrBlock() const
Get the innermost lambda or block enclosing the current location, if any.
Definition: Sema.cpp:2389
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:9004
SmallVector< sema::FunctionScopeInfo *, 4 > FunctionScopes
Stack containing information about each of the nested function, block, and method scopes that are cur...
Definition: Sema.h:851
ASTContext & Context
Definition: Sema.h:911
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:534
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:15319
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:13946
@ UPPC_Requirement
Definition: Sema.h:14014
const LangOptions & getLangOpts() const
Definition: Sema.h:527
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:20090
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:9398
@ CCEK_ArrayBound
Array bound in array declarator or new-expression.
Definition: Sema.h:10017
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:2751
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:358
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:334
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:346
Represents a reference to a non-type template parameter pack that has been substituted with a non-tem...
Definition: ExprCXX.h:4573
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:149
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:865
Represents the result of substituting a set of types for a template type parameter pack.
Definition: Type.h:6470
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:759
bool isParameterPack() const
Definition: Type.h:6350
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:7908
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:7919
SourceLocation getNameLoc() const
Definition: TypeLoc.h:536
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:8741
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:4021
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3924
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
bool isParameterPack() const
Determine whether this value is actually a function parameter pack, init-capture pack,...
Definition: Decl.cpp:5420
Represents a variable declaration or definition.
Definition: Decl.h:886
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
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl *, ResolvedUnexpandedPackExpr * >, SourceLocation > UnexpandedParameterPack
Definition: Sema.h:238
@ 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:1278
@ 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::@225 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