This is the mail archive of the gcc@gcc.gnu.org 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


> -----Original Message-----
> From: Gabriel Dos Reis [mailto:gdr@codesourcery.com]
> Sent: Tuesday, February 05, 2002 5:21 PM
> To: dewar@gnat.com
> Cc: gdr@codesourcery.com; aoliva@redhat.com; coola@ngs.ru;
> gcc@gcc.gnu.org; pcarlini@unitus.it
> Subject: Re: a warning to implement
> 
> 
> dewar@gnat.com (Robert Dewar) writes:
> 
> | <<Then you're wrong because the issue of the debate wasn't 
> whether it
> | should be valid statement; the issue was whether it could 
> be a useful
> | construct -- incidentally some wanted to make it ill-formed.
> | >>
> | 
> | Sorry, I can't imagine any useful use of this construct
> 
> That *you* can't imagine a useful use of that construct doesn't mean
> other people don't. Other people do imagine, in the same way people
> have uses of SNaNs.

There's a little difference here: SNaNs have a definite behaviour, which is
different from NaNs; however, from a language point of view, "int x = x;" is
exactly equivalent to "int x;" and really different from "int x = x0;". 

So I think it's well advised fro the compiler to warn that it doesn't do
anything with the "=x" part of the declaration, much like it warns about "if
(a = 1)" by fear it was in fact "if (a == 1)" or about "a == 0;" because it
often is a typo for "a = 0;"; in all cases there's an obvious way to avoid
the warning *in a portable way* if you really meant what was written: "int
x", "if ((a = 1) != 0)" or "(void)a;".

ALL these constructs are perfectly valid, and have perfectly correct
behaviour. We can even argue that "f() == 0;" can be used to avoid a warning
about unused return value from a call to "int f();" :-)

The fact is that in all these circumstances, GCC emit warnings. So it seems
better *for GCC* to emit a warning for "int x = x;", and to enable it for
"-Wall".

Just my .02euros

	Bernard
--------------------------------------------
Bernard Dautrevaux
Microprocess Ingenierie
97 bis, rue de Colombes
92400 COURBEVOIE
FRANCE
Tel:	+33 (0) 1 47 68 80 80
Fax:	+33 (0) 1 47 88 97 85
e-mail:	dautrevaux@microprocess.com
		b.dautrevaux@usa.net
-------------------------------------------- 


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