Thread overview
[Issue 6374] New: [CTFE] Cannot subscript using pointer to array
Jul 24, 2011
kennytm@gmail.com
Jul 24, 2011
kennytm@gmail.com
Jul 26, 2011
Walter Bright
July 24, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6374

           Summary: [CTFE] Cannot subscript using pointer to array
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Mac OS X
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: kennytm@gmail.com


--- Comment #0 from kennytm@gmail.com 2011-07-24 14:05:05 PDT ---
Test case:

---------------------
static assert({
    int[] arr = [1];
    arr.ptr[0] = 2;   // <-- line 3
    return arr[0];
}() == 2);
---------------------
y.d(3): Error: cannot determine length of cast(int*)arr at compile time
y.d(5): Error: cannot evaluate delegate pure nothrow int()
{
int[] arr = [1];
(cast(int*)arr)[0u] = 2;
return arr[0u];
}
() at compile time
y.d(1): Error: static assert  (delegate pure nothrow int()
{
int[] arr = [1];
(cast(int*)arr)[0u] = 2;
return arr[0u];
}
() == 2) is not evaluatable at compile time
---------------------

Slicing is OK, though.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 24, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6374



--- Comment #1 from kennytm@gmail.com 2011-07-24 14:53:02 PDT ---
Note that this prevents std.array.appender from being CTFE-able, because it contains the code:

                _data.arr.ptr[len] = cast(Unqual!T)item;  // <-- error
                _data.arr = _data.arr.ptr[0 .. len + 1];  // (OK)

Currently, this could be worked-around by swapping the two statements and use the standard indexing:

                _data.arr = _data.arr.ptr[0 .. len+1];  // OK
                _data.arr[len] = cast(Unqual!T)item;    // now OK

but I think the more proper solution is to fix this bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 26, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6374


Walter Bright <bugzilla@digitalmars.com> changed:

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


--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> 2011-07-26 15:18:37 PDT ---
https://github.com/D-Programming-Language/dmd/commit/0904c8aa200e4d080d500d96d5904c33ba17cc86

https://github.com/D-Programming-Language/dmd/commit/e48a8c67f02172c72e04f36759d2d6868d716368

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