[llvm-branch-commits] [clang] [clang] Use uniform lifetime bounds under exceptions (PR #175817)

Paul Kirth via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jan 13 19:01:12 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)) {
----------------
ilovepi wrote:

no. I was just not thinking clearly enough. All that I needed was a more restrictive condition to use when setting Expr needs cleanup. All in all much cleaner and smaller. 

https://github.com/llvm/llvm-project/pull/175817


More information about the llvm-branch-commits mailing list