Bug 1060 – inout in arguments breaks the lvalueness of function

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2007-03-13T16:58:00Z
Last change time
2014-02-16T15:21:53Z
Assigned to
bugzilla
Creator
gavrilyak

Comments

Comment #0 by gavrilyak — 2007-03-13T16:58:42Z
int[] foo(int[] arr){ return arr; } int[] boo(inout int[] arr){ return arr; } int[] arr = [1,2,3]; foo(foo(arr)); // ok boo(boo(arr)); // Error: boo(arr) is not an lvalue
Comment #1 by fvbommel — 2007-03-13T17:30:56Z
(In reply to comment #0) > int[] foo(int[] arr){ > return arr; > } > > int[] boo(inout int[] arr){ > return arr; > } > > int[] arr = [1,2,3]; > > foo(foo(arr)); // ok > boo(boo(arr)); // Error: boo(arr) is not an lvalue Inout arguments don't "break" the lvalueness of a function. In fact, functions aren't lvalues, nor are their return values (which is presumably what you actually meant). The problem isn't that lvalueness is "broken", it's that an inout argument requires an lvalue to be passed and you're not doing it (in either case). Because of that, the second case doesn't work. The first one works fine because the parameter to foo isn't required to be an lvalue. Summary: the problem is in your code, not in the compiler or language. If this explanation isn't clear enough, please post a question about this in digitalmars.D.learn about this. Maybe someone there can explain it better.
Comment #2 by gavrilyak — 2007-03-14T15:19:54Z
Thanks for explanation, it's clear. That's how it's supposed to work and C++ works same way too, though it looks like premature optimization. For me semantics of those 2 snippets is the same int[] boo(inout int[] arr){ return arr; } int[] arr = [1,2,3]; //first - works int[] temp = boo(arr); boo(temp); //second boo(boo(arr)); May be D can be less restrictive then C++ and this issue is just a feature request :-).