aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-02-18 02:12:44 +0000
committerDouglas Gregor <dgregor@apple.com>2011-02-18 02:12:44 +0000
commit8f5667d06a785719691c1139b961411d7f0aedf5 (patch)
tree19366c905ad4a27f7d1e4f2767d7932b1f0b07f5
parent4ae493cccbfbf122ec6ebac0e330232c22fa8489 (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125818 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaTemplate.cpp11
-rw-r--r--test/SemaTemplate/instantiate-non-type-template-parameter.cpp19
2 files changed, 28 insertions, 2 deletions
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp
index 88ba3f9a88..12ed3732e7 100644
--- a/lib/Sema/SemaTemplate.cpp
+++ b/lib/Sema/SemaTemplate.cpp
@@ -3707,8 +3707,15 @@ Sema::BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg,
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);
}
diff --git a/test/SemaTemplate/instantiate-non-type-template-parameter.cpp b/test/SemaTemplate/instantiate-non-type-template-parameter.cpp
index cbadcde2c1..027c1e8bb7 100644
--- a/test/SemaTemplate/instantiate-non-type-template-parameter.cpp
+++ b/test/SemaTemplate/instantiate-non-type-template-parameter.cpp
@@ -34,3 +34,22 @@ namespace PR6986 {
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);
+}