From bf6b0a9759beb95273b7f6b9a5dcf7b77dea62eb Mon Sep 17 00:00:00 2001 From: k-hara Date: Thu, 17 Jul 2014 12:39:09 +0900 Subject: [PATCH] fix Issue 13077 - std.range.array with shared InputRangeObject --- std/array.d | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/std/array.d b/std/array.d index 109456972ce..89eea8b62ba 100644 --- a/std/array.d +++ b/std/array.d @@ -2475,7 +2475,12 @@ if (isDynamicArray!A) auto bigDataFun() @trusted nothrow { return _data.arr.ptr[0 .. len + 1];} auto bigData = bigDataFun(); - emplaceRef!T(bigData[len], item); + static if (is(Unqual!T == T)) + alias uitem = item; + else + auto ref uitem() @trusted nothrow @property { return cast(Unqual!T)item; } + + emplaceRef!(Unqual!T)(bigData[len], uitem); //We do this at the end, in case of exceptions _data.arr = bigData; @@ -2947,7 +2952,8 @@ unittest } unittest -{ //9528 +{ + //9528 const(E)[] fastCopy(E)(E[] src) { auto app = appender!(const(E)[])(); foreach (i, e; src) @@ -2963,15 +2969,16 @@ unittest } unittest -{ //10753 +{ + //10753 struct Foo { immutable dchar d; } struct Bar { immutable int x; } - "12".map!Foo.array; - [1, 2].map!Bar.array; + "12".map!Foo.array; + [1, 2].map!Bar.array; } unittest @@ -3064,6 +3071,24 @@ unittest static assert(!is(typeof(appender(foo())))); } +unittest +{ + // Issue 13077 + static class A {} + + // reduced case + auto w = appender!(shared(A)[])(); + w.put(new shared A()); + + // original case + import std.range; + InputRange!(shared A) foo() + { + return [new shared A].inputRangeObject; + } + auto res = foo.array; +} + /++ Convenience function that returns a $(D RefAppender!A) object initialized with $(D array). Don't use null for the $(D array) pointer, use the other