@@ -4210,7 +4210,7 @@ class PackExpansionExpr : public Expr {
42104210
42114211public:
42124212 PackExpansionExpr (QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
4213- std::optional< unsigned > NumExpansions)
4213+ UnsignedOrNone NumExpansions)
42144214 : Expr(PackExpansionExprClass, T, Pattern->getValueKind (),
42154215 Pattern->getObjectKind()),
42164216 EllipsisLoc(EllipsisLoc),
@@ -4233,7 +4233,7 @@ class PackExpansionExpr : public Expr {
42334233
42344234 // / Determine the number of expansions that will be produced when
42354235 // / this pack expansion is instantiated, if already known.
4236- std::optional< unsigned > getNumExpansions () const {
4236+ UnsignedOrNone getNumExpansions () const {
42374237 if (NumExpansions)
42384238 return NumExpansions - 1 ;
42394239
@@ -4304,8 +4304,7 @@ class SizeOfPackExpr final
43044304 // / the given parameter pack.
43054305 SizeOfPackExpr (QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
43064306 SourceLocation PackLoc, SourceLocation RParenLoc,
4307- std::optional<unsigned > Length,
4308- ArrayRef<TemplateArgument> PartialArgs)
4307+ UnsignedOrNone Length, ArrayRef<TemplateArgument> PartialArgs)
43094308 : Expr(SizeOfPackExprClass, SizeType, VK_PRValue, OK_Ordinary),
43104309 OperatorLoc (OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
43114310 Length(Length ? *Length : PartialArgs.size()), Pack(Pack) {
@@ -4325,7 +4324,7 @@ class SizeOfPackExpr final
43254324 static SizeOfPackExpr *Create (ASTContext &Context, SourceLocation OperatorLoc,
43264325 NamedDecl *Pack, SourceLocation PackLoc,
43274326 SourceLocation RParenLoc,
4328- std::optional< unsigned > Length = std::nullopt ,
4327+ UnsignedOrNone Length = std::nullopt ,
43294328 ArrayRef<TemplateArgument> PartialArgs = {});
43304329 static SizeOfPackExpr *CreateDeserialized (ASTContext &Context,
43314330 unsigned NumPartialArgs);
@@ -4467,7 +4466,7 @@ class PackIndexingExpr final
44674466
44684467 Expr *getIndexExpr () const { return cast<Expr>(SubExprs[1 ]); }
44694468
4470- std::optional< unsigned > getSelectedIndex () const {
4469+ UnsignedOrNone getSelectedIndex () const {
44714470 if (isInstantiationDependent ())
44724471 return std::nullopt ;
44734472 ConstantExpr *CE = cast<ConstantExpr>(getIndexExpr ());
@@ -4477,7 +4476,7 @@ class PackIndexingExpr final
44774476 }
44784477
44794478 Expr *getSelectedExpr () const {
4480- std::optional< unsigned > Index = getSelectedIndex ();
4479+ UnsignedOrNone Index = getSelectedIndex ();
44814480 assert (Index && " extracting the indexed expression of a dependant pack" );
44824481 return getTrailingObjects<Expr *>()[*Index];
44834482 }
@@ -4525,12 +4524,12 @@ class SubstNonTypeTemplateParmExpr : public Expr {
45254524 SubstNonTypeTemplateParmExpr (QualType Ty, ExprValueKind ValueKind,
45264525 SourceLocation Loc, Expr *Replacement,
45274526 Decl *AssociatedDecl, unsigned Index,
4528- std::optional< unsigned > PackIndex, bool RefParam,
4527+ UnsignedOrNone PackIndex, bool RefParam,
45294528 bool Final)
45304529 : Expr(SubstNonTypeTemplateParmExprClass, Ty, ValueKind, OK_Ordinary),
45314530 Replacement (Replacement),
45324531 AssociatedDeclAndRef(AssociatedDecl, RefParam), Index(Index),
4533- PackIndex(PackIndex ? *PackIndex + 1 : 0 ), Final(Final) {
4532+ PackIndex(PackIndex.toInternalRepresentation() ), Final(Final) {
45344533 assert (AssociatedDecl != nullptr );
45354534 SubstNonTypeTemplateParmExprBits.NameLoc = Loc;
45364535 setDependence (computeDependence (this ));
@@ -4552,10 +4551,8 @@ class SubstNonTypeTemplateParmExpr : public Expr {
45524551 // / This should match the result of `getParameter()->getIndex()`.
45534552 unsigned getIndex () const { return Index; }
45544553
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);
45594556 }
45604557
45614558 // This substitution is Final, which means the substitution is fully
@@ -4882,15 +4879,15 @@ class CXXFoldExpr : public Expr {
48824879 SourceLocation RParenLoc;
48834880 // When 0, the number of expansions is not known. Otherwise, this is one more
48844881 // than the number of expansions.
4885- unsigned NumExpansions;
4882+ UnsignedOrNone NumExpansions = std:: nullopt ;
48864883 Stmt *SubExprs[SubExpr::Count];
48874884 BinaryOperatorKind Opcode;
48884885
48894886public:
48904887 CXXFoldExpr (QualType T, UnresolvedLookupExpr *Callee,
48914888 SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Opcode,
48924889 SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc,
4893- std::optional< unsigned > NumExpansions);
4890+ UnsignedOrNone NumExpansions);
48944891
48954892 CXXFoldExpr (EmptyShell Empty) : Expr(CXXFoldExprClass, Empty) {}
48964893
@@ -4919,11 +4916,7 @@ class CXXFoldExpr : public Expr {
49194916 SourceLocation getEllipsisLoc () const { return EllipsisLoc; }
49204917 BinaryOperatorKind getOperator () const { return Opcode; }
49214918
4922- std::optional<unsigned > getNumExpansions () const {
4923- if (NumExpansions)
4924- return NumExpansions - 1 ;
4925- return std::nullopt ;
4926- }
4919+ UnsignedOrNone getNumExpansions () const { return NumExpansions; }
49274920
49284921 SourceLocation getBeginLoc () const LLVM_READONLY {
49294922 if (LParenLoc.isValid ())
0 commit comments