[Bug 164] New: Array assignment doesn't call destructors

via D.gnu d.gnu at puremagic.com
Tue Nov 4 22:29:35 PST 2014


http://bugzilla.gdcproject.org/show_bug.cgi?id=164

            Bug ID: 164
           Summary: Array assignment doesn't call destructors
           Product: GDC
           Version: 4.9.x
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: Normal
         Component: gdc
          Assignee: ibuclaw at gdcproject.org
          Reporter: shachar at shemesh.biz

Created attachment 78
  --> http://bugzilla.gdcproject.org/attachment.cgi?id=78&action=edit
Smart pointer example

Please consider the RAII smart pointer implementation attached. The smart
pointer is implemented following the rule of three.

The unit test, however, fails on line 137. When a static array is being
initialized over with the array's init, GDC neither calls the destructors nor
uses opAssign, causing a resource leak. This problem also exists in DMD, and
was filed there (see https://issues.dlang.org/show_bug.cgi?id=13661).

Changing the static if at line 108 to false, we reset the array by using array
iteration to assign to the individual elements. This variant passes on DMD, but
fails on GDC.

Lastly, changing the static if at line 110 to false, we perform an actual loop
over the elements. This passes on all compilers.

To the best of my understanding:
array type[4] a;

the following three lines should be completely equivalent:
a = a.init;
a[] = type.init;
foreach(ref i; a) i = type.init;

Shachar

-- 
You are receiving this mail because:
You are watching all bug changes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/d.gnu/attachments/20141105/df4e262e/attachment.html>


More information about the D.gnu mailing list