<html>
    <head>
      <base href="http://bugzilla.gdcproject.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Array assignment doesn't call destructors"
   href="http://bugzilla.gdcproject.org/show_bug.cgi?id=164">164</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Array assignment doesn't call destructors
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>GDC
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>4.9.x
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>Normal
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>gdc
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>ibuclaw@gdcproject.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>shachar@shemesh.biz
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=78" name="attach_78" title="Smart pointer example">attachment 78</a> <a href="attachment.cgi?id=78&action=edit" title="Smart pointer example">[details]</a></span>
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 <a href="https://issues.dlang.org/show_bug.cgi?id=13661">https://issues.dlang.org/show_bug.cgi?id=13661</a>).

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</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are watching all bug changes.</li>
      </ul>
    </body>
</html>