[Issue 10424] array operations accept rvalues on the lhs
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jun 20 18:39:16 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10424
Kenji Hara <k.hara.pg at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |INVALID
--- Comment #2 from Kenji Hara <k.hara.pg at gmail.com> 2013-06-20 18:39:14 PDT ---
(In reply to comment #0)
> int f();
> int[] g();
> void main()
> {
> //f() = 42; // as expected: Error: f() is not an lvalue
> //g() = [42]; // as expected: Error: g() is not an lvalue
> g()[] = [42]; // compiles, but shouldn't
> }
The line is correct D code. g() returns an rvalue int[] array, but the
assignment is element-wise, and elements of array are always lvalue.
Then, there's no meaningless rvalue modification.
void main()
{
int[] a = [1];
int[] arr = a;
int[] g() { return arr; }
g()[] = [42]; // element-wise assignment
// essentially same as:
// int[] x = [42]; arr[] = x[];
assert(arr.ptr == a.ptr);
assert(arr == [42]);
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list