diff mbox

[C++] PR 51379

Message ID 4EFF85E1.4050206@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Dec. 31, 2011, 10 p.m. UTC
Hi,
> On 12/31/2011 03:08 PM, Paolo Carlini wrote:
>> this implements in a straightforward way the resolution of DR 799 (which
>> went in CD2): basically a reinterpret_cast to the type of the expression
>> itself is fine for integral, enumeration, pointer, or pointer-to-member
>> type. Tested x86_64-linux.
>
>> +  else if ((cxx_dialect != cxx98)
> This DR should apply to C++98 mode as well.
I suspected that. Thus I'm finishing testing the below instead. Ok?

Thanks,
Paolo.

/////////////////////
/cp
2011-12-31  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/51379
	* typeck.c (build_reinterpret_cast_1): Implement resolution of
	DR 799.

/testsuite
2011-12-31  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/51379
	* g++.dg/conversion/reinterpret4.C: New.
	* g++.dg/conversion/reinterpret1.C: Adjust.

Comments

Jason Merrill Jan. 1, 2012, 8:12 p.m. UTC | #1
OK.

Jason
diff mbox

Patch

Index: testsuite/g++.dg/conversion/reinterpret1.C
===================================================================
--- testsuite/g++.dg/conversion/reinterpret1.C	(revision 182759)
+++ testsuite/g++.dg/conversion/reinterpret1.C	(working copy)
@@ -3,4 +3,4 @@ 
 struct Y { Y(int &); };
 
 int v;
-Y y1(reinterpret_cast<int>(v));  // { dg-error "" }
+Y y1(reinterpret_cast<int>(v));
Index: testsuite/g++.dg/conversion/reinterpret4.C
===================================================================
--- testsuite/g++.dg/conversion/reinterpret4.C	(revision 0)
+++ testsuite/g++.dg/conversion/reinterpret4.C	(revision 0)
@@ -0,0 +1,4 @@ 
+// PR c++/51379
+
+unsigned long t1 = 1;
+unsigned long t2 = reinterpret_cast<unsigned long>(t1);
Index: cp/typeck.c
===================================================================
--- cp/typeck.c	(revision 182759)
+++ cp/typeck.c	(working copy)
@@ -6203,6 +6203,11 @@  build_reinterpret_cast_1 (tree type, tree expr, bo
   else if (TYPE_PTR_P (type) && INTEGRAL_OR_ENUMERATION_TYPE_P (intype))
     /* OK */
     ;
+  else if ((INTEGRAL_OR_ENUMERATION_TYPE_P (type)
+	    || TYPE_PTR_P (type) || TYPE_PTR_TO_MEMBER_P (type))
+	   && same_type_p (type, intype))
+    /* DR 799 */
+    return fold_if_not_in_template (build_nop (type, expr));
   else if ((TYPE_PTRFN_P (type) && TYPE_PTRFN_P (intype))
 	   || (TYPE_PTRMEMFUNC_P (type) && TYPE_PTRMEMFUNC_P (intype)))
     return fold_if_not_in_template (build_nop (type, expr));