public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/48001] New: -Wuninitialized warning caught a different way for printf and ++ in loop
@ 2011-03-05 20:43 jerome.borme at gmail dot com
  2011-03-05 20:46 ` [Bug middle-end/48001] " jerome.borme at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: jerome.borme at gmail dot com @ 2011-03-05 20:43 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48001

           Summary: -Wuninitialized warning caught a different way for
                    printf and ++ in loop
           Product: gcc
           Version: 4.5.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jerome.borme@gmail.com


I checked bug meta-bug #24639, also bug #43361 and bug #27589, but I could not
b sure this is a duplicate. The 3rd test below is the surprising one.

gcc -c -Wuninitialized test.c

/* 1st test */
int main () {
  int i, x ;
  x++ ;       // printf ("%d", x) ; would give the same result
  return 0 ;
}
-->  ‘x’ is used uninitialized in this function
This is expected, we should be incrementing x without first initialization. It
works the same for x++ and printf x.

/* 2nd test */
#include <stdio.h>
int main () {
  int i, x ;
  for (i = 0 ; i < 10 ; i++) printf ("%d", x) ;
  return 0 ;
}
--> ‘x’ may be used uninitialized in this function
I think this corresponds to bug #27589. We should not printf x without
initializing, but the compiler cannot be sure if we will actually be printed or
not before  evaluating the “for” test at runtime.

/* 3rd test */
int main () {
  int i, x ;
  for (i = 0 ; i < 10 ; i++) x++ ;
  return 0 ;
}
--> No warning at all.
This is surprising:
* Outside a loop, both printf and x++ give the same warning.
* Inside a loop, printf will give a warning, while x++ will not do it.


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

end of thread, other threads:[~2011-03-05 22:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-05 20:43 [Bug middle-end/48001] New: -Wuninitialized warning caught a different way for printf and ++ in loop jerome.borme at gmail dot com
2011-03-05 20:46 ` [Bug middle-end/48001] " jerome.borme at gmail dot com
2011-03-05 21:41 ` [Bug middle-end/48001] inconsistent warning within loop always taken and outside the loop manu at gcc dot gnu.org
2011-03-05 22:25 ` jerome.borme at gmail dot com

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).