Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix Issue 17246 - [REG2.053] Extra destructor call.
- Loading branch information
1 parent
7253190
commit 6eccdee
Showing
3 changed files
with
61 additions
and
7 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
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,50 @@ | ||
/* REQUIRED_ARGS: | ||
* OPTIONAL_ARGS: | ||
*/ | ||
|
||
// https://issues.dlang.org/show_bug.cgi?id=17246 | ||
|
||
struct Foo | ||
{ | ||
int* rc; | ||
this(int val) | ||
{ | ||
rc = new int; | ||
(*rc) = 1; | ||
} | ||
this(this) | ||
{ | ||
(*rc)++; | ||
} | ||
~this() | ||
{ | ||
if (rc) | ||
{ | ||
assert(*rc > 0); | ||
(*rc)--; | ||
} | ||
} | ||
} | ||
|
||
struct Bar | ||
{ | ||
Foo foo; | ||
this(Foo foo, bool) | ||
{ | ||
this.foo = foo; | ||
} | ||
} | ||
|
||
bool fun(bool val) { return !val; } | ||
|
||
auto genBar(bool flag) | ||
{ | ||
return flag ? Bar() : Bar(Foo(10), fun(!flag)); | ||
} | ||
|
||
int main(string[] args) | ||
{ | ||
auto bar = genBar(args.length == 0); | ||
return 0; | ||
} | ||
|