digitalmars.D.bugs - [Issue 6869] New: Disallow array to pointer cast
- d-bugmail puremagic.com (44/44) Oct 31 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6869
- d-bugmail puremagic.com (9/9) Oct 31 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6869
- d-bugmail puremagic.com (9/9) Jan 31 2012 http://d.puremagic.com/issues/show_bug.cgi?id=6869
- d-bugmail puremagic.com (10/10) Jan 31 2012 http://d.puremagic.com/issues/show_bug.cgi?id=6869
- d-bugmail puremagic.com (9/9) Jan 31 2012 http://d.puremagic.com/issues/show_bug.cgi?id=6869
http://d.puremagic.com/issues/show_bug.cgi?id=6869
Summary: Disallow array to pointer cast
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Keywords: accepts-invalid
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody puremagic.com
ReportedBy: bearophile_hugs eml.cc
This is a spinoff of bug 3990
In DMD 2.056 this code compiles:
void main() {
int[] a1 = [5, 4, 3];
int* p1 = cast(int*)a1; // no compile error here
}
Similar code using user-created struct doesn't compile:
struct Foo {
int* p;
size_t n;
}
void main() {
Foo f;
auto x = cast(int*)f; // compile error here
}
I don't see the need to accept this cast, because allowing the array to pointer
cast means introducing/leaving an useless special case, and there in practice
this special case is not useful because arrays have the ptr property:
struct Foo {
int* p;
size_t n;
}
void main() {
Foo f;
auto x = f.ptr; // OK
}
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: -------
Oct 31 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6869 See some discussion: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=148090 An answer: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=148099 -- 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=6869
yebblies <yebblies gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |yebblies gmail.com
Severity|normal |enhancement
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 31 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6869
bearophile_hugs eml.cc changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|enhancement |normal
Reverted to bug, this isn't an enhancement, it's a bug.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 31 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6869 How is it a bug? Implicit conversions from arrays to pointers have been deprecated, but as far as I know this is an intentional feature of D, regardless of if it's a useful/bug prone one or not. Is there any reason you know of why this is not working as intended? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 31 2012









d-bugmail puremagic.com 