This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: missing initializer warnings


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]