http://d.puremagic.com/issues/show_bug.cgi?id=8830



--- Comment #1 from monarchdo...@gmail.com 2012-10-16 06:57:02 PDT ---
(In reply to comment #0)
> Minimal test case:
> 
> //----
> import std.stdio;
> 
> string[] foo(string s)
> {
>   auto ss = s[1..$];
>   auto l = ss.length;
>   string s2 = ss.ptr[0..2];
>   return [ss, s2];
> 
> }
> 
> void main()
> {
>   enum bar = foo("hello");
>   writeln(bar);
> }
> //----
> 
> Creates:
> 
> //----
> [
>   "ello", //Sliced 1..$ of "hello"
>   "hel"   // *should* be "ello"[0..2], but is actually "hello"[0..2]
> ]
> //----
> 
> It would appear that when slicing a pointer extracted from a previously 
> sliced,
> array, it will slice from the first index of that *original* array.


What is strange though, is that ss.ptr *does* point to the right element:
//----
string[] foo(string s)
{
  auto ss = s[1..$];
  auto l = ss.length;
  string s2 = [*ss.ptr];
  return [ss, s2];
}

void main()
{
  enum bar = foo("hello");
  writeln(bar);
}
//----
[
  "ello",
  "e" //extracted pointer points to the right element.
]
//----

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to