Skip to content

Commit

Permalink
Merge pull request #4023 from BBasile/ussue-15639
Browse files Browse the repository at this point in the history
fixed issue 15639 - allocator.make enables abstract class instantiation
  • Loading branch information
schveiguy committed Mar 4, 2016
2 parents 167b286 + 175b912 commit 3edc09d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion std/experimental/allocator/package.d
Expand Up @@ -452,7 +452,12 @@ auto make(T, Allocator, A...)(auto ref Allocator alloc, auto ref A args)
auto m = alloc.allocate(max(stateSize!T, 1));
if (!m.ptr) return null;
scope(failure) alloc.deallocate(m);
static if (is(T == class)) return emplace!T(m, args);
static if (is(T == class))
{
static assert(!isAbstractClass!T, "class " ~ T.stringof ~
" is abstract and can't be created with make()");
return emplace!T(m, args);
}
else return emplace(cast(T*) m.ptr, args);
}

Expand Down Expand Up @@ -490,6 +495,14 @@ unittest
assert(cust.id == 42);
}

unittest // bugzilla 15639
{
abstract class Foo {}
class Bar: Foo {}
static assert(!is(typeof(theAllocator.make!Foo)));
static assert( is(typeof(theAllocator.make!Bar)));
}

unittest
{
void test(Allocator)(auto ref Allocator alloc)
Expand Down

0 comments on commit 3edc09d

Please sign in to comment.