When a function template instance is called, it is called indirectly, likely due to being "weak" function (arm.c:arm_encode_section_info).
However when the same call is subject of a tail call optimization, it is called directly. The function is also called directly when there is no function template definition visible in the source, e.g. when old style template organization makes template definitions visible in a single source file only. What is the reasoning behind the distinction between between weak and normal functions made in arm.c:arm_encode_section_info? It falls a bit short because it treats function calls inconsistently, depending on the visibility of their definition. And while it could simply be treated as a bug in the tail call optimization, I'd rather suggest to not treat "weak" functions differently, because (1) efficiency of template based code is greatly affected and (2) I can see little reason to use long-calls for known "weak" functions but short-calls for all other external functions including those which are not yet known to be "weak". Invocation: arm-elf-gcc -O2 -S source.cpp Sample code: template<class T> class Q { public: Q(); void f (); }; // called directly if this definition is removed. template<class T> void Q<T>::f() { } class U { public: int g(); Q<char>& rx; }; int U::g() { rx.f(); // indirect call is used rx.f(); // turned into direct call by tail call optimization } -- Summary: inconsistent code for template function calls Product: gcc Version: 4.0.1 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: a dot kaiser at gmx dot net GCC target triplet: arm-elf http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25249