@@ -101,7 +101,7 @@ class ElaboratedTypePolicyRAII {
101101 SuppressTagKeyword = Policy.SuppressTagKeyword ;
102102 SuppressScope = Policy.SuppressScope ;
103103 Policy.SuppressTagKeyword = true ;
104- Policy.SuppressScope = true ;
104+ Policy.SuppressScope = !Policy. EnforceScopeForElaboratedTypes ;
105105 }
106106
107107 ~ElaboratedTypePolicyRAII () {
@@ -1728,8 +1728,10 @@ void TypePrinter::printElaboratedBefore(const ElaboratedType *T,
17281728 Policy.SuppressScope = OldSupressScope;
17291729 return ;
17301730 }
1731- if (Qualifier && !(Policy.SuppressTypedefs &&
1732- T->getNamedType ()->getTypeClass () == Type::Typedef))
1731+ if (Qualifier &&
1732+ !(Policy.SuppressTypedefs &&
1733+ T->getNamedType ()->getTypeClass () == Type::Typedef) &&
1734+ !Policy.EnforceScopeForElaboratedTypes )
17331735 Qualifier->print (OS, Policy);
17341736 }
17351737
@@ -2220,15 +2222,6 @@ static void printArgument(const TemplateArgument &A, const PrintingPolicy &PP,
22202222 A.print (PP, OS, IncludeType);
22212223}
22222224
2223- static void printArgument (const TemplateArgumentLoc &A,
2224- const PrintingPolicy &PP, llvm::raw_ostream &OS,
2225- bool IncludeType) {
2226- const TemplateArgument::ArgKind &Kind = A.getArgument ().getKind ();
2227- if (Kind == TemplateArgument::ArgKind::Type)
2228- return A.getTypeSourceInfo ()->getType ().print (OS, PP);
2229- return A.getArgument ().print (PP, OS, IncludeType);
2230- }
2231-
22322225static bool isSubstitutedTemplateArgument (ASTContext &Ctx, TemplateArgument Arg,
22332226 TemplateArgument Pattern,
22342227 ArrayRef<TemplateArgument> Args,
@@ -2399,15 +2392,40 @@ template <typename TA>
23992392static void
24002393printTo (raw_ostream &OS, ArrayRef<TA> Args, const PrintingPolicy &Policy,
24012394 const TemplateParameterList *TPL, bool IsPack, unsigned ParmIndex) {
2402- // Drop trailing template arguments that match default arguments.
2403- if (TPL && Policy.SuppressDefaultTemplateArgs &&
2404- !Policy.PrintCanonicalTypes && !Args.empty () && !IsPack &&
2395+ llvm::SmallVector<TemplateArgument, 8 > ArgsToPrint;
2396+ for (const TA &A : Args)
2397+ ArgsToPrint.push_back (getArgument (A));
2398+ if (TPL && !Policy.PrintCanonicalTypes && !IsPack &&
24052399 Args.size () <= TPL->size ()) {
2406- llvm::SmallVector<TemplateArgument, 8 > OrigArgs;
2407- for (const TA &A : Args)
2408- OrigArgs.push_back (getArgument (A));
2409- while (!Args.empty () && getArgument (Args.back ()).getIsDefaulted ())
2410- Args = Args.drop_back ();
2400+ // Drop trailing template arguments that match default arguments.
2401+ if (Policy.SuppressDefaultTemplateArgs ) {
2402+ while (!ArgsToPrint.empty () &&
2403+ getArgument (ArgsToPrint.back ()).getIsDefaulted ())
2404+ ArgsToPrint.pop_back ();
2405+ } else if (Policy.EnforceDefaultTemplateArgs ) {
2406+ for (unsigned I = Args.size (); I < TPL->size (); ++I) {
2407+ auto Param = TPL->getParam (I);
2408+ if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Param)) {
2409+ // If we met a non default-argument past provided list of arguments,
2410+ // it is either a pack which must be the last arguments, or provided
2411+ // argument list was problematic. Bail out either way. Do the same
2412+ // for each kind of template argument.
2413+ if (!TTPD->hasDefaultArgument ())
2414+ break ;
2415+ ArgsToPrint.push_back (getArgument (TTPD->getDefaultArgument ()));
2416+ } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Param)) {
2417+ if (!TTPD->hasDefaultArgument ())
2418+ break ;
2419+ ArgsToPrint.push_back (getArgument (TTPD->getDefaultArgument ()));
2420+ } else if (auto *NTTPD = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
2421+ if (!NTTPD->hasDefaultArgument ())
2422+ break ;
2423+ ArgsToPrint.push_back (getArgument (NTTPD->getDefaultArgument ()));
2424+ } else {
2425+ llvm_unreachable (" unexpected template parameter" );
2426+ }
2427+ }
2428+ }
24112429 }
24122430
24132431 const char *Comma = Policy.MSVCFormatting ? " ," : " , " ;
@@ -2416,7 +2434,7 @@ printTo(raw_ostream &OS, ArrayRef<TA> Args, const PrintingPolicy &Policy,
24162434
24172435 bool NeedSpace = false ;
24182436 bool FirstArg = true ;
2419- for (const auto &Arg : Args ) {
2437+ for (const auto &Arg : ArgsToPrint ) {
24202438 // Print the argument into a string.
24212439 SmallString<128 > Buf;
24222440 llvm::raw_svector_ostream ArgOS (Buf);
0 commit comments