diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ab5c1449a8e..1c4b06d9943 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2002-07-05 Jason Merrill + * cvt.c (cp_convert_to_pointer): Call force_fit_type for null + pointers. + PR optimization/7145 * tree.c (cp_copy_res_decl_for_inlining): Also copy DECL_INITIAL. diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index 0c43fc3609c..bd42b42c4ed 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -252,6 +252,8 @@ cp_convert_to_pointer (type, expr, force) else expr = build_int_2 (0, 0); TREE_TYPE (expr) = type; + /* Fix up the representation of -1 if appropriate. */ + force_fit_type (expr, 0); return expr; } diff --git a/gcc/testsuite/g++.dg/other/ptrmem3.C b/gcc/testsuite/g++.dg/other/ptrmem3.C new file mode 100644 index 00000000000..ed6d8757441 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/ptrmem3.C @@ -0,0 +1,14 @@ +// Bug: The double cast had an TREE_INT_CST_HIGH of 0, while the single +// cast had -1, so the comparison failed. + +// { dg-do run } + +struct A { }; + +typedef int A::* aip; +typedef long A::* alp; + +int main() +{ + return ((aip)(alp)0 != (aip)0); +}