Comment #0 by bearophile_hugs — 2014-03-24T15:58:27Z
(This is tagged as error instead of enhancement request.)
This wrong code surprisingly compiles and runs with no errors:
void main() {
import std.bitmanip: BitArray;
BitArray ba;
ba.length = 10;
auto b = ba[100];
}
Built-in D arrays have bound tests, so in not-release mode I'd like BitArray to give a run-time assert error on code like that. It helps me debug code that uses BitArrays.
Comment #1 by andrej.mitrovich — 2014-03-25T05:39:42Z
This is strange, because I can see this is checked in the in blocks:
-----
bool opIndex(size_t i) const
in
{
assert(i < len);
}
body
{
// Andrei: review for @@@64-bit@@@
return cast(bool) bt(ptr, i);
}
/**********************************************
* Sets the $(D i)'th bit in the $(D BitArray).
*/
bool opIndexAssign(bool b, size_t i)
in
{
assert(i < len);
}
body
{
if (b)
bts(ptr, i);
else
btr(ptr, i);
return b;
}
-----
Comment #2 by andrej.mitrovich — 2014-03-25T05:47:10Z
(In reply to comment #1)
> This is strange, because I can see this is checked in the in blocks:
Oh I see what's going on, Phobos is built with -release mode.
It seems to me that we should distribute both a -debug and -release mode version of the Phobos static library, and then allow the user to link with either one. I guess sc.ini can be manipulated in some way to enable this.. no idea.
Comment #3 by andrej.mitrovich — 2014-04-23T20:00:26Z
(In reply to Andrej Mitrovic from comment #2)
> (In reply to comment #1)
> > This is strange, because I can see this is checked in the in blocks:
>
> Oh I see what's going on, Phobos is built with -release mode.
>
> It seems to me that we should distribute both a -debug and -release mode
> version of the Phobos static library, and then allow the user to link with
> either one. I guess sc.ini can be manipulated in some way to enable this..
> no idea.
So this is a generic problem with distribution. I wonder if there's an open bug for Phobos static lib not being distributed with debug mode..
Comment #4 by bugzilla — 2019-12-08T07:54:31Z
IMHO, the assert is wrong. It should be an exception in the body of the function (probably enforce), because this can be triggered by user input.
Comment #5 by robert.schadek — 2024-12-01T16:20:39Z