Bug 9935 – static if evaluation of template causes OOM/stack overflow.

Status
RESOLVED
Resolution
WORKSFORME
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-04-15T03:45:00Z
Last change time
2013-10-07T00:11:48Z
Keywords
ice
Assigned to
nobody
Creator
ibuclaw

Attachments

IDFilenameSummaryContent-TypeSize
1209typetuple.dtypetuple.dtext/x-dsrc1782

Comments

Comment #0 by ibuclaw — 2013-04-15T03:45:11Z
Found this when trying to reduce another bug. Attached problematic source.
Comment #1 by ibuclaw — 2013-04-15T03:45:59Z
Created attachment 1209 typetuple.d
Comment #2 by ibuclaw — 2013-04-15T03:46:52Z
Requires -unittest to reproduce.
Comment #3 by ibuclaw — 2013-04-15T03:51:38Z
And here is the change that dustmite made to cause the bug. --- diff -pur bug.reduced/typetuple.d bug.test/typetuple.d --- bug.reduced/typetuple.d 2013-04-15 11:48:35.739230767 +0100 +++ bug.test/typetuple.d 2013-04-15 11:49:13.303231268 +0100 @@ -34,7 +34,7 @@ alias GenericReplace!(T, U, TList).resul template GenericReplace(args...) { -alias args[0]from; +alias args[]from; alias args[1]to; alias args[2 .. $] tuple;
Comment #4 by bugzilla — 2013-10-07T00:10:09Z
The example code: ------------------ template TypeTuple(TList...) { alias TList TypeTuple; } template staticIndexOf(T, TList...) { enum staticIndexOf = genericIndexOf!(T, TList).index; } template genericIndexOf(args...) { alias args[0]e; alias args[1 .. $] tuple; alias Alias!(tuple[0]) head; alias tuple[1 .. $] tail; static if (isSame!(e, head)) { enum index = 0; } else { enum next = genericIndexOf!(e, tail).index; enum index = (next == -1) ? -1 : 1 + next; } } template Replace(alias T, alias U, TList...) { alias GenericReplace!(T, U, TList).result Replace; } template GenericReplace(args...) { alias args[]from; alias args[1]to; alias args[2 .. $] tuple; alias Alias!(tuple[0]) head; alias tuple[1 .. $] tail; static if (isSame!(from, head)) alias TypeTuple!(to, tail) result; else alias TypeTuple!(head, GenericReplace!(from, to, tail).result) result; } unittest { static assert(Pack!(Replace!(1111, "11", 2222, 1111, 1111, 1111)). equals!(2222, "11", 1111, 1111)); } template Alias(a...) { alias a Alias; } template isSame(ab...) { static if (!__traits(compiles, expectType!ab) && __traits(compiles, expectBool!(ab[0] == ab[1]))) static if (!__traits(compiles) ) enum isSame = ab[0] == ab[1]; else enum isSame = (isSame); else enum isSame = __traits(isSame, ab, ab); } template expectBool(bool b) {} template Pack(T...) { template equals(U...) { static if (T.length == 0) enum equals = true; else enum equals = isSame!(T, U) && Pack!(T[1 .. $]).equals!(U); } }
Comment #5 by bugzilla — 2013-10-07T00:11:48Z
2.064 head produces error message: test.d(53): Error: template instance test.Replace!(1111, "11", 2222, 1111, 1111, 1111) recursive expansion