D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9932 - CTFE cannot be used when a struct has "uninitialized" static array union members?
Summary: CTFE cannot be used when a struct has "uninitialized" static array union memb...
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-14 11:22 UTC by simendsjo
Modified: 2013-11-22 06:31 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description simendsjo 2013-04-14 11:22:16 UTC
Ref: http://forum.dlang.org/thread/gegwzcaswemphdlcahfl@forum.dlang.org
Related to http://d.puremagic.com/issues/show_bug.cgi?id=8543 ?
----
This is probably not a minimal test-case, and I haven't tested 
with more types, but it shows the problem.

// This works
struct S {
    this(int i) {
        a = i;
    }
    union {
        int a = void;
        int b = void;
    }
}
unittest
{
    auto s = S(1);
    assert(&s.a == &s.b);
    enum s2 = S(1);
    static assert(S(1).a == 1);
}

// But this doesn't
struct S2 {
    this(int i) { // error at this line
        a[] = i;
    }
    union {
        int[1] a = void;
        int[1] b = void;
    }
}
unittest
{
    auto s = S2(1);
    assert(s.a.ptr == s.b.ptr);
    // bug.d(19): Error: uninitialized variable 'b' cannot be 
returned from CTFE
    enum s2 = S2(1);
}

void main() {
}
Comment 1 yebblies 2013-11-22 06:31:02 UTC
Works now.