Bug 11257 – Allow whole implicit conversion if one or more overlapped field could.

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-10-14T04:00:35Z
Last change time
2018-12-16T10:30:03Z
Keywords
pull
Assigned to
No Owner
Creator
Kenji Hara
See also
https://issues.dlang.org/show_bug.cgi?id=12885

Comments

Comment #0 by k.hara.pg — 2013-10-14T04:00:35Z
Compiler rejects this code so the implicit conversion from const(R) to R breaks mutable field 'stripped' const-correctness. struct R { union { const(Object) original; Object stripped; } } void main() { const R cr; R mr = cr; // Error: cannot implicitly convert expression // (cr) of type const(R) to R } However, I think this is a little restricted behavior. Because qualified and overlapped field is D-specific feature. It's mostly used for bypassing the restriction of const qualifier. Therefore, in many case it would be protected by private access specifier. The feature is necessary in order to allow const(Rebindable) to Rebindable conversion.
Comment #1 by k.hara.pg — 2013-10-14T05:57:34Z
Comment #2 by github-bugzilla — 2013-10-14T20:51:11Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/0f00e6b6f29707f7a18b6e559aecf6bca50fca90 fix Issue 11257 - Allow whole implicit conversion if one or more overlapped field could.
Comment #3 by bugzilla — 2018-12-16T09:55:20Z
I can't agree with this. A cast should be used to break out of const, and should not be allowed in @safe code.