public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/23140] New: void warning on virtual classes with no destructor
@ 2005-07-29 21:07 thor at math dot tu-berlin dot de
2005-07-29 21:15 ` [Bug c++/23140] " pinskia at gcc dot gnu dot org
0 siblings, 1 reply; 2+ messages in thread
From: thor at math dot tu-berlin dot de @ 2005-07-29 21:07 UTC (permalink / raw)
To: gcc-bugs
If compiled with -Wall, g++-4.0.1 will warn on classes with virtual functions
but *no* destructor at all. Note that even though this warning is well justified
on classes implementing a destructor - because virtual classes might get deleted
thru a base class pointer - this warning is not useful for classes with a
trivial (compiler-generated) destructor. Note that g++-3.4 and earler releases
of g++ did not warn on this case either.
How to reproduce: Enter the following code and save as "destructor.cpp":
/*snip*/
class A {
int x;
public:
A(int a)
: x(a)
{ }
//
virtual int get(void) const
{
return x;
}
};
class B : public A {
int y;
public:
B(int a)
: A(a), y(a+1)
{ }
//
virtual int get(void) const
{
return y;
}
};
int main(int argc,char **argv)
{
return 0;
}
/*snip*/
Then compile as:
$ g++-4.0 -Wall destructor.cpp
Compiler output is:
destructor.cpp:1: warning: 'class A' has virtual functions but non-virtual
destructor
destructor.cpp:14: warning: 'class B' has virtual functions but non-virtual
destructor
Note that this warning is unjustified because deleting a class thru a base
class pointer works fine if both derived and base class only provide a
trivial (compiler-generated) destructor.
--
Summary: void warning on virtual classes with no destructor
Product: gcc
Version: 4.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: thor at math dot tu-berlin dot de
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23140
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/23140] void warning on virtual classes with no destructor
2005-07-29 21:07 [Bug c++/23140] New: void warning on virtual classes with no destructor thor at math dot tu-berlin dot de
@ 2005-07-29 21:15 ` pinskia at gcc dot gnu dot org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-07-29 21:15 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-07-29 21:14 -------
Actually this was a requested thing for 4.0, see PR 11624.
*** This bug has been marked as a duplicate of 11624 ***
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23140
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-07-29 21:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-29 21:07 [Bug c++/23140] New: void warning on virtual classes with no destructor thor at math dot tu-berlin dot de
2005-07-29 21:15 ` [Bug c++/23140] " pinskia at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).