[Issue 2486] taking address of slice rvalue is valid
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Nov 10 03:10:08 PST 2011
http://d.puremagic.com/issues/show_bug.cgi?id=2486
Kenji Hara <k.hara.pg at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Platform|x86 |All
Version|1.037 |D1 & D2
OS/Version|Linux |All
Severity|minor |normal
--- Comment #1 from Kenji Hara <k.hara.pg at gmail.com> 2011-11-10 03:09:27 PST ---
This is still valid in D2.
import std.stdio;
void main()
{
int[] arr = [1,2,3];
auto p = &(arr[0..2]); // same as &(arr[0..2])
writeln(typeof(p).stringof); // int[]*
writeln(arr.ptr);
writeln(&arr);
writeln(p);
assert(&arr == p);
}
I think this is bad behavior, because it allows nonsense code like follows.
void main()
{
int[] arr = [1,2,3];
foo(arr[0..2]); // ref parameter can receive lvalue made by slicing
assert(arr == [1,2,3]); // assertion succeeds...
}
void foo(ref int[] arr)
{
arr = [4,5,6]; // what is modified?
}
--
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