Bug 13006 – Allow inout return type without inout parameters

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-06-29T15:06:46Z
Last change time
2024-12-13T18:21:47Z
Keywords
pull
Assigned to
No Owner
Creator
Kenji Hara
See also
https://issues.dlang.org/show_bug.cgi?id=19126
Moved to GitHub: dmd#18843 →

Comments

Comment #0 by k.hara.pg — 2014-06-29T15:06:46Z
Currently unique expressions can be converted to arbitrary type qualifier. int * mp = new int(1); immutable(int)* ip = new int(1); But, currently we cannot define a function that returns unique expression without pure attribute. int* foo() pure { return new int(1); } int * mp = foo(); // OK immutable(int)* ip = foo(); // OK int* bar() { return new int(1); } int * mp = bar(); // OK immutable(int)* ip = bar(); // NG! I think it is possible by the subject proposal. inout(int)* bar1() { return new int(1); } int * mp = bar1(); // could be possible immutable(int)* ip = bar1(); // could be possible inout(int)* bar2() { inout(int)* p = new int(1); // <-- propagate expression uniqueness via inout qualifier return p; } int * mp = bar2(); // could be possible immutable(int)* ip = bar2(); // could be possible In my thought, there's some assumptions as follows. 1. Unique expressions (eg. new int(1)) could be converted to arbitrary type qualifier, so it should be convertible to inout type. 2. If inout type appears on return type without inout parameter, it would be converted to arbitrary type qualifier without restrictions from function argument types. My proposal have some pros: 1. Some limitations about inout type qualifier could be lifted. For example, isInputRange definition would be simplified. 2. Unique expressions could be more useful in D. By using inout, we can propagate it in function body. and cons: 1. We should have a way to copy inout objects - eg. qualified postblit feature (DIP49) is necessary.
Comment #1 by k.hara.pg — 2014-07-11T09:07:47Z
Comment #2 by slavo5150 — 2018-01-25T09:28:25Z
This feature requires a DIP. See discussion at https://github.com/dlang/dmd/pull/3740
Comment #3 by robert.schadek — 2024-12-13T18:21:47Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18843 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB