public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* Re: No warning issued here?
       [not found] <199904220937.CAA25778@cygnus.com>
@ 1999-04-22  3:19 ` Doug Semler
  1999-04-30 23:15   ` Alexandre Oliva
  0 siblings, 1 reply; 2+ messages in thread
From: Doug Semler @ 1999-04-22  3:19 UTC (permalink / raw)
  To: hanwen; +Cc: egcs-bugs

> 
> void f()
> {
>   int i = i;
> }
> 
> /*
> Problem description:
> 
> This compiles without a hitch.
> 
> I would expect a warning to be emitted because of the use of i in the
> righthand side.  Even if this conforms to the C++ standard, this is
> likely to be a programming error, so a warning would be in place.
> 
> 
> 
> 
>   
>  */

(C++ standard basic.scope.pdecl says this is indeterminite value, btw)

You get a warning when compiling with -Wall -O (optimization needed for
reason to ensure the assignment is optimized away...can gcc detect 
uninitialized variables for unoptimized code?)

int i;
int f()
{
   int i = i;
   return i;
}

ruck:~> gcc -O -c crap.c -Wall
crap.c: In function `f':
crap.c:4: warning: `i' might be used uninitialized in this function


---
Doug Semler                       | doug@seaspace.com
SeaSpace Corporation              | Garbage In -- Gospel Out
Least Senior Software Developer;  | Minister of things to do Next Quarter
Low Man on the Totem Pole         | (but will Never Be Done) DNRC  O-
A closed mind is a terrible thing | Bus Error (passengers dumped)
  
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS/M d---(pu) s++:- a-- C++ UILSH+++$ P--- L++ E--- W+
N++ o-- K? w--(++$) O- M-- V- PS+ !PE Y PGP t(+) 5+++ X+
R- tv+(-) b+(++) DI++++ D G e++>++++ h!>--- r% y+>+++++**
------END GEEK CODE BLOCK------


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: No warning issued here?
  1999-04-22  3:19 ` No warning issued here? Doug Semler
@ 1999-04-30 23:15   ` Alexandre Oliva
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Oliva @ 1999-04-30 23:15 UTC (permalink / raw)
  To: Doug Semler; +Cc: hanwen, egcs-bugs

On Apr 22, 1999, Doug Semler <doug@seaspace.com> wrote:

>> int i = i;

> You get a warning when compiling with -Wall -O (optimization needed for
> reason to ensure the assignment is optimized away...

Yep, this is even documented :-)

`-Wuninitialized'
     An automatic variable is used without first being initialized.

     These warnings are possible only in optimizing compilation,
     because they require data flow information that is computed only
     when optimizing.  If you don't specify `-O', you simply won't get
     these warnings.

-- 
Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Brasil
{oliva,Alexandre.Oliva}@dcc.unicamp.br  aoliva@{acm.org,computer.org}
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
*** E-mail about software projects will be forwarded to mailing lists



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1999-04-30 23:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <199904220937.CAA25778@cygnus.com>
1999-04-22  3:19 ` No warning issued here? Doug Semler
1999-04-30 23:15   ` Alexandre Oliva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).