Issue 13537: forbid modifying overlapping mutable/immutable fields in @safe code#5467
Issue 13537: forbid modifying overlapping mutable/immutable fields in @safe code#5467quickfur wants to merge 2 commits intodlang:masterfrom
Conversation
|
|
Does this help with memory safety? |
|
Not directly, no. But potentially it might prevent an illegal attempt to modify read-only memory. |
|
Does this also work with nested anonymous unions? |
|
It seems to work: Compiler output: Changing the last line to Did you have a specific test case in mind? |
|
No, I just tried to fix this problem before and I couldn't figure out how to make it work for anonymous unions. |
|
ping @WalterBright @yebblies |
|
Is overlapping const and immutable allowed? |
|
Yes. |
|
It looks to me like it isn't with this patch... Could I get a test case added for it? |
|
Added a test case... though I'm not sure how exactly to test this, since const/immutable by definition means you can't modify anything, so it's not as if you could test that assigning to the const field is allowed. |
|
This should be extended so that using unions to bypass qualifiers shared, const, immutable, and inout should not be allowed in safe code. |
|
Then what should we do about |
|
Since it cannot be mechanically verified as safe, then yes, it has to be trusted (if it is actually safe). |
|
Are you planning on moving forward with this or should I take it over? |
|
I'm short on time to work on this right now, please take this over so that it doesn't get delayed any longer. Thanks! |
|
Rebooted as #5940 |
This implementation is a compromise; it only prevents immutable breakage in
@safecode, but still allows this in@systemcode, because forbidding it in@systemcode would break existing code such asstd.typecons.Rebindablethat use a union to reinterpret type modifiers.