Thread overview
[Issue 6195] New: [GSoC] opSlice defined on range prevents call to postblit.
Jun 22, 2011
Cristi Cobzarenco
Apr 24, 2012
SomeDude
Apr 25, 2012
Kenji Hara
June 22, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6195

           Summary: [GSoC] opSlice defined on range prevents call to
                    postblit.
           Product: D
           Version: D2
          Platform: All
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: cristi.cobzarenco@gmail.com


--- Comment #0 from Cristi Cobzarenco <cristi.cobzarenco@gmail.com> 2011-06-22 08:52:02 PDT ---
import std.stdio;

struct Test {
    int count;

    this( int x )                { count = x; }
    this( this )                 { writeln("Postblit!"); }

    typeof(this)   opSlice()     { return this; }
    int            front() const { return 42; }
    @property bool empty() const { return count == 0; }
    void           popFront()    { --count; }

}

int main(string[] argv) {
    auto v = Test(5);

    foreach( x ; v )
        writeln( x );
    writeln( "Count: ", v.count );
    return 0;
}

In the code above "Postblit!" doesn't get written, but a copy of v is
definitely created since "Count: 5" gets printed. It seems that foreach() calls
opSlice and for some reason the returned object gets blitted without calling
the postblit ctor (maybe a misguided return value optimization?).
Removing the opSlice() definition results in correct behaviour.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 24, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6195


SomeDude <lovelydear@mailmetrash.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lovelydear@mailmetrash.com


--- Comment #1 from SomeDude <lovelydear@mailmetrash.com> 2012-04-24 11:30:03 PDT ---
With 2.059, the output is:
PS E:\DigitalMars\dmd2\samples> rdmd bug
Postblit!
42
42
42
42
42
Count: 5
PS E:\DigitalMars\dmd2\samples>

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 25, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6195


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2012-04-24 18:19:32 PDT ---
Maybe a dup of 4437.

*** This issue has been marked as a duplicate of issue 4437 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------