[cfe-commits] r135262 - in /cfe/trunk: lib/Sema/SemaTemplate.cpp test/SemaTemplate/deduction.cpp

John McCall rjmccall at apple.com
Fri Jul 15 00:47:58 PDT 2011


Author: rjmccall
Date: Fri Jul 15 02:47:58 2011
New Revision: 135262

URL: http://llvm.org/viewvc/llvm-project?rev=135262&view=rev
Log:
Restore the C-style cast hack for enum template arguments,
which is required given the current setup for template
argument deduction substitution validation, and add a test
case to make sure we don't break it in the future.


Modified:
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/test/SemaTemplate/deduction.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=135262&r1=135261&r2=135262&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Fri Jul 15 02:47:58 2011
@@ -4152,7 +4152,16 @@
   else
     BT = T;
 
-  return Owned(IntegerLiteral::Create(Context, *Arg.getAsIntegral(), BT, Loc));
+  Expr *E = IntegerLiteral::Create(Context, *Arg.getAsIntegral(), BT, Loc);
+  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);
 }
 
 /// \brief Match two template parameters within template parameter lists.

Modified: cfe/trunk/test/SemaTemplate/deduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/deduction.cpp?rev=135262&r1=135261&r2=135262&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/deduction.cpp (original)
+++ cfe/trunk/test/SemaTemplate/deduction.cpp Fri Jul 15 02:47:58 2011
@@ -150,3 +150,15 @@
     }
   };
 }
+
+// Verify that we can deduce enum-typed arguments correctly.
+namespace test14 {
+  enum E { E0, E1 };
+  template <E> struct A {};
+  template <E e> void foo(const A<e> &a) {}
+
+  void test() {
+    A<E0> a;
+    foo(a);
+  }
+}





More information about the cfe-commits mailing list