Bug 18848 – std.allocator: Regions are non-copyable, yet are passed around in examples

Status
NEW
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-05-10T11:21:07Z
Last change time
2024-12-01T16:33:41Z
Keywords
pull
Assigned to
Eduard Staniloiu
Creator
Vladimir Panteleev
Moved to GitHub: phobos#10334 →

Comments

Comment #0 by dlang-bugzilla — 2018-05-10T11:21:07Z
Here is an example from std.experimental.allocator.building_blocks.allocator_list.AllocatorList: // 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)), NullAllocator); 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 objects 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 instances).
Comment #1 by dlang-bugzilla — 2018-05-15T23:03:19Z
https://github.com/dlang/phobos/pull/6509 See the comment there for more discussion.
Comment #2 by robert.schadek — 2024-12-01T16:33:41Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10334 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB