www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 932] New: static foreach in second template instantiation uses wrong tupleof

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

           Summary: static foreach in second template instantiation uses
                    wrong tupleof
           Product: D
           Version: 1.00
          Platform: PC
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: fvbommel wxs.nl


---
void Fields(C)()
{
    foreach(i, a; typeof(C.tupleof))
    {
        // fails for second instantiation:
        // "test.d(7): static assert  (is(int == real)) is false"
        static assert(is(typeof(a) == typeof(C.tupleof)[i]));
    }
}

struct MyStruct1 {
    int afield;
}

struct MyStruct2 {
    real afield;
}

void main() {
    Fields!(MyStruct1);
    Fields!(MyStruct2);
}
---

Reduced from code by Kyle Furlong, posted at
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.bugs&article_id=10262

I tested this on v1.00 and v1.002-v1.005, all fail above assert.

(keyword "wrong-code" because this causes wrong code generation, though with
the static assert it of course doesn't compile. See the original example (at
link above) for a program that compiles and produces wrong code)


-- 
Feb 06 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=932






Added to DStress as
http://dstress.kuehne.cn/run/f/foreach_38_A.d
http://dstress.kuehne.cn/run/f/foreach_38_B.d
http://dstress.kuehne.cn/run/f/foreach_38_C.d


-- 
Apr 05 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=932


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |clugdbug yahoo.com.au
         Resolution|                            |INVALID





This is an invalid bug. It fails because:
        static assert(is( typeof(a)));
will always fail (a evaluates to 'int') inside a static foreach.

Correct code would be:

        static assert(is(typeof(C.tupleof)[i]  == a));

and that passes on DMD1.045 and 2.030.

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