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

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 17 07:54:53 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:

> but it doesn’t yet address cases like `GSLPointer pointer(Cond ? Owner().ptr : GSLPointer())`

I am wondering if it was possible to use the same or similar MemberExpr filter when we drill down to the branches of the conditional operator. If it is too hard to do, I am OK with the current solution. But to me expanding the MemberExpr logic to handle more expressions sounds more natural than adding logic for a new expression type. 

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


More information about the cfe-commits mailing list