From: Douglas Gregor Date: Mon, 20 Dec 2010 22:28:59 +0000 (+0000) Subject: Clean up the printing of template argument packs; previously, we were X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dace95b13e2ceb0c3ec8de6babd926dc5114e1e5;p=clang Clean up the printing of template argument packs; previously, we were getting extra "<>" delimiters around template argument packs. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@122280 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index f4898486e7..a2d9a17d31 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -2796,7 +2796,8 @@ public: /// enclosing the template arguments. static std::string PrintTemplateArgumentList(const TemplateArgument *Args, unsigned NumArgs, - const PrintingPolicy &Policy); + const PrintingPolicy &Policy, + bool SkipBrackets = false); static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args, unsigned NumArgs, diff --git a/lib/AST/TypePrinter.cpp b/lib/AST/TypePrinter.cpp index c11920ac28..bd0467d246 100644 --- a/lib/AST/TypePrinter.cpp +++ b/lib/AST/TypePrinter.cpp @@ -759,16 +759,23 @@ std::string TemplateSpecializationType::PrintTemplateArgumentList( const TemplateArgument *Args, unsigned NumArgs, - const PrintingPolicy &Policy) { + const PrintingPolicy &Policy, + bool SkipBrackets) { std::string SpecString; - SpecString += '<'; + if (!SkipBrackets) + SpecString += '<'; + for (unsigned Arg = 0; Arg < NumArgs; ++Arg) { - if (Arg) + if (SpecString.size() > !SkipBrackets) SpecString += ", "; // Print the argument into a string. std::string ArgString; - { + if (Args[Arg].getKind() == TemplateArgument::Pack) { + ArgString = PrintTemplateArgumentList(Args[Arg].pack_begin(), + Args[Arg].pack_size(), + Policy, true); + } else { llvm::raw_string_ostream ArgOut(ArgString); Args[Arg].print(Policy, ArgOut); } @@ -788,7 +795,8 @@ TemplateSpecializationType::PrintTemplateArgumentList( if (SpecString[SpecString.size() - 1] == '>') SpecString += ' '; - SpecString += '>'; + if (!SkipBrackets) + SpecString += '>'; return SpecString; } @@ -800,12 +808,17 @@ PrintTemplateArgumentList(const TemplateArgumentLoc *Args, unsigned NumArgs, std::string SpecString; SpecString += '<'; for (unsigned Arg = 0; Arg < NumArgs; ++Arg) { - if (Arg) + if (SpecString.size() > 1) SpecString += ", "; // Print the argument into a string. std::string ArgString; - { + if (Args[Arg].getArgument().getKind() == TemplateArgument::Pack) { + ArgString = PrintTemplateArgumentList( + Args[Arg].getArgument().pack_begin(), + Args[Arg].getArgument().pack_size(), + Policy, true); + } else { llvm::raw_string_ostream ArgOut(ArgString); Args[Arg].getArgument().print(Policy, ArgOut); } diff --git a/test/CXX/temp/temp.decls/temp.variadic/p4.cpp b/test/CXX/temp/temp.decls/temp.variadic/p4.cpp index 47883fe423..db4db7ddd2 100644 --- a/test/CXX/temp/temp.decls/temp.variadic/p4.cpp +++ b/test/CXX/temp/temp.decls/temp.variadic/p4.cpp @@ -12,4 +12,4 @@ struct tuple_of_refs { Tuple *t_int_ref_float_ref; tuple_of_refs::types *t_int_ref_float_ref_2 = t_int_ref_float_ref; - + diff --git a/test/CXX/temp/temp.decls/temp.variadic/p5.cpp b/test/CXX/temp/temp.decls/temp.variadic/p5.cpp index 94d874fc8d..aff9b44539 100644 --- a/test/CXX/temp/temp.decls/temp.variadic/p5.cpp +++ b/test/CXX/temp/temp.decls/temp.variadic/p5.cpp @@ -30,7 +30,7 @@ ExpansionLengthMismatch::Inner::type *il_pairs; tuple, pair >*il_pairs_2 = il_pairs; -ExpansionLengthMismatch::Inner::type // expected-note{{in instantiation of}} +ExpansionLengthMismatch::Inner::type // expected-note{{in instantiation of template class 'ExpansionLengthMismatch::Inner' requested here}} *il_pairs_bad;