On 03/07/2018 03:01 PM, Paolo Invernizzi wrote:
Are we asking to statically check things like:
Assign Expressions [1]
Undefined Behavior:
if the lvalue and rvalue have partially overlapping storage
if the lvalue and rvalue's storage overlaps exactly but the types are
different
A simple way to get overlapping storage is with a union. Unfortunately,
DMD accepts this:
----
struct S
{
union
{
int i;
byte b;
float f;
struct
{
byte b2;
align(1) int i2;
}
}
}
void main() @safe
{
S s;
s.i = s.b; /* Partially overlapping, different types. */
s.f = s.i; /* Exactly overlapping, different types. */
s.i = s.i2; /* Partially overlapping, same type. */
}
----
I've filed an issue:
https://issues.dlang.org/show_bug.cgi?id=18568
If you have more examples of UB in @safe functions, don't hesitate to
file them as bugs.