🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #1464

gcc 2.3.1 bug with function templates (multiple definitions)

#1464
From: Seth C. Goldstein
Date: Sat, 21 Nov 1992 08:21
53 lines
2201 bytes
Machine:	sparc
Version:	gcc version 2.3.1
OS:		SunOS Release 4.1.2
problem:	If more than one  use of a function, which is defined
		with a template, occurs in a file, the assembler claims
		that the function is defined more than once.

sample code:
/////////////////////////////////////////////////////////// start
int *packAddress(void);
void packDone(int);
#define intsIn(T)	((sizeof(T)+(sizeof(T)-1))/sizeof(int))

int i;
double d;
int j;

template<class T>
void
pack(T& data)
{
	T *p = (T *)packAddress();

	*p = data;
	packDone(intsIn(T));
}

foo()
{
	pack(i);
	pack(d);
	pack(j);
}
/////////////////////////////////////////////////////////// end
sample compilation:
/////////////////////////////////////////////////////////// start
gcc-2.3.1 -v -o foo foo.C
Reading specs from /usr/sww/lib/gcc-lib/sparc-sun-sunos4.1/2.3.1/specs
gcc version 2.3.1
 /usr/sww/lib/gcc-lib/sparc-sun-sunos4.1/2.3.1/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix foo.C /usr/tmp/cca21700.i
GNU CPP version 2.3.1 (sparc)
 /usr/sww/lib/gcc-lib/sparc-sun-sunos4.1/2.3.1/cc1plus /usr/tmp/cca21700.i -quiet -dumpbase foo.cc -version -o /usr/tmp/cca21700.s
GNU C++ version 2.3.1 (sparc) compiled by GNU C version 2.3.1.
foo.C: In function `int  foo ()':
foo.C:24: warning: control reaches end of non-void function
 as -o /usr/tmp/cca217001.o /usr/tmp/cca21700.s
as: "/usr/tmp/cca21700.s", line 57: error: redefinition of symbol "_pack"
gcc-2.3.1: /usr/tmp/cca217001.o: No such file or directory
/////////////////////////////////////////////////////////// end

-seth

p.s. Am I sending these reports to the correct place?
Technical Details
Message-ID: <9211220021.AA21710@boing.CS.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!cs.berkeley.edu!sethg

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!cs.berkeley.edu!sethg
From: sethg@cs.berkeley.edu (Seth C. Goldstein)
Subject: gcc 2.3.1 bug with function templates (multiple definitions)
Message-ID: <9211220021.AA21710@boing.CS.Berkeley.EDU>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Sat, 21 Nov 1992 08:21:08 GMT
Approved: bug-gcc@prep.ai.mit.edu
Lines: 55