[clang] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

Boaz Brickner via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 13 08:36:50 PST 2024


================
@@ -1199,6 +1207,21 @@ static void checkExprLifetimeImpl(Sema &SemaRef,
       break;
     }
 
+    case LK_LifetimeCapture: {
+      if (!MTE)
+        return false;
+      assert(shouldLifetimeExtendThroughPath(Path) ==
+                 PathLifetimeKind::NoExtend &&
+             "No lifetime extension in function calls");
+      if (CapEntity->Entity != nullptr)
+        SemaRef.Diag(DiagLoc, diag::warn_dangling_reference_captured)
+            << true << CapEntity->Entity << DiagRange;
+      else
+        SemaRef.Diag(DiagLoc, diag::warn_dangling_reference_captured)
+            << false << "<ignore>" << DiagRange;
----------------
bricknerb wrote:

Instead of having true and "<ignored>" parameters, how about splitting to two different warnings?

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


More information about the cfe-commits mailing list