www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18848] New: std.allocator: Regions are non-copyable, yet are


          Issue ID: 18848
           Summary: std.allocator: Regions are non-copyable, yet are
                    passed around in examples
           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 an example from

// Ouroboros allocator list based upon 4MB regions, fetched directly from
// mmap. All memory is released upon destruction.
alias A1 = AllocatorList!((n) => Region!MmapAllocator(max(n, 1024 * 4096)),

The example features a lambda returning a Region.

However, Regions cannot be copied, as they have a destructor which deallocates
everything. A comment in the implementation says:

    TODO: The postblit of $(D BasicRegion) should be disabled because such
    should not be copied around naively.

(That's the only occurrence of BasicRegion in Phobos, so I assume that's just
an old name for Region.)

Though NRVO may make the verbatim example code behave correctly, it is fragile,
and small code modifications e.g. to work around issue 18848 can cause
difficult-to-debug problems (due to dangling pointers in other Region

May 10 2018