Compiling and linking these two files together should succeed.
/* BEGIN 1.cpp */
int callme();
int main(int argc, char** argv) { return callme(); }
/* END 1.cpp */
/* BEGIN 2.cpp */
template<typename T> struct holder { static int var; };
template<typename T> int holder<T>::var = 0;
int callme() { return holder<void>::var; }
/* END 2.cpp */
Indeed, compiling and linking them together without LTO succeeds. However, with
LTO, linking fails because of an undefined reference:
$ g++-4.5 -flto 1.cpp 2.cpp
/tmp/ccORg22M.lto.o: In function `main':
ccsrvz5g.o:(.text+0x10): undefined reference to `_Z6callmev'
collect2: ld returned 1 exit status
--
Summary: Static members of templates cause LTO to omit required
code
Product: gcc
Version: 4.5.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: lto
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: alexey at feldgendler dot ru
GCC build triplet: x86_64-linux-gnu
GCC host triplet: x86_64-linux-gnu
GCC target triplet: x86_64-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45496