+2002-04-25 Jason Merrill <jason@redhat.com>
+
+ PR c++/5607
+ * search.c (check_final_overrider): No longer static.
+ * class.c (update_vtable_entry_for_fn): Call it.
+ * cp-tree.h: Adjust.
+
2002-04-25 Neil Booth <neil@daikokuya.demon.co.uk>
* cp-lang.c (LANG_HOOKS_SET_YYDEBUG): Remove.
if (overrider == error_mark_node)
return;
+ /* Check for unsupported covariant returns again now that we've
+ calculated the base offsets. */
+ check_final_overrider (TREE_PURPOSE (overrider), fn);
+
/* Assume that we will produce a thunk that convert all the way to
the final overrider, and not to an intermediate virtual base. */
virtual_base = NULL_TREE;
extern tree binfo_for_vtable PARAMS ((tree));
extern tree binfo_from_vbase PARAMS ((tree));
extern tree look_for_overrides_here PARAMS ((tree, tree));
+extern int check_final_overrider PARAMS ((tree, tree));
extern tree dfs_walk PARAMS ((tree,
tree (*) (tree, void *),
tree (*) (tree, void *),
static tree dfs_unuse_fields PARAMS ((tree, void *));
static tree add_conversions PARAMS ((tree, void *));
static int covariant_return_p PARAMS ((tree, tree));
-static int check_final_overrider PARAMS ((tree, tree));
static int look_for_overrides_r PARAMS ((tree, tree));
static struct search_level *push_search_level
PARAMS ((struct stack_level *, struct obstack *));
/* Check that virtual overrider OVERRIDER is acceptable for base function
BASEFN. Issue diagnostic, and return zero, if unacceptable. */
-static int
+int
check_final_overrider (overrider, basefn)
tree overrider, basefn;
{
--- /dev/null
+// PR c++/5607
+
+// Currently we don't support covariant returns that would actually require
+// a pointer adjustment. We were failing to recognize this as such a case,
+// so were silently generating bad code. When we do support covariant
+// returns properly, the expected error should go away, and the testcase
+// should pass execution.
+
+// { NOT YET dg-do run }
+
+class A {
+public:
+ virtual A* getThis() { return this; }
+};
+
+class B {
+int a;
+public:
+ virtual B* getThis() { return this; }
+};
+
+class AB : public A, public B { // { dg-error "covariant" }
+public:
+ virtual AB* getThis() { return this; }
+};
+
+int main ()
+{
+ AB* ab = new AB();
+
+ A* a = ab;
+ B* b = ab;
+
+ if (a->getThis() != a
+ || b->getThis() != b)
+ return 1;
+
+ return 0;
+}