[clang] [clang] Fix dangling false positives for conditional operators. (PR #120233)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 18 01:26:01 PST 2024


================
@@ -582,6 +582,15 @@ static void visitFunctionCallArguments(IndirectLocalPath &Path, Expr *Call,
     //   Temp().ptr; // Here ptr might not dangle.
     if (isa<MemberExpr>(Arg->IgnoreImpCasts()))
       return;
+    // Avoid false positives when the object is constructed from a conditional
+    // operator argument. A common case is:
+    //   // 'ptr' might not be owned by the Owner object.
+    //   std::string_view s = cond() ? Owner().ptr : sv;
----------------
Xazax-hun wrote:

Is `const string_view& sv = Owner().sv;` a false negative? We cannot actually know if `sv` is actually owned or not because we have no lifetimebound annotation and the gsl owner does not tell us anything about fields, only about conversions/ctors. 



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


More information about the cfe-commits mailing list