🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #1147

Multiple instantiation of template functions problem

#1147
From: Tom Epperly
Date: Thu, 12 Nov 1992 08:03
76 lines
3964 bytes
Machine: DECstation 3100
OS: Ultrix 4.2
Compiler: gcc-2.3.1

I am unable to compile the following simple C++ program which uses a
simple template function.  I discovered the problem in another
program and wrote this simpler one to demonstrate the problem.  The
program is followed by the compiler output.  I don't have a copy of
the ANSI draft, so I may have done something illegal.  Previous
version of GCC seemed to handle this okay.

// This may look like C code, but it is really -*- C++ -*-

#include<iostream.h>

template<class DataType>
void swap(DataType d1, DataType d2){
  DataType temp;
  temp = d1;
  d1 = d2;
  d2 = temp;
}

main(){
  int i1,i2;
  double d1,d2;
  i1 = 0;
  i2 = 4;
  d1 = 3.14;
  d2 = 1.42;
  cout << "i1 = " << i1 << ", i2 = " << i2 << '\n';
  cout << "d1 = " << d1 << ", d2 = " << d2 << '\n';
  swap(i1,i2);
  swap(d1,d2);
  cout << "i1 = " << i1 << ", i2 = " << i2 << '\n';
  cout << "d1 = " << d1 << ", d2 = " << d2 << '\n';
}

cd /usr/tmp/
g++ -v -g -o TempTest TempTest.cc -lg++
Reading specs from /usr/local/lib/gcc-lib/decstation/2.3.1/specs
gcc version 2.3.1
 /usr/local/lib/gcc-lib/decstation/2.3.1/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__ANSI_COMPAT -DMIPSEL -DR3000 -DSYSTYPE_BSD -D_SYSTYPE_BSD -Dbsd4_2 -Dhost_mips -Dmips -Dultrix -Dunix -D__ANSI_COMPAT -D__MIPSEL__ -D__R3000__ -D__SYSTYPE_BSD__ -D___SYSTYPE_BSD__ -D__bsd4_2__ -D__host_mips__ -D__mips__ -D__ultrix__ -D__unix__ -D__ANSI_COMPAT -D__MIPSEL -D__R3000 -D__SYSTYPE_BSD -D___SYSTYPE_BSD -D__bsd4_2 -D__host_mips -D__mips -D__ultrix -D__unix -g -D__LANGUAGE_C_PLUS_PLUS__ -D__


LANGUAGE_C_PLUS_PLUS -D__LANGUAGE_C__ -D__LANGUAGE_C -DLANGUAGE_C TempTest.cc /usr/tmp/cca21309.i
GNU CPP version 2.3.1 [AL 1.1, MM 28] DECstation running ultrix
 /usr/local/lib/gcc-lib/decstation/2.3.1/cc1plus /usr/tmp/cca21309.i -quiet -dumpbase TempTest.cc -g -version -o /usr/tmp/cca21309.s
GNU C++ version 2.3.1 [AL 1.1, MM 28] DECstation running ultrix compiled by GNU C version 2.3.1.
 as -nocpp -EL -g -v -o /usr/tmp/cca213091.o /usr/tmp/cca21309.s
/usr/lib/cmplrs/cc/as0 -v -G 8 -EL -g2 -O1 /usr/tmp/cca21309.s -o /tmp/ctmaa21312 -t /tmp/ctmsta21312 
as0: main swap swap 
as0: Error: TempTest.cc, line 4: .ent must precede the definition of the symbol swap
as0: Error: TempTest.cc, line 4: Conflicting definition of symbol swap

0.1u 0.1s 0:02 13% 77+69k 0+4io 22pf+0w
 as -nocpp -EL -g -v -o /usr/tmp/cca213091.o /usr/tmp/cca21309.s
/usr/lib/cmplrs/cc/as0 -v -G 8 -EL -g2 -O1 /usr/tmp/cca21309.s -o /tmp/ctmaa21314 -t /tmp/ctmsta21314 
as0: main swap swap 
as0: Error: TempTest.cc, line 4: .ent must precede the definition of the symbol swap
as0: Error: TempTest.cc, line 4: Conflicting definition of symbol swap

0.1u 0.1s 0:01 14% 64+68k 0+2io 7pf+0w
/usr/local/bin/gcc: /usr/tmp/cca213091.o: No such file or directory

Compilation exited abnormally with code 1 at Thu Nov 12 13:57:25


--
-------------------------------------------------------------------------------
Tom Epperly	University of Wisconsin-Madison		Chemical Engineering
(608) 262-8264	epperly@osnome.che.wisc.edu		Graduate Student
Member of the League for Programming Freedom(fighting software monopolies)
	For more info contact me or lpf@uunet.uu.net.
If you feel you must flame, please send email rather than posting.
-------------------------------------------------------------------------------
Technical Details
Message-ID: <9211122003.AA21348@osnome.che.wisc.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!know!hri.com!noc.near.net!news.bbn.com!usc!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!osnome.che.wisc.edu!epperly

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!know!hri.com!noc.near.net!news.bbn.com!usc!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!osnome.che.wisc.edu!epperly
From: epperly@osnome.che.wisc.edu (Tom Epperly)
Newsgroups: gnu.g++.bug
Subject: Multiple instantiation of template functions problem
Message-ID: <9211122003.AA21348@osnome.che.wisc.edu>
Date: 12 Nov 92 08:03:42 GMT
Sender: gnulists@ai.mit.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 73
Approved: bug-g++@prep.ai.mit.edu