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 if (
auto *TTP = dyn_cast_or_null<TemplateTemplateParmDecl>(
149 if (TTP->isParameterPack())
154 ContainsIntermediatePacks |=
162 TraverseTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc
T,
163 bool TraverseQualifier)
override {
164 if (TryTraverseSpecializationProducingPacks(
T.getTypePtr(),
167 return DynamicRecursiveASTVisitor::TraverseTemplateSpecializationTypeLoc(
168 T, TraverseQualifier);
171 bool TraverseTemplateSpecializationType(TemplateSpecializationType *
T,
172 bool TraverseQualfier)
override {
173 if (TryTraverseSpecializationProducingPacks(
T, SourceLocation()))
175 return DynamicRecursiveASTVisitor::TraverseTemplateSpecializationType(
T);
180 bool TraverseObjCDictionaryLiteral(ObjCDictionaryLiteral *E)
override {
189 TraverseStmt(Element.
Key);
190 TraverseStmt(Element.
Value);
200 bool TraverseStmt(Stmt *S)
override {
201 Expr *E = dyn_cast_or_null<Expr>(S);
210 bool TraverseType(QualType
T,
bool TraverseQualifier =
true)
override {
220 bool TraverseTypeLoc(TypeLoc TL,
bool TraverseQualifier =
true)
override {
231 bool TraverseDecl(Decl *D)
override {
242 bool TraverseAttr(Attr *A)
override {
251 bool TraversePackExpansionType(PackExpansionType *
T,
252 bool TraverseQualifier)
override {
255 bool TraversePackExpansionTypeLoc(PackExpansionTypeLoc TL,
256 bool TraverseQualifier)
override {
259 bool TraversePackExpansionExpr(PackExpansionExpr *E)
override {
262 bool TraverseCXXFoldExpr(CXXFoldExpr *E)
override {
return true; }
263 bool TraversePackIndexingExpr(PackIndexingExpr *E)
override {
266 bool TraversePackIndexingType(PackIndexingType *E,
267 bool TraverseQualifier)
override {
270 bool TraversePackIndexingTypeLoc(PackIndexingTypeLoc TL,
271 bool TraverseQualifier)
override {
279 TraverseUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D)
override {
283 return DynamicRecursiveASTVisitor::TraverseUnresolvedUsingValueDecl(D);
287 bool TraverseUnresolvedUsingTypenameDecl(
288 UnresolvedUsingTypenameDecl *D)
override {
292 return DynamicRecursiveASTVisitor::TraverseUnresolvedUsingTypenameDecl(D);
296 bool TraverseTemplateArgument(
const TemplateArgument &Arg)
override {
305 TraverseTemplateArgumentLoc(
const TemplateArgumentLoc &ArgLoc)
override {
313 bool TraverseCXXBaseSpecifier(
const CXXBaseSpecifier &Base)
override {
314 if (
Base.isPackExpansion())
321 bool TraverseConstructorInitializer(CXXCtorInitializer *
Init)
override {
322 if (
Init->isPackExpansion())
333 bool TraverseLambdaExpr(
LambdaExpr *Lambda)
override {
339 SaveAndRestore _(InLambdaOrBlock,
true);
340 unsigned OldDepthLimit = DepthLimit;
343 DepthLimit = TPL->getDepth();
345 DynamicRecursiveASTVisitor::TraverseLambdaExpr(Lambda);
347 DepthLimit = OldDepthLimit;
352 bool TraverseBlockExpr(BlockExpr *
Block)
override {
353 if (!
Block->containsUnexpandedParameterPack())
356 SaveAndRestore _(InLambdaOrBlock,
true);
357 DynamicRecursiveASTVisitor::TraverseBlockExpr(
Block);
362 bool TraverseLambdaCapture(
LambdaExpr *Lambda,
const LambdaCapture *
C,
363 Expr *
Init)
override {
364 if (
C->isPackExpansion())
370 bool TraverseUnresolvedLookupExpr(UnresolvedLookupExpr *E)
override {
373 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND);
374 TTP && TTP->isParameterPack())
377 return DynamicRecursiveASTVisitor::TraverseUnresolvedLookupExpr(E);
380 bool TraverseSubstBuiltinTemplatePackType(SubstBuiltinTemplatePackType *
T,
381 bool TraverseQualifier)
override {
389 bool TraverseFunctionParmPackExpr(FunctionParmPackExpr *)
override {
390 ContainsIntermediatePacks =
true;
394 bool TraverseSubstNonTypeTemplateParmPackExpr(
395 SubstNonTypeTemplateParmPackExpr *)
override {
396 ContainsIntermediatePacks =
true;
400 bool VisitSubstTemplateTypeParmPackType(
401 SubstTemplateTypeParmPackType *)
override {
402 ContainsIntermediatePacks =
true;
406 bool VisitSubstTemplateTypeParmPackTypeLoc(
407 SubstTemplateTypeParmPackTypeLoc)
override {
408 ContainsIntermediatePacks =
true;
412 bool containsIntermediatePacks()
const {
return ContainsIntermediatePacks; }
437 if (Unexpanded.empty())
447 for (
auto &Pack : Unexpanded) {
448 auto DeclaresThisPack = [&](
NamedDecl *LocalPack) {
449 if (
auto *TTPT = Pack.first.dyn_cast<
const TemplateTypeParmType *>()) {
450 auto *TTPD = dyn_cast<TemplateTypeParmDecl>(LocalPack);
451 return TTPD && TTPD->getTypeForDecl() == TTPT;
455 if (llvm::any_of(CSI->LocalPacks, DeclaresThisPack))
456 ParamPackReferences.push_back(Pack);
459 if (ParamPackReferences.empty()) {
471 bool EnclosingStmtExpr =
false;
475 Func->CompoundScopes,
477 EnclosingStmtExpr =
true;
486 if (!EnclosingStmtExpr) {
487 CSI->ContainsUnexpandedParameterPack =
true;
491 Unexpanded = ParamPackReferences;
499 for (
unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
501 if (
const TemplateTypeParmType *TTP
502 = Unexpanded[I].first.dyn_cast<
const TemplateTypeParmType *>())
503 Name = TTP->getIdentifier();
507 if (Name && NamesKnown.insert(Name).second)
508 Names.push_back(Name);
510 if (Unexpanded[I].second.isValid())
511 Locations.push_back(Unexpanded[I].second);
514 auto DB =
Diag(Loc, diag::err_unexpanded_parameter_pack)
515 << (int)UPPC << (
int)Names.size();
516 for (
size_t I = 0, E = std::min(Names.size(), (
size_t)2); I != E; ++I)
519 for (
unsigned I = 0, N = Locations.size(); I != N; ++I)
530 if (!
T->getType()->containsUnexpandedParameterPack())
534 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(
536 assert(!Unexpanded.empty() &&
"Unable to find unexpanded parameter packs");
549 CollectUnexpandedParameterPacksVisitor Visitor(Unexpanded);
550 Visitor.TraverseStmt(E);
557 bool LambdaReferencingOuterPacks =
559 assert((!Unexpanded.empty() || LambdaReferencingOuterPacks) &&
560 "Unable to find unexpanded parameter packs");
570 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(RE);
571 assert(!Unexpanded.empty() &&
"Unable to find unexpanded parameter packs");
578 for (
auto Parm : Unexpanded)
579 if (ParmSet.contains(Parm.first.dyn_cast<
NamedDecl *>()))
580 UnexpandedParms.push_back(Parm);
581 if (UnexpandedParms.empty())
597 CollectUnexpandedParameterPacksVisitor(Unexpanded)
599 assert(!Unexpanded.empty() &&
"Unable to find unexpanded parameter packs");
634 CollectUnexpandedParameterPacksVisitor(Unexpanded)
636 assert(!Unexpanded.empty() &&
"Unable to find unexpanded parameter packs");
648 CollectUnexpandedParameterPacksVisitor(Unexpanded)
650 assert(!Unexpanded.empty() &&
"Unable to find unexpanded parameter packs");
661 CollectUnexpandedParameterPacksVisitor(Unexpanded)
662 .TraverseTemplateArgumentLoc(Arg);
663 assert(!Unexpanded.empty() &&
"Unable to find unexpanded parameter packs");
669 CollectUnexpandedParameterPacksVisitor(Unexpanded)
670 .TraverseTemplateArgument(Arg);
675 CollectUnexpandedParameterPacksVisitor(Unexpanded)
676 .TraverseTemplateArgumentLoc(Arg);
681 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(
T);
686 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(TL);
692 CollectUnexpandedParameterPacksVisitor(Unexpanded)
693 .TraverseNestedNameSpecifierLoc(NNS);
699 CollectUnexpandedParameterPacksVisitor(Unexpanded)
700 .TraverseDeclarationNameInfo(NameInfo);
705 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(E);
716 auto *
T = dyn_cast_or_null<BuiltinTemplateDecl>(
718 if (
T &&
T->isPackProducingBuiltinTemplate())
755 Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
762 llvm_unreachable(
"Unhandled template argument kind?");
786 EllipsisLoc, NumExpansions);
810 Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
815 return Context.getPackExpansionType(Pattern, NumExpansions,
833 Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
846 bool FailOnPackProducingTemplates,
bool &ShouldExpand,
849 RetainExpansion =
false;
851 bool HaveFirstPack =
false;
858 unsigned Depth = 0, Index = 0;
860 bool IsVarDeclPack =
false;
862 std::optional<unsigned> NumPrecomputedArguments;
864 if (
auto *TTP = ParmPack.first.dyn_cast<
const TemplateTypeParmType *>()) {
865 Depth = TTP->getDepth();
866 Index = TTP->getIndex();
867 Name = TTP->getIdentifier();
868 }
else if (
auto *TST =
870 .dyn_cast<
const TemplateSpecializationType *>()) {
873 ShouldExpand =
false;
874 if (!FailOnPackProducingTemplates)
883 diag::err_unsupported_builtin_template_pack_expansion)
884 << TST->getTemplateName();
887 .dyn_cast<
const SubstBuiltinTemplatePackType *>()) {
889 NumPrecomputedArguments = S->getNumArgs();
893 IsVarDeclPack =
true;
896 llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation =
900 BindingPack = cast_if_present<FunctionParmPackExpr>(BindingExpr);
902 ShouldExpand =
false;
912 unsigned NewPackSize, PendingPackExpansionSize = 0;
915 llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation =
924 ShouldExpand =
false;
927 }
else if (BindingPack) {
929 }
else if (NumPrecomputedArguments) {
930 NewPackSize = *NumPrecomputedArguments;
937 ShouldExpand =
false;
943 TemplateArgs(Depth, Index).getPackAsArray();
944 NewPackSize = Pack.size();
945 PendingPackExpansionSize =
952 ->
castAs<PackExpansionType>()
953 ->getNumExpansions();
957 ->getNumExpansions();
970 unsigned PartialDepth, PartialIndex;
972 if (PartialDepth == Depth && PartialIndex == Index) {
973 RetainExpansion =
true;
975 NumPartialExpansions = NewPackSize;
976 PartiallySubstitutedPackLoc = ParmPack.second;
982 if (!NumExpansions) {
985 NumExpansions = NewPackSize;
987 HaveFirstPack =
true;
991 if (NewPackSize != *NumExpansions) {
1013 unsigned LeastNewPackSize = NewPackSize - PendingPackExpansionSize;
1014 if (PendingPackExpansionSize && LeastNewPackSize <= *NumExpansions) {
1015 ShouldExpand =
false;
1023 else if (HaveFirstPack)
1024 Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict)
1026 << (LeastNewPackSize != NewPackSize) << LeastNewPackSize
1029 Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_multilevel)
1030 << Name << *NumExpansions << (LeastNewPackSize != NewPackSize)
1031 << LeastNewPackSize <<
SourceRange(ParmPack.second);
1045 if (NumPartialExpansions) {
1046 if (NumExpansions && *NumExpansions < *NumPartialExpansions) {
1051 Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_partial)
1052 << PartialPack << *NumPartialExpansions << *NumExpansions
1057 NumExpansions = NumPartialExpansions;
1067 for (
unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
1072 if (
const TemplateTypeParmType *TTP =
1073 Unexpanded[I].first.dyn_cast<
const TemplateTypeParmType *>()) {
1074 Depth = TTP->getDepth();
1075 Index = TTP->getIndex();
1076 }
else if (
auto *TST =
1078 .first.dyn_cast<
const TemplateSpecializationType *>()) {
1082 return std::nullopt;
1083 }
else if (
auto *PST =
1086 .dyn_cast<const SubstBuiltinTemplatePackType *>()) {
1088 "inconsistent pack sizes");
1089 Result = PST->getNumArgs();
1097 llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation =
1103 return std::nullopt;
1106 assert((!
Result || *
Result == Size) &&
"inconsistent pack sizes");
1117 return std::nullopt;
1120 unsigned Size = TemplateArgs(Depth, Index).pack_size();
1121 assert((!
Result || *
Result == Size) &&
"inconsistent pack sizes");
1132 CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(Pattern);
1143#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case TST_##Trait:
1144#include "clang/Basic/TransformTypeTraits.def"
1147 if (!
T.isNull() &&
T->containsUnexpandedParameterPack())
1191#define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t:
1192#include "clang/Basic/OpenCLImageTypes.def"
1193#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case TST_##Name:
1194#include "clang/Basic/HLSLIntangibleTypes.def"
1202 switch (Chunk.
Kind) {
1217 for (
unsigned i = 0, e = Chunk.
Fun.
NumParams; i != e; ++i) {
1219 QualType ParamTy = Param->getType();
1220 assert(!ParamTy.
isNull() &&
"Couldn't parse type?");
1237 if (!
T.isNull() &&
T->containsUnexpandedParameterPack())
1250 if (TRC->containsUnexpandedParameterPack())
1261 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
1266 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
1267 return std::make_unique<ParameterPackValidatorCCC>(*
this);
1291 ParameterPackValidatorCCC CCC{};
1296 PDiag(diag::err_sizeof_pack_no_pack_name_suggest) << &Name,
1297 PDiag(diag::note_parameter_pack_here));
1298 ParameterPack = Corrected.getCorrectionDecl();
1312 Diag(NameLoc, diag::err_expected_name_of_pack) << &Name;
1323 if (
auto *D = dyn_cast<DeclRefExpr>(PackExpression); D) {
1346 ? diag::warn_cxx23_pack_indexing
1347 : diag::ext_pack_indexing);
1356 bool FullySubstituted) {
1358 std::optional<int64_t> Index;
1366 Index =
Value.getExtValue();
1367 IndexExpr = Res.
get();
1370 if (Index && FullySubstituted) {
1371 if (*Index < 0 || *Index >= int64_t(ExpandedExprs.size())) {
1372 Diag(PackExpression->
getBeginLoc(), diag::err_pack_index_out_of_bound)
1373 << *Index << PackExpression << ExpandedExprs.size();
1379 PackExpression, IndexExpr, Index,
1380 ExpandedExprs, FullySubstituted);
1393 if (!ExpansionTSInfo)
1401 NumExpansions = Expansion.
getTypePtr()->getNumExpansions();
1441 llvm_unreachable(
"Invalid TemplateArgument Kind!");
1455 if (
auto *Subst = Arg.
getAsType()->
getAs<SubstTemplateTypeParmPackType>())
1456 Pack = Subst->getArgumentPack();
1458 return std::nullopt;
1463 dyn_cast<SubstNonTypeTemplateParmPackExpr>(Arg.
getAsExpr()))
1464 Pack = Subst->getArgumentPack();
1465 else if (
auto *Subst = dyn_cast<FunctionParmPackExpr>(Arg.
getAsExpr())) {
1467 if (PD->isParameterPack())
1468 return std::nullopt;
1469 return Subst->getNumExpansions();
1471 return std::nullopt;
1477 Pack = Subst->getArgumentPack();
1479 return std::nullopt;
1489 return std::nullopt;
1496 if (Elem.isPackExpansion())
1497 return std::nullopt;
1507 if (Elem.containsUnexpandedParameterPack())
1508 return std::nullopt;
1518 auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
1545 return Diag(EllipsisLoc,
1547 ? diag::err_fold_expression_packs_both_sides
1548 : diag::err_pack_expansion_without_parameter_packs)
1556 Expr *Pack = LHS ? LHS : RHS;
1557 assert(Pack &&
"fold expression with neither LHS nor RHS");
1559 return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
1571 if (!Functions.
empty()) {
1577 if (Callee.isInvalid())
1583 return BuildCXXFoldExpr(ULE, LParenLoc, LHS, Opc, EllipsisLoc, RHS, RParenLoc,
1595 EllipsisLoc, RHS, RParenLoc, NumExpansions);
1620 return Diag(EllipsisLoc, diag::err_fold_expression_empty)
1625 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 TraverseStmt(MaybeConst< Stmt > *S)
virtual bool TraverseAttr(MaybeConst< Attr > *At)
virtual bool TraverseLambdaCapture(MaybeConst< LambdaExpr > *LE, const LambdaCapture *C, MaybeConst< Expr > *Init)
virtual bool TraverseTemplateName(TemplateName Template)
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.
NamedDecl * getFoundDecl() const
Fetch the unique decl found by this lookup.
Sema::LookupNameKind getLookupKind() const
Gets the kind of lookup to perform.
LookupResultKind getResultKind() const
const DeclarationNameInfo & getLookupNameInfo() const
Gets the name info to look up.
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 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...
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...
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.
void setBegin(SourceLocation b)
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 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.
The JSON file list parser is used to communicate input to InstallAPI.
@ 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.
const FunctionProtoType * T
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
@ Template
We are parsing a template declaration.
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
DynamicRecursiveASTVisitorBase< false > DynamicRecursiveASTVisitor
U cast(CodeGen::Address addr)
@ ArrayBound
Array bound in array declarator or new-expression.
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
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
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.
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.