Bug 23140 - void warning on virtual classes with no destructor
Summary: void warning on virtual classes with no destructor
Status: RESOLVED DUPLICATE of bug 11624
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.1
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-07-29 21:00 UTC by thor
Modified: 2005-07-29 21:14 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description thor 2005-07-29 21:00:58 UTC
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.
Comment 1 Andrew Pinski 2005-07-29 21:14:46 UTC
Actually this was a requested thing for 4.0, see PR 11624.

*** This bug has been marked as a duplicate of 11624 ***