#include <iostream> using namespace std;
template <typename T> class C1 { public: T V; C1(T v) : V(v) {}; class nested { public: T W; nested(T w) : W(w) {}; }; }; // This works well template <typename T> T f1 ( C1<T>& c) { return c.V; } // the problem is HERE template <typename T> T f2 ( typename C1<T>::nested& c) { return c.W; } // This is correct with gcc 3.3.2 20031022 // This is incorrect with gcc 3.4.2 20041017 // This is incorrect with gcc 3.4.3 20041226 // This is incorrect with gcc4 4.0.0 20041228 // Error : // nestedFriendTemplateFunction.cc:44: error: no matching function for call to `f2(C1<float>::nested&)' // Need EXPLICITE instantiation ==> GCC BUG !!! // float f2 (C1<float>::nested& c) { return c.W; } int main() { C1<int> c(123); cout<<f1(c)<<endl; C1<float>::nested n(3.5); cout<<n.W<<endl; cout<<f2(n)<<endl; // CANNOT FIND THE CORRECT CODE FOR THIS } So, starting from version 3.4.2 it is no more possible to use a template function that refers to a nested class of a template class. g++ versions : Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.3/specs Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux Thread model: posix gcc version 3.4.3 20041226 (Red Hat 3.4.3-11) Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --with-gxx-include-dir=/usr/include/c++/3.4.3 --enable-languages=c,c++,java,f95 --enable-java-awt=gtk --host=i386-redhat-linux Thread model: posix gcc version 4.0.0 20041228 (Red Hat 4.0.0-0.17) -- Summary: No more possible to have a template function that uses a nested class of a template class Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jean-pierre dot chevallet at imag dot fr CC: gcc-bugs at gcc dot gnu dot org GCC host triplet: i386-redhat-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19288