How to cast `shared` away reliably
Nick Treleaven
nick at geany.org
Sat Feb 14 15:43:40 UTC 2026
On Wednesday, 11 February 2026 at 21:12:31 UTC, Nick Treleaven
wrote:
> On Wednesday, 11 February 2026 at 16:49:19 UTC, Arafel wrote:
>> https://dlang.org/spec/type.html#derived-data-types
>>
>> However, of the items listed there, pointers are indeed
>> showing this behaviour, but functions and delegates aren't.
>
> A type qualifier on a delegate type applies to its context
> pointer, it does nothing for function (pointer) types.
Sorry, that was wrong - see Paul Backus's reply.
...
>> cast() foo = &i; // WORKS!!
>
> I think due to the `alias this` it is actually doing this:
>
> (cast() foo).t = &i; // WORKS!!
>
> That is a bit confusing. The cast gives you `Pointer!int`. I
> think the docs here need to mention that:
> https://dlang.org/spec/expression.html#cast_qualifier
>
> Note that this does not work:
>
> cast() foo.t = &i; // error, `shared(int)*` = `int*`
>
>> cast() bar = &i; // FAILS
>
> Because that does `shared(int)*` = `int*`, which is a type
> error.
BTW the git docs have now been updated to describe qualifier
casts in more detail:
https://github.com/dlang/dlang.org/pull/4395
More information about the Digitalmars-d
mailing list