[cfe-commits] r148905 - in /cfe/trunk: lib/AST/Type.cpp lib/Sema/SemaTemplateInstantiate.cpp test/SemaTemplate/alias-templates.cpp

Richard Smith richard-llvm at metafoo.co.uk
Tue Jan 24 18:14:59 PST 2012


Author: rsmith
Date: Tue Jan 24 20:14:59 2012
New Revision: 148905

URL: http://llvm.org/viewvc/llvm-project?rev=148905&view=rev
Log:
Fix PR11848: decree that an alias template contains an unexpanded parameter pack
iff its substitution contains an unexpanded parameter pack. This has the effect
that we now reject declarations such as this (which we used to crash when
expanding):

  template<typename T> using Int = int;
  template<typename ...Ts> void f(Int<Ts> ...ints);

The standard is inconsistent on how this case should be treated.

Modified:
    cfe/trunk/lib/AST/Type.cpp
    cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
    cfe/trunk/test/SemaTemplate/alias-templates.cpp

Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=148905&r1=148904&r2=148905&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Tue Jan 24 20:14:59 2012
@@ -1889,7 +1889,9 @@
          Canon.isNull()? T.isDependent() : Canon->isDependentType(),
          Canon.isNull()? T.isDependent() 
                        : Canon->isInstantiationDependentType(),
-         false, T.containsUnexpandedParameterPack()),
+         false,
+         Canon.isNull()? T.containsUnexpandedParameterPack()
+                       : Canon->containsUnexpandedParameterPack()),
     Template(T), NumArgs(NumArgs) {
   assert(!T.getAsDependentTemplateName() && 
          "Use DependentTemplateSpecializationType for dependent template-name");
@@ -1922,7 +1924,7 @@
     if (Args[Arg].getKind() == TemplateArgument::Type &&
         Args[Arg].getAsType()->isVariablyModifiedType())
       setVariablyModified();
-    if (Args[Arg].containsUnexpandedParameterPack())
+    if (Canon.isNull() && Args[Arg].containsUnexpandedParameterPack())
       setContainsUnexpandedParameterPack();
 
     new (&TemplateArgs[Arg]) TemplateArgument(Args[Arg]);

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=148905&r1=148904&r2=148905&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Tue Jan 24 20:14:59 2012
@@ -1510,7 +1510,7 @@
   // FIXME: When OldParm is a parameter pack and NewParm is not a parameter
   // pack, we actually have a set of instantiated locations. Maintain this set!
   if (OldParm->isParameterPack() && !NewParm->isParameterPack()) {
-    // Add the new parameter to 
+    // Add the new parameter to the instantiated parameter pack.
     CurrentInstantiationScope->InstantiatedLocalPackArg(OldParm, NewParm);
   } else {
     // Introduce an Old -> New mapping

Modified: cfe/trunk/test/SemaTemplate/alias-templates.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/alias-templates.cpp?rev=148905&r1=148904&r2=148905&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/alias-templates.cpp (original)
+++ cfe/trunk/test/SemaTemplate/alias-templates.cpp Tue Jan 24 20:14:59 2012
@@ -68,3 +68,36 @@
 
 itt::rebind<bool> btr;
 itt::rebind_thing<bool> btt(btr);
+
+namespace PR11848 {
+  template<typename T> using U = int;
+
+  template<typename T, typename ...Ts>
+  void f(U<T> i, U<Ts> ...is) { // expected-error {{type 'U<Ts>' (aka 'int') of function parameter pack does not contain any unexpanded parameter packs}}
+    return i + f<Ts...>(is...); // expected-error {{pack expansion does not contain any unexpanded parameter packs}}
+  }
+
+  template<typename ...Ts>
+  struct S {
+    S(U<Ts>...ts); // expected-error {{does not contain any unexpanded parameter packs}}
+  };
+
+  template<typename T>
+  struct Hidden1 {
+    template<typename ...Ts>
+    Hidden1(typename T::template U<Ts> ...ts);
+  };
+
+  template<typename T, typename ...Ts>
+  struct Hidden2 {
+    Hidden2(typename T::template U<Ts> ...ts);
+  };
+
+  struct Hide {
+    template<typename T> using U = int;
+  };
+
+  // FIXME: This case crashes clang at the moment.
+  //Hidden1<Hide> h1;
+  Hidden2<Hide, double, char> h2(1, 2);
+}





More information about the cfe-commits mailing list