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);
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);
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));