From a89ed6f10cee820e772f90f4753b084b3fcd5138 Mon Sep 17 00:00:00 2001 From: Atila Neves Date: Fri, 22 Sep 2023 13:00:32 -0700 Subject: [PATCH 1/2] Cover atomic increase of ref count --- tests/ut/ref_counted.d | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/ut/ref_counted.d b/tests/ut/ref_counted.d index 655bd9d..fad6da4 100644 --- a/tests/ut/ref_counted.d +++ b/tests/ut/ref_counted.d @@ -177,8 +177,10 @@ mixin TestUtils; @("default.struct.shared") @system unittest { { - auto ptr = RefCounted!(shared SharedStruct)(5); + auto ptr0 = RefCounted!(shared SharedStruct)(5); SharedStruct.numStructs.shouldEqual(1); + auto ptr2 = ptr0; // copying the pointer ups the ref count but not # of structs + SharedStruct.numStructs.should == 1; } SharedStruct.numStructs.shouldEqual(0); } From 2174a51183df491b436bd8acad75b2c7ebe27229 Mon Sep 17 00:00:00 2001 From: Atila Neves Date: Fri, 22 Sep 2023 13:06:17 -0700 Subject: [PATCH 2/2] Make foreach targets lvalues --- tests/ut/vector.d | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/ut/vector.d b/tests/ut/vector.d index fe9b0f5..6217424 100644 --- a/tests/ut/vector.d +++ b/tests/ut/vector.d @@ -420,7 +420,9 @@ private void consumeVec(T)(auto ref T vec) { @("foreach") @safe unittest { - foreach(e; vector(7, 7, 7).range) { + // can't be inline in the foreach otherwise disappears before anything happens + scope v = vector(7, 7, 7); + foreach(e; v.range) { e.should == 7; } } @@ -482,7 +484,9 @@ private void consumeVec(T)(auto ref T vec) { @("String") @safe unittest { - foreach(c; String("oooooo").range) + // can't be inline in the foreach otherwise disappears + auto s = String("oooooo"); + foreach(c; s.range) c.should == 'o'; }