digitalmars.D - Casting between Structs
- Jonathan Marler (20/20) Feb 08 2020 I reduced an issue in my project to this code snippet:
- jxel (7/28) Feb 08 2020 The spec is wrong in many aspects. It was written then never
- Jonathan Marler (4/9) Feb 08 2020 I hope you're wrong about this. Can someone in D leadership
- Jonathan Marler (4/15) Feb 08 2020 I've created a bug here: "Struct Cast Not Documented or
- Walter Bright (2/4) Feb 13 2020 It shouldn't compile. I'd have to investigate with the implementation.
I reduced an issue in my project to this code snippet: struct Struct1 { } struct Struct2 { } void func1(const Struct1); void func2() { Struct2 s; func1(cast(Struct1)s); } DMD compiles this just fine but according to the spec this should not compile. The spec (https://dlang.org/spec/expression.html#CastExpression section 8) says that "Casting a value v to a struct S, when value is not a struct of the same type, is equivalent to: S(v)", however, if I write Struct1(s) in this example, I get a compile error. Is the spec wrong or is this a problem in the DMD compiler? P.S. this snippet causes LDC to segfault (https://github.com/ldc-developers/ldc/issues/3314), but it's not clear whether it should be made to work like DMD, or if they should conform to the spec and make this a compile error
Feb 08 2020
On Saturday, 8 February 2020 at 17:36:17 UTC, Jonathan Marler wrote:I reduced an issue in my project to this code snippet: struct Struct1 { } struct Struct2 { } void func1(const Struct1); void func2() { Struct2 s; func1(cast(Struct1)s); } DMD compiles this just fine but according to the spec this should not compile. The spec (https://dlang.org/spec/expression.html#CastExpression section 8) says that "Casting a value v to a struct S, when value is not a struct of the same type, is equivalent to: S(v)", however, if I write Struct1(s) in this example, I get a compile error. Is the spec wrong or is this a problem in the DMD compiler? P.S. this snippet causes LDC to segfault (https://github.com/ldc-developers/ldc/issues/3314), but it's not clear whether it should be made to work like DMD, or if they should conform to the spec and make this a compile errorThe spec is wrong in many aspects. It was written then never followed. Not sure if it even gets updated. This seems like it should be an error. I don't know why you would ever want to do a cast like that, especially with lvalues. And if you did want to there is an easy alternative *cast(S1*)&v.
Feb 08 2020
On Saturday, 8 February 2020 at 19:28:26 UTC, jxel wrote:On Saturday, 8 February 2020 at 17:36:17 UTC, Jonathan Marler wrote:I hope you're wrong about this. Can someone in D leadership please prove this statement wrong by clarifying whether this is a bug in DMD or a missing feature in the spec?[...]The spec is wrong in many aspects. It was written then never followed. Not sure if it even gets updated.
Feb 08 2020
On Sunday, 9 February 2020 at 01:54:36 UTC, Jonathan Marler wrote:On Saturday, 8 February 2020 at 19:28:26 UTC, jxel wrote:I've created a bug here: "Struct Cast Not Documented or Incorrectly Accepted" https://issues.dlang.org/show_bug.cgi?id=20570On Saturday, 8 February 2020 at 17:36:17 UTC, Jonathan Marler wrote:I hope you're wrong about this. Can someone in D leadership please prove this statement wrong by clarifying whether this is a bug in DMD or a missing feature in the spec?[...]The spec is wrong in many aspects. It was written then never followed. Not sure if it even gets updated.
Feb 08 2020
On 2/8/2020 6:05 PM, Jonathan Marler wrote:I've created a bug here: "Struct Cast Not Documented or Incorrectly Accepted" https://issues.dlang.org/show_bug.cgi?id=20570It shouldn't compile. I'd have to investigate with the implementation.
Feb 13 2020