Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 73602dc

Browse files
committed
C++: Also suppress destructor calls on throwing ternary expressions.
1 parent a6a0e20 commit 73602dc

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,26 @@ private predicate usedAsCondition(Expr expr) {
257257
)
258258
}
259259

260+
private predicate hasThrowingChild(Expr e) {
261+
e = any(ThrowExpr throw).getFullyConverted()
262+
or
263+
exists(Expr child |
264+
e = getRealParent(child) and
265+
hasThrowingChild(child)
266+
)
267+
}
268+
260269
private predicate isInConditionalEvaluation(Expr e) {
261270
exists(ConditionalExpr cond |
262271
e = cond.getThen().getFullyConverted() and not cond.isTwoOperand()
263272
or
264273
e = cond.getElse().getFullyConverted()
274+
or
275+
// If one of the operands throws then the temporaries constructed in either
276+
// branch will also be attached to the ternary expression. We suppress
277+
// those destructor calls as well.
278+
hasThrowingChild([cond.getThen(), cond.getElse()]) and
279+
e = cond.getFullyConverted()
265280
)
266281
or
267282
isInConditionalEvaluation(getRealParent(e))

0 commit comments

Comments
 (0)