@@ -22,14 +22,20 @@ proc canRaiseDisp(p: BProc; n: PNode): bool =
2222 result = canRaiseConservative (n)
2323
2424proc preventNrvo (p: BProc ; le, ri: PNode ): bool =
25- proc locationEscapes (p: BProc ; le: PNode ): bool =
25+ proc locationEscapes (p: BProc ; le: PNode ; inTryStmt: bool ): bool =
2626 var n = le
2727 while true :
2828 # do NOT follow nkHiddenDeref here!
2929 case n.kind
3030 of nkSym:
3131 # we don't own the location so it escapes:
32- return n.sym.owner != p.prc
32+ if n.sym.owner != p.prc:
33+ return true
34+ elif inTryStmt and sfUsedInFinallyOrExcept in n.sym.flags:
35+ # it is also an observable store if the location is used
36+ # in 'except' or 'finally'
37+ return true
38+ return false
3339 of nkDotExpr, nkBracketExpr, nkObjUpConv, nkObjDownConv,
3440 nkCheckedFieldExpr:
3541 n = n[0 ]
@@ -46,7 +52,7 @@ proc preventNrvo(p: BProc; le, ri: PNode): bool =
4652 # we use the weaker 'canRaise' here in order to prevent too many
4753 # annoying warnings, see #14514
4854 if canRaise (ri[0 ]) and
49- (p .nestedTryStmts.len > 0 or locationEscapes (p, le) ):
55+ locationEscapes (p, le, p .nestedTryStmts.len > 0 ):
5056 message (p.config, le.info, warnObservableStores, $ le)
5157
5258proc hasNoInit (call: PNode ): bool {.inline .} =
0 commit comments