typeck.c (build_ptrmemfunc): Just reinterpret if there's no adjustment necessary.
authorJason Merrill <jason@redhat.com>
Thu, 24 Aug 2000 20:43:51 +0000 (16:43 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 24 Aug 2000 20:43:51 +0000 (16:43 -0400)
        * typeck.c (build_ptrmemfunc): Just reinterpret if there's no
        adjustment necessary.

From-SVN: r35954

gcc/cp/ChangeLog
gcc/cp/typeck.c

index 20a8f798ef85b69e252df7951ed8de73cbeff37e..9028c79bd09bef479e09b337ecec4516e0e3c031 100644 (file)
@@ -1,3 +1,8 @@
+2000-08-24  Jason Merrill  <jason@redhat.com>
+
+       * typeck.c (build_ptrmemfunc): Just reinterpret if there's no
+       adjustment necessary.
+
 2000-08-24  Greg McGary  <greg@mcgary.org>
 
        * cp-tree.h (MAIN_NAME_P): Remove macro.
index 3b3313deede7eda40977cc9a8e5b8de71b21c3f6..964993d9392f8c29040baacf0ebb5adf825dd2fe 100644 (file)
@@ -6125,12 +6125,21 @@ build_ptrmemfunc (type, pfn, force)
        cp_error ("invalid conversion to type `%T' from type `%T'", 
                  to_type, pfn_type);
 
+      n = get_delta_difference (TYPE_PTRMEMFUNC_OBJECT_TYPE (pfn_type),
+                               TYPE_PTRMEMFUNC_OBJECT_TYPE (to_type),
+                               force);
+
       /* We don't have to do any conversion to convert a
         pointer-to-member to its own type.  But, we don't want to
         just return a PTRMEM_CST if there's an explicit cast; that
         cast should make the expression an invalid template argument.  */
-      if (TREE_CODE (pfn) != PTRMEM_CST && same_type_p (to_type, pfn_type))
-       return pfn;
+      if (TREE_CODE (pfn) != PTRMEM_CST)
+       {
+         if (same_type_p (to_type, pfn_type))
+           return pfn;
+         else if (integer_zerop (n))
+           return build_reinterpret_cast (to_type, pfn);
+       }
 
       if (TREE_SIDE_EFFECTS (pfn))
        pfn = save_expr (pfn);
@@ -6142,9 +6151,6 @@ build_ptrmemfunc (type, pfn, force)
          npfn = build_component_ref (pfn, pfn_identifier, NULL_TREE, 0);
          delta = build_component_ref (pfn, delta_identifier, NULL_TREE, 0);
          delta = cp_convert (ptrdiff_type_node, delta);
-         n = get_delta_difference (TYPE_PTRMEMFUNC_OBJECT_TYPE (pfn_type),
-                                   TYPE_PTRMEMFUNC_OBJECT_TYPE (to_type),
-                                   force);
          delta = cp_build_binary_op (PLUS_EXPR, delta, n);
          return build_ptrmemfunc1 (to_type, delta, NULL_TREE, npfn,
                                    NULL_TREE);
@@ -6173,9 +6179,6 @@ build_ptrmemfunc (type, pfn, force)
          idx = build_component_ref (pfn, index_identifier, NULL_TREE, 0);
        }
 
-      n = get_delta_difference (TYPE_PTRMEMFUNC_OBJECT_TYPE (pfn_type),
-                               TYPE_PTRMEMFUNC_OBJECT_TYPE (to_type),
-                               force);
       delta = cp_build_binary_op (PLUS_EXPR, ndelta, n);
       delta2 = cp_build_binary_op (PLUS_EXPR, ndelta2, n);
       e1 = fold (build (GT_EXPR, boolean_type_node, idx, integer_zero_node));