🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

G++ gives signal 11 in template processing

#989
From: Nate Osgood
Date: Mon, 28 Sep 1992 23:47
68 lines
2831 bytes
Hi.  I'm using g++ 2.2.2 on a Sun4 under SunOS 4.1.2

This is a report of an easy to exhibit but somewhat puzzling bug.  The
followng program causes g++ to crash as follows:

Reading specs from /usr/uns/lib/gcc-lib/sun4/2.2.2/specs
gcc version 2.2.2
 /usr/uns/lib/gcc-lib/sun4/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 /usr/tmp/foo.c /usr/tmp/cca26631.i
GNU CPP version 2.2.2 (sparc)
 /usr/uns/lib/gcc-lib/sun4/2.2.2/cc1plus /usr/tmp/cca26631.i -quiet -dumpbase foo.cc -version -o /usr/tmp/cca26631.s
GNU C++ version 2.2.2 (sparc) compiled by GNU C version 2.2.2.
/usr/tmp/foo.c: In method `int  StackBase<unsigned int>::Depth ()':
/usr/tmp/foo.c:13: warning: control reaches end of non-void function
/usr/site/gcc2: Internal compiler error: program cc1plus got fatal signal 11


The crash apparently occurs as a result of a template in the code.  It
is hard to say exactly what SINGLE THING causes the bug -- my guess is
that the ultimate cause is a discrepency between the stated return
type for a method in the prototype, and the ACTUAL return type
specified in the function template.  (i.e. rather than warning of a
mismatch in return types, g++ crashes, apparently via segmentation
fault).   on the other hand, tweaking this code in other ways can also
make the problem vanish (e.g. by removing the "depth" method below).
in any case, it's a small amount of code and a dramatic result:

------------------------------

template<class Contents> class StackBase 
{
 public:
  Contents    Pop();
  int    Depth();

};

/*  Note that the Pop function should return "Contents" but does not
	below */


template<class Contents>     StackBase<Contents>::Pop()
{
}

/* for some reason, this additioanl function must be present to exhibit
	the error	*/
template<class Contents> int    StackBase<Contents>::Depth()
{
}


/*  Now we USE the template (cause it to be instantiated) */

typedef  StackBase<unsigned int> SBB;

------------




Thanks!

Nate Osgood
-- 
-------------------------------------------------------------------------------
Nate Osgood			| ARPA: hacrat@catfish.lcs.mit.edu
CS Graduate Student		| 
MIT LCS Room NE43-636		| UUCP: ...!uunet!catfish.lcs.mit.edu!hacrat
Technical Details
Message-ID: <1992Sep28.234702.12157@mintaka.lcs.mit.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!convex!linac!pacific.mps.ohio-state.edu!cis.ohio-state.edu!catfish.lcs.mit.edu!hacrat

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!convex!linac!pacific.mps.ohio-state.edu!cis.ohio-state.edu!catfish.lcs.mit.edu!hacrat
From: hacrat@catfish.lcs.mit.edu (Nate Osgood)
Subject: G++ gives signal 11 in template processing
Message-ID: <1992Sep28.234702.12157@mintaka.lcs.mit.edu>
Sender: gnulists@ai.mit.edu
Organization: MIT Laboratory for Computer Science
Distribution: gnu
Date: Mon, 28 Sep 1992 23:47:02 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 69