[cfe-commits] r125818 - in /cfe/trunk: lib/Sema/SemaTemplate.cpp test/SemaTemplate/instantiate-non-type-template-parameter.cpp

Douglas Gregor dgregor at apple.com
Thu Feb 17 18:12:44 PST 2011


Author: dgregor
Date: Thu Feb 17 20:12:44 2011
New Revision: 125818

URL: http://llvm.org/viewvc/llvm-project?rev=125818&view=rev
Log:
When we're creating an expression for an integral template argument of
enumeration type, we were generating an integer literal implicitly
casted to the appropriate enumeration type. However, later checks on
that expression would strip the implicit cast.

This commit tweaks the lame hack, by creating an explicit cast instead
of an implicit cast. The right answer is to introduce a 
SubstNonTypeTemplateParmExpr expression that acts like the substituted
result. I'll investigate that soon.


Modified:
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/test/SemaTemplate/instantiate-non-type-template-parameter.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=125818&r1=125817&r2=125818&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Thu Feb 17 20:12:44 2011
@@ -3707,8 +3707,15 @@
     BT = T;
 
   Expr *E = IntegerLiteral::Create(Context, *Arg.getAsIntegral(), BT, Loc);
-  ImpCastExprToType(E, T, CK_IntegralCast);
-
+  if (T->isEnumeralType()) {
+    // FIXME: This is a hack. We need a better way to handle substituted
+    // non-type template parameters.
+    E = CStyleCastExpr::Create(Context, T, VK_RValue, CK_IntegralCast,
+                                      E, 0, 
+                                      Context.getTrivialTypeSourceInfo(T, Loc),
+                                      Loc, Loc);
+  }
+  
   return Owned(E);
 }
 

Modified: cfe/trunk/test/SemaTemplate/instantiate-non-type-template-parameter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-non-type-template-parameter.cpp?rev=125818&r1=125817&r2=125818&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-non-type-template-parameter.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-non-type-template-parameter.cpp Thu Feb 17 20:12:44 2011
@@ -34,3 +34,22 @@
     ckey_m m;
   }
 }
+
+namespace rdar8980215 {
+  enum E { E1, E2, E3 };
+
+  template<typename T, E e = E2>
+  struct X0 { 
+    X0() {}
+    template<typename U> X0(const X0<U, e> &);
+  };
+
+  template<typename T>
+  struct X1 : X0<T> { 
+    X1() {}
+    template<typename U> X1(const X1<U> &x) : X0<T>(x) { }
+  };
+
+  X1<int> x1i;
+  X1<float> x1f(x1i);
+}





More information about the cfe-commits mailing list