digitalmars.D.learn - Safe code doesnt seem to complain when it should
- HuskyNator (14/14) Jan 06 2022 I can't figure out why this code works:
- Paul Backus (6/20) Jan 06 2022 This is a known bug in the compiler's inference of the `@safe`
I can't figure out why this code works: ```d union A { int* b; float c; } int fun(A a) safe { return *(()=>a.b)(); // return *a.b; //Complains about pointer type overlap } ``` I tried to find out how ` safe` should be handled in this scenario, and found [lambda's could be denoted as trusted](https://dlang.org/blog/2016/09/28/how-to-write-trusted-code-in-d/#:~:text=is%20used%20instead.-,%40trusted%20escapes,-A%20% 0trusted%20escape), but this even works without a ` trusted` denotation. Am I missing something?
Jan 06 2022
On Thursday, 6 January 2022 at 16:12:10 UTC, HuskyNator wrote:I can't figure out why this code works: ```d union A { int* b; float c; } int fun(A a) safe { return *(()=>a.b)(); // return *a.b; //Complains about pointer type overlap } ``` I tried to find out how ` safe` should be handled in this scenario, and found [lambda's could be denoted as trusted](https://dlang.org/blog/2016/09/28/how-to-write-trusted-code-in-d/#:~:text=is%20used%20instead.-,%40trusted%20escapes,-A%20% 0trusted%20escape), but this even works without a ` trusted` denotation. Am I missing something?This is a known bug in the compiler's inference of the ` safe` attribute. * Bug report: https://issues.dlang.org/show_bug.cgi?id=20655 * Fix PR: https://github.com/dlang/dmd/pull/10884 Looks like the fix is currently blocked due to other issues.
Jan 06 2022