public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "thor at math dot tu-berlin dot de" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/23140] New: void warning on virtual classes with no destructor Date: Fri, 29 Jul 2005 21:07:00 -0000 [thread overview] Message-ID: <20050729210058.23140.thor@math.tu-berlin.de> (raw) 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
next reply other threads:[~2005-07-29 21:01 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2005-07-29 21:07 thor at math dot tu-berlin dot de [this message] 2005-07-29 21:15 ` [Bug c++/23140] " pinskia at gcc dot gnu dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20050729210058.23140.thor@math.tu-berlin.de \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).