www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22126] New: -checkaction=context should not print overlapped

https://issues.dlang.org/show_bug.cgi?id=22126

          Issue ID: 22126
           Summary: -checkaction=context should not print overlapped
                    struct members
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dkorpel live.nl

Reduced test case:
```
struct S 
{
    union 
    {
        double num;
        immutable(char)[] name;
    }
}

void main() 
{
    assert(S.init != S.init);
}
```

Compiling with -checkaction=context gives:

core.exception.OutOfMemoryError src/core/exception.d(647): Memory allocation
failed
----------------

The problem is that the double 'num' overlaps the length field of 'name', and
double.nan interpreted as a length is 0x7FF8000000000000, so it's no wonder
Memory allocation failed. 

formatMembers in core/internal/dassert.d should not naively iterate over
.tupleof but watch for overlapped fields.

--
Jul 16 2021