www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4941] New: TypeTuple slice boundaries are not CTFE'd

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

           Summary: TypeTuple slice boundaries are not CTFE'd
           Product: D
           Version: D1 & D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: patch, rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: rsinfu gmail.com



---
Type tuples can't be sliced with boundaries that involve CTFE-able function
call(s). The following valid code doesn't compile (both D1 & D2):
--------------------
template T(_...) { alias _ T; }
size_t mid(size_t n) { return n/2; }

alias T!(int, int, int)[0 .. mid($)] A;
// Error: Integer constant expression expected instead of mid(3u)
--------------------


Patch against dmd r687, makes it sure that TypeSlice boundaries get CTFE'd.

--- src/mtype.c
+++ src/mtype.c
   -7787,11 +7787,11    Type *TypeSlice::semantic(Loc loc, Scope *sc)
     TypeTuple *tt = (TypeTuple *)tbn;

     lwr = semanticLength(sc, tbn, lwr);
-    lwr = lwr->optimize(WANTvalue);
+    lwr = lwr->optimize(WANTvalue | WANTinterpret);
     uinteger_t i1 = lwr->toUInteger();

     upr = semanticLength(sc, tbn, upr);
-    upr = upr->optimize(WANTvalue);
+    upr = upr->optimize(WANTvalue | WANTinterpret);
     uinteger_t i2 = upr->toUInteger();

     if (!(i1 <= i2 && i2 <= tt->arguments->dim))

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




---
Created an attachment (id=776)
Patch against dmd r687, CTFE on tuple slice boundaries


same fix to other relevant parts, and fixes following additional cases:


template T(_...) { alias _ T; }
size_t mid(size_t n) { return n/2; }

alias T!(int, int)[0 .. mid($)] A;      // A
alias T!(1, 2, 3)[0 .. mid($)] B;       // B

void main()
{
    T!(int, int, int) values;
    auto slice = values[0 .. mid($)];   // C
}

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


Walter Bright <bugzilla digitalmars.com> changed:

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



21:08:58 PDT ---
http://www.dsource.org/projects/dmd/changeset/696

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