C++: Do not consider expression results discardable when there is a conversion

This commit is contained in:
Jeroen Ketema
2025-07-04 14:10:34 +02:00
parent b185cc8b95
commit 2908570ce9

View File

@@ -4146,7 +4146,8 @@ predicate exprNeedsCopyIfNotLoaded(Expr expr) {
private predicate exprImmediatelyDiscarded(Expr expr) {
exists(ExprStmt s |
s = expr.getParent() and
not exists(StmtExpr se | s = se.getStmt().(BlockStmt).getLastStmt())
not exists(StmtExpr se | s = se.getStmt().(BlockStmt).getLastStmt()) and
not exists(Conversion c | c = expr.getConversion*() and not isTransparentConversion(c))
)
or
exists(CommaExpr c | c.getLeftOperand() = expr)