bearophile Wrote:
> Before filing a possible bug report I prefer to ask here, because my ideas
> are often wrong.
> This is a small D2 program:
>
> nothrow void foo() {
> // auto a = new int[5]; // not allowed here
> int[int] aa;
> for (int i; i < 100_000_000; i++)
> aa[i] = i;
> }
> void main() {
> foo();
> }
>
> Inside that function foo() you can't put a "new int[5]" I presume because it
> can throw a memory overflow exception. But then why are insertions into an
> associative array allowed? Can't they produce the same memory overflow
> exception? In theory nothrow functions can forbid adding new items to
> associative arrays.
>
>
> [Related: In Python stack overflows are normal exceptions that you can catch,
> etc. But I presume it's OK for nothrow functions in D2 to not refuse the
> possibility of a stack overflow error, because essentially all D2 functions
> can produce stack overflows, if before calling them the stack was filled up.]
>
> Bye,
> bearophile
Allocations are allowed inside nothrow functions. If I remember correctly, the
reasons are that disallowing them would limit usefulness, and that
OutOfMemoryError is not generally recoverable.