From 211c10aff2b2cdfd9280f159cab7825b8a323c80 Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Fri, 26 Feb 2016 07:06:31 +0100 Subject: [PATCH] fixed issue 15721 --- std/experimental/allocator/package.d | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/std/experimental/allocator/package.d b/std/experimental/allocator/package.d index 3c9e91b5794..54cee20a6ce 100644 --- a/std/experimental/allocator/package.d +++ b/std/experimental/allocator/package.d @@ -1099,7 +1099,19 @@ void dispose(A, T)(auto ref A alloc, T p) if (is(T == class) || is(T == interface)) { if (!p) return; - auto support = (cast(void*) p)[0 .. typeid(p).initializer.length]; + static if (is(T==interface)) + { + version(Windows) + { + import core.sys.windows.unknwn; + static assert(!is(T: IUnknown), "COM interfaces can't be destroyed in " + ~ __PRETTY_FUNCTION__); + } + auto ob = cast(Object) p; + } + else + alias ob = p; + auto support = (cast(void*) ob)[0 .. typeid(ob).initializer.length]; destroy(p); alloc.deallocate(support); } @@ -1155,6 +1167,20 @@ unittest theAllocator.dispose(arr); } +unittest //bugzilla 15721 +{ + import std.experimental.allocator.mallocator: Mallocator; + + interface Foo {} + class Bar: Foo {} + + Bar bar; + Foo foo; + bar = Mallocator.instance.make!Bar; + foo = cast(Foo) bar; + Mallocator.instance.dispose(foo); +} + /** Returns a dynamically-typed $(D CAllocator) built around a given statically-