On 11/18/2011 03:19 PM, Paolo Carlini wrote:
On 11/18/2011 03:11 PM, Jason Merrill wrote:
On 11/18/2011 08:57 AM, Paolo Carlini wrote:
On 11/18/2011 02:53 PM, Jason Merrill wrote:
I think let's go straight to cp_build_unary_op from
tsubst_copy_and_build in this case; it can't be overloaded, and we
don't want to mess with build_non_dependent_expr.
Ok. In the meanwhile I actually tested the attached, and it works.
Is it
what you have in mind?
That looks the same as the patch I was responding to; I mean to call
cp_build_unary_op directly rather than build_x_unary_op from
tsubst_copy_and_build in the FIX_TRUNC_EXPR case.
Ah ok, I didn't understand in the email client which (patch/message)
you were responding too, sorry, and couldn't see any other direct call
of cp_build_unary_op in the whole pt.c, but sure I'll test that.
Tested the below (x86_64-linux, as usual). Ok mainline and 4_6?
Thanks,
Paolo.
////////////////////
/cp
2011-11-18 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/51150
* pt.c (tsubst_copy_and_build): Handle FIX_TRUNC_EXPR.
/testsuite
2011-11-18 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/51150
* g++.dg/cpp0x/pr51150.C: New.
Index: testsuite/g++.dg/cpp0x/pr51150.C
===================================================================
--- testsuite/g++.dg/cpp0x/pr51150.C (revision 0)
+++ testsuite/g++.dg/cpp0x/pr51150.C (revision 0)
@@ -0,0 +1,20 @@
+// PR c++/51150
+// { dg-options "-std=c++0x" }
+
+struct Clock {
+ double Now();
+};
+template <class T> void Foo(Clock* clock) {
+ const int now = clock->Now();
+}
+
+template void Foo<float>(Clock*);
+
+template <class T> void Boo(int val) {
+ const int now1 = (double)(val);
+ const int now2 = const_cast<double>(val); // { dg-error "invalid" }
+ const int now3 = static_cast<double>(val);
+ const int now4 = reinterpret_cast<double>(val); // { dg-error "invalid" }
+}
+
+template void Boo<float>(int);
Index: cp/pt.c
===================================================================
--- cp/pt.c (revision 181476)
+++ cp/pt.c (working copy)
@@ -13387,6 +13387,10 @@ tsubst_copy_and_build (tree t,
return build_x_unary_op (TREE_CODE (t), RECUR (TREE_OPERAND (t, 0)),
complain);
+ case FIX_TRUNC_EXPR:
+ return cp_build_unary_op (FIX_TRUNC_EXPR, RECUR (TREE_OPERAND (t, 0)),
+ 0, complain);
+
case ADDR_EXPR:
op1 = TREE_OPERAND (t, 0);
if (TREE_CODE (op1) == LABEL_DECL)