]> granicus.if.org Git - clang/commitdiff
Clean up the printing of template argument packs; previously, we were
authorDouglas Gregor <dgregor@apple.com>
Mon, 20 Dec 2010 22:28:59 +0000 (22:28 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 20 Dec 2010 22:28:59 +0000 (22:28 +0000)
getting extra "<>" delimiters around template argument packs.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@122280 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Type.h
lib/AST/TypePrinter.cpp
test/CXX/temp/temp.decls/temp.variadic/p4.cpp
test/CXX/temp/temp.decls/temp.variadic/p5.cpp

index f4898486e721afda2c062e61d537b16fe05b519c..a2d9a17d31ba93fbece1c69d4dccba7fd1b2053d 100644 (file)
@@ -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,
index c11920ac28ad7ede43a88048a8c6cad614a793a3..bd0467d246b82eb025f9da3530472fed9854c9a4 100644 (file)
@@ -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);
     }
index 47883fe423c23ab2650d5af8046c8b1c433c87bf..db4db7ddd26e58282808231329ff9e17abb574a6 100644 (file)
@@ -12,4 +12,4 @@ struct tuple_of_refs {
 
 Tuple<int&, float&> *t_int_ref_float_ref;
 tuple_of_refs<int&, float&>::types *t_int_ref_float_ref_2 =  t_int_ref_float_ref;
-  
+
index 94d874fc8d77606a039cdac3e0f43c8a93f961ff..aff9b44539f698c3cb25d77a724d030ca18e724f 100644 (file)
@@ -30,7 +30,7 @@ ExpansionLengthMismatch<int, long>::Inner<unsigned int, unsigned long>::type
   *il_pairs;
 tuple<pair<int, unsigned int>, pair<long, unsigned long> >*il_pairs_2 = il_pairs;
 
-ExpansionLengthMismatch<short, int, long>::Inner<unsigned int, unsigned long>::type // expected-note{{in instantiation of}}
+ExpansionLengthMismatch<short, int, long>::Inner<unsigned int, unsigned long>::type // expected-note{{in instantiation of template class 'ExpansionLengthMismatch<short, int, long>::Inner<unsigned int, unsigned long>' requested here}}
   *il_pairs_bad;