Do a class invariants affect -release builds?

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Dec 5 16:33:33 PST 2015


On 12/5/15 6:54 PM, Chris Wright wrote:

> I've never used a release build of anything. Bounds checking isn't that
> expensive.
>

void main()
{
     int[] arr = new int[10];
     assert(arr.capacity == 1000); // obviously wrong
     arr[10] = 5;
}

dmd -release -boundscheck=on testboundscheck.d

./testboundscheck

core.exception.RangeError at testboundscheck.d(5): Range violation
----------------
4   testboundscheck                     0x000000010df8454d 
_d_arraybounds + 97
5   testboundscheck                     0x000000010df77da6 
testboundscheck.__array + 38
6   testboundscheck                     0x000000010df77d71 _Dmain + 49
7   testboundscheck                     0x000000010df94e83 
D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv + 39
8   testboundscheck                     0x000000010df94dbb void 
rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) + 55
9   testboundscheck                     0x000000010df94e28 void 
rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).runAll() + 44
10  testboundscheck                     0x000000010df94dbb void 
rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) + 55
11  testboundscheck                     0x000000010df94d0d _d_run_main + 497
12  testboundscheck                     0x000000010df77e0f main + 15
13  libdyld.dylib                       0x00007fff928d15c8 start + 0
14  ???                                 0x0000000000000000 0x0 + 0

-Steve


More information about the Digitalmars-d-learn mailing list