conv.emplace: Fix emplacing structs w/o this()

This commit is contained in:
Eugen Wissner 2018-10-08 17:51:59 +02:00
parent 4f9927a8c3
commit 6d01680685
2 changed files with 20 additions and 3 deletions

View File

@ -1587,7 +1587,7 @@ struct Array(T)
@nogc nothrow pure @safe unittest @nogc nothrow pure @safe unittest
{ {
struct SWithDtor static struct SWithDtor
{ {
~this() @nogc nothrow pure @safe ~this() @nogc nothrow pure @safe
{ {

View File

@ -190,13 +190,17 @@ do
static assert(is(typeof({ static T t; })), static assert(is(typeof({ static T t; })),
"Default constructor is disabled"); "Default constructor is disabled");
} }
else static if (is(typeof(result.__ctor(args))))
{
result.__ctor(args);
}
else static if (is(typeof(T(args)))) else static if (is(typeof(T(args))))
{ {
*result = T(args); *result = T(args);
} }
else static if (is(typeof(result.__ctor(args)))) else static if (is(typeof(*result = args))) // Args.length == 1, assignment
{ {
result.__ctor(args); *result = args;
} }
else else
{ {
@ -245,6 +249,19 @@ do
static assert(is(typeof(emplace!F((void[]).init)))); static assert(is(typeof(emplace!F((void[]).init))));
} }
// Can emplace structs without a constructor
@nogc nothrow pure @safe unittest
{
static struct SWithDtor
{
~this() @nogc nothrow pure @safe
{
}
}
static assert(is(typeof(emplace!SWithDtor(null, SWithDtor()))));
static assert(is(typeof(emplace!SWithDtor(null))));
}
/** /**
* Thrown if a type conversion fails. * Thrown if a type conversion fails.
*/ */