www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2564] New: CTFE: the index in a tuple foreach is uninitialized (bogus error)

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

           Summary: CTFE: the index in a tuple foreach is uninitialized
                    (bogus error)
           Product: D
           Version: 2.023
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: clugdbug yahoo.com.au


int foo(E...)(string[2] s)
{
    foreach(int i,T; E) {
        auto z = s[i].dup;
    }
    return 0;
}

static x = foo!(int, int)(["x", "y"]);
---
bug.d(4): Error: variable i is used before initialization
bug.d(9): Error: cannot evaluate foo(&["x","y"]) at compile ti
me
bug.d(9): Error: cannot evaluate foo(&["x","y"]) at compile ti
me
---
A workaround:
    foreach(int j,T; E) {
       int i=j;
       ...
    }
Does not happen in D1.039


-- 
Jan 07 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2564


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch





Actually it's nothing to do with foreach. Reduced test case shows it is use of
'enum' manifest constants. They're not getting constant-folded correctly.

int bug2564()
{
    enum int Q=0;
    string [2] s = ["a", "b"];    
    assert(s[Q].dup=="a");
    return 0;
}

static int bug2564b = bug2564();

PATCH:
In interpret.c, getVarExp.
-    if ((v->isConst() || v->isInvariant()) && v->init 
+    if ((v->isConst() || v->isInvariant() || v->storage_class & STCmanifest)
&& v->init

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 25 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2564


Walter Bright <bugzilla digitalmars.com> changed:

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





13:34:33 PDT ---
Fixed dmd 2.032

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