Patchwork [C++] PR 51150

login
register
mail settings
Submitter Paolo Carlini
Date Nov. 18, 2011, 1:57 p.m.
Message ID <4EC6645A.8030407@oracle.com>
Download mbox | patch
Permalink /patch/126410/
State New
Headers show

Comments

Paolo Carlini - Nov. 18, 2011, 1:57 p.m.
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.carlini@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.carlini@oracle.com>

	PR c++/51150
	* g++.dg/cpp0x/pr51150.C: New.
Jason Merrill - Nov. 18, 2011, 2:11 p.m.
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.

Jason
Paolo Carlini - Nov. 18, 2011, 2:19 p.m.
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.

Thanks,
Paolo.

Patch

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: