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.carl...@oracle.com>

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

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

        PR c++/51379
        * g++.dg/cpp0x/reinterpret1.C: New.
        * g++.dg/conversion/reinterpret1.C: Adjust, run in C++98 mode.
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));

Reply via email to