http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56328
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-02-14 20:39:53 UTC --- The foo<2> specialization is not declared in main.cpp before it would be needed, so the program is ill-formed, no diagnostic required, according to [templ.expl.spec]/6. Also, the following paragraph is relevant: "When writing a specialization, be careful about its location, or to make it compile will be such a trial as to kindle its self-immolation."