Patchwork [C++] PR 51379

login
register
mail settings
Submitter Paolo Carlini
Date Dec. 31, 2011, 8:08 p.m.
Message ID <4EFF6BB5.3070507@oracle.com>
Download mbox | patch
Permalink /patch/133746/
State New
Headers show

Comments

Paolo Carlini - Dec. 31, 2011, 8:08 p.m.
Hi,

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.

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/cpp0x/reinterpret1.C: New.
	* g++.dg/conversion/reinterpret1.C: Adjust, run in C++98 mode.
Jason Merrill - Dec. 31, 2011, 8:25 p.m.
OK.

Jason
Jason Merrill - Dec. 31, 2011, 8:33 p.m.
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.

Jason

Patch

Index: testsuite/g++.dg/conversion/reinterpret1.C
===================================================================
--- testsuite/g++.dg/conversion/reinterpret1.C	(revision 182759)
+++ testsuite/g++.dg/conversion/reinterpret1.C	(working copy)
@@ -1,4 +1,5 @@ 
 // PR c++/15076
+// { dg-options -std=c++98 }
 
 struct Y { Y(int &); };
 
Index: testsuite/g++.dg/cpp0x/reinterpret1.C
===================================================================
--- testsuite/g++.dg/cpp0x/reinterpret1.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/reinterpret1.C	(revision 0)
@@ -0,0 +1,5 @@ 
+// PR c++/51379
+// { dg-options -std=c++0x }
+
+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 ((cxx_dialect != cxx98)
+	   && (INTEGRAL_OR_ENUMERATION_TYPE_P (type)
+	       || TYPE_PTR_P (type) || TYPE_PTR_TO_MEMBER_P (type))
+	   && same_type_p (type, intype))
+    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));