D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3978 - Compiler crash on improper struct initialization
Summary: Compiler crash on improper struct initialization
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2010-03-16 17:18 UTC by Paul D. Anderson
Modified: 2015-06-09 01:27 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Paul D. Anderson 2010-03-16 17:18:14 UTC
The following code fragment causes the compiler to crash with the following useful information:

"dmd.exe has encountered a problem and needs to close.  We are sorry for the inconvenience."

//--------------------
public S s = S();

public struct S {
    private int[] a = [ 0 ];
}
//--------------------

I realize the code is incorrect, but I expected an error message, not a trainwreck.

Adding initializer information solves the problem:

//--------------------
public S s = S([0]); // compiles correctly

public struct S {
    private int[] a = [ 0 ];
}
//--------------------

Eliminating the forward reference solves the problem:

//--------------------
public struct S {
    private int[] a = [ 0 ];
}

public S s = S(); // compiles correctly
//--------------------
Comment 1 bearophile_hugs 2010-03-16 18:10:41 UTC
I think that removing the forward reference doesn't solve the problem.

If I add this line at the end:
void main() {}
The situation changes.
Comment 2 Don 2010-03-19 06:59:43 UTC
This was fixed in DMD 2.036.