]> granicus.if.org Git - clang/commitdiff
Restore the C-style cast hack for enum template arguments,
authorJohn McCall <rjmccall@apple.com>
Fri, 15 Jul 2011 07:47:58 +0000 (07:47 +0000)
committerJohn McCall <rjmccall@apple.com>
Fri, 15 Jul 2011 07:47:58 +0000 (07:47 +0000)
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.

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

lib/Sema/SemaTemplate.cpp
test/SemaTemplate/deduction.cpp

index 2514b48de3157fdbe2747da089d23993576dfc59..3ac190e1d4c811bfefd26d8860995081f9130000 100644 (file)
@@ -4152,7 +4152,16 @@ Sema::BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg,
   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.
index 15c061c26198fdd0d6634ecef3701f7f54a161bd..aecb5ee7c8b3dca59ca546140c7b2e2a0d247a41 100644 (file)
@@ -150,3 +150,15 @@ namespace test3 {
     }
   };
 }
+
+// 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);
+  }
+}