Bug 6937 – new with struct doesn't allow field assignment

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2011-11-12T08:44:00Z
Last change time
2012-12-06T19:53:18Z
Assigned to
nobody
Creator
code

Comments

Comment #0 by code — 2011-11-12T08:44:16Z
struct { int a; } auto s1 = S(2); // works auto s2 = new S(2); // doesn't work ---------- New with struct strictly requires a defined constructor while it should have the same construction rules as a normal struct literal.
Comment #1 by github-bugzilla — 2012-12-06T18:38:18Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/4a22ca0053252454c5cddab2c5754b8a2f500544 fix Issue 6937 - new with struct doesn't allow field assignment https://github.com/D-Programming-Language/dmd/commit/ee695eb92086cb73f62e7e01f019171776308435 Merge pull request #1353 from 9rnsr/fix6937 Issue 6937 - new with struct doesn't allow field assignment
Comment #2 by bearophile_hugs — 2012-12-06T19:10:36Z
Despite this looks like a silent little change, this is a significant improvement in D, and it's one of the best improvements for DMD 2.061. This removes some useless code from my D2 code base.
Comment #3 by bearophile_hugs — 2012-12-06T19:37:53Z
(In reply to comment #2) > Despite this looks like a silent little change, this is a significant > improvement in D, and it's one of the best improvements for DMD 2.061. This > removes some useless code from my D2 code base. This is not yet allowed to remove some more boilerplate code (the "new"): struct Node(T) { T data; Node* left, right; } void main() { alias N = Node!int; auto t1 = new N(1, new N(2, new N(3))); // OK alias M = Node!int.__ctor; // Not OK auto t2 = M(1, M(2, M(3))); }
Comment #4 by k.hara.pg — 2012-12-06T19:46:54Z
(In reply to comment #3) > This is not yet allowed to remove some more boilerplate code (the "new"): > > > struct Node(T) { > T data; > Node* left, right; > } > void main() { > alias N = Node!int; > auto t1 = new N(1, new N(2, new N(3))); // OK > alias M = Node!int.__ctor; // Not OK > auto t2 = M(1, M(2, M(3))); > } This is completely unrelated to this issue. Ideally __ctor should not appear in user code, and language specification would never support it.