🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: g++ 2.2.2 and template syntax?

#845
From: Mike Stump
Date: Sat, 29 Aug 1992 15:28
160 lines
3612 bytes
This problem should not exist in the next release of gcc.

cygnus bash[901] /usr/latest/bin/g++ t3.cc
cygnus bash[902] a.out
I am zero
I am one
I am two
I am zero
I am zero
cygnus bash[903] /usr/latest/bin/g++ -DARMTEMPLATES t3.cc
cygnus bash[904] a.out
I am zero
I am one
I am two
I am zero
I am zero
cygnus bash[905] /usr/latest/bin/g++ -DCOMPLAIN t3.cc
t3.cc: In function `int  main (int, char **)':
t3.cc:82: bad argument 0 for function `Printer<Zero>::Printer (class Printer<Zero>&)' (type was class Printer<One>)
t3.cc:82: in base initialization for class `Printer<Zero>'
cygnus bash[909] a.out
a.out: command not found

I suspect that is the behavior you want to see, right?


> From: warsaw@nlm.nih.gov (Barry A. Warsaw)
> Message-Id: <WARSAW.92Aug28115053@anthem.nlm.nih.gov>
> Organization: Century Computing, Inc.
> Date: 28 Aug 92 16:50:53 GMT
> Apparently-To: gnu-g++-bug@uunet.uu.net
> To: bug-g++@prep.ai.mit.edu

> Is there a difference between the template syntax that g++ 2.2.2
> parses and that which the ARM specifies?  I'm a template novice so
> apologies if its me that's confused.

> The following program illustrates the problem.  Compile with no
> switches to watch it work.  Compile with -DARMTEMPLATES to compile
> with (my understanding of) ARM syntax for the copy constructor of a
> template class.  Compile instead with -DCOMPLAIN to see that, even
> though (I think) g++ doesn't parse the correct syntax, it does do The
> Right Thing.

> In brief, should the copy ctor of a template class look like:

> template<class Thing>
> class Printer
> {
> public:
> 	Printer( Printer<Thing>& copy );
> };

> as my reading of the ARM indicates, or should it be:

> template<class Thing>
> class Printer
> {
> public:
> 	Printer( Printer& copy );
> };

> as g++ seems to want?

> Thanks,
> -Barry

> -------------------- snip snip --------------------
> #include <iostream.h>

> #ifdef ARMTEMPLATES
> #define SCOPEDTHING(c,t) c<t>
> #else
> #define SCOPEDTHING(c,t) c
> #endif


> template<class Thing>
> class Printer
> {
> public:
> 	Printer( Thing& t );
> 	Printer( SCOPEDTHING(Printer,Thing)& copy );

> 	void whoami( void ) const
> 	{
> 		cout << "I am " << xt.who << endl;
> 	};

> private:
> 	Thing& xt;
> };


> template<class Thing>
> Printer<Thing>::Printer( Thing& t )
> 	: xt( t )
> {};


> template<class Thing>
> Printer<Thing>::Printer( SCOPEDTHING(Printer,Thing)& copy )
> 	: xt( copy.xt )
> {};


> class Zero
> {
> public:
> 	char* who;
> 	Zero( void )
> 		: who( "zero" )
> 	{};
> };


> class One
> {
> public:
> 	char* who;
> 	One( void )
> 		: who( "one" )
> 	{};
> };


> class Two
> {
> public:
> 	char* who;
> 	Two( void )
> 		: who( "two" )
> 	{};
> };


> int main( int, char** )
> {
> 	Zero zero;
> 	One one;
> 	Two two;
> 	Zero another;

> 	Printer<Zero> z( zero );
> 	Printer<One> o( one );
> 	Printer<Two> t( two );
> 	Printer<Zero> a( another );
> 	Printer<Zero> b( z );
> #ifdef COMPLAIN
> 	Printer<Zero> c( o );
> #endif COMPLAIN

> 	z.whoami();
> 	o.whoami();
> 	t.whoami();
> 	a.whoami();
> 	b.whoami();

> 	return( 0 );
> };
Technical Details
Message-ID: <9208291528.AA29987@cygnus.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cygnus.com!mrs

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cygnus.com!mrs
From: mrs@cygnus.com (Mike Stump)
Subject: Re:  g++ 2.2.2 and template syntax?
Message-ID: <9208291528.AA29987@cygnus.com>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Sat, 29 Aug 1992 15:28:22 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 161