Thread overview | ||||||
---|---|---|---|---|---|---|
|
October 16, 2012 [Issue 8830] New: [CTFE] Incorrect slicing with pointer from sliced array | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=8830 Summary: [CTFE] Incorrect slicing with pointer from sliced array Product: D Version: unspecified Platform: All OS/Version: All Status: NEW Severity: major Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: monarchdodra@gmail.com --- Comment #0 from monarchdodra@gmail.com 2012-10-16 06:56:32 PDT --- 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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 16, 2012 [Issue 8830] [CTFE] Incorrect slicing with pointer from sliced array | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarchdodra@gmail.com | http://d.puremagic.com/issues/show_bug.cgi?id=8830 --- Comment #1 from monarchdodra@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: ------- |
October 21, 2012 [Issue 8830] [CTFE] Incorrect slicing with pointer from sliced array | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarchdodra@gmail.com | http://d.puremagic.com/issues/show_bug.cgi?id=8830 --- Comment #2 from github-bugzilla@puremagic.com 2012-10-20 17:18:49 PDT --- Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/abe37596dcfd0a150b86f703b582cfcf495c1727 Fix issue 8830 [CTFE] Incorrect slicing with pointer from sliced array Simple bug -- the offset of the pointer needs to be added to the slice. https://github.com/D-Programming-Language/dmd/commit/be5cae498f81c1e5965fd7755f432ffb7fdb5ec1 Minor code cleanup following bug 8830 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 21, 2012 [Issue 8830] [CTFE] Incorrect slicing with pointer from sliced array | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarchdodra@gmail.com | http://d.puremagic.com/issues/show_bug.cgi?id=8830 Walter Bright <bugzilla@digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |bugzilla@digitalmars.com Version|unspecified |D1 & D2 Resolution| |FIXED -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation