Skip to content

Commit 91434fc

Browse files
CyberShadow0xEAB
authored andcommitted
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 a7e90e9 commit 91434fc

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
@@ -104,11 +104,6 @@ struct Region(ParentAllocator,
104104
this(cast(ubyte[]) (parent.allocate(n.roundUpToAlignment(alignment))));
105105
}
106106

107-
/*
108-
TODO: The postblit of `BasicRegion` should be disabled because such objects
109-
should not be copied around naively.
110-
*/
111-
112107
/**
113108
If `ParentAllocator` defines `deallocate`, the region defines a destructor
114109
that uses `ParentAllocator.deallocate` to free the memory chunk.
@@ -119,6 +114,13 @@ struct Region(ParentAllocator,
119114
with (_impl) parent.deallocate(_begin[0 .. _end - _begin]);
120115
}
121116

117+
/**
118+
`Region` deallocates on destruction (see above), therefore is not copyable.
119+
*/
120+
static if (!is(ParentAllocator == NullAllocator)
121+
&& hasMember!(ParentAllocator, "deallocate"))
122+
@disable this(this);
123+
122124
/**
123125
Rounds the given size to a multiple of the `alignment`
124126
*/

0 commit comments

Comments
 (0)