diff --git a/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll b/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll index 6f8cfe93507..b5a96f5c8b7 100644 --- a/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll +++ b/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll @@ -127,6 +127,11 @@ private predicate ignoreExprAndDescendants(Expr expr) { exists(BuiltInVarArgsStart vaStartExpr | vaStartExpr.getLastNamedParameter().getFullyConverted() = expr ) + or + // Do not translate implicit destructor calls for unnamed temporary variables that are + // conditionally constructed (until we have a mechanism for calling these only when the + // temporary's constructor was run) + isConditionalTemporaryDestructorCall(expr) } /** @@ -252,6 +257,20 @@ private predicate usedAsCondition(Expr expr) { ) } +private predicate isInConditionalEvaluation(Expr e) { + exists(ConditionalExpr cond | + e = cond.getThen() and not cond.isTwoOperand() + or + e = cond.getElse() + ) + or + isInConditionalEvaluation(getRealParent(e)) +} + +private predicate isConditionalTemporaryDestructorCall(DestructorCall dc) { + isInConditionalEvaluation(dc.getQualifier().(ReuseExpr).getReusedExpr()) +} + /** * Holds if `conv` is an `InheritanceConversion` that requires a `TranslatedLoad`, despite not being * marked as having an lvalue-to-rvalue conversion.