[cfe-commits] r131989 - in /cfe/trunk: include/clang/Basic/DiagnosticGroups.td include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExprCXX.cpp test/SemaCXX/destructor.cpp

Eli Friedman eli.friedman at gmail.com
Mon May 30 14:49:42 PDT 2011


On Mon, May 30, 2011 at 2:40 PM, Argyrios Kyrtzidis <akyrtzi at gmail.com> wrote:
> On May 30, 2011, at 2:36 PM, Argyrios Kyrtzidis wrote:
>
> Hi Nico,
> On May 30, 2011, at 12:19 PM, Nico Weber wrote:
>
> Hi Argyrios and Matthieu,
> this warning found a few problems in chromium – thanks! However, it also
> finds a few false positives, so I don't think I can turn it on by default,
> which is a bummer.
> All of the false positives are of this form:
> class SomeInterface {
>  public:
>   virtual void interfaceMethod() {}  // or = 0;
>  protected:
>   ~SomeInterface() {}
> }
> class WorkerClass : public SomeInterface {
>  public:
>   // many non-virtual functions, but also:
>   virtual void interfaceMethod() override { /* do actual work */ }
> };
> void f() {
>   scoped_ptr<WorkerClass> c(new WorkerClass);  // simplified example
> }
> This is a somewhat standard pattern (see
> e.g. http://www.gotw.ca/publications/mill18.htm, "Virtual Question #2").
> Do you have any good suggestions how to deal with this case?
>
> If WorkerClass gets subclassed in the future, deletion in "f()" will be
> undefined behavior. Ideally WorkerClass should be marked "final" and then
> there will also be no warning; does this sound reasonable ?
>
> Um, to be exact, undefined behavior if you delete a WorkerClass * pointer.

Sure, except that there isn't any way to do that outside of C++0x mode. :)

-Eli




More information about the cfe-commits mailing list