digitalmars.D.bugs - [Issue 8486] New: Possibly wrong interaction of Variant and const arrays
- d-bugmail puremagic.com (35/35) Jul 31 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8486
- d-bugmail puremagic.com (11/11) Jul 31 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8486
- d-bugmail puremagic.com (7/7) Jul 31 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8486
- d-bugmail puremagic.com (25/27) Aug 01 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8486
- d-bugmail puremagic.com (9/9) Aug 01 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8486
- d-bugmail puremagic.com (7/9) Aug 01 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8486
http://d.puremagic.com/issues/show_bug.cgi?id=8486 Summary: Possibly wrong interaction of Variant and const arrays Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: Phobos AssignedTo: nobody puremagic.com ReportedBy: cybevnm gmail.com During initializing Variant, D discards top level const of array, which leads to little unintuitive behaviour. Consider code: import std.stdio; import std.variant; void main() { const int[] arr; Variant v = Variant( arr ); writeln( v.peek!( typeof( arr ) )() ); writeln( v.peek!( const(int)[] )() ); writeln( v.type() ); } ...and output: %dmd main.d && ./main.d null 7FFF358AE298 const(int)[] As you can see peek works successfully not for original array type, but for type without top level const. Is Variant supposed to work in that way ? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 31 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8486 klickverbot <code klickverbot.at> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |code klickverbot.at --- Variant should generally ignore top-level const for »value types« (i.e. array slices, pointers, integral types, …). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 31 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8486 --- … the point being that this is, if anything, analogous to the constness of the Variant instance itself, not the contained type. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 31 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8486… the point being that this is, if anything, analogous to the constness of the Variant instance itself, not the contained type.Unfortunately, Variant's handling of arrays is different to handling of class references. So we have next situtation: import std.variant; class C { } void main() { { const C c; Variant v = Variant( c ); assert( v.peek!( typeof(c) )() != null ); } { const C[] cs; Variant v = Variant( cs ); assert( v.peek!( typeof(cs) )() == null ); } } But array top-level const cutting is understandable, it's the way it works in all other places... -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 01 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8486 --- I meant that Variant should regard e.g. const(T[]) and const(T)[] or const(T*) and const(T)* equivalent, i.e. allow implicit conversion between them. The fact that const is automatically stripped from arrays is not Variant-specific, template functions generally work like that in D. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 01 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8486I meant that Variant should regard e.g. const(T[]) and const(T)[] or const(T*) and const(T)* equivalent, i.e. allow implicit conversion between them.Agree, it will resolve the problem. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 01 2012