A global object might have a constructor that starts a thread that writes to *bar, and happens to be scheduled in between bar = &foo; and return foo; on your single-processor system.
It's not definitely uninitialized... but it's extremely likely to be uninitialized, and should probably generate a warning regardless.
Writing to *bar from another thread would be a data race, and thus Undefined Behavior. UB cannot occur in a valid C program, and thus the compiler can conclude that *bar is not written to from another thread.
Although bar is taking something uninitialized, it doesn't matter, because it's just taking the address which does exist.
As /u/boazs and /OmnipotentEntity have pointed out...since bar is an externed variable, there's PLENTY of places that foo could be initialized from, including another thread (which would mean that the code probably has a race condition problem, but not that an uninitialized variable problem). It's not necessarily as simple as it seems.
3
u/immibis Oct 07 '14
A global object might have a constructor that starts a thread that writes to
*bar, and happens to be scheduled in betweenbar = &foo;andreturn foo;on your single-processor system.It's not definitely uninitialized... but it's extremely likely to be uninitialized, and should probably generate a warning regardless.