DMD 1.027 and 2.011 releases

Jason House jason.james.house at gmail.com
Mon Feb 25 18:49:09 PST 2008


Ary Borenszweig wrote:

> Walter Bright escribió:
>> Graham St Jack wrote:
>>>> It would work just like "nothrow" does for C++.
>>>
>>> Just checking - I hope this means that if a nothrow function actually
>>> DID try to throw an exception (by calling something that throws),
>>> compiler-
>>> generated code would trap it and terminate the program with an error
>>> message?
>> 
>> No, but it will try to detect errors at compile time.
> 
> Does this mean this will not compile:
> 
> int foo(int[] someArray, int someIndex) nothrow {
> return someArray[someIndex];
> }

I sincerely hope that design by contract will allow for us to iron out
issues like this.  Ideally, something very near the following should be
valid:

int foo(int[] someArray, int someIndex) nothrow
in{
  assert(someIndex < someArray.length && someIndex >= 0);
}
body{
  return someArray[someIndex];
}

I've always hoped for in and out contracts to be usable by the compiler for
optimization (such as verifying nothrow).  I know this looks like it
violates the nothrow (when not compiled with the release flag), but I'm ok
with that for code I'm debugging.  Printing the failed assert and ending
the program is more useful to me anyway.


More information about the Digitalmars-d-announce mailing list