@@ -3660,7 +3660,8 @@ class TreeTransform {
36603660 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
36613661 }
36623662
3663- bool HeuristicallyComputeSizeOfPackExpr() const { return true; }
3663+ std::optional<unsigned>
3664+ ComputeSizeOfPackExprWithoutSubstitution(ArrayRef<TemplateArgument> PackArgs);
36643665
36653666 /// Build a new expression to compute the length of a parameter pack.
36663667 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
@@ -16030,6 +16031,49 @@ TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
1603016031 E->getNumExpansions());
1603116032}
1603216033
16034+ template <typename Derived>
16035+ std::optional<unsigned>
16036+ TreeTransform<Derived>::ComputeSizeOfPackExprWithoutSubstitution(
16037+ ArrayRef<TemplateArgument> PackArgs) {
16038+ std::optional<unsigned> Result = 0;
16039+ for (const TemplateArgument &Arg : PackArgs) {
16040+ if (!Arg.isPackExpansion()) {
16041+ Result = *Result + 1;
16042+ continue;
16043+ }
16044+
16045+ TemplateArgumentLoc ArgLoc;
16046+ InventTemplateArgumentLoc(Arg, ArgLoc);
16047+
16048+ // Find the pattern of the pack expansion.
16049+ SourceLocation Ellipsis;
16050+ std::optional<unsigned> OrigNumExpansions;
16051+ TemplateArgumentLoc Pattern =
16052+ getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
16053+ OrigNumExpansions);
16054+
16055+ // Substitute under the pack expansion. Do not expand the pack (yet).
16056+ TemplateArgumentLoc OutPattern;
16057+ Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
16058+ if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
16059+ /*Uneval*/ true))
16060+ return true;
16061+
16062+ // See if we can determine the number of arguments from the result.
16063+ std::optional<unsigned> NumExpansions =
16064+ getSema().getFullyPackExpandedSize(OutPattern.getArgument());
16065+ if (!NumExpansions) {
16066+ // No: we must be in an alias template expansion, and we're going to
16067+ // need to actually expand the packs.
16068+ Result = std::nullopt;
16069+ break;
16070+ }
16071+
16072+ Result = *Result + *NumExpansions;
16073+ }
16074+ return Result;
16075+ }
16076+
1603316077template<typename Derived>
1603416078ExprResult
1603516079TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
@@ -16095,46 +16139,8 @@ TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
1609516139 }
1609616140
1609716141 // Try to compute the result without performing a partial substitution.
16098- std::optional<unsigned> Result = 0;
16099- for (const TemplateArgument &Arg : PackArgs) {
16100- if (!getDerived().HeuristicallyComputeSizeOfPackExpr()) {
16101- Result = std::nullopt;
16102- break;
16103- }
16104- if (!Arg.isPackExpansion()) {
16105- Result = *Result + 1;
16106- continue;
16107- }
16108-
16109- TemplateArgumentLoc ArgLoc;
16110- InventTemplateArgumentLoc(Arg, ArgLoc);
16111-
16112- // Find the pattern of the pack expansion.
16113- SourceLocation Ellipsis;
16114- std::optional<unsigned> OrigNumExpansions;
16115- TemplateArgumentLoc Pattern =
16116- getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
16117- OrigNumExpansions);
16118-
16119- // Substitute under the pack expansion. Do not expand the pack (yet).
16120- TemplateArgumentLoc OutPattern;
16121- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
16122- if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
16123- /*Uneval*/ true))
16124- return true;
16125-
16126- // See if we can determine the number of arguments from the result.
16127- std::optional<unsigned> NumExpansions =
16128- getSema().getFullyPackExpandedSize(OutPattern.getArgument());
16129- if (!NumExpansions) {
16130- // No: we must be in an alias template expansion, and we're going to need
16131- // to actually expand the packs.
16132- Result = std::nullopt;
16133- break;
16134- }
16135-
16136- Result = *Result + *NumExpansions;
16137- }
16142+ std::optional<unsigned> Result =
16143+ getDerived().ComputeSizeOfPackExprWithoutSubstitution(PackArgs);
1613816144
1613916145 // Common case: we could determine the number of expansions without
1614016146 // substituting.
0 commit comments