Bug 12883 – implicit conversion of struct to mutable via alias this

Status
REOPENED
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2014-06-09T22:32:20Z
Last change time
2024-12-13T18:21:26Z
Keywords
rejects-valid
Assigned to
Nils
Creator
Nils
Blocks
12885
See also
https://issues.dlang.org/show_bug.cgi?id=12885
Moved to GitHub: dmd#18836 →

Comments

Comment #0 by nilsbossung — 2014-06-09T22:32:20Z
--- static struct S { int x; void* dummy; @property S mutable() const {return S(42);} alias mutable this; } void main() { const c = S(13); S m1 = c; assert(m1.x == 42); S m2; m2 = c; assert(m2.x == 42); static void f(S s) {assert(s.x == 42);} f(c); } --- Pull request is on the way.
Comment #1 by nilsbossung — 2014-06-09T22:47:06Z
Comment #2 by k.hara.pg — 2014-06-16T02:32:57Z
With struct type S, copy operation from const S to mutable S should be handled postblit always. So, 'alias this' never be considered in the case, and this is invalid issue.
Comment #3 by razvan.nitu1305 — 2018-11-15T15:18:53Z
This is a valid issue. Alias this should be employed if a copy constructor is not defined.
Comment #4 by robert.schadek — 2024-12-13T18:21:26Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18836 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB