Bug 6809 – IFTI should imply const where inout is present on args, but not on return type

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-10-12T16:32:00Z
Last change time
2013-04-08T21:17:17Z
Assigned to
nobody
Creator
schveiguy

Comments

Comment #0 by schveiguy — 2011-10-12T16:32:01Z
example: void foo(T)(T v) { } inout(int)* bar(inout(int)* x) { foo(x); return x; } bug.d(1): Error: inout on parameter means inout must be on return type as well (if from D1 code, replace with 'ref') bug.d(1): Error: variable bug.foo!(inout(int)*).foo.v inout variables can only be declared inside inout functions bug.d(7): Error: template instance bug.foo!(inout(int)*) error instantiating It is safe for IFTI to assume all inout parameters are const instead of inout, since inout implicitly casts to const. However, inout should still be used where it participates in the return type. For example, this currently-valid code should continue to compile: T foo(T)(T v) { return v; } inout(int)* bar(inout(int)* x) { return foo(x); }
Comment #1 by lovelydear — 2012-04-28T02:21:59Z
Compiles with dmd 2.059 Win32
Comment #2 by k.hara.pg — 2013-04-08T21:17:17Z
By fixing 7105, it has been changed to valid code.