This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Wish : -Winitialize on instance variables in constructors.
- From: John Carter <john dot carter at tait dot co dot nz>
- To: gcc at gcc dot gnu dot org
- Date: Thu, 26 Sep 2002 12:22:19 +1200 (NZST)
- Subject: Wish : -Winitialize on instance variables in constructors.
While I quite understand that -Winitialize cannot be expected to work on
instance variables in an arbitary method, it would be nice if it worked in
constructors, (a far simpler problem).
For example, this code...
==uninit.cpp=========================================
#include <iostream>
extern void doThing( int useit);
class A {
int a;
public:
A() {
int b;
int c;
doThing( a);
doThing( b);
doThing( c);
}
};
int main() {
A a;
int b;
int c;
int d = 1;
doThing( b);
doThing( c);
doThing( d);
}
===========================================
When compile using gcc 3.1.1 like so...
g++ -c -Wuninitialized -O uninit.cpp
Produces the following output...
==============================================
uninit.cpp: In function `int main()':
uninit.cpp:20: warning: `int b' might be used uninitialized in this function
uninit.cpp:21: warning: `int c' might be used uninitialized in this function
uninit.cpp:9: warning: `int b' might be used uninitialized in this function
uninit.cpp:10: warning: `int c' might be used uninitialized in this function
=============================================
Which doesn't warn you that the instance variable a is used uninitialized
in the constructor.
Thanks,
--
John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : john.carter@tait.co.nz
New Zealand
Good Ideas:
Ruby - http://www.ruby-lang-org - The best of perl,python,scheme without the pain.
Valgrind - http://developer.kde.org/~sewardj/ - memory debugger for x86-GNU/Linux
Free your books - http://www.bookcrossing.com