23#include "llvm/Support/SaveAndRestore.h"
34class CollectUnexpandedParameterPacksVisitor
36 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded;
38 bool InLambdaOrBlock =
false;
39 unsigned DepthLimit = (unsigned)-1;
42 bool ContainsIntermediatePacks =
false;
45 void addUnexpanded(NamedDecl *ND, SourceLocation Loc = SourceLocation()) {
46 if (
auto *VD = dyn_cast<VarDecl>(ND)) {
50 auto *FD = dyn_cast<FunctionDecl>(VD->getDeclContext());
51 auto *FTD = FD ? FD->getDescribedFunctionTemplate() :
nullptr;
52 if (FTD && FTD->getTemplateParameters()->getDepth() >= DepthLimit)
59 Unexpanded.push_back({ND, Loc});
62 void addUnexpanded(
const TemplateTypeParmType *
T,
63 SourceLocation Loc = SourceLocation()) {
64 if (
T->getDepth() < DepthLimit)
65 Unexpanded.push_back({
T, Loc});
68 bool addUnexpanded(
const SubstBuiltinTemplatePackType *
T,
69 SourceLocation Loc = SourceLocation()) {
70 Unexpanded.push_back({
T, Loc});
74 bool addUnexpanded(
const TemplateSpecializationType *
T,
75 SourceLocation Loc = SourceLocation()) {
78 Unexpanded.push_back({
T, Loc});
85 TryTraverseSpecializationProducingPacks(
const TemplateSpecializationType *
T,
92 addUnexpanded(
T, Loc);
104 explicit CollectUnexpandedParameterPacksVisitor(
105 SmallVectorImpl<UnexpandedParameterPack> &Unexpanded)
106 : Unexpanded(Unexpanded) {
107 ShouldWalkTypesOfTypeLocs =
false;
110 ShouldVisitImplicitCode =
true;
118 bool VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL)
override {
129 bool VisitTemplateTypeParmType(TemplateTypeParmType *
T)
override {
130 if (
T->isParameterPack())
138 bool VisitDeclRefExpr(DeclRefExpr *E)
override {
147 bool TraverseQualifier =
true)
override {
149 if (PackIndexingTemplateStorage *PI =
150 Template.getAsPackIndexingTemplate())
153 if (
auto *TTP = dyn_cast_or_null<TemplateTemplateParmDecl>(
155 if (TTP->isParameterPack())
160 ContainsIntermediatePacks |=
169 TraverseTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc
T,
170 bool TraverseQualifier)
override {
171 if (TryTraverseSpecializationProducingPacks(
T.getTypePtr(),
174 return DynamicRecursiveASTVisitor::TraverseTemplateSpecializationTypeLoc(
175 T, TraverseQualifier);
178 bool TraverseTemplateSpecializationType(TemplateSpecializationType *
T,
179 bool TraverseQualfier)
override {
180 if (TryTraverseSpecializationProducingPacks(
T, SourceLocation()))
182 return DynamicRecursiveASTVisitor::TraverseTemplateSpecializationType(
T);
187 bool TraverseObjCDictionaryLiteral(ObjCDictionaryLiteral *E)
override {
196 TraverseStmt(Element.
Key);
197 TraverseStmt(Element.
Value);
207 bool TraverseStmt(Stmt *S)
override {
208 Expr *E = dyn_cast_or_null<Expr>(S);
217 bool TraverseType(QualType
T,
bool TraverseQualifier =
true)
override {
227 bool TraverseTypeLoc(TypeLoc TL,
bool TraverseQualifier =
true)
override {
238 bool TraverseDecl(Decl *D)
override {
249 bool TraverseAttr(Attr *A)
override {
258 bool TraversePackExpansionType(PackExpansionType *
T,
259 bool TraverseQualifier)
override {
262 bool TraversePackExpansionTypeLoc(PackExpansionTypeLoc TL,
263 bool TraverseQualifier)
override {
266 bool TraversePackExpansionExpr(PackExpansionExpr *E)
override {
269 bool TraverseCXXFoldExpr(CXXFoldExpr *E)
override {
return true; }
270 bool TraversePackIndexingExpr(PackIndexingExpr *E)
override {
273 bool TraversePackIndexingType(PackIndexingType *E,
274 bool TraverseQualifier)
override {
277 bool TraversePackIndexingTypeLoc(PackIndexingTypeLoc TL,
278 bool TraverseQualifier)
override {
286 TraverseUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D)
override {
290 return DynamicRecursiveASTVisitor::TraverseUnresolvedUsingValueDecl(D);
294 bool TraverseUnresolvedUsingTypenameDecl(
295 UnresolvedUsingTypenameDecl *D)
override {
299 return DynamicRecursiveASTVisitor::TraverseUnresolvedUsingTypenameDecl(D);
303 bool TraverseTemplateArgument(
const TemplateArgument &Arg)
override {
312 TraverseTemplateArgumentLoc(
const TemplateArgumentLoc &ArgLoc)
override {
320 bool TraverseCXXBaseSpecifier(
const CXXBaseSpecifier &Base)
override {
321 if (
Base.isPackExpansion())
328 bool TraverseConstructorInitializer(CXXCtorInitializer *
Init)
override {
329 if (
Init->isPackExpansion())
340 bool TraverseLambdaExpr(
LambdaExpr *Lambda)
override {
346 SaveAndRestore _(InLambdaOrBlock,
true);
347 unsigned OldDepthLimit = DepthLimit;
350 DepthLimit = TPL->getDepth();
352 DynamicRecursiveASTVisitor::TraverseLambdaExpr(Lambda);
354 DepthLimit = OldDepthLimit;
359 bool TraverseBlockExpr(BlockExpr *
Block)
override {
360 if (!
Block->containsUnexpandedParameterPack())
363 SaveAndRestore _(InLambdaOrBlock,
true);
364 DynamicRecursiveASTVisitor::TraverseBlockExpr(
Block);
369 bool TraverseLambdaCapture(
LambdaExpr *Lambda,
const LambdaCapture *
C,
370 Expr *
Init)
override {
371 if (
C->isPackExpansion())
377 bool TraverseUnresolvedLookupExpr(UnresolvedLookupExpr *E)
override {
380 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND);
381 TTP && TTP->isParameterPack())
384 return DynamicRecursiveASTVisitor::TraverseUnresolvedLookupExpr(E);
387 bool TraverseSubstBuiltinTemplatePackType(SubstBuiltinTemplatePackType *
T,
388 bool TraverseQualifier)
override {
396 bool TraverseFunctionParmPackExpr(FunctionParmPackExpr *)
override {
397 ContainsIntermediatePacks =
true;
401 bool TraverseSubstNonTypeTemplateParmPackExpr(
402 SubstNonTypeTemplateParmPackExpr *)
override {
403 ContainsIntermediatePacks =
true;
407 bool VisitSubstTemplateTypeParmPackType(
408 SubstTemplateTypeParmPackType *)
override {
409 ContainsIntermediatePacks =
true;
413 bool VisitSubstTemplateTypeParmPackTypeLoc(
414 SubstTemplateTypeParmPackTypeLoc)
override {
415 ContainsIntermediatePacks =
true;
419 bool containsIntermediatePacks()
const {
return ContainsIntermediatePacks; }
444 if (Unexpanded.empty())
454 for (
auto &Pack : Unexpanded) {
455 auto DeclaresThisPack = [&](
NamedDecl *LocalPack) {
456 if (
auto *TTPT = Pack.first.dyn_cast<
const TemplateTypeParmType *>()) {
457 auto *TTPD = dyn_cast<TemplateTypeParmDecl>(LocalPack);
458 return TTPD && TTPD->getTypeForDecl() == TTPT;
462 if (llvm::any_of(CSI->LocalPacks, DeclaresThisPack))
463 ParamPackReferences.push_back(Pack);
466 if (ParamPackReferences.empty()) {
478 bool EnclosingStmtExpr =
false;
482 Func->CompoundScopes,
484 EnclosingStmtExpr =
true;
493 if (!EnclosingStmtExpr) {
494 CSI->ContainsUnexpandedParameterPack =
true;
498 Unexpanded = ParamPackReferences;
506 for (
unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
508 if (
const TemplateTypeParmType *TTP
509 = Unexpanded[I].first.dyn_cast<
const TemplateTypeParmType *>())
510 Name = TTP->getIdentifier();
514 if (Name && NamesKnown.insert(Name).second)
515 Names.push_back(Name);
517 if (Unexpanded[I].second.isValid())
518 Locations.push_back(Unexpanded[I].second);
521 auto DB =
Diag(Loc, diag::err_unexpanded_parameter_pack)
522 << (int)UPPC << (
int)Names.size();
523 for (
size_t I = 0, E = std::min(Names.size(), (
size_t)2); I != E; ++I)
526 for (
unsigned I = 0, N = Locations.size(); I != N; ++I)
537 if (!
T->getType()->containsUnexpandedParameterPack())
541 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(
543 assert(!Unexpanded.empty() &&
"Unable to find unexpanded parameter packs");
556 CollectUnexpandedParameterPacksVisitor Visitor(Unexpanded);
557 Visitor.TraverseStmt(E);
564 bool LambdaReferencingOuterPacks =
566 assert((!Unexpanded.empty() || LambdaReferencingOuterPacks) &&
567 "Unable to find unexpanded parameter packs");
577 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(RE);
578 assert(!Unexpanded.empty() &&
"Unable to find unexpanded parameter packs");
585 for (
auto Parm : Unexpanded)
586 if (ParmSet.contains(Parm.first.dyn_cast<
NamedDecl *>()))
587 UnexpandedParms.push_back(Parm);
588 if (UnexpandedParms.empty())
604 CollectUnexpandedParameterPacksVisitor(Unexpanded)
606 assert(!Unexpanded.empty() &&
"Unable to find unexpanded parameter packs");
641 CollectUnexpandedParameterPacksVisitor(Unexpanded)
643 assert(!Unexpanded.empty() &&
"Unable to find unexpanded parameter packs");
655 CollectUnexpandedParameterPacksVisitor(Unexpanded)
657 assert(!Unexpanded.empty() &&
"Unable to find unexpanded parameter packs");
668 CollectUnexpandedParameterPacksVisitor(Unexpanded)
669 .TraverseTemplateArgumentLoc(Arg);
670 assert(!Unexpanded.empty() &&
"Unable to find unexpanded parameter packs");
676 CollectUnexpandedParameterPacksVisitor(Unexpanded)
677 .TraverseTemplateArgument(Arg);
682 CollectUnexpandedParameterPacksVisitor(Unexpanded)
683 .TraverseTemplateArgumentLoc(Arg);
688 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(
T);
694 CollectUnexpandedParameterPacksVisitor(Unexpanded)
700 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(TL);
706 CollectUnexpandedParameterPacksVisitor(Unexpanded)
707 .TraverseNestedNameSpecifierLoc(NNS);
713 CollectUnexpandedParameterPacksVisitor(Unexpanded)
714 .TraverseDeclarationNameInfo(NameInfo);
719 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(E);
730 auto *
T = dyn_cast_or_null<BuiltinTemplateDecl>(
732 if (
T &&
T->isPackProducingBuiltinTemplate())
769 Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
776 llvm_unreachable(
"Unhandled template argument kind?");
800 EllipsisLoc, NumExpansions);
824 Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
829 return Context.getPackExpansionType(Pattern, NumExpansions,
847 Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
860 bool FailOnPackProducingTemplates,
bool &ShouldExpand,
863 RetainExpansion =
false;
865 bool HaveFirstPack =
false;
872 unsigned Depth = 0, Index = 0;
874 bool IsVarDeclPack =
false;
876 std::optional<unsigned> NumPrecomputedArguments;
878 if (
auto *TTP = ParmPack.first.dyn_cast<
const TemplateTypeParmType *>()) {
879 Depth = TTP->getDepth();
880 Index = TTP->getIndex();
881 Name = TTP->getIdentifier();
882 }
else if (
auto *TST =
884 .dyn_cast<
const TemplateSpecializationType *>()) {
887 ShouldExpand =
false;
888 if (!FailOnPackProducingTemplates)
897 diag::err_unsupported_builtin_template_pack_expansion)
898 << TST->getTemplateName();
901 .dyn_cast<
const SubstBuiltinTemplatePackType *>()) {
903 NumPrecomputedArguments = S->getNumArgs();
907 IsVarDeclPack =
true;
910 llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation =
914 BindingPack = cast_if_present<FunctionParmPackExpr>(BindingExpr);
916 ShouldExpand =
false;
926 unsigned NewPackSize, PendingPackExpansionSize = 0;
933 llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation =
942 ShouldExpand =
false;
945 }
else if (BindingPack) {
947 }
else if (NumPrecomputedArguments) {
948 NewPackSize = *NumPrecomputedArguments;
955 ShouldExpand =
false;
961 TemplateArgs(Depth, Index).getPackAsArray();
962 NewPackSize = Pack.size();
963 PendingPackExpansionSize =
970 ->
castAs<PackExpansionType>()
971 ->getNumExpansions();
975 ->getNumExpansions();
988 unsigned PartialDepth, PartialIndex;
990 if (PartialDepth == Depth && PartialIndex == Index) {
991 RetainExpansion =
true;
993 NumPartialExpansions = NewPackSize;
994 PartiallySubstitutedPackLoc = ParmPack.second;
1000 if (!NumExpansions) {
1003 NumExpansions = NewPackSize;
1005 HaveFirstPack =
true;
1009 if (NewPackSize != *NumExpansions) {
1031 unsigned LeastNewPackSize = NewPackSize - PendingPackExpansionSize;
1032 if (PendingPackExpansionSize && LeastNewPackSize <= *NumExpansions) {
1033 ShouldExpand =
false;
1041 else if (HaveFirstPack)
1042 Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict)
1044 << (LeastNewPackSize != NewPackSize) << LeastNewPackSize
1047 Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_multilevel)
1048 << Name << *NumExpansions << (LeastNewPackSize != NewPackSize)
1049 << LeastNewPackSize <<
SourceRange(ParmPack.second);
1063 if (NumPartialExpansions) {
1064 if (NumExpansions && *NumExpansions < *NumPartialExpansions) {
1069 Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_partial)
1070 << PartialPack << *NumPartialExpansions << *NumExpansions
1075 NumExpansions = NumPartialExpansions;
1085 for (
unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
1090 if (
const TemplateTypeParmType *TTP =
1091 Unexpanded[I].first.dyn_cast<
const TemplateTypeParmType *>()) {
1092 Depth = TTP->getDepth();
1093 Index = TTP->getIndex();
1094 }
else if (
auto *TST =
1096 .first.dyn_cast<
const TemplateSpecializationType *>()) {
1100 return std::nullopt;
1101 }
else if (
auto *PST =
1104 .dyn_cast<const SubstBuiltinTemplatePackType *>()) {
1106 "inconsistent pack sizes");
1107 Result = PST->getNumArgs();
1115 llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation =
1121 return std::nullopt;
1124 assert((!
Result || *
Result == Size) &&
"inconsistent pack sizes");
1135 return std::nullopt;
1138 unsigned Size = TemplateArgs(Depth, Index).pack_size();
1139 assert((!
Result || *
Result == Size) &&
"inconsistent pack sizes");
1150 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(Pattern);
1161#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case TST_##Trait:
1162#include "clang/Basic/BuiltinTraits.inc"
1165 if (!
T.isNull() &&
T->containsUnexpandedParameterPack())
1209#define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t:
1210#include "clang/Basic/OpenCLImageTypes.def"
1211#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case TST_##Name:
1212#include "clang/Basic/HLSLIntangibleTypes.def"
1220 switch (Chunk.
Kind) {
1235 for (
unsigned i = 0, e = Chunk.
Fun.
NumParams; i != e; ++i) {
1237 QualType ParamTy = Param->getType();
1238 assert(!ParamTy.
isNull() &&
"Couldn't parse type?");
1255 if (!
T.isNull() &&
T->containsUnexpandedParameterPack())
1268 if (TRC->containsUnexpandedParameterPack())
1279 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
1284 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
1285 return std::make_unique<ParameterPackValidatorCCC>(*
this);
1302 switch (R.getResultKind()) {
1304 ParameterPack = R.getFoundDecl();
1309 ParameterPackValidatorCCC CCC{};
1311 CorrectTypo(R.getLookupNameInfo(), R.getLookupKind(), S,
nullptr,
1314 PDiag(diag::err_sizeof_pack_no_pack_name_suggest) << &Name,
1315 PDiag(diag::note_parameter_pack_here));
1316 ParameterPack = Corrected.getCorrectionDecl();
1330 Diag(NameLoc, diag::err_expected_name_of_pack) << &Name;
1341 if (
auto *D = dyn_cast<DeclRefExpr>(PackExpression); D) {
1364 ? diag::warn_cxx23_pack_indexing
1365 : diag::ext_pack_indexing);
1374 bool FullySubstituted) {
1376 std::optional<uint64_t> Index;
1384 Index =
Value.getZExtValue();
1385 IndexExpr = Res.
get();
1388 if (Index && FullySubstituted) {
1389 if (*Index >= ExpandedExprs.size()) {
1390 Diag(PackExpression->
getBeginLoc(), diag::err_pack_index_out_of_bound)
1391 << *Index << PackExpression << ExpandedExprs.size();
1397 PackExpression, IndexExpr, Index,
1398 ExpandedExprs, FullySubstituted);
1404 assert(!Pattern.
isNull() && IndexExpr);
1411 Diag(NameLoc, diag::err_expected_name_of_pack) << Pattern;
1414 if (!Name.
isNull() && DenotesPack)
1415 DiagCompat(NameLoc, diag_compat::pack_indexing_template);
1421 bool FullySubstituted,
1430 IndexExpr = Res.
get();
1431 uint64_t
V =
Value.getZExtValue();
1432 if (FullySubstituted &&
V >= Expansions.size()) {
1434 <<
V << Pattern << Expansions.size();
1439 return Context.getPackIndexingTemplateName(Pattern, IndexExpr,
1440 FullySubstituted, Expansions);
1452 TL.setNameLoc(NameLoc);
1466 if (!ExpansionTSInfo)
1474 NumExpansions = Expansion.
getTypePtr()->getNumExpansions();
1514 llvm_unreachable(
"Invalid TemplateArgument Kind!");
1528 if (
auto *Subst = Arg.
getAsType()->
getAs<SubstTemplateTypeParmPackType>())
1529 Pack = Subst->getArgumentPack();
1531 return std::nullopt;
1536 dyn_cast<SubstNonTypeTemplateParmPackExpr>(Arg.
getAsExpr()))
1537 Pack = Subst->getArgumentPack();
1538 else if (
auto *Subst = dyn_cast<FunctionParmPackExpr>(Arg.
getAsExpr())) {
1540 if (PD->isParameterPack())
1541 return std::nullopt;
1542 return Subst->getNumExpansions();
1544 return std::nullopt;
1550 Pack = Subst->getArgumentPack();
1552 return std::nullopt;
1562 return std::nullopt;
1569 if (Elem.isPackExpansion())
1570 return std::nullopt;
1580 if (Elem.containsUnexpandedParameterPack())
1581 return std::nullopt;
1591 auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
1618 return Diag(EllipsisLoc,
1620 ? diag::err_fold_expression_packs_both_sides
1621 : diag::err_pack_expansion_without_parameter_packs)
1629 Expr *Pack = LHS ? LHS : RHS;
1630 assert(Pack &&
"fold expression with neither LHS nor RHS");
1632 return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
1644 if (!Functions.
empty()) {
1650 if (Callee.isInvalid())
1656 return BuildCXXFoldExpr(ULE, LParenLoc, LHS, Opc, EllipsisLoc, RHS, RParenLoc,
1668 EllipsisLoc, RHS, RParenLoc, NumExpansions);
1693 return Diag(EllipsisLoc, diag::err_fold_expression_empty)
1698 ScalarType,
Context.getTrivialTypeSourceInfo(ScalarType, EllipsisLoc),
static void CheckFoldOperand(Sema &S, Expr *E)
static bool isParameterPack(Expr *PackExpression)
Defines the clang::TypeLoc interface and its subclasses.
bool isPackExpansion() const
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
StringRef getOpcodeStr() const
Represents a folding of a pack over an operator.
An expression "T()" which creates an rvalue of a non-class type T.
Represents a C++ nested-name-specifier or a global scope specifier.
bool isValid() const
A scope specifier is present, and it refers to a real scope.
SourceRange getRange() const
SourceLocation getBeginLoc() const
NestedNameSpecifier getScopeRep() const
Retrieve the representation of the nested-name-specifier.
const TypeClass * getTypePtr() const
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
SourceLocation getLocation() const
Captures information about "declaration specifiers".
TST getTypeSpecType() const
ParsedType getRepAsType() const
Expr * getRepAsExpr() const
Decl - This represents one declaration (or definition), e.g.
bool isParameterPack() const
Whether this declaration is a parameter pack.
bool isTemplateParameterPack() const
isTemplateParameter - Determines whether this declaration is a template parameter pack.
The name of a declaration.
@ CXXConversionFunctionName
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.
const DeclaratorChunk & getTypeObject(unsigned i) const
Return the specified TypeInfo from this declarator.
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
Expr * getTrailingRequiresClause()
Sets a trailing requires clause for this declarator.
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
virtual bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc)
virtual bool TraverseConstructorInitializer(MaybeConst< CXXCtorInitializer > *Init)
virtual bool TraverseDecl(MaybeConst< Decl > *D)
virtual bool TraverseTypeLoc(TypeLoc TL, bool TraverseQualifier=true)
virtual bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier &Base)
virtual bool TraverseTemplateName(TemplateName Template, bool TraverseQualifier=true)
virtual bool TraverseStmt(MaybeConst< Stmt > *S)
virtual bool TraverseAttr(MaybeConst< Attr > *At)
virtual bool TraverseLambdaCapture(MaybeConst< LambdaExpr > *LE, const LambdaCapture *C, MaybeConst< Expr > *Init)
virtual bool TraverseType(QualType T, bool TraverseQualifier=true)
virtual bool TraverseTemplateArgument(const TemplateArgument &Arg)
This represents one expression.
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates).
bool containsErrors() const
Whether this expression contains subexpressions which had errors.
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
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.
Represents a reference to a function parameter pack, init-capture pack, or binding pack that has been...
unsigned getNumExpansions() const
Get the number of parameters in this parameter pack.
One of these records is kept for each identifier that is lexed.
A simple pair of identifier info and location.
SourceLocation getLoc() const
IdentifierInfo * getIdentifierInfo() const
const TypeClass * getTypePtr() const
TemplateParameterList * getTemplateParameterList() const
If this is a generic lambda expression, retrieve the template parameter list associated with it,...
SmallVector< ValueDecl *, 4 > DeclArgumentPack
A set of declarations.
Represents the results of name lookup.
Data structure that captures multiple levels of template argument lists for use in template instantia...
bool hasTemplateArgument(unsigned Depth, unsigned Index) const
Determine whether there is a non-NULL template argument at the given depth and index.
unsigned getNumLevels() const
Determine the number of levels in this template argument list.
This represents a decl that may have a name.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
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...
unsigned getNumElements() const
getNumElements - Return number of elements of objective-c dictionary literal.
ObjCDictionaryElement getKeyValueElement(unsigned Index) const
decls_iterator decls_begin() const
unsigned getNumDecls() const
Gets the number of declarations in the unresolved set.
Represents a C++11 pack expansion that produces a sequence of expressions.
Expr * getPattern()
Retrieve the pattern of the pack expansion.
UnsignedOrNone getNumExpansions() const
Determine the number of expansions that will be produced when this pack expansion is instantiated,...
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis that describes this pack expansion.
void setEllipsisLoc(SourceLocation Loc)
SourceLocation getEllipsisLoc() const
TypeLoc getPatternLoc() const
Expr * getIndexExpr() const
static PackIndexingExpr * Create(ASTContext &Context, SourceLocation EllipsisLoc, SourceLocation RSquareLoc, Expr *PackIdExpr, Expr *IndexExpr, std::optional< int64_t > Index, ArrayRef< Expr * > SubstitutedExprs={}, bool FullySubstituted=false)
Expr * getIndexExpr() const
Represents a parameter to a function.
Represents the parsed form of a C++ template argument.
KindType getKind() const
Determine what kind of template argument we have.
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.
SourceLocation getNameLoc() const
Retrieve the location of the template argument.
const CXXScopeSpec & getScopeSpec() const
Retrieve the nested-name-specifier that precedes the template name in a template template argument.
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
SourceLocation getBeginLoc() const LLVM_READONLY
ArrayRef< ParmVarDecl * > getLocalParameters() const
Scope - A scope is a transient data structure that is used while parsing the program.
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
SemaDiagnosticBuilder DiagCompat(SourceLocation Loc, unsigned CompatDiagId)
Emit a compatibility diagnostic.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Sema - This implements semantic analysis and AST building for C.
ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo)
Package the given type and TSI into a ParsedType.
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
sema::CapturingScopeInfo * getEnclosingLambdaOrBlock() const
Get the innermost lambda or block enclosing the current location, if any.
bool containsUnexpandedParameterPacks(Declarator &D)
Determine whether the given declarator contains any unexpanded parameter packs.
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
SmallVector< sema::FunctionScopeInfo *, 4 > FunctionScopes
Stack containing information about each of the nested function, block, and method scopes that are cur...
TemplateName BuildPackIndexingTemplateName(TemplateName Pattern, Expr *IndexExpr, bool FullySubstituted=false, ArrayRef< TemplateName > Expansions={})
TypeResult ActOnPackIndexingDeducedTemplateSpecializationType(TemplateName Name, SourceLocation NameLoc)
bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc, SourceRange PatternRange, ArrayRef< UnexpandedParameterPack > Unexpanded, const MultiLevelTemplateArgumentList &TemplateArgs, bool FailOnPackProducingTemplates, bool &ShouldExpand, bool &RetainExpansion, UnsignedOrNone &NumExpansions, bool Diagnose=true)
Determine whether we could expand a pack expansion with the given set of parameter packs into separat...
TemplateName ActOnPackIndexingTemplateName(TemplateName Pattern, SourceLocation NameLoc, Expr *IndexExpr)
ExprResult BuildPackIndexingExpr(Expr *PackExpression, SourceLocation EllipsisLoc, Expr *IndexExpr, SourceLocation RSquareLoc, ArrayRef< Expr * > ExpandedExprs={}, bool FullySubstituted=false)
ASTContext & getASTContext() const
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)
ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, llvm::APSInt &Value, CCEKind CCE)
ExprResult BuildCXXFoldExpr(UnresolvedLookupExpr *Callee, SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, UnsignedOrNone NumExpansions)
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
UnexpandedParameterPackContext
The context in which an unexpanded parameter pack is being diagnosed.
const LangOptions & getLangOpts() const
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.
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.
UnsignedOrNone getNumArgumentsInExpansion(QualType T, const MultiLevelTemplateArgumentList &TemplateArgs)
Determine the number of arguments in the given pack expansion type.
ParsedTemplateArgument ActOnTemplateTemplateArgument(const ParsedTemplateArgument &Arg)
Invoked when parsing a template argument.
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.
void diagnoseTypo(const TypoCorrection &Correction, const PartialDiagnostic &TypoDiag, bool ErrorRecovery=true)
UnsignedOrNone getFullyPackExpandedSize(TemplateArgument Arg)
Given a template argument that contains an unexpanded parameter pack, but which has already been subs...
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)
void diagnoseMissingTemplateArguments(TemplateName Name, SourceLocation Loc)
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 ).
@ Diagnose
Diagnose issues that are non-constant or that are extensions.
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)
UnsignedOrNone getNumArgumentsInExpansionFromUnexpanded(llvm::ArrayRef< UnexpandedParameterPack > Unexpanded, const MultiLevelTemplateArgumentList &TemplateArgs)
bool DiagnoseUnexpandedParameterPacks(SourceLocation Loc, UnexpandedParameterPackContext UPPC, ArrayRef< UnexpandedParameterPack > Unexpanded)
Diagnose unexpanded parameter packs.
TemplateArgumentLoc getTemplateArgumentPackExpansionPattern(TemplateArgumentLoc OrigLoc, SourceLocation &Ellipsis, UnsignedOrNone &NumExpansions) const
Returns the pattern of the pack expansion for a template argument.
TypeSourceInfo * CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc, UnsignedOrNone NumExpansions)
Construct a pack expansion type from the pattern of the pack expansion.
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, UnsignedOrNone Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs={})
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
SourceLocation getEndLoc() const LLVM_READONLY
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
A structure for storing an already-substituted template template parameter pack.
Location wrapper for a TemplateArgument.
SourceLocation getLocation() const
SourceLocation getTemplateEllipsisLoc() const
const TemplateArgument & getArgument() const
SourceLocation getTemplateNameLoc() const
SourceLocation getTemplateKWLoc() const
TypeSourceInfo * getTypeSourceInfo() const
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Represents a template argument.
Expr * getAsExpr() const
Retrieve the template argument as an expression.
UnsignedOrNone 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.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
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.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
bool isCanonicalExpr() const
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
Represents a C++ template name within the type system.
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.
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.
QualType getType() const
Get the type for which this source info wrapper provides information.
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type.
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
A container of type source information.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
QualType getType() const
Return the type wrapped by this type source info.
SourceLocation getNameLoc() const
The base class of the type hierarchy.
const T * castAs() const
Member-template castAs<specific type>.
DeducedType * getContainedDeducedType() const
Get the DeducedType whose type will be deduced for a variable with an initializer of this type.
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
const T * getAs() const
Member-template getAs<specific type>'.
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...
SourceLocation getBeginLoc() const LLVM_READONLY
A set of unresolved declarations.
bool isPackExpansion() const
Determine whether this is a pack expansion.
bool isPackExpansion() const
Determine whether this is a pack expansion.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
bool isParameterPack() const
Determine whether this value is actually a function parameter pack, init-capture pack,...
Contains information about the compound statement currently being parsed.
Retains information about a function, method, or block that is currently being parsed.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Top level wrappers for InstallAPI frontend operations.
@ TST_typename_pack_indexing
bool isa(CodeGen::Address addr)
@ Ambiguous
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
@ NotFound
No entity found met the criteria.
@ FoundOverloaded
Name lookup found a set of overloaded functions that met the criteria.
@ Found
Name lookup found a single declaration that met the criteria.
@ FoundUnresolvedValue
Name lookup found an unresolvable value declaration and cannot yet complete.
@ NotFoundInCurrentInstantiation
No entity found met the criteria within the current instantiation,, but there were dependent base cla...
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl *, const TemplateSpecializationType *, const SubstBuiltinTemplatePackType * >, SourceLocation > UnexpandedParameterPack
bool isPackProducingBuiltinTemplateName(TemplateName N)
@ Result
The result type of a method or function.
ActionResult< ParsedType > TypeResult
std::pair< unsigned, unsigned > getDepthAndIndex(const NamedDecl *ND)
Retrieve the depth and index of a template parameter.
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
@ Template
We are parsing a template declaration.
@ Undeduced
Not deduced yet. This is for example an 'auto' which was just parsed.
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
DynamicRecursiveASTVisitorBase< false > DynamicRecursiveASTVisitor
U cast(CodeGen::Address addr)
@ PackIndex
Index of a pack indexing expression or specifier.
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
@ None
No keyword precedes the qualified type name.
ActionResult< Expr * > ExprResult
@ 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
Expr * NumElts
This is the size of the array, or null if [] or [*] was specified.
bool hasTrailingReturnType() const
Determine whether this function declarator had a trailing-return-type.
TypeAndRange * Exceptions
Pointer to a new[]'d array of TypeAndRange objects that contain the types in the function's dynamic e...
ParamInfo * Params
Params - This is a pointer to a new[]'d array of ParamInfo objects that describe the parameters speci...
ParsedType getTrailingReturnType() const
Get the trailing-return-type for this function declarator.
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
unsigned getNumExceptions() const
Get the number of dynamic exception specifications.
ExceptionSpecificationType getExceptionSpecType() const
Get the type of exception specification this function has.
Expr * NoexceptExpr
Pointer to the expression in the noexcept-specifier of this function, if it has one.
One instance of this struct is used for each type in a declarator that is parsed.
MemberPointerTypeInfo Mem
enum clang::DeclaratorChunk::@340323374315200305336204205154073066142310370142 Kind
Expr * Value
The value of the dictionary element.
bool isPackExpansion() const
Determines whether this dictionary element is a pack expansion.
Expr * Key
The key for the dictionary element.