Using the below code snipped (bug.C), and compiling it using: gcc -Wall -O2 -save-temps -c -o bug.o bug.C causes _ZN1B1fIiEEvPT_ to disappear from the .s-file, and later on breaking the link. Using -O1 works fine. ---- bug.C ---- struct B { template <class T> void f(T * t); void dummyInst(); }; template <class T> void B::f(T * t) { } void B::dummyInst() { f((int*)0); }
I'm seeing this happening in 4.3.x too, isn't new in 4.4.x. Now, I'm not sure to understand which is the problem: indeed, it disappears, but it's also true that nothing calls it. I would ask you to provide a short testcase which doesn't link anymore and was fine before (4.2.x?). Thanks.
If another translation unit is relying on finding an instantiation in bug.o then you should use an explicit instantiation to ensure it is present, or the other translation unit should include the definition of B::f
This is expected, any optimizing compiler (e.g., ICC behaves the same as GCC) will get rid of that implicit instantiation, while inlining. Really, this is not going to change.