On Thursday, 11 November 2021 at 09:24:17 UTC, Atila Neves wrote:
>On Wednesday, 10 November 2021 at 13:52:26 UTC, deadalnix wrote:
>On Tuesday, 9 November 2021 at 18:33:01 UTC, Atila Neves wrote:
>I think that C++'s greatest gift to the world was the destructor. We have those too! Let's use them.
Indeed, but I have unfortunate news. We broke the gift. In D, object can be destroyed without being constructed first.
Consider: https://godbolt.org/z/EdW75jWGn
This is the first problem we need to fix here, if we don't want to have to plaster our code with runtime checks.
@disable this();
, but you knew that. It's true that requiring a programmer to do something to prevent bugs is a terrible idea. Sigh.
Sorry for reviving this thread, was just sifting through...
The following code also outputs dtor!
, unfortunately :(
import std.stdio:writeln;
struct S{
@disable this();
~this(){
writeln("dtor!");
}
}
void main(){
S s = void;
}
Compiler :
LDC - the LLVM D compiler (1.25.0):
based on DMD v2.095.1 and LLVM 11.1.0