[Issue 5931] keyword new won't allow default initialization of a struct where it has a non-zero argument constructor
https://issues.dlang.org/show_bug.cgi?id=5931 Johannes Loherchanged: What|Removed |Added Status|NEW |RESOLVED CC||johannes.lo...@fg4f.de Resolution|--- |WONTFIX --- Comment #6 from Johannes Loher --- The first problem mentioned has been solved since 2.063. The second problem is still present, error message of 2.080.0: main.d(16): Error: none of the overloads of this are callable using argument types (File), candidates are: /usr/include/dlang/dmd/std/stdio.d(387): std.stdio.File.this(shared(_IO_FILE)* handle, string name, uint refs = 1u, bool isPopened = false) /usr/include/dlang/dmd/std/stdio.d(425):std.stdio.File.this(string name, const(char[]) stdioOpenmode = "rb") /usr/include/dlang/dmd/std/stdio.d(443):std.stdio.File.__ctor(R1, R2)(R1 name) if (isInputRange!R1 && isSomeChar!(ElementEncodingType!R1)) /usr/include/dlang/dmd/std/stdio.d(451):std.stdio.File.__ctor(R1, R2)(R1 name, R2 mode) if (isInputRange!R1 && isSomeChar!(ElementEncodingType!R1) && isInputRange!R2 && isSomeChar!(ElementEncodingType!R2)) The reason is in general, that you can't call postblits as if they were constructors (`File file; auto f = File(file);` also does not work). However, it seems that postblits will probably be replaced by some form of copy constructor, so this might even resolve this issue. I will close this for now. If you really want this feature, please submit a new issue as an enhancement request. --
[Issue 5931] keyword new won't allow default initialization of a struct where it has a non-zero argument constructor
http://d.puremagic.com/issues/show_bug.cgi?id=5931 Christopher the Magnificent ultimatemacfana...@gmail.com changed: What|Removed |Added Summary|keyword new insists on |keyword new won't allow |calling a struct's |default initialization of a |(non-zero argument) |struct where it has a |constructor--in other |non-zero argument |words, it won't allow |constructor |default initialization; | |also postblit this(this)| |constructor dosen't get | |called from new| |structname(struct_instan | |ce) | --- Comment #3 from Christopher the Magnificent ultimatemacfana...@gmail.com 2011-05-06 12:32:02 PDT --- (In reply to comment #2) Post-blit is only called when you override the whole structure, as in: import std.stdio; struct S { this(this) { writeln(postblit); } } void main() { S s; S t; s = t;// -- call postblit on s. } Pointer-assignment will *not* call post-blit as you have not blitted (memcpy-ed) anything. *Shouldn't* post-blit be invokable by calling File(file)? Wouldn't this be a desirable behavior? If not, how do I allocate a default-initialized File struct in the heap using new (so that I can follow that by overwriting the whole structure and get post-blitter to run)? what I'm taking about is this (this is what I want to do): import std.stdio; struct Tokenizer { File* file = null; void initFile(File f) { this.file = new File; // I want to allocate a new File struct and set it to File.init -- DOESNT WORK! *this.file = f; // copy bits and then automatically call post-blit File.this(this) } } At the line above marked DOESN'T WORK, the compiler refuses to allocate a new default-initialized File struct. This is a problem -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 5931] keyword new won't allow default initialization of a struct where it has a non-zero argument constructor
http://d.puremagic.com/issues/show_bug.cgi?id=5931 --- Comment #4 from kenn...@gmail.com 2011-05-06 12:47:28 PDT --- (In reply to comment #3) *Shouldn't* post-blit be invokable by calling File(file)? Wouldn't this be a desirable behavior? Sorry, got distracted by the 'this.file = new File(...)' part because of your 'File file;' :). No it should not call post-blit directly, because is possible to *declare* such a constructor. The problem is, should D define the implicitly-defined copy constructor which does: struct S { this(ref S s) { this = s; // implicitly calls the postblit } ... } ? [snip] At the line above marked DOESN'T WORK, the compiler refuses to allocate a new default-initialized File struct. This is a problem This problem is the same as issue 4249. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 5931] keyword new won't allow default initialization of a struct where it has a non-zero argument constructor
http://d.puremagic.com/issues/show_bug.cgi?id=5931 --- Comment #5 from kenn...@gmail.com 2011-05-06 12:48:43 PDT --- (In reply to comment #4) (In reply to comment #3) [snip] At the line above marked DOESN'T WORK, the compiler refuses to allocate a new default-initialized File struct. This is a problem This problem is the same as issue 4249. I mean issue 4247 -.- -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---