Comment #0 by bearophile_hugs — 2010-08-26T06:25:39Z
This enhancement request comes from bug 4005
Currently (dmd 2.048) the following program prints:
test.d(3): Error: exit cannot be interpreted at compile time, because it has no available source code
test.d(6): Error: cannot evaluate foo() at compile time
test.d(6): Error: static assert (foo() == 100) is not evaluatable at compile time
import std.c.stdlib: exit;
int foo() {
exit(1);
return 100;
}
static assert(foo() == 100);
void main() {}
I'd like exit() to work at compile-time too, and stop the compilation gracefully (dmd return value is the value given to exit()).
See also bug 3952
Comment #1 by clugdbug — 2011-06-23T00:52:15Z
Implementing a complicated corner case for an obscure and dangerous feature would
need a extremely powerful rationale.
Marking as INVALID rather WONTFIX, because the bug report doesn't have any use case at all.
To give an idea of the complexity: consider what would happen if it were called speculatively, eg in a template constraint.
Comment #2 by doob — 2011-06-23T02:09:29Z
Isn't this exactly what static assert is for?
Comment #3 by bearophile_hugs — 2011-06-24T16:26:25Z
(In reply to comment #1)
I don't reopen this enhancement request because I trust your judgement, but here are some answers:
> Marking as INVALID rather WONTFIX, because the bug report doesn't have any use case at all.
Sometimes to debug normal run-time code I add a printf() followed by an exit() becuse I don't need the computation to continue after the debug print. The compile-time exit was meant to be used like that, with the compile-time string print of bug 3952 (that doesn't print a newline after the string).
> consider what would happen if it were called speculatively, eg in a template constraint.
It's an exit(), so it has to stops the whole compiler and the whole compilation stack.