[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Bug c++/7302] -Wnon-virtual-dtor should't complain of protected dtor




------- Comment #16 from pluto at agmk dot net  2007-02-22 02:02 -------
quite better ( modulo coding style ) patch is:

--- class.c.orig        2006-10-12 22:02:53.000000000 +0200
+++ class.c     2007-02-22 02:54:11.888652367 +0100
@@ -5105,15 +5105,15 @@
       tree dtor;

       dtor = CLASSTYPE_DESTRUCTORS (t);
-      /* Warn only if the dtor is non-private or the class has
-        friends.  */
       if (/* An implicitly declared destructor is always public.  And,
             if it were virtual, we would have created it by now.  */
          !dtor
          || (!DECL_VINDEX (dtor)
-             && (!TREE_PRIVATE (dtor)
-                 || CLASSTYPE_FRIEND_CLASSES (t)
-                 || DECL_FRIENDLIST (TYPE_MAIN_DECL (t)))))
+                 && (/* public non-virtual */
+                     (!TREE_PRIVATE (dtor) && !TREE_PROTECTED (dtor))
+                     || (/* or non-public non-virtual with friends */
+                         (TREE_PRIVATE (dtor) || TREE_PROTECTED (dtor))
+                          && (CLASSTYPE_FRIEND_CLASSES (t) || DECL_FRIENDLIST
(TYPE_MAIN_DECL (t)))))))
        warning (0, "%q#T has virtual functions but non-virtual destructor",
                 t);
     }

it correctly warns on B, C and D classes:

struct A {
        virtual void f() = 0;
protected:
        ~A(); // ok.
};

struct B {
        virtual void f() = 0;
        ~B(); // warn! public non-virtual dtor.
};

struct C {
        virtual void f() = 0;
        // warn! implicit public non-virtual dtor.
};

struct D {
        virtual void f() = 0;
private:
        friend class C;
        ~D(); // warn! can be called from class C.
};


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=7302

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.



Reply to: