Bug 4961 – ICE(interpret.c) Tuple in union as part of static struct member
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-09-30T12:52:00Z
Last change time
2011-09-16T08:57:00Z
Keywords
ice-on-valid-code
Assigned to
nobody
Creator
simen.kjaras
Comments
Comment #0 by simen.kjaras — 2010-09-30T12:52:16Z
The below code crashes DMD with the following message:
Assertion failure: 'existing->op == TOKstructliteral' on line 2090 in file 'interpret.c'
abnormal program termination
////////////////////////////
import std.typecons;
struct bar {
static bar b = bar( 0 );
union {
int[1] value;
Tuple!( int ) fields;
}
this( int r ) {
fields.expand[0] = r;
}
}
Comment #1 by clugdbug — 2010-10-05T01:56:06Z
Reduced test case shows it doesn't require tuples.
struct Fields4961 { int x; }
struct bar4961 {
union {
int[1] value;
Fields4961 fields;
}
this( int r ) {
fields.x = r;
}
}
static bar4961 b4961 = bar4961( 0 );
Interestingly, if you swap 'value' and 'fields', you get an error message with no line number:
Error: duplicate union initialization for value
Comment #2 by simen.kjaras — 2011-09-16T08:57:00Z
This example has been reduced to a limitation of CTFE. The original problem is gone. The below code works as expected:
struct Fields4961 { int x; }
struct bar4961 {
union {
int[1] value;
Fields4961 fields;
}
this( int r ) {
fields.x = r;
}
}
static bar4961 b4961; // No longer initialized here. No CTFE problems.
static this( ) {
b4961 = bar4961( 0 );
}