Thread overview
Throw in a pre-condition of a nothrow function
Mar 08, 2013
bearophile
Mar 08, 2013
Maxim Fomin
Mar 08, 2013
Rob T
Mar 08, 2013
bearophile
March 08, 2013
Currently this code compiles:


void foo() nothrow
in {
    throw new Exception(null);
} body {
}
void main() {
    foo();
}



Then at runtime throws:

object.Exception@test.d(3)
---------
0x00402044 in nothrow void test.foo() at ...
...


Is this good? Isn't the "nothrow" tag used by the compiler to better optimize functions?

Bye,
bearophile
March 08, 2013
That's a bug. Interesting point here is whether it is a regression or not.
March 08, 2013
On Friday, 8 March 2013 at 19:39:47 UTC, bearophile wrote:
> Currently this code compiles:
[...]

Nice edge case to test the compiler with.

Definitely looks like a bug. It should not compile given the nothrow attrib.

If it was throwable, what to do about throwing a null reference is an interesting question.

--rt
March 08, 2013
Rob T:

> Definitely looks like a bug. It should not compile given the nothrow attrib.

http://d.puremagic.com/issues/show_bug.cgi?id=9669

Bye,
bearophile