From 32263fbfa7ec19a80c8c337a5aea087183e1257d Mon Sep 17 00:00:00 2001 From: dkorpel Date: Wed, 14 Jul 2021 13:56:32 +0200 Subject: [PATCH 1/3] Fix issue 22124 - Corrupted closure with -dip1000 --- src/core/thread/osthread.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/thread/osthread.d b/src/core/thread/osthread.d index 2915225865..f4488fd005 100644 --- a/src/core/thread/osthread.d +++ b/src/core/thread/osthread.d @@ -256,7 +256,7 @@ class Thread : ThreadBase * In: * fn must not be null. */ - this( void function() fn, size_t sz = 0 ) @safe pure nothrow @nogc + this(return scope void function() fn, size_t sz = 0) @safe pure nothrow @nogc { super(fn, sz); } @@ -273,7 +273,7 @@ class Thread : ThreadBase * In: * dg must not be null. */ - this( void delegate() dg, size_t sz = 0 ) @safe pure nothrow @nogc + this(return scope void delegate() dg, size_t sz = 0) @safe pure nothrow @nogc { super(dg, sz); } From d7fb1d562fe30a0279111bc0f47ca951ceb2d6e0 Mon Sep 17 00:00:00 2001 From: dkorpel Date: Fri, 16 Jul 2021 00:45:23 +0200 Subject: [PATCH 2/3] Add test case for issue 22124 --- src/core/thread/osthread.d | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/core/thread/osthread.d b/src/core/thread/osthread.d index f4488fd005..2e76335277 100644 --- a/src/core/thread/osthread.d +++ b/src/core/thread/osthread.d @@ -1143,6 +1143,18 @@ unittest thr.join(); } +// https://issues.dlang.org/show_bug.cgi?id=22124 +unittest +{ + Thread thread = new Thread({}); + auto fun(Thread t, int x) + { + t.__ctor({x = 3;}); + return t; + } + assert(!__traits(compiles, () @nogc => fun(thread, 3) )); +} + unittest { import core.sync.semaphore; From ab596775f0c1dfd24c3626e3c980af4cb760dbc4 Mon Sep 17 00:00:00 2001 From: dkorpel Date: Fri, 16 Jul 2021 00:53:53 +0200 Subject: [PATCH 3/3] Add return scope to ThreadBase as well --- src/core/thread/threadbase.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/thread/threadbase.d b/src/core/thread/threadbase.d index c2c2333efe..b70908b95b 100644 --- a/src/core/thread/threadbase.d +++ b/src/core/thread/threadbase.d @@ -100,14 +100,14 @@ class ThreadBase // Initialization /////////////////////////////////////////////////////////////////////////// - this(void function() fn, size_t sz = 0) @safe pure nothrow @nogc + this(return scope void function() fn, size_t sz = 0) @safe pure nothrow @nogc in(fn) { this(sz); m_call = fn; } - this(void delegate() dg, size_t sz = 0) @safe pure nothrow @nogc + this(return scope void delegate() dg, size_t sz = 0) @safe pure nothrow @nogc in(dg) { this(sz);