Bug 8760 – for a struct A, new A should work if A a; does
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-10-04T14:59:00Z
Last change time
2014-09-14T14:54:46Z
Assigned to
nobody
Creator
fawzi
Comments
Comment #0 by fawzi — 2012-10-04T14:59:20Z
--------
module t2;
struct A{
this(int i){}
}
void f(){
auto a=new A;
}
---------
fails to compile with dmd 2.060:
t2.d(8): Error: constructor t2.A.this (int i) is not callable using argument types ()
t2.d(8): Error: expected 1 function arguments, not 0
This creates strange problems (for example Variant not working), as a workaround one can give a default argument to the constructor, and then the error is suppressed.
As a struct can be default initialized when on the stack (with 'A a;'), it is only logical to expect to be able to allocate it on the heap with 'new A;'.
This is related with the discussions in issue3680 and issue3438 , but independently from the larger changes/discussion in there, I think this simple operation should work, only when @disable this(){} there should be an error with new A
Comment #1 by k.hara.pg — 2014-09-14T14:54:46Z
*** This issue has been marked as a duplicate of issue 4247 ***