D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9244 - union containing pointers not allowed
Summary: union containing pointers not allowed
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 regression
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2012-12-29 20:40 UTC by Era Scarecrow
Modified: 2013-02-01 14:11 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Era Scarecrow 2012-12-29 20:40:55 UTC
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 Jonathan M Davis 2012-12-29 23:03:21 UTC
If this is a regression, it needs to be marked as such.
Comment 2 yebblies 2013-01-14 03:49:46 UTC
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
Comment 4 github-bugzilla 2013-02-01 14:07:06 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/0e21647a30c50e02e4a9ce43ee7e891a41d7c255
fix Issue 9244 - union containing pointers not allowed

https://github.com/D-Programming-Language/dmd/commit/95a3f5ff979f40ff0e7ae459b8d9786d64f901a7
Merge pull request #1591 from WalterBright/b46

fix Issue 9244 - union containing pointers not allowed