Skip to content

Commit

Permalink
fix Issue 18099 - betterC check throw statements error!
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright authored and wilzbach committed Dec 29, 2017
1 parent 642da20 commit 42ea373
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/dmd/func.d
Expand Up @@ -6,12 +6,12 @@
* Authors: $(LINK2 http://www.digitalmars.com, Walter Bright)
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/func.d, _func.d)
* Documentation: https://dlang.org/phobos/dmd_func.html
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/func.d
*/

module dmd.func;

// Online documentation: https://dlang.org/phobos/dmd_func.html

import core.stdc.stdio;
import core.stdc.string;
import dmd.aggregate;
Expand Down Expand Up @@ -104,7 +104,8 @@ public:
override void visit(TryFinallyStatement s)
{
DtorExpStatement des;
if (fd.nrvo_can && s.finalbody && (des = s.finalbody.isDtorExpStatement()) !is null && fd.nrvo_var == des.var)
if (fd.nrvo_can && s.finalbody && (des = s.finalbody.isDtorExpStatement()) !is null &&
fd.nrvo_var == des.var && global.params.useExceptions)
{
/* Normally local variable dtors are called regardless exceptions.
* But for nrvo_var, its dtor should be called only when exception is thrown.
Expand Down
19 changes: 19 additions & 0 deletions test/compilable/test18099.d
@@ -0,0 +1,19 @@

/* REQUIRED_ARGS: -betterC
*/

// https://issues.dlang.org/show_bug.cgi?id=18099

struct D
{
static struct V
{
~this() { }
}

V get()
{
V v;
return v;
}
}

0 comments on commit 42ea373

Please sign in to comment.