[C++0x] implementing forward declarations for enums

Rodrigo Rivas rodrigorivascosta@gmail.com
Thu Sep 23 15:06:00 GMT 2010


>>>> I had to initialize the variable nested_being_defined to get it to compile
>>>> (possible uninitialized warning).  I initialized it to false.
>>>>
>>> Ok, actually it is never used uninitialized, but let's get rid of the warning.
>>>
>> I saw that it was never used uninitialized and was surprised gcc wasn't
>> able to diagnose that.
>
> Can you file a bug for this warning false positive?
Actually, I don't think this is an error. This situation can be
simplified to the following code:

void fun()
{
   bool flag; /* uninitalized */

   if (some_condition())
      flag = xxx;

   actions();

   if (some_condition())
      use(flag);
}

Now, I know that "some_condition()" returns the same value in the two
calls, so "flag" is initialized and used, or not used at all. But the
compiler cannot know that. That's why it emits the *possible*
uninitialized warning.
Curiously, it does so with -O2 but not with -O0, probably due to the
extra analysis of the life of variables.

Regards.
Rodrigo



More information about the Gcc mailing list