From c0fb999749af2baf3ab71404cfb93b1e2805845d Mon Sep 17 00:00:00 2001 From: Cauterite Date: Tue, 26 Jul 2016 22:48:27 +1000 Subject: [PATCH 1/4] make Unique.opDot() inout typecons.Unique.opDot() should be inout to allow use through const access paths. --- std/typecons.d | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/std/typecons.d b/std/typecons.d index 8679d9878ca..e2ff485eeab 100644 --- a/std/typecons.d +++ b/std/typecons.d @@ -164,7 +164,7 @@ public: return u; } /** Forwards member access to contents. */ - RefT opDot() { return _p; } + auto opDot() inout { return _p; } /** Postblit operator is undefined to prevent the cloning of $(D Unique) objects. @@ -288,6 +288,24 @@ private: assert(!uf2.isEmpty); } +unittest +{ + struct Bar {int val;} + struct Foo { + Unique!Bar bar = new Bar; + } + + Foo foo; + foo.bar.val = 6; + const Foo* ptr = &foo; + static assert(is(typeof(ptr) == const(Foo*))); + static assert(is(typeof(ptr.bar) == const(Unique!Bar))); + static assert(is(typeof(ptr.bar.val) == const(int))); + assert(ptr.bar.val == 6); + foo.bar.val = 7; + assert(ptr.bar.val == 7); +} + // Used in Tuple.toString private template sharedToString(alias field) if (is(typeof(field) == shared)) From 052fcc9430211d19f7998b469c6d2442a3a4dc18 Mon Sep 17 00:00:00 2001 From: Cauterite Date: Tue, 26 Jul 2016 22:56:53 +1000 Subject: [PATCH 2/4] tab -> spaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit god forbid anyone have a tab in their code ¬_¬ --- std/typecons.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/std/typecons.d b/std/typecons.d index e2ff485eeab..eeac95729e4 100644 --- a/std/typecons.d +++ b/std/typecons.d @@ -290,7 +290,7 @@ private: unittest { - struct Bar {int val;} + struct Bar {int val;} struct Foo { Unique!Bar bar = new Bar; } From 52110d98db4a3fe4087bc183b5e0b0883f846a28 Mon Sep 17 00:00:00 2001 From: Cauterite Date: Wed, 27 Jul 2016 00:18:42 +1000 Subject: [PATCH 3/4] appeasing the brace Nazis --- std/typecons.d | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/std/typecons.d b/std/typecons.d index eeac95729e4..03ea2cb5fe3 100644 --- a/std/typecons.d +++ b/std/typecons.d @@ -291,7 +291,8 @@ private: unittest { struct Bar {int val;} - struct Foo { + struct Foo + { Unique!Bar bar = new Bar; } From e50b77fbceefedb023524d0348c19af42eb1e576 Mon Sep 17 00:00:00 2001 From: Cauterite Date: Wed, 27 Jul 2016 01:41:31 +1000 Subject: [PATCH 4/4] document unittest --- std/typecons.d | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/std/typecons.d b/std/typecons.d index 03ea2cb5fe3..62cf0fb6b8f 100644 --- a/std/typecons.d +++ b/std/typecons.d @@ -288,7 +288,8 @@ private: assert(!uf2.isEmpty); } -unittest +// ensure Unique behaves correctly through const access paths +@system unittest { struct Bar {int val;} struct Foo