Goswin von Brederlow wrote: > In Foo the variable is just uninitialized, in Bar it is definetly used > uninitialized and in Baz it might be used uninitialized. Is there any > -W switch to make g++ detect such errors or is that a shortcomming of > -Wuninitialized?
Your example is just not what -Wuninitialized was designed to warn about, which is auto variables whose lifetime begins and ends within the scope of the function and thus it's relatively straightforward to compute that if the first use comes before any definition, then warn. But a member's lifetime is not related to the scope of any member function but to the lifetime of the object. So it would probably require some form of interprocedural analysis as e.g. you'd have to see both the constructor and the member function at the same time in order to say what is used before being initialized -- too bad if they're in different translation units. Moreover, the current -Wuninitialized warning is done in the middle end as it relies on the program having been transformed into SSA form and the dataflow equations solved. But this member analysis pass would need tons of C++ specific knowledge, for example public members could be initialized in the ctor of a derived class -- which brings up a whole other nightmare since there would be no way in general to know without whole-program analysis whether or not this is the case, so you'd probably only be able to ever consider private members. Anyway, so this pass would need tons of C++ specific information (like all the arcane rules for order of construction) and so it would probably have to be done in the front-end. But warnings implemented in front-ends which require this kind of dataflow information are notoriously fickle in that they either miss tons of legitimate cases or warn spuriously all over the place, because the required machinery to get it right runs later. I'm far from a gcc expert and I could be entirely wrong but it seems to me that all of this means that this form of warning is just not practical to implement at all. Brian