← Back to index
|
Original Bugzilla link
Bug 4534 – Dmd crash with templates
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-07-29T16:59:00Z
Last change time
2010-08-29T19:03:33Z
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0
by bearophile_hugs — 2010-07-29T16:59:44Z
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.
Comment #1
by andrej.mitrovich — 2010-08-29T19:00:50Z
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. :)
Comment #2
by bearophile_hugs — 2010-08-29T19:03:33Z
You are right, thank you very much. So I close this bug.