D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4093 - Segfault(interpret.c): with recursive struct templates
Summary: Segfault(interpret.c): with recursive struct templates
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-15 11:41 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-15 11:41:19 UTC
struct Zug(int Z){
    const void * bahn = Bug4093!(0).hof.bahn;
}

struct Bug4093(int Q){
    Zug!(0) hof;
}

const a = Zug!(0).bahn;
====
crash.d(220): Error: 'this' is only defined in non-static member functions, not
crash
crash.d(220): Error: this for hof needs to be type Bug4093 not type int
Comment 1 Don 2010-04-20 01:39:08 UTC
This bug is completely fixed by the patch to 4094. However, I think this bug does reveal another problem which is also worth fixing.

The segfault itself can also be fixed with this patch to expression.c line 280. The error message it gives is nonsense (so the patch to bug 4094 fixes that), but I think adding more ErrorExps is no bad thing, and may prevent another future crash.


            e1->error("this for %s needs to be type %s not type %s",
                var->toChars(), ad->toChars(), t->toChars());
+            e1 = new ErrorExp();
        }
Comment 2 Don 2010-05-05 19:10:53 UTC
Fixed DMD2.044
Comment 3 siegelords_abode 2010-09-05 08:57:10 UTC
The test code in the original comment does not compile on DMD2.048 (Error: variable hof cannot be read at compile time) and causes a segfault in DMD1.063. Is this bug really fixed?
Comment 4 Don 2011-04-28 06:20:52 UTC
Although this bug is fixed in D2, it is NOT fixed for D1 (where it generates a stack overflow).
Comment 5 Don 2011-12-23 15:16:04 UTC
(In reply to comment #4)
> Although this bug is fixed in D2, it is NOT fixed for D1 (where it generates a
> stack overflow).

Don't know why I thought that. This bug never existed on D1. The stack overflow only occurs on a debug version of DMD; on a release DMD, it generates a "recursive template expansion" error. There's no difference between D1 and D2; change the 'const void *' to 'enum void *' to see the D1 behaviour in D2.