www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20651] New: Document that destructors may not allocate memory

https://issues.dlang.org/show_bug.cgi?id=20651

          Issue ID: 20651
           Summary: Document that destructors may not allocate memory
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dlang.org
          Assignee: nobody puremagic.com
          Reporter: default_357-line yahoo.de

Consider the code from issue 20650:

class Foo { ~this() { new int; } }
void main() { new Foo; }

This runs into
core.exception.InvalidMemoryOperationError src/core/exception.d(647): Invalid
memory operation .

The reason is that the GC may not be invoked during finalizers, ie. when
destructors are run. There is almost never a reason to do this; however, this
should still be documented in the language spec at
https://dlang.org/spec/class.html#destructors .

--
Mar 09 2020