Article View: gnu.g++.bug
Article #133GCC 2.1: bizarre error messages when returning a reference
From: Gerald Baumgartner
Date: Fri, 10 Apr 1992 04:30
Date: Fri, 10 Apr 1992 04:30
76 lines
2961 bytes
2961 bytes
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: ...
--Gerald
Technical Details
Message-ID:
<18392@ector.cs.purdue.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cs.purdue.edu!gbShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cs.purdue.edu!gb From: gb@cs.purdue.edu (Gerald Baumgartner) Subject: GCC 2.1: bizarre error messages when returning a reference Message-ID: <18392@ector.cs.purdue.edu> Sender: gnulists@ai.mit.edu Organization: Department of Computer Science, Purdue University Distribution: gnu Date: Fri, 10 Apr 1992 04:30:49 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 77