digitalmars.D - nothrow functions/methods
- bearophile (15/15) Feb 28 2010 Before filing a possible bug report I prefer to ask here, because my ide...
- Daniel Murphy (2/22) Feb 28 2010 Allocations are allowed inside nothrow functions. If I remember correct...
- bearophile (9/10) Feb 28 2010 OK. Then can you tell me why the following program produces:
- Don (2/15) Feb 28 2010 That's clearly a bug.
- bearophile (6/7) Feb 28 2010 Thank you for your answer Don.
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
Feb 28 2010
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, bearophileAllocations 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.
Feb 28 2010
Daniel Murphy: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.<OK. Then can you tell me why the following program produces: test2.d(1): Error: function test2.foo 'foo' is nothrow yet may throw nothrow void foo() { auto a = new int[5]; } void main() {} Bye, bearophile
Feb 28 2010
bearophile wrote:Daniel Murphy:That's clearly a bug.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.<OK. Then can you tell me why the following program produces: test2.d(1): Error: function test2.foo 'foo' is nothrow yet may throw nothrow void foo() { auto a = new int[5]; } void main() {} Bye, bearophile
Feb 28 2010
Don:That's clearly a bug.Thank you for your answer Don. http://d.puremagic.com/issues/show_bug.cgi?id=3864 (In future I will even start trying to fix them.) Bye, bearophile
Feb 28 2010