[Bug c++/106159] New: Have -Woverloaded-virtual not warn about virtual destructors?

adl at gnu dot org gcc-bugzilla@gcc.gnu.org
Fri Jul 1 10:29:48 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106159

            Bug ID: 106159
           Summary: Have -Woverloaded-virtual not warn about virtual
                    destructors?
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: adl at gnu dot org
  Target Milestone: ---

The new version of -Woverloaded-virtual recently introduced seems to warn about
virtual destructors in case of multiple inheritance.  Is this really intended? 
Could destructors be ignored from this warning?   Also note that the diagnostic
is output three times.

$ cat > vee.cc <EOF
struct left
{
  virtual ~left() {}
};

struct right
{
  virtual ~right() {}
};

struct both:
  public left, public right
{
};
EOF
$ g++ -Wall vee.cc -O2 -Woverloaded-virtual -c
vee.cc:8:11: warning: 'virtual right::~right()' was hidden
[-Woverloaded-virtual=]
    8 |   virtual ~right() {}
      |           ^
vee.cc:11:8: note:   by 'virtual both::~both()'
   11 | struct both:
      |        ^~~~
vee.cc:8:11: warning: 'virtual right::~right()' was hidden
[-Woverloaded-virtual=]
    8 |   virtual ~right() {}
      |           ^
vee.cc:11:8: note:   by 'virtual both::~both()'
   11 | struct both:
      |        ^~~~
vee.cc:8:11: warning: 'virtual right::~right()' was hidden
[-Woverloaded-virtual=]
    8 |   virtual ~right() {}
      |           ^
vee.cc:11:8: note:   by 'virtual both::~both()'
   11 | struct both:
      |        ^~~~

$ g++ --version
g++ (Debian 20220630-1) 13.0.0 20220630 (experimental) [master
r13-1359-gaa1ae74711b]
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


More information about the Gcc-bugs mailing list