This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: gcc-4.0-virtual function return type
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: JFanatiker <jfanatiker at yahoo dot de>
- Cc: gcc at gcc dot gnu dot org
- Date: Mon, 08 Nov 2004 09:18:28 +0000
- Subject: Re: gcc-4.0-virtual function return type
- Organization: Codesourcery LLC
- References: <200411072136.45269.jfanatiker@yahoo.de>
JFanatiker wrote:
Hi!
I read the current changes of gcc-4.0. There is the following in the C++ part:
G++ has an undocumented extension to virtual function covariance rules that
allowed the overrider to return a type that was implicitly convertable to the
overridden function's return type. For instance a function returning void *
could be overridden by a function returning T *. This is now deprecated and
will be removed in a future release.
-----------
Why are you going to throw away such good features like this one? This feature
Are you a user of this feature? Do you know of programs that use it?
Clearly if there is significant use, we'll reconsider.
The feature is deprecated because
1) It led to user confusion about what was valid/invalid (bug report)
2) It is not documented - no user would know for sure what it was
supposed to do
3) It is (possibly) incomplete in that say, an 'int' returning function
cannot be overridden by a 'short' returning function, which some might
say is more specialized.
4) It does not work for Ts that have non-trival destructors -- either
the destructor is not called, or the caller of the virtual function must
know which instance will actually be called so the dynamic type is
known (this rather misses the point of virtual function calls)[%].
We are trying to move away from extensions that are unused, undocumented,
incomplete and not propsed to ISO.
nathan
% a third alternative would be for the virtual function to return (by
reference) a pointer to a cleanup function. As you can see, this is getting
complicated.
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk