D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7324 - Access Violation when printing struct with union
Summary: Access Violation when printing struct with union
Status: RESOLVED DUPLICATE of issue 7230
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-19 20:04 UTC by Andrej Mitrovic
Modified: 2012-03-25 03:18 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2012-01-19 20:04:35 UTC
import std.stdio;

struct JSONValue {
    union {
        string              str;
        long                integer;
        real                floating;
        JSONValue[string]   object;
        JSONValue[]         array;
    }
    
    int type;
}

void main()
{
    JSONValue foo;
    foo.str = "a";  // remove to avoid access violation
    
    JSONValue bar;
    bar.object["foo"] = foo;
    
    writeln(bar.object["foo"]);  // object.Error: Access Violation
}

This is taken from std.json, which suffers from these segfaults when you try to print out the 'object' field. Using `foreach (key, val)` works fine though.
Comment 1 Kenji Hara 2012-03-25 03:18:02 UTC

*** This issue has been marked as a duplicate of issue 7230 ***