This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: missing initializer warnings
- To: egcs-bugs at cygnus dot com
- Subject: Re: missing initializer warnings
- From: Nathan Sidwell <nathan at cs dot bris dot ac dot uk>
- Date: Thu, 02 Jul 1998 09:52:05 +0100
- Organization: Computer Science Dept, Bristol University
- References: <359A7908.5684@cs.bris.ac.uk>
I'm following up on my own post about the unintialized structure member
warning. I've trawled through the patches archive and found the mail
concerning its insertion into egcs
(http://www.cygnus.com/ml/egcs-patches/1998-Jun/0421.html and
followups). I guess I should have done that first - let that be a lesson
to me.
I think Jeffrey Law hits it on the head -- there are too many false
positives. And the way to inhibit the warning by putting explicit zeroes
in is just too annoying.
Also, having had a chance to sleep on it, I think this warning is
*dangerous*, because it can lead to a false sense of security. With it,
egcs only warns about some cases of implicit initialization to zero.
There are other cases where *uninitialized* members are not diagnosed.
Consider the following
struct S
{
int a;
S(){}
};
static S s;
Here the constructor S::S() does not initialize member a and leaves it
*undefined*. egcs emits no warning either during parsing the
constructor, or during its application. This problem *has* bitten me
when I added a member variable and forgot to initialize it in the
constructors -- I can't recall being bitten by the initialized to zero
method.
The problem I see is that both initialization by initializer list and by
constructor can be thought of as initialization, and I, the programmer,
know I'm being warned about implicit zero initialization, I might
therefore (reasonably?) expect to be warned about the far more dangerous
uninitialized member. When optimization is on I'm warned about possible
unintialized automatic variables. I know members of the `this' object
aren't the same as automatics, but they can look like it in the source
code. Actually detecting this kind of error might well be quite hard.
nathan
--
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
You can up the bandwidth, but you can't up the speed of light
nathan@acm.org http://www.cs.bris.ac.uk/~nathan/ nathan@cs.bris.ac.uk