[Issue 18804] std.algorithm.mutation.copy puts whole source range into target range when it should put elements

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Apr 30 01:07:11 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=18804

ag0aep6g <ag0aep6g at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
                 CC|                            |ag0aep6g at gmail.com
          Component|dmd                         |phobos
           Hardware|x86                         |All
            Summary|Side effects incorrectly    |std.algorithm.mutation.copy
                   |optimized out when results  |puts whole source range
                   |are discarded               |into target range when it
                   |                            |should put elements
                 OS|Windows                     |All

--- Comment #1 from ag0aep6g <ag0aep6g at gmail.com> ---
Generally, please post complete code, including imports. Also include the
contents of other files like "in".

What happens here is that `copy` puts the range as a whole into the NullSink.
This is not DMD optimizing anything out.

Reduced test case:

----
import std.algorithm.mutation: copy;

struct NullSink
{
    void put(E)(E) {}
}

int line = 0;

struct R
{
    int front;
    @property bool empty() { return line == 1; }
    void popFront() { line = 1; }
}

void main()
{
    R r;
    copy(r, NullSink());
    assert(line == 1); /* fails; should pass */
}
----

Pull request to fix this:
https://github.com/dlang/phobos/pull/6485

--


More information about the Digitalmars-d-bugs mailing list