digitalmars.D.bugs - [Issue 10013] New: `inout` constructor sometimes fails to create immutable object
- d-bugmail puremagic.com (40/40) Apr 30 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10013
- d-bugmail puremagic.com (20/20) May 04 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10013
http://d.puremagic.com/issues/show_bug.cgi?id=10013 Summary: `inout` constructor sometimes fails to create immutable object Product: D Version: D2 Platform: All OS/Version: All Status: NEW Keywords: rejects-valid Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: verylonglogin.reg gmail.com 16:34:45 MSD --- --- class C { this() inout { } this(inout int[]) inout { } } void main() { auto c0 = new immutable C(cast(immutable int[]) null); // OK auto c1 = new immutable C(); // Error (line 10) auto c2 = new immutable C(null); // Error (line 11) } --- dmd output: --- main.d(10): Error: inout constructor main.C.this creates inout object, not immutable main.d(11): Error: inout constructor main.C.this creates mutable object, not immutable --- Partial workaround: Mark constructor as `pure` or `immutable` if possible. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 30 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10013 These are the designed behavior. 1. If the inout constructor has inout parameters, the created object is restricted to the argument qualifiers - it is same as normal inout functions. So: auto c0 = new immutable C(cast(immutable int[]) null); // OK constructor call creates inout object and it is implicitly translated to immutable by the immutable arguments. 1.5 'null' literal is normally treated as a mutable data, so auto c2 = new immutable C(null); // Error (line 11) constructor call creates mutable C object, but it is not convertible to immutable. 2. To convert the created object to any qualifier, the constructor should have 'pure' attribute at least. So: auto c1 = new immutable C(); // Error (line 10) fails to compile. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 04 2013