relax disabled Final!T unary operators

via Digitalmars-d digitalmars-d at puremagic.com
Wed Mar 29 13:11:11 PDT 2017


On Wednesday, 29 March 2017 at 17:59:10 UTC, H. S. Teoh wrote:
> On Fri, Mar 24, 2017 at 11:00:20AM -0700, H. S. Teoh via 
> Digitalmars-d wrote:
>> (Just wait till I try it on a union... that's gonna throw 
>> things off,
>> I'm almost certain.)
> [...]
>
> And just as I predicted:
>
> 	https://issues.dlang.org/show_bug.cgi?id=17284
>
> In a nutshell: the compiler rejects assigning to pointer fields 
> in a union when in @safe code (for obvious reasons), but to 
> work around that, just write Final!U instead, and you can 
> freely assign overlapping pointers in @safe code willy-nilly.
>
> I think Final should be modified so that it outright rejects 
> PODs and unions, at the minimum, if not structs as well.
>
> I think it's a bad idea to have it accept structs and then 
> allow modifying struct members.  This would prohibit things 
> like Final!(RefCounted!T), for example; but if anybody wants to 
> use Final on a RefCounted object, they should perhaps use 
> RefCounted!(Final!T) instead.
>
>
> T

As I explained in the bug report 
(https://issues.dlang.org/show_bug.cgi?id=17284) the particular 
@safe-ty issue has nothing to do with Final. That said, I agree 
that Final is wrongly designed. In fact I argued that it should 
reject structs even before the PR was merged, but I didn't have 
much free time time to defend my position back then: 
https://github.com/dlang/phobos/pull/3862#issuecomment-199164913



More information about the Digitalmars-d mailing list