-Wmaybe-uninitialized
For an automatic variable, if there exists a path from the function
entry to a use of the variable that is initialized, but there exist
some other paths the variable is not initialized, the compiler will
emit a warning if it can not prove the uninitialized paths do not
happen at run time. These warnings are made optional because GCC is
not smart enough to see all the reasons why the code might be
correct despite appearing to have an error
. Here is one example of
how this can happen:
{
int x;
switch (y)
{
case 1: x = 1;
break;
case 2: x = 4;
break;
case 3: x = 5;
}
foo (x);
}
If the value of "y" is always 1, 2 or 3, then "x" is always
initialized, but GCC doesn't know this. To suppress the warning,
the user needs to provide a default case with assert(0) or similar
code.
This option also warns when a non-volatile automatic variable might
be changed by a call to "longjmp". These warnings as well are
possible only in optimizing compilation.
The compiler sees only the calls to "setjmp". It cannot know where
"longjmp" will be called; in fact, a signal handler could call it
at any point in the code. As a result, you may get a warning even
when there is in fact no problem because "longjmp" cannot in fact
be called at the place that would cause a problem.
Some spurious warnings can be avoided if you declare all the
functions you use that never return as "noreturn".
This warning is enabled by -Wall or -Wextra.
For an automatic variable, if there exists a path from the function
entry to a use of the variable that is initialized, but there exist
some other paths the variable is not initialized, the compiler will
emit a warning if it can not prove the uninitialized paths do not
happen at run time. These warnings are made optional because GCC is
not smart enough to see all the reasons why the code might be
correct despite appearing to have an error
![难过](http://static.blog.csdn.net/xheditor/xheditor_emot/default/sad.gif)
how this can happen:
{
int x;
switch (y)
{
case 1: x = 1;
break;
case 2: x = 4;
break;
case 3: x = 5;
}
foo (x);
}
If the value of "y" is always 1, 2 or 3, then "x" is always
initialized, but GCC doesn't know this. To suppress the warning,
the user needs to provide a default case with assert(0) or similar
code.
This option also warns when a non-volatile automatic variable might
be changed by a call to "longjmp". These warnings as well are
possible only in optimizing compilation.
The compiler sees only the calls to "setjmp". It cannot know where
"longjmp" will be called; in fact, a signal handler could call it
at any point in the code. As a result, you may get a warning even
when there is in fact no problem because "longjmp" cannot in fact
be called at the place that would cause a problem.
Some spurious warnings can be avoided if you declare all the
functions you use that never return as "noreturn".
This warning is enabled by -Wall or -Wextra.