www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18847] New: std.allocator: Region uses .parent before it can

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

          Issue ID: 18847
           Summary: std.allocator: Region uses .parent before it can be
                    set
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: dlang-bugzilla thecybershadow.net
                CC: andrei erdani.com

Here is one constructor of
std.experimental.allocator.building_blocks.region.Region:

    static if (!is(ParentAllocator == NullAllocator))
    this(size_t n)
    {
        this(cast(ubyte[])(parent.allocate(n.roundUpToAlignment(alignment))));
    }

If parent has state, then there is no way to set it before it is used in the
constructor.

There is a workaround: copy the contents of the constructor of the invoking
code, then use the constructor taking a buffer, and only then initialize the
parent. This is sub-ideal.

The constructor(s) should probably accept a parent argument as needed, or the
object should support deferred initialization.

--
May 10 2018