Thread overview | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
December 02, 2008 [Issue 2486] New: taking address of slice rvalue is valid | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=2486 Summary: taking address of slice rvalue is valid Product: D Version: 1.037 Platform: PC OS/Version: Linux Status: NEW Keywords: spec Severity: minor Priority: P2 Component: DMD AssignedTo: bugzilla@digitalmars.com ReportedBy: kamm-removethis@incasoftware.de I was surprised to see that following compiles and generates reasonable code: int[] a = [1, 2, 3] auto addr = &a[0..2]; Since the frontend seems to explicitly allow it, it's probably intentional and we've made LDC behave the same way. Could a description and rationale be added to the spec? -- |
November 10, 2011 [Issue 2486] taking address of slice rvalue is valid | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2486 Kenji Hara <k.hara.pg@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@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: ------- |
January 23, 2012 [Issue 2486] taking address of slice rvalue is valid | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2486 Walter Bright <bugzilla@digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords|spec | CC| |bugzilla@digitalmars.com --- Comment #2 from Walter Bright <bugzilla@digitalmars.com> 2012-01-22 20:13:33 PST --- I agree, and will fix the spec. So it's a compiler bug that this code is accepted. It should only work for const references. Changing to a compiler bug. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 24, 2012 [Issue 2486] taking address of slice rvalue is valid | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2486 --- Comment #3 from Kenji Hara <k.hara.pg@gmail.com> 2012-01-24 05:38:49 PST --- Maybe the documentation fix is: https://github.com/D-Programming-Language/d-programming-language.org/commit/8681d6fb36bd7a00a395bfc66205d5dbe8b19d88 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 23, 2012 [Issue 2486] taking address of slice rvalue is valid | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2486 --- Comment #4 from Kenji Hara <k.hara.pg@gmail.com> 2012-02-23 02:38:57 PST --- I found related bug that returning slice by auto ref causes an error. ---- struct S { int[] a; auto ref opSlice(){ return a[]; } // line 4 } void main() { S s; s[]; } Output: ---- test.d(4): Error: slice expression this.a[] is not a modifiable lvalue -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
December 03, 2012 [Issue 2486] taking address of slice rvalue is valid | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2486 Kenji Hara <k.hara.pg@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |accepts-invalid, pull --- Comment #5 from Kenji Hara <k.hara.pg@gmail.com> 2012-12-02 22:22:32 PST --- D2 pull: https://github.com/D-Programming-Language/dmd/pull/1343 https://github.com/D-Programming-Language/phobos/pull/989 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
December 07, 2012 [Issue 2486] taking address of slice rvalue is valid | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2486 --- Comment #6 from github-bugzilla@puremagic.com 2012-12-06 21:50:15 PST --- Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/7062ce191a651ca94fc779ac646a5ef5653b4559 fix Issue 2486 - taking address of slice rvalue is valid https://github.com/D-Programming-Language/phobos/commit/af4fea78550216647dbf3e4aaa7d89ab1b79f542 Merge pull request #989 from 9rnsr/fix2486 Issue 2486 - taking address of slice rvalue is valid -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 07, 2013 [Issue 2486] taking address of slice rvalue is valid | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2486 yebblies <yebblies@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bearophile_hugs@eml.cc --- Comment #7 from yebblies <yebblies@gmail.com> 2013-01-07 13:45:08 EST --- *** Issue 9270 has been marked as a duplicate of this issue. *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
March 06, 2013 [Issue 2486] taking address of slice rvalue is valid | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2486 --- Comment #8 from github-bugzilla@puremagic.com 2013-03-05 22:52:16 PST --- Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/4573ac12bbe1fde782684ed9042f57ab53b05e90 fix Issue 2486 - taking address of slice rvalue is valid -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
March 06, 2013 [Issue 2486] taking address of slice rvalue should not be allowed | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2486 Andrej Mitrovic <andrej.mitrovich@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |andrej.mitrovich@gmail.com Summary|taking address of slice |taking address of slice |rvalue is valid |rvalue should not be | |allowed --- Comment #9 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-03-06 05:52:43 PST --- Changing title to make it easier to understand in changelog. -- 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