D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 14860 - Destructor is not called for block assignment
Summary: Destructor is not called for block assignment
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 major
Assignee: No Owner
URL:
Keywords: pull, wrong-code
Depends on:
Blocks:
 
Reported: 2015-08-02 02:03 UTC by Kenji Hara
Modified: 2017-07-22 12:36 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Kenji Hara 2015-08-02 02:03:56 UTC
It's similar to 14815.

From: http://forum.dlang.org/thread/wkwzokdccfbjnzeqmqmz@forum.dlang.org

uint dtorCount;

struct S
{
    uint x;
    void opAssign(const ref S rhs) { assert(false, "Not called"); }
    ~this() { ++dtorCount; }
}

void main()
{
    S[] a;
    a.length = 1;
    a[0].x = 42; // Some random non-init value

    a[] = S.init;

    assert(a[0].x == 0); // As expected, the value has been reset
    assert(dtorCount == 0); // Passes?!?
}
Comment 2 github-bugzilla 2015-08-02 11:07:55 UTC
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/35f1f6226aa523305e41f3dee68fbb0ce8fafdf4
Supplemental fix for issue 14860

`task[] = RTask.init;` has two bugs:

1. `RTask` is a nested struct, so `RTask.init` contains null context pointer.
2. That is a block assignment, so there is a possibility to call
   `RTask.~this()` on garbage objects (stack allocated `buf` is initialized by `void`).

Fixed to use `emplaceRef` on each elements.

https://github.com/D-Programming-Language/phobos/commit/deeab6c867fbed479fe57604a52f25e360f0b410
Merge pull request #3522 from 9rnsr/fix14860

Supplemental fix for issue 14860
Comment 3 github-bugzilla 2015-08-02 14:58:52 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/fd8af3a98e1deb370aecf940c939f8a7794a850e
fix Issue 14860 - Destructor is not called for block assignment

https://github.com/D-Programming-Language/dmd/commit/286906ba8ffe9e75905998fd99a6349b7a0f6b4e
Merge pull request #4856 from 9rnsr/fix14860

Issue 14860 - Destructor is not called for block assignment
Comment 5 github-bugzilla 2017-07-22 12:36:16 UTC
Commits pushed to dmd-cxx at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/fd8af3a98e1deb370aecf940c939f8a7794a850e
fix Issue 14860 - Destructor is not called for block assignment

https://github.com/dlang/dmd/commit/286906ba8ffe9e75905998fd99a6349b7a0f6b4e
Merge pull request #4856 from 9rnsr/fix14860