@@ -3660,6 +3660,9 @@ class TreeTransform {
3660
3660
return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
3661
3661
}
3662
3662
3663
+ std::optional<unsigned>
3664
+ ComputeSizeOfPackExprWithoutSubstitution(ArrayRef<TemplateArgument> PackArgs);
3665
+
3663
3666
/// Build a new expression to compute the length of a parameter pack.
3664
3667
ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
3665
3668
SourceLocation PackLoc,
@@ -15877,6 +15880,49 @@ TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
15877
15880
E->getNumExpansions());
15878
15881
}
15879
15882
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
+
15880
15926
template<typename Derived>
15881
15927
ExprResult
15882
15928
TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
@@ -15942,42 +15988,8 @@ TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
15942
15988
}
15943
15989
15944
15990
// 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);
15981
15993
15982
15994
// Common case: we could determine the number of expansions without
15983
15995
// substituting.
0 commit comments