Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8951 from RazvanN7/Issue_19393
Fix Issue 19393 - Structure dtor isn't called after passed to T[] argument. Memory leaks issue
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
string result; | ||
|
||
struct S | ||
{ | ||
this(this) | ||
{ | ||
result ~= "A"; | ||
} | ||
|
||
~this() | ||
{ | ||
result ~= "B"; | ||
} | ||
} | ||
|
||
void foo(const(S)[] ar...) | ||
{ | ||
/* postblit gets called on this initialization, | ||
* then when the function returns, the destructor | ||
* gets called => result = "AB"; | ||
*/ | ||
auto d = ar[0]; | ||
} | ||
|
||
void bar() | ||
{ | ||
/* S(null) needs to be destroyed after the function call, | ||
* that means that another `B` is appended => result = "ABB" | ||
*/ | ||
foo(S()); | ||
} | ||
|
||
void main() | ||
{ | ||
bar(); | ||
assert(result == "ABB"); | ||
} |