Bug 20728 – There is third way to create immutable data

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-04-11T01:33:46Z
Last change time
2020-04-11T02:01:22Z
Assigned to
No Owner
Creator
Victor Porton

Comments

Comment #0 by porton — 2020-04-11T01:33:46Z
https://dlang.org/spec/const3.html says that there are two ways of "Creating immutable data". I disagree, there is also the third way: auto int x = 1; void f(ref immutable int r) { } f(x); This is neither literal nor cast to immutable data. It is the third way. See also https://forum.dlang.org/post/[email protected] as a hint about the issue whether it actually creates immutable data.
Comment #1 by destructionator — 2020-04-11T02:01:22Z
Your sample code doesn't even compile. That's because of this rule. That page doesn't mention the implicit cast of unique data (such as returned from a pure function), though that is technically a cast so it is kinda covered. But regardless, your example is invalid so I'm closing this. Please make sure your code actually does what you think it does before opening a bug.