🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: GCC 2.1: bizarre error messages when returning a reference

#227
From: Mike Stump
Date: Fri, 10 Apr 1992 10:26
84 lines
3419 bytes
This problem has been fixed.  The next release of gcc should be better.

> From: gb@cs.purdue.edu (Gerald Baumgartner)
> Newsgroups: gnu.g++.bug
> Subject: GCC 2.1: bizarre error messages when returning a reference
> Message-Id: <18392@ector.cs.purdue.edu>
> Date: 10 Apr 92 04:30:49 GMT
> Organization: Department of Computer Science, Purdue University
> To: bug-g++@prep.ai.mit.edu

> Given the following little test program in C++:

> 	class Object {
> 	public:
> 		virtual ~Object();
> 	};

> 	class OutputStream : public Object {
> 	public:
> 		OutputStream( Object & );
> 		virtual int foo (void) = 0;
> 		virtual operator int();
> 	};

> 	OutputStream &
> 	flush( OutputStream & stream )
> 	{
> 		return (stream);
> 	}

> GCC 2.1 produces the error message

> 	stdin: In function `class OutputStream& flush (class OutputStream&)':
> 	stdin:14: cannot allocate an object of type `OutputStream'
> 	stdin:14: since the following virtual functions are abstract:
> 	stdin:8: int  OutputStream::foo ()
> 	stdin:8: int  OutputStream::foo ()
> 	stdin:14: in conversion to type `OutputStream'

> and then dumps core (memory fault).  The compiler does not notice that
> the idea is to convert to type `OutputStream &' and not to `OutputStream'.

> If the member function declaration

> 		virtual operator int();

> is deleted from class OutputStream, then everything works fine.  There is
> no error message and no core dump.

> If the constructor OutputStream::OutputStream is omitted instead, we
> get the error message

> 	stdin: In function `class OutputStream& flush (class OutputStream&)':
> 	stdin:15: conversion to non-scalar type requested

> followed by a core dump (memory fault).  If we omit the abstract member
> function OutputStream::foo, the compiler says:

> 	stdin: In function `class OutputStream& flush (class OutputStream&)':
> 	stdin:15: bad argument 0 for function
> 		  `OutputStream::OutputStream (class Object&)' (type was int )
> 	stdin:15: in conversion to type `OutputStream'

> followed by the usual core dump.

> Now we leave class OutputStream untouched, but we remove the virtual
> destructor of class Object.  That is class Object becomes

> 	class Object { };

> Instead of a core dump, the result is an endless loop of error messages:

> 	stdin: In function `class OutputStream& flush (class OutputStream&)':
> 	stdin:14: cannot allocate an object of type `OutputStream'
> 	stdin:14: since the following virtual functions are abstract:
> 	stdin:7: int  OutputStream::foo ()
> 	stdin:14: in conversion to type `OutputStream'
> 	stdin:14: cannot allocate an object of type `OutputStream'
> 	stdin:14: since type `OutputStream' has abstract virtual functions
> 	stdin:14: in conversion to type `OutputStream'
> 	stdin:14: cannot allocate an object of type `OutputStream'
> 	stdin:14: since type `OutputStream' has abstract virtual functions
> 	stdin:14: in conversion to type `OutputStream'
> 	stdin:14: ...
Technical Details
Message-ID: <9204101026.AA22720@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:  GCC 2.1: bizarre error messages when returning a reference
Message-ID: <9204101026.AA22720@cygnus.com>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Fri, 10 Apr 1992 10:26:44 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 85