Skip to content

Commit 24050c5

Browse files
committed
Fix Issue 18848 - std.allocator: Regions are non-copyable, yet are passed around in examples
This doesn't fix that non-copyable regions are still passed around in examples, so we still rely on NRVO to do its thing and elide the copy, but at least this will now catch wrong code that mistakenly copied Regions around.
1 parent 27a8757 commit 24050c5

File tree

1 file changed

+7
-5
lines changed
  • std/experimental/allocator/building_blocks

1 file changed

+7
-5
lines changed

std/experimental/allocator/building_blocks/region.d

+7-5
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,6 @@ struct Region(ParentAllocator = NullAllocator,
9696
this(cast(ubyte[]) (parent.allocate(n.roundUpToAlignment(alignment))));
9797
}
9898

99-
/*
100-
TODO: The postblit of `BasicRegion` should be disabled because such objects
101-
should not be copied around naively.
102-
*/
103-
10499
/**
105100
If `ParentAllocator` is not $(REF_ALTTEXT `NullAllocator`, NullAllocator, std,experimental,allocator,building_blocks,null_allocator) and defines `deallocate`,
106101
the region defines a destructor that uses `ParentAllocator.deallocate` to free the
@@ -113,6 +108,13 @@ struct Region(ParentAllocator = NullAllocator,
113108
parent.deallocate(_begin[0 .. _end - _begin]);
114109
}
115110

111+
/**
112+
`Region` deallocates on destruction (see above), therefore is not copyable.
113+
*/
114+
static if (!is(ParentAllocator == NullAllocator)
115+
&& hasMember!(ParentAllocator, "deallocate"))
116+
@disable this(this);
117+
116118
/**
117119
Rounds the given size to a multiple of the `alignment`
118120
*/

0 commit comments

Comments
 (0)