On 04/09/13 16:06, Ian Lance Taylor wrote: > On Wed, Sep 4, 2013 at 6:40 AM, Kirill Tkhai <[email protected]> wrote: >> >> the following example compiles without warnings: >> >> $ cat a.c >> int func (int p) >> { >> int x; >> if (p != 0) >> x = 1; >> return x; >> } >> >> $ gcc -c a.c -Wall >> (no messages) >> >> Is there no error? Why compiler doesn't print a error >> about uninitialized variable? >> >> I saw many pieces like this in GNU software. Does >> it mean that it is a de-facto standard and gcc won't warn >> about code like this in the future? > > This question would be more appropriate on the mailing list > [email protected]. The mailing list [email protected] is for > discussions about the development of GCC itself. Please take any > followups to gcc-help. Thanks. > > That said, I think this case is a bug. Please report it following the > instructions at http://gcc.gnu.org/bugs. Thanks. > > Ian >
That depends on the version of gcc. I believe the "-Wmaybe-uninitialized" option was introduced in gcc 4.7, precisely to cover cases like this. Previous versions of gcc considered "x" to be initialised if some paths lead to its initialisation, so no warning is triggered. David
