[llvm-bugs] [Bug 32837] virtual destructor not called

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Apr 28 10:07:33 PDT 2017


http://bugs.llvm.org/show_bug.cgi?id=32837

Reid Kleckner <rnk at google.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|NEW                         |RESOLVED
                 CC|                            |rnk at google.com

--- Comment #2 from Reid Kleckner <rnk at google.com> ---
I believe the sample code has UB. Array delete isn't polymorphic, you can't
delete an array of S2 objects as a pointer to an array of S objects. Consider
how this would go wrong for a two-element array when sizeof(S2) != sizeof(S):

struct S { virtual ~S(); };
struct S2 { virtual ~S2() { __builtin_printf("asdf\n"); } int grow; };
int main() { delete [] static_cast<S *>(new S2[2]); }

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170428/d7c63455/attachment.html>


More information about the llvm-bugs mailing list