digitalmars.D.bugs - [Issue 3990] New: Deferencing a dynamic array as pointer
- d-bugmail puremagic.com (31/31) Mar 20 2010 http://d.puremagic.com/issues/show_bug.cgi?id=3990
- d-bugmail puremagic.com (16/16) May 06 2010 http://d.puremagic.com/issues/show_bug.cgi?id=3990
- d-bugmail puremagic.com (8/8) Apr 26 2011 http://d.puremagic.com/issues/show_bug.cgi?id=3990
- d-bugmail puremagic.com (14/19) Oct 31 2011 http://d.puremagic.com/issues/show_bug.cgi?id=3990
- d-bugmail puremagic.com (13/15) Oct 31 2011 http://d.puremagic.com/issues/show_bug.cgi?id=3990
- d-bugmail puremagic.com (21/38) Oct 31 2011 http://d.puremagic.com/issues/show_bug.cgi?id=3990
- d-bugmail puremagic.com (9/14) Oct 31 2011 http://d.puremagic.com/issues/show_bug.cgi?id=3990
- d-bugmail puremagic.com (10/16) Oct 31 2011 http://d.puremagic.com/issues/show_bug.cgi?id=3990
- d-bugmail puremagic.com (10/10) Oct 31 2011 http://d.puremagic.com/issues/show_bug.cgi?id=3990
- d-bugmail puremagic.com (10/13) Oct 31 2011 http://d.puremagic.com/issues/show_bug.cgi?id=3990
- d-bugmail puremagic.com (14/14) Nov 01 2011 http://d.puremagic.com/issues/show_bug.cgi?id=3990
- d-bugmail puremagic.com (11/11) Dec 22 2011 http://d.puremagic.com/issues/show_bug.cgi?id=3990
- d-bugmail puremagic.com (10/10) Jan 29 2012 http://d.puremagic.com/issues/show_bug.cgi?id=3990
http://d.puremagic.com/issues/show_bug.cgi?id=3990 Summary: Deferencing a dynamic array as pointer Product: D Version: 2.041 Platform: x86 OS/Version: Windows Status: NEW Keywords: accepts-invalid Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: bearophile_hugs eml.cc This D2 code is currrently allowed, but I think it has to become a syntax error, dynamic arrays are not pointers: void main() { int[] a1 = [5, 4, 3]; assert(*a1 == 5); alias typeof(a1) T1; assert(is(typeof(*T1))); int* p1 = cast(int*)a1; assert(p1 == a1.ptr); } ---------------- Similar code can be written for a fixed-size array like: int[3] a2 = [5, 4, 3]; For fixed-size arrays such conversions to pointers can be more acceptable. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 20 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3990 Another case that I think is related: import std.stdio: writeln; struct Arr(int N) { int[N] data; alias data this; } void main() { auto p = new Arr!(10); *p = 10; writeln(p.data); // Output: 10 10 10 10 10 10 10 10 10 10 } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 06 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3990 More very good rationale from Steven Schveighoffer, that I think settles the situation: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=135391 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 26 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3990 1.assert(*a1 == 5); alias typeof(a1) T1; assert(is(typeof(*T1)));Dereferencing dynamic or static array without -d option is deprecated. I think this is 'accepts-invalid'. 2.int* p1 = cast(int*)a1; assert(p1 == a1.ptr);Explicit casting is still valid. cast(int*)a1 means cast(int*)a1.ptr -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 31 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3990 This is not related.auto p = new Arr!(10); *p = 10;means Arr!(10)* p = new Arr!(10); (*p).data = 10; // see alias this after deref-ing of p And, the assignment an element type into static array is valid. int[10] sa; sa = 10; // translated to sa[] = 10 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 31 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3990Don agrees: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=148054assert(*a1 == 5); alias typeof(a1) T1; assert(is(typeof(*T1)));Dereferencing dynamic or static array without -d option is deprecated. I think this is 'accepts-invalid'.2.I don't see the need to accept this cast. There is the ".ptr" so this cast is not useful in practice. And generally this cast is refused by DMD 2.056 as you see in the following program, so you are introducing/leaving an useless special case: struct Foo { int* p; size_t n; } void main() { Foo f; auto x = cast(int*)f; } So I think cast(int*)a1 should be forbidden. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------int* p1 = cast(int*)a1; assert(p1 == a1.ptr);Explicit casting is still valid. cast(int*)a1 means cast(int*)a1.ptr
Oct 31 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3990This is not related.You are right, it's not related, it's a different problem.And, the assignment an element type into static array is valid. int[10] sa; sa = 10; // translated to sa[] = 10It's currently valid, but I think it should be forbidden. I think D should require the [] here. See bug 3971 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 31 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3990I don't see the need to accept this cast. There is the ".ptr" so this cast is not useful in practice. And generally this cast is refused by DMD 2.056 as you see in the following program, so you are introducing/leaving an useless special case:[snip]So I think cast(int*)a1 should be forbidden.The title of this issue is "Deferencing a dynamic array as pointer". Therefore even if you think it is not useful, we should not discuss it in here. Instead, you can file it as a new issue. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 31 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3990 Kenji Hara <k.hara.pg gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |patch https://github.com/D-Programming-Language/dmd/pull/483 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 31 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3990 Thank you for the patch.The title of this issue is "Deferencing a dynamic array as pointer". Therefore even if you think it is not useful, we should not discuss it in here. Instead, you can file it as a new issue.I have lumped them together because to me they look like quite similar issues: in both cases an array is seen as a pointer. But OK, I have opened the new report bug 6869 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 31 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3990 Walter Bright <bugzilla digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |bugzilla digitalmars.com Resolution| |FIXED 13:16:14 PDT --- https://github.com/D-Programming-Language/dmd/commit/889fd53a5bc849d88ce1c3a8c907930f88471144 https://github.com/D-Programming-Language/dmd/commit/95b6e6b5188a59b32e6333b2053b6d06798c64f3 https://github.com/D-Programming-Language/dmd/commit/0b49647ad92be63274c156bbc7a6d9213a25d9ae -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 01 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3990 Don <clugdbug yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jarrett.billingsley gmail.c | |om *** Issue 1381 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: -------
Dec 22 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3990 yebblies <yebblies gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |2korden gmail.com *** Issue 4772 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: -------
Jan 29 2012