Hello, gcc 3.4.3 compiles and links the following code successfully:
#include <iostream> class X {}; template <typename T> void g (const T & t) { std::cout << "Function g was called" << std::endl; } template <typename T> void f() { T a; g<typename S>(a); // <--------------- Crucial line } int main(int argc, char* argv[]) { f<X>(); } // ----------------------------------------------------------------------------- The ggc compiles and links this code without an error. The execution of this code does NOT write the output of function g "Function g was called", so function g is apparently not called. What does gcc do with the line "g<typename S>(a)"? Shouldn't it report an error, since there is no type S defined anywhere? Shouldn't gcc reject the word "typname" in an explicit function template argument specification? Maybe it has something to do with the "two-stage name lookup", because if we make the crucial line not dependent on the template parameter by just replacing T with X in the previous line, the gcc suddenly reports an error saying: test.cxx: In function `void f()': test.cxx:23: error: template argument 1 is invalid test.cxx:23: error: no matching function for call to `g(X&)' Compiler and Environment Details: ================================= $ g++ -v -save-temps test.cxx Reading specs from /usr/local/gcc-3.4.3/lib/gcc/i686-pc-linux-gnu/3.4.3/specs Configured with: /usr/gcc-3.4.3/configure --enable-languages=c,c++ --prefix=/usr/local/gcc-3.4.3 Thread model: posix gcc version 3.4.3 /usr/local/gcc-3.4.3/libexec/gcc/i686-pc-linux-gnu/3.4.3/cc1plus -E -quiet -v -D_GNU_SOURCE test.cxx -mtune=pentiumpro -o test.ii ignoring nonexistent directory "/usr/local/gcc-3.4.3/lib/gcc/i686-pc-linux-gnu/3.4.3/../../../../i686-pc-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/local/gcc-3.4.3/lib/gcc/i686-pc-linux-gnu/3.4.3/../../../../include/c++/3.4.3 /usr/local/gcc-3.4.3/lib/gcc/i686-pc-linux-gnu/3.4.3/../../../../include/c++/3.4.3/i686-pc-linux-gnu /usr/local/gcc-3.4.3/lib/gcc/i686-pc-linux-gnu/3.4.3/../../../../include/c++/3.4.3/backward /usr/local/include /usr/local/gcc-3.4.3/include /usr/local/gcc-3.4.3/lib/gcc/i686-pc-linux-gnu/3.4.3/include /usr/include End of search list. /usr/local/gcc-3.4.3/libexec/gcc/i686-pc-linux-gnu/3.4.3/cc1plus -fpreprocessed test.ii -quiet -dumpbase test.cxx -mtune=pentiumpro -auxbase test -version -o test.s GNU C++ version 3.4.3 (i686-pc-linux-gnu) compiled by GNU C version 3.4.3. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 as -V -Qy -o test.o test.s GNU assembler version 2.14.90.0.4 (i386-redhat-linux) using BFD version 2.14.90.0.4 20030523 /usr/local/gcc-3.4.3/libexec/gcc/i686-pc-linux-gnu/3.4.3/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o /usr/local/gcc-3.4.3/lib/gcc/i686-pc-linux-gnu/3.4.3/crtbegin.o -L/usr/local/gcc-3.4.3/lib/gcc/i686-pc-linux-gnu/3.4.3 -L/usr/local/gcc-3.4.3/lib/gcc/i686-pc-linux-gnu/3.4.3/../../.. test.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/local/gcc-3.4.3/lib/gcc/i686-pc-linux-gnu/3.4.3/crtend.o /usr/lib/crtn.o -- Summary: "typename" in explicit template argument specification Product: gcc Version: 3.4.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: o dot kwak at rtsgroup dot net http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26380