www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11151] New: Undetected overlapping initialization

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11151

           Summary: Undetected overlapping initialization
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid, wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: k.hara.pg gmail.com



The union field U.a and U.y are overlapped but compiler doesn't detect the
issue.

import core.stdc.stdio : printf;
union U
{
    struct
    {
        align(1) long a;
        align(1) int b;
    }
    struct
    {
        align(1) int x;
        align(1) long y;
    }
}
void main()
{
    pragma(msg, U.a.offsetof);  // 0
    pragma(msg, U.b.offsetof);  // 8
    pragma(msg, U.x.offsetof);  // 0
    pragma(msg, U.y.offsetof);  // 4

    U u = {a:1, y:2};   // overlapped initializing U.a and U.y
    printf("u.a = %lld\n", u.a);    // 8589934593 , Wrong!
    printf("u.b = %d\n",   u.b);    // 0
    printf("u.x = %d\n",   u.x);    // 1
    printf("u.y = %lld\n", u.y);    // 2
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 01 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11151


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull



https://github.com/D-Programming-Language/dmd/pull/2605

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 01 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11151




Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/cd6102367906c0a76f4ad56375e8bdf653321e0b
fix Issue 11151 - Undetected overlapping initialization

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 05 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11151


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 05 2013