[PATCH] [Clang/CodeGen] Prevent crash if destructor class is not accessible

Richard Smith richard at metafoo.co.uk
Mon Jun 22 15:23:19 PDT 2015


On Mon, Jun 22, 2015 at 2:09 PM, John McCall <rjmccall at gmail.com> wrote:

> Richard: this code is already testing hasTrivialDestructor.  If you would
> be comfortable with declaring a trivial destructor except for performance
> reasons, maybe hasTrivialDestructor should be returning true?


I don't think that's the right place to address this: if you could somehow
get hold of the type of the anonymous union, you should find it has a
deleted destructor, and CodeGen should not even be considering making a
call to a deleted function. In fact, you can observe this:

struct A {
  ~A();
};

struct B {
  A a;
};

struct Evil {
  template<typename T> Evil(T *p) { p->~T(); }
};

struct C {
  union {
    B b;
    Evil e = this;
  };

  ~C() noexcept;
};

Clang (correctly, as far as I'm aware) rejects this because the anonymous
union has a deleted destructor. I think the right semantic model is that
the anonymous union field is never destroyed by the destructor of the
enclosing class.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150622/3273ab2b/attachment.html>


More information about the cfe-commits mailing list