<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jun 22, 2015 at 2:09 PM, John McCall <span dir="ltr"><<a href="mailto:rjmccall@gmail.com" target="_blank">rjmccall@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">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?</blockquote><div><br></div><div>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:</div><div><br></div><div><div>struct A {</div><div>  ~A();</div><div>};</div><div><br></div><div>struct B {</div><div>  A a;</div><div>};</div><div><br></div><div>struct Evil {</div><div>  template<typename T> Evil(T *p) { p->~T(); }</div><div>};</div><div><br></div><div>struct C {</div><div>  union {</div><div>    B b;          </div><div>    Evil e = this;</div><div>  };</div><div><br></div><div>  ~C() noexcept;</div><div>};</div><div><br></div></div><div>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.</div></div></div></div>