D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4072 - Stack overflow on recursive template expansion inside contract
Summary: Stack overflow on recursive template expansion inside contract
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-invalid-code, patch
Depends on:
Blocks:
 
Reported: 2010-04-08 06:18 UTC by Don
Modified: 2015-06-09 01:27 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Don 2010-04-08 06:18:01 UTC
void bug4072(T)(T x)
   if (is(typeof(bug4072(x))))
{}

static assert(!is(typeof(bug4072(7))));

-----
PATCH:

template.c line 1421.
-----------------------------------
        Objects dedargs;
+        static int nest = 0;
+        if (++nest > 300)
+        {
+            global.gag = 0;            // ensure error message gets printed
+            error("recursive expansion");
+            if (sc->tinst) sc->tinst->printInstantiationTrace();
+            fatal();
+        }
        m = td->deduceFunctionTemplateMatch(loc, targsi, ethis, fargs, &dedargs);
+        --nest;
        //printf("deduceFunctionTemplateMatch = %d\n", m);
        if (!m)                 // if no match
            continue;
Comment 1 Walter Bright 2010-04-08 13:59:47 UTC
changeset 432
Comment 2 Don 2010-04-09 13:43:37 UTC
Fixed DMD2.043.