a warning to implement
Alexandre Oliva
aoliva@redhat.com
Sat Feb 2 16:05:00 GMT 2002
On Feb 2, 2002, Paolo Carlini <pcarlini@unitus.it> 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
else
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 http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist Professional serial bug killer
More information about the Gcc
mailing list