Bug 11652 - incorrect template instantiation in some circumstances
Summary: incorrect template instantiation in some circumstances
Status: RESOLVED DUPLICATE of bug 10968
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3
: P2 normal
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-07-23 22:34 UTC by Gehua Yang
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gehua Yang 2003-07-23 22:34:06 UTC
---------------- 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 -------------------------------
Comment 1 Andrew Pinski 2003-07-23 22:41:48 UTC
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 ***