D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11015 - BitArray.opCom is invalid on 64 bit machines
Summary: BitArray.opCom is invalid on 64 bit machines
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 All
: P2 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2013-09-12 01:33 UTC by nbelov
Modified: 2020-03-21 03:56 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description nbelov 2013-09-12 01:33:01 UTC
result.ptr[dim - 1] &= ~(~0 << (len & (bitsPerSizeT-1)));
On 64 bit machine 0 - is 32 bit value, but bitsPerSizeT == 64.

Need add cast 0 to size_t:
result.ptr[dim - 1] &= ~(~cast(size_t)0 << (len & (bitsPerSizeT-1)));


Test:
       foreach (len; 1 .. 256)
        {
            foreach (i; 0 .. len)
            {
                BitArray a1; a1.length = len;
                foreach (j; 0 .. len)
                {
                    a1[j] = true;
                }

                a1[i] = false;

                BitArray a2; a2.length = len;
                a2[i] = true;
                BitArray a3 = ~a2;

                assert(a3 == a1);
            }
        }

For reproduce you need fix opEquals (see bug #10948: http://d.puremagic.com/issues/show_bug.cgi?id=10948)