Article View: gnu.g++.bug
Article #1297GNU C++ emits unnecessary warning with class with a private destructor
From: Jeremy Fitzhardinge
Date: Sat, 19 Dec 1992 03:52
Date: Sat, 19 Dec 1992 03:52
41 lines
1712 bytes
1712 bytes
GNU C++ 2.3.2 emits a warning when a class has a private destructor and
no friends. However, this doesn't mean that the destructor can never be
called if, for example, there is a public method that calls it.
It is probably worthwhile to have this as a warning, but not by default.
Also, the warning message refers to line number 0, which isn't very accurate.
-- bug.cc --
// This is a trivial example which produces the warning
class foo
{
private:
int data;
~foo();
public:
void remove();
foo(int x) { data = x; }
};
void
foo::remove()
{
data=0;
delete this;
}
-- end bug.cc --
Reading specs from /usr/local/lib/gcc-lib/sparc-sunos4/2.3.2/specs
gcc version 2.3.2
/usr/local/lib/gcc-lib/sparc-sunos4/2.3.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 -I/usr/local/libg++/2.2/include bug.cc /tmp/cca27111.i
GNU CPP version 2.3.2 (sparc)
/usr/local/lib/gcc-lib/sparc-sunos4/2.3.2/cc1plus /tmp/cca27111.i -quiet -dumpbase bug.cc -version -o /tmp/cca27111.s
GNU C++ version 2.3.2 (sparc) compiled by GNU C version 2.3.2.
bug.cc:0: warning: class `foo' only defines a private destructor and has no friends
as -o bug.o /tmp/cca27111.s
J
Technical Details
Message-ID:
<9212180552.AA27124@chao.sw.oz.au>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!sw.oz.AU!jeremyShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!sw.oz.AU!jeremy From: jeremy@sw.oz.AU (Jeremy Fitzhardinge) Subject: GNU C++ emits unnecessary warning with class with a private destructor Message-ID: <9212180552.AA27124@chao.sw.oz.au> Sender: gnulists@ai.mit.edu Organization: Softway Pty Ltd Distribution: gnu Date: Sat, 19 Dec 1992 03:52:33 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 43