Hi!
A program I've made has code similar to the following:
int main(int argc, char** argv)
{
bool b;
ClassForSomething* obj;
(...);
b = false;
try
{
obj = new ClassForSomething(...);
b = true;
} catch(AnException* eFailed)
{
(...);
};
if(b)
{
b = false;
try
{
result = obj->DoSomething();
b = true;
} catch(AnException* eFailedAgain)
{
(...);
}
(...)
}
The program is compiled using Visual C++ 2005 Express, with "Warning Level" set to "Level 4".
The compiler, then, issues this warning:
warning C4701: potentially uninitialized local variable 'obj' used
at the line containing:
result = obj->DoSomething();
Um... am I doing something wrong If I understand this code correctly, obj never comes unitialized at this line (or never comes to this line at all). Anyone can shed a light on this for me, please :)

"potentially uninitialized local variable"???
Lugoff81
drainey
Dion
Martin: I think I must disagree with you. If "obj" is not initialized because of an exception, b will never be "true", and the second try-catch block would never be entered. That's exactly my point.
- Izhido
EDIT: Received alert on Martin, but didn't see his post. Maybe it was a private msg...
LindaW567
I can't follow the logic of your code fragment, but I like the technique of setting pointers to NULL to indicate that they aren't initialized. You can call delete on a NULL pointer, so clean up needn't care whether it got some other value.
Of course, I don't use W4, either. I know people who use W4 and treat warnings as errors, but I use W3. With W4, it seems like I end up convoluting my code just to make the compiler shut up.
Peter Doyle
It is not easy to solve the general problem of determining which, of the possible code paths, is really possible.