@@ -4210,7 +4210,7 @@ class PackExpansionExpr : public Expr {
4210
4210
4211
4211
public:
4212
4212
PackExpansionExpr (QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
4213
- std::optional< unsigned > NumExpansions)
4213
+ UnsignedOrNone NumExpansions)
4214
4214
: Expr(PackExpansionExprClass, T, Pattern->getValueKind (),
4215
4215
Pattern->getObjectKind()),
4216
4216
EllipsisLoc(EllipsisLoc),
@@ -4233,7 +4233,7 @@ class PackExpansionExpr : public Expr {
4233
4233
4234
4234
// / Determine the number of expansions that will be produced when
4235
4235
// / this pack expansion is instantiated, if already known.
4236
- std::optional< unsigned > getNumExpansions () const {
4236
+ UnsignedOrNone getNumExpansions () const {
4237
4237
if (NumExpansions)
4238
4238
return NumExpansions - 1 ;
4239
4239
@@ -4304,8 +4304,7 @@ class SizeOfPackExpr final
4304
4304
// / the given parameter pack.
4305
4305
SizeOfPackExpr (QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
4306
4306
SourceLocation PackLoc, SourceLocation RParenLoc,
4307
- std::optional<unsigned > Length,
4308
- ArrayRef<TemplateArgument> PartialArgs)
4307
+ UnsignedOrNone Length, ArrayRef<TemplateArgument> PartialArgs)
4309
4308
: Expr(SizeOfPackExprClass, SizeType, VK_PRValue, OK_Ordinary),
4310
4309
OperatorLoc (OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
4311
4310
Length(Length ? *Length : PartialArgs.size()), Pack(Pack) {
@@ -4325,7 +4324,7 @@ class SizeOfPackExpr final
4325
4324
static SizeOfPackExpr *Create (ASTContext &Context, SourceLocation OperatorLoc,
4326
4325
NamedDecl *Pack, SourceLocation PackLoc,
4327
4326
SourceLocation RParenLoc,
4328
- std::optional< unsigned > Length = std::nullopt,
4327
+ UnsignedOrNone Length = std::nullopt,
4329
4328
ArrayRef<TemplateArgument> PartialArgs = {});
4330
4329
static SizeOfPackExpr *CreateDeserialized (ASTContext &Context,
4331
4330
unsigned NumPartialArgs);
@@ -4467,7 +4466,7 @@ class PackIndexingExpr final
4467
4466
4468
4467
Expr *getIndexExpr () const { return cast<Expr>(SubExprs[1 ]); }
4469
4468
4470
- std::optional< unsigned > getSelectedIndex () const {
4469
+ UnsignedOrNone getSelectedIndex () const {
4471
4470
if (isInstantiationDependent ())
4472
4471
return std::nullopt;
4473
4472
ConstantExpr *CE = cast<ConstantExpr>(getIndexExpr ());
@@ -4477,7 +4476,7 @@ class PackIndexingExpr final
4477
4476
}
4478
4477
4479
4478
Expr *getSelectedExpr () const {
4480
- std::optional< unsigned > Index = getSelectedIndex ();
4479
+ UnsignedOrNone Index = getSelectedIndex ();
4481
4480
assert (Index && " extracting the indexed expression of a dependant pack" );
4482
4481
return getTrailingObjects<Expr *>()[*Index];
4483
4482
}
@@ -4525,12 +4524,12 @@ class SubstNonTypeTemplateParmExpr : public Expr {
4525
4524
SubstNonTypeTemplateParmExpr (QualType Ty, ExprValueKind ValueKind,
4526
4525
SourceLocation Loc, Expr *Replacement,
4527
4526
Decl *AssociatedDecl, unsigned Index,
4528
- std::optional< unsigned > PackIndex, bool RefParam,
4527
+ UnsignedOrNone PackIndex, bool RefParam,
4529
4528
bool Final)
4530
4529
: Expr(SubstNonTypeTemplateParmExprClass, Ty, ValueKind, OK_Ordinary),
4531
4530
Replacement (Replacement),
4532
4531
AssociatedDeclAndRef(AssociatedDecl, RefParam), Index(Index),
4533
- PackIndex(PackIndex ? *PackIndex + 1 : 0 ), Final(Final) {
4532
+ PackIndex(PackIndex.toInternalRepresentation() ), Final(Final) {
4534
4533
assert (AssociatedDecl != nullptr );
4535
4534
SubstNonTypeTemplateParmExprBits.NameLoc = Loc;
4536
4535
setDependence (computeDependence (this ));
@@ -4552,10 +4551,8 @@ class SubstNonTypeTemplateParmExpr : public Expr {
4552
4551
// / This should match the result of `getParameter()->getIndex()`.
4553
4552
unsigned getIndex () const { return Index; }
4554
4553
4555
- std::optional<unsigned > getPackIndex () const {
4556
- if (PackIndex == 0 )
4557
- return std::nullopt;
4558
- return PackIndex - 1 ;
4554
+ UnsignedOrNone getPackIndex () const {
4555
+ return UnsignedOrNone::fromInternalRepresentation (PackIndex);
4559
4556
}
4560
4557
4561
4558
// This substitution is Final, which means the substitution is fully
@@ -4882,15 +4879,15 @@ class CXXFoldExpr : public Expr {
4882
4879
SourceLocation RParenLoc;
4883
4880
// When 0, the number of expansions is not known. Otherwise, this is one more
4884
4881
// than the number of expansions.
4885
- unsigned NumExpansions;
4882
+ UnsignedOrNone NumExpansions = std::nullopt ;
4886
4883
Stmt *SubExprs[SubExpr::Count];
4887
4884
BinaryOperatorKind Opcode;
4888
4885
4889
4886
public:
4890
4887
CXXFoldExpr (QualType T, UnresolvedLookupExpr *Callee,
4891
4888
SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Opcode,
4892
4889
SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc,
4893
- std::optional< unsigned > NumExpansions);
4890
+ UnsignedOrNone NumExpansions);
4894
4891
4895
4892
CXXFoldExpr (EmptyShell Empty) : Expr(CXXFoldExprClass, Empty) {}
4896
4893
@@ -4919,11 +4916,7 @@ class CXXFoldExpr : public Expr {
4919
4916
SourceLocation getEllipsisLoc () const { return EllipsisLoc; }
4920
4917
BinaryOperatorKind getOperator () const { return Opcode; }
4921
4918
4922
- std::optional<unsigned > getNumExpansions () const {
4923
- if (NumExpansions)
4924
- return NumExpansions - 1 ;
4925
- return std::nullopt;
4926
- }
4919
+ UnsignedOrNone getNumExpansions () const { return NumExpansions; }
4927
4920
4928
4921
SourceLocation getBeginLoc () const LLVM_READONLY {
4929
4922
if (LParenLoc.isValid ())
0 commit comments