http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56328
Bug #: 56328 Summary: Explicit instantiation of inline function template works for base template, fails for specialized template Classification: Unclassified Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: michael.schlot...@sloede.com Why does the compiler treat a specialized template differently from the base template when it comes to explicit instantiation of inline function templates? The following code gives a linker error, unless the second "inline" (see AAA) is removed. In any case, this seems to be a problem of the compiler, not the linker. main.cpp ==================================== template <int dim> void f(int src); int main(int, char** ) { f<1>(456); f<2>(789); } ==================================== template.cpp ==================================== template <int dim> void f(int src); template <int dim> inline void f(int src) { (void)0; } template <> inline /* AAA */ void f<2>(int src) { (void)0; } template void f<1>(int); template void f<2>(int); ==================================== Command used: /pds/opt/gcc-4.7-2/bin/g++ main.cpp template.cpp Error message: /tmp/cc42UAxE.o: In function `main': main.cpp:(.text+0x1f): undefined reference to `void f<2>(int)' collect2: error: ld returned 1 exit status g++ -v: Using built-in specs. COLLECT_GCC=/pds/opt/gcc-4.7-2/bin/g++ COLLECT_LTO_WRAPPER=/aia/opt/gcc-4.7-2/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.7.2/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: /pds/opt/install/gcc//gcc-4.7.2/configure --prefix=/pds/opt/gcc-4.7-2 --enable-threads=posix Thread model: posix gcc version 4.7.2 (GCC)