D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7783 - compiler generated struct equality doesn't compare array fields
Summary: compiler generated struct equality doesn't compare array fields
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-25 22:10 UTC by Martin Nowak
Modified: 2012-03-26 13:38 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Martin Nowak 2012-03-25 22:10:53 UTC
cat > bug.d << CODE
struct Foo
{
    string name;
    bool b;
}

void main()
{
    auto a = Foo("foobar".idup, true);
    auto b = Foo("foobar".idup, true);
    assert(a == b);
}
CODE

dmd -run bug

--------

The structures are compared bitwise which fails here.
Comment 1 Kenji Hara 2012-03-25 23:54:49 UTC
I think this is just same as bug 3789.
Comment 2 Walter Bright 2012-03-26 00:37:49 UTC
In the absense of a user-defined opEquals for the struct, equality is defined as a bitwise compare. This is working as expected. Not a bug.
Comment 3 bearophile_hugs 2012-03-26 04:27:27 UTC
(In reply to comment #2)
> In the absense of a user-defined opEquals for the struct, equality is defined
> as a bitwise compare. This is working as expected. Not a bug.

See my answer in Bug 3789 .
Comment 4 Martin Nowak 2012-03-26 13:38:49 UTC
I didn't found the specs.
http://dlang.org/expression.html#EqualExpression