std.uni.ReallocPolicy question

Steven Schveighoffer schveiguy at gmail.com
Thu Dec 13 16:26:35 UTC 2018


On 12/12/18 4:42 AM, Eduard Staniloiu wrote:
> Anybody knows why `std/uni.ReallocPolicy`'s `realloc` and `destroy` are 
> `@trusted`?
> Those were introduced by this PR: 
> https://github.com/dlang/phobos/pull/6041/files
> 
> `realloc` and `destroy` are never `@safe` solely from their point of 
> view, as they don't know if there are any references to the memory they 
> are freeing. The caller has this information and he can safely make the 
> call to them `@trusted`.

>From the stand point of that PR, nothing changed except the ability to 
build with dip1000 I think. Instead of the struct being tagged @safe, 
and the functions inside tagged @trusted, the whole thing was tagged 
@trusted.

And I 100% agree, that shouldn't have been @safe or @trusted ever.

The correct way to do this would be to hoist the @trusted tag out to the 
usage of those structs. But I don't know enough about the code to make 
an informed recommendation.

-Steve


More information about the Digitalmars-d mailing list