From 1baf12b102cc430229d3072433d877f5dc1b0ffb Mon Sep 17 00:00:00 2001 From: k-hara Date: Tue, 19 Aug 2014 21:51:58 +0900 Subject: [PATCH] fix Issue 13300 - pure function 'std.array.Appender!(T[]).Appender.ensureAddable' cannot call impure function 'test.T.__fieldPostBlit' --- std/variant.d | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/std/variant.d b/std/variant.d index 0c61bde26c5..00f38e682a0 100644 --- a/std/variant.d +++ b/std/variant.d @@ -585,14 +585,20 @@ public: opAssign(value); } - this(this) + static if (!AllowedTypes.length || anySatisfy!(hasElaborateCopyConstructor, AllowedTypes)) { - fptr(OpID.postblit, &store, null); + this(this) + { + fptr(OpID.postblit, &store, null); + } } - ~this() + static if (!AllowedTypes.length || anySatisfy!(hasElaborateDestructor, AllowedTypes)) { - fptr(OpID.destruct, &store, null); + ~this() + { + fptr(OpID.destruct, &store, null); + } } /** Assigns a $(D_PARAM VariantN) from a generic @@ -2425,6 +2431,36 @@ unittest assert(S.cnt == 0); } +unittest +{ + // Bugzilla 13300 + static struct S + { + this(this) {} + ~this() {} + } + + static assert( hasElaborateCopyConstructor!(Variant)); + static assert(!hasElaborateCopyConstructor!(Algebraic!bool)); + static assert( hasElaborateCopyConstructor!(Algebraic!S)); + static assert( hasElaborateCopyConstructor!(Algebraic!(bool, S))); + + static assert( hasElaborateDestructor!(Variant)); + static assert(!hasElaborateDestructor!(Algebraic!bool)); + static assert( hasElaborateDestructor!(Algebraic!S)); + static assert( hasElaborateDestructor!(Algebraic!(bool, S))); + + import std.array; + alias Algebraic!bool Value; + + static struct T + { + Value value; + @disable this(); + } + auto a = appender!(T[]); +} + unittest { // Make sure Variant can handle types with opDispatch but no length field.