forked from dlang/dmd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fix-immutable-conv.dd
24 lines (20 loc) · 960 Bytes
/
fix-immutable-conv.dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
`-preview=fixImmmutableConv` has been added
The compiler allows implicitly converting a return value with indirections to immutable if it determines the result must be unique.
Formerly, this check would inspect the types of the indirections, and forget to take into account conversions, such as `int[]` to `void[]`:
---
int[] f(ref void[] m) pure
{
auto result = new int[5];
m = result;
return result;
}
void main()
{
void[] v;
immutable x = f(v);
// `v` is now a mutable alias to immutable variable `x`
}
---
This was filed as [issue 15660](https://issues.dlang.org/show_bug.cgi?id=15660), which has been fixed some time ago by making the check more strict: the called function must be strongly pure.
However, to avoid breaking code, the fix was only active with the `-preview=dip1000` switch.
Since it is unrelated to dip1000 (which is about `scope` pointers), the fix has been moved to a new `-preview=fixImmmutableConv` switch.