Bug 3978 – Compiler crash on improper struct initialization
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-03-16T17:18:00Z
Last change time
2015-06-09T01:27:58Z
Keywords
ice-on-invalid-code
Assigned to
nobody
Creator
paul.d.anderson
Comments
Comment #0 by paul.d.anderson — 2010-03-16T17:18:14Z
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 by bearophile_hugs — 2010-03-16T18:10:41Z
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.