Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
August 17, 2012 cast oddities - void* <-> AA | ||||
---|---|---|---|---|
| ||||
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 |
August 17, 2012 Re: cast oddities - void* <-> AA | ||||
---|---|---|---|---|
| ||||
Posted in reply to Iain Buclaw | 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/
|
August 18, 2012 Re: cast oddities - void* <-> AA | ||||
---|---|---|---|---|
| ||||
Posted in reply to Iain Buclaw | 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
|
August 18, 2012 Re: cast oddities - void* <-> AA | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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. |
August 18, 2012 Re: cast oddities - void* <-> AA | ||||
---|---|---|---|---|
| ||||
Posted in reply to Iain Buclaw | 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
|
Copyright © 1999-2021 by the D Language Foundation