feature suggestion/request -- Take 2

Han-Wen Nienhuys hanwen@cs.uu.nl
Wed Jun 30 23:07:00 GMT 1999


martin@mira.isdn.cs.tu-berlin.de writes:
> > Do you think this is desirable? 
> 
> No. If you don't want a check on the syntactic level, you really want
> to test whether data being read had been initialized before, be it in
> the constructor or by some other means.
> 
> If you want such functionality, you should use Purify or
> -fcheck-memory-usage.

OK.  Last time I looked Checker was not ready for mainstream C++ use.
Time to look again, I guess.

> > Would this be hard to implement?
> 
> Yes. Consider
> 
> 	class Bla {
> 	      int k;
> 	      int j;
>               void foo(){
>                  j = 5;
>               }
> 
> 	      Bla () {
> 		  foo();
> 	      }
> 	};
> 
> Do you want to compiler to complain about j not being initialized in
> the ctor? In the end, j *is* initialized in the ctor. Statically
> detecting whether some memory location is initialized is the halting
> problem, so it is not solvable.

I am not saying I want a complete solution.  If you do

	void f(int *)
	{

	}


	void g ()
	{
		int j;
		f(&j);

		do_something_with_j(j);
	}

then GCC won't catch the error either.  In my style, constructors
assign default values to non-aggegrates and do nothing funky.
Occasionally I add a new data member, and forget to add an
initializer.  I would like to catch that case; it seemed to me like a
reasonable extension of -Wuninitialized

> You *really* want to initialize members in the
> member-initializer-lists anyway, because it guarantees you
> initialization.

It does not prevent me from forgetting to add an initialization, and
using -Weffc++ in conjunction with the library is a PITA.  Besides, I
do not want to.  I think that that style of coding is unreadable, and
just another example of the brokenness of C++.

(But let's not get into flamewars.)


-- 

Han-Wen Nienhuys, hanwen@cs.uu.nl ** GNU LilyPond - The Music Typesetter 
      http://www.cs.uu.nl/people/hanwen/lilypond/index.html 





More information about the Gcc-bugs mailing list