Article View: gnu.g++.bug
Article #198declaration bug for functions returning templates
From: Scott Kohn
Date: Fri, 07 Aug 1992 00:43
Date: Fri, 07 Aug 1992 00:43
41 lines
1946 bytes
1946 bytes
There is a bug in gcc-2.2.2 with defining functions which return a template object
Foo<type> where Foo<type> has not yet been seen by the compiler. Consider the
following program:
---------------------------------------------------------------------------------
template <class T> class Foo
{
public:
Foo() { }
~Foo() { }
};
#ifdef THIS_WORKS_OK
Foo<int> Bar();
#endif
#ifdef THIS_ALSO_WORKS_OK
Foo<int> global_foo;
#endif
Foo<int> Bar() { Foo<int> b; return(b); }
---------------------------------------------------------------------------------
picard [473]% g++ -c -Wall -v junk.c
Reading specs from /cse/grad/skohn/lib/gcc-lib/sparc-sun-sunos4.1/2.2.2/specs
gcc version 2.2.2
/cse/grad/skohn/lib/gcc-lib/sparc-sun-sunos4.1/2.2.2/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 -Wall junk.c /usr/tmp/cca11751.i
GNU CPP version 2.2.2 (sparc)
/cse/grad/skohn/lib/gcc-lib/sparc-sun-sunos4.1/2.2.2/cc1plus /usr/tmp/cca11751.i -quiet -dumpbase junk.cc -Wall -version -o /usr/tmp/cca11751.s
GNU C++ version 2.2.2 (sparc) compiled by GNU C version 2.2.2.
junk.c:16: semicolon missing after declaration of `Foo<int>'
junk.c: In function `int Bar ()':
junk.c:16: aggregate value used where an integer was expected
However, if we define either of the two #ifdef macros, everything works OK.
So, you can work around the problem by declaring the function before the
actual definition. Sigh.
-- Scott
Technical Details
Message-ID:
<9208070043.AA11791@picard.ucsd.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cs.ucsd.edu!skohnShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cs.ucsd.edu!skohn From: skohn@cs.ucsd.edu (Scott Kohn) Subject: declaration bug for functions returning templates Message-ID: <9208070043.AA11791@picard.ucsd.edu> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Fri, 7 Aug 1992 00:43:41 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 42