Silently enters 'void* this;' pointer making compiling error out. Current beta (v2.061, windows 32bit)
Only by using traits will the problem show itself.
[code]
static assert(__traits(compiles, {
union xxx {
int i;
//bitfields will make such functions...
mixin("int geti() @safe const nothrow pure {return i;}void seti(int ii) @safe pure nothrow {i = ii;}");
}
}));
[/code]
output:
test.d(??): Error: static assert (__traits(compiles,delegate pure nothrow @safe void()
{
union xxx
{
int i;
mixin("int geti() @safe const nothrow pure {return i;}void seti(int ii) @safe pure nothrow {i = ii;}");
void* this;
}
}
)) is false
Comment #1 by issues.dlang — 2012-12-29T23:03:21Z
If this is a regression, it needs to be marked as such.
Comment #2 by yebblies — 2013-01-14T03:49:46Z
Reduced:
void main()
{
union U {
int i;
@safe int x() { return i; }
}
}
Because U has a function in it, dmd incorrectly decides it is a nested union and (even worse) inserts a void* member.
A regression because:
- @safe code didn't always disallow unions with pointers
- wrapping x in an attribute such as @safe used to make the compiler infer U as non-nested
Workaround: make U static