Bug 6753 – Regression(2.055beta) "Reinterpret" cast of array to a tail const one doesn't work inside @trusted
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-10-01T14:09:00Z
Last change time
2011-10-23T11:26:58Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
dmitry.olsh
Comments
Comment #0 by dmitry.olsh — 2011-10-01T14:09:34Z
This used to work on 2.055:
struct Interval{ int a,b; }
@safe struct S
{
int[] arr;
@trusted @property auto byInterval() const
{
return cast(const(Interval)[])arr;
}
}
Now on 2.056head (on commit fac2d5107a003320ce5389de04fcb6705e3795c9)
it's rejected with:
Error: cast from const(int[]) to const(Interval)[] not allowed in safe code
Maybe byInterval somehow doesn't override it's safety level to "trusted".
The following workaround works which makes me think it's a bug in upcoming 2.056.
@safe struct S
{
int[] arr;
@trusted @property auto byInterval() const
{
const(int)[] tmp = arr;
return cast(const(Interval)[])tmp;
}
}