Yet another leak in the sinking ship of @safe
Chris Wright via Digitalmars-d
digitalmars-d at puremagic.com
Thu Feb 18 15:41:13 PST 2016
On Thu, 18 Feb 2016 19:17:27 +0000, Era Scarecrow wrote:
> On Thursday, 18 February 2016 at 18:41:25 UTC, Steven Schveighoffer
> wrote:
>> On 2/18/16 1:30 PM, Timon Gehr wrote:
>>> No problem here. There is no way to assign to a void[] without doing
>>> 2.
>>
>> foo(void[] arr)
>> {
>> void[] arr2 = [1234, 5678, 91011];
>> arr[] = arr2[0 .. arr.length];
>> }
>
> Since void throws away type information (and all the safety
> related to it), would it be easier to simply require @safe code can't
> cast implicitly to void? It seems like explicit casting would take care
> of most of this, or disallowing to/from void converting period while in
> @safe code.
Casting *from* void[] is also a big issue. Disallow all implicit and
explicit casts between void[] and anything else to start, and we can look
at the rest case-by-caste.
We can probably cast to const(void)[] safely, and we can probably cast
arrays that contain no pointers to void[] safely. Casting from void[] to
const(T)[] where T contains no pointers (or arrays or functions or
delegates) should also be safe.
> To be honest, I think there's only 1 time I actually used a
> void[] in my code, and that was while writing a section in the BitArray
> replacement code years back in the case you wanted to use/read another
> block of data as the source for the BitArray. Beyond that I never
> touched it.
A lot of the IO stuff in Phobos uses void[]. std.socket is lousy with it.
I think the intention is that you can send arbitrary data over the wire
without having to explicitly marshal it into a ubyte[].
More information about the Digitalmars-d
mailing list