@@ -3660,6 +3660,9 @@ class TreeTransform {
36603660 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
36613661 }
36623662
3663+ std::optional<unsigned>
3664+ ComputeSizeOfPackExprWithoutSubstitution(ArrayRef<TemplateArgument> PackArgs);
3665+
36633666 /// Build a new expression to compute the length of a parameter pack.
36643667 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
36653668 SourceLocation PackLoc,
@@ -15877,6 +15880,49 @@ TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
1587715880 E->getNumExpansions());
1587815881}
1587915882
15883+ template <typename Derived>
15884+ std::optional<unsigned>
15885+ TreeTransform<Derived>::ComputeSizeOfPackExprWithoutSubstitution(
15886+ ArrayRef<TemplateArgument> PackArgs) {
15887+ std::optional<unsigned> Result = 0;
15888+ for (const TemplateArgument &Arg : PackArgs) {
15889+ if (!Arg.isPackExpansion()) {
15890+ Result = *Result + 1;
15891+ continue;
15892+ }
15893+
15894+ TemplateArgumentLoc ArgLoc;
15895+ InventTemplateArgumentLoc(Arg, ArgLoc);
15896+
15897+ // Find the pattern of the pack expansion.
15898+ SourceLocation Ellipsis;
15899+ std::optional<unsigned> OrigNumExpansions;
15900+ TemplateArgumentLoc Pattern =
15901+ getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
15902+ OrigNumExpansions);
15903+
15904+ // Substitute under the pack expansion. Do not expand the pack (yet).
15905+ TemplateArgumentLoc OutPattern;
15906+ Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
15907+ if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
15908+ /*Uneval*/ true))
15909+ return true;
15910+
15911+ // See if we can determine the number of arguments from the result.
15912+ std::optional<unsigned> NumExpansions =
15913+ getSema().getFullyPackExpandedSize(OutPattern.getArgument());
15914+ if (!NumExpansions) {
15915+ // No: we must be in an alias template expansion, and we're going to
15916+ // need to actually expand the packs.
15917+ Result = std::nullopt;
15918+ break;
15919+ }
15920+
15921+ Result = *Result + *NumExpansions;
15922+ }
15923+ return Result;
15924+ }
15925+
1588015926template<typename Derived>
1588115927ExprResult
1588215928TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
@@ -15942,42 +15988,8 @@ TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
1594215988 }
1594315989
1594415990 // Try to compute the result without performing a partial substitution.
15945- std::optional<unsigned> Result = 0;
15946- for (const TemplateArgument &Arg : PackArgs) {
15947- if (!Arg.isPackExpansion()) {
15948- Result = *Result + 1;
15949- continue;
15950- }
15951-
15952- TemplateArgumentLoc ArgLoc;
15953- InventTemplateArgumentLoc(Arg, ArgLoc);
15954-
15955- // Find the pattern of the pack expansion.
15956- SourceLocation Ellipsis;
15957- std::optional<unsigned> OrigNumExpansions;
15958- TemplateArgumentLoc Pattern =
15959- getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
15960- OrigNumExpansions);
15961-
15962- // Substitute under the pack expansion. Do not expand the pack (yet).
15963- TemplateArgumentLoc OutPattern;
15964- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
15965- if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
15966- /*Uneval*/ true))
15967- return true;
15968-
15969- // See if we can determine the number of arguments from the result.
15970- std::optional<unsigned> NumExpansions =
15971- getSema().getFullyPackExpandedSize(OutPattern.getArgument());
15972- if (!NumExpansions) {
15973- // No: we must be in an alias template expansion, and we're going to need
15974- // to actually expand the packs.
15975- Result = std::nullopt;
15976- break;
15977- }
15978-
15979- Result = *Result + *NumExpansions;
15980- }
15991+ std::optional<unsigned> Result =
15992+ getDerived().ComputeSizeOfPackExprWithoutSubstitution(PackArgs);
1598115993
1598215994 // Common case: we could determine the number of expansions without
1598315995 // substituting.
0 commit comments