digitalmars.D - cast oddities - void* <-> AA
- Iain Buclaw (28/28) Aug 17 2012 Discovered this through some other issue when finishing up the
- Iain Buclaw (2/5) Aug 17 2012 s/scalar/non-scalar/
- bearophile (4/6) Aug 17 2012 Accepting the cast of an AA to void* seems bad.
- Richard Webb (4/4) Aug 18 2012 fwiw, I raised a bug about this on Orange a while back:
- David Nadlinger (6/18) Aug 18 2012 I also once encountered some cases where the DMD frontend would
Discovered this through some other issue when finishing up the latest frontend merge. In the following example, I feel that this should not compile at all. void main() { int[int] a; void* b = cast(void*)a; } Given that the definition of an AA is (as defined in rt.aaA): struct AA { void* a; } Similarly for this code: void main() { int[int] a; void* b; a = cast(int[int]) b; // fails a = cast(int[int]) &b; // works } Correct me if I'm wrong, but both examples should warrant bug reports. NB: These examples don't compile on GDC because of the safe guards from directly converting between scalar and pointer types. Regards Iain
Aug 17 2012
On Friday, 17 August 2012 at 22:15:10 UTC, Iain Buclaw wrote:NB: These examples don't compile on GDC because of the safe guards from directly converting between scalar and pointer types.s/scalar/non-scalar/
Aug 17 2012
Iain Buclaw:Correct me if I'm wrong, but both examples should warrant bug reports.Accepting the cast of an AA to void* seems bad. Bye, bearophile
Aug 17 2012
fwiw, I raised a bug about this on Orange a while back: https://github.com/jacob-carlborg/orange/issues/17. I thought it a bit odd that it compiled in DMD at the time, but i don't think i opened a bug about it.
Aug 18 2012
On Friday, 17 August 2012 at 22:15:10 UTC, Iain Buclaw wrote:In the following example, I feel that this should not compile at all. void main() { int[int] a; void* b = cast(void*)a; } Given that the definition of an AA is (as defined in rt.aaA): struct AA { void* a; }I also once encountered some cases where the DMD frontend would allow conversions between structs and scalar types or other unrelated structs which happened to have the same member layout – which broke LDC, as the LLVM IR is typed. David
Aug 18 2012