------- Comment #11 from jakub at gcc dot gnu dot org 2010-08-31 20:53 ------- Because when foo is not static, it has to be compiled. If it is static, GCC figures it is a pure function (only reads memory and arguments and computes from it its return value) and as the result in main of the function isn't used, that call is optimized away very early. As foo isn't used anywhere else, it isn't compiled at all.
-- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45467