Bug 23523 – Allow User-Defined Implicit Conversions for const/immutable containers

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-11-30T14:57:31Z
Last change time
2024-12-13T19:26:02Z
Assigned to
No Owner
Creator
John Hall
Moved to GitHub: dmd#18139 →

Comments

Comment #0 by john.michael.hall — 2022-11-30T14:57:31Z
From here (among other places) on the forum https://forum.dlang.org/post/[email protected] Allow `const type!T` to convert to `type!(const T)` Similarly, allow `immutable type!T` to convert to `type!(immutable T)`
Comment #1 by john.michael.hall — 2022-11-30T18:21:11Z
In the past the argument from Walter against something like opImplicitCast has always been that users would get confused about random things happening if they had freedom to do any implicit cast they could think of. The solution to this would be only to allow the implicit conversions discussed above. So instead of some general opImplicitCast it might be better described as opImplicitConstCast.
Comment #2 by nick — 2022-12-04T18:19:34Z
> Similarly, allow `immutable type!T` to convert to `type!(immutable T)` That isn't always safe: struct S(T) { int* p; } void main() { auto s = S!(immutable int)(); immutable si = S!int(); s = si; // currently an error *s.p = 4; assert(*si.p == 0); // fails }
Comment #3 by robert.schadek — 2024-12-13T19:26:02Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18139 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB