Thread overview
[Issue 15575] Wrong value for static immutable struct with union
Jan 18, 2016
Cédric Picard
Jan 18, 2016
ag0aep6g@gmail.com
Oct 28, 2022
RazvanN
Dec 17, 2022
Iain Buclaw
[Issue 15575] partial initialization of a union member causes wrong diagnostic during CTFE
Oct 05, 2023
Basile-z
January 18, 2016
https://issues.dlang.org/show_bug.cgi?id=15575

--- Comment #1 from Cédric Picard <cpicard@openmailbox.org> ---
I should mention that the code is inspired by Adam Ruppe's arsd/color.d and that a comment next to the "if (__ctfe)" part mentions that it is a hack arround bug 10937. That may be related.

--
January 18, 2016
https://issues.dlang.org/show_bug.cgi?id=15575

ag0aep6g@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice
                 CC|                            |ag0aep6g@gmail.com

--
October 28, 2022
https://issues.dlang.org/show_bug.cgi?id=15575

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305@gmail.com

--- Comment #2 from RazvanN <razvan.nitu1305@gmail.com> ---
The code does not crash but produces the following errors now:

test.d(27): Error: uninitialized variable `components` cannot be returned from
CTFE
test.d(27):        while evaluating `pragma(msg, colorA.components)`
test.d(30):        while evaluating `pragma(msg, colorA)`

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=15575

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--
October 05, 2023
https://issues.dlang.org/show_bug.cgi?id=15575

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|ice                         |CTFE, rejects-valid
                 CC|                            |b2.temp@gmx.com
            Summary|Wrong value for static      |partial initialization of a
                   |immutable struct with union |union member causes wrong
                   |                            |diagnostic during CTFE

--- Comment #3 from Basile-z <b2.temp@gmx.com> ---
updated test case:

```
struct B15575 {
    union {
        ubyte[2] a;
        struct {
            ubyte b;
            ubyte c;
        }
    }

    this(ubyte b) {
        if (b)
            this.a[0] = b;
        else
            this.b = b;
        this.c = 0;
    }
}

void main()
{
    auto a = B15575(7).a;     // run-time OK
    pragma(msg, B15575(7).a); // CTFE NG
}
```

--