Casting between Structs
Jonathan Marler
johnnymarler at gmail.com
Sat Feb 8 17:36:17 UTC 2020
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
More information about the Digitalmars-d
mailing list