Bug 9566 – Regression (2.062): Cannot use struct .init when it contains a static array initialized from a single element.
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-02-21T21:26:00Z
Last change time
2013-02-25T04:56:48Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
Marco.Leise
Comments
Comment #0 by Marco.Leise — 2013-02-21T21:26:11Z
Seeing is believing. Reduced test case:
____________________
import core.stdc.stdlib;
struct SZDDFile
{
ExpandData* pExpandData = null;
struct ExpandData
{
ubyte[4096] window = 0;
}
void open()
{
pExpandData = cast(ExpandData*) malloc (ExpandData.sizeof);
*pExpandData = ExpandData.init;
}
}
____________________
Error: cannot implicitly convert expression (cast(ubyte)0u) of type ubyte to ubyte[4096LU]
Comment #1 by monarchdodra — 2013-02-21T22:57:51Z
(In reply to comment #0)
> Seeing is believing. Reduced test case:
> ____________________
>
> import core.stdc.stdlib;
>
> struct SZDDFile
> {
> ExpandData* pExpandData = null;
>
> struct ExpandData
> {
> ubyte[4096] window = 0;
> }
>
> void open()
> {
> pExpandData = cast(ExpandData*) malloc (ExpandData.sizeof);
> *pExpandData = ExpandData.init;
> }
> }
> ____________________
>
> Error: cannot implicitly convert expression (cast(ubyte)0u) of type ubyte to
> ubyte[4096LU]
It's not about the surrounding code, but rather, whether or not you use the .init property. Reduced test case:
//----
struct ExpandData
{
ubyte[4096] window = 0;
}
void main()
{
ExpandData a;
auto b = ExpandData.init; //Comment me.
}
//----
Works in 2.061, so is a regression.
Comment #2 by monarchdodra — 2013-02-21T23:03:44Z
(In reply to comment #1)
> It's not about the surrounding code, but rather, whether or not you use the
> .init property.
Right, came from the message boards, where you said "I didn't imagine it would depend on any surrounding code", and didn't notice you had already pinned it in the title.
Please ignore that sentence then.