Article View: gnu.g++.bug
Article #1246@ Function template in 2.3.2
From: Taed Nelson
Date: Fri, 11 Dec 1992 22:10
Date: Fri, 11 Dec 1992 22:10
53 lines
1605 bytes
1605 bytes
I am using G++ 2.3.2 on SunOS 4.1.1 on a sparcStation 1. It generates bad
assembly code when function templates are used.
The code supplied below compiles and runs correctly under Borland C++ on DOS.
------------------------------------------------------------------------------
g++ -Wall test.cc
as: "/usr/tmp/cca12274.s", line 151: error: redefinition of symbol "_getString"
as: "/usr/tmp/cca12274.s", line 167: error: redefinition of symbol "_getString"
------------------------------------------------------------------------------
#include <stdio.h>
class base {
public:
int value;
const char *string;
base () { string = "BASE"; };
};
class d1 : public base {
public:
const char *string;
d1 () { string = "D1"; };
};
class d2 : public base {
public:
const char *string;
d2 () { string = "D2"; };
};
template <class T>
const char *getString (T *p_class)
{
return (p_class->string);
};
int main ()
{
base o_base;
d1 o_d1;
d2 o_d2;
printf ("%s %s %s\n",
getString (&o_base),
getString (&o_d1),
getString (&o_d2));
return (0);
}
------------------------------------------------------------------------------
Technical Details
Message-ID:
<9212112210.AA10796@berlioz.nsc.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!berlioz.nsc.com!nelsonShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!berlioz.nsc.com!nelson From: nelson@berlioz.nsc.com (Taed Nelson) Subject: @ Function template in 2.3.2 Message-ID: <9212112210.AA10796@berlioz.nsc.com> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Fri, 11 Dec 1992 22:10:28 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 58