digitalmars.D.bugs - [Issue 7539] New: cast(bool) of empty array must result in false
- d-bugmail puremagic.com (43/43) Feb 18 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7539
- d-bugmail puremagic.com (10/10) Feb 18 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7539
- d-bugmail puremagic.com (10/10) Feb 19 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7539
http://d.puremagic.com/issues/show_bug.cgi?id=7539 Summary: cast(bool) of empty array must result in false Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: timon.gehr gmx.ch --- Comment #0 from timon.gehr gmx.ch 2012-02-18 19:44:16 PST --- cast(bool)array must be rewritten to cast(bool)array.length. assert(!""); // currently fails assert(![]); // currently passes assert(![' '][1..1]); // passes assert(!" "[1..1]); // fails assert(a==b && (!a&&b||!b&&a)); // might fail more or less randomly for dynamic arrays a,b The current behavior is that cast(bool)array is translated to cast(bool)array.ptr. This is likely a leftover from the times when dynamic arrays implicitly converted to their .ptr properties. It does not convey any useful semantics, yet it is invoked implicitly every time a dynamic array appears in a boolean evaluation context. struct DynArray{ size_t length; int* ptr; alias ptr this; } void main(){ DynArray a; int[] b; writeln(cast(bool)a); // false writeln(cast(bool)b); // false a.ptr = new int; writeln(cast(bool)a); // true *(cast(int**)&b+1) = new int; // "b.ptr = new int" writeln(cast(bool)b); // true } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 18 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7539 --- Comment #1 from timon.gehr gmx.ch 2012-02-18 20:18:38 PST --- More evidence: Currently these both fail to interpret with the same error message. static assert(cast(int*)[]||1); static assert(cast(bool)[]||1); The current semantics were an accident. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 18 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7539 bearophile_hugs eml.cc changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bearophile_hugs eml.cc --- Comment #2 from bearophile_hugs eml.cc 2012-02-19 04:57:07 PST --- See also issue 4733 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 19 2012