[LLVMbugs] [Bug 12246] New: [-Wdelete-non-virtual-dtor] fires for protected destructor in base class

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Mar 11 20:19:37 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=12246

             Bug #: 12246
           Summary: [-Wdelete-non-virtual-dtor] fires for protected
                    destructor in base class
           Product: clang
           Version: 3.0
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: ben at pope.name
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


** This is also applicable to trunk as of r152547 **

struct Base {
    virtual void func() {}
protected:
    ~Base() {}
};

struct Derived : Base {};

int main() {
    Derived * foo = new Derived;
    delete foo;
}

clang++ -Wall file.cpp

If Base::~Base were public, (but nobody deletes through a base*) the warning is
desirable (with a suggestion to make it protected).
If foo is of static type Base* and Base::~Base is protected, an error is
correctly emitted.
If foo is of static type Base* and Base::~Base is public, the warning is
correctly emitted.

This appears to be a new warning; in 2.9 it doesn't exist, I suspect
-Wnon-virtual-dtor to be related but it wasn't part of -Wall in 2.9.

Motivation: http://www.gotw.ca/publications/mill18.htm Guideline #4

Additional motivation: g++ 4.6.2 gets this right (and I'm led to believe since
4.3) ;)

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list