Bug 6578 – Ignored const with struct with constructor

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-08-30T04:57:00Z
Last change time
2013-04-26T04:16:29Z
Keywords
accepts-invalid, pull
Assigned to
yebblies
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2011-08-30T04:57:48Z
In DMD 2.055head this compiles and runs with no errors: struct Foo { int x; this(int x_) { this.x = x_; } } void main() { auto f1 = new const(Foo)(1); f1.x++; auto f2 = new immutable(Foo)(1); f2.x++; auto f3 = const(Foo)(1); f3.x++; auto f4 = immutable(Foo)(1); f4.x++; } While this generates two errors: struct Foo { int x; } void main() { auto f5 = const(Foo)(1); f5.x++; // error auto f6 = immutable(Foo)(1); f6.x++; // error } I think in the first program the f1,f2,f3,f4 structs too need to raise a compile-time error. Thanks to Timon Gehr for a suggestion.
Comment #1 by yebblies — 2012-01-30T22:26:17Z
Comment #2 by yebblies — 2013-03-05T07:25:03Z
*** Issue 9647 has been marked as a duplicate of this issue. ***
Comment #3 by github-bugzilla — 2013-03-06T00:44:46Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/b133ffbad523c03c11a3253595fb4edf1ccc53b4 Issue 6578 - Wrong type deduction for NewExp and __ctor with struct Add the constructor's modifiers to the result type, instead of replacing them. https://github.com/D-Programming-Language/dmd/commit/a319e6d4c70de1fcc28a21b743d3367fb533e116 Merge pull request #666 from yebblies/issue6578 Issue 6578 - Wrong type deduction for NewExp and __ctor with struct
Comment #4 by k.hara.pg — 2013-03-06T23:11:53Z
Yet another test case: struct S { this(int[] arr) immutable {} } void main() { auto s = S([1,2,3]); pragma(msg, typeof(s)); // prints immutable(S) } Can be fixed by: https://github.com/D-Programming-Language/dmd/pull/1726
Comment #5 by k.hara.pg — 2013-04-26T04:16:29Z
(In reply to comment #4) > Yet another test case: > > struct S { > this(int[] arr) immutable {} > } > void main() { > auto s = S([1,2,3]); > pragma(msg, typeof(s)); // prints immutable(S) > } > > Can be fixed by: > https://github.com/D-Programming-Language/dmd/pull/1726 Pull-request 1726 is merged, and this issue has been fixed properly.