Thread overview
[Issue 10298] New: CTFE fails with array literal initialization
Jun 08, 2013
Walter Bright
Jun 12, 2013
Don
Jun 15, 2013
yebblies
June 08, 2013
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: -------
June 12, 2013
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: -------
June 15, 2013
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: -------
June 15, 2013
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: -------