This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: a warning to implement

On Feb  2, 2002, Paolo Carlini <> wrote:

>> int x = x;
>> Is there any plans for implementing the feature?

> Hi Andrey,
> indeed it looks like gcc does'nt warn. On the other hand EDG-based compilers
> emit:

> "uzarov.c", line 3: warning #592: variable "x" is used before its value is set
>     int x = x;
>             ^

> I have quickly browsed GNATS for warnings and it looks like there is'nt a PR
> dealing with this. Why don't you submit one??

Such usage is explicitly allowed in the C and C++ Standards.  I'll
grant you it's of dubious use, but one of the legal uses I can think
for it is to avoid getting a warning about a variable being used
uninitialized when you know for sure that it is not, but the compiler
can't tell as much.  For example:

  int x;

  if (some condition)
    set x
  else if (some other condition)
    set x
    run a function that never returns but is not marked as such
  // or consider it know that one of the conditions above is known to
  // be always true

  some statement using x

Without `int x = x;', you'd get a warning in the last statement, and
the only way to avoid it would be by introducing code that would make
the generated code less efficient.

But I agree there are times when such a warning could be useful.  It
just shouldn't be enabled with -Wall.

Alexandre Oliva   Enjoy Guarana', see
Red Hat GCC Developer                  aoliva@{,}
CS PhD student at IC-Unicamp        oliva@{,}
Free Software Evangelist                Professional serial bug killer

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]