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?

Paolo.

///////////////////
/cp
2011-11-18  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/51150
        * pt.c (tsubst_copy_and_build): Handle FIX_TRUNC_EXPR.
        * call.c (build_new_op_1): Likewise.

/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 181474)
+++ cp/pt.c     (working copy)
@@ -13384,6 +13384,7 @@ tsubst_copy_and_build (tree t,
     case UNARY_PLUS_EXPR:  /* Unary + */
     case REALPART_EXPR:
     case IMAGPART_EXPR:
+    case FIX_TRUNC_EXPR:
       return build_x_unary_op (TREE_CODE (t), RECUR (TREE_OPERAND (t, 0)),
                                complain);
 
Index: cp/call.c
===================================================================
--- cp/call.c   (revision 181474)
+++ cp/call.c   (working copy)
@@ -5227,6 +5227,7 @@ build_new_op_1 (enum tree_code code, int flags, tr
     case REALPART_EXPR:
     case IMAGPART_EXPR:
     case ABS_EXPR:
+    case FIX_TRUNC_EXPR:
       return cp_build_unary_op (code, arg1, candidates != 0, complain);
 
     case ARRAY_REF:

Reply via email to