www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3801] New: CTFE: this.arr[i] cannot be evaluated at compile time for structs

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

           Summary: CTFE: this.arr[i] cannot be evaluated at compile time
                    for structs
           Product: D
           Version: 2.040
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: blocker
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: ludwig informatik.uni-luebeck.de


--- Comment #0 from Sönke Ludwig <ludwig informatik.uni-luebeck.de> 2010-02-14
07:45:33 PST ---
A static array contained inside a struct is not accessible during CTFE. Because
of this, it seems impossible (since some versions) to define compile-time
constants of such structures (for example tuple vectors or matrices).

---
struct S {
  int arr[1];

  this(int x){
    arr[0] = x; // (this.arr[0u]) = x cannot be evaluated at compile time
  }
}

immutable S s_constant = S(1); // Error: cannot evaluate __ctmp1.this(1) at
compile time
---

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 14 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3801


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au
           Severity|blocker                     |major


--- Comment #1 from Don <clugdbug yahoo.com.au> 2010-02-26 07:37:38 PST ---
a.b[i]=c; isn't implemented in CTFE yet, but a.b=c; is, so I'm downgrading from
blocker. (It's still high priority, though).
Workaround:

struct S {
  int arr[1];

  this(int x){
    int[1] z = x;
    arr = z;
  }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 26 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3801



--- Comment #2 from Sönke Ludwig <ludwig informatik.uni-luebeck.de> 2010-02-27
03:44:47 PST ---
Unfortunately, the workaround also errors out with (although I did not check a
current svn build):

test.d(6): Error: this.arr[] = cast(const(int[]))x cannot be evaluated at
compile time


But this gave me finally another idea, which seems to work:

struct test {
  int[1] f;

  this(int x){
    int[] dst = f;
    dst[0] = x;
  }
}

[Now off to some code porting and finally trying out the recent features...
;-)]

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 27 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3801


Sönke Ludwig <ludwig informatik.uni-luebeck.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |http://d.puremagic.com/issu
                   |                            |es/show_bug.cgi?id=3984


--- Comment #3 from Sönke Ludwig <ludwig informatik.uni-luebeck.de> 2010-03-18
23:46:33 PDT ---
Unfortunately, the workaround also does not work (compiles but generates
incorrect code): http://d.puremagic.com/issues/show_bug.cgi?id=3984.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 18 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3801


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|major                       |blocker


--- Comment #4 from Don <clugdbug yahoo.com.au> 2010-03-24 12:06:16 PDT ---
Yeah, there doesn't seem to be any workaround. Changing it back to blocker.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 24 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3801


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #5 from Don <clugdbug yahoo.com.au> 2011-04-08 21:16:50 PDT ---
Fixed.
D1:
https://github.com/D-Programming-Language/dmd/commit/ef2a0f1da10331c4de102ca3e029ea1c1c1a46bf

D2:
https://github.com/D-Programming-Language/dmd/commit/0219a5f0dcc88076759a4c472582954d0fb804b0

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