File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -4428,7 +4428,7 @@ nothrow @safe @nogc unittest
44284428 }
44294429}
44304430
4431- private extern (C) void rt_finalize (void * data , bool det= true ) nothrow ;
4431+ private extern (C) void rt_finalize2 (void * p , bool det = true , bool resetMemory = true ) nothrow ;
44324432
44334433// / ditto
44344434void destroy (bool initialize = true , T)(T obj) if (is (T == class ))
@@ -4448,7 +4448,7 @@ void destroy(bool initialize = true, T)(T obj) if (is(T == class))
44484448 {
44494449 // Bypass overloaded opCast
44504450 auto ptr = (() @trusted => * cast (void ** ) &obj)();
4451- rt_finalize (ptr);
4451+ rt_finalize2 (ptr, true , initialize );
44524452 }
44534453}
44544454
@@ -4723,6 +4723,25 @@ nothrow unittest
47234723 destroy (B.init);
47244724}
47254725
4726+ // make sure destroy!false skips re-initialization
4727+ unittest
4728+ {
4729+ static struct S { int x; }
4730+ static class C { int x; }
4731+ static extern (C++ ) class Cpp { int x; }
4732+
4733+ static void test (T)(T inst)
4734+ {
4735+ inst.x = 123 ;
4736+ destroy ! false (inst);
4737+ assert (inst.x == 123 , T.stringof);
4738+ }
4739+
4740+ test(S());
4741+ test(new C ());
4742+ test(new Cpp ());
4743+ }
4744+
47264745// / ditto
47274746void destroy (bool initialize = true , T)(ref T obj)
47284747if (__traits(isStaticArray, T))
You can’t perform that action at this time.
0 commit comments