typeck.c (get_delta_difference): If via a virtual base, return zero.

cp:
	* typeck.c (get_delta_difference): If via a virtual base,
	return zero.
	* cvt.c (cp_convert_to_pointer): If via a virtual base, do no
	adjustment.
testsuite:
	* g++.old-deja/g++.mike/pmf5.C: Remove test.

From-SVN: r38039
This commit is contained in:
Nathan Sidwell 2000-12-05 15:35:59 +00:00 committed by Nathan Sidwell
parent 4839149c4c
commit 61402b802a
5 changed files with 34 additions and 44 deletions

View File

@ -1,3 +1,10 @@
2000-12-05 Nathan Sidwell <nathan@codesourcery.com>
* typeck.c (get_delta_difference): If via a virtual base,
return zero.
* cvt.c (cp_convert_to_pointer): If via a virtual base, do no
adjustment.
2000-12-04 Richard Henderson <rth@redhat.com>
* error.c (dump_tree): Use output_add_string not OB_PUTS.

View File

@ -209,10 +209,9 @@ cp_convert_to_pointer (type, expr, force)
if (virt_binfo)
{
if (force)
cp_warning ("pointer to member cast via virtual base `%T' of `%T' will only work for objects of dynamic type `%T'",
cp_warning ("pointer to member cast via virtual base `%T' of `%T'",
BINFO_TYPE (virt_binfo),
BINFO_TYPE (BINFO_INHERITANCE_CHAIN (virt_binfo)),
code == MINUS_EXPR ? b2 : b1);
BINFO_TYPE (BINFO_INHERITANCE_CHAIN (virt_binfo)));
else
{
cp_error ("pointer to member cast via virtual base `%T' of `%T'",
@ -220,13 +219,16 @@ cp_convert_to_pointer (type, expr, force)
BINFO_TYPE (BINFO_INHERITANCE_CHAIN (virt_binfo)));
return error_mark_node;
}
/* This is a reinterpret cast, whose result is unspecified.
We choose to do nothing. */
return build1 (NOP_EXPR, type, expr);
}
if (TREE_CODE (expr) == PTRMEM_CST)
expr = cplus_expand_constant (expr);
if (binfo && ! TREE_VIA_VIRTUAL (binfo))
expr = size_binop (code, convert (sizetype,expr),
if (binfo)
expr = size_binop (code, convert (sizetype, expr),
BINFO_OFFSET (binfo));
}
else if (TYPE_PTRMEMFUNC_P (type))

View File

@ -5936,31 +5936,39 @@ get_delta_difference (from, to, force)
virt_binfo = binfo_from_vbase (binfo);
if (virt_binfo)
cp_warning ("pointer to member cast via virtual base `%T' of `%T' will only work for objects of dynamic type `%T'",
BINFO_TYPE (virt_binfo),
BINFO_TYPE (BINFO_INHERITANCE_CHAIN (virt_binfo)), from);
{
/* This is a reinterpret cast, we choose to do nothing. */
cp_warning ("pointer to member cast via virtual base `%T' of `%T'",
BINFO_TYPE (virt_binfo),
BINFO_TYPE (BINFO_INHERITANCE_CHAIN (virt_binfo)));
return delta;
}
delta = BINFO_OFFSET (binfo);
delta = cp_convert (ptrdiff_type_node, delta);
return cp_build_binary_op (MINUS_EXPR,
delta = cp_build_binary_op (MINUS_EXPR,
integer_zero_node,
delta);
return delta;
}
virt_binfo = binfo_from_vbase (binfo);
if (virt_binfo)
{
/* This is a reinterpret cast, we choose to do nothing. */
if (force)
cp_warning ("pointer to member cast via virtual base `%T' of `%T' will only work for objects of dynamic type `%T'",
cp_warning ("pointer to member cast via virtual base `%T' of `%T'",
BINFO_TYPE (virt_binfo),
BINFO_TYPE (BINFO_INHERITANCE_CHAIN (virt_binfo)), to);
BINFO_TYPE (BINFO_INHERITANCE_CHAIN (virt_binfo)));
else
cp_error ("pointer to member conversion via virtual base `%T' of `%T'",
BINFO_TYPE (virt_binfo),
BINFO_TYPE (BINFO_INHERITANCE_CHAIN (virt_binfo)));
return delta;
}
delta = BINFO_OFFSET (binfo);
return BINFO_OFFSET (binfo);
return cp_convert (ptrdiff_type_node, delta);
}
/* Return a constructor for the pointer-to-member-function TYPE using

View File

@ -1,3 +1,7 @@
2000-12-05 Nathan Sidwell <nathan@codesourcery.com>
* g++.old-deja/g++.mike/pmf5.C: Remove test.
2000-12-05 Richard Henderson <rth@redhat.com>
* gcc.c-torture/compile/20001205-1.c: New.

View File

@ -1,31 +0,0 @@
// Special g++ Options: -w
class A {
int j;
};
class Space {
int j;
};
typedef int (A::*pma)();
class B : public Space, virtual public A {
public:
int i;
int foo () {
return i!=42;
}
B() {
i = 42;
}
};
int call_base (A* ap, pma pmf) {
return (ap->*pmf)();
}
int main() {
B b;
return call_base ((A*)&b, (pma)&B::foo);
}