D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 14595 - [REG2.066] RefCounted data corrupted when in an AA
Summary: [REG2.066] RefCounted data corrupted when in an AA
Status: RESOLVED DUPLICATE of issue 14321
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2015-05-17 02:04 UTC by Vladimir Panteleev
Modified: 2020-02-08 08:55 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 Vladimir Panteleev 2015-05-17 02:04:08 UTC
/////////////// test.d //////////////
import std.typecons;

alias ObjectWriter = RefCounted!int;

ObjectWriter[string] writers;

void main()
{
    writers[null] = ObjectWriter(42);
    auto pwriter = null in writers;
    assert(*pwriter == 42);
}
/////////////////////////////////////

Assertion fails on Linux/64.

Introduced in https://github.com/D-Programming-Language/dmd/pull/3672
Comment 1 Vladimir Panteleev 2015-05-17 03:08:37 UTC
I have reduced the above to the following code:

//////////// test.d ////////////
struct S
{
    this(int) { }

    bool okToDestroy;

    ~this()
    {
        assert(okToDestroy);
    }
}

S[string] aa;

void main()
{
    aa[null] = S(42);
    aa[null].okToDestroy = true;
}
////////////////////////////////

But this reduction does not manifest as a regression.
Comment 2 Vladimir Panteleev 2015-05-17 03:38:41 UTC
Alternative reduction:

//////// test.d ////////
struct S
{
    int* count;

    this(int)
    {
        count = new int;
        *count = 1;
    }

    this(this)
    {
        ++count;
    }

    ~this()
    {
        --*count;
    }
}

S[string] aa;

void main()
{
    aa[null] = S(42);
    auto p = null in aa;
    assert(*p.count);
}
////////////////////////

2.064.2: works
2.065.0: ICE
2.066.1: assert fails
Comment 3 Vladimir Panteleev 2015-05-17 03:40:21 UTC
(In reply to Vladimir Panteleev from comment #2)
>         ++count;

Should be ++*count
Comment 4 Kenji Hara 2015-06-01 12:24:28 UTC
The root problem is same with issue 14321, and it's already fixed in git-head (2.068a).

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