------- Comment #3 from mmitchel at gcc dot gnu dot org 2008-09-20 21:59 ------- I suspect that things have been improved so that this code is no longer required. My expectation is that in the past we only emitted the static when we emitted the function body, so the code made sense. But, now, with the cgraph infrastructure, the compiler is probably perfect capable of emitting a variable without its containing function.
Andrew raises a good point about -frepo. The interesting question is what happens if there is an undefined referenced to the variable, but not the function; does collect2 arrange that we actually emit the function? For example: test.h ------ template <typename T> void * f(T) { static int i; } a.C --- #include "test.h" int* p = f(3); int main() {} With -O2 -frepo, does this link? I'd expect that we end up with an undefined referenced to f<int>::i in a.o, but that this variable isn't listed in the set of things that could be generated by recompiling a.C, so we lose. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36959