www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4534] New: Dmd crash with templates

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

           Summary: Dmd crash with templates
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc


--- Comment #0 from bearophile_hugs eml.cc 2010-07-29 16:59:44 PDT ---
This code crashes dmd 2.047 with:
Internal error: ..\ztc\cod3.c 1303


template Format(A...) {
    static if (A.length == 0)
        enum Format = "";
    else static if (is(typeof(A[0]) : const(char)[]))
        enum Format = FormatString!(A[0], A[1..$]);
}

template FormatString(const(char)[] F, A...) {
    static if (F.length == 0)
        enum FormatString = Format!(A);
    else static if (F.length == 1)
        enum FormatString = F[0] ~ Format!(A);
    else static if (F[0..2] == "%s")
        enum FormatString = A[0] ~ FormatString!(F[2..$], A[1..$]);
    else
        enum FormatString = F[0] ~ FormatString!(F[1..$], A);
}

template Tuple(T...) {
    alias T Tuple;
}

enum Type : string { i1 = "x", i2 = "y", i3 = "z" }
enum Size { small = 1, medium = 2, large = 3 }

void main() {
    auto types = Tuple!("a", "b", "c");
    auto sizes = Tuple!("1", "2", "3");

    Type run_t = Type.i1;
    Size run_n = Size.medium;

    enum string pattern = "if (run_t == Type.%s_type && run_n == %s && run_m ==
%s) foo!(%s, Size.%s, Size.%s)();";

    foreach (t; types)
        foreach (n; sizes)
            foreach (m; sizes)
                enum string txt = Format!(pattern, t, n, m, t, n, m);
}


Please reduce this test case if you can, or improve the bug title.

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


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2010-08-29
19:00:50 PDT ---
On 2.047 it causes that error, but on 2.048 it seems to be gone. I don't know
how to close bug reports so you'll have to do it. :)

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


bearophile_hugs eml.cc changed:

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


--- Comment #2 from bearophile_hugs eml.cc 2010-08-29 19:03:33 PDT ---
You are right, thank you very much. So I close this bug.

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