Closed Bug 792634 Opened 7 years ago Closed 7 years ago

nsDeque.cpp:100:10: warning: deleting object of abstract class type ‘nsDequeFunctor’ which has non-virtual destructor will cause undefined behaviour [-Wdelete-non-virtual-dtor]

Categories

(Core :: XPCOM, defect)

x86_64
Linux
defect
Not set

Tracking

()

RESOLVED FIXED
mozilla18

People

(Reporter: dholbert, Assigned: dholbert)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

/xpcom/glue/nsDeque.cpp triggers this build warning right now (in GCC 4.7):
{
nsDeque.cpp: In member function ‘void nsDeque::SetDeallocator(nsDequeFunctor*)’:
nsDeque.cpp:100:10: warning: deleting object of abstract class type ‘nsDequeFunctor’ which has non-virtual destructor will cause undefined behaviour [-Wdelete-non-virtual-dtor]
}

The class in question, nsDequeFunctor, is indeed abstract (it has a pure virtual method) and it does have subclasses -- so this warning is legit.  Hypothetically, if its subclasses had explicit destructors, they wouldn't be getting invoked here, and that's bad.

From a cursory glance at a few of the subclasses, it looks like they *don't* have destructors of their own, so I think we're OK at the moment.  But we shouldn't assume that'll always be true. (unless we had some sort of static-analysis assurance of that)

So -- I think we should give nsDequeFunctor a virtual destructor.
Attached patch fixSplinter Review
Assignee: nobody → dholbert
Status: NEW → ASSIGNED
Attachment #662753 - Flags: review?(benjamin)
Comment on attachment 662753 [details] [diff] [review]
fix

Sure. If it already has a vtable the virtual destructor doesn't hurt.
Attachment #662753 - Flags: review?(benjamin) → review+
https://hg.mozilla.org/mozilla-central/rev/a8309d954e2c
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Flags: in-testsuite-
Resolution: --- → FIXED
Target Milestone: --- → mozilla18
You need to log in before you can comment on or make changes to this bug.