www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10298] New: CTFE fails with array literal initialization

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

           Summary: CTFE fails with array literal initialization
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bugzilla digitalmars.com


--- Comment #0 from Walter Bright <bugzilla digitalmars.com> 2013-06-08
01:16:57 PDT ---
The following code works at runtime, but fails when initialized with a literal:

------------------
struct Bug7940 {
    int m;
}

struct App7940 {
   Bug7940[] x;
}

int bug7940() {
  Bug7940[2] y = [Bug7940(),Bug7940()]; // this line causes the failure
  //Bug7940[2] y;    // works
  App7940 app;
  app.x = y[0..1];
  app.x[0].m = 12;
  assert(y[0].m == 12);
  assert(app.x[0].m == 12);
  return 1;
}

static assert(bug7940());   // fails CTFE

void main()
{
    assert(bug7940());  //  works at runtime
}

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


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |CTFE, wrong-code


--- Comment #1 from Don <clugdbug yahoo.com.au> 2013-06-12 01:38:14 PDT ---
Reduced test case
--------------

struct Bug10298 {
    int m;
}

int bug10298()
{
    Bug10298[2] y = [Bug10298(), Bug10298()];
    y[0].m = 6;
    assert(y[0].m == 6);
    return 1;
}

static assert(bug10298());

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



--- Comment #2 from github-bugzilla puremagic.com 2013-06-14 21:06:07 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/dfcaed6cd55f5bbaa121788fbf256e07f7e47a20
Fix bug 10298 CTFE wrong code for struct array literal init

The elements in an array literal need to have constness
implicitly cast away when they are being slice assigned.

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


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies gmail.com
         Resolution|                            |FIXED


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