digitalmars.D.bugs - [Issue 6288] New: std.conv.to removes const/immutable when converting a class
- d-bugmail puremagic.com (50/50) Jul 11 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6288
- d-bugmail puremagic.com (10/10) Sep 20 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6288
- d-bugmail puremagic.com (11/11) Sep 22 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6288
- d-bugmail puremagic.com (11/11) Oct 09 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6288
http://d.puremagic.com/issues/show_bug.cgi?id=6288 Summary: std.conv.to removes const/immutable when converting a class Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: Phobos AssignedTo: nobody puremagic.com ReportedBy: schveiguy yahoo.com --- Comment #0 from Steven Schveighoffer <schveiguy yahoo.com> 2011-07-11 10:19:14 PDT --- The code in std.conv.to looks like this for converting to base/derived class: /** Object-to-object conversions throw exception when the source is non-null and the target is null. */ T toImpl(T, S)(S value) if (is(S : Object) && is(T : Object)) { auto result = cast(T) value; if (!result && value) { throw new ConvException("Cannot convert object of static type " ~S.classinfo.name~" and dynamic type "~value.classinfo.name ~" to type "~T.classinfo.name); } return result; } This does not take into account that cast can easily remove const or immutable decorations. For example: import std.conv; class C {} class D : C {} void main() { const(C) c = new D; D d = to!D(c); assert(d !is null); } This compiles as of 2.054, and clearly is removing const without requiring a cast. Unfortunately, cast() is the mechanism to do dynamic conversions, so the logic to allow compilation needs to check that const is not being removed or immutable is not being removed/added. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 11 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6288 Kenji Hara <k.hara.pg gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |patch --- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2011-09-20 05:44:35 PDT --- https://github.com/D-Programming-Language/phobos/pull/271 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 20 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6288 Steven Schveighoffer <schveiguy yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED --- Comment #2 from Steven Schveighoffer <schveiguy yahoo.com> 2011-09-22 08:00:36 PDT --- https://github.com/D-Programming-Language/phobos/commit/8b6ef3b46be8ea50b9aef96b2b2d12c378315189 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 22 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6288 Kenji Hara <k.hara.pg gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |Jesse.K.Phillips+D gmail.co | |m --- Comment #3 from Kenji Hara <k.hara.pg gmail.com> 2011-10-09 03:47:02 PDT --- *** Issue 5307 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: -------
Oct 09 2011