[llvm-branch-commits] [clang] [clang] Use uniform lifetime bounds under exceptions (PR #175817)
Eli Friedman via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Jan 13 14:42:23 PST 2026
================
@@ -6686,8 +6686,22 @@ Expr *Sema::MaybeCreateExprWithCleanups(Expr *SubExpr) {
assert(ExprCleanupObjects.size() >= FirstCleanup);
assert(Cleanup.exprNeedsCleanups() ||
ExprCleanupObjects.size() == FirstCleanup);
- if (!Cleanup.exprNeedsCleanups())
+ if (!Cleanup.exprNeedsCleanups()) {
+ // If we have a 'new' expression with a non-trivial destructor, we need to
+ // wrap it in an ExprWithCleanups to ensure that the destructor is called
+ // if the constructor throws.
+ if (auto *NE = dyn_cast<CXXNewExpr>(SubExpr)) {
----------------
efriedma-quic wrote:
Should we just add `Cleanup.setExprNeedsCleanups(true);` in Sema::BuildCXXNew? Explicitly checking for "new" here seems incomplete.
https://github.com/llvm/llvm-project/pull/175817
More information about the llvm-branch-commits
mailing list