Consider this example:
struct Foo
{
@disable this(ref return scope Foo rhs);
}
uint[2000] fun() @safe
{
return Foo();
}
void main() @safe
{
import std;
writeln(fun);
}
This will compile and print garbage data, (although a segfault is probably possible as well), despite there being an obvious type mismatch.
If the function signature is changed to a non-array type, e. g.
float fun() @safe
LDC will raise:
Invalid bitcast
%4 = bitcast %onlineapp.Foo* %1 to float, !dbg !1241
in function _D9onlineapp3funFNfZf
LLVM ERROR: Broken function found, compilation aborted!
DMD will not complain and complete the compilation as before.
run.dlang.org suggests that this happens since release 2.086.
Comment #1 by b2.temp — 2019-11-10T03:53:35Z
reduced w/o phobos. should not compile
---
struct Foo
{
this(ref scope Foo);
}
ubyte fun()
{
return Foo();
}
void main(){}
---
should fail with
---
Error: cannot implicitly convert expression `Foo()` of type `Foo` to `ubyte`
---