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.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/conversion/reinterpret4.C: New.
* g++.dg/conversion/reinterpret1.C: Adjust.
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));