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.
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` ---
@RazvanN7 created dlang/dmd pull request #10558 "Issue 20376 - @disable this(ref return scope Foo rhs) enables broken binaries (out-of-bounds access)" mentioning this issue: - Issue 20376 - @disable this(ref return scope Foo rhs) enables broken binaries (out-of-bounds access) https://github.com/dlang/dmd/pull/10558
dlang/dmd pull request #10558 "Issue 20376 - @disable this(ref return scope Foo rhs) enables broken binaries (out-of-bounds access)" was merged into stable: - ab5518692cbe8b1d2ab2618c093ca3a569a63ace by RazvanN7: Fix Issue 20376 - @disable this(ref return scope Foo rhs) enables broken binaries (out-of-bounds access) https://github.com/dlang/dmd/pull/10558