The specialization of a function is not called if compile with -03 option, the generic implementation is called insteed. This appear only if the declaration of the specialization is in another file. The specialization is called if compiled with -02 or lees optimization, or if the generic implementation is declared with the buildin noinline.
Configuration of gcc -v: Using built-in specs. Target: i686-pc-linux-gnu Configured with: ../src/configure --prefix=/project/spg/tools/Open-Sources/gcc/4.1.1/Linux-x86/ --enable-__cxa_atexit --enable-shared --enable-long-long --enable-threads --enable-languages=c,c++ --with-gnu-as --with-gnu-ar --with-gnu-ld --with-gcc Thread model: posix gcc version 4.1.1 Three files: header #ifndef _TCLASS_H_ #define _TCLASS_H_ template<typename T> bool foo(T val) { return false; } #endif scpecialization: #include "tclass.h" template<> bool foo(int val) { return true; } main: #include "tclass.h" int main() { return(foo(1)); } -- Summary: Specialization of a function is not called if compile with -03 option Product: gcc Version: 4.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: maxime dot fiandino at imag dot fr GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28271