Compiled with a recent master DMD version, flags -preview=dip1000 and -run
-----------------------------
@safe ref foo(return ref noreturn arg){return arg;}
@safe void main()
{ foo(*null);
}
-----------------------------
The above example crashes at runtime with the following message:
-----------------------------
[email protected](1): Accessed expression of type `noreturn`
----------------
??:? _d_assert_msg [0x43a7c8]
??:? pure nothrow ref @nogc @safe noreturn app.foo(return ref noreturn) [0x43a730]
??:? _Dmain [0x43a73e]
-----------------------------
The example should run without any error, because `foo` function does not actually take or return the bottom value - only a (null) reference to one. It's the same reason why this program runs without error:
-----------------------------
@safe ref foo(return ref int arg){return arg;}
@safe void main()
{ foo(*cast(int*)null);
}
-----------------------------
Comment #1 by dlang-bugzilla — 2023-05-12T14:37:11Z
Worked before https://github.com/dlang/dmd/pull/14187 , though I'm not sure if this is something that should work... The conclusion makes sense to me only with a rather literal interpretation of the definition of noreturn in object - we "undo" the null pointer dereference by using "ref". With an alternative definition of noreturn, e.g. `typeof(assert(false))`, I'm not sure that this makes sense any more.
Comment #2 by robert.schadek — 2024-12-13T19:24:39Z