[PATCH] Fix incorrect substitution substituting into variadic alias template

Eli Friedman eli.friedman at gmail.com
Wed Jul 17 17:43:35 PDT 2013


Patch attached.  Fixes PR16646.  The concept is that when substitution
replaces a pack with another pack, we don't want to expand the pack
immediately: we want to expand it at the same level as the original
pack.

I'm not confident that this patch is correct, though: just stripping
off the PackExpansionType in the middle of instantiation seems weird.
Also, I'm not sure what other tests would be relevant.

-Eli
-------------- next part --------------
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index e86c742..2f4cf77 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1417,6 +1417,8 @@ TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB,
            "Template argument kind mismatch");
 
     QualType Replacement = Arg.getAsType();
+    if (const PackExpansionType *PET = Replacement->getAs<PackExpansionType>())
+      Replacement = PET->getPattern();
 
     // TODO: only do this uniquing once, at the start of instantiation.
     QualType Result
diff --git a/test/SemaTemplate/alias-templates.cpp b/test/SemaTemplate/alias-templates.cpp
index 20ba6e0..326efc6 100644
--- a/test/SemaTemplate/alias-templates.cpp
+++ b/test/SemaTemplate/alias-templates.cpp
@@ -166,3 +166,13 @@ namespace PR13136 {
     return 0;
   }
 }
+
+namespace PR16646 {
+  template <typename T> struct DefaultValue { const T value=0;};
+  template <typename ... Args> struct tuple {};
+  template <typename ... Args> using Zero = tuple<DefaultValue<Args> ...>;
+  template <typename ... Args> void f(const Zero<Args ...> &t);
+  void f() {
+      f(Zero<int,double,double>());
+  }
+}


More information about the cfe-commits mailing list