[Issue 18457] New: betterC - struct destructor is always called at function return
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Feb 18 13:56:03 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=18457
Issue ID: 18457
Summary: betterC - struct destructor is always called at
function return
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: mephisto at nordhoff-online.de
D seems to have an optimization:
If a struct is initialized in a function and is returned from the same
function, the destructor will not be called at return.
But:
With betterC this optimization doesn't appear.
Problem:
This produces a different behaviour of betterC and non-betterC.
an example code from file "source/app.d":
----
struct S {
~this() {}
}
S myFunction() {
S s = S();
return s;
}
S myOFunction( S s) {
return s;
}
extern( C) void main() {}
----
extraction from:
$ dmd -vcg-ast source/app.d
----
S myFunction()
{
S s = S();
try
return s;
catch(Throwable __o3)
{
s.~this();
throw __o3;
}
}
S myOFunction(S s)
{
try
{
return s;
}
finally
s.~this();
}
----
extraction from:
$ dmd -betterC -vcg-ast source/app.d
----
S myFunction()
{
S s = S();
try
{
return s;
}
finally
s.~this();
}
S myOFunction(S s)
{
try
{
return s;
}
finally
s.~this();
}
----
--
More information about the Digitalmars-d-bugs
mailing list