---------------- temp.cxx --------------------------------- #include <vector> #include <iostream> // a template class definition // but it cannot be instantiated without // the definition of function by_val() template<class T> class container { T a; T* b; public: T* by_addr() const { return b; } T by_val() const; int size() const { return 100; } }; class trace_pt { int i; }; // with template class definition // we can define varibles in template type // note that this variable definition would not // trigger template instantiation because it still // lacks of one member function class trace { container<trace_pt> a_; public: int size() const { return a_.size(); } }; // supply member function definition here template<class T> T container<T>::by_val() const { return a; } // do explicit template instantiation // At this point, it should be able to // compile the template code template class container<trace_pt>; ------------------------ END ------------------------------- Symtom: GCC3.3 would not generate (extern) symbol and code for container<trace_pt>::size() function. But some other previous versions of GCC do NOT have this problem (including GCC 2.95, 3.04, and 3.2). Here are the nm results from object files of different GCC versions: pre yangg2 $ g++295 -o temp.o -c temp.cxx pre yangg2 $ nm -Cg temp.o | grep size 00000000 W container<trace_pt>::size(void) const pre yangg2 $ g++304 -o temp.o -c temp.cxx pre yangg2 $ nm -Cg | grep size 00000000 W container<trace_pt>::size() const pre yangg2 $ g++33 -o temp.o -c temp.cxx pre yangg2 $ nm -Cg temp.o | grep size pre yangg2 $ pre yangg2 $ nm -C temp.o | grep by_addr 00000000 W container<trace_pt>::by_addr() const As we can see, only GCC3.3 does not generate the code for function container<trace_pt>::size() and this function only. ----------- My GCC configurations ----------------- pre yangg2 $ g++295 -v Using builtin specs. gcc version 2.95.4 20020320 [FreeBSD] pre yangg2 $ g++33 -v Reading specs from /usr/local/bin/../lib/gcc-lib/i386-unknown- freebsd4.8/3.3/specs Configured with: ../gcc-3.3/configure --prefix=/software/gcc-3.3-0/pkg -- localstatedir=/var --disable-nls --program-suffix=33 --enable-shared --enable- version-specific-runtime-libs Thread model: posix gcc version 3.3 pre yangg2 $ gcc304 -v Reading specs from /usr/local/bin/../lib/gcc-lib/i386-unknown- freebsd4.5/3.0.4/specs Configured with: ../gcc-3.0.4/configure --prefix=/servers/sys/packages/gcc- 3.0.4-1 --enable-version-specific-runtime-libs Thread model: posix gcc version 3.0.4 -------------------- end -------------------------------
This is a dup of bug 10968 which is already fixed for 3.3.1 which will be released within the next two weeks. *** This bug has been marked as a duplicate of 10968 ***