Issue ID: 18568
           Summary: partially overlapping assignments have undefined
                    behavior but are accepted in @safe code
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: safe
          Severity: normal
          Priority: P1
         Component: dmd

Prompted by this forum post:

On assignments, the spec says [1]:

> Undefined Behavior:
> 1. if the lvalue and rvalue have partially overlapping storage
> 2. if the lvalue and rvalue's storage overlaps exactly but the types are
>    different

But DMD accepts this:

struct S
        int i;
        byte b;
        float f;
            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. */

According to the spec, all those assignments have undefined behavior. So they
shouldn't be allowed in @safe code.

(As always, this can be fixed by letting DMD reject the code, or by changing
the spec to give the code defined behavior.)



Reply via email to