This is the mail archive of the
mailing list for the GCC project.
Re: Request for a C++ warning for undefined behaviour
- From: Michael Matz <matz at suse dot de>
- To: skaller <skaller at ozemail dot com dot au>
- Cc: gcc at gcc dot gnu dot org, Mark Mitchell <mark at codesourcery dot com>
- Date: Wed, 13 Aug 2003 13:01:31 +0200 (CEST)
- Subject: Re: Request for a C++ warning for undefined behaviour
On 13 Aug 2003, skaller wrote:
> If you write that kind of code you deserve everything you get.
Well, that's the case for all errors one made. So in extension you would
suggest to remove all warnings and error messages?
> The error your example exhibits is not detectable in general
> due to the flaw in the C++ type system.
I've said something like this. But in the above case it is easily
detectable. Namely it's a call to a member function in the argument list
to an base class initializer.
> It would be possible to check if, in a ctor-initialiser, a direct call
> is made to a virtual function of the current class.
It's not just virtual functions. You can't call _any_ members before the
mem-initializers for base classes have complete.
> Unfortunately, it is possible to circumvent such a check in
> any number of devious ways, for example by simply wrapping
> the call in a non-virtual member.
See above. That's not enough. One would have to go for instance through
a normal file-static function.
> Since you shouldn't be writing code anything remotely like this in the
> first place, it hardly seems like it would be worthwhile to provide a
> special case check here.
That's not a logical conclusion. Besides, usefullness lies in the eye of
the beholder. Indeed from your above remarks I would conclude that this
warning would also be useful to you, because you already made an error in
your assumptions, namely that you can call non-virtual members.