diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -2078,6 +2078,23 @@ return false; } +template +static ArrayRef dropDefaultedArguments(ArrayRef Args, + const PrintingPolicy &Policy, + const TemplateParameterList *TPL) { + ASTContext &Ctx = TPL->getParam(0)->getASTContext(); + llvm::SmallVector OrigArgs; + for (const TA &A : Args) + OrigArgs.push_back(getArgument(A)); + while (!Args.empty() && + isSubstitutedDefaultArgument(Ctx, getArgument(Args.back()), + TPL->getParam(Args.size() - 1), OrigArgs, + TPL->getDepth())) + Args = Args.drop_back(); + + return Args; +} + template static void printTo(raw_ostream &OS, ArrayRef Args, const PrintingPolicy &Policy, @@ -2086,15 +2103,7 @@ if (TPL && Policy.SuppressDefaultTemplateArgs && !Policy.PrintCanonicalTypes && !Args.empty() && !IsPack && Args.size() <= TPL->size()) { - ASTContext &Ctx = TPL->getParam(0)->getASTContext(); - llvm::SmallVector OrigArgs; - for (const TA &A : Args) - OrigArgs.push_back(getArgument(A)); - while (!Args.empty() && - isSubstitutedDefaultArgument(Ctx, getArgument(Args.back()), - TPL->getParam(Args.size() - 1), - OrigArgs, TPL->getDepth())) - Args = Args.drop_back(); + Args = dropDefaultedArguments(Args, Policy, TPL); } const char *Comma = Policy.MSVCFormatting ? "," : ", ";