Bug 18064 and covariant returns
Mark Mitchell
mark@codesourcery.com
Tue Oct 26 22:36:00 GMT 2004
Nathan Sidwell wrote:
> We apparently have a gnu extension that allows a virtual function
> returning void * to be overridden by one returning T *, provided
> T is not a class type
>
> search.c:
> else if (!pedantic
> && can_convert (TREE_TYPE (base_type), TREE_TYPE (over_type)))
> /* GNU extension, allow trivial pointer conversions such as
> converting to void *, or qualification conversion. */
> {
> /* can_convert will permit user defined conversion from a
> (reference to) class type. We must reject them. */
> over_return = non_reference (TREE_TYPE (over_type));
> if (CLASS_TYPE_P (over_return))
> fail = 2;
>
> This is not documented in extend.texi.
>
> Do we want to keep the extension?
>
> My preference would be to deprecate and remove it (it's easier to
> remove than document), but I'm not passionate about that.
I would be in favor of removing this extension. However, as extensions
go, this is relatively non-evil, so I would not be violently opposed.
(If we're going to keep the extension, it seems like it would actually
make more sense to allow any pointer type convertible to "void *". In
general, one could extend C++ to allow any covariant type, so that, for
example, you could override a function returning "int" with one
returning "short". Not that I think that's a great idea.)
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
More information about the Gcc
mailing list