http://d.puremagic.com/issues/show_bug.cgi?id=7530

           Summary: Postblit not called structs returned from an array
                    index expr.
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: slud...@outerproduct.org


--- Comment #0 from S´┐Żnke Ludwig <slud...@outerproduct.org> 2012-02-17 04:15:29 
PST ---
Created an attachment (id=1076)
Reproduction case

Attached is a small example with a pseudo RefCount struct.
Running with the ternary operator enabled "dmd -version=BUG -run" yields:

---
1st pass
CREATE 18FE34 1
COPY 443FD0 2
DESTROY 18FE34 2 IN
DESTROY 18FE34 1 OUT
POS2: 443FD0 1
DESTROY 18FE5C 1 IN          <- destroys the object although the static
DESTROY 18FE5C -100 OUT         array should still hold a reference

2nd pass
POS1: 443FD0 0               <- the static variable now references an
POS2: 443FD0 0                  already destroyed object
DESTROY 18FE5C 0 IN
DESTROY 18FE5C -1 OUT
---

The line "return cnt[0];" fails to call the struct's postblit and
causes the returned object to get destroyed as the ref count goes to
zero.

running with "dmd -run" yields the expected output:

---
1st pass
CREATE 18FE34 1
COPY 4B3FD0 2
DESTROY 18FE34 2 IN
DESTROY 18FE34 1 OUT
POS2: 4B3FD0 1
COPY 18FE5C 2                 <- correctly copied on return
DESTROY 18FE5C 2 IN
DESTROY 18FE5C 1 OUT

2nd pass
POS1: 4B3FD0 1
POS2: 4B3FD0 1
COPY 18FE5C 2                 <- correctly copied on return
DESTROY 18FE5C 2 IN
DESTROY 18FE5C 1 OUT          <- the static reference is still there
---

"auto ret = cnt[0]; return ret;" will correctly call the postblit constructor.

Occurs at least in DMD 2.058 and 2.057.

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

Reply via email to