Hello,<br><br>I had talked about changing the implementation of the non-virtual-dtor warning on cfe-dev, since it's extremely noisy (and for this reason, I guess, not wired up in -Wmost, -Wall or even -Wextra). The idea was not to warn at the class definition, but rather to warn whenever `delete` was called on a polymorphic class that had no virtual destructor.<br>
<br>I tried my hand at it. It's my first foray into Sema though so it may warrant a thorough review :)<br><br>I found  Sema::ActOnCXXDelete  which seems highly suitable for this check, and indeed there lies the check on the completeness of the class on which delete is invoked.<br>
<br>I have avoided to warn on the array form of  delete[]  , as far as I know arrays should never be treated polymorphically (if only because of the stride).<br><br>I could not get it to warn, however, within `~auto_ptr`. I suppose this is because warnings are suppressed within system headers, however this is really unfortunate, because even though this warning is indeed emitted within a system header (pointing at the delete expression there), it is caused by an incorrect usage of the facility in the first place.<br>
<br>I think that it should be possible to get around this by supplying another location, by example, upon detection that the location is within a system header, switch to another warning and tell the user that she should not build an `auto_ptr` with her class because the destructor does not seem correct (and pointing at the point of instantiation, where the note is normally emitted). I don't know if it has already been done however, and if it is desirable.<br>
<br>Anyway, here is a first stab at introducing this warning.<br><br><br>Note: `final` is not yet available for a class in CLang, I have put a FIXME on top of the check advising it to be modified so as not to warn on final classes (when it'll be available).<br>
<br>Note: is there a reason the accessibility check is performed in a separate `if` statement ? The lines:<br><br>    if (const RecordType *RT = PointeeElem->getAs<RecordType>()) {<br>      CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());<br>
<br>appear twice in  Sema::ActOnCXXDelete  and I could not find any reason as to why it would be necessary to split the two groups. I would suggest the accessibility check could be moved up into the first.<br><br><br>Summary:<br>
> new DiagnosticGroup DeleteNonVirtualDtor, wired up in Extra (activated individually by -Wdelete-non-virtual-dtor)<br>> new Diagnostic in Sema: warn_delete_non_virtual_dtor<br>> added small check to  Sema::ActOnCXXDelete<br>
> added tests to SemaCXX/destructor.cpp<br><br>--Matthieu<br>