www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9425] New: Static struct initializer fails to init array

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

           Summary: Static struct initializer fails to init array
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: SebastianGraf t-online.de


--- Comment #0 from Sebastian Graf <SebastianGraf t-online.de> 2013-01-29
09:14:41 PST ---
I found this when fixing a bug in ldc on Win8 x64. I'm pretty sure all
platforms are concerned, because the linux CI server complained for the same
reason.

import std.conv;

struct S { int array[4]; }

void main() 
{ 
    int array[4] = 67; // array = [67, 67, 67, 67]
    static S s = S(67); // s.array = [67, 0, 0, 0]
    assert(array == s.array, "s.array (actual): " ~ to!string(s.array) ~ ",
array (expected): " ~ to!string(array));
}

When initializing array in S' initializer, only the first element of the array
takes the value, the others are zero'd. I expected the array to be filled with
the value. 
Note that this is the case when you don't declare s as static, so I assume it
is a bug.

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



--- Comment #1 from Sebastian Graf <SebastianGraf t-online.de> 2013-01-30
08:53:52 PST ---
This is related to Bug2931. There's a dmd testcase for that in
http://github.com/D-Programming-Language/dmd/blob/e7eff4deef0fb5ec9a89cee4716785832fc41fb9/test/runnable/test42.d#L3193
. The actual test case bug2931_2 conflicts with what I expected it to assert:
Only the first element is initialized with the value, all other elements are
assumed to be zero.
This however contradicts dmd's behavior for the non-static case.

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



--- Comment #2 from Kenji Hara <k.hara.pg gmail.com> 2013-02-02 05:49:34 PST ---
(In reply to comment #1)
 This is related to Bug2931. There's a dmd testcase for that in
 http://github.com/D-Programming-Language/dmd/blob/e7eff4deef0fb5ec9a89cee4716785832fc41fb9/test/runnable/test42.d#L3193
 . The actual test case bug2931_2 conflicts with what I expected it to assert:
 Only the first element is initialized with the value, all other elements are
 assumed to be zero.
 This however contradicts dmd's behavior for the non-static case.

For the one level block initializing of static array, current dmd generates correct code. static int[3] x = 1; // block initializing void main() { import std.stdio; writeln(x); // print [1, 1, 1]; } It is from dmd0.98. https://github.com/d-programming-language/dmd/commit/15d4546d07d5dedb7424677ae4dc0b18e57ef6da#L11R799 So, the test case for bug 2931 is wrong, IMO. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 02 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9425



--- Comment #3 from Don <clugdbug yahoo.com.au> 2013-02-04 02:41:11 PST ---
I did quite a lot of work (In reply to comment #2)
 (In reply to comment #1)
 This is related to Bug2931. There's a dmd testcase for that in
 http://github.com/D-Programming-Language/dmd/blob/e7eff4deef0fb5ec9a89cee4716785832fc41fb9/test/runnable/test42.d#L3193
 . The actual test case bug2931_2 conflicts with what I expected it to assert:
 Only the first element is initialized with the value, all other elements are
 assumed to be zero.
 This however contradicts dmd's behavior for the non-static case.

For the one level block initializing of static array, current dmd generates correct code. static int[3] x = 1; // block initializing void main() { import std.stdio; writeln(x); // print [1, 1, 1]; } It is from dmd0.98. https://github.com/d-programming-language/dmd/commit/15d4546d07d5dedb7424677ae4dc0b18e57ef6da#L11R799 So, the test case for bug 2931 is wrong, IMO.

I agree. Note that it behaves as expected in CTFE: --- struct S { int array[4]; } enum S s = S(67); int tain() { return s.array[2]; } static assert(tain()==67); ---- Though I get a CTFE ICE if I change that to a 2D array :-(. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 04 2013